2024-10-07 00:58:29 +03:00
|
|
|
|
package Common.Visual;
|
2024-10-14 21:55:58 +03:00
|
|
|
|
import Common.MainModule_;
|
2024-10-11 00:00:30 +03:00
|
|
|
|
import Common.Utils.Utils_;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
|
2024-10-07 17:46:38 +03:00
|
|
|
|
import javax.swing.*;
|
2024-10-08 22:33:49 +03:00
|
|
|
|
import javax.swing.event.ChangeListener;
|
|
|
|
|
|
import javax.swing.text.DefaultFormatter;
|
2024-10-07 17:46:38 +03:00
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
import java.util.Stack;
|
2024-10-11 00:00:30 +03:00
|
|
|
|
public class UI_ {
|
2024-10-14 15:19:13 +03:00
|
|
|
|
public static boolean active = false; //есть ли интерфейс. в консольных версиях не нужен.
|
2024-10-08 22:33:49 +03:00
|
|
|
|
//---
|
2024-10-14 15:19:13 +03:00
|
|
|
|
public static boolean isActive() {
|
|
|
|
|
|
return active;
|
|
|
|
|
|
}
|
2024-10-07 17:46:38 +03:00
|
|
|
|
//-----
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-08 22:33:49 +03:00
|
|
|
|
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) {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
return !UI_.isActive() || (JOptionPane.showConfirmDialog(parent,
|
2024-10-08 22:33:49 +03:00
|
|
|
|
text + "?",
|
|
|
|
|
|
"Подтверждение",
|
|
|
|
|
|
JOptionPane.YES_NO_OPTION,
|
|
|
|
|
|
JOptionPane.QUESTION_MESSAGE) == 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static boolean Question(String text) {
|
2024-10-14 21:55:58 +03:00
|
|
|
|
return Question(MainModule_.instance.getUI().getFrontWindow(), text);
|
2024-10-08 22:33:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
public static void Info(String message) {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.CopyToClipboard(message);
|
|
|
|
|
|
if (UI_.isActive())
|
2024-10-14 21:55:58 +03:00
|
|
|
|
JOptionPane.showMessageDialog(MainModule_.instance.getUI().getFrontWindow(), message, "", 1);
|
2024-10-08 22:33:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
public static void Error(String message) {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.CopyToClipboard(message);
|
|
|
|
|
|
if (UI_.isActive())
|
2024-10-14 21:55:58 +03:00
|
|
|
|
JOptionPane.showMessageDialog(MainModule_.instance.getUI().getFrontWindow(), message, "", 0);
|
2024-10-08 22:33:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
public static boolean Warning(String text) {
|
2024-10-11 00:00:30 +03:00
|
|
|
|
return !UI_.isActive() ||
|
2024-10-14 21:55:58 +03:00
|
|
|
|
JOptionPane.showConfirmDialog(MainModule_.instance.getUI().getFrontWindow(),
|
2024-10-08 22:33:49 +03:00
|
|
|
|
text + "\nВы уверены?",
|
|
|
|
|
|
"Подтверждение",
|
|
|
|
|
|
JOptionPane.YES_NO_OPTION,
|
|
|
|
|
|
JOptionPane.WARNING_MESSAGE) == 0;
|
|
|
|
|
|
}
|
2024-10-15 12:45:13 +03:00
|
|
|
|
//-----
|
|
|
|
|
|
public static void ShowTabsNames(JTabbedPane tabs, boolean flag) {
|
|
|
|
|
|
ShowTabsNames(tabs, 0, flag);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void ShowTabsNames(JTabbedPane tabs, int startIndex, boolean flag) {
|
|
|
|
|
|
for (int i = startIndex; i < tabs.getTabCount(); ++i)
|
|
|
|
|
|
tabs.setTitleAt(i, flag ? tabs.getToolTipTextAt(i) : "");
|
|
|
|
|
|
}
|
2024-10-08 22:33:49 +03:00
|
|
|
|
//--
|
2024-10-07 00:58:29 +03:00
|
|
|
|
}
|