2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Rectangle;
27 import java.awt.Toolkit;
28 import java.awt.datatransfer.Clipboard;
29 import java.awt.datatransfer.DataFlavor;
30 import java.awt.datatransfer.StringSelection;
31 import java.awt.datatransfer.Transferable;
32 import java.awt.dnd.DnDConstants;
33 import java.awt.dnd.DropTargetDragEvent;
34 import java.awt.dnd.DropTargetDropEvent;
35 import java.awt.dnd.DropTargetEvent;
36 import java.awt.dnd.DropTargetListener;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.awt.event.FocusAdapter;
40 import java.awt.event.FocusEvent;
41 import java.awt.event.ItemEvent;
42 import java.awt.event.ItemListener;
43 import java.awt.event.KeyAdapter;
44 import java.awt.event.KeyEvent;
45 import java.awt.event.MouseEvent;
46 import java.awt.print.PageFormat;
47 import java.awt.print.PrinterJob;
48 import java.beans.PropertyChangeEvent;
50 import java.io.FileWriter;
51 import java.io.IOException;
52 import java.io.PrintWriter;
54 import java.util.ArrayList;
55 import java.util.Arrays;
56 import java.util.Deque;
57 import java.util.Enumeration;
58 import java.util.Hashtable;
59 import java.util.List;
60 import java.util.Locale;
61 import java.util.Vector;
62 import java.util.concurrent.Callable;
64 import javax.swing.ButtonGroup;
65 import javax.swing.JCheckBoxMenuItem;
66 import javax.swing.JComponent;
67 import javax.swing.JEditorPane;
68 import javax.swing.JInternalFrame;
69 import javax.swing.JLabel;
70 import javax.swing.JLayeredPane;
71 import javax.swing.JMenu;
72 import javax.swing.JMenuItem;
73 import javax.swing.JPanel;
74 import javax.swing.JScrollPane;
75 import javax.swing.SwingUtilities;
77 import ext.vamsas.ServiceHandle;
78 import jalview.analysis.AlignmentSorter;
79 import jalview.analysis.AlignmentUtils;
80 import jalview.analysis.CrossRef;
81 import jalview.analysis.Dna;
82 import jalview.analysis.GeneticCodeI;
83 import jalview.analysis.ParseProperties;
84 import jalview.analysis.SequenceIdMatcher;
85 import jalview.api.AlignExportSettingsI;
86 import jalview.api.AlignViewControllerGuiI;
87 import jalview.api.AlignViewControllerI;
88 import jalview.api.AlignViewportI;
89 import jalview.api.AlignmentViewPanel;
90 import jalview.api.FeatureSettingsControllerI;
91 import jalview.api.FeatureSettingsModelI;
92 import jalview.api.SplitContainerI;
93 import jalview.api.ViewStyleI;
94 import jalview.api.analysis.SimilarityParamsI;
95 import jalview.bin.Cache;
96 import jalview.bin.Console;
97 import jalview.bin.Jalview;
98 import jalview.commands.CommandI;
99 import jalview.commands.EditCommand;
100 import jalview.commands.EditCommand.Action;
101 import jalview.commands.OrderCommand;
102 import jalview.commands.RemoveGapColCommand;
103 import jalview.commands.RemoveGapsCommand;
104 import jalview.commands.SlideSequencesCommand;
105 import jalview.commands.TrimRegionCommand;
106 import jalview.datamodel.AlignExportSettingsAdapter;
107 import jalview.datamodel.AlignedCodonFrame;
108 import jalview.datamodel.Alignment;
109 import jalview.datamodel.AlignmentAnnotation;
110 import jalview.datamodel.AlignmentExportData;
111 import jalview.datamodel.AlignmentI;
112 import jalview.datamodel.AlignmentOrder;
113 import jalview.datamodel.AlignmentView;
114 import jalview.datamodel.ColumnSelection;
115 import jalview.datamodel.HiddenColumns;
116 import jalview.datamodel.PDBEntry;
117 import jalview.datamodel.SeqCigar;
118 import jalview.datamodel.Sequence;
119 import jalview.datamodel.SequenceGroup;
120 import jalview.datamodel.SequenceI;
121 import jalview.gui.ColourMenuHelper.ColourChangeListener;
122 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
123 import jalview.io.AlignmentProperties;
124 import jalview.io.AnnotationFile;
125 import jalview.io.BackupFiles;
126 import jalview.io.BioJsHTMLOutput;
127 import jalview.io.DataSourceType;
128 import jalview.io.FileFormat;
129 import jalview.io.FileFormatI;
130 import jalview.io.FileFormats;
131 import jalview.io.FileLoader;
132 import jalview.io.FileParse;
133 import jalview.io.FormatAdapter;
134 import jalview.io.HtmlSvgOutput;
135 import jalview.io.IdentifyFile;
136 import jalview.io.JPredFile;
137 import jalview.io.JalviewFileChooser;
138 import jalview.io.JalviewFileView;
139 import jalview.io.JnetAnnotationMaker;
140 import jalview.io.NewickFile;
141 import jalview.io.ScoreMatrixFile;
142 import jalview.io.TCoffeeScoreFile;
143 import jalview.io.vcf.VCFLoader;
144 import jalview.jbgui.GAlignFrame;
145 import jalview.project.Jalview2XML;
146 import jalview.schemes.ColourSchemeI;
147 import jalview.schemes.ColourSchemes;
148 import jalview.schemes.ResidueColourScheme;
149 import jalview.schemes.TCoffeeColourScheme;
150 import jalview.util.HttpUtils;
151 import jalview.util.ImageMaker.TYPE;
152 import jalview.util.MessageManager;
153 import jalview.util.Platform;
154 import jalview.viewmodel.AlignmentViewport;
155 import jalview.viewmodel.ViewportRanges;
156 import jalview.ws.DBRefFetcher;
157 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
158 import jalview.ws.jws1.Discoverer;
159 import jalview.ws.jws2.Jws2Discoverer;
160 import jalview.ws.jws2.jabaws2.Jws2Instance;
161 import jalview.ws.seqfetcher.DbSourceProxy;
167 * @version $Revision$
169 @SuppressWarnings("serial")
170 public class AlignFrame extends GAlignFrame implements DropTargetListener,
171 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
174 public static final int DEFAULT_WIDTH = 700;
176 public static final int DEFAULT_HEIGHT = 500;
179 * The currently displayed panel (selected tabbed view if more than one)
181 public AlignmentPanel alignPanel;
183 AlignViewport viewport;
185 public AlignViewControllerI avc;
187 List<AlignmentPanel> alignPanels = new ArrayList<>();
190 * Last format used to load or save alignments in this window
192 FileFormatI currentFileFormat = null;
195 * Current filename for this alignment
197 String fileName = null;
202 * Creates a new AlignFrame object with specific width and height.
208 public AlignFrame(AlignmentI al, int width, int height)
210 this(al, null, width, height);
214 * Creates a new AlignFrame object with specific width, height and
220 * @param sequenceSetId
222 public AlignFrame(AlignmentI al, int width, int height,
223 String sequenceSetId)
225 this(al, null, width, height, sequenceSetId);
229 * Creates a new AlignFrame object with specific width, height and
235 * @param sequenceSetId
238 public AlignFrame(AlignmentI al, int width, int height,
239 String sequenceSetId, String viewId)
241 this(al, null, width, height, sequenceSetId, viewId);
245 * new alignment window with hidden columns
249 * @param hiddenColumns
250 * ColumnSelection or null
252 * Width of alignment frame
256 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
259 this(al, hiddenColumns, width, height, null);
263 * Create alignment frame for al with hiddenColumns, a specific width and
264 * height, and specific sequenceId
267 * @param hiddenColumns
270 * @param sequenceSetId
273 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
274 int height, String sequenceSetId)
276 this(al, hiddenColumns, width, height, sequenceSetId, null);
280 * Create alignment frame for al with hiddenColumns, a specific width and
281 * height, and specific sequenceId
284 * @param hiddenColumns
287 * @param sequenceSetId
292 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
293 int height, String sequenceSetId, String viewId)
295 setSize(width, height);
297 if (al.getDataset() == null)
302 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
304 alignPanel = new AlignmentPanel(this, viewport);
306 addAlignmentPanel(alignPanel, true);
310 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
311 HiddenColumns hiddenColumns, int width, int height)
313 setSize(width, height);
315 if (al.getDataset() == null)
320 viewport = new AlignViewport(al, hiddenColumns);
322 if (hiddenSeqs != null && hiddenSeqs.length > 0)
324 viewport.hideSequence(hiddenSeqs);
326 alignPanel = new AlignmentPanel(this, viewport);
327 addAlignmentPanel(alignPanel, true);
332 * Make a new AlignFrame from existing alignmentPanels
339 public AlignFrame(AlignmentPanel ap)
343 addAlignmentPanel(ap, false);
348 * initalise the alignframe from the underlying viewport data and the
355 // setBackground(Color.white); // BH 2019
357 if (!Jalview.isHeadlessMode())
359 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
362 avc = new jalview.controller.AlignViewController(this, viewport,
364 if (viewport.getAlignmentConservationAnnotation() == null)
366 // BLOSUM62Colour.setEnabled(false);
367 conservationMenuItem.setEnabled(false);
368 modifyConservation.setEnabled(false);
369 // PIDColour.setEnabled(false);
370 // abovePIDThreshold.setEnabled(false);
371 // modifyPID.setEnabled(false);
374 String sortby = Cache.getDefault("SORT_ALIGNMENT", "No sort");
376 if (sortby.equals("Id"))
378 sortIDMenuItem_actionPerformed(null);
380 else if (sortby.equals("Pairwise Identity"))
382 sortPairwiseMenuItem_actionPerformed(null);
386 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
388 setMenusFromViewport(viewport);
389 buildSortByAnnotationScoresMenu();
390 calculateTree.addActionListener(new ActionListener()
394 public void actionPerformed(ActionEvent e)
401 if (Desktop.desktop != null)
403 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
404 if (!Platform.isJS())
406 addServiceListeners();
411 if (viewport.getWrapAlignment())
413 wrapMenuItem_actionPerformed(null);
416 if (Cache.getDefault("SHOW_OVERVIEW", false))
418 this.overviewMenuItem_actionPerformed(null);
423 final List<AlignmentViewPanel> selviews = new ArrayList<>();
424 final List<AlignmentPanel> origview = new ArrayList<>();
425 final String menuLabel = MessageManager
426 .getString("label.copy_format_from");
427 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
428 new ViewSetProvider()
432 public AlignmentPanel[] getAllAlignmentPanels()
435 origview.add(alignPanel);
436 // make an array of all alignment panels except for this one
437 List<AlignmentPanel> aps = new ArrayList<>(
438 Arrays.asList(Desktop.getAlignmentPanels(null)));
439 aps.remove(AlignFrame.this.alignPanel);
440 return aps.toArray(new AlignmentPanel[aps.size()]);
442 }, selviews, new ItemListener()
446 public void itemStateChanged(ItemEvent e)
448 if (origview.size() > 0)
450 final AlignmentPanel ap = origview.get(0);
453 * Copy the ViewStyle of the selected panel to 'this one'.
454 * Don't change value of 'scaleProteinAsCdna' unless copying
457 ViewStyleI vs = selviews.get(0).getAlignViewport()
459 boolean fromSplitFrame = selviews.get(0)
460 .getAlignViewport().getCodingComplement() != null;
463 vs.setScaleProteinAsCdna(ap.getAlignViewport()
464 .getViewStyle().isScaleProteinAsCdna());
466 ap.getAlignViewport().setViewStyle(vs);
469 * Also rescale ViewStyle of SplitFrame complement if there is
470 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
471 * the whole ViewStyle (allow cDNA protein to have different
474 AlignViewportI complement = ap.getAlignViewport()
475 .getCodingComplement();
476 if (complement != null && vs.isScaleProteinAsCdna())
478 AlignFrame af = Desktop.getAlignFrameFor(complement);
479 ((SplitFrame) af.getSplitViewContainer())
481 af.setMenusForViewport();
485 ap.setSelected(true);
486 ap.alignFrame.setMenusForViewport();
491 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase(Locale.ROOT)
492 .indexOf("devel") > -1
493 || Cache.getDefault("VERSION", "DEVELOPMENT")
494 .toLowerCase(Locale.ROOT).indexOf("test") > -1)
496 formatMenu.add(vsel);
498 addFocusListener(new FocusAdapter()
501 public void focusGained(FocusEvent e)
503 Jalview.setCurrentAlignFrame(AlignFrame.this);
510 * Change the filename and format for the alignment, and enable the 'reload'
511 * button functionality.
518 public void setFileName(String file, FileFormatI format)
521 setFileFormat(format);
522 reload.setEnabled(true);
526 * JavaScript will have this, maybe others. More dependable than a file name
527 * and maintains a reference to the actual bytes loaded.
531 public void setFileObject(File file)
533 this.fileObject = file;
537 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
540 void addKeyListener()
542 addKeyListener(new KeyAdapter()
545 public void keyPressed(KeyEvent evt)
547 if (viewport.cursorMode
548 && ((evt.getKeyCode() >= KeyEvent.VK_0
549 && evt.getKeyCode() <= KeyEvent.VK_9)
550 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
551 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
552 && Character.isDigit(evt.getKeyChar()))
554 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
557 switch (evt.getKeyCode())
560 case 27: // escape key
561 deselectAllSequenceMenuItem_actionPerformed(null);
565 case KeyEvent.VK_DOWN:
566 if (evt.isAltDown() || !viewport.cursorMode)
568 moveSelectedSequences(false);
570 if (viewport.cursorMode)
572 alignPanel.getSeqPanel().moveCursor(0, 1, evt.isShiftDown());
577 if (evt.isAltDown() || !viewport.cursorMode)
579 moveSelectedSequences(true);
581 if (viewport.cursorMode)
583 alignPanel.getSeqPanel().moveCursor(0, -1, evt.isShiftDown());
588 case KeyEvent.VK_LEFT:
589 if (evt.isAltDown() || !viewport.cursorMode)
591 slideSequences(false,
592 alignPanel.getSeqPanel().getKeyboardNo1());
596 alignPanel.getSeqPanel().moveCursor(-1, 0, evt.isShiftDown());
601 case KeyEvent.VK_RIGHT:
602 if (evt.isAltDown() || !viewport.cursorMode)
604 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
608 alignPanel.getSeqPanel().moveCursor(1, 0, evt.isShiftDown());
612 case KeyEvent.VK_SPACE:
613 if (viewport.cursorMode)
615 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
616 || evt.isShiftDown() || evt.isAltDown());
620 // case KeyEvent.VK_A:
621 // if (viewport.cursorMode)
623 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
624 // //System.out.println("A");
628 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
629 * System.out.println("closing bracket"); } break;
631 case KeyEvent.VK_DELETE:
632 case KeyEvent.VK_BACK_SPACE:
633 if (!viewport.cursorMode)
635 cut_actionPerformed();
639 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
640 || evt.isShiftDown() || evt.isAltDown());
646 if (viewport.cursorMode)
648 alignPanel.getSeqPanel().setCursorRow();
652 if (viewport.cursorMode && !evt.isControlDown())
654 alignPanel.getSeqPanel().setCursorColumn();
658 if (viewport.cursorMode)
660 alignPanel.getSeqPanel().setCursorPosition();
664 case KeyEvent.VK_ENTER:
665 case KeyEvent.VK_COMMA:
666 if (viewport.cursorMode)
668 alignPanel.getSeqPanel().setCursorRowAndColumn();
673 if (viewport.cursorMode)
675 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
679 if (viewport.cursorMode)
681 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
686 viewport.cursorMode = !viewport.cursorMode;
687 setStatus(MessageManager
688 .formatMessage("label.keyboard_editing_mode", new String[]
689 { (viewport.cursorMode ? "on" : "off") }));
690 if (viewport.cursorMode)
692 ViewportRanges ranges = viewport.getRanges();
693 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
695 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
698 alignPanel.getSeqPanel().seqCanvas.repaint();
704 Help.showHelpWindow();
705 } catch (Exception ex)
707 ex.printStackTrace();
712 boolean toggleSeqs = !evt.isControlDown();
713 boolean toggleCols = !evt.isShiftDown();
714 toggleHiddenRegions(toggleSeqs, toggleCols);
719 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
720 boolean modifyExisting = true; // always modify, don't clear
721 // evt.isShiftDown();
722 boolean invertHighlighted = evt.isAltDown();
723 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
727 case KeyEvent.VK_PAGE_UP:
728 viewport.getRanges().pageUp();
730 case KeyEvent.VK_PAGE_DOWN:
731 viewport.getRanges().pageDown();
737 public void keyReleased(KeyEvent evt)
739 switch (evt.getKeyCode())
741 case KeyEvent.VK_LEFT:
742 if (evt.isAltDown() || !viewport.cursorMode)
744 viewport.firePropertyChange("alignment", null,
745 viewport.getAlignment().getSequences());
749 case KeyEvent.VK_RIGHT:
750 if (evt.isAltDown() || !viewport.cursorMode)
752 viewport.firePropertyChange("alignment", null,
753 viewport.getAlignment().getSequences());
761 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
763 ap.alignFrame = this;
764 avc = new jalview.controller.AlignViewController(this, viewport,
769 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
771 int aSize = alignPanels.size();
773 tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
775 if (aSize == 1 && ap.av.getViewName() == null)
777 this.getContentPane().add(ap, BorderLayout.CENTER);
783 setInitialTabVisible();
786 expandViews.setEnabled(true);
787 gatherViews.setEnabled(true);
788 tabbedPane.addTab(ap.av.getViewName(), ap);
790 ap.setVisible(false);
795 if (ap.av.isPadGaps())
797 ap.av.getAlignment().padGaps();
799 ap.av.updateConservation(ap);
800 ap.av.updateConsensus(ap);
801 ap.av.updateStrucConsensus(ap);
805 public void setInitialTabVisible()
807 expandViews.setEnabled(true);
808 gatherViews.setEnabled(true);
809 tabbedPane.setVisible(true);
810 AlignmentPanel first = alignPanels.get(0);
811 tabbedPane.addTab(first.av.getViewName(), first);
812 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
815 public AlignViewport getViewport()
820 /* Set up intrinsic listeners for dynamically generated GUI bits. */
821 private void addServiceListeners()
823 final java.beans.PropertyChangeListener thisListener;
824 Desktop.instance.addJalviewPropertyChangeListener("services",
825 thisListener = new java.beans.PropertyChangeListener()
828 public void propertyChange(PropertyChangeEvent evt)
830 // // System.out.println("Discoverer property change.");
831 // if (evt.getPropertyName().equals("services"))
833 SwingUtilities.invokeLater(new Runnable()
840 "Rebuild WS Menu for service change");
841 BuildWebServiceMenu();
848 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
851 public void internalFrameClosed(
852 javax.swing.event.InternalFrameEvent evt)
854 // System.out.println("deregistering discoverer listener");
855 Desktop.instance.removeJalviewPropertyChangeListener("services",
857 closeMenuItem_actionPerformed(true);
860 // Finally, build the menu once to get current service state
861 new Thread(new Runnable()
866 BuildWebServiceMenu();
872 * Configure menu items that vary according to whether the alignment is
873 * nucleotide or protein
875 public void setGUINucleotide()
877 AlignmentI al = getViewport().getAlignment();
878 boolean nucleotide = al.isNucleotide();
880 loadVcf.setVisible(nucleotide);
881 showTranslation.setVisible(nucleotide);
882 showReverse.setVisible(nucleotide);
883 showReverseComplement.setVisible(nucleotide);
884 conservationMenuItem.setEnabled(!nucleotide);
886 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
887 showGroupConservation.setEnabled(!nucleotide);
889 showComplementMenuItem
890 .setText(nucleotide ? MessageManager.getString("label.protein")
891 : MessageManager.getString("label.nucleotide"));
895 * set up menus for the current viewport. This may be called after any
896 * operation that affects the data in the current view (selection changed,
897 * etc) to update the menus to reflect the new state.
900 public void setMenusForViewport()
902 setMenusFromViewport(viewport);
906 * Need to call this method when tabs are selected for multiple views, or when
907 * loading from Jalview2XML.java
912 public void setMenusFromViewport(AlignViewport av)
914 padGapsMenuitem.setSelected(av.isPadGaps());
915 colourTextMenuItem.setSelected(av.isShowColourText());
916 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
917 modifyPID.setEnabled(abovePIDThreshold.isSelected());
918 conservationMenuItem.setSelected(av.getConservationSelected());
919 modifyConservation.setEnabled(conservationMenuItem.isSelected());
920 seqLimits.setSelected(av.getShowJVSuffix());
921 idRightAlign.setSelected(av.isRightAlignIds());
922 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
923 renderGapsMenuItem.setSelected(av.isRenderGaps());
924 wrapMenuItem.setSelected(av.getWrapAlignment());
925 scaleAbove.setVisible(av.getWrapAlignment());
926 scaleLeft.setVisible(av.getWrapAlignment());
927 scaleRight.setVisible(av.getWrapAlignment());
928 annotationPanelMenuItem.setState(av.isShowAnnotation());
930 * Show/hide annotations only enabled if annotation panel is shown
932 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
933 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
934 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
935 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
936 viewBoxesMenuItem.setSelected(av.getShowBoxes());
937 viewTextMenuItem.setSelected(av.getShowText());
938 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
939 showGroupConsensus.setSelected(av.isShowGroupConsensus());
940 showGroupConservation.setSelected(av.isShowGroupConservation());
941 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
942 showSequenceLogo.setSelected(av.isShowSequenceLogo());
943 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
945 ColourMenuHelper.setColourSelected(colourMenu,
946 av.getGlobalColourScheme());
948 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
949 hiddenMarkers.setState(av.getShowHiddenMarkers());
950 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
951 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
952 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
953 autoCalculate.setSelected(av.autoCalculateConsensus);
954 sortByTree.setSelected(av.sortByTree);
955 listenToViewSelections.setSelected(av.followSelection);
957 showProducts.setEnabled(canShowProducts());
958 setGroovyEnabled(Desktop.getGroovyConsole() != null);
964 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
968 public void setGroovyEnabled(boolean b)
970 runGroovy.setEnabled(b);
973 private IProgressIndicator progressBar;
978 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
981 public void setProgressBar(String message, long id)
983 progressBar.setProgressBar(message, id);
987 public void registerHandler(final long id,
988 final IProgressIndicatorHandler handler)
990 progressBar.registerHandler(id, handler);
995 * @return true if any progress bars are still active
998 public boolean operationInProgress()
1000 return progressBar.operationInProgress();
1004 * Sets the text of the status bar. Note that setting a null or empty value
1005 * will cause the status bar to be hidden, with possibly undesirable flicker
1006 * of the screen layout.
1009 public void setStatus(String text)
1011 statusBar.setText(text == null || text.isEmpty() ? " " : text);
1015 * Added so Castor Mapping file can obtain Jalview Version
1017 public String getVersion()
1019 return Cache.getProperty("VERSION");
1022 public FeatureRenderer getFeatureRenderer()
1024 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1028 public void fetchSequence_actionPerformed()
1030 new SequenceFetcher(this);
1034 public void addFromFile_actionPerformed(ActionEvent e)
1036 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1040 public void reload_actionPerformed(ActionEvent e)
1042 if (fileName != null)
1044 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1045 // originating file's format
1046 // TODO: work out how to recover feature settings for correct view(s) when
1047 // file is reloaded.
1048 if (FileFormat.Jalview.equals(currentFileFormat))
1050 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1051 for (int i = 0; i < frames.length; i++)
1053 if (frames[i] instanceof AlignFrame && frames[i] != this
1054 && ((AlignFrame) frames[i]).fileName != null
1055 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1059 frames[i].setSelected(true);
1060 Desktop.instance.closeAssociatedWindows();
1061 } catch (java.beans.PropertyVetoException ex)
1067 Desktop.instance.closeAssociatedWindows();
1069 FileLoader loader = new FileLoader();
1070 DataSourceType protocol = HttpUtils.startsWithHttpOrHttps(fileName)
1071 ? DataSourceType.URL
1072 : DataSourceType.FILE;
1073 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1077 Rectangle bounds = this.getBounds();
1079 FileLoader loader = new FileLoader();
1081 AlignFrame newframe = null;
1083 if (fileObject == null)
1086 DataSourceType protocol = HttpUtils.startsWithHttpOrHttps(
1087 fileName) ? DataSourceType.URL : DataSourceType.FILE;
1088 newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
1093 newframe = loader.LoadFileWaitTillLoaded(fileObject,
1094 DataSourceType.FILE, currentFileFormat);
1097 newframe.setBounds(bounds);
1098 if (featureSettings != null && featureSettings.isShowing())
1100 final Rectangle fspos = featureSettings.frame.getBounds();
1101 // TODO: need a 'show feature settings' function that takes bounds -
1102 // need to refactor Desktop.addFrame
1103 newframe.featureSettings_actionPerformed(null);
1104 final FeatureSettings nfs = newframe.featureSettings;
1105 SwingUtilities.invokeLater(new Runnable()
1110 nfs.frame.setBounds(fspos);
1113 this.featureSettings.close();
1114 this.featureSettings = null;
1116 this.closeMenuItem_actionPerformed(true);
1122 public void addFromText_actionPerformed(ActionEvent e)
1125 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1129 public void addFromURL_actionPerformed(ActionEvent e)
1131 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1135 public void save_actionPerformed(ActionEvent e)
1137 if (fileName == null || (currentFileFormat == null)
1138 || HttpUtils.startsWithHttpOrHttps(fileName))
1140 saveAs_actionPerformed();
1144 saveAlignment(fileName, currentFileFormat);
1149 * Saves the alignment to a file with a name chosen by the user, if necessary
1150 * warning if a file would be overwritten
1153 public void saveAs_actionPerformed()
1155 String format = currentFileFormat == null ? null
1156 : currentFileFormat.getName();
1157 JalviewFileChooser chooser = JalviewFileChooser
1158 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1160 chooser.setFileView(new JalviewFileView());
1161 chooser.setDialogTitle(
1162 MessageManager.getString("label.save_alignment_to_file"));
1163 chooser.setToolTipText(MessageManager.getString("action.save"));
1165 int value = chooser.showSaveDialog(this);
1167 if (value != JalviewFileChooser.APPROVE_OPTION)
1171 currentFileFormat = chooser.getSelectedFormat();
1172 // todo is this (2005) test now obsolete - value is never null?
1173 while (currentFileFormat == null)
1175 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1177 .getString("label.select_file_format_before_saving"),
1178 MessageManager.getString("label.file_format_not_specified"),
1179 JvOptionPane.WARNING_MESSAGE);
1180 currentFileFormat = chooser.getSelectedFormat();
1181 value = chooser.showSaveDialog(this);
1182 if (value != JalviewFileChooser.APPROVE_OPTION)
1188 fileName = chooser.getSelectedFile().getPath();
1190 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1191 Cache.setProperty("LAST_DIRECTORY", fileName);
1192 saveAlignment(fileName, currentFileFormat);
1195 boolean lastSaveSuccessful = false;
1197 FileFormatI lastFormatSaved;
1199 String lastFilenameSaved;
1202 * Raise a dialog or status message for the last call to saveAlignment.
1204 * @return true if last call to saveAlignment(file, format) was successful.
1206 public boolean isSaveAlignmentSuccessful()
1209 if (!lastSaveSuccessful)
1211 if (!Platform.isHeadless())
1213 JvOptionPane.showInternalMessageDialog(this, MessageManager
1214 .formatMessage("label.couldnt_save_file", new Object[]
1215 { lastFilenameSaved }),
1216 MessageManager.getString("label.error_saving_file"),
1217 JvOptionPane.WARNING_MESSAGE);
1221 Console.error(MessageManager
1222 .formatMessage("label.couldnt_save_file", new Object[]
1223 { lastFilenameSaved }));
1229 setStatus(MessageManager.formatMessage(
1230 "label.successfully_saved_to_file_in_format", new Object[]
1231 { lastFilenameSaved, lastFormatSaved }));
1234 return lastSaveSuccessful;
1238 * Saves the alignment to the specified file path, in the specified format,
1239 * which may be an alignment format, or Jalview project format. If the
1240 * alignment has hidden regions, or the format is one capable of including
1241 * non-sequence data (features, annotations, groups), then the user may be
1242 * prompted to specify what to include in the output.
1247 public void saveAlignment(String file, FileFormatI format)
1249 lastSaveSuccessful = true;
1250 lastFilenameSaved = file;
1251 lastFormatSaved = format;
1253 if (FileFormat.Jalview.equals(format))
1255 String shortName = title;
1256 if (shortName.indexOf(File.separatorChar) > -1)
1258 shortName = shortName
1259 .substring(shortName.lastIndexOf(File.separatorChar) + 1);
1261 lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
1264 Console.debug("lastSaveSuccessful=" + lastSaveSuccessful);
1265 if (lastSaveSuccessful)
1267 this.getViewport().setSavedUpToDate(true);
1270 statusBar.setText(MessageManager.formatMessage(
1271 "label.successfully_saved_to_file_in_format", new Object[]
1277 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1278 Callable<Void> cancelAction = () -> {
1279 lastSaveSuccessful = false;
1282 Callable<Void> outputAction = () -> {
1283 // todo defer this to inside formatSequences (or later)
1284 AlignmentExportData exportData = viewport.getAlignExportData(options);
1285 String output = new FormatAdapter(alignPanel, options)
1286 .formatSequences(format, exportData.getAlignment(),
1287 exportData.getOmitHidden(),
1288 exportData.getStartEndPostions(),
1289 viewport.getAlignment().getHiddenColumns());
1292 lastSaveSuccessful = false;
1296 // create backupfiles object and get new temp filename destination
1297 boolean doBackup = BackupFiles.getEnabled();
1298 BackupFiles backupfiles = null;
1301 Console.trace("ALIGNFRAME making backupfiles object for " + file);
1302 backupfiles = new BackupFiles(file);
1306 String tempFilePath = doBackup ? backupfiles.getTempFilePath()
1308 Console.trace("ALIGNFRAME setting PrintWriter");
1309 PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
1311 if (backupfiles != null)
1313 Console.trace("ALIGNFRAME about to write to temp file "
1314 + backupfiles.getTempFilePath());
1318 Console.trace("ALIGNFRAME about to close file");
1320 Console.trace("ALIGNFRAME closed file");
1321 AlignFrame.this.setTitle(file);
1322 statusBar.setText(MessageManager.formatMessage(
1323 "label.successfully_saved_to_file_in_format", new Object[]
1324 { fileName, format.getName() }));
1325 lastSaveSuccessful = true;
1326 } catch (IOException e)
1328 lastSaveSuccessful = false;
1330 "ALIGNFRAME Something happened writing the temp file");
1331 Console.error(e.getMessage());
1332 Console.debug(Cache.getStackTraceString(e));
1333 } catch (Exception ex)
1335 lastSaveSuccessful = false;
1337 "ALIGNFRAME Something unexpected happened writing the temp file");
1338 Console.error(ex.getMessage());
1339 Console.debug(Cache.getStackTraceString(ex));
1344 backupfiles.setWriteSuccess(lastSaveSuccessful);
1345 Console.debug("ALIGNFRAME writing temp file was "
1346 + (lastSaveSuccessful ? "" : "NOT ") + "successful");
1347 // do the backup file roll and rename the temp file to actual file
1348 Console.trace("ALIGNFRAME about to rollBackupsAndRenameTempFile");
1349 lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
1350 Console.debug("ALIGNFRAME performed rollBackupsAndRenameTempFile "
1351 + (lastSaveSuccessful ? "" : "un") + "successfully");
1354 Console.debug("lastSaveSuccessful=" + lastSaveSuccessful);
1355 if (lastSaveSuccessful)
1357 AlignFrame.this.getViewport().setSavedUpToDate(true);
1364 * show dialog with export options if applicable; else just do it
1366 if (AlignExportOptions.isNeeded(viewport, format))
1368 AlignExportOptions choices = new AlignExportOptions(
1369 alignPanel.getAlignViewport(), format, options);
1370 choices.setResponseAction(0, outputAction);
1371 choices.setResponseAction(1, cancelAction);
1372 choices.showDialog();
1378 outputAction.call();
1379 } catch (Exception e)
1381 // TODO Auto-generated catch block
1382 e.printStackTrace();
1388 * Outputs the alignment to textbox in the requested format, if necessary
1389 * first prompting the user for whether to include hidden regions or
1392 * @param fileFormatName
1395 protected void outputText_actionPerformed(String fileFormatName)
1397 FileFormatI fileFormat = FileFormats.getInstance()
1398 .forName(fileFormatName);
1399 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1400 Callable<Void> outputAction = () -> {
1401 // todo defer this to inside formatSequences (or later)
1402 AlignmentExportData exportData = viewport.getAlignExportData(options);
1403 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1404 cap.setForInput(null);
1407 FileFormatI format = fileFormat;
1408 cap.setText(new FormatAdapter(alignPanel, options).formatSequences(
1409 format, exportData.getAlignment(),
1410 exportData.getOmitHidden(),
1411 exportData.getStartEndPostions(),
1412 viewport.getAlignment().getHiddenColumns()));
1413 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1414 "label.alignment_output_command", new Object[]
1415 { fileFormat.getName() }), 600, 500);
1416 } catch (OutOfMemoryError oom)
1418 new OOMWarning("Outputting alignment as " + fileFormat.getName(),
1426 * show dialog with export options if applicable; else just do it
1428 if (AlignExportOptions.isNeeded(viewport, fileFormat))
1430 AlignExportOptions choices = new AlignExportOptions(
1431 alignPanel.getAlignViewport(), fileFormat, options);
1432 choices.setResponseAction(0, outputAction);
1433 choices.showDialog();
1439 outputAction.call();
1440 } catch (Exception e)
1442 e.printStackTrace();
1454 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1456 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1457 htmlSVG.exportHTML(null);
1461 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1463 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1464 bjs.exportHTML(null);
1467 public void createImageMap(File file, String image)
1469 alignPanel.makePNGImageMap(file, image);
1473 * Creates a PNG image of the alignment and writes it to the given file. If
1474 * the file is null, the user is prompted to choose a file.
1479 public void createPNG(File f)
1481 alignPanel.makeAlignmentImage(TYPE.PNG, f);
1485 * Creates an EPS image of the alignment and writes it to the given file. If
1486 * the file is null, the user is prompted to choose a file.
1491 public void createEPS(File f)
1493 alignPanel.makeAlignmentImage(TYPE.EPS, f);
1497 * Creates an SVG image of the alignment and writes it to the given file. If
1498 * the file is null, the user is prompted to choose a file.
1503 public void createSVG(File f)
1505 alignPanel.makeAlignmentImage(TYPE.SVG, f);
1509 public void pageSetup_actionPerformed(ActionEvent e)
1511 PrinterJob printJob = PrinterJob.getPrinterJob();
1512 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1522 public void printMenuItem_actionPerformed(ActionEvent e)
1524 // Putting in a thread avoids Swing painting problems
1525 PrintThread thread = new PrintThread(alignPanel);
1530 public void exportFeatures_actionPerformed(ActionEvent e)
1532 new AnnotationExporter(alignPanel).exportFeatures();
1536 public void exportAnnotations_actionPerformed(ActionEvent e)
1538 new AnnotationExporter(alignPanel).exportAnnotations();
1542 public void associatedData_actionPerformed(ActionEvent e)
1544 final JalviewFileChooser chooser = new JalviewFileChooser(
1545 Cache.getProperty("LAST_DIRECTORY"));
1546 chooser.setFileView(new JalviewFileView());
1547 String tooltip = MessageManager
1548 .getString("label.load_jalview_annotations");
1549 chooser.setDialogTitle(tooltip);
1550 chooser.setToolTipText(tooltip);
1551 chooser.setResponseHandler(0, () -> {
1552 String choice = chooser.getSelectedFile().getPath();
1553 Cache.setProperty("LAST_DIRECTORY", choice);
1554 loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
1558 chooser.showOpenDialog(this);
1562 * Close the current view or all views in the alignment frame. If the frame
1563 * only contains one view then the alignment will be removed from memory.
1565 * @param closeAllTabs
1568 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1570 if (alignPanels != null && alignPanels.size() < 2)
1572 closeAllTabs = true;
1577 if (alignPanels != null)
1581 if (this.isClosed())
1583 // really close all the windows - otherwise wait till
1584 // setClosed(true) is called
1585 for (int i = 0; i < alignPanels.size(); i++)
1587 AlignmentPanel ap = alignPanels.get(i);
1594 closeView(alignPanel);
1599 if (featureSettings != null && featureSettings.isOpen())
1601 featureSettings.close();
1602 featureSettings = null;
1605 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1606 * be called recursively, with the frame now in 'closed' state
1608 this.setClosed(true);
1610 } catch (Exception ex)
1612 ex.printStackTrace();
1617 * Close the specified panel and close up tabs appropriately.
1619 * @param panelToClose
1621 public void closeView(AlignmentPanel panelToClose)
1623 int index = tabbedPane.getSelectedIndex();
1624 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1625 alignPanels.remove(panelToClose);
1626 panelToClose.closePanel();
1627 panelToClose = null;
1629 tabbedPane.removeTabAt(closedindex);
1630 tabbedPane.validate();
1632 if (index > closedindex || index == tabbedPane.getTabCount())
1634 // modify currently selected tab index if necessary.
1638 this.tabSelectionChanged(index);
1644 void updateEditMenuBar()
1647 if (viewport.getHistoryList().size() > 0)
1649 undoMenuItem.setEnabled(true);
1650 CommandI command = viewport.getHistoryList().peek();
1651 undoMenuItem.setText(MessageManager
1652 .formatMessage("label.undo_command", new Object[]
1653 { command.getDescription() }));
1657 undoMenuItem.setEnabled(false);
1658 undoMenuItem.setText(MessageManager.getString("action.undo"));
1661 if (viewport.getRedoList().size() > 0)
1663 redoMenuItem.setEnabled(true);
1665 CommandI command = viewport.getRedoList().peek();
1666 redoMenuItem.setText(MessageManager
1667 .formatMessage("label.redo_command", new Object[]
1668 { command.getDescription() }));
1672 redoMenuItem.setEnabled(false);
1673 redoMenuItem.setText(MessageManager.getString("action.redo"));
1678 public void addHistoryItem(CommandI command)
1680 if (command.getSize() > 0)
1682 viewport.addToHistoryList(command);
1683 viewport.clearRedoList();
1684 updateEditMenuBar();
1685 viewport.updateHiddenColumns();
1686 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1687 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1688 // viewport.getColumnSelection()
1689 // .getHiddenColumns().size() > 0);
1695 * @return alignment objects for all views
1697 AlignmentI[] getViewAlignments()
1699 if (alignPanels != null)
1701 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1703 for (AlignmentPanel ap : alignPanels)
1705 als[i++] = ap.av.getAlignment();
1709 if (viewport != null)
1711 return new AlignmentI[] { viewport.getAlignment() };
1723 protected void undoMenuItem_actionPerformed(ActionEvent e)
1725 if (viewport.getHistoryList().isEmpty())
1729 CommandI command = viewport.getHistoryList().pop();
1730 viewport.addToRedoList(command);
1731 command.undoCommand(getViewAlignments());
1733 AlignmentViewport originalSource = getOriginatingSource(command);
1734 updateEditMenuBar();
1736 if (originalSource != null)
1738 if (originalSource != viewport)
1741 "Implementation worry: mismatch of viewport origin for undo");
1743 originalSource.updateHiddenColumns();
1744 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1746 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1747 // viewport.getColumnSelection()
1748 // .getHiddenColumns().size() > 0);
1749 originalSource.firePropertyChange("alignment", null,
1750 originalSource.getAlignment().getSequences());
1761 protected void redoMenuItem_actionPerformed(ActionEvent e)
1763 if (viewport.getRedoList().size() < 1)
1768 CommandI command = viewport.getRedoList().pop();
1769 viewport.addToHistoryList(command);
1770 command.doCommand(getViewAlignments());
1772 AlignmentViewport originalSource = getOriginatingSource(command);
1773 updateEditMenuBar();
1775 if (originalSource != null)
1778 if (originalSource != viewport)
1781 "Implementation worry: mismatch of viewport origin for redo");
1783 originalSource.updateHiddenColumns();
1784 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1786 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1787 // viewport.getColumnSelection()
1788 // .getHiddenColumns().size() > 0);
1789 originalSource.firePropertyChange("alignment", null,
1790 originalSource.getAlignment().getSequences());
1794 AlignmentViewport getOriginatingSource(CommandI command)
1796 AlignmentViewport originalSource = null;
1797 // For sequence removal and addition, we need to fire
1798 // the property change event FROM the viewport where the
1799 // original alignment was altered
1800 AlignmentI al = null;
1801 if (command instanceof EditCommand)
1803 EditCommand editCommand = (EditCommand) command;
1804 al = editCommand.getAlignment();
1805 List<Component> comps = PaintRefresher.components
1806 .get(viewport.getSequenceSetId());
1808 for (Component comp : comps)
1810 if (comp instanceof AlignmentPanel)
1812 if (al == ((AlignmentPanel) comp).av.getAlignment())
1814 originalSource = ((AlignmentPanel) comp).av;
1821 if (originalSource == null)
1823 // The original view is closed, we must validate
1824 // the current view against the closed view first
1827 PaintRefresher.validateSequences(al, viewport.getAlignment());
1830 originalSource = viewport;
1833 return originalSource;
1837 * Calls AlignmentI.moveSelectedSequencesByOne with current sequence selection
1838 * or the sequence under cursor in keyboard mode
1843 public void moveSelectedSequences(boolean up)
1845 SequenceGroup sg = viewport.getSelectionGroup();
1849 if (viewport.cursorMode)
1851 sg = new SequenceGroup();
1852 sg.addSequence(viewport.getAlignment().getSequenceAt(
1853 alignPanel.getSeqPanel().seqCanvas.cursorY), false);
1861 if (sg.getSize() < 1)
1866 // TODO: JAL-3733 - add an event to the undo buffer for this !
1868 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1869 viewport.getHiddenRepSequences(), up);
1870 alignPanel.paintAlignment(true, false);
1873 synchronized void slideSequences(boolean right, int size)
1875 List<SequenceI> sg = new ArrayList<>();
1876 if (viewport.cursorMode)
1878 sg.add(viewport.getAlignment()
1879 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
1881 else if (viewport.getSelectionGroup() != null
1882 && viewport.getSelectionGroup().getSize() != viewport
1883 .getAlignment().getHeight())
1885 sg = viewport.getSelectionGroup()
1886 .getSequences(viewport.getHiddenRepSequences());
1894 List<SequenceI> invertGroup = new ArrayList<>();
1896 for (SequenceI seq : viewport.getAlignment().getSequences())
1898 if (!sg.contains(seq))
1900 invertGroup.add(seq);
1904 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1906 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1907 for (int i = 0; i < invertGroup.size(); i++)
1909 seqs2[i] = invertGroup.get(i);
1912 SlideSequencesCommand ssc;
1915 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1916 viewport.getGapCharacter());
1920 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1921 viewport.getGapCharacter());
1924 int groupAdjustment = 0;
1925 if (ssc.getGapsInsertedBegin() && right)
1927 if (viewport.cursorMode)
1929 alignPanel.getSeqPanel().moveCursor(size, 0);
1933 groupAdjustment = size;
1936 else if (!ssc.getGapsInsertedBegin() && !right)
1938 if (viewport.cursorMode)
1940 alignPanel.getSeqPanel().moveCursor(-size, 0);
1944 groupAdjustment = -size;
1948 if (groupAdjustment != 0)
1950 viewport.getSelectionGroup().setStartRes(
1951 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1952 viewport.getSelectionGroup().setEndRes(
1953 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1957 * just extend the last slide command if compatible; but not if in
1958 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1960 boolean appendHistoryItem = false;
1961 Deque<CommandI> historyList = viewport.getHistoryList();
1962 boolean inSplitFrame = getSplitViewContainer() != null;
1963 if (!inSplitFrame && historyList != null && historyList.size() > 0
1964 && historyList.peek() instanceof SlideSequencesCommand)
1966 appendHistoryItem = ssc.appendSlideCommand(
1967 (SlideSequencesCommand) historyList.peek());
1970 if (!appendHistoryItem)
1972 addHistoryItem(ssc);
1985 protected void copy_actionPerformed()
1987 if (viewport.getSelectionGroup() == null)
1991 // TODO: preserve the ordering of displayed alignment annotation in any
1992 // internal paste (particularly sequence associated annotation)
1993 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1994 String[] omitHidden = null;
1996 if (viewport.hasHiddenColumns())
1998 omitHidden = viewport.getViewAsString(true);
2001 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
2002 seqs, omitHidden, null);
2004 StringSelection ss = new StringSelection(output);
2008 jalview.gui.Desktop.internalCopy = true;
2009 // Its really worth setting the clipboard contents
2010 // to empty before setting the large StringSelection!!
2011 Toolkit.getDefaultToolkit().getSystemClipboard()
2012 .setContents(new StringSelection(""), null);
2014 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
2016 } catch (OutOfMemoryError er)
2018 new OOMWarning("copying region", er);
2022 HiddenColumns hiddenColumns = null;
2023 if (viewport.hasHiddenColumns())
2025 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
2026 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
2028 // create new HiddenColumns object with copy of hidden regions
2029 // between startRes and endRes, offset by startRes
2030 hiddenColumns = new HiddenColumns(
2031 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
2032 hiddenCutoff, hiddenOffset);
2035 Desktop.jalviewClipboard = new Object[] { seqs,
2036 viewport.getAlignment().getDataset(), hiddenColumns };
2037 setStatus(MessageManager.formatMessage(
2038 "label.copied_sequences_to_clipboard", new Object[]
2039 { Integer.valueOf(seqs.length).toString() }));
2049 protected void pasteNew_actionPerformed(ActionEvent e)
2061 protected void pasteThis_actionPerformed(ActionEvent e)
2067 * Paste contents of Jalview clipboard
2069 * @param newAlignment
2070 * true to paste to a new alignment, otherwise add to this.
2072 void paste(boolean newAlignment)
2074 boolean externalPaste = true;
2077 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2078 Transferable contents = c.getContents(this);
2080 if (contents == null)
2089 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2090 if (str.length() < 1)
2095 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2097 } catch (OutOfMemoryError er)
2099 new OOMWarning("Out of memory pasting sequences!!", er);
2103 SequenceI[] sequences;
2104 boolean annotationAdded = false;
2105 AlignmentI alignment = null;
2107 if (Desktop.jalviewClipboard != null)
2109 // The clipboard was filled from within Jalview, we must use the
2111 // And dataset from the copied alignment
2112 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2113 // be doubly sure that we create *new* sequence objects.
2114 sequences = new SequenceI[newseq.length];
2115 for (int i = 0; i < newseq.length; i++)
2117 sequences[i] = new Sequence(newseq[i]);
2119 alignment = new Alignment(sequences);
2120 externalPaste = false;
2124 // parse the clipboard as an alignment.
2125 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2127 sequences = alignment.getSequencesArray();
2131 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2137 if (Desktop.jalviewClipboard != null)
2139 // dataset is inherited
2140 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2144 // new dataset is constructed
2145 alignment.setDataset(null);
2147 alwidth = alignment.getWidth() + 1;
2151 AlignmentI pastedal = alignment; // preserve pasted alignment object
2152 // Add pasted sequences and dataset into existing alignment.
2153 alignment = viewport.getAlignment();
2154 alwidth = alignment.getWidth() + 1;
2155 // decide if we need to import sequences from an existing dataset
2156 boolean importDs = Desktop.jalviewClipboard != null
2157 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2158 // importDs==true instructs us to copy over new dataset sequences from
2159 // an existing alignment
2160 Vector<SequenceI> newDs = (importDs) ? new Vector<>() : null; // used to
2162 // minimum dataset set
2164 for (int i = 0; i < sequences.length; i++)
2168 newDs.addElement(null);
2170 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2172 if (importDs && ds != null)
2174 if (!newDs.contains(ds))
2176 newDs.setElementAt(ds, i);
2177 ds = new Sequence(ds);
2178 // update with new dataset sequence
2179 sequences[i].setDatasetSequence(ds);
2183 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2188 // copy and derive new dataset sequence
2189 sequences[i] = sequences[i].deriveSequence();
2190 alignment.getDataset()
2191 .addSequence(sequences[i].getDatasetSequence());
2192 // TODO: avoid creation of duplicate dataset sequences with a
2193 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2195 alignment.addSequence(sequences[i]); // merges dataset
2199 newDs.clear(); // tidy up
2201 if (alignment.getAlignmentAnnotation() != null)
2203 for (AlignmentAnnotation alan : alignment
2204 .getAlignmentAnnotation())
2206 if (alan.graphGroup > fgroup)
2208 fgroup = alan.graphGroup;
2212 if (pastedal.getAlignmentAnnotation() != null)
2214 // Add any annotation attached to alignment.
2215 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2216 for (int i = 0; i < alann.length; i++)
2218 annotationAdded = true;
2219 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2221 AlignmentAnnotation newann = new AlignmentAnnotation(
2223 if (newann.graphGroup > -1)
2225 if (newGraphGroups.size() <= newann.graphGroup
2226 || newGraphGroups.get(newann.graphGroup) == null)
2228 for (int q = newGraphGroups
2229 .size(); q <= newann.graphGroup; q++)
2231 newGraphGroups.add(q, null);
2233 newGraphGroups.set(newann.graphGroup,
2234 Integer.valueOf(++fgroup));
2236 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2240 newann.padAnnotation(alwidth);
2241 alignment.addAnnotation(newann);
2251 addHistoryItem(new EditCommand(
2252 MessageManager.getString("label.add_sequences"),
2253 Action.PASTE, sequences, 0, alignment.getWidth(),
2256 // Add any annotations attached to sequences
2257 for (int i = 0; i < sequences.length; i++)
2259 if (sequences[i].getAnnotation() != null)
2261 AlignmentAnnotation newann;
2262 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2264 annotationAdded = true;
2265 newann = sequences[i].getAnnotation()[a];
2266 newann.adjustForAlignment();
2267 newann.padAnnotation(alwidth);
2268 if (newann.graphGroup > -1)
2270 if (newann.graphGroup > -1)
2272 if (newGraphGroups.size() <= newann.graphGroup
2273 || newGraphGroups.get(newann.graphGroup) == null)
2275 for (int q = newGraphGroups
2276 .size(); q <= newann.graphGroup; q++)
2278 newGraphGroups.add(q, null);
2280 newGraphGroups.set(newann.graphGroup,
2281 Integer.valueOf(++fgroup));
2283 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2287 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2291 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2299 // propagate alignment changed.
2300 viewport.getRanges().setEndSeq(alignment.getHeight() - 1);
2301 if (annotationAdded)
2303 // Duplicate sequence annotation in all views.
2304 AlignmentI[] alview = this.getViewAlignments();
2305 for (int i = 0; i < sequences.length; i++)
2307 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2312 for (int avnum = 0; avnum < alview.length; avnum++)
2314 if (alview[avnum] != alignment)
2316 // duplicate in a view other than the one with input focus
2317 int avwidth = alview[avnum].getWidth() + 1;
2318 // this relies on sann being preserved after we
2319 // modify the sequence's annotation array for each duplication
2320 for (int a = 0; a < sann.length; a++)
2322 AlignmentAnnotation newann = new AlignmentAnnotation(
2324 sequences[i].addAlignmentAnnotation(newann);
2325 newann.padAnnotation(avwidth);
2326 alview[avnum].addAnnotation(newann); // annotation was
2327 // duplicated earlier
2328 // TODO JAL-1145 graphGroups are not updated for sequence
2329 // annotation added to several views. This may cause
2331 alview[avnum].setAnnotationIndex(newann, a);
2336 buildSortByAnnotationScoresMenu();
2338 viewport.firePropertyChange("alignment", null,
2339 alignment.getSequences());
2340 if (alignPanels != null)
2342 for (AlignmentPanel ap : alignPanels)
2344 ap.validateAnnotationDimensions(false);
2349 alignPanel.validateAnnotationDimensions(false);
2355 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2357 String newtitle = new String("Copied sequences");
2359 if (Desktop.jalviewClipboard != null
2360 && Desktop.jalviewClipboard[2] != null)
2362 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2363 af.viewport.setHiddenColumns(hc);
2366 // >>>This is a fix for the moment, until a better solution is
2368 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2369 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2370 .getFeatureRenderer());
2372 // TODO: maintain provenance of an alignment, rather than just make the
2373 // title a concatenation of operations.
2376 if (title.startsWith("Copied sequences"))
2382 newtitle = newtitle.concat("- from " + title);
2387 newtitle = new String("Pasted sequences");
2390 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2395 } catch (Exception ex)
2397 ex.printStackTrace();
2398 System.out.println("Exception whilst pasting: " + ex);
2399 // could be anything being pasted in here
2405 protected void expand_newalign(ActionEvent e)
2409 AlignmentI alignment = AlignmentUtils
2410 .expandContext(getViewport().getAlignment(), -1);
2411 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2413 String newtitle = new String("Flanking alignment");
2415 if (Desktop.jalviewClipboard != null
2416 && Desktop.jalviewClipboard[2] != null)
2418 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2419 af.viewport.setHiddenColumns(hc);
2422 // >>>This is a fix for the moment, until a better solution is
2424 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2425 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2426 .getFeatureRenderer());
2428 // TODO: maintain provenance of an alignment, rather than just make the
2429 // title a concatenation of operations.
2431 if (title.startsWith("Copied sequences"))
2437 newtitle = newtitle.concat("- from " + title);
2441 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2443 } catch (Exception ex)
2445 ex.printStackTrace();
2446 System.out.println("Exception whilst pasting: " + ex);
2447 // could be anything being pasted in here
2448 } catch (OutOfMemoryError oom)
2450 new OOMWarning("Viewing flanking region of alignment", oom);
2455 * Action Cut (delete and copy) the selected region
2458 protected void cut_actionPerformed()
2460 copy_actionPerformed();
2461 delete_actionPerformed();
2465 * Performs menu option to Delete the currently selected region
2468 protected void delete_actionPerformed()
2471 SequenceGroup sg = viewport.getSelectionGroup();
2477 Callable okAction = () -> {
2478 SequenceI[] cut = sg.getSequences()
2479 .toArray(new SequenceI[sg.getSize()]);
2481 addHistoryItem(new EditCommand(
2482 MessageManager.getString("label.cut_sequences"), Action.CUT,
2483 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2484 viewport.getAlignment()));
2486 viewport.setSelectionGroup(null);
2487 viewport.sendSelection();
2488 viewport.getAlignment().deleteGroup(sg);
2490 viewport.firePropertyChange("alignment", null,
2491 viewport.getAlignment().getSequences());
2492 if (viewport.getAlignment().getHeight() < 1)
2496 AlignFrame.this.setClosed(true);
2497 } catch (Exception ex)
2505 * If the cut affects all sequences, prompt for confirmation
2507 boolean wholeHeight = sg.getSize() == viewport.getAlignment()
2509 boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes())
2510 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2511 if (wholeHeight && wholeWidth)
2513 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
2514 dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
2515 Object[] options = new Object[] {
2516 MessageManager.getString("action.ok"),
2517 MessageManager.getString("action.cancel") };
2518 dialog.showDialog(MessageManager.getString("warn.delete_all"),
2519 MessageManager.getString("label.delete_all"),
2520 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
2521 options, options[0]);
2528 } catch (Exception e)
2530 e.printStackTrace();
2542 protected void deleteGroups_actionPerformed(ActionEvent e)
2544 if (avc.deleteGroups())
2546 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2547 alignPanel.updateAnnotation();
2548 alignPanel.paintAlignment(true, true);
2559 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2561 SequenceGroup sg = new SequenceGroup(
2562 viewport.getAlignment().getSequences());
2564 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2565 viewport.setSelectionGroup(sg);
2566 viewport.isSelectionGroupChanged(true);
2567 viewport.sendSelection();
2568 // JAL-2034 - should delegate to
2569 // alignPanel to decide if overview needs
2571 alignPanel.paintAlignment(false, false);
2572 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2582 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2584 if (viewport.cursorMode)
2586 alignPanel.getSeqPanel().keyboardNo1 = null;
2587 alignPanel.getSeqPanel().keyboardNo2 = null;
2589 viewport.setSelectionGroup(null);
2590 viewport.getColumnSelection().clear();
2591 viewport.setSearchResults(null);
2592 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2593 // JAL-2034 - should delegate to
2594 // alignPanel to decide if overview needs
2596 alignPanel.paintAlignment(false, false);
2597 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2598 viewport.sendSelection();
2608 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2610 SequenceGroup sg = viewport.getSelectionGroup();
2614 selectAllSequenceMenuItem_actionPerformed(null);
2619 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2621 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2623 // JAL-2034 - should delegate to
2624 // alignPanel to decide if overview needs
2627 alignPanel.paintAlignment(true, false);
2628 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2629 viewport.sendSelection();
2633 public void invertColSel_actionPerformed(ActionEvent e)
2635 viewport.invertColumnSelection();
2636 alignPanel.paintAlignment(true, false);
2637 viewport.sendSelection();
2647 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2649 trimAlignment(true);
2659 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2661 trimAlignment(false);
2664 void trimAlignment(boolean trimLeft)
2666 ColumnSelection colSel = viewport.getColumnSelection();
2669 if (!colSel.isEmpty())
2673 column = colSel.getMin();
2677 column = colSel.getMax();
2681 if (viewport.getSelectionGroup() != null)
2683 seqs = viewport.getSelectionGroup()
2684 .getSequencesAsArray(viewport.getHiddenRepSequences());
2688 seqs = viewport.getAlignment().getSequencesArray();
2691 TrimRegionCommand trimRegion;
2694 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2695 column, viewport.getAlignment());
2696 viewport.getRanges().setStartRes(0);
2700 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2701 column, viewport.getAlignment());
2704 setStatus(MessageManager.formatMessage("label.removed_columns",
2706 { Integer.valueOf(trimRegion.getSize()).toString() }));
2708 addHistoryItem(trimRegion);
2710 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2712 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2713 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2715 viewport.getAlignment().deleteGroup(sg);
2719 viewport.firePropertyChange("alignment", null,
2720 viewport.getAlignment().getSequences());
2731 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2733 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2736 if (viewport.getSelectionGroup() != null)
2738 seqs = viewport.getSelectionGroup()
2739 .getSequencesAsArray(viewport.getHiddenRepSequences());
2740 start = viewport.getSelectionGroup().getStartRes();
2741 end = viewport.getSelectionGroup().getEndRes();
2745 seqs = viewport.getAlignment().getSequencesArray();
2748 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2749 "Remove Gapped Columns", seqs, start, end,
2750 viewport.getAlignment());
2752 addHistoryItem(removeGapCols);
2754 setStatus(MessageManager.formatMessage("label.removed_empty_columns",
2756 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2758 // This is to maintain viewport position on first residue
2759 // of first sequence
2760 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2761 ViewportRanges ranges = viewport.getRanges();
2762 int startRes = seq.findPosition(ranges.getStartRes());
2763 // ShiftList shifts;
2764 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2765 // edit.alColumnChanges=shifts.getInverse();
2766 // if (viewport.hasHiddenColumns)
2767 // viewport.getColumnSelection().compensateForEdits(shifts);
2768 ranges.setStartRes(seq.findIndex(startRes) - 1);
2769 viewport.firePropertyChange("alignment", null,
2770 viewport.getAlignment().getSequences());
2781 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2783 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2786 if (viewport.getSelectionGroup() != null)
2788 seqs = viewport.getSelectionGroup()
2789 .getSequencesAsArray(viewport.getHiddenRepSequences());
2790 start = viewport.getSelectionGroup().getStartRes();
2791 end = viewport.getSelectionGroup().getEndRes();
2795 seqs = viewport.getAlignment().getSequencesArray();
2798 // This is to maintain viewport position on first residue
2799 // of first sequence
2800 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2801 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2803 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2804 viewport.getAlignment()));
2806 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2808 viewport.firePropertyChange("alignment", null,
2809 viewport.getAlignment().getSequences());
2820 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2822 viewport.setPadGaps(padGapsMenuitem.isSelected());
2823 viewport.firePropertyChange("alignment", null,
2824 viewport.getAlignment().getSequences());
2828 * Opens a Finder dialog
2833 public void findMenuItem_actionPerformed(ActionEvent e)
2835 new Finder(alignPanel, false, null);
2839 * Create a new view of the current alignment.
2842 public void newView_actionPerformed(ActionEvent e)
2844 newView(null, true);
2848 * Creates and shows a new view of the current alignment.
2851 * title of newly created view; if null, one will be generated
2852 * @param copyAnnotation
2853 * if true then duplicate all annnotation, groups and settings
2854 * @return new alignment panel, already displayed.
2856 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2859 * Create a new AlignmentPanel (with its own, new Viewport)
2861 AlignmentPanel newap = new jalview.project.Jalview2XML()
2862 .copyAlignPanel(alignPanel);
2863 if (!copyAnnotation)
2866 * remove all groups and annotation except for the automatic stuff
2868 newap.av.getAlignment().deleteAllGroups();
2869 newap.av.getAlignment().deleteAllAnnotations(false);
2872 newap.av.setGatherViewsHere(false);
2874 if (viewport.getViewName() == null)
2876 viewport.setViewName(
2877 MessageManager.getString("label.view_name_original"));
2881 * Views share the same edits undo and redo stacks
2883 newap.av.setHistoryList(viewport.getHistoryList());
2884 newap.av.setRedoList(viewport.getRedoList());
2887 * copy any visualisation settings that are not saved in the project
2889 newap.av.setColourAppliesToAllGroups(
2890 viewport.getColourAppliesToAllGroups());
2893 * Views share the same mappings; need to deregister any new mappings
2894 * created by copyAlignPanel, and register the new reference to the shared
2897 newap.av.replaceMappings(viewport.getAlignment());
2900 * start up cDNA consensus (if applicable) now mappings are in place
2902 if (newap.av.initComplementConsensus())
2904 newap.refresh(true); // adjust layout of annotations
2907 newap.av.setViewName(getNewViewName(viewTitle));
2909 addAlignmentPanel(newap, true);
2910 newap.alignmentChanged();
2912 if (alignPanels.size() == 2)
2914 viewport.setGatherViewsHere(true);
2916 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2922 * Make a new name for the view, ensuring it is unique within the current
2923 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2924 * these now use viewId. Unique view names are still desirable for usability.)
2929 protected String getNewViewName(String viewTitle)
2931 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2932 boolean addFirstIndex = false;
2933 if (viewTitle == null || viewTitle.trim().length() == 0)
2935 viewTitle = MessageManager.getString("action.view");
2936 addFirstIndex = true;
2940 index = 1;// we count from 1 if given a specific name
2942 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2944 List<Component> comps = PaintRefresher.components
2945 .get(viewport.getSequenceSetId());
2947 List<String> existingNames = getExistingViewNames(comps);
2949 while (existingNames.contains(newViewName))
2951 newViewName = viewTitle + " " + (++index);
2957 * Returns a list of distinct view names found in the given list of
2958 * components. View names are held on the viewport of an AlignmentPanel.
2963 protected List<String> getExistingViewNames(List<Component> comps)
2965 List<String> existingNames = new ArrayList<>();
2966 for (Component comp : comps)
2968 if (comp instanceof AlignmentPanel)
2970 AlignmentPanel ap = (AlignmentPanel) comp;
2971 if (!existingNames.contains(ap.av.getViewName()))
2973 existingNames.add(ap.av.getViewName());
2977 return existingNames;
2981 * Explode tabbed views into separate windows.
2984 public void expandViews_actionPerformed(ActionEvent e)
2986 Desktop.explodeViews(this);
2990 * Gather views in separate windows back into a tabbed presentation.
2993 public void gatherViews_actionPerformed(ActionEvent e)
2995 Desktop.instance.gatherViews(this);
3005 public void font_actionPerformed(ActionEvent e)
3007 new FontChooser(alignPanel);
3017 protected void seqLimit_actionPerformed(ActionEvent e)
3019 viewport.setShowJVSuffix(seqLimits.isSelected());
3021 alignPanel.getIdPanel().getIdCanvas()
3022 .setPreferredSize(alignPanel.calculateIdWidth());
3023 alignPanel.paintAlignment(true, false);
3027 public void idRightAlign_actionPerformed(ActionEvent e)
3029 viewport.setRightAlignIds(idRightAlign.isSelected());
3030 alignPanel.paintAlignment(false, false);
3034 public void centreColumnLabels_actionPerformed(ActionEvent e)
3036 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
3037 alignPanel.paintAlignment(false, false);
3043 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3046 protected void followHighlight_actionPerformed()
3049 * Set the 'follow' flag on the Viewport (and scroll to position if now
3052 final boolean state = this.followHighlightMenuItem.getState();
3053 viewport.setFollowHighlight(state);
3056 alignPanel.scrollToPosition(viewport.getSearchResults());
3067 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3069 viewport.setColourText(colourTextMenuItem.isSelected());
3070 alignPanel.paintAlignment(false, false);
3080 public void wrapMenuItem_actionPerformed(ActionEvent e)
3082 scaleAbove.setVisible(wrapMenuItem.isSelected());
3083 scaleLeft.setVisible(wrapMenuItem.isSelected());
3084 scaleRight.setVisible(wrapMenuItem.isSelected());
3085 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3086 alignPanel.updateLayout();
3090 public void showAllSeqs_actionPerformed(ActionEvent e)
3092 viewport.showAllHiddenSeqs();
3096 public void showAllColumns_actionPerformed(ActionEvent e)
3098 viewport.showAllHiddenColumns();
3099 alignPanel.paintAlignment(true, true);
3100 viewport.sendSelection();
3104 public void hideSelSequences_actionPerformed(ActionEvent e)
3106 viewport.hideAllSelectedSeqs();
3110 * called by key handler and the hide all/show all menu items
3115 protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3118 boolean hide = false;
3119 SequenceGroup sg = viewport.getSelectionGroup();
3120 if (!toggleSeqs && !toggleCols)
3122 // Hide everything by the current selection - this is a hack - we do the
3123 // invert and then hide
3124 // first check that there will be visible columns after the invert.
3125 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3126 && sg.getStartRes() <= sg.getEndRes()))
3128 // now invert the sequence set, if required - empty selection implies
3129 // that no hiding is required.
3132 invertSequenceMenuItem_actionPerformed(null);
3133 sg = viewport.getSelectionGroup();
3137 viewport.expandColSelection(sg, true);
3138 // finally invert the column selection and get the new sequence
3140 invertColSel_actionPerformed(null);
3147 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3149 hideSelSequences_actionPerformed(null);
3152 else if (!(toggleCols && viewport.hasSelectedColumns()))
3154 showAllSeqs_actionPerformed(null);
3160 if (viewport.hasSelectedColumns())
3162 hideSelColumns_actionPerformed(null);
3165 viewport.setSelectionGroup(sg);
3170 showAllColumns_actionPerformed(null);
3179 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3180 * event.ActionEvent)
3183 public void hideAllButSelection_actionPerformed(ActionEvent e)
3185 toggleHiddenRegions(false, false);
3186 viewport.sendSelection();
3193 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3197 public void hideAllSelection_actionPerformed(ActionEvent e)
3199 SequenceGroup sg = viewport.getSelectionGroup();
3200 viewport.expandColSelection(sg, false);
3201 viewport.hideAllSelectedSeqs();
3202 viewport.hideSelectedColumns();
3203 alignPanel.updateLayout();
3204 alignPanel.paintAlignment(true, true);
3205 viewport.sendSelection();
3212 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3216 public void showAllhidden_actionPerformed(ActionEvent e)
3218 viewport.showAllHiddenColumns();
3219 viewport.showAllHiddenSeqs();
3220 alignPanel.paintAlignment(true, true);
3221 viewport.sendSelection();
3225 public void hideSelColumns_actionPerformed(ActionEvent e)
3227 viewport.hideSelectedColumns();
3228 alignPanel.updateLayout();
3229 alignPanel.paintAlignment(true, true);
3230 viewport.sendSelection();
3234 public void hiddenMarkers_actionPerformed(ActionEvent e)
3236 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3247 protected void scaleAbove_actionPerformed(ActionEvent e)
3249 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3250 alignPanel.updateLayout();
3251 alignPanel.paintAlignment(true, false);
3261 protected void scaleLeft_actionPerformed(ActionEvent e)
3263 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3264 alignPanel.updateLayout();
3265 alignPanel.paintAlignment(true, false);
3275 protected void scaleRight_actionPerformed(ActionEvent e)
3277 viewport.setScaleRightWrapped(scaleRight.isSelected());
3278 alignPanel.updateLayout();
3279 alignPanel.paintAlignment(true, false);
3289 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3291 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3292 alignPanel.paintAlignment(false, false);
3302 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3304 viewport.setShowText(viewTextMenuItem.isSelected());
3305 alignPanel.paintAlignment(false, false);
3315 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3317 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3318 alignPanel.paintAlignment(false, false);
3321 public FeatureSettings featureSettings;
3324 public FeatureSettingsControllerI getFeatureSettingsUI()
3326 return featureSettings;
3330 public void featureSettings_actionPerformed(ActionEvent e)
3332 showFeatureSettingsUI();
3336 public FeatureSettingsControllerI showFeatureSettingsUI()
3338 if (featureSettings != null)
3340 featureSettings.closeOldSettings();
3341 featureSettings = null;
3343 if (!showSeqFeatures.isSelected())
3345 // make sure features are actually displayed
3346 showSeqFeatures.setSelected(true);
3347 showSeqFeatures_actionPerformed(null);
3349 featureSettings = new FeatureSettings(this);
3350 return featureSettings;
3354 * Set or clear 'Show Sequence Features'
3360 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3362 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3363 alignPanel.paintAlignment(true, true);
3367 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3368 * the annotations panel as a whole.
3370 * The options to show/hide all annotations should be enabled when the panel
3371 * is shown, and disabled when the panel is hidden.
3376 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3378 final boolean setVisible = annotationPanelMenuItem.isSelected();
3379 viewport.setShowAnnotation(setVisible);
3380 this.showAllSeqAnnotations.setEnabled(setVisible);
3381 this.hideAllSeqAnnotations.setEnabled(setVisible);
3382 this.showAllAlAnnotations.setEnabled(setVisible);
3383 this.hideAllAlAnnotations.setEnabled(setVisible);
3384 alignPanel.updateLayout();
3388 public void alignmentProperties()
3391 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3394 String content = MessageManager.formatMessage("label.html_content",
3396 { contents.toString() });
3399 if (Platform.isJS())
3401 JLabel textLabel = new JLabel();
3402 textLabel.setText(content);
3403 textLabel.setBackground(Color.WHITE);
3405 pane = new JPanel(new BorderLayout());
3406 ((JPanel) pane).setOpaque(true);
3407 pane.setBackground(Color.WHITE);
3408 ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
3417 JEditorPane editPane = new JEditorPane("text/html", "");
3418 editPane.setEditable(false);
3419 editPane.setText(content);
3423 JInternalFrame frame = new JInternalFrame();
3425 frame.getContentPane().add(new JScrollPane(pane));
3427 Desktop.addInternalFrame(frame, MessageManager
3428 .formatMessage("label.alignment_properties", new Object[]
3429 { getTitle() }), 500, 400);
3433 * Opens an Overview panel for the alignment, unless one is open already
3438 public void overviewMenuItem_actionPerformed(ActionEvent e)
3440 boolean showHiddenRegions = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START,
3442 openOverviewPanel(showHiddenRegions);
3445 public OverviewPanel openOverviewPanel(boolean showHidden)
3447 if (alignPanel.overviewPanel != null)
3449 return alignPanel.overviewPanel;
3451 JInternalFrame frame = new JInternalFrame();
3452 final OverviewPanel overview = new OverviewPanel(alignPanel, frame, showHidden);
3453 frame.setContentPane(overview);
3454 Desktop.addInternalFrame(frame, "", true, frame.getWidth(), frame.getHeight(),
3456 frame.setFrameIcon(null);
3458 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3459 final AlignmentPanel thePanel = this.alignPanel;
3460 frame.addInternalFrameListener(
3461 new javax.swing.event.InternalFrameAdapter()
3464 public void internalFrameClosed(
3465 javax.swing.event.InternalFrameEvent evt)
3468 thePanel.setOverviewPanel(null);
3471 if (getKeyListeners().length > 0)
3473 frame.addKeyListener(getKeyListeners()[0]);
3476 alignPanel.setOverviewPanel(overview);
3477 alignPanel.setOverviewTitle(this);
3483 public void textColour_actionPerformed()
3485 new TextColourChooser().chooseColour(alignPanel, null);
3489 * public void covariationColour_actionPerformed() {
3491 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3495 public void annotationColour_actionPerformed()
3497 new AnnotationColourChooser(viewport, alignPanel);
3501 public void annotationColumn_actionPerformed(ActionEvent e)
3503 new AnnotationColumnChooser(viewport, alignPanel);
3507 * Action on the user checking or unchecking the option to apply the selected
3508 * colour scheme to all groups. If unchecked, groups may have their own
3509 * independent colour schemes.
3514 public void applyToAllGroups_actionPerformed(boolean selected)
3516 viewport.setColourAppliesToAllGroups(selected);
3520 * Action on user selecting a colour from the colour menu
3523 * the name (not the menu item label!) of the colour scheme
3526 public void changeColour_actionPerformed(String name)
3529 * 'User Defined' opens a panel to configure or load a
3530 * user-defined colour scheme
3532 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3534 new UserDefinedColours(alignPanel);
3539 * otherwise set the chosen colour scheme (or null for 'None')
3541 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3542 viewport, viewport.getAlignment(),
3543 viewport.getHiddenRepSequences());
3548 * Actions on setting or changing the alignment colour scheme
3553 public void changeColour(ColourSchemeI cs)
3555 // TODO: pull up to controller method
3556 ColourMenuHelper.setColourSelected(colourMenu, cs);
3558 viewport.setGlobalColourScheme(cs);
3560 alignPanel.paintAlignment(true, true);
3564 * Show the PID threshold slider panel
3567 protected void modifyPID_actionPerformed()
3569 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3570 alignPanel.getViewName());
3571 SliderPanel.showPIDSlider();
3575 * Show the Conservation slider panel
3578 protected void modifyConservation_actionPerformed()
3580 SliderPanel.setConservationSlider(alignPanel,
3581 viewport.getResidueShading(), alignPanel.getViewName());
3582 SliderPanel.showConservationSlider();
3586 * Action on selecting or deselecting (Colour) By Conservation
3589 public void conservationMenuItem_actionPerformed(boolean selected)
3591 modifyConservation.setEnabled(selected);
3592 viewport.setConservationSelected(selected);
3593 viewport.getResidueShading().setConservationApplied(selected);
3595 changeColour(viewport.getGlobalColourScheme());
3598 modifyConservation_actionPerformed();
3602 SliderPanel.hideConservationSlider();
3607 * Action on selecting or deselecting (Colour) Above PID Threshold
3610 public void abovePIDThreshold_actionPerformed(boolean selected)
3612 modifyPID.setEnabled(selected);
3613 viewport.setAbovePIDThreshold(selected);
3616 viewport.getResidueShading().setThreshold(0,
3617 viewport.isIgnoreGapsConsensus());
3620 changeColour(viewport.getGlobalColourScheme());
3623 modifyPID_actionPerformed();
3627 SliderPanel.hidePIDSlider();
3638 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3640 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3641 AlignmentSorter.sortByPID(viewport.getAlignment(),
3642 viewport.getAlignment().getSequenceAt(0));
3643 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3644 viewport.getAlignment()));
3645 alignPanel.paintAlignment(true, false);
3655 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3657 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3658 AlignmentSorter.sortByID(viewport.getAlignment());
3660 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3661 alignPanel.paintAlignment(true, false);
3671 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3673 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3674 AlignmentSorter.sortByLength(viewport.getAlignment());
3675 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3676 viewport.getAlignment()));
3677 alignPanel.paintAlignment(true, false);
3687 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3689 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3690 AlignmentSorter.sortByGroup(viewport.getAlignment());
3691 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3692 viewport.getAlignment()));
3694 alignPanel.paintAlignment(true, false);
3704 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3706 new RedundancyPanel(alignPanel, this);
3716 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3718 if ((viewport.getSelectionGroup() == null)
3719 || (viewport.getSelectionGroup().getSize() < 2))
3721 JvOptionPane.showInternalMessageDialog(this,
3722 MessageManager.getString(
3723 "label.you_must_select_least_two_sequences"),
3724 MessageManager.getString("label.invalid_selection"),
3725 JvOptionPane.WARNING_MESSAGE);
3729 JInternalFrame frame = new JInternalFrame();
3730 frame.setContentPane(new PairwiseAlignPanel(viewport));
3731 Desktop.addInternalFrame(frame,
3732 MessageManager.getString("action.pairwise_alignment"), 600,
3738 public void autoCalculate_actionPerformed(ActionEvent e)
3740 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3741 if (viewport.autoCalculateConsensus)
3743 viewport.firePropertyChange("alignment", null,
3744 viewport.getAlignment().getSequences());
3749 public void sortByTreeOption_actionPerformed(ActionEvent e)
3751 viewport.sortByTree = sortByTree.isSelected();
3755 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3757 viewport.followSelection = listenToViewSelections.isSelected();
3761 * Constructs a tree panel and adds it to the desktop
3764 * tree type (NJ or AV)
3766 * name of score model used to compute the tree
3768 * parameters for the distance or similarity calculation
3770 void newTreePanel(String type, String modelName,
3771 SimilarityParamsI options)
3773 String frameTitle = "";
3776 boolean onSelection = false;
3777 if (viewport.getSelectionGroup() != null
3778 && viewport.getSelectionGroup().getSize() > 0)
3780 SequenceGroup sg = viewport.getSelectionGroup();
3782 /* Decide if the selection is a column region */
3783 for (SequenceI _s : sg.getSequences())
3785 if (_s.getLength() < sg.getEndRes())
3787 JvOptionPane.showMessageDialog(Desktop.desktop,
3788 MessageManager.getString(
3789 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3790 MessageManager.getString(
3791 "label.sequences_selection_not_aligned"),
3792 JvOptionPane.WARNING_MESSAGE);
3801 if (viewport.getAlignment().getHeight() < 2)
3807 tp = new TreePanel(alignPanel, type, modelName, options);
3808 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3810 frameTitle += " from ";
3812 if (viewport.getViewName() != null)
3814 frameTitle += viewport.getViewName() + " of ";
3817 frameTitle += this.title;
3819 Desktop.addInternalFrame(tp, frameTitle, 600, 500);
3830 public void addSortByOrderMenuItem(String title,
3831 final AlignmentOrder order)
3833 final JMenuItem item = new JMenuItem(MessageManager
3834 .formatMessage("action.by_title_param", new Object[]
3837 item.addActionListener(new java.awt.event.ActionListener()
3840 public void actionPerformed(ActionEvent e)
3842 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3844 // TODO: JBPNote - have to map order entries to curent SequenceI
3846 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3848 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3849 viewport.getAlignment()));
3851 alignPanel.paintAlignment(true, false);
3857 * Add a new sort by annotation score menu item
3860 * the menu to add the option to
3862 * the label used to retrieve scores for each sequence on the
3865 public void addSortByAnnotScoreMenuItem(JMenu sort,
3866 final String scoreLabel)
3868 final JMenuItem item = new JMenuItem(scoreLabel);
3870 item.addActionListener(new java.awt.event.ActionListener()
3873 public void actionPerformed(ActionEvent e)
3875 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3876 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3877 viewport.getAlignment());// ,viewport.getSelectionGroup());
3878 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3879 viewport.getAlignment()));
3880 alignPanel.paintAlignment(true, false);
3886 * last hash for alignment's annotation array - used to minimise cost of
3889 protected int _annotationScoreVectorHash;
3892 * search the alignment and rebuild the sort by annotation score submenu the
3893 * last alignment annotation vector hash is stored to minimize cost of
3894 * rebuilding in subsequence calls.
3898 public void buildSortByAnnotationScoresMenu()
3900 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3905 if (viewport.getAlignment().getAlignmentAnnotation()
3906 .hashCode() != _annotationScoreVectorHash)
3908 sortByAnnotScore.removeAll();
3909 // almost certainly a quicker way to do this - but we keep it simple
3910 Hashtable<String, String> scoreSorts = new Hashtable<>();
3911 AlignmentAnnotation aann[];
3912 for (SequenceI sqa : viewport.getAlignment().getSequences())
3914 aann = sqa.getAnnotation();
3915 for (int i = 0; aann != null && i < aann.length; i++)
3917 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3919 scoreSorts.put(aann[i].label, aann[i].label);
3923 Enumeration<String> labels = scoreSorts.keys();
3924 while (labels.hasMoreElements())
3926 addSortByAnnotScoreMenuItem(sortByAnnotScore, labels.nextElement());
3928 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3931 _annotationScoreVectorHash = viewport.getAlignment()
3932 .getAlignmentAnnotation().hashCode();
3937 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3938 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3939 * call. Listeners are added to remove the menu item when the treePanel is
3940 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3944 public void buildTreeSortMenu()
3946 sortByTreeMenu.removeAll();
3948 List<Component> comps = PaintRefresher.components
3949 .get(viewport.getSequenceSetId());
3950 List<TreePanel> treePanels = new ArrayList<>();
3951 for (Component comp : comps)
3953 if (comp instanceof TreePanel)
3955 treePanels.add((TreePanel) comp);
3959 if (treePanels.size() < 1)
3961 sortByTreeMenu.setVisible(false);
3965 sortByTreeMenu.setVisible(true);
3967 for (final TreePanel tp : treePanels)
3969 final JMenuItem item = new JMenuItem(tp.getTitle());
3970 item.addActionListener(new java.awt.event.ActionListener()
3973 public void actionPerformed(ActionEvent e)
3975 tp.sortByTree_actionPerformed();
3976 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3981 sortByTreeMenu.add(item);
3985 public boolean sortBy(AlignmentOrder alorder, String undoname)
3987 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3988 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3989 if (undoname != null)
3991 addHistoryItem(new OrderCommand(undoname, oldOrder,
3992 viewport.getAlignment()));
3994 alignPanel.paintAlignment(true, false);
3999 * Work out whether the whole set of sequences or just the selected set will
4000 * be submitted for multiple alignment.
4003 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4005 // Now, check we have enough sequences
4006 AlignmentView msa = null;
4008 if ((viewport.getSelectionGroup() != null)
4009 && (viewport.getSelectionGroup().getSize() > 1))
4011 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4012 // some common interface!
4014 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4015 * SequenceI[sz = seqs.getSize(false)];
4017 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4018 * seqs.getSequenceAt(i); }
4020 msa = viewport.getAlignmentView(true);
4022 else if (viewport.getSelectionGroup() != null
4023 && viewport.getSelectionGroup().getSize() == 1)
4025 int option = JvOptionPane.showConfirmDialog(this,
4026 MessageManager.getString("warn.oneseq_msainput_selection"),
4027 MessageManager.getString("label.invalid_selection"),
4028 JvOptionPane.OK_CANCEL_OPTION);
4029 if (option == JvOptionPane.OK_OPTION)
4031 msa = viewport.getAlignmentView(false);
4036 msa = viewport.getAlignmentView(false);
4042 * Decides what is submitted to a secondary structure prediction service: the
4043 * first sequence in the alignment, or in the current selection, or, if the
4044 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4045 * region or the whole alignment. (where the first sequence in the set is the
4046 * one that the prediction will be for).
4048 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4050 AlignmentView seqs = null;
4052 if ((viewport.getSelectionGroup() != null)
4053 && (viewport.getSelectionGroup().getSize() > 0))
4055 seqs = viewport.getAlignmentView(true);
4059 seqs = viewport.getAlignmentView(false);
4061 // limit sequences - JBPNote in future - could spawn multiple prediction
4063 // TODO: viewport.getAlignment().isAligned is a global state - the local
4064 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4065 if (!viewport.getAlignment().isAligned(false))
4067 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4068 // TODO: if seqs.getSequences().length>1 then should really have warned
4082 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4084 // Pick the tree file
4085 JalviewFileChooser chooser = new JalviewFileChooser(
4086 Cache.getProperty("LAST_DIRECTORY"));
4087 chooser.setFileView(new JalviewFileView());
4088 chooser.setDialogTitle(
4089 MessageManager.getString("label.select_newick_like_tree_file"));
4090 chooser.setToolTipText(
4091 MessageManager.getString("label.load_tree_file"));
4093 chooser.setResponseHandler(0, () -> {
4094 String filePath = chooser.getSelectedFile().getPath();
4095 Cache.setProperty("LAST_DIRECTORY", filePath);
4096 NewickFile fin = null;
4099 fin = new NewickFile(new FileParse(chooser.getSelectedFile(),
4100 DataSourceType.FILE));
4101 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4102 } catch (Exception ex)
4104 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4105 MessageManager.getString("label.problem_reading_tree_file"),
4106 JvOptionPane.WARNING_MESSAGE);
4107 ex.printStackTrace();
4109 if (fin != null && fin.hasWarningMessage())
4111 JvOptionPane.showMessageDialog(Desktop.desktop,
4112 fin.getWarningMessage(),
4114 .getString("label.possible_problem_with_tree_file"),
4115 JvOptionPane.WARNING_MESSAGE);
4119 chooser.showOpenDialog(this);
4122 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4124 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4127 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4128 int h, int x, int y)
4130 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4134 * Add a treeviewer for the tree extracted from a Newick file object to the
4135 * current alignment view
4142 * Associated alignment input data (or null)
4151 * @return TreePanel handle
4153 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4154 AlignmentView input, int w, int h, int x, int y)
4156 TreePanel tp = null;
4162 if (nf.getTree() != null)
4164 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4170 tp.setLocation(x, y);
4173 Desktop.addInternalFrame(tp, treeTitle, w, h);
4175 } catch (Exception ex)
4177 ex.printStackTrace();
4183 private boolean buildingMenu = false;
4186 * Generates menu items and listener event actions for web service clients
4189 public void BuildWebServiceMenu()
4191 while (buildingMenu)
4195 System.err.println("Waiting for building menu to finish.");
4197 } catch (Exception e)
4201 final AlignFrame me = this;
4202 buildingMenu = true;
4203 new Thread(new Runnable()
4208 final List<JMenuItem> legacyItems = new ArrayList<>();
4211 // System.err.println("Building ws menu again "
4212 // + Thread.currentThread());
4213 // TODO: add support for context dependent disabling of services based
4215 // alignment and current selection
4216 // TODO: add additional serviceHandle parameter to specify abstract
4218 // class independently of AbstractName
4219 // TODO: add in rediscovery GUI function to restart discoverer
4220 // TODO: group services by location as well as function and/or
4222 // object broker mechanism.
4223 final Vector<JMenu> wsmenu = new Vector<>();
4224 final IProgressIndicator af = me;
4227 * do not i18n these strings - they are hard-coded in class
4228 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4229 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4231 final JMenu msawsmenu = new JMenu("Alignment");
4232 final JMenu secstrmenu = new JMenu(
4233 "Secondary Structure Prediction");
4234 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4235 final JMenu analymenu = new JMenu("Analysis");
4236 final JMenu dismenu = new JMenu("Protein Disorder");
4237 // JAL-940 - only show secondary structure prediction services from
4238 // the legacy server
4239 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4241 Discoverer.services != null && (Discoverer.services.size() > 0))
4243 // TODO: refactor to allow list of AbstractName/Handler bindings to
4245 // stored or retrieved from elsewhere
4246 // No MSAWS used any more:
4247 // Vector msaws = null; // (Vector)
4248 // Discoverer.services.get("MsaWS");
4249 Vector<ServiceHandle> secstrpr = Discoverer.services
4251 if (secstrpr != null)
4253 // Add any secondary structure prediction services
4254 for (int i = 0, j = secstrpr.size(); i < j; i++)
4256 final ext.vamsas.ServiceHandle sh = secstrpr.get(i);
4257 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4258 .getServiceClient(sh);
4259 int p = secstrmenu.getItemCount();
4260 impl.attachWSMenuEntry(secstrmenu, me);
4261 int q = secstrmenu.getItemCount();
4262 for (int litm = p; litm < q; litm++)
4264 legacyItems.add(secstrmenu.getItem(litm));
4270 // Add all submenus in the order they should appear on the web
4272 wsmenu.add(msawsmenu);
4273 wsmenu.add(secstrmenu);
4274 wsmenu.add(dismenu);
4275 wsmenu.add(analymenu);
4276 // No search services yet
4277 // wsmenu.add(seqsrchmenu);
4279 javax.swing.SwingUtilities.invokeLater(new Runnable()
4286 webService.removeAll();
4287 // first, add discovered services onto the webservices menu
4288 if (wsmenu.size() > 0)
4290 for (int i = 0, j = wsmenu.size(); i < j; i++)
4292 webService.add(wsmenu.get(i));
4297 webService.add(me.webServiceNoServices);
4299 // TODO: move into separate menu builder class.
4301 // logic for 2.11.1.4 is
4302 // always look to see if there is a discover. if there isn't
4303 // we can't show any Jws2 services
4304 // if there are services available, show them - regardless of
4305 // the 'show JWS2 preference'
4306 // if the discoverer is running then say so
4307 // otherwise offer to trigger discovery if 'show JWS2' is not
4309 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4310 if (jws2servs != null)
4312 if (jws2servs.hasServices())
4314 jws2servs.attachWSMenuEntry(webService, me);
4315 for (Jws2Instance sv : jws2servs.getServices())
4317 if (sv.description.toLowerCase(Locale.ROOT)
4320 for (JMenuItem jmi : legacyItems)
4322 jmi.setVisible(false);
4328 if (jws2servs.isRunning())
4330 JMenuItem tm = new JMenuItem(
4331 "Still discovering JABA Services");
4332 tm.setEnabled(false);
4335 else if (!Cache.getDefault("SHOW_JWS2_SERVICES", true))
4337 JMenuItem enableJws2 = new JMenuItem(
4338 "Discover Web Services");
4339 enableJws2.setToolTipText(
4340 "Select to start JABA Web Service discovery (or enable option in Web Service preferences)");
4341 enableJws2.setEnabled(true);
4342 enableJws2.addActionListener(new ActionListener()
4346 public void actionPerformed(ActionEvent e)
4348 // start service discoverer, but ignore preference
4349 Desktop.instance.startServiceDiscovery(false,
4353 webService.add(enableJws2);
4357 build_urlServiceMenu(me.webService);
4358 build_fetchdbmenu(webService);
4359 for (JMenu item : wsmenu)
4361 if (item.getItemCount() == 0)
4363 item.setEnabled(false);
4367 item.setEnabled(true);
4370 } catch (Exception e)
4373 "Exception during web service menu building process.",
4378 } catch (Exception e)
4381 buildingMenu = false;
4388 * construct any groupURL type service menu entries.
4392 protected void build_urlServiceMenu(JMenu webService)
4394 // TODO: remove this code when 2.7 is released
4395 // DEBUG - alignmentView
4397 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4398 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4400 * @Override public void actionPerformed(ActionEvent e) {
4401 * jalview.datamodel.AlignmentView
4402 * .testSelectionViews(af.viewport.getAlignment(),
4403 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4405 * }); webService.add(testAlView);
4407 // TODO: refactor to RestClient discoverer and merge menu entries for
4408 // rest-style services with other types of analysis/calculation service
4409 // SHmmr test client - still being implemented.
4410 // DEBUG - alignmentView
4412 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4415 client.attachWSMenuEntry(
4416 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4422 * Searches the alignment sequences for xRefs and builds the Show
4423 * Cross-References menu (formerly called Show Products), with database
4424 * sources for which cross-references are found (protein sources for a
4425 * nucleotide alignment and vice versa)
4427 * @return true if Show Cross-references menu should be enabled
4429 public boolean canShowProducts()
4431 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4432 AlignmentI dataset = viewport.getAlignment().getDataset();
4434 showProducts.removeAll();
4435 final boolean dna = viewport.getAlignment().isNucleotide();
4437 if (seqs == null || seqs.length == 0)
4439 // nothing to see here.
4443 boolean showp = false;
4446 List<String> ptypes = new CrossRef(seqs, dataset)
4447 .findXrefSourcesForSequences(dna);
4449 for (final String source : ptypes)
4452 final AlignFrame af = this;
4453 JMenuItem xtype = new JMenuItem(source);
4454 xtype.addActionListener(new ActionListener()
4457 public void actionPerformed(ActionEvent e)
4459 showProductsFor(af.viewport.getSequenceSelection(), dna,
4463 showProducts.add(xtype);
4465 showProducts.setVisible(showp);
4466 showProducts.setEnabled(showp);
4467 } catch (Exception e)
4470 "canShowProducts threw an exception - please report to help@jalview.org",
4478 * Finds and displays cross-references for the selected sequences (protein
4479 * products for nucleotide sequences, dna coding sequences for peptides).
4482 * the sequences to show cross-references for
4484 * true if from a nucleotide alignment (so showing proteins)
4486 * the database to show cross-references for
4488 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4489 final String source)
4491 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4496 * Construct and display a new frame containing the translation of this
4497 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4500 public void showTranslation_actionPerformed(GeneticCodeI codeTable)
4502 AlignmentI al = null;
4505 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4507 al = dna.translateCdna(codeTable);
4508 } catch (Exception ex)
4510 Console.error("Exception during translation. Please report this !",
4512 final String msg = MessageManager.getString(
4513 "label.error_when_translating_sequences_submit_bug_report");
4514 final String errorTitle = MessageManager
4515 .getString("label.implementation_error")
4516 + MessageManager.getString("label.translation_failed");
4517 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4518 JvOptionPane.ERROR_MESSAGE);
4521 if (al == null || al.getHeight() == 0)
4523 final String msg = MessageManager.getString(
4524 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4525 final String errorTitle = MessageManager
4526 .getString("label.translation_failed");
4527 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4528 JvOptionPane.WARNING_MESSAGE);
4532 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4533 af.setFileFormat(this.currentFileFormat);
4534 final String newTitle = MessageManager
4535 .formatMessage("label.translation_of_params", new Object[]
4536 { this.getTitle(), codeTable.getId() });
4537 af.setTitle(newTitle);
4538 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4540 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4541 viewport.openSplitFrame(af, new Alignment(seqs));
4545 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4552 * Set the file format
4556 public void setFileFormat(FileFormatI format)
4558 this.currentFileFormat = format;
4562 * Try to load a features file onto the alignment.
4565 * contents or path to retrieve file or a File object
4567 * access mode of file (see jalview.io.AlignFile)
4568 * @return true if features file was parsed correctly.
4570 public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
4573 return avc.parseFeaturesFile(file, sourceType,
4574 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4579 public void refreshFeatureUI(boolean enableIfNecessary)
4581 // note - currently this is only still here rather than in the controller
4582 // because of the featureSettings hard reference that is yet to be
4584 if (enableIfNecessary)
4586 viewport.setShowSequenceFeatures(true);
4587 showSeqFeatures.setSelected(true);
4593 public void dragEnter(DropTargetDragEvent evt)
4598 public void dragExit(DropTargetEvent evt)
4603 public void dragOver(DropTargetDragEvent evt)
4608 public void dropActionChanged(DropTargetDragEvent evt)
4613 public void drop(DropTargetDropEvent evt)
4615 // JAL-1552 - acceptDrop required before getTransferable call for
4616 // Java's Transferable for native dnd
4617 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4618 Transferable t = evt.getTransferable();
4620 final AlignFrame thisaf = this;
4621 final List<Object> files = new ArrayList<>();
4622 List<DataSourceType> protocols = new ArrayList<>();
4626 Desktop.transferFromDropTarget(files, protocols, evt, t);
4627 } catch (Exception e)
4629 e.printStackTrace();
4633 new Thread(new Runnable()
4640 // check to see if any of these files have names matching sequences
4643 SequenceIdMatcher idm = new SequenceIdMatcher(
4644 viewport.getAlignment().getSequencesArray());
4646 * Object[] { String,SequenceI}
4648 ArrayList<Object[]> filesmatched = new ArrayList<>();
4649 ArrayList<Object> filesnotmatched = new ArrayList<>();
4650 for (int i = 0; i < files.size(); i++)
4653 Object file = files.get(i);
4654 String fileName = file.toString();
4656 DataSourceType protocol = (file instanceof File
4657 ? DataSourceType.FILE
4658 : FormatAdapter.checkProtocol(fileName));
4659 if (protocol == DataSourceType.FILE)
4662 if (file instanceof File)
4665 Platform.cacheFileData(fl);
4669 fl = new File(fileName);
4671 pdbfn = fl.getName();
4673 else if (protocol == DataSourceType.URL)
4675 URL url = new URL(fileName);
4676 pdbfn = url.getFile();
4678 if (pdbfn.length() > 0)
4680 // attempt to find a match in the alignment
4681 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4682 int l = 0, c = pdbfn.indexOf(".");
4683 while (mtch == null && c != -1)
4688 } while ((c = pdbfn.indexOf(".", l)) > l);
4691 pdbfn = pdbfn.substring(0, l);
4693 mtch = idm.findAllIdMatches(pdbfn);
4700 type = new IdentifyFile().identify(file, protocol);
4701 } catch (Exception ex)
4705 if (type != null && type.isStructureFile())
4707 filesmatched.add(new Object[] { file, protocol, mtch });
4711 // File wasn't named like one of the sequences or wasn't a PDB
4713 filesnotmatched.add(file);
4717 if (filesmatched.size() > 0)
4719 boolean autoAssociate = Cache
4720 .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
4723 String msg = MessageManager.formatMessage(
4724 "label.automatically_associate_structure_files_with_sequences_same_name",
4726 { Integer.valueOf(filesmatched.size())
4728 String ttl = MessageManager.getString(
4729 "label.automatically_associate_structure_files_by_name");
4730 int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
4731 ttl, JvOptionPane.YES_NO_OPTION);
4732 autoAssociate = choice == JvOptionPane.YES_OPTION;
4736 for (Object[] fm : filesmatched)
4738 // try and associate
4739 // TODO: may want to set a standard ID naming formalism for
4740 // associating PDB files which have no IDs.
4741 for (SequenceI toassoc : (SequenceI[]) fm[2])
4743 PDBEntry pe = new AssociatePdbFileWithSeq()
4744 .associatePdbWithSeq(fm[0].toString(),
4745 (DataSourceType) fm[1], toassoc, false,
4749 System.err.println("Associated file : "
4750 + (fm[0].toString()) + " with "
4751 + toassoc.getDisplayId(true));
4755 // TODO: do we need to update overview ? only if features are
4757 alignPanel.paintAlignment(true, false);
4763 * add declined structures as sequences
4765 for (Object[] o : filesmatched)
4767 filesnotmatched.add(o[0]);
4771 if (filesnotmatched.size() > 0)
4773 if (assocfiles > 0 && (Cache.getDefault(
4774 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4775 || JvOptionPane.showConfirmDialog(thisaf,
4776 "<html>" + MessageManager.formatMessage(
4777 "label.ignore_unmatched_dropped_files_info",
4780 filesnotmatched.size())
4783 MessageManager.getString(
4784 "label.ignore_unmatched_dropped_files"),
4785 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4789 for (Object fn : filesnotmatched)
4791 loadJalviewDataFile(fn, null, null, null);
4795 } catch (Exception ex)
4797 ex.printStackTrace();
4805 * Attempt to load a "dropped" file or URL string, by testing in turn for
4807 * <li>an Annotation file</li>
4808 * <li>a JNet file</li>
4809 * <li>a features file</li>
4810 * <li>else try to interpret as an alignment file</li>
4814 * either a filename or a URL string.
4816 public void loadJalviewDataFile(Object file, DataSourceType sourceType,
4817 FileFormatI format, SequenceI assocSeq)
4819 // BH 2018 was String file
4822 if (sourceType == null)
4824 sourceType = FormatAdapter.checkProtocol(file);
4826 // if the file isn't identified, or not positively identified as some
4827 // other filetype (PFAM is default unidentified alignment file type) then
4828 // try to parse as annotation.
4829 boolean isAnnotation = (format == null
4830 || FileFormat.Pfam.equals(format))
4831 ? new AnnotationFile().annotateAlignmentView(viewport,
4837 // first see if its a T-COFFEE score file
4838 TCoffeeScoreFile tcf = null;
4841 tcf = new TCoffeeScoreFile(file, sourceType);
4844 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4848 new TCoffeeColourScheme(viewport.getAlignment()));
4849 isAnnotation = true;
4850 setStatus(MessageManager.getString(
4851 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4855 // some problem - if no warning its probable that the ID matching
4856 // process didn't work
4857 JvOptionPane.showMessageDialog(Desktop.desktop,
4858 tcf.getWarningMessage() == null
4859 ? MessageManager.getString(
4860 "label.check_file_matches_sequence_ids_alignment")
4861 : tcf.getWarningMessage(),
4862 MessageManager.getString(
4863 "label.problem_reading_tcoffee_score_file"),
4864 JvOptionPane.WARNING_MESSAGE);
4871 } catch (Exception x)
4874 "Exception when processing data source as T-COFFEE score file",
4880 // try to see if its a JNet 'concise' style annotation file *before*
4882 // try to parse it as a features file
4885 format = new IdentifyFile().identify(file, sourceType);
4887 if (FileFormat.ScoreMatrix == format)
4889 ScoreMatrixFile sm = new ScoreMatrixFile(
4890 new FileParse(file, sourceType));
4892 // todo: i18n this message
4893 setStatus(MessageManager.formatMessage(
4894 "label.successfully_loaded_matrix",
4895 sm.getMatrixName()));
4897 else if (FileFormat.Jnet.equals(format))
4899 JPredFile predictions = new JPredFile(file, sourceType);
4900 new JnetAnnotationMaker();
4901 JnetAnnotationMaker.add_annotation(predictions,
4902 viewport.getAlignment(), 0, false);
4903 viewport.getAlignment().setupJPredAlignment();
4904 isAnnotation = true;
4906 // else if (IdentifyFile.FeaturesFile.equals(format))
4907 else if (FileFormat.Features.equals(format))
4909 if (parseFeaturesFile(file, sourceType))
4911 SplitFrame splitFrame = (SplitFrame) getSplitViewContainer();
4912 if (splitFrame != null)
4914 splitFrame.repaint();
4918 alignPanel.paintAlignment(true, true);
4924 new FileLoader().LoadFile(viewport, file, sourceType, format);
4931 alignPanel.adjustAnnotationHeight();
4932 viewport.updateSequenceIdColours();
4933 buildSortByAnnotationScoresMenu();
4934 alignPanel.paintAlignment(true, true);
4936 } catch (Exception ex)
4938 ex.printStackTrace();
4939 } catch (OutOfMemoryError oom)
4944 } catch (Exception x)
4949 + (sourceType != null
4950 ? (sourceType == DataSourceType.PASTE
4952 : "using " + sourceType + " from "
4956 ? "(parsing as '" + format + "' file)"
4958 oom, Desktop.desktop);
4963 * Method invoked by the ChangeListener on the tabbed pane, in other words
4964 * when a different tabbed pane is selected by the user or programmatically.
4967 public void tabSelectionChanged(int index)
4972 * update current Overview window title (if there is one)
4973 * to add view name "Original" if necessary
4975 alignPanel.setOverviewTitle(this);
4978 * switch panels and set Overview title (if there is one
4979 * because it was opened automatically)
4981 alignPanel = alignPanels.get(index);
4982 alignPanel.setOverviewTitle(this);
4984 viewport = alignPanel.av;
4985 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
4986 setMenusFromViewport(viewport);
4987 if (featureSettings != null && featureSettings.isOpen()
4988 && featureSettings.fr.getViewport() != viewport)
4990 if (viewport.isShowSequenceFeatures())
4992 // refresh the featureSettings to reflect UI change
4993 showFeatureSettingsUI();
4997 // close feature settings for this view.
4998 featureSettings.close();
5005 * 'focus' any colour slider that is open to the selected viewport
5007 if (viewport.getConservationSelected())
5009 SliderPanel.setConservationSlider(alignPanel,
5010 viewport.getResidueShading(), alignPanel.getViewName());
5014 SliderPanel.hideConservationSlider();
5016 if (viewport.getAbovePIDThreshold())
5018 SliderPanel.setPIDSliderSource(alignPanel,
5019 viewport.getResidueShading(), alignPanel.getViewName());
5023 SliderPanel.hidePIDSlider();
5027 * If there is a frame linked to this one in a SplitPane, switch it to the
5028 * same view tab index. No infinite recursion of calls should happen, since
5029 * tabSelectionChanged() should not get invoked on setting the selected
5030 * index to an unchanged value. Guard against setting an invalid index
5031 * before the new view peer tab has been created.
5033 final AlignViewportI peer = viewport.getCodingComplement();
5036 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
5037 .getAlignPanel().alignFrame;
5038 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5040 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5046 * On right mouse click on view tab, prompt for and set new view name.
5049 public void tabbedPane_mousePressed(MouseEvent e)
5051 if (e.isPopupTrigger())
5053 String msg = MessageManager.getString("label.enter_view_name");
5054 String ttl = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
5055 String reply = JvOptionPane.showInputDialog(msg, ttl);
5059 viewport.setViewName(reply);
5060 // TODO warn if reply is in getExistingViewNames()?
5061 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5066 public AlignViewport getCurrentView()
5072 * Open the dialog for regex description parsing.
5075 protected void extractScores_actionPerformed(ActionEvent e)
5077 ParseProperties pp = new jalview.analysis.ParseProperties(
5078 viewport.getAlignment());
5079 // TODO: verify regex and introduce GUI dialog for version 2.5
5080 // if (pp.getScoresFromDescription("col", "score column ",
5081 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5083 if (pp.getScoresFromDescription("description column",
5084 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5086 buildSortByAnnotationScoresMenu();
5094 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5098 protected void showDbRefs_actionPerformed(ActionEvent e)
5100 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5106 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5110 protected void showNpFeats_actionPerformed(ActionEvent e)
5112 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5116 * find the viewport amongst the tabs in this alignment frame and close that
5121 public boolean closeView(AlignViewportI av)
5125 this.closeMenuItem_actionPerformed(false);
5128 Component[] comp = tabbedPane.getComponents();
5129 for (int i = 0; comp != null && i < comp.length; i++)
5131 if (comp[i] instanceof AlignmentPanel)
5133 if (((AlignmentPanel) comp[i]).av == av)
5136 closeView((AlignmentPanel) comp[i]);
5144 protected void build_fetchdbmenu(JMenu webService)
5146 // Temporary hack - DBRef Fetcher always top level ws entry.
5147 // TODO We probably want to store a sequence database checklist in
5148 // preferences and have checkboxes.. rather than individual sources selected
5150 final JMenu rfetch = new JMenu(
5151 MessageManager.getString("action.fetch_db_references"));
5152 rfetch.setToolTipText(MessageManager.getString(
5153 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5154 webService.add(rfetch);
5156 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5157 MessageManager.getString("option.trim_retrieved_seqs"));
5158 trimrs.setToolTipText(
5159 MessageManager.getString("label.trim_retrieved_sequences"));
5161 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5162 trimrs.addActionListener(new ActionListener()
5165 public void actionPerformed(ActionEvent e)
5167 trimrs.setSelected(trimrs.isSelected());
5168 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5169 Boolean.valueOf(trimrs.isSelected()).toString());
5173 JMenuItem fetchr = new JMenuItem(
5174 MessageManager.getString("label.standard_databases"));
5175 fetchr.setToolTipText(
5176 MessageManager.getString("label.fetch_embl_uniprot"));
5177 fetchr.addActionListener(new ActionListener()
5181 public void actionPerformed(ActionEvent e)
5183 new Thread(new Runnable()
5188 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5189 .getAlignment().isNucleotide();
5190 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5191 alignPanel.av.getSequenceSelection(),
5192 alignPanel.alignFrame, null,
5193 alignPanel.alignFrame.featureSettings, isNucleotide);
5194 dbRefFetcher.addListener(new FetchFinishedListenerI()
5197 public void finished()
5200 for (FeatureSettingsModelI srcSettings : dbRefFetcher
5201 .getFeatureSettingsModels())
5204 alignPanel.av.mergeFeaturesStyle(srcSettings);
5206 AlignFrame.this.setMenusForViewport();
5209 dbRefFetcher.fetchDBRefs(false);
5217 new Thread(new Runnable()
5222 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5223 .getSequenceFetcherSingleton();
5224 javax.swing.SwingUtilities.invokeLater(new Runnable()
5229 String[] dbclasses = sf.getNonAlignmentSources();
5230 List<DbSourceProxy> otherdb;
5231 JMenu dfetch = new JMenu();
5232 JMenu ifetch = new JMenu();
5233 JMenuItem fetchr = null;
5234 int comp = 0, icomp = 0, mcomp = 15;
5235 String mname = null;
5237 for (String dbclass : dbclasses)
5239 otherdb = sf.getSourceProxy(dbclass);
5240 // add a single entry for this class, or submenu allowing 'fetch
5242 if (otherdb == null || otherdb.size() < 1)
5248 mname = "From " + dbclass;
5250 if (otherdb.size() == 1)
5252 final DbSourceProxy[] dassource = otherdb
5253 .toArray(new DbSourceProxy[0]);
5254 DbSourceProxy src = otherdb.get(0);
5255 fetchr = new JMenuItem(src.getDbSource());
5256 fetchr.addActionListener(new ActionListener()
5260 public void actionPerformed(ActionEvent e)
5262 new Thread(new Runnable()
5268 boolean isNucleotide = alignPanel.alignFrame
5269 .getViewport().getAlignment()
5271 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5272 alignPanel.av.getSequenceSelection(),
5273 alignPanel.alignFrame, dassource,
5274 alignPanel.alignFrame.featureSettings,
5277 .addListener(new FetchFinishedListenerI()
5280 public void finished()
5282 FeatureSettingsModelI srcSettings = dassource[0]
5283 .getFeatureColourScheme();
5284 alignPanel.av.mergeFeaturesStyle(
5286 AlignFrame.this.setMenusForViewport();
5289 dbRefFetcher.fetchDBRefs(false);
5295 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5296 MessageManager.formatMessage(
5297 "label.fetch_retrieve_from", new Object[]
5298 { src.getDbName() })));
5304 final DbSourceProxy[] dassource = otherdb
5305 .toArray(new DbSourceProxy[0]);
5307 DbSourceProxy src = otherdb.get(0);
5308 fetchr = new JMenuItem(MessageManager
5309 .formatMessage("label.fetch_all_param", new Object[]
5310 { src.getDbSource() }));
5311 fetchr.addActionListener(new ActionListener()
5314 public void actionPerformed(ActionEvent e)
5316 new Thread(new Runnable()
5322 boolean isNucleotide = alignPanel.alignFrame
5323 .getViewport().getAlignment()
5325 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5326 alignPanel.av.getSequenceSelection(),
5327 alignPanel.alignFrame, dassource,
5328 alignPanel.alignFrame.featureSettings,
5331 .addListener(new FetchFinishedListenerI()
5334 public void finished()
5336 AlignFrame.this.setMenusForViewport();
5339 dbRefFetcher.fetchDBRefs(false);
5345 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5346 MessageManager.formatMessage(
5347 "label.fetch_retrieve_from_all_sources",
5349 { Integer.valueOf(otherdb.size())
5351 src.getDbSource(), src.getDbName() })));
5354 // and then build the rest of the individual menus
5355 ifetch = new JMenu(MessageManager.formatMessage(
5356 "label.source_from_db_source", new Object[]
5357 { src.getDbSource() }));
5359 String imname = null;
5361 for (DbSourceProxy sproxy : otherdb)
5363 String dbname = sproxy.getDbName();
5364 String sname = dbname.length() > 5
5365 ? dbname.substring(0, 5) + "..."
5367 String msname = dbname.length() > 10
5368 ? dbname.substring(0, 10) + "..."
5372 imname = MessageManager
5373 .formatMessage("label.from_msname", new Object[]
5376 fetchr = new JMenuItem(msname);
5377 final DbSourceProxy[] dassrc = { sproxy };
5378 fetchr.addActionListener(new ActionListener()
5382 public void actionPerformed(ActionEvent e)
5384 new Thread(new Runnable()
5390 boolean isNucleotide = alignPanel.alignFrame
5391 .getViewport().getAlignment()
5393 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5394 alignPanel.av.getSequenceSelection(),
5395 alignPanel.alignFrame, dassrc,
5396 alignPanel.alignFrame.featureSettings,
5399 .addListener(new FetchFinishedListenerI()
5402 public void finished()
5404 AlignFrame.this.setMenusForViewport();
5407 dbRefFetcher.fetchDBRefs(false);
5413 fetchr.setToolTipText(
5414 "<html>" + MessageManager.formatMessage(
5415 "label.fetch_retrieve_from", new Object[]
5419 if (++icomp >= mcomp || i == (otherdb.size()))
5421 ifetch.setText(MessageManager.formatMessage(
5422 "label.source_to_target", imname, sname));
5424 ifetch = new JMenu();
5432 if (comp >= mcomp || dbi >= (dbclasses.length))
5434 dfetch.setText(MessageManager.formatMessage(
5435 "label.source_to_target", mname, dbclass));
5437 dfetch = new JMenu();
5450 * Left justify the whole alignment.
5453 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5455 AlignmentI al = viewport.getAlignment();
5457 viewport.firePropertyChange("alignment", null, al);
5461 * Right justify the whole alignment.
5464 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5466 AlignmentI al = viewport.getAlignment();
5468 viewport.firePropertyChange("alignment", null, al);
5472 public void setShowSeqFeatures(boolean b)
5474 showSeqFeatures.setSelected(b);
5475 viewport.setShowSequenceFeatures(b);
5482 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5483 * awt.event.ActionEvent)
5486 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5488 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5489 alignPanel.paintAlignment(false, false);
5496 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5500 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5502 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5503 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5511 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5512 * .event.ActionEvent)
5515 protected void showGroupConservation_actionPerformed(ActionEvent e)
5517 viewport.setShowGroupConservation(showGroupConservation.getState());
5518 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5525 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5526 * .event.ActionEvent)
5529 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5531 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5532 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5539 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5540 * .event.ActionEvent)
5543 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5545 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5546 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5550 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5552 showSequenceLogo.setState(true);
5553 viewport.setShowSequenceLogo(true);
5554 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5555 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5559 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5561 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5568 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5569 * .event.ActionEvent)
5572 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5574 if (avc.makeGroupsFromSelection())
5576 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5577 alignPanel.updateAnnotation();
5578 alignPanel.paintAlignment(true,
5579 viewport.needToUpdateStructureViews());
5583 public void clearAlignmentSeqRep()
5585 // TODO refactor alignmentseqrep to controller
5586 if (viewport.getAlignment().hasSeqrep())
5588 viewport.getAlignment().setSeqrep(null);
5589 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5590 alignPanel.updateAnnotation();
5591 alignPanel.paintAlignment(true, true);
5596 protected void createGroup_actionPerformed(ActionEvent e)
5598 if (avc.createGroup())
5600 if (applyAutoAnnotationSettings.isSelected())
5602 alignPanel.updateAnnotation(true, false);
5604 alignPanel.alignmentChanged();
5609 protected void unGroup_actionPerformed(ActionEvent e)
5613 alignPanel.alignmentChanged();
5618 * make the given alignmentPanel the currently selected tab
5620 * @param alignmentPanel
5622 public void setDisplayedView(AlignmentPanel alignmentPanel)
5624 if (!viewport.getSequenceSetId()
5625 .equals(alignmentPanel.av.getSequenceSetId()))
5627 throw new Error(MessageManager.getString(
5628 "error.implementation_error_cannot_show_view_alignment_frame"));
5630 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5631 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5633 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5638 * Action on selection of menu options to Show or Hide annotations.
5641 * @param forSequences
5642 * update sequence-related annotations
5643 * @param forAlignment
5644 * update non-sequence-related annotations
5647 protected void setAnnotationsVisibility(boolean visible,
5648 boolean forSequences, boolean forAlignment)
5650 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5651 .getAlignmentAnnotation();
5656 for (AlignmentAnnotation aa : anns)
5659 * don't display non-positional annotations on an alignment
5661 if (aa.annotations == null)
5665 boolean apply = (aa.sequenceRef == null && forAlignment)
5666 || (aa.sequenceRef != null && forSequences);
5669 aa.visible = visible;
5672 alignPanel.validateAnnotationDimensions(true);
5673 alignPanel.alignmentChanged();
5677 * Store selected annotation sort order for the view and repaint.
5680 protected void sortAnnotations_actionPerformed()
5682 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5684 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5685 alignPanel.paintAlignment(false, false);
5690 * @return alignment panels in this alignment frame
5692 public List<? extends AlignmentViewPanel> getAlignPanels()
5694 // alignPanels is never null
5695 // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5700 * Open a new alignment window, with the cDNA associated with this (protein)
5701 * alignment, aligned as is the protein.
5703 protected void viewAsCdna_actionPerformed()
5705 // TODO no longer a menu action - refactor as required
5706 final AlignmentI alignment = getViewport().getAlignment();
5707 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5708 if (mappings == null)
5712 List<SequenceI> cdnaSeqs = new ArrayList<>();
5713 for (SequenceI aaSeq : alignment.getSequences())
5715 for (AlignedCodonFrame acf : mappings)
5717 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5721 * There is a cDNA mapping for this protein sequence - add to new
5722 * alignment. It will share the same dataset sequence as other mapped
5723 * cDNA (no new mappings need to be created).
5725 final Sequence newSeq = new Sequence(dnaSeq);
5726 newSeq.setDatasetSequence(dnaSeq);
5727 cdnaSeqs.add(newSeq);
5731 if (cdnaSeqs.size() == 0)
5733 // show a warning dialog no mapped cDNA
5736 AlignmentI cdna = new Alignment(
5737 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5738 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5739 AlignFrame.DEFAULT_HEIGHT);
5740 cdna.alignAs(alignment);
5741 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5743 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5744 AlignFrame.DEFAULT_HEIGHT);
5748 * Set visibility of dna/protein complement view (available when shown in a
5754 protected void showComplement_actionPerformed(boolean show)
5756 SplitContainerI sf = getSplitViewContainer();
5759 sf.setComplementVisible(this, show);
5764 * Generate the reverse (optionally complemented) of the selected sequences,
5765 * and add them to the alignment
5768 protected void showReverse_actionPerformed(boolean complement)
5770 AlignmentI al = null;
5773 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5774 al = dna.reverseCdna(complement);
5775 viewport.addAlignment(al, "");
5776 addHistoryItem(new EditCommand(
5777 MessageManager.getString("label.add_sequences"), Action.PASTE,
5778 al.getSequencesArray(), 0, al.getWidth(),
5779 viewport.getAlignment()));
5780 } catch (Exception ex)
5782 System.err.println(ex.getMessage());
5788 * Try to run a script in the Groovy console, having first ensured that this
5789 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5790 * be targeted at this alignment.
5793 protected void runGroovy_actionPerformed()
5795 Jalview.setCurrentAlignFrame(this);
5796 groovy.ui.Console console = Desktop.getGroovyConsole();
5797 if (console != null)
5801 console.runScript();
5802 } catch (Exception ex)
5804 System.err.println((ex.toString()));
5805 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
5806 MessageManager.getString("label.couldnt_run_groovy_script"),
5807 MessageManager.getString("label.groovy_support_failed"),
5808 JvOptionPane.ERROR_MESSAGE);
5813 System.err.println("Can't run Groovy script as console not found");
5818 * Hides columns containing (or not containing) a specified feature, provided
5819 * that would not leave all columns hidden
5821 * @param featureType
5822 * @param columnsContaining
5825 public boolean hideFeatureColumns(String featureType,
5826 boolean columnsContaining)
5828 boolean notForHiding = avc.markColumnsContainingFeatures(
5829 columnsContaining, false, false, featureType);
5832 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5833 false, featureType))
5835 getViewport().hideSelectedColumns();
5843 protected void selectHighlightedColumns_actionPerformed(
5844 ActionEvent actionEvent)
5846 // include key modifier check in case user selects from menu
5847 avc.markHighlightedColumns(
5848 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5849 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5850 | ActionEvent.CTRL_MASK)) != 0);
5854 * Rebuilds the Colour menu, including any user-defined colours which have
5855 * been loaded either on startup or during the session
5857 public void buildColourMenu()
5859 colourMenu.removeAll();
5861 colourMenu.add(applyToAllGroups);
5862 colourMenu.add(textColour);
5863 colourMenu.addSeparator();
5865 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
5866 viewport.getAlignment(), false);
5868 colourMenu.add(annotationColour);
5869 bg.add(annotationColour);
5870 colourMenu.addSeparator();
5871 colourMenu.add(conservationMenuItem);
5872 colourMenu.add(modifyConservation);
5873 colourMenu.add(abovePIDThreshold);
5874 colourMenu.add(modifyPID);
5876 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5877 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5881 * Open a dialog (if not already open) that allows the user to select and
5882 * calculate PCA or Tree analysis
5884 protected void openTreePcaDialog()
5886 if (alignPanel.getCalculationDialog() == null)
5888 new CalculationChooser(AlignFrame.this);
5893 protected void loadVcf_actionPerformed()
5895 JalviewFileChooser chooser = new JalviewFileChooser(
5896 Cache.getProperty("LAST_DIRECTORY"));
5897 chooser.setFileView(new JalviewFileView());
5898 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
5899 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
5900 final AlignFrame us = this;
5901 chooser.setResponseHandler(0, () -> {
5902 String choice = chooser.getSelectedFile().getPath();
5903 Cache.setProperty("LAST_DIRECTORY", choice);
5904 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
5905 new VCFLoader(choice).loadVCF(seqs, us);
5908 chooser.showOpenDialog(null);
5912 private Rectangle lastFeatureSettingsBounds = null;
5915 public void setFeatureSettingsGeometry(Rectangle bounds)
5917 lastFeatureSettingsBounds = bounds;
5921 public Rectangle getFeatureSettingsGeometry()
5923 return lastFeatureSettingsBounds;
5927 class PrintThread extends Thread
5931 public PrintThread(AlignmentPanel ap)
5936 static PageFormat pf;
5941 PrinterJob printJob = PrinterJob.getPrinterJob();
5945 printJob.setPrintable(ap, pf);
5949 printJob.setPrintable(ap);
5952 if (printJob.printDialog())
5957 } catch (Exception PrintException)
5959 PrintException.printStackTrace();