public class IJ1Helper extends AbstractContextual
The LegacyService needs to patch ImageJ 1.x's classes before they are loaded. Unfortunately, this is tricky: if the LegacyService already uses those classes, it is a matter of luck whether we can get the patches in before those classes are loaded.
Therefore, we put as much interaction with ImageJ 1.x as possible into this class and keep a reference to it in the LegacyService.
Constructor and Description |
---|
IJ1Helper(LegacyService legacyService) |
Modifier and Type | Method and Description |
---|---|
void |
addAliases(ScriptService scriptService)
Add name aliases for ImageJ1 classes to the ScriptService.
|
void |
addCommand(String menuPath,
String label,
String command) |
void |
addMenuItems()
Adds legacy-compatible scripts and commands to the ImageJ1 menu structure.
|
void |
appAbout()
Displays the About ImageJ 1.x dialog.
|
void |
appPrefs()
Handles display of the ImageJ 1.x preferences.
|
void |
appQuit()
Handles shutdown of ImageJ 1.x.
|
String |
commandsName() |
void |
dispose()
Forcibly shuts down ImageJ1, with no user interaction or opportunity to
cancel.
|
void |
finishRecording()
Completes recording of a command.
|
static String |
getAdditionalMacroFunctions()
Gets the result of
Interpreter.getAdditionalFunctions() . |
ClassLoader |
getClassLoader() |
Hashtable<String,String> |
getCommands() |
String |
getDirectory(String title,
File file)
Chooses a directory using ImageJ 1.x' directory chooser.
|
int[] |
getIDList() |
Frame |
getIJ() |
ij.ImagePlus |
getImage(int imageID) |
int |
getImageID(Object o)
Gets the ID of the given
ImagePlus object. |
static Object |
getInterpreter()
Returns the active macro
Interpreter . |
static Context |
getLegacyContext()
Gets the SciJava application context linked to the ImageJ 1.x instance.
|
String |
getMacroParameter(String label)
Gets a macro parameter of type
String . |
boolean |
getMacroParameter(String label,
boolean defaultValue)
Gets a macro parameter of type boolean.
|
double |
getMacroParameter(String label,
double defaultValue)
Gets a macro parameter of type double.
|
String |
getMacroParameter(String label,
String defaultValue)
Gets a macro parameter of type
String . |
MenuBar |
getMenuBar() |
String |
getOptions()
Delegates to ImageJ 1.x'
Macro.getOptions() function. |
Object |
getSearchBar() |
Hashtable<Integer,String> |
getShortcuts() |
Panel |
getStatusBar() |
static String |
getTitle(Object o)
Returns
ImagePlus.getTitle() if the object is an ImagePlus ,
otherwise null. |
Component |
getToolBar() |
Object |
getVariable(Object interpreter,
String name)
Gets the value of the specified variable, from the given macro
Interpreter . |
String[] |
getVariables(Object interpreter)
Gets the value of the specified variable, from the given macro
Interpreter . |
String |
getVersion()
Gets the version of ImageJ 1.x.
|
int |
getX() |
int |
getY() |
void |
handleException(Throwable e)
Delegate exception handling to ImageJ 1.x.
|
boolean |
hasInstance() |
void |
initialize() |
boolean |
isDisposing()
Whether we are in the process of forcibly shutting down ImageJ1.
|
boolean |
isImagePlus(Class<?> c)
Returns true if the class is assignable to
ImagePlus . |
boolean |
isImagePlus(Object o)
Returns true if the object is an instance of
ImagePlus . |
boolean |
isMacintosh() |
boolean |
isMacro()
Determines whether we're running inside a macro right now.
|
boolean |
isRMIEnabled()
Determines whether Edit>Options>Misc...>Run single instance
listener is set.
|
boolean |
isVisible() |
boolean |
isWindowClosed(Frame window) |
static void |
openAndAddToRecent(File file)
Opens an image and adds the path to the File>Open Recent menu.
|
File |
openDialog(String title)
Uses ImageJ 1.x' OpenDialog
|
File |
openDialog(String title,
File file)
Uses ImageJ 1.x' OpenDialog
|
Object |
openImage(String path)
Opens an image using ImageJ 1.x.
|
Object |
openImage(String path,
boolean show)
Opens an image using ImageJ 1.x.
|
void |
openPathDirectly(String path)
Opens a path using ImageJ 1.x, bypassing the (javassisted) IJ utility
class.
|
boolean |
quitting() |
void |
recordOption(String key,
String value)
Records an option in ImageJ 1.x's macro recorder, safely.
|
void |
run(String command)
Evaluates the specified command.
|
String |
runMacro(String macro)
Evaluates the specified macro.
|
String |
runMacroFile(String path,
String arg)
Evaluates the specified macro.
|
File |
saveDialog(String title,
File file,
String extension)
Uses ImageJ 1.x' SaveDialog
|
void |
setCheckNameDuplicates(boolean checkDuplicates)
Sets
WindowManager checkForDuplicateName field. |
void |
setDebugMode(boolean debug)
Enables or disables ImageJ 1.x' debug mode.
|
void |
setDefaultDirectory(File directory)
Sets OpenDialog's default directory
|
void |
setKeyDown(int keyCode) |
void |
setKeyUp(int keyCode) |
void |
setLocation(int x,
int y) |
void |
setOptions(String options)
Delegates to ImageJ 1.x'
Macro.setOptions(String) function. |
void |
setProgress(int val,
int max) |
void |
setStatus(String message) |
void |
setVisible(boolean toggle) |
boolean |
shiftKeyDown()
Ask ImageJ 1.x whether it thinks whether the Shift key is held down.
|
void |
showMessage(String title,
String message) |
boolean |
showMessageWithCancel(String title,
String message) |
void |
startRecording(String command)
Begins recording of a command.
|
static void |
subscribeEvents(Context context) |
void |
syncActiveImage(ImageDisplay activeDisplay) |
void |
updateRecentMenu(String path) |
context, getContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setContext
public IJ1Helper(LegacyService legacyService)
public void initialize()
public void dispose()
ImageJ.quitting()
returns
true
), then this method does nothing.public boolean isDisposing()
public void addAliases(ScriptService scriptService)
public boolean isVisible()
public boolean isRMIEnabled()
public void setCheckNameDuplicates(boolean checkDuplicates)
WindowManager
checkForDuplicateName
field.public void setVisible(boolean toggle)
public void syncActiveImage(ImageDisplay activeDisplay)
public void setKeyDown(int keyCode)
public void setKeyUp(int keyCode)
public boolean hasInstance()
public String getVersion()
public boolean isMacintosh()
public void setStatus(String message)
public void setProgress(int val, int max)
public Component getToolBar()
public Panel getStatusBar()
public Object getSearchBar()
public Frame getIJ()
public void setLocation(int x, int y)
public int getX()
public int getY()
public boolean isWindowClosed(Frame window)
public boolean quitting()
public int[] getIDList()
public ij.ImagePlus getImage(int imageID)
public static String getTitle(Object o)
ImagePlus.getTitle()
if the object is an ImagePlus
,
otherwise null.public ClassLoader getClassLoader()
public String commandsName()
public void updateRecentMenu(String path)
public static void openAndAddToRecent(File file)
file
- the image to openpublic void recordOption(String key, String value)
Both the key and the value will be escaped to avoid problems. This behavior
differs from direct calls to Recorder.recordOption(String, String)
,
which do not escape either string.
key
- the name of the optionvalue
- the value of the optionpublic void startRecording(String command)
Recorder.setCommand(String)
public void finishRecording()
Recorder.saveCommand()
public boolean isMacro()
public boolean getMacroParameter(String label, boolean defaultValue)
label
- the name of the macro parameterdefaultValue
- the default valuepublic double getMacroParameter(String label, double defaultValue)
label
- the name of the macro parameterdefaultValue
- the default valuepublic String getMacroParameter(String label, String defaultValue)
String
.label
- the name of the macro parameterdefaultValue
- the default valuepublic String getMacroParameter(String label)
String
.label
- the name of the macro parameternull
if the parameter was not specifiedpublic static Object getInterpreter()
Interpreter
.public static String getAdditionalMacroFunctions()
Interpreter.getAdditionalFunctions()
.public String[] getVariables(Object interpreter)
Interpreter
.interpreter
- The macro Interpreter
to query.key\tvalue
form, as given by
Interpreter.getVariables()
.ClassCastException
- if the given interpreter is not an
Interpreter
.public Object getVariable(Object interpreter, String name)
Interpreter
.interpreter
- The macro Interpreter
to query.name
- The name of the variable to retrieve.String
, a
Double
or null
.ClassCastException
- if the given interpreter is not an
Interpreter
.public boolean isImagePlus(Object o)
ImagePlus
.public boolean isImagePlus(Class<?> c)
ImagePlus
.public int getImageID(Object o)
ImagePlus
object. If the given object is
not an ImagePlus
, throws IllegalArgumentException
.o
- The ImagePlus
whose ID is needed.ImagePlus.getID()
.ClassCastException
- if the given object is not an ImagePlus
.isImagePlus(Object)
public static Context getLegacyContext()
public static void subscribeEvents(Context context)
public MenuBar getMenuBar()
public void addMenuItems()
public void run(String command)
command
- the command to executepublic String runMacro(String macro)
macro
- the macro to evaluatepublic String runMacroFile(String path, String arg)
path
- the macro file to evaluatearg
- the macro argumentpublic Object openImage(String path)
path
- the image file to openpublic Object openImage(String path, boolean show)
path
- the image file to openpublic void openPathDirectly(String path)
path
- the image file to openpublic void setDebugMode(boolean debug)
debug
- whether to show debug messages or notpublic void handleException(Throwable e)
e
- the exception to handlepublic boolean shiftKeyDown()
public String getOptions()
Macro.getOptions()
function.public void setOptions(String options)
Macro.setOptions(String)
function.options
- the macro options, or null to resetpublic void appQuit()
public void appAbout()
public void setDefaultDirectory(File directory)
public File saveDialog(String title, File file, String extension)
public String getDirectory(String title, File file)
public void appPrefs()
Copyright © 2014–2022 ImageJ. All rights reserved.