ThreeB 1.1
Public Member Functions | Package Functions | Package Attributes | Private Member Functions | Private Attributes
EControlPanel Class Reference

Control panel for running 3B plugin and providing interactive update. More...

List of all members.

Public Member Functions

void windowOpened (WindowEvent e)
void windowClosed (WindowEvent e)
void windowDeactivated (WindowEvent e)
void windowActivated (WindowEvent e)
void windowDeiconified (WindowEvent e)
void windowIconified (WindowEvent e)
void windowClosing (WindowEvent e)
void issue_stop ()
synchronized void append (final ArrayList< Spot > p, int its)
void send_update_canvas_event ()
void die (final String s)
void send_status_text_message (final String s)
void send_time_text_message (final String s)

Package Functions

 EControlPanel (Rectangle roi_, double ps_, String filename_, ThreeBRunner tbr_)
void export_reconstruction_as_ij ()

Package Attributes

JButton exportButton
JButton closeButton
JLabel time_msg

Private Member Functions

GridBagConstraints canvas_pos ()
GridBagConstraints status_pos ()
GridBagConstraints time_pos ()
GridBagConstraints buttons_pos ()
GridBagConstraints pixel_size_pos ()
GridBagConstraints blur_pos ()
void set_status (String s)
void set_time (String s)
synchronized void update_canvas ()
synchronized FloatProcessor reconstruct ()

Private Attributes

ImagePlus linear_reconstruction
ImageCanvas canvas
JButton stopButton
Color exportButtonColor
JLabel status
FloatSliderWithBox blur_fwhm
FloatSliderWithBox reconstructed_pixel_size
Panel complete
JPanel buttons
ThreeBRunner tbr
ArrayList< Spotpts
Rectangle roi
double zoom = 0.01
double reconstruction_blur_fwhm = .5
double pixel_size_in_nm
String filename
int iterations = 0

Detailed Description

Control panel for running 3B plugin and providing interactive update.

Definition at line 888 of file three_B.java.


Constructor & Destructor Documentation

EControlPanel::EControlPanel ( Rectangle  roi_,
double  ps_,
String  filename_,
ThreeBRunner  tbr_ 
) [inline, package]

Definition at line 918 of file three_B.java.

