integrating ptolemy plot PlotMLFrame

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

integrating ptolemy plot PlotMLFrame

Zummy
I am writing a ptolemy plot plugin for ImageJ for plot profiles.  Ptolemy
Plot has it's own window class called PlotMLFrame or PlotFrame.  I am
trying to make this Frame work better with ImageJ.  Right now, if I'm
running as an applet, and exit ImageJ, the PlotMLFrame remains showing.
Thus, I am looking for some way to close or hide the window.  Perhaps
an interface could be written which would allow "foreign" windows to
be integrated into the ImageJ, such that all windows would close when
ImageJ "stops".  I realize that if I use ImageJ as an application, this would
work okay, I'm just trying to solve the applet case for now.

Any suggestions?

package plugins.Graphics;

import ij.ImagePlus;
import ij.gui.ProfilePlot;
import ij.plugin.filter.PlugInFilter;
import ij.plugin.filter.Profiler;
import ij.process.ImageProcessor;
import ij.util.Tools;

import java.awt.Dimension;

import ptolemy.plot.plotml.PlotMLFrame;

class Plot extends ptolemy.plot.NIFPlot {
public Plot(String title, String xLabel, String yLabel, float []
xValues, float [] yValues) {
            setTitle(title);
            setXLabel(xLabel);
            setYLabel(yLabel);
            if (xValues== null || yValues== null) {
                    xValues = new float [1];
                    yValues = new float [1];
                    xValues[0] = -1f;
                    yValues[0] = -1f;
            }
            for (int i = 0; i < xValues. length; i++) {
            addPoint(0, xValues[i], yValues[i], true );
            }
            double [] a = Tools.getMinMax(xValues);
            double xMin=a[0]; double xMax=a[1];
            a = Tools.getMinMax(yValues);
            double yMin=a[0]; double yMax=a[1];
            setXRange(xMin, xMax);
            setYRange(yMin, yMax);
     }
}

class PtProfilePlot extends ProfilePlot {
public PtProfilePlot(ImagePlus imp) {
super (imp);
}
public void createWindow() {
         if (profile == null )
                 return ;
         Dimension d = getPlotSize();
         String xLabel = "Distance ("+ units + ")" ;
         int n = profile . length ;
         if (xValues == null ) {
                 xValues = new float [n];
                 for (int i=0; i<n; i++)
                         xValues [i] = (float )(i* xInc );
         }
         float [] yValues = new float [n];
         for (int i=0; i<n; i++) {
                 yValues[i] = (float ) profile [i];
         }
         Plot plot = new Plot("Plot of "+ imp .getShortTitle(),
xLabel, yLabel , xValues , yValues);
         PlotMLFrame pf = new PlotMLFrame( "Plot of "+ imp
.getShortTitle(), plot);
         pf.setVisible( true);
     }

}
public class Pt_Profiler extends Profiler implements PlugInFilter {
private ImagePlus imp ;
public int setup(String arg, ImagePlus imp) {
this . imp = imp;
return super .setup(arg, imp);
}
public void run(ImageProcessor ip) {
new PtProfilePlot( imp).createWindow();
}
}
Reply | Threaded
Open this post in threaded view
|

Re: integrating ptolemy plot PlotMLFrame

Michael Schmid
Hi John,

just an idea, I have not tried whether this works:
get a reference to the toolbar:
   Toolbar tb = Toolbar.getInstance();
add a ComponentListener:
   tb.addComponentListener(this);
and see whether you get a call to the componentHidden(ComponentEvent e)
method of your class if the Toolbar window closes.

On a Macintosh, you can use MRJQuitHandler, see QuitHandler.java
that comes with ImageJ on Macs.

Michael
________________________________________________________________

On 8 Jun 2007, at 22:13, John Carlson wrote:

