Newer
Older
/* MultiComparator.java
*
* created: Tue Sep 11 2001
*
* This file is part of Artemis
*
* Copyright(C) 2001,2002 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or(at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/MultiComparator.java,v 1.2 2004-07-29 13:38:50 tjc Exp $
*/
package uk.ac.sanger.artemis.components;
import uk.ac.sanger.artemis.*;
import uk.ac.sanger.artemis.util.FileDocument;
import uk.ac.sanger.artemis.util.OutOfRangeException;
import uk.ac.sanger.artemis.util.InputStreamProgressListener;
import uk.ac.sanger.artemis.io.EntryInformationException;
import uk.ac.sanger.artemis.io.DocumentEntryFactory;
import uk.ac.sanger.artemis.io.EntryInformation;
import uk.ac.sanger.artemis.io.SimpleEntryInformation;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.io.File;
import java.util.Vector;
import java.net.URL;
import javax.swing.*;
import java.awt.dnd.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import javax.swing.border.Border;
import javax.swing.border.BevelBorder;
/**
* This JFrame component contains an arbitrary number of AlignmentViewer
* components and FeatureDisplay components along with ComparatorGlue objects
* to keep them synchronized.
*
* @author Kim Rutherford <kmr@sanger.ac.uk>
* @version $Id: MultiComparator.java,v 1.2 2004-07-29 13:38:50 tjc Exp $
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
**/
public class MultiComparator extends JFrame
implements DropTargetListener
{
/** The menu_bar is created in makeMenus(). */
private final JMenuBar menu_bar = new JMenuBar();
/**
* An array of EntryGroup objects to display(set by the constructor). The
* array will contain at least one EntryGroup and will be exactly one
* element longer than comparison_data_array.
**/
private EntryGroup[] entry_group_array = null;
/**
* An array of ComparisonData objects to display(set by the constructor).
* The array will be exactly one element shorter than entry_group_array.
**/
private ComparisonData[] comparison_data_array = null;
/**
* An array of Selection objects - one per EntryGroup. Created by
* makeSelectionArray()
**/
private Selection[] selection_array = null;
/**
* An array of GotoEventSource objects - one per EntryGroup. Created by
* makeGotoEventSourceArray()
**/
private GotoEventSource[] goto_event_source_array = null;
/**
* An array of FeatureDisplay objects - one per EntryGroup. Created in the
* constructor.
**/
private FeatureDisplay[] feature_display_array = null;
/**
* An array of AlignmentViewer objects - one per ComparisonData. Created
* in the constructor.
**/
private AlignmentViewer[] alignment_viewer_array = null;
/**
* An array of AlignmentViewer objects - one per ComparisonData. Created
* in the constructor.
**/
private ComparatorGlue[] comparator_glue_array = null;
/**
* An array of BasePlotGroup objects - one per FeatureDisplay/EntryGroup.
* Created in the constructor.
**/
private BasePlotGroup[] base_plot_group_array = null;
/** This menu is populated by makeFileMenu(). */
private final JMenu file_menu = new JMenu("File");
/**
* The EntrySourceVector reference that is created in the constructor.
**/
private EntrySourceVector entry_sources;
/** Used to show the progress of loading file. */
private InputStreamProgressListener progress_listener;
/** current group used for drag and drop */
private int current_group = -1;
/**
* Initialise entry_group_array and comparison_data_array and create all
* the FeatureDisplay and AlignmentViewer components.
* @param entry_group_array The EntryGroup components to display.
* @param comparison_data_array The ComparisonData to display. This array
* must have one element less than entry_group_array.
* @param progress_listener The object to which InputStreamProgressEvents
* will be send while reading. Currently unused.
**/
public MultiComparator(final EntryGroup[] entry_group_array,
final ComparisonData[] comparison_data_array,
final InputStreamProgressListener
progress_listener)
{
super();
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if(entry_group_array.length != comparison_data_array.length + 1)
throw new Error("internal error - " +
"MultiComparator got illegal arguments");
this.entry_group_array = entry_group_array;
this.comparison_data_array = comparison_data_array;
this.progress_listener = progress_listener;
this.entry_sources = Utilities.getEntrySources(this, null);
setDropTarget(new DropTarget(this,this));
final StringBuffer title_buffer = new StringBuffer();
title_buffer.append("ACT: ");
for(int i = 0; i < entry_group_array.length - 1; ++i)
{
final String sequence_name =
entry_group_array[i].getDefaultEntry().getName();
title_buffer.append(sequence_name).append(" vs ");
}
final EntryGroup last_entry_group =
entry_group_array[entry_group_array.length - 1];
title_buffer.append(last_entry_group.getDefaultEntry().getName());
setTitle(title_buffer.toString());
makeSelectionArray();
makeGotoEventSourceArray();
feature_display_array =
new FeatureDisplay[entry_group_array.length];
base_plot_group_array =
new BasePlotGroup[entry_group_array.length];
alignment_viewer_array =
new AlignmentViewer[comparison_data_array.length];
comparator_glue_array =
new ComparatorGlue[comparison_data_array.length];
for(int i = 0; i < getEntryGroupArray().length; ++i)
{
final EntryGroup this_entry_group = getEntryGroupArray()[i];
final BasePlotGroup base_plot_group =
new BasePlotGroup(this_entry_group, this,
getSelectionArray()[i],
getGotoEventSourceArray()[i]);
final int scroll_bar_position;
if(i == getEntryGroupArray().length - 1 &&
getEntryGroupArray().length == 2)
{
// put scrollbar at the top normally, but at the bottom of the lower
// sequence if there's two entries on display
scroll_bar_position = FeatureDisplay.SCROLLBAR_AT_BOTTOM;
}
else
scroll_bar_position = FeatureDisplay.SCROLLBAR_AT_TOP;
feature_display_array[i] =
new FeatureDisplay(this_entry_group,
getSelectionArray()[i],
getGotoEventSourceArray()[i],
base_plot_group,
scroll_bar_position);
feature_display_array[i].setShowLabels(false);
feature_display_array[i].setHardLeftEdge(false);
if(getEntryGroupArray().length > 2)
{
feature_display_array[i].setShowForwardFrameLines(false);
feature_display_array[i].setShowReverseFrameLines(false);
}
feature_display_array[i].addDisplayAdjustmentListener(base_plot_group);
base_plot_group_array[i] = base_plot_group;
this_entry_group.ref();
}
for(int i = 0 ; i < getComparisonDataArray().length ; ++i)
{
alignment_viewer_array[i] =
new AlignmentViewer(getFeatureDisplayArray()[i] ,
getFeatureDisplayArray()[i + 1],
getComparisonDataArray()[i]);
comparator_glue_array[i] =
new ComparatorGlue(this,
getFeatureDisplayArray()[i],
getFeatureDisplayArray()[i + 1],
getAlignmentViewerArray()[i]);
}
final Font default_font = getDefaultFont();
setFont(default_font);
makeMenus();
GridBagLayout gridbag = new GridBagLayout();
getContentPane().setLayout(gridbag);
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.NORTH;
c.gridheight = 1;
c.weightx = 1;
c.weighty = 0;
for(int i = 0; i < getFeatureDisplayArray().length; ++i)
{
if(!(i == getEntryGroupArray().length - 1 &&
getEntryGroupArray().length == 2))
{
// put graph above the sequence in this case
c.weighty = 0;
gridbag.setConstraints(base_plot_group_array[i], c);
getContentPane().add(base_plot_group_array[i]);
}
c.weighty = 0;
gridbag.setConstraints(feature_display_array[i], c);
getContentPane().add(feature_display_array[i]);
if(i == getEntryGroupArray().length - 1 &&
getEntryGroupArray().length == 2)
{
// put graph below the sequence in this case
c.weighty = 0;
gridbag.setConstraints(base_plot_group_array[i], c);
getContentPane().add(base_plot_group_array[i]);
}
if(i < getAlignmentViewerArray().length)
{
c.fill = GridBagConstraints.BOTH;
c.weighty = 1;
gridbag.setConstraints(getAlignmentViewerArray()[i], c);
getContentPane().add(getAlignmentViewerArray()[i]);
}
}
for(int i = 0 ; i < getEntryGroupArray().length ; ++i)
{
final EntryGroupChangeListener change_listener =
new EntryGroupChangeListener()
{
public void entryGroupChanged(final EntryGroupChangeEvent event)
{
switch(event.getType())
{
case EntryGroupChangeEvent.ENTRY_ADDED:
case EntryGroupChangeEvent.ENTRY_DELETED:
makeFileMenu();
break;
}
}
};
getEntryGroupArray()[i].addEntryGroupChangeListener(change_listener);
final EntryChangeListener entry_change_listener =
new EntryChangeListener()
{
public void entryChanged(final EntryChangeEvent event)
{
switch(event.getType())
{
case EntryChangeEvent.NAME_CHANGED:
makeFileMenu();
break;
}
}
};
getEntryGroupArray()[i].addEntryChangeListener(entry_change_listener);
}
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
closeComparator();
}
});
final URL icon_url = Splash.class.getResource("/icon.gif");
if(icon_url != null)
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
final Image icon_image = toolkit.getImage(icon_url);
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(icon_image, 0);
try
{
tracker.waitForAll();
setIconImage(icon_image);
}
catch(InterruptedException e)
{
// ignore and continue
}
}
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
packme();
int screen_height = screen.height;
int screen_width = screen.width;
if(getAlignmentViewerArray().length > 0)
{
if(screen_width <= 900 || screen_height <= 700)
setSize(screen_width * 9 / 10, screen_height * 9 / 10);
else
setSize(900, 700);
}
setLocation(new Point((screen.width - getSize().width) / 2,
(screen.height - getSize().height) / 2));
}
/**
* Move all the sequences(and comparisons) up one place. The first and
* last EntryGroups should be the same(reference).
**/
private void rotateSequences()
{
final EntryGroup[] new_entry_groups =
new EntryGroup[getEntryGroupArray().length];
final ComparisonData[] new_comparison_data =
new ComparisonData[getComparisonDataArray().length];
for(int i = 1 ; i < new_entry_groups.length ; ++i)
new_entry_groups[i - 1] = getEntryGroupArray()[i];
new_entry_groups[new_entry_groups.length - 1] = new_entry_groups[0];
for(int i = 1; i < new_comparison_data.length; ++i)
new_comparison_data[i - 1] = getComparisonDataArray()[i];
new_comparison_data[new_comparison_data.length - 1] =
getComparisonDataArray()[0];
final MultiComparator new_comparator =
new MultiComparator(new_entry_groups, new_comparison_data,
progress_listener);
setVisible(false);
new_comparator.setVisible(true);
closeComparator();
}
/**
* If there are no unsaved changes, close this EntryEdit. Otherwise ask
* the user first.
**/
private void closeComparator()
{
for(int i = 0 ; i < getEntryGroupArray().length ; ++i)
{
final EntryGroup entry_group = getEntryGroupArray()[i];
if(entry_group.hasUnsavedChanges() &&
entry_group.refCount() == 1)
{
final YesNoDialog yes_no_dialog =
new YesNoDialog(this,
"there are unsaved changes - really close?");
if(!yes_no_dialog.getResult())
return;
}
}
for(int i = 0 ; i < getEntryGroupArray().length ; ++i)
{
final EntryGroup entry_group = getEntryGroupArray()[i];
entry_group.unref();
}
dispose();
}
/**
* This method will call pack() and then move the JFrame to the centre of
* the screen. (Implementation of the FeatureDisplayOwner interface).
**/
public void packme()
{
pack();
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
final int x_position =(screen.width - getSize().width) / 2;
int y_position =(screen.height - getSize().height) / 2;
if(y_position < 10)
y_position = 10;
setLocation(new Point(x_position, y_position));
}
/**
* Make one Selection object each EntryGroup.
**/
private void makeSelectionArray()
{
selection_array = new Selection[getEntryGroupArray().length];
for(int i = 0 ; i < selection_array.length ; ++i)
selection_array[i] = new Selection(null);
}
/**
* Make subject_goto_event_source and query_goto_event_source and wire them
* togeather so that goto events do the right thing.
**/
private void makeGotoEventSourceArray()
{
goto_event_source_array =
new GotoEventSource[getEntryGroupArray().length];
for(int i = 0 ; i < goto_event_source_array.length ; ++i)
{
goto_event_source_array[i] =
new SimpleGotoEventSource(getEntryGroupArray()[i])
{
/**
* Send the given event to all the GotoListeners.
**/
public void sendGotoEvent(final GotoEvent goto_event)
{
// temporarily disable moving so that the other FeatureDisplay
// doesn't start moving(because of the listeners set up in
// addDisplayListeners()
super.sendGotoEvent(goto_event);
}
};
}
}
/**
* Save the given entry, prompting for a file name if necessary.
**/
private void saveEntry(final Entry entry)
{
if(entry.getName() == null)
{
final EntryFileDialog file_dialog = new EntryFileDialog(this, true);
file_dialog.saveEntry(entry, true, true,
true, DocumentEntryFactory.ANY_FORMAT);
}
else
{
try
{
entry.save(DocumentEntryFactory.ANY_FORMAT);
}
catch(IOException e)
{
new MessageDialog(this, "error while saving: " + e);
return;
}
catch(EntryInformationException e)
{
new MessageDialog(this, "error while saving: " + e);
return;
}
}
}
/**
* Return the name to use for the sub JMenu for the given EntryGroup.
**/
private String makeNewSubMenuName(final EntryGroup entry_group)
{
final Entry sequence_entry = entry_group.getSequenceEntry();
if(sequence_entry == null)
return "(no name)";
else
{
final String sequence_name = sequence_entry.getName();
if(sequence_name == null)
return "(no name)";
else
return sequence_name;
}
}
/**
* Make and add the menus for this component.
**/
private void makeMenus()
{
final Font default_font = getDefaultFont();
setJMenuBar(menu_bar);
makeFileMenu();
menu_bar.add(file_menu);
final JMenu entries_menu = new JMenu("Entries");
menu_bar.add(entries_menu);
final JMenu select_menu = new JMenu("Select");
menu_bar.add(select_menu);
final JMenu view_menu = new JMenu("View");
menu_bar.add(view_menu);
final JMenu goto_menu = new JMenu("Goto");
menu_bar.add(goto_menu);
final JMenu edit_menu = new JMenu("Edit");
menu_bar.add(edit_menu);
final JMenu create_menu = new JMenu("Create");
menu_bar.add(create_menu);
final JMenu write_menu = new JMenu("Write");
menu_bar.add(write_menu);
JMenu run_menu = null;
if(Options.isUnixHost())
{
run_menu = new JMenu("Run");
menu_bar.add(run_menu);
}
final JMenu graph_menu = new JMenu("Graph");
menu_bar.add(graph_menu);
for(int i = 0 ; i < getEntryGroupArray().length ; ++i)
{
final EntryGroup entry_group = getEntryGroupArray()[i];
final String sub_menu_name = makeNewSubMenuName(entry_group);
final EntryGroupMenu this_entries_menu =
new EntryGroupMenu(this,
getEntryGroupArray()[i],
sub_menu_name);
entries_menu.add(this_entries_menu);
final SelectMenu this_select_menu =
new SelectMenu(this,
getSelectionArray()[i],
getGotoEventSourceArray()[i],
getEntryGroupArray()[i],
getBasePlotGroupArray()[i],
sub_menu_name);
select_menu.add(this_select_menu);
final ViewMenu this_view_menu =
new ViewMenu(this,
getSelectionArray()[i],
getGotoEventSourceArray()[i],
getEntryGroupArray()[i],
getBasePlotGroupArray()[i],
sub_menu_name);
view_menu.add(this_view_menu);
final GotoMenu this_goto_menu =
new GotoMenu(this,
getSelectionArray()[i],
getGotoEventSourceArray()[i],
getEntryGroupArray()[i],
sub_menu_name);
goto_menu.add(this_goto_menu);
AddMenu this_create_menu = null;
if(Options.readWritePossible())
{
final EditMenu this_edit_menu =
new EditMenu(this,
getSelectionArray()[i],
getGotoEventSourceArray()[i],
getEntryGroupArray()[i],
getBasePlotGroupArray()[i],
sub_menu_name);
edit_menu.add(this_edit_menu);
this_create_menu =
new AddMenu(this,
getSelectionArray()[i],
getEntryGroupArray()[i],
getGotoEventSourceArray()[i],
getBasePlotGroupArray()[i],
sub_menu_name);
create_menu.add(this_create_menu);
final WriteMenu this_write_menu =
new WriteMenu(this,
getSelectionArray()[i],
getEntryGroupArray()[i],
sub_menu_name);
write_menu.add(this_write_menu);
if(Options.isUnixHost())
{
final RunMenu this_run_menu =
new RunMenu(this,
getSelectionArray()[i],
sub_menu_name);
run_menu.add(this_run_menu);
}
}
final GraphMenu this_graph_menu =
new GraphMenu(this,
getEntryGroupArray()[i],
getBasePlotGroupArray()[i],
getFeatureDisplayArray()[i],
sub_menu_name);
graph_menu.add(this_graph_menu);
}
final JMenu display_menu = new JMenu("Display");
final JMenuItem hide_on_frame_lines_item =
new JMenuItem("Hide Frame Lines");
hide_on_frame_lines_item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
for(int i = 0 ; i < getFeatureDisplayArray().length ; ++i)
{
getFeatureDisplayArray()[i].setShowForwardFrameLines(false);
getFeatureDisplayArray()[i].setShowReverseFrameLines(false);
}
}
});
display_menu.add(hide_on_frame_lines_item);
final JMenuItem show_on_frame_lines_item =
new JMenuItem("Show Frame Lines");
show_on_frame_lines_item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
for(int i = 0 ; i < getFeatureDisplayArray().length ; ++i)
{
getFeatureDisplayArray()[i].setShowForwardFrameLines(true);
getFeatureDisplayArray()[i].setShowReverseFrameLines(true);
}
}
});
display_menu.add(show_on_frame_lines_item);
menu_bar.add(display_menu);
}
/**
* Make a new File menu replacing the current one(if any).
**/
private void makeFileMenu()
{
file_menu.removeAll();
final EntryGroup[] entry_group_array = getEntryGroupArray();
JMenuItem popFileManager = new JMenuItem("Show File Manager ...");
popFileManager.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(ActMain.filemanager == null)
ActMain.filemanager = new FileManager(MultiComparator.this,null);
else
ActMain.filemanager.setVisible(true);
}
});
file_menu.add(popFileManager);
if(entry_group_array[0] ==
entry_group_array[entry_group_array.length - 1])
{
final JMenuItem rotate_button = new JMenuItem("Rotate Sequences");
rotate_button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
rotateSequences();
}
});
file_menu.add(rotate_button);
file_menu.addSeparator();
}
for(int i = 0; i < getEntryGroupArray().length; ++i)
{
final EntryGroup entry_group = getEntryGroupArray()[i];
final String new_menu_name = makeNewSubMenuName(entry_group);
final JMenu entry_group_menu = new JMenu(new_menu_name);
file_menu.add(entry_group_menu);
for(int source_index = 0; source_index < entry_sources.size();
++source_index)
{
final EntrySource this_source =
entry_sources.elementAt(source_index);
if(this_source.isFullEntrySource())
continue;
String entry_source_name = this_source.getSourceName();
String menu_item_name = null;
if(entry_source_name.equals("Filesystem"))
menu_item_name = "Read An Entry ...";
else
menu_item_name = "Read An Entry From " + entry_source_name + " ...";
final JMenuItem read_entry = new JMenuItem(menu_item_name);
read_entry.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
readAnEntry(this_source,entry_group);
}
});
entry_group_menu.add(read_entry);
}
entry_group_menu.addSeparator();
if(entry_group == null || entry_group.size() == 0)
{
// don't create a menu
}
else
{
final JMenu save_entry_menu = new JMenu("Save Entry");
for(int entry_index = 0; entry_index < entry_group.size();
++entry_index)
{
final Entry this_entry = entry_group.elementAt(entry_index);
String entry_name = this_entry.getName();
if(entry_name == null)
entry_name = "no name";
final ActionListener save_entry_listener =
new ActionListener()
{
public void actionPerformed(final ActionEvent event)
{
MultiComparator.this.saveEntry(this_entry);
}
};
final JMenuItem save_entry_item = new JMenuItem(entry_name);
save_entry_item.addActionListener(save_entry_listener);
save_entry_menu.add(save_entry_item);
}
entry_group_menu.add(save_entry_menu);
final JMenuItem save_all_menu = new JMenuItem("Save All");
save_all_menu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
for(int entry_index = 0; entry_index < entry_group.size();
++entry_index)
{
final Entry this_entry = entry_group.elementAt(entry_index);
MultiComparator.this.saveEntry(this_entry);
}
}
});
entry_group_menu.add(save_all_menu);
entry_group_menu.addSeparator();
}
final JMenuItem edit_subject = new JMenuItem("Edit In Artemis");
edit_subject.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
final EntryEdit entry_edit = new EntryEdit(entry_group);
entry_edit.setVisible(true);
}
});
entry_group_menu.add(edit_subject);
}
file_menu.addSeparator();
final JMenuItem close_button = new JMenuItem("Close");
close_button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
closeComparator();
}
});
file_menu.add(close_button);
}
/**
* Read an entry
**/
private void readAnEntry(final EntrySource this_source,
final EntryGroup entry_group)
{
final ProgressThread progress_thread = new ProgressThread(null,
"Loading Entry...");
SwingWorker entryWorker = new SwingWorker()
{
public Object construct()
{
try
{
final Entry new_entry = this_source.getEntry(entry_group.getBases(),
progress_thread, true);
if(new_entry != null)
entry_group.add(new_entry);
}
catch(final OutOfRangeException e)
{
new MessageDialog(MultiComparator.this,
"read failed: one of the features " +
"in the entry has an out of " +
"range location: " +
e.getMessage());
}
catch(final IOException e)
{
new MessageDialog(MultiComparator.this,
"read failed due to an IO error: " +
e.getMessage());
}
return null;
}
public void finished()
{
if(progress_thread !=null)
progress_thread.finished();
}
};
entryWorker.start();
}
/**
* Read an entry
**/
private void readAnEntryFromFile(final File file,
final EntryGroup entry_group)
{
final ProgressThread progress_thread = new ProgressThread(null,
"Loading Entry...");
progress_thread.start();
SwingWorker entryWorker = new SwingWorker()
{
public Object construct()
{
try
{
EntryInformation new_entry_information =
new SimpleEntryInformation(Options.getArtemisEntryInformation());
final Entry new_entry = new Entry(entry_group.getBases(),
EntryFileDialog.getEntryFromFile(null,
new FileDocument(file),
new_entry_information, false));
if(new_entry != null)
entry_group.add(new_entry);
}
catch(final OutOfRangeException e)
{
new MessageDialog(MultiComparator.this,
"read failed: one of the features " +
"in the entry has an out of " +
"range location: " +
e.getMessage());
}
return null;
}
public void finished()
{
if(progress_thread !=null)
progress_thread.finished();
}
};
entryWorker.start();
}
/**
* Return the current default font(from Diana.options).
**/
private Font getDefaultFont()
{
return Options.getOptions().getFont();
}
/**
* Return the EntryGroup objects that were passed to the constructor.
**/
private EntryGroup[] getEntryGroupArray()
{
return entry_group_array;
}
/**
* Return the ComparisonData objects that were passed to the constructor.
**/
private ComparisonData[] getComparisonDataArray()
{
return comparison_data_array;
}
/**
* Return the AlignmentViewer objects that were created in the constructor.
**/
private AlignmentViewer[] getAlignmentViewerArray()
{
return alignment_viewer_array;
}
/**
* Return the FeatureDisplay objects that were created in the constructor.
**/
private FeatureDisplay[] getFeatureDisplayArray()
{
return feature_display_array;
}