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 java.util.function.*;
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 java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import java.time.Duration;
import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;
import javax.swing.border.TitledBorder;
import javax.swing.border.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.text.SimpleDateFormat;
import java.nio.charset.Charset;
import static x30_pkg.x30_util.DynamicObject;
import java.nio.file.*;
import static java.nio.file.StandardWatchEventKinds.*;
import org.fife.ui.autocomplete.*;
import org.fife.rsta.ui.CollapsibleSectionPanel;
import org.fife.rsta.ui.GoToDialog;
import org.fife.rsta.ui.SizeGripIcon;
import org.fife.rsta.ui.search.FindDialog;
import org.fife.rsta.ui.search.ReplaceDialog;
import org.fife.rsta.ui.search.ReplaceToolBar;
import org.fife.rsta.ui.search.SearchEvent;
import org.fife.rsta.ui.search.SearchListener;
import org.fife.rsta.ui.search.FindToolBar;
import org.fife.ui.rsyntaxtextarea.ErrorStrip;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
import org.fife.ui.rtextarea.SearchResult;
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
import org.fife.ui.rsyntaxtextarea.SyntaxScheme;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.Const;
import org.apache.bcel.generic.*;
import java.lang.reflect.Type;
import java.awt.datatransfer.StringSelection;
import java.util.jar.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.nio.file.Path;
import java.text.*;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;
import javax.swing.Timer;
import org.fife.ui.rsyntaxtextarea.*;
import javax.swing.undo.UndoManager;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.geom.*;
import java.text.NumberFormat;
import java.util.TimeZone;
import java.awt.datatransfer.UnsupportedFlavorException;
import javax.swing.Icon;
public class main {
abstract static public class G22CRUDAndDetailPanel extends ConceptWithChangeListeners implements Swingable, IUnstructured {
static final public String _fieldOrder = "selected collapsiblePanel g22utils crud scpDetail handleSelectionVar";
public Ref selected = new Ref();
public CollapsibleNorthPanel collapsiblePanel = new CollapsibleNorthPanel(true);
final public G22CRUDAndDetailPanel setG22utils(G22Utils g22utils) {
return g22utils(g22utils);
}
public G22CRUDAndDetailPanel g22utils(G22Utils g22utils) {
this.g22utils = g22utils;
return this;
}
final public G22Utils getG22utils() {
return g22utils();
}
public G22Utils g22utils() {
return g22utils;
}
transient public G22Utils g22utils;
transient public SimpleCRUD_v2 crud;
transient public SingleComponentPanel scpDetail;
abstract public SimpleCRUD_v2 makeCRUD();
transient public RSTVar handleSelectionVar = new RSTVar<>(__1 -> handleSelection_impl(__1));
public JComponent makeDetailView(A a) {
return jTodo();
}
{
_doneLoading2();
}
public void _doneLoading2() {
super._doneLoading2();
collapsiblePanel.wrappedSideComponent = () -> centerAndEastWithMargin(collapsiblePanel.sideComponent(), vstack(collapsiblePanel.collapseButton()));
}
public transient JComponent visualize_cache;
public JComponent visualize() {
if (visualize_cache == null)
visualize_cache = visualize_load();
return visualize_cache;
}
public JComponent visualize_load() {
return markVisualizer(this, visualize_impl());
}
public JComponent visualize_impl() {
crud = makeCRUD();
putCRUDButtonsNextToSearchBar(crud);
scpDetail = singleComponentPanel();
if (collapsiblePanel.expanded)
selectAfterUpdate(selected.get());
var crudVis = crud.visualize();
crudVisualized();
handleSelectionVar.forceUpdate();
crud.onSelectionChanged(() -> {
var selected = crud.selected();
this.selected.set(selected);
handleSelectionVar.set(selected);
});
collapsiblePanel.defaultSplitPoint(0.3);
collapsiblePanel.init(crud.entityName() + " List", jCenteredSection(crud.entityNamePlural(), crudVis), scpDetail);
collapsiblePanel.onChange(() -> change());
return collapsiblePanel.visualize();
}
public void handleSelection_impl(A selected) {
if (selected == null)
scpDetail.set(emptyDetailView());
else {
var view = makeDetailView(selected);
var lvTitle = liveValue_hasChangeListeners(selected, () -> detailTitle(selected));
scpDetail.set(jCenteredRaisedBoldLiveValueSection(lvTitle, view));
}
}
transient public IF1 detailTitle;
public String detailTitle(A item) {
return detailTitle != null ? detailTitle.get(item) : detailTitle_base(item);
}
final public String detailTitle_fallback(IF1 _f, A item) {
return _f != null ? _f.get(item) : detailTitle_base(item);
}
public String detailTitle_base(A item) {
return appendPrefix(crud.entityName() + " " + item.id + ": ", str(item));
}
public JComponent emptyDetailView() {
return jGazelleLogo();
}
public void crudVisualized() {
}
public void addCountToEnclosingTab(boolean b) {
crud.addCountToEnclosingTab(b);
}
public void updateCount() {
crud.update();
}
final public void setSelected(A A) {
edit(A);
}
public void edit(A A) {
var searcher = crud().tableSearcher();
{
if (searcher != null)
searcher.clearSearchField();
}
crud().setSelected(A);
}
public void selectAfterUpdate(A A) {
crud.selectAfterUpdate(A);
}
public SimpleCRUD_v2 crud() {
visualize();
return crud;
}
}
static public G22Utils g22utils(Concepts cc) {
return (G22Utils) cc.miscMapGet(G22Utils.class);
}
static public G22Utils g22utils(Concept cc) {
return g22utils(concepts(cc));
}
static public JComponent jTodo() {
return jcenteredlabel("TODO");
}
static public JPanel centerAndEastWithMargin(Swingable c, Swingable e) {
return centerAndEastWithMargin(c, toComponent(e));
}
static public JPanel centerAndEastWithMargin(Swingable c, Component e) {
return centerAndEastWithMargin(toComponent(c), e);
}
static public JPanel centerAndEastWithMargin(Component c, Swingable e) {
return centerAndEastWithMargin(c, toComponent(e));
}
static public JPanel centerAndEastWithMargin(Component c, Component e) {
return centerAndEastWithMarginInbetween(c, e);
}
static public JPanel vstack(Object... parts) {
return vstack2(parts);
}
static public JPanel vstack(List parts) {
return vstack(toObjectArray(parts));
}
static public A markVisualizer(Object visualizer, A a) {
return setMetaSrc(a, visualizer);
}
static public void putCRUDButtonsNextToSearchBar(SimpleCRUD_v2 crud) {
var searcher = crud.tableSearcher();
searcher.scpRightOfSearchPanel.set(crud.wrappedButtonBar);
}
static public SingleComponentPanel singleComponentPanel() {
return singleComponentPanel(null);
}
static public 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 "return new SingleComponentPanel(c);";
}
});
}
static public JPanel jCenteredSection(Component c) {
return jCenteredSection("", c);
}
static public JPanel jCenteredSection(String title, Swingable c) {
return jCenteredSection(title, wrap(c));
}
static public JPanel jCenteredSection(String title, Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = jSection(title, c);
((TitledBorder) p.getBorder()).setTitleJustification(TitledBorder.CENTER);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = jSection(title, c);\r\n ((TitledBorder) p.getBorder()).setTitleJu...";
}
});
}
static public JPanel jCenteredSection(String title) {
return jCenteredSection(title, jpanel());
}
static public void change() {
callOpt(getOptMC("mainConcepts"), "allChanged");
}
static public SimpleLiveValue liveValue_hasChangeListeners(A object, IF0 getter) {
return liveValue_hasChangeListeners(object, null, getter);
}
static public SimpleLiveValue liveValue_hasChangeListeners(A object, Class type, IF0 getter) {
return liveValue_hasChangeListeners(object, type, getter, null);
}
static public SimpleLiveValue liveValue_hasChangeListeners(A object, IF0 getter, IVF1 setter) {
return liveValue_hasChangeListeners(object, null, getter, setter);
}
static public SimpleLiveValue liveValue_hasChangeListeners(A object, Class type, IF0 getter, IVF1 setter) {
SimpleLiveValue value = new SimpleLiveValue<>(type, getter.get());
addWeakChangeListener(object, value, val -> val.set(getter.get()));
value.onChange(() -> {
{
if (setter != null)
setter.get(value.get());
}
});
return value;
}
static public JPanel jCenteredRaisedBoldLiveValueSection(IF0WithChangeListeners lv, Component c) {
return swing(() -> {
return new jCenteredLiveValueSection_class(lv, c).borderType(BevelBorder.RAISED).bold(true).init();
});
}
static public String appendPrefix(String prefix, String s) {
return addPrefix(prefix, s);
}
static public String str(Object o) {
return o == null ? "null" : o.toString();
}
static public String str(char[] c) {
return c == null ? "null" : new String(c);
}
static public String str(char[] c, int offset, int count) {
return new String(c, offset, count);
}
static public JComponent jGazelleLogo() {
return setOpaqueBackground(Color.white, jimage(gazelleLogoImageID()));
}
static public Concepts concepts(Concept c) {
return c == null ? null : c._concepts;
}
static public JLabel jcenteredlabel(String text) {
return jcenteredLabel(text);
}
static public JLabel jcenteredlabel() {
return jcenteredLabel();
}
static public A toComponent(A c) {
return c;
}
static public Component toComponent(Swingable c) {
return c == null ? null : c.visualize();
}
static public JPanel centerAndEastWithMarginInbetween(Component c, final Component e) {
return centerAndEast(c, withLeftMargin(e));
}
static public JPanel vstack2(final Object... parts) {
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;
smartAddWithLayout(panel, gbc, parts);
gbc.weighty = 1;
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...";
}
});
}
static public Object[] toObjectArray(Collection c) {
return toObjectArray((Iterable) c);
}
static public Object[] toObjectArray(Iterable c) {
List l = asList(c);
return l.toArray(new Object[l.size()]);
}
static public A setMetaSrc(A a, Object src) {
setMetaAndVerify(a, "src", src);
return a;
}
static public A setMetaSrc(A a, Object src) {
setMetaAndVerify(a, "src", src);
return a;
}
static public Object swing(Object f) {
return swingAndWait(f);
}
static public void swing(Runnable f) {
swingAndWait(f);
}
static public A swing(F0 f) {
return (A) swingAndWait(f);
}
static public A swing(IF0 f) {
return (A) swingAndWait(f);
}
static public RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static public RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
static public JComponent wrap(Object swingable) {
return _recordNewSwingComponent(wrap_2(swingable));
}
static public JComponent wrap_2(Object swingable) {
if (swingable == null)
return null;
JComponent c;
if (swingable instanceof Component)
c = componentToJComponent((Component) swingable);
else if (swingable instanceof Swingable)
c = componentToJComponent(((Swingable) swingable).visualize());
else
c = componentToJComponent((Component) callOpt(swingable, "swing"));
if (c instanceof JTable || c instanceof JList || c instanceof JTextArea || c instanceof JEditorPane || c instanceof JTextPane || c instanceof JTree)
return jscroll(c);
return c == null ? jlabel(str(swingable)) : c;
}
static public A get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
static public A get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
static public boolean get(boolean[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : false;
}
static public Object get(Object o, String field) {
try {
if (o == null)
return null;
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) {
makeAccessible(f);
return f.get(o);
}
if (o instanceof DynamicObject)
return getOptDynOnly(((DynamicObject) o), field);
} catch (Exception e) {
throw asRuntimeException(e);
}
throw new RuntimeException("Field '" + field + "' not found in " + o.getClass().getName());
}
static public Object get_raw(String field, Object o) {
return get_raw(o, field);
}
static public Object get_raw(Object o, String field) {
try {
if (o == null)
return null;
Field f = get_findField(o.getClass(), field);
makeAccessible(f);
return f.get(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object get(Class c, String field) {
try {
Field f = get_findStaticField(c, field);
makeAccessible(f);
return f.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static public 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 public 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 public Object get(String field, Object o) {
return get(o, field);
}
static public boolean get(BitSet bs, int idx) {
return bs != null && bs.get(idx);
}
static public JPanel jSection(Component c) {
return jSection("", c);
}
static public JPanel jSection(final String title, final Component c) {
return swing(new F0() {
public JPanel get() {
try {
Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED);
border = BorderFactory.createTitledBorder(border, title);
JSection panel = new JSection(c);
panel.setBorder(border);
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED);\r\n bo...";
}
});
}
static public JPanel jSection(String title) {
return jSection(title, jpanel());
}
static public JPanel jSection(LiveValue> lv, Component c) {
return jLiveValueSection(lv, c);
}
static public JPanel jpanel(LayoutManager layout, Object... components) {
return jpanel(layout, asList(components));
}
static public JPanel jpanel(LayoutManager layout, List components) {
return smartAdd(jpanel(layout), components);
}
static public JPanel jpanel(LayoutManager layout) {
return swing(() -> new JPanel(layout));
}
static public JPanel jpanel() {
return swing(() -> new JPanel());
}
static public Object callOpt(Object o) {
return callF(o);
}
static public Object callOpt(Object o, String method, Object... args) {
return callOpt_withVarargs(o, method, args);
}
static public Object getOptMC(String field) {
return getOpt(mc(), field);
}
static public void addWeakChangeListener(IHasChangeListeners src, ChangeTriggerable target) {
addWeakChangeListener(src, target, o -> o.change());
}
static public void addWeakChangeListener(IHasChangeListeners src, A target, IVF1 action) {
if (src == null || action == null || target == null)
return;
var ref = weakRef(target);
src.onChange(new Runnable() {
public void run() {
try {
var target = ref.get();
if (target == null)
src.removeChangeListener(this);
else
action.get(target);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "var target = ref!;\r\n if (target == null)\r\n src.removeChangeListener(t...";
}
});
}
static public String addPrefix(String prefix, String s) {
return s.startsWith(prefix) ? s : prefix + s;
}
static public A setOpaqueBackground(final Color color, final A a) {
if (a != null) {
swing(() -> {
a.setBackground(color);
a.setOpaque(true);
a.putClientProperty("substancelaf.colorizationFactor", 1.0);
});
}
return a;
}
static public JLabel jimage(Image img) {
return jImageLabel(img);
}
static public JLabel jimage(String imageID) {
return jImageLabel(imageID);
}
static public String gazelleLogoImageID() {
return "#1102967";
}
static public JLabel jcenteredLabel(String text) {
return setHorizontalAlignment(JLabel.CENTER, jLabel(text));
}
static public JLabel jcenteredLabel() {
return jcenteredLabel(" ");
}
static public JPanel centerAndEast(final Component c, final Component e) {
return swing(new F0() {
public JPanel get() {
try {
JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, wrap(c));
panel.add(BorderLayout.EAST, wrap(e));
return panel;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel panel = new JPanel(new BorderLayout);\r\n panel.add(BorderLayout.CENT...";
}
});
}
static public int withLeftMargin_defaultWidth = 6;
static public JPanel withLeftMargin(Swingable c) {
return withLeftMargin(toComponent(c));
}
static public JPanel withLeftMargin(Component c) {
return withLeftMargin(withLeftMargin_defaultWidth, c);
}
static public JPanel withLeftMargin(int margin, Swingable c) {
return withLeftMargin(margin, toComponent(c));
}
static public JPanel withLeftMargin(int margin, Component c) {
return swing(new F0() {
public JPanel get() {
try {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(0, margin, 0, 0));
p.add(c);
return p;
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "JPanel p = new JPanel(new BorderLayout);\r\n p.setBorder(BorderFactory.creat...";
}
});
}
static public JPanel smartAddWithLayout(JPanel panel, Object layout, List parts) {
for (Object o : parts) panel.add(wrapForSmartAdd(o), layout);
return panel;
}
static public JPanel smartAddWithLayout(JPanel panel, Object layout, Object... parts) {
return smartAddWithLayout(panel, layout, asList(flattenArray2(parts)));
}
static public Component jrigid() {
return javax.swing.Box.createRigidArea(new Dimension(0, 0));
}
static public ArrayList asList(A[] a) {
return a == null ? new ArrayList() : new ArrayList(Arrays.asList(a));
}
static public ArrayList asList(char[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (var i : a) l.add(i);
return l;
}
static public ArrayList asList(byte[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (var i : a) l.add(i);
return l;
}
static public ArrayList asList(int[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (int i : a) l.add(i);
return l;
}
static public ArrayList asList(long[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (long i : a) l.add(i);
return l;
}
static public ArrayList asList(float[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (float i : a) l.add(i);
return l;
}
static public ArrayList asList(double[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (double i : a) l.add(i);
return l;
}
static public ArrayList asList(short[] a) {
if (a == null)
return null;
ArrayList l = emptyList(a.length);
for (short i : a) l.add(i);
return l;
}
static public ArrayList asList(Iterator it) {
ArrayList l = new ArrayList();
if (it != null)
while (it.hasNext()) l.add(it.next());
return l;
}
static public ArrayList asList(IterableIterator s) {
return asList((Iterator) s);
}
static public ArrayList asList(Iterable s) {
if (s instanceof ArrayList)
return (ArrayList) s;
ArrayList l = new ArrayList();
if (s != null)
for (A a : s) l.add(a);
return l;
}
static public ArrayList asList(Producer p) {
ArrayList l = new ArrayList();
A a;
if (p != null)
while ((a = p.next()) != null) l.add(a);
return l;
}
static public ArrayList asList(Enumeration e) {
ArrayList l = new ArrayList();
if (e != null)
while (e.hasMoreElements()) l.add(e.nextElement());
return l;
}
static public ArrayList asList(ReverseChain c) {
return c == null ? emptyList() : c.toList();
}
static public List asList(Pair p) {
return p == null ? null : ll(p.a, p.b);
}
static public void setMetaAndVerify(Object o, Object key, Object value) {
setMeta(o, key, value);
assertSame(() -> "setMeta failed (class: " + className(o) + ", key: " + key + ")", value, metaGet(o, key));
}
static public void setMetaAndVerify(IMeta o, Object key, Object value) {
setMeta(o, key, value);
assertSame(() -> "setMeta failed (class: " + className(o) + ", key: " + key + ")", value, metaGet(o, key));
}
static public void swingAndWait(Runnable r) {
try {
if (isAWTThread())
r.run();
else {
r = addThreadInfoToRunnable(r);
executingSwingCode(r);
EventQueue.invokeAndWait(r);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object swingAndWait(Object f) {
if (isAWTThread())
return callF(f);
else {
Var result = new Var();
swingAndWait(new Runnable() {
public void run() {
try {
result.set(callF(f));
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "result.set(callF(f));";
}
});
return result.get();
}
}
static public void _handleError(Error e) {
}
static public A _recordNewSwingComponent(A c) {
if (c != null)
callF((Object) vm_generalMap_get("newSwingComponentRegistry"), (Object) c);
return c;
}
static public JComponent componentToJComponent(Component c) {
if (c instanceof JComponent)
return (JComponent) c;
if (c instanceof JFrame)
return ((JFrame) c).getRootPane();
if (c == null)
return null;
throw fail("boohoo " + getClassName(c));
}
static public JScrollPane jscroll(Component c) {
return swing(() -> {
return c instanceof JScrollPane ? ((JScrollPane) c) : new JScrollPane(c);
});
}
static public JLabel jlabel(final String text) {
return swingConstruct(BetterLabel.class, text);
}
static public JLabel jlabel() {
return jlabel(" ");
}
static public int l(Object[] a) {
return a == null ? 0 : a.length;
}
static public int l(boolean[] a) {
return a == null ? 0 : a.length;
}
static public int l(byte[] a) {
return a == null ? 0 : a.length;
}
static public int l(short[] a) {
return a == null ? 0 : a.length;
}
static public int l(long[] a) {
return a == null ? 0 : a.length;
}
static public int l(int[] a) {
return a == null ? 0 : a.length;
}
static public int l(float[] a) {
return a == null ? 0 : a.length;
}
static public int l(double[] a) {
return a == null ? 0 : a.length;
}
static public int l(char[] a) {
return a == null ? 0 : a.length;
}
static public int l(Collection c) {
return c == null ? 0 : c.size();
}
static public int l(Iterator i) {
return iteratorCount_int_close(i);
}
static public int l(Map m) {
return m == null ? 0 : m.size();
}
static public int l(CharSequence s) {
return s == null ? 0 : s.length();
}
static public long l(File f) {
return f == null ? 0 : f.length();
}
static public int l(MultiSet ms) {
return ms == null ? 0 : ms.size();
}
static public int l(IMultiMap mm) {
return mm == null ? 0 : mm.size();
}
static public int l(IntRange r) {
return r == null ? 0 : r.length();
}
static public int l(IntBuffer b) {
return b == null ? 0 : b.size();
}
static public int l(IntSize o) {
return o == null ? 0 : o.size();
}
static public Field getOpt_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);
return null;
}
static public Field makeAccessible(Field f) {
try {
f.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, f);
}
return f;
}
static public Method makeAccessible(Method m) {
try {
m.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, m);
}
return m;
}
static public Constructor makeAccessible(Constructor c) {
try {
c.setAccessible(true);
} catch (Throwable e) {
vmBus_send("makeAccessible_error", e, c);
}
return c;
}
static public Object getOptDynOnly(DynamicObject o, String field) {
if (o == null || o.fieldValues == null)
return null;
return o.fieldValues.get(field);
}
static public RuntimeException asRuntimeException(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
return t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static public class jLiveValueSection_class extends SingleComponentPanel {
public LiveValue> liveValue;
public String getTitle() {
return strOrEmpty(liveValue.get());
}
public jLiveValueSection_class(LiveValue> lv, Component c) {
super(c);
bindLiveValueListenerToComponent(this, liveValue = lv, new Runnable() {
public void run() {
try {
swingLater(new Runnable() {
public void run() {
try {
setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED), getTitle()));
revalidate();
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "setBorder(BorderFactory.createTitledBorder(\r\n BorderFactory.createBeve...";
}
});
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "swingLater(r {\r\n setBorder(BorderFactory.createTitledBorder(\r\n Bo...";
}
});
}
}
static public JPanel jLiveValueSection(LiveValue> lv, Component c) {
return swingNu(jLiveValueSection_class.class, lv, c);
}
static public JPanel smartAdd(JPanel panel, List parts) {
for (Object o : parts) addToContainer(panel, wrapForSmartAdd(o));
return panel;
}
static public JPanel smartAdd(JPanel panel, Object... parts) {
return smartAdd(panel, asList(parts));
}
static public Map> callF_cache = newDangerousWeakHashMap();
static public A callF(F0 f) {
return f == null ? null : f.get();
}
static public B callF(F1 f, A a) {
return f == null ? null : f.get(a);
}
static public A callF(IF0 f) {
return f == null ? null : f.get();
}
static public B callF(IF1 f, A a) {
return f == null ? null : f.get(a);
}
static public B callF(A a, IF1 f) {
return f == null ? null : f.get(a);
}
static public C callF(F2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
static public C callF(IF2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
static public void callF(VF1 f, A a) {
if (f != null)
f.get(a);
}
static public void callF(A a, IVF1 f) {
if (f != null)
f.get(a);
}
static public void callF(IVF1 f, A a) {
if (f != null)
f.get(a);
}
static public Object callF(Runnable r) {
{
if (r != null)
r.run();
}
return null;
}
static public Object callF(Object f, Object... args) {
return safeCallF(f, args);
}
static public Object safeCallF(Object f, Object... args) {
if (f instanceof Runnable) {
((Runnable) f).run();
return null;
}
if (f == null)
return null;
Class c = f.getClass();
ArrayList methods;
synchronized (callF_cache) {
methods = callF_cache.get(c);
if (methods == null)
methods = callF_makeCache(c);
}
int n = l(methods);
if (n == 0) {
if (f instanceof String)
throw fail("Legacy call: " + f);
throw fail("No get method in " + getClassName(c));
}
if (n == 1)
return invokeMethod(methods.get(0), f, args);
for (int i = 0; i < n; i++) {
Method m = methods.get(i);
if (call_checkArgs(m, args, false))
return invokeMethod(m, f, args);
}
throw fail("No matching get method in " + getClassName(c));
}
static public ArrayList callF_makeCache(Class c) {
ArrayList l = new ArrayList();
Class _c = c;
do {
for (Method m : _c.getDeclaredMethods()) if (m.getName().equals("get")) {
makeAccessible(m);
l.add(m);
}
if (!l.isEmpty())
break;
_c = _c.getSuperclass();
} while (_c != null);
callF_cache.put(c, l);
return l;
}
static public Object callOpt_withVarargs(Object o, String method, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(method, args);
if (me == null) {
return null;
}
if ((me.getModifiers() & Modifier.STATIC) == 0)
return null;
return invokeMethod(me, null, args);
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(method, args);
if (me != null)
return invokeMethod(me, o, args);
List methods = cache.cache.get(method);
if (methods != null)
methodSearch: for (Method m : methods) {
{
if (!(m.isVarArgs()))
continue;
}
Object[] newArgs = massageArgsForVarArgsCall(m, args);
if (newArgs != null)
return invokeMethod(m, o, newArgs);
}
return null;
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object getOpt(Object o, String field) {
return getOpt_cached(o, field);
}
static public Object getOpt(String field, Object o) {
return getOpt_cached(o, field);
}
static public Object getOpt_raw(Object o, String field) {
try {
Field f = getOpt_findField(o.getClass(), field);
if (f == null)
return null;
makeAccessible(f);
return f.get(o);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Object getOpt(Class c, String field) {
try {
if (c == null)
return null;
Field f = getOpt_findStaticField(c, field);
if (f == null)
return null;
makeAccessible(f);
return f.get(null);
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public Field getOpt_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);
return null;
}
static public Class mc() {
return main.class;
}
static public WeakReference weakRef(A a) {
return newWeakReference(a);
}
static public JLabel jImageLabel(Image img) {
return swingNu(JLabel.class, imageIcon(img));
}
static public JLabel jImageLabel(javax.swing.Icon icon) {
return swingNu(JLabel.class, icon);
}
static public JLabel jImageLabel(String imageID) {
return jImageLabel(imageIcon(imageID));
}
static public JLabel jImageLabel(String text, String imageID) {
final JLabel l = swingNu(JLabel.class, text, imageIcon(imageID), JLabel.CENTER);
{
swing(() -> {
l.setVerticalTextPosition(SwingConstants.BOTTOM);
l.setHorizontalTextPosition(SwingConstants.CENTER);
});
}
return l;
}
static public A setHorizontalAlignment(final int pos, final A a) {
swingCall(a, "setHorizontalAlignment", pos);
return a;
}
static public A setHorizontalAlignment(final int pos, final A a) {
swingCall(a, "setHorizontalAlignment", pos);
return a;
}
static public A setHorizontalAlignment(final int pos, final A a) {
swingCall(a, "setHorizontalAlignment", pos);
return a;
}
static public JLabel jLabel(String text) {
return jlabel(text);
}
static public JLabel jLabel() {
return jlabel();
}
static public Component wrapForSmartAdd(Object o) {
if (o == null)
return jpanel();
if (o instanceof String)
return jlabel((String) o);
return wrap(o);
}
static public 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);
}
static public ArrayList emptyList() {
return new ArrayList();
}
static public ArrayList emptyList(int capacity) {
return new ArrayList(max(0, capacity));
}
static public ArrayList emptyList(Iterable l) {
return l instanceof Collection ? emptyList(((Collection) l).size()) : emptyList();
}
static public ArrayList emptyList(Object[] l) {
return emptyList(l(l));
}
static public ArrayList emptyList(Class c) {
return new ArrayList();
}
static public List ll(A... a) {
ArrayList l = new ArrayList(a.length);
if (a != null)
for (A x : a) l.add(x);
return l;
}
static public void setMeta(IMeta o, Object key, Object value) {
metaMapPut(o, key, value);
}
static public void setMeta(Object o, Object key, Object value) {
metaMapPut(o, key, value);
}
static public void assertSame(Object a, Object b) {
assertSame("", a, b);
}
static public void assertSame(String msg, Object a, Object b) {
if (a != b)
throw fail(joinNemptiesWithColon(msg, a + " != " + b + " (" + identityHash(a) + "/" + identityHash(b) + ")"));
}
static public void assertSame(IF0 msg, Object a, Object b) {
if (a != b)
throw fail(joinNemptiesWithColon(msg.get(), a + " != " + b + " (" + identityHash(a) + "/" + identityHash(b) + ")"));
}
static public String className(Object o) {
return getClassName(o);
}
static public Object metaGet(IMeta o, Object key) {
return metaMapGet(o, key);
}
static public Object metaGet(Object o, Object key) {
return metaMapGet(o, key);
}
static public Object metaGet(String key, IMeta o) {
return metaMapGet(o, key);
}
static public Object metaGet(String key, Object o) {
return metaMapGet(o, key);
}
static public boolean isAWTThread() {
if (isAndroid())
return false;
if (isHeadless())
return false;
return isAWTThread_awt();
}
static public boolean isAWTThread_awt() {
return SwingUtilities.isEventDispatchThread();
}
static public Runnable addThreadInfoToRunnable(final Object r) {
final Object info = _threadInfo();
return info == null ? asRunnable(r) : new Runnable() {
public void run() {
try {
_inheritThreadInfo(info);
callF(r);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "_inheritThreadInfo(info); callF(r);";
}
};
}
static transient public Set> onExecutingSwingCode;
public static void onExecutingSwingCode(IVF1 f) {
onExecutingSwingCode = createOrAddToSyncLinkedHashSet(onExecutingSwingCode, f);
}
public static void removeExecutingSwingCodeListener(IVF1 f) {
main.remove(onExecutingSwingCode, f);
}
public static void executingSwingCode(Runnable code) {
if (onExecutingSwingCode != null)
for (var listener : onExecutingSwingCode) pcallF_typed(listener, code);
}
static public Object vm_generalMap_get(Object key) {
return vm_generalMap().get(key);
}
static public RuntimeException fail() {
throw new RuntimeException("fail");
}
static public RuntimeException fail(Throwable e) {
throw asRuntimeException(e);
}
static public RuntimeException fail(Object msg) {
throw new RuntimeException(String.valueOf(msg));
}
static public RuntimeException fail(Object... objects) {
throw new Fail(objects);
}
static public RuntimeException fail(String msg) {
throw new RuntimeException(msg == null ? "" : msg);
}
static public RuntimeException fail(String msg, Throwable innerException) {
throw new RuntimeException(msg, innerException);
}
static public String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
static public A swingConstruct(final Class c, final Object... args) {
return swing(new F0() {
public A get() {
try {
return nuObject(c, args);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "return nuObject(c, args);";
}
});
}
static public int iteratorCount_int_close(Iterator i) {
try {
int n = 0;
if (i != null)
while (i.hasNext()) {
i.next();
++n;
}
if (i instanceof AutoCloseable)
((AutoCloseable) i).close();
return n;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public void vmBus_send(String msg, Object... args) {
Object arg = vmBus_wrapArgs(args);
pcallFAll_minimalExceptionHandling(vm_busListeners_live(), msg, arg);
pcallFAll_minimalExceptionHandling(vm_busListenersByMessage_live().get(msg), msg, arg);
}
static public void vmBus_send(String msg) {
vmBus_send(msg, (Object) null);
}
static public String strOrEmpty(Object o) {
return o == null ? "" : str(o);
}
static public A bindLiveValueListenerToComponent(A component, IHasChangeListeners lv, Runnable listener) {
return bindHasChangeListenersToComponent(component, lv, listener);
}
static public void swingLater(long delay, final Object r) {
javax.swing.Timer timer = new javax.swing.Timer(toInt(delay), actionListener(wrapAsActivity(r)));
timer.setRepeats(false);
timer.start();
}
static public void swingLater(Object r) {
var runnable = toRunnable(r);
executingSwingCode(runnable);
SwingUtilities.invokeLater(runnable);
}
static public A setBorder(Border border, A c) {
if (c != null) {
swing(() -> {
c.setBorder(border);
});
}
return c;
}
static public A setBorder(A c, Border border) {
return setBorder(border, c);
}
static public A revalidate(final A c) {
if (c == null || !c.isShowing())
return c;
{
swing(() -> {
c.revalidate();
c.repaint();
});
}
return c;
}
static public void revalidate(JFrame f) {
revalidate((Component) f);
}
static public void revalidate(JInternalFrame f) {
revalidate((Component) f);
}
static public A swingNu(final Class c, final Object... args) {
return swingConstruct(c, args);
}
static public void addToContainer(Container a, Component... b) {
if (a == null)
return;
{
swing(() -> {
for (Component c : unnullForIteration(b)) if (c != null)
a.add(c);
});
}
}
static public Map newDangerousWeakHashMap() {
return _registerDangerousWeakMap(synchroMap(new WeakHashMap()));
}
static public Map newDangerousWeakHashMap(Object initFunction) {
return _registerDangerousWeakMap(synchroMap(new WeakHashMap()), initFunction);
}
static public Object invokeMethod(Method m, Object o, Object... args) {
try {
try {
return m.invoke(o, args);
} catch (InvocationTargetException e) {
throw rethrow(getExceptionCause(e));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e.getMessage() + " - was calling: " + m + ", args: " + joinWithSpace(classNames(args)));
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public boolean call_checkArgs(Method m, Object[] args, boolean debug) {
Class>[] types = m.getParameterTypes();
if (types.length != l(args)) {
if (debug)
print("Bad parameter length: " + args.length + " vs " + types.length);
return false;
}
for (int i = 0; i < types.length; i++) {
Object arg = args[i];
if (!(arg == null ? !types[i].isPrimitive() : isInstanceX(types[i], arg))) {
if (debug)
print("Bad parameter " + i + ": " + arg + " vs " + types[i]);
return false;
}
}
return true;
}
static final public Map callOpt_cache = newDangerousWeakHashMap();
static public Object callOpt_cached(Object o, String methodName, Object... args) {
try {
if (o == null)
return null;
if (o instanceof Class) {
Class c = (Class) o;
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me == null || (me.getModifiers() & Modifier.STATIC) == 0)
return null;
return invokeMethod(me, null, args);
} else {
Class c = o.getClass();
_MethodCache cache = callOpt_getCache(c);
Method me = cache.findMethod(methodName, args);
if (me == null)
return null;
return invokeMethod(me, o, args);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public _MethodCache callOpt_getCache(Class c) {
_MethodCache cache = callOpt_cache.get(c);
if (cache == null)
callOpt_cache.put(c, cache = new _MethodCache(c));
return cache;
}
static public Object[] massageArgsForVarArgsCall(Executable m, Object[] args) {
Class>[] types = m.getParameterTypes();
int n = types.length - 1, nArgs = l(args);
if (nArgs < n)
return null;
for (int i = 0; i < n; i++) if (!argumentCompatibleWithType(args[i], types[i]))
return null;
Class varArgType = types[n].getComponentType();
for (int i = n; i < nArgs; i++) if (!argumentCompatibleWithType(args[i], varArgType))
return null;
Object[] newArgs = new Object[n + 1];
arraycopy(args, 0, newArgs, 0, n);
int nVarArgs = nArgs - n;
Object varArgs = Array.newInstance(varArgType, nVarArgs);
for (int i = 0; i < nVarArgs; i++) Array.set(varArgs, i, args[n + i]);
newArgs[n] = varArgs;
return newArgs;
}
static public class getOpt_Map extends WeakHashMap {
public getOpt_Map() {
if (getOpt_special == null)
getOpt_special = new HashMap();
clear();
}
public void clear() {
super.clear();
put(Class.class, getOpt_special);
put(String.class, getOpt_special);
}
}
static final public Map> getOpt_cache = _registerDangerousWeakMap(synchroMap(new getOpt_Map()));
static public HashMap getOpt_special;
static public Map getOpt_getFieldMap(Object o) {
Class c = _getClass(o);
HashMap map = getOpt_cache.get(c);
if (map == null)
map = getOpt_makeCache(c);
return map;
}
static public Object getOpt_cached(Object o, String field) {
try {
if (o == null)
return null;
Map map = getOpt_getFieldMap(o);
if (map == getOpt_special) {
if (o instanceof Class)
return getOpt((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
}
Field f = map.get(field);
if (f != null)
return f.get(o);
if (o instanceof DynamicObject)
return syncMapGet2(((DynamicObject) o).fieldValues, field);
return null;
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public HashMap getOpt_makeCache(Class c) {
HashMap map;
if (isSubtypeOf(c, Map.class))
map = getOpt_special;
else {
map = new HashMap();
if (!reflection_classesNotToScan().contains(c.getName())) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields()) {
makeAccessible(f);
String name = f.getName();
if (!map.containsKey(name))
map.put(name, f);
}
_c = _c.getSuperclass();
} while (_c != null);
}
}
if (getOpt_cache != null)
getOpt_cache.put(c, map);
return map;
}
static public WeakReference newWeakReference(A a) {
return a == null ? null : new WeakReference(a);
}
static public int imageIcon_cacheSize = 10;
static public boolean imageIcon_verbose = false;
static public Map imageIcon_cache;
static public Lock imageIcon_lock = lock();
static public ThreadLocal imageIcon_fixGIF = new ThreadLocal();
static public ImageIcon imageIcon(String imageID) {
try {
if (imageID == null)
return null;
Lock __0 = imageIcon_lock;
lock(__0);
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(__0);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public ImageIcon imageIcon(File f) {
try {
return new ImageIcon(f.toURI().toURL());
} catch (Exception __e) {
throw rethrow(__e);
}
}
static public ImageIcon imageIcon(Image img) {
return img == null ? null : new ImageIcon(img);
}
static public ImageIcon imageIcon(RGBImage img) {
return imageIcon(img.getBufferedImage());
}
static public Object swingCall(final Object o, final String method, final Object... args) {
return swing(new F0