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 java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import org.pushingpixels.substance.api.*;
import org.pushingpixels.substance.api.skin.*;
public class main {
public static void main(final String[] args) throws Exception { { swingAndWait(new Runnable() { public void run() { try { substance();
JTable table = sexyTable();
showFrame(tableWithSearcher(table));
printComponentTree(getFrame(table));
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); } } public String toString() { return "substance();\n JTable table = sexyTable();\n showFrame(tableWithSearcher(table));\n printComponentTree(getFrame(table));"; }}); }}
static JTable sexyTable() {
final JTable table = tableWithToolTips();
tablePopupMenu(table, new Object() { void get(JPopupMenu menu, final int row) { try {
final String item = first(getTableLine(table, row));
MouseEvent e = tablePopupMenu_mouseEvent.get();
final int col = table.columnAtPoint(e.getPoint());
final Object value = table.getModel().getValueAt(row, col);
//print("Cell type: " + getClassName(value));
if (value instanceof ImageIcon) {
addMenuItem(menu, "Copy image to clipboard", new Runnable() { public void run() { try {
copyImageToClipboard(((ImageIcon) value).getImage());
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); } } public String toString() { return "copyImageToClipboard(((ImageIcon) value).getImage());"; }});
} else {
final String text = str(value);
addMenuItem(menu, "Copy text to clipboard", new Runnable() { public void run() { try {
copyTextToClipboard(text);
print("Copied text to clipboard: " + quote(text));
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); } } public String toString() { return "copyTextToClipboard(text);\r\n print(\"Copied text to clipboard: \" + quote(text));"; }});
}
addMenuItem(menu, "Set row height...", new Runnable() { public void run() { try {
final JTextField tf = jTextField(table.getRowHeight());
showTitledForm("Set row height",
"Pixels", tf, new Runnable() { public void run() { try {
table.setRowHeight(parseInt(trim(tf.getText())))
;
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); } } public String toString() { return "table.setRowHeight(parseInt(trim(tf.getText())))"; }});
} catch (Exception __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); } } public String toString() { return "final JTextField tf = jTextField(table.getRowHeight());\r\n showTitledForm(\"Set row height\",\r\n \"Pixels\", tf, r {\r\n table.setRowHeight(parseInt(trim(tf.getText())))\r\n });"; }});
} catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}
public String toString() { return "final S item = first(getTableLine(table, row));\r\n MouseEvent e = tablePopupMenu_mouseEvent.get();\r\n final int col = table.columnAtPoint(e.getPoint());\r\n final O value = table.getModel().getValueAt(row, col);\r\n //print(\"Cell type: \" + getClassName(value));\r\n\r\n if (value instanceof ImageIcon) {\r\n addMenuItem(menu, \"Copy image to clipboard\", r {\r\n copyImageToClipboard(((ImageIcon) value).getImage());\r\n });\r\n } else {\r\n final S text = str(value);\r\n addMenuItem(menu, \"Copy text to clipboard\", r {\r\n copyTextToClipboard(text);\r\n print(\"Copied text to clipboard: \" + quote(text));\r\n });\r\n }\r\n \r\n addMenuItem(menu, \"Set row height...\", r {\r\n final JTextField tf = jTextField(table.getRowHeight());\r\n showTitledForm(\"Set row height\",\r\n \"Pixels\", tf, r {\r\n table.setRowHeight(parseInt(trim(tf.getText())))\r\n });\r\n });"; }});
// Disable Ctrl+PageUp and Ctrl+PageDown
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
//table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, InputEvent.CTRL_MASK), "none");
/*table.registerKeyboardAction(
null,
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
);*/
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
table.getInputMap(JComponent.WHEN_FOCUSED)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
((InputMap) UIManager.get("Table.ancestorInputMap")).put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.CTRL_MASK), "none");
return table;
}
static void printComponentTree(String indent, Component c) {
print(indent + c);
if (c instanceof Container)
for (Component comp : ((Container) c).getComponents())
printComponentTree(indent + " ", comp);
}
static void printComponentTree(Component c) {
printComponentTree("", c);
}
static JFrame getFrame(Object o) {
if (o instanceof ButtonGroup) o = first(buttonsInGroup((ButtonGroup) o));
if (!(o instanceof Component)) return null;
Component c = (Component) o;
while (c != null) {
if (c instanceof JFrame) return (JFrame) c;
c = c.getParent();
}
return null;
}
static JComponent tableWithSearcher(final JTable t) {
final JTextField input = new JTextField();
onUpdate(input, new Runnable() {
List lastFiltered, lastOriginal;
public void run() {
String pat = trim(input.getText());
List