References FloatSliderWithBox::addChangeListener(), blur_fwhm, blur_pos(), buttons, buttons_pos(), canvas, canvas_pos(), closeButton, complete, exportButton, exportButtonColor, filename, linear_reconstruction, pixel_size_in_nm, pixel_size_pos(), pts, reconstruct(), reconstructed_pixel_size, ThreeBRunner::register(), roi, set_status(), set_time(), FloatSliderWithBox::setFormat(), FloatSliderWithBox::setUnits(), status, status_pos(), stopButton, tbr, time_msg, and time_pos().

    {
        //Constract superclass
        super(filename_);

        tbr = tbr_;
        filename=filename_;

        roi = roi_;
        pixel_size_in_nm = ps_;
        pts = new ArrayList<Spot>();

    
        //Now generate the dialog box
        complete = new Panel(new GridBagLayout());

        //Create the image viewer
        linear_reconstruction = new ImagePlus();
        linear_reconstruction.setProcessor(reconstruct());
        canvas = new ImageCanvas(linear_reconstruction);
        
        //Make the image scrollable. This seems to work, if the correct cargo-culting
        //is performed with the gridbaglayout fill constraints. I don't really understand why.
        ScrollPane scroll = new ScrollPane();
        scroll.add(canvas);
        complete.add(scroll, canvas_pos());

        //Create the status message
        status = new JLabel();
        if(tbr != null)
            set_status("Running.");
        else
            set_status("Using loaded data.");
        complete.add(status, status_pos());
        
        //Create the ETA massage
        time_msg = new JLabel();
        if(tbr != null)
            set_time("unknown");
        else
            set_time("not running");
        complete.add(time_msg, time_pos());
        

        
        //The two control sliders
        blur_fwhm = new FloatSliderWithBox("Reconstruction blur FWHM", 0, 150, 100.0, 5, false);
        blur_fwhm.setUnits("nm").setFormat("%5.1f");
        blur_fwhm.addChangeListener(new SomethingChanges(this));
        complete.add(blur_fwhm, blur_pos());

        reconstructed_pixel_size = new FloatSliderWithBox("Reconstructed pixel size", 1, 300, 10.0, 5, true);
        reconstructed_pixel_size.setUnits("nm").setFormat("%5.1f");
        reconstructed_pixel_size.addChangeListener(new SomethingChanges(this));
        complete.add(reconstructed_pixel_size, pixel_size_pos());

        //The button bar
        buttons = new JPanel();
        
        exportButton = new JButton("Export...");
        exportButton.addActionListener(new ExportButtonListener(this));
        buttons.add(exportButton);
        exportButtonColor = exportButton.getBackground();
        
        //No point in having a stop button if this is just a viewer
        if(tbr != null)
        {
            stopButton = new JButton("Stop");
            stopButton.addActionListener(new StopButtonListener(this));
            buttons.add(stopButton);
        }

        closeButton = new JButton("Close");
        closeButton.addActionListener(new CloseButtonListener(this));
        buttons.add(closeButton);


        complete.add(buttons, buttons_pos());

        getContentPane().add(complete);
        
        //This class knows how to handle window close events.
        //Don't close the window by default, so we can try to bring up a 
        //confirmation dialog.
        addWindowListener(this);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        

        //Cargo culting...
        pack();
        setVisible(true);
        validate();


        //Start the 3B thread, if we have one to run.
        if(tbr != null)
        {
            tbr.register(this);
            Thread t = new Thread(tbr);
            t.start();
        }
    }

Member Function Documentation

GridBagConstraints EControlPanel::canvas_pos ( ) [inline, private]

Definition at line 1022 of file three_B.java.

Referenced by EControlPanel().

    {
        GridBagConstraints g = new GridBagConstraints();
        g.gridx = 0;
        g.gridy = 0;
        g.fill = GridBagConstraints.BOTH;
        g.weightx=100;
        g.weighty=100;
        return g;
    }
GridBagConstraints EControlPanel::status_pos ( ) [inline, private]

Definition at line 1033 of file three_B.java.

Referenced by EControlPanel().

    {
        GridBagConstraints g = new GridBagConstraints();
        g.gridx = 0;
        g.gridy = 1;
        g.anchor = GridBagConstraints.FIRST_LINE_START;
        g.fill = GridBagConstraints.BOTH;
        return g;
    }
GridBagConstraints EControlPanel::time_pos ( ) [inline, private]

Definition at line 1043 of file three_B.java.

Referenced by EControlPanel().

    {
        GridBagConstraints g = new GridBagConstraints();
        g.gridx = 0;
        g.gridy = 2;
        g.anchor = GridBagConstraints.FIRST_LINE_START;
        g.fill = GridBagConstraints.BOTH;
        return g;
    }
GridBagConstraints EControlPanel::buttons_pos ( ) [inline, private]

Definition at line 1052 of file three_B.java.

Referenced by EControlPanel().

    {
        GridBagConstraints g = new GridBagConstraints();
        g.gridx = 0;
        g.gridy = 5;
        g.fill = GridBagConstraints.BOTH;
        return g;
    }
GridBagConstraints EControlPanel::pixel_size_pos ( ) [inline, private]

Definition at line 1061 of file three_B.java.

Referenced by EControlPanel().

    {
        GridBagConstraints g = new GridBagConstraints();
        g.gridx = 0;
        g.gridy = 4;
        g.anchor = GridBagConstraints.FIRST_LINE_START;
        g.fill = GridBagConstraints.BOTH;
        return g;
    }
