values(Map map) {
return map == null ? emptyList() : map.values();
}
public static Map vm_generalMap_map;
public static Map vm_generalMap() {
if (vm_generalMap_map == null)
vm_generalMap_map = (Map) get(javax(), "generalMap");
return vm_generalMap_map;
}
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 String getSelectedItem(JList l) {
return (String) l.getSelectedValue();
}
public static String getSelectedItem(JComboBox cb) {
return strOrNull(cb.getSelectedItem());
}
public static Throwable unwrapTrivialExceptionWraps(Throwable e) {
if (e == null)
return e;
while (e.getClass() == RuntimeException.class && e.getCause() != null && eq(e.getMessage(), str(e.getCause()))) e = e.getCause();
return e;
}
public static String replacePrefix(String prefix, String replacement, String s) {
if (!startsWith(s, prefix))
return s;
return replacement + substring(s, l(prefix));
}
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 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 Set vm_busListeners_live_cache;
public static Set vm_busListeners_live() {
if (vm_busListeners_live_cache == null)
vm_busListeners_live_cache = vm_busListeners_live_load();
return vm_busListeners_live_cache;
}
public static Set vm_busListeners_live_load() {
return vm_generalIdentityHashSet("busListeners");
}
public static Map vm_busListenersByMessage_live_cache;
public static Map vm_busListenersByMessage_live() {
if (vm_busListenersByMessage_live_cache == null)
vm_busListenersByMessage_live_cache = vm_busListenersByMessage_live_load();
return vm_busListenersByMessage_live_cache;
}
public static Map vm_busListenersByMessage_live_load() {
return vm_generalHashMap("busListenersByMessage");
}
public static B mapPutOrRemove(Map map, A key, B value) {
if (map != null && key != null)
if (value != null)
return map.put(key, value);
else
return map.remove(key);
return null;
}
public static Set synchroWeakHashSet() {
return Collections.newSetFromMap((Map) newWeakHashMap());
}
public static Object pcallFunction(Object f, Object... args) {
try {
return callFunction(f, args);
} catch (Throwable __e) {
_handleException(__e);
}
return null;
}
public static boolean eqOneOf(Object o, Object... l) {
for (Object x : l) if (eq(o, x))
return true;
return false;
}
public static File programDir_mine;
public static File programDir() {
return programDir(getProgramID());
}
public static File programDir(String snippetID) {
boolean me = sameSnippetID(snippetID, programID());
if (programDir_mine != null && me)
return programDir_mine;
File dir = new File(javaxDataDir(), formatSnippetIDOpt(snippetID));
if (me) {
String c = caseID();
if (nempty(c))
dir = newFile(dir, c);
}
return dir;
}
public static File programDir(String snippetID, String subPath) {
return new File(programDir(snippetID), subPath);
}
public static void _registerIO(Object object, String path, boolean opened) {
}
public static AutoCloseable tempSetTL(ThreadLocal tl, A a) {
return tempSetThreadLocal(tl, a);
}
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 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 String strOrNull(Object o) {
return o == null ? null : str(o);
}
public static JMenuItem jMenuItem(final String text) {
return jmenuItem(text);
}
public static JMenuItem jMenuItem(String text, Object r) {
return jmenuItem(text, r);
}
public static Pair jmenu_autoMnemonic(String s) {
int i = indexOf(s, '&');
if (i >= 0 && i < l(s) && isLetterOrDigit(s.charAt(i + 1)))
return pair(substring(s, 0, i) + substring(s, i + 1), (int) s.charAt(i + 1));
return pair(s, 0);
}
public static ActionListener actionListenerInNewThread(final Object runnable) {
return actionListenerInNewThread(runnable, null);
}
public static ActionListener actionListenerInNewThread(final Object runnable, final Object instanceToHold) {
if (runnable instanceof ActionListener)
return (ActionListener) runnable;
return new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent _evt) {
try {
startThread("Action Listener", new Runnable() {
public void run() {
try {
AutoCloseable __294 = holdInstance(instanceToHold);
try {
callF(runnable);
} finally {
_close(__294);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "AutoCloseable __294 = holdInstance(instanceToHold); try {\r\n callF(runnab...";
}
});
} catch (Throwable __e) {
messageBox(__e);
}
}
};
}
public static Object callFunction(Object f, Object... args) {
return callF(f, args);
}
public static boolean sameSnippetID(String a, String b) {
if (!isSnippetID(a) || !isSnippetID(b))
return false;
return parseSnippetID(a) == parseSnippetID(b);
}
public static volatile String caseID_caseID;
public static String caseID() {
return caseID_caseID;
}
public static void caseID(String id) {
caseID_caseID = id;
}
public static AutoCloseable tempSetThreadLocal(final ThreadLocal tl, A a) {
if (tl == null)
return null;
final A prev = setThreadLocal(tl, a);
return new AutoCloseable() {
public String toString() {
return "tl.set(prev);";
}
public void close() throws Exception {
tl.set(prev);
}
};
}
public static 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 boolean isLetterOrDigit(char c) {
return Character.isLetterOrDigit(c);
}
public static Pair pair(A a, B b) {
return new Pair(a, b);
}
public static Pair pair(A a) {
return new Pair(a, a);
}
public static A setThreadLocal(ThreadLocal tl, A value) {
if (tl == null)
return null;
A old = tl.get();
tl.set(value);
return old;
}
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 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 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 abstract static class DynForm extends DynSCP {
public JComponent visualize2() {
return jscroll_trackWidth(makeForm3(asObjectArray(formParams())));
}
public abstract List formParams();
}
public static class Pair implements Comparable> {
public A a;
public B b;
public Pair() {
}
public Pair(A a, B b) {
this.b = b;
this.a = a;
}
public int hashCode() {
return hashCodeFor(a) + 2 * hashCodeFor(b);
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Pair))
return false;
Pair t = (Pair) o;
return eq(a, t.a) && eq(b, t.b);
}
public String toString() {
return "<" + a + ", " + b + ">";
}
public int compareTo(Pair p) {
if (p == null)
return 1;
int i = ((Comparable) a).compareTo(p.a);
if (i != 0)
return i;
return ((Comparable) b).compareTo(p.b);
}
}
public abstract static class DynSCP extends DynModule {
public transient SingleComponentPanel scp;
public transient ReliableSingleThread rstRevisualize2 = new ReliableSingleThread(new Runnable() {
public void run() {
try {
revisualize2_impl();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "revisualize2_impl();";
}
});
public static boolean verbose;
public JComponent visualize() {
scp = singleComponentPanel();
scp.setComponent(visualize2());
return scp;
}
public void unvisualize() {
scp = null;
unvisualize2();
}
public JComponent visualize2() {
return null;
}
public void unvisualize2() {
}
public void revisualize2() {
rstRevisualize2.trigger();
}
public void revisualize2_impl() {
Lock __75 = lock;
lock(__75);
try {
if (scp == null)
return;
JComponent c = visualize2();
if (c != scp.getComponent()) {
if (verbose)
print("Setting component");
scp.setComponent(c);
}
} finally {
unlock(__75);
}
}
public void setComponent(Component c) {
if (scp != null)
scp.setComponent(c);
}
public JComponent getComponent() {
return scp == null ? null : (JComponent) scp.getComponent();
}
public boolean isShowing() {
return scp != null;
}
}
public static interface IVar {
public void set(A a);
public A get();
public boolean has();
public void clear();
}
public static class ReliableSingleThread implements Runnable {
public Object runnable;
public boolean trigger;
public Thread thread;
public String name = "Single Thread";
public F0 enter;
public ReliableSingleThread(Object runnable) {
this.runnable = runnable;
}
public void trigger() {
go();
}
public synchronized void go() {
trigger = true;
if (!running()) {
AutoCloseable __1652 = callF(enter);
try {
thread = startThread(name, new Runnable() {
public void run() {
try {
_run();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "_run();";
}
});
} finally {
_close(__1652);
}
}
}
public void run() {
go();
}
public void get() {
go();
}
public synchronized boolean running() {
return thread != null;
}
public void triggerAndWait() {
trigger();
while (running()) sleep(1);
}
public void _run() {
while (licensed()) {
synchronized (this) {
if (!trigger) {
thread = null;
break;
}
trigger = false;
}
pcallF(runnable);
}
}
public synchronized void cancel() {
cancelAndInterruptThread(thread);
thread = null;
}
}
public static String getType(Object o) {
return getClassName(o);
}
public static JScrollPane jscroll_trackWidth(JComponent c) {
return jscroll(scrollable_trackWidth(c));
}
public static JPanel makeForm3(Object... parts) {
return withRightMargin(makeForm2(parts));
}
public static Object[] asObjectArray(List l) {
return toObjectArray(l);
}
public static int hashCodeFor(Object a) {
return a == null ? 0 : a.hashCode();
}
public static SingleComponentPanel singleComponentPanel() {
return singleComponentPanel(null);
}
public static SingleComponentPanel singleComponentPanel(final Component c) {
return swing(new F0() {
public SingleComponentPanel get() {
try {
return new SingleComponentPanel(c);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret new SingleComponentPanel(c);";
}
});
}
public static Class _run(String progID, String... args) {
Class main = hotwire(progID);
callMain(main, args);
return main;
}
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 void cancelAndInterruptThread(Thread t) {
if (t == null)
return;
cancelThread(t);
t.interrupt();
}
public static JPanel scrollable_trackWidth(final Component component) {
class P extends SingleComponentPanel implements Scrollable {
public P() {
super(component);
}
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 20;
}
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return (direction == SwingConstants.HORIZONTAL ? visibleRect.width : visibleRect.height) * 5 / 6;
}
public boolean getScrollableTracksViewportWidth() {
return true;
}
public boolean getScrollableTracksViewportHeight() {
return false;
}
}
return swing(new F0() {
public P get() {
try {
return new P();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret new P;";
}
});
}
public static int withRightMargin_defaultWidth = 6;
public static JPanel withRightMargin(Component c) {
return withRightMargin(withRightMargin_defaultWidth, c);
}
public static JPanel withRightMargin(final int w, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, w));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
public static JPanel makeForm2(Object... parts) {
return makeForm_customLayout(formLayouter1(), parts);
}
public static Object[] toObjectArray(Collection c) {
List l = asList(c);
return l.toArray(new Object[l.size()]);
}
public static Class> hotwire(String src) {
assertFalse(_inCore());
Class j = getJavaX();
if (isAndroid()) {
synchronized (j) {
List libraries = new ArrayList();
File srcDir = (File) call(j, "transpileMain", src, libraries);
if (srcDir == null)
throw fail("transpileMain returned null (src=" + quote(src) + ")");
Object androidContext = get(j, "androidContext");
return (Class) call(j, "loadx2android", srcDir, src);
}
} else {
Class c = (Class) (call(j, "hotwire", src));
hotwire_copyOver(c);
return c;
}
}
public static A callMain(A c, String... args) {
callOpt(c, "main", new Object[] { args });
return c;
}
public static void callMain() {
callMain(mc());
}
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 void cancelThread(Thread t) {
if (t == null)
return;
ping();
synchronized (ping_actions) {
ping_actions.put(t, "cancelled");
ping_anyActions = true;
}
}
public static Dimension getPreferredSize(final Component c) {
return c == null ? null : swing(new F0() {
public Dimension get() {
try {
return c.getPreferredSize();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret c.getPreferredSize();";
}
});
}
public static JPanel makeForm_customLayout(final F1 layouter, final Object... parts) {
return makeForm_customArrangement(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)";
}
}, 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 void assertFalse(Object o) {
if (!(eq(o, false)))
throw fail(str(o));
}
public static boolean assertFalse(boolean b) {
if (b)
throw fail("oops");
return b;
}
public static boolean assertFalse(String msg, boolean b) {
if (b)
throw fail(msg);
return b;
}
public static boolean _inCore() {
return false;
}
public static List hotwire_copyOver_after = synchroList();
public static void hotwire_copyOver(Class c) {
for (String field : ll("print_log", "print_silent", "androidContext", "_userHome")) setOptIfNotNull(c, field, getOpt(mc(), field));
setOptIfNotNull(c, "mainBot", getMainBot());
setOpt(c, "creator_class", new WeakReference(mc()));
pcallFAll(hotwire_copyOver_after, c);
}
public static JPanel makeForm_customArrangement(final F1, JPanel> arrange, final Object... _parts) {
return swing(new F0() {
public JPanel get() {
try {
return callF(arrange, showForm_arrange1(showForm_makeComponents(null, _parts)));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret callF(arrange,\r\n showForm_arrange1(showForm_makeComponents(null, _pa...";
}
});
}
public static JPanel customLayoutPanel(final Object layouter) {
return jpanel(layoutManagerFromFunction(layouter));
}
public static JPanel customLayoutPanel(final Object layouter, final List extends Component> components) {
return addAllComponents(customLayoutPanel(layouter), components);
}
public static List getComponents(final Component c) {
return !(c instanceof Container) ? emptyList() : asList(swing(new F0() {
public Component[] get() {
try {
return ((Container) c).getComponents();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret ((Container) c).getComponents();";
}
}));
}
public static boolean containsATextArea(Component c) {
return childOfType(c, JTextArea.class) != null;
}
public static void add(BitSet bs, int i) {
bs.set(i);
}
public static boolean add(Collection c, A a) {
return c != null && c.add(a);
}
public static void add(Container c, Component x) {
addToContainer(c, x);
}
public static int totalPreferredHeight(List l) {
int h = 0;
for (Component c : unnull(l)) h += c.getPreferredSize().height;
return h;
}
public static List listWithoutIndicesInBitSet(List l, BitSet bs) {
List out = new ArrayList();
for (int i = 0; i < l(l); i++) if (!bs.get(i))
out.add(l.get(i));
return out;
}
public static double doubleRatio(double x, double y) {
return y == 0 ? 0 : x / y;
}
public static Dimension componentsBoundingSize(Container container, int insetBottomRight) {
Rectangle r = new Rectangle(0, 0, 0, 0);
for (Component c : container.getComponents()) r = rectangleUnion(r, c.getBounds());
return new Dimension(r.x + r.width + insetBottomRight, r.y + r.height + insetBottomRight);
}
public static void setOptIfNotNull(Object o, String field, Object value) {
if (value != null)
setOpt(o, field, value);
}
public static Object mainBot;
public static Object getMainBot() {
return mainBot;
}
public static List showForm_arrange1(List> l) {
int minW = showForm_leftWidth(l);
List out = new ArrayList();
for (List row : l) out.add(westAndCenter(withRightMargin(showForm_gapBetweenColumns, jMinWidth(minW, first(row))), second(row)));
return out;
}
public static List> showForm_makeComponents(final Boolean internalFrame, Object... _parts) {
List> l = new ArrayList();
List parts = asList(_parts);
JButton submitButton = null;
for (int i = 0; i < l(parts); i++) {
final Object o = parts.get(i), next = get(parts, i + 1);
if (o instanceof String && next instanceof Component)
setComponentID((Component) next, (String) o);
if (o instanceof Component || o instanceof String || next instanceof Component) {
l.add(mapLL("wrapForSmartAdd", o == null ? new JPanel() : o instanceof String ? humanizeFormLabel((String) o) : o, next));
if (next instanceof JButton && submitButton == null)
submitButton = (JButton) next;
i++;
} else if (isRunnable(o))
l.add(mapLL("wrapForSmartAdd", null, submitButton = jbutton(showFormSubmitButtonName(), new Runnable() {
public void run() {
try {
Object result = call(o);
if (neq(Boolean.FALSE, result)) {
if (isTrue(internalFrame))
disposeInternalFrame(heldInstance(JButton.class));
else if (isFalse(internalFrame))
disposeFrame(heldInstance(JButton.class));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Object result = call(o);\r\n if (neq(Boolean.FALSE, result)) {\r\n ...";
}
})));
else
print("showForm: Unknown element type: " + getClassName(o));
}
if (submitButton != null) {
final JButton _submitButton = submitButton;
onEnterInAllTextFields(concatLists(l), new Runnable() {
public void run() {
try {
clickButton(_submitButton);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "clickButton(_submitButton)";
}
});
}
for (List row : l) {
JComponent left = first(row);
if (left instanceof JLabel)
makeBold((JLabel) left).setVerticalAlignment(JLabel.TOP);
}
return l;
}
public static JPanel jpanel(LayoutManager layout) {
return swingNu(JPanel.class, layout);
}
public static JPanel jpanel() {
return swingNu(JPanel.class);
}
public static LayoutManager layoutManagerFromFunction(final Object layouter) {
return new AbstractLayoutManager() {
public void layoutContainer(Container parent) {
Dimension size = (Dimension) (callF(layouter, parent));
if (size != null)
preferredSize = size;
}
};
}
public static A addAllComponents(final A c, final List extends Component> components) {
if (nempty(components)) {
swing(new Runnable() {
public void run() {
try {
for (Component x : components) c.add(x);
revalidate(c);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "for (Component x : components)\r\n c.add(x);\r\n revalidate(c);";
}
});
}
return c;
}
public static A childOfType(Component c, Class theClass) {
return first(childrenOfType(c, theClass));
}
public static A childOfType(Class theClass, Component c) {
return childOfType(c, theClass);
}
public static void addToContainer(final Container a, final Component b) {
if (a != null && b != null) {
swing(new Runnable() {
public void run() {
try {
a.add(b);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "a.add(b);";
}
});
}
}
public static Rectangle rectangleUnion(Rectangle a, Rectangle b) {
return a == null ? b : b == null ? a : a.union(b);
}
public static int showForm_defaultGap = 4;
public static int showForm_gapBetweenColumns = 10;
public static JPanel showFormTitled(final String title, final Object... _parts) {
JDesktopPane desktop = mainDesktopPane();
if (desktop != null)
return showInternalFrameFormTitled(desktop, title, _parts);
return swing(new F0() {
public JPanel get() {
try {
final Var frame = new Var();
JPanel panel = showForm_makePanel(false, _parts);
frame.set(showForm_makeFrame(title, panel));
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "final new Var frame;\r\n JPanel panel = showForm_makePanel(false, _p...";
}
});
}
public static JPanel showForm_makePanel(Boolean internalFrame, Object... _parts) {
List out = showForm_arrange1(showForm_makeComponents(internalFrame, _parts));
return vstackWithSpacing(out, showForm_defaultGap);
}
public static int showForm_leftWidth(List> l) {
int minW = 0;
for (List row : l) minW = max(minW, getMinimumSize(first(row)).width);
return minW;
}
public static JPanel westAndCenter(final Component w, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.WEST, wrap(w));
panel.add(BorderLayout.CENTER, wrap(c));
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel panel = new JPanel(new BorderLayout);\r\n panel.add(BorderLayout.WEST...";
}
});
}
public static A jMinWidth(final int w, final A c) {
if (c == null)
return null;
return swing(new F0() {
public A get() {
try {
Dimension size = c.getMinimumSize();
c.setMinimumSize(new Dimension(w, size.height));
return jPreferWidth(w, c);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Dimension size = c.getMinimumSize();\r\n c.setMinimumSize(new Dimension(/*ma...";
}
});
}
public static Object first(Object list) {
return first((Iterable) list);
}
public static A first(List list) {
return empty(list) ? null : list.get(0);
}
public static A first(A[] bla) {
return bla == null || bla.length == 0 ? null : bla[0];
}
public static A first(IterableIterator i) {
return first((Iterator) i);
}
public static A first(Iterator i) {
return i == null || !i.hasNext() ? null : i.next();
}
public static A first(Iterable i) {
if (i == null)
return null;
Iterator it = i.iterator();
return it.hasNext() ? it.next() : null;
}
public static Character first(String s) {
return empty(s) ? null : s.charAt(0);
}
public static A first(Pair p) {
return p == null ? null : p.a;
}
public static A second(List l) {
return get(l, 1);
}
public static A second(A[] bla) {
return bla == null || bla.length <= 1 ? null : bla[1];
}
public static B second(Pair p) {
return p == null ? null : p.b;
}
public static void setComponentID(Component c, String id) {
if (c != null)
componentID_map.put(c, id);
}
public static List mapLL(Object f, Object... data) {
return map(f, ll(data));
}
public static Component wrapForSmartAdd(Object o) {
if (o == null)
return jpanel();
if (o instanceof String)
return jlabel((String) o);
return wrap(o);
}
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 boolean isRunnable(Object o) {
return o instanceof Runnable || hasMethod(o, "get");
}
public static String showFormSubmitButtonName() {
return "Submit";
}
public static void disposeInternalFrame(Component c) {
final JInternalFrame f = getInternalFrame(c);
if (f != null) {
swing(new Runnable() {
public void run() {
try {
f.dispose();
setOpt(f, "lastFocusOwner", null);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "f.dispose();\r\n setOpt(f, \"lastFocusOwner\" , null); // Help GC";
}
});
}
}
public static void disposeFrame(final Component c) {
disposeWindow(c);
}
public static void onEnterInAllTextFields(JComponent c, Object action) {
if (action == null)
return;
for (Component tf : allChildren(c)) onEnterIfTextField(tf, action);
}
public static void onEnterInAllTextFields(List c, Object action) {
for (Object o : unnull(c)) if (o instanceof JComponent)
onEnterInAllTextFields((JComponent) o, action);
}
public static void clickButton(final JButton b) {
if (b != null) {
swing(new Runnable() {
public void run() {
try {
if (b.isEnabled())
b.doClick();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (b.isEnabled())\r\n b.doClick();";
}
});
}
}
public static A makeBold(final A c) {
if (c != null) {
swing(new Runnable() {
public void run() {
try {
c.setFont(c.getFont().deriveFont(Font.BOLD));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "c.setFont(c.getFont().deriveFont(Font.BOLD));";
}
});
}
return c;
}
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 List childrenOfType(Component c, Class theClass) {
List l = new ArrayList();
scanForComponents(c, theClass, l);
return l;
}
public static List childrenOfType(Class theClass, Component c) {
return childrenOfType(c, theClass);
}
public static Map componentID_map = weakHashMap();
public static String componentID(Component c) {
return c == null ? null : componentID_map.get(c);
}
public static JDesktopPane mainDesktopPane_value;
public static JDesktopPane mainDesktopPane() {
return mainDesktopPane_value;
}
public static JPanel showInternalFrameFormTitled(final JDesktopPane desktop, final String title, final Object... _parts) {
JPanel panel = showForm_makePanel(true, _parts);
showForm_makeInternalFrame(desktop, title, panel);
return panel;
}
public static JFrame showForm_makeFrame(String title, JPanel panel) {
return handleEscapeKey(minFrameWidth(showPackedFrame(title, withMargin(panel)), 400));
}
public static int vstackWithSpacing_default = 10;
public static JPanel vstackWithSpacing(final List parts) {
return vstackWithSpacing(parts, vstackWithSpacing_default);
}
public static JPanel vstackWithSpacing(final List parts, final int spacing) {
return swing(new F0() {
public JPanel get() {
try {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(spacing / 2, 0, spacing / 2, 0);
smartAddWithLayout(panel, gbc, toObjectArray(nonNulls(parts)));
gbc.weighty = 1;
gbc.insets = new Insets(0, 0, 0, 0);
panel.add(jrigid(), gbc);
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel panel = new JPanel(new GridBagLayout);\r\n new GridBagConstraints gbc...";
}
});
}
public static JPanel vstackWithSpacing(Component... parts) {
return vstackWithSpacing(asList(parts), vstackWithSpacing_default);
}
public static Dimension getMinimumSize(final Component c) {
return c == null ? null : swing(new F0() {
public Dimension get() {
try {
return c.getMinimumSize();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "ret c.getMinimumSize();";
}
});
}
public static A jPreferWidth(int w, A c) {
Dimension size = c.getPreferredSize();
c.setPreferredSize(new Dimension(w, size.height));
return c;
}
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 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 boolean hasMethod(Object o, String method, Object... args) {
return findMethod(o, method, args) != null;
}
public static JInternalFrame getInternalFrame(final Object _o) {
return _o == null ? null : swing(new F0() {
public JInternalFrame 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 JInternalFrame)
return (JInternalFrame) 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 List allChildren(Component c) {
return childrenOfType(c, Component.class);
}
public static void onEnterIfTextField(Component c, Object action) {
if (action == null)
return;
if (c instanceof JTextField)
onEnter((JTextField) c, action);
else if (c instanceof JComboBox)
onEnter((JComboBox) c, action);
}
public static void scanForComponents(final Component c, final Class theClass, final List l) {
if (theClass.isInstance(c))
l.add((A) c);
if (c instanceof Container) {
swing(new Runnable() {
public void run() {
try {
for (Component comp : ((Container) c).getComponents()) scanForComponents(comp, theClass, l);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "for (Component comp : ((Container) c).getComponents())\r\n scanForComponen...";
}
});
}
}
public static JInternalFrame showForm_makeInternalFrame(JDesktopPane desktop, String title, JPanel panel) {
JInternalFrame f = addInternalFrame(desktop, title, withMargin(panel));
minInternalFrameWidth(f, 400);
packInternalFrameVertically(f);
centerInternalFrame(f);
return f;
}
public static JFrame handleEscapeKey(final JFrame frame) {
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
frame.getRootPane().registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
frame.dispose();
}
}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
return frame;
}
public static JFrame minFrameWidth(JFrame frame, int w) {
if (frame != null && frame.getWidth() < w)
frame.setSize(w, frame.getHeight());
return frame;
}
public static JFrame minFrameWidth(int w, JFrame frame) {
return minFrameWidth(frame, w);
}
public static JFrame showPackedFrame(String title, Component contents) {
return packFrame(showFrame(title, contents));
}
public static JFrame showPackedFrame(Component contents) {
return packFrame(showFrame(contents));
}
public static JPanel smartAddWithLayout(JPanel panel, Object layout, List parts) {
for (Object o : parts) panel.add(wrapForSmartAdd(o), layout);
return panel;
}
public static JPanel smartAddWithLayout(JPanel panel, Object layout, Object... parts) {
return smartAddWithLayout(panel, layout, asList(flattenArray2(parts)));
}
public static List nonNulls(List l) {
return withoutNulls(l);
}
public static Map nonNulls(Map map) {
return withoutNulls(map);
}
public static Component jrigid() {
return javax.swing.Box.createRigidArea(new Dimension(0, 0));
}
public static boolean containsSpaces(String s) {
return indexOf(s, ' ') >= 0;
}
public static String join(String glue, Iterable strings) {
if (strings == null)
return "";
if (strings instanceof Collection) {
if (((Collection) strings).size() == 1)
return str(first(((Collection) strings)));
}
StringBuilder buf = new StringBuilder();
Iterator i = strings.iterator();
if (i.hasNext()) {
buf.append(i.next());
while (i.hasNext()) buf.append(glue).append(i.next());
}
return buf.toString();
}
public static String join(String glue, String... strings) {
return join(glue, Arrays.asList(strings));
}
public static String join(Iterable strings) {
return join("", strings);
}
public static String join(Iterable strings, String glue) {
return join(glue, strings);
}
public static String join(String[] strings) {
return join("", strings);
}
public static String join(String glue, Pair p) {
return p == null ? "" : str(p.a) + glue + str(p.b);
}
public static 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 Method findMethod(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Method m = findMethod_static((Class) o, method, args, false);
if (m == null)
return null;
m.setAccessible(true);
return m;
} else {
Method m = findMethod_instance(o, method, args, false);
if (m == null)
return null;
m.setAccessible(true);
return m;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Method findMethod_static(Class c, String method, Object[] args, boolean debug) {
Class _c = c;
while (c != null) {
for (Method m : c.getDeclaredMethods()) {
if (debug)
System.out.println("Checking method " + m.getName() + " with " + m.getParameterTypes().length + " parameters");
;
if (!m.getName().equals(method)) {
if (debug)
System.out.println("Method name mismatch: " + method);
continue;
}
if ((m.getModifiers() & Modifier.STATIC) == 0 || !findMethod_checkArgs(m, args, debug))
continue;
return m;
}
c = c.getSuperclass();
}
return null;
}
public static Method findMethod_instance(Object o, String method, Object[] args, boolean debug) {
Class c = o.getClass();
while (c != null) {
for (Method m : c.getDeclaredMethods()) {
if (debug)
System.out.println("Checking method " + m.getName() + " with " + m.getParameterTypes().length + " parameters");
;
if (m.getName().equals(method) && findMethod_checkArgs(m, args, debug))
return m;
}
c = c.getSuperclass();
}
return null;
}
public static boolean findMethod_checkArgs(Method m, Object[] args, boolean debug) {
Class>[] types = m.getParameterTypes();
if (types.length != args.length) {
if (debug)
System.out.println("Bad parameter length: " + args.length + " vs " + types.length);
return false;
}
for (int i = 0; i < types.length; i++) if (!(args[i] == null || isInstanceX(types[i], args[i]))) {
if (debug)
System.out.println("Bad parameter " + i + ": " + args[i] + " vs " + types[i]);
return false;
}
return true;
}
public static List buttonsInGroup(ButtonGroup g) {
if (g == null)
return ll();
return asList(g.getElements());
}
public static ThreadLocal addInternalFrame_dontSelect = new ThreadLocal();
public static ThreadLocal addInternalFrame_layer = new ThreadLocal();
public static ThreadLocal addInternalFrame_toBack = new ThreadLocal();
public static JInternalFrame addInternalFrame(final JDesktopPane desktop, final String title, final int x, final int y, final int w, final int h) {
return addInternalFrame(desktop, title, x, y, w, h, null);
}
public static JInternalFrame addInternalFrame(final JDesktopPane desktop, final String title, final int x, final int y, final int w, final int h, final Component contents) {
return addInternalFrame(desktop, title, rect(x, y, w, h), contents);
}
public static JInternalFrame addInternalFrame(final JDesktopPane desktop, final String title, final Component contents) {
return addInternalFrame(desktop, title, null, contents);
}
public static JInternalFrame addInternalFrame(final JDesktopPane desktop, final String title, final Rect r, final Component contents) {
final boolean dontSelect = isTrue(optParam(addInternalFrame_dontSelect));
final boolean toBack = isTrue(optParam(addInternalFrame_toBack));
final Integer layer = optParam(addInternalFrame_layer);
return swing(new F0() {
public JInternalFrame get() {
try {
JInternalFrame frame;
if (contents instanceof JInternalFrame)
frame = (JInternalFrame) contents;
else {
frame = jInternalFrame(title);
setInternalFrameContents(frame, contents);
}
frame.setVisible(true);
desktop.add(frame, layer);
if (r != null)
setBounds(frame, r);
else
internalFrameDefaultPosition(frame);
if (dontSelect)
if (toBack)
frame.toBack();
else
frame.toFront();
else
frame.setSelected(true);
return fixInternalFrame(frame);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JInternalFrame frame;\r\n if (contents instanceof JInternalFrame)\r\n fra...";
}
});
}
public static JInternalFrame addInternalFrame(JDesktopPane desktop, String title) {
return addInternalFrame(desktop, title, jpanel());
}
public static JInternalFrame minInternalFrameWidth(final JInternalFrame frame, final int w) {
{
swing(new Runnable() {
public void run() {
try {
if (frame != null && frame.getWidth() < w)
frame.setSize(w, frame.getHeight());
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "if (frame != null && frame.getWidth() < w)\r\n frame.setSize(w, frame.getH...";
}
});
}
return frame;
}
public static JInternalFrame minInternalFrameWidth(int w, JInternalFrame frame) {
return minInternalFrameWidth(frame, w);
}
public static A packInternalFrameVertically(A c) {
return packInternalFrameVertically(-1, c);
}
public static A packInternalFrameVertically(int width, A c) {
final JInternalFrame win = getInternalFrame(c);
if (win == null)
return c;
final int w = width < 0 ? win.getWidth() : width;
{
swing(new Runnable() {
public void run() {
try {
win.pack();
win.setSize(w, win.getHeight());
fixInternalFrame(win);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "win.pack();\r\n win.setSize(w, win.getHeight());\r\n fixInternalFrame(win);";
}
});
}
return c;
}
public static JInternalFrame centerInternalFrame(final JInternalFrame f) {
{
swing(new Runnable() {
public void run() {
try {
Container c = f.getParent();
if (c != null) {
f.setLocation((c.getWidth() - f.getWidth()) / 2, (c.getHeight() - f.getHeight()) / 2);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Container c = f.getParent();\r\n if (c != null) {\r\n //print(\"Container ...";
}
});
}
return f;
}
public static JInternalFrame centerInternalFrame(final int w, final int h, final JInternalFrame f) {
{
swing(new Runnable() {
public void run() {
try {
f.setSize(w, h);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "f.setSize(w, h);";
}
});
}
return centerInternalFrame(f);
}
public static int packFrame_minw = 150, packFrame_minh = 50;
public static A packFrame(final A c) {
{
swing(new Runnable() {
public void run() {
try {
Window w = getWindow(c);
if (w != null) {
w.pack();
int maxW = getScreenWidth() - 50, maxH = getScreenHeight() - 50;
w.setSize(min(maxW, max(w.getWidth(), packFrame_minw)), min(maxH, max(w.getHeight(), packFrame_minh)));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Window w = getWindow(c);\r\n if (w != null) {\r\n w.pack();\r\n int ma...";
}
});
}
return c;
}
public static JFrame packFrame(ButtonGroup g) {
return packFrame(getFrame(g));
}
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 Object[] flattenArray2(Object... a) {
List l = new ArrayList();
if (a != null)
for (Object x : a) if (x instanceof Object[])
l.addAll(asList((Object[]) x));
else if (x instanceof Collection)
l.addAll((Collection) x);
else
l.add(x);
return asObjectArray(l);
}
public static List withoutNulls(List l) {
if (!containsNulls(l))
return l;
List l2 = new ArrayList();
for (A a : l) if (a != null)
l2.add(a);
return l2;
}
public static Map withoutNulls(Map map) {
Map map2 = similarEmptyMap(map);
for (A a : keys(map)) if (a != null) {
B b = map.get(a);
if (b != null)
map2.put(a, b);
}
return map2;
}
public static boolean isUpperCaseLetter(char c) {
return Character.isUpperCase(c);
}
public static Rect rect(int x, int y, int w, int h) {
return new Rect(x, y, w, h);
}
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 boolean jInternalFrame_iconifiable = true;
public static JInternalFrame jInternalFrame() {
return jInternalFrame("");
}
public static JInternalFrame jInternalFrame(final String title) {
return swing(new F0() {
public JInternalFrame get() {
try {
JInternalFrame f = new JInternalFrame(title, true, true, true, jInternalFrame_iconifiable);
f.setVisible(true);
return f;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JInternalFrame f = new JInternalFrame(title, true, true, true, jInternalFrame...";
}
});
}
public static void setInternalFrameContents(final Component c, final Object contents) {
{
swing(new Runnable() {
public void run() {
try {
JInternalFrame frame = getInternalFrame(c);
if (frame == null)
return;
frame.getContentPane().removeAll();
frame.getContentPane().setLayout(new BorderLayout());
if (contents != null)
frame.getContentPane().add(wrap(contents));
revalidate(frame);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JInternalFrame frame = getInternalFrame(c);\r\n if (frame == null) return;\r\n...";
}
});
}
}
public static A setBounds(final int x, final int y, final int w, final int h, final A a) {
if (a != null) {
swing(new Runnable() {
public void run() {
try {
a.setBounds(x, y, w, h);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "a.setBounds(x, y, w, h);";
}
});
}
return a;
}
public static A setBounds(final A a, final Rect r) {
if (a != null) {
swing(new Runnable() {
public void run() {
try {
a.setBounds(toRectangle(r));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "a.setBounds(toRectangle(r));";
}
});
}
return a;
}
public static A setBounds(A a, int x, int y, int w, int h) {
return setBounds(x, y, w, h, a);
}
public static void internalFrameDefaultPosition(JInternalFrame f) {
f.setSize(500, 300);
centerInternalFrame(f);
}
public static int fixInternalFrame_borderTopLeft = 0;
public static int fixInternalFrame_borderBottomRight = 40;
public static JInternalFrame fixInternalFrame(final JInternalFrame f) {
return swing(new F0() {
public JInternalFrame get() {
try {
Container c = f.getParent();
if (c == null)
return f;
Rect r = toRect(f.getBounds());
int a = fixInternalFrame_borderTopLeft, b = fixInternalFrame_borderBottomRight;
Rect outer = new Rect(a, a, c.getWidth() - b, c.getHeight() - b);
if (!rectContains(outer, r))
f.setLocation(max(a, min(r.x, outer.x2())), max(a, min(r.y, outer.y2())));
if (r.w > c.getWidth() || r.h > c.getHeight())
f.setSize(c.getWidth() - a, c.getHeight() - a);
return f;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Container c = f.getParent();\r\n if (c == null) ret f;\r\n Rect r = toRect(...";
}
});
}
public static int getScreenWidth() {
return getScreenSize().width;
}
public static int getScreenHeight() {
return getScreenSize().height;
}
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 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 boolean containsNulls(Collection c) {
return contains(c, null);
}
public static Map similarEmptyMap(Map m) {
if (m instanceof TreeMap)
return new TreeMap(((TreeMap) m).comparator());
if (m instanceof LinkedHashMap)
return new LinkedHashMap();
return new HashMap();
}
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(String name, Object[] params) {
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 Rectangle toRectangle(Rect r) {
return r == null ? null : r.getRectangle();
}
public static Rect toRect(Rectangle r) {
return r == null ? null : new Rect(r);
}
public static boolean rectContains(int x1, int y1, int w, int h, Pt p) {
return p.x >= x1 && p.y >= y1 && p.x < x1 + w && p.y < y1 + h;
}
public static boolean rectContains(Rect a, Rect b) {
return b.x >= a.x && b.y >= a.y && b.x2() <= a.x2() && b.y2() <= a.y2();
}
public static String programTitle() {
return getProgramName();
}
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 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 String getProgramName_cache;
public static String getProgramName() {
Lock __1293 = downloadLock();
lock(__1293);
try {
if (getProgramName_cache == null)
getProgramName_cache = getSnippetTitleOpt(programID());
return getProgramName_cache;
} finally {
unlock(__1293);
}
}
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 Frame getAWTFrame(final Object _o) {
return swing(new F0() {
public Frame get() {
try {
Object o = _o;
if (o instanceof ButtonGroup)
o = first(buttonsInGroup((ButtonGroup) o));
if (!(o instanceof Component))
return null;
Component c = (Component) o;
while (c != null) {
if (c instanceof Frame)
return (Frame) c;
c = c.getParent();
}
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "O o = _o;\r\n /*\r\n ifdef HaveProcessing\r\n if (o instanceof PApplet) ...";
}
});
}
public static int imageIcon_cacheSize = 10;
public static boolean imageIcon_verbose;
public static Map imageIcon_cache;
public static Lock imageIcon_lock = lock();
public static ThreadLocal imageIcon_fixGIF = new ThreadLocal();
public static ImageIcon imageIcon(String imageID) {
try {
if (imageID == null)
return null;
Lock __615 = imageIcon_lock;
lock(__615);
try {
if (imageIcon_cache == null)
imageIcon_cache = new MRUCache(imageIcon_cacheSize);
imageID = fsI(imageID);
ImageIcon ii = imageIcon_cache.get(imageID);
if (ii == null) {
if (imageIcon_verbose)
print("Loading image icon: " + imageID);
File f = loadBinarySnippet(imageID);
Boolean b = imageIcon_fixGIF.get();
if (!isFalse(b))
ii = new ImageIcon(loadBufferedImageFixingGIFs(f));
else
ii = new ImageIcon(f.toURI().toURL());
} else
imageIcon_cache.remove(imageID);
imageIcon_cache.put(imageID, ii);
return ii;
} finally {
unlock(__615);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static ImageIcon imageIcon(Image img) {
return new ImageIcon(img);
}
public static ImageIcon imageIcon(RGBImage img) {
return imageIcon(img.getBufferedImage());
}
public static String or2(String a, String b) {
return nempty(a) ? a : b;
}
public static String or2(String a, String b, String c) {
return or2(or2(a, b), c);
}
public static void standardTitlePopupMenu(final JFrame frame) {
if (isSubstanceLAF())
titlePopupMenu(frame, new VF1() {
public void get(JPopupMenu menu) {
try {
boolean alwaysOnTop = frame.isAlwaysOnTop();
menu.add(jmenuItem("Restart Program", "restart"));
menu.add(jmenuItem("Duplicate Program", "duplicateThisProgram"));
menu.add(jmenuItem("Show Console", "showConsole"));
menu.add(jCheckBoxMenuItem("Always On Top", alwaysOnTop, new Runnable() {
public void run() {
try {
toggleAlwaysOnTop(frame);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "toggleAlwaysOnTop(frame)";
}
}));
menu.add(jMenuItem("Shoot Window", new Runnable() {
public void run() {
try {
shootWindowGUI_external(frame, 500);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "shootWindowGUI_external(frame, 500)";
}
}));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "bool alwaysOnTop = frame.isAlwaysOnTop();\r\n menu.add(jmenuItem(\"Restar...";
}
});
}
public static Rectangle screenRectangle() {
return new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
}
public static Random random_random = new Random();
public static int random(int n) {
return n <= 0 ? 0 : random_random.nextInt(n);
}
public static double random(double max) {
return random() * max;
}
public static double random() {
return random_random.nextInt(100001) / 100000.0;
}
public static double random(double min, double max) {
return min + random() * (max - min);
}
public static int random(int min, int max) {
return min + random(max - min);
}
public static A random(List l) {
return oneOf(l);
}
public static A random(Collection c) {
if (c instanceof List)
return random((List) c);
int i = random(l(c));
return collectionGet(c, i);
}
public static JFrame consoleFrame() {
return (JFrame) getOpt(get(getJavaX(), "console"), "frame");
}
public static void autoVMExit() {
call(getJavaX(), "autoVMExit");
}
public static void restart() {
Object j = getJavaX();
call(j, "cleanRestart", get(j, "fullArgs"));
}
public static void duplicateThisProgram() {
nohupJavax(trim(programID() + " " + smartJoin((String[]) get(getJavaX(), "fullArgs"))));
}
public static void showConsole() {
callOpt(get(javax(), "console"), "showConsole");
}
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 String fsI(String id) {
return formatSnippetID(id);
}
public static String fsI(long id) {
return formatSnippetID(id);
}
public static File loadBinarySnippet(String snippetID) {
try {
long id = parseSnippetID(snippetID);
File f = DiskSnippetCache_getLibrary(id);
if (fileSize(f) == 0)
f = loadDataSnippetToFile(snippetID);
return f;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static boolean loadBufferedImageFixingGIFs_debug;
public static ThreadLocal> loadBufferedImageFixingGIFs_output = new ThreadLocal();
public static Image loadBufferedImageFixingGIFs(File file) {
try {
if (!file.exists())
return null;
if (!isGIF(file))
return ImageIO.read(file);
if (loadBufferedImageFixingGIFs_debug)
print("loadBufferedImageFixingGIFs" + ": checking gif");
ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
reader.setInput(ImageIO.createImageInputStream(file));
int numImages = reader.getNumImages(true);
IIOMetadata imageMetaData = reader.getImageMetadata(0);
String metaFormatName = imageMetaData.getNativeMetadataFormatName();
boolean foundBug = false;
for (int i = 0; i < numImages && !foundBug; i++) {
IIOMetadataNode root = (IIOMetadataNode) reader.getImageMetadata(i).getAsTree(metaFormatName);
int nNodes = root.getLength();
for (int j = 0; j < nNodes; j++) {
org.w3c.dom.Node node = root.item(j);
if (node.getNodeName().equalsIgnoreCase("GraphicControlExtension")) {
String delay = ((IIOMetadataNode) node).getAttribute("delayTime");
if (Integer.parseInt(delay) == 0) {
foundBug = true;
}
break;
}
}
}
if (loadBufferedImageFixingGIFs_debug)
print("loadBufferedImageFixingGIFs" + ": " + f2s(file) + " foundBug=" + foundBug);
Image image;
if (!foundBug) {
image = Toolkit.getDefaultToolkit().createImage(f2s(file));
} else {
ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
{
ImageOutputStream ios = ImageIO.createImageOutputStream(baoStream);
try {
ImageWriter writer = ImageIO.getImageWriter(reader);
writer.setOutput(ios);
writer.prepareWriteSequence(null);
for (int i = 0; i < numImages; i++) {
BufferedImage frameIn = reader.read(i);
IIOMetadataNode root = (IIOMetadataNode) reader.getImageMetadata(i).getAsTree(metaFormatName);
int nNodes = root.getLength();
for (int j = 0; j < nNodes; j++) {
org.w3c.dom.Node node = root.item(j);
if (node.getNodeName().equalsIgnoreCase("GraphicControlExtension")) {
String delay = ((IIOMetadataNode) node).getAttribute("delayTime");
if (Integer.parseInt(delay) == 0) {
((IIOMetadataNode) node).setAttribute("delayTime", "10");
}
break;
}
}
IIOMetadata metadata = writer.getDefaultImageMetadata(new ImageTypeSpecifier(frameIn), null);
metadata.setFromTree(metadata.getNativeMetadataFormatName(), root);
IIOImage frameOut = new IIOImage(frameIn, null, metadata);
writer.writeToSequence(frameOut, writer.getDefaultWriteParam());
}
writer.endWriteSequence();
} finally {
_close(ios);
}
}
byte[] data = baoStream.toByteArray();
setVar(loadBufferedImageFixingGIFs_output.get(), data);
if (loadBufferedImageFixingGIFs_debug)
print("Data size: " + l(data));
image = Toolkit.getDefaultToolkit().createImage(data);
}
return image;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static boolean isSubstanceLAF() {
return substanceLookAndFeelEnabled();
}
public static boolean titlePopupMenu(final Component c, final Object menuMaker) {
JComponent titleBar = getTitlePaneComponent(getPossiblyInternalFrame(c));
if (titleBar == null) {
print("Can't add title right click!");
return false;
} else {
componentPopupMenu(titleBar, menuMaker);
return true;
}
}
public static JCheckBoxMenuItem jCheckBoxMenuItem(String text, boolean checked, final Object r) {
final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(text, checked);
addActionListener(mi, new Runnable() {
public void run() {
try {
callF(r, isChecked(mi));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "callF(r, isChecked(mi))";
}
});
return mi;
}
public static void toggleAlwaysOnTop(JFrame frame) {
frame.setAlwaysOnTop(!frame.isAlwaysOnTop());
}
public static void shootWindowGUI_external(JFrame frame) {
call(hotwireOnce("#1007178"), "shootWindowGUI", frame);
}
public static void shootWindowGUI_external(final JFrame frame, int delay) {
call(hotwireOnce("#1007178"), "shootWindowGUI", frame, delay);
}
public static A oneOf(List l) {
return l.isEmpty() ? null : l.get(new Random().nextInt(l.size()));
}
public static char oneOf(String s) {
return empty(s) ? '?' : s.charAt(random(l(s)));
}
public static String oneOf(String... l) {
return oneOf(asList(l));
}
public static A collectionGet(Collection c, int idx) {
if (c == null || idx < 0 || idx >= l(c))
return null;
if (c instanceof List)
return listGet((List) c, idx);
Iterator it = c.iterator();
for (int i = 0; i < idx; i++) if (it.hasNext())
it.next();
else
return null;
return it.hasNext() ? it.next() : null;
}
public static void nohupJavax(final String javaxargs) {
startThread(new Runnable() {
public void run() {
try {
call(hotwireOnce("#1008562"), "nohupJavax", javaxargs);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "call(hotwireOnce(\"#1008562\"), \"nohupJavax\", javaxargs);";
}
});
}
public static void nohupJavax(final String javaxargs, final String vmArgs) {
startThread(new Runnable() {
public void run() {
try {
call(hotwireOnce("#1008562"), "nohupJavax", javaxargs, vmArgs);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "call(hotwireOnce(\"#1008562\"), \"nohupJavax\", javaxargs, vmArgs);";
}
});
}
public static String trim(String s) {
return s == null ? null : s.trim();
}
public static String trim(StringBuilder buf) {
return buf.toString().trim();
}
public static String trim(StringBuffer buf) {
return buf.toString().trim();
}
public static String smartJoin(String[] args) {
if (args.length == 1)
return args[0];
String[] a = new String[args.length];
for (int i = 0; i < a.length; i++) a[i] = !isJavaIdentifier(args[i]) && !isQuoted(args[i]) ? quote(args[i]) : args[i];
return join(" ", a);
}
public static String smartJoin(List args) {
return smartJoin(toStringArray(args));
}
public static String getSnippetTitle(String id) {
try {
if (id == null)
return null;
if (!isSnippetID(id))
return "?";
if (isLocalSnippetID(id))
return localSnippetTitle(id);
long parsedID = parseSnippetID(id);
String url;
if (isImageServerSnippet(parsedID))
url = imageServerURL() + "title/" + parsedID + muricaCredentialsQuery();
else if (isGeneralFileServerSnippet(parsedID))
url = "http://butter.botcompany.de:8080/files/name/" + parsedID;
else
url = tb_mainServer() + "/tb-int/getfield.php?id=" + parsedID + "&field=title" + standardCredentials_noCookies();
String title = trim(loadPageSilently(url));
if (title != null)
try {
saveTextFileIfChanged(snippetTitle_cacheFile(id), title);
} catch (Throwable __e) {
print(exceptionToStringShort(__e));
}
return or(title, "?");
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static String getSnippetTitle(long id) {
return getSnippetTitle(fsI(id));
}
public static File DiskSnippetCache_file(long snippetID) {
return new File(getGlobalCache(), "data_" + snippetID + ".jar");
}
public static File DiskSnippetCache_getLibrary(long snippetID) throws IOException {
File file = DiskSnippetCache_file(snippetID);
return file.exists() ? file : null;
}
public static void DiskSnippetCache_putLibrary(long snippetID, byte[] data) throws IOException {
saveBinaryFile(DiskSnippetCache_file(snippetID), data);
}
public static byte[] loadDataSnippetImpl(String snippetID) throws IOException {
byte[] data;
try {
URL url = new URL(dataSnippetLink(snippetID));
print("Loading library: " + hideCredentials(url));
try {
data = loadBinaryPage(url.openConnection());
} catch (RuntimeException e) {
data = null;
}
if (data == null || data.length == 0) {
url = new URL("http://data.tinybrain.de/blobs/" + parseSnippetID(snippetID));
print("Loading library: " + hideCredentials(url));
data = loadBinaryPage(url.openConnection());
}
print("Bytes loaded: " + data.length);
} catch (FileNotFoundException e) {
throw new IOException("Binary snippet #" + snippetID + " not found or not public");
}
return data;
}
public static long fileSize(String path) {
return getFileSize(path);
}
public static long fileSize(File f) {
return getFileSize(f);
}
public static File loadDataSnippetToFile(String snippetID) {
try {
snippetID = fsI(snippetID);
File f = DiskSnippetCache_file(parseSnippetID(snippetID));
List urlsTried = new ArrayList();
List errors = new ArrayList();
try {
URL url = addAndReturn(urlsTried, new URL(dataSnippetLink(snippetID)));
print("Loading library: " + hideCredentials(url));
try {
loadBinaryPageToFile(openConnection(url), f);
if (fileSize(f) == 0)
throw fail();
} catch (Throwable e) {
errors.add(e);
url = addAndReturn(urlsTried, new URL("http://data.tinybrain.de/blobs/" + psI(snippetID)));
print("Trying other server: " + hideCredentials(url));
loadBinaryPageToFile(openConnection(url), f);
print("Got bytes: " + fileSize(f));
}
if (fileSize(f) == 0)
throw fail();
System.err.println("Bytes loaded: " + fileSize(f));
} catch (Throwable e) {
printStackTrace(e);
errors.add(e);
throw fail("Binary snippet " + snippetID + " not found or not public. URLs tried: " + allToString(urlsTried) + ", errors: " + allToString(errors));
}
return f;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static byte[] isGIF_magic = bytesFromHex("47494638");
public static boolean isGIF(byte[] data) {
return byteArrayStartsWith(data, isGIF_magic);
}
public static boolean isGIF(File f) {
return isGIF(loadBeginningOfBinaryFile(f, l(isGIF_magic)));
}
public static void setVar(IVar v, A value) {
if (v != null)
v.set(value);
}
public static boolean substanceLookAndFeelEnabled() {
return startsWith(getLookAndFeel(), "org.pushingpixels.");
}
public static JComponent getTitlePaneComponent(RootPaneContainer window) {
if (window instanceof JInternalFrame)
return getInternalFrameTitlePaneComponent((JInternalFrame) window);
if (!substanceLookAndFeelEnabled() || window == null)
return null;
JRootPane rootPane = window.getRootPane();
if (rootPane != null) {
Object ui = rootPane.getUI();
return (JComponent) call(ui, "getTitlePane");
}
return null;
}
public static RootPaneContainer getPossiblyInternalFrame(Component c) {
JInternalFrame f = getInternalFrame(c);
if (f != null)
return f;
return optCast(RootPaneContainer.class, getWindow(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 Class hotwireOnce(String programID) {
return hotwireCached(programID, false);
}
public static A listGet(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
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 isQuoted(String s) {
if (isNormalQuoted(s))
return true;
return isMultilineQuoted(s);
}
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 boolean isLocalSnippetID(String snippetID) {
return isSnippetID(snippetID) && isLocalSnippetID(psI(snippetID));
}
public static boolean isLocalSnippetID(long snippetID) {
return snippetID >= 1000 && snippetID <= 9999;
}
public static String localSnippetTitle(String snippetID) {
if (!isLocalSnippetID(snippetID))
return null;
File f = localSnippetFile(snippetID);
if (!f.exists())
return null;
return or2(getFileInfoField(dropExtension(f), "Title"), "Unnamed");
}
public static boolean isImageServerSnippet(long id) {
return id >= 1100000 && id < 1200000;
}
public static String imageServerURL() {
return or2(trim(loadTextFile(javaxDataDir("image-server-url.txt"))), "http://botcompany.de/images/raw/");
}
public static String muricaCredentialsQuery() {
return htmlQuery(muricaCredentials());
}
public static boolean isGeneralFileServerSnippet(long id) {
return id >= 1400000 && id < 1500000;
}
public static String tb_mainServer_default = "http://tinybrain.de:8080";
public static Object tb_mainServer_override;
public static String tb_mainServer() {
if (tb_mainServer_override != null)
return (String) callF(tb_mainServer_override);
return trim(loadTextFile(tb_mainServer_file(), tb_mainServer_default));
}
public static File tb_mainServer_file() {
return getProgramFile("#1001638", "mainserver.txt");
}
public static boolean tb_mainServer_isDefault() {
return eq(tb_mainServer(), tb_mainServer_default);
}
public static String standardCredentials_noCookies() {
return standardCredentials() + "&noCookies=1";
}
public static boolean saveTextFileIfChanged(File f, String contents) {
return saveTextFileIfDifferent(f, contents);
}
public static File snippetTitle_cacheFile(String snippetID) {
return javaxCachesDir("Snippet Titles/" + psI(snippetID));
}
public static File getGlobalCache() {
File file = new File(javaxCachesDir(), "Binary Snippets");
file.mkdirs();
return file;
}
public static byte[] saveBinaryFile(String fileName, byte[] contents) {
try {
File file = new File(fileName);
File parentFile = file.getParentFile();
if (parentFile != null)
parentFile.mkdirs();
String tempFileName = fileName + "_temp";
FileOutputStream fileOutputStream = newFileOutputStream(tempFileName);
fileOutputStream.write(contents);
fileOutputStream.close();
if (file.exists() && !file.delete())
throw new IOException("Can't delete " + fileName);
if (!new File(tempFileName).renameTo(file))
throw new IOException("Can't rename " + tempFileName + " to " + fileName);
vmBus_send("wroteFile", file);
return contents;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public static byte[] saveBinaryFile(File fileName, byte[] contents) {
return saveBinaryFile(fileName.getPath(), contents);
}
public static String dataSnippetLink(String snippetID) {
long id = parseSnippetID(snippetID);
if (id >= 1100000 && id < 1200000)
return imageServerURL() + id;
if (id >= 1400000 && id < 1500000)
return "http://butter.botcompany.de:8080/files/" + id + "?_pass=" + muricaPassword();
if (id >= 1200000 && id < 1300000) {
String pw = muricaPassword();
if (empty(pw))
throw fail("Please set 'murica password by running #1008829");
return "http://butter.botcompany.de:8080/1008823/raw/" + id + "?_pass=" + pw;
} else
return "http://eyeocr.sourceforge.net/filestore/filestore.php?cmd=serve&file=blob_" + id + "&contentType=application/binary";
}
public static ThreadLocal