Issue with opening images in side bar of script editor

Hello @albertcardona,

I tried by chance to double click on the side bar of the script editor to open an image in FIJI, and it worked! So that’s great, but instead of having the proper image LUT and B&C (which I have when I directly drag and drop the image [tiff]):

image

I get a weirdly displayed virtual stack (actually it’s even fully red before I adjust the brightness):

image

Is that easily solvable ?

Best,

Nico

Hi @NikoKiaru,

The Script Editor uses:

  final Object o = ioService.open(f.getAbsolutePath());
  // Open in whatever way possible
  if (null != o) uiService.show(o);

See: https://github.com/scijava/script-editor/blob/master/src/main/java/org/scijava/ui/swing/script/TextEditor.java#L648

So this is a scijava services question for @ctrueden.

Best,

Albert

2 Likes

Note also that, if the current set of file system tree listeners in the Script Editor don’t suit you, you can change them. Either in the java code, and then running this to compile it and store it into your Fiji jars folder:

mvn -Dimagej.app.directory=/path/to/Fiji.app/ -Dmaven.test.skip=true clean install

Or, in a live session, by grabbing the Frame of the Script Editor, removing the listener from the tree and replacing it with your own, for example:

from java.awt import Frame
from org.scijava.ui.swing.script import FileSystemTree
from ij import IJ

class CustomLeafListener(FileSystemTree.LeafListener):
  def __init__(self, texteditor):
    self.texteditor = texteditor
  def leafDoubleClicked(self, fileOb):
    name = fileOb.getName()
    idot = name.rfind('.')
    if -1 == idot:
      print "File name lacks extension"
      return
    # Open depending on what it is  
    extension = name[idot+1:].lower() # in lowercase
    languages = set(["py", "clj", "js", "java", "bs", "ijm", "r", "rb", "sc", "txt", "md"])
    if extension in languages:
      self.texteditor.open(fileOb)
    else:
      # Let ImageJ handle it
      print "Asking ImageJ to open file", fileOb
      IJ.open(fileOb.getAbsolutePath())

# Find the java.awt.Frame of the ScriptEditor
for frame in Frame.getFrames():
  if frame.getClass().getSimpleName() == "TextEditor":
    # Grab its private "tree" instance of FileSystemTree
    field = frame.getClass().getDeclaredField("tree")
    field.setAccessible(True)
    tree = field.get(frame)
    # Remove any registered LeafListener
    map(tree.removeLeafListener, tree.getLeafListeners())
    # Add your own
    tree.addLeafListener(CustomLeafListener(frame))

Push “Run” and that’s that. Adjust as needed to open whatever you want, then “Run” again: it replaces itself as the listener.

In the example above, I used IJ.open, so that’s exactly equivalent to drag and drop over the Fiji toolbar, or the “File - Open…” menu item.

2 Likes

Pretty cool! And i wasn’t aware at all about the Frame.getFrames() static function. This looks very convenient for horrible hacks, so I will use it reasonably (or not).

1 Like

Your “horrible hack” is my “this software gets out of my way and lets me get things done” :slight_smile:

2 Likes

I’ve seen this bug; it’s a deep bug in the imglib2-ij layer. It manifests because ioService.open(file) invokes SCIFIO via the DatasetIOPlugin, and SCIFIO opens an ImgLib2 image, which gets wrapped to ImageJ1 for display by imglib2-ij. I debugged deeply into it a couple months ago with @elevans, but we didn’t end up solving it. Unfortunately, it doesn’t look like we filed an issue for it in imglib2-ij. Ed, do you remember if there is an existing issue for this problem anywhere else?

2 Likes