GridBagConstraints EControlPanel::blur_pos ( ) [inline, private]

Definition at line 1071 of file three_B.java.

Referenced by EControlPanel().

    {
        GridBagConstraints g = new GridBagConstraints();
        g.gridx = 0;
        g.gridy = 3;
        g.anchor = GridBagConstraints.FIRST_LINE_START;
        g.fill = GridBagConstraints.BOTH;
        return g;
    }
void EControlPanel::set_status ( String  s) [inline, private]

Definition at line 1081 of file three_B.java.

References status.

Referenced by EControlPanel(), and send_status_text_message().

    {
        status.setText("Status: " + s);
    }
void EControlPanel::set_time ( String  s) [inline, private]

Definition at line 1086 of file three_B.java.

References time_msg.

Referenced by EControlPanel(), and send_time_text_message().

    {
        time_msg.setText("Estimated time: " + s);
    }
synchronized void EControlPanel::update_canvas ( ) [inline, private]

Generic redraw function which recomputes the reconstruction.

this is a synchronized method since it makes use of the shared writable array of points.

Definition at line 1094 of file three_B.java.

References blur_fwhm, canvas, ThreeBGlobalConstants::critical_iterations, exportButton, exportButtonColor, FloatSliderWithBox::getValue(), iterations, linear_reconstruction, pixel_size_in_nm, reconstruct(), reconstructed_pixel_size, reconstruction_blur_fwhm, and zoom.

Referenced by send_update_canvas_event().

    {
        reconstruction_blur_fwhm = blur_fwhm.getValue();
        zoom = pixel_size_in_nm / reconstructed_pixel_size.getValue();

        linear_reconstruction.setProcessor(reconstruct());
        linear_reconstruction.updateImage();
        linear_reconstruction.updateAndRepaintWindow();
        canvas.repaint();   
        //Update the canvas size and viewport to prevent funny things with zooming.
        canvas.setDrawingSize(linear_reconstruction.getWidth(), linear_reconstruction.getHeight());
        canvas.setSourceRect(new Rectangle(linear_reconstruction.getWidth(), linear_reconstruction.getHeight()));
        //validate();
        //pack();

        if(iterations >= ThreeBGlobalConstants.critical_iterations)
        {
            exportButton.setBackground(exportButtonColor);
        }
        else
        {
            exportButton.setBackground(Color.RED);
        }

    }
void EControlPanel::windowOpened ( WindowEvent  e) [inline]

Definition at line 1123 of file three_B.java.

{ }
void EControlPanel::windowClosed ( WindowEvent  e) [inline]

Definition at line 1124 of file three_B.java.

{}
void EControlPanel::windowDeactivated ( WindowEvent  e) [inline]

Definition at line 1125 of file three_B.java.

{ }
void EControlPanel::windowActivated ( WindowEvent  e) [inline]

Definition at line 1126 of file three_B.java.

{ }
void EControlPanel::windowDeiconified ( WindowEvent  e) [inline]

Definition at line 1127 of file three_B.java.

{ }
void EControlPanel::windowIconified ( WindowEvent  e) [inline]

Definition at line 1128 of file three_B.java.

{ }
void EControlPanel::windowClosing ( WindowEvent  e) [inline]

Send a stop message to the thread if the window is closed.

Definition at line 1131 of file three_B.java.

References ThreeBRunner::has_stopped(), ThreeBRunner::stop_thread(), and tbr.

    {
        if(tbr != null && !tbr.has_stopped())
        {
            int confirmed = JOptionPane.showConfirmDialog(null, "3B still running! Closing will terminate the run. Really close?", "User Confirmation", JOptionPane.YES_NO_OPTION);

            if (confirmed == JOptionPane.YES_OPTION)
            {
                dispose();
                tbr.stop_thread();
            }

        }
        else
        {
            //OK to close
            dispose();
        }
    }
void EControlPanel::export_reconstruction_as_ij ( ) [inline, package]

