001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.gui.menu;
020
021import icy.action.FileActions;
022import icy.action.SequenceOperationActions;
023import icy.action.SequenceOperationActions.ExtractChannelAction;
024import icy.action.SequenceOperationActions.RemoveChannelAction;
025import icy.gui.component.button.IcyCommandButton;
026import icy.gui.component.button.IcyCommandMenuButton;
027import icy.gui.component.button.IcyCommandToggleMenuButton;
028import icy.gui.util.RibbonUtil;
029import icy.main.Icy;
030import icy.resource.ResourceUtil;
031import icy.resource.icon.IcyIcon;
032import icy.sequence.Sequence;
033import icy.system.thread.ThreadUtil;
034import icy.type.DataType;
035import icy.util.StringUtil;
036
037import org.pushingpixels.flamingo.api.common.CommandToggleButtonGroup;
038import org.pushingpixels.flamingo.api.common.JCommandButton;
039import org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonKind;
040import org.pushingpixels.flamingo.api.common.RichTooltip;
041import org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu;
042import org.pushingpixels.flamingo.api.common.popup.JPopupPanel;
043import org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback;
044import org.pushingpixels.flamingo.api.ribbon.JRibbonBand;
045import org.pushingpixels.flamingo.api.ribbon.RibbonElementPriority;
046import org.pushingpixels.flamingo.api.ribbon.RibbonTask;
047
048/**
049 * @author Stephane
050 */
051public class SequenceOperationTask extends RibbonTask
052{
053    public static class FileBand extends JRibbonBand
054    {
055        /**
056        *
057        */
058        private static final long serialVersionUID = -2677243480668715388L;
059
060        public static final String BAND_NAME = "File";
061
062        final IcyCommandButton openButton;
063        final IcyCommandButton openRegionButton;
064        final IcyCommandButton saveButton;
065
066        public FileBand()
067        {
068            super(BAND_NAME, new IcyIcon(ResourceUtil.ICON_DOC));
069
070            openButton = new IcyCommandButton(FileActions.openSequenceAction);
071            openRegionButton = new IcyCommandButton(FileActions.openSequenceRegionAction);
072            // openAreaButton = new IcyCommandButton("Open region", new IcyIcon(ResourceUtil.ICON_CROP));
073            // openAreaButton.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
074            // openAreaButton.setPopupRichTooltip(new RichTooltip("Open selected region",
075            // "Open the selected ROI region from the original image at a specific resolution level"));
076            // openAreaButton.setPopupCallback(new PopupPanelCallback()
077            // {
078            // @Override
079            // public JPopupPanel getPopupPanel(JCommandButton commandButton)
080            // {
081            // final JCommandPopupMenu result = new JCommandPopupMenu();
082            //
083            // for (int r = 0; r < 5; r++)
084            // result.addMenuButton(new IcyCommandMenuButton(new OpenSequenceRegionAction(r)));
085            //
086            // return result;
087            // }
088            // });
089            saveButton = new IcyCommandButton(FileActions.saveAsSequenceAction);
090
091            addCommandButton(openButton, RibbonElementPriority.MEDIUM);
092            addCommandButton(openRegionButton, RibbonElementPriority.MEDIUM);
093            addCommandButton(saveButton, RibbonElementPriority.MEDIUM);
094
095            RibbonUtil.setRestrictiveResizePolicies(this);
096            updateButtonsState();
097        }
098
099        void updateButtonsState()
100        {
101            final Sequence sequence = Icy.getMainInterface().getActiveSequence();
102
103            openRegionButton.setEnabled(
104                    (sequence != null) && (!StringUtil.isEmpty(sequence.getFilename())) && sequence.hasSelectedROI());
105            saveButton.setEnabled(Icy.getMainInterface().getActiveSequence() != null);
106        }
107    }
108
109    public static class CopyConvertBand extends JRibbonBand
110    {
111        /**
112         * 
113         */
114        private static final long serialVersionUID = -2677243480668715388L;
115
116        public static final String BAND_NAME = "Copy / Convert";
117
118        final IcyCommandButton cloneButton;
119        final IcyCommandButton convertButton;
120        final IcyCommandButton convertButtonRaw;
121
122        public CopyConvertBand()
123        {
124            super(BAND_NAME, new IcyIcon(ResourceUtil.ICON_TOOLS));
125
126            setToolTipText("Copy and data type conversion operation");
127
128            // clone sequence
129            cloneButton = new IcyCommandButton(SequenceOperationActions.cloneSequenceAction);
130            addCommandButton(cloneButton, RibbonElementPriority.MEDIUM);
131
132            // data type conversion
133            convertButton = new IcyCommandButton("Conversion", new IcyIcon(ResourceUtil.ICON_BAND_RIGHT));
134            convertButton.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
135            convertButton.setPopupRichTooltip(new RichTooltip("Data type conversion",
136                    "Convert the sequence to the selected data type (values are scaled to fit the new type)"));
137            convertButton.setPopupCallback(new PopupPanelCallback()
138            {
139                @Override
140                public JPopupPanel getPopupPanel(JCommandButton commandButton)
141                {
142                    final JCommandPopupMenu result = new JCommandPopupMenu();
143                    final Sequence sequence = Icy.getMainInterface().getActiveSequence();
144
145                    if (sequence != null)
146                    {
147                        final CommandToggleButtonGroup group = new CommandToggleButtonGroup();
148
149                        result.addMenuButton(getConvertButton(sequence, DataType.UBYTE, true, group));
150                        result.addMenuButton(getConvertButton(sequence, DataType.BYTE, true, group));
151                        result.addMenuButton(getConvertButton(sequence, DataType.USHORT, true, group));
152                        result.addMenuButton(getConvertButton(sequence, DataType.SHORT, true, group));
153                        result.addMenuButton(getConvertButton(sequence, DataType.UINT, true, group));
154                        result.addMenuButton(getConvertButton(sequence, DataType.INT, true, group));
155                        result.addMenuButton(getConvertButton(sequence, DataType.FLOAT, true, group));
156                        result.addMenuButton(getConvertButton(sequence, DataType.DOUBLE, true, group));
157                    }
158
159                    return result;
160                }
161            });
162            addCommandButton(convertButton, RibbonElementPriority.MEDIUM);
163
164            // data type conversion
165            convertButtonRaw = new IcyCommandButton("Raw conversion", new IcyIcon(ResourceUtil.ICON_BAND_RIGHT));
166            convertButtonRaw.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
167            convertButtonRaw.setPopupRichTooltip(new RichTooltip("Raw data type conversion",
168                    "Convert the sequence to the selected data type (values remain unchanged or are clamped in case of overflow)"));
169            convertButtonRaw.setPopupCallback(new PopupPanelCallback()
170            {
171                @Override
172                public JPopupPanel getPopupPanel(JCommandButton commandButton)
173                {
174                    final JCommandPopupMenu result = new JCommandPopupMenu();
175                    final Sequence sequence = Icy.getMainInterface().getActiveSequence();
176
177                    if (sequence != null)
178                    {
179                        final CommandToggleButtonGroup group = new CommandToggleButtonGroup();
180
181                        result.addMenuButton(getConvertButton(sequence, DataType.UBYTE, false, group));
182                        result.addMenuButton(getConvertButton(sequence, DataType.BYTE, false, group));
183                        result.addMenuButton(getConvertButton(sequence, DataType.USHORT, false, group));
184                        result.addMenuButton(getConvertButton(sequence, DataType.SHORT, false, group));
185                        result.addMenuButton(getConvertButton(sequence, DataType.UINT, false, group));
186                        result.addMenuButton(getConvertButton(sequence, DataType.INT, false, group));
187                        result.addMenuButton(getConvertButton(sequence, DataType.FLOAT, false, group));
188                        result.addMenuButton(getConvertButton(sequence, DataType.DOUBLE, false, group));
189                    }
190
191                    return result;
192                }
193            });
194            addCommandButton(convertButtonRaw, RibbonElementPriority.MEDIUM);
195
196            RibbonUtil.setRestrictiveResizePolicies(this);
197            updateButtonsState();
198        }
199
200        public static IcyCommandToggleMenuButton getConvertButton(final Sequence sequence, final DataType dataType,
201                final boolean scaled, CommandToggleButtonGroup group)
202        {
203            final IcyCommandToggleMenuButton result = new IcyCommandToggleMenuButton(
204                    SequenceOperationActions.getConvertSequenceAction(dataType, scaled));
205
206            group.add(result);
207
208            // sequence has same datatype ?
209            if (sequence.getDataType_() == dataType)
210            {
211                // select and disable it
212                group.setSelected(result, true);
213                result.setEnabled(false);
214            }
215            else
216                group.setSelected(result, false);
217
218            return result;
219        }
220
221        void updateButtonsState()
222        {
223            final Sequence seq = Icy.getMainInterface().getActiveSequence();
224            final boolean enabled = (seq != null);
225            final boolean notEmpty = (seq != null) && !seq.isEmpty();
226
227            cloneButton.setEnabled(enabled);
228            convertButton.setEnabled(notEmpty);
229            convertButtonRaw.setEnabled(notEmpty);
230        }
231    }
232
233    public static class RenderingBand extends JRibbonBand
234    {
235        /**
236         * 
237         */
238        private static final long serialVersionUID = -2677243480668715388L;
239
240        public static final String BAND_NAME = "Rendering";
241
242        final IcyCommandButton argbButton;
243        final IcyCommandButton rgbButton;
244        final IcyCommandButton grayButton;
245
246        public RenderingBand()
247        {
248            super(BAND_NAME, new IcyIcon(ResourceUtil.ICON_TOOLS));
249
250            setToolTipText("Color and gray rendering");
251
252            // ARGB rendering
253            argbButton = new IcyCommandButton(SequenceOperationActions.argbSequenceAction);
254            addCommandButton(argbButton, RibbonElementPriority.MEDIUM);
255
256            // RGB rendering
257            rgbButton = new IcyCommandButton(SequenceOperationActions.rgbSequenceAction);
258            addCommandButton(rgbButton, RibbonElementPriority.MEDIUM);
259
260            // Gray rendering
261            grayButton = new IcyCommandButton(SequenceOperationActions.graySequenceAction);
262            addCommandButton(grayButton, RibbonElementPriority.MEDIUM);
263
264            RibbonUtil.setRestrictiveResizePolicies(this);
265            updateButtonsState();
266        }
267
268        void updateButtonsState()
269        {
270            final Sequence seq = Icy.getMainInterface().getActiveSequence();
271            final boolean enabled = (seq != null) && !seq.isEmpty();
272
273            argbButton.setEnabled(enabled);
274            rgbButton.setEnabled(enabled);
275            grayButton.setEnabled(enabled);
276        }
277    }
278
279    public static class PlanarOperationBand extends JRibbonBand
280    {
281        /**
282         * 
283         */
284        private static final long serialVersionUID = -7475753600896040618L;
285
286        private static final String BAND_NAME = "Plane (XY)";
287
288        final IcyCommandButton cropButton;
289        final IcyCommandButton canvasResizeButton;
290        final IcyCommandButton imageResizeButton;
291
292        // final IcyCommandButton mergeButton;
293
294        public PlanarOperationBand()
295        {
296            super(BAND_NAME, new IcyIcon(ResourceUtil.ICON_PICTURE));
297
298            setToolTipText("XY (plane) operation");
299
300            // fast crop operation
301            cropButton = new IcyCommandButton(SequenceOperationActions.cropSequenceAction);
302            addCommandButton(cropButton, RibbonElementPriority.MEDIUM);
303
304            // canvas resize operation
305            canvasResizeButton = new IcyCommandButton(SequenceOperationActions.canvasResizeAction);
306            addCommandButton(canvasResizeButton, RibbonElementPriority.MEDIUM);
307
308            // image resize operation
309            imageResizeButton = new IcyCommandButton(SequenceOperationActions.imageResizeAction);
310            addCommandButton(imageResizeButton, RibbonElementPriority.MEDIUM);
311
312            // merge operation
313            // mergeButton = new IcyCommandButton("Merge...");
314            // mergeButton.setActionRichTooltip(new RichTooltip("Resize image",
315            // "Resize an image using different policies."));
316            // mergeButton.addActionListener(new ActionListener()
317            // {
318            // @Override
319            // public void actionPerformed(ActionEvent e)
320            // {
321            // }
322            // });
323            // not yet implemented
324            // addCommandButton(mergeButton, RibbonElementPriority.MEDIUM);
325
326            RibbonUtil.setRestrictiveResizePolicies(this);
327            updateButtonsState();
328        }
329
330        void updateButtonsState()
331        {
332            final Sequence seq = Icy.getMainInterface().getActiveSequence();
333            final boolean enabled = (seq != null) && !seq.isEmpty();
334
335            cropButton.setEnabled(enabled);
336            canvasResizeButton.setEnabled(enabled);
337            imageResizeButton.setEnabled(enabled);
338            // mergeButton.setEnabled(enabled);
339        }
340    }
341
342    public static class ChannelOperationBand extends JRibbonBand
343    {
344        /**
345         * 
346         */
347        private static final long serialVersionUID = -2677243480668715388L;
348
349        public static final String BAND_NAME = "Channel (C)";
350
351        final IcyCommandButton extractButton;
352        final IcyCommandButton removeButton;
353        final IcyCommandButton mergeButton;
354
355        public ChannelOperationBand()
356        {
357            super(BAND_NAME, new IcyIcon(ResourceUtil.ICON_TOOLS));
358
359            setToolTipText("Channel operation");
360
361            // single channel extraction
362            extractButton = new IcyCommandButton("Extract", new IcyIcon(ResourceUtil.ICON_INDENT_DECREASE));
363            extractButton.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
364            extractButton.setPopupRichTooltip(new RichTooltip("Single channel extraction",
365                    "Create a new single channel sequence from selected channel of active sequence."));
366            extractButton.setPopupCallback(new PopupPanelCallback()
367            {
368                @Override
369                public JPopupPanel getPopupPanel(JCommandButton commandButton)
370                {
371                    final JCommandPopupMenu result = new JCommandPopupMenu();
372                    final Sequence sequence = Icy.getMainInterface().getActiveSequence();
373
374                    if (sequence != null)
375                    {
376                        for (int c = 0; c < sequence.getSizeC(); c++)
377                        {
378                            final IcyCommandMenuButton button;
379
380                            if (c < SequenceOperationActions.extractChannelActions.length)
381                                button = new IcyCommandMenuButton(SequenceOperationActions.extractChannelActions[c]);
382                            else
383                                button = new IcyCommandMenuButton(new ExtractChannelAction(c));
384
385                            result.addMenuButton(button);
386                        }
387
388                        result.addMenuButton(
389                                new IcyCommandMenuButton(SequenceOperationActions.extractAllChannelAction));
390                    }
391
392                    return result;
393                }
394            });
395            addCommandButton(extractButton, RibbonElementPriority.MEDIUM);
396
397            // single channel remove
398            removeButton = new IcyCommandButton("Remove", new IcyIcon(ResourceUtil.ICON_INDENT_REMOVE));
399            removeButton.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
400            removeButton.setPopupRichTooltip(
401                    new RichTooltip("Remove channel", "Remove the selected channel from active sequence."));
402            removeButton.setPopupCallback(new PopupPanelCallback()
403            {
404                @Override
405                public JPopupPanel getPopupPanel(JCommandButton commandButton)
406                {
407                    final JCommandPopupMenu result = new JCommandPopupMenu();
408                    final Sequence sequence = Icy.getMainInterface().getActiveSequence();
409
410                    if (sequence != null)
411                    {
412                        for (int c = 0; c < sequence.getSizeC(); c++)
413                        {
414                            final IcyCommandMenuButton button;
415
416                            if (c < SequenceOperationActions.removeChannelActions.length)
417                                button = new IcyCommandMenuButton(SequenceOperationActions.removeChannelActions[c]);
418                            else
419                                button = new IcyCommandMenuButton(new RemoveChannelAction(c));
420
421                            result.addMenuButton(button);
422                        }
423                    }
424
425                    return result;
426                }
427            });
428            addCommandButton(removeButton, RibbonElementPriority.MEDIUM);
429
430            // channel merge operation
431            mergeButton = new IcyCommandButton(SequenceOperationActions.mergeChannelsAction);
432            addCommandButton(mergeButton, RibbonElementPriority.MEDIUM);
433
434            RibbonUtil.setRestrictiveResizePolicies(this);
435            updateButtonsState();
436        }
437
438        void updateButtonsState()
439        {
440            final Sequence seq = Icy.getMainInterface().getActiveSequence();
441            final boolean enabled = (seq != null);
442            final boolean several = (seq != null) && (seq.getSizeC() > 1);
443
444            extractButton.setEnabled(several);
445            removeButton.setEnabled(several);
446            mergeButton.setEnabled(enabled);
447        }
448    }
449
450    public static class ZOperationBand extends JRibbonBand
451    {
452        /**
453         * 
454         */
455        private static final long serialVersionUID = 8301134961618666184L;
456
457        public static final String BAND_NAME = "Stack (Z)";
458
459        final IcyCommandButton reverseButton;
460        final IcyCommandButton extractButton;
461        final IcyCommandButton removeButton;
462        final IcyCommandButton advancedRemoveButton;
463        final IcyCommandButton addButton;
464        final IcyCommandButton mergeButton;
465
466        public ZOperationBand()
467        {
468            super(BAND_NAME, new IcyIcon(ResourceUtil.ICON_LAYER_V1));
469
470            setToolTipText("Z (stack) operation");
471
472            // reverse slices
473            reverseButton = new IcyCommandButton(SequenceOperationActions.reverseSlicesAction);
474            addCommandButton(reverseButton, RibbonElementPriority.MEDIUM);
475
476            // slice extraction
477            extractButton = new IcyCommandButton(SequenceOperationActions.extractSliceAction);
478            addCommandButton(extractButton, RibbonElementPriority.MEDIUM);
479
480            // slice remove
481            removeButton = new IcyCommandButton(SequenceOperationActions.removeSliceAction);
482            addCommandButton(removeButton, RibbonElementPriority.MEDIUM);
483
484            // ADVANCED
485            startGroup();
486
487            // add slices
488            addButton = new IcyCommandButton(SequenceOperationActions.addSlicesAction);
489            addCommandButton(addButton, RibbonElementPriority.MEDIUM); // advanced Z slice remove
490
491            // slices merge
492            mergeButton = new IcyCommandButton(SequenceOperationActions.mergeSlicesAction);
493            addCommandButton(mergeButton, RibbonElementPriority.MEDIUM);
494
495            // advanced slice remove
496            advancedRemoveButton = new IcyCommandButton(SequenceOperationActions.removeSlicesAction);
497            addCommandButton(advancedRemoveButton, RibbonElementPriority.MEDIUM);
498
499            RibbonUtil.setRestrictiveResizePolicies(this);
500            updateButtonsState();
501        }
502
503        void updateButtonsState()
504        {
505            final Sequence seq = Icy.getMainInterface().getActiveSequence();
506            final boolean enabled = (seq != null);
507            final boolean notEmpty = (seq != null) && !seq.isEmpty();
508            final boolean several = (seq != null) && (seq.getSizeZ() > 1);
509
510            reverseButton.setEnabled(several);
511            extractButton.setEnabled(several);
512            removeButton.setEnabled(several);
513            addButton.setEnabled(notEmpty);
514            mergeButton.setEnabled(enabled);
515            advancedRemoveButton.setEnabled(several);
516        }
517    }
518
519    public static class TOperationBand extends JRibbonBand
520    {
521        /**
522         * 
523         */
524        private static final long serialVersionUID = 3728386745443331069L;
525
526        public static final String BAND_NAME = "Frame (T)";
527
528        final IcyCommandButton reverseButton;
529        final IcyCommandButton extractButton;
530        final IcyCommandButton removeButton;
531        final IcyCommandButton advancedRemoveButton;
532        final IcyCommandButton addButton;
533        final IcyCommandButton mergeButton;
534
535        public TOperationBand()
536        {
537            super(BAND_NAME, new IcyIcon(ResourceUtil.ICON_LAYER_H1));
538
539            setToolTipText("T (frame) operation");
540
541            // reverse frames
542            reverseButton = new IcyCommandButton(SequenceOperationActions.reverseFramesAction);
543            addCommandButton(reverseButton, RibbonElementPriority.MEDIUM);
544
545            // frame extraction
546            extractButton = new IcyCommandButton(SequenceOperationActions.extractFrameAction);
547            addCommandButton(extractButton, RibbonElementPriority.MEDIUM);
548
549            // frame remove
550            removeButton = new IcyCommandButton(SequenceOperationActions.removeFrameAction);
551            addCommandButton(removeButton, RibbonElementPriority.MEDIUM);
552
553            // ADVANCED
554            startGroup();
555
556            // add frames
557            addButton = new IcyCommandButton(SequenceOperationActions.addFramesAction);
558            addCommandButton(addButton, RibbonElementPriority.MEDIUM);
559
560            // frames merge
561            mergeButton = new IcyCommandButton(SequenceOperationActions.mergeFramesAction);
562            addCommandButton(mergeButton, RibbonElementPriority.MEDIUM);
563
564            // advanced frame remove
565            advancedRemoveButton = new IcyCommandButton(SequenceOperationActions.removeFramesAction);
566            addCommandButton(advancedRemoveButton, RibbonElementPriority.MEDIUM);
567
568            RibbonUtil.setRestrictiveResizePolicies(this);
569            updateButtonsState();
570        }
571
572        void updateButtonsState()
573        {
574            final Sequence seq = Icy.getMainInterface().getActiveSequence();
575            final boolean enabled = (seq != null);
576            final boolean notEmpty = (seq != null) && !seq.isEmpty();
577            final boolean several = (seq != null) && (seq.getSizeT() > 1);
578
579            reverseButton.setEnabled(several);
580            extractButton.setEnabled(several);
581            removeButton.setEnabled(several);
582            addButton.setEnabled(notEmpty);
583            mergeButton.setEnabled(enabled);
584            advancedRemoveButton.setEnabled(several);
585        }
586    }
587
588    public static class ZTConversionBand extends JRibbonBand
589    {
590        /**
591         * 
592         */
593        private static final long serialVersionUID = 8210688977085548878L;
594
595        private static final String BAND_NAME = "Z / T conversion";
596
597        final IcyCommandButton convertToZButton;
598        final IcyCommandButton convertToTButton;
599        final IcyCommandButton advancedConvertButton;
600
601        public ZTConversionBand()
602        {
603            super(BAND_NAME, new IcyIcon(ResourceUtil.ICON_LAYER_V2));
604
605            setToolTipText("Z/T conversion");
606
607            // convert to Z stack
608            convertToZButton = new IcyCommandButton(SequenceOperationActions.convertToSlicesAction);
609            addCommandButton(convertToZButton, RibbonElementPriority.MEDIUM);
610
611            // convert to T stack
612            convertToTButton = new IcyCommandButton(SequenceOperationActions.convertToFramesAction);
613            addCommandButton(convertToTButton, RibbonElementPriority.MEDIUM);
614
615            // advanced conversion
616            advancedConvertButton = new IcyCommandButton(SequenceOperationActions.advancedZTConvertAction);
617            addCommandButton(advancedConvertButton, RibbonElementPriority.MEDIUM);
618
619            RibbonUtil.setRestrictiveResizePolicies(this);
620            updateButtonsState();
621        }
622
623        void updateButtonsState()
624        {
625            final Sequence seq = Icy.getMainInterface().getActiveSequence();
626            final boolean severalZ = (seq != null) && (seq.getSizeZ() > 1);
627            final boolean severalT = (seq != null) && (seq.getSizeT() > 1);
628
629            convertToTButton.setEnabled(severalZ);
630            convertToZButton.setEnabled(severalT);
631            advancedConvertButton.setEnabled(severalZ || severalT);
632        }
633    }
634
635    public static final String NAME = "Image / Sequence";
636
637    final FileBand fileBand;
638    final CopyConvertBand copyConvertBand;
639    final RenderingBand colorConvertBand;
640    final ZTConversionBand stackConversionBand;
641    final PlanarOperationBand planarOperationBand;
642    final ChannelOperationBand channelOperationBand;
643    final ZOperationBand zStackOperationBand;
644    final TOperationBand tStackOperationBand;
645    final Runnable buttonUpdater;
646
647    public SequenceOperationTask()
648    {
649        super(NAME, new FileBand(), new CopyConvertBand(), new PlanarOperationBand(), new ChannelOperationBand(),
650                new ZOperationBand(), new TOperationBand(), new ZTConversionBand(), new RenderingBand());
651
652        fileBand = (FileBand) getBand(0);
653        copyConvertBand = (CopyConvertBand) getBand(1);
654        planarOperationBand = (PlanarOperationBand) getBand(2);
655        channelOperationBand = (ChannelOperationBand) getBand(3);
656        zStackOperationBand = (ZOperationBand) getBand(4);
657        tStackOperationBand = (TOperationBand) getBand(5);
658        stackConversionBand = (ZTConversionBand) getBand(6);
659        colorConvertBand = (RenderingBand) getBand(7);
660
661        fileBand.updateButtonsState();
662        copyConvertBand.updateButtonsState();
663        colorConvertBand.updateButtonsState();
664        channelOperationBand.updateButtonsState();
665        planarOperationBand.updateButtonsState();
666        stackConversionBand.updateButtonsState();
667        zStackOperationBand.updateButtonsState();
668        tStackOperationBand.updateButtonsState();
669
670        buttonUpdater = new Runnable()
671        {
672            @Override
673            public void run()
674            {
675                // sleep a bit
676                ThreadUtil.sleep(1);
677
678                ThreadUtil.invokeNow(new Runnable()
679                {
680                    @Override
681                    public void run()
682                    {
683                        fileBand.updateButtonsState();
684                        copyConvertBand.updateButtonsState();
685                        colorConvertBand.updateButtonsState();
686                        channelOperationBand.updateButtonsState();
687                        planarOperationBand.updateButtonsState();
688                        stackConversionBand.updateButtonsState();
689                        zStackOperationBand.updateButtonsState();
690                        tStackOperationBand.updateButtonsState();
691                    }
692                });
693            }
694        };
695    }
696
697    /**
698     * @deprecated Use Too
699     */
700    @Deprecated
701    public double getFillValue()
702    {
703        return Icy.getMainInterface().getROIRibbonTask().getFillValue();
704    }
705
706    /**
707     * call this method on sequence change
708     */
709    public void onSequenceChange()
710    {
711        ThreadUtil.runSingle(buttonUpdater);
712    }
713}