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 javax.swing.border.*;
import org.pushingpixels.substance.api.*;
import org.pushingpixels.substance.api.skin.*;
import javax.swing.undo.UndoManager;
public class main {
static String concepts = "\n xdzeaxtmkazaxncy - Set object to string X\n ocipgkzuhonmxyxp - Run standard function X on object\n rkaqgiahlhpqcsfb - Cool!\n";
static Object object;
static String text;
static JTextArea taObject;
static JTextField tfCmd;
public static void main(final String[] args) throws Exception { { swingAndWait(new Runnable() { public void run() { try {
blueSteel();
useConcepts(concepts);
object = 5;
text = struct(object);
taObject = wrappedTextArea(text);
setFontSize(taObject, 15);
tfCmd = jtextfield("ocipgkzuhonmxyxp plus1");
showFrame(
centerAndSouth(jSection("Object", taObject),
jSection("Command", textFieldWithButton("Go", tfCmd))));
onEnter(tfCmd, "go");
requestFocus(tfCmd);
hideConsole();
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "blueSteel();\n useConcepts(concepts);\n object = 5;\n text = struct(object);\n t..."; }}); }}
static void go() {
tfCmd.selectAll();
final Lisp cmd = englishToLisp(getTextTrim(tfCmd));
{ Thread _t_0 = new Thread() {
public void run() { try { try { { JWindow _loading_window = showLoadingAnimation(); try { /* loading try */
if (cmd.is("ocipgkzuhonmxyxp", 1)) // Run standard function X on object
setObject(makeAndCall_cached(cmd.raw(0), object));
if (cmd.is("xdzeaxtmkazaxncy", 1)) // Set object to string X
setObject(cmd.raw(0));
if (cmd.is("rkaqgiahlhpqcsfb"))
infoBox("Thanks!");
/* loading try */ } finally { disposeWindow(_loading_window); }
/* loading end */ } /* after loading */
} catch (Throwable __e) { messageBox(__e); }} catch (Throwable __e) { printStackTrace2(__e); } }
};
_t_0.start(); }
}
static void setObject(final Object o) { swingAndWait(new Runnable() { public void run() { try {
object = o;
try {
text = struct(o);
} catch (Throwable e) {
text = getStackTrace(e);
}
taObject.setText(text);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "object = o;\n try {\n text = struct(o);\n } catch (Throwable e) {\n text = g..."; }}); }
static String struct(Object o) {
return structure(o);
}
static void requestFocus(final JComponent c) { focus(c); }
static JPanel centerAndSouth(Component c, Component s) {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, wrap(c));
if (s != null) panel.add(BorderLayout.SOUTH, wrap(s));
return panel;
}
static JWindow infoBox(String text) {
return infoMessage(text);
}
static JWindow infoBox(String text, double seconds) {
return infoMessage(text, seconds);
}
static JPanel textFieldWithButton(String buttonText, final JTextField tf) {
return centerAndEast(tf, withLeftMargin(jbutton(buttonText, new Runnable() { public void run() { try { simulateEnter(tf) ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "simulateEnter(tf)"; }})));
}
static Object makeAndCall_cached(String functionName, Object... args) {
return preciseCall(loadFunctions_cached(functionName), functionName, args);
}
static JTextField jtextfield() {
return jTextField();
}
static JTextField jtextfield(String text) {
return jTextField(text);
}
static JTextField jtextfield(Object o) {
return jTextField(o);
}
static String getTextTrim(JTextComponent c) {
return trim(getText(c));
}
static void useConcepts(String concepts) {
useConceptsDump(concepts);
}
static A setFontSize(int size, A a) {
if (a != null) a.setFont(a.getFont().deriveFont((float) size));
return a;
}
static A setFontSize(A a, int size) {
return setFontSize(size, a);
}
static JTextField onEnter(JTextField tf, final Object action) {
if (action == null || tf == null) return tf;
tf.addActionListener(actionListener(action));
return tf;
}
static JButton onEnter(JButton btn, final Object action) {
if (action == null || btn == null) return btn;
btn.addActionListener(actionListener(action));
return btn;
}
static JList onEnter(JList list, final Object action) {
list.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent ke) {
if (ke.getKeyCode() == KeyEvent.VK_ENTER)
pcallF(action);
}
});
return list;
}
static String getStackTrace(Throwable throwable) {
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
return writer.toString();
}
static void blueSteel() {
substanceLAF("BusinessBlueSteel");
}
static Lisp englishToLisp(String s) {
return clParse(englishToConceptLanguage(s));
}
static JFrame showFrame() {
return makeFrame();
}
static JFrame showFrame(Object content) {
return makeFrame(content);
}
static JFrame showFrame(String title) {
return makeFrame(title);
}
static JFrame showFrame(String title, Object content) {
return makeFrame(title, content);
}
static JFrame showFrame(final JFrame frame) {
if (frame != null) { swingAndWait(new Runnable() { public void run() { try {
if (frameTooSmall(frame)) frameStandardSize(frame);
frame.setVisible(true);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "if (frameTooSmall(frame)) frameStandardSize(frame);\r\n frame.setVisible(true);"; }}); }
return frame;
}
// make or update frame
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;
}
}
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);"; }});
}
}
static JTextArea wrappedTextArea(JTextArea ta) {
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
return ta;
}
static JTextArea wrappedTextArea() {
return wrappedTextArea(new JTextArea());
}
static JTextArea wrappedTextArea(String text) {
JTextArea ta = wrappedTextArea();
ta.setText(text);
return ta;
}
static JPanel jSection(String title, Component c) {
Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED);
border = BorderFactory.createTitledBorder(border, title);
JPanel panel = new SingleComponentPanel(wrap(c));
panel.setBorder(border);
return panel;
}
static JPanel jSection(String title) {
return jSection(title, new JPanel());
}
static JPanel centerAndEast(Component c, Component e) {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, wrap(c));
panel.add(BorderLayout.EAST, wrap(e));
return panel;
}
static boolean frameTooSmall(JFrame frame) {
return frame.getWidth() < 100 || frame.getHeight() < 50;
}
static JFrame consoleFrame() {
return (JFrame) getOpt(get(getJavaX(), "console"), "frame");
}
static void useConceptsDump(String concepts) {
List usedConcepts = conceptsFromDump(concepts);
//dumpConcepts2(findAIConcepts(conceptsUsed));
//printAIConcepts(usedConcepts);
setOpt(mc(), "englishToConceptLanguage_concepts_global", usedConcepts);
aiConceptsMap_cached_autoClearInterval = 0;
aiConceptsMap_cached_cache.set(indexByField(usedConcepts, "globalID"));
ai();
}
static WeakHashMap makeFrame_myFrames = new WeakHashMap();
static JFrame makeFrame() {
return makeFrame((Component) null);
}
static JFrame makeFrame(Object content) {
return makeFrame(programTitle(), content);
}
static JFrame makeFrame(String title) {
return makeFrame(title, null);
}
static JFrame makeFrame(String title, Object content) {
return makeFrame(title, content, true);
}
static JFrame makeFrame(final String title, final Object content, final boolean showIt) {
return (JFrame) swing(new Object() { Object get() { try {
if (getFrame(content) != null)
return setFrameTitle((Component) content, title);
final JFrame frame = new JFrame(title);
makeFrame_myFrames.put(frame, Boolean.TRUE);
JComponent wrapped = wrap(content);
if (wrapped != null)
frame.getContentPane().add(wrapped);
frame.setBounds(300, 100, 500, 400);
if (showIt)
frame.setVisible(true);
//callOpt(content, "requestFocus");
//exitOnFrameClose(frame);
standardTitlePopupMenu(frame);
return frame;
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "if (getFrame(content) != null)\r\n ret setFrameTitle((Component) content, tit..."; }});
}
static Object pcallF(Object f, Object... args) {
return pcallFunction(f, args);
}
static void focus(final JComponent c) {
swingLater(new Runnable() { public void run() { try {
c.requestFocus();
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "c.requestFocus();"; }});
}
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 HashMap, Class> loadFunctions_cache = new HashMap();
static Class loadFunctions_cached(String... functions) {
return loadFunctions_cached(asList(functions));
}
static Class loadFunctions_cached(List functions) {
Set functionSet = new TreeSet(functions);
synchronized(loadFunctions_cache) {
Class c = loadFunctions_cache.get(functionSet);
if (c == null) {
loadFunctions_cache.put(functionSet, c = loadFunctions(functionSet));
assertNotNull(loadFunctions_cache.get(functionSet));
}
return c;
}
}
static void simulateEnter(JTextField tf) {
for (ActionListener a : tf.getActionListeners())
a.actionPerformed(new ActionEvent(tf, ActionEvent.ACTION_PERFORMED, null));
}
static ActionListener actionListener(final Object runnable) {
return new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent _evt) { pcallF(runnable); }};
}
static String trim(String s) { return s == null ? null : s.trim(); }
static String trim(StringBuilder buf) { return buf.toString().trim(); }
static String trim(StringBuffer buf) { return buf.toString().trim(); }
static void frameStandardSize(JFrame frame) {
frame.setBounds(300, 100, 500, 400);
}
static void setFrameContents(JFrame frame, Object contents) {
frame.getContentPane().removeAll();
frame.getContentPane().add(wrap(contents));
revalidate(frame);
}
static boolean englishToConceptLanguage_dropPunctuation;
static String englishToConceptLanguage(String s) {
{ String _a_1 = englishToConceptLanguage_simple(s); if (!empty(_a_1)) return _a_1; }
{ String _a_2 = englishToConceptLanguage_xyz(s, null); if (!empty(_a_2)) return _a_2; }
if (englishToConceptLanguage_dropPunctuation)
{ String _a_3 = englishToConceptLanguage_xyz(s, "dropPunctuation"); if (!empty(_a_3)) return _a_3; }
return s;
}
static JTextField jTextField() {
return jTextField("");
}
static JTextField jTextField(String text) {
JTextField tf = new JTextField(unnull(text));
jenableUndoRedo(tf);
tf.selectAll();
return tf;
}
static JTextField jTextField(Object o) {
return jTextField(strOrEmpty(o));
}
static boolean infoMessage_alwaysOnTop = true;
static double infoMessage_defaultTime = 5.0;
// automatically switches to AWT thread for you
static JWindow infoMessage(String text) {
return infoMessage(text, infoMessage_defaultTime);
}
static JWindow infoMessage(final String text, final double seconds) {
print(text);
return infoMessage_noprint(text, seconds);
}
static JWindow infoMessage_noprint(String text) {
return infoMessage_noprint(text, infoMessage_defaultTime);
}
static JWindow infoMessage_noprint(final String text, final double seconds) {
if (isHeadless()) return null;
return (JWindow) swingAndWait(new Object() { Object get() { try {
JTextArea ta = wrappedTextArea(text);
ta.setFont(typeWriterFont());
JScrollPane sp = jscroll(ta);
final JWindow window = showWindow(withMargin(sp));
window.setSize(300, 150);
moveToTopRightCorner(window);
onClick(ta, new Runnable() { public void run() { try { window.dispose() ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "window.dispose()"; }});
if (infoMessage_alwaysOnTop)
window.setAlwaysOnTop(true);
window.setVisible(true);
disposeWindowAfter(iround(seconds*1000), window);
return window;
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "JTextArea ta = wrappedTextArea(text);\r\n ta.setFont(typeWriterFont());\r\n JS..."; }});
}
static Lisp clParse(String s) {
List tok = tok_groupRoundBrackets(s);
if (l(tok) == 1) return null;
Lisp l = lisp(unquote(tok.get(1)));
for (int i = 3; i < l(tok); i += 2) {
String t = tok.get(i);
if (t.startsWith("(") && t.endsWith(")"))
l.add(assertNotNull(clParse(dropFirstAndLast(t))));
else
l.add(lisp(aiUsing(unquote(t))));
}
return l;
}
static List clParse(List l) {
return map("clParse", l);
}
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()"; }});
}
static boolean preciseCall_debug;
static Object preciseCall(Object o, String method, Object... args) { try {
if (o instanceof Class) {
List methods = findMethodsNamed2((Class) o, method, true);
Lowest best = new Lowest();
for (Method m : methods) {
int score = methodApplicabilityScore(m, args);
if (score < Integer.MAX_VALUE) {
if (preciseCall_debug)
print("Method score: " + m + " " + score);
best.put(m, score);
}
}
Method m = best.get();
if (m == null) throw fail("No suitable method found: " + methodSignature(method, args));
return m.invoke(null, args);
} else {
throw todo();
}
} catch (Exception __e) { throw rethrow(__e); } }
static JButton jbutton(String text, Object action) {
return newButton(text, action);
}
// button without action
static JButton jbutton(String text) {
return newButton(text, null);
}
static JButton jbutton(BufferedImage img, Object action) {
return setButtonImage(img, jbutton("", action));
}
static boolean structure_showTiming, structure_checkTokenCount;
static String structure(Object o) {
structure_Data d = new structure_Data();
StringWriter sw = new StringWriter();
d.out = new PrintWriter(sw);
structure_go(o, d);
String s = str(sw);
if (structure_checkTokenCount) {
print("token count=" + d.n);
assertEquals("token count", l(javaTokC(s)), d.n);
}
return s;
}
static void structure_go(Object o, structure_Data d) {
structure_1(o, d);
while (nempty(d.stack))
popLast(d.stack).run();
}
static void structureToPrintWriter(Object o, PrintWriter out) {
structure_Data d = new structure_Data();
d.out = out;
structure_go(o, d);
}
// leave to false, unless unstructure() breaks
static boolean structure_allowShortening = false;
static int structure_shareStringsLongerThan = 20;
static class structure_Data {
PrintWriter out;
int stringSizeLimit;
IdentityHashMap