示例#1
0
 public void update() {
   CompositeImage ci = getImage();
   if (ci == null || checkbox == null) return;
   int n = checkbox.length;
   int nChannels = ci.getNChannels();
   if (nChannels != n && nChannels <= CompositeImage.MAX_CHANNELS) {
     instance = null;
     location = getLocation();
     close();
     new Channels();
     return;
   }
   boolean[] active = ci.getActiveChannels();
   for (int i = 0; i < checkbox.length; i++) checkbox[i].setState(active[i]);
   int index = 0;
   switch (ci.getMode()) {
     case IJ.COMPOSITE:
       index = 0;
       break;
     case IJ.COLOR:
       index = 1;
       break;
     case IJ.GRAYSCALE:
       index = 2;
       break;
   }
   choice.select(index);
 }
示例#2
0
 /**
  * Copies the LUTs and display mode of 'imp' to this image. Does nothing if 'imp' is not a
  * CompositeImage or 'imp' and this image do not have the same number of channels.
  */
 public synchronized void copyLuts(ImagePlus imp) {
   int channels = getNChannels();
   if (!imp.isComposite() || imp.getNChannels() != channels) return;
   CompositeImage ci = (CompositeImage) imp;
   LUT[] luts = ci.getLuts();
   if (luts != null && luts.length == channels) {
     lut = luts;
     cip = null;
   }
   int mode2 = ci.getMode();
   setMode(mode2);
   if (mode2 == COMPOSITE) {
     boolean[] active2 = ci.getActiveChannels();
     for (int i = 0; i < MAX_CHANNELS; i++) active[i] = active2[i];
   }
   if (ci.hasCustomLuts()) customLuts = true;
 }
示例#3
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;
       }
     }
   }
 }