/** * Sets the level of the root logger * * @param level A string indicating the desired level * (i.e.: ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARN). */ public static synchronized void setRootLevel(String level) { try { ReflectedUniverse r = new ReflectedUniverse(); r.exec("import org.apache.log4j.Level"); r.exec("import org.apache.log4j.Logger"); r.exec("root = Logger.getRootLogger()"); r.exec("root.setLevel(Level." + level + ")"); } catch (ReflectException exc) { return; } return; }
/** * Sets the level of the root logger * * @param level A string indicating the desired level * (i.e.: ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARN). */ public static synchronized void setRootLevel(String level) { try { ReflectedUniverse r = new ReflectedUniverse(); r.exec("import org.apache.log4j.Level"); r.exec("import org.apache.log4j.Logger"); r.exec("root = Logger.getRootLogger()"); r.exec("root.setLevel(Level." + level + ")"); } catch (ReflectException exc) { return; } return; }
/** * Checks whether the log4j framework was successfully enabled * * @return {@code true} if logging was successfully enabled */ public static synchronized boolean isEnabled() { try { ReflectedUniverse r = new ReflectedUniverse(); r.exec("import org.apache.log4j.Level"); r.exec("import org.apache.log4j.Logger"); r.exec("root = Logger.getRootLogger()"); Enumeration en = (Enumeration) r.exec("root.getAllAppenders()"); return en.hasMoreElements(); } catch (ReflectException exc) { return false; } }
/** * Checks whether the log4j framework was successfully enabled * * @return {@code true} if logging was successfully enabled */ public static synchronized boolean isEnabled() { try { ReflectedUniverse r = new ReflectedUniverse(); r.exec("import org.apache.log4j.Level"); r.exec("import org.apache.log4j.Logger"); r.exec("root = Logger.getRootLogger()"); Enumeration en = (Enumeration) r.exec("root.getAllAppenders()"); return en.hasMoreElements(); } catch (ReflectException exc) { return false; } }
@Override public void close(boolean fileOnly) throws IOException { try { if (r != null && r.getVar("openMovieFile") != null) { r.exec("openMovieFile.close()"); if (!fileOnly) { r.exec("m.disposeQTObject()"); r.exec("imageTrack.disposeQTObject()"); r.exec("QTSession.close()"); } } } catch (ReflectException e) { LOGGER.debug("Failed to close QuickTime session", e); } if (!fileOnly) { currentId = null; times = null; image = null; } }
@Override public void close(boolean fileOnly) throws IOException { try { if (r != null && r.getVar("openMovieFile") != null) { r.exec("openMovieFile.close()"); if (!fileOnly) { r.exec("m.disposeQTObject()"); r.exec("imageTrack.disposeQTObject()"); r.exec("QTSession.close()"); } } } catch (ReflectException e) { LOGGER.debug("Failed to close QuickTime session", e); } if (!fileOnly) { currentId = null; times = null; image = null; } }
/** Gets width and height for the given PICT bytes. */ public Dimension getPictDimensions(byte[] bytes) throws FormatException, ReflectException { checkQTLibrary(); try { r.exec("QTSession.open()"); r.setVar("bytes", bytes); r.exec("pict = new Pict(bytes)"); r.exec("box = pict.getPictFrame()"); int width = ((Integer) r.exec("box.getWidth()")).intValue(); int height = ((Integer) r.exec("box.getHeight()")).intValue(); r.exec("QTSession.close()"); return new Dimension(width, height); } catch (ReflectException e) { r.exec("QTSession.close()"); throw new FormatException("PICT height determination failed", e); } }
/** Gets width and height for the given PICT bytes. */ public Dimension getPictDimensions(byte[] bytes) throws FormatException, ReflectException { checkQTLibrary(); try { r.exec("QTSession.open()"); r.setVar("bytes", bytes); r.exec("pict = new Pict(bytes)"); r.exec("box = pict.getPictFrame()"); int width = ((Integer) r.exec("box.getWidth()")).intValue(); int height = ((Integer) r.exec("box.getHeight()")).intValue(); r.exec("QTSession.close()"); return new Dimension(width, height); } catch (ReflectException e) { r.exec("QTSession.close()"); throw new FormatException("PICT height determination failed", e); } }
/** * Enable SLF4J logging using logback, in the context of ImageJ. * * This allows logging events to be echoed to the ImageJ status bar, * regardless of how the logging configuration file was set up. * * @param debug true if debug-level output should be shown * @return whether or not ImageJ log enabling was successful */ public static synchronized boolean enableIJLogging(boolean debug) { ReflectedUniverse r = new ReflectedUniverse(); try { r.exec("import loci.common.LogbackTools"); r.exec("import loci.plugins.util.IJStatusEchoer"); r.exec("appender = new IJStatusEchoer()"); r.setVar("debug", debug); r.exec("LogbackTools.enableIJLogging(debug, appender)"); } catch (ReflectException exc) { return false; } return true; }
/** * Enable SLF4J logging using logback, in the context of ImageJ. * * This allows logging events to be echoed to the ImageJ status bar, * regardless of how the logging configuration file was set up. * * @param debug true if debug-level output should be shown * @return whether or not ImageJ log enabling was successful */ public static synchronized boolean enableIJLogging(boolean debug) { ReflectedUniverse r = new ReflectedUniverse(); try { r.exec("import loci.common.LogbackTools"); r.exec("import loci.plugins.util.IJStatusEchoer"); r.exec("appender = new IJStatusEchoer()"); r.setVar("debug", debug); r.exec("LogbackTools.enableIJLogging(debug, appender)"); } catch (ReflectException exc) { return false; } return true; }
/** Gets the QuickTime for Java version number. */ public String getQTVersion() { if (isJVM64Bit()) return "Not available"; else if (isQTExpired()) return "Expired"; else if (!canDoQT()) return "Missing"; else { try { String qtMajor = r.exec("QTSession.getMajorVersion()").toString(); String qtMinor = r.exec("QTSession.getMinorVersion()").toString(); return qtMajor + "." + qtMinor; } catch (Throwable t) { LOGGER.debug("Could not retrieve QuickTime for Java version", t); return "Error"; } } }
/** Obtains a BufferedImage from the given data source using JAI. */ protected BufferedImage openBufferedImage(int no) throws FormatException { r.setVar("no", no); RenderedImage img; try { r.exec("img = dec.decodeAsRenderedImage(no)"); img = (RenderedImage) r.exec("new NullOpImage(img, null, OpImage.OP_IO_BOUND, null)"); } catch (ReflectException exc) { throw new FormatException(exc); } return AWTImageTools.convertRenderedImage(img); }
/** Gets the QuickTime for Java version number. */ public String getQTVersion() { if (isJVM64Bit()) return "Not available"; else if (isQTExpired()) return "Expired"; else if (!canDoQT()) return "Missing"; else { try { String qtMajor = r.exec("QTSession.getMajorVersion()").toString(); String qtMinor = r.exec("QTSession.getMinorVersion()").toString(); return qtMajor + "." + qtMinor; } catch (Throwable t) { LOGGER.debug("Could not retrieve QuickTime for Java version", t); return "Error"; } } }
/** Obtains a BufferedImage from the given data source using JAI. */ protected BufferedImage openBufferedImage(int no) throws FormatException { r.setVar("no", no); RenderedImage img; try { r.exec("img = dec.decodeAsRenderedImage(no)"); img = (RenderedImage) r.exec("new NullOpImage(img, null, OpImage.OP_IO_BOUND, null)"); } catch (ReflectException exc) { throw new FormatException(exc); } return AWTImageTools.convertRenderedImage(img); }
/** * Allows exploration of a reflected universe in an interactive environment. */ public static void main(String[] args) throws IOException { ReflectedUniverse r = new ReflectedUniverse(); System.out.println("Reflected universe test environment. " + "Type commands, or press ^D to quit."); if (args.length > 0) { r.setAccessibilityIgnored(true); System.out.println("Ignoring accessibility modifiers."); } BufferedReader in = new BufferedReader(new InputStreamReader(System.in, Constants.ENCODING)); while (true) { System.out.print("> "); String line = in.readLine(); if (line == null) break; try { r.exec(line); } catch (ReflectException exc) { LOGGER.debug("Could not execute '{}'", line, exc); } } System.out.println(); }
/** * Allows exploration of a reflected universe in an interactive environment. * * @param args if non-empty, access modifiers will be ignored * @throws IOException if there is an error reading from stdin */ public static void main(String[] args) throws IOException { ReflectedUniverse r = new ReflectedUniverse(); System.out.println("Reflected universe test environment. " + "Type commands, or press ^D to quit."); if (args.length > 0) { r.setAccessibilityIgnored(true); System.out.println("Ignoring accessibility modifiers."); } BufferedReader in = new BufferedReader(new InputStreamReader(System.in, Constants.ENCODING)); while (true) { System.out.print("> "); String line = in.readLine(); if (line == null) break; try { r.exec(line); } catch (ReflectException exc) { LOGGER.debug("Could not execute '{}'", line, exc); } } System.out.println(); }
@Override public Object openPlane(int no, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, -1, x, y, w, h); // paint frame into image try { r.setVar("time", times[no]); r.exec("moviePlayer.setTime(time)"); r.exec("qtip.redraw(null)"); r.exec("qtip.updateConsumers(null)"); } catch (ReflectException re) { throw new FormatException("Open movie failed", re); } return AWTImageTools.getSubimage(AWTImageTools.makeBuffered(image), isLittleEndian(), x, y, w, h); }
@Override public Object openPlane(int no, int x, int y, int w, int h) throws FormatException, IOException { FormatTools.checkPlaneParameters(this, no, -1, x, y, w, h); // paint frame into image try { r.setVar("time", times[no]); r.exec("moviePlayer.setTime(time)"); r.exec("qtip.redraw(null)"); r.exec("qtip.updateConsumers(null)"); } catch (ReflectException re) { throw new FormatException("Open movie failed", re); } return AWTImageTools.getSubimage(AWTImageTools.makeBuffered(image), isLittleEndian(), x, y, w, h); }
public void displayImage5D(ImagePlus imp) { WindowManager.setTempCurrentImage(imp); IFormatReader r = process.getReader(); ReflectedUniverse ru = new ReflectedUniverse(); try { ru.exec("import i5d.Image5D"); ru.setVar("title", imp.getTitle()); ru.setVar("stack", imp.getStack()); ru.setVar("sizeC", imp.getNChannels()); ru.setVar("sizeZ", imp.getNSlices()); ru.setVar("sizeT", imp.getNFrames()); ru.exec("i5d = new Image5D(title, stack, sizeC, sizeZ, sizeT)"); ru.setVar("cal", imp.getCalibration()); ru.setVar("fi", imp.getOriginalFileInfo()); ru.exec("i5d.setCalibration(cal)"); ru.exec("i5d.setFileInfo(fi)"); //ru.exec("i5d.setDimensions(sizeC, sizeZ, sizeT)"); ru.exec("i5d.show()"); } catch (ReflectException exc) { WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem interfacing with Image5D"); } }
public void displayImage5D(ImagePlus imp) { WindowManager.setTempCurrentImage(imp); IFormatReader r = process.getReader(); ReflectedUniverse ru = new ReflectedUniverse(); try { ru.exec("import i5d.Image5D"); ru.setVar("title", imp.getTitle()); ru.setVar("stack", imp.getStack()); ru.setVar("sizeC", imp.getNChannels()); ru.setVar("sizeZ", imp.getNSlices()); ru.setVar("sizeT", imp.getNFrames()); ru.exec("i5d = new Image5D(title, stack, sizeC, sizeZ, sizeT)"); ru.setVar("cal", imp.getCalibration()); ru.setVar("fi", imp.getOriginalFileInfo()); ru.exec("i5d.setCalibration(cal)"); ru.exec("i5d.setFileInfo(fi)"); //ru.exec("i5d.setDimensions(sizeC, sizeZ, sizeT)"); ru.exec("i5d.show()"); } catch (ReflectException exc) { WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem interfacing with Image5D"); } }