p = jmenu_autoMnemonic(dropPrefix(\"[disabled] \", text));\r\n JM...";
}
});
}
public static MenuItem menuItem(String text, final Object r) {
MenuItem mi = new MenuItem(text);
mi.addActionListener(actionListener(r));
return mi;
}
public static Set synchroWeakHashSet() {
return Collections.newSetFromMap((Map) newWeakHashMap());
}
public static boolean containsNewLines(String s) {
return containsNewLine(s);
}
public static String jlabel_textAsHTML_center(String text) {
return "" + replace(htmlencode(text), "\n", "
") + "
";
}
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 JMenuItem disableMenuItem(final JMenuItem mi) {
if (mi != null) {
swing(new Runnable() {
public void run() {
try {
mi.setEnabled(false);
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "mi.setEnabled(false);";
}
});
}
return mi;
}
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 __1091 = holdInstance(instanceToHold);
try {
callF(runnable);
} finally {
_close(__1091);
}
} catch (Exception __e) {
throw rethrow(__e);
}
}
public String toString() {
return "AutoCloseable __1091 = holdInstance(instanceToHold); try {\r\n callF(runna...";
}
});
} catch (Throwable __e) {
messageBox(__e);
}
}
};
}
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 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 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 LineBuffer {
public VF1 onLine;
public StringBuilder currentLine = new StringBuilder();
public LineBuffer() {
}
public LineBuffer(VF1 onLine) {
this.onLine = onLine;
}
public void append(String s) {
append(s, onLine);
}
public void append(String s, VF1 onLine) {
currentLine.append(s);
if (contains(s, '\n')) {
int i = 0, j;
s = str(currentLine);
while ((j = indexOf(s, i, '\n')) >= 0) {
String line = dropTrailingBackslashR(substring(s, i, j));
callF(onLine, line);
i = j + 1;
}
currentLine = new StringBuilder(substring(s, i));
}
}
public int size() {
return l(currentLine);
}
}
public abstract static class LiveValue {
public abstract Class getType();
public abstract A get();
public abstract void onChange(Runnable l);
public abstract void removeOnChangeListener(Runnable l);
public void onChangeAndNow(Runnable l) {
onChange(l);
callF(l);
}
}
public static class RightAlignedLine extends JPanel {
public RightAlignedLine(Component... components) {
setLayout(LetterLayout.rightAlignedRow());
for (Component component : components) add(component);
}
public void add(String text) {
add(new JLabel(text));
}
}
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 static class LetterLayout implements LayoutManager {
public String[] lines;
public Map map = new TreeMap();
public RC[] rows;
public RC[] cols;
public Cell[][] cells;
public int spacingX = 10, spacingY = 10;
public int insetTop, insetBottom, insetLeft, insetRight;
public int template;
public boolean formWideLeftSide, formWideRightSide;
public static final int STALACTITE = 1, LEFT_ALIGNED_ROW = 2, CENTERED_ROW = 3, FORM = 4, RIGHT_ALIGNED_ROW = 5;
public boolean debug;
public void setLeftBorder(int border) {
insetLeft = border;
}
public void setRightBorder(int border) {
insetRight = border;
}
public static JComponent withBorder(JComponent component, int border) {
JPanel panel = new JPanel(new LetterLayout("C").setBorder(border));
panel.add("C", component);
return panel;
}
public static JPanel panel(String... lines) {
return new JPanel(new LetterLayout(lines));
}
public static JPanel stalactitePanel() {
return new JPanel(stalactite());
}
public static class DummyComponent extends JComponent {
}
public static class Cell {
public boolean aux;
public int minWidth, minHeight;
public Component component;
public int colspan, rowspan;
public double weightX, weightY;
}
public static class RC {
public int min;
public double weightSum;
public int start;
public int minEnd;
}
public LetterLayout(int template) {
this.template = template;
}
public LetterLayout(String... lines) {
this.lines = lines;
}
public void removeLayoutComponent(Component component) {
map.values().remove(component);
}
public void layoutContainer(Container container) {
prepareLayout(container);
if (debug)
System.out.println("Container size: " + container.getSize());
Insets insets = getInsets(container);
for (int r = 0; r < rows.length; r++) {
for (int i = 0; i < cols.length; ) {
Cell cell = cells[i][r];
if (cell.aux)
++i;
else {
if (cell.component != null) {
int x1 = cols[i].start;
int y1 = rows[r].start;
int x2 = i + cell.colspan < cols.length ? cols[i + cell.colspan].start - spacingX : container.getWidth() - insets.right;
int y2 = r + cell.rowspan < rows.length ? rows[r + cell.rowspan].start - spacingY : container.getHeight() - insets.bottom;
if (debug)
System.out.println("Layouting (" + i + ", " + r + ", " + cell.component.getClass().getName() + "): " + x1 + " " + y1 + " " + x2 + " " + y2);
cell.component.setBounds(x1, y1, x2 - x1, y2 - y1);
}
i += cells[i][r].colspan;
}
}
}
}
public final void prepareLayout(Container container) {
applyTemplate(container);
int numRows = lines.length, numCols = lines[0].length();
for (int i = 1; i < numRows; i++) if (lines[i].length() != numCols)
throw new IllegalArgumentException("Lines have varying length");
cells = new Cell[numCols][numRows];
rows = new RC[numRows];
cols = new RC[numCols];
for (int r = 0; r < numRows; r++) rows[r] = new RC();
for (int i = 0; i < numCols; i++) cols[i] = new RC();
for (int r = 0; r < numRows; r++) for (int i = 0; i < numCols; i++) cells[i][r] = new Cell();
for (int r = 0; r < numRows; r++) {
String line = lines[r];
for (int i = 0; i < numCols; ) {
Cell cell = cells[i][r];
if (cell.aux) {
++i;
continue;
}
char ch = line.charAt(i);
int iNext = i;
do ++iNext; while (iNext < numCols && ch == line.charAt(iNext));
int rNext = r;
do ++rNext; while (rNext < numRows && ch == lines[rNext].charAt(i));
cell.weightX = numCols == 1 || iNext > i + 1 ? 1.0 : 0.0;
cell.weightY = numRows == 1 || rNext > r + 1 ? 1.0 : 0.0;
Component c = map.get(String.valueOf(ch));
cell.component = c;
if (c != null) {
cell.minWidth = c.getMinimumSize().width + spacingX;
cell.minHeight = getMinimumHeight(c) + spacingY;
}
cell.colspan = iNext - i;
cell.rowspan = rNext - r;
if (cell.colspan == 1)
cols[i].min = Math.max(cols[i].min, cell.minWidth);
if (cell.rowspan == 1)
rows[r].min = Math.max(rows[r].min, cell.minHeight);
for (int r2 = r; r2 < rNext; r2++) for (int i2 = i; i2 < iNext; i2++) if (r2 != r || i2 != i)
cells[i2][r2].aux = true;
i = iNext;
}
}
while (true) {
for (int i = 0; i < numCols; i++) {
int minStart = i == 0 ? 0 : cols[i - 1].minEnd;
double weightStart = i == 0 ? 0.0 : cols[i - 1].weightSum;
for (int r = 0; r < numRows; r++) {
Cell cell = cells[i][r];
if (!cell.aux) {
RC rc = cols[i + cell.colspan - 1];
rc.minEnd = Math.max(rc.minEnd, minStart + cell.minWidth);
rc.weightSum = Math.max(rc.weightSum, weightStart + cell.weightX);
}
}
}
for (int r = 0; r < numRows; r++) {
int minStart = r == 0 ? 0 : rows[r - 1].minEnd;
double weightStart = r == 0 ? 0.0 : rows[r - 1].weightSum;
for (int i = 0; i < numCols; i++) {
Cell cell = cells[i][r];
if (!cell.aux) {
RC rc = rows[r + cell.rowspan - 1];
rc.minEnd = Math.max(rc.minEnd, minStart + cell.minHeight);
rc.weightSum = Math.max(rc.weightSum, weightStart + cell.weightY);
}
}
}
if (allWeightsZero(cols)) {
for (int r = 0; r < numRows; r++) for (int i = 0; i < numCols; i++) cells[i][r].weightX = 1.0;
continue;
}
if (allWeightsZero(rows)) {
for (int r = 0; r < numRows; r++) for (int i = 0; i < numCols; i++) cells[i][r].weightY = 1.0;
continue;
}
break;
}
Insets insets = getInsets(container);
determineStarts(cols, insets.left, container.getWidth() - insets.left - insets.right + spacingX, spacingX);
determineStarts(rows, insets.top, container.getHeight() - insets.top - insets.bottom + spacingY, spacingY);
}
public final boolean allWeightsZero(RC[] rcs) {
for (int i = 0; i < rcs.length; i++) if (rcs[i].weightSum != 0.0)
return false;
return true;
}
public static int getMinimumHeight(Component c) {
return c.getMinimumSize().height;
}
public final void applyTemplate(Container container) {
if (template == STALACTITE) {
Component[] components = container.getComponents();
lines = new String[components.length + 2];
map.clear();
for (int i = 0; i < components.length; i++) {
String s = String.valueOf(makeIndexChar(i));
map.put(s, components[i]);
lines[i] = s;
}
lines[components.length] = lines[components.length + 1] = " ";
} else if (template == FORM) {
Component[] components = container.getComponents();
int numRows = components.length / 2;
lines = new String[numRows + 2];
map.clear();
for (int row = 0; row < numRows; row++) {
String lower = String.valueOf(makeIndexChar(row));
String upper = String.valueOf(makeAlternateIndexChar(row));
Component rightComponent = components[row * 2 + 1];
if (rightComponent instanceof DummyComponent)
upper = lower;
lines[row] = (formWideLeftSide ? lower + lower : lower) + (formWideRightSide ? upper + upper : upper);
map.put(lower, components[row * 2]);
if (!(rightComponent instanceof DummyComponent))
map.put(upper, rightComponent);
}
lines[numRows] = lines[numRows + 1] = (formWideLeftSide ? " " : " ") + (formWideRightSide ? " " : " ");
} else if (template == LEFT_ALIGNED_ROW) {
lines = new String[] { makeSingleRow(container) + RIGHT_CHAR + RIGHT_CHAR };
} else if (template == CENTERED_ROW) {
lines = new String[] { "" + LEFT_CHAR + LEFT_CHAR + makeSingleRow(container) + RIGHT_CHAR + RIGHT_CHAR };
} else if (template == RIGHT_ALIGNED_ROW) {
lines = new String[] { "" + LEFT_CHAR + LEFT_CHAR + makeSingleRow(container) };
}
}
public final String makeSingleRow(Container container) {
Component[] components = container.getComponents();
StringBuffer buf = new StringBuffer();
map.clear();
for (int i = 0; i < components.length; i++) {
String s = String.valueOf(makeAlternateIndexChar(i));
map.put(s, components[i]);
buf.append(s);
}
return buf.toString();
}
public static void determineStarts(RC[] rcs, int start, int totalSize, int spacing) {
int minTotal = rcs[rcs.length - 1].minEnd;
double weightSum = rcs[rcs.length - 1].weightSum;
int spare = (int) ((totalSize - minTotal) / (weightSum == 0.0 ? 1.0 : weightSum));
int x = start, minSum = 0;
double prevWeightSum = 0.0;
for (int i = 0; i < rcs.length; i++) {
int width = rcs[i].minEnd - minSum + (int) ((rcs[i].weightSum - prevWeightSum) * spare) - spacing;
rcs[i].start = x;
x += width + spacing;
prevWeightSum = rcs[i].weightSum;
minSum = rcs[i].minEnd;
}
}
public void addLayoutComponent(String s, Component component) {
map.put(s, component);
}
public Dimension minimumLayoutSize(Container container) {
prepareLayout(container);
Insets insets = getInsets(container);
Dimension result = new Dimension(insets.left + cols[cols.length - 1].minEnd + insets.right - spacingX, insets.top + rows[rows.length - 1].minEnd + insets.bottom - spacingY);
return result;
}
public final Insets getInsets(Container container) {
Insets insets = container.getInsets();
return new Insets(insets.top + insetTop, insets.left + insetLeft, insets.bottom + insetBottom, insets.right + insetRight);
}
public Dimension preferredLayoutSize(Container container) {
return minimumLayoutSize(container);
}
public LetterLayout setSpacing(int x, int y) {
spacingX = x;
spacingY = y;
return this;
}
public LetterLayout setSpacing(int spacing) {
return setSpacing(spacing, spacing);
}
public LetterLayout setBorder(int top, int left, int bottom, int right) {
insetTop = top;
insetLeft = left;
insetBottom = bottom;
insetRight = right;
return this;
}
public LetterLayout setBorder(int inset) {
return setBorder(inset, inset, inset, inset);
}
public LetterLayout setTopBorder(int inset) {
insetTop = inset;
return this;
}
public static LetterLayout stalactite() {
return new LetterLayout(STALACTITE);
}
public static LetterLayout leftAlignedRow() {
return new LetterLayout(LEFT_ALIGNED_ROW);
}
public static LetterLayout leftAlignedRow(int spacing) {
return leftAlignedRow().setSpacing(spacing);
}
public static LetterLayout centeredRow() {
return new LetterLayout(CENTERED_ROW);
}
public static LetterLayout rightAlignedRow() {
return new LetterLayout(RIGHT_ALIGNED_ROW);
}
public static JPanel rightAlignedRowPanel(JComponent... components) {
return makePanel(new LetterLayout(RIGHT_ALIGNED_ROW), components);
}
public static JPanel makePanel(LetterLayout letterLayout, JComponent[] components) {
JPanel panel = new JPanel(letterLayout);
for (JComponent component : components) {
panel.add(component);
}
return panel;
}
public static LetterLayout form() {
LetterLayout letterLayout = new LetterLayout(FORM);
letterLayout.formWideLeftSide = true;
letterLayout.formWideRightSide = true;
return letterLayout;
}
public static LetterLayout formWideRightSide() {
LetterLayout letterLayout = new LetterLayout(FORM);
letterLayout.formWideRightSide = true;
return letterLayout;
}
public static Component getDummyComponent() {
return new DummyComponent();
}
public static JPanel newPanel(String... lines) {
return new JPanel(new LetterLayout(lines));
}
public boolean isDebug() {
return debug;
}
public void setDebug(boolean debug) {
this.debug = debug;
}
public static char makeIndexChar(int idx) {
return (char) ('a' + idx * 2);
}
public static char makeAlternateIndexChar(int idx) {
return (char) ('b' + idx * 2);
}
public static char LEFT_CHAR = ',', RIGHT_CHAR = '.';
public static void main(String[] args) {
System.out.println((int) makeIndexChar(0));
System.out.println((int) makeAlternateIndexChar(0));
System.out.println((int) makeIndexChar(32000));
System.out.println((int) makeAlternateIndexChar(32000));
System.out.println((int) LEFT_CHAR);
System.out.println((int) RIGHT_CHAR);
}
}
public static String dropTrailingBackslashR(String s) {
int i = l(s);
while (i > 0 && s.charAt(i - 1) == '\r') --i;
return substring(s, 0, i);
}
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 hashCodeFor(Object a) {
return a == null ? 0 : a.hashCode();
}
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);";
}
});
}
}
}