Generate a fresh ImageJ image in a standard imageJ window, so that ti can be manipulated using the usual ImageJ commands.

The image is size calibrated, so scalebars are easy to add.

Definition at line 1154 of file three_B.java.

References filename, FloatSliderWithBox::getValue(), linear_reconstruction, and reconstructed_pixel_size.

Referenced by ExportButtonListener::actionPerformed().

    {
        ImageProcessor export = linear_reconstruction.getProcessor().duplicate();
        ImagePlus export_win = new ImagePlus(filename + " reconstruction", export);
        export_win.getCalibration().pixelWidth = reconstructed_pixel_size.getValue();
        export_win.getCalibration().pixelHeight = reconstructed_pixel_size.getValue();
        export_win.getCalibration().setXUnit("nm");
        export_win.getCalibration().setYUnit("nm");
        export_win.show();
        export_win.updateAndDraw();
    }
synchronized FloatProcessor EControlPanel::reconstruct ( ) [inline, private]

Compute a brand new reconstruction.

Definition at line 1167 of file three_B.java.

References pixel_size_in_nm, pts, reconstruction_blur_fwhm, roi, and zoom.

Referenced by EControlPanel(), and update_canvas().

    {
        //Reconstruct an image which is based around the ROI in size
        int xoff = (int)roi.x;
        int yoff = (int)roi.y;

        int xsize = (int)Math.ceil(roi.width * zoom);
        int ysize = (int)Math.ceil(roi.height * zoom);
        
        //New blank image set to zero
        FloatProcessor reconstructed = new FloatProcessor(xsize, ysize);

        for(int i=0; i < pts.size(); i++)
        {
            
            //Increment the count 
            int xc = (int)Math.floor((pts.get(i).x-xoff) * zoom + 0.5);
            int yc = (int)Math.floor((pts.get(i).y-yoff) * zoom + 0.5);
            float p = reconstructed.getPixelValue(xc, yc);
            reconstructed.putPixelValue(xc, yc, p+1);
        }

        double blur_sigma = reconstruction_blur_fwhm / (2 * Math.sqrt(2 * Math.log(2))) * zoom / pixel_size_in_nm;

        (new GaussianBlur()).blurGaussian(reconstructed, blur_sigma, blur_sigma, 0.005);
        return reconstructed;
    }
void EControlPanel::issue_stop ( ) [inline]

Definition at line 1196 of file three_B.java.

References ThreeBRunner::stop_thread(), stopButton, and tbr.

Referenced by StopButtonListener::actionPerformed().

    {
        if(tbr != null)
            tbr.stop_thread();
        stopButton.setEnabled(false);
    }
synchronized void EControlPanel::append ( final ArrayList< Spot p,
int  its 
) [inline]

Callback issued by the runnre thread which appends the latest set of points to the array.

This is synchronized since it involves the shared writable array of points.

Definition at line 1208 of file three_B.java.

References iterations, and pts.

Referenced by ThreeBLoader::run(), and ThreeBRunner::send_new_points().

    {
        for(int i=0; i < p.size(); i++)
            pts.add(p.get(i));

        iterations = its;
    }
void EControlPanel::send_update_canvas_event ( ) [inline]

Callback for causing a recomputation of the reconstruction.

This is a safe method for telling the class to recompute and redraw the reconstruction. It can be called from anywhere, but ensures that the redraw happens in the GUI thread.

Definition at line 1220 of file three_B.java.

References update_canvas().

Referenced by ThreeBLoader::run(), ThreeBRunner::send_new_points(), and SomethingChanges::stateChanged().

    {
        SwingUtilities.invokeLater(
            new Runnable() {
                final public void run() {
                        update_canvas();
                    }
                }
        );
    }
void EControlPanel::die ( final String  s) [inline]

Callback which causes a fatal termination of the 3B control panel.

This is generally caused by something changing such that the error condition was not seen in the Java code, but was seen in C++. Ought never to be called.

