public class Utils extends Object implements PlugIn
Modifier and Type | Field and Description |
---|---|
static String |
BUILD_DATE
A reference to the build date
|
static String |
BUILD_YEAR
A reference to the build year
|
static String |
VERSION
The BAR version
|
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
fileExists(File file)
Tests whether a file or directory exists.
|
static boolean |
fileExists(String filepath)
Tests whether a file or directory exists at the specified path.
|
static ResultsTable |
generateGaussianData()
Returns a
ResultsTable containing Gaussian ("normally")
distributed values without displaying it. |
static String |
getBARDir()
Returns the path to the root directory of BAR.
|
static URL |
getBARresource(String resourcePath) |
static String |
getClipboardText()
Retrieves text from the system clipboard.
|
static String |
getDocURL()
Returns the URL of BAR's documentation page.
|
static String |
getJavadocURL()
Returns the URL of BAR's API.
|
static String |
getLibDir()
Returns the path to
BAR/lib/ . |
static String |
getMyRoutinesDir()
Returns the path to
BAR/My_Routines/ , creating it . |
static String |
getPluginsBasedBARDir()
The absolute path to the legacy /BAR directory on the "plugins" folder.
|
static ResultsTable |
getResultsTable()
Returns a reference to the default IJ Results table.
|
static String |
getSnippetsDir()
Deprecated.
|
static String |
getSourceURL()
Returns the URL of BAR's Git repository.
|
static ResultsTable |
getTable()
Variant of
getTable(boolean, WindowListener) that ignores
WindowListeners. |
static ResultsTable |
getTable(boolean displayInResults,
WindowListener listener)
Prompts the user for tabular data, retrieved from several sources
including 1) Importing a new text/csv file; 2) Trying to import data from
the system clipboard; 3) Importing a demo dataset populated by random
(Gaussian) values; 4) the
ResultsTable of any TextWindow
or a PlotWindow currently being displayed in ImageJ. |
static ResultsTable |
getTable(Component relativeComponent,
boolean displayInResults,
boolean offerSampleChoice,
WindowListener listener) |
static ResultsTable |
getTable(String textWindowTitle)
Returns the ResultsTable associated with the specified TextWindow.
|
static void |
listDirectory(String dir)
Prints the contents of a directory to a dedicated TextWindow displayed on
the center of the screen.
|
static void |
listDirectory(String dir,
boolean cascade)
Prints the contents of a directory to a dedicated TextWindow allowed to
be displayed with a slight offset from frontmost window.
|
static void |
listDirectory(String dir,
int xPos,
int yPos)
Prints the contents of a directory to a dedicated TextWindow displayed at
the specified location.
|
static ResultsTable |
openAndDisplayTable(String path,
String title,
WindowListener listener)
Opens a tab or comma delimited text file.
|
static ResultsTable |
openAndDisplayTable(String path,
String title,
WindowListener listener,
boolean silent)
Opens a tab or comma delimited text file.
|
static void |
openIJ1Script(String dir,
String filename)
Opens the specified file in the ImageJ1 built-in editor.
|
static void |
openIJ2Script(File file)
Opens the specified file in the ImageJ2 Script Editor.
|
static void |
openLib(String filename)
Opens the specified file in the "lib" directory of BAR.
|
static void |
openScript(String dir,
String filename)
Alias for
openIJ2Script(File) |
static void |
openSnippet(String filename)
Opens the specified file in the "My Routines" directory of BAR.
|
static void |
revealFile(File file)
"Reveals" the specified file path in the operating system.
|
static void |
revealFile(String filePath)
"Reveals" the file associated with the specified file path in the
operating system.
|
void |
run(String arg) |
static void |
shiftClickWarning()
Displays a status-bar warning on "open by Shift-click" being disabled for
pre-compiled plugins.
|
static void |
zapCompiledFiles(File directory)
Removes
$py.class , .class , .pyc and .pyo
files from the specified directory. |
static void |
zapCompiledLibs()
Removes
$py.class , .class , .pyc and .pyo
files from the "lib" directory of BAR. |
public static String VERSION
public static String BUILD_DATE
public static String BUILD_YEAR
public static void shiftClickWarning()
public static String getClipboardText()
public static void listDirectory(String dir, int xPos, int yPos)
An error message is displayed in a dialog box if directory could not be
found or if directory is empty (see fileExists(File)
).
A FileDrop
listener is attached to the
TextWindow
, which means that, once displayed,
the method can be triggered by dragging and dropping files from the
native file manager.
Some system files (hidden files, Thumbs.db
) are excluded from the
list. If the directory is empty, users are prompted with the option to
reveal the file in the native file browser (see
revealFile(String)
).
Users can double click on a listed file path to have it open by ImageJ.
dir
- Path of the directory to be listedxPos
- The screen x location (from top-left corner) where the
TextWindow should be displayedyPos
- The screen y location (from top-left corner) where the
TextWindow should be displayedlistDirectory(String)
,
listDirectory(String, boolean)
public static void listDirectory(String dir)
dir
- the path of the directory to be listedlistDirectory(String, int, int)
,
listDirectory(String, boolean)
public static void listDirectory(String dir, boolean cascade)
dir
- the path of the directory to be listedcascade
- if true
TextWindow
"cascades" from ImageJ's
frontmost
window. If
false
, TextWidow is displayed in the center of the
screenlistDirectory(String, int, int)
,
listDirectory(String)
public static void openScript(String dir, String filename)
openIJ2Script(File)
public static void openIJ1Script(String dir, String filename)
dir
- the directory containing the file to be openedfilename
- the filename of the file to be openedopenScript(String, String)
public static void openIJ2Script(File file)
file
- the file to be openedopenScript(String, String)
,
openIJ1Script(String, String)
public static void openSnippet(String filename)
filename
- the filename of the script to be openedgetMyRoutinesDir()
,
openScript(String, String)
public static void zapCompiledLibs()
$py.class
, .class
, .pyc
and .pyo
files from the "lib" directory of BAR.getLibDir()
,
zapCompiledLibs()
public static void zapCompiledFiles(File directory)
$py.class
, .class
, .pyc
and .pyo
files from the specified directory.directory
- the directory to be cleansedzapCompiledLibs()
public static void openLib(String filename)
filename
- the filename of the lib/
file to be openedopenScript(String, String)
,
getLibDir()
public static boolean fileExists(File file)
message
is displayed in a dialog box if file
cannot be foundfile
- the File to be testedtrue
, if successful.fileExists(String)
public static boolean fileExists(String filepath)
filepath
- the file path to be testedtrue
, if successfulfileExists(File)
public static void revealFile(String filePath)
revealFile(File)
filePath
- the file path to be opened by the operating systemfileExists(File)
public static void revealFile(File file)
file
is a directory, opens it in the file manager of the
operating system, otherwise the application associated with the file type
will be launched. An error message is displayed in a dialog box if file
path is invalid, or if the operating system could not be detected.file
- the file to be opened by the operating systemfileExists(File)
public static String getLibDir()
BAR/lib/
.public static String getBARDir()
public static String getPluginsBasedBARDir()
public static String getMyRoutinesDir()
BAR/My_Routines/
, creating it .@Deprecated public static String getSnippetsDir()
public static String getJavadocURL()
public static String getDocURL()
public static String getSourceURL()
public static ResultsTable getResultsTable()
getTable(boolean, WindowListener)
to display data in
the "Results" window). This method is thought for IJ macros, since the IJ
macro language can only interact with the "Results" window. Note that any
previous data in the "Results" window will be lost.ResultsTable
in the
"Results" window or null
if chosen source did not contain
valid data. Note that the IJ1 macro interpreter converts all
returned objects into their String valuesgetTable()
public static ResultsTable getTable()
getTable(boolean, WindowListener)
that ignores
WindowListeners.ResultsTable
or null
if
chosen source did not contain valid datagetTable(boolean, WindowListener)
,
getResultsTable()
public static ResultsTable getTable(String textWindowTitle)
textWindowTitle
- The title of the TextWindow
holding the
TextPanel
and associated ResultsTable
ResultsTable
associated with the specified TextWindow
title or an empty ResultsTable
if no table exists.getTable(boolean, WindowListener)
,
getResultsTable()
public static ResultsTable getTable(boolean displayInResults, WindowListener listener)
ResultsTable
of any TextWindow
or a PlotWindow
currently being displayed in ImageJ. For 1) and
2) data is displayed in a new TextWindow.displayInResults
- If true
chosen data is displayed in the "Results"
window. Useful, since macros (and several plugins) can only
work with the "Results" window. Note that any previous data in
the "Results" window will be lost. If false
chosen
data is displayed on a dedicated window.listener
- The WindowListener
to be added to the window
containing data (if retrieval was successful. It is ignored
when null. Note that the window containing the data can either
be a TextWindow
or a PlotWindow
ResultsTable
or null
if
chosen source did not contain valid datagetResultsTable()
,
getTable()
public static ResultsTable getTable(Component relativeComponent, boolean displayInResults, boolean offerSampleChoice, WindowListener listener)
public static ResultsTable openAndDisplayTable(String path, String title, WindowListener listener, boolean silent)
path
- The absolute pathname string of the file. A file open dialog
is displayed if path is null
or an empty string.title
- The title of the window in which data is displayed. The
filename is used if title is null or an empty string. To avoid
windows with duplicated titles, title is made unique by
WindowManager
.listener
- The WindowListener
to be added to the window
containing data if retrieval was successful. It is ignored
when null
.silent
- If true
I/O exceptions are silently ignored.null
if
file could not be open.getTable()
,
Opener.openTable(String)
public static ResultsTable openAndDisplayTable(String path, String title, WindowListener listener) throws IOException
path
- The absolute pathname string of the file. A file open dialog
is displayed if path is null
or an empty string.title
- The title of the window in which data is displayed. The
filename is used if title is null or an empty string. To avoid
windows with duplicated titles, title is made unique by
WindowManager
.listener
- The WindowListener
to be added to the window
containing data if retrieval was successful. It is ignored
when null
.null
if
table was empty.IOException
- if file could not be openedgetTable()
,
Opener.openTable(String)
public static ResultsTable generateGaussianData()
ResultsTable
containing Gaussian ("normally")
distributed values without displaying it.getTable(boolean, WindowListener)
,
getTable()
,
getResultsTable()
Copyright © 2014–2017 Fiji. All rights reserved.