no message

This commit is contained in:
2024-10-11 00:00:30 +03:00
parent a11b7711f7
commit f317ab1aa1
341 changed files with 1866 additions and 1688 deletions

106
src/Common/Visual/UI_.java Normal file
View File

@@ -0,0 +1,106 @@
package Common.Visual;
import Common.Database.Tables.DataSet;
import Common.Utils.Utils_;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Themes.DefaultTheme;
import Common.Visual.Themes.VisualiserTheme;
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 UI_ {
public static boolean active=false; //есть ли интерфейс. в консольных версиях не нужен.
public static MenuElement[] last_menu_path; //для меню
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();
container.repaint();
container.revalidate();
}
// http://java-online.ru/swing-joptionpane.xhtml
public static <T> void TrySelect(JComboBox box, T value_in) {
if (value_in != null) {
for (int i = 0; i < box.getItemCount(); ++i) {
T value = (T) box.getItemAt(i);
if (value.equals(value_in)) {
box.setSelectedIndex(i);
return;
}
}
box.addItem(value_in);
box.setSelectedIndex(box.getItemCount() - 1);
}
}
public static void TrySelect_s(JComboBox box, String value_string_in) {
for (int i = 0; i < box.getItemCount(); ++i) {
Object value = box.getItemAt(i);
if (value.toString().equals(value_string_in)) {
box.setSelectedIndex(i);
return;
}
}
}
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 !UI_.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) {
Utils_.CopyToClipboard(message);
if (UI_.isActive())
JOptionPane.showMessageDialog(getFrontWindow(), message, "", 1);
}
public static void Error(String message) {
Utils_.CopyToClipboard(message);
if (UI_.isActive())
JOptionPane.showMessageDialog(getFrontWindow(), message, "", 0);
}
public static boolean Warning(String text) {
return !UI_.isActive() ||
JOptionPane.showConfirmDialog(getFrontWindow(),
text + "\nВы уверены?",
"Подтверждение",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE) == 0;
}
//--
}