| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 
 |  
import ij.*;
import ij.gui.*;
import ij.process.*;
import ij.io.*;
import ij.io.FileSaver;
import java.io.*;
import java.awt.* ;
import java.awt.image.*;
import javax.swing.* ;
import java.awt.event.*;
import ij.plugin.*;
import ij.plugin.PlugIn;
import java.util.regex.* ;
 
public class stk_image_ implements PlugIn
{
       public void run(String str)
       {
      	      Runtime.getRuntime().gc();
              JFrame fen = new MaFenetre() ;
              fen.setVisible(true) ;
       }
}
//class qui charge la dll C
class Main
{
       static {System.loadLibrary("Analyse");}
       public static native int Tifftranslate(String j);
}
 
class MaFenetre extends JFrame
{
	private JMenuBar barreMenus ;
	private JMenu fichier ;
	private JMenuItem ouvrir,fermer,ouvrirs;
	public MaFenetre ()
	{
	       setTitle("Image stack Plugin!") ;
	       setBounds(10,40,250,200) ;
	       barreMenus = new JMenuBar() ;
	       setJMenuBar(barreMenus) ;
	       fichier = new JMenu("Fichier") ;
	       barreMenus.add(fichier) ;
	       ouvrir = new JMenuItem("Charger un fichier .stk") ;
	       fichier.add(ouvrir) ;
	       ouvrirs = new JMenuItem("Charger un répertoire (*.stk)") ;
	       fichier.add(ouvrirs) ;
	       fermer = new JMenuItem("Quitter") ;
	       fichier.add(fermer) ;
           ouvrir.addActionListener(new ArborescenceFichier());
           ouvrirs.addActionListener(new ArborescenceDossier());
           fermer.addActionListener(new QuitterProg());
	}
}
 
 
class ArborescenceFichier implements ActionListener 
{
    public void actionPerformed(ActionEvent e)
    {
		JFileChooser filechoose = new JFileChooser();
		filechoose.setCurrentDirectory(new File("."));
		String approve = new String("Ouvrir");
        String monfichier= null;
		int resultatEnregistrer = filechoose.showDialog(filechoose,approve);
		if (resultatEnregistrer == JFileChooser.APPROVE_OPTION)
			monfichier = filechoose.getSelectedFile().toString();
		Thread thr1 = new ThreadImage("Image",monfichier);//premier thread qui affiche l'image
		Thread thr2 = new ThreadCommunicationC("Communication",monfichier);//2eme thread qui lance la dll
 
		thr1.start();
        try{
        	thr1.join();
        	} 
        catch (InterruptedException err) 
        	{
        		IJ.showMessage("erreur!!");
        		return;
        	}
 
		thr2.start();
        try{
        	thr2.join();
        	} 
        catch (InterruptedException err) 
        	{
        		IJ.showMessage("erreur!!");
        		return;
        	}//on attend que le thread est terminé pour continuer le prog
    	Pattern p=Pattern.compile("\\.");
    	String[] items = p.split(monfichier);
    	String result=null;
    	if (monfichier.indexOf(".stk")!=-1)
    		result=items[0]+".rect.stk";
    	else if (monfichier.indexOf(".STK")!=-1)
    		result=items[0]+".rect.STK";
    	else IJ.showMessage("problème d'ouverture de fichier de sortie");
    	IJ.open(result);
    }
}
 
class ThreadImage extends Thread
{
	private String threadName;
	private String path;
	public ThreadImage(String threadName,String path) 
	{
        this.threadName = threadName;
        this.path=path;
    }
	public void run() 
	{
		IJ.open(path);
	}
} 
class ThreadCommunicationC extends Thread
{
	private String threadName;
	private String path;
	public ThreadCommunicationC(String threadName,String path) 
	{
        this.threadName = threadName;
        this.path=path;
    }
	public void run() 
	{
		//Splash s = new Splash();
    	Main communicationc=new Main();
    	communicationc.Tifftranslate(path);
	}
}
class ArborescenceDossier implements ActionListener 
{
    public void actionPerformed(ActionEvent e) 
    {
		File mondossier= null;
		int j=0;
		String[] list=null;
		String[] fichierstk=null;
		JFileChooser filechoose = new JFileChooser();
		filechoose.setCurrentDirectory(new File("."));
		filechoose.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY );
		String approve = new String("Charger");
		int resultatEnregistrer = filechoose.showDialog(filechoose,approve); 
		if (resultatEnregistrer == JFileChooser.APPROVE_OPTION) 
			mondossier = filechoose.getSelectedFile();
		list = mondossier.list();
		for(int i = 0; i < list.length; i++)
			if (list[i].endsWith(".sh"))
			{
				fichierstk[j]=list[i];
				j++;
			}
    }
}
class QuitterProg implements ActionListener 
{
      public void actionPerformed(ActionEvent e)
      {
    	     System.exit(0);
      }
} | 
Partager