-
Notifications
You must be signed in to change notification settings - Fork 35
/
BigDataViewer.java
795 lines (681 loc) · 27.2 KB
/
BigDataViewer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/*
* #%L
* BigDataViewer core classes with minimal dependencies.
* %%
* Copyright (C) 2012 - 2022 BigDataViewer developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package bdv;
import bdv.tools.PreferencesDialog;
import bdv.ui.UIUtils;
import bdv.ui.keymap.Keymap;
import bdv.ui.keymap.KeymapManager;
import bdv.ui.keymap.KeymapSettingsPage;
import bdv.viewer.ConverterSetups;
import bdv.viewer.ViewerState;
import bdv.ui.appearance.AppearanceManager;
import bdv.ui.appearance.AppearanceSettingsPage;
import dev.dirs.ProjectDirectories;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ActionMap;
import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;
import net.imglib2.Volatile;
import net.imglib2.converter.Converter;
import net.imglib2.display.ColorConverter;
import net.imglib2.display.RealARGBColorConverter;
import net.imglib2.display.ScaledARGBConverter;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.volatiles.VolatileARGBType;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.scijava.ui.behaviour.io.InputTriggerConfig;
import org.scijava.ui.behaviour.io.yaml.YamlConfigIO;
import bdv.cache.CacheControl;
import bdv.export.ProgressWriter;
import bdv.export.ProgressWriterConsole;
import bdv.spimdata.SpimDataMinimal;
import bdv.spimdata.WrapBasicImgLoader;
import bdv.spimdata.XmlIoSpimDataMinimal;
import bdv.tools.HelpDialog;
import bdv.tools.InitializeViewerState;
import bdv.tools.RecordMaxProjectionDialog;
import bdv.tools.RecordMovieDialog;
import bdv.tools.VisibilityAndGroupingDialog;
import bdv.tools.bookmarks.Bookmarks;
import bdv.tools.bookmarks.BookmarksEditor;
import bdv.tools.brightness.BrightnessDialog;
import bdv.tools.brightness.ConverterSetup;
import bdv.tools.brightness.MinMaxGroup;
import bdv.tools.brightness.RealARGBColorConverterSetup;
import bdv.tools.brightness.SetupAssignments;
import bdv.tools.crop.CropDialog;
import bdv.tools.transformation.ManualTransformation;
import bdv.tools.transformation.ManualTransformationEditor;
import bdv.tools.transformation.TransformedSource;
import bdv.viewer.NavigationActions;
import bdv.viewer.SourceAndConverter;
import bdv.viewer.ViewerFrame;
import bdv.viewer.ViewerOptions;
import bdv.viewer.ViewerPanel;
import mpicbg.spim.data.SpimDataException;
import mpicbg.spim.data.generic.AbstractSpimData;
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.generic.sequence.BasicViewSetup;
import mpicbg.spim.data.sequence.Angle;
import mpicbg.spim.data.sequence.Channel;
import org.scijava.ui.behaviour.util.Actions;
public class BigDataViewer
{
public static String configDir = ProjectDirectories.from( "sc", "fiji", "bigdataviewer" ).configDir;
protected final ViewerFrame viewerFrame;
protected final ViewerPanel viewer;
protected final SetupAssignments setupAssignments;
protected final ManualTransformation manualTransformation;
protected final Bookmarks bookmarks;
protected final BrightnessDialog brightnessDialog;
protected final CropDialog cropDialog;
protected final RecordMovieDialog movieDialog;
protected final RecordMaxProjectionDialog movieMaxProjectDialog;
protected final VisibilityAndGroupingDialog activeSourcesDialog;
protected final HelpDialog helpDialog;
private final KeymapManager keymapManager;
private final AppearanceManager appearanceManager;
protected final PreferencesDialog preferencesDialog;
protected final ManualTransformationEditor manualTransformationEditor;
protected final BookmarksEditor bookmarkEditor;
protected final JFileChooser fileChooser;
protected File proposedSettingsFile;
public void toggleManualTransformation()
{
manualTransformationEditor.toggle();
}
public void initSetBookmark()
{
bookmarkEditor.initSetBookmark();
}
public void initGoToBookmark()
{
bookmarkEditor.initGoToBookmark();
}
public void initGoToBookmarkRotation()
{
bookmarkEditor.initGoToBookmarkRotation();
}
private static String createSetupName( final BasicViewSetup setup )
{
if ( setup.hasName() )
return setup.getName();
String name = "";
final Angle angle = setup.getAttribute( Angle.class );
if ( angle != null )
name += ( name.isEmpty() ? "" : " " ) + "a " + angle.getName();
final Channel channel = setup.getAttribute( Channel.class );
if ( channel != null )
name += ( name.isEmpty() ? "" : " " ) + "c " + channel.getName();
return name;
}
/**
* Create standard converter from the given {@code type} to ARGB:
* <ul>
* <li>For {@code RealType}s a {@link RealARGBColorConverter} is
* returned.</li>
* <li>For {@code ARGBType}s a {@link ScaledARGBConverter.ARGB} is
* returned.</li>
* <li>For {@code VolatileARGBType}s a
* {@link ScaledARGBConverter.VolatileARGB} is returned.</li>
* </ul>
*/
@SuppressWarnings( "unchecked" )
public static < T extends NumericType< T > > Converter< T, ARGBType > createConverterToARGB( final T type )
{
if ( type instanceof RealType )
{
final RealType< ? > t = ( RealType< ? > ) type;
final double typeMin = Math.max( 0, Math.min( t.getMinValue(), 65535 ) );
final double typeMax = Math.max( 0, Math.min( t.getMaxValue(), 65535 ) );
return ( Converter< T, ARGBType > ) RealARGBColorConverter.create( t, typeMin, typeMax );
}
else if ( type instanceof ARGBType )
return ( Converter< T, ARGBType > ) new ScaledARGBConverter.ARGB( 0, 255 );
else if ( type instanceof VolatileARGBType )
return ( Converter< T, ARGBType > ) new ScaledARGBConverter.VolatileARGB( 0, 255 );
else
throw new IllegalArgumentException( "ImgLoader of type " + type.getClass() + " not supported." );
}
/**
* Create a {@code ConverterSetup} for the given {@code SourceAndConverter}.
* {@link SourceAndConverter#asVolatile() Nested volatile}
* {@code SourceAndConverter} are added to the {@code ConverterSetup} if
* present. If {@code SourceAndConverter} does not comprise a
* {@code ColorConverter}, returns {@code null}.
*
* @param soc
* {@code SourceAndConverter} for which to create a
* {@code ConverterSetup}
* @param setupId
* setupId of the created {@code ConverterSetup}
* @return a new {@code ConverterSetup} or {@code null}
*/
public static ConverterSetup createConverterSetup( final SourceAndConverter< ? > soc, final int setupId )
{
final List< ColorConverter > converters = new ArrayList<>();
final Converter< ?, ARGBType > c = soc.getConverter();
if ( c instanceof ColorConverter )
converters.add( ( ColorConverter ) c );
final SourceAndConverter< ? extends Volatile< ? > > vsoc = soc.asVolatile();
if ( vsoc != null )
{
final Converter< ?, ARGBType > vc = vsoc.getConverter();
if ( vc instanceof ColorConverter )
converters.add( ( ColorConverter ) vc );
}
if ( converters.isEmpty() )
return null;
else
return new RealARGBColorConverterSetup( setupId, converters );
}
/**
* Decorate source with an extra transformation, that can be edited manually
* in this viewer. {@link SourceAndConverter#asVolatile() Nested volatile}
* {@code SourceAndConverter} are wrapped as well, if present.
*/
public static < T, V extends Volatile< T > > SourceAndConverter< T > wrapWithTransformedSource( final SourceAndConverter< T > soc )
{
if ( soc.asVolatile() == null )
return new SourceAndConverter<>( new TransformedSource<>( soc.getSpimSource() ), soc.getConverter() );
@SuppressWarnings( "unchecked" )
final SourceAndConverter< V > vsoc = ( SourceAndConverter< V > ) soc.asVolatile();
final TransformedSource< T > ts = new TransformedSource<>( soc.getSpimSource() );
final TransformedSource< V > vts = new TransformedSource<>( vsoc.getSpimSource(), ts );
return new SourceAndConverter<>( ts, soc.getConverter(), new SourceAndConverter<>( vts, vsoc.getConverter() ) );
}
private static < T extends NumericType< T >, V extends Volatile< T > & NumericType< V > > void initSetupNumericType(
final AbstractSpimData< ? > spimData,
final BasicViewSetup setup,
final List< ConverterSetup > converterSetups,
final List< SourceAndConverter< ? > > sources )
{
final int setupId = setup.getId();
final ViewerImgLoader imgLoader = ( ViewerImgLoader ) spimData.getSequenceDescription().getImgLoader();
@SuppressWarnings( "unchecked" )
final ViewerSetupImgLoader< T, V > setupImgLoader = ( ViewerSetupImgLoader< T, V > ) imgLoader.getSetupImgLoader( setupId );
final T type = setupImgLoader.getImageType();
final V volatileType = setupImgLoader.getVolatileImageType();
if ( ! ( type instanceof NumericType ) )
throw new IllegalArgumentException( "ImgLoader of type " + type.getClass() + " not supported." );
final String setupName = createSetupName( setup );
SourceAndConverter< V > vsoc = null;
if ( volatileType != null )
{
final VolatileSpimSource< V > vs = new VolatileSpimSource<>( spimData, setupId, setupName );
vsoc = new SourceAndConverter<>( vs, createConverterToARGB( volatileType ) );
}
final SpimSource< T > s = new SpimSource<>( spimData, setupId, setupName );
final SourceAndConverter< T > soc = new SourceAndConverter<>( s, createConverterToARGB( type ), vsoc );
final SourceAndConverter< T > tsoc = wrapWithTransformedSource( soc );
sources.add( tsoc );
final ConverterSetup converterSetup = createConverterSetup( tsoc, setupId );
if ( converterSetup != null )
converterSetups.add( converterSetup );
}
public static void initSetups(
final AbstractSpimData< ? > spimData,
final List< ConverterSetup > converterSetups,
final List< SourceAndConverter< ? > > sources )
{
for ( final BasicViewSetup setup : spimData.getSequenceDescription().getViewSetupsOrdered() )
initSetupNumericType( spimData, setup, converterSetups, sources );
}
/**
*
* @param converterSetups
* list of {@link ConverterSetup} that control min/max and color
* of sources.
* @param sources
* list of pairs of source of some type and converter from that
* type to ARGB.
* @param spimData
* may be null. The {@link AbstractSpimData} of the dataset (if
* there is one). If it exists, it is used to set up a "Crop"
* dialog.
* @param numTimepoints
* the number of timepoints in the dataset.
* @param cache
* handle to cache. This is used to control io timing.
* @param windowTitle
* title of the viewer window.
* @param progressWriter
* a {@link ProgressWriter} to which BDV may report progress
* (currently only used in the "Record Movie" dialog).
* @param options
* optional parameters.
*/
public BigDataViewer(
final ArrayList< ConverterSetup > converterSetups,
final ArrayList< SourceAndConverter< ? > > sources,
final AbstractSpimData< ? > spimData,
final int numTimepoints,
final CacheControl cache,
final String windowTitle,
final ProgressWriter progressWriter,
final ViewerOptions options )
{
final KeymapManager optionsKeymapManager = options.values.getKeymapManager();
final AppearanceManager optionsAppearanceManager = options.values.getAppearanceManager();
keymapManager = optionsKeymapManager != null ? optionsKeymapManager : new KeymapManager( configDir );
appearanceManager = optionsAppearanceManager != null ? optionsAppearanceManager : new AppearanceManager( configDir );
InputTriggerConfig inputTriggerConfig = options.values.getInputTriggerConfig();
final Keymap keymap = this.keymapManager.getForwardSelectedKeymap();
if ( inputTriggerConfig == null )
inputTriggerConfig = keymap.getConfig();
viewerFrame = new ViewerFrame( sources, numTimepoints, cache, keymapManager, appearanceManager, options.inputTriggerConfig( inputTriggerConfig ) );
if ( windowTitle != null )
viewerFrame.setTitle( windowTitle );
viewer = viewerFrame.getViewerPanel();
// final ConverterSetup.SetupChangeListener requestRepaint = s -> viewer.requestRepaint();
// for ( final ConverterSetup cs : converterSetups )
// cs.setupChangeListeners().add( requestRepaint );
manualTransformation = new ManualTransformation( viewer );
manualTransformationEditor = new ManualTransformationEditor( viewer, viewerFrame.getKeybindings() );
bookmarks = new Bookmarks();
bookmarkEditor = new BookmarksEditor( viewer, viewerFrame.getKeybindings(), bookmarks );
final ConverterSetups setups = viewerFrame.getConverterSetups();
if ( converterSetups.size() != sources.size() )
System.err.println( "WARNING! Constructing BigDataViewer, with converterSetups.size() that is not the same as sources.size()." );
final int numSetups = Math.min( converterSetups.size(), sources.size() );
for ( int i = 0; i < numSetups; ++i )
{
final SourceAndConverter< ? > source = sources.get( i );
final ConverterSetup setup = converterSetups.get( i );
if ( setup != null )
setups.put( source, setup );
}
setupAssignments = new SetupAssignments( converterSetups, 0, 65535 );
if ( setupAssignments.getMinMaxGroups().size() > 0 )
{
final MinMaxGroup group = setupAssignments.getMinMaxGroups().get( 0 );
for ( final ConverterSetup setup : setupAssignments.getConverterSetups() )
setupAssignments.moveSetupToGroup( setup, group );
}
brightnessDialog = new BrightnessDialog( viewerFrame, setupAssignments );
if (spimData != null )
viewer.getSourceInfoOverlayRenderer().setTimePointsOrdered( spimData.getSequenceDescription().getTimePoints().getTimePointsOrdered() );
cropDialog = ( spimData == null ) ? null : new CropDialog( viewerFrame, viewer, spimData.getSequenceDescription() );
movieDialog = new RecordMovieDialog( viewerFrame, viewer, progressWriter );
// this is just to get updates of window size:
viewer.getDisplay().overlays().add( movieDialog );
movieMaxProjectDialog = new RecordMaxProjectionDialog( viewerFrame, viewer, progressWriter );
// this is just to get updates of window size:
viewer.getDisplay().overlays().add( movieMaxProjectDialog );
activeSourcesDialog = new VisibilityAndGroupingDialog( viewerFrame, viewer.state() );
helpDialog = new HelpDialog( viewerFrame );
fileChooser = new JFileChooser();
fileChooser.setFileFilter( new FileFilter()
{
@Override
public String getDescription()
{
return "xml files";
}
@Override
public boolean accept( final File f )
{
if ( f.isDirectory() )
return true;
if ( f.isFile() )
{
final String s = f.getName();
final int i = s.lastIndexOf( '.' );
if ( i > 0 && i < s.length() - 1 )
{
final String ext = s.substring( i + 1 ).toLowerCase();
return ext.equals( "xml" );
}
}
return false;
}
} );
preferencesDialog = new PreferencesDialog( viewerFrame, keymap, new String[] { KeyConfigContexts.BIGDATAVIEWER } );
preferencesDialog.addPage( new AppearanceSettingsPage( "Appearance", appearanceManager ) );
preferencesDialog.addPage( new KeymapSettingsPage( "Keymap", this.keymapManager, this.keymapManager.getCommandDescriptions() ) );
appearanceManager.appearance().updateListeners().add( viewerFrame::repaint );
appearanceManager.addLafComponent( fileChooser );
SwingUtilities.invokeLater(() -> appearanceManager.updateLookAndFeel());
final Actions navigationActions = new Actions( inputTriggerConfig, "bdv", "navigation" );
navigationActions.install( viewerFrame.getKeybindings(), "navigation" );
NavigationActions.install( navigationActions, viewer, options.values.is2D() );
final Actions bdvActions = new Actions( inputTriggerConfig, "bdv" );
bdvActions.install( viewerFrame.getKeybindings(), "bdv" );
BigDataViewerActions.install( bdvActions, this );
keymap.updateListeners().add( () -> {
navigationActions.updateKeyConfig( keymap.getConfig() );
bdvActions.updateKeyConfig( keymap.getConfig() );
viewerFrame.getTransformBehaviours().updateKeyConfig( keymap.getConfig() );
} );
final JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu( "File" );
menubar.add( menu );
final ActionMap actionMap = viewerFrame.getKeybindings().getConcatenatedActionMap();
final JMenuItem miLoadSettings = new JMenuItem( actionMap.get( BigDataViewerActions.LOAD_SETTINGS ) );
miLoadSettings.setText( "Load settings" );
menu.add( miLoadSettings );
final JMenuItem miSaveSettings = new JMenuItem( actionMap.get( BigDataViewerActions.SAVE_SETTINGS ) );
miSaveSettings.setText( "Save settings" );
menu.add( miSaveSettings );
menu.addSeparator();
final JMenuItem miPreferences = new JMenuItem( actionMap.get( BigDataViewerActions.PREFERENCES_DIALOG ) );
miPreferences.setText( "Preferences..." );
menu.add( miPreferences );
menu = new JMenu( "Settings" );
menubar.add( menu );
final JMenuItem miBrightness = new JMenuItem( actionMap.get( BigDataViewerActions.BRIGHTNESS_SETTINGS ) );
miBrightness.setText( "Brightness & Color" );
menu.add( miBrightness );
final JMenuItem miVisibility = new JMenuItem( actionMap.get( BigDataViewerActions.VISIBILITY_AND_GROUPING ) );
miVisibility.setText( "Visibility & Grouping" );
menu.add( miVisibility );
menu = new JMenu( "Tools" );
menubar.add( menu );
if ( cropDialog != null )
{
final JMenuItem miCrop = new JMenuItem( actionMap.get( BigDataViewerActions.CROP ) );
miCrop.setText( "Crop" );
menu.add( miCrop );
}
final JMenuItem miMovie = new JMenuItem( actionMap.get( BigDataViewerActions.RECORD_MOVIE ) );
miMovie.setText( "Record Movie" );
menu.add( miMovie );
final JMenuItem miMaxProjectMovie = new JMenuItem( actionMap.get( BigDataViewerActions.RECORD_MAX_PROJECTION_MOVIE ) );
miMaxProjectMovie.setText( "Record Max-Projection Movie" );
menu.add( miMaxProjectMovie );
final JMenuItem miManualTransform = new JMenuItem( actionMap.get( BigDataViewerActions.MANUAL_TRANSFORM ) );
miManualTransform.setText( "Manual Transform" );
menu.add( miManualTransform );
menu = new JMenu( "Help" );
menubar.add( menu );
final JMenuItem miHelp = new JMenuItem( actionMap.get( BigDataViewerActions.SHOW_HELP ) );
miHelp.setText( "Show Help" );
menu.add( miHelp );
viewerFrame.setJMenuBar( menubar );
}
public static BigDataViewer open( final AbstractSpimData< ? > spimData, final String windowTitle, final ProgressWriter progressWriter, final ViewerOptions options )
{
if ( WrapBasicImgLoader.wrapImgLoaderIfNecessary( spimData ) )
{
System.err.println( "WARNING:\nOpening <SpimData> dataset that is not suited for interactive browsing.\nConsider resaving as HDF5 for better performance." );
}
final ArrayList< ConverterSetup > converterSetups = new ArrayList<>();
final ArrayList< SourceAndConverter< ? > > sources = new ArrayList<>();
initSetups( spimData, converterSetups, sources );
final AbstractSequenceDescription< ?, ?, ? > seq = spimData.getSequenceDescription();
final int numTimepoints = seq.getTimePoints().size();
final CacheControl cache = ( ( ViewerImgLoader ) seq.getImgLoader() ).getCacheControl();
final BigDataViewer bdv = new BigDataViewer( converterSetups, sources, spimData, numTimepoints, cache, windowTitle, progressWriter, options );
WrapBasicImgLoader.removeWrapperIfPresent( spimData );
bdv.viewerFrame.setVisible( true );
InitializeViewerState.initTransform( bdv.viewer );
return bdv;
}
public static BigDataViewer open( final String xmlFilename, final String windowTitle, final ProgressWriter progressWriter, final ViewerOptions options ) throws SpimDataException
{
final SpimDataMinimal spimData = new XmlIoSpimDataMinimal().load( xmlFilename );
final BigDataViewer bdv = open( spimData, windowTitle, progressWriter, options );
if ( !bdv.tryLoadSettings( xmlFilename ) )
InitializeViewerState.initBrightness( 0.001, 0.999, bdv.viewerFrame );
return bdv;
}
public static BigDataViewer open(
final ArrayList< ConverterSetup > converterSetups,
final ArrayList< SourceAndConverter< ? > > sources,
final int numTimepoints,
final CacheControl cache,
final String windowTitle,
final ProgressWriter progressWriter,
final ViewerOptions options )
{
final BigDataViewer bdv = new BigDataViewer( converterSetups, sources, null, numTimepoints, cache, windowTitle, progressWriter, options );
bdv.viewerFrame.setVisible( true );
InitializeViewerState.initTransform( bdv.viewer );
return bdv;
}
public ViewerPanel getViewer()
{
return viewer;
}
public ViewerFrame getViewerFrame()
{
return viewerFrame;
}
public ConverterSetups getConverterSetups()
{
return viewerFrame.getConverterSetups();
}
/**
* @deprecated Instead {@code getViewer().state()} returns the {@link ViewerState} that can be modified directly.
*/
@Deprecated
public SetupAssignments getSetupAssignments()
{
return setupAssignments;
}
public ManualTransformationEditor getManualTransformEditor()
{
return manualTransformationEditor;
}
public KeymapManager getKeymapManager()
{
return keymapManager;
}
public AppearanceManager getAppearanceManager()
{
return appearanceManager;
}
public boolean tryLoadSettings( final String xmlFilename )
{
proposedSettingsFile = null;
if( xmlFilename.startsWith( "http://" ) )
{
// load settings.xml from the BigDataServer
final String settings = xmlFilename + "settings";
{
try
{
loadSettings( settings );
return true;
}
catch ( final FileNotFoundException e )
{}
catch ( final Exception e )
{
e.printStackTrace();
}
}
}
else if ( xmlFilename.endsWith( ".xml" ) )
{
final String settings = xmlFilename.substring( 0, xmlFilename.length() - ".xml".length() ) + ".settings" + ".xml";
proposedSettingsFile = new File( settings );
if ( proposedSettingsFile.isFile() )
{
try
{
loadSettings( settings );
return true;
}
catch ( final Exception e )
{
e.printStackTrace();
}
}
}
return false;
}
public void saveSettings()
{
fileChooser.setSelectedFile( proposedSettingsFile );
final int returnVal = fileChooser.showSaveDialog( null );
if ( returnVal == JFileChooser.APPROVE_OPTION )
{
proposedSettingsFile = fileChooser.getSelectedFile();
try
{
saveSettings( proposedSettingsFile.getCanonicalPath() );
}
catch ( final IOException e )
{
e.printStackTrace();
}
}
}
public void saveSettings( final String xmlFilename ) throws IOException
{
final Element root = new Element( "Settings" );
root.addContent( viewer.stateToXml() );
root.addContent( setupAssignments.toXml() );
root.addContent( manualTransformation.toXml() );
root.addContent( bookmarks.toXml() );
final Document doc = new Document( root );
final XMLOutputter xout = new XMLOutputter( Format.getPrettyFormat() );
xout.output( doc, new FileWriter( xmlFilename ) );
}
/**
* If {@code options} doesn't define a {@link InputTriggerConfig}, try to
* load it from files in this order:
* <ol>
* <li>"bdvkeyconfig.yaml" in the current directory.
* <li>".bdv/bdvkeyconfig.yaml" in the user's home directory.
* <li>legacy "bigdataviewer.keys.properties" in current directory (will be
* also written to "bdvkeyconfig.yaml").
* </ol>
*
* @deprecated This method is no longer used internally.
* {@code InputTriggerConfig}s are now managed through {@link KeymapManager}.
*/
@Deprecated
public static InputTriggerConfig getInputTriggerConfig( final ViewerOptions options )
{
InputTriggerConfig conf = options.values.getInputTriggerConfig();
// try "bdvkeyconfig.yaml" in current directory
if ( conf == null && new File( "bdvkeyconfig.yaml" ).isFile() )
{
try
{
conf = new InputTriggerConfig( YamlConfigIO.read( "bdvkeyconfig.yaml" ) );
}
catch ( final IOException e )
{}
}
// try "~/.bdv/bdvkeyconfig.yaml"
if ( conf == null )
{
final String fn = System.getProperty( "user.home" ) + "/.bdv/bdvkeyconfig.yaml";
if ( new File( fn ).isFile() )
{
try
{
conf = new InputTriggerConfig( YamlConfigIO.read( fn ) );
}
catch ( final IOException e )
{}
}
}
if ( conf == null )
{
conf = new InputTriggerConfig();
}
return conf;
}
public void loadSettings()
{
fileChooser.setSelectedFile( proposedSettingsFile );
final int returnVal = fileChooser.showOpenDialog( null );
if ( returnVal == JFileChooser.APPROVE_OPTION )
{
proposedSettingsFile = fileChooser.getSelectedFile();
try
{
loadSettings( proposedSettingsFile.getCanonicalPath() );
}
catch ( final Exception e )
{
e.printStackTrace();
}
}
}
public void loadSettings( final String xmlFilename ) throws IOException, JDOMException
{
final SAXBuilder sax = new SAXBuilder();
final Document doc = sax.build( xmlFilename );
final Element root = doc.getRootElement();
viewer.stateFromXml( root );
setupAssignments.restoreFromXml( root );
manualTransformation.restoreFromXml( root );
bookmarks.restoreFromXml( root );
activeSourcesDialog.update();
viewer.requestRepaint();
}
public void expandAndFocusCardPanel()
{
viewerFrame.getSplitPanel().setCollapsed( false );
viewerFrame.getSplitPanel().getRightComponent().requestFocusInWindow();
}
public void collapseCardPanel()
{
viewerFrame.getSplitPanel().setCollapsed( true );
viewer.requestFocusInWindow();
}
public static void main( final String[] args )
{
final String fn = "/Users/pietzsch/workspace/data/111010_weber_resave.xml";
try
{
System.setProperty( "apple.laf.useScreenMenuBar", "true" );
// System.setProperty( "apple.awt.application.appearance", "system" );
UIUtils.installFlatLafInfos();
System.out.println( "reading config files from \"" + configDir + "\"" );
final BigDataViewer bdv = open( fn, new File( fn ).getName(), new ProgressWriterConsole(), ViewerOptions.options() );
// DumpInputConfig.writeToYaml( System.getProperty( "user.home" ) + "/.bdv/bdvkeyconfig.yaml", bdv.getViewerFrame() );
}
catch ( final Exception e )
{
e.printStackTrace();
}
}
}