> _threadInheritInfo_retrievers = synchroList();
static public void _threadInheritInfo(Object info) {
if (info == null)
return;
pcallFAll(_threadInheritInfo_retrievers, (Map) info);
}
static public JRootPane getRootPane(Component c) {
Component f = (Component) getPossiblyInternalFrame(c);
return f instanceof RootPaneContainer ? (JRootPane) swingCall(f, "getRootPane") : null;
}
static public int toInt_checked(long l) {
if (l != (int) l)
throw fail("Too large for int: " + l);
return (int) l;
}
static public A _recordNewSwingComponent(A c) {
if (c != null)
callF((Object) vm_generalMap_get("newSwingComponentRegistry"), (Object) c);
return c;
}
static public JComponent componentToJComponent(Component c) {
if (c instanceof JComponent)
return (JComponent) c;
if (c instanceof JFrame)
return ((JFrame) c).getRootPane();
if (c == null)
return null;
throw fail("boohoo " + getClassName(c));
}
static public JScrollPane jscroll(Component c) {
return swing(() -> {
return c instanceof JScrollPane ? ((JScrollPane) c) : new JScrollPane(c);
});
}
static public JLabel jlabel(final String text) {
return swingConstruct(BetterLabel.class, text);
}
static public JLabel jlabel() {
return jlabel(" ");
}
static public class jLiveValueSection_class extends SingleComponentPanel {
public LiveValue> liveValue;
public String getTitle() {
return strOrEmpty(liveValue.get());
}
public jLiveValueSection_class(LiveValue> lv, Component c) {
super(c);
bindLiveValueListenerToComponent(this, liveValue = lv, new Runnable() {
public void run() {
try {
swingLater(new Runnable() {
public void run() {
try {
setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED), getTitle()));
revalidate();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "setBorder(BorderFactory.createTitledBorder(\r\n BorderFactory.createBeve...";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "swingLater(r {\r\n setBorder(BorderFactory.createTitledBorder(\r\n Bo...";
}
});
}
}
static public JPanel jLiveValueSection(LiveValue> lv, Component c) {
return swingNu(jLiveValueSection_class.class, lv, c);
}
static public JPanel smartAdd(JPanel panel, List parts) {
for (Object o : parts) addToContainer(panel, wrapForSmartAdd(o));
return panel;
}
static public JPanel smartAdd(JPanel panel, Object... parts) {
return smartAdd(panel, asList(parts));
}
static public boolean nempty(Collection c) {
return !empty(c);
}
static public boolean nempty(CharSequence s) {
return !empty(s);
}
static public boolean nempty(Object[] o) {
return !empty(o);
}
static public boolean nempty(byte[] o) {
return !empty(o);
}
static public boolean nempty(int[] o) {
return !empty(o);
}
static public boolean nempty(BitSet bs) {
return !empty(bs);
}
static public boolean nempty(Map m) {
return !empty(m);
}
static public boolean nempty(Iterator i) {
return i != null && i.hasNext();
}
static public boolean nempty(IMultiMap mm) {
return mm != null && mm.size() != 0;
}
static public boolean nempty(Object o) {
return !empty(o);
}
static public boolean nempty(IntRange r) {
return !empty(r);
}
static public boolean nempty(IntBuffer b) {
return b != null && !b.isEmpty();
}
static public boolean nempty(Rect r) {
return r != null && r.w != 0 && r.h != 0;
}
static public boolean nempty(MultiSet ms) {
return ms != null && !ms.isEmpty();
}
static public String str_nullIfEmpty(Object o) {
return nullIfEmpty(strOrNull(o));
}
static public String dropPrefix(String prefix, String s) {
return s == null ? null : s.startsWith(prefix) ? s.substring(l(prefix)) : s;
}
static public JButton basicJButton(String text) {
return swing(() -> new JButton(text));
}
static public A swingConstruct(final Class c, final Object... args) {
return swing(new F0() {
public A get() {
try {
return nuObject(c, args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "return nuObject(c, args);";
}
});
}
static public A jtransparent(final A a) {
{
swing(() -> {
a.setOpaque(false);
});
}
return a;
}
static public JPanel borderLayoutPanel() {
return jpanel(new BorderLayout());
}
static public boolean swic(String a, String b) {
return startsWithIgnoreCase(a, b);
}
static public boolean swic(String a, String b, Matches m) {
if (!swic(a, b))
return false;
m.m = new String[] { substring(a, l(b)) };
return true;
}
static public boolean ewic(String a, String b) {
return endsWithIgnoreCase(a, b);
}
static public boolean ewic(String a, String b, Matches m) {
return endsWithIgnoreCase(a, b, m);
}
static public boolean containsNewLines(String s) {
return containsNewLine(s);
}
static public String jlabel_textAsHTML_center(String text) {
return "" + replace(htmlencode2(text), "\n", "
") + "
";
}
static public Object call_withVarargs(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.findStaticMethod(methodName, args);
if (me != null)
return invokeMethod(me, null, args);
List methods = cache.cache.get(methodName);
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() + "." + methodName + "(" + joinWithComma(classNames(args)) + ") not found");
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me != null)
return invokeMethod(me, o, args);
List methods = cache.cache.get(methodName);
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() + "." + methodName + "(" + joinWithComma(classNames(args)) + ") not found");
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public List immutableEmptyList() {
return Collections.emptyList();
}
static public byte[] emptyByteArray_a = new byte[0];
static public byte[] emptyByteArray() {
return emptyByteArray_a;
}
static public short[] emptyShortArray = new short[0];
static public short[] emptyShortArray() {
return emptyShortArray;
}
static public Map immutableEmptyMap() {
return Collections.emptyMap();
}
static public String getType(Object o) {
return getClassName(o);
}
static public long getFileSize(String path) {
return path == null ? 0 : new File(path).length();
}
static public long getFileSize(File f) {
return f == null ? 0 : f.length();
}
static public Throwable getException(Runnable r) {
try {
callF(r);
return null;
} catch (Throwable e) {
return e;
}
}
static public String baseClassName(String className) {
return substring(className, className.lastIndexOf('.') + 1);
}
static public String baseClassName(Object o) {
return baseClassName(getClassName(o));
}
static public String prependIfNempty(String prefix, String s) {
return empty(s) ? unnull(s) : prefix + s;
}
static public JButton jimageButtonScaledToWidth(int w, String imageID, Runnable action) {
return jimageButtonScaledToWidth(w, imageID, "", action);
}
static public JButton jimageButtonScaledToWidth(int w, String imageID, String toolTip, Runnable action) {
return jimageButton(scaleImageToWidth(w, imageID), toolTip, action);
}
static public String errorIconID() {
return "#1101390";
}
static public JComponent showErrorFrame(Throwable e) {
if (e == null)
return null;
return showTextWordWrapped("Error", renderStackTrace((e)));
}
static public JLabel jlabel_noAutoToolTip() {
return jlabel_noAutoToolTip(" ");
}
static public JLabel jlabel_noAutoToolTip(String text) {
var lbl = swingConstruct(BetterLabel.class, text);
lbl.autoToolTip = false;
return lbl;
}
static public WeakHasherMap symbol_map = new WeakHasherMap(new Hasher() {
public int hashCode(Symbol symbol) {
return symbol.text.hashCode();
}
public boolean equals(Symbol a, Symbol b) {
if (a == null)
return b == null;
return b != null && eq(a.text, b.text);
}
});
static public Symbol symbol(String s) {
if (s == null)
return null;
synchronized (symbol_map) {
Symbol symbol = new Symbol(s, true);
Symbol existingSymbol = symbol_map.findKey(symbol);
if (existingSymbol == null)
symbol_map.put(existingSymbol = symbol, true);
return existingSymbol;
}
}
static public Symbol symbol(CharSequence s) {
if (s == null)
return null;
if (s instanceof Symbol)
return (Symbol) s;
if (s instanceof String)
return symbol((String) s);
return symbol(str(s));
}
static public Symbol symbol(Object o) {
return symbol((CharSequence) o);
}
static public boolean activateFrame(final Component c, Object... __) {
return swing(new F0() {
public Boolean get() {
try {
Frame f = getAWTFrame(c);
if (f == null)
return false;
if (!f.isVisible())
f.setVisible(true);
boolean windowsHack = optPar("windowsHack", __, true);
boolean iconified = f.getState() == Frame.ICONIFIED;
boolean maximize = boolPar("maximize", __);
if (iconified)
f.setState(maximize ? Frame.MAXIMIZED_BOTH : Frame.NORMAL);
if (windowsHack && !iconified && isWindows()) {
boolean fullscreen = f.getExtendedState() == Frame.MAXIMIZED_BOTH;
f.setExtendedState(JFrame.ICONIFIED);
f.setExtendedState(fullscreen ? JFrame.MAXIMIZED_BOTH : JFrame.NORMAL);
}
f.toFront();
return true;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Frame f = getAWTFrame(c);\r\n if (f == null) false;\r\n if (!f.isVisible())...";
}
});
}
static public Frame getAWTFrame(final Object _o) {
return swing(new F0() {
public Frame get() {
try {
Object o = _o;
if (o instanceof ButtonGroup)
o = first(buttonsInGroup((ButtonGroup) o));
if (!(o instanceof Component))
return null;
Component c = (Component) o;
while (c != null) {
if (c instanceof Frame)
return (Frame) c;
c = c.getParent();
}
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "O o = _o;\r\n /*\r\n ifdef HaveProcessing\r\n if (o instanceof PApplet) ...";
}
});
}
static public A withTypeWriterFont(A c) {
return setFont(c, typeWriterFont());
}
static public JTextArea jTextArea() {
return jTextArea("");
}
static public JTextArea jTextArea(final String text) {
return jTextAreaWithUndo(text);
}
static public String programTitle() {
return getProgramName();
}
static public A optParam(ThreadLocal tl, A defaultValue) {
return optPar(tl, defaultValue);
}
static public A optParam(ThreadLocal tl) {
return optPar(tl);
}
static public Object optParam(String name, Map params) {
return mapGet(params, name);
}
static public 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;
}
static public Object optParam(Object[] opt, String name) {
return optParam(opt, name, null);
}
static public Object optParam(String name, Object[] params) {
return optParam(params, name);
}
static public JFrame getFrame(final Object _o) {
return swing(new F0() {
public JFrame get() {
try {
Object o = _o;
if (o instanceof ButtonGroup)
o = first(buttonsInGroup((ButtonGroup) o));
if (!(o instanceof Component))
return null;
Component c = (Component) o;
while (c != null) {
if (c instanceof JFrame)
return (JFrame) c;
c = c.getParent();
}
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "O o = _o;\r\n if (o instanceof ButtonGroup) o = first(buttonsInGroup((Button...";
}
});
}
static public JFrame setFrameIconLater(Component c, final String imageID) {
final JFrame frame = getFrame(c);
if (frame != null)
startThread("Loading Icon", new Runnable() {
public void run() {
try {
final Image i = imageIcon(or2(imageID, "#1005557")).getImage();
swingLater(new Runnable() {
public void run() {
try {
frame.setIconImage(i);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "frame.setIconImage(i);";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "final Image i = imageIcon(or2(imageID, \"#1005557\")).getImage();\r\n swingL...";
}
});
return frame;
}
static public void _initFrame(JFrame f) {
myFrames_list.put(f, Boolean.TRUE);
standardTitlePopupMenu(f);
}
static public Rectangle defaultNewFrameBounds_r = new Rectangle(300, 100, 500, 400);
static public Rectangle defaultNewFrameBounds() {
return swing(new F0() {
public Rectangle get() {
try {
defaultNewFrameBounds_r.translate(60, 20);
var bounds = preferredScreenBounds();
if (!bounds.contains(defaultNewFrameBounds_r))
defaultNewFrameBounds_r.setLocation(centerX(bounds) + random_incl(-30, 30), centerY(bounds) + random_incl(-20, 20));
return new Rectangle(defaultNewFrameBounds_r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "defaultNewFrameBounds_r.translate(60, 20);\r\n var bounds = preferredScreenB...";
}
});
}
static public void hideConsole() {
final JFrame frame = consoleFrame();
if (frame != null) {
autoVMExit();
swingLater(new Runnable() {
public void run() {
try {
frame.setVisible(false);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "frame.setVisible(false);";
}
});
}
}
static public String getProgramTitle() {
return getProgramName();
}
static public Object interceptPrintInThisThread(Object f) {
Object old = print_byThread().get();
print_byThread().set(f);
return old;
}
static public void printNumberedLines(Map map) {
printNumberedLines(mapToLines(map));
}
static public void printNumberedLines(String prefix, Map map) {
printNumberedLines(prefix, mapToLines(map));
}
static public A printNumberedLines(A l) {
int i = 0;
if (l != null)
for (Object a : cloneList(l)) print((++i) + ". " + str(a));
return l;
}
static public A printNumberedLines(String prefix, A l) {
int i = 0;
if (l != null)
for (Object a : cloneList(l)) print(prefix + (++i) + ". " + str(a));
return l;
}
static public void printNumberedLines(Object[] l) {
printNumberedLines("", l);
}
static public void printNumberedLines(String prefix, Object[] l) {
printNumberedLines(prefix, wrapAsList(l));
}
static public void printNumberedLines(Object o) {
printNumberedLines(lines(str(o)));
}
static public String lines(Iterable lines) {
return fromLines(lines);
}
static public String lines(Object[] lines) {
return fromLines(asList(lines));
}
static public List lines(String s) {
return toLines(s);
}
static public String lines(Iterable l, IF1 f) {
return mapToLines(l, f);
}
static public TreeMap asCaseInsensitiveMap(Map map) {
if (isCIMap(map))
return (TreeMap) map;
TreeMap m = ciMap();
putAll(m, map);
return m;
}
static public A printHidingCredentials(A o) {
print(hideCredentials(str(o)));
return o;
}
static public JWindow makeWindow(final Component c) {
return swing(new F0() {
public JWindow get() {
try {
JWindow w = new JWindow();
w.add(wrap(c));
return w;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "new JWindow w;\r\n w.add(wrap(c));\r\n ret w;";
}
});
}
static public JPanel infoMessage_makePanel(String text) {
final JTextArea ta = wrappedTextArea(text);
onClick(ta, new Runnable() {
public void run() {
try {
disposeWindow(ta);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "disposeWindow(ta)";
}
});
int size = 14;
if (l(text) <= 50)
size *= 2;
else if (l(text) < 100)
size = iround(size * 1.5);
ta.setFont(typeWriterFont(size));
JScrollPane sp = jscroll(ta);
return withMargin(sp);
}
static public int moveToTopRightCorner_inset = 20;
static public A moveToTopRightCorner(A a) {
return moveToTopRightCorner(moveToTopRightCorner_inset, moveToTopRightCorner_inset, a);
}
static public A moveToTopRightCorner(int insetX, int insetY, A a) {
{
swing(() -> {
Window w = getWindow(a);
if (w != null) {
var bounds = preferredScreenBounds();
w.setLocation(bounds.x2() - w.getWidth() - insetX, bounds.y1() + insetY);
}
});
}
return a;
}
static public boolean vmBus_noObjections(String msg, Object... args) {
return !vmBus_anyFalse(msg, args);
}
static public boolean regionMatches(String a, int offsetA, String b, int offsetB, int len) {
return a != null && b != null && a.regionMatches(offsetA, b, offsetB, len);
}
static public boolean regionMatches(String a, int offsetA, String b) {
return regionMatches(a, offsetA, b, 0, l(b));
}
static public 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);
}
static public String javaTok_substringC(String s, int i, int j) {
return s.substring(i, j);
}
static public 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;
}
static public 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 String join(String glue, Iterable strings) {
if (strings == null)
return "";
if (strings instanceof Collection) {
if (((Collection) strings).size() == 1)
return strOrEmpty(first((Collection) strings));
}
StringBuilder buf = new StringBuilder();
Iterator i = strings.iterator();
if (i.hasNext()) {
buf.append(strOrEmpty(i.next()));
while (i.hasNext()) buf.append(glue).append(strOrEmpty(i.next()));
}
return buf.toString();
}
public static String join(String glue, String... strings) {
return join(glue, Arrays.asList(strings));
}
public static String join(String glue, Object... strings) {
return join(glue, Arrays.asList(strings));
}
static public String join(Iterable strings) {
return join("", strings);
}
static public String join(Iterable strings, String glue) {
return join(glue, strings);
}
public static String join(String[] strings) {
return join("", strings);
}
static public String join(String glue, Pair p) {
return p == null ? "" : str(p.a) + glue + str(p.b);
}
static public Object callFunction(Object f, Object... args) {
return callF(f, args);
}
static public void logQuotedWithTime(String s) {
logQuotedWithTime(standardLogFile(), s);
}
static public void logQuotedWithTime(File logFile, String s) {
logQuoted(logFile, logQuotedWithTime_format(s));
}
static public void logQuotedWithTime(String logFile, String s) {
logQuoted(logFile, logQuotedWithTime_format(s));
}
static public String logQuotedWithTime_format(String s) {
return (now()) + " " + s;
}
static public File javaxDataDir_dir;
static public File javaxDataDir() {
return javaxDataDir_dir != null ? javaxDataDir_dir : new File(userHome(), "JavaX-Data");
}
static public File javaxDataDir(String... subs) {
return newFile(javaxDataDir(), subs);
}
static public int isAndroid_flag;
static public boolean isAndroid() {
if (isAndroid_flag == 0)
isAndroid_flag = System.getProperty("java.vendor").toLowerCase().indexOf("android") >= 0 ? 1 : -1;
return isAndroid_flag > 0;
}
static public Object vm_generalMap_get(Object key) {
return vm_generalMap().get(key);
}
static public Object vm_generalMap_put(Object key, Object value) {
return mapPutOrRemove(vm_generalMap(), key, value);
}
static public Object callJavaX(String method, Object... args) {
return callOpt(getJavaX(), method, args);
}
static public double toDouble(Object o) {
if (o instanceof Number)
return ((Number) o).doubleValue();
if (o instanceof BigInteger)
return ((BigInteger) o).doubleValue();
if (o instanceof String)
return parseDouble((String) o);
if (o == null)
return 0.0;
throw fail(o);
}
static public Class javax() {
return getJavaX();
}
static public 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;
}
static public TimedCache