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 java.awt.datatransfer.StringSelection;
import javax.imageio.metadata.*;
import javax.imageio.stream.*;
import java.text.SimpleDateFormat;
import java.nio.charset.Charset;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import static x30_pkg.x30_util.DynamicObject;
import javax.swing.Icon;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
import java.awt.geom.*;
class main {
static class JFilePathButton implements Swingable , IFieldsToList{
File file;
JFilePathButton() {}
JFilePathButton(File file) {
this.file = file;}
public String toString() { return shortClassName_dropNumberPrefix(this) + "(" + file + ")"; }public Object[] _fieldsToList() { return new Object[] {file}; }
transient JButton button;
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()); }
JComponent visualize_impl() {
if (button == null) {
button = jimageButtonScaledToWidth(16, "#1101292", "", () -> showInExplorer());
componentPopupMenuItem(button, "Copy path", () -> copyToClipboard(f2s(file)));
}
updateToolTip();
return button;
}
void showInExplorer() {
{ startThread(new Runnable() { public void run() { try { File dirToShow = isFile(file) ? dirOfFile(file) : file;
//startPlatformFileManager(dirToShow);
desktopOpen(dirToShow);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "File dirToShow = isFile(file) ? dirOfFile(file) : file;\r\n //startPlatfor..."; }}); }
}
void setFile(File file) {
this.file = file;
updateToolTip();
}
void updateToolTip() {
setEnabled(button, file != null);
toolTip(file == null ? "No file" : f2s(file) + " [click to show in file explorer]", button);
}
}
static String shortClassName_dropNumberPrefix(Object o) {
return dropNumberPrefix(shortClassName(o));
}
static A markVisualizer(Object visualizer, A a) {
return setMetaSrc(a, visualizer);
}
static JButton jimageButtonScaledToWidth(int w, String imageID, Runnable action) { return jimageButtonScaledToWidth(w, imageID, "", action); }
static JButton jimageButtonScaledToWidth(int w, String imageID, String toolTip, Runnable action) {
return jimageButton(scaleImageToWidth(w, imageID), toolTip, action);
}
static A componentPopupMenuItem(A c, final String name, final Object action) {
componentPopupMenu(c, new VF1() { public void get(JPopupMenu menu) { try {
addMenuItem(menu, name, action);
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "addMenuItem(menu, name, action);"; }});
return c;
}
static void componentPopupMenuItem(JComponent c, final JMenuItem menuItem) {
componentPopupMenu(c, new VF1() { public void get(JPopupMenu menu) { try {
addMenuItem(menu, menuItem);
} catch (Exception __e) { throw rethrow(__e); } }
public String toString() { return "addMenuItem(menu, menuItem);"; }});
}
static String copyToClipboard(String text) {
return copyTextToClipboard(text);
}
static A copyToClipboard(A image) {
copyImageToClipboard(image);
return image;
}
static File copyToClipboard(File f) {
return copyFileToClipboard(f);
}
static String f2s(File f) {
return f == null ? null : f.getAbsolutePath();
}
static String f2s(String s) { return f2s(newFile(s)); }
static String f2s(java.nio.file.Path p) {
return p == null ? null : f2s(p.toFile());
}
static Thread startThread(Object runnable) {
return startThread(defaultThreadName(), runnable);
}
static Thread startThread(String name, Runnable runnable) {
runnable = wrapAsActivity(runnable);
return startThread(newThread(runnable, name));
}
static Thread startThread(String name, Object runnable) {
runnable = wrapAsActivity(runnable);
return startThread(newThread(toRunnable(runnable), name));
}
static Thread startThread(Thread t) {
_registerThread(t);
t.start();
return t;
}
static boolean isFile(File f) {
return f != null && f.isFile();
}
static boolean isFile(String path) {
return isFile(newFile(path));
}
static File dirOfFile(File f) {
return f == null ? null : f.getParentFile();
}
static void desktopOpen(File f) { try {
if (f != null) {
print("desktopOpen: " + f2s(f));
Desktop.getDesktop().open(f);
}
} catch (Exception __e) { throw rethrow(__e); } }
static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
static A setEnabled(A c, boolean enable) {
if (c != null) { swing(() -> { c.setEnabled(enable); }); }
return c;
}
static A setEnabled(boolean enable, A c) {
return setEnabled(c, enable);
}
static void setEnabled(boolean enable, JComponent... l) {
for (var c : unnullForIteration(l))
setEnabled(c, enable);
}
static A toolTip(A c, final Object toolTip) {
return setToolTipText(c, toolTip);
}
static A toolTip(Object toolTip, A c) {
return setToolTipText(toolTip, c);
}
static String dropNumberPrefix(String s) {
return dropFirst(s, indexOfNonDigit(s));
}
static String shortClassName(Object o) {
if (o == null) return null;
Class c = o instanceof Class ? (Class) o : o.getClass();
String name = c.getName();
return shortenClassName(name);
}
static A setMetaSrc(A a, Object src) {
setMetaAndVerify(a, "src", src);
return a;
}
static A setMetaSrc(A a, Object src) {
setMetaAndVerify(a, "src", src);
return a;
}
static JButton jimageButton(String imageID, Object action) {
JButton btn = jbutton("", action);
btn.setIcon(imageIcon(imageID));
return btn;
}
// button without action
static JButton jimageButton(String imageID) {
return jimageButton(imageID, null);
}
static JButton jimageButton(Image img) {
return jimageButton(img, null, null);
}
static JButton jimageButton(String imageID, String toolTip, Runnable action) {
return jimageButton(imageIcon(imageID), toolTip, action);
}
static JButton jimageButton(Image img, String toolTip, Runnable action) {
var btn = jbutton("", action);
setButtonImage(btn, img);
return setToolTip(toolTip, btn);
}
static JButton jimageButton(ImageIcon img, String toolTip, Runnable action) {
var btn = jbutton("", action);
setButtonImage(btn, img);
return setToolTip(toolTip, btn);
}
static BufferedImage scaleImageToWidth(BufferedImage img, int newW) {
return resizeImage(img, newW);
}
static BufferedImage scaleImageToWidth(int newW, BufferedImage img) {
return scaleImageToWidth(img, newW);
}
static BufferedImage scaleImageToWidth(int newW, String imageID) {
return scaleImageToWidth(newW, loadImage2(imageID));
}
static ThreadLocal componentPopupMenu_mouseEvent;
static void componentPopupMenu_init() {
{ swing(() -> {
if (componentPopupMenu_mouseEvent == null)
componentPopupMenu_mouseEvent = (ThreadLocal) vm_generalMap_get("mouseEvent");
if (componentPopupMenu_mouseEvent == null)
vm_generalMap_put("componentPopupMenu_mouseEvent" , componentPopupMenu_mouseEvent = new ThreadLocal());
}); }
}
static void componentPopupMenu(final JComponent component, IVF1 menuMaker) {
componentPopupMenu(component, (Object) menuMaker);
}
// menuMaker = voidfunc(JPopupMenu)
static void componentPopupMenu(final JComponent component, final Object menuMaker) {
if (component == null || menuMaker == null) return;
{ swing(() -> {
Object adapter = componentPopupMenu_initForComponent(component);
((List) _get(adapter, "maker")).add(menuMaker);
}); }
}
static Object componentPopupMenu_initForComponent(final JComponent component) {
return component == null ? null : swing(new F0