l = new ArrayList();
for (Object o : array) l.add(_getClass(o));
return l;
}
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 A bindLiveValueListenerToComponent(A component, final LiveValue lv, final Runnable listener) {
if (lv != null)
bindToComponent(component, new Runnable() {
public void run() {
try {
lv.onChangeAndNow(listener);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ifdef bindLiveValueListenerToComponent_debug\r\n print(\"bindLiveValueL...";
}
}, new Runnable() {
public void run() {
try {
lv.removeOnChangeListener(listener);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "lv.removeOnChangeListener(listener)";
}
});
return component;
}
public static boolean setText_opt = true;
public static A setText(A c, Object text) {
setText((Object) c, text);
return c;
}
public static A setText(final A c, Object text) {
final String s = strUnnull(text);
{
swing(new Runnable() {
public void run() {
try {
c.getEditor().setItem(s);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "c.getEditor().setItem(s);";
}
});
}
return c;
}
public static void setText(JLabel c, Object text) {
setText((Object) c, text);
}
public static JButton setText(JButton c, Object text) {
setText((Object) c, jlabel_textAsHTML_center_ifNeeded(strUnnull(text)));
return c;
}
public static A setText(final A c, Object text) {
if (c == null)
return null;
final String s = strUnnull(text);
{
swing(new Runnable() {
public void run() {
try {
if (!setText_opt || neq(callOpt(c, "getText"), s))
call(c, "setText", s);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (!setText_opt || neq(callOpt(c, \"getText\"), s))\r\n call(c, \"setText\", s);";
}
});
}
return c;
}
public static String strOrNull(Object o) {
return o == null ? null : str(o);
}
public static Throwable printStackTrace(Throwable 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 lockOrFail(Lock lock, long timeout) {
try {
ping();
if (!lock.tryLock(timeout, TimeUnit.MILLISECONDS)) {
String s = "Couldn't acquire lock after " + timeout + " ms.";
if (lock instanceof ReentrantLock) {
ReentrantLock l = (ReentrantLock) (lock);
s += " Hold count: " + l.getHoldCount() + ", owner: " + call(l, "getOwner");
}
throw fail(s);
}
ping();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static ReentrantLock fairLock() {
return new ReentrantLock(true);
}
public static volatile String caseID_caseID;
public static String caseID() {
return caseID_caseID;
}
public static void caseID(String id) {
caseID_caseID = id;
}
public static String quoteUnlessIdentifierOrInteger(String s) {
return quoteIfNotIdentifierOrInteger(s);
}
public static long parseLong(String s) {
if (s == null)
return 0;
return Long.parseLong(dropSuffix("L", s));
}
public static long parseLong(Object s) {
return Long.parseLong((String) s);
}
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 synchroHashMap() {
return Collections.synchronizedMap(new HashMap());
}
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 String strUnnull(Object o) {
return o == null ? "" : str(o);
}
public static String jlabel_textAsHTML_center_ifNeeded(String text) {
if (swic(text, "") && ewic(text, ""))
return text;
if (!containsNewLines(text))
return text;
return jlabel_textAsHTML_center(text);
}
public static String getStackTrace(Throwable throwable) {
lastException(throwable);
return getStackTrace_noRecord(throwable);
}
public static String getStackTrace_noRecord(Throwable throwable) {
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
return hideCredentials(writer.toString());
}
public static String getStackTrace() {
return getStackTrace_noRecord(new Throwable());
}
public static String quoteIfNotIdentifierOrInteger(String s) {
if (s == null)
return null;
return isJavaIdentifier(s) || isInteger(s) ? s : quote(s);
}
public static String dropSuffix(String suffix, String s) {
return s.endsWith(suffix) ? s.substring(0, l(s) - l(suffix)) : s;
}
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 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 boolean ewic(String a, String b) {
return endsWithIgnoreCase(a, b);
}
public static boolean ewic(String a, String b, Matches m) {
return endsWithIgnoreCase(a, b, m);
}
public static boolean containsNewLines(String s) {
return containsNewLine(s);
}
public static String jlabel_textAsHTML_center(String text) {
return "" + replace(htmlencode(text), "\n", " ") + "
";
}
public static volatile PersistableThrowable lastException_lastException;
public static PersistableThrowable lastException() {
return lastException_lastException;
}
public static void lastException(Throwable e) {
lastException_lastException = persistableThrowable(e);
}
public static String hideCredentials(URL url) {
return url == null ? null : hideCredentials(str(url));
}
public static String hideCredentials(String url) {
return url.replaceAll("([&?])(_pass|key)=[^&\\s\"]*", "$1$2=");
}
public static String hideCredentials(Object o) {
return hideCredentials(str(o));
}
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 boolean isInteger(String s) {
int n = l(s);
if (n == 0)
return false;
int i = 0;
if (s.charAt(0) == '-')
if (++i >= n)
return false;
while (i < n) {
char c = s.charAt(i);
if (c < '0' || c > '9')
return false;
++i;
}
return true;
}
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 boolean startsWithIgnoreCase(String a, String b) {
return regionMatchesIC(a, 0, b, 0, b.length());
}
public static boolean endsWithIgnoreCase(String a, String b) {
int la = l(a), lb = l(b);
return la >= lb && regionMatchesIC(a, la - lb, b, 0, lb);
}
public static boolean endsWithIgnoreCase(String a, String b, Matches m) {
if (!endsWithIgnoreCase(a, b))
return false;
m.m = new String[] { substring(a, 0, l(a) - l(b)) };
return true;
}
public static boolean containsNewLine(String s) {
return contains(s, '\n');
}
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 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 htmlencode(Object o) {
return htmlencode(str(o));
}
public static String htmlencode(String s) {
if (s == null)
return "";
StringBuilder out = new StringBuilder(Math.max(16, s.length()));
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&')
out.append("").append((int) c).append(';');
else
out.append(c);
}
return out.toString();
}
public static PersistableThrowable persistableThrowable(Throwable e) {
return e == null ? null : new PersistableThrowable(e);
}
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 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 class SimpleLiveValue extends LiveValue {
public Class type;
public volatile A value;
public transient List onChange = synchroList();
public SimpleLiveValue(Class type) {
this.type = type;
}
public SimpleLiveValue(Class type, A value) {
this.value = value;
this.type = type;
}
public Class getType() {
return type;
}
public A get() {
return value;
}
public void onChange(Runnable l) {
onChange.add(l);
}
public void onChangeAndNow(Runnable l) {
onChange(l);
callF(l);
}
public void removeOnChangeListener(Runnable l) {
onChange.remove(l);
}
public void fireChanged() {
pcallFAll(onChange);
}
public void set(A a) {
if (neq(value, a)) {
value = a;
fireChanged();
}
}
}
public abstract static class VF2 {
public abstract void get(A a, B b);
}
public static class Var implements IVar {
public A v;
public Var() {
}
public Var(A v) {
this.v = v;
}
public synchronized void set(A a) {
if (v != a) {
v = a;
notifyAll();
}
}
public synchronized A get() {
return v;
}
public synchronized boolean has() {
return v != null;
}
public synchronized void clear() {
v = null;
}
public String toString() {
return str(get());
}
}
public abstract static class DynCRUD extends DynModule {
public transient Class conceptClass;
public transient SimpleCRUD crud;
public DynCRUD() {
}
public DynCRUD(Class conceptClass) {
this.conceptClass = conceptClass;
}
public void start() {
super.start();
db();
crud = makeCRUD();
}
public JComponent visualize() {
makeConceptsTable_idWidth = 0;
showConceptsTable_afterUpdate.set(new VF1() {
public void get(JTable t) {
try {
int n = tableColumnCount(t);
for (int i = 0; i < n; i++) setColumnName(t, i, i == 0 ? "" : humanizeFormLabel(getColumnName(t, i)));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "int n = tableColumnCount(t);\r\n for i to n:\r\n setColumnName(t, i, ...";
}
});
return withMargin(crud.make());
}
public SimpleCRUD makeCRUD() {
return new SimpleCRUD (db_mainConcepts(), conceptClass);
}
public JTable table() {
return crud == null ? null : crud.table;
}
public A selected() {
return crud == null ? null : crud.selectedConcept();
}
public void addButton(JComponent button) {
if (crud != null)
addComponent(crud.buttons, button);
}
public void addButton(String name, Object action) {
addButton(jbutton(name, action));
}
public void makeSortable() {
addRowSorter(table());
rowSorter_setComparatorForAllColumns(table(), alphaNumComparator());
}
public String searchTerm() {
return crud == null || crud.tableSearcher == null ? null : gtt(crud.tableSearcher.tfInput);
}
public void addCountToName() {
onConceptChangeAndNow(new Runnable() {
public void run() {
try {
setModuleName(programTitle() + " (" + conceptCount() + ")");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "setModuleName(programTitle() + \" (\" + conceptCount() + \")\")";
}
});
}
public Concepts conceptsObject() {
return crud.concepts;
}
public List list(Class c) {
return conceptsObject().list(c);
}
public List concepts() {
AutoCloseable __25 = enter();
try {
return list(conceptClass);
} finally {
_close(__25);
}
}
public int conceptCount() {
AutoCloseable __26 = enter();
try {
return countConcepts(conceptClass);
} finally {
_close(__26);
}
}
public void deleteAll() {
AutoCloseable __27 = enter();
try {
deleteConcepts(conceptClass);
} finally {
_close(__27);
}
}
public void addDialog() {
AutoCloseable __28 = enter();
try {
crud.newConcept();
} finally {
_close(__28);
}
}
}
public static class PersistableThrowable {
public String className;
public String msg;
public String stacktrace;
public PersistableThrowable() {
}
public PersistableThrowable(Throwable e) {
if (e == null)
className = "Crazy Null Error";
else {
className = getClassName(e).replace('/', '.');
msg = e.getMessage();
stacktrace = getStackTrace_noRecord(e);
}
}
public String toString() {
return nempty(msg) ? className + ": " + msg : className;
}
}
public abstract static class LiveValue {
public abstract Class getType();
public abstract A get();
public abstract void onChange(Runnable l);
public abstract void removeOnChangeListener(Runnable l);
public void onChangeAndNow(Runnable l) {
onChange(l);
callF(l);
}
}
public static boolean SimpleCRUD_searcher = true;
public static class SimpleCRUD {
public Class cc;
public JTable table;
public JPanel buttons, panel;
public Object renderer;
public String hID = "ID";
public Set excludeFieldsFromEditing;
public String modifiedField;
public TableSearcher tableSearcher;
public Set multiLineFields;
public Concepts concepts;
public SimpleCRUD(Class cc) {
this(db_mainConcepts(), cc);
}
public SimpleCRUD(Concepts concepts, Class cc) {
this.cc = cc;
this.concepts = concepts;
}
public SimpleCRUD show(String frameTitle) {
make();
showFrame(frameTitle, panel);
return this;
}
public SimpleCRUD show() {
return show(plural(shortClassName(cc)));
}
public SimpleCRUD showMaximized() {
show();
maximizeFrame(panel);
return this;
}
public JPanel makePanel() {
return make();
}
public JPanel make() {
db();
framesBot();
table = makeConceptsTable(cc, wrapRenderer(renderer));
{
swing(new Runnable() {
public void run() {
try {
buttons = jRightAlignedLine(jbutton("Add...", new Runnable() {
public void run() {
try {
newConcept();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "newConcept()";
}
}), tableDependButton(table, jbutton("Edit", new Runnable() {
public void run() {
try {
editConcept(selectedConcept());
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "editConcept(selectedConcept())";
}
})), tableDependButton(table, jbutton("Delete", new Runnable() {
public void run() {
try {
final List l = selectedConcepts();
withDBLock(new Runnable() {
public void run() {
try {
for (A c : l) c.delete();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "for (A c : l) c.delete()";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "final List l = selectedConcepts();\r\n withDBLock(r { for (A c : l)...";
}
})));
if (SimpleCRUD_searcher) {
tableSearcher = tableWithSearcher2(table, "withMargin", true);
panel = centerAndSouthWithMargin(tableSearcher.panel, buttons);
} else
panel = centerAndSouthWithMargin(table, buttons);
Object fEdit = new VF1() {
public void get(Integer row) {
try {
editConcept((A) getConcept(toLong(getTableCell(table, row, 0))));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "editConcept((A) getConcept(toLong(getTableCell(table, row, 0))))";
}
};
tablePopupMenuItem(table, "Edit...", fEdit);
onDoubleClick(table, fEdit);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "buttons = jRightAlignedLine(\r\n jbutton(\"Add...\", r { newConcept() }),\r...";
}
});
}
return panel;
}
public Object wrapRenderer(final Object renderer) {
return renderer == null ? null : new F1() {
public Object get(A a) {
try {
return putAll(litorderedmap(hID, str(a.id)), (Map) callF(renderer, a));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "putAll(litorderedmap(hID, str(a.id)), (Map) callF(renderer, a))";
}
};
}
public void newConcept() {
final A c = unlisted(cc);
final Map map = makeComponents(c);
Runnable r = new Runnable() {
public void run() {
try {
register(c);
saveData(c, map);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "register(c);\r\n saveData(c, map);";
}
};
AutoCloseable __32 = tempSetMCOpt("formLayouter1_fixer2", 12);
try {
showFormTitled2("New " + shortClassName(cc), arrayPlus(mapToObjectArray(map), r));
} finally {
_close(__32);
}
}
public void editConcept(final A c) {
if (c == null)
return;
final Map map = makeComponents(c);
Runnable r = new Runnable() {
public void run() {
try {
saveData(c, map);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "saveData(c, map)";
}
};
AutoCloseable __33 = tempSetMCOpt("formLayouter1_fixer2", 12);
try {
showFormTitled2("Edit " + shortClassName(cc) + " #" + c.id, arrayPlus(mapToObjectArray(map), r));
} finally {
_close(__33);
}
}
public A selectedConcept() {
return (A) getConcept(toLong(selectedTableCell(table, 0)));
}
public List selectedConcepts() {
int[] rows = table.getSelectedRows();
List l = new ArrayList();
for (int row : rows) l.add((A) getConcept(toLong(getTableCell(table, row, 0))));
return l;
}
public Map makeComponents(A c) {
Map map = litorderedmap();
makeComponents(c, map);
return map;
}
public JComponent fieldComponent(A c, String field) {
Class type = getFieldType(cc, field);
Object value = getOpt(c, field);
if (type == boolean.class)
return jCenteredCheckBox(isTrue(value));
else if (contains(multiLineFields, field))
return typeWriterTextArea((String) value);
else
try {
return autoComboBox(structureOrText_crud(value), new TreeSet(map("structureOrText_crud", collect(list(cc), field))));
} catch (Throwable e) {
printException(e);
return jTextField(structureOrText_crud(value));
}
}
public void saveComponent(A c, String field, JComponent comp) {
comp = unwrap(comp);
if (comp instanceof JTextComponent)
cset(c, field, convertToField(trimIf(!(comp instanceof JTextArea), getText((JTextComponent) comp)), cc, field));
else if (comp instanceof JComboBox)
cset(c, field, convertToField(getTextTrim((JComboBox) comp), cc, field));
else if (comp instanceof JCheckBox)
cset(c, field, isChecked((JCheckBox) comp));
}
public List fields() {
if (excludeFieldsFromEditing != null && modifiedField != null)
excludeFieldsFromEditing.add(modifiedField);
return listWithoutSet(filter(conceptFieldsInOrder(cc), new F1() {
public Boolean get(String field) {
try {
return fieldType(cc, field) != Concept.Ref.class;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "fieldType(cc, field) != Concept.Ref.class";
}
}), excludeFieldsFromEditing);
}
public void excludeFieldsFromEditing(String... fields) {
excludeFieldsFromEditing = setPlus(excludeFieldsFromEditing, fields);
}
public void makeComponents(A c, Map map) {
for (String field : fields()) map.put(field, fieldComponent(c, field));
}
public void saveData(A c, Map components) {
for (String field : keys(components)) saveComponent(c, field, components.get(field));
if (modifiedField != null)
cset(c, modifiedField, now());
}
}
public static interface IVar {
public void set(A a);
public A get();
public boolean has();
public void clear();
}
public static String structureOrText_crud(Object o) {
if (o == null)
return "";
if (o instanceof Long)
return str(o);
if (o instanceof File)
return ((File) o).getAbsolutePath();
return structureOrText(o);
}
public static List synchroList() {
return Collections.synchronizedList(new ArrayList ());
}
public static List synchroList(List l) {
return Collections.synchronizedList(l);
}
public static String getType(Object o) {
return getClassName(o);
}
public static void onChange(JSpinner spinner, Object r) {
spinner.addChangeListener(changeListener(r));
}
public static A onChange(A b, Object r) {
b.addItemListener(itemListener(r));
return b;
}
public static void onChange(JTextComponent tc, Object r) {
onUpdate(tc, r);
}
public static void onChange(final JSlider slider, final Object r) {
{
swing(new Runnable() {
public void run() {
try {
slider.addChangeListener(changeListener(r));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "slider.addChangeListener(changeListener(r));";
}
});
}
}
public static void onChange(JComboBox cb, final Object r) {
if (isEditableComboBox(cb))
onChange(textFieldFromComboBox(cb), r);
else
onSelectedItem(cb, new VF1() {
public void get(String s) {
try {
callF(r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(r)";
}
});
}
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 db() {
conceptsAndBot();
}
public static void db(Integer autoSaveInterval) {
conceptsAndBot(autoSaveInterval);
}
public static int tableColumnCount(JTable table) {
return tableNumColumns(table);
}
public static void setColumnName(final JTable table, final int idx, final String name) {
if (table != null) {
swing(new Runnable() {
public void run() {
try {
if (table.getColumnCount() > idx)
table.getColumnModel().getColumn(idx).setHeaderValue(name);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (table.getColumnCount() > idx)\r\n table.getColumnModel().getColumn(idx...";
}
});
}
}
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 String getColumnName(final JTable table, final int idx) {
return table == null ? null : swing(new F0() {
public String get() {
try {
return table.getColumnCount() <= idx ? null : str(table.getColumnModel().getColumn(idx).getHeaderValue());
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret table.getColumnCount() <= idx ? null\r\n : str(table.getColumnModel()....";
}
});
}
public static A addComponent(final A c, final Component component) {
if (component != null) {
swing(new Runnable() {
public void run() {
try {
c.add(component);
revalidate(c);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "c.add(component);\r\n revalidate(c);";
}
});
}
return c;
}
public static JButton jbutton(String text, Object action) {
return newButton(text, action);
}
public static JButton jbutton(String text) {
return newButton(text, null);
}
public static JButton jbutton(Action action) {
return swingNu(JButton.class, action);
}
public static JTable addRowSorter(final JTable table) {
if (table != null) {
swing(new Runnable() {
public void run() {
try {
table.setRowSorter(new TableRowSorter(table.getModel()));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "table.setRowSorter(new TableRowSorter(table.getModel()));";
}
});
}
return table;
}
public static void rowSorter_setComparatorForAllColumns(JTable table, final Comparator comparator) {
if (table == null)
return;
setTableModel_fixSorter.put(table, new VF2() {
public void get(JTable table, RowSorter sorter) {
try {
if (sorter instanceof TableRowSorter) {
int n = tableColumnCount(table);
for (int i = 0; i < n; i++) ((TableRowSorter) sorter).setComparator(i, comparator);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (sorter cast TableRowSorter) {\r\n int n = tableColumnCount(table);\r\n ...";
}
});
}
public static AlphanumComparator alphaNumComparator_instance;
public static Comparator alphaNumComparator() {
if (alphaNumComparator_instance == null)
alphaNumComparator_instance = new AlphanumComparator();
return alphaNumComparator_instance;
}
public static String gtt(JTextComponent c) {
return getTextTrim(c);
}
public static String gtt(JComboBox cb) {
return getTextTrim(cb);
}
public static void onConceptChangeAndNow(Runnable r) {
onConceptsChangeAndNow(r);
}
public static String programTitle() {
return getProgramName();
}
public static void concepts() {
conceptsAndBot();
}
public static void concepts(int autoSaveInterval) {
conceptsAndBot(autoSaveInterval);
}
public static int countConcepts(Class c, Object... params) {
return db_mainConcepts().countConcepts(c, params);
}
public static int countConcepts() {
return db_mainConcepts().countConcepts();
}
public static int countConcepts(String className) {
return db_mainConcepts().countConcepts(className);
}
public static int countConcepts(Concepts concepts, String className) {
return concepts.countConcepts(className);
}
public static void deleteConcepts(List conceptsOrIDs) {
db_mainConcepts().deleteConcepts(conceptsOrIDs);
}
public static List deleteConcepts(Class c, Object... params) {
List l = findConceptsWhere(c, params);
deleteConcepts(l);
return l;
}
public static JFrame showFrame() {
return makeFrame();
}
public static JFrame showFrame(Object content) {
return makeFrame(content);
}
public static JFrame showFrame(String title) {
return makeFrame(title);
}
public static JFrame showFrame(String title, Object content) {
return makeFrame(title, content);
}
public static JFrame showFrame(final JFrame f) {
if (f != null) {
swing(new Runnable() {
public void run() {
try {
if (frameTooSmall(f))
frameStandardSize(f);
if (!f.isVisible())
f.setVisible(true);
if (f.getState() == Frame.ICONIFIED)
f.setState(Frame.NORMAL);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (frameTooSmall(f)) frameStandardSize(f);\r\n if (!f.isVisible()) f.setVis...";
}
});
}
return f;
}
public static JFrame showFrame(String title, Object content, JFrame frame) {
if (frame == null)
return showFrame(title, content);
else {
frame.setTitle(title);
setFrameContents(frame, content);
return frame;
}
}
public static String plural(String s) {
return getPlural(s);
}
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 JFrame maximizeFrame(final Component c) {
JFrame f = swing(new F0() {
public JFrame get() {
try {
JFrame f = getFrame(c);
if (f != null)
f.setExtendedState(JFrame.MAXIMIZED_BOTH);
return f;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JFrame f = getFrame(c);\r\n if (f != null)\r\n f.setExtendedState(JFrame....";
}
});
if (!isAWTThread()) {
Dimension d = maximumWindowBounds().getSize();
long start = sysNow();
while (licensed()) {
try {
if (f.getWidth() >= d.getWidth() - 100 && f.getHeight() >= d.getHeight() - 100)
break;
if (sysNow() >= start + 100) {
warn("maximizeFrame timeout");
break;
}
} catch (Throwable __e) {
_handleException(__e);
}
sleep(1);
}
}
return f;
}
public static volatile boolean framesBot_has;
public static Android3 framesBot() {
if (framesBot_has)
return null;
framesBot_has = true;
Android3 android = new Android3();
android.greeting = programIDPlusHome() + " Frames.";
android.console = false;
android.responder = new Responder() {
public String answer(String s, List history) {
if (match("activate frames", s)) {
swingLater(new Runnable() {
public void run() {
try {
activateMyFrames();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "// prevent blocking when called from same program's AWT thread\r\n act...";
}
});
return "OK, activating " + programName();
}
return null;
}
};
return makeBot(android);
}
public static ThreadLocal> showConceptsTable_dropFields = new ThreadLocal();
public static ThreadLocal showConceptsTable_postProcess = new ThreadLocal();
public static ThreadLocal showConceptsTable_afterUpdate = new ThreadLocal();
public static ThreadLocal showConceptsTable_concepts = new ThreadLocal();
public static int makeConceptsTable_idWidth = 50;
public static JTable showConceptsTable(Class extends Concept> c) {
JTable table = makeConceptsTable(c);
showFrame(plural(shortClassName(c)), table);
return table;
}
public static JTable makeConceptsTable(final Class extends Concept> c) {
List dropFields = getAndClearThreadLocal(showConceptsTable_dropFields);
final Object pp = getAndClearThreadLocal(showConceptsTable_postProcess);
final Object afterUpdate = optParam(showConceptsTable_afterUpdate);
final Concepts concepts = optParam(showConceptsTable_concepts, db_mainConcepts());
final List fields = listMinusList(concatLists(ll("id"), conceptFieldsInOrder(c)), dropFields);
final JTable table = sexyTable();
tablePopupMenu(table, new VF2() {
public void get(JPopupMenu menu, final Integer row) {
try {
addMenuItem(menu, "Delete", new Runnable() {
public void run() {
try {
final long id = toLong(getTableCell(table, row, 0));
withDBLock(new Runnable() {
public void run() {
try {
deleteConcept(id);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "deleteConcept(id)";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "final long id = toLong(getTableCell(table, row, 0));\r\n withDBLock(r { de...";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "addMenuItem(menu, \"Delete\", r {\r\n final long id = toLong(getTableCell(ta...";
}
});
awtOnConceptChanges(table, new Runnable() {
public void run() {
try {
List data = new ArrayList();
for (final Concept cc : list(concepts, c)) data.add(map(new F1() {
public Object get(String field) {
try {
return renderForTable(cget(cc, field));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "renderForTable(cget(cc, field))";
}
}, fields));
data = (List) postProcess(pp, data);
fillTableWithData(table, data, map("humanizeFormLabel", fields));
if (table.getColumnCount() > 0)
table.getColumnModel().getColumn(0).setMaxWidth(makeConceptsTable_idWidth);
pcallF(afterUpdate, table);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "//print(\"Updating concept table\");\r\n new List data;\r\n for (final ...";
}
}, true);
return table;
}
public static JTable makeConceptsTable(final Class cClass, final Object renderer) {
if (renderer == null)
return makeConceptsTable(cClass);
final Object pp = optParam(showConceptsTable_postProcess);
final Object afterUpdate = optParam(showConceptsTable_afterUpdate);
final Concepts concepts = optParam(showConceptsTable_concepts);
final JTable table = sexyTable();
awtOnConceptChanges(table, 1000, new Runnable() {
public void run() {
try {
List data = new ArrayList();
for (A c : list(concepts, cClass)) addIfNotNull(data, (Map) pcallF(renderer, c));
data = (List) postProcess(pp, data);
dataToTable_uneditable(data, table);
pcallF(afterUpdate, table);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "new List data;\r\n for (A c : list(concepts, cClass))\r\n addIfNotNu...";
}
});
return table;
}
public static JTable showConceptsTable(final Class c, final Object f) {
JTable table = makeConceptsTable(c, f);
showFrame(plural(shortClassName(c)), table);
return table;
}
public static JTable showConceptsTable(String title, Class cClass, Object f) {
return setFrameTitle(title, showConceptsTable(cClass, f));
}
public static JPanel jRightAlignedLine(Component... components) {
return jrightAlignedLine(components);
}
public static JPanel jRightAlignedLine(List extends Component> components) {
return jrightAlignedLine(components);
}
public static JButton tableDependButton(JTable tbl, JButton b) {
tableDependButtons(tbl, ll(b));
return b;
}
public static JButton tableDependButton(JTable tbl, String text, Object action) {
return tableDependButton(tbl, jbutton(text, action));
}
public static A selectedConcept(JTable table, Class cc) {
return (A) getConcept(toLong(selectedTableCell(table, 0)));
}
public static Object withDBLock(Object r) {
Lock __72 = db_mainConcepts().lock;
lock(__72);
try {
return callF(r);
} finally {
unlock(__72);
}
}
public static A withDBLock(F0 r) {
return (A) withDBLock((Object) r);
}
public static class TableSearcher {
public JTable table;
public JTextField tfInput;
public JComponent searchPanel, panel;
public F2 rowTester;
public String input() {
return gtt(tfInput);
}
}
public static TableSearcher tableWithSearcher2(final JTable t, Object... __) {
final TableSearcher s = new TableSearcher();
s.table = t;
s.tfInput = jtextfield();
s.rowTester = new F2() {
public Boolean get(String pat, Map row) {
try {
return anyValueContainsIgnoreCase(row, pat);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "anyValueContainsIgnoreCase(row, pat)";
}
};
onUpdate(s.tfInput, new Runnable() {
public List lastFiltered, lastOriginal;
public void run() {
String pat = s.input();
List> data = rawTableData(t);
if (eq(lastFiltered, data))
data = lastOriginal;
List data2 = new ArrayList();
for (Map map : data) if (isTrue(callF(s.rowTester, pat, map)))
data2.add(map);
lastFiltered = data2;
lastOriginal = data;
dataToTable(t, data2);
}
});
s.searchPanel = withLabel("Search:", s.tfInput);
JComponent top = s.searchPanel;
s.panel = boolOptPar(__, "withMargin") ? northAndCenterWithMargin(top, t) : northAndCenter(top, t);
return s;
}
public static JPanel centerAndSouthWithMargin(Component c, Component s) {
return centerAndSouth(c, withTopMargin(s));
}
public static Concept getConcept(long id) {
return db_mainConcepts().getConcept(id);
}
public static A getConcept(Class cc, long id) {
return getConcept(db_mainConcepts(), cc, id);
}
public static A getConcept(Concepts concepts, Class cc, long id) {
Concept c = concepts.getConcept(id);
if (c == null)
return null;
if (!isInstance(cc, c))
throw fail("Can't convert concept: " + getClassName(c) + " -> " + getClassName(cc) + " (" + id + ")");
return (A) c;
}
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 Object getTableCell(JTable tbl, int row, int col) {
if (row >= 0 && row < tbl.getModel().getRowCount())
return tbl.getModel().getValueAt(row, col);
return null;
}
public static void tablePopupMenuItem(final JTable table, final String name, final Object action) {
tablePopupMenu(table, new VF2() {
public void get(JPopupMenu menu, final Integer row) {
try {
addMenuItem(menu, name, new Runnable() {
public void run() {
try {
pcallF(action, row);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pcallF(action, row)";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "addMenuItem(menu, name, r { pcallF(action, row) });";
}
});
}
public static JList onDoubleClick(final JList list, final Object runnable) {
{
swing(new Runnable() {
public void run() {
try {
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 2) {
int idx = list.locationToIndex(evt.getPoint());
Object item = list.getModel().getElementAt(idx);
list.setSelectedIndex(idx);
callF(runnable, item);
}
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "list.addMouseListener(new MouseAdapter {\r\n public void mouseClicked(Mous...";
}
});
}
return list;
}
public static JTable onDoubleClick(final JTable table, final Object runnable) {
{
swing(new Runnable() {
public void run() {
try {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 2) {
int idx = table.rowAtPoint(evt.getPoint());
table.setRowSelectionInterval(idx, idx);
callF(runnable, idx);
}
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "table.addMouseListener(new MouseAdapter {\r\n public void mouseClicked(Mou...";
}
});
}
return table;
}
public static void onDoubleClick(final JComponent c, final Object runnable) {
{
swing(new Runnable() {
public void run() {
try {
c.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getButton() == 1 && evt.getClickCount() == 2)
callF(runnable, evt.getPoint());
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "c.addMouseListener(new MouseAdapter {\r\n public void mouseClicked(MouseEv...";
}
});
}
}
public static Map putAll(Map a, Map extends A, ? extends B> b) {
if (a != null)
a.putAll(b);
return a;
}
public static LinkedHashMap litorderedmap(Object... x) {
LinkedHashMap map = new LinkedHashMap();
litmap_impl(map, x);
return map;
}
public static A unlisted(Class c, Object... args) {
concepts_unlisted.set(true);
try {
return nuObject(c, args);
} finally {
concepts_unlisted.set(null);
}
}
public static void register(Concept c) {
db_mainConcepts().register(c);
}
public static AutoCloseable tempSetMCOpt(final String field, Object value) {
final Object oldValue = getMCOpt(field);
setMCOpt(field, value);
return new AutoCloseable() {
public String toString() {
return "setMCOpt(field, oldValue);";
}
public void close() throws Exception {
setMCOpt(field, oldValue);
}
};
}
public static JPanel showFormTitled2(String title, Object... parts) {
return showFormTitled_customLayout(formLayouter1(), title, parts);
}
public static Object[] arrayPlus(Object[] a1, Object... a2) {
return concatArrays(a1, a2);
}
public static Object[] mapToObjectArray(Map map) {
List l = new ArrayList();
for (Object o : keys(map)) {
l.add(o);
l.add(map.get(o));
}
return toObjectArray(l);
}
public static Object selectedTableCell(JTable t, int col) {
return getTableCell(t, selectedTableRow(t), col);
}
public static Object selectedTableCell(final JTable t) {
return swing(new F0() {
public Object get() {
try {
return selectedTableCell(t, t.getSelectedColumn());
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret selectedTableCell(t, t.getSelectedColumn());";
}
});
}
public static Object selectedTableCell(final JTable t, final String colName) {
return swing(new F0() {
public Object get() {
try {
return selectedTableCell(t, tableColumnViewIndex(t, colName));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret selectedTableCell(t, tableColumnViewIndex(t, colName));";
}
});
}
public static JCheckBox jCenteredCheckBox() {
return centerCheckBox(new JCheckBox());
}
public static JCheckBox jCenteredCheckBox(boolean checked) {
return centerCheckBox(new JCheckBox("", checked));
}
public static JCheckBox jCenteredCheckBox(String text, boolean checked) {
return centerCheckBox(new JCheckBox(text, checked));
}
public static JCheckBox jCenteredCheckBox(String text) {
return centerCheckBox(new JCheckBox(text));
}
public static JCheckBox jCenteredCheckBox(String text, boolean checked, final Object onChange) {
return centerCheckBox(jCheckBox(text, checked, onChange));
}
public static JCheckBox jCenteredCheckBox(boolean checked, final Object onChange) {
return centerCheckBox(jCheckBox(checked, onChange));
}
public static JTextArea typeWriterTextArea() {
return newTypeWriterTextArea();
}
public static JTextArea typeWriterTextArea(String text) {
return newTypeWriterTextArea(text);
}
public static AutoComboBox autoComboBox() {
return autoComboBox(new ArrayList());
}
public static AutoComboBox autoComboBox(final Collection items) {
return swing(new F0() {
public AutoComboBox get() {
try {
AutoComboBox cb = new AutoComboBox();
cb.setKeyWord(items);
return cb;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "new AutoComboBox cb;\r\n cb.setKeyWord(items);\r\n ret cb;";
}
});
}
public static AutoComboBox autoComboBox(String value, Collection items) {
return setText(autoComboBox(items), value);
}
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 (Object o : l) x.add(callF(f, 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 collect(Collection c, String field) {
return collectField(c, field);
}
public static List collect(String field, Collection c) {
return collectField(c, field);
}
public static List collect(Class c, String field) {
return collect(list(c), field);
}
public static void printException(Throwable e) {
printStackTrace(e);
}
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 JComponent unwrap(JComponent c) {
return c instanceof JScrollPane ? unwrapScrollPane((JScrollPane) c) : c;
}
public static Object convertToField(Object o, Class c, String field) {
Field f = setOpt_findField(c, field);
if (f == null)
return o;
Class t = f.getType();
if (t == Long.class || t == long.class)
return toLong(o);
else if (t == Integer.class || t == int.class)
return toInt(o);
else if (t == String.class)
return o instanceof String ? (String) o : str(o);
else if (t == File.class)
if (o instanceof String)
return new File((String) o).getAbsoluteFile();
return o;
}
public static String trimIf(boolean b, String s) {
return b ? trim(s) : s;
}
public static String getText(final AbstractButton c) {
return c == null ? "" : (String) swingAndWait(new F0() {
public Object get() {
try {
return c.getText();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret c.getText();";
}
});
}
public static String getText(final JTextComponent c) {
return c == null ? "" : (String) swingAndWait(new F0() {
public Object get() {
try {
return c.getText();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret c.getText();";
}
});
}
public static String getText(final JLabel l) {
return l == null ? "" : (String) swingAndWait(new F0() {
public Object get() {
try {
return l.getText();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret l.getText();";
}
});
}
public static String getText(final JComboBox cb) {
if (cb == null)
return null;
if (isEditableComboBox(cb))
return unnull((String) cb.getEditor().getItem());
else
return str(cb.getSelectedItem());
}
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 boolean isChecked(final JCheckBox checkBox) {
return checkBox != null && (boolean) swing(new F0() {
public Boolean get() {
try {
return checkBox.isSelected();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret checkBox.isSelected();";
}
});
}
public static boolean isChecked(final JCheckBoxMenuItem mi) {
return mi != null && (boolean) swing(new F0() {
public Boolean get() {
try {
return mi.isSelected();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret mi.isSelected();";
}
});
}
public static void cUpdatePNGFile(Concept c, String field, BufferedImage image, boolean deleteOldFile) {
PNGFile png = (PNGFile) (cget(c, field));
if (image == null && png != null)
cset(c, field, null);
else if (image != null && (png == null || !imagesIdentical(png.getImage(), image))) {
if (png != null && deleteOldFile)
png.delete();
cset(c, field, new PNGFile(image));
}
}
public static Set fields(Object c) {
return listFields(c);
}
public static List listWithoutSet(Collection l, Collection stuff) {
return listMinusSet(l, stuff);
}
public static List filter(Iterable c, Object pred) {
if (pred instanceof F1)
return filter(c, (F1 ) pred);
List x = new ArrayList();
if (c != null)
for (Object o : c) if (isTrue(callF(pred, o)))
x.add(o);
return x;
}
public static List filter(Object pred, Iterable c) {
return filter(c, pred);
}
public static List filter(Iterable c, F1 pred) {
List x = new ArrayList();
if (c != null)
for (B o : c) if (pred.get(o).booleanValue())
x.add(o);
return x;
}
public static List filter(F1 pred, Iterable c) {
return filter(c, pred);
}
public static List conceptFieldsInOrder(Concept c) {
return conceptFieldsInOrder(c.getClass());
}
public static List conceptFieldsInOrder(Class extends Concept> c) {
String order = toStringOpt(getOpt(c, "_fieldOrder"));
Set set = asTreeSet(conceptFields(c));
if (order == null)
return asList(set);
List fields = splitAtSpace(order);
setAddAll(fields, set);
return fields;
}
public static Set setPlus(Collection l, A... more) {
Set set = similarEmptySet(l);
addAll(set, l);
for (A a : more) set.add(a);
return set;
}
public static Set keys(Map map) {
return map == null ? new HashSet() : map.keySet();
}
public static Set keys(Object map) {
return keys((Map) map);
}
public static long now_virtualTime;
public static long now() {
return now_virtualTime != 0 ? now_virtualTime : System.currentTimeMillis();
}
public static Map> setTableModel_after = weakHashMap();
public static Map> setTableModel_fixSorter = weakHashMap();
public static void setTableModel(final JTable table, final TableModel model) {
{
swing(new Runnable() {
public void run() {
try {
Map widths = tableColumnWidthsByName(table);
int[] i = table.getSelectedRows();
TableRowSorter sorter = model.getColumnCount() == tableColumnCount(table) ? (TableRowSorter) table.getRowSorter() : null;
List extends RowSorter.SortKey> sortKeys = sorter == null ? null : sorter.getSortKeys();
table.setModel(model);
int n = model.getRowCount();
ListSelectionModel sel = table.getSelectionModel();
for (int j = 0; j < i.length; j++) if (i[j] < n)
sel.addSelectionInterval(i[j], i[j]);
tableSetColumnPreferredWidths(table, widths);
if (sorter != null) {
sorter.setModel(model);
callF(setTableModel_fixSorter.get(table), table, sorter);
if (sortKeys != null)
sorter.setSortKeys(sortKeys);
}
table.setRowSorter(sorter);
callF(setTableModel_after.get(table), table);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Map widths = tableColumnWidthsByName(table);\r\n int[] i = ...";
}
});
}
}
public static String structureOrText(Object o) {
return o instanceof String ? (String) o : structure(o);
}
public static ChangeListener changeListener(final Object r) {
return new ChangeListener() {
public void stateChanged(ChangeEvent e) {
pcallF(r);
}
};
}
public static ItemListener itemListener(final Object r) {
return new ItemListener() {
public void itemStateChanged(ItemEvent e) {
pcallF(r);
}
};
}
public static void onUpdate(JComponent c, final Object r) {
if (c instanceof JTextComponent)
((JTextComponent) c).getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
call(r);
}
public void removeUpdate(DocumentEvent e) {
call(r);
}
public void changedUpdate(DocumentEvent e) {
call(r);
}
});
else if (c instanceof ItemSelectable)
((ItemSelectable) c).addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
call(r);
}
});
else
print("Warning: onUpdate doesn't know " + getClassName(c));
}
public static void onUpdate(List extends JComponent> l, Object r) {
for (JComponent c : l) onUpdate(c, r);
}
public static boolean isEditableComboBox(final JComboBox cb) {
return cb != null && swing(new F0() {
public Boolean get() {
try {
return cb.isEditable();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret cb.isEditable();";
}
});
}
public static JTextField textFieldFromComboBox(JComboBox cb) {
return (JTextField) cb.getEditor().getEditorComponent();
}
public static JComboBox onSelectedItem(final JComboBox cb, final VF1 f) {
addActionListener(cb, new Runnable() {
public void run() {
try {
pcallF(f, selectedItem(cb));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pcallF(f, selectedItem(cb))";
}
});
return cb;
}
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 volatile boolean conceptsAndBot_running;
public static void conceptsAndBot() {
conceptsAndBot(null);
}
public static void conceptsAndBot(Integer autoSaveInterval) {
if (conceptsAndBot_running)
return;
conceptsAndBot_running = true;
try {
ensureDBNotRunning(dbBotStandardName());
} catch (Throwable _e) {
db_mainConcepts().dontSave = true;
throw rethrow(_e);
}
if (autoSaveInterval != null)
db_mainConcepts().persist(autoSaveInterval);
else
db_mainConcepts().persist();
dbBot();
}
public static int tableNumColumns(final JTable table) {
return swing(new F0() {
public Integer get() {
try {
return table.getColumnCount();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret table.getColumnCount();";
}
});
}
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) {
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 String joinWithSpace(Collection c) {
return join(" ", c);
}
public static String joinWithSpace(String... c) {
return join(" ", c);
}
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 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(RootPaneContainer c) {
revalidate((Component) c);
}
public static void revalidate(JFrame f) {
revalidate((Component) f);
}
public static void revalidate(JInternalFrame f) {
revalidate((Component) f);
}
public static boolean newButton_autoToolTip = true;
public static JButton newButton(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);
if (newButton_autoToolTip) {
btn.setToolTipText(btn.getText());
}
if (action != null)
btn.addActionListener(actionListener(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 A swingNu(final Class c, final Object... args) {
return swingConstruct(c, args);
}
public static void onConceptsChangeAndNow(Runnable r) {
onConceptsChange(r);
callF(r);
}
public static String getProgramName_cache;
public static String getProgramName() {
Lock __830 = downloadLock();
lock(__830);
try {
if (getProgramName_cache == null)
getProgramName_cache = getSnippetTitleOpt(programID());
return getProgramName_cache;
} finally {
unlock(__830);
}
}
public static void _onLoad_getProgramName() {
startThread(new Runnable() {
public void run() {
try {
getProgramName();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "getProgramName();";
}
});
}
public static List findConceptsWhere(Class c, Object... params) {
return findConceptsWhere(db_mainConcepts(), c, params);
}
public static List findConceptsWhere(String c, Object... params) {
return findConceptsWhere(db_mainConcepts(), c, params);
}
public static List findConceptsWhere(Concepts concepts, Class c, Object... params) {
params = expandParams(c, params);
if (concepts.fieldIndices != null)
for (int i = 0; i < l(params); i += 2) {
IFieldIndex index = concepts.getFieldIndex(c, (String) params[i]);
if (index != null) {
List rawList = index.getAll(params[i + 1]);
params = dropEntryFromParams(params, i);
if (params == null)
return rawList;
List l = new ArrayList();
for (A x : rawList) if (checkConceptFields(x, params))
l.add(x);
return l;
}
}
return filterConcepts(concepts.list(c), params);
}
public static List findConceptsWhere(Concepts concepts, String c, Object... params) {
return filterConcepts(concepts.list(c), params);
}
public static String makeFrame_defaultIcon;
public static boolean makeFrame_hideConsole;
public static ThreadLocal> makeFrame_post = new ThreadLocal();
public static JFrame makeFrame() {
return makeFrame((Component) null);
}
public static JFrame makeFrame(Object content) {
return makeFrame(programTitle(), content);
}
public static JFrame makeFrame(String title) {
return makeFrame(title, null);
}
public static JFrame makeFrame(String title, Object content) {
return makeFrame(title, content, true);
}
public static JFrame makeFrame(final String title, final Object content, final boolean showIt) {
final VF1 post = optParam(makeFrame_post);
return swing(new F0() {
public JFrame get() {
try {
if (getFrame(content) != null)
return getFrame(setFrameTitle((Component) content, title));
final JFrame frame = new JFrame(title);
if (makeFrame_defaultIcon != null)
setFrameIconLater(frame, makeFrame_defaultIcon);
_initFrame(frame);
Component wrapped = wrap(content);
if (wrapped != null)
frame.getContentPane().add(wrapped);
frame.setBounds(defaultNewFrameBounds());
callF(post, frame);
if (showIt)
frame.setVisible(true);
if (showIt && makeFrame_hideConsole) {
hideConsole();
makeFrame_hideConsole = false;
}
return frame;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (getFrame(content) != null)\r\n ret getFrame(setFrameTitle((Component) ...";
}
});
}
public static boolean frameTooSmall(JFrame frame) {
return frame.getWidth() < 100 || frame.getHeight() < 50;
}
public static void frameStandardSize(JFrame frame) {
frame.setBounds(300, 100, 500, 400);
}
public static void setFrameContents(final Component c, final Object contents) {
{
swing(new Runnable() {
public void run() {
try {
JFrame frame = getFrame(c);
frame.getContentPane().removeAll();
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(wrap(contents));
revalidate(frame);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JFrame frame = getFrame(c);\r\n frame.getContentPane().removeAll();\r\n fra...";
}
});
}
}
public static List getPlural_specials = ll("sheep", "fish");
public static String getPlural(String s) {
if (containsIgnoreCase(getPlural_specials, s))
return s;
if (ewic(s, "y"))
return dropSuffixIgnoreCase("y", s) + "ies";
if (ewic(s, "ss"))
return s + "es";
if (ewic(s, "s"))
return s;
return s + "s";
}
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 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...";
}
});
}
public static Rectangle maximumWindowBounds() {
return maxWindowBounds();
}
public static long sysNow() {
ping();
return System.nanoTime() / 1000000;
}
public static boolean warn_on = true;
public static void warn(String s) {
if (warn_on)
print("Warning: " + s);
}
public static void warn(String s, List warnings) {
warn(s);
if (warnings != null)
warnings.add(s);
}
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 volatile boolean sleep_noSleep;
public static void sleep(long ms) {
ping();
if (ms < 0)
return;
if (isAWTThread() && ms > 100)
throw fail("Should not sleep on AWT thread");
try {
Thread.sleep(ms);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void sleep() {
try {
if (sleep_noSleep)
throw fail("nosleep");
print("Sleeping.");
sleepQuietly();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String programIDPlusHome() {
String s = fsI(programID());
String home = userHomeIfNotActual();
if (home != null)
s += " " + quote(home);
return s;
}
public static void swingLater(long delay, final Object r) {
javax.swing.Timer timer = new javax.swing.Timer(toInt(delay), actionListener(wrapAsActivity(r)));
timer.setRepeats(false);
timer.start();
}
public static void swingLater(Object r) {
SwingUtilities.invokeLater(toRunnable(r));
}
public static List activateMyFrames() {
final List l = myFrames();
{
swing(new Runnable() {
public void run() {
try {
for (JFrame f : l) activateFrame(f);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "for (JFrame f : l)\r\n activateFrame(f);";
}
});
}
return l;
}
public static String programName() {
return getProgramName();
}
public static int makeBot(String greeting) {
return makeAndroid3(greeting).port;
}
public static Android3 makeBot(Android3 a) {
makeAndroid3(a);
return a;
}
public static Android3 makeBot(String greeting, Object responder) {
Android3 a = new Android3(greeting);
a.responder = makeResponder(responder);
makeBot(a);
return a;
}
public static Android3 makeBot() {
return makeAndroid3(defaultBotName());
}
public static A getAndClearThreadLocal(ThreadLocal tl) {
A a = tl.get();
tl.set(null);
return a;
}
public static A optParam(ThreadLocal tl, A defaultValue) {
return optPar(tl, defaultValue);
}
public static A optParam(ThreadLocal tl) {
return optPar(tl);
}
public static A optParam(Object[] opt, String name, A 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 A optParam(Object[] opt, String name) {
return optParam(opt, name, null);
}
public static List listMinusList(Collection l, Collection stuff) {
if (empty(stuff) && l instanceof List)
return (List) l;
List l2 = cloneList(l);
for (Object o : stuff) l2.remove(o);
return l2;
}
public static List concatLists(Collection ... lists) {
List l = new ArrayList();
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
public static List concatLists(Collection extends Collection > lists) {
List l = new ArrayList();
for (Collection list : lists) if (list != null)
l.addAll(list);
return l;
}
public static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
for (A x : a) l.add(x);
return l;
}
public static boolean sexyTable_drag = false;
public static JTable sexyTable() {
final JTable table = sexyTableWithoutDrag();
if (sexyTable_drag)
tableEnableTextDrag(table);
return table;
}
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 void deleteConcept(long id) {
db_mainConcepts().deleteConcept(id);
}
public static void deleteConcept(Concept c) {
if (c != null)
c.delete();
}
public static void deleteConcept(Concept.Ref ref) {
if (ref != null)
deleteConcept(ref.get());
}
public static int awtOnConceptChanges_defaultDelay = 1000;
public static void awtOnConceptChanges(Component component, Object runnable) {
awtOnConceptChanges(componentToJComponent(component), runnable, true);
}
public static void awtOnConceptChanges(JComponent component, final Object runnable, boolean runOnFirstTime) {
awtOnConceptChanges(component, awtOnConceptChanges_defaultDelay, 0, runnable, runOnFirstTime);
}
public static void awtOnConceptChanges(JComponent component, int delay, final Object runnable) {
awtOnConceptChanges(component, delay, delay, runnable);
}
public static void awtOnConceptChanges(JComponent component, int delay, int firstDelay, Object runnable) {
awtOnConceptChanges(component, delay, firstDelay, runnable, true);
}
public static boolean awtOnConceptChanges_debug;
public static void awtOnConceptChanges(JComponent component, int delay, int firstDelay, final Object runnable, final boolean runOnFirstTime) {
installTimer(component, delay, firstDelay, new Runnable() {
public long c = runOnFirstTime ? -1 : changeCount();
public void run() {
long _c = changeCount();
if (awtOnConceptChanges_debug)
print("awtOnConceptChanges: " + _c + " / " + c);
if (_c != c) {
c = _c;
call(runnable);
}
}
});
}
public static Object renderForTable(Object o) {
return or(toBufferedImageOpt(o), o);
}
public static A postProcess(Object f, A a) {
return callPostProcessor(f, a);
}
public static void fillTableWithData(final JTable table, List rows, List colNames) {
fillTableWithData(table, rows, toStringArray(colNames));
}
public static void fillTableWithData(final JTable table, List rows, String... colNames) {
final DefaultTableModel model = fillTableWithData_makeModel(rows, colNames);
setTableModel(table, model);
}
public static DefaultTableModel fillTableWithData_makeModel(List rows, String... colNames) {
Pair p = fillTableWithData_makeData(rows, colNames);
return new DefaultTableModel(p.a, p.b) {
public Class getColumnClass(int column) {
return or(_getClass(getValueAt(0, column)), String.class);
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
};
}
public static void addIfNotNull(Collection l, A a) {
if (a != null && l != null)
l.add(a);
}
public static JTable dataToTable_uneditable(Object data, final JTable table) {
return dataToTable_uneditable(table, data);
}
public static JTable dataToTable_uneditable(final JTable table, final Object data) {
{
swing(new Runnable() {
public void run() {
try {
dataToTable(table, data, true);
makeTableUneditable(table);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "dataToTable(table, data, true);\r\n makeTableUneditable(table);";
}
});
}
return table;
}
public static JTable dataToTable_uneditable(final Object data) {
return dataToTable_uneditable(showTable(), data);
}
public static JTable dataToTable_uneditable(Object data, String title) {
return dataToTable_uneditable(showTable(title), data);
}
public 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;
}
public static A setFrameTitle(String title, A c) {
return setFrameTitle(c, title);
}
public static JFrame setFrameTitle(String title) {
Object f = getOpt(mc(), "frame");
if (f instanceof JFrame)
return setFrameTitle((JFrame) f, title);
return null;
}
public static JPanel jrightAlignedLine(final Component... components) {
return swing(new F0() {
public RightAlignedLine get() {
try {
return new RightAlignedLine(components);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret RightAlignedLine(components);";
}
});
}
public static JPanel jrightAlignedLine(List extends Component> components) {
return jrightAlignedLine(asArray(Component.class, components));
}
public static void tableDependButtons(final JTable table, List extends Component> buttons) {
for (Component c : buttons) if (c instanceof JButton) {
final JButton b = (JButton) (c);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
b.setEnabled(table.getSelectedRow() >= 0);
}
});
b.setEnabled(table.getSelectedRow() >= 0);
}
}
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 boolean anyValueContainsIgnoreCase(Map map, String pat) {
for (Object val : values(map)) if (val instanceof String && containsIgnoreCase((String) val, pat))
return true;
return false;
}
public static List> rawTableData(JTable t) {
int n = tableRows(t);
List l = new ArrayList();
for (int i = 0; i < n; i++) l.add(rawTableLineAsMap(t, i));
return l;
}
public static JTable dataToTable(Object data) {
return dataToTable(showTable(), data);
}
public static JTable dataToTable(Object data, String title) {
return dataToTable(showTable(title), data);
}
public static JTable dataToTable(JTable table, Object data) {
return dataToTable(table, data, false);
}
public static JTable dataToTable(JTable table, Object data, boolean now) {
List rows = new ArrayList();
List cols = new ArrayList();
if (data instanceof List) {
for (Object x : (List) data) {
try {
rows.add(dataToTable_makeRow(x, cols));
} catch (Throwable __e) {
_handleException(__e);
}
}
} else if (data instanceof Map) {
Map map = (Map) (data);
for (Object key : map.keySet()) {
Object value = map.get(key);
rows.add(litlist(structureOrTextForUser(key), structureOrTextForUser(value)));
}
} else if (data != null)
print("Unknown data type: " + data);
fillTableWithData(table, rows, cols);
return table;
}
public static boolean boolOptPar(ThreadLocal tl) {
return boolOptParam(tl);
}
public static boolean boolOptPar(Object[] __, String name) {
return boolOptParam(__, name);
}
public static JPanel northAndCenterWithMargin(Component n, Component c) {
return northAndCenter(withBottomMargin(n), c);
}
public static JPanel northAndCenter(Component n, Component c) {
return centerAndNorth(c, n);
}
public static int withTopMargin_defaultWidth = 6;
public static JPanel withTopMargin(Component c) {
return withTopMargin(withTopMargin_defaultWidth, c);
}
public static JPanel withTopMargin(final int w, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(w, 0, 0, 0));
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 boolean isInstance(Class type, Object arg) {
return type.isInstance(arg);
}
public static Object getMCOpt(String field) {
return getOptMC(field);
}
public static void setMCOpt(String field, Object value) {
setOptMC(field, value);
}
public static JPanel showFormTitled_customLayout(final F1 layouter, final String title, final Object... parts) {
return showFormTitled_customArrangement(false, new F1, JPanel>() {
public JPanel get(List components) {
try {
return customLayoutPanel(layouter, components);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "customLayoutPanel(layouter, components)";
}
}, title, parts);
}
public static int formLayouter1_yPlus = 5;
public static int formLayouter1_fixer2 = 0;
public static F1 formLayouter1() {
final int yplus = formLayouter1_yPlus, fixer2 = formLayouter1_fixer2;
return new F1() {
public Dimension get(Container parent) {
try {
List l = getComponents(parent);
BitSet bigOnes = new BitSet();
for (int i = 0; i < l(l); i++) if (containsATextArea(l.get(i)))
add(bigOnes, i);
int nBigOnes = bigOnes.cardinality();
int mandatoryHeight = totalPreferredHeight(listWithoutIndicesInBitSet(l, bigOnes));
int gap = 4, outerSpacing = 5;
Dimension size = parent.getSize();
int gapsAndMargins = outerSpacing * 2 - (l(l) - 1) * gap;
int totalSpace = size.height - gapsAndMargins - fixer2;
int liberalSpace = totalSpace - mandatoryHeight;
double perBigOne = doubleRatio(liberalSpace, nBigOnes);
double y = outerSpacing;
for (int i = 0; i < l(l); i++) {
Component c = l.get(i);
boolean big = contains(bigOnes, i);
double h = big ? perBigOne : c.getPreferredSize().height;
int actualY = iround(y);
c.setBounds(10, actualY, size.width - outerSpacing * 2, iround(y + h) - actualY);
y += h + gap;
}
Dimension pref = componentsBoundingSize(parent, outerSpacing);
if (parent.getHeight() == 0)
pref.height = totalPreferredHeight(l) + gapsAndMargins + yplus;
return pref;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "L l = getComponents(parent);\r\n new BitSet bigOnes;\r\n for i o...";
}
};
}
public static Object[] concatArrays(Object[]... arrays) {
int l = 0;
for (Object[] a : arrays) l += l(a);
Object[] x = new Object[l];
int i = 0;
for (Object[] a : arrays) if (a != null) {
System.arraycopy(a, 0, x, i, l(a));
i += l(a);
}
return x;
}
public static Object[] toObjectArray(Collection c) {
List l = asList(c);
return l.toArray(new Object[l.size()]);
}
public static int selectedTableRow(final JTable t) {
return t == null ? -1 : swing(new F0() {
public Integer get() {
try {
return t.getSelectedRow();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret t.getSelectedRow();";
}
});
}
public static int tableColumnViewIndex(final JTable t, final String colName) {
return swing(new F0() {
public Integer get() {
try {
return t.convertColumnIndexToView(t.getColumn(colName).getModelIndex());
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret t.convertColumnIndexToView(t.getColumn(colName).getModelIndex());";
}
});
}
public static JCheckBox centerCheckBox(JCheckBox cb) {
return setHorizontalAlignment(SwingConstants.CENTER, cb);
}
public static JCheckBox jCheckBox() {
return swingNu(JCheckBox.class);
}
public static JCheckBox jCheckBox(boolean checked) {
return swingNu(JCheckBox.class, "", checked);
}
public static JCheckBox jCheckBox(String text, boolean checked) {
return swingNu(JCheckBox.class, text, checked);
}
public static JCheckBox jCheckBox(String text) {
return swingNu(JCheckBox.class, text);
}
public static JCheckBox jCheckBox(String text, boolean checked, final Object onChange) {
JCheckBox cb = jCheckBox(checked, onChange);
cb.setText(text);
return cb;
}
public static JCheckBox jCheckBox(boolean checked, final Object onChange) {
final JCheckBox cb = jCheckBox(checked);
cb.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
pcallF(onChange, cb.isSelected());
}
});
return cb;
}
public static JTextArea newTypeWriterTextArea() {
return newTypeWriterTextArea("");
}
public static JTextArea newTypeWriterTextArea(String text) {
return setFont(jTextArea(text), typeWriterFont());
}
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(Class c) {
return new ArrayList();
}
public static List collectField(Collection c, String field) {
List l = new ArrayList();
if (c != null)
for (Object a : c) l.add(getOpt(a, field));
return l;
}
public static List collectField(String field, Collection c) {
return collectField(c, field);
}
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 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 JComponent unwrapScrollPane(JScrollPane sp) {
return sp == null ? null : (JComponent) sp.getViewport().getView();
}
public static Field setOpt_findField(Class c, String field) {
HashMap map;
synchronized (getOpt_cache) {
map = getOpt_cache.get(c);
if (map == null)
map = getOpt_makeCache(c);
}
return map.get(field);
}
public static void setOpt(Object o, String field, Object value) {
try {
if (o == null)
return;
Class c = o.getClass();
HashMap map;
if (getOpt_cache == null)
map = getOpt_makeCache(c);
else
synchronized (getOpt_cache) {
map = getOpt_cache.get(c);
if (map == null)
map = getOpt_makeCache(c);
}
if (map == getOpt_special) {
if (o instanceof Class) {
setOpt((Class) o, field, value);
return;
}
setOpt_raw(o, field, value);
return;
}
Field f = map.get(field);
if (f != null)
smartSet(f, o, value);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static void setOpt(Class c, String field, Object value) {
if (c == null)
return;
try {
Field f = setOpt_findStaticField(c, field);
if (f != null)
smartSet(f, null, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Field setOpt_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) {
f.setAccessible(true);
return f;
}
_c = _c.getSuperclass();
} while (_c != null);
return null;
}
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 boolean imagesIdentical(BufferedImage img1, BufferedImage img2) {
if (img1 == null)
return img2 == null;
if (img2 == null)
return false;
int w = img1.getWidth(), h = img1.getHeight();
if (w != img2.getWidth() || h != img2.getHeight())
return false;
for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) if (img1.getRGB(x, y) != img2.getRGB(x, y))
return false;
return true;
}
public static Set listFields(Object c) {
TreeSet fields = new TreeSet();
for (Field f : _getClass(c).getDeclaredFields()) fields.add(f.getName());
return fields;
}
public static List listMinusSet(Iterable l, Collection stuff) {
if (empty(stuff))
return asList(l);
Set set = asSet(stuff);
List l2 = new ArrayList();
for (A a : l) if (!set.contains(a))
l2.add(a);
return l2;
}
public static String toStringOpt(Object o) {
return o instanceof String ? ((String) o) : null;
}
public static TreeSet asTreeSet(List l) {
TreeSet set = new TreeSet();
for (Object o : l) if (o != null)
set.add(o);
return set;
}
public static TreeSet asTreeSet(Set set) {
return set instanceof TreeSet ? (TreeSet) set : new TreeSet(set);
}
public static String[] conceptFields_drop = { "className", "fieldValues", "id", "created", "refs", "backRefs", "_concepts" };
public static Set conceptFields(Concept c) {
return setMinus(mergeSets(allNonStaticNonTransientFields(c), keys(c.fieldValues)), conceptFields_drop);
}
public static Set conceptFields(Class extends Concept> c) {
return setMinus(allNonStaticNonTransientFields(c), conceptFields_drop);
}
public static List splitAtSpace(String s) {
return empty(s) ? emptyList() : asList(s.split("\\s+"));
}
public static void setAddAll(List a, Collection b) {
for (A x : b) setAdd(a, x);
}
public static Set similarEmptySet(Collection m) {
if (m instanceof TreeSet)
return new TreeSet(((TreeSet) m).comparator());
if (m instanceof LinkedHashSet)
return new LinkedHashSet();
return new HashSet();
}
public static void addAll(Collection c, Iterable b) {
if (c != null && b != null)
for (A a : b) c.add(a);
}
public static boolean addAll(Collection c, Collection b) {
return c != null && b != null && c.addAll(b);
}
public static boolean addAll(Collection c, B... b) {
return c != null && c.addAll(Arrays.asList(b));
}
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 class getOpt_Map extends WeakHashMap {
public getOpt_Map() {
if (getOpt_special == null)
getOpt_special = new HashMap();
clear();
}
public void clear() {
super.clear();
put(Class.class, getOpt_special);
put(String.class, getOpt_special);
}
}
public static final Map> getOpt_cache = _registerDangerousWeakMap(synchroMap(new getOpt_Map()));
public static HashMap getOpt_special;
public static Object getOpt_cached(Object o, String field) {
try {
if (o == null)
return null;
Class c = o.getClass();
HashMap map;
synchronized (getOpt_cache) {
map = getOpt_cache.get(c);
if (map == null)
map = getOpt_makeCache(c);
}
if (map == getOpt_special) {
if (o instanceof Class)
return getOpt((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
}
Field f = map.get(field);
if (f != null)
return f.get(o);
if (o instanceof DynamicObject)
return ((DynamicObject) o).fieldValues.get(field);
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static HashMap getOpt_makeCache(Class c) {
HashMap map;
if (isSubtypeOf(c, Map.class))
map = getOpt_special;
else {
map = new HashMap();
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) {
f.setAccessible(true);
String name = f.getName();
if (!map.containsKey(name))
map.put(name, f);
}
_c = _c.getSuperclass();
} while (_c != null);
}
if (getOpt_cache != null)
getOpt_cache.put(c, map);
return map;
}
public static Map weakHashMap() {
return newWeakHashMap();
}
public static Map tableColumnWidthsByName(JTable table) {
TableColumnModel tcm = table.getColumnModel();
if (tcm == null)
return null;
int n = tcm.getColumnCount();
TreeMap map = new TreeMap();
for (int i = 0; i < n; i++) {
TableColumn tc = tcm.getColumn(i);
map.put(str(tc.getHeaderValue()), tc.getWidth());
}
return map;
}
public static boolean tableSetColumnPreferredWidths_debug;
public static void tableSetColumnPreferredWidths(final JTable table, final Map widths) {
if (table == null || widths == null)
return;
{
swing(new Runnable() {
public void run() {
try {
try {
TableColumnModel tcm = table.getColumnModel();
int n = tcm.getColumnCount();
for (int i = 0; i < n; i++) {
TableColumn tc = tcm.getColumn(i);
Integer w = widths.get(str(tc.getHeaderValue()));
if (w != null) {
tc.setPreferredWidth(w);
if (tableSetColumnPreferredWidths_debug)
print("Setting preferred width of column " + i + " to " + w);
}
}
} catch (Throwable __e) {
_handleException(__e);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "pcall {\r\n TableColumnModel tcm = table.getColumnModel();\r\n int n = tcm....";
}
});
}
}
public static void tableSetColumnPreferredWidths(JTable table, Object... widths) {
tableSetColumnPreferredWidths(table, litorderedmap(widths));
}
public static void addActionListener(JTextField tf, final Runnable action) {
onEnter(tf, action);
}
public static void addActionListener(final JComboBox cb, final Runnable action) {
if (cb != null) {
swing(new Runnable() {
public void run() {
try {
cb.addActionListener(actionListener(action));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "cb.addActionListener(actionListener(action));";
}
});
}
}
public static void addActionListener(final AbstractButton b, final Runnable action) {
if (b != null) {
swing(new Runnable() {
public void run() {
try {
b.addActionListener(actionListener(action));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "b.addActionListener(actionListener(action));";
}
});
}
}
public static String selectedItem(JList l) {
return getSelectedItem(l);
}
public static String selectedItem(JComboBox cb) {
return getSelectedItem(cb);
}
public static Object collectionMutex(Object 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 void ensureDBNotRunning(String name) {
if (hasBot(name)) {
try {
String id = fsI(dropAfterSpace(name));
String framesBot = id + " Frames";
print("Trying to activate frames of running DB: " + id);
if (isOK(sendOpt(framesBot, "activate frames")) && isMainProgram())
cleanKill();
} catch (Throwable __e) {
_handleException(__e);
}
throw fail("Already running: " + name);
}
}
public static void ensureDBNotRunning() {
ensureDBNotRunning(dbBotStandardName());
}
public static String dbBotStandardName() {
String home = userHome();
String name = dbBotName(getDBProgramID());
if (neq(home, actualUserHome()))
name += " " + quote(home);
return name + ".";
}
public static volatile Android3 dbBot_instance;
public static Android3 dbBot() {
return dbBot(dbBotStandardName());
}
public static Android3 dbBot(String name) {
ensureDBNotRunning(name);
assertNotNull(mainConcepts);
return dbBot_instance = methodsBot2(name, mainConcepts, db_standardExposedMethods(), mainConcepts.lock);
}
public static boolean containsSpaces(String s) {
return indexOf(s, ' ') >= 0;
}
public static A getOrKeep(Map map, A 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();
for (int i = 0; i < l(s); i++) if (isUpperCaseLetter(s.charAt(i)) && i > j) {
l.add(substring(s, j, i));
j = i;
}
if (j < l(s))
l.add(substring(s, j));
return l;
}
public static String dropPrefix(String prefix, String s) {
return s == null ? null : s.startsWith(prefix) ? s.substring(l(prefix)) : s;
}
public static ActionListener actionListener(final Object runnable) {
return actionListener(runnable, null);
}
public static ActionListener actionListener(final Object runnable, final Object instanceToHold) {
if (runnable instanceof ActionListener)
return (ActionListener) runnable;
final Object info = _threadInfo();
return new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent _evt) {
try {
_threadInheritInfo(info);
AutoCloseable __71 = holdInstance(instanceToHold);
try {
callF(runnable);
} finally {
_close(__71);
}
} catch (Throwable __e) {
messageBox(__e);
}
}
};
}
public static void onConceptsChange(Runnable r) {
addConceptIndex(simpleConceptIndex(r));
}
public static Lock downloadLock_lock = fairLock();
public static Lock downloadLock() {
return downloadLock_lock;
}
public static String getSnippetTitleOpt(String s) {
return isSnippetID(s) ? getSnippetTitle(s) : s;
}
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 Object[] expandParams(Class c, Object[] params) {
if (l(params) == 1)
params = new Object[] { singleFieldName(c), params[0] };
else
warnIfOddCount(params);
return params;
}
public static Object[] dropEntryFromParams(Object[] params, int i) {
int n = l(params);
if (i < 0 || i >= n)
return params;
if (n == 2)
return null;
Object[] p = new Object[n - 2];
System.arraycopy(params, 0, p, 0, i);
System.arraycopy(params, i + 2, p, i, n - i - 2);
return p;
}
public static boolean checkConceptFields(Concept x, Object... data) {
for (int i = 0; i < l(data); i += 2) if (neq(cget(x, (String) data[i]), deref(data[i + 1])))
return false;
return true;
}
public static List filterConcepts(List list, Object... params) {
List l = new ArrayList();
for (A x : list) if (checkConceptFields(x, params))
l.add(x);
return l;
}
public static 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;
}
public static void _initFrame(JFrame f) {
myFrames_list.put(f, Boolean.TRUE);
standardTitlePopupMenu(f);
}
public static Rectangle defaultNewFrameBounds_r = new Rectangle(300, 100, 500, 400);
public static Rectangle defaultNewFrameBounds() {
return swing(new F0() {
public Rectangle get() {
try {
defaultNewFrameBounds_r.translate(60, 20);
if (!screenRectangle().contains(defaultNewFrameBounds_r))
defaultNewFrameBounds_r.setLocation(30 + random(30), 20 + random(20));
return new Rectangle(defaultNewFrameBounds_r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "defaultNewFrameBounds_r.translate(60, 20);\r\n if (!screenRectangle().contai...";
}
});
}
public static 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);";
}
});
}
}
public static boolean containsIgnoreCase(Collection l, String s) {
if (l != null)
for (String x : l) if (eqic(x, s))
return true;
return false;
}
public static boolean containsIgnoreCase(String[] l, String s) {
if (l != null)
for (String x : l) if (eqic(x, s))
return true;
return false;
}
public static boolean containsIgnoreCase(String s, char c) {
return indexOfIgnoreCase(s, String.valueOf(c)) >= 0;
}
public static boolean containsIgnoreCase(String a, String b) {
return indexOfIgnoreCase(a, b) >= 0;
}
public static String dropSuffixIgnoreCase(String suffix, String s) {
return ewic(s, suffix) ? s.substring(0, l(s) - l(suffix)) : s;
}
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 List buttonsInGroup(ButtonGroup g) {
if (g == null)
return ll();
return asList(g.getElements());
}
public static Rectangle maxWindowBounds() {
return GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
}
public static Throwable innerException(Throwable e) {
return getInnerException(e);
}
public static Object sleepQuietly_monitor = new Object();
public static void sleepQuietly() {
try {
assertFalse(isAWTThread());
synchronized (sleepQuietly_monitor) {
sleepQuietly_monitor.wait();
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String fsI(String id) {
return formatSnippetID(id);
}
public static String fsI(long id) {
return formatSnippetID(id);
}
public static String userHomeIfNotActual() {
String home = userHome();
return eq(home, actualUserHome()) ? null : home;
}
public static Runnable wrapAsActivity(Object r) {
return toRunnable(r);
}
public static Map myFrames_list = weakHashMap();
public static List myFrames() {
return swing(new F0>() {
public List get() {
try {
return keysList(myFrames_list);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret keysList(myFrames_list);";
}
});
}
public static boolean activateFrame(final Component c) {
return swing(new F0() {
public Boolean get() {
try {
Frame f = getAWTFrame(c);
if (f == null)
return false;
if (!f.isVisible())
f.setVisible(true);
if (f.getState() == Frame.ICONIFIED)
f.setState(Frame.NORMAL);
if (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())...";
}
});
}
public static boolean makeAndroid3_disable;
public static class Android3 {
public String greeting;
public boolean publicOverride;
public int startPort = 5000;
public Responder responder;
public boolean console = true;
public boolean quiet;
public boolean daemon = false;
public boolean incomingSilent = false;
public int incomingPrintLimit = 200;
public boolean useMultiPort = true;
public boolean recordHistory;
public boolean verbose;
public int answerPrintLimit = 500;
public boolean newLineAboveAnswer, newLineBelowAnswer;
public int port;
public long vport;
public DialogHandler handler;
public ServerSocket server;
public Android3(String greeting) {
this.greeting = greeting;
}
public Android3() {
}
public synchronized void dispose() {
if (server != null) {
try {
server.close();
} catch (IOException e) {
print("[internal] " + e);
}
server = null;
}
if (vport != 0) {
try {
print("Disposing " + this);
removeFromMultiPort(vport);
vport = 0;
} catch (Throwable __e) {
_handleException(__e);
}
}
}
public String toString() {
return "Bot: " + greeting + " [vport " + vport + "]";
}
}
public abstract static class Responder {
public abstract String answer(String s, List history);
}
public static Android3 makeAndroid3(final String greeting) {
return makeAndroid3(new Android3(greeting));
}
public static Android3 makeAndroid3(final String greeting, Responder responder) {
Android3 android = new Android3(greeting);
android.responder = responder;
return makeAndroid3(android);
}
public static Android3 makeAndroid3(final Android3 a) {
if (makeAndroid3_disable)
return a;
if (a.responder == null)
a.responder = new Responder() {
public String answer(String s, List history) {
return callStaticAnswerMethod(s, history);
}
};
if (!a.quiet)
print("[bot] " + a.greeting);
if (a.console && (readLine_noReadLine || makeAndroid3_consoleInUse()))
a.console = false;
record(a);
if (a.useMultiPort)
a.vport = addToMultiPort(a.greeting, makeAndroid3_verboseResponder(a));
if (a.console)
makeAndroid3_handleConsole(a);
if (a.useMultiPort)
return a;
a.handler = makeAndroid3_makeDialogHandler(a);
if (a.quiet)
startDialogServer_quiet.set(true);
try {
a.port = a.daemon ? startDialogServerOnPortAboveDaemon(a.startPort, a.handler) : startDialogServerOnPortAbove(a.startPort, a.handler);
} finally {
startDialogServer_quiet.set(null);
}
a.server = startDialogServer_serverSocket;
return a;
}
public static void makeAndroid3_handleConsole(final Android3 a) {
if (!a.quiet)
print("You may also type on this console.");
startThread(new Runnable() {
public void run() {
try {
List history = new ArrayList();
while (licensed()) {
String line;
try {
line = readLine();
} catch (Throwable e) {
print(getInnerMessage(e));
break;
}
if (line == null)
break;
{
history.add(line);
history.add(makeAndroid3_getAnswer(line, history, a));
}
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "List history = new ArrayList();\r\n while (licensed()) {\r\n Stri...";
}
});
}
public static DialogHandler makeAndroid3_makeDialogHandler(final Android3 a) {
return new DialogHandler() {
public void run(final DialogIO io) {
if (!a.publicOverride && !(publicCommOn() || io.isLocalConnection())) {
io.sendLine("Sorry, not allowed");
return;
}
String dialogID = randomID(8);
io.sendLine(a.greeting + " / Your ID: " + dialogID);
List history = new ArrayList();
while (io.isStillConnected()) {
if (io.waitForLine()) {
final String line = io.readLineNoBlock();
String s = dialogID + " at " + now() + ": " + quote(line);
if (!a.incomingSilent)
print(shorten(s, a.incomingPrintLimit));
if (eq(line, "bye")) {
io.sendLine("bye stranger");
return;
}
Matches m = new Matches();
if (a.recordHistory)
history.add(line);
String answer;
if (match3("this is a continuation of talk *", s, m) || match3("hello bot! this is a continuation of talk *", s, m)) {
dialogID = unquote(m.m[0]);
answer = "ok";
} else
try {
makeAndroid3_io.set(io);
answer = makeAndroid3_getAnswer(line, history, a);
} finally {
makeAndroid3_io.set(null);
}
if (a.recordHistory)
history.add(answer);
io.sendLine(answer);
}
}
}
};
}
public static String makeAndroid3_getAnswer(String line, List history, Android3 a) {
String answer, originalAnswer;
try {
originalAnswer = a.responder.answer(line, history);
answer = makeAndroid3_fallback(line, history, originalAnswer);
} catch (Throwable e) {
e = getInnerException(e);
printStackTrace(e);
originalAnswer = answer = e.toString();
}
if (!a.incomingSilent) {
if (originalAnswer == null)
originalAnswer = "?";
if (a.newLineAboveAnswer)
print();
print(">" + dropFirst(indentx(2, shorten(rtrim(originalAnswer), a.answerPrintLimit))));
if (a.newLineBelowAnswer)
print();
}
return answer;
}
public static String makeAndroid3_fallback(String s, List history, String answer) {
if (answer == null && match3("what is your pid", s))
return getPID();
if (answer == null && match3("what is your program id", s))
return getProgramID();
if (match3("get injection id", s))
return getInjectionID();
if (answer == null)
answer = "?";
if (answer.indexOf('\n') >= 0 || answer.indexOf('\r') >= 0)
answer = quote(answer);
return answer;
}
public static boolean makeAndroid3_consoleInUse() {
if (isTrue(vm_generalMap_get("consoleInUse")))
return true;
for (Object o : record_list) if (o instanceof Android3 && ((Android3) o).console)
return true;
return false;
}
public static Responder makeAndroid3_verboseResponder(final Android3 a) {
return new Responder() {
public String answer(String s, List history) {
if (a.verbose)
print("> " + shorten(s, a.incomingPrintLimit));
String answer = a.responder.answer(s, history);
if (a.verbose)
print("< " + shorten(answer, a.incomingPrintLimit));
return answer;
}
};
}
public static ThreadLocal makeAndroid3_io = new ThreadLocal();
public static Android3 makeAndroid3() {
return makeAndroid3(getProgramTitle() + ".");
}
public static String makeResponder_callAnswerMethod(Object bot, String s, List history) {
String answer = (String) callOpt(bot, "answer", s, history);
if (answer == null)
answer = (String) callOpt(bot, "answer", s);
return answer;
}
public static Responder makeResponder(final Object bot) {
if (bot instanceof Responder)
return (Responder) bot;
if (bot instanceof String) {
String f = (String) (bot);
return new Responder() {
public String answer(String s, List history) {
String answer = (String) callOptMC((String) bot, s, history);
if (answer == null)
answer = (String) callOptMC((String) bot, s);
return answer;
}
};
}
return new Responder() {
public String answer(String s, List history) {
return makeResponder_callAnswerMethod(bot, s, history);
}
};
}
public static String defaultBotName() {
return getProgramTitle() + ".";
}
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 A optPar(Object[] params, String name) {
return optParam(params, name);
}
public static A optPar(Object[] params, String name, A defaultValue) {
return optParam(params, name, defaultValue);
}
public static boolean even(int i) {
return (i & 1) == 0;
}
public static boolean even(long i) {
return (i & 1) == 0;
}
public static void tableEnableTextDrag(final JTable table) {
TransferHandler th = new TransferHandler() {
@Override
public int getSourceActions(JComponent c) {
return COPY;
}
@Override
public Transferable createTransferable(JComponent c) {
Object o = selectedTableCell(table);
return new StringSelection(str(o));
}
};
tableEnableDrag(table, th);
}
public static boolean jmenuItem_newThreads;
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(text);
JMenuItem mi = new JMenuItem(p.a);
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(text);\r\n JMenuItem mi = new JMenuItem(...";
}
});
}
public static MenuItem menuItem(String text, final Object r) {
MenuItem mi = new MenuItem(text);
mi.addActionListener(actionListener(r));
return mi;
}
public static 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));
}
public static Timer installTimer(JComponent component, Object r, long delay) {
return installTimer(component, r, delay, delay);
}
public static Timer installTimer(RootPaneContainer frame, long delay, Object r) {
return installTimer(frame.getRootPane(), r, delay, delay);
}
public static Timer installTimer(JComponent component, long delay, Object r) {
return installTimer(component, r, delay, delay);
}
public static Timer installTimer(JComponent component, long delay, long firstDelay, Object r) {
return installTimer(component, r, delay, firstDelay);
}
public static Timer installTimer(final JComponent component, final Object r, final long delay, final long firstDelay) {
return installTimer(component, r, delay, firstDelay, true);
}
public static Timer installTimer(final JComponent component, final Object r, final long delay, final long firstDelay, final boolean repeats) {
if (component == null)
return null;
return (Timer) swingAndWait(new F0() {
public Object get() {
try {
final Var timer = new Var();
timer.set(new Timer(toInt(delay), new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent _evt) {
try {
AutoCloseable __580 = tempActivity(r);
try {
try {
if (!allPaused())
if (isFalse(callF(r)))
cancelTimer(timer.get());
} catch (Throwable __e) {
_handleException(__e);
}
} finally {
_close(__580);
}
} 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...";
}
});
}
public static Timer installTimer(RootPaneContainer frame, long delay, long firstDelay, Object r) {
return installTimer(frame.getRootPane(), delay, firstDelay, r);
}
public static long changeCount() {
return db_mainConcepts().changes;
}
public static A or(A a, A b) {
return a != null ? a : b;
}
public static BufferedImage toBufferedImageOpt(Object o) {
if (o instanceof BufferedImage)
return (BufferedImage) o;
if (o instanceof MakesBufferedImage)
return ((MakesBufferedImage) o).getBufferedImage();
if (o instanceof File)
if (isImageFile(((File) o)))
return loadImage2(((File) o));
String c = getClassName(o);
if (eqOneOf(c, "main$BWImage", "main$RGBImage"))
return (BufferedImage) call(o, "getBufferedImage");
if (eq(c, "main$PNGFile"))
return (BufferedImage) call(o, "getImage");
return null;
}
public static A callPostProcessor(Object f, A a) {
return f == null ? a : (A) callF(f, a);
}
public static String[] toStringArray(Collection c) {
String[] a = new String[l(c)];
Iterator it = c.iterator();
for (int i = 0; i < l(a); i++) a[i] = it.next();
return a;
}
public static String[] toStringArray(Object o) {
if (o instanceof String[])
return (String[]) o;
else if (o instanceof Collection)
return toStringArray((Collection) o);
else
throw fail("Not a collection or array: " + getClassName(o));
}
public static Pair fillTableWithData_makeData(List rows, List colNames) {
return fillTableWithData_makeData(rows, asStringArray(colNames));
}
public static Pair fillTableWithData_makeData(List rows, String... colNames) {
Object[][] data = new Object[rows.size()][];
int w = 0;
for (int i = 0; i < rows.size(); i++) {
List l = rows.get(i);
Object[] r = new Object[l.size()];
for (int j = 0; j < l.size(); j++) {
Object o = l.get(j);
if (o instanceof BufferedImage)
o = imageIcon((BufferedImage) o);
if (o instanceof RGBImage)
o = imageIcon((RGBImage) o);
r[j] = o;
}
data[i] = r;
w = Math.max(w, l.size());
}
Object[] columnNames = new Object[w];
for (int i = 0; i < w; i++) columnNames[i] = i < l(colNames) ? colNames[i] : "?";
return pair(data, columnNames);
}
public static void makeTableUneditable(JTable table) {
for (int c = 0; c < table.getColumnCount(); c++) {
Class> col_class = table.getColumnClass(c);
table.setDefaultEditor(col_class, null);
}
}
public static boolean showTable_searcher = true;
public static JTable showTable(Object data) {
return dataToTable_uneditable(data);
}
public static JTable showTable(String title, Object data) {
return showTable(data, title);
}
public static JTable showTable(Object data, String title) {
return dataToTable_uneditable(data, title);
}
public static JTable showTable(JTable table, Object data) {
return showTable(table, data, autoFrameTitle());
}
public static JTable showTable(Object data, JTable table) {
return showTable(table, data);
}
public static JTable showTable(JTable table, Object data, String title) {
if (table == null)
table = showTable(data, title);
else {
setFrameTitle(table, title);
dataToTable_uneditable(table, data);
}
return table;
}
public static JTable showTable() {
return showTable(new ArrayList>(), new ArrayList());
}
public static JTable showTable(String title) {
return showTable(new ArrayList