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 javax.swing.border.*;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.awt.geom.*;
import java.text.SimpleDateFormat;
import java.nio.charset.Charset;
import static x30_pkg.x30_util.DynamicObject;
import javax.swing.Icon;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import javax.swing.event.AncestorListener;
import javax.swing.event.AncestorEvent;
import javax.swing.Timer;
import javax.swing.undo.UndoManager;
import java.text.NumberFormat;
import java.awt.datatransfer.UnsupportedFlavorException;
class main {
static void test_imageSurfaceRevalidationInFullCenter() {
ImageSurface imageSurface = imageSurface();
imageSurface.setImage(whiteImage(50, 50));
imageSurface.verbose(true);
enableScaffolding(imageSurface);
showFrame(jMinSize(500, 500, jscroll_borderless(setBackground(Color.gray, jFullCenter(imageSurface)))));
sleepSeconds(1);
var parent = getParent(imageSurface);
print("Parent layout: " + parent.getLayout());
print("Parent: " + parent);
assertEqualsVerbose("Image surface size (base line)", new Dimension(50, 50), jGetSize(imageSurface));
imageSurface.setImage(whiteImage(100, 100));
sleepSeconds(1);
assertEqualsVerbose("Image surface size after image change", new Dimension(100, 100), jGetSize(imageSurface));
}
static ImageSurface imageSurface(BufferedImage img) {
return swingNu(ImageSurface.class, img);
}
static ImageSurface imageSurface(MakesBufferedImage img) {
return swingNu(ImageSurface.class, img);
}
static ImageSurface imageSurface() {
return swingNu(ImageSurface.class);
}
static BufferedImage whiteImage(int w, int h) {
return newBufferedImage(w, h, Color.white);
}
static BufferedImage whiteImage(int size) {
return whiteImage(size, size);
}
static BufferedImage whiteImage(WidthAndHeight size) {
return whiteImage(size.getWidth(), size.getHeight());
}
static A enableScaffolding(A o) {
if (o instanceof IMeta) ((IMeta) o).metaPut("scaffolding", true);
return o;
}
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 f) {
if (f != null) { swing(() -> {
if (frameTooSmall(f)) frameStandardSize(f);
if (!f.isVisible()) f.setVisible(true); // XXX
if (f.getState() == Frame.ICONIFIED) f.setState(Frame.NORMAL);
}); }
return f;
}
// 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 A jMinSize(int w, int h, A c) {
return jMinWidth(w, jMinHeight(h, c));
}
static A jMinSize(A c, Dimension d) {
return jMinSize(d.width, d.height, c);
}
static JScrollPane jscroll_borderless(Component c) {
return borderlessScrollPane(jscroll(c));
}
static A setBackground(final Color color, final A a) {
if (a != null) { swing(() -> { a.setBackground(color); }); }
return a;
}
static A setBackground(A a, Color color) {
return setBackground(color, a);
}
static JPanel jFullCenter(final Component c) {
return swing(new F0() { public JPanel get() { try {
JPanel panel = new JPanel(new GridBagLayout());
panel.add(c);
return panel;
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "JPanel panel = new JPanel(new GridBagLayout);\r\n panel.add(c);\r\n ret panel;"; }});
}
static void sleepSeconds(double s) {
if (s > 0) sleep(round(s*1000));
}
static Container getParent(final Component c) {
return c == null ? null : swing(new F0() { public Container get() { try { return c.getParent(); } catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "return c.getParent();"; }});
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static boolean printAlsoToSystemOut = true;
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal