import ij.*; import ij.measure.*; import ij.plugin.*; import ij.util.*; import ij.process.*; import ij.plugin.filter.*; import java.util.*; import ij.gui.*; public class ResultsAndText_gj implements PlugIn, Measurements { String readme= "This plug-in extends ResultsTable and TextPanel functions." +"\nThe Analyzer.ResultsTable is usually the pivot of an analysis process and" +"\n can be displayed on the IJ system TextPanel." +"\n " +"\nFile>SaveAs>measurements" +"\n saves the textpanel including text written by a plugin via IJ.write;" +"\n it does not save the resultsTable." +"\n " +"\nAnalyze>Clear Results" +"\n clears both the textpanel and resultsTable." +"\n " +"\nThis ResultsAndText plugin provides additional functions:" +"\n* TextPanel clear to headings/noheadings without clearing of ResultsTable" +"\n " +"\n* selective ResultsTable list," +"\n {eg after a (large) ResultsTable generated by analyzeParticles" +"\n used with Display Results unchecked or" +"\n ResultsTable columns extended post table creation}" +"\n" +"\n* save ResultsTable to a float image," +"\n* restore from the current float image" +"\n this version does not support row labels" +"\nThese functions allow checkpointing and restart or" +"\n remote pickup of a multiphase analysis process" +"\n where details (eg tracking data from extended analyzeParticles)" +"\n can be saved/restored for continuing or remote analysis." +"\n arg==\"about\": displays this message" +"\n arg==null: runs a demonstration sequence" +"\n arg==\"install\": installs plugin options" +GJx.sign ; public static final int CLEAR_HEAD=2,CLEAR=ParticleAnalyzer.CLEAR_WORKSHEET;//64 public void run(String arg) { StringTokenizer st=new StringTokenizer(arg); String verb=""; char action='0'; if (st.countTokens()>0)verb=st.nextToken(); if (verb.length()==1)action=verb.charAt(0); else{ String verbs="c clear,h heading,m measurements, r reset,l list,s save,t restore" +",a about,d readme,x concatReadme,i install,u uninstall"; int n=verbs.indexOf(verb); if(n>1)action=verbs.charAt(n-2); } //IJ.write(""+action); switch (action){ case 'c':{IJ.setColumnHeadings(""); break;} case 'h':{IJ.setColumnHeadings(Analyzer.getResultsTable().getColumnHeadings()); IJ.write(" ");//headings dont appear unless a line is written break;} case 'm':{new MeasurementsWriter().run(""); break;} case 'r':{Analyzer.getResultsTable().reset(); break;} case 'l':{new ResultsList(arg); break;} case 's':{new ResultsTable_Image("put"); break;} case 't':{new ResultsTable_Image("get"); // new ResultsList("list"); break;} case 'a':{if(!IJ.showMessageWithCancel("About ResultsAndText_gj",readme))return; break;} case 'd':{GJx.writeAbout("About ResultsAndText_gj",readme); break;} case 'x':{GJx.writeAbout("About ResultsAndText_gj",readme,false); break;} case 'i':{if(!IJ.showMessageWithCancel ("ResultsAndText_gj","InstallPluginsGJ"))return; (new InstallPluginsGJ()).run(""); break;} case 'u':{if(!IJ.showMessageWithCancel ("ResultsAndText_gj","UNInstallPluginsGJ"))return; (new InstallPluginsGJ()).run("un"); break;} default: case '0':{ if(!IJ.showMessageWithCancel("About ResultsAndText_gj",readme))return; if(!IJ.showMessageWithCancel("ResultsAndText_gj" ,"ResultsAndText\n Demonstration\n" +"\n before running, it best to ensure\n30+ lines are visible in worksheet textpanel")) return; IJ.showMessage("clear IJ textPanel &" +"\nclear Analyzer.ResultsTable"); IJ.setColumnHeadings(""); Analyzer.getResultsTable().reset(); IJ.showMessage("generate Analyzer.ResultsTable entries" +"\nclear Textpanel\nlist ResultsTable\n no headings"); testResults(31); new ResultsList(CLEAR); IJ.showMessage("clear Textpanel\n list ResultsTable with headings" +"\nsave ResultsTable in image" +"\n if saved ResultsTable_image is already current," +"\n then will restore ResultsTable"); new ResultsList(CLEAR_HEAD); new ResultsTable_Image();// no GRAY32 so write IJ.showMessage("restore ResultsTable from image"); new ResultsTable_Image();// GRAY32 image current so read IJ.showMessage("ResultsTable_list with headings"); new ResultsList(CLEAR_HEAD); IJ.showMessage("display About on textpanel worksheet"); GJx.writeAbout("About ResultsAndText_gj",readme); if(!IJ.showMessageWithCancel("ResultsAndText_gj","InstallPluginsGJ"))return; (new InstallPluginsGJ()).run(); } } } ResultsTable testResults(int n){ ResultsTable rt=Analyzer.getResultsTable(); rt.reset(); String[] headings={"","x","x^2","logX"}; int[]cols={1,2,3}; for(int i=0;i0){to_res=iargs[0];arg_set=true;} if (iargs.length>1)from_res=iargs[1]; }} rt = Analyzer.getResultsTable(); if (rt==null)if(!IJ.showMessageWithCancel("setup","null ResultsTable?"))return; rCount=rt.getCounter(); if(rCount==0)if(!IJ.showMessageWithCancel("setup","empty ResultsTable?"))return; if((this.options>=0) && (this.options&FROMFIRST)!=0){to_res=1;from_res=rCount;} else{to_res=rCount;from_res=0;} if(this.options<0)if(!showDialog())return; boolean selectCols=false; if((this.options&SELECTCOLS)!=0)selectCols=true; int rCount=rt.getCounter(); int n0,n1,n2,n3; if((this.options&FROMFIRST)>0){//"from n to m"} n0=to_res-1;n1=from_res;n2=0;n3=0; if(n1>rCount)n1=rCount; if(n1<0)n1=0;} else{//{"first n, last m", n1=to_res;n2=rCount-from_res;n0=0;n3=rCount; if(n1>rCount)n1=rCount; if(n2<=n1)n2=n1+1;} if((this.options & CLEAR)>0)IJ.setColumnHeadings(""); if((this.options & CLEAR_HEAD)>0) IJ.setColumnHeadings(selectCols?getColumnHeadings(rt):rt.getColumnHeadings()); //IJ.write(""+this.options+","+n0+","+n1+","+n2+","+n3+rt+colIs); //IJ.showMessage("options:"+this.options); for (int i=n0;i0); gd.showDialog(); if (gd.wasCanceled())return false; switch (gd.getNextChoiceIndex()){ case 0:{options&=~CLEAR;break;} case 1:{options|=CLEAR;break;} case 2:{options|=CLEAR_HEAD;break;}} if((gd.getNextChoiceIndex())==1)options|=FROMFIRST;else options &=~FROMFIRST; to_res = (int)gd.getNextNumber(); from_res = (int)gd.getNextNumber(); if (gd.invalidNumber()) { IJ.error("invalid number"); return false;} if(gd.getNextBoolean())options|=SELECTCOLS;else options&=~SELECTCOLS; staticOptions=options; if((options&SELECTCOLS)!=0){ if(getListCols(st,nCols))options |= CLEAR_HEAD; else return false;} staticOptions=options; return true; } public int[] s2ints(String s) { StringTokenizer st = new StringTokenizer(s, ", \t"); int nInts = st.countTokens(); int[] ints = new int[nInts]; for(int i=0; i8)fsl=8; y+=nCols;array[y]=fsl; for(int j=0;j=chs.length)r<<=8;else r=(r<<8)+chs[n+i];} return Float.intBitsToFloat(r); } static String decode(float[] fs){int p=0; char[] chs=new char[fs.length*4]; char[]ch4; for(int i=0;i>8*(3-i))&0xff); //IJ.write(""+chs[i]+"["+Integer.toHexString((n>>8*(3-i))&0xff) ); } return chs; } } class GJx{ public static String sign="" +"\n \nwritten by" +"\nGreg Joss, 1st March 2001 last modified 9th March 2001" +"\nDepartment of Biological Sciences, Phone: (61)(2) 9850 8212 Fax: 9850 8245" +"\nMacquarie University, Email: gjoss@rna.bio.mq.edu.au" +"\nNorth Ryde, (Sydney,) NSW 2109, Australia" +"\n \nAll comments, criticisms, suggestions, feedback or bug reports" +"\n would be gratefully received and appreciated." ; public static void writeAbout(String title, String readme) {writeAbout(title,readme,true);} public static void writeAbout(String title, String readme, boolean clear) { if (clear)IJ.setColumnHeadings(""); IJ.write(title+'\n'+readme); } } /** Adds a plugin based command to the end of a specified menu. * @param plugin the plugin name (e.g. "Inverter_", "Inverter_("about")") * @param menuCode PLUGINS_MENU, IMPORT_MENU or SAVE_AS_MENU * @param command the menu item label * @param command the keyboard shortcut (e.g. "y", "Y", "F1") * @param ij ImageJ (the action listener) * * @return returns an error code(NORMAL_RETURN,SHORTCUT_IN_USE_ERROR,etc.) */ //public //'public' requires separate source file class InstallPluginsGJ { ImageJ ij; public void run(){run("");} public void run(String arg) { if (arg=="about"){IJ.showMessage("Install_GJ_Plugins","all is Trivial");return;} String[][] ps = {{"-","-",""} ,{"ResultsAndText_gj(\"reset\")" ,"Results reset" ,"F1"} ,{"ResultsAndText_gj(\"list\")" ,"Results list" ,"F2"} ,{"ResultsAndText_gj(\"save\")" ,"Results save" ,"F3"} ,{"ResultsAndText_gj(\"restore\")" ,"Results restore" ,"F4"} ,{"-","-",""} ,{"ResultsAndText_gj(\"clear\")" ,"Worksheet clear" ,"F5"} ,{"ResultsAndText_gj(\"heading\")" ,"Worksheet clear to headings" ,"F6"} ,{"ResultsAndText_gj(\"measurements\")" ,"Worksheet saved as measurements" ,"F7"} ,{"-","-",""} ,{"ResultsAndText_gj(\"about\")" ,"ResultsAndText about" ,""} ,{"ResultsAndText_gj(\"readme\")" ,"ResultsAndText readme" ,""} ,{"ResultsAndText_gj(\"\")" ,"ResultsAndText demonstration" ,""} ,{"ResultsAndText_gj(\"x\")" ,"ResultsAndText install plugins",""} ,{"ResultsAndText_gj(\"u\")" ,"ResultsAndText uninstall" ,""} ,{"-","-",""} }; String[]rets={"NORMAL_RETURN","COMMAND_IN_USE","INVALID_SHORTCUT" ,"SHORTCUT_IN_USE","NOT_INSTALLED","COMMAND_NOT_FOUND"}; if (arg=="un"){int n=0; for (int i=0; i