imagej.patcher
Class LegacyHooks

java.lang.Object
  extended by imagej.patcher.LegacyHooks
Direct Known Subclasses:
EssentialLegacyHooks

public abstract class LegacyHooks
extends Object

Extension points for ImageJ 1.x.

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 interface 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.

Author:
Johannes Schindelin

Nested Class Summary
static class LegacyHooks.FatJarNameComparator
           
 
Field Summary
 Collection<File> _pluginClasspath
           
 
Constructor Summary
LegacyHooks()
           
 
Method Summary
 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.
 void error(Throwable t)
          Shows an exception.
 String getAppName()
          Returns the name to use in place of "ImageJ".
 Object getContext()
          Return the current context, if any.
 URL getIconURL()
          Returns the icon to use in place of the ImageJ microscope.
 List<File> handleExtraPluginJars()
          Extension point to add to ImageJ 1.x' PluginClassLoader's class path.
 boolean handleNoSuchMethodError(NoSuchMethodError e)
          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.
 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()
          Disposes and prepares for quitting.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_pluginClasspath

public final Collection<File> _pluginClasspath
Constructor Detail

LegacyHooks

public LegacyHooks()
Method Detail

isLegacyMode

public boolean isLegacyMode()
Determines whether the image windows should be displayed or not.

Returns:
false if ImageJ 1.x should be prevented from opening image windows.

getContext

public Object getContext()
Return the current context, if any.

For ImageJ2-specific hooks, the returned object will be the current SciJava context, or null if the context is not yet initialized.

Returns:
the context, or null

quit

public boolean quit()
Disposes and prepares for quitting.

Returns:
whether ImageJ 1.x should be allowed to call System.exit()

installed

public void installed()
Runs when the hooks are installed into an existing legacy environment.


dispose

public void dispose()
Disposes of the hooks.

This method is called when ImageJ 1.x is quitting or when new hooks are installed.


interceptRunPlugIn

public Object interceptRunPlugIn(String className,
                                 String arg)
Intercepts the call to IJ.runPlugIn(String, String).

Parameters:
className - the class name
arg - the argument passed to the runPlugIn method
Returns:
the object to return, or null to let ImageJ 1.x handle the call

showProgress

public void showProgress(double progress)
Updates the progress bar, where 0 <= progress <= 1.0.

Parameters:
value - between 0.0 and 1.0

showProgress

public 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. The bar is erased if currentValue >= finalValue.

Parameters:
currentIndex - the step that was just started
finalIndex - the final step.

showStatus

public void showStatus(String status)
Shows a status message.

Parameters:
status - the message

log

public void log(String message)
Logs a message.

Parameters:
message - the message

registerImage

public void registerImage(Object image)
Registers an image (possibly not seen before).

Parameters:
image - the new image

unregisterImage

public void unregisterImage(Object image)
Releases an image.

Parameters:
imagej - the image

debug

public void debug(String string)
Logs a debug message (to be shown only in debug mode).

Parameters:
string - the debug message

error

public void error(Throwable t)
Shows an exception.

Parameters:
t - the exception

getAppName

public String getAppName()
Returns the name to use in place of "ImageJ".

Returns:
the application name

getIconURL

public URL getIconURL()
Returns the icon to use in place of the ImageJ microscope.

Returns:
the URL to the icon to use, or null

openInEditor

public boolean openInEditor(String path)
Extension point to override ImageJ 1.x' editor.

Parameters:
path - the path to the file to open
Returns:
true if the hook opened a different editor

createInEditor

public boolean createInEditor(String fileName,
                              String content)
Extension point to override ImageJ 1.x' editor.

Parameters:
fileName - the name of the new file
content - the initial content
Returns:
true if the hook opened a different editor

handleExtraPluginJars

public List<File> handleExtraPluginJars()
Extension point to add to ImageJ 1.x' PluginClassLoader's class path.

Returns:
a list of class path elements to add

runAfterRefreshMenus

public void runAfterRefreshMenus()
Extension point to run after Help>Refresh Menus


handleNoSuchMethodError

public boolean handleNoSuchMethodError(NoSuchMethodError e)
Extension point to enhance ImageJ 1.x' error reporting upon NoSuchMethodError.

Parameters:
e - the exception to handle
Returns:
true if the error was handled by the legacy hook

newPluginClassLoader

public void newPluginClassLoader(ClassLoader loader)
Extension point to run after a new PluginClassLoader was initialized.

Parameters:
loader - the PluginClassLoader instance

addPluginDirectory

public String[] addPluginDirectory(File directory,
                                   String[] names)
Extension point to modify the order in which .jar files are added to the PluginClassLoader.

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.

Parameters:
directory - the directory which ImageJ 1.x looked at
names - the list of file names in the order ImageJ 1.x discovered them
Returns:
the ordered, filtered and/or augmented list

initialized

public void initialized()
First extension point to run just after ImageJ 1.x spun up.


autoGenerateConfigFile

public InputStream autoGenerateConfigFile(File directory)

autoGenerateConfigFile

protected StringBuilder autoGenerateConfigFile(File topLevelDirectory,
                                               File directory,
                                               String menuPath,
                                               String packageName,
                                               StringBuilder builder)


Copyright © 2011–2014 SciJava. All rights reserved.