Beispiel #1
0
 /** Quit using a separate thread, hopefully avoiding thread deadlocks. */
 public void run() {
   quitting = true;
   boolean changes = false;
   int[] wList = WindowManager.getIDList();
   if (wList != null) {
     for (int i = 0; i < wList.length; i++) {
       ImagePlus imp = WindowManager.getImage(wList[i]);
       if (imp != null && imp.changes == true) {
         changes = true;
         break;
       }
     }
   }
   Frame[] frames = WindowManager.getNonImageWindows();
   if (frames != null) {
     for (int i = 0; i < frames.length; i++) {
       if (frames[i] != null && (frames[i] instanceof Editor)) {
         if (((Editor) frames[i]).fileChanged()) {
           changes = true;
           break;
         }
       }
     }
   }
   if (windowClosed
       && !changes
       && Menus.window.getItemCount() > Menus.WINDOW_MENU_ITEMS
       && !(IJ.macroRunning() && WindowManager.getImageCount() == 0)) {
     GenericDialog gd = new GenericDialog("ImageJ", this);
     gd.addMessage("Are you sure you want to quit ImageJ?");
     gd.showDialog();
     quitting = !gd.wasCanceled();
     windowClosed = false;
   }
   if (!quitting) return;
   if (!WindowManager.closeAllWindows()) {
     quitting = false;
     return;
   }
   // IJ.log("savePreferences");
   if (applet == null) {
     saveWindowLocations();
     Prefs.savePreferences();
   }
   IJ.cleanup();
   // setVisible(false);
   // IJ.log("dispose");
   dispose();
   if (exitWhenQuitting) System.exit(0);
 }
Beispiel #2
0
 public void itemStateChanged(ItemEvent e) {
   ImagePlus imp = WindowManager.getCurrentImage();
   if (imp == null) return;
   if (!imp.isComposite()) {
     int channels = imp.getNChannels();
     if (channels == 1 && imp.getStackSize() <= 4) channels = imp.getStackSize();
     if (imp.getBitDepth() == 24 || (channels > 1 && channels < CompositeImage.MAX_CHANNELS)) {
       GenericDialog gd = new GenericDialog(imp.getTitle());
       gd.addMessage("Convert to multi-channel composite image?");
       gd.showDialog();
       if (gd.wasCanceled()) return;
       else IJ.doCommand("Make Composite");
     } else {
       IJ.error(
           "Channels",
           "A composite image is required (e.g., "
               + moreLabel
               + " Open HeLa Cells),\nor create one using "
               + moreLabel
               + " Make Composite.");
       return;
     }
   }
   if (!imp.isComposite()) return;
   CompositeImage ci = (CompositeImage) imp;
   Object source = e.getSource();
   if (source == choice) {
     int index = ((Choice) source).getSelectedIndex();
     switch (index) {
       case 0:
         ci.setMode(IJ.COMPOSITE);
         break;
       case 1:
         ci.setMode(IJ.COLOR);
         break;
       case 2:
         ci.setMode(IJ.GRAYSCALE);
         break;
     }
     ci.updateAndDraw();
     if (Recorder.record) {
       String mode = null;
       switch (index) {
         case 0:
           mode = "composite";
           break;
         case 1:
           mode = "color";
           break;
         case 2:
           mode = "grayscale";
           break;
       }
       Recorder.record("Stack.setDisplayMode", mode);
     }
   } else if (source instanceof Checkbox) {
     for (int i = 0; i < checkbox.length; i++) {
       Checkbox cb = (Checkbox) source;
       if (cb == checkbox[i]) {
         if (ci.getMode() == IJ.COMPOSITE) {
           boolean[] active = ci.getActiveChannels();
           active[i] = cb.getState();
           if (Recorder.record) {
             String str = "";
             for (int c = 0; c < ci.getNChannels(); c++) str += active[c] ? "1" : "0";
             Recorder.record("Stack.setActiveChannels", str);
             Recorder.record("//Stack.toggleChannel", imp.getChannel());
           }
         } else {
           imp.setPosition(i + 1, imp.getSlice(), imp.getFrame());
           if (Recorder.record) Recorder.record("Stack.setChannel", i + 1);
         }
         ci.updateAndDraw();
         return;
       }
     }
   }
 }