public abstract class LegacyHooks extends Object
These extension points will be patched into ImageJ 1.x by the
CodeHacker
. To override the behavior of ImageJ 1.x, a new instance of
this class needs to be installed into ij.IJ._hooks
.
The essential functionality of the hooks is provided in the
EssentialLegacyHooks
class, which makes an excellent base class for
project-specific implementations.
Modifier and Type | Class and Description |
---|---|
static class |
LegacyHooks.FatJarNameComparator
Comparator to ensure that problematic fat JARs are sorted last.
|
Constructor and Description |
---|
LegacyHooks() |
Modifier and Type | Method and Description |
---|---|
void |
addMenuItem(String menuPath,
String command)
Callback for ImageJ 1.x' menu parsing machinery.
|
protected void |
addPluginClasspath(File file) |
String[] |
addPluginDirectory(File directory,
String[] names)
Extension point to modify the order in which .jar files are added to the
PluginClassLoader.
|
InputStream |
autoGenerateConfigFile(File directory) |
protected StringBuilder |
autoGenerateConfigFile(File topLevelDirectory,
File directory,
String menuPath,
String packageName,
StringBuilder builder) |
boolean |
createInEditor(String fileName,
String content)
Extension point to override ImageJ 1.x' editor.
|
void |
debug(String string)
Logs a debug message (to be shown only in debug mode).
|
void |
dispose()
Disposes of the hooks.
|
boolean |
disposing()
Allows interception of ImageJ 1.x's disposal routine while quitting.
|
protected void |
enableIJ1PluginDirs(boolean enable) |
void |
error(Throwable t)
Shows an exception.
|
String |
getAppName()
Returns the name to use in place of "ImageJ".
|
String |
getAppVersion()
Returns the version to use in place of the legacy version.
|
static Collection<File> |
getClasspathElements(ClassLoader fromClassLoader,
StringBuilder errors,
ClassLoader... excludeClassLoaders)
Do not use: for internal use only.
|
Object |
getContext()
Returns the current context, if any.
|
URL |
getIconURL()
Returns the icon to use in place of the ImageJ microscope.
|
Map<String,String> |
getMenuStructure()
Returns ImageJ 1.x' menu structure as a map.
|
Iterable<Thread> |
getThreadAncestors()
Iterates through the current thread's ancestors.
|
List<File> |
handleExtraPluginJars()
Extension point to add to ImageJ 1.x' PluginClassLoader's class path.
|
boolean |
handleNoSuchMethodError(NoSuchMethodError error)
Extension point to enhance ImageJ 1.x' error reporting upon
NoSuchMethodError . |
void |
initialized()
First extension point to run just after ImageJ 1.x spun up.
|
void |
installed()
Runs when the hooks are installed into an existing legacy environment.
|
boolean |
interceptCloseAllWindows()
Allows closing additional windows at the end of
WindowManager.closeAllWindows() . |
Object |
interceptDragAndDropFile(File f)
Optionally override opening drag-and-dropped files via legacy hooks.
|
Object |
interceptFileOpen(String path)
Optionally override opening resources via legacy hooks.
|
void |
interceptImageWindowClose(Object window)
Hook to ensure
ImageWindow s are fully cleaned up when
they are closed. |
boolean |
interceptKeyPressed(KeyEvent e)
Intercepts keyboard events sent to ImageJ 1.x.
|
Object |
interceptOpen(String path,
int planeIndex,
boolean display)
Deprecated.
this will be removed before ij1-patcher 1.0.0
|
Object |
interceptOpenImage(String path,
int planeIndex)
Optionally override opening images via legacy hooks.
|
Object |
interceptOpenRecent(String path)
Optionally override opening recent images via legacy hooks.
|
Object |
interceptRunPlugIn(String className,
String arg)
Intercepts the call to
IJ.runPlugIn(String, String) . |
boolean |
isLegacyMode()
Determines whether the image windows should be displayed or not.
|
void |
log(String message)
Logs a message.
|
void |
newPluginClassLoader(ClassLoader loader)
Extension point to run after a new PluginClassLoader was initialized.
|
boolean |
openInEditor(String path)
Extension point to override ImageJ 1.x' editor.
|
boolean |
quit()
Allows interception of ImageJ 1.x's
ImageJ.quit() method. |
void |
registerImage(Object image)
Registers an image (possibly not seen before).
|
void |
runAfterRefreshMenus()
Extension point to run after Help>Refresh Menus
|
void |
showProgress(double progress)
Updates the progress bar, where
0 <= progress <= 1.0 . |
void |
showProgress(int currentIndex,
int finalIndex)
Updates the progress bar, where the length of the bar is set to
(currentValue + 1) / finalValue of the maximum bar length. |
void |
showStatus(String status)
Shows a status message.
|
void |
unregisterImage(Object image)
Releases an image.
|
public boolean isLegacyMode()
public Object getContext()
For ImageJ2-specific hooks, the returned object will be the current SciJava context, or null if the context is not yet initialized.
public boolean quit()
ImageJ.quit()
method.public void installed()
public void dispose()
This method is called when ImageJ 1.x is quitting or when new hooks are installed.
public Object interceptRunPlugIn(String className, String arg)
IJ.runPlugIn(String, String)
.className
- the class namearg
- the argument passed to the runPlugIn
methodpublic void showProgress(double progress)
0 <= progress <= 1.0
.progress
- between 0.0 and 1.0public void showProgress(int currentIndex, int finalIndex)
(currentValue + 1) / finalValue
of the maximum bar length. The bar
is erased if currentValue >= finalValue
.currentIndex
- the step that was just startedfinalIndex
- the final step.public void showStatus(String status)
status
- the messagepublic void log(String message)
message
- the messagepublic void registerImage(Object image)
image
- the new imagepublic void unregisterImage(Object image)
image
- the imagepublic void debug(String string)
string
- the debug messagepublic void error(Throwable t)
t
- the exceptionpublic String getAppName()
public String getAppVersion()
public URL getIconURL()
public boolean openInEditor(String path)
path
- the path to the file to openpublic boolean createInEditor(String fileName, String content)
fileName
- the name of the new filecontent
- the initial contentprotected void enableIJ1PluginDirs(boolean enable)
protected void addPluginClasspath(File file)
public List<File> handleExtraPluginJars()
public void runAfterRefreshMenus()
public boolean handleNoSuchMethodError(NoSuchMethodError error)
NoSuchMethodError
.error
- the exception to handlepublic void newPluginClassLoader(ClassLoader loader)
loader
- the PluginClassLoader instancepublic String[] addPluginDirectory(File directory, String[] names)
There is a problem which only strikes large distributions of ImageJ such as Fiji: some .jar files try to be helpful and bundle classes which are actually not theirs, causing problems when newer versions of those .jar files which they shadow are present in the plugins/ or jars/ directory but are not respected by the class loader.
The default hook of this extension point therefore hard-codes a few file names of known offenders (which we politely will call fat .jar files normally) and just pushes them back to the end of the list.
directory
- the directory which ImageJ 1.x looked atnames
- the list of file names in the order ImageJ 1.x discovered thempublic void initialized()
public InputStream autoGenerateConfigFile(File directory)
protected StringBuilder autoGenerateConfigFile(File topLevelDirectory, File directory, String menuPath, String packageName, StringBuilder builder)
public void addMenuItem(String menuPath, String command)
This method is called whenever ImageJ 1.x adds a command to the menu structure.
menuPath
- the menu path of the menu item, or null when reinitializingcommand
- the command associated with the menu item, or null when reinitializingpublic Map<String,String> getMenuStructure()
@Deprecated public Object interceptOpen(String path, int planeIndex, boolean display)
This is intended as a "HandleExtraFileTypesPlus".
path
- the path to the resource to open, or null
if a dialog
needs to be shownplaneIndex
- If applicable - the index of plane to open or -1 for all planesdisplay
- if true, the opened object should be displayed before returningnull
to let ImageJ 1.x open the path.public Object interceptFileOpen(String path)
This is intended as a "HandleExtraFileTypesPlus".
path
- the path to the resource to open, or null
if a dialog
needs to be shownnull
to let ImageJ 1.x open the resource.public Object interceptOpenImage(String path, int planeIndex)
This is intended as a "HandleExtraFileTypesPlus".
path
- the path to the image to open, or null
if a dialog
needs to be shownplaneIndex
- If applicable - the index of plane to open or -1 for all planesnull
to let ImageJ 1.x open the image.public Object interceptOpenRecent(String path)
path
- the path to the recent image to opennull
to let ImageJ 1.x open the image.public Object interceptDragAndDropFile(File f)
f
- the file that was dragged onto the IJ UInull
to let ImageJ 1.x open the file
as normal.public static Collection<File> getClasspathElements(ClassLoader fromClassLoader, StringBuilder errors, ClassLoader... excludeClassLoaders)
public boolean interceptKeyPressed(KeyEvent e)
e
- the keyboard eventpublic Iterable<Thread> getThreadAncestors()
ImageJ 1.x' macro options are thread-local. Unfortunately, this does not take into account thread relationships e.g. when threads are spawned in parallel.
By overriding this method, legacy hooks can force ImageJ 1.x to look harder for macro options.
public boolean interceptCloseAllWindows()
WindowManager.closeAllWindows()
.
When returning false
, ImageJ 1.x will be disallowed from quitting.
public void interceptImageWindowClose(Object window)
ImageWindow
s are fully cleaned up when
they are closed.public boolean disposing()
This method is called after it has been confirmed that quitting should proceed. That is, the user OKed all the windows being closed, etc. This method provides one final chance to cancel the quit operation by returning false; otherwise, it performs any needed disposal and cleanup.
which is where ImageJ 1.x actually quits
Copyright © 2014–2022 ImageJ. All rights reserved.