Login  Register

Re: Urgent: Unable to terminate plug-in

Posted by hlee19 on Jul 13, 2015; 10:12pm
URL: http://imagej.273.s1.nabble.com/Urgent-Unable-to-terminate-plug-in-tp5013523p5013539.html

Hello,
Thank you for the advice. The thing is, I would like to let the user cancel/exit the program in the middle, instead of being forced to keep selecting files/enter input.

Could you please let me know if there's anything wrong with my running the program as follows?:
-Copy the java files from Eclipse into a folder
-Place the folder in ImageJ's Plugins folder
-Open ImageJ
-Open the needed .im image
-Compile and run the one .java file (the rest are files with classes that determine a new Object or txt files)

My program takes an input txt file, finds the values the user wants to merge into one (i.e., the values 5 and 47 become 6000), creates and saves a new txt file to reflect that, uses the opened image's pixel values to do the same with the values (i.e., the pixels with values 5 and 47 have 6000 instead), and saves and opens the new image. I would also then like it to ask the user if he/she would like to run the plugin again, but that would be the next bit after fixing this bug.

Here is what the main part of the code looks like (before implementing your suggestion):

        public int setup(String arg, ImagePlus imp) {
                return DOES_STACKS+DOES_32;
        }

        public void run(ImageProcessor ip){
                if(!IJ.showMessageWithCancel("Merge Sections", "Please input the values you wish to combine into one section, each separated ONLY by a space."))
                                return;            //I would like the user to be able to exit the program at these return statements; but when the user clicks Cancel/exits, the program doesn't exit completely but rather comes back to run this method again
                String inputVals = IJ.getString("Values ", "0");
                if(inputVals.equals("")) return;
               
                String[] numToMerge = inputVals.split("\\s+"); //put the values into a String array
                if(!IJ.showMessageWithCancel("Merge Sections", "Values entered: " + inputVals + "\nPlease select a .txt file that contains the section names and values."))
                        return;
               
                OpenDialog od = new OpenDialog("Please select a .txt file that contains the section names and values.");
                File file = new File(od.getPath());  //file contains everything in the user-selected file
                String fileName = od.getFileName();
                if(fileName == null || !IJ.showMessageWithCancel("Merge Sections", "File selected: " + file.getName()))
                        return;
               
                DoublyLinkedList list = new DoublyLinkedList();
                DoublyLinkedList updatedList = new DoublyLinkedList();
                int mergedSecNum = 6000; //to be the starting number of the merged sections
               
                //updatedList has the merged sections; is the new list
                try {
                        updatedList = updateList(file, list, mergedSecNum, numToMerge, updatedList);
                } catch (FileNotFoundException e) {
                        GenericDialog d = new GenericDialog("");
                        d.addMessage("File not found!");
                        d.showDialog();
                        if(d.wasCanceled()) return;
                }
               
                ArrayList<String> al = new ArrayList<String>();
                ListNode cur = updatedList.getFirst();
                while(cur != null){
                        String s = cur.getValue().getName() + "\t" + cur.getValue().getNumber();
                        al.add(s);
                        cur = cur.getNext();
                }
                               
                TextPanel p = new TextPanel("");
                p.append(al);
                String[] sepFileName = removeFileExt(fileName);
                p.saveAs("C:\\Program Files (x86)\\ImageJ\\plugins\\Merge\\"+sepFileName[0]+((mergedSecNum-5990)/10)+"."+sepFileName[1]);
               
                ImagePlus imp = mergeInImage(numToMerge, mergedSecNum);
                imp.show();
                imp.unlock();
               
                return;

        }

Thank you very much, and please let me know if anything is obscure.