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); }
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; } } } }