timer = new Var();
timer.set(new Timer(toInt(delay), new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent _evt) { try {
AutoCloseable __229 = tempActivity(r); try {
try {
if (!allPaused())
if (isFalse(callF(r)))
cancelTimer(timer.get());
} catch (Throwable __e) { _handleException(__e); }
} finally { _close(__229); }} catch (Throwable __e) { messageBox(__e); }}}));
timer.get().setInitialDelay(toInt(firstDelay));
timer.get().setRepeats(repeats);
bindTimerToComponent(timer.get(), component);
return timer.get();
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "final new Var timer;\r\n timer.set(new Timer(toInt(delay), actionList..."; }});
}
static Timer installTimer(RootPaneContainer frame, long delay, long firstDelay, Object r) {
return installTimer(frame.getRootPane(), delay, firstDelay, r);
}
static boolean swic(String a, String b) {
return startsWithIgnoreCase(a, b);
}
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;
}
static boolean ewic(String a, String b) {
return endsWithIgnoreCase(a, b);
}
static boolean ewic(String a, String b, Matches m) {
return endsWithIgnoreCase(a, b, m);
}
static boolean containsNewLines(String s) {
return containsNewLine(s);
}
static String jlabel_textAsHTML_center(String text) {
return ""
+ replace(htmlencode(text), "\n", "
")
+ "
";
}
static List buttonsInGroup(ButtonGroup g) {
if (g == null) return ll();
return asList(g.getElements());
}
static A toolTip(A c, final Object toolTip) {
return setToolTipText(c, toolTip);
}
static A toolTip(Object toolTip, A c) {
return setToolTipText(toolTip, c);
}
static JComponent getInternalFrameTitlePaneComponent(JInternalFrame f) {
return (JComponent) childWithClassNameEndingWith(f, "InternalFrameTitlePane");
}
static A setFrameTitle(A c, final String title) {
final Frame f = getAWTFrame(c);
if (f != null) { swing(new Runnable() { public void run() { try { f.setTitle(title);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "f.setTitle(title);"; }}); }
return c;
}
static A setFrameTitle(String title, A c) {
return setFrameTitle(c, title);
}
// magically find a field called "frame" in main class :-)
static JFrame setFrameTitle(String title) {
Object f = getOpt(mc(), "frame");
if (f instanceof JFrame)
return setFrameTitle((JFrame) f, title);
return null;
}
static String getFrameTitle(Component c) {
JFrame f = getFrame(c);
return f == null ? null : f.getTitle();
}
static Set vm_generalIdentityHashSet(Object name) {
synchronized(get(javax(), "generalMap")) {
Set set = (Set) (vm_generalMap_get(name));
if (set == null)
vm_generalMap_put(name, set = syncIdentityHashSet());
return set;
}
}
static Map vm_generalHashMap(Object name) {
synchronized(get(javax(), "generalMap")) {
Map m = (Map) (vm_generalMap_get(name));
if (m == null)
vm_generalMap_put(name, m = syncHashMap());
return m;
}
}
static void addIfNotNull(Collection l, A a) {
if (a != null && l != null) l.add(a);
}
static void closeAutoCloseables(Collection l) {
if (l != null) for (AutoCloseable c : l) { try { c.close(); } catch (Throwable __e) { _handleException(__e); }}
}
static boolean hasMethod(Object o, String method, Object... args) {
return findMethod_cached(o, method, args) != null;
}
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;
}
static A nuInstance(Class c) {
return nuEmptyObject(c);
}
static A copyFields(Object x, A y, String... fields) {
if (empty(fields)) { // assume we should copy all fields
Map map = objectToMap(x);
for (String field : map.keySet())
setOpt(y, field, map.get(field));
} else
for (String field : fields) {
Object o = getOpt(x, field);
if (o != null)
setOpt(y, field, o);
}
return y;
}
static A copyFields(Object x, A y, Collection fields) {
return copyFields(x, y, asStringArray(fields));
}
static boolean isStringOrIntOrLong(Object o) {
return o instanceof String || o instanceof Integer || o instanceof Long;
}
static Object dm_getStemByID(Object id) {
return dm_callOS("getModuleByID", str(id));
}
static A or(A a, A b) {
return a != null ? a : b;
}
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);
}
// return Int.MAX_VALUE if not applicable
// Lower score is better
static int methodApplicabilityScore_onTypes(Method m, Class[] argTypes) {
Class>[] types = m.getParameterTypes();
if (types.length != argTypes.length) return Integer.MAX_VALUE;
int score = 0;
for (int i = 0; i < types.length; i++) {
Class a = argTypes[i];
Class c = types[i];
if (c == a) {} // perfect match
else if (isSubclassOf(a, c)) ++score;
else return Integer.MAX_VALUE;
}
return score;
}
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());
// We're technically violating the one-synchronized-object-per-thread rule,
// but it should be OK here.
// TODO: remove empty sets from map
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)"; }});
}
}
static AutoCloseable vmBus_onMessage(String msg, final VF2 onMessage) {
return vmBus_onMessage(msg, new VF1