import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import org.pushingpixels.substance.api.*;
import org.pushingpixels.substance.api.skin.*;
import java.awt.datatransfer.StringSelection;
class main {
public static void main(final String[] args) throws Exception { { swing(new Runnable() { public void run() { try { substance();
autoRestart();
final AutoComboBox box = autoComboBox(ll("Hello", "World"));
showForm(
"", box,
new Object() { Object get() { try {
infoBox(getText(box));
return false;
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "infoBox(getText(box));\n false;"; }});
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "substance();\n autoRestart();\n final AutoComboBox box = autoComboBox(ll(\"Hel..."; }}); }}
static double autoRestart_interval = 10;
static boolean autoRestart_on, autoRestart_debug, autoRestart_simulate;
static java.util.Timer autoRestart_timer;
static void autoRestart(double interval) {
autoRestart_interval = interval;
autoRestart();
}
static void autoRestart() {
if (autoRestart_on) return;
autoRestart_on = true;
autoRestart_schedule();
preloadProgramTitle();
}
static void autoRestart_off() {
if (!autoRestart_on) return;
stopTimer(autoRestart_timer);
autoRestart_timer = null;
}
static void autoRestart_schedule() {
autoRestart_timer = doLater_daemon(toMS(autoRestart_interval), "autoRestart_check");
}
static void autoRestart_check() {
try {
String newMD5 = loadPageSilently("http://ai1.lol/1010693/raw?id=" + psI(programID()));
if (!isMD5(newMD5)) { if (autoRestart_debug) print("autoRestart: no server transpilation"); return; }
if (autoRestart_localMD5 == null)
autoRestart_localMD5 = md5(loadCachedTranspilation(programID()));
String localMD5 = autoRestart_localMD5();
if (neq(localMD5, newMD5)) {
if (autoRestart_simulate)
print("Would upgrade now. " + localMD5 + " -> " + newMD5);
else {
infoBox("Upgrading " + programTitle());
restartWithDelay(1000);
sleep();
}
}
} finally {
if (autoRestart_debug) print("autoRestart: Done");
autoRestart_schedule();
}
}
static List ll(A... a) {
ArrayList l = new ArrayList(a.length);
for (A x : a) l.add(x);
return l;
}
static RuntimeException rethrow(Throwable e) {
throw asRuntimeException(e);
}
static Object swing(Object f) {
return swingAndWait(f);
}
static A swing(F0 f) {
return (A) swingAndWait(f);
}
static JPanel showForm(Object... parts) {
return showFormTitled(autoFrameTitle(), parts);
}
static String getText(final JTextComponent c) {
return c == null ? "" : (String) swingAndWait(new Object() { Object get() { try { return c.getText() ; } catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "c.getText()"; }});
}
static String getText(final JLabel l) {
return l == null ? "" : (String) swingAndWait(new Object() { Object get() { try { return l.getText() ; } catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "l.getText()"; }});
}
// returns the contents of text field for editable combo box
static String getText(final JComboBox cb) {
if (cb.isEditable())
return unnull((String) cb.getEditor().getItem());
else
return str(cb.getSelectedItem());
}
static void substance() {
substanceLAF();
}
static void substance(String skinName) {
substanceLAF(skinName);
}
// get purpose 1: access a list/array/map (safer version of x.get(y))
static A get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
// seems to conflict with other signatures
/*static B get(Map map, A key) {
ret map != null ? map.get(key) : null;
}*/
static A get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
// default to false
static boolean get(boolean[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : false;
}
// get purpose 2: access a field by reflection or a map
static Object get(Object o, String field) {
try {
if (o instanceof Class) return get((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
Field f = getOpt_findField(o.getClass(), field);
if (f != null) {
f.setAccessible(true);
return f.get(o);
}
if (o instanceof DynamicObject)
return ((DynamicObject) o).fieldValues.get(field);
} catch (Exception e) {
throw asRuntimeException(e);
}
throw new RuntimeException("Field '" + field + "' not found in " + o.getClass().getName());
}
static Object get_raw(Object o, String field) {
try {
Field f = get_findField(o.getClass(), field);
f.setAccessible(true);
return f.get(o);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static Object get(Class c, String field) {
try {
Field f = get_findStaticField(c, field);
f.setAccessible(true);
return f.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static Field get_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields())
if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
static Field get_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields())
if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
static Map _registerThread_threads = newWeakHashMap();
static Thread _registerThread(Thread t) {
_registerThread_threads.put(t, true);
return t;
}
static void _registerThread() { _registerThread(Thread.currentThread()); }
static JWindow infoBox(String text) {
return infoMessage(text);
}
static JWindow infoBox(String text, double seconds) {
return infoMessage(text, seconds);
}
static JWindow infoBox(Throwable e) {
return infoMessage(e);
}
static AutoComboBox autoComboBox() {
return autoComboBox(new ArrayList());
}
static AutoComboBox autoComboBox(final Collection items) {
return swing(new F0() { AutoComboBox get() { try {
AutoComboBox cb = new AutoComboBox();
cb.setKeyWord(items);
return cb;
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "new AutoComboBox cb;\r\n cb.setKeyWord(items);\r\n ret cb;"; }});
}
static AutoComboBox autoComboBox(String value, Collection items) {
return setText(autoComboBox(items), value);
}
static void restartWithDelay(int delay) {
Object j = getJavaX();
call(j, "preKill");
call(j, "nohupJavax", smartJoin((String[]) get(j, "fullArgs")), call(j, "fullVMArguments"));
sleep(delay);
System.exit(0);
sleep();
}
static String unnull(String s) {
return s == null ? "" : s;
}
static List unnull(List l) {
return l == null ? emptyList() : l;
}
static Map unnull(Map l) {
return l == null ? emptyMap() : l;
}
static Iterable unnull(Iterable i) {
return i == null ? emptyList() : i;
}
static A[] unnull(A[] a) {
return a == null ? (A[]) new Object[0] : a;
}
static BitSet unnull(BitSet b) {
return b == null ? new BitSet() : b;
}
static Map newWeakHashMap() {
return _registerWeakMap(synchroMap(new WeakHashMap()));
}
static String substanceLAF_defaultSkin = "Creme";
static void substanceLAF() {
substanceLAF(null);
}
static void substanceLAF(String skinName) {
try {
enableSubstance_impl(or2(skinName, substanceLAF_defaultSkin));
} catch (Throwable __e) { printStackTrace2(__e); }
}
static ThreadLocal loadPage_charset = new ThreadLocal();
static boolean loadPage_allowGzip = true, loadPage_debug;
static boolean loadPage_anonymous; // don't send computer ID
static int loadPage_verboseness = 100000;
static int loadPage_retries = 1; //60; // seconds
static ThreadLocal loadPage_silent = new ThreadLocal();
static volatile int loadPage_forcedTimeout; // ms
static ThreadLocal loadPage_forcedTimeout_byThread = new ThreadLocal(); // ms
static ThreadLocal