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