Definition at line 1235 of file three_B.java.

Referenced by ThreeBRunner::die().

    {
        SwingUtilities.invokeLater(
            new Runnable() {
                final public void run() {
                        ij.IJ.showStatus("3B run terminated due to an error.\n");
                        JOptionPane.showMessageDialog(null, "Error: "+s, "Fatal error", JOptionPane.ERROR_MESSAGE);
                        dispose();
                    }
                }
        );
    }
void EControlPanel::send_status_text_message ( final String  s) [inline]

Callback to update the status message safely.

Definition at line 1249 of file three_B.java.

References set_status().

Referenced by ThreeBLoader::run(), ThreeBRunner::run(), and ThreeBRunner::send_message_string().

    {
        SwingUtilities.invokeLater(
            new Runnable(){
                final public void run() {
                        set_status(s);
                    }
                }
        );
    }
void EControlPanel::send_time_text_message ( final String  s) [inline]

Callback to update the status message safely.

Definition at line 1262 of file three_B.java.

References set_time().

Referenced by ThreeBRunner::send_new_points().

    {
        SwingUtilities.invokeLater(
            new Runnable(){
                final public void run() {
                        set_time(s);
                    }
                }
        );
    }

Member Data Documentation

Definition at line 890 of file three_B.java.

Referenced by EControlPanel(), export_reconstruction_as_ij(), and update_canvas().

ImageCanvas EControlPanel::canvas [private]

Definition at line 891 of file three_B.java.

Referenced by EControlPanel(), and update_canvas().

JButton EControlPanel::stopButton [private]

Definition at line 892 of file three_B.java.

Referenced by EControlPanel(), and issue_stop().

JButton EControlPanel::exportButton [package]

Definition at line 892 of file three_B.java.

Referenced by EControlPanel(), and update_canvas().

JButton EControlPanel::closeButton [package]

Definition at line 892 of file three_B.java.

Referenced by EControlPanel().

Definition at line 893 of file three_B.java.

Referenced by EControlPanel(), and update_canvas().

JLabel EControlPanel::status [private]

Definition at line 894 of file three_B.java.

Referenced by EControlPanel(), and set_status().

JLabel EControlPanel::time_msg [package]

Definition at line 894 of file three_B.java.

Referenced by EControlPanel(), and set_time().

Definition at line 895 of file three_B.java.

Referenced by EControlPanel(), and update_canvas().

Definition at line 896 of file three_B.java.

Referenced by EControlPanel(), export_reconstruction_as_ij(), and update_canvas().

Panel EControlPanel::complete [private]

Definition at line 898 of file three_B.java.

Referenced by EControlPanel().

JPanel EControlPanel::buttons [private]

Definition at line 899 of file three_B.java.

Referenced by EControlPanel().

Definition at line 901 of file three_B.java.

Referenced by EControlPanel(), issue_stop(), and windowClosing().

ArrayList<Spot> EControlPanel::pts [private]

Definition at line 902 of file three_B.java.

Referenced by append(), EControlPanel(), and reconstruct().

Rectangle EControlPanel::roi [private]

Definition at line 905 of file three_B.java.

Referenced by EControlPanel(), and reconstruct().

double EControlPanel::zoom = 0.01 [private]

Definition at line 906 of file three_B.java.

Referenced by reconstruct(), and update_canvas().

Definition at line 908 of file three_B.java.

Referenced by reconstruct(), and update_canvas().

Definition at line 910 of file three_B.java.

Referenced by EControlPanel(), reconstruct(), and update_canvas().

String EControlPanel::filename [private]

Definition at line 911 of file three_B.java.

Referenced by EControlPanel(), and export_reconstruction_as_ij().

int EControlPanel::iterations = 0 [private]

Definition at line 915 of file three_B.java.

Referenced by append(), and update_canvas().


The documentation for this class was generated from the following file: