import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import java.time.Duration;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;
import javax.swing.Timer;
import static x30_pkg.x30_util.DynamicObject;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
import java.awt.geom.*;
class main {
static JLabel jLabelShortCalcedEvery(IF0 calc, double interval) {
JLabel label = jSimpleLabel();
if (calc != null) awtEveryAndNow(label, interval, () -> {
try {
Object o = calc.get();
String toolTip, text;
if (o instanceof WithToolTip) {
toolTip = ((WithToolTip) o).toolTip();
text = str(((WithToolTip) o).get());
} else {
text = toolTip = str(o);
}
setToolTip(label, toolTip);
label.setText(text);
} catch (Throwable __e) { printStackTrace(__e); }
});
return label;
}
static JLabel jLabelShortCalcedEvery(double interval, IF0 calc) {
return jLabelShortCalcedEvery(calc, interval);
}
static JLabel jSimpleLabel() { return jSimpleLabel(""); }
static JLabel jSimpleLabel(String text) {
return swing(() -> new JLabel(text));
}
static A awtEveryAndNow(A component, long delay, Object r) {
swingEvery(component, delay, 0, r);
return component;
}
static A awtEveryAndNow(A component, long delay, Runnable r) {
return awtEveryAndNow(component, delay, (Object) r);
}
static A awtEveryAndNow(A component, double delaySeconds, Object r) {
return awtEveryAndNow(component, toMS(delaySeconds), r);
}
static A awtEveryAndNow(A component, double delaySeconds, Runnable r) {
return awtEveryAndNow(component, toMS(delaySeconds), r);
}
static void awtEveryAndNow(RootPaneContainer frame, long delay, Object r) {
swingEvery(frame, delay, 0, r);
}
static String str(Object o) {
return o == null ? "null" : o.toString();
}
static String str(char[] c) {
return new String(c);
}
static String str(char[] c, int offset, int count) {
return new String(c, offset, count);
}
static A setToolTip(A c, Object toolTip) {
return setToolTipText(c, toolTip);
}
static A setToolTip(Object toolTip, A c) {
return setToolTipText(c, toolTip);
}
static void setToolTip(TrayIcon trayIcon, String toolTip) {
setTrayIconToolTip(trayIcon, toolTip);
}
static A printStackTrace(A e) {
// we go to system.out now - system.err is nonsense
if (e != null) print(getStackTrace(e));
return e;
}
static void printStackTrace() {
printStackTrace(new Throwable());
}
static void printStackTrace(String msg) {
printStackTrace(new Throwable(msg));
}
static void printStackTrace(String msg, Throwable e) {
printStackTrace(new Throwable(msg, e));
}
static Object swing(Object f) {
return swingAndWait(f);
}
static void swing(Runnable f) {
swingAndWait(f);
}
static A swing(F0 f) {
return (A) swingAndWait(f);
}
static A swing(IF0 f) {
return (A) swingAndWait(f);
}
static void swingEvery(JComponent component, long delay, Object r) {
installTimer(component, delay, r);
}
static void swingEvery(JComponent component, long delay, long firstDelay, Object r) {
installTimer(component, r, delay, firstDelay);
}
static void swingEvery(RootPaneContainer frame, long delay, Object r) {
installTimer(frame, delay, r);
}
static void swingEvery(RootPaneContainer frame, long delay, long firstDelay, Object r) {
installTimer(frame, delay, firstDelay, r);
}
static long toMS(double seconds) {
return (long) (seconds*1000);
}
static A setToolTipText(final A c, final Object toolTip) {
if (c == null) return null;
{ swing(() -> {
String s = str_nullIfEmpty(toolTip);
if (neq(s, c.getToolTipText()))
c.setToolTipText(s);
}); }
return c;
}
static A setToolTipText(Object toolTip, A c) {
return setToolTipText(c, toolTip);
}
static void setTrayIconToolTip(TrayIcon trayIcon, String toolTip) {
if (trayIcon != null) trayIcon.setToolTip(toolTip);
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static boolean printAlsoToSystemOut = true;
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal