getProcessor, viewer

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

getProcessor, viewer

Boizeau marielaure
Hello everybody,

 

I would like to make a little interface with 4 buttons and an image,
(easy when you know Panel_Window)

I would like to change images when i press to the first button, without
changing the panel.

I think everything is on those lines, but i send you all of my code
immediately after.

 

 this.imp=OpenImage(list[i]);
   IJ.showMessage ("Open image have been actionned and  +list[i] :
"+list[i]);
                 imp.getProcessor();
               imp.updateAndDraw();

public ImagePlus OpenImage(String image) {
  IJ.showMessage ("Open image have been actionned  ");
  IJ.open(image);
  IJ.run("Convert Stack to RGB");
  ImagePlus imp = WindowManager.getCurrentImage();
       ImageWindow win = IJ.getImage().getWindow();
  win.setBounds(win.getMaximumBounds());
  win.maximize();
  return imp ;
  }
 
 
Thanks for your help
 
ML
 
 
 
// **************************
 
import ij.plugin.*;
import ij.*;
import ij.gui.*;
import ij.process.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import ij.io.*;
import ij.measure.*;
import ij.plugin.filter.*;
import java.awt.event.*;
import ij.plugin.filter.PlugInFilter;
import ij.io.SaveDialog;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
 

/**
     Opens an image window and adds a panel below the image containing
"Invert" and
     "Flip" buttons. If no images are open, creates a blank 400x200 byte
image,
     otherwise.
*/
 
public class AAPanel_Window implements PlugIn  {
 
    static final int WIDTH = 400;
    static final int HEIGHT = 610;
    int titi=0;
    int i=0;
   String dir;
   String[] list;
   ImagePlus test;
   CustomCanvas cc;
 
 
  public void run(String arg) {
  IJ.showMessage ("Choose an image from your workspace ");
  OpenDialog od = new OpenDialog("Select a file in source folder...",
"");
  dir=od.getDirectory();
  list = new File(dir).list();
  if (list==null)
  return;
  int n = list.length;
  int[] cList= new int[n];
  IJ.open(list[0]);
  IJ.run("Convert Stack to RGB");
  ImagePlus imp = WindowManager.getCurrentImage();
       ImageWindow win = IJ.getImage().getWindow();
  win.setBounds(win.getMaximumBounds());
  win.maximize();
       cc = new CustomCanvas(imp);
            new CustomWindow(imp, cc);
 
    }
 
 
 

    //*******  CLASS CustomCanvas
  class CustomCanvas extends ImageCanvas {
        CustomCanvas(ImagePlus imp) {
            super(imp);
        }
   
        public void mousePressed(MouseEvent e) {
            super.mousePressed(e);
            IJ.write("mousePressed:
("+offScreenX(e.getX())+","+offScreenY(e.getY())+")");
        }
    } // CustomCanvas inner class
   
 

//*******  CLASS CustomWindow
class CustomWindow extends ImageWindow implements ActionListener {
        private Button button1, button2, button3, button4;
        CustomWindow(ImagePlus imp, ImageCanvas ic) {
            super(imp, ic);
            addPanel();
        }
   
        void addPanel() {
            Panel panel = new Panel();
            panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
            button1 = new Button(" Next");
            button1.addActionListener(this);
            panel.add(button1);
 
            button2 = new Button(" Previous ");
            button2.addActionListener(this);
            panel.add(button2);
 
 button3 = new Button(" TakeOff");
            button3.addActionListener(this);
            panel.add(button3);
 
 button4 = new Button(" Add ");
            button4.addActionListener(this);
            panel.add(button4);
            add(panel);
            pack();
 
      Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
            Point loc = getLocation();
            Dimension size = getSize();
            if (loc.y+size.height>screen.height)
                getCanvas().zoomOut(0, 0);
         }
     
        public void actionPerformed(ActionEvent e) {
            Object b = e.getSource();
 if (b==button1){
   i= i+1;
   this.imp=OpenImage(list[i]);
   IJ.showMessage ("Open image have been actionned and  +list[i] :
"+list[i]);
                 imp.getProcessor();
               imp.updateAndDraw();
//                imp.getProcessor().invert();
//                imp.updateAndDraw();
 
   } else {
    if (b==button2){i= i-1; }
     else {if (b==button3){TakeOff();}
      else {if (b==button4){ Add();}
        else { IJ.showMessage ("NOTHING HAVE BEEN DONE");}
      }
     }
   }
 }
 
   public ImagePlus OpenImage(String image) {
  IJ.showMessage ("Open image have been actionned  ");
  IJ.open(image);
  IJ.run("Convert Stack to RGB");
  ImagePlus imp = WindowManager.getCurrentImage();
       ImageWindow win = IJ.getImage().getWindow();
  win.setBounds(win.getMaximumBounds());
  win.maximize();
  return imp ;
  }
 
 void Add() {
  IJ.showMessage ("button3 Add ");
       }
 
 void TakeOff() {
  IJ.showMessage ("button4    TakeOff ");
       }
 
 
 

        }
       
    }