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 javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.text.SimpleDateFormat;
import java.nio.charset.Charset;
import static x30_pkg.x30_util.DynamicObject;
import java.awt.geom.*;
class main {
static JButton setButtonImage(Icon img, JButton btn) {
btn.setIcon(img);
return btn;
}
static JButton setButtonImage(Image img, JButton btn) {
btn.setIcon(imageIcon(img));
return btn;
}
static A setButtonImage(Image img, A btn) {
btn.setIcon(imageIcon(img));
return btn;
}
static A setButtonImage(A btn, Image img) {
return setButtonImage(img, btn);
}
static A setButtonImage(A btn, String imageID) {
btn.setIcon(imageIcon(imageID));
return btn;
}
static JButton setButtonImage(JButton btn, Image img) {
return setButtonImage(img, btn);
}
static JButton setButtonImage(JButton btn, Icon img) {
return setButtonImage(img, btn);
}
static int imageIcon_cacheSize = 10;
static boolean imageIcon_verbose = false;
static Map imageIcon_cache;
static Lock imageIcon_lock = lock();
static ThreadLocal imageIcon_fixGIF = new ThreadLocal();
// not going through BufferedImage preserves animations
static ImageIcon imageIcon(String imageID) { try {
if (imageID == null) return null;
Lock __0 = imageIcon_lock; lock(__0); try {
if (imageIcon_cache == null)
imageIcon_cache = new MRUCache(imageIcon_cacheSize);
imageID = fsI(imageID);
ImageIcon ii = imageIcon_cache.get(imageID);
if (ii == null) {
if (imageIcon_verbose) print("Loading image icon: " + imageID);
File f = loadBinarySnippet(imageID);
Boolean b = imageIcon_fixGIF.get();
if (!isFalse(b))
ii = new ImageIcon(loadBufferedImageFixingGIFs(f));
else
ii = new ImageIcon(f.toURI().toURL());
} else
imageIcon_cache.remove(imageID); // move to front of cache on access
imageIcon_cache.put(imageID, ii);
return ii;
} finally { unlock(__0); } } catch (Exception __e) { throw rethrow(__e); } }
// doesn't fix GIFs
static ImageIcon imageIcon(File f) { try {
return new ImageIcon(f.toURI().toURL());
} catch (Exception __e) { throw rethrow(__e); } }
static ImageIcon imageIcon(Image img) {
return img == null ? null : new ImageIcon(img);
}
static void lock(Lock lock) { try {
ping();
if (lock == null) return;
try {
vmBus_send("locking", lock, "thread" , currentThread());
lock.lockInterruptibly();
vmBus_send("locked", lock, "thread" , currentThread());
} catch (InterruptedException e) {
Object reason = vm_threadInterruptionReasonsMap().get(currentThread());
print("Locking interrupted! Reason: " + strOr(reason, "Unknown"));
printStackTrace(e);
rethrow(e);
}
// NO call to ping here! Make sure lock is always released.
} catch (Exception __e) { throw rethrow(__e); } }
static void lock(Lock lock, String msg) {
print("Locking: " + msg);
lock(lock);
}
static void lock(Lock lock, String msg, long timeout) {
print("Locking: " + msg);
lockOrFail(lock, timeout);
}
static ReentrantLock lock() {
return fairLock();
}
static String fsI(String id) {
return formatSnippetID(id);
}
static String fsI(long id) {
return formatSnippetID(id);
}
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