public class Utils extends Object implements ij.plugin.PlugIn
Modifier and Type | Field and Description |
---|---|
static boolean |
debug |
static boolean |
debug_clip |
static boolean |
debug_event |
static boolean |
debug_mouse |
static boolean |
debug_sql |
static boolean |
debug_thing |
static double |
FL_ERROR
The error to use in floating-point or double floating point literal comparisons.
|
static boolean |
java3d |
static String |
last_dir
The path of the directory from which images have been recently loaded.
|
static String |
last_file
The path of the last opened file.
|
static String |
version |
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static void |
addEnablerListener(Checkbox master,
Component[] enable,
Component[] disable)
A helper for GenericDialog checkboxes to control other the enabled state of other GUI elements in the same dialog.
|
static void |
addLayerChoice(String label,
Layer selected,
GenericDialog gd) |
static void |
addLayerRangeChoices(Layer selected,
GenericDialog gd) |
static void |
addLayerRangeChoices(Layer first,
Layer last,
GenericDialog gd) |
static boolean |
addPlugIns(JPopupMenu popup,
String menu,
Project project,
Callable<Displayable> active)
Returns false if none to add.
|
static JMenu |
addPlugIns(String menu,
Project project,
Callable<Displayable> active)
Returns null if none to add.
|
static void |
addRGBColorSliders(GenericDialog gd,
Color color) |
static String |
asHexRGBColor(Color color) |
static void |
asHexRGBColor(StringBuilder sb,
Color color) |
static List<Long> |
asList(long[] ids) |
static List<Long> |
asList(long[] ids,
int first,
int length) |
static String |
caller(Object called)
Returns a String representation of the class of the object one step before in the stack trace.
|
static <A,B> ArrayList<B> |
castCollection(Collection<A> classAs,
Class<B> type,
boolean doThrow) |
static boolean |
check(String msg) |
static boolean |
checkYN(String msg) |
static File |
chooseFile(String name,
String extension) |
static File |
chooseFile(String default_dir,
String name,
String extension)
Select a file from the file system, for saving purposes.
|
static String |
cleanString(String s)
Converts sequences of spaces into single space, and trims the ends.
|
static ij.process.ImageProcessor |
convertTo(ij.process.ImageProcessor ip,
int type,
boolean scaling)
Converts the ImageProcessor to an ImageProcessor of the given type, or the same if of equal type.
|
static BufferedImage |
convertToBufferedImage(ij.process.ByteProcessor bp) |
static double[] |
copy(double[] a,
int new_length)
Will make a new double[] array, then fit in it as many points from the given array as possible according to the desired new length.
|
static double[] |
copy(double[] a,
int first,
int new_length) |
static long[] |
copy(long[] a,
int new_length) |
static long[] |
copy(long[] a,
int first,
int new_length) |
static ij.process.ImageProcessor |
createProcessor(int type,
int width,
int height) |
static ij.measure.ResultsTable |
createResultsTable(String title,
String[] columns)
Creates a new ResultsTable with the given window title and column titles, and 2 decimals of precision, or if one exists for the given window title, returns it.
|
static InputStream |
createStream(String path_or_url) |
static String |
cutNumber(double d,
int n_decimals) |
static String |
cutNumber(double d,
int n_decimals,
boolean remove_trailing_zeros)
remove_trailing_zeros will leave at least one zero after the comma if appropriate.
|
static String |
d2s(double d,
int n_decimals) |
static void |
debug(String msg) |
static void |
debugDialog() |
static void |
debugMouse(String msg) |
static void |
destroy(ControlWindow master)
Destroy house keeping threads.
|
static void |
drawPoint(Graphics g,
int x,
int y) |
static boolean |
ensure(File f)
Ensure the file can be written to.
|
static boolean |
ensure(String filepath) |
static boolean |
equalContent(Collection<?> a,
Collection<?> b)
If both are null will throw an error.
|
static boolean |
equalContent(Map<?,?> a,
Map<?,?> b)
If both are null will throw an error.
|
static ij.process.FloatProcessor |
fastConvertToFloat(ij.process.ByteProcessor ip)
A method that circumvents the findMinAndMax when creating a float processor from an existing processor.
|
static ij.process.FloatProcessor |
fastConvertToFloat(ij.process.ImageProcessor ip) |
static ij.process.FloatProcessor |
fastConvertToFloat(ij.process.ImageProcessor ip,
int type)
A method that circumvents the findMinAndMax when creating a float processor from an existing processor.
|
static ij.process.FloatProcessor |
fastConvertToFloat(ij.process.ShortProcessor ip)
A method that circumvents the findMinAndMax when creating a float processor from an existing processor.
|
static ij.ImagePlus[] |
findAllOpenImages()
Scan the WindowManager for all open images, including stacks.
|
static ij.ImagePlus[] |
findOpenImages()
Scan the WindowManager for non-stack images
|
static ij.ImagePlus[] |
findOpenStacks()
Scan the WindowManager for open stacks.
|
static IndexColorModel |
fireLUT()
Returns a byte[3][256] containing the colors of the fire LUT.
|
static String |
fixDir(String path)
Convert a D:\\this\that\there to D://this/that/there/
Notice it adds an ending backslash.
|
static int[] |
get4Ints(int hex) |
static String |
getCharacter(int i)
1 A, 2 B, 3 C --- 26 - z, 27 AA, 28 AB, 29 AC --- 26*27 AAA
|
static int |
getControlModifier()
The CTRL key functionality is passed over to the COMMAND key (aka META key) in a MacOSX.
|
static double |
getCos(double x1,
double y1,
double x2,
double y2)
The cosinus between two vectors (in polar coordinates), by means of the dot product.
|
static Dimension |
getDimensions(String text,
Font font)
Get the width and height of single-line text.
|
static Object |
getField(Object ob,
Class<?> c,
String field_name)
Get by reflection a private or protected field in the given object.
|
static Object |
getField(Object ob,
String field_name) |
static String[] |
getHexRGBColor(Color color) |
static PrintStream |
getLogStream() |
static Color |
getRGBColorFromHex(String hex) |
static int |
indexOf(Object needle,
Object[] haystack) |
static void |
invokeLater(Runnable r)
Invoke in the context of the event dispatch thread.
|
static boolean |
isControlDown(InputEvent e)
The CTRL key functionality is passed over to the COMMAND key (aka META key) in a MacOSX.
|
static boolean |
isPopupTrigger(MouseEvent me)
OS-agnostic diagnosis of whether the click was for the contextual popup menu.
|
static boolean |
isTrakEM2Subfile(File f)
Returns true if the file cannonical path contains "/trakem2." (adjusted for Windows as well).
|
static boolean |
isTrakEM2Subpath(String path)
Returns true if the path contains "/trakem2." (adjusted for Windows as well).
|
static boolean |
isValidIdentifier(String s) |
static Bureaucrat |
launchTPlugIn(KeyEvent ke,
String menu,
Project project,
Displayable active)
Returns null if no plugin was launched.
|
static void |
log(Object ob) |
static void |
log(String msg)
Intended for the user to see.
|
static void |
log(String msg,
Object ob)
Pretty-print the object, for example arrays as [0, 1, 2].
|
static void |
log2(Object... ob) |
static void |
log2(Object ob)
Pretty-print the object, for example arrays as [0, 1, 2].
|
static void |
log2(String msg)
Intended for developers: prints to terminal.
|
static void |
log2(String msg,
Object ob)
Pretty-print the object, for example arrays as [0, 1, 2].
|
static void |
log2(String msg,
Object ob1,
Object... ob) |
static void |
logAll(String msg)
Print in all printable places: log window, System.out.println, and status bar.
|
static void |
logMany2(Object... ob) |
static void |
logStamped(String msg)
Intended for the user to see; time-stamps every logging line.
|
static int |
luminance(Color c)
0.3 * R + 0.6 * G + 0.1 * B
|
static String |
makeValidIdentifier(String s)
user=> (def pat #"\b[a-zA-Z]+[\w]*\b")
#'user/pat
user=>(re-seq pat "abc def 1a334")
("abc" "def")
user=> (re-seq pat "abc def a334")
("abc" "def" "a334")
|
static boolean |
matches(String pattern,
String s) |
static Color |
mix(Color c1,
Color c2)
Mix colors visually: red + green = yellow, etc.
|
static ThreadPoolExecutor |
newFixedThreadPool(int n_proc)
Creates a new fixed thread pool whose threads are in the same ThreadGroup as the Thread that calls this method.
|
static ThreadPoolExecutor |
newFixedThreadPool(int n_proc,
String namePrefix) |
static ThreadPoolExecutor |
newFixedThreadPool(int n_proc,
String namePrefix,
boolean use_caching_thread) |
static ThreadPoolExecutor |
newFixedThreadPool(String namePrefix)
Creates a new fixed thread pool with as many threads as CPUs, and whose threads are in the same ThreadGroup as the Thread that calls this method.
|
static String |
now()
Returns the time as HH:MM:SS
|
static String |
openTextFile(String path) |
static char[] |
openTextFileChars(String path) |
static String[] |
openTextFileLines(String path)
Returns the file found at path as an array of lines, or null if not found.
|
static void |
paint(Pipe pipe,
Map<Layer,ij.process.ImageProcessor> slices,
int value,
float scale)
Paints an approximation of the pipe into the set of slices.
|
static void |
printCaller(Object called_object)
Find out which method from which class called the method where the printCaller is used; for debugging purposes.
|
static void |
printCaller(Object called_object,
int lines) |
static String |
removeExtension(String path) |
static boolean |
removeFile(File f)
Remove the file, or if it's a directory, recursively go down subdirs and remove all contents, but will stop on encountering a non-hidden file that is not an empty dir.
|
static boolean |
removePrefixedFiles(File parent,
String prefix,
ArrayList<String> removed_paths)
Returns true if all files and their subdirectories, recursively, under parent folder have been removed.
|
static void |
restoreMenuBar()
Restore ImageJ's MenuBar
|
static void |
revalidateComponent(Component c)
Like calling pack() on a Frame but on a Component.
|
static void |
reverse(double[] a)
Reverse in place an array of doubles.
|
static void |
reverse(long[] a)
Reverse in place an array of longs.
|
void |
run(String arg) |
static boolean |
safeCopy(String source,
String target) |
static boolean |
saveToFile(File f,
String contents) |
static boolean |
saveToFile(String name,
String extension,
String contents) |
static String[] |
selectFile(String title_msg)
Returns null or the selected directory and file.
|
static void |
setDebug(boolean debug) |
static void |
setDebugMouse(boolean debug_mouse) |
static void |
setDebugSQL(boolean debug_sql) |
static void |
setEnabled(Container root,
boolean b)
Recursively enable/disable all components of the @param root Container.
|
static void |
setField(Object ob,
Class<?> c,
String field_name,
Object value) |
static void |
setLogStream(PrintStream ps) |
static void |
setup(ControlWindow master)
Initialize house keeping threads.
|
static void |
showAllTables(HashMap<Class<?>,ij.measure.ResultsTable> ht) |
static void |
showMessage(String msg) |
static void |
showMessage(String title,
String msg) |
static void |
showMessageT(String msg)
Runs the showMessage in a separate Thread.
|
static void |
showProgress(double p) |
static void |
showStatus(String msg) |
static void |
showStatus(String msg,
boolean focus) |
static void |
sleep(long miliseconds) |
static double[] |
toDouble(int[] a,
int len) |
static int[] |
toInt(double[] a,
int len) |
static String |
toString(Object ob)
Print an object; if it's an array, print each element, recursively, as [0, 1, 2] or [[0, 1, 2], [3, 4, 5]], etc, same for Iterable and Map objects.
|
static String |
trim(CharSequence sb) |
static void |
updateComponent(Component c)
Repaint the given Component on the swing repaint thread (aka "SwingUtilities.invokeLater").
|
static void |
wait(Collection<Future<?>> fus) |
static void |
waitIfAlive(Collection<Future<?>> fus,
boolean throwException) |
static boolean |
wrongImageJVersion() |
static String |
zeroPad(int i,
int n_digits)
Zero-pad a number, so that '1' becomes '001' if n_digits is 3.
|
public static String version
public static boolean debug
public static boolean debug_mouse
public static boolean debug_sql
public static boolean debug_event
public static boolean debug_clip
public static boolean debug_thing
public static final double FL_ERROR
public static String last_dir
public static String last_file
public static final boolean java3d
public static void debug(String msg)
public static void debugMouse(String msg)
public static final void setup(ControlWindow master)
public static final void destroy(ControlWindow master)
public static void setLogStream(PrintStream ps)
public static PrintStream getLogStream()
public static final void log(String msg)
public static final void logStamped(String msg)
public static final void logAll(String msg)
public static final void log2(String msg)
public static final void log2(Object ob)
public static final void log2(String msg, Object ob)
public static final void log(Object ob)
public static final void log(String msg, Object ob)
public static final void log2(Object... ob)
public static final void logMany2(Object... ob)
public static final String toString(Object ob)
public static void setDebug(boolean debug)
public static void setDebugMouse(boolean debug_mouse)
public static void setDebugSQL(boolean debug_sql)
public static final void printCaller(Object called_object)
public static final void printCaller(Object called_object, int lines)
public static final String caller(Object called)
public static final void restoreMenuBar()
public static final void showMessage(String msg)
public static final void showMessageT(String msg)
public static final void showStatus(String msg, boolean focus)
public static final void showStatus(String msg)
public static final void showProgress(double p)
public static void debugDialog()
public static ij.ImagePlus[] findOpenStacks()
public static ij.ImagePlus[] findOpenImages()
public static ij.ImagePlus[] findAllOpenImages()
public static String cutNumber(double d, int n_decimals)
public static final String cutNumber(double d, int n_decimals, boolean remove_trailing_zeros)
public static final String zeroPad(int i, int n_digits)
public static final boolean check(String msg)
public static final boolean checkYN(String msg)
public static final String d2s(double d, int n_decimals)
public static final void asHexRGBColor(StringBuilder sb, Color color)
public static final int[] get4Ints(int hex)
public void run(String arg)
run
in interface ij.plugin.PlugIn
public static final File chooseFile(String default_dir, String name, String extension)
public static final String[] selectFile(String title_msg)
public static final String cleanString(String s)
public static final String[] openTextFileLines(String path)
public static final char[] openTextFileChars(String path)
public static final double getCos(double x1, double y1, double x2, double y2)
public static final void addEnablerListener(Checkbox master, Component[] enable, Component[] disable)
public static final boolean wrongImageJVersion()
public static final void addLayerRangeChoices(Layer selected, GenericDialog gd)
public static final void addLayerRangeChoices(Layer first, Layer last, GenericDialog gd)
public static final void addLayerChoice(String label, Layer selected, GenericDialog gd)
public static final void addRGBColorSliders(GenericDialog gd, Color color)
public static final ij.process.ImageProcessor convertTo(ij.process.ImageProcessor ip, int type, boolean scaling)
public static final double[] copy(double[] a, int new_length)
public static final long[] copy(long[] a, int new_length)
public static final double[] copy(double[] a, int first, int new_length)
public static final long[] copy(long[] a, int first, int new_length)
public static final void reverse(double[] a)
public static final void reverse(long[] a)
public static final double[] toDouble(int[] a, int len)
public static final int[] toInt(double[] a, int len)
public static final boolean isPopupTrigger(MouseEvent me)
public static final void updateComponent(Component c)
public static final void revalidateComponent(Component c)
public static final String now()
public static final void sleep(long miliseconds)
public static final Color mix(Color c1, Color c2)
public static final String getCharacter(int i)
public static final Object getField(Object ob, Class<?> c, String field_name)
public static final ij.process.FloatProcessor fastConvertToFloat(ij.process.ByteProcessor ip)
public static final ij.process.FloatProcessor fastConvertToFloat(ij.process.ShortProcessor ip)
public static final ij.process.FloatProcessor fastConvertToFloat(ij.process.ImageProcessor ip, int type)
public static final ij.process.FloatProcessor fastConvertToFloat(ij.process.ImageProcessor ip)
public static final ij.measure.ResultsTable createResultsTable(String title, String[] columns)
public static final ij.process.ImageProcessor createProcessor(int type, int width, int height)
public static void paint(Pipe pipe, Map<Layer,ij.process.ImageProcessor> slices, int value, float scale)
public static final boolean isValidIdentifier(String s)
public static final String makeValidIdentifier(String s)
user=> (def pat #"\b[a-zA-Z]+[\w]*\b") #'user/pat user=>(re-seq pat "abc def 1a334") ("abc" "def") user=> (re-seq pat "abc def a334") ("abc" "def" "a334")Then concatenate all good words with underscores.
public static final boolean removeFile(File f)
public static boolean isTrakEM2Subfile(File f) throws Exception
Exception
public static boolean isTrakEM2Subpath(String path)
public static final boolean removePrefixedFiles(File parent, String prefix, ArrayList<String> removed_paths)
public static final int getControlModifier()
public static final boolean isControlDown(InputEvent e)
public static final void drawPoint(Graphics g, int x, int y)
public static final String trim(CharSequence sb)
public static final void wait(Collection<Future<?>> fus)
public static final void waitIfAlive(Collection<Future<?>> fus, boolean throwException)
public static final String fixDir(String path)
public static final ThreadPoolExecutor newFixedThreadPool(int n_proc)
public static final ThreadPoolExecutor newFixedThreadPool(String namePrefix)
public static final ThreadPoolExecutor newFixedThreadPool(int n_proc, String namePrefix)
public static final ThreadPoolExecutor newFixedThreadPool(int n_proc, String namePrefix, boolean use_caching_thread)
public static final boolean equalContent(Collection<?> a, Collection<?> b)
public static final boolean equalContent(Map<?,?> a, Map<?,?> b)
public static final boolean addPlugIns(JPopupMenu popup, String menu, Project project, Callable<Displayable> active)
public static final JMenu addPlugIns(String menu, Project project, Callable<Displayable> active)
public static final Bureaucrat launchTPlugIn(KeyEvent ke, String menu, Project project, Displayable active)
active
- may be null.public static final Dimension getDimensions(String text, Font font)
public static final InputStream createStream(String path_or_url) throws Exception
Exception
public static void setEnabled(Container root, boolean b)
public static final boolean ensure(String filepath)
public static final boolean ensure(File f)
public static final int luminance(Color c)
public static final void invokeLater(Runnable r)
public static final IndexColorModel fireLUT()
public static final BufferedImage convertToBufferedImage(ij.process.ByteProcessor bp)
public static final boolean safeCopy(String source, String target) throws IOException
source
- The file to copy.target
- The new file to create.IOException
public static final <A,B> ArrayList<B> castCollection(Collection<A> classAs, Class<B> type, boolean doThrow)
Copyright © 2015–2021 Fiji. All rights reserved.