no message
This commit is contained in:
@@ -1,13 +1,41 @@
|
||||
package Common.Visual;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Mode;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.Themes.DefaultTheme;
|
||||
import Common.Visual.Themes.VisualiserTheme;
|
||||
import _VisualDVM.Global;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.text.DefaultFormatter;
|
||||
import java.awt.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Stack;
|
||||
public class CommonUI {
|
||||
public static boolean active=true; //есть ли интерфейс. в консольных версиях не нужен.
|
||||
public static boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
//---
|
||||
public static LinkedHashMap<Class<? extends DataSet>, DataMenuBar> menuBars = new LinkedHashMap<>();
|
||||
public static Stack<Component> windowsStack = new Stack<>();
|
||||
static VisualiserTheme theme = new DefaultTheme();
|
||||
public static VisualiserTheme getTheme() {
|
||||
return theme;
|
||||
}
|
||||
public static void setTheme(VisualiserTheme theme_in){
|
||||
theme= theme_in;
|
||||
}
|
||||
public static Component getFrontWindow() {
|
||||
Component res = null;
|
||||
try {
|
||||
res = windowsStack.peek();
|
||||
} catch (Exception ignored){
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
//-----
|
||||
public static void Clear(Container container) {
|
||||
container.removeAll();
|
||||
@@ -37,4 +65,42 @@ public class CommonUI {
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void MakeSpinnerRapid(JSpinner spinner, ChangeListener listener) {
|
||||
JComponent comp = spinner.getEditor();
|
||||
JFormattedTextField field = (JFormattedTextField) comp.getComponent(0);
|
||||
DefaultFormatter formatter = (DefaultFormatter) field.getFormatter();
|
||||
formatter.setCommitsOnValidEdit(true);
|
||||
formatter.setAllowsInvalid(true);
|
||||
spinner.addChangeListener(listener);
|
||||
}
|
||||
//Примитивные диалоговые элементы
|
||||
public static boolean Question(Component parent, String text) {
|
||||
return !CommonUI.isActive() || (JOptionPane.showConfirmDialog(parent,
|
||||
text + "?",
|
||||
"Подтверждение",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE) == 0);
|
||||
}
|
||||
public static boolean Question(String text) {
|
||||
return Question(getFrontWindow(), text);
|
||||
}
|
||||
public static void Info(String message) {
|
||||
CommonUtils.CopyToClipboard(message);
|
||||
if (CommonUI.isActive())
|
||||
JOptionPane.showMessageDialog(getFrontWindow(), message, "", 1);
|
||||
}
|
||||
public static void Error(String message) {
|
||||
CommonUtils.CopyToClipboard(message);
|
||||
if (CommonUI.isActive())
|
||||
JOptionPane.showMessageDialog(getFrontWindow(), message, "", 0);
|
||||
}
|
||||
public static boolean Warning(String text) {
|
||||
return !CommonUI.isActive() ||
|
||||
JOptionPane.showConfirmDialog(getFrontWindow(),
|
||||
text + "\nВы уверены?",
|
||||
"Подтверждение",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE) == 0;
|
||||
}
|
||||
//--
|
||||
}
|
||||
|
||||
21
src/Common/Visual/Fonts/VisualiserFonts.java
Normal file
21
src/Common/Visual/Fonts/VisualiserFonts.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package Common.Visual.Fonts;
|
||||
public enum VisualiserFonts {
|
||||
GoodState,
|
||||
ReadyState,
|
||||
BadState,
|
||||
Fatal,
|
||||
ProgressState,
|
||||
UnknownState,
|
||||
Hyperlink,
|
||||
Disabled,
|
||||
//бесцветные
|
||||
Distribution,
|
||||
//---
|
||||
TreeItalic,
|
||||
TreePlain,
|
||||
TreeBold,
|
||||
TreeBoldItalic,
|
||||
BlueState,
|
||||
NewVersion, //---
|
||||
Menu
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package Common.Visual;
|
||||
import _VisualDVM.Syntax.VisualiserFonts;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
public interface StatusEnum {
|
||||
default String getDescription() {
|
||||
return toString();
|
||||
|
||||
60
src/Common/Visual/Themes/DefaultTheme.java
Normal file
60
src/Common/Visual/Themes/DefaultTheme.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package Common.Visual.Themes;
|
||||
import java.awt.*;
|
||||
public class DefaultTheme extends VisualiserTheme{
|
||||
@Override
|
||||
protected String getForegroundHex() {
|
||||
return "#000000";
|
||||
}
|
||||
@Override
|
||||
protected String getBackgroundHex() {
|
||||
return "#f7f7f7";
|
||||
}
|
||||
@Override
|
||||
protected String getSelectionBackgroundHex() {
|
||||
return "#dae3f1";
|
||||
}
|
||||
@Override
|
||||
protected String getTreeBackgroundHex() {
|
||||
return "#ffffff";
|
||||
}
|
||||
@Override
|
||||
protected String getBarForegroundHex() {
|
||||
return "#637780";
|
||||
}
|
||||
@Override
|
||||
protected String getBarBackgroundHex() {
|
||||
return "#ffffff";
|
||||
}
|
||||
@Override
|
||||
protected String getTableBackgroundHex() {
|
||||
return "#ffffff";
|
||||
}
|
||||
@Override
|
||||
protected Color getGoodFontColor() {
|
||||
return Color.decode("#009738");
|
||||
}
|
||||
@Override
|
||||
protected Color getReadyFontColor2() {
|
||||
return Color.decode("#FFD700");
|
||||
}
|
||||
@Override
|
||||
protected Color getProgressFontColor() {
|
||||
return Color.decode("#f39a28");
|
||||
}
|
||||
@Override
|
||||
protected Color getBadFontColor() {
|
||||
return Color.decode("#ab0000");
|
||||
}
|
||||
@Override
|
||||
protected Color getFatalFontColor() {
|
||||
return Color.decode("#FF4500");
|
||||
}
|
||||
@Override
|
||||
protected Color getUnknownFontColor() {
|
||||
return Color.GRAY;
|
||||
}
|
||||
@Override
|
||||
protected Color getHyperlinkFontColor() {
|
||||
return Color.blue;
|
||||
}
|
||||
}
|
||||
8
src/Common/Visual/Themes/ThemeElement.java
Normal file
8
src/Common/Visual/Themes/ThemeElement.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package Common.Visual.Themes;
|
||||
public interface ThemeElement {
|
||||
default void FontUp() {
|
||||
}
|
||||
default void FontDown() {
|
||||
}
|
||||
void applyTheme();
|
||||
}
|
||||
175
src/Common/Visual/Themes/VisualiserTheme.java
Normal file
175
src/Common/Visual/Themes/VisualiserTheme.java
Normal file
@@ -0,0 +1,175 @@
|
||||
package Common.Visual.Themes;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
import Common.Visual.VisualiserColor;
|
||||
import org.fife.ui.rsyntaxtextarea.Theme;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import static java.awt.Font.MONOSPACED;
|
||||
public abstract class VisualiserTheme {
|
||||
public Color foreground;
|
||||
public Color background;
|
||||
public Color selection_background;
|
||||
public Color trees_background;
|
||||
public Color bar_foreground;
|
||||
public Color bar_background;
|
||||
public Color table_background;
|
||||
//--
|
||||
protected abstract String getForegroundHex();
|
||||
protected abstract String getBackgroundHex();
|
||||
protected abstract String getSelectionBackgroundHex();
|
||||
protected abstract String getTreeBackgroundHex();
|
||||
protected abstract String getBarForegroundHex();
|
||||
protected abstract String getBarBackgroundHex();
|
||||
protected abstract String getTableBackgroundHex();
|
||||
protected abstract Color getGoodFontColor();
|
||||
protected abstract Color getReadyFontColor2();
|
||||
protected abstract Color getProgressFontColor();
|
||||
protected abstract Color getBadFontColor();
|
||||
protected abstract Color getFatalFontColor();
|
||||
protected abstract Color getUnknownFontColor();
|
||||
protected abstract Color getHyperlinkFontColor();
|
||||
//--
|
||||
public LinkedHashMap<VisualiserFonts, Font> Fonts = new LinkedHashMap<>();
|
||||
public LinkedHashMap<VisualiserColor, Color> Colors = new LinkedHashMap<>();
|
||||
protected void createFonts(){
|
||||
Fonts.put(VisualiserFonts.GoodState,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, "Times New Roman");
|
||||
put(TextAttribute.FOREGROUND, getGoodFontColor());
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.ReadyState,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, "Times New Roman");
|
||||
put(TextAttribute.FOREGROUND, getReadyFontColor2());
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.BadState,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, "Times New Roman");
|
||||
put(TextAttribute.FOREGROUND, getBadFontColor());
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.BlueState,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, "Times New Roman");
|
||||
put(TextAttribute.FOREGROUND, getHyperlinkFontColor());
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.Fatal,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, "Times New Roman");
|
||||
put(TextAttribute.FOREGROUND, getFatalFontColor());
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.UnknownState,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, "Times New Roman");
|
||||
put(TextAttribute.FOREGROUND, getUnknownFontColor());
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.Hyperlink,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, MONOSPACED);
|
||||
put(TextAttribute.FOREGROUND, getHyperlinkFontColor());
|
||||
put(TextAttribute.SIZE, 18);
|
||||
put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
|
||||
put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.ProgressState,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, "Times New Roman");
|
||||
put(TextAttribute.FOREGROUND, getProgressFontColor());
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.Disabled, new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, MONOSPACED);
|
||||
put(TextAttribute.BACKGROUND, Color.lightGray);
|
||||
put(TextAttribute.FOREGROUND, Color.lightGray);
|
||||
put(TextAttribute.SIZE, 18);
|
||||
put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
||||
}
|
||||
}
|
||||
));
|
||||
Fonts.put(VisualiserFonts.Distribution,
|
||||
new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, MONOSPACED);
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
Fonts.put(VisualiserFonts.TreePlain, new Font("Times New Roman", Font.PLAIN, 16));
|
||||
Fonts.put(VisualiserFonts.TreeItalic, new Font("Times New Roman", Font.ITALIC, 16));
|
||||
Fonts.put(VisualiserFonts.TreeBold, new Font("Times New Roman", Font.BOLD, 16));
|
||||
Fonts.put(VisualiserFonts.TreeBoldItalic, new Font("Times New Roman", Font.BOLD|Font.ITALIC, 16));
|
||||
Fonts.put(VisualiserFonts.Menu, new Font("Times New Roman", Font.ITALIC, 16));
|
||||
Fonts.put(VisualiserFonts.NewVersion, new Font(
|
||||
new HashMap<TextAttribute, Object>() {
|
||||
{
|
||||
put(TextAttribute.FAMILY, "Times New Roman");
|
||||
put(TextAttribute.FOREGROUND, Color.BLACK);
|
||||
put(TextAttribute.BACKGROUND, Color.YELLOW);
|
||||
put(TextAttribute.SIZE, 16);
|
||||
}
|
||||
}
|
||||
|
||||
));
|
||||
}
|
||||
public VisualiserTheme() {
|
||||
try {
|
||||
//-----------------------------------------------
|
||||
foreground = Color.decode(getForegroundHex());
|
||||
background = Color.decode(getBackgroundHex());
|
||||
selection_background = Color.decode(getSelectionBackgroundHex());
|
||||
trees_background = Color.decode(getTreeBackgroundHex());
|
||||
bar_foreground = Color.decode(getBarForegroundHex());
|
||||
bar_background = Color.decode(getBarBackgroundHex());
|
||||
table_background = Color.decode(getTableBackgroundHex());
|
||||
createFonts();
|
||||
} catch (Exception ex) {
|
||||
CommonUtils.MainLog.PrintException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
5
src/Common/Visual/VisualiserColor.java
Normal file
5
src/Common/Visual/VisualiserColor.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package Common.Visual;
|
||||
public enum VisualiserColor {
|
||||
ToolTip_background,
|
||||
ToolTip_foreground
|
||||
}
|
||||
24
src/Common/Visual/Windows/Dialog/DBObjectDialog.java
Normal file
24
src/Common/Visual/Windows/Dialog/DBObjectDialog.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import Common.Database.Objects.DBObject;
|
||||
public abstract class DBObjectDialog<T extends DBObject, F extends DialogFields> extends Dialog<T, F> {
|
||||
public boolean edit = false;
|
||||
public DBObjectDialog(Class<F> f) {
|
||||
super(f);
|
||||
}
|
||||
@Override
|
||||
public void Init(Object... params) {
|
||||
//тут входной параметр всегда объект. он же и есть Result
|
||||
//считаем что он всегда создан.
|
||||
Result = (T) params[0];
|
||||
fillFields();
|
||||
}
|
||||
public void SetEditLimits() {
|
||||
//установить ограничения если объект в режиме редактирования( например нельзя менять тип машины, или почту адресата)
|
||||
}
|
||||
public void fillFields() {
|
||||
//отобразить объект
|
||||
}
|
||||
public void SetReadonly(){
|
||||
//заблокировать окно для редактирования
|
||||
}
|
||||
}
|
||||
156
src/Common/Visual/Windows/Dialog/Dialog.java
Normal file
156
src/Common/Visual/Windows/Dialog/Dialog.java
Normal file
@@ -0,0 +1,156 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.CommonUI;
|
||||
import Common.Visual.Themes.ThemeElement;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
import Common.Utils.TextLog;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
//T Тип объекта
|
||||
//F Тип полей.
|
||||
public class Dialog<T, F extends DialogFields> extends JDialog implements ThemeElement {
|
||||
public F fields; //рабочая область диалога.
|
||||
public String title_text;
|
||||
public JLabel lTitle = new JLabel();
|
||||
public boolean OK = false;
|
||||
//--------------------------------------
|
||||
public T Result = null;
|
||||
public Class<F> f = null;
|
||||
public TextLog Log = new TextLog(); //журнал валидации.
|
||||
protected JScrollPane scroll = null;
|
||||
protected JPanel buttonsPane = null;
|
||||
protected JButton btnOK = null;
|
||||
protected JButton btnCancel = null;
|
||||
protected JCheckBox showNoMore = null;
|
||||
public String getIconPath() {
|
||||
return "";
|
||||
}
|
||||
protected Component content;
|
||||
//--------------------------------------
|
||||
public Dialog(Class<F> f_in) {
|
||||
f = f_in;
|
||||
setModal(true);
|
||||
toFront();
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
lTitle.setFont(CommonUI.getTheme().Fonts.get(VisualiserFonts.Menu));
|
||||
if (!getIconPath().isEmpty()) {
|
||||
setIconImage(CommonUtils.getIcon(getIconPath()).getImage());
|
||||
}
|
||||
//делаем титульную надпись в самом окне чтобы не зависеть от языковой политики ОС
|
||||
getContentPane().add(lTitle, BorderLayout.NORTH);
|
||||
//сюда добавляется содержимое.
|
||||
content = null;
|
||||
CreateContent();
|
||||
InitFields(); //дополнительная инициализация полей..
|
||||
getContentPane().add(NeedsScroll() ? (scroll = new JScrollPane(content)) : content, BorderLayout.CENTER);
|
||||
CreateButtons();
|
||||
// call onCancel() when cross is clicked
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
CommonUI.windowsStack.pop();
|
||||
onCancel();
|
||||
onClose();
|
||||
}
|
||||
});
|
||||
// pack(); //авторазмер окна.
|
||||
setLocationRelativeTo(null);
|
||||
LoadSize();
|
||||
}
|
||||
public void CreateContent() {
|
||||
try {
|
||||
content = (fields = f.newInstance()).getContent();
|
||||
//--?
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
}
|
||||
public void onClose() {
|
||||
|
||||
}
|
||||
public void LoadSize() {
|
||||
setMinimumSize(new Dimension(getDefaultWidth(), getDefaultHeight()));
|
||||
setPreferredSize(new Dimension(getDefaultWidth(), getDefaultHeight()));
|
||||
}
|
||||
//бывает что у полей собственные скроллы
|
||||
public boolean NeedsScroll() {
|
||||
return true;
|
||||
}
|
||||
public boolean NeedsShowNoMore() {
|
||||
return false;
|
||||
}
|
||||
public int getDefaultWidth() {
|
||||
return 800;
|
||||
}
|
||||
public int getDefaultHeight() {
|
||||
return 450;
|
||||
}
|
||||
//создание полей формы( без заполнения)
|
||||
public void InitFields() {
|
||||
}
|
||||
public void CreateButtons() {
|
||||
btnOK = new JButton(" OK ");
|
||||
btnCancel = new JButton("Отмена");
|
||||
buttonsPane = new JPanel();
|
||||
buttonsPane.setOpaque(true);
|
||||
buttonsPane.setBackground(Color.WHITE);
|
||||
btnOK.addActionListener(e -> onOK());
|
||||
btnCancel.addActionListener(e -> onCancel());
|
||||
buttonsPane.add(btnOK);
|
||||
buttonsPane.add(btnCancel);
|
||||
if (NeedsShowNoMore()) {
|
||||
buttonsPane.add(showNoMore = new JCheckBox("больше не показывать"));
|
||||
showNoMore.setOpaque(true);
|
||||
showNoMore.setBackground(Color.WHITE);
|
||||
}
|
||||
getContentPane().add(buttonsPane, BorderLayout.SOUTH);
|
||||
}
|
||||
public boolean isOnTop() {
|
||||
return true;
|
||||
}
|
||||
public boolean ShowDialog(String title, Object... params) {
|
||||
OK = false;
|
||||
title_text = title;
|
||||
Init(params);
|
||||
ShowTitle();
|
||||
setAlwaysOnTop(isOnTop());
|
||||
CommonUI.windowsStack.push(this);
|
||||
setVisible(true);
|
||||
return OK;
|
||||
}
|
||||
public void ShowTitle() {
|
||||
lTitle.setText(getTitleText());
|
||||
}
|
||||
public String getTitleText() {
|
||||
return title_text;
|
||||
}
|
||||
public void Init(Object... params) {
|
||||
}
|
||||
public void onOK() {
|
||||
Log.Clear();
|
||||
validateFields();
|
||||
if (Log.isEmpty()) {
|
||||
ProcessResult();
|
||||
OK = true;
|
||||
CloseAction();
|
||||
} else
|
||||
CommonUI.Error("Валидация не пройдена:\n" + Log.toString());
|
||||
}
|
||||
protected void onCancel() {
|
||||
CloseAction();
|
||||
}
|
||||
public void CloseAction() {
|
||||
dispose();
|
||||
}
|
||||
public void validateFields() {
|
||||
}
|
||||
public void ProcessResult() {
|
||||
}
|
||||
@Override
|
||||
public void applyTheme() {
|
||||
//todo -> Применение темы
|
||||
}
|
||||
}
|
||||
5
src/Common/Visual/Windows/Dialog/DialogFields.java
Normal file
5
src/Common/Visual/Windows/Dialog/DialogFields.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import java.awt.*;
|
||||
public interface DialogFields {
|
||||
Component getContent();
|
||||
}
|
||||
9
src/Common/Visual/Windows/Dialog/DialogSlider.java
Normal file
9
src/Common/Visual/Windows/Dialog/DialogSlider.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class DialogSlider extends JSlider implements DialogFields {
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
9
src/Common/Visual/Windows/Dialog/DialogSpinner.java
Normal file
9
src/Common/Visual/Windows/Dialog/DialogSpinner.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class DialogSpinner extends JSpinner implements DialogFields {
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
16
src/Common/Visual/Windows/Dialog/DialogTextComboBox.java
Normal file
16
src/Common/Visual/Windows/Dialog/DialogTextComboBox.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import Common.Visual.CommonUI;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class DialogTextComboBox extends JComboBox<String> implements DialogFields {
|
||||
public DialogTextComboBox() {
|
||||
setFont(CommonUI.getTheme().Fonts.get(VisualiserFonts.Menu));
|
||||
setEditable(false);
|
||||
}
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
10
src/Common/Visual/Windows/Dialog/DialogTextField.java
Normal file
10
src/Common/Visual/Windows/Dialog/DialogTextField.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import Common_old.UI.TextField.StyledTextField;
|
||||
|
||||
import java.awt.*;
|
||||
public class DialogTextField extends StyledTextField implements DialogFields {
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
42
src/Common/Visual/Windows/Dialog/DialogWrapText.java
Normal file
42
src/Common/Visual/Windows/Dialog/DialogWrapText.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import Common.Visual.CommonUI;
|
||||
import Common.Visual.Fonts.VisualiserFonts;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
public class DialogWrapText extends JTextPane implements DialogFields {
|
||||
public DialogWrapText(){
|
||||
setOpaque(true);
|
||||
setBackground(Color.WHITE);
|
||||
setFont(CommonUI.getTheme().Fonts.get(VisualiserFonts.TreeBold));
|
||||
setEditable(false);
|
||||
}
|
||||
@Override
|
||||
public Component getContent() {
|
||||
return this;
|
||||
}
|
||||
/*
|
||||
public void setTextW(String text_in){
|
||||
String[] lines = text_in.split("\n");
|
||||
String labelText = "";
|
||||
if (lines.length == 1) {
|
||||
labelText = text_in;
|
||||
} else {
|
||||
int i = 0;
|
||||
for (String line : lines) {
|
||||
String fline = "";
|
||||
if (i == 0) {
|
||||
fline = "<html><body>" + line + "<br>";
|
||||
} else if (i == lines.length - 1) {
|
||||
fline = line + "</body></html>";
|
||||
} else {
|
||||
fline = line + "<br>";
|
||||
}
|
||||
++i;
|
||||
labelText += fline;
|
||||
}
|
||||
}
|
||||
setText(labelText);
|
||||
}
|
||||
*/
|
||||
}
|
||||
11
src/Common/Visual/Windows/Dialog/NumberDialog.java
Normal file
11
src/Common/Visual/Windows/Dialog/NumberDialog.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
public abstract class NumberDialog<F extends DialogFields> extends Dialog<Integer, F> {
|
||||
public NumberDialog(Class<F> f) {
|
||||
super(f);
|
||||
}
|
||||
@Override
|
||||
public void Init(Object... params) {
|
||||
if (params.length > 0) setNumber((int) params[0]);
|
||||
}
|
||||
public abstract void setNumber(int num_in);
|
||||
}
|
||||
22
src/Common/Visual/Windows/Dialog/PercentsForm.java
Normal file
22
src/Common/Visual/Windows/Dialog/PercentsForm.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
public class PercentsForm extends SliderNumberForm {
|
||||
public PercentsForm() {
|
||||
}
|
||||
@Override
|
||||
public String getTitleText() {
|
||||
return super.getTitleText() + "%";
|
||||
}
|
||||
@Override
|
||||
public void InitFields() {
|
||||
fields.setPaintLabels(true);
|
||||
fields.setPaintTicks(true);
|
||||
fields.setPaintTrack(true);
|
||||
fields.setSnapToTicks(true);
|
||||
fields.setMinorTickSpacing(1);
|
||||
fields.setMajorTickSpacing(25);
|
||||
}
|
||||
@Override
|
||||
public void Init(Object... params) {
|
||||
super.Init(params[0], 0, 100);
|
||||
}
|
||||
}
|
||||
10
src/Common/Visual/Windows/Dialog/SessionMaxtimeDialog.java
Normal file
10
src/Common/Visual/Windows/Dialog/SessionMaxtimeDialog.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import javax.swing.*;
|
||||
public class SessionMaxtimeDialog extends SpinnerNumberForm {
|
||||
public SessionMaxtimeDialog() {
|
||||
}
|
||||
@Override
|
||||
public void InitFields() {
|
||||
fields.setModel(new SpinnerNumberModel(10, 5, 65535, 1));
|
||||
}
|
||||
}
|
||||
53
src/Common/Visual/Windows/Dialog/SliderNumberForm.java
Normal file
53
src/Common/Visual/Windows/Dialog/SliderNumberForm.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
public class SliderNumberForm extends NumberDialog<DialogSlider> {
|
||||
public SliderNumberForm() {
|
||||
super(DialogSlider.class);
|
||||
setResizable(false);
|
||||
}
|
||||
@Override
|
||||
public void setNumber(int num_in) {
|
||||
fields.setValue(num_in);
|
||||
}
|
||||
//тут всегда должно быть три параметра
|
||||
//минимум нет смысла задавать меньше 1
|
||||
@Override
|
||||
public void Init(Object... params) {
|
||||
if (params.length == 3) {
|
||||
setNumber((Integer) params[0]);
|
||||
fields.setMinimum((Integer) params[1]);
|
||||
fields.setMaximum((Integer) params[2]);
|
||||
}
|
||||
fields.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
ShowTitle();
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void InitFields() {
|
||||
fields.setPaintLabels(true);
|
||||
fields.setPaintTicks(true);
|
||||
fields.setPaintTrack(true);
|
||||
fields.setSnapToTicks(false);
|
||||
fields.setMinorTickSpacing(1);
|
||||
fields.setMajorTickSpacing(1);
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 600;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 200;
|
||||
}
|
||||
@Override
|
||||
public String getTitleText() {
|
||||
return title_text + " : " + fields.getValue();
|
||||
}
|
||||
@Override
|
||||
public void ProcessResult() {
|
||||
Result = fields.getValue();
|
||||
}
|
||||
}
|
||||
22
src/Common/Visual/Windows/Dialog/SpinnerNumberForm.java
Normal file
22
src/Common/Visual/Windows/Dialog/SpinnerNumberForm.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package Common.Visual.Windows.Dialog;
|
||||
public abstract class SpinnerNumberForm extends NumberDialog<DialogSpinner> {
|
||||
public SpinnerNumberForm() {
|
||||
super(DialogSpinner.class);
|
||||
}
|
||||
@Override
|
||||
public void setNumber(int num_in) {
|
||||
fields.setValue(num_in);
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 400;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 130;
|
||||
}
|
||||
@Override
|
||||
public void ProcessResult() {
|
||||
Result = (Integer) fields.getValue();
|
||||
}
|
||||
}
|
||||
35
src/Common/Visual/Windows/Dialog/Text/ComboTextDialog.java
Normal file
35
src/Common/Visual/Windows/Dialog/Text/ComboTextDialog.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package Common.Visual.Windows.Dialog.Text;
|
||||
import Common.Visual.Windows.Dialog.Dialog;
|
||||
import Common.Visual.Windows.Dialog.DialogTextComboBox;
|
||||
|
||||
import java.util.Vector;
|
||||
public class ComboTextDialog extends Dialog<String, DialogTextComboBox> {
|
||||
public ComboTextDialog() {
|
||||
super(DialogTextComboBox.class);
|
||||
}
|
||||
@Override
|
||||
public void ProcessResult() {
|
||||
Result = (String) fields.getSelectedItem();
|
||||
}
|
||||
@Override
|
||||
public void validateFields() {
|
||||
if (fields.getSelectedItem() == null)
|
||||
Log.Writeln("Элемент не выбран");
|
||||
}
|
||||
@Override
|
||||
public void Init(Object... params) {
|
||||
Vector<String> sp = (Vector<String>) params[0];
|
||||
if (!sp.isEmpty()) {
|
||||
for (Object p : sp)
|
||||
fields.addItem(p.toString());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 450;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 135;
|
||||
}
|
||||
}
|
||||
10
src/Common/Visual/Windows/Dialog/Text/FileNameForm.java
Normal file
10
src/Common/Visual/Windows/Dialog/Text/FileNameForm.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package Common.Visual.Windows.Dialog.Text;
|
||||
import Common_old.Utils.Utils;
|
||||
public class FileNameForm extends TextFieldDialog {
|
||||
public FileNameForm() {
|
||||
}
|
||||
@Override
|
||||
public void validateFields() {
|
||||
Utils.validateFileShortNewName(fields.getText(), Log);
|
||||
}
|
||||
}
|
||||
25
src/Common/Visual/Windows/Dialog/Text/MultilineTextForm.java
Normal file
25
src/Common/Visual/Windows/Dialog/Text/MultilineTextForm.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package Common.Visual.Windows.Dialog.Text;
|
||||
import Common_old.UI.Editor.BaseEditor;
|
||||
public class MultilineTextForm extends TextDialog<BaseEditor> {
|
||||
public MultilineTextForm() {
|
||||
super(BaseEditor.class);
|
||||
}
|
||||
//при наследовании по умолчанию поля не присваивать!
|
||||
//инициализация полей работает после конструктора предка!!
|
||||
@Override
|
||||
public void ProcessResult() {
|
||||
Result = fields.getText();
|
||||
}
|
||||
@Override
|
||||
public void InitFields() {
|
||||
fields.setSearchEnabled(false);
|
||||
fields.setLineWrap(true);
|
||||
fields.setWrapStyleWord(true);
|
||||
fields.setHighlightCurrentLine(false);
|
||||
}
|
||||
@Override
|
||||
public void setText(String text_in) {
|
||||
fields.setText(text_in);
|
||||
fields.setCaretPosition(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package Common.Visual.Windows.Dialog.Text;
|
||||
public class ReadOnlyMultilineTextForm extends MultilineTextForm {
|
||||
public ReadOnlyMultilineTextForm() {
|
||||
}
|
||||
@Override
|
||||
public void InitFields() {
|
||||
fields.setEditable(false);
|
||||
}
|
||||
@Override
|
||||
public void CreateButtons() {
|
||||
}
|
||||
}
|
||||
15
src/Common/Visual/Windows/Dialog/Text/TextDialog.java
Normal file
15
src/Common/Visual/Windows/Dialog/Text/TextDialog.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package Common.Visual.Windows.Dialog.Text;
|
||||
import Common.Visual.Windows.Dialog.Dialog;
|
||||
import Common.Visual.Windows.Dialog.DialogFields;
|
||||
//текстовый диалог. возвращает текст. может иметь параметром исходный текст.
|
||||
public abstract class TextDialog<F extends DialogFields> extends Dialog<String, F> {
|
||||
public TextDialog(Class<F> f) {
|
||||
super(f);
|
||||
}
|
||||
@Override
|
||||
public void Init(Object... params) {
|
||||
if (params.length > 0) setText((String) params[0]);
|
||||
}
|
||||
public abstract void setText(String text_in);
|
||||
}
|
||||
|
||||
35
src/Common/Visual/Windows/Dialog/Text/TextFieldDialog.java
Normal file
35
src/Common/Visual/Windows/Dialog/Text/TextFieldDialog.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package Common.Visual.Windows.Dialog.Text;
|
||||
import Common.Visual.Windows.Dialog.DialogTextField;
|
||||
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
public class TextFieldDialog extends TextDialog<DialogTextField> {
|
||||
public TextFieldDialog() {
|
||||
super(DialogTextField.class);
|
||||
setResizable(false);
|
||||
fields.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
onOK();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 450;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 135;
|
||||
}
|
||||
@Override
|
||||
public void ProcessResult() {
|
||||
Result = fields.getText();
|
||||
}
|
||||
@Override
|
||||
public void setText(String text_in) {
|
||||
fields.setText(text_in);
|
||||
}
|
||||
}
|
||||
97
src/Common/Visual/Windows/Form.java
Normal file
97
src/Common/Visual/Windows/Form.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package Common.Visual.Windows;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.Themes.ThemeElement;
|
||||
import Common.Database.Objects.DBForm.DBForm;
|
||||
|
||||
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 Form() {
|
||||
if (getIconPath()!=null) setIconImage(CommonUtils.getIcon(getIconPath()).getImage());
|
||||
SetListener();
|
||||
this.setTitle(CommonUtils.isWindows() ? getWTitleText() : getUTitleText());
|
||||
pack();
|
||||
setMinimumSize(new Dimension(getDefaultWidth(), getDefaultHeight()));
|
||||
}
|
||||
abstract protected JPanel getMainPanel();
|
||||
public String getIconPath() {
|
||||
return null;
|
||||
}
|
||||
public String getWTitleText() {
|
||||
return "";
|
||||
}
|
||||
public String getUTitleText() {
|
||||
return "";
|
||||
}
|
||||
protected String getFormKey() {
|
||||
return null;
|
||||
}
|
||||
protected void SetListener() {
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
Close();
|
||||
}
|
||||
});
|
||||
}
|
||||
public int getDefaultWidth() {
|
||||
return 800;
|
||||
}
|
||||
public int getDefaultHeight() {
|
||||
return 450;
|
||||
}
|
||||
/*
|
||||
*вызывать после перегрузки, чтобы отобразить окно.
|
||||
*/
|
||||
public Component getRelative() {
|
||||
return null;
|
||||
}
|
||||
public void Show() {
|
||||
try {
|
||||
LoadWindowParameters();
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
setContentPane(getMainPanel());
|
||||
setVisible(true);
|
||||
}
|
||||
public void Close() {
|
||||
try {
|
||||
SaveWindowParameters();
|
||||
} catch (Exception e) {
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
setVisible(false);
|
||||
dispose();
|
||||
AfterClose();
|
||||
}
|
||||
public void AfterClose() {
|
||||
}
|
||||
public void LoadWindowParameters() throws Exception {
|
||||
if (getFormKey()!=null)
|
||||
if (CommonUtils.db.forms.Data.containsKey(getFormKey())) {
|
||||
dbInfo = CommonUtils.db.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);
|
||||
CommonUtils.db.Update(dbInfo);
|
||||
} else
|
||||
CommonUtils.db.Insert(new DBForm(getFormKey(), this));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void applyTheme() {
|
||||
//todo -> применение темы.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user