> I am writing a ptolemy plot plugin for ImageJ for plot profiles.  
> Ptolemy
> Plot has it's own window class called PlotMLFrame or PlotFrame.
(...)
>   Right now, if I'm
> running as an applet, and exit ImageJ, the PlotMLFrame remains  
> showing.
> Thus, I am looking for some way to close or hide the window.
Reply | Threaded
Open this post in threaded view
|

Re: integrating ptolemy plot PlotMLFrame

Wayne Rasband
In reply to this post by Zummy
Call WindowManager.addWindow() when the the PlotMLFrame opens and
WindowManager.removeWindow() when it closes. This also adds the window
to the Window menu. You will need to be using ImageJ 1.38u or later.

-wayne

On Jun 8, 2007, at 4:13 PM, John Carlson wrote:

> I am writing a ptolemy plot plugin for ImageJ for plot profiles.  
> Ptolemy
> Plot has it's own window class called PlotMLFrame or PlotFrame.  I am
> trying to make this Frame work better with ImageJ.  Right now, if I'm
> running as an applet, and exit ImageJ, the PlotMLFrame remains showing.
> Thus, I am looking for some way to close or hide the window.  Perhaps
> an interface could be written which would allow "foreign" windows to
> be integrated into the ImageJ, such that all windows would close when
> ImageJ "stops".  I realize that if I use ImageJ as an application,
> this would
> work okay, I'm just trying to solve the applet case for now.
>
> Any suggestions?
>
> package plugins.Graphics;
>
> import ij.ImagePlus;
> import ij.gui.ProfilePlot;
> import ij.plugin.filter.PlugInFilter;
> import ij.plugin.filter.Profiler;
> import ij.process.ImageProcessor;
> import ij.util.Tools;
>
> import java.awt.Dimension;
>
> import ptolemy.plot.plotml.PlotMLFrame;
>
> class Plot extends ptolemy.plot.NIFPlot {
> public Plot(String title, String xLabel, String yLabel, float []
> xValues, float [] yValues) {
>            setTitle(title);
>            setXLabel(xLabel);
>            setYLabel(yLabel);
>            if (xValues== null || yValues== null) {
>                    xValues = new float [1];
>                    yValues = new float [1];
>                    xValues[0] = -1f;
>                    yValues[0] = -1f;
>            }
>            for (int i = 0; i < xValues. length; i++) {
>            addPoint(0, xValues[i], yValues[i], true );
>            }
>            double [] a = Tools.getMinMax(xValues);
>            double xMin=a[0]; double xMax=a[1];
>            a = Tools.getMinMax(yValues);
>            double yMin=a[0]; double yMax=a[1];
>            setXRange(xMin, xMax);
>            setYRange(yMin, yMax);
>     }
> }
>
> class PtProfilePlot extends ProfilePlot {
> public PtProfilePlot(ImagePlus imp) {
> super (imp);
> }
> public void createWindow() {
>         if (profile == null )
>                 return ;
>         Dimension d = getPlotSize();
>         String xLabel = "Distance ("+ units + ")" ;
>         int n = profile . length ;
>         if (xValues == null ) {
>                 xValues = new float [n];
>                 for (int i=0; i<n; i++)
>                         xValues [i] = (float )(i* xInc );
>         }
>         float [] yValues = new float [n];
>         for (int i=0; i<n; i++) {
>                 yValues[i] = (float ) profile [i];
>         }
>         Plot plot = new Plot("Plot of "+ imp .getShortTitle(), xLabel,
> yLabel , xValues , yValues);
>         PlotMLFrame pf = new PlotMLFrame( "Plot of "+ imp
> .getShortTitle(), plot);
>         pf.setVisible( true);
>     }
>
> }
> public class Pt_Profiler extends Profiler implements PlugInFilter {
> private ImagePlus imp ;
> public int setup(String arg, ImagePlus imp) {
> this . imp = imp;
> return super .setup(arg, imp);
> }
> public void run(ImageProcessor ip) {
> new PtProfilePlot( imp).createWindow();
> }
> }
>