Warning : session_start(): open(/var/lib/php/sessions/sess_ffpspj7pgg8l9lcm3un4rp7j3g, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning : session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
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 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 javax.imageio.*;
import java.math.*;
import x30_pkg.x30_util;
import static x30_pkg.x30_util.VF1;
import static x30_pkg.x30_util.l;
import static x30_pkg.x30_util.fail;
import static x30_pkg.x30_util.indexOf;
import static x30_pkg.x30_util.getOpt;
import static x30_pkg.x30_util.setOpt;
import static x30_pkg.x30_util.callOpt;
import static x30_pkg.x30_util.newWeakHashMap;
import static x30_pkg.x30_util.newDangerousWeakHashMap;
import static x30_pkg.x30_util.get;
import static x30_pkg.x30_util.get_raw;
import static x30_pkg.x30_util.assertTrue;
import static x30_pkg.x30_util.isHeadless;
import static x30_pkg.x30_util.isAndroid;
import static x30_pkg.x30_util.isTrue;
import static x30_pkg.x30_util.asList;
import x30_pkg.x30_util.DynamicObject;
import loadableUtils.utils;
import static loadableUtils.utils._threadInfo;
import static loadableUtils.utils._threadInheritInfo;
import static loadableUtils.utils._threadInfo_addMakerAndRetriever;
import static loadableUtils.utils.dm_currentModule;
import static loadableUtils.utils.dm_current_mandatory;
import static loadableUtils.utils.match;
import static loadableUtils.utils.getOpt_raw;
import static loadableUtils.utils.setOpt_raw;
import static loadableUtils.utils.getField;
import static loadableUtils.utils.fieldType;
import static loadableUtils.utils.format3;
import static loadableUtils.utils.vm_generalIdentityHashSet;
import static loadableUtils.utils.vm_generalHashMap;
import static loadableUtils.utils.vm_generalWeakSubMap;
import static loadableUtils.utils.bindToComponent;
import static loadableUtils.utils.struct;
import static loadableUtils.utils.structure;
import static loadableUtils.utils.loadPage;
import static loadableUtils.utils.loadPage_utf8;
import static loadableUtils.utils.loadPageSilentlyWithTimeout;
import static loadableUtils.utils.loadPageSilently;
import static loadableUtils.utils.loadSnippet;
import static loadableUtils.utils.loadSnippetQuietly;
import static loadableUtils.utils.sendToLocalBot;
import static loadableUtils.utils.componentPopupMenu;
import static loadableUtils.utils.componentPopupMenu_top;
import static loadableUtils.utils.componentPopupMenu_initForComponent;
import static loadableUtils.utils.componentPopupMenu_getEvent;
import static loadableUtils.utils.listPopupMenu;
import static loadableUtils.utils.tablePopupMenu;
import static loadableUtils.utils.rowSorter_setComparators;
import static loadableUtils.utils.sexyTableWithoutDrag;
import static loadableUtils.utils.dm_current_generic;
import static loadableUtils.utils.dm_current_mandatory_generic;
import static loadableUtils.utils.cset;
import static loadableUtils.utils.DynamicObject_loading;
import static loadableUtils.utils.concepts_unlisted;
import static loadableUtils.utils.makePopupMenuConditional;
import static loadableUtils.utils.makeConceptsTable_idWidth;
import static loadableUtils.utils.showConceptsTable_afterUpdate;
import static loadableUtils.utils.dynamicObjectIsLoading;
import loadableUtils.utils.F0;
import loadableUtils.utils.F1;
import loadableUtils.utils.IF1;
import loadableUtils.utils.Matches;
import loadableUtils.utils.BetterLabel;
import loadableUtils.utils.SingleComponentPanel;
import loadableUtils.utils.Snippet;
import loadableUtils.utils.Q;
import loadableUtils.utils.ImageSurface;
import loadableUtils.utils.structure_Data;
import loadableUtils.utils.structure_ClassInfo;
import loadableUtils.utils.RGBImage;
import loadableUtils.utils.RGB;
import loadableUtils.utils.BWImage;
import loadableUtils.utils.MakesBufferedImage;
import loadableUtils.utils.MultiSet;
import loadableUtils.utils.Concept;
import loadableUtils.utils.Concepts;
import loadableUtils.utils.IConceptIndex;
import loadableUtils.utils.IFieldIndex;
import loadableUtils.utils.Derefable;
import loadableUtils.utils.ImageSurfaceSelector;
import loadableUtils.utils.SimpleCRUD;
import loadableUtils.utils.PersistableThrowable;
import loadableUtils.utils.DynModule;
import loadableUtils.utils.DynPrintLog;
import loadableUtils.utils.DynObjectTable;
import loadableUtils.utils.DynImageSurface;
import loadableUtils.utils.DynCalculatedList;
import loadableUtils.utils.Rect;
import loadableUtils.utils.Pt;
import net.dv8tion.jda.core.events.guild.member.*;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.requests.restaction.MessageAction;
import java.util.function.Consumer;
import java.text.SimpleDateFormat;
import java.text.NumberFormat;
import javax.swing.undo.UndoManager;
import java.text.*;
import java.awt.datatransfer.StringSelection;
import java.util.TimeZone;
import java.awt.geom.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import javax.net.ssl.*;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import net.dv8tion.jda.core.*;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.hooks.*;
import net.dv8tion.jda.core.events.message.*;
import net.dv8tion.jda.core.events.message.react.*;
import net.dv8tion.jda.core.events.Event;
import net.dv8tion.jda.core.events.user.update.*;
class main {
public static class ReactToEvents extends DynTalkBot2 {
public void init() {
super.init();
onDiscordEvent(e -> {
print("Generic Discord event: " + e);
if (e instanceof UserUpdateOnlineStatusEvent)
print("User " + ((UserUpdateOnlineStatusEvent) e).getMember() + " old presence : " + ((UserUpdateOnlineStatusEvent) e).getOldValue() + ", new presence: " + ((UserUpdateOnlineStatusEvent) e).getNewValue());
});
}
}
public static boolean _moduleClass_ReactToEvents = true;
public static Object callF(Object f, Object... args) {
try {
if (f instanceof String)
return callMC((String) f, args);
return x30_util.callF(f, args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static A callF(F0 f) {
return f == null ? null : f.get();
}
public static A callF(IF0 f) {
return f == null ? null : f.get();
}
public static B callF(F1 f, A a) {
return f == null ? null : f.get(a);
}
public static B callF(IF1 f, A a) {
return f == null ? null : f.get(a);
}
public static C callF(F2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
public static void callF(VF1 f, A a) {
if (f != null)
f.get(a);
}
public static Object callMC(String method, Object... args) {
return call(mc(), method, args);
}
public static Object call(Object o) {
return callF(o);
}
public static Object call(Object o, String method, Object... args) {
return call_withVarargs(o, method, args);
}
public static void _onLoad_initUtils() {
utils.__javax = javax();
}
public static void _onLoad_defaultClassFinder() {
setDefaultClassFinder(new F1() {
public Class get(String name) {
try {
Class c = findClass_fullName(name);
if (c != null)
return c;
if (startsWith(name, "main$"))
return loadableUtils.utils.findClass_fullName("loadableUtils.utils" + substring(name, 4));
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Class c = findClass_fullName(name);\r\n if (c != null) ret c;\r\n if (start...";
}
});
}
public static String programID() {
return getProgramID();
}
public static String programID(Object o) {
return getProgramID(o);
}
public static volatile StringBuffer local_log = new StringBuffer();
public static volatile Appendable print_log = local_log;
public static volatile int print_log_max = 1024 * 1024;
public static volatile int local_log_max = 100 * 1024;
public static boolean print_silent = false;
public static Object print_byThread_lock = new Object();
public static volatile ThreadLocal print_byThread;
public static volatile Object print_allThreads;
public static volatile Object print_preprocess;
public static void print() {
print("");
}
public static A print(String s, A o) {
print((endsWithLetterOrDigit(s) ? s + ": " : s) + o);
return o;
}
public static A print(A o) {
ping_okInCleanUp();
if (print_silent)
return o;
String s = String.valueOf(o) + "\n";
print_noNewLine(s);
return o;
}
public static void print_noNewLine(String s) {
Object f = getThreadLocal(print_byThread_dontCreate());
if (f == null)
f = print_allThreads;
if (f != null)
if (isFalse(f instanceof F1 ? ((F1) f).get(s) : callF(f, s)))
return;
print_raw(s);
}
public static void print_raw(String s) {
if (print_preprocess != null)
s = (String) callF(print_preprocess, s);
s = fixNewLines(s);
Appendable loc = local_log;
Appendable buf = print_log;
int loc_max = print_log_max;
if (buf != loc && buf != null) {
print_append(buf, s, print_log_max);
loc_max = local_log_max;
}
if (loc != null)
print_append(loc, s, loc_max);
System.out.print(s);
}
public static void print_autoRotate() {
}
public static AutoCloseable tempInterceptPrintIfNotIntercepted(F1 f) {
return print_byThread().get() == null ? tempInterceptPrint(f) : null;
}
public static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
public static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
public static Class mc() {
return main.class;
}
public static Object call_withVarargs(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findStaticMethod(method, args);
if (me != null)
return invokeMethod(me, null, args);
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
{
if (!(isStaticMethod(m)))
continue;
}
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return invokeMethod(m, null, newArgs);
}
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(method, args);
if (me != null)
return invokeMethod(me, o, args);
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return invokeMethod(m, o, newArgs);
}
throw fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found in " + c);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Class javax() {
return getJavaX();
}
public static void setDefaultClassFinder(Object cf) {
_defaultClassFinder_value = cf;
}
public static HashMap findClass_fullName_cache = new HashMap();
public static Class findClass_fullName(String name) {
synchronized (findClass_fullName_cache) {
if (findClass_fullName_cache.containsKey(name))
return findClass_fullName_cache.get(name);
Class c;
try {
c = Class.forName(name);
} catch (ClassNotFoundException e) {
c = null;
}
findClass_fullName_cache.put(name, c);
return c;
}
}
public static boolean startsWith(String a, String b) {
return a != null && a.startsWith(b);
}
public static boolean startsWith(String a, char c) {
return nemptyString(a) && a.charAt(0) == c;
}
public static boolean startsWith(String a, String b, Matches m) {
if (!startsWith(a, b))
return false;
m.m = new String[] { substring(a, strL(b)) };
return true;
}
public static boolean startsWith(List a, List b) {
if (a == null || listL(b) > listL(a))
return false;
for (int i = 0; i < listL(b); i++) if (neq(a.get(i), b.get(i)))
return false;
return true;
}
public static String substring(String s, int x) {
return substring(s, x, strL(s));
}
public static String substring(String s, int x, int y) {
if (s == null)
return null;
if (x < 0)
x = 0;
if (x >= s.length())
return "";
if (y < x)
y = x;
if (y > s.length())
y = s.length();
return s.substring(x, y);
}
public static Object _defaultClassFinder_value = defaultDefaultClassFinder();
public static Object _defaultClassFinder() {
return _defaultClassFinder_value;
}
public static String programID;
public static String getProgramID() {
return nempty(programID) ? formatSnippetIDOpt(programID) : "?";
}
public static String getProgramID(Class c) {
String id = (String) getOpt(c, "programID");
if (nempty(id))
return formatSnippetID(id);
return "?";
}
public static String getProgramID(Object o) {
return getProgramID(getMainClass(o));
}
public static boolean endsWithLetterOrDigit(String s) {
return s != null && s.length() > 0 && Character.isLetterOrDigit(s.charAt(s.length() - 1));
}
public static void ping_okInCleanUp() {
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
}
public static Object getThreadLocal(Object o, String name) {
ThreadLocal t = (ThreadLocal) (getOpt(o, name));
return t != null ? t.get() : null;
}
public static A getThreadLocal(ThreadLocal tl) {
return tl == null ? null : tl.get();
}
public static A getThreadLocal(ThreadLocal tl, A defaultValue) {
return or(getThreadLocal(tl), defaultValue);
}
public static ThreadLocal print_byThread_dontCreate() {
return print_byThread;
}
public static boolean isFalse(Object o) {
return eq(false, o);
}
public static String fixNewLines(String s) {
int i = indexOf(s, '\r');
if (i < 0)
return s;
int l = s.length();
StringBuilder out = new StringBuilder(l);
out.append(s, 0, i);
for (; i < l; i++) {
char c = s.charAt(i);
if (c != '\r')
out.append(c);
else {
out.append('\n');
if (i + 1 < l && s.charAt(i + 1) == '\n')
++i;
}
}
return out.toString();
}
public static void print_append(Appendable buf, String s, int max) {
try {
synchronized (buf) {
buf.append(s);
if (buf instanceof StringBuffer)
rotateStringBuffer(((StringBuffer) buf), max);
else if (buf instanceof StringBuilder)
rotateStringBuilder(((StringBuilder) buf), max);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static ThreadLocal print_byThread() {
synchronized (print_byThread_lock) {
if (print_byThread == null)
print_byThread = new ThreadLocal();
}
return print_byThread;
}
public static AutoCloseable tempInterceptPrint(F1 f) {
return tempSetThreadLocal(print_byThread(), f);
}
public static void _handleError(Error e) {
call(javax(), "_handleError", e);
}
public static final Map callOpt_cache = newDangerousWeakHashMap();
public static Object callOpt_cached(Object o, String methodName, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me == null || (me.getModifiers() & Modifier.STATIC) == 0)
return null;
return invokeMethod(me, null, args);
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me == null)
return null;
return invokeMethod(me, o, args);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static _MethodCache callOpt_getCache(Class c) {
synchronized (callOpt_cache) {
_MethodCache cache = callOpt_cache.get(c);
if (cache == null)
callOpt_cache.put(c, cache = new _MethodCache(c));
return cache;
}
}
public static Object invokeMethod(Method m, Object o, Object... args) {
try {
try {
return m.invoke(o, args);
} catch (InvocationTargetException e) {
throw rethrow(getExceptionCause(e));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e.getMessage() + " - was calling: " + m + ", args: " + joinWithSpace(classNames(args)));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static boolean isStaticMethod(Method m) {
return methodIsStatic(m);
}
public static Object[] massageArgsForVarArgsCall(Method m, Object[] args) {
Class>[] types = m.getParameterTypes();
int n = types.length - 1, nArgs = args.length;
if (nArgs < n)
return null;
for (int i = 0; i < n; i++) if (!argumentCompatibleWithType(args[i], types[i]))
return null;
Class varArgType = types[n].getComponentType();
for (int i = n; i < nArgs; i++) if (!argumentCompatibleWithType(args[i], varArgType))
return null;
Object[] newArgs = new Object[n + 1];
arraycopy(args, 0, newArgs, 0, n);
Object[] varArgs = arrayOfType(varArgType, nArgs - n);
arraycopy(args, n, varArgs, 0, nArgs - n);
newArgs[n] = varArgs;
return newArgs;
}
public static String joinWithComma(Collection c) {
return join(", ", c);
}
public static String joinWithComma(String... c) {
return join(", ", c);
}
public static String joinWithComma(Pair p) {
return p == null ? "" : joinWithComma(str(p.a), str(p.b));
}
public static List classNames(Collection l) {
return getClassNames(l);
}
public static List classNames(Object[] l) {
return getClassNames(Arrays.asList(l));
}
public static Class __javax;
public static Class getJavaX() {
try {
return __javax;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static boolean nemptyString(String s) {
return s != null && s.length() > 0;
}
public static int strL(String s) {
return s == null ? 0 : s.length();
}
public static int listL(Collection l) {
return l == null ? 0 : l.size();
}
public static boolean neq(Object a, Object b) {
return !eq(a, b);
}
public static Object defaultDefaultClassFinder() {
return new F1() {
public Class get(String name) {
try {
Class c = findClass_fullName(name);
if (c != null)
return c;
if (startsWith(name, "loadableUtils.utils$"))
return findClass_fullName("main" + substring(name, 19));
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Class c = findClass_fullName(name);\r\n if (c != null) ret c;\r\n if (start...";
}
};
}
public static boolean nempty(Collection c) {
return !empty(c);
}
public static boolean nempty(CharSequence s) {
return !empty(s);
}
public static boolean nempty(Object[] o) {
return !empty(o);
}
public static boolean nempty(byte[] o) {
return !empty(o);
}
public static boolean nempty(int[] o) {
return !empty(o);
}
public static boolean nempty(Map m) {
return !empty(m);
}
public static boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
public static boolean nempty(Object o) {
return !empty(o);
}
public static String formatSnippetIDOpt(String s) {
return isSnippetID(s) ? formatSnippetID(s) : s;
}
public static String formatSnippetID(String id) {
return "#" + parseSnippetID(id);
}
public static String formatSnippetID(long id) {
return "#" + id;
}
public static Class getMainClass() {
return mc();
}
public static Class getMainClass(Object o) {
try {
if (o == null)
return null;
if (o instanceof Class && eq(((Class) o).getName(), "x30"))
return (Class) o;
return (o instanceof Class ? (Class) o : o.getClass()).getClassLoader().loadClass("main");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static volatile boolean ping_pauseAll = false;
public static int ping_sleep = 100;
public static volatile boolean ping_anyActions = false;
public static Map ping_actions = newWeakHashMap();
public static ThreadLocal ping_isCleanUpThread = new ThreadLocal();
public static boolean ping() {
if (ping_pauseAll || ping_anyActions)
ping_impl(true);
return true;
}
public static boolean ping_impl(boolean okInCleanUp) {
try {
if (ping_pauseAll && !isAWTThread()) {
do Thread.sleep(ping_sleep); while (ping_pauseAll);
return true;
}
if (ping_anyActions) {
if (!okInCleanUp && !isTrue(ping_isCleanUpThread.get()))
failIfUnlicensed();
Object action = null;
synchronized (ping_actions) {
if (!ping_actions.isEmpty()) {
action = ping_actions.get(currentThread());
if (action instanceof Runnable)
ping_actions.remove(currentThread());
if (ping_actions.isEmpty())
ping_anyActions = false;
}
}
if (action instanceof Runnable)
((Runnable) action).run();
else if (eq(action, "cancelled"))
throw fail("Thread cancelled.");
}
return false;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static A or(A a, A b) {
return a != null ? a : b;
}
public static boolean eq(Object a, Object b) {
return a == b || (a == null ? b == null : b != null && a.equals(b));
}
public static void rotateStringBuffer(StringBuffer buf, int max) {
try {
if (buf == null)
return;
synchronized (buf) {
if (buf.length() <= max)
return;
try {
int newLength = max / 2;
int ofs = buf.length() - newLength;
String newString = buf.substring(ofs);
buf.setLength(0);
buf.append("[...] ").append(newString);
} catch (Exception e) {
buf.setLength(0);
}
buf.trimToSize();
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static void rotateStringBuilder(StringBuilder buf, int max) {
try {
if (buf == null)
return;
synchronized (buf) {
if (buf.length() <= max)
return;
try {
int newLength = max / 2;
int ofs = buf.length() - newLength;
String newString = buf.substring(ofs);
buf.setLength(0);
buf.append("[...] ").append(newString);
} catch (Exception e) {
buf.setLength(0);
}
buf.trimToSize();
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static AutoCloseable tempSetThreadLocal(final ThreadLocal tl, A a) {
if (tl == null)
return null;
final A prev = setThreadLocal(tl, a);
return new AutoCloseable() {
public String toString() {
return "tl.set(prev);";
}
public void close() throws Exception {
tl.set(prev);
}
};
}
public static Throwable getExceptionCause(Throwable e) {
Throwable c = e.getCause();
return c != null ? c : e;
}
public static String joinWithSpace(Collection c) {
return join(" ", c);
}
public static String joinWithSpace(String... c) {
return join(" ", c);
}
public static boolean methodIsStatic(Method m) {
return (m.getModifiers() & Modifier.STATIC) != 0;
}
public static boolean argumentCompatibleWithType(Object arg, Class type) {
return arg == null ? !type.isPrimitive() : isInstanceX(type, arg);
}
public static void arraycopy(Object[] a, Object[] b) {
if (a != null && b != null)
arraycopy(a, 0, b, 0, min(a.length, b.length));
}
public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int n) {
if (n != 0)
System.arraycopy(src, srcPos, dest, destPos, n);
}
public static A[] arrayOfType(Class type, int n) {
return makeArray(type, n);
}
public static A[] arrayOfType(int n, Class type) {
return arrayOfType(type, n);
}
public static String join(String glue, Iterable strings) {
if (strings == null)
return "";
if (strings instanceof Collection) {
if (((Collection) strings).size() == 1)
return str(first(((Collection) strings)));
}
StringBuilder buf = new StringBuilder();
Iterator i = strings.iterator();
if (i.hasNext()) {
buf.append(i.next());
while (i.hasNext()) buf.append(glue).append(i.next());
}
return buf.toString();
}
public static String join(String glue, String... strings) {
return join(glue, Arrays.asList(strings));
}
public static String join(Iterable strings) {
return join("", strings);
}
public static String join(Iterable strings, String glue) {
return join(glue, strings);
}
public static String join(String[] strings) {
return join("", strings);
}
public static String join(String glue, Pair p) {
return p == null ? "" : str(p.a) + glue + str(p.b);
}
public static String str(Object o) {
return o == null ? "null" : o.toString();
}
public static String str(char[] c) {
return new String(c);
}
public static List getClassNames(Collection l) {
List out = new ArrayList();
if (l != null)
for (Object o : l) out.add(o == null ? null : getClassName(o));
return out;
}
public static boolean empty(Collection c) {
return c == null || c.isEmpty();
}
public static boolean empty(CharSequence s) {
return s == null || s.length() == 0;
}
public static boolean empty(Map map) {
return map == null || map.isEmpty();
}
public static boolean empty(Object[] o) {
return o == null || o.length == 0;
}
public static boolean empty(Object o) {
if (o instanceof Collection)
return empty((Collection) o);
if (o instanceof String)
return empty((String) o);
if (o instanceof Map)
return empty((Map) o);
if (o instanceof Object[])
return empty((Object[]) o);
if (o instanceof byte[])
return empty((byte[]) o);
if (o == null)
return true;
throw fail("unknown type for 'empty': " + getType(o));
}
public static boolean empty(Iterator i) {
return i == null || !i.hasNext();
}
public static boolean empty(float[] a) {
return a == null || a.length == 0;
}
public static boolean empty(int[] a) {
return a == null || a.length == 0;
}
public static boolean empty(long[] a) {
return a == null || a.length == 0;
}
public static boolean empty(byte[] a) {
return a == null || a.length == 0;
}
public static boolean empty(short[] a) {
return a == null || a.length == 0;
}
public static boolean empty(MultiSet ms) {
return ms == null || ms.isEmpty();
}
public static boolean empty(File f) {
return getFileSize(f) == 0;
}
public static boolean isSnippetID(String s) {
try {
parseSnippetID(s);
return true;
} catch (RuntimeException e) {
return false;
}
}
public static long parseSnippetID(String snippetID) {
long id = Long.parseLong(shortenSnippetID(snippetID));
if (id == 0)
throw fail("0 is not a snippet ID");
return id;
}
public static boolean isAWTThread() {
if (isAndroid())
return false;
if (isHeadless())
return false;
return isAWTThread_awt();
}
public static boolean isAWTThread_awt() {
return SwingUtilities.isEventDispatchThread();
}
public static void failIfUnlicensed() {
assertTrue("license off", licensed());
}
public static Thread currentThread() {
return Thread.currentThread();
}
public static A setThreadLocal(ThreadLocal tl, A value) {
if (tl == null)
return null;
A old = tl.get();
tl.set(value);
return old;
}
public static boolean isInstanceX(Class type, Object arg) {
if (type == boolean.class)
return arg instanceof Boolean;
if (type == int.class)
return arg instanceof Integer;
if (type == long.class)
return arg instanceof Long;
if (type == float.class)
return arg instanceof Float;
if (type == short.class)
return arg instanceof Short;
if (type == char.class)
return arg instanceof Character;
if (type == byte.class)
return arg instanceof Byte;
if (type == double.class)
return arg instanceof Double;
return type.isInstance(arg);
}
public static int min(int a, int b) {
return Math.min(a, b);
}
public static long min(long a, long b) {
return Math.min(a, b);
}
public static float min(float a, float b) {
return Math.min(a, b);
}
public static float min(float a, float b, float c) {
return min(min(a, b), c);
}
public static double min(double a, double b) {
return Math.min(a, b);
}
public static double min(double[] c) {
double x = Double.MAX_VALUE;
for (double d : c) x = Math.min(x, d);
return x;
}
public static float min(float[] c) {
float x = Float.MAX_VALUE;
for (float d : c) x = Math.min(x, d);
return x;
}
public static byte min(byte[] c) {
byte x = 127;
for (byte d : c) if (d < x)
x = d;
return x;
}
public static short min(short[] c) {
short x = 0x7FFF;
for (short d : c) if (d < x)
x = d;
return x;
}
public static int min(int[] c) {
int x = Integer.MAX_VALUE;
for (int d : c) if (d < x)
x = d;
return x;
}
public static A[] makeArray(Class type, int n) {
return (A[]) Array.newInstance(type, n);
}
public static Object first(Object list) {
return first((Iterable) list);
}
public static A first(List list) {
return empty(list) ? null : list.get(0);
}
public static A first(A[] bla) {
return bla == null || bla.length == 0 ? null : bla[0];
}
public static A first(IterableIterator i) {
return first((Iterator ) i);
}
public static A first(Iterator i) {
return i == null || !i.hasNext() ? null : i.next();
}
public static A first(Iterable i) {
if (i == null)
return null;
Iterator it = i.iterator();
return it.hasNext() ? it.next() : null;
}
public static Character first(String s) {
return empty(s) ? null : s.charAt(0);
}
public static A first(Pair p) {
return p == null ? null : p.a;
}
public static String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
public static String getType(Object o) {
return getClassName(o);
}
public static long getFileSize(String path) {
return path == null ? 0 : new File(path).length();
}
public static long getFileSize(File f) {
return f == null ? 0 : f.length();
}
public static String shortenSnippetID(String snippetID) {
if (snippetID.startsWith("#"))
snippetID = snippetID.substring(1);
String httpBlaBla = "http://tinybrain.de/";
if (snippetID.startsWith(httpBlaBla))
snippetID = snippetID.substring(httpBlaBla.length());
return "" + parseLong(snippetID);
}
public static volatile boolean licensed_yes = true;
public static boolean licensed() {
if (!licensed_yes)
return false;
ping_okInCleanUp();
return true;
}
public static void licensed_off() {
licensed_yes = false;
}
public static long parseLong(String s) {
if (empty(s))
return 0;
return Long.parseLong(dropSuffix("L", s));
}
public static long parseLong(Object s) {
return Long.parseLong((String) s);
}
public static String dropSuffix(String suffix, String s) {
return s.endsWith(suffix) ? s.substring(0, l(s) - l(suffix)) : s;
}
public static final class _MethodCache {
public final Class c;
public final HashMap> cache = new HashMap();
public _MethodCache(Class c) {
this.c = c;
_init();
}
public void _init() {
Class _c = c;
while (_c != null) {
for (Method m : _c.getDeclaredMethods()) if (!reflection_isForbiddenMethod(m))
multiMapPut(cache, m.getName(), makeAccessible(m));
_c = _c.getSuperclass();
}
for (Class intf : allInterfacesImplementedBy(c)) for (Method m : intf.getDeclaredMethods()) if (m.isDefault() && !reflection_isForbiddenMethod(m))
multiMapPut(cache, m.getName(), makeAccessible(m));
}
public Method findMethod(String method, Object[] args) {
try {
List m = cache.get(method);
if (m == null)
return null;
int n = m.size();
for (int i = 0; i < n; i++) {
Method me = m.get(i);
if (call_checkArgs(me, args, false))
return me;
}
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public Method findStaticMethod(String method, Object[] args) {
try {
List m = cache.get(method);
if (m == null)
return null;
int n = m.size();
for (int i = 0; i < n; i++) {
Method me = m.get(i);
if (isStaticMethod(me) && call_checkArgs(me, args, false))
return me;
}
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
}
public abstract static class DynTalkBot2 extends DynServerAwareDiscordBot {
public static boolean _switchableField_myName = true;
public String myName = "Anonymous bot";
public transient boolean useAGIBlueForDropPunctuation = true;
public transient boolean preprocessAtSelfToMyName = true;
public transient boolean dropPunctuation = true;
public transient boolean ngbCommands = true;
public transient boolean perGuildAuth = false;
public List authorizedUsers = ll(547706854680297473L);
public void init() {
super.init();
dm_vmBus_onMessage_q("discordGuildJoin", new VF1() {
public void get(Map map) {
try {
{
if (!(map.get("module") == module()))
return;
}
print("Got join");
getByServer(getLong("guildID", map), true).onUserJoin(getLong("userID", map), map);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret unless map.get('module) == module();\r\n print(\"Got join\");\r\n get...";
}
});
}
public class ByServer extends DynServerAwareDiscordBot.ByServer {
public List guildAuthorizedUsers;
public DynTalkBot2 m2() {
return DynTalkBot2.this;
}
public void onUserJoin(long userID, Object... __) {
}
@Override
public String answer(String input, Map map) {
String __32 = super.answer(input, map);
if (!empty(__32))
return __32;
return processLine(input, map);
}
public String dropMyPrefixOrNull(String s) {
String sOld = s;
s = dropPrefixICTrim_orNull(myPrefix(), s);
if (s == null)
print("no got prefix: " + quote(myPrefix()) + " / " + quote(sOld));
return s;
}
public String processLine(String s, Object... __) {
s = preprocess(s, __);
return processSimplifiedLine(s, __);
}
public String preprocess(String s, Object... __) {
print("Preprocessing: " + s);
if (preprocessAtSelfToMyName && discordBotID != 0)
s = replace(s, atSelf(), " " + myName + " ");
if (dropPunctuation)
s = dropPunctuation3_withAGIBlue(useAGIBlueForDropPunctuation, s);
s = trim(simpleSpaces_noTok(s));
print("simplified >> " + quote(s));
return s;
}
public String myPrefix() {
return preprocessAtSelfToMyName ? (endsWithLetterOrDigit(myName) ? myName + " " : myName) : (dropPunctuation ? replace(atSelf(), "@", "") : atSelf()) + " ";
}
public String processSimplifiedLine(String input, Object... __) {
Matches m = new Matches();
input = dropMyPrefixOrNull(input);
if (input == null)
return null;
if (ngbCommands) {
if (eqicOneOf(input, "support channel", "support server", "support"))
return "Get support for me here: " + nextGenBotsDiscordInvite();
if (eqicOneOf(input, "source", "sources", "source code"))
return snippetLink(programID());
}
if (swic_trim(input, "add master ", m)) {
String __33 = checkAuth(__);
if (!empty(__33))
return __33;
setAdd(authorizedUsers, parseFirstLong(m.rest()));
change();
return "Okidoki. Have " + n2(l(authorizedUsers), "master");
}
if (eqic(input, "masters"))
return empty(authorizedUsers) ? "I have no masters." : "My masters are: " + joinWithComma(map("discordAtPlusID", authorizedUsers));
if (swic_trim(input, "delete master ", m)) {
String __34 = checkAuth(__);
if (!empty(__34))
return __34;
remove(authorizedUsers, parseFirstLong(m.rest()));
change();
return "Okidoki. Have " + n2(l(authorizedUsers), "master");
}
if (eqic(input, "guild count")) {
String __35 = checkAuth(__);
if (!empty(__35))
return __35;
return "Total guilds joined: " + guildCount + ". Live guilds: " + liveGuildCount();
}
return null;
}
public boolean authed(Object... __) {
return contains(authorizedUsers, optPar("userID", __));
}
public String checkAuth(Object... __) {
long userID = longPar("userID", __);
boolean result = authed(__);
print("Auth-checking user ID: " + userID + " => " + result);
if (!result)
return "You are not authorized";
return null;
}
public String guildStructure() {
return structure_nullingInstancesOfClass(_getClass(module()), this);
}
}
public String serveGuildBackup(MessageChannel channel, Guild guild, String data) {
if (guild == null)
return "Do this in a guild";
if (containsDiscordToken(data))
return "DISCORD TOKEN EXPOSED ALARM!! NOTIFY ADMINISTRATOR";
String baseName = urlencode(jda_selfUserName(discord)) + "-" + guild.getIdLong() + "-" + ymd_minus_hms();
String zipName = baseName + ".zip";
File zip = programFile("backups/" + zipName);
createZipFileWithSingleTextFile(zip, baseName + ".txt", data);
channel.sendMessage("Here's my latest brain contents for this guild.").addFile(zip).queue();
return null;
}
public String serveGuildBackup(MessageChannel channel, Guild guild, ByServer bs) {
return serveGuildBackup(channel, guild, bs.guildStructure());
}
public String atSelfOrMyName() {
return preprocessAtSelfToMyName ? myName : atSelf();
}
}
public abstract static class DynServerAwareDiscordBot extends DynDiscordHopper {
public Map dataByServer = new HashMap();
public int guildCount;
public transient IF0 makeByServer;
public class ByServer {
public boolean isGuild = false;
public String answer(String s, Map map) {
return null;
}
public boolean setField(String name, Object value) {
if (set_trueIfChanged(this, name, value))
return false;
{
_change();
return true;
}
}
public Member getSelfMember(Guild guild) {
return guild.getMember(getSelfUser());
}
}
@Override
public String answer(String input, Map map) {
String __72 = super.answer(input, map);
if (!empty(__72))
return __72;
long guildID = toLong(map.get("guildID"));
long id = guildID;
print("Guild ID: " + guildID);
if (id == 0) {
id = toLong(map.get("userID"));
print("User ID: " + id);
}
A data = getByServer(id, id == guildID);
Message msg = (Message) (map.get("msg"));
if (msg != null && nempty(msg.getAttachments()))
return data.answer(input, map);
else
return mapEachLine_tlft_nempties(input, s -> {
return data.answer(s, map);
});
}
public A getByServer(long id, boolean isGuild) {
return pairA(getByServer2(id, isGuild));
}
public Pair getByServer2(long id, boolean isGuild) {
A data;
boolean isNew = false;
Pair __73 = syncGetOrCreate2(dataByServer, id, makeByServer);
data = __73.a;
isNew = __73.b;
data.isGuild = isGuild;
if (isNew) {
if (data.isGuild)
++guildCount;
change();
}
return pair(data, isNew);
}
public void start() {
super.start();
if (guildCount == 0)
setField("guildCount", countValuesWhere_sync(dataByServer, "isGuild", true));
}
public int liveGuildCount() {
return l(discord.getGuilds());
}
public long idForByServer(A bs) {
return bs == null ? 0 : toLong(keyForValue_sync(dataByServer, bs));
}
}
public static interface IF0 {
public A get();
}
public abstract static class DynDiscordHopper extends DynPrintLogAndEnabled {
public static boolean _switchableField_discordToken = true;
public String discordToken;
public String discordBotName;
public long discordBotID;
public boolean reactToBots = true;
public transient JDA discord;
public transient Color discordImageEmbedMysteriousLineColor = colorFromHex("36393f");
public transient Consumer onQueueError = error -> {
AutoCloseable __45 = enter();
try {
printStackTrace(error);
} finally {
_close(__45);
}
};
public void startDiscord() {
if (!discordEnabled()) {
print("Not enabled");
return;
}
vm_cleanPrints();
logModuleOutput();
discord = discordBot(new ListenerAdapter() {
@Override
public void onMessageUpdate(MessageUpdateEvent e) {
try {
AutoCloseable __46 = enter();
try {
{
if (!discordEnabled() || !licensed())
return;
}
Message msg = e.getMessage();
long msgID = msg.getIdLong();
User user = e.getAuthor();
long userID = user == null ? 0 : user.getIdLong();
String content = e.getMessage().getContentRaw();
MessageChannel channel = e.getChannel();
long channelID = channel.getIdLong();
String rendered = msgID + ": " + content;
print("Message edited: " + rendered);
vmBus_send("editedDiscordMessage", litmapparams("event", e, "module", dm_me(), "msgID", msgID, "msg", msg, "content", content, "channelID", channelID, "channel", channel, "user", user, "userID", userID));
Object lineConcept = dm_discord_lineForMsgID_unimported(msgID);
if (lineConcept == null)
return;
call(lineConcept, "_setField", "editedText", content);
} finally {
_close(__46);
}
} catch (Throwable __e) {
_handleException(__e);
}
}
@Override
public void onMessageReceived(MessageReceivedEvent e) {
try {
AutoCloseable __47 = enter();
try {
{
if (!discordEnabled() || !licensed())
return;
}
User user = e.getAuthor();
if (!reactToUser(user)) {
print("Not reacting to user " + user);
return;
}
boolean bot = user.isBot();
long msgID = e.getMessage().getIdLong();
long userID = user.getIdLong();
Guild guild = e.getGuild();
long guildID = toLong(call(guild, "getIdLong"));
Member member = e.getMember();
String userName = member == null ? null : member.getNickname();
if (userName == null && member != null)
userName = member.getEffectiveName();
if (userName == null)
userName = e.getAuthor().getName();
final Message msg = e.getMessage();
MessageChannel channel = e.getChannel();
long channelID = channel.getIdLong();
boolean isPrivate = e.getChannelType() == ChannelType.PRIVATE;
String content = trim(msg.getContentRaw());
print("Msg from " + userName + ": " + content);
vmBus_send("incomingDiscordMessage", litmapparams("fromBot", bot, "module", dm_me(), "msgID", msgID, "userID", userID, "userName", userName, "event", e, "guildID", guildID, "guild", guild, "member", member, "msg", msg, "content", content, "isPrivate", isPrivate, "channelID", channelID, "channel", channel));
} finally {
_close(__47);
}
} catch (Throwable __e) {
_handleException(__e);
}
}
@Override
public void onMessageReactionAdd(MessageReactionAddEvent e) {
try {
AutoCloseable __48 = enter();
try {
{
if (!discordEnabled() || !licensed())
return;
}
MessageReaction r = e.getReaction();
if (!reactToUser(e.getUser()))
return;
boolean bot = e.getUser().isBot();
long msgID = r.getMessageIdLong();
String emoji = r.getReactionEmote().getName();
vmBus_send("incomingDiscordReaction", litmapparams("fromBot", bot, "module", dm_me(), "msgID", msgID, "emoji", emoji));
} finally {
_close(__48);
}
} catch (Throwable __e) {
_handleException(__e);
}
}
@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
try {
AutoCloseable __49 = enter();
try {
print("Got guild join");
{
if (!discordEnabled() || !licensed())
return;
}
print("Join >> getting user ID");
long userID = rcall_long("getIdLong", rcall("getUser", event.getMember()));
print("Join >> sending");
vmBus_send("discordGuildJoin", litmapparams("module", dm_me(), "event", event, "userID", userID, "guildID", discord_guildIDFromEvent_gen(event)));
} finally {
_close(__49);
}
} catch (Throwable __e) {
_handleException(__e);
}
}
@Override
public void onGuildMemberLeave(GuildMemberLeaveEvent event) {
try {
AutoCloseable __50 = enter();
try {
print("Got guild leave");
{
if (!discordEnabled() || !licensed())
return;
}
long userID = rcall_long("getIdLong", rcall("getUser", event.getMember()));
vmBus_send("discordGuildLeave", litmapparams("module", dm_me(), "event", event, "userID", userID));
} finally {
_close(__50);
}
} catch (Throwable __e) {
_handleException(__e);
}
}
}, "token", discordToken);
dm_registerAs("liveDiscordModule");
dm_vmBus_answerToMessage("activeDiscordTokens", new F0>() {
public List get() {
try {
return ll(discordToken);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret ll(discordToken);";
}
});
try {
setField("discordBotName", jda_selfUserName(discord));
setField("discordBotID", jda_selfUserID(discord));
} catch (Throwable __e) {
_handleException(__e);
}
print("Bot name: " + discordBotName);
}
public void cleanMeUp() {
if (discord != null) {
try {
print("Shutting down discord");
discord.shutdown();
print("Bot shut down");
} catch (Throwable __e) {
_handleException(__e);
}
}
discord = null;
}
public Object userConcept(User user) {
String crud = dm_gazelle_linesCRUD();
Object userConcept = dm_call(crud, "uniqUser", user.getIdLong());
dm_call(crud, "cset", userConcept, litobjectarray("name", user.getName()));
return userConcept;
}
public MessageChannel getChannel(long channelID) {
return discord.getTextChannelById(channelID);
}
public void postInChannel(long channelID, String msg) {
if (channelID == 0)
return;
postInChannel(getChannel(channelID), msg);
}
public void uploadFileInChannel(long channelID, File file, String fileName, String msg, IVF1 onPost) {
if (channelID == 0)
return;
uploadFileInChannel(getChannel(channelID), file, fileName, msg, onPost);
}
public void postInChannel(MessageChannel channel, String msg, IVF1 onPost) {
String originalMsg = msg;
msg = shortenForDiscord(msg);
String postID = (String) (dm_call(gazelle_postedLinesCRUD(), "postingLine", channel.getId(), msg));
print("Posting in channel " + channel + ": " + msg);
MessageAction a = channel.sendMessage(msg);
if (msg != originalMsg)
a.addFile(toUtf8(originalMsg), genericTextFileName());
a.queue(m -> msgPosted(m, onPost, postID), onQueueError);
}
public String genericTextFileName() {
return ymd_minus_hms() + ".txt";
}
public void msgPosted(Message m, IVF1 onPost, String postID) {
if (nempty(postID))
dm_call(gazelle_postedLinesCRUD(), "donePosting", postID, "discord msg " + m.getId());
long msgId = m.getIdLong();
print("I sent msg: " + msgId);
pcallF(onPost, m);
}
public void postInChannel(String channel, String msg) {
long id = dm_discord_channelID(channel);
if (id == 0)
throw fail("Channel not found: " + channel);
postInChannel(id, msg);
}
public void postInChannel(MessageChannel channel, String msg) {
postInChannel(channel, msg, null);
}
public void postImage(Map msgMap, String url) {
postImage(msgMap, url, "");
}
public void postImage(Map msgMap, String url, String description) {
postImage((MessageChannel) get("channel", msgMap), url, description);
}
public void postImage(MessageChannel channel, String url, String description) {
channel.sendMessage(new EmbedBuilder().setImage(absoluteURL(url)).setDescription(unnull(description)).setColor(discordImageEmbedMysteriousLineColor).build()).queue(null, onQueueError);
}
public void editMessage(long channelID, long msgID, String text) {
getChannel(channelID).editMessageById(str(msgID), text).queue(null, onQueueError);
}
public void sendPM(long userID, String text) {
print("Sending PM to " + userID + ": " + text);
discord.getUserById(userID).openPrivateChannel().queue(channel -> {
channel.sendMessage(shortenForDiscord(text)).queue(null, onQueueError);
}, onQueueError);
print("PM queued");
}
public void reply(Map msgMap, String text) {
reply(msgMap, text, null);
}
public void reply(Map msgMap, String text, Object onPost) {
if (empty(text = trim(text)))
return;
postInChannel((MessageChannel) msgMap.get("channel"), text, toIVF1(onPost));
}
public void iAmTyping(Map msgMap) {
try {
((MessageChannel) msgMap.get("channel")).sendTyping().queue(null, onQueueError);
} catch (Throwable __e) {
_handleException(__e);
}
}
public String startKeepAliveModule() {
AutoCloseable __51 = enter();
try {
return dm_discord_startKeepAliveModule(module());
} finally {
_close(__51);
}
}
public boolean reactToUser(User user) {
boolean bot = user.isBot();
if (bot && !reactToBots)
return false;
if (user.getIdLong() == discordBotID)
return false;
return true;
}
public void uploadFileInChannel(MessageChannel channel, File file, String fileName, String msg, IVF1 onPost) {
msg = shortenForDiscord(msg);
MessageAction a = empty(msg) ? channel.sendFile(file, fileName) : channel.sendMessage(msg).addFile(file, fileName);
a.queue(m -> msgPosted(m, onPost, null), onQueueError);
}
public void uploadFileInChannel(MessageChannel channel, byte[] data, String fileName, String msg, IVF1 onPost) {
msg = shortenForDiscord(msg);
MessageAction a = empty(msg) ? channel.sendFile(data, fileName) : channel.sendMessage(msg).addFile(data, fileName);
a.queue(m -> msgPosted(m, onPost, null), onQueueError);
}
public void uploadFileInChannel(long channelID, byte[] data, String fileName, String msg, IVF1 onPost) {
uploadFileInChannel(getChannel(channelID), data, fileName, msg, onPost);
}
public boolean discordEnabled() {
return enabled;
}
public boolean printToModule() {
return true;
}
public boolean discordHopperMetaCmdsEnabled = false;
public long preferredChannelID;
public transient double minutesToKeepRecordedAnswers = 60.0;
public List recordedAnswers = syncList();
public static class RecordedAnswer {
public long timestamp;
public long questionMsgID, answerMsgID, channelID;
public String questionText, answerText;
public String toString() {
return stdToString(this);
}
}
public static boolean _switchableField_verboseEvents = true;
public transient boolean verboseEvents = false;
public transient List onDiscordStarted = new ArrayList();
public transient List> onDiscordEvent = syncList();
public ListenerAdapter genericListener = new ListenerAdapter() {
public void onGenericEvent(Event e) {
AutoCloseable __18 = enter();
try {
if (verboseEvents)
print("Discord event: " + e);
pcallFAll(onDiscordEvent, e);
} finally {
_close(__18);
}
}
};
public void onDiscordEvent(IVF1 e) {
onDiscordEvent.add(e);
}
public void enhanceFrame(Container f) {
super.enhanceFrame(f);
internalFramePopupMenuItem(f, "Start keep-alive module", runnableThread(new Runnable() {
public void run() {
try {
startKeepAliveModule();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "startKeepAliveModule();";
}
}));
minFrameSize(f, 300, 300);
}
public void start() {
super.start();
startThread("Start", new Runnable() {
public void run() {
try {
AutoCloseable __19 = enter();
try {
init();
startMe();
} finally {
_close(__19);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "AutoCloseable __19 = enter(); try { \r\n init();\r\n startMe();\r\n } finall...";
}
});
}
public void startMe() {
dm_vmBus_onMessage_q("incomingDiscordMessage", new VF1() {
public void get(Map map) {
try {
if (!enabled)
return;
Object module = map.get("module");
if (!dm_isMe(module))
return;
String s = getString("content", map);
long channelID = toLong(map.get("channelID"));
if (channelID != 0 && preferredChannelID == 0)
setField("preferredChannelID", channelID);
cleanRecordedAnswers();
String answer = answer(s, map);
sendReply(map, answer);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (!enabled) ret;\r\n O module = map.get('module);\r\n if (!dm_isMe(mo...";
}
});
startDiscord();
discord.addEventListener(genericListener);
print("onDiscordStarted=" + onDiscordStarted);
pcallFAll(onDiscordStarted);
}
public void sendReply(Map map, String answer) {
if (empty(answer))
return;
cleanRecordedAnswers();
RecordedAnswer a = new RecordedAnswer();
if (minutesToKeepRecordedAnswers > 0) {
a.timestamp = now();
a.questionMsgID = getLong("msgID", map);
a.channelID = getLong("channelID", map);
a.questionText = getString("content", map);
a.answerText = answer;
print("Recording answer : " + a);
recordedAnswers.add(a);
change();
}
dm_rcall("reply", map.get("module"), map, answer, (IVF1) msg -> {
a.answerMsgID = rcall_long("getIdLong", msg);
change();
});
}
public String answer(String s, Map map) {
if (discordHopperMetaCmdsEnabled && eq(s, "!bot count"))
return lstr(dm_activeDiscordTokens());
List tokens = extractPossibleDiscordTokens(s);
for (String token : unnull(tokens)) {
if (getLong("guildID", map) != 0)
return "Send tokens only in private messages!!";
String answer = "That's a Discord token!";
if (contains(concatLists((List>) vmBus_queryAll("activeDiscordTokens")), token))
answer += " And I'm there already.";
else {
answer += " Jumping there!!";
dm_showNewModuleWithParams(dm_moduleLibID(), "discordToken", token);
}
reply(map, answer);
}
return null;
}
public String atSelf() {
return discordAt(discordBotID);
}
public void onDiscordStarted(Runnable r) {
onDiscordStarted.add(r);
}
public User getSelfUser() {
return discord.getSelfUser();
}
public void init() {
dm_watchField("discordToken", new Runnable() {
public void run() {
try {
if (nempty(discordToken))
dm_reloadModule();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (nempty(discordToken)) dm_reloadModule()";
}
});
dm_watchField("enabled", new Runnable() {
public void run() {
try {
if (nempty(discordToken))
dm_reloadModule();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (nempty(discordToken)) dm_reloadModule()";
}
});
}
public void cleanRecordedAnswers() {
RecordedAnswer a;
boolean change = false;
synchronized (recordedAnswers) {
while ((a = first(recordedAnswers)) != null && elapsedMinutes_timestamp(a.timestamp) > minutesToKeepRecordedAnswers) {
print("Removing old answer: " + a);
recordedAnswers.remove(a);
}
change = true;
}
if (change)
change();
}
public JComponent visualize() {
JComponent _c = super.visualize();
if (empty(discordToken))
containerAddFirst(buttons, jThreadedButton("Give me a token!", new Runnable() {
public void run() {
try {
AutoCloseable __20 = enter();
try {
dm_stringFieldDialog("discordToken");
} finally {
_close(__20);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "AutoCloseable __20 = enter(); try { dm_stringFieldDialog discordToken();\r\n ...";
}
}));
return _c;
}
public boolean warnOnDelete() {
return true;
}
public String migrateToType(String moduleLibID) {
String moduleID = assertNotNull(dm_showNewModuleWithParams(moduleLibID, "discordToken", discordToken));
print("Migrated to new module " + moduleID + ", disabling me");
setEnabled(false);
dm_reload();
return moduleID;
}
}
public static class Pair implements Comparable> {
public A a;
public B b;
public Pair() {
}
public Pair(A a, B b) {
this.b = b;
this.a = a;
}
public int hashCode() {
return hashCodeFor(a) + 2 * hashCodeFor(b);
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Pair))
return false;
Pair t = (Pair) o;
return eq(a, t.a) && eq(b, t.b);
}
public String toString() {
return "<" + a + ", " + b + ">";
}
public int compareTo(Pair p) {
if (p == null)
return 1;
int i = ((Comparable ) a).compareTo(p.a);
if (i != 0)
return i;
return ((Comparable) b).compareTo(p.b);
}
}
public static interface IVF1 {
public void get(A a);
}
public abstract static class DynPrintLogAndEnabled extends DynPrintLog {
public volatile boolean enabled = true;
public transient JPanel buttons;
public JComponent visualize() {
return dm_visualizeWithEnabled(super.visualize());
}
public JComponent dm_visualizeWithEnabled(JComponent main) {
return centerAndSouthWithMargins(main, buttons = jrightalignedline(dm_fieldCheckBox("enabled")));
}
public void setEnabled(boolean b) {
setField("enabled", b);
}
}
public static String discordAtPlusID(long userID) {
return userID == 0 ? "unknown person" : "<@" + userID + "> (" + userID + ")";
}
public static boolean reflection_isForbiddenMethod(Method m) {
return m.getDeclaringClass() == Object.class && eqOneOf(m.getName(), "finalize", "clone", "registerNatives");
}
public static void multiMapPut(Map > map, A a, B b) {
List l = map.get(a);
if (l == null)
map.put(a, l = new ArrayList());
l.add(b);
}
public static Field makeAccessible(Field f) {
try {
f.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, f);
}
return f;
}
public static Method makeAccessible(Method m) {
try {
m.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, m);
}
return m;
}
public static Constructor makeAccessible(Constructor c) {
try {
c.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, c);
}
return c;
}
public static Set allInterfacesImplementedBy(Class c) {
if (c == null)
return null;
HashSet set = new HashSet();
allInterfacesImplementedBy_find(c, set);
return set;
}
public static void allInterfacesImplementedBy_find(Class c, Set set) {
if (c.isInterface() && !set.add(c))
return;
do {
for (Class intf : c.getInterfaces()) allInterfacesImplementedBy_find(intf, set);
} while ((c = c.getSuperclass()) != null);
}
public static Method findMethod(Object o, String method, Object... args) {
return findMethod_cached(o, method, args);
}
public static boolean findMethod_checkArgs(Method m, Object[] args, boolean debug) {
Class>[] types = m.getParameterTypes();
if (types.length != args.length) {
if (debug)
System.out.println("Bad parameter length: " + args.length + " vs " + types.length);
return false;
}
for (int i = 0; i < types.length; i++) if (!(args[i] == null || isInstanceX(types[i], args[i]))) {
if (debug)
System.out.println("Bad parameter " + i + ": " + args[i] + " vs " + types[i]);
return false;
}
return true;
}
public static boolean call_checkArgs(Method m, Object[] args, boolean debug) {
Class>[] types = m.getParameterTypes();
if (types.length != args.length) {
if (debug)
print("Bad parameter length: " + args.length + " vs " + types.length);
return false;
}
for (int i = 0; i < types.length; i++) {
Object arg = args[i];
if (!(arg == null ? !types[i].isPrimitive() : isInstanceX(types[i], arg))) {
if (debug)
print("Bad parameter " + i + ": " + arg + " vs " + types[i]);
return false;
}
}
return true;
}
public static Method findStaticMethod(Class c, String method, Object... args) {
Class _c = c;
while (c != null) {
for (Method m : c.getDeclaredMethods()) {
if (!m.getName().equals(method))
continue;
if ((m.getModifiers() & Modifier.STATIC) == 0 || !findStaticMethod_checkArgs(m, args))
continue;
return m;
}
c = c.getSuperclass();
}
return null;
}
public static boolean findStaticMethod_checkArgs(Method m, Object[] args) {
Class>[] types = m.getParameterTypes();
if (types.length != args.length)
return false;
for (int i = 0; i < types.length; i++) if (!(args[i] == null || isInstanceX(types[i], args[i])))
return false;
return true;
}
public static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
if (a != null)
for (A x : a) l.add(x);
return l;
}
public static AutoCloseable dm_vmBus_onMessage_q(final String msg, final VF1 onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF1 () {
public void get(final A a) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage, a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, a);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage, a);";
}
});
}
public static AutoCloseable dm_vmBus_onMessage_q(final String msg, final VF2 onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF2 () {
public void get(final A a, final B b) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage, a, b);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, a, b);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage, a, b);";
}
});
}
public static AutoCloseable dm_vmBus_onMessage_q(final String msg, final Runnable onMessage) {
final DynModule m = dm_current_mandatory();
return dm_vmBus_onMessage(msg, new VF1 () {
public void get(final A a) {
try {
m.q().add(new Runnable() {
public void run() {
try {
callF(onMessage);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "switch to m.q();\r\n callF(onMessage);";
}
});
}
public static long getLong(Object o, String field) {
return toLong(getOpt(o, field));
}
public static long getLong(String field, Object o) {
return getLong(o, field);
}
public static String dropPrefixICTrim_orNull(String prefix, String s) {
return swic(s, prefix) ? trim(s.substring(l(prefix))) : null;
}
public static String quote(Object o) {
if (o == null)
return "null";
return quote(str(o));
}
public static String quote(String s) {
if (s == null)
return "null";
StringBuilder out = new StringBuilder((int) (l(s) * 1.5 + 2));
quote_impl(s, out);
return out.toString();
}
public static void quote_impl(String s, StringBuilder out) {
out.append('"');
int l = s.length();
for (int i = 0; i < l; i++) {
char c = s.charAt(i);
if (c == '\\' || c == '"')
out.append('\\').append(c);
else if (c == '\r')
out.append("\\r");
else if (c == '\n')
out.append("\\n");
else if (c == '\0')
out.append("\\0");
else
out.append(c);
}
out.append('"');
}
public static List replace(List l, A a, A b) {
for (int i = 0; i < l(l); i++) if (eq(l.get(i), a))
l.set(i, b);
return l;
}
public static List replace(A a, A b, List l) {
return replace(l, a, b);
}
public static String replace(String s, String a, String b) {
return s == null ? null : a == null || b == null ? s : s.replace(a, b);
}
public static String replace(String s, char a, char b) {
return s == null ? null : s.replace(a, b);
}
public static String dropPunctuation3_withAGIBlue(boolean useAGIBlue, String s) {
return useAGIBlue ? dropPunctuation3_withAGIBlue(s) : dropPunctuation3(s);
}
public static String dropPunctuation3_withAGIBlue(String s) {
if (!agiBlue_validPageName(s))
return dropPunctuation3(s);
String y = dropPunctuation3_cache.get(s);
if (y != null)
return y;
{
String __1 = agiBlue_lookupInSlice_pcall("xwxxvxozhdlwsxzj", s, "dropPunctuation");
if (!empty(__1))
return __1;
}
y = dropPunctuation3(s);
agiBlue_postInSlice_pcall("xwxxvxozhdlwsxzj", s, "dropPunctuation", y);
return y;
}
public static String trim(String s) {
return s == null ? null : s.trim();
}
public static String trim(StringBuilder buf) {
return buf.toString().trim();
}
public static String trim(StringBuffer buf) {
return buf.toString().trim();
}
public static String simpleSpaces_noTok(String s) {
return s == null ? null : s.replaceAll("\\s+", " ");
}
public static boolean eqicOneOf(String s, String... l) {
for (String x : l) if (eqic(s, x))
return true;
return false;
}
public static String nextGenBotsDiscordInvite() {
return "https://discord.gg/SEAjPqk";
}
public static String snippetLink(String id) {
return empty(id) ? id : "http://code.botcompany.de/" + parseSnippetID(id);
}
public static boolean swic_trim(String a, String b, Matches m) {
if (!swic(a, b))
return false;
m.m = new String[] { trim(substring(a, l(b))) };
return true;
}
public static boolean setAdd(Collection c, A a) {
if (c == null || c.contains(a))
return false;
c.add(a);
return true;
}
public static long parseFirstLong(String s) {
return parseLong(jextract("", s));
}
public static void change() {
callOpt(getOptMC("mainConcepts"), "allChanged");
}
public static String n2(long l) {
return formatWithThousands(l);
}
public static String n2(Collection l) {
return n2(l(l));
}
public static String n2(double l, String singular) {
return n2(l, singular, singular + "s");
}
public static String n2(double l, String singular, String plural) {
if (fraction(l) == 0)
return n2((long) l, singular, plural);
else
return l + " " + plural;
}
public static String n2(long l, String singular, String plural) {
return n_fancy2(l, singular, plural);
}
public static String n2(long l, String singular) {
return n_fancy2(l, singular, singular + "s");
}
public static String n2(Collection l, String singular) {
return n2(l(l), singular);
}
public static String n2(Collection l, String singular, String plural) {
return n_fancy2(l, singular, plural);
}
public static String n2(Map m, String singular, String plural) {
return n_fancy2(m, singular, plural);
}
public static String n2(Map m, String singular) {
return n2(l(m), singular);
}
public static String n2(Object[] a, String singular) {
return n2(l(a), singular);
}
public static String n2(Object[] a, String singular, String plural) {
return n_fancy2(a, singular, plural);
}
public static String n2(MultiSet ms, String singular, String plural) {
return n_fancy2(ms, singular, plural);
}
public static boolean eqic(String a, String b) {
if ((a == null) != (b == null))
return false;
if (a == null)
return true;
return a.equalsIgnoreCase(b);
}
public static boolean eqic(char a, char b) {
if (a == b)
return true;
char u1 = Character.toUpperCase(a);
char u2 = Character.toUpperCase(b);
if (u1 == u2)
return true;
return Character.toLowerCase(u1) == Character.toLowerCase(u2);
}
public static List map(Iterable l, Object f) {
return map(f, l);
}
public static List map(Object f, Iterable l) {
List x = emptyList(l);
if (l != null)
for (Object o : l) x.add(callF(f, o));
return x;
}
public static List map(Iterable l, F1 f) {
return map(f, l);
}
public static List map(F1 f, Iterable l) {
List x = emptyList(l);
if (l != null)
for (A o : l) x.add(callF(f, o));
return x;
}
public static List map(IF1 f, Iterable l) {
return map(l, f);
}
public static List map(Iterable l, IF1 f) {
List x = emptyList(l);
if (l != null)
for (A o : l) x.add(f.get(o));
return x;
}
public static List map(IF1 f, A[] l) {
return map(l, f);
}
public static List map(A[] l, IF1 f) {
List x = emptyList(l);
if (l != null)
for (A o : l) x.add(f.get(o));
return x;
}
public static List map(Object f, Object[] l) {
return map(f, asList(l));
}
public static List map(Object[] l, Object f) {
return map(f, l);
}
public static List map(Object f, Map map) {
return map(map, f);
}
public static List map(Map map, Object f) {
List x = new ArrayList();
if (map != null)
for (Object _e : map.entrySet()) {
Map.Entry e = (Map.Entry) _e;
x.add(callF(f, e.getKey(), e.getValue()));
}
return x;
}
public static List map(Map map, IF2 f) {
return map(map, (Object) f);
}
public static void remove(List l, int i) {
if (l != null && i >= 0 && i < l(l))
l.remove(i);
}
public static void remove(Collection l, A a) {
if (l != null)
l.remove(a);
}
public static boolean contains(Collection c, Object o) {
return c != null && c.contains(o);
}
public static boolean contains(Object[] x, Object o) {
if (x != null)
for (Object a : x) if (eq(a, o))
return true;
return false;
}
public static boolean contains(String s, char c) {
return s != null && s.indexOf(c) >= 0;
}
public static boolean contains(String s, String b) {
return s != null && s.indexOf(b) >= 0;
}
public static boolean contains(BitSet bs, int i) {
return bs != null && bs.get(i);
}
public static A optPar(ThreadLocal tl, A defaultValue) {
A a = tl.get();
if (a != null) {
tl.set(null);
return a;
}
return defaultValue;
}
public static A optPar(ThreadLocal tl) {
return optPar(tl, null);
}
public static Object optPar(Object[] params, String name) {
return optParam(params, name);
}
public static Object optPar(String name, Object[] params) {
return optParam(params, name);
}
public static Object optPar(String name, Map params) {
return optParam(name, params);
}
public static A optPar(Object[] params, String name, A defaultValue) {
return optParam(params, name, defaultValue);
}
public static A optPar(String name, Object[] params, A defaultValue) {
return optParam(params, name, defaultValue);
}
public static long longPar(String name, Object[] params) {
return toLong(optPar(name, params));
}
public static String structure_nullingInstancesOfClass(Class c, Object o) {
if (c == null)
return structure(o);
structure_Data data = new structure_Data();
structure_ClassInfo info = new structure_ClassInfo();
info.special = info.nullInstances = true;
data.infoByClass.put(c, info);
return structure(o, data);
}
public static Class> _getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
public static Class _getClass(Object o) {
return o == null ? null : o instanceof Class ? (Class) o : o.getClass();
}
public static Class _getClass(Object realm, String name) {
try {
return getClass(realm).getClassLoader().loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
}
public static boolean containsDiscordToken(String s) {
return regexpFind(discordTokenRegexp(), s);
}
public static String urlencode(String x) {
try {
return URLEncoder.encode(unnull(x), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
public static String jda_selfUserName(JDA jda) {
return jda_selfUser(jda).getName();
}
public static String ymd_minus_hms() {
return ymd() + "-" + hms();
}
public static File programFile(String name) {
return prepareProgramFile(name);
}
public static File programFile(String progID, String name) {
return prepareProgramFile(progID, name);
}
public static File createZipFileWithSingleTextFile(File zipFile, String name, String text) {
ZipOutputStream outZip = newZipOutputStream(zipFile);
try {
zip_addTextFile(outZip, name, text);
return zipFile;
} finally {
_close(outZip);
}
}
public static boolean set_trueIfChanged(Object o, String field, Object value) {
if (eq(get(o, field), value))
return false;
set(o, field, value);
return true;
}
public static long toLong(Object o) {
if (o instanceof Number)
return ((Number) o).longValue();
if (o instanceof String)
return parseLong((String) o);
return 0;
}
public static String mapEachLine_tlft_nempties(Object f, String text) {
return lines_possiblyRTrim(text, nempties(mapLines_tlft(f, text)));
}
public static String mapEachLine_tlft_nempties(String text, Object f) {
return mapEachLine_tlft_nempties(f, text);
}
public static String mapEachLine_tlft_nempties(String text, IF1 f) {
return mapEachLine_tlft_nempties(f, text);
}
public static A pairA(Pair p) {
return p == null ? null : p.a;
}
public static Pair syncGetOrCreate2(Map map, A key, Class extends B> c) {
try {
synchronized (map) {
B b = map.get(key);
if (b == null) {
map.put(key, b = c.newInstance());
return pair(b, true);
}
return pair(b, false);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Pair syncGetOrCreate2(Class extends B> c, Map map, A key) {
return syncGetOrCreate2(map, key, c);
}
public static Pair syncGetOrCreate2(Map map, A key, F0 f) {
try {
synchronized (map) {
B b = map.get(key);
if (b == null) {
map.put(key, b = callF(f));
return pair(b, true);
}
return pair(b, false);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Pair syncGetOrCreate2(Map map, A key, IF0 f) {
try {
synchronized (map) {
B b = map.get(key);
if (b == null) {
map.put(key, b = f.get());
return pair(b, true);
}
return pair(b, false);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Pair pair(A a, B b) {
return new Pair(a, b);
}
public static Pair pair(A a) {
return new Pair(a, a);
}
public static int countValuesWhere_sync(Map map, Object... data) {
if (map == null)
return 0;
synchronized (map) {
return countWhere(values(map), data);
}
}
public static A keyForValue_sync(B value, Map map) {
return keyForValue_sync(map, value);
}
public static A keyForValue_sync(Map map, B value) {
if (map == null || value == null)
return null;
synchronized (map) {
return keyForValue(map, value);
}
}
public static List syncList() {
return synchroList();
}
public static List syncList(List l) {
return synchroList(l);
}
public static String stdToString(Object o) {
return standard_toString(o);
}
public static void pcallFAll(Collection l, Object... args) {
if (l != null)
for (Object f : cloneList(l)) pcallF(f, args);
}
public static void pcallFAll(Iterator it, Object... args) {
while (it.hasNext()) pcallF(it.next(), args);
}
public static void _close(AutoCloseable c) {
if (c != null)
try {
c.close();
} catch (Throwable e) {
if (c instanceof javax.imageio.stream.ImageOutputStream)
return;
else
throw rethrow(e);
}
}
public static void internalFramePopupMenuItem(Container f, final String name, final Object action) {
internalFrameTitlePopupMenuItem(((JInternalFrame) f), name, action);
}
public static Runnable runnableThread(final Runnable r) {
return new Runnable() {
public void run() {
try {
startThread(r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "startThread(r)";
}
};
}
public static void minFrameSize(Component c, int w, int h) {
minimalFrameSize(c, w, h);
}
public static Thread startThread(Object runnable) {
return startThread(defaultThreadName(), runnable);
}
public static Thread startThread(String name, Object runnable) {
runnable = wrapAsActivity(runnable);
return startThread(newThread(toRunnable(runnable), name));
}
public static Thread startThread(Thread t) {
_registerThread(t);
t.start();
return t;
}
public static boolean dm_isMe(Object mod) {
return dm_getModule(mod) == dm_current_mandatory();
}
public static String getString(Map map, Object key) {
return map == null ? null : (String) map.get(key);
}
public static String getString(List l, int idx) {
return (String) get(l, idx);
}
public static String getString(Object o, Object key) {
if (o instanceof Map)
return getString((Map) o, key);
if (key instanceof String)
return (String) getOpt(o, (String) key);
throw fail("Not a string key: " + getClassName(key));
}
public static String getString(String key, Object o) {
return getString(o, (Object) key);
}
public static long now_virtualTime;
public static long now() {
return now_virtualTime != 0 ? now_virtualTime : System.currentTimeMillis();
}
public static Object dm_rcall(String method, Object moduleOrID, Object... args) {
return dm_call(moduleOrID, method, args);
}
public static long rcall_long(String method, Object o, Object... args) {
return toLong(rcall(method, o, args));
}
public static String lstr(Map map) {
return str(l(map));
}
public static String lstr(Collection c) {
return str(l(c));
}
public static String lstr(String s) {
return str(l(s));
}
public static List dm_activeDiscordTokens() {
return concatLists((List>) vmBus_queryAll("activeDiscordTokens"));
}
public static List extractPossibleDiscordTokens(String s) {
return regexpAll(discordTokenRegexp(), s);
}
public static String unnull(String s) {
return s == null ? "" : s;
}
public static Collection unnull(Collection l) {
return l == null ? emptyList() : l;
}
public static List unnull(List l) {
return l == null ? emptyList() : l;
}
public static Map unnull(Map l) {
return l == null ? emptyMap() : l;
}
public static Iterable unnull(Iterable i) {
return i == null ? emptyList() : i;
}
public static A[] unnull(A[] a) {
return a == null ? (A[]) new Object[0] : a;
}
public static BitSet unnull(BitSet b) {
return b == null ? new BitSet() : b;
}
public static Pt unnull(Pt p) {
return p == null ? new Pt() : p;
}
public static Pair unnull(Pair p) {
return p != null ? p : new Pair(null, null);
}
public static List concatLists(Collection ... lists) {
List l = new ArrayList();
if (lists != null)
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
public static List concatLists(Collection extends Collection > lists) {
List l = new ArrayList();
if (lists != null)
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
public static List vmBus_queryAll(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
List out = new ArrayList();
for (Object o : unnull(vm_busListeners_live())) addIfNotNull(out, pcallF(o, msg, arg));
for (Object o : unnull(vm_busListenersByMessage_live().get(msg))) addIfNotNull(out, pcallF(o, msg, arg));
return out;
}
public static String dm_showNewModuleWithParams(String moduleLibID, Object... params) {
String moduleID = dm_makeNewModuleWithParams(moduleLibID, params);
dm_showModule(moduleID);
return moduleID;
}
public static String dm_moduleLibID() {
return programID() + "/" + shortClassName(dm_current_mandatory());
}
public static String dm_moduleLibID(Object mod) {
if (mod == null)
return null;
mod = dm_getModule(mod);
if (hasSuperclassShortNamed(mod, "DynModule"))
return programID(mod) + "/" + shortClassName(mod);
return null;
}
public static String discordAt(long userID) {
return userID == 0 ? "unknown person" : "<@" + userID + ">";
}
public static void dm_watchField(String field, Runnable onChange) {
new Dyn_FieldWatcher(dm_current_mandatory(), field, onChange);
}
public static void dm_reloadModule(Object module) {
dm_reloadModuleInBackground(module);
}
public static void dm_reloadModule() {
dm_reloadModuleInBackground();
}
public static double elapsedMinutes_timestamp(long time) {
return toMinutes(now() - time);
}
public static void containerAddFirst(final Container c, final Component... l) {
{
swing(new Runnable() {
public void run() {
try {
for (int i = 0; i < l(l); i++) c.add(l[i], i);
revalidate(c);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "for (int i = 0; i < l(l); i++)\r\n c.add(l[i], i);\r\n revalidate(c);";
}
});
}
}
public static JButton jThreadedButton(final String text, final Object action) {
return swing(new F0() {
public JButton get() {
try {
String text2 = dropPrefix("[disabled] ", text);
final JButton btn = new JButton(text2);
if (l(text2) < l(text))
btn.setEnabled(false);
btn.setToolTipText(btn.getText());
if (action != null)
btn.addActionListener(actionListenerInNewThread(action, btn));
return btn;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "S text2 = dropPrefix(\"[disabled] \", text);\r\n final JButton btn = new JButt...";
}
});
}
public static void dm_stringFieldDialog(final String field, final Object... __) {
final DynModule m = dm_current_mandatory();
final String humanized = humanizeFormLabel(field);
final JTextField tf = jtextfield(get(m, field));
showFormTitled(or2(stringOptPar(__, "formTitle"), "Set " + humanized), humanized + ":", tf, new Runnable() {
public void run() {
try {
m.setField(field, gtt(tf));
callF(optPar(__, "onSet"));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "m.setField(field, gtt(tf));\r\n callF(optPar(__, \"onSet\"));";
}
});
}
public static A assertNotNull(A a) {
assertTrue(a != null);
return a;
}
public static A assertNotNull(String msg, A a) {
assertTrue(msg, a != null);
return a;
}
public static A setEnabled(A c, boolean enable) {
if (c != null) {
swing(new Runnable() {
public void run() {
try {
c.setEnabled(enable);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "c.setEnabled(enable);";
}
});
}
return c;
}
public static A setEnabled(boolean enable, A c) {
return setEnabled(c, enable);
}
public static void dm_reload() {
dm_reloadMe();
}
public static int hashCodeFor(Object a) {
return a == null ? 0 : a.hashCode();
}
public static boolean eqOneOf(Object o, Object... l) {
for (Object x : l) if (eq(o, x))
return true;
return false;
}
public static void vmBus_send(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
pcallFAll(vm_busListeners_live(), msg, arg);
pcallFAll(vm_busListenersByMessage_live().get(msg), msg, arg);
}
public static void vmBus_send(String msg) {
vmBus_send(msg, (Object) null);
}
public static Method findMethod_cached(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
_MethodCache cache = callOpt_getCache(((Class) o));
List methods = cache.cache.get(method);
if (methods != null)
for (Method m : methods) if (isStaticMethod(m) && findMethod_checkArgs(m, args, false))
return m;
return null;
} else {
_MethodCache cache = callOpt_getCache(o.getClass());
List methods = cache.cache.get(method);
if (methods != null)
for (Method m : methods) if (findMethod_checkArgs(m, args, false))
return m;
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static AutoCloseable dm_vmBus_onMessage(final String msg, final VF1 onMessage) {
return dm_ownResource(vmBus_onMessage(msg, onMessage));
}
public static AutoCloseable dm_vmBus_onMessage(String msg, final VF2 onMessage) {
return dm_ownResource(vmBus_onMessage(msg, onMessage));
}
public static AutoCloseable dm_vmBus_onMessage(String msg, Runnable onMessage) {
return dm_ownResource(vmBus_onMessage(msg, onMessage));
}
public static boolean swic(String a, String b) {
return startsWithIgnoreCase(a, b);
}
public static boolean swic(String a, String b, Matches m) {
if (!swic(a, b))
return false;
m.m = new String[] { substring(a, l(b)) };
return true;
}
public static List dropPunctuation3_keep = ll("*", "<", ">");
public static Map dropPunctuation3_cache = defaultSizeMRUCache();
public static List dropPunctuation3(List tok) {
tok = new ArrayList(tok);
for (int i = 1; i < tok.size(); i += 2) {
String t = tok.get(i);
if (t.length() == 1 && !Character.isLetter(t.charAt(0)) && !Character.isDigit(t.charAt(0)) && !dropPunctuation3_keep.contains(t)) {
tok.set(i - 1, tok.get(i - 1) + tok.get(i + 1));
tok.remove(i);
tok.remove(i);
i -= 2;
}
}
return tok;
}
public static String dropPunctuation3(String s) {
return getOrCreate_f0(dropPunctuation3_cache, s, () -> join(dropPunctuation3(javaTokNoQuotes(s))));
}
public static boolean agiBlue_validPageName(String s) {
s = trim(s);
return nempty(s) && !containsNewLine(s);
}
public static String agiBlue_lookupInSlice_pcall(String sliceID, String q, String... keys) {
try {
return agiBlue_lookupInSlice(sliceID, q, keys);
} catch (Throwable __e) {
return null;
}
}
public static String agiBlue_postInSlice_pcall(String slice, String a, String b, String c) {
try {
return agiBlue_postInSlice(slice, a, b, c);
} catch (Throwable __e) {
return null;
}
}
public static String jextract(String pat, String s) {
return jextract(pat, javaTok(s));
}
public static String jextract(String pat, List tok) {
List tokpat = javaTok(pat);
jfind_preprocess(tokpat);
int i = jfind(tok, tokpat);
if (i < 0)
return null;
int j = i + l(tokpat) - 2;
return joinSubList(tok, i, j);
}
public static Object getOptMC(String field) {
return getOpt(mc(), field);
}
public static String formatWithThousands(long l) {
return formatWithThousandsSeparator(l);
}
public static double fraction(double d) {
return d % 1;
}
public static String n_fancy2(long l, String singular, String plural) {
return formatWithThousandsSeparator(l) + " " + trim(l == 1 ? singular : plural);
}
public static String n_fancy2(Collection l, String singular, String plural) {
return n_fancy2(l(l), singular, plural);
}
public static String n_fancy2(Map m, String singular, String plural) {
return n_fancy2(l(m), singular, plural);
}
public static String n_fancy2(Object[] a, String singular, String plural) {
return n_fancy2(l(a), singular, plural);
}
public static String n_fancy2(MultiSet ms, String singular, String plural) {
return n_fancy2(l(ms), singular, plural);
}
public static String asString(Object o) {
return o == null ? null : o.toString();
}
public static ArrayList emptyList() {
return new ArrayList();
}
public static ArrayList emptyList(int capacity) {
return new ArrayList(max(0, capacity));
}
public static ArrayList emptyList(Iterable l) {
return l instanceof Collection ? emptyList(((Collection) l).size()) : emptyList();
}
public static ArrayList emptyList(Object[] l) {
return emptyList(l(l));
}
public static ArrayList emptyList(Class c) {
return new ArrayList();
}
public static A optParam(ThreadLocal tl, A defaultValue) {
return optPar(tl, defaultValue);
}
public static A optParam(ThreadLocal tl) {
return optPar(tl);
}
public static Object optParam(String name, Map params) {
return mapGet(params, name);
}
public static A optParam(Object[] opt, String name, A defaultValue) {
int n = l(opt);
if (n == 1 && opt[0] instanceof Map) {
Map map = (Map) (opt[0]);
return map.containsKey(name) ? (A) map.get(name) : defaultValue;
}
if (!even(l(opt)))
throw fail("Odd parameter length");
for (int i = 0; i < l(opt); i += 2) if (eq(opt[i], name))
return (A) opt[i + 1];
return defaultValue;
}
public static Object optParam(Object[] opt, String name) {
return optParam(opt, name, null);
}
public static Class> getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
return null;
}
}
public static Class getClass(Object o) {
return o instanceof Class ? (Class) o : o.getClass();
}
public static Class getClass(Object realm, String name) {
try {
try {
return getClass(realm).getClassLoader().loadClass(classNameToVM(name));
} catch (ClassNotFoundException e) {
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String classNameToVM(String name) {
return name.replace(".", "$");
}
public static boolean regexpFind(String pat, String s) {
return regexpFinds(pat, s);
}
public static String discordTokenRegexp() {
return "[MN][A-Za-z\\d]{23}\\.[\\w-]{6}\\.[\\w-]{27}";
}
public static SelfUser jda_selfUser(JDA jda) {
return jda.getSelfUser();
}
public static String ymd() {
return ymd(now());
}
public static String ymd(long now) {
return year(now) + formatInt(month(now), 2) + formatInt(dayOfMonth(now), 2);
}
public static String hms() {
return hms(now());
}
public static String hms(long time) {
return new SimpleDateFormat("HHmmss").format(time);
}
public static File prepareProgramFile(String name) {
return mkdirsForFile(getProgramFile(name));
}
public static File prepareProgramFile(String progID, String name) {
return mkdirsForFile(getProgramFile(progID, name));
}
public static ZipOutputStream newZipOutputStream(String path) {
return newZipOutputStream(new File(path));
}
public static ZipOutputStream newZipOutputStream(File zip) {
try {
return new ZipOutputStream(newFileOutputStream(zip));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static void zip_addTextFile(ZipOutputStream outZip, String name, String text) {
try {
if (text == null)
return;
outZip.putNextEntry(new ZipEntry(name));
byte[] utf8 = toUtf8(text);
outZip.write(utf8, 0, l(utf8));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static A set(A o, String field, Object value) {
if (o == null)
return null;
if (o instanceof Class)
set((Class) o, field, value);
else
try {
Field f = set_findField(o.getClass(), field);
makeAccessible(f);
smartSet(f, o, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
return o;
}
public static void set(Class c, String field, Object value) {
if (c == null)
return;
try {
Field f = set_findStaticField(c, field);
makeAccessible(f);
smartSet(f, null, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Field set_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
public static Field set_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
public static String lines_possiblyRTrim(String originalText, List lines) {
return endsWithNewLine(originalText) ? lines(lines) : lines_rtrim(lines);
}
public static List nempties(Collection c) {
return filterNempty(c);
}
public static List mapLines_tlft(Object f, String text) {
return map(f, tlft(text));
}
public static List mapLines_tlft(String text, F1 f) {
return mapLines_tlft(f, text);
}
public static List mapLines_tlft(F1 f, String text) {
return map(f, tlft(text));
}
public static int countWhere(Collection c, Object... data) {
int n = 0;
if (c != null)
for (Object x : c) if (checkFields(x, data))
++n;
return n;
}
public static Collection values(Map map) {
return map == null ? emptyList() : map.values();
}
public static A keyForValue(B value, Map map) {
return reverseLookup(value, map);
}
public static A keyForValue(Map map, B value) {
return reverseLookup(map, value);
}
public static List synchroList() {
return Collections.synchronizedList(new ArrayList ());
}
public static List synchroList(List l) {
return Collections.synchronizedList(l);
}
public static String standard_toString(Object o) {
if (o == null)
return "null";
String name = shortClassName(o);
Set fields = fieldNames(o);
if (empty(fields))
return name;
return name + "(" + joinWithComma(mapNonNulls(fields, field -> {
Object value = get(o, field);
if (value == null)
return null;
return field + "=" + str(value);
})) + ")";
}
public static ArrayList cloneList(Iterable l) {
return l instanceof Collection ? cloneList((Collection) l) : asList(l);
}
public static ArrayList cloneList(Collection l) {
if (l == null)
return new ArrayList();
synchronized (collectionMutex(l)) {
return new ArrayList (l);
}
}
public static Object pcallF(Object f, Object... args) {
return pcallFunction(f, args);
}
public static A pcallF(F0 f) {
try {
return f == null ? null : f.get();
} catch (Throwable __e) {
return null;
}
}
public static B pcallF(F1 f, A a) {
try {
return f == null ? null : f.get(a);
} catch (Throwable __e) {
return null;
}
}
public static void pcallF(VF1 f, A a) {
try {
if (f != null)
f.get(a);
} catch (Throwable __e) {
_handleException(__e);
}
}
public static void internalFrameTitlePopupMenuItem(JInternalFrame f, final String name, final Object action) {
internalFrameTitlePopupMenu(f, new VF1() {
public void get(JPopupMenu menu) {
try {
addMenuItem(menu, name, action);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "addMenuItem(menu, name, action)";
}
});
}
public static void minimalFrameSize(Component c, int w, int h) {
Container f = getPIFrame(c);
if (f != null)
setSize(f, max(w, getWidth(f)), max(h, getHeight(f)));
}
public static String defaultThreadName_name;
public static String defaultThreadName() {
if (defaultThreadName_name == null)
defaultThreadName_name = "A thread by " + programID();
return defaultThreadName_name;
}
public static Runnable wrapAsActivity(Object r) {
return toRunnable(r);
}
public static Thread newThread(Object runnable) {
return new Thread(_topLevelErrorHandling(toRunnable(runnable)));
}
public static Thread newThread(Object runnable, String name) {
if (name == null)
name = defaultThreadName();
return new Thread(_topLevelErrorHandling(toRunnable(runnable)), name);
}
public static Thread newThread(String name, Object runnable) {
return newThread(runnable, name);
}
public static Runnable toRunnable(final Object o) {
if (o instanceof Runnable)
return (Runnable) o;
return new Runnable() {
public void run() {
try {
callF(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(o)";
}
};
}
public static Map _registerThread_threads;
public static Object _onRegisterThread;
public static Thread _registerThread(Thread t) {
if (_registerThread_threads == null)
_registerThread_threads = newWeakHashMap();
_registerThread_threads.put(t, true);
vm_generalWeakSubMap("thread2mc").put(t, weakRef(mc()));
callF(_onRegisterThread, t);
return t;
}
public static void _registerThread() {
_registerThread(Thread.currentThread());
}
public static Object dm_getModule(Object moduleOrID) {
if (moduleOrID == null || eq(moduleOrID, ""))
return null;
if (isString(moduleOrID) && isIdentifier(((String) moduleOrID)))
return dm_getService(((String) moduleOrID));
if (isStringOrIntOrLong(moduleOrID))
return dm_callOS("getDynModuleByID", str(moduleOrID));
return dm_resolveModule(moduleOrID);
}
public static Object dm_call(Object moduleOrID, String method, Object... args) {
Object mod = dm_getModule(moduleOrID);
if (mod == null)
return null;
AutoCloseable __0 = dm_enter(mod);
try {
return call_withVarargs(mod, method, args);
} finally {
_close(__0);
}
}
public static Object rcall(String method, Object o, Object... args) {
return call_withVarargs(o, method, args);
}
public static List regexpAll(String pattern, String text) {
List matches = new ArrayList();
Matcher matcher = regexp(pattern, text);
while (matcher.find()) matches.add(matcher.group());
return matches;
}
public static Map emptyMap() {
return new HashMap();
}
public static Object vmBus_wrapArgs(Object... args) {
return empty(args) ? null : l(args) == 1 ? args[0] : args;
}
public static Set vm_busListeners_live_cache;
public static Set vm_busListeners_live() {
if (vm_busListeners_live_cache == null)
vm_busListeners_live_cache = vm_busListeners_live_load();
return vm_busListeners_live_cache;
}
public static Set vm_busListeners_live_load() {
return vm_generalIdentityHashSet("busListeners");
}
public static void addIfNotNull(Collection l, A a) {
if (a != null && l != null)
l.add(a);
}
public static void addIfNotNull(MultiSet ms, A a) {
if (a != null && ms != null)
ms.add(a);
}
public static Map vm_busListenersByMessage_live_cache;
public static Map vm_busListenersByMessage_live() {
if (vm_busListenersByMessage_live_cache == null)
vm_busListenersByMessage_live_cache = vm_busListenersByMessage_live_load();
return vm_busListenersByMessage_live_cache;
}
public static Map vm_busListenersByMessage_live_load() {
return vm_generalHashMap("busListenersByMessage");
}
public static String dm_makeNewModuleWithParams(String moduleLibID, Object... params) {
return (String) dm_callOS("makeNewModule", moduleLibID, false, "beforeStart", new VF1() {
public void get(Object mod) {
try {
print("Got module: " + dm_mod(mod));
dm_call(mod, "setFields", params);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "print(\"Got module: \" + dm_mod(mod));\r\n dm_call(mod, 'setFields, params);";
}
});
}
public static void dm_showModule(Object module) {
Object stem = dm_getStem(module);
if (stem != null)
dm_callOS("showModule", stem);
}
public static void dm_showModule() {
dm_showModule(dm_current_mandatory_generic());
}
public static String shortClassName(Object o) {
if (o == null)
return null;
Class c = o instanceof Class ? (Class) o : o.getClass();
String name = c.getName();
return shortenClassName(name);
}
public static boolean hasSuperclassShortNamed(Object o, String name) {
Class c = _getClass(o);
while (c != null) if (shortClassNameIs(c, name))
return true;
else
c = c.getSuperclass();
return false;
}
public static void dm_reloadModuleInBackground(Object module) {
dm_callOS("reloadModuleInBackground", dm_getStem(module));
}
public static void dm_reloadModuleInBackground() {
dm_reloadModuleInBackground(dm_current_mandatory_generic());
}
public static double toMinutes(long ms) {
return ms / 60000.0;
}
public static Object swing(Object f) {
return swingAndWait(f);
}
public static A swing(F0 f) {
return (A) swingAndWait(f);
}
public static A swing(IF0 f) {
return (A) swingAndWait(f);
}
public static A revalidate(final A c) {
if (c == null || !c.isShowing())
return c;
{
swing(new Runnable() {
public void run() {
try {
c.revalidate();
c.repaint();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "// magic combo to actually relayout and repaint\r\n c.revalidate();\r\n c.r...";
}
});
}
return c;
}
public static void revalidate(JFrame f) {
revalidate((Component) f);
}
public static void revalidate(JInternalFrame f) {
revalidate((Component) f);
}
public static String dropPrefix(String prefix, String s) {
return s == null ? null : s.startsWith(prefix) ? s.substring(l(prefix)) : s;
}
public static ActionListener actionListenerInNewThread(final Object runnable) {
return actionListenerInNewThread(runnable, null);
}
public static ActionListener actionListenerInNewThread(final Object runnable, final Object instanceToHold) {
if (runnable instanceof ActionListener)
return (ActionListener) runnable;
return new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent _evt) {
try {
startThread("Action Listener", new Runnable() {
public void run() {
try {
AutoCloseable __0 = holdInstance(instanceToHold);
try {
callF(runnable);
} finally {
_close(__0);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "AutoCloseable __0 = holdInstance(instanceToHold); try {\r\n callF(runnable...";
}
});
} catch (Throwable __e) {
messageBox(__e);
}
}
};
}
public static Map humanizeFormLabel_replacements = litmap("id", "ID", "md5", "MD5");
public static String humanizeFormLabel(String s) {
if (containsSpace(s))
return s;
return firstToUpper(joinWithSpace(replaceElementsUsingMap(splitCamelCase(s), humanizeFormLabel_replacements)).replace("I D", "ID"));
}
public static JTextField jtextfield() {
return jTextField();
}
public static JTextField jtextfield(String text) {
return jTextField(text);
}
public static JTextField jtextfield(Object o) {
return jTextField(o);
}
public static int showForm_defaultGap = 4;
public static int showForm_gapBetweenColumns = 10;
public static JPanel showFormTitled(final String title, final Object... _parts) {
JDesktopPane desktop = mainDesktopPane();
if (desktop != null)
return showInternalFrameFormTitled(desktop, title, _parts);
return swing(new F0() {
public JPanel get() {
try {
final Var frame = new Var();
JPanel panel = showForm_makePanel(false, _parts);
frame.set(showForm_makeFrame(title, panel));
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "final new Var frame;\r\n JPanel panel = showForm_makePanel(false, _p...";
}
});
}
public static JPanel showForm_makePanel(Boolean internalFrame, Object... _parts) {
List out = showForm_arrange1(showForm_makeComponents(internalFrame, _parts));
return vstackWithSpacing(out, showForm_defaultGap);
}
public static String or2(String a, String b) {
return nempty(a) ? a : b;
}
public static String or2(String a, String b, String c) {
return or2(or2(a, b), c);
}
public static String stringOptPar(Object[] params, String name) {
return (String) optPar(params, name);
}
public static String gtt(JTextComponent c) {
return getTextTrim(c);
}
public static String gtt(JComboBox cb) {
return getTextTrim(cb);
}
public static void dm_reloadMe() {
dm_reloadModule(dm_currentModule());
}
public static A dm_ownResource(A resource) {
dm_currentModuleMandatory().ownResource(resource);
return resource;
}
public static AutoCloseable vmBus_onMessage(final String msg, final VF1 onMessage) {
Map map = vm_busListenersByMessage_live();
synchronized (map) {
Set listeners = map.get(msg);
if (listeners == null)
map.put(msg, listeners = syncIdentityHashSet());
return tempAdd(listeners, new VF2() {
public void get(String _msg, Object arg) {
try {
callF(onMessage, arg);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, arg)";
}
});
}
}
public static AutoCloseable vmBus_onMessage(String msg, final VF2 onMessage) {
return vmBus_onMessage(msg, new VF1() {
public void get(Object[] o) {
try {
callF(onMessage, first(o), second(o));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(onMessage, first(o), second(o));";
}
});
}
public static AutoCloseable vmBus_onMessage(String msg, Runnable onMessage) {
return vmBus_onMessage(msg, runnableToVF1(onMessage));
}
public static boolean startsWithIgnoreCase(String a, String b) {
return regionMatchesIC(a, 0, b, 0, b.length());
}
public static Map defaultSizeMRUCache() {
return mruCache(defaultStringTransformerCacheSize());
}
public static B getOrCreate_f0(Map map, A key, F0 create) {
B b = map.get(key);
if (b == null)
mapPut(map, key, b = callF(create));
return b;
}
public static B getOrCreate_f0(Map map, A key, IF0 create) {
B b = map.get(key);
if (b == null)
mapPut(map, key, b = callF(create));
return b;
}
public static List javaTokNoQuotes(String s) {
return quotelessJavaTok(s);
}
public static boolean containsNewLine(String s) {
return contains(s, '\n');
}
public static String agiBlue_lookupInSlice(String sliceID, String q, String... keys) {
return first((List) loadJSONPage(printHidingCredentials(agiBlue_linkForPhrase(q, paramsPlus(paramsWithSameKey("get", keys), "slice", sliceID)))));
}
public static ThreadLocal>> agiBlue_postInSlice_queue = new ThreadLocal();
public static String agiBlue_postInSlice(String slice, String a, String b, String c) {
List> queue = agiBlue_postInSlice_queue.get();
if (queue != null) {
queue.add(ll(slice, a, b, c));
return "Queued";
} else
return loadPage(agiBlueURL() + "/bot/post" + hquery("slice", slice, "q", a, "key", b, "value", c));
}
public static int javaTok_n, javaTok_elements;
public static boolean javaTok_opt = false;
public static List javaTok(String s) {
++javaTok_n;
ArrayList tok = new ArrayList();
int l = s == null ? 0 : s.length();
int i = 0, n = 0;
while (i < l) {
int j = i;
char c, d;
while (j < l) {
c = s.charAt(j);
d = j + 1 >= l ? '\0' : s.charAt(j + 1);
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (c == '/' && d == '*') {
do ++j; while (j < l && !s.substring(j, Math.min(j + 2, l)).equals("*/"));
j = Math.min(j + 2, l);
} else if (c == '/' && d == '/') {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
tok.add(javaTok_substringN(s, i, j));
++n;
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (c == '\'' && Character.isJavaIdentifierStart(d) && i + 2 < l && "'\\".indexOf(s.charAt(i + 2)) < 0) {
j += 2;
while (j < l && Character.isJavaIdentifierPart(s.charAt(j))) ++j;
} else if (c == '\'' || c == '"') {
char opener = c;
++j;
while (j < l) {
int c2 = s.charAt(j);
if (c2 == opener || c2 == '\n' && opener == '\'') {
++j;
break;
} else if (c2 == '\\' && j + 1 < l)
j += 2;
else
++j;
}
} else if (Character.isJavaIdentifierStart(c))
do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || s.charAt(j) == '\''));
else if (Character.isDigit(c)) {
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
if (j < l && s.charAt(j) == 'L')
++j;
} else if (c == '[' && d == '[') {
do ++j; while (j + 1 < l && !s.substring(j, j + 2).equals("]]"));
j = Math.min(j + 2, l);
} else if (c == '[' && d == '=' && i + 2 < l && s.charAt(i + 2) == '[') {
do ++j; while (j + 2 < l && !s.substring(j, j + 3).equals("]=]"));
j = Math.min(j + 3, l);
} else
++j;
tok.add(javaTok_substringC(s, i, j));
++n;
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
javaTok_elements += tok.size();
return tok;
}
public static List javaTok(List tok) {
return javaTokWithExisting(join(tok), tok);
}
public static int jfind(String s, String in) {
return jfind(javaTok(s), in);
}
public static int jfind(List tok, String in) {
return jfind(tok, 1, in);
}
public static int jfind(List tok, int startIdx, String in) {
return jfind(tok, startIdx, in, null);
}
public static int jfind(List tok, String in, Object condition) {
return jfind(tok, 1, in, condition);
}
public static int jfind(List tok, int startIdx, String in, Object condition) {
return jfind(tok, startIdx, javaTokForJFind_array(in), condition);
}
public static int jfind(List tok, List tokin) {
return jfind(tok, 1, tokin);
}
public static int jfind(List tok, int startIdx, List tokin) {
return jfind(tok, startIdx, tokin, null);
}
public static int jfind(List tok, int startIdx, String[] tokinC, Object condition) {
return findCodeTokens(tok, startIdx, false, tokinC, condition);
}
public static int jfind(List tok, int startIdx, List tokin, Object condition) {
return jfind(tok, startIdx, codeTokensAsStringArray(tokin), condition);
}
public static List jfind_preprocess(List tok) {
for (String type : litlist("quoted", "id", "int")) replaceSublist(tok, ll("<", "", type, "", ">"), ll("<" + type + ">"));
replaceSublist(tok, ll("\\", "", "*"), ll("\\*"));
return tok;
}
public static String joinSubList(List l, int i, int j) {
return join(subList(l, i, j));
}
public static String joinSubList(List l, int i) {
return join(subList(l, i));
}
public static String formatWithThousandsSeparator(long l) {
return NumberFormat.getInstance(new Locale("en_US")).format(l);
}
public static int max(int a, int b) {
return Math.max(a, b);
}
public static int max(int a, int b, int c) {
return max(max(a, b), c);
}
public static long max(int a, long b) {
return Math.max((long) a, b);
}
public static long max(long a, long b) {
return Math.max(a, b);
}
public static double max(int a, double b) {
return Math.max((double) a, b);
}
public static float max(float a, float b) {
return Math.max(a, b);
}
public static double max(double a, double b) {
return Math.max(a, b);
}
public static int max(Collection c) {
int x = Integer.MIN_VALUE;
for (int i : c) x = max(x, i);
return x;
}
public static double max(double[] c) {
if (c.length == 0)
return Double.MIN_VALUE;
double x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
public static float max(float[] c) {
if (c.length == 0)
return Float.MAX_VALUE;
float x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
public static byte max(byte[] c) {
byte x = -128;
for (byte d : c) if (d > x)
x = d;
return x;
}
public static short max(short[] c) {
short x = -0x8000;
for (short d : c) if (d > x)
x = d;
return x;
}
public static int max(int[] c) {
int x = Integer.MIN_VALUE;
for (int d : c) if (d > x)
x = d;
return x;
}
public static B mapGet(Map map, A a) {
return map == null || a == null ? null : map.get(a);
}
public static B mapGet(A a, Map map) {
return map == null || a == null ? null : map.get(a);
}
public static boolean even(int i) {
return (i & 1) == 0;
}
public static boolean even(long i) {
return (i & 1) == 0;
}
public static boolean regexpFinds(String pat, String s) {
return regexp(pat, s).find();
}
public static boolean regexpFinds(Pattern pat, String s) {
return regexp(pat, s).find();
}
public static int year() {
return localYear();
}
public static int year(long now) {
return localYear(now);
}
public static String formatInt(int i, int digits) {
return padLeft(str(i), '0', digits);
}
public static String formatInt(long l, int digits) {
return padLeft(str(l), '0', digits);
}
public static int month() {
return localMonth();
}
public static int month(long now) {
return localMonth(now);
}
public static int dayOfMonth() {
return localDayOfMonth();
}
public static int dayOfMonth(long now) {
return localDayOfMonth(now);
}
public static File mkdirsForFile(File file) {
File dir = file.getParentFile();
if (dir != null) {
dir.mkdirs();
if (!dir.isDirectory())
if (dir.isFile())
throw fail("Please delete the file " + f2s(dir) + " - it is supposed to be a directory!");
else
throw fail("Unknown IO exception during mkdirs of " + f2s(file));
}
return file;
}
public static String mkdirsForFile(String path) {
mkdirsForFile(new File(path));
return path;
}
public static File getProgramFile(String progID, String fileName) {
if (new File(fileName).isAbsolute())
return new File(fileName);
return new File(getProgramDir(progID), fileName);
}
public static File getProgramFile(String fileName) {
return getProgramFile(getProgramID(), fileName);
}
public static FileOutputStream newFileOutputStream(File path) throws IOException {
return newFileOutputStream(path.getPath());
}
public static FileOutputStream newFileOutputStream(String path) throws IOException {
return newFileOutputStream(path, false);
}
public static FileOutputStream newFileOutputStream(File path, boolean append) throws IOException {
return newFileOutputStream(path.getPath(), append);
}
public static FileOutputStream newFileOutputStream(String path, boolean append) throws IOException {
mkdirsForFile(path);
FileOutputStream f = new FileOutputStream(path, append);
_registerIO(f, path, true);
return f;
}
public static byte[] toUtf8(String s) {
try {
return s.getBytes("UTF-8");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static void smartSet(Field f, Object o, Object value) throws Exception {
try {
f.set(o, value);
} catch (Exception e) {
Class type = f.getType();
if (type == int.class && value instanceof Long)
value = ((Long) value).intValue();
if (type == LinkedHashMap.class && value instanceof Map) {
f.set(o, asLinkedHashMap((Map) value));
return;
}
try {
if (f.getType() == Concept.Ref.class) {
f.set(o, ((Concept) o).new Ref((Concept) value));
return;
}
if (o instanceof Concept.Ref) {
f.set(o, ((Concept.Ref) o).get());
return;
}
} catch (Throwable _e) {
}
throw e;
}
}
public static boolean endsWithNewLine(String s) {
return endsWith(s, "\n");
}
public static String lines(Iterable lines) {
return fromLines(lines);
}
public static String lines(Object[] lines) {
return fromLines(asList(lines));
}
public static List lines(String s) {
return toLines(s);
}
public static String lines_rtrim(Collection lines) {
return rtrim_fromLines(lines);
}
public static List filterNempty(Collection c) {
List l = new ArrayList();
for (String x : unnull(c)) if (nempty(x))
l.add(x);
return l;
}
public static List tlft(String s) {
return toLinesFullTrim(s);
}
public static List tlft(File f) {
return toLinesFullTrim(f);
}
public static boolean checkFields(Object x, Object... data) {
for (int i = 0; i < l(data); i += 2) if (neq(getOpt(x, (String) data[i]), data[i + 1]))
return false;
return true;
}
public static A reverseLookup(B value, Map map) {
return reverseLookup(map, value);
}
public static A reverseLookup(Map map, B value) {
if (map != null && value != null)
for (A key : map.keySet()) if (eq(map.get(key), value))
return key;
return null;
}
public static Set fieldNames(Object o) {
return allFields(o);
}
public static List mapNonNulls(Iterable l, Object f) {
return mapNonNulls(f, l);
}
public static List mapNonNulls(Object f, Iterable l) {
List x = new ArrayList();
if (l != null)
for (Object o : l) addIfNotNull(x, callF(f, o));
return x;
}
public static List mapNonNulls(Object f, Object[] l) {
List x = new ArrayList();
if (l != null)
for (Object o : l) addIfNotNull(x, callF(f, o));
return x;
}
public static List mapNonNulls(Iterable l, F1 f) {
return mapNonNulls(f, l);
}
public static List mapNonNulls(F1 f, Iterable l) {
List x = new ArrayList();
if (l != null)
for (Object o : l) addIfNotNull(x, callF(f, o));
return x;
}
public static List mapNonNulls(Iterable l, IF1 f) {
List x = emptyList(l);
if (l != null)
for (A o : l) addIfNotNull(x, f.get(o));
return x;
}
public static Object collectionMutex(List l) {
return l;
}
public static Object collectionMutex(Object o) {
if (o instanceof List)
return o;
String c = className(o);
if (eq(c, "java.util.TreeMap$KeySet"))
c = className(o = getOpt(o, "m"));
else if (eq(c, "java.util.HashMap$KeySet"))
c = className(o = get_raw(o, "this$0"));
if (eqOneOf(c, "java.util.TreeMap$AscendingSubMap", "java.util.TreeMap$DescendingSubMap"))
c = className(o = get_raw(o, "m"));
return o;
}
public static Object pcallFunction(Object f, Object... args) {
try {
return callFunction(f, args);
} catch (Throwable __e) {
_handleException(__e);
}
return null;
}
public static volatile PersistableThrowable _handleException_lastException;
public static List _handleException_onException = synchroList(ll("printStackTrace2"));
public static void _handleException(Throwable e) {
_handleException_lastException = persistableThrowable(e);
Throwable e2 = innerException(e);
if (e2.getClass() == RuntimeException.class && eq(e2.getMessage(), "Thread cancelled.") || e2 instanceof InterruptedException)
return;
for (Object f : cloneList(_handleException_onException)) try {
callF(f, e);
} catch (Throwable e3) {
printStackTrace2(e3);
}
}
public static void internalFrameTitlePopupMenu(final JInternalFrame f, final Object... params) {
{
swing(new Runnable() {
public void run() {
try {
Object menuMaker;
if (l(params) == 1 && !(params[0] instanceof JMenu))
menuMaker = params[0];
else
menuMaker = new VF1() {
public void get(JPopupMenu menu) {
try {
addMenuItems(menu, params);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "addMenuItems(menu, params)";
}
};
Component titleComponent = getInternalFrameTitlePaneComponent(f);
if (!(titleComponent instanceof JComponent))
print("Can't add internal frame title popup menu!");
else {
componentPopupMenu((JComponent) titleComponent, menuMaker);
setOpt(componentPopupMenu_initForComponent((JComponent) titleComponent), "internalFrameLeftButtonMagic", isTrue(vm_generalMap_get("internalFramePopupOnLeftButton")));
}
componentPopupMenu(f, menuMaker);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Object menuMaker;\r\n if (l(params) == 1 && !(params[0] instanceof JMenu))\r\n...";
}
});
}
}
public static void addMenuItem(JPopupMenu menu, String text, Object action) {
menu.add(jmenuItem(text, action));
}
public static void addMenuItem(JPopupMenu menu, JMenuItem menuItem) {
menu.add(menuItem);
}
public static void addMenuItem(JMenu menu, String text, Object action) {
menu.add(jmenuItem(text, action));
}
public static void addMenuItem(Menu menu, String text, Object action) {
menu.add(menuItem(text, action));
}
public static void addMenuItem(JMenu menu, JMenuItem menuItem) {
menu.add(menuItem);
}
public static Container getPIFrame(Component c) {
return (Container) getPossiblyInternalFrame(c);
}
public static A setSize(final A c, final int w, final int h) {
if (c != null) {
swing(new Runnable() {
public void run() {
try {
c.setSize(w, h);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "c.setSize(w, h);";
}
});
}
return c;
}
public static void setSize(Component c, Dimension d) {
setSize(c, d.width, d.height);
}
public static int getWidth(Component c) {
return c == null ? 0 : (int) swingCall(c, "getWidth");
}
public static int getHeight(Component c) {
return c == null ? 0 : (int) swingCall(c, "getHeight");
}
public static Runnable _topLevelErrorHandling(final Runnable runnable) {
final Object info = _threadInfo();
return new Runnable() {
public void run() {
try {
try {
_threadInheritInfo(info);
runnable.run();
} catch (Throwable __e) {
_handleException(__e);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pcall {\r\n _threadInheritInfo(info);\r\n runnable.run();\r\n }";
}
};
}
public static WeakReference weakRef(A a) {
return newWeakReference(a);
}
public static boolean isString(Object o) {
return o instanceof String;
}
public static boolean isIdentifier(String s) {
return isJavaIdentifier(s);
}
public static Object dm_getService(String serviceName) {
return empty(serviceName) ? null : dm_getModule(vmBus_query(assertIdentifier(serviceName)));
}
public static boolean isStringOrIntOrLong(Object o) {
return o instanceof String || o instanceof Integer || o instanceof Long;
}
public static Object dm_callOS(String functionName, Object... args) {
return call(dm_os(), functionName, args);
}
public static Object dm_resolveModule(Object moduleOrStem) {
return dm_callOS("resolveModule", moduleOrStem);
}
public static AutoCloseable dm_enter(Object mod) {
return (AutoCloseable) callOpt(dm_getModule(mod), "enter");
}
public static Matcher regexp(String pat, String s) {
return regexp(compileRegexp(pat), unnull(s));
}
public static Matcher regexp(Pattern pat, String s) {
return pat.matcher(unnull(s));
}
public static Pattern regexp(String pat) {
return compileRegexp(pat);
}
public static Object dm_mod(Object moduleOrID) {
return dm_getModule(moduleOrID);
}
public static Object dm_getStem(Object moduleOrID) {
if (isStringOrIntOrLong(moduleOrID))
return dm_getStemByID(moduleOrID);
return or(getOpt(dm_getModule(moduleOrID), "_host"), moduleOrID);
}
public static String shortenClassName(String name) {
if (name == null)
return null;
int i = lastIndexOf(name, "$");
if (i < 0)
i = lastIndexOf(name, ".");
return i < 0 ? name : substring(name, i + 1);
}
public static boolean shortClassNameIs(Object o, String name) {
return eq(shortClassName(o), name);
}
public static void swingAndWait(Runnable r) {
try {
if (isAWTThread())
r.run();
else
EventQueue.invokeAndWait(addThreadInfoToRunnable(r));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static Object swingAndWait(final Object f) {
if (isAWTThread())
return callF(f);
else {
final Var result = new Var();
swingAndWait(new Runnable() {
public void run() {
try {
result.set(callF(f));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "result.set(callF(f));";
}
});
return result.get();
}
}
public static ThreadLocal> holdInstance_l = new ThreadLocal();
public static AutoCloseable holdInstance(Object o) {
if (o == null)
return null;
listThreadLocalAdd(holdInstance_l, o);
return new AutoCloseable() {
public void close() {
listThreadLocalPopLast(holdInstance_l);
}
};
}
public static void messageBox(final String msg) {
if (headless())
print(msg);
else {
swing(new Runnable() {
public void run() {
try {
JOptionPane.showMessageDialog(null, msg, "JavaX", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JOptionPane.showMessageDialog(null, msg, \"JavaX\", JOptionPane.INFORMATION_MES...";
}
});
}
}
public static void messageBox(Throwable e) {
printStackTrace(e);
messageBox(hideCredentials(innerException2(e)));
}
public static HashMap litmap(Object... x) {
HashMap map = new HashMap();
litmap_impl(map, x);
return map;
}
public static void litmap_impl(Map map, Object... x) {
if (x != null)
for (int i = 0; i < x.length - 1; i += 2) if (x[i + 1] != null)
map.put(x[i], x[i + 1]);
}
public static boolean containsSpace(String s) {
return containsSpaces(s);
}
public static String firstToUpper(String s) {
if (empty(s))
return s;
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
}
public static List replaceElementsUsingMap(Iterable l, final Map map) {
return map(l, new F1 () {
public A get(A a) {
try {
return getOrKeep(map, a);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "getOrKeep(map, a)";
}
});
}
public static List splitCamelCase(String s) {
return ai_splitCamelCase(s);
}
public static JTextField jTextField() {
return jTextField("");
}
public static JTextField jTextField(final String text) {
return swing(new F0() {
public JTextField get() {
try {
JTextField tf = new JTextField(unnull(text));
standardTextFieldPopupMenu(tf);
jenableUndoRedo(tf);
tf.selectAll();
return tf;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JTextField tf = new JTextField(unnull(text));\r\n standardTextFieldPopupMenu...";
}
});
}
public static JTextField jTextField(Object o) {
return jTextField(strOrEmpty(o));
}
public static JDesktopPane mainDesktopPane_value;
public static JDesktopPane mainDesktopPane() {
return mainDesktopPane_value;
}
public static JPanel showInternalFrameFormTitled(final JDesktopPane desktop, final String title, final Object... _parts) {
JPanel panel = showForm_makePanel(true, _parts);
showForm_makeInternalFrame(desktop, title, panel);
return panel;
}
public static JFrame showForm_makeFrame(String title, JPanel panel) {
return handleEscapeKey(minFrameWidth(showPackedFrame(title, withMargin(panel)), 400));
}
public static List showForm_arrange1(List> l) {
int minW = showForm_leftWidth(l);
List out = new ArrayList();
for (List row : l) out.add(westAndCenter(withRightMargin(showForm_gapBetweenColumns, jMinWidth(minW, first(row))), second(row)));
return out;
}
public static List> showForm_makeComponents(final Boolean internalFrame, Object... _parts) {
List> l = new ArrayList();
List parts = asList(_parts);
JButton submitButton = null;
for (int i = 0; i < l(parts); i++) {
final Object o = parts.get(i), next = get(parts, i + 1);
if (o instanceof String && next instanceof Component)
setComponentID((Component) next, (String) o);
if (o instanceof Component || o instanceof String || next instanceof Component) {
l.add(mapLL("wrapForSmartAdd", o == null ? new JPanel() : o instanceof String ? humanizeFormLabel((String) o) : o, next));
if (next instanceof JButton && submitButton == null)
submitButton = (JButton) next;
i++;
} else if (isRunnable(o))
l.add(mapLL("wrapForSmartAdd", null, submitButton = jbutton(showFormSubmitButtonName(), new Runnable() {
public void run() {
try {
Object result = call(o);
if (neq(Boolean.FALSE, result)) {
if (isTrue(internalFrame))
disposeInternalFrame(heldInstance(JButton.class));
else if (isFalse(internalFrame))
disposeFrame(heldInstance(JButton.class));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Object result = call(o);\r\n if (neq(Boolean.FALSE, result)) {\r\n ...";
}
})));
else
print("showForm: Unknown element type: " + getClassName(o));
}
if (submitButton != null) {
final JButton _submitButton = submitButton;
onEnterInAllTextFields(concatLists(l), new Runnable() {
public void run() {
try {
clickButton(_submitButton);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "clickButton(_submitButton)";
}
});
}
for (List row : l) {
JComponent left = first(row);
if (left instanceof JLabel)
makeBold((JLabel) left).setVerticalAlignment(JLabel.TOP);
}
return l;
}
public static int vstackWithSpacing_default = 10;
public static JPanel vstackWithSpacing(final List parts) {
return vstackWithSpacing(parts, vstackWithSpacing_default);
}
public static JPanel vstackWithSpacing(final List parts, final int spacing) {
return swing(new F0() {
public JPanel get() {
try {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(spacing / 2, 0, spacing / 2, 0);
smartAddWithLayout(panel, gbc, toObjectArray(nonNulls(parts)));
gbc.weighty = 1;
gbc.insets = new Insets(0, 0, 0, 0);
panel.add(jrigid(), gbc);
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel panel = new JPanel(new GridBagLayout);\r\n new GridBagConstraints gbc...";
}
});
}
public static JPanel vstackWithSpacing(Component... parts) {
return vstackWithSpacing(asList(parts), vstackWithSpacing_default);
}
public static String getTextTrim(JTextComponent c) {
return trim(getText(c));
}
public static String getTextTrim(JComboBox cb) {
return trim(getText(cb));
}
public static String getTextTrim(JComponent c) {
if (c instanceof JLabel)
return trim(((JLabel) c).getText());
if (c instanceof JComboBox)
return getTextTrim((JComboBox) c);
return getTextTrim((JTextComponent) c);
}
public static Throwable printStackTrace2(Throwable e) {
print(getStackTrace2(e));
return e;
}
public static void printStackTrace2() {
printStackTrace2(new Throwable());
}
public static void printStackTrace2(String msg) {
printStackTrace2(new Throwable(msg));
}
public static DynModule dm_currentModuleMandatory() {
return dm_current_mandatory();
}
public static Set syncIdentityHashSet() {
return (Set) synchronizedSet(identityHashSet());
}
public static AutoCloseable tempAdd(final Collection l, final A a) {
if (l == null || l.contains(a))
return null;
l.add(a);
return new AutoCloseable() {
public String toString() {
return "l.remove(a);";
}
public void close() throws Exception {
l.remove(a);
}
};
}
public static A second(List l) {
return get(l, 1);
}
public static A second(Iterable l) {
if (l == null)
return null;
Iterator it = iterator(l);
if (!it.hasNext())
return null;
it.next();
return it.hasNext() ? it.next() : null;
}
public static A second(A[] bla) {
return bla == null || bla.length <= 1 ? null : bla[1];
}
public static B second(Pair p) {
return p == null ? null : p.b;
}
public static char second(String s) {
return charAt(s, 1);
}
public static A third(List l) {
return _get(l, 2);
}
public static A third(Iterable l) {
if (l == null)
return null;
Iterator it = iterator(l);
for (int _repeat_0 = 0; _repeat_0 < 2; _repeat_0++) {
if (!it.hasNext())
return null;
it.next();
}
return it.hasNext() ? it.next() : null;
}
public static A third(A[] bla) {
return bla == null || bla.length <= 2 ? null : bla[2];
}
public static VF1 runnableToVF1(final Runnable r) {
return r == null ? null : new VF1 () {
public void get(A a) {
try {
r.run();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "r.run()";
}
};
}
public static boolean regionMatchesIC(String a, int offsetA, String b, int offsetB, int len) {
return a != null && a.regionMatches(true, offsetA, b, offsetB, len);
}
public static Map mruCache(int maxSize) {
return synchronizedMRUCache(maxSize);
}
public static int defaultStringTransformerCacheSize() {
return 1000;
}
public static void mapPut(Map map, A key, B value) {
if (map != null && key != null && value != null)
map.put(key, value);
}
public static List quotelessJavaTok(String s) {
ArrayList tok = new ArrayList();
int l = s.length();
int i = 0, n = 0;
while (i < l) {
int j = i;
char c, d;
while (j < l) {
c = s.charAt(j);
d = j + 1 >= l ? '\0' : s.charAt(j + 1);
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (c == '/' && d == '*') {
do ++j; while (j < l && !s.substring(j, Math.min(j + 2, l)).equals("*/"));
j = Math.min(j + 2, l);
} else if (c == '/' && d == '/') {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
tok.add(javaTok_substringN(s, i, j));
++n;
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (Character.isJavaIdentifierStart(c))
do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || "'".indexOf(s.charAt(j)) >= 0));
else if (Character.isDigit(c)) {
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
if (j < l && s.charAt(j) == 'L')
++j;
} else
++j;
tok.add(javaTok_substringC(s, i, j));
++n;
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
return tok;
}
public static Object loadJSONPage(String url) {
return jsonDecode(loadPage(url));
}
public static A printHidingCredentials(A o) {
print(hideCredentials(str(o)));
return o;
}
public static String agiBlue_linkForPhrase(String phrase, Object... additionalParams) {
return agiBlueURL() + hquery(arrayPlus(additionalParams, "q", phrase));
}
public static Object[] paramsPlus(Object[] a1, Object... a2) {
if (a2 == null)
return a1;
if (a1 == null)
return a2;
if (l(a1) == 1 && a1[0] instanceof Map)
return new Object[] { mapPlus((Map) a1[0], a2) };
assertEvenLength(a1);
assertEvenLength(a2);
Map map = paramsToOrderedMap(a1);
int n = l(a2);
for (int i = 0; i < n; i += 2) {
Object key = a2[i];
if (key != null)
map.put(key, a2[i + 1]);
}
return mapToParams(map);
}
public static Object[] paramsWithSameKey(Object key, Collection values) {
return paramsWithSameKey(key, asObjectArray(values));
}
public static Object[] paramsWithSameKey(Object key, Object... values) {
int n = l(values);
Object[] o = new Object[n * 2];
for (int i = 0; i < n; i++) {
o[i * 2] = key;
o[i * 2 + 1] = values[i];
}
return o;
}
public static boolean agiBlueURL_noHTTPS = false;
public static String agiBlueURL_url = "https://agi.blue";
public static String agiBlueURL() {
return agiBlueURL_noHTTPS ? replacePrefix("https://", "http://", agiBlueURL_url) : agiBlueURL_url;
}
public static String hquery(Map params) {
return htmlQuery(params);
}
public static String hquery(Object... data) {
return htmlQuery(data);
}
public static String javaTok_substringN(String s, int i, int j) {
if (i == j)
return "";
if (j == i + 1 && s.charAt(i) == ' ')
return " ";
return s.substring(i, j);
}
public static String javaTok_substringC(String s, int i, int j) {
return s.substring(i, j);
}
public static List javaTokWithExisting(String s, List existing) {
++javaTok_n;
int nExisting = javaTok_opt && existing != null ? existing.size() : 0;
ArrayList tok = existing != null ? new ArrayList(nExisting) : new ArrayList();
int l = s.length();
int i = 0, n = 0;
while (i < l) {
int j = i;
char c, d;
while (j < l) {
c = s.charAt(j);
d = j + 1 >= l ? '\0' : s.charAt(j + 1);
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++j;
else if (c == '/' && d == '*') {
do ++j; while (j < l && !s.substring(j, Math.min(j + 2, l)).equals("*/"));
j = Math.min(j + 2, l);
} else if (c == '/' && d == '/') {
do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0);
} else
break;
}
if (n < nExisting && javaTokWithExisting_isCopyable(existing.get(n), s, i, j))
tok.add(existing.get(n));
else
tok.add(javaTok_substringN(s, i, j));
++n;
i = j;
if (i >= l)
break;
c = s.charAt(i);
d = i + 1 >= l ? '\0' : s.charAt(i + 1);
if (c == '\'' && Character.isJavaIdentifierStart(d) && i + 2 < l && "'\\".indexOf(s.charAt(i + 2)) < 0) {
j += 2;
while (j < l && Character.isJavaIdentifierPart(s.charAt(j))) ++j;
} else if (c == '\'' || c == '"') {
char opener = c;
++j;
while (j < l) {
if (s.charAt(j) == opener) {
++j;
break;
} else if (s.charAt(j) == '\\' && j + 1 < l)
j += 2;
else
++j;
}
} else if (Character.isJavaIdentifierStart(c))
do ++j; while (j < l && (Character.isJavaIdentifierPart(s.charAt(j)) || "'".indexOf(s.charAt(j)) >= 0));
else if (Character.isDigit(c)) {
do ++j; while (j < l && Character.isDigit(s.charAt(j)));
if (j < l && s.charAt(j) == 'L')
++j;
} else if (c == '[' && d == '[') {
do ++j; while (j + 1 < l && !s.substring(j, j + 2).equals("]]"));
j = Math.min(j + 2, l);
} else if (c == '[' && d == '=' && i + 2 < l && s.charAt(i + 2) == '[') {
do ++j; while (j + 2 < l && !s.substring(j, j + 3).equals("]=]"));
j = Math.min(j + 3, l);
} else
++j;
if (n < nExisting && javaTokWithExisting_isCopyable(existing.get(n), s, i, j))
tok.add(existing.get(n));
else
tok.add(javaTok_substringC(s, i, j));
++n;
i = j;
}
if ((tok.size() % 2) == 0)
tok.add("");
javaTok_elements += tok.size();
return tok;
}
public static boolean javaTokWithExisting_isCopyable(String t, String s, int i, int j) {
return t.length() == j - i && s.regionMatches(i, t, 0, j - i);
}
public static Map javaTokForJFind_array_cache = synchronizedMRUCache(1000);
public static String[] javaTokForJFind_array(String s) {
String[] tok = javaTokForJFind_array_cache.get(s);
if (tok == null)
javaTokForJFind_array_cache.put(s, tok = codeTokensAsStringArray(jfind_preprocess(javaTok(s))));
return tok;
}
public static int findCodeTokens(List tok, String... tokens) {
return findCodeTokens(tok, 1, false, tokens);
}
public static int findCodeTokens(List tok, boolean ignoreCase, String... tokens) {
return findCodeTokens(tok, 1, ignoreCase, tokens);
}
public static int findCodeTokens(List tok, int startIdx, boolean ignoreCase, String... tokens) {
return findCodeTokens(tok, startIdx, ignoreCase, tokens, null);
}
public static HashSet findCodeTokens_specials = lithashset("*", "", "", "", "\\*");
public static int findCodeTokens_bails, findCodeTokens_nonbails;
public static interface findCodeTokens_Matcher {
public boolean get(String token);
}
public static int findCodeTokens(List tok, int startIdx, boolean ignoreCase, String[] tokens, Object condition) {
int end = tok.size() - tokens.length * 2 + 2, nTokens = tokens.length;
int i = startIdx | 1;
String firstToken = tokens[0];
if (!ignoreCase && !findCodeTokens_specials.contains(firstToken)) {
while (i < end && !firstToken.equals(tok.get(i))) i += 2;
}
findCodeTokens_Matcher[] matchers = new findCodeTokens_Matcher[nTokens];
for (int j = 0; j < nTokens; j++) {
String p = tokens[j];
findCodeTokens_Matcher matcher;
if (p.equals("*"))
matcher = t -> true;
else if (p.equals(""))
matcher = t -> isQuoted(t);
else if (p.equals(""))
matcher = t -> isIdentifier(t);
else if (p.equals(""))
matcher = t -> isInteger(t);
else if (p.equals("\\*"))
matcher = t -> t.equals("*");
else if (ignoreCase)
matcher = t -> eqic(p, t);
else
matcher = t -> t.equals(p);
matchers[j] = matcher;
}
outer: for (; i < end; i += 2) {
for (int j = 0; j < nTokens; j++) if (!matchers[j].get(tok.get(i + j * 2)))
continue outer;
if (condition == null || checkTokCondition(condition, tok, i - 1))
return i;
}
return -1;
}
public static String[] codeTokensAsStringArray(List tok) {
int n = max(0, (l(tok) - 1) / 2);
String[] out = new String[n];
for (int i = 0; i < n; i++) out[i] = tok.get(i * 2 + 1);
return out;
}
public static ArrayList litlist(A... a) {
ArrayList l = new ArrayList(a.length);
for (A x : a) l.add(x);
return l;
}
public static List replaceSublist(List l, List x, List y) {
if (x == null)
return l;
int i = 0;
while (true) {
i = indexOfSubList(l, x, i);
if (i < 0)
break;
replaceSublist(l, i, i + l(x), y);
i += l(y);
}
return l;
}
public static List replaceSublist(List l, int fromIndex, int toIndex, List y) {
int n = y.size(), toIndex_new = fromIndex + n;
if (toIndex_new < toIndex) {
removeSubList(l, toIndex_new, toIndex);
copyListPart(y, 0, l, fromIndex, n);
} else {
copyListPart(y, 0, l, fromIndex, toIndex - fromIndex);
if (toIndex_new > toIndex)
l.addAll(toIndex, subList(y, toIndex - fromIndex));
}
return l;
}
public static List subList(List l, int startIndex) {
return subList(l, startIndex, l(l));
}
public static List subList(int startIndex, int endIndex, List l) {
return subList(l, startIndex, endIndex);
}
public static List subList(List l, int startIndex, int endIndex) {
if (l == null)
return null;
int n = l(l);
startIndex = Math.max(0, startIndex);
endIndex = Math.min(n, endIndex);
if (startIndex >= endIndex)
return ll();
if (startIndex == 0 && endIndex == n)
return l;
return l.subList(startIndex, endIndex);
}
public static int localYear() {
return localYear(now());
}
public static int localYear(long time) {
return parseInt(simpleDateFormat_local("yyyy").format(time));
}
public static String padLeft(String s, char c, int n) {
return rep(c, n - l(s)) + s;
}
public static String padLeft(String s, int n) {
return padLeft(s, ' ', n);
}
public static int localMonth(long time) {
return parseInt(simpleDateFormat_local("MM").format(time));
}
public static int localMonth() {
return localMonth(now());
}
public static int localDayOfMonth(long time) {
return parseInt(simpleDateFormat_local("dd").format(time));
}
public static int localDayOfMonth() {
return localDayOfMonth(now());
}
public static String f2s(File f) {
return f == null ? null : f.getAbsolutePath();
}
public static String f2s(String s) {
return f2s(newFile(s));
}
public static String f2s(java.nio.file.Path p) {
return p == null ? null : f2s(p.toFile());
}
public static File getProgramDir() {
return programDir();
}
public static File getProgramDir(String snippetID) {
return programDir(snippetID);
}
public static void _registerIO(Object object, String path, boolean opened) {
}
public static LinkedHashMap asLinkedHashMap(Map map) {
if (map instanceof LinkedHashMap)
return (LinkedHashMap) map;
LinkedHashMap m = new LinkedHashMap();
if (map != null)
synchronized (collectionMutex(map)) {
m.putAll(map);
}
return m;
}
public static boolean endsWith(String a, String b) {
return a != null && a.endsWith(b);
}
public static boolean endsWith(String a, char c) {
return nempty(a) && lastChar(a) == c;
}
public static boolean endsWith(String a, String b, Matches m) {
if (!endsWith(a, b))
return false;
m.m = new String[] { dropLast(l(b), a) };
return true;
}
public static String fromLines(Iterable lines) {
StringBuilder buf = new StringBuilder();
if (lines != null)
for (Object line : lines) buf.append(str(line)).append('\n');
return buf.toString();
}
public static String fromLines(String... lines) {
return fromLines(asList(lines));
}
public static IterableIterator toLines(File f) {
return linesFromFile(f);
}
public static List toLines(String s) {
List lines = new ArrayList();
if (s == null)
return lines;
int start = 0;
while (true) {
int i = toLines_nextLineBreak(s, start);
if (i < 0) {
if (s.length() > start)
lines.add(s.substring(start));
break;
}
lines.add(s.substring(start, i));
if (s.charAt(i) == '\r' && i + 1 < s.length() && s.charAt(i + 1) == '\n')
i += 2;
else
++i;
start = i;
}
return lines;
}
public static int toLines_nextLineBreak(String s, int start) {
for (int i = start; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '\r' || c == '\n')
return i;
}
return -1;
}
public static String rtrim_fromLines(Collection lines) {
StringBuilder buf = new StringBuilder();
if (lines != null) {
boolean first = true;
for (Object line : lines) {
if (first)
first = false;
else
buf.append('\n');
buf.append(str(line));
}
}
return buf.toString();
}
public static List toLinesFullTrim(String s) {
List l = new ArrayList();
for (String line : toLines(s)) if (nempty(line = trim(line)))
l.add(line);
return l;
}
public static List toLinesFullTrim(File f) {
List l = new ArrayList();
for (String line : linesFromFile(f)) if (nempty(line = trim(line)))
l.add(line);
return l;
}
public static Set allFields(Object o) {
TreeSet fields = new TreeSet();
Class _c = _getClass(o);
do {
for (Field f : _c.getDeclaredFields()) fields.add(f.getName());
_c = _c.getSuperclass();
} while (_c != null);
return fields;
}
public static String className(Object o) {
return getClassName(o);
}
public static Object callFunction(Object f, Object... args) {
return callF(f, args);
}
public static PersistableThrowable persistableThrowable(Throwable e) {
return e == null ? null : new PersistableThrowable(e);
}
public static Throwable innerException(Throwable e) {
return getInnerException(e);
}
public static void addMenuItems(JMenu m, Object... x) {
fillJMenu(m, x);
}
public static void addMenuItems(JPopupMenu m, Object... x) {
fillJPopupMenu(m, x);
}
public static JComponent getInternalFrameTitlePaneComponent(JInternalFrame f) {
return (JComponent) childWithClassNameEndingWith(f, "InternalFrameTitlePane");
}
public static Object vm_generalMap_get(Object key) {
return vm_generalMap().get(key);
}
public static boolean jmenuItem_newThreads = false;
public static JMenuItem jmenuItem(final String text) {
return jMenuItem(text, null);
}
public static JMenuItem jmenuItem(final String text, final Object r) {
return swing(new F0() {
public JMenuItem get() {
try {
Pair p = jmenu_autoMnemonic(dropPrefix("[disabled] ", text));
JMenuItem mi = new JMenuItem(p.a);
if (startsWith(text, "[disabled] "))
disableMenuItem(mi);
if (p.b != 0)
mi.setMnemonic(p.b);
mi.addActionListener(jmenuItem_newThreads ? actionListenerInNewThread(r) : actionListener(r));
return mi;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Pair p = jmenu_autoMnemonic(dropPrefix(\"[disabled] \", text));\r\n JM...";
}
});
}
public static MenuItem menuItem(String text, final Object r) {
MenuItem mi = new MenuItem(text);
mi.addActionListener(actionListener(r));
return mi;
}
public static RootPaneContainer getPossiblyInternalFrame(Component c) {
JInternalFrame f = getInternalFrame(c);
if (f != null)
return f;
return optCast(RootPaneContainer.class, getWindow(c));
}
public static Object swingCall(final Object o, final String method, final Object... args) {
return swing(new F0() {
public Object get() {
try {
return call(o, method, args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret call(o, method, args);";
}
});
}
public static WeakReference newWeakReference(A a) {
return a == null ? null : new WeakReference(a);
}
public static boolean isJavaIdentifier(String s) {
if (empty(s) || !Character.isJavaIdentifierStart(s.charAt(0)))
return false;
for (int i = 1; i < s.length(); i++) if (!Character.isJavaIdentifierPart(s.charAt(i)))
return false;
return true;
}
public static Object vmBus_query(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
{
Object __1 = pcallFAll_returnFirstNotNull(vm_busListeners_live(), msg, arg);
if (__1 != null)
return __1;
}
return pcallFAll_returnFirstNotNull(vm_busListenersByMessage_live().get(msg), msg, arg);
}
public static Object vmBus_query(String msg) {
return vmBus_query(msg, (Object) null);
}
public static String assertIdentifier(String s) {
return assertIsIdentifier(s);
}
public static String assertIdentifier(String msg, String s) {
return assertIsIdentifier(msg, s);
}
public static Object dm_os() {
{
Object __1 = vm_generalMap_get("stefansOS");
if (__1 != null)
return __1;
}
return creator();
}
public static Map compileRegexp_cache = syncMRUCache(10);
public static java.util.regex.Pattern compileRegexp(String pat) {
java.util.regex.Pattern p = compileRegexp_cache.get(pat);
if (p == null) {
compileRegexp_cache.put(pat, p = java.util.regex.Pattern.compile(pat));
}
return p;
}
public static Object dm_getStemByID(Object id) {
return dm_callOS("getModuleByID", str(id));
}
public static int lastIndexOf(String a, String b) {
return a == null || b == null ? -1 : a.lastIndexOf(b);
}
public static int lastIndexOf(String a, char b) {
return a == null ? -1 : a.lastIndexOf(b);
}
public static Runnable addThreadInfoToRunnable(final Object r) {
final Object info = _threadInfo();
return info == null ? asRunnable(r) : new Runnable() {
public void run() {
try {
_inheritThreadInfo(info);
callF(r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "_inheritThreadInfo(info); callF(r);";
}
};
}
public static void listThreadLocalAdd(ThreadLocal> tl, A a) {
List l = tl.get();
if (l == null)
tl.set(l = new ArrayList());
l.add(a);
}
public static A listThreadLocalPopLast(ThreadLocal> tl) {
List l = tl.get();
if (l == null)
return null;
A a = popLast(l);
if (empty(l))
tl.set(null);
return a;
}
public static boolean headless() {
return isHeadless();
}
public static A printStackTrace(A e) {
print(getStackTrace(e));
return e;
}
public static void printStackTrace() {
printStackTrace(new Throwable());
}
public static void printStackTrace(String msg) {
printStackTrace(new Throwable(msg));
}
public static void printStackTrace(String msg, Throwable e) {
printStackTrace(new Throwable(msg, e));
}
public static String hideCredentials(URL url) {
return url == null ? null : hideCredentials(str(url));
}
public static String hideCredentials(String url) {
try {
if (startsWithOneOf(url, "http://", "https://") && isAGIBlueDomain(hostNameFromURL(url)))
return url;
} catch (Throwable e) {
print("HideCredentials", e);
}
return url.replaceAll("([&?])(_pass|key)=[^&\\s\"]*", "$1$2=");
}
public static String hideCredentials(Object o) {
return hideCredentials(str(o));
}
public static Throwable innerException2(Throwable e) {
if (e == null)
return null;
while (empty(e.getMessage()) && e.getCause() != null) e = e.getCause();
return e;
}
public static boolean containsSpaces(String s) {
return indexOf(s, ' ') >= 0;
}
public static A getOrKeep(Map map, A a) {
if (map == null)
return a;
A v = map.get(a);
return v != null ? v : a;
}
public static List ai_splitCamelCase(String s) {
int j = 0;
List l = new ArrayList();
if (isAllUpperCase(s)) {
l.add(s);
return l;
}
for (int i = 0; i < l(s); i++) if (i > j && isUpperCaseLetter(s.charAt(i))) {
l.add(substring(s, j, i));
j = i;
}
if (j < l(s))
l.add(substring(s, j));
return l;
}
public static JTextField standardTextFieldPopupMenu(final JTextField tf) {
final WeakReference ref = weakRef(tf);
componentPopupMenuItem(tf, "Copy text to clipboard", new Runnable() {
public void run() {
try {
copyTextToClipboard(ref.get().getText());
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "copyTextToClipboard(ref.get().getText())";
}
});
componentPopupMenuItem(tf, "Paste", new Runnable() {
public void run() {
try {
ref.get().paste();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ref.get().paste()";
}
});
return tf;
}
public static A jenableUndoRedo(final A textcomp) {
{
swing(new Runnable() {
public void run() {
try {
final UndoManager undo = new UndoManager();
vm_generalWeakSet("Undo Managers").add(undo);
textcomp.getDocument().addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent evt) {
undo.addEdit(evt.getEdit());
}
});
textcomp.getActionMap().put("Undo", abstractAction("Undo", new Runnable() {
public void run() {
try {
if (undo.canUndo())
undo.undo();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (undo.canUndo()) undo.undo()";
}
}));
textcomp.getActionMap().put("Redo", abstractAction("Redo", new Runnable() {
public void run() {
try {
if (undo.canRedo())
undo.redo();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (undo.canRedo()) undo.redo()";
}
}));
textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo");
textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "final new UndoManager undo;\r\n vm_generalWeakSet(\"Undo Managers\").add(undo)...";
}
});
}
return textcomp;
}
public static String strOrEmpty(Object o) {
return o == null ? "" : str(o);
}
public static JInternalFrame showForm_makeInternalFrame(JDesktopPane desktop, String title, JPanel panel) {
JInternalFrame f = addInternalFrame(desktop, title, withMargin(panel));
minInternalFrameWidth(f, 400);
packInternalFrameVertically(f);
centerInternalFrame(f);
return f;
}
public static JFrame handleEscapeKey(final JFrame frame) {
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
frame.getRootPane().registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
frame.dispose();
}
}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
return frame;
}
public static JFrame minFrameWidth(JFrame frame, int w) {
if (frame != null && frame.getWidth() < w)
frame.setSize(w, frame.getHeight());
return frame;
}
public static JFrame minFrameWidth(int w, JFrame frame) {
return minFrameWidth(frame, w);
}
public static JFrame showPackedFrame(String title, Component contents) {
return packFrame(showFrame(title, contents));
}
public static JFrame showPackedFrame(Component contents) {
return packFrame(showFrame(contents));
}
public static int withMargin_defaultWidth = 6;
public static JPanel withMargin(Component c) {
return withMargin(withMargin_defaultWidth, c);
}
public static JPanel withMargin(int w, Component c) {
return withMargin(w, w, c);
}
public static JPanel withMargin(int w, int h, Component c) {
return withMargin(w, h, w, h, c);
}
public static JPanel withMargin(final int top, final int left, final int bottom, final int right, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(top, left, bottom, right));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
public static int showForm_leftWidth(List> l) {
int minW = 0;
for (List row : l) minW = max(minW, getMinimumSize(first(row)).width);
return minW;
}
public static JPanel westAndCenter(final Component w, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.WEST, wrap(w));
panel.add(BorderLayout.CENTER, wrap(c));
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel panel = new JPanel(new BorderLayout);\r\n panel.add(BorderLayout.WEST...";
}
});
}
public static int withRightMargin_defaultWidth = 6;
public static JPanel withRightMargin(Component c) {
return withRightMargin(withRightMargin_defaultWidth, c);
}
public static JPanel withRightMargin(final int w, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, w));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
public static