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 */
019
020package icy.gui.main;
021
022import java.util.ArrayList;
023import java.util.List;
024
025import javax.swing.JFrame;
026import javax.swing.JInternalFrame;
027
028import icy.common.listener.AcceptListener;
029import icy.gui.inspector.InspectorPanel;
030import icy.gui.inspector.LayersPanel;
031import icy.gui.inspector.RoisPanel;
032import icy.gui.menu.ApplicationMenu;
033import icy.gui.menu.ROITask;
034import icy.gui.menu.ToolRibbonTask;
035import icy.gui.viewer.Viewer;
036import icy.image.IcyBufferedImage;
037import icy.image.lut.LUT;
038import icy.imagej.ImageJWrapper;
039import icy.painter.Overlay;
040import icy.painter.Painter;
041import icy.plugin.abstract_.Plugin;
042import icy.preferences.GeneralPreferences;
043import icy.preferences.XMLPreferences;
044import icy.roi.ROI;
045import icy.search.SearchEngine;
046import icy.sequence.Sequence;
047import icy.swimmingPool.SwimmingPool;
048import icy.type.collection.CollectionUtil;
049import icy.undo.IcyUndoManager;
050import icy.util.StringUtil;
051
052/**
053 * MainInterfaceBatch
054 * Default implementation used when Icy is launched in batch mode, without any GUI
055 * 
056 * @see icy.gui.main.MainInterfaceGui
057 * @author Nicolas HERVE & Stephane
058 */
059public class MainInterfaceBatch implements MainInterface
060{
061    /**
062     * Swimming Pool can be useful even in batch mode
063     */
064    private final SwimmingPool swimmingPool;
065    /**
066     * We keep trace of active sequence.
067     */
068    private Sequence activeSequence;
069    /**
070     * We keep trace of active plugin.
071     */
072    private Plugin activePlugin;
073
074    public MainInterfaceBatch()
075    {
076        swimmingPool = new SwimmingPool();
077    }
078
079    @Override
080    public void init()
081    {
082        activeSequence = null;
083        activePlugin = null;
084    }
085
086    @Override
087    public boolean isHeadLess()
088    {
089        // always true with this interface
090        return true;
091    }
092
093    @Override
094    public ArrayList<JFrame> getExternalFrames()
095    {
096        return new ArrayList<JFrame>();
097    }
098
099    @Override
100    public ArrayList<JInternalFrame> getInternalFrames()
101    {
102        return new ArrayList<JInternalFrame>();
103    }
104
105    @Override
106    public XMLPreferences getPreferences()
107    {
108        return null;
109    }
110
111    @Override
112    public InspectorPanel getInspector()
113    {
114        return null;
115    }
116
117    @Override
118    public RoisPanel getRoisPanel()
119    {
120        return null;
121    }
122
123    @Override
124    public LayersPanel getLayersPanel()
125    {
126        return null;
127    }
128
129    @Override
130    public ArrayList<Plugin> getActivePlugins()
131    {
132        return CollectionUtil.createArrayList(activePlugin, false);
133    }
134
135    @Override
136    public LUT getActiveLUT()
137    {
138        return null;
139    }
140
141    @Override
142    public Viewer getActiveViewer()
143    {
144        return null;
145    }
146
147    @Override
148    public Sequence getActiveSequence()
149    {
150        return activeSequence;
151    }
152
153    @Override
154    public IcyBufferedImage getActiveImage()
155    {
156        if (activeSequence != null)
157            return activeSequence.getFirstImage();
158
159        return null;
160    }
161
162    @Override
163    public IcyUndoManager getUndoManager()
164    {
165        if (activeSequence != null)
166            return activeSequence.getUndoManager();
167
168        return null;
169    }
170
171    @Override
172    public boolean undo()
173    {
174        if (activeSequence != null)
175            return activeSequence.undo();
176
177        return false;
178    }
179
180    @Override
181    public boolean redo()
182    {
183        if (activeSequence != null)
184            return activeSequence.redo();
185
186        return false;
187    }
188
189    @Override
190    public Viewer getFocusedViewer()
191    {
192        return getActiveViewer();
193    }
194
195    @Override
196    public Sequence getFocusedSequence()
197    {
198        return getActiveSequence();
199    }
200
201    @Override
202    public IcyBufferedImage getFocusedImage()
203    {
204        return getActiveImage();
205    }
206
207    @Override
208    public ArrayList<Viewer> getViewers()
209    {
210        return new ArrayList<Viewer>();
211    }
212
213    @Override
214    public void setFocusedViewer(Viewer viewer)
215    {
216    }
217
218    @Override
219    public void setActiveViewer(Viewer viewer)
220    {
221    }
222
223    @Override
224    public void addToDesktopPane(JInternalFrame internalFrame)
225    {
226    }
227
228    @Override
229    public IcyDesktopPane getDesktopPane()
230    {
231        return null;
232    }
233
234    @Override
235    public ApplicationMenu getApplicationMenu()
236    {
237        return null;
238    }
239
240    @Override
241    public TaskFrameManager getTaskWindowManager()
242    {
243        return null;
244    }
245
246    @Override
247    public void registerPlugin(Plugin plugin)
248    {
249        if (plugin != null)
250            activePlugin = plugin;
251    }
252
253    @Override
254    public void unRegisterPlugin(Plugin plugin)
255    {
256        if (plugin == activePlugin)
257            activePlugin = null;
258    }
259
260    @Override
261    public void registerViewer(Viewer viewer)
262    {
263    }
264
265    @Override
266    public void unRegisterViewer(Viewer viewer)
267    {
268    }
269
270    // @Override
271    // public void registerStreamPlugin(PluginStreamGenerator pluginStreamGenerator)
272    // {
273    // }
274
275    @Override
276    @Deprecated
277    public MainFrame getFrame()
278    {
279        return getMainFrame();
280    }
281
282    @Override
283    public MainFrame getMainFrame()
284    {
285        return null;
286    }
287
288    @Override
289    public void closeSequence(Sequence sequence)
290    {
291        if (sequence == activeSequence)
292            activeSequence = null;
293    }
294
295    @Deprecated
296    @Override
297    public void closeViewersOfSequence(Sequence sequence)
298    {
299        closeSequence(sequence);
300    }
301
302    @Override
303    public void closeAllViewers()
304    {
305        activeSequence = null;
306    }
307
308    @Override
309    public Viewer getFirstViewer(Sequence sequence)
310    {
311        return null;
312    }
313
314    @Override
315    public ArrayList<Viewer> getViewers(Sequence sequence)
316    {
317        return new ArrayList<Viewer>();
318    }
319
320    @Override
321    public boolean isUniqueViewer(Viewer viewer)
322    {
323        return false;
324    }
325
326    @Override
327    public ArrayList<Sequence> getSequences()
328    {
329        if (activeSequence != null)
330            return CollectionUtil.createArrayList(activeSequence);
331
332        return new ArrayList<Sequence>();
333    }
334
335    @Override
336    public ArrayList<Sequence> getSequences(String name)
337    {
338        if ((activeSequence != null) && StringUtil.equals(name, activeSequence.getName()))
339            return CollectionUtil.createArrayList(activeSequence);
340
341        return new ArrayList<Sequence>();
342    }
343
344    @Override
345    public Sequence getFirstSequencesContaining(ROI roi)
346    {
347        return getFirstSequenceContaining(roi);
348    }
349
350    @Deprecated
351    @Override
352    public Sequence getFirstSequencesContaining(Painter painter)
353    {
354        return getFirstSequenceContaining(painter);
355    }
356
357    @Override
358    public ArrayList<Sequence> getSequencesContaining(ROI roi)
359    {
360        if ((activeSequence != null) && activeSequence.contains(roi))
361            return CollectionUtil.createArrayList(activeSequence);
362
363        return new ArrayList<Sequence>();
364    }
365
366    @Deprecated
367    @Override
368    public ArrayList<Sequence> getSequencesContaining(Painter painter)
369    {
370        if ((activeSequence != null) && activeSequence.contains(painter))
371            return CollectionUtil.createArrayList(activeSequence);
372
373        return new ArrayList<Sequence>();
374    }
375
376    @Override
377    public ArrayList<Sequence> getSequencesContaining(Overlay overlay)
378    {
379        if ((activeSequence != null) && activeSequence.contains(overlay))
380            return CollectionUtil.createArrayList(activeSequence);
381
382        return new ArrayList<Sequence>();
383    }
384
385    @Override
386    public ArrayList<ROI> getROIs()
387    {
388        if (activeSequence != null)
389            return activeSequence.getROIs();
390
391        // TODO: add ROI from swimming pool ?
392
393        return new ArrayList<ROI>();
394    }
395
396    @Override
397    @Deprecated
398    public ROI getROI(Painter painter)
399    {
400        if (painter instanceof Overlay)
401            return getROI((Overlay) painter);
402
403        return null;
404    }
405
406    @Override
407    public ROI getROI(Overlay overlay)
408    {
409        final List<ROI> rois = getROIs();
410
411        for (ROI roi : rois)
412            if (roi.getOverlay() == overlay)
413                return roi;
414
415        return null;
416    }
417
418    @Deprecated
419    @Override
420    public ArrayList<Painter> getPainters()
421    {
422        if (activeSequence != null)
423            return activeSequence.getPainters();
424
425        // TODO: add Painter from swimming pool ?
426
427        return new ArrayList<Painter>();
428    }
429
430    @Override
431    public List<Overlay> getOverlays()
432    {
433        if (activeSequence != null)
434            return activeSequence.getOverlays();
435
436        // TODO: add Overlay from swimming pool ?
437
438        return new ArrayList<Overlay>();
439    }
440
441    @Override
442    public SwimmingPool getSwimmingPool()
443    {
444        return swimmingPool;
445    }
446
447    @Override
448    public String getSelectedTool()
449    {
450        return null;
451    }
452
453    @Override
454    public void setSelectedTool(String command)
455    {
456        //
457    }
458
459    @Override
460    public ROITask getROIRibbonTask()
461    {
462        return null;
463    }
464
465    @Deprecated
466    @Override
467    public ToolRibbonTask getToolRibbon()
468    {
469        return null;
470    }
471
472    @Override
473    public boolean isAlwaysOnTop()
474    {
475        return false;
476    }
477
478    @Override
479    public boolean isDetachedMode()
480    {
481        return false;
482    }
483
484    @Override
485    public void setAlwaysOnTop(boolean value)
486    {
487    }
488
489    @Override
490    public void setDetachedMode(boolean value)
491    {
492    }
493
494    @Deprecated
495    @Override
496    public void addListener(MainListener listener)
497    {
498    }
499
500    @Deprecated
501    @Override
502    public void removeListener(MainListener listener)
503    {
504    }
505
506    @Override
507    public void addCanExitListener(AcceptListener listener)
508    {
509    }
510
511    @Override
512    public void removeCanExitListener(AcceptListener listener)
513    {
514    }
515
516    @Deprecated
517    @Override
518    public void beginUpdate()
519    {
520    }
521
522    @Deprecated
523    @Override
524    public void endUpdate()
525    {
526    }
527
528    @Deprecated
529    @Override
530    public boolean isUpdating()
531    {
532        return false;
533    }
534
535    @Deprecated
536    @Override
537    public void registerExternalFrame(JFrame frame)
538    {
539    }
540
541    @Deprecated
542    @Override
543    public void unRegisterExternalFrame(JFrame frame)
544    {
545    }
546
547    @Override
548    public boolean isOpened(Sequence sequence)
549    {
550        return (sequence == activeSequence);
551    }
552
553    @Override
554    public Sequence getFirstSequenceContaining(ROI roi)
555    {
556        if ((activeSequence != null) && activeSequence.contains(roi))
557            return activeSequence;
558
559        return null;
560    }
561
562    @Override
563    @Deprecated
564    public Sequence getFirstSequenceContaining(Painter painter)
565    {
566        if ((activeSequence != null) && activeSequence.contains(painter))
567            return activeSequence;
568
569        return null;
570    }
571
572    @Override
573    public Sequence getFirstSequenceContaining(Overlay overlay)
574    {
575        if ((activeSequence != null) && activeSequence.contains(overlay))
576            return activeSequence;
577
578        return null;
579    }
580
581    @Override
582    public Viewer getFirstViewerContaining(ROI roi)
583    {
584        return null;
585    }
586
587    @Deprecated
588    @Override
589    public Viewer getFirstViewerContaining(Painter painter)
590    {
591        return null;
592    }
593
594    @Override
595    public Viewer getFirstViewerContaining(Overlay overlay)
596    {
597        return null;
598    }
599
600    @Override
601    public boolean canExitExternal()
602    {
603        return true;
604    }
605
606    @Override
607    public ImageJWrapper getImageJ()
608    {
609        return null;
610    }
611
612    @Deprecated
613    @Override
614    public void addFocusedViewerListener(FocusedViewerListener listener)
615    {
616    }
617
618    @Deprecated
619    @Override
620    public void removeFocusedViewerListener(FocusedViewerListener listener)
621    {
622    }
623
624    @Deprecated
625    @Override
626    public void addFocusedSequenceListener(FocusedSequenceListener listener)
627    {
628    }
629
630    @Deprecated
631    @Override
632    public void removeFocusedSequenceListener(FocusedSequenceListener listener)
633    {
634    }
635
636    @Override
637    public void addGlobalViewerListener(GlobalViewerListener listener)
638    {
639    }
640
641    @Override
642    public void removeGlobalViewerListener(GlobalViewerListener listener)
643    {
644    }
645
646    @Override
647    public void addGlobalSequenceListener(GlobalSequenceListener listener)
648    {
649    }
650
651    @Override
652    public void removeGlobalSequenceListener(GlobalSequenceListener listener)
653    {
654    }
655
656    @Override
657    public void addGlobalROIListener(GlobalROIListener listener)
658    {
659    }
660
661    @Override
662    public void removeGlobalROIListener(GlobalROIListener listener)
663    {
664    }
665
666    @Override
667    public void addGlobalOverlayListener(GlobalOverlayListener listener)
668    {
669    }
670
671    @Override
672    public void removeGlobalOverlayListener(GlobalOverlayListener listener)
673    {
674    }
675
676    @Override
677    public void addGlobalPluginListener(GlobalPluginListener listener)
678    {
679    }
680
681    @Override
682    public void removeGlobalPluginListener(GlobalPluginListener listener)
683    {
684    }
685
686    @Override
687    public void addActiveViewerListener(ActiveViewerListener listener)
688    {
689    }
690
691    @Override
692    public void removeActiveViewerListener(ActiveViewerListener listener)
693    {
694    }
695
696    @Override
697    public void addActiveSequenceListener(ActiveSequenceListener listener)
698    {
699    }
700
701    @Override
702    public void removeActiveSequenceListener(ActiveSequenceListener listener)
703    {
704    }
705
706    @Override
707    public void addSequence(Sequence sequence)
708    {
709        if (sequence != null)
710            activeSequence = sequence;
711    }
712
713    @Override
714    public void setGlobalViewSyncId(int id)
715    {
716
717    }
718
719    @Override
720    public SearchEngine getSearchEngine()
721    {
722        return null;
723    }
724
725    @Override
726    public boolean isVirtualMode()
727    {
728        return GeneralPreferences.getVirtualMode();
729    }
730
731    @Override
732    public void setVirtualMode(boolean value)
733    {
734        GeneralPreferences.setVirtualMode(value);
735    }
736}