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.util.Locale;
25 import java.awt.BorderLayout;
26 import java.awt.Color;
27 import java.awt.Component;
28 import java.awt.Rectangle;
29 import java.awt.Toolkit;
30 import java.awt.datatransfer.Clipboard;
31 import java.awt.datatransfer.DataFlavor;
32 import java.awt.datatransfer.StringSelection;
33 import java.awt.datatransfer.Transferable;
34 import java.awt.dnd.DnDConstants;
35 import java.awt.dnd.DropTargetDragEvent;
36 import java.awt.dnd.DropTargetDropEvent;
37 import java.awt.dnd.DropTargetEvent;
38 import java.awt.dnd.DropTargetListener;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.awt.event.FocusAdapter;
42 import java.awt.event.FocusEvent;
43 import java.awt.event.ItemEvent;
44 import java.awt.event.ItemListener;
45 import java.awt.event.KeyAdapter;
46 import java.awt.event.KeyEvent;
47 import java.awt.event.MouseEvent;
48 import java.awt.print.PageFormat;
49 import java.awt.print.PrinterJob;
50 import java.beans.PropertyChangeEvent;
52 import java.io.FileWriter;
53 import java.io.IOException;
54 import java.io.PrintWriter;
56 import java.util.ArrayList;
57 import java.util.Arrays;
58 import java.util.Deque;
59 import java.util.Enumeration;
60 import java.util.HashMap;
61 import java.util.Hashtable;
62 import java.util.List;
64 import java.util.Vector;
65 import java.util.concurrent.CompletableFuture;
67 import javax.swing.ButtonGroup;
68 import javax.swing.JCheckBoxMenuItem;
69 import javax.swing.JComponent;
70 import javax.swing.JEditorPane;
71 import javax.swing.JInternalFrame;
72 import javax.swing.JLabel;
73 import javax.swing.JLayeredPane;
74 import javax.swing.JMenu;
75 import javax.swing.JMenuItem;
76 import javax.swing.JPanel;
77 import javax.swing.JScrollPane;
78 import javax.swing.SwingUtilities;
80 import ext.vamsas.ServiceHandle;
81 import jalview.analysis.AlignmentSorter;
82 import jalview.analysis.AlignmentUtils;
83 import jalview.analysis.CrossRef;
84 import jalview.analysis.Dna;
85 import jalview.analysis.GeneticCodeI;
86 import jalview.analysis.ParseProperties;
87 import jalview.analysis.SequenceIdMatcher;
88 import jalview.api.AlignExportSettingsI;
89 import jalview.api.AlignViewControllerGuiI;
90 import jalview.api.AlignViewControllerI;
91 import jalview.api.AlignViewportI;
92 import jalview.api.AlignmentViewPanel;
93 import jalview.api.FeatureSettingsControllerI;
94 import jalview.api.FeatureSettingsModelI;
95 import jalview.api.SplitContainerI;
96 import jalview.api.ViewStyleI;
97 import jalview.api.analysis.SimilarityParamsI;
98 import jalview.bin.Cache;
99 import jalview.bin.Console;
100 import jalview.bin.Jalview;
101 import jalview.commands.CommandI;
102 import jalview.commands.EditCommand;
103 import jalview.commands.EditCommand.Action;
104 import jalview.commands.OrderCommand;
105 import jalview.commands.RemoveGapColCommand;
106 import jalview.commands.RemoveGapsCommand;
107 import jalview.commands.SlideSequencesCommand;
108 import jalview.commands.TrimRegionCommand;
109 import jalview.datamodel.AlignExportSettingsAdapter;
110 import jalview.datamodel.AlignedCodonFrame;
111 import jalview.datamodel.Alignment;
112 import jalview.datamodel.AlignmentAnnotation;
113 import jalview.datamodel.AlignmentExportData;
114 import jalview.datamodel.AlignmentI;
115 import jalview.datamodel.AlignmentOrder;
116 import jalview.datamodel.AlignmentView;
117 import jalview.datamodel.ColumnSelection;
118 import jalview.datamodel.HiddenColumns;
119 import jalview.datamodel.PDBEntry;
120 import jalview.datamodel.SeqCigar;
121 import jalview.datamodel.Sequence;
122 import jalview.datamodel.SequenceGroup;
123 import jalview.datamodel.SequenceI;
124 import jalview.gui.ColourMenuHelper.ColourChangeListener;
125 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
126 import jalview.io.AlignmentProperties;
127 import jalview.io.AnnotationFile;
128 import jalview.io.BackupFiles;
129 import jalview.io.BioJsHTMLOutput;
130 import jalview.io.DataSourceType;
131 import jalview.io.FileFormat;
132 import jalview.io.FileFormatI;
133 import jalview.io.FileFormats;
134 import jalview.io.FileLoader;
135 import jalview.io.FileParse;
136 import jalview.io.FormatAdapter;
137 import jalview.io.HtmlSvgOutput;
138 import jalview.io.IdentifyFile;
139 import jalview.io.JPredFile;
140 import jalview.io.JalviewFileChooser;
141 import jalview.io.JalviewFileView;
142 import jalview.io.JnetAnnotationMaker;
143 import jalview.io.NewickFile;
144 import jalview.io.ScoreMatrixFile;
145 import jalview.io.TCoffeeScoreFile;
146 import jalview.io.vcf.VCFLoader;
147 import jalview.jbgui.GAlignFrame;
148 import jalview.project.Jalview2XML;
149 import jalview.schemes.ColourSchemeI;
150 import jalview.schemes.ColourSchemes;
151 import jalview.schemes.ResidueColourScheme;
152 import jalview.schemes.TCoffeeColourScheme;
153 import jalview.util.HttpUtils;
154 import jalview.util.ImageMaker.TYPE;
155 import jalview.util.MessageManager;
156 import jalview.util.Platform;
157 import jalview.viewmodel.AlignmentViewport;
158 import jalview.viewmodel.ViewportRanges;
159 import jalview.ws.DBRefFetcher;
160 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
161 import jalview.ws.jws1.Discoverer;
162 import jalview.ws.jws2.Jws2Discoverer;
163 import jalview.ws.jws2.jabaws2.Jws2Instance;
164 import jalview.ws.seqfetcher.DbSourceProxy;
170 * @version $Revision$
172 @SuppressWarnings("serial")
173 public class AlignFrame extends GAlignFrame implements DropTargetListener,
174 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
177 public static final int DEFAULT_WIDTH = 700;
179 public static final int DEFAULT_HEIGHT = 500;
182 * The currently displayed panel (selected tabbed view if more than one)
184 public AlignmentPanel alignPanel;
186 AlignViewport viewport;
188 public AlignViewControllerI avc;
190 List<AlignmentPanel> alignPanels = new ArrayList<>();
193 * Last format used to load or save alignments in this window
195 FileFormatI currentFileFormat = null;
198 * Current filename for this alignment
200 String fileName = null;
205 * Creates a new AlignFrame object with specific width and height.
211 public AlignFrame(AlignmentI al, int width, int height)
213 this(al, null, width, height);
217 * Creates a new AlignFrame object with specific width, height and
223 * @param sequenceSetId
225 public AlignFrame(AlignmentI al, int width, int height,
226 String sequenceSetId)
228 this(al, null, width, height, sequenceSetId);
232 * Creates a new AlignFrame object with specific width, height and
238 * @param sequenceSetId
241 public AlignFrame(AlignmentI al, int width, int height,
242 String sequenceSetId, String viewId)
244 this(al, null, width, height, sequenceSetId, viewId);
248 * new alignment window with hidden columns
252 * @param hiddenColumns
253 * ColumnSelection or null
255 * Width of alignment frame
259 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
262 this(al, hiddenColumns, width, height, null);
266 * Create alignment frame for al with hiddenColumns, a specific width and
267 * height, and specific sequenceId
270 * @param hiddenColumns
273 * @param sequenceSetId
276 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
277 int height, String sequenceSetId)
279 this(al, hiddenColumns, width, height, sequenceSetId, null);
283 * Create alignment frame for al with hiddenColumns, a specific width and
284 * height, and specific sequenceId
287 * @param hiddenColumns
290 * @param sequenceSetId
295 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
296 int height, String sequenceSetId, String viewId)
298 setSize(width, height);
300 if (al.getDataset() == null)
305 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
307 alignPanel = new AlignmentPanel(this, viewport);
309 addAlignmentPanel(alignPanel, true);
313 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
314 HiddenColumns hiddenColumns, int width, int height)
316 setSize(width, height);
318 if (al.getDataset() == null)
323 viewport = new AlignViewport(al, hiddenColumns);
325 if (hiddenSeqs != null && hiddenSeqs.length > 0)
327 viewport.hideSequence(hiddenSeqs);
329 alignPanel = new AlignmentPanel(this, viewport);
330 addAlignmentPanel(alignPanel, true);
335 * Make a new AlignFrame from existing alignmentPanels
342 public AlignFrame(AlignmentPanel ap)
346 addAlignmentPanel(ap, false);
351 * initalise the alignframe from the underlying viewport data and the
356 // setBackground(Color.white); // BH 2019
358 if (!Jalview.isHeadlessMode())
360 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
363 avc = new jalview.controller.AlignViewController(this, viewport,
365 if (viewport.getAlignmentConservationAnnotation() == null)
367 // BLOSUM62Colour.setEnabled(false);
368 conservationMenuItem.setEnabled(false);
369 modifyConservation.setEnabled(false);
370 // PIDColour.setEnabled(false);
371 // abovePIDThreshold.setEnabled(false);
372 // modifyPID.setEnabled(false);
375 String sortby = Cache.getDefault("SORT_ALIGNMENT", "No sort");
377 if (sortby.equals("Id"))
379 sortIDMenuItem_actionPerformed(null);
381 else if (sortby.equals("Pairwise Identity"))
383 sortPairwiseMenuItem_actionPerformed(null);
387 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
389 setMenusFromViewport(viewport);
390 buildSortByAnnotationScoresMenu();
391 calculateTree.addActionListener(new ActionListener()
395 public void actionPerformed(ActionEvent e)
402 if (Desktop.desktop != null)
404 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
405 if (!Platform.isJS())
407 addServiceListeners();
412 if (viewport.getWrapAlignment())
414 wrapMenuItem_actionPerformed(null);
417 if (Cache.getDefault("SHOW_OVERVIEW", false))
419 this.overviewMenuItem_actionPerformed(null);
424 final List<AlignmentViewPanel> selviews = new ArrayList<>();
425 final List<AlignmentPanel> origview = new ArrayList<>();
426 final String menuLabel = MessageManager
427 .getString("label.copy_format_from");
428 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
429 new ViewSetProvider()
433 public AlignmentPanel[] getAllAlignmentPanels()
436 origview.add(alignPanel);
437 // make an array of all alignment panels except for this one
438 List<AlignmentPanel> aps = new ArrayList<>(
439 Arrays.asList(Desktop.getAlignmentPanels(null)));
440 aps.remove(AlignFrame.this.alignPanel);
441 return aps.toArray(new AlignmentPanel[aps.size()]);
443 }, selviews, new ItemListener()
447 public void itemStateChanged(ItemEvent e)
449 if (origview.size() > 0)
451 final AlignmentPanel ap = origview.get(0);
454 * Copy the ViewStyle of the selected panel to 'this one'.
455 * Don't change value of 'scaleProteinAsCdna' unless copying
458 ViewStyleI vs = selviews.get(0).getAlignViewport()
460 boolean fromSplitFrame = selviews.get(0)
461 .getAlignViewport().getCodingComplement() != null;
464 vs.setScaleProteinAsCdna(ap.getAlignViewport()
465 .getViewStyle().isScaleProteinAsCdna());
467 ap.getAlignViewport().setViewStyle(vs);
470 * Also rescale ViewStyle of SplitFrame complement if there is
471 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
472 * the whole ViewStyle (allow cDNA protein to have different
475 AlignViewportI complement = ap.getAlignViewport()
476 .getCodingComplement();
477 if (complement != null && vs.isScaleProteinAsCdna())
479 AlignFrame af = Desktop.getAlignFrameFor(complement);
480 ((SplitFrame) af.getSplitViewContainer())
482 af.setMenusForViewport();
486 ap.setSelected(true);
487 ap.alignFrame.setMenusForViewport();
492 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase(Locale.ROOT)
493 .indexOf("devel") > -1
494 || Cache.getDefault("VERSION", "DEVELOPMENT")
495 .toLowerCase(Locale.ROOT).indexOf("test") > -1)
497 formatMenu.add(vsel);
499 addFocusListener(new FocusAdapter()
502 public void focusGained(FocusEvent e)
504 Jalview.setCurrentAlignFrame(AlignFrame.this);
511 * Change the filename and format for the alignment, and enable the 'reload'
512 * button functionality.
519 public void setFileName(String file, FileFormatI format)
522 setFileFormat(format);
523 reload.setEnabled(true);
527 * JavaScript will have this, maybe others. More dependable than a file name
528 * and maintains a reference to the actual bytes loaded.
532 public void setFileObject(File file)
534 this.fileObject = file;
538 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
541 void addKeyListener()
543 addKeyListener(new KeyAdapter()
546 public void keyPressed(KeyEvent evt)
548 if (viewport.cursorMode
549 && ((evt.getKeyCode() >= KeyEvent.VK_0
550 && evt.getKeyCode() <= KeyEvent.VK_9)
551 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
552 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
553 && Character.isDigit(evt.getKeyChar()))
555 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
558 switch (evt.getKeyCode())
561 case 27: // escape key
562 deselectAllSequenceMenuItem_actionPerformed(null);
566 case KeyEvent.VK_DOWN:
567 if (evt.isAltDown() || !viewport.cursorMode)
569 moveSelectedSequences(false);
571 if (viewport.cursorMode)
573 alignPanel.getSeqPanel().moveCursor(0, 1, evt.isShiftDown());
578 if (evt.isAltDown() || !viewport.cursorMode)
580 moveSelectedSequences(true);
582 if (viewport.cursorMode)
584 alignPanel.getSeqPanel().moveCursor(0, -1, evt.isShiftDown());
589 case KeyEvent.VK_LEFT:
590 if (evt.isAltDown() || !viewport.cursorMode)
592 slideSequences(false,
593 alignPanel.getSeqPanel().getKeyboardNo1());
597 alignPanel.getSeqPanel().moveCursor(-1, 0, evt.isShiftDown());
602 case KeyEvent.VK_RIGHT:
603 if (evt.isAltDown() || !viewport.cursorMode)
605 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
609 alignPanel.getSeqPanel().moveCursor(1, 0, evt.isShiftDown());
613 case KeyEvent.VK_SPACE:
614 if (viewport.cursorMode)
616 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
617 || evt.isShiftDown() || evt.isAltDown());
621 // case KeyEvent.VK_A:
622 // if (viewport.cursorMode)
624 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
625 // //System.out.println("A");
629 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
630 * System.out.println("closing bracket"); } break;
632 case KeyEvent.VK_DELETE:
633 case KeyEvent.VK_BACK_SPACE:
634 if (!viewport.cursorMode)
636 cut_actionPerformed();
640 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
641 || evt.isShiftDown() || evt.isAltDown());
647 if (viewport.cursorMode)
649 alignPanel.getSeqPanel().setCursorRow();
653 if (viewport.cursorMode && !evt.isControlDown())
655 alignPanel.getSeqPanel().setCursorColumn();
659 if (viewport.cursorMode)
661 alignPanel.getSeqPanel().setCursorPosition();
665 case KeyEvent.VK_ENTER:
666 case KeyEvent.VK_COMMA:
667 if (viewport.cursorMode)
669 alignPanel.getSeqPanel().setCursorRowAndColumn();
674 if (viewport.cursorMode)
676 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
680 if (viewport.cursorMode)
682 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
687 viewport.cursorMode = !viewport.cursorMode;
688 setStatus(MessageManager
689 .formatMessage("label.keyboard_editing_mode", new String[]
690 { (viewport.cursorMode ? "on" : "off") }));
691 if (viewport.cursorMode)
693 ViewportRanges ranges = viewport.getRanges();
694 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
696 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
699 alignPanel.getSeqPanel().seqCanvas.repaint();
705 Help.showHelpWindow();
706 } catch (Exception ex)
708 ex.printStackTrace();
713 boolean toggleSeqs = !evt.isControlDown();
714 boolean toggleCols = !evt.isShiftDown();
715 toggleHiddenRegions(toggleSeqs, toggleCols);
720 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
721 boolean modifyExisting = true; // always modify, don't clear
722 // evt.isShiftDown();
723 boolean invertHighlighted = evt.isAltDown();
724 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
728 case KeyEvent.VK_PAGE_UP:
729 viewport.getRanges().pageUp();
731 case KeyEvent.VK_PAGE_DOWN:
732 viewport.getRanges().pageDown();
738 public void keyReleased(KeyEvent evt)
740 switch (evt.getKeyCode())
742 case KeyEvent.VK_LEFT:
743 if (evt.isAltDown() || !viewport.cursorMode)
745 viewport.firePropertyChange("alignment", null,
746 viewport.getAlignment().getSequences());
750 case KeyEvent.VK_RIGHT:
751 if (evt.isAltDown() || !viewport.cursorMode)
753 viewport.firePropertyChange("alignment", null,
754 viewport.getAlignment().getSequences());
762 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
764 ap.alignFrame = this;
765 avc = new jalview.controller.AlignViewController(this, viewport,
770 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
772 int aSize = alignPanels.size();
774 tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
776 if (aSize == 1 && ap.av.getViewName() == null)
778 this.getContentPane().add(ap, BorderLayout.CENTER);
784 setInitialTabVisible();
787 expandViews.setEnabled(true);
788 gatherViews.setEnabled(true);
789 tabbedPane.addTab(ap.av.getViewName(), ap);
791 ap.setVisible(false);
796 if (ap.av.isPadGaps())
798 ap.av.getAlignment().padGaps();
800 ap.av.updateConservation(ap);
801 ap.av.updateConsensus(ap);
802 ap.av.updateStrucConsensus(ap);
806 public void setInitialTabVisible()
808 expandViews.setEnabled(true);
809 gatherViews.setEnabled(true);
810 tabbedPane.setVisible(true);
811 AlignmentPanel first = alignPanels.get(0);
812 tabbedPane.addTab(first.av.getViewName(), first);
813 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
816 public AlignViewport getViewport()
821 /* Set up intrinsic listeners for dynamically generated GUI bits. */
822 private void addServiceListeners()
824 final java.beans.PropertyChangeListener thisListener;
825 Desktop.instance.addJalviewPropertyChangeListener("services",
826 thisListener = new java.beans.PropertyChangeListener()
829 public void propertyChange(PropertyChangeEvent evt)
831 // // System.out.println("Discoverer property change.");
832 // if (evt.getPropertyName().equals("services"))
834 SwingUtilities.invokeLater(new Runnable()
841 "Rebuild WS Menu for service change");
842 BuildWebServiceMenu();
849 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
852 public void internalFrameClosed(
853 javax.swing.event.InternalFrameEvent evt)
855 // System.out.println("deregistering discoverer listener");
856 Desktop.instance.removeJalviewPropertyChangeListener("services",
858 closeMenuItem_actionPerformed(true);
861 // Finally, build the menu once to get current service state
862 new Thread(new Runnable()
867 BuildWebServiceMenu();
873 * Configure menu items that vary according to whether the alignment is
874 * nucleotide or protein
876 public void setGUINucleotide()
878 AlignmentI al = getViewport().getAlignment();
879 boolean nucleotide = al.isNucleotide();
881 loadVcf.setVisible(nucleotide);
882 showTranslation.setVisible(nucleotide);
883 showReverse.setVisible(nucleotide);
884 showReverseComplement.setVisible(nucleotide);
885 conservationMenuItem.setEnabled(!nucleotide);
887 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
888 showGroupConservation.setEnabled(!nucleotide);
890 showComplementMenuItem
891 .setText(nucleotide ? MessageManager.getString("label.protein")
892 : MessageManager.getString("label.nucleotide"));
896 * set up menus for the current viewport. This may be called after any
897 * operation that affects the data in the current view (selection changed,
898 * etc) to update the menus to reflect the new state.
901 public void setMenusForViewport()
903 setMenusFromViewport(viewport);
907 * Need to call this method when tabs are selected for multiple views, or when
908 * loading from Jalview2XML.java
913 public void setMenusFromViewport(AlignViewport av)
915 padGapsMenuitem.setSelected(av.isPadGaps());
916 colourTextMenuItem.setSelected(av.isShowColourText());
917 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
918 modifyPID.setEnabled(abovePIDThreshold.isSelected());
919 conservationMenuItem.setSelected(av.getConservationSelected());
920 modifyConservation.setEnabled(conservationMenuItem.isSelected());
921 seqLimits.setSelected(av.getShowJVSuffix());
922 idRightAlign.setSelected(av.isRightAlignIds());
923 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
924 renderGapsMenuItem.setSelected(av.isRenderGaps());
925 wrapMenuItem.setSelected(av.getWrapAlignment());
926 scaleAbove.setVisible(av.getWrapAlignment());
927 scaleLeft.setVisible(av.getWrapAlignment());
928 scaleRight.setVisible(av.getWrapAlignment());
929 annotationPanelMenuItem.setState(av.isShowAnnotation());
931 * Show/hide annotations only enabled if annotation panel is shown
933 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
934 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
935 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
936 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
937 viewBoxesMenuItem.setSelected(av.getShowBoxes());
938 viewTextMenuItem.setSelected(av.getShowText());
939 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
940 showGroupConsensus.setSelected(av.isShowGroupConsensus());
941 showGroupConservation.setSelected(av.isShowGroupConservation());
942 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
943 showSequenceLogo.setSelected(av.isShowSequenceLogo());
944 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
946 ColourMenuHelper.setColourSelected(colourMenu,
947 av.getGlobalColourScheme());
949 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
950 hiddenMarkers.setState(av.getShowHiddenMarkers());
951 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
952 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
953 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
954 autoCalculate.setSelected(av.autoCalculateConsensus);
955 sortByTree.setSelected(av.sortByTree);
956 listenToViewSelections.setSelected(av.followSelection);
958 showProducts.setEnabled(canShowProducts());
959 setGroovyEnabled(Desktop.getGroovyConsole() != null);
965 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
969 public void setGroovyEnabled(boolean b)
971 runGroovy.setEnabled(b);
974 private IProgressIndicator progressBar;
979 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
982 public void setProgressBar(String message, long id)
984 progressBar.setProgressBar(message, id);
988 public void registerHandler(final long id,
989 final IProgressIndicatorHandler handler)
991 progressBar.registerHandler(id, handler);
996 * @return true if any progress bars are still active
999 public boolean operationInProgress()
1001 return progressBar.operationInProgress();
1005 * Sets the text of the status bar. Note that setting a null or empty value
1006 * will cause the status bar to be hidden, with possibly undesirable flicker
1007 * of the screen layout.
1010 public void setStatus(String text)
1012 statusBar.setText(text == null || text.isEmpty() ? " " : text);
1016 * Added so Castor Mapping file can obtain Jalview Version
1018 public String getVersion()
1020 return Cache.getProperty("VERSION");
1023 public FeatureRenderer getFeatureRenderer()
1025 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1029 public void fetchSequence_actionPerformed()
1031 new SequenceFetcher(this);
1035 public void addFromFile_actionPerformed(ActionEvent e)
1037 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1041 public void reload_actionPerformed(ActionEvent e)
1043 if (fileName != null)
1045 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1046 // originating file's format
1047 // TODO: work out how to recover feature settings for correct view(s) when
1048 // file is reloaded.
1049 if (FileFormat.Jalview.equals(currentFileFormat))
1051 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1052 for (int i = 0; i < frames.length; i++)
1054 if (frames[i] instanceof AlignFrame && frames[i] != this
1055 && ((AlignFrame) frames[i]).fileName != null
1056 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1060 frames[i].setSelected(true);
1061 Desktop.instance.closeAssociatedWindows();
1062 } catch (java.beans.PropertyVetoException ex)
1068 Desktop.instance.closeAssociatedWindows();
1070 FileLoader loader = new FileLoader();
1071 DataSourceType protocol = HttpUtils.startsWithHttpOrHttps(fileName)
1072 ? DataSourceType.URL
1073 : DataSourceType.FILE;
1074 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1078 Rectangle bounds = this.getBounds();
1080 FileLoader loader = new FileLoader();
1082 AlignFrame newframe = null;
1084 if (fileObject == null)
1087 DataSourceType protocol = HttpUtils.startsWithHttpOrHttps(
1088 fileName) ? DataSourceType.URL : DataSourceType.FILE;
1089 newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
1094 newframe = loader.LoadFileWaitTillLoaded(fileObject,
1095 DataSourceType.FILE, currentFileFormat);
1098 newframe.setBounds(bounds);
1099 if (featureSettings != null && featureSettings.isShowing())
1101 final Rectangle fspos = featureSettings.frame.getBounds();
1102 // TODO: need a 'show feature settings' function that takes bounds -
1103 // need to refactor Desktop.addFrame
1104 newframe.featureSettings_actionPerformed(null);
1105 final FeatureSettings nfs = newframe.featureSettings;
1106 SwingUtilities.invokeLater(new Runnable()
1111 nfs.frame.setBounds(fspos);
1114 this.featureSettings.close();
1115 this.featureSettings = null;
1117 this.closeMenuItem_actionPerformed(true);
1123 public void addFromText_actionPerformed(ActionEvent e)
1126 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1130 public void addFromURL_actionPerformed(ActionEvent e)
1132 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1136 public void save_actionPerformed(ActionEvent e)
1138 if (fileName == null || (currentFileFormat == null)
1139 || HttpUtils.startsWithHttpOrHttps(fileName))
1141 saveAs_actionPerformed();
1145 saveAlignment(fileName, currentFileFormat);
1150 * Saves the alignment to a file with a name chosen by the user, if necessary
1151 * warning if a file would be overwritten
1154 public void saveAs_actionPerformed()
1156 String format = currentFileFormat == null ? null
1157 : currentFileFormat.getName();
1158 JalviewFileChooser chooser = JalviewFileChooser
1159 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1161 chooser.setFileView(new JalviewFileView());
1162 chooser.setDialogTitle(
1163 MessageManager.getString("label.save_alignment_to_file"));
1164 chooser.setToolTipText(MessageManager.getString("action.save"));
1166 int value = chooser.showSaveDialog(this);
1168 if (value != JalviewFileChooser.APPROVE_OPTION)
1172 currentFileFormat = chooser.getSelectedFormat();
1173 // todo is this (2005) test now obsolete - value is never null?
1174 while (currentFileFormat == null)
1176 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1178 .getString("label.select_file_format_before_saving"),
1179 MessageManager.getString("label.file_format_not_specified"),
1180 JvOptionPane.WARNING_MESSAGE);
1181 currentFileFormat = chooser.getSelectedFormat();
1182 value = chooser.showSaveDialog(this);
1183 if (value != JalviewFileChooser.APPROVE_OPTION)
1189 fileName = chooser.getSelectedFile().getPath();
1191 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1192 Cache.setProperty("LAST_DIRECTORY", fileName);
1193 saveAlignment(fileName, currentFileFormat);
1196 boolean lastSaveSuccessful = false;
1198 FileFormatI lastFormatSaved;
1200 String lastFilenameSaved;
1203 * Raise a dialog or status message for the last call to saveAlignment.
1205 * @return true if last call to saveAlignment(file, format) was successful.
1207 public boolean isSaveAlignmentSuccessful()
1210 if (!lastSaveSuccessful)
1212 if (!Platform.isHeadless())
1214 JvOptionPane.showInternalMessageDialog(this, MessageManager
1215 .formatMessage("label.couldnt_save_file", new Object[]
1216 { lastFilenameSaved }),
1217 MessageManager.getString("label.error_saving_file"),
1218 JvOptionPane.WARNING_MESSAGE);
1222 Console.error(MessageManager
1223 .formatMessage("label.couldnt_save_file", new Object[]
1224 { lastFilenameSaved }));
1230 setStatus(MessageManager.formatMessage(
1231 "label.successfully_saved_to_file_in_format", new Object[]
1232 { lastFilenameSaved, lastFormatSaved }));
1235 return lastSaveSuccessful;
1239 * Saves the alignment to the specified file path, in the specified format,
1240 * which may be an alignment format, or Jalview project format. If the
1241 * alignment has hidden regions, or the format is one capable of including
1242 * non-sequence data (features, annotations, groups), then the user may be
1243 * prompted to specify what to include in the output.
1248 public void saveAlignment(String file, FileFormatI format)
1250 lastSaveSuccessful = true;
1251 lastFilenameSaved = file;
1252 lastFormatSaved = format;
1254 if (FileFormat.Jalview.equals(format))
1256 String shortName = title;
1257 if (shortName.indexOf(File.separatorChar) > -1)
1259 shortName = shortName
1260 .substring(shortName.lastIndexOf(File.separatorChar) + 1);
1262 lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
1265 statusBar.setText(MessageManager.formatMessage(
1266 "label.successfully_saved_to_file_in_format", new Object[]
1272 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1273 Runnable cancelAction = new Runnable()
1278 lastSaveSuccessful = false;
1281 Runnable outputAction = new Runnable()
1286 // todo defer this to inside formatSequences (or later)
1287 AlignmentExportData exportData = viewport
1288 .getAlignExportData(options);
1289 String output = new FormatAdapter(alignPanel, options)
1290 .formatSequences(format, exportData.getAlignment(),
1291 exportData.getOmitHidden(),
1292 exportData.getStartEndPostions(),
1293 viewport.getAlignment().getHiddenColumns());
1296 lastSaveSuccessful = false;
1300 // create backupfiles object and get new temp filename destination
1301 boolean doBackup = BackupFiles.getEnabled();
1302 BackupFiles backupfiles = null;
1306 "ALIGNFRAME making backupfiles object for " + file);
1307 backupfiles = new BackupFiles(file);
1311 String tempFilePath = doBackup ? backupfiles.getTempFilePath()
1313 Console.trace("ALIGNFRAME setting PrintWriter");
1314 PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
1316 if (backupfiles != null)
1318 Console.trace("ALIGNFRAME about to write to temp file "
1319 + backupfiles.getTempFilePath());
1323 Console.trace("ALIGNFRAME about to close file");
1325 Console.trace("ALIGNFRAME closed file");
1326 AlignFrame.this.setTitle(file);
1327 statusBar.setText(MessageManager.formatMessage(
1328 "label.successfully_saved_to_file_in_format",
1330 { fileName, format.getName() }));
1331 lastSaveSuccessful = true;
1332 } catch (IOException e)
1334 lastSaveSuccessful = false;
1336 "ALIGNFRAME Something happened writing the temp file");
1337 Console.error(e.getMessage());
1338 Console.debug(Cache.getStackTraceString(e));
1339 } catch (Exception ex)
1341 lastSaveSuccessful = false;
1343 "ALIGNFRAME Something unexpected happened writing the temp file");
1344 Console.error(ex.getMessage());
1345 Console.debug(Cache.getStackTraceString(ex));
1350 backupfiles.setWriteSuccess(lastSaveSuccessful);
1351 Console.debug("ALIGNFRAME writing temp file was "
1352 + (lastSaveSuccessful ? "" : "NOT ") + "successful");
1353 // do the backup file roll and rename the temp file to actual file
1355 "ALIGNFRAME about to rollBackupsAndRenameTempFile");
1356 lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
1358 "ALIGNFRAME performed rollBackupsAndRenameTempFile "
1359 + (lastSaveSuccessful ? "" : "un")
1367 * show dialog with export options if applicable; else just do it
1369 if (AlignExportOptions.isNeeded(viewport, format))
1371 AlignExportOptions choices = new AlignExportOptions(
1372 alignPanel.getAlignViewport(), format, options);
1373 choices.setResponseAction(0, outputAction);
1374 choices.setResponseAction(1, cancelAction);
1375 choices.showDialog();
1384 * Outputs the alignment to textbox in the requested format, if necessary
1385 * first prompting the user for whether to include hidden regions or
1388 * @param fileFormatName
1391 protected void outputText_actionPerformed(String fileFormatName)
1393 FileFormatI fileFormat = FileFormats.getInstance()
1394 .forName(fileFormatName);
1395 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1396 Runnable outputAction = new Runnable()
1401 // todo defer this to inside formatSequences (or later)
1402 AlignmentExportData exportData = viewport
1403 .getAlignExportData(options);
1404 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1405 cap.setForInput(null);
1408 FileFormatI format = fileFormat;
1409 cap.setText(new FormatAdapter(alignPanel, options)
1410 .formatSequences(format, exportData.getAlignment(),
1411 exportData.getOmitHidden(),
1412 exportData.getStartEndPostions(),
1413 viewport.getAlignment().getHiddenColumns()));
1414 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1415 "label.alignment_output_command", new Object[]
1416 { fileFormat.getName() }), 600, 500);
1417 } catch (OutOfMemoryError oom)
1419 new OOMWarning("Outputting alignment as " + fileFormat.getName(),
1427 * show dialog with export options if applicable; else just do it
1429 if (AlignExportOptions.isNeeded(viewport, fileFormat))
1431 AlignExportOptions choices = new AlignExportOptions(
1432 alignPanel.getAlignViewport(), fileFormat, options);
1433 choices.setResponseAction(0, outputAction);
1434 choices.showDialog();
1449 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1451 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1452 htmlSVG.exportHTML(null);
1456 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1458 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1459 bjs.exportHTML(null);
1462 public void createImageMap(File file, String image)
1464 alignPanel.makePNGImageMap(file, image);
1468 * Creates a PNG image of the alignment and writes it to the given file. If
1469 * the file is null, the user is prompted to choose a file.
1474 public void createPNG(File f)
1476 alignPanel.makeAlignmentImage(TYPE.PNG, f);
1480 * Creates an EPS image of the alignment and writes it to the given file. If
1481 * the file is null, the user is prompted to choose a file.
1486 public void createEPS(File f)
1488 alignPanel.makeAlignmentImage(TYPE.EPS, f);
1492 * Creates an SVG image of the alignment and writes it to the given file. If
1493 * the file is null, the user is prompted to choose a file.
1498 public void createSVG(File f)
1500 alignPanel.makeAlignmentImage(TYPE.SVG, f);
1504 public void pageSetup_actionPerformed(ActionEvent e)
1506 PrinterJob printJob = PrinterJob.getPrinterJob();
1507 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1517 public void printMenuItem_actionPerformed(ActionEvent e)
1519 // Putting in a thread avoids Swing painting problems
1520 PrintThread thread = new PrintThread(alignPanel);
1525 public void exportFeatures_actionPerformed(ActionEvent e)
1527 new AnnotationExporter(alignPanel).exportFeatures();
1531 public void exportAnnotations_actionPerformed(ActionEvent e)
1533 new AnnotationExporter(alignPanel).exportAnnotations();
1537 public void associatedData_actionPerformed(ActionEvent e)
1539 final JalviewFileChooser chooser = new JalviewFileChooser(
1540 Cache.getProperty("LAST_DIRECTORY"));
1541 chooser.setFileView(new JalviewFileView());
1542 String tooltip = MessageManager
1543 .getString("label.load_jalview_annotations");
1544 chooser.setDialogTitle(tooltip);
1545 chooser.setToolTipText(tooltip);
1546 chooser.setResponseHandler(0, new Runnable()
1551 String choice = chooser.getSelectedFile().getPath();
1552 Cache.setProperty("LAST_DIRECTORY", choice);
1553 loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
1557 chooser.showOpenDialog(this);
1561 * Close the current view or all views in the alignment frame. If the frame
1562 * only contains one view then the alignment will be removed from memory.
1564 * @param closeAllTabs
1567 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1569 if (alignPanels != null && alignPanels.size() < 2)
1571 closeAllTabs = true;
1576 if (alignPanels != null)
1580 if (this.isClosed())
1582 // really close all the windows - otherwise wait till
1583 // setClosed(true) is called
1584 for (int i = 0; i < alignPanels.size(); i++)
1586 AlignmentPanel ap = alignPanels.get(i);
1593 closeView(alignPanel);
1598 if (featureSettings != null && featureSettings.isOpen())
1600 featureSettings.close();
1601 featureSettings = null;
1604 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1605 * be called recursively, with the frame now in 'closed' state
1607 this.setClosed(true);
1609 } catch (Exception ex)
1611 ex.printStackTrace();
1616 * Close the specified panel and close up tabs appropriately.
1618 * @param panelToClose
1620 public void closeView(AlignmentPanel panelToClose)
1622 int index = tabbedPane.getSelectedIndex();
1623 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1624 alignPanels.remove(panelToClose);
1625 panelToClose.closePanel();
1626 panelToClose = null;
1628 tabbedPane.removeTabAt(closedindex);
1629 tabbedPane.validate();
1631 if (index > closedindex || index == tabbedPane.getTabCount())
1633 // modify currently selected tab index if necessary.
1637 this.tabSelectionChanged(index);
1643 void updateEditMenuBar()
1646 if (viewport.getHistoryList().size() > 0)
1648 undoMenuItem.setEnabled(true);
1649 CommandI command = viewport.getHistoryList().peek();
1650 undoMenuItem.setText(MessageManager
1651 .formatMessage("label.undo_command", new Object[]
1652 { command.getDescription() }));
1656 undoMenuItem.setEnabled(false);
1657 undoMenuItem.setText(MessageManager.getString("action.undo"));
1660 if (viewport.getRedoList().size() > 0)
1662 redoMenuItem.setEnabled(true);
1664 CommandI command = viewport.getRedoList().peek();
1665 redoMenuItem.setText(MessageManager
1666 .formatMessage("label.redo_command", new Object[]
1667 { command.getDescription() }));
1671 redoMenuItem.setEnabled(false);
1672 redoMenuItem.setText(MessageManager.getString("action.redo"));
1677 public void addHistoryItem(CommandI command)
1679 if (command.getSize() > 0)
1681 viewport.addToHistoryList(command);
1682 viewport.clearRedoList();
1683 updateEditMenuBar();
1684 viewport.updateHiddenColumns();
1685 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1686 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1687 // viewport.getColumnSelection()
1688 // .getHiddenColumns().size() > 0);
1694 * @return alignment objects for all views
1696 AlignmentI[] getViewAlignments()
1698 if (alignPanels != null)
1700 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1702 for (AlignmentPanel ap : alignPanels)
1704 als[i++] = ap.av.getAlignment();
1708 if (viewport != null)
1710 return new AlignmentI[] { viewport.getAlignment() };
1722 protected void undoMenuItem_actionPerformed(ActionEvent e)
1724 if (viewport.getHistoryList().isEmpty())
1728 CommandI command = viewport.getHistoryList().pop();
1729 viewport.addToRedoList(command);
1730 command.undoCommand(getViewAlignments());
1732 AlignmentViewport originalSource = getOriginatingSource(command);
1733 updateEditMenuBar();
1735 if (originalSource != null)
1737 if (originalSource != viewport)
1740 "Implementation worry: mismatch of viewport origin for undo");
1742 originalSource.updateHiddenColumns();
1743 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1745 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1746 // viewport.getColumnSelection()
1747 // .getHiddenColumns().size() > 0);
1748 originalSource.firePropertyChange("alignment", null,
1749 originalSource.getAlignment().getSequences());
1760 protected void redoMenuItem_actionPerformed(ActionEvent e)
1762 if (viewport.getRedoList().size() < 1)
1767 CommandI command = viewport.getRedoList().pop();
1768 viewport.addToHistoryList(command);
1769 command.doCommand(getViewAlignments());
1771 AlignmentViewport originalSource = getOriginatingSource(command);
1772 updateEditMenuBar();
1774 if (originalSource != null)
1777 if (originalSource != viewport)
1780 "Implementation worry: mismatch of viewport origin for redo");
1782 originalSource.updateHiddenColumns();
1783 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1785 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1786 // viewport.getColumnSelection()
1787 // .getHiddenColumns().size() > 0);
1788 originalSource.firePropertyChange("alignment", null,
1789 originalSource.getAlignment().getSequences());
1793 AlignmentViewport getOriginatingSource(CommandI command)
1795 AlignmentViewport originalSource = null;
1796 // For sequence removal and addition, we need to fire
1797 // the property change event FROM the viewport where the
1798 // original alignment was altered
1799 AlignmentI al = null;
1800 if (command instanceof EditCommand)
1802 EditCommand editCommand = (EditCommand) command;
1803 al = editCommand.getAlignment();
1804 List<Component> comps = PaintRefresher.components
1805 .get(viewport.getSequenceSetId());
1807 for (Component comp : comps)
1809 if (comp instanceof AlignmentPanel)
1811 if (al == ((AlignmentPanel) comp).av.getAlignment())
1813 originalSource = ((AlignmentPanel) comp).av;
1820 if (originalSource == null)
1822 // The original view is closed, we must validate
1823 // the current view against the closed view first
1826 PaintRefresher.validateSequences(al, viewport.getAlignment());
1829 originalSource = viewport;
1832 return originalSource;
1836 * Calls AlignmentI.moveSelectedSequencesByOne with current sequence selection
1837 * or the sequence under cursor in keyboard mode
1842 public void moveSelectedSequences(boolean up)
1844 SequenceGroup sg = viewport.getSelectionGroup();
1848 if (viewport.cursorMode)
1850 sg = new SequenceGroup();
1851 sg.addSequence(viewport.getAlignment().getSequenceAt(
1852 alignPanel.getSeqPanel().seqCanvas.cursorY), false);
1860 if (sg.getSize() < 1)
1865 // TODO: JAL-3733 - add an event to the undo buffer for this !
1867 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1868 viewport.getHiddenRepSequences(), up);
1869 alignPanel.paintAlignment(true, false);
1872 synchronized void slideSequences(boolean right, int size)
1874 List<SequenceI> sg = new ArrayList<>();
1875 if (viewport.cursorMode)
1877 sg.add(viewport.getAlignment()
1878 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
1880 else if (viewport.getSelectionGroup() != null
1881 && viewport.getSelectionGroup().getSize() != viewport
1882 .getAlignment().getHeight())
1884 sg = viewport.getSelectionGroup()
1885 .getSequences(viewport.getHiddenRepSequences());
1893 List<SequenceI> invertGroup = new ArrayList<>();
1895 for (SequenceI seq : viewport.getAlignment().getSequences())
1897 if (!sg.contains(seq))
1899 invertGroup.add(seq);
1903 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1905 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1906 for (int i = 0; i < invertGroup.size(); i++)
1908 seqs2[i] = invertGroup.get(i);
1911 SlideSequencesCommand ssc;
1914 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1915 viewport.getGapCharacter());
1919 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1920 viewport.getGapCharacter());
1923 int groupAdjustment = 0;
1924 if (ssc.getGapsInsertedBegin() && right)
1926 if (viewport.cursorMode)
1928 alignPanel.getSeqPanel().moveCursor(size, 0);
1932 groupAdjustment = size;
1935 else if (!ssc.getGapsInsertedBegin() && !right)
1937 if (viewport.cursorMode)
1939 alignPanel.getSeqPanel().moveCursor(-size, 0);
1943 groupAdjustment = -size;
1947 if (groupAdjustment != 0)
1949 viewport.getSelectionGroup().setStartRes(
1950 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1951 viewport.getSelectionGroup().setEndRes(
1952 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1956 * just extend the last slide command if compatible; but not if in
1957 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1959 boolean appendHistoryItem = false;
1960 Deque<CommandI> historyList = viewport.getHistoryList();
1961 boolean inSplitFrame = getSplitViewContainer() != null;
1962 if (!inSplitFrame && historyList != null && historyList.size() > 0
1963 && historyList.peek() instanceof SlideSequencesCommand)
1965 appendHistoryItem = ssc.appendSlideCommand(
1966 (SlideSequencesCommand) historyList.peek());
1969 if (!appendHistoryItem)
1971 addHistoryItem(ssc);
1984 protected void copy_actionPerformed()
1986 if (viewport.getSelectionGroup() == null)
1990 // TODO: preserve the ordering of displayed alignment annotation in any
1991 // internal paste (particularly sequence associated annotation)
1992 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1993 String[] omitHidden = null;
1995 if (viewport.hasHiddenColumns())
1997 omitHidden = viewport.getViewAsString(true);
2000 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
2001 seqs, omitHidden, null);
2003 StringSelection ss = new StringSelection(output);
2007 jalview.gui.Desktop.internalCopy = true;
2008 // Its really worth setting the clipboard contents
2009 // to empty before setting the large StringSelection!!
2010 Toolkit.getDefaultToolkit().getSystemClipboard()
2011 .setContents(new StringSelection(""), null);
2013 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
2015 } catch (OutOfMemoryError er)
2017 new OOMWarning("copying region", er);
2021 HiddenColumns hiddenColumns = null;
2022 if (viewport.hasHiddenColumns())
2024 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
2025 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
2027 // create new HiddenColumns object with copy of hidden regions
2028 // between startRes and endRes, offset by startRes
2029 hiddenColumns = new HiddenColumns(
2030 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
2031 hiddenCutoff, hiddenOffset);
2034 Desktop.jalviewClipboard = new Object[] { seqs,
2035 viewport.getAlignment().getDataset(), hiddenColumns };
2036 setStatus(MessageManager.formatMessage(
2037 "label.copied_sequences_to_clipboard", new Object[]
2038 { Integer.valueOf(seqs.length).toString() }));
2048 protected void pasteNew_actionPerformed(ActionEvent e)
2060 protected void pasteThis_actionPerformed(ActionEvent e)
2066 * Paste contents of Jalview clipboard
2068 * @param newAlignment
2069 * true to paste to a new alignment, otherwise add to this.
2071 void paste(boolean newAlignment)
2073 boolean externalPaste = true;
2076 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2077 Transferable contents = c.getContents(this);
2079 if (contents == null)
2088 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2089 if (str.length() < 1)
2094 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2096 } catch (OutOfMemoryError er)
2098 new OOMWarning("Out of memory pasting sequences!!", er);
2102 SequenceI[] sequences;
2103 boolean annotationAdded = false;
2104 AlignmentI alignment = null;
2106 if (Desktop.jalviewClipboard != null)
2108 // The clipboard was filled from within Jalview, we must use the
2110 // And dataset from the copied alignment
2111 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2112 // be doubly sure that we create *new* sequence objects.
2113 sequences = new SequenceI[newseq.length];
2114 for (int i = 0; i < newseq.length; i++)
2116 sequences[i] = new Sequence(newseq[i]);
2118 alignment = new Alignment(sequences);
2119 externalPaste = false;
2123 // parse the clipboard as an alignment.
2124 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2126 sequences = alignment.getSequencesArray();
2130 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2136 if (Desktop.jalviewClipboard != null)
2138 // dataset is inherited
2139 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2143 // new dataset is constructed
2144 alignment.setDataset(null);
2146 alwidth = alignment.getWidth() + 1;
2150 AlignmentI pastedal = alignment; // preserve pasted alignment object
2151 // Add pasted sequences and dataset into existing alignment.
2152 alignment = viewport.getAlignment();
2153 alwidth = alignment.getWidth() + 1;
2154 // decide if we need to import sequences from an existing dataset
2155 boolean importDs = Desktop.jalviewClipboard != null
2156 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2157 // importDs==true instructs us to copy over new dataset sequences from
2158 // an existing alignment
2159 Vector<SequenceI> newDs = (importDs) ? new Vector<>() : null; // used to
2161 // minimum dataset set
2163 for (int i = 0; i < sequences.length; i++)
2167 newDs.addElement(null);
2169 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2171 if (importDs && ds != null)
2173 if (!newDs.contains(ds))
2175 newDs.setElementAt(ds, i);
2176 ds = new Sequence(ds);
2177 // update with new dataset sequence
2178 sequences[i].setDatasetSequence(ds);
2182 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2187 // copy and derive new dataset sequence
2188 sequences[i] = sequences[i].deriveSequence();
2189 alignment.getDataset()
2190 .addSequence(sequences[i].getDatasetSequence());
2191 // TODO: avoid creation of duplicate dataset sequences with a
2192 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2194 alignment.addSequence(sequences[i]); // merges dataset
2198 newDs.clear(); // tidy up
2200 if (alignment.getAlignmentAnnotation() != null)
2202 for (AlignmentAnnotation alan : alignment
2203 .getAlignmentAnnotation())
2205 if (alan.graphGroup > fgroup)
2207 fgroup = alan.graphGroup;
2211 if (pastedal.getAlignmentAnnotation() != null)
2213 // Add any annotation attached to alignment.
2214 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2215 for (int i = 0; i < alann.length; i++)
2217 annotationAdded = true;
2218 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2220 AlignmentAnnotation newann = new AlignmentAnnotation(
2222 if (newann.graphGroup > -1)
2224 if (newGraphGroups.size() <= newann.graphGroup
2225 || newGraphGroups.get(newann.graphGroup) == null)
2227 for (int q = newGraphGroups
2228 .size(); q <= newann.graphGroup; q++)
2230 newGraphGroups.add(q, null);
2232 newGraphGroups.set(newann.graphGroup,
2233 Integer.valueOf(++fgroup));
2235 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2239 newann.padAnnotation(alwidth);
2240 alignment.addAnnotation(newann);
2250 addHistoryItem(new EditCommand(
2251 MessageManager.getString("label.add_sequences"),
2252 Action.PASTE, sequences, 0, alignment.getWidth(),
2255 // Add any annotations attached to sequences
2256 for (int i = 0; i < sequences.length; i++)
2258 if (sequences[i].getAnnotation() != null)
2260 AlignmentAnnotation newann;
2261 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2263 annotationAdded = true;
2264 newann = sequences[i].getAnnotation()[a];
2265 newann.adjustForAlignment();
2266 newann.padAnnotation(alwidth);
2267 if (newann.graphGroup > -1)
2269 if (newann.graphGroup > -1)
2271 if (newGraphGroups.size() <= newann.graphGroup
2272 || newGraphGroups.get(newann.graphGroup) == null)
2274 for (int q = newGraphGroups
2275 .size(); q <= newann.graphGroup; q++)
2277 newGraphGroups.add(q, null);
2279 newGraphGroups.set(newann.graphGroup,
2280 Integer.valueOf(++fgroup));
2282 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2286 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2290 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2298 // propagate alignment changed.
2299 viewport.getRanges().setEndSeq(alignment.getHeight() - 1);
2300 if (annotationAdded)
2302 // Duplicate sequence annotation in all views.
2303 AlignmentI[] alview = this.getViewAlignments();
2304 for (int i = 0; i < sequences.length; i++)
2306 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2311 for (int avnum = 0; avnum < alview.length; avnum++)
2313 if (alview[avnum] != alignment)
2315 // duplicate in a view other than the one with input focus
2316 int avwidth = alview[avnum].getWidth() + 1;
2317 // this relies on sann being preserved after we
2318 // modify the sequence's annotation array for each duplication
2319 for (int a = 0; a < sann.length; a++)
2321 AlignmentAnnotation newann = new AlignmentAnnotation(
2323 sequences[i].addAlignmentAnnotation(newann);
2324 newann.padAnnotation(avwidth);
2325 alview[avnum].addAnnotation(newann); // annotation was
2326 // duplicated earlier
2327 // TODO JAL-1145 graphGroups are not updated for sequence
2328 // annotation added to several views. This may cause
2330 alview[avnum].setAnnotationIndex(newann, a);
2335 buildSortByAnnotationScoresMenu();
2337 viewport.firePropertyChange("alignment", null,
2338 alignment.getSequences());
2339 if (alignPanels != null)
2341 for (AlignmentPanel ap : alignPanels)
2343 ap.validateAnnotationDimensions(false);
2348 alignPanel.validateAnnotationDimensions(false);
2354 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2356 String newtitle = new String("Copied sequences");
2358 if (Desktop.jalviewClipboard != null
2359 && Desktop.jalviewClipboard[2] != null)
2361 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2362 af.viewport.setHiddenColumns(hc);
2365 // >>>This is a fix for the moment, until a better solution is
2367 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2368 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2369 .getFeatureRenderer());
2371 // TODO: maintain provenance of an alignment, rather than just make the
2372 // title a concatenation of operations.
2375 if (title.startsWith("Copied sequences"))
2381 newtitle = newtitle.concat("- from " + title);
2386 newtitle = new String("Pasted sequences");
2389 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2394 } catch (Exception ex)
2396 ex.printStackTrace();
2397 System.out.println("Exception whilst pasting: " + ex);
2398 // could be anything being pasted in here
2404 protected void expand_newalign(ActionEvent e)
2408 AlignmentI alignment = AlignmentUtils
2409 .expandContext(getViewport().getAlignment(), -1);
2410 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2412 String newtitle = new String("Flanking alignment");
2414 if (Desktop.jalviewClipboard != null
2415 && Desktop.jalviewClipboard[2] != null)
2417 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2418 af.viewport.setHiddenColumns(hc);
2421 // >>>This is a fix for the moment, until a better solution is
2423 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2424 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2425 .getFeatureRenderer());
2427 // TODO: maintain provenance of an alignment, rather than just make the
2428 // title a concatenation of operations.
2430 if (title.startsWith("Copied sequences"))
2436 newtitle = newtitle.concat("- from " + title);
2440 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2442 } catch (Exception ex)
2444 ex.printStackTrace();
2445 System.out.println("Exception whilst pasting: " + ex);
2446 // could be anything being pasted in here
2447 } catch (OutOfMemoryError oom)
2449 new OOMWarning("Viewing flanking region of alignment", oom);
2454 * Action Cut (delete and copy) the selected region
2457 protected void cut_actionPerformed()
2459 copy_actionPerformed();
2460 delete_actionPerformed();
2464 * Performs menu option to Delete the currently selected region
2467 protected void delete_actionPerformed()
2470 SequenceGroup sg = viewport.getSelectionGroup();
2476 Runnable okAction = new Runnable()
2481 SequenceI[] cut = sg.getSequences()
2482 .toArray(new SequenceI[sg.getSize()]);
2484 addHistoryItem(new EditCommand(
2485 MessageManager.getString("label.cut_sequences"), Action.CUT,
2486 cut, sg.getStartRes(),
2487 sg.getEndRes() - sg.getStartRes() + 1,
2488 viewport.getAlignment()));
2490 viewport.setSelectionGroup(null);
2491 viewport.sendSelection();
2492 viewport.getAlignment().deleteGroup(sg);
2494 viewport.firePropertyChange("alignment", null,
2495 viewport.getAlignment().getSequences());
2496 if (viewport.getAlignment().getHeight() < 1)
2500 AlignFrame.this.setClosed(true);
2501 } catch (Exception ex)
2509 * If the cut affects all sequences, prompt for confirmation
2511 boolean wholeHeight = sg.getSize() == viewport.getAlignment()
2513 boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes())
2514 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2515 if (wholeHeight && wholeWidth)
2517 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
2518 dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
2519 Object[] options = new Object[] {
2520 MessageManager.getString("action.ok"),
2521 MessageManager.getString("action.cancel") };
2522 dialog.showDialog(MessageManager.getString("warn.delete_all"),
2523 MessageManager.getString("label.delete_all"),
2524 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
2525 options, options[0]);
2540 protected void deleteGroups_actionPerformed(ActionEvent e)
2542 if (avc.deleteGroups())
2544 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2545 alignPanel.updateAnnotation();
2546 alignPanel.paintAlignment(true, true);
2557 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2559 SequenceGroup sg = new SequenceGroup(
2560 viewport.getAlignment().getSequences());
2562 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2563 viewport.setSelectionGroup(sg);
2564 viewport.isSelectionGroupChanged(true);
2565 viewport.sendSelection();
2566 // JAL-2034 - should delegate to
2567 // alignPanel to decide if overview needs
2569 alignPanel.paintAlignment(false, false);
2570 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2580 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2582 if (viewport.cursorMode)
2584 alignPanel.getSeqPanel().keyboardNo1 = null;
2585 alignPanel.getSeqPanel().keyboardNo2 = null;
2587 viewport.setSelectionGroup(null);
2588 viewport.getColumnSelection().clear();
2589 viewport.setSearchResults(null);
2590 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2591 // JAL-2034 - should delegate to
2592 // alignPanel to decide if overview needs
2594 alignPanel.paintAlignment(false, false);
2595 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2596 viewport.sendSelection();
2606 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2608 SequenceGroup sg = viewport.getSelectionGroup();
2612 selectAllSequenceMenuItem_actionPerformed(null);
2617 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2619 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2621 // JAL-2034 - should delegate to
2622 // alignPanel to decide if overview needs
2625 alignPanel.paintAlignment(true, false);
2626 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2627 viewport.sendSelection();
2631 public void invertColSel_actionPerformed(ActionEvent e)
2633 viewport.invertColumnSelection();
2634 alignPanel.paintAlignment(true, false);
2635 viewport.sendSelection();
2645 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2647 trimAlignment(true);
2657 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2659 trimAlignment(false);
2662 void trimAlignment(boolean trimLeft)
2664 ColumnSelection colSel = viewport.getColumnSelection();
2667 if (!colSel.isEmpty())
2671 column = colSel.getMin();
2675 column = colSel.getMax();
2679 if (viewport.getSelectionGroup() != null)
2681 seqs = viewport.getSelectionGroup()
2682 .getSequencesAsArray(viewport.getHiddenRepSequences());
2686 seqs = viewport.getAlignment().getSequencesArray();
2689 TrimRegionCommand trimRegion;
2692 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2693 column, viewport.getAlignment());
2694 viewport.getRanges().setStartRes(0);
2698 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2699 column, viewport.getAlignment());
2702 setStatus(MessageManager.formatMessage("label.removed_columns",
2704 { Integer.valueOf(trimRegion.getSize()).toString() }));
2706 addHistoryItem(trimRegion);
2708 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2710 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2711 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2713 viewport.getAlignment().deleteGroup(sg);
2717 viewport.firePropertyChange("alignment", null,
2718 viewport.getAlignment().getSequences());
2729 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2731 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2734 if (viewport.getSelectionGroup() != null)
2736 seqs = viewport.getSelectionGroup()
2737 .getSequencesAsArray(viewport.getHiddenRepSequences());
2738 start = viewport.getSelectionGroup().getStartRes();
2739 end = viewport.getSelectionGroup().getEndRes();
2743 seqs = viewport.getAlignment().getSequencesArray();
2746 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2747 "Remove Gapped Columns", seqs, start, end,
2748 viewport.getAlignment());
2750 addHistoryItem(removeGapCols);
2752 setStatus(MessageManager.formatMessage("label.removed_empty_columns",
2754 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2756 // This is to maintain viewport position on first residue
2757 // of first sequence
2758 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2759 ViewportRanges ranges = viewport.getRanges();
2760 int startRes = seq.findPosition(ranges.getStartRes());
2761 // ShiftList shifts;
2762 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2763 // edit.alColumnChanges=shifts.getInverse();
2764 // if (viewport.hasHiddenColumns)
2765 // viewport.getColumnSelection().compensateForEdits(shifts);
2766 ranges.setStartRes(seq.findIndex(startRes) - 1);
2767 viewport.firePropertyChange("alignment", null,
2768 viewport.getAlignment().getSequences());
2779 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2781 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2784 if (viewport.getSelectionGroup() != null)
2786 seqs = viewport.getSelectionGroup()
2787 .getSequencesAsArray(viewport.getHiddenRepSequences());
2788 start = viewport.getSelectionGroup().getStartRes();
2789 end = viewport.getSelectionGroup().getEndRes();
2793 seqs = viewport.getAlignment().getSequencesArray();
2796 // This is to maintain viewport position on first residue
2797 // of first sequence
2798 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2799 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2801 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2802 viewport.getAlignment()));
2804 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2806 viewport.firePropertyChange("alignment", null,
2807 viewport.getAlignment().getSequences());
2818 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2820 viewport.setPadGaps(padGapsMenuitem.isSelected());
2821 viewport.firePropertyChange("alignment", null,
2822 viewport.getAlignment().getSequences());
2826 * Opens a Finder dialog
2831 public void findMenuItem_actionPerformed(ActionEvent e)
2833 new Finder(alignPanel, false, null);
2837 * Create a new view of the current alignment.
2840 public void newView_actionPerformed(ActionEvent e)
2842 newView(null, true);
2846 * Creates and shows a new view of the current alignment.
2849 * title of newly created view; if null, one will be generated
2850 * @param copyAnnotation
2851 * if true then duplicate all annnotation, groups and settings
2852 * @return new alignment panel, already displayed.
2854 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2857 * Create a new AlignmentPanel (with its own, new Viewport)
2859 AlignmentPanel newap = new jalview.project.Jalview2XML()
2860 .copyAlignPanel(alignPanel);
2861 if (!copyAnnotation)
2864 * remove all groups and annotation except for the automatic stuff
2866 newap.av.getAlignment().deleteAllGroups();
2867 newap.av.getAlignment().deleteAllAnnotations(false);
2870 newap.av.setGatherViewsHere(false);
2872 if (viewport.getViewName() == null)
2874 viewport.setViewName(
2875 MessageManager.getString("label.view_name_original"));
2879 * Views share the same edits undo and redo stacks
2881 newap.av.setHistoryList(viewport.getHistoryList());
2882 newap.av.setRedoList(viewport.getRedoList());
2885 * copy any visualisation settings that are not saved in the project
2887 newap.av.setColourAppliesToAllGroups(
2888 viewport.getColourAppliesToAllGroups());
2891 * Views share the same mappings; need to deregister any new mappings
2892 * created by copyAlignPanel, and register the new reference to the shared
2895 newap.av.replaceMappings(viewport.getAlignment());
2898 * start up cDNA consensus (if applicable) now mappings are in place
2900 if (newap.av.initComplementConsensus())
2902 newap.refresh(true); // adjust layout of annotations
2905 newap.av.setViewName(getNewViewName(viewTitle));
2907 addAlignmentPanel(newap, true);
2908 newap.alignmentChanged();
2910 if (alignPanels.size() == 2)
2912 viewport.setGatherViewsHere(true);
2914 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2919 * Make a new name for the view, ensuring it is unique within the current
2920 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2921 * these now use viewId. Unique view names are still desirable for usability.)
2926 protected String getNewViewName(String viewTitle)
2928 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2929 boolean addFirstIndex = false;
2930 if (viewTitle == null || viewTitle.trim().length() == 0)
2932 viewTitle = MessageManager.getString("action.view");
2933 addFirstIndex = true;
2937 index = 1;// we count from 1 if given a specific name
2939 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2941 List<Component> comps = PaintRefresher.components
2942 .get(viewport.getSequenceSetId());
2944 List<String> existingNames = getExistingViewNames(comps);
2946 while (existingNames.contains(newViewName))
2948 newViewName = viewTitle + " " + (++index);
2954 * Returns a list of distinct view names found in the given list of
2955 * components. View names are held on the viewport of an AlignmentPanel.
2960 protected List<String> getExistingViewNames(List<Component> comps)
2962 List<String> existingNames = new ArrayList<>();
2963 for (Component comp : comps)
2965 if (comp instanceof AlignmentPanel)
2967 AlignmentPanel ap = (AlignmentPanel) comp;
2968 if (!existingNames.contains(ap.av.getViewName()))
2970 existingNames.add(ap.av.getViewName());
2974 return existingNames;
2978 * Explode tabbed views into separate windows.
2981 public void expandViews_actionPerformed(ActionEvent e)
2983 Desktop.explodeViews(this);
2987 * Gather views in separate windows back into a tabbed presentation.
2990 public void gatherViews_actionPerformed(ActionEvent e)
2992 Desktop.instance.gatherViews(this);
3002 public void font_actionPerformed(ActionEvent e)
3004 new FontChooser(alignPanel);
3014 protected void seqLimit_actionPerformed(ActionEvent e)
3016 viewport.setShowJVSuffix(seqLimits.isSelected());
3018 alignPanel.getIdPanel().getIdCanvas()
3019 .setPreferredSize(alignPanel.calculateIdWidth());
3020 alignPanel.paintAlignment(true, false);
3024 public void idRightAlign_actionPerformed(ActionEvent e)
3026 viewport.setRightAlignIds(idRightAlign.isSelected());
3027 alignPanel.paintAlignment(false, false);
3031 public void centreColumnLabels_actionPerformed(ActionEvent e)
3033 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
3034 alignPanel.paintAlignment(false, false);
3040 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3043 protected void followHighlight_actionPerformed()
3046 * Set the 'follow' flag on the Viewport (and scroll to position if now
3049 final boolean state = this.followHighlightMenuItem.getState();
3050 viewport.setFollowHighlight(state);
3053 alignPanel.scrollToPosition(viewport.getSearchResults());
3064 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3066 viewport.setColourText(colourTextMenuItem.isSelected());
3067 alignPanel.paintAlignment(false, false);
3077 public void wrapMenuItem_actionPerformed(ActionEvent e)
3079 scaleAbove.setVisible(wrapMenuItem.isSelected());
3080 scaleLeft.setVisible(wrapMenuItem.isSelected());
3081 scaleRight.setVisible(wrapMenuItem.isSelected());
3082 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3083 alignPanel.updateLayout();
3087 public void showAllSeqs_actionPerformed(ActionEvent e)
3089 viewport.showAllHiddenSeqs();
3093 public void showAllColumns_actionPerformed(ActionEvent e)
3095 viewport.showAllHiddenColumns();
3096 alignPanel.paintAlignment(true, true);
3097 viewport.sendSelection();
3101 public void hideSelSequences_actionPerformed(ActionEvent e)
3103 viewport.hideAllSelectedSeqs();
3107 * called by key handler and the hide all/show all menu items
3112 protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3115 boolean hide = false;
3116 SequenceGroup sg = viewport.getSelectionGroup();
3117 if (!toggleSeqs && !toggleCols)
3119 // Hide everything by the current selection - this is a hack - we do the
3120 // invert and then hide
3121 // first check that there will be visible columns after the invert.
3122 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3123 && sg.getStartRes() <= sg.getEndRes()))
3125 // now invert the sequence set, if required - empty selection implies
3126 // that no hiding is required.
3129 invertSequenceMenuItem_actionPerformed(null);
3130 sg = viewport.getSelectionGroup();
3134 viewport.expandColSelection(sg, true);
3135 // finally invert the column selection and get the new sequence
3137 invertColSel_actionPerformed(null);
3144 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3146 hideSelSequences_actionPerformed(null);
3149 else if (!(toggleCols && viewport.hasSelectedColumns()))
3151 showAllSeqs_actionPerformed(null);
3157 if (viewport.hasSelectedColumns())
3159 hideSelColumns_actionPerformed(null);
3162 viewport.setSelectionGroup(sg);
3167 showAllColumns_actionPerformed(null);
3176 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3177 * event.ActionEvent)
3180 public void hideAllButSelection_actionPerformed(ActionEvent e)
3182 toggleHiddenRegions(false, false);
3183 viewport.sendSelection();
3190 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3194 public void hideAllSelection_actionPerformed(ActionEvent e)
3196 SequenceGroup sg = viewport.getSelectionGroup();
3197 viewport.expandColSelection(sg, false);
3198 viewport.hideAllSelectedSeqs();
3199 viewport.hideSelectedColumns();
3200 alignPanel.updateLayout();
3201 alignPanel.paintAlignment(true, true);
3202 viewport.sendSelection();
3209 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3213 public void showAllhidden_actionPerformed(ActionEvent e)
3215 viewport.showAllHiddenColumns();
3216 viewport.showAllHiddenSeqs();
3217 alignPanel.paintAlignment(true, true);
3218 viewport.sendSelection();
3222 public void hideSelColumns_actionPerformed(ActionEvent e)
3224 viewport.hideSelectedColumns();
3225 alignPanel.updateLayout();
3226 alignPanel.paintAlignment(true, true);
3227 viewport.sendSelection();
3231 public void hiddenMarkers_actionPerformed(ActionEvent e)
3233 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3244 protected void scaleAbove_actionPerformed(ActionEvent e)
3246 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3247 alignPanel.updateLayout();
3248 alignPanel.paintAlignment(true, false);
3258 protected void scaleLeft_actionPerformed(ActionEvent e)
3260 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3261 alignPanel.updateLayout();
3262 alignPanel.paintAlignment(true, false);
3272 protected void scaleRight_actionPerformed(ActionEvent e)
3274 viewport.setScaleRightWrapped(scaleRight.isSelected());
3275 alignPanel.updateLayout();
3276 alignPanel.paintAlignment(true, false);
3286 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3288 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3289 alignPanel.paintAlignment(false, false);
3299 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3301 viewport.setShowText(viewTextMenuItem.isSelected());
3302 alignPanel.paintAlignment(false, false);
3312 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3314 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3315 alignPanel.paintAlignment(false, false);
3318 public FeatureSettings featureSettings;
3321 public FeatureSettingsControllerI getFeatureSettingsUI()
3323 return featureSettings;
3327 public void featureSettings_actionPerformed(ActionEvent e)
3329 showFeatureSettingsUI();
3333 public FeatureSettingsControllerI showFeatureSettingsUI()
3335 if (featureSettings != null)
3337 featureSettings.closeOldSettings();
3338 featureSettings = null;
3340 if (!showSeqFeatures.isSelected())
3342 // make sure features are actually displayed
3343 showSeqFeatures.setSelected(true);
3344 showSeqFeatures_actionPerformed(null);
3346 featureSettings = new FeatureSettings(this);
3347 return featureSettings;
3351 * Set or clear 'Show Sequence Features'
3357 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3359 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3360 alignPanel.paintAlignment(true, true);
3364 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3365 * the annotations panel as a whole.
3367 * The options to show/hide all annotations should be enabled when the panel
3368 * is shown, and disabled when the panel is hidden.
3373 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3375 final boolean setVisible = annotationPanelMenuItem.isSelected();
3376 viewport.setShowAnnotation(setVisible);
3377 this.showAllSeqAnnotations.setEnabled(setVisible);
3378 this.hideAllSeqAnnotations.setEnabled(setVisible);
3379 this.showAllAlAnnotations.setEnabled(setVisible);
3380 this.hideAllAlAnnotations.setEnabled(setVisible);
3381 alignPanel.updateLayout();
3385 public void alignmentProperties()
3388 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3391 String content = MessageManager.formatMessage("label.html_content",
3393 { contents.toString() });
3396 if (Platform.isJS())
3398 JLabel textLabel = new JLabel();
3399 textLabel.setText(content);
3400 textLabel.setBackground(Color.WHITE);
3402 pane = new JPanel(new BorderLayout());
3403 ((JPanel) pane).setOpaque(true);
3404 pane.setBackground(Color.WHITE);
3405 ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
3414 JEditorPane editPane = new JEditorPane("text/html", "");
3415 editPane.setEditable(false);
3416 editPane.setText(content);
3420 JInternalFrame frame = new JInternalFrame();
3422 frame.getContentPane().add(new JScrollPane(pane));
3424 Desktop.addInternalFrame(frame, MessageManager
3425 .formatMessage("label.alignment_properties", new Object[]
3426 { getTitle() }), 500, 400);
3436 public void overviewMenuItem_actionPerformed(ActionEvent e)
3438 if (alignPanel.overviewPanel != null)
3443 JInternalFrame frame = new JInternalFrame();
3444 final OverviewPanel overview = new OverviewPanel(alignPanel);
3445 frame.setContentPane(overview);
3446 Desktop.addInternalFrame(frame, MessageManager
3447 .formatMessage("label.overview_params", new Object[]
3448 { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
3451 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3452 frame.addInternalFrameListener(
3453 new javax.swing.event.InternalFrameAdapter()
3456 public void internalFrameClosed(
3457 javax.swing.event.InternalFrameEvent evt)
3460 alignPanel.setOverviewPanel(null);
3463 if (getKeyListeners().length > 0)
3465 frame.addKeyListener(getKeyListeners()[0]);
3468 alignPanel.setOverviewPanel(overview);
3472 public void textColour_actionPerformed()
3474 new TextColourChooser().chooseColour(alignPanel, null);
3478 * public void covariationColour_actionPerformed() {
3480 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3484 public void annotationColour_actionPerformed()
3486 new AnnotationColourChooser(viewport, alignPanel);
3490 public void annotationColumn_actionPerformed(ActionEvent e)
3492 new AnnotationColumnChooser(viewport, alignPanel);
3496 * Action on the user checking or unchecking the option to apply the selected
3497 * colour scheme to all groups. If unchecked, groups may have their own
3498 * independent colour schemes.
3503 public void applyToAllGroups_actionPerformed(boolean selected)
3505 viewport.setColourAppliesToAllGroups(selected);
3509 * Action on user selecting a colour from the colour menu
3512 * the name (not the menu item label!) of the colour scheme
3515 public void changeColour_actionPerformed(String name)
3518 * 'User Defined' opens a panel to configure or load a
3519 * user-defined colour scheme
3521 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3523 new UserDefinedColours(alignPanel);
3528 * otherwise set the chosen colour scheme (or null for 'None')
3530 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3531 viewport, viewport.getAlignment(),
3532 viewport.getHiddenRepSequences());
3537 * Actions on setting or changing the alignment colour scheme
3542 public void changeColour(ColourSchemeI cs)
3544 // TODO: pull up to controller method
3545 ColourMenuHelper.setColourSelected(colourMenu, cs);
3547 viewport.setGlobalColourScheme(cs);
3549 alignPanel.paintAlignment(true, true);
3553 * Show the PID threshold slider panel
3556 protected void modifyPID_actionPerformed()
3558 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3559 alignPanel.getViewName());
3560 SliderPanel.showPIDSlider();
3564 * Show the Conservation slider panel
3567 protected void modifyConservation_actionPerformed()
3569 SliderPanel.setConservationSlider(alignPanel,
3570 viewport.getResidueShading(), alignPanel.getViewName());
3571 SliderPanel.showConservationSlider();
3575 * Action on selecting or deselecting (Colour) By Conservation
3578 public void conservationMenuItem_actionPerformed(boolean selected)
3580 modifyConservation.setEnabled(selected);
3581 viewport.setConservationSelected(selected);
3582 viewport.getResidueShading().setConservationApplied(selected);
3584 changeColour(viewport.getGlobalColourScheme());
3587 modifyConservation_actionPerformed();
3591 SliderPanel.hideConservationSlider();
3596 * Action on selecting or deselecting (Colour) Above PID Threshold
3599 public void abovePIDThreshold_actionPerformed(boolean selected)
3601 modifyPID.setEnabled(selected);
3602 viewport.setAbovePIDThreshold(selected);
3605 viewport.getResidueShading().setThreshold(0,
3606 viewport.isIgnoreGapsConsensus());
3609 changeColour(viewport.getGlobalColourScheme());
3612 modifyPID_actionPerformed();
3616 SliderPanel.hidePIDSlider();
3627 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3629 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3630 AlignmentSorter.sortByPID(viewport.getAlignment(),
3631 viewport.getAlignment().getSequenceAt(0));
3632 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3633 viewport.getAlignment()));
3634 alignPanel.paintAlignment(true, false);
3644 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3646 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3647 AlignmentSorter.sortByID(viewport.getAlignment());
3649 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3650 alignPanel.paintAlignment(true, false);
3660 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3662 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3663 AlignmentSorter.sortByLength(viewport.getAlignment());
3664 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3665 viewport.getAlignment()));
3666 alignPanel.paintAlignment(true, false);
3676 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3678 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3679 AlignmentSorter.sortByGroup(viewport.getAlignment());
3680 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3681 viewport.getAlignment()));
3683 alignPanel.paintAlignment(true, false);
3693 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3695 new RedundancyPanel(alignPanel, this);
3705 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3707 if ((viewport.getSelectionGroup() == null)
3708 || (viewport.getSelectionGroup().getSize() < 2))
3710 JvOptionPane.showInternalMessageDialog(this,
3711 MessageManager.getString(
3712 "label.you_must_select_least_two_sequences"),
3713 MessageManager.getString("label.invalid_selection"),
3714 JvOptionPane.WARNING_MESSAGE);
3718 JInternalFrame frame = new JInternalFrame();
3719 frame.setContentPane(new PairwiseAlignPanel(viewport));
3720 Desktop.addInternalFrame(frame,
3721 MessageManager.getString("action.pairwise_alignment"), 600,
3727 public void autoCalculate_actionPerformed(ActionEvent e)
3729 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3730 if (viewport.autoCalculateConsensus)
3732 viewport.firePropertyChange("alignment", null,
3733 viewport.getAlignment().getSequences());
3738 public void sortByTreeOption_actionPerformed(ActionEvent e)
3740 viewport.sortByTree = sortByTree.isSelected();
3744 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3746 viewport.followSelection = listenToViewSelections.isSelected();
3750 * Constructs a tree panel and adds it to the desktop
3753 * tree type (NJ or AV)
3755 * name of score model used to compute the tree
3757 * parameters for the distance or similarity calculation
3759 void newTreePanel(String type, String modelName,
3760 SimilarityParamsI options)
3762 String frameTitle = "";
3765 boolean onSelection = false;
3766 if (viewport.getSelectionGroup() != null
3767 && viewport.getSelectionGroup().getSize() > 0)
3769 SequenceGroup sg = viewport.getSelectionGroup();
3771 /* Decide if the selection is a column region */
3772 for (SequenceI _s : sg.getSequences())
3774 if (_s.getLength() < sg.getEndRes())
3776 JvOptionPane.showMessageDialog(Desktop.desktop,
3777 MessageManager.getString(
3778 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3779 MessageManager.getString(
3780 "label.sequences_selection_not_aligned"),
3781 JvOptionPane.WARNING_MESSAGE);
3790 if (viewport.getAlignment().getHeight() < 2)
3796 tp = new TreePanel(alignPanel, type, modelName, options);
3797 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3799 frameTitle += " from ";
3801 if (viewport.getViewName() != null)
3803 frameTitle += viewport.getViewName() + " of ";
3806 frameTitle += this.title;
3808 Desktop.addInternalFrame(tp, frameTitle, 600, 500);
3819 public void addSortByOrderMenuItem(String title,
3820 final AlignmentOrder order)
3822 final JMenuItem item = new JMenuItem(MessageManager
3823 .formatMessage("action.by_title_param", new Object[]
3826 item.addActionListener(new java.awt.event.ActionListener()
3829 public void actionPerformed(ActionEvent e)
3831 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3833 // TODO: JBPNote - have to map order entries to curent SequenceI
3835 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3837 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3838 viewport.getAlignment()));
3840 alignPanel.paintAlignment(true, false);
3846 * Add a new sort by annotation score menu item
3849 * the menu to add the option to
3851 * the label used to retrieve scores for each sequence on the
3854 public void addSortByAnnotScoreMenuItem(JMenu sort,
3855 final String scoreLabel)
3857 final JMenuItem item = new JMenuItem(scoreLabel);
3859 item.addActionListener(new java.awt.event.ActionListener()
3862 public void actionPerformed(ActionEvent e)
3864 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3865 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3866 viewport.getAlignment());// ,viewport.getSelectionGroup());
3867 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3868 viewport.getAlignment()));
3869 alignPanel.paintAlignment(true, false);
3875 * last hash for alignment's annotation array - used to minimise cost of
3878 protected int _annotationScoreVectorHash;
3881 * search the alignment and rebuild the sort by annotation score submenu the
3882 * last alignment annotation vector hash is stored to minimize cost of
3883 * rebuilding in subsequence calls.
3887 public void buildSortByAnnotationScoresMenu()
3889 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3894 if (viewport.getAlignment().getAlignmentAnnotation()
3895 .hashCode() != _annotationScoreVectorHash)
3897 sortByAnnotScore.removeAll();
3898 // almost certainly a quicker way to do this - but we keep it simple
3899 Hashtable<String, String> scoreSorts = new Hashtable<>();
3900 AlignmentAnnotation aann[];
3901 for (SequenceI sqa : viewport.getAlignment().getSequences())
3903 aann = sqa.getAnnotation();
3904 for (int i = 0; aann != null && i < aann.length; i++)
3906 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3908 scoreSorts.put(aann[i].label, aann[i].label);
3912 Enumeration<String> labels = scoreSorts.keys();
3913 while (labels.hasMoreElements())
3915 addSortByAnnotScoreMenuItem(sortByAnnotScore, labels.nextElement());
3917 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3920 _annotationScoreVectorHash = viewport.getAlignment()
3921 .getAlignmentAnnotation().hashCode();
3926 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3927 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3928 * call. Listeners are added to remove the menu item when the treePanel is
3929 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3933 public void buildTreeSortMenu()
3935 sortByTreeMenu.removeAll();
3937 List<Component> comps = PaintRefresher.components
3938 .get(viewport.getSequenceSetId());
3939 List<TreePanel> treePanels = new ArrayList<>();
3940 for (Component comp : comps)
3942 if (comp instanceof TreePanel)
3944 treePanels.add((TreePanel) comp);
3948 if (treePanels.size() < 1)
3950 sortByTreeMenu.setVisible(false);
3954 sortByTreeMenu.setVisible(true);
3956 for (final TreePanel tp : treePanels)
3958 final JMenuItem item = new JMenuItem(tp.getTitle());
3959 item.addActionListener(new java.awt.event.ActionListener()
3962 public void actionPerformed(ActionEvent e)
3964 tp.sortByTree_actionPerformed();
3965 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3970 sortByTreeMenu.add(item);
3974 public boolean sortBy(AlignmentOrder alorder, String undoname)
3976 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3977 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3978 if (undoname != null)
3980 addHistoryItem(new OrderCommand(undoname, oldOrder,
3981 viewport.getAlignment()));
3983 alignPanel.paintAlignment(true, false);
3988 * Work out whether the whole set of sequences or just the selected set will
3989 * be submitted for multiple alignment.
3992 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3994 // Now, check we have enough sequences
3995 AlignmentView msa = null;
3997 if ((viewport.getSelectionGroup() != null)
3998 && (viewport.getSelectionGroup().getSize() > 1))
4000 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4001 // some common interface!
4003 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4004 * SequenceI[sz = seqs.getSize(false)];
4006 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4007 * seqs.getSequenceAt(i); }
4009 msa = viewport.getAlignmentView(true);
4011 else if (viewport.getSelectionGroup() != null
4012 && viewport.getSelectionGroup().getSize() == 1)
4014 int option = JvOptionPane.showConfirmDialog(this,
4015 MessageManager.getString("warn.oneseq_msainput_selection"),
4016 MessageManager.getString("label.invalid_selection"),
4017 JvOptionPane.OK_CANCEL_OPTION);
4018 if (option == JvOptionPane.OK_OPTION)
4020 msa = viewport.getAlignmentView(false);
4025 msa = viewport.getAlignmentView(false);
4031 * Decides what is submitted to a secondary structure prediction service: the
4032 * first sequence in the alignment, or in the current selection, or, if the
4033 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4034 * region or the whole alignment. (where the first sequence in the set is the
4035 * one that the prediction will be for).
4037 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4039 AlignmentView seqs = null;
4041 if ((viewport.getSelectionGroup() != null)
4042 && (viewport.getSelectionGroup().getSize() > 0))
4044 seqs = viewport.getAlignmentView(true);
4048 seqs = viewport.getAlignmentView(false);
4050 // limit sequences - JBPNote in future - could spawn multiple prediction
4052 // TODO: viewport.getAlignment().isAligned is a global state - the local
4053 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4054 if (!viewport.getAlignment().isAligned(false))
4056 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4057 // TODO: if seqs.getSequences().length>1 then should really have warned
4071 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4073 // Pick the tree file
4074 JalviewFileChooser chooser = new JalviewFileChooser(
4075 Cache.getProperty("LAST_DIRECTORY"));
4076 chooser.setFileView(new JalviewFileView());
4077 chooser.setDialogTitle(
4078 MessageManager.getString("label.select_newick_like_tree_file"));
4079 chooser.setToolTipText(
4080 MessageManager.getString("label.load_tree_file"));
4082 chooser.setResponseHandler(0, new Runnable()
4087 String filePath = chooser.getSelectedFile().getPath();
4088 Cache.setProperty("LAST_DIRECTORY", filePath);
4089 NewickFile fin = null;
4092 fin = new NewickFile(new FileParse(chooser.getSelectedFile(),
4093 DataSourceType.FILE));
4094 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4095 } catch (Exception ex)
4097 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4099 .getString("label.problem_reading_tree_file"),
4100 JvOptionPane.WARNING_MESSAGE);
4101 ex.printStackTrace();
4103 if (fin != null && fin.hasWarningMessage())
4105 JvOptionPane.showMessageDialog(Desktop.desktop,
4106 fin.getWarningMessage(),
4107 MessageManager.getString(
4108 "label.possible_problem_with_tree_file"),
4109 JvOptionPane.WARNING_MESSAGE);
4113 chooser.showOpenDialog(this);
4116 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4118 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4121 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4122 int h, int x, int y)
4124 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4128 * Add a treeviewer for the tree extracted from a Newick file object to the
4129 * current alignment view
4136 * Associated alignment input data (or null)
4145 * @return TreePanel handle
4147 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4148 AlignmentView input, int w, int h, int x, int y)
4150 TreePanel tp = null;
4156 if (nf.getTree() != null)
4158 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4164 tp.setLocation(x, y);
4167 Desktop.addInternalFrame(tp, treeTitle, w, h);
4169 } catch (Exception ex)
4171 ex.printStackTrace();
4177 private boolean buildingMenu = false;
4180 * Generates menu items and listener event actions for web service clients
4183 public void BuildWebServiceMenu()
4185 while (buildingMenu)
4189 System.err.println("Waiting for building menu to finish.");
4191 } catch (Exception e)
4195 final AlignFrame me = this;
4196 buildingMenu = true;
4197 new Thread(new Runnable()
4202 final List<JMenuItem> legacyItems = new ArrayList<>();
4205 // System.err.println("Building ws menu again "
4206 // + Thread.currentThread());
4207 // TODO: add support for context dependent disabling of services based
4209 // alignment and current selection
4210 // TODO: add additional serviceHandle parameter to specify abstract
4212 // class independently of AbstractName
4213 // TODO: add in rediscovery GUI function to restart discoverer
4214 // TODO: group services by location as well as function and/or
4216 // object broker mechanism.
4217 final Vector<JMenu> wsmenu = new Vector<>();
4218 final IProgressIndicator af = me;
4221 * do not i18n these strings - they are hard-coded in class
4222 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4223 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4225 final JMenu msawsmenu = new JMenu("Alignment");
4226 final JMenu secstrmenu = new JMenu(
4227 "Secondary Structure Prediction");
4228 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4229 final JMenu analymenu = new JMenu("Analysis");
4230 final JMenu dismenu = new JMenu("Protein Disorder");
4231 // JAL-940 - only show secondary structure prediction services from
4232 // the legacy server
4233 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4235 Discoverer.services != null && (Discoverer.services.size() > 0))
4237 // TODO: refactor to allow list of AbstractName/Handler bindings to
4239 // stored or retrieved from elsewhere
4240 // No MSAWS used any more:
4241 // Vector msaws = null; // (Vector)
4242 // Discoverer.services.get("MsaWS");
4243 Vector<ServiceHandle> secstrpr = Discoverer.services
4245 if (secstrpr != null)
4247 // Add any secondary structure prediction services
4248 for (int i = 0, j = secstrpr.size(); i < j; i++)
4250 final ext.vamsas.ServiceHandle sh = secstrpr.get(i);
4251 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4252 .getServiceClient(sh);
4253 int p = secstrmenu.getItemCount();
4254 impl.attachWSMenuEntry(secstrmenu, me);
4255 int q = secstrmenu.getItemCount();
4256 for (int litm = p; litm < q; litm++)
4258 legacyItems.add(secstrmenu.getItem(litm));
4264 // Add all submenus in the order they should appear on the web
4266 wsmenu.add(msawsmenu);
4267 wsmenu.add(secstrmenu);
4268 wsmenu.add(dismenu);
4269 wsmenu.add(analymenu);
4270 // No search services yet
4271 // wsmenu.add(seqsrchmenu);
4273 javax.swing.SwingUtilities.invokeLater(new Runnable()
4280 webService.removeAll();
4281 // first, add discovered services onto the webservices menu
4282 if (wsmenu.size() > 0)
4284 for (int i = 0, j = wsmenu.size(); i < j; i++)
4286 webService.add(wsmenu.get(i));
4291 webService.add(me.webServiceNoServices);
4293 // TODO: move into separate menu builder class.
4295 // logic for 2.11.1.4 is
4296 // always look to see if there is a discover. if there isn't
4297 // we can't show any Jws2 services
4298 // if there are services available, show them - regardless of
4299 // the 'show JWS2 preference'
4300 // if the discoverer is running then say so
4301 // otherwise offer to trigger discovery if 'show JWS2' is not
4303 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4304 if (jws2servs != null)
4306 if (jws2servs.hasServices())
4308 jws2servs.attachWSMenuEntry(webService, me);
4309 for (Jws2Instance sv : jws2servs.getServices())
4311 if (sv.description.toLowerCase(Locale.ROOT)
4314 for (JMenuItem jmi : legacyItems)
4316 jmi.setVisible(false);
4322 if (jws2servs.isRunning())
4324 JMenuItem tm = new JMenuItem(
4325 "Still discovering JABA Services");
4326 tm.setEnabled(false);
4329 else if (!Cache.getDefault("SHOW_JWS2_SERVICES", true))
4331 JMenuItem enableJws2 = new JMenuItem(
4332 "Discover Web Services");
4333 enableJws2.setToolTipText(
4334 "Select to start JABA Web Service discovery (or enable option in Web Service preferences)");
4335 enableJws2.setEnabled(true);
4336 enableJws2.addActionListener(new ActionListener()
4340 public void actionPerformed(ActionEvent e)
4342 // start service discoverer, but ignore preference
4343 Desktop.instance.startServiceDiscovery(false,
4347 webService.add(enableJws2);
4351 build_urlServiceMenu(me.webService);
4352 build_fetchdbmenu(webService);
4353 for (JMenu item : wsmenu)
4355 if (item.getItemCount() == 0)
4357 item.setEnabled(false);
4361 item.setEnabled(true);
4364 } catch (Exception e)
4367 "Exception during web service menu building process.",
4372 } catch (Exception e)
4375 buildingMenu = false;
4382 * construct any groupURL type service menu entries.
4386 protected void build_urlServiceMenu(JMenu webService)
4388 // TODO: remove this code when 2.7 is released
4389 // DEBUG - alignmentView
4391 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4392 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4394 * @Override public void actionPerformed(ActionEvent e) {
4395 * jalview.datamodel.AlignmentView
4396 * .testSelectionViews(af.viewport.getAlignment(),
4397 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4399 * }); webService.add(testAlView);
4401 // TODO: refactor to RestClient discoverer and merge menu entries for
4402 // rest-style services with other types of analysis/calculation service
4403 // SHmmr test client - still being implemented.
4404 // DEBUG - alignmentView
4406 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4409 client.attachWSMenuEntry(
4410 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4416 * Searches the alignment sequences for xRefs and builds the Show
4417 * Cross-References menu (formerly called Show Products), with database
4418 * sources for which cross-references are found (protein sources for a
4419 * nucleotide alignment and vice versa)
4421 * @return true if Show Cross-references menu should be enabled
4423 public boolean canShowProducts()
4425 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4426 AlignmentI dataset = viewport.getAlignment().getDataset();
4428 showProducts.removeAll();
4429 final boolean dna = viewport.getAlignment().isNucleotide();
4431 if (seqs == null || seqs.length == 0)
4433 // nothing to see here.
4437 boolean showp = false;
4440 List<String> ptypes = new CrossRef(seqs, dataset)
4441 .findXrefSourcesForSequences(dna);
4443 for (final String source : ptypes)
4446 final AlignFrame af = this;
4447 JMenuItem xtype = new JMenuItem(source);
4448 xtype.addActionListener(new ActionListener()
4451 public void actionPerformed(ActionEvent e)
4453 showProductsFor(af.viewport.getSequenceSelection(), dna,
4457 showProducts.add(xtype);
4459 showProducts.setVisible(showp);
4460 showProducts.setEnabled(showp);
4461 } catch (Exception e)
4464 "canShowProducts threw an exception - please report to help@jalview.org",
4471 public List<String> getProducts()
4473 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4474 AlignmentI dataset = viewport.getAlignment().getDataset();
4476 boolean dna = viewport.getAlignment().isNucleotide();
4478 if (seqs == null || seqs.length == 0)
4480 // nothing to see here.
4484 return new CrossRef(seqs, dataset).findXrefSourcesForSequences(dna);
4488 * Finds and displays cross-references for the selected sequences (protein
4489 * products for nucleotide sequences, dna coding sequences for peptides).
4492 * the sequences to show cross-references for
4494 * true if from a nucleotide alignment (so showing proteins)
4496 * the database to show cross-references for
4499 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4500 final String source)
4502 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4506 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4507 final String source)
4509 showProductsFor(sel, _odna, source, false, null);
4512 public CompletableFuture<Void> showProductsFor(final SequenceI[] sel,
4513 final boolean _odna, final String source, boolean returnFuture,
4516 CompletableFuture<Void> cf = CompletableFuture
4517 .runAsync(() -> runCrossRefActionAndCacheAlignFrame(sel, _odna,
4518 source, returnFuture, id));
4519 return returnFuture ? cf : null;
4522 private void runCrossRefActionAndCacheAlignFrame(SequenceI[] sel,
4523 boolean _odna, String source, boolean cacheAlignFrame, String id)
4525 final AlignFrame af = this;
4526 CrossRefAction.getHandlerFor(sel, _odna, source, af).run();
4527 af.cacheAlignFrameFromRestId(id);
4531 * Construct and display a new frame containing the translation of this
4532 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4535 public void showTranslation_actionPerformed(GeneticCodeI codeTable)
4537 AlignmentI al = null;
4540 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4542 al = dna.translateCdna(codeTable);
4543 } catch (Exception ex)
4545 Console.error("Exception during translation. Please report this !",
4547 final String msg = MessageManager.getString(
4548 "label.error_when_translating_sequences_submit_bug_report");
4549 final String errorTitle = MessageManager
4550 .getString("label.implementation_error")
4551 + MessageManager.getString("label.translation_failed");
4552 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4553 JvOptionPane.ERROR_MESSAGE);
4556 if (al == null || al.getHeight() == 0)
4558 final String msg = MessageManager.getString(
4559 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4560 final String errorTitle = MessageManager
4561 .getString("label.translation_failed");
4562 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4563 JvOptionPane.WARNING_MESSAGE);
4567 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4568 af.setFileFormat(this.currentFileFormat);
4569 final String newTitle = MessageManager
4570 .formatMessage("label.translation_of_params", new Object[]
4571 { this.getTitle(), codeTable.getId() });
4572 af.setTitle(newTitle);
4573 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4575 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4576 viewport.openSplitFrame(af, new Alignment(seqs));
4580 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4587 * Set the file format
4591 public void setFileFormat(FileFormatI format)
4593 this.currentFileFormat = format;
4597 * Try to load a features file onto the alignment.
4600 * contents or path to retrieve file or a File object
4602 * access mode of file (see jalview.io.AlignFile)
4603 * @return true if features file was parsed correctly.
4605 public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
4608 return avc.parseFeaturesFile(file, sourceType,
4609 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4614 public void refreshFeatureUI(boolean enableIfNecessary)
4616 // note - currently this is only still here rather than in the controller
4617 // because of the featureSettings hard reference that is yet to be
4619 if (enableIfNecessary)
4621 viewport.setShowSequenceFeatures(true);
4622 showSeqFeatures.setSelected(true);
4628 public void dragEnter(DropTargetDragEvent evt)
4633 public void dragExit(DropTargetEvent evt)
4638 public void dragOver(DropTargetDragEvent evt)
4643 public void dropActionChanged(DropTargetDragEvent evt)
4648 public void drop(DropTargetDropEvent evt)
4650 // JAL-1552 - acceptDrop required before getTransferable call for
4651 // Java's Transferable for native dnd
4652 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4653 Transferable t = evt.getTransferable();
4655 final AlignFrame thisaf = this;
4656 final List<Object> files = new ArrayList<>();
4657 List<DataSourceType> protocols = new ArrayList<>();
4661 Desktop.transferFromDropTarget(files, protocols, evt, t);
4662 } catch (Exception e)
4664 e.printStackTrace();
4668 new Thread(new Runnable()
4675 // check to see if any of these files have names matching sequences
4678 SequenceIdMatcher idm = new SequenceIdMatcher(
4679 viewport.getAlignment().getSequencesArray());
4681 * Object[] { String,SequenceI}
4683 ArrayList<Object[]> filesmatched = new ArrayList<>();
4684 ArrayList<Object> filesnotmatched = new ArrayList<>();
4685 for (int i = 0; i < files.size(); i++)
4688 Object file = files.get(i);
4689 String fileName = file.toString();
4691 DataSourceType protocol = (file instanceof File
4692 ? DataSourceType.FILE
4693 : FormatAdapter.checkProtocol(fileName));
4694 if (protocol == DataSourceType.FILE)
4697 if (file instanceof File)
4700 Platform.cacheFileData(fl);
4704 fl = new File(fileName);
4706 pdbfn = fl.getName();
4708 else if (protocol == DataSourceType.URL)
4710 URL url = new URL(fileName);
4711 pdbfn = url.getFile();
4713 if (pdbfn.length() > 0)
4715 // attempt to find a match in the alignment
4716 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4717 int l = 0, c = pdbfn.indexOf(".");
4718 while (mtch == null && c != -1)
4723 } while ((c = pdbfn.indexOf(".", l)) > l);
4726 pdbfn = pdbfn.substring(0, l);
4728 mtch = idm.findAllIdMatches(pdbfn);
4735 type = new IdentifyFile().identify(file, protocol);
4736 } catch (Exception ex)
4740 if (type != null && type.isStructureFile())
4742 filesmatched.add(new Object[] { file, protocol, mtch });
4746 // File wasn't named like one of the sequences or wasn't a PDB
4748 filesnotmatched.add(file);
4752 if (filesmatched.size() > 0)
4754 boolean autoAssociate = Cache
4755 .getDefault("AUTOASSOCIATE_PDBANDSEQS", false);
4758 String msg = MessageManager.formatMessage(
4759 "label.automatically_associate_structure_files_with_sequences_same_name",
4761 { Integer.valueOf(filesmatched.size())
4763 String ttl = MessageManager.getString(
4764 "label.automatically_associate_structure_files_by_name");
4765 int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
4766 ttl, JvOptionPane.YES_NO_OPTION);
4767 autoAssociate = choice == JvOptionPane.YES_OPTION;
4771 for (Object[] fm : filesmatched)
4773 // try and associate
4774 // TODO: may want to set a standard ID naming formalism for
4775 // associating PDB files which have no IDs.
4776 for (SequenceI toassoc : (SequenceI[]) fm[2])
4778 PDBEntry pe = new AssociatePdbFileWithSeq()
4779 .associatePdbWithSeq(fm[0].toString(),
4780 (DataSourceType) fm[1], toassoc, false,
4784 System.err.println("Associated file : "
4785 + (fm[0].toString()) + " with "
4786 + toassoc.getDisplayId(true));
4790 // TODO: do we need to update overview ? only if features are
4792 alignPanel.paintAlignment(true, false);
4798 * add declined structures as sequences
4800 for (Object[] o : filesmatched)
4802 filesnotmatched.add(o[0]);
4806 if (filesnotmatched.size() > 0)
4808 if (assocfiles > 0 && (Cache.getDefault(
4809 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4810 || JvOptionPane.showConfirmDialog(thisaf,
4811 "<html>" + MessageManager.formatMessage(
4812 "label.ignore_unmatched_dropped_files_info",
4815 filesnotmatched.size())
4818 MessageManager.getString(
4819 "label.ignore_unmatched_dropped_files"),
4820 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4824 for (Object fn : filesnotmatched)
4826 loadJalviewDataFile(fn, null, null, null);
4830 } catch (Exception ex)
4832 ex.printStackTrace();
4840 * Attempt to load a "dropped" file or URL string, by testing in turn for
4842 * <li>an Annotation file</li>
4843 * <li>a JNet file</li>
4844 * <li>a features file</li>
4845 * <li>else try to interpret as an alignment file</li>
4849 * either a filename or a URL string.
4851 public void loadJalviewDataFile(Object file, DataSourceType sourceType,
4852 FileFormatI format, SequenceI assocSeq)
4854 // BH 2018 was String file
4857 if (sourceType == null)
4859 sourceType = FormatAdapter.checkProtocol(file);
4861 // if the file isn't identified, or not positively identified as some
4862 // other filetype (PFAM is default unidentified alignment file type) then
4863 // try to parse as annotation.
4864 boolean isAnnotation = (format == null
4865 || FileFormat.Pfam.equals(format))
4866 ? new AnnotationFile().annotateAlignmentView(viewport,
4872 // first see if its a T-COFFEE score file
4873 TCoffeeScoreFile tcf = null;
4876 tcf = new TCoffeeScoreFile(file, sourceType);
4879 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4883 new TCoffeeColourScheme(viewport.getAlignment()));
4884 isAnnotation = true;
4885 setStatus(MessageManager.getString(
4886 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4890 // some problem - if no warning its probable that the ID matching
4891 // process didn't work
4892 JvOptionPane.showMessageDialog(Desktop.desktop,
4893 tcf.getWarningMessage() == null
4894 ? MessageManager.getString(
4895 "label.check_file_matches_sequence_ids_alignment")
4896 : tcf.getWarningMessage(),
4897 MessageManager.getString(
4898 "label.problem_reading_tcoffee_score_file"),
4899 JvOptionPane.WARNING_MESSAGE);
4906 } catch (Exception x)
4909 "Exception when processing data source as T-COFFEE score file",
4915 // try to see if its a JNet 'concise' style annotation file *before*
4917 // try to parse it as a features file
4920 format = new IdentifyFile().identify(file, sourceType);
4922 if (FileFormat.ScoreMatrix == format)
4924 ScoreMatrixFile sm = new ScoreMatrixFile(
4925 new FileParse(file, sourceType));
4927 // todo: i18n this message
4928 setStatus(MessageManager.formatMessage(
4929 "label.successfully_loaded_matrix",
4930 sm.getMatrixName()));
4932 else if (FileFormat.Jnet.equals(format))
4934 JPredFile predictions = new JPredFile(file, sourceType);
4935 new JnetAnnotationMaker();
4936 JnetAnnotationMaker.add_annotation(predictions,
4937 viewport.getAlignment(), 0, false);
4938 viewport.getAlignment().setupJPredAlignment();
4939 isAnnotation = true;
4941 // else if (IdentifyFile.FeaturesFile.equals(format))
4942 else if (FileFormat.Features.equals(format))
4944 if (parseFeaturesFile(file, sourceType))
4946 SplitFrame splitFrame = (SplitFrame) getSplitViewContainer();
4947 if (splitFrame != null)
4949 splitFrame.repaint();
4953 alignPanel.paintAlignment(true, true);
4959 new FileLoader().LoadFile(viewport, file, sourceType, format);
4966 alignPanel.adjustAnnotationHeight();
4967 viewport.updateSequenceIdColours();
4968 buildSortByAnnotationScoresMenu();
4969 alignPanel.paintAlignment(true, true);
4971 } catch (Exception ex)
4973 ex.printStackTrace();
4974 } catch (OutOfMemoryError oom)
4979 } catch (Exception x)
4984 + (sourceType != null
4985 ? (sourceType == DataSourceType.PASTE
4987 : "using " + sourceType + " from "
4991 ? "(parsing as '" + format + "' file)"
4993 oom, Desktop.desktop);
4998 * Method invoked by the ChangeListener on the tabbed pane, in other words
4999 * when a different tabbed pane is selected by the user or programmatically.
5002 public void tabSelectionChanged(int index)
5006 alignPanel = alignPanels.get(index);
5007 viewport = alignPanel.av;
5008 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5009 setMenusFromViewport(viewport);
5010 if (featureSettings != null && featureSettings.isOpen()
5011 && featureSettings.fr.getViewport() != viewport)
5013 if (viewport.isShowSequenceFeatures())
5015 // refresh the featureSettings to reflect UI change
5016 showFeatureSettingsUI();
5020 // close feature settings for this view.
5021 featureSettings.close();
5028 * 'focus' any colour slider that is open to the selected viewport
5030 if (viewport.getConservationSelected())
5032 SliderPanel.setConservationSlider(alignPanel,
5033 viewport.getResidueShading(), alignPanel.getViewName());
5037 SliderPanel.hideConservationSlider();
5039 if (viewport.getAbovePIDThreshold())
5041 SliderPanel.setPIDSliderSource(alignPanel,
5042 viewport.getResidueShading(), alignPanel.getViewName());
5046 SliderPanel.hidePIDSlider();
5050 * If there is a frame linked to this one in a SplitPane, switch it to the
5051 * same view tab index. No infinite recursion of calls should happen, since
5052 * tabSelectionChanged() should not get invoked on setting the selected
5053 * index to an unchanged value. Guard against setting an invalid index
5054 * before the new view peer tab has been created.
5056 final AlignViewportI peer = viewport.getCodingComplement();
5059 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
5060 .getAlignPanel().alignFrame;
5061 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5063 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5069 * On right mouse click on view tab, prompt for and set new view name.
5072 public void tabbedPane_mousePressed(MouseEvent e)
5074 if (e.isPopupTrigger())
5076 String msg = MessageManager.getString("label.enter_view_name");
5077 String ttl = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
5078 String reply = JvOptionPane.showInputDialog(msg, ttl);
5082 viewport.setViewName(reply);
5083 // TODO warn if reply is in getExistingViewNames()?
5084 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5089 public AlignViewport getCurrentView()
5095 * Open the dialog for regex description parsing.
5098 protected void extractScores_actionPerformed(ActionEvent e)
5100 ParseProperties pp = new jalview.analysis.ParseProperties(
5101 viewport.getAlignment());
5102 // TODO: verify regex and introduce GUI dialog for version 2.5
5103 // if (pp.getScoresFromDescription("col", "score column ",
5104 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5106 if (pp.getScoresFromDescription("description column",
5107 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5109 buildSortByAnnotationScoresMenu();
5117 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5121 protected void showDbRefs_actionPerformed(ActionEvent e)
5123 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5129 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5133 protected void showNpFeats_actionPerformed(ActionEvent e)
5135 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5139 * find the viewport amongst the tabs in this alignment frame and close that
5144 public boolean closeView(AlignViewportI av)
5148 this.closeMenuItem_actionPerformed(false);
5151 Component[] comp = tabbedPane.getComponents();
5152 for (int i = 0; comp != null && i < comp.length; i++)
5154 if (comp[i] instanceof AlignmentPanel)
5156 if (((AlignmentPanel) comp[i]).av == av)
5159 closeView((AlignmentPanel) comp[i]);
5167 protected void build_fetchdbmenu(JMenu webService)
5169 // Temporary hack - DBRef Fetcher always top level ws entry.
5170 // TODO We probably want to store a sequence database checklist in
5171 // preferences and have checkboxes.. rather than individual sources selected
5173 final JMenu rfetch = new JMenu(
5174 MessageManager.getString("action.fetch_db_references"));
5175 rfetch.setToolTipText(MessageManager.getString(
5176 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5177 webService.add(rfetch);
5179 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5180 MessageManager.getString("option.trim_retrieved_seqs"));
5181 trimrs.setToolTipText(
5182 MessageManager.getString("label.trim_retrieved_sequences"));
5184 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5185 trimrs.addActionListener(new ActionListener()
5188 public void actionPerformed(ActionEvent e)
5190 trimrs.setSelected(trimrs.isSelected());
5191 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5192 Boolean.valueOf(trimrs.isSelected()).toString());
5196 JMenuItem fetchr = new JMenuItem(
5197 MessageManager.getString("label.standard_databases"));
5198 fetchr.setToolTipText(
5199 MessageManager.getString("label.fetch_embl_uniprot"));
5200 fetchr.addActionListener(new ActionListener()
5204 public void actionPerformed(ActionEvent e)
5206 new Thread(new Runnable()
5211 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5212 .getAlignment().isNucleotide();
5213 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5214 alignPanel.av.getSequenceSelection(),
5215 alignPanel.alignFrame, null,
5216 alignPanel.alignFrame.featureSettings, isNucleotide);
5217 dbRefFetcher.addListener(new FetchFinishedListenerI()
5220 public void finished()
5223 for (FeatureSettingsModelI srcSettings : dbRefFetcher
5224 .getFeatureSettingsModels())
5227 alignPanel.av.mergeFeaturesStyle(srcSettings);
5229 AlignFrame.this.setMenusForViewport();
5232 dbRefFetcher.fetchDBRefs(false);
5240 new Thread(new Runnable()
5245 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5246 .getSequenceFetcherSingleton();
5247 javax.swing.SwingUtilities.invokeLater(new Runnable()
5252 String[] dbclasses = sf.getNonAlignmentSources();
5253 List<DbSourceProxy> otherdb;
5254 JMenu dfetch = new JMenu();
5255 JMenu ifetch = new JMenu();
5256 JMenuItem fetchr = null;
5257 int comp = 0, icomp = 0, mcomp = 15;
5258 String mname = null;
5260 for (String dbclass : dbclasses)
5262 otherdb = sf.getSourceProxy(dbclass);
5263 // add a single entry for this class, or submenu allowing 'fetch
5265 if (otherdb == null || otherdb.size() < 1)
5271 mname = "From " + dbclass;
5273 if (otherdb.size() == 1)
5275 final DbSourceProxy[] dassource = otherdb
5276 .toArray(new DbSourceProxy[0]);
5277 DbSourceProxy src = otherdb.get(0);
5278 fetchr = new JMenuItem(src.getDbSource());
5279 fetchr.addActionListener(new ActionListener()
5283 public void actionPerformed(ActionEvent e)
5285 new Thread(new Runnable()
5291 boolean isNucleotide = alignPanel.alignFrame
5292 .getViewport().getAlignment()
5294 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5295 alignPanel.av.getSequenceSelection(),
5296 alignPanel.alignFrame, dassource,
5297 alignPanel.alignFrame.featureSettings,
5300 .addListener(new FetchFinishedListenerI()
5303 public void finished()
5305 FeatureSettingsModelI srcSettings = dassource[0]
5306 .getFeatureColourScheme();
5307 alignPanel.av.mergeFeaturesStyle(
5309 AlignFrame.this.setMenusForViewport();
5312 dbRefFetcher.fetchDBRefs(false);
5318 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5319 MessageManager.formatMessage(
5320 "label.fetch_retrieve_from", new Object[]
5321 { src.getDbName() })));
5327 final DbSourceProxy[] dassource = otherdb
5328 .toArray(new DbSourceProxy[0]);
5330 DbSourceProxy src = otherdb.get(0);
5331 fetchr = new JMenuItem(MessageManager
5332 .formatMessage("label.fetch_all_param", new Object[]
5333 { src.getDbSource() }));
5334 fetchr.addActionListener(new ActionListener()
5337 public void actionPerformed(ActionEvent e)
5339 new Thread(new Runnable()
5345 boolean isNucleotide = alignPanel.alignFrame
5346 .getViewport().getAlignment()
5348 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5349 alignPanel.av.getSequenceSelection(),
5350 alignPanel.alignFrame, dassource,
5351 alignPanel.alignFrame.featureSettings,
5354 .addListener(new FetchFinishedListenerI()
5357 public void finished()
5359 AlignFrame.this.setMenusForViewport();
5362 dbRefFetcher.fetchDBRefs(false);
5368 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5369 MessageManager.formatMessage(
5370 "label.fetch_retrieve_from_all_sources",
5372 { Integer.valueOf(otherdb.size())
5374 src.getDbSource(), src.getDbName() })));
5377 // and then build the rest of the individual menus
5378 ifetch = new JMenu(MessageManager.formatMessage(
5379 "label.source_from_db_source", new Object[]
5380 { src.getDbSource() }));
5382 String imname = null;
5384 for (DbSourceProxy sproxy : otherdb)
5386 String dbname = sproxy.getDbName();
5387 String sname = dbname.length() > 5
5388 ? dbname.substring(0, 5) + "..."
5390 String msname = dbname.length() > 10
5391 ? dbname.substring(0, 10) + "..."
5395 imname = MessageManager
5396 .formatMessage("label.from_msname", new Object[]
5399 fetchr = new JMenuItem(msname);
5400 final DbSourceProxy[] dassrc = { sproxy };
5401 fetchr.addActionListener(new ActionListener()
5405 public void actionPerformed(ActionEvent e)
5407 new Thread(new Runnable()
5413 boolean isNucleotide = alignPanel.alignFrame
5414 .getViewport().getAlignment()
5416 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5417 alignPanel.av.getSequenceSelection(),
5418 alignPanel.alignFrame, dassrc,
5419 alignPanel.alignFrame.featureSettings,
5422 .addListener(new FetchFinishedListenerI()
5425 public void finished()
5427 AlignFrame.this.setMenusForViewport();
5430 dbRefFetcher.fetchDBRefs(false);
5436 fetchr.setToolTipText(
5437 "<html>" + MessageManager.formatMessage(
5438 "label.fetch_retrieve_from", new Object[]
5442 if (++icomp >= mcomp || i == (otherdb.size()))
5444 ifetch.setText(MessageManager.formatMessage(
5445 "label.source_to_target", imname, sname));
5447 ifetch = new JMenu();
5455 if (comp >= mcomp || dbi >= (dbclasses.length))
5457 dfetch.setText(MessageManager.formatMessage(
5458 "label.source_to_target", mname, dbclass));
5460 dfetch = new JMenu();
5474 * Left justify the whole alignment.
5477 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5479 AlignmentI al = viewport.getAlignment();
5481 viewport.firePropertyChange("alignment", null, al);
5485 * Right justify the whole alignment.
5488 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5490 AlignmentI al = viewport.getAlignment();
5492 viewport.firePropertyChange("alignment", null, al);
5496 public void setShowSeqFeatures(boolean b)
5498 showSeqFeatures.setSelected(b);
5499 viewport.setShowSequenceFeatures(b);
5506 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5507 * awt.event.ActionEvent)
5510 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5512 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5513 alignPanel.paintAlignment(false, false);
5520 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5524 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5526 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5527 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5535 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5536 * .event.ActionEvent)
5539 protected void showGroupConservation_actionPerformed(ActionEvent e)
5541 viewport.setShowGroupConservation(showGroupConservation.getState());
5542 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5549 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5550 * .event.ActionEvent)
5553 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5555 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5556 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5563 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5564 * .event.ActionEvent)
5567 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5569 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5570 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5574 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5576 showSequenceLogo.setState(true);
5577 viewport.setShowSequenceLogo(true);
5578 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5579 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5583 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5585 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5592 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5593 * .event.ActionEvent)
5596 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5598 if (avc.makeGroupsFromSelection())
5600 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5601 alignPanel.updateAnnotation();
5602 alignPanel.paintAlignment(true,
5603 viewport.needToUpdateStructureViews());
5607 public void clearAlignmentSeqRep()
5609 // TODO refactor alignmentseqrep to controller
5610 if (viewport.getAlignment().hasSeqrep())
5612 viewport.getAlignment().setSeqrep(null);
5613 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5614 alignPanel.updateAnnotation();
5615 alignPanel.paintAlignment(true, true);
5620 protected void createGroup_actionPerformed(ActionEvent e)
5622 if (avc.createGroup())
5624 if (applyAutoAnnotationSettings.isSelected())
5626 alignPanel.updateAnnotation(true, false);
5628 alignPanel.alignmentChanged();
5633 protected void unGroup_actionPerformed(ActionEvent e)
5637 alignPanel.alignmentChanged();
5642 * make the given alignmentPanel the currently selected tab
5644 * @param alignmentPanel
5646 public void setDisplayedView(AlignmentPanel alignmentPanel)
5648 if (!viewport.getSequenceSetId()
5649 .equals(alignmentPanel.av.getSequenceSetId()))
5651 throw new Error(MessageManager.getString(
5652 "error.implementation_error_cannot_show_view_alignment_frame"));
5654 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5655 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5657 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5662 * Action on selection of menu options to Show or Hide annotations.
5665 * @param forSequences
5666 * update sequence-related annotations
5667 * @param forAlignment
5668 * update non-sequence-related annotations
5671 protected void setAnnotationsVisibility(boolean visible,
5672 boolean forSequences, boolean forAlignment)
5674 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5675 .getAlignmentAnnotation();
5680 for (AlignmentAnnotation aa : anns)
5683 * don't display non-positional annotations on an alignment
5685 if (aa.annotations == null)
5689 boolean apply = (aa.sequenceRef == null && forAlignment)
5690 || (aa.sequenceRef != null && forSequences);
5693 aa.visible = visible;
5696 alignPanel.validateAnnotationDimensions(true);
5697 alignPanel.alignmentChanged();
5701 * Store selected annotation sort order for the view and repaint.
5704 protected void sortAnnotations_actionPerformed()
5706 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5708 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5709 alignPanel.paintAlignment(false, false);
5714 * @return alignment panels in this alignment frame
5716 public List<? extends AlignmentViewPanel> getAlignPanels()
5718 // alignPanels is never null
5719 // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5724 * Open a new alignment window, with the cDNA associated with this (protein)
5725 * alignment, aligned as is the protein.
5727 protected void viewAsCdna_actionPerformed()
5729 // TODO no longer a menu action - refactor as required
5730 final AlignmentI alignment = getViewport().getAlignment();
5731 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5732 if (mappings == null)
5736 List<SequenceI> cdnaSeqs = new ArrayList<>();
5737 for (SequenceI aaSeq : alignment.getSequences())
5739 for (AlignedCodonFrame acf : mappings)
5741 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5745 * There is a cDNA mapping for this protein sequence - add to new
5746 * alignment. It will share the same dataset sequence as other mapped
5747 * cDNA (no new mappings need to be created).
5749 final Sequence newSeq = new Sequence(dnaSeq);
5750 newSeq.setDatasetSequence(dnaSeq);
5751 cdnaSeqs.add(newSeq);
5755 if (cdnaSeqs.size() == 0)
5757 // show a warning dialog no mapped cDNA
5760 AlignmentI cdna = new Alignment(
5761 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5762 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5763 AlignFrame.DEFAULT_HEIGHT);
5764 cdna.alignAs(alignment);
5765 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5767 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5768 AlignFrame.DEFAULT_HEIGHT);
5772 * Set visibility of dna/protein complement view (available when shown in a
5778 protected void showComplement_actionPerformed(boolean show)
5780 SplitContainerI sf = getSplitViewContainer();
5783 sf.setComplementVisible(this, show);
5788 * Generate the reverse (optionally complemented) of the selected sequences,
5789 * and add them to the alignment
5792 protected void showReverse_actionPerformed(boolean complement)
5794 AlignmentI al = null;
5797 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5798 al = dna.reverseCdna(complement);
5799 viewport.addAlignment(al, "");
5800 addHistoryItem(new EditCommand(
5801 MessageManager.getString("label.add_sequences"), Action.PASTE,
5802 al.getSequencesArray(), 0, al.getWidth(),
5803 viewport.getAlignment()));
5804 } catch (Exception ex)
5806 System.err.println(ex.getMessage());
5812 * Try to run a script in the Groovy console, having first ensured that this
5813 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5814 * be targeted at this alignment.
5817 protected void runGroovy_actionPerformed()
5819 Jalview.setCurrentAlignFrame(this);
5820 groovy.ui.Console console = Desktop.getGroovyConsole();
5821 if (console != null)
5825 console.runScript();
5826 } catch (Exception ex)
5828 System.err.println((ex.toString()));
5829 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
5830 MessageManager.getString("label.couldnt_run_groovy_script"),
5831 MessageManager.getString("label.groovy_support_failed"),
5832 JvOptionPane.ERROR_MESSAGE);
5837 System.err.println("Can't run Groovy script as console not found");
5842 * Hides columns containing (or not containing) a specified feature, provided
5843 * that would not leave all columns hidden
5845 * @param featureType
5846 * @param columnsContaining
5849 public boolean hideFeatureColumns(String featureType,
5850 boolean columnsContaining)
5852 boolean notForHiding = avc.markColumnsContainingFeatures(
5853 columnsContaining, false, false, featureType);
5856 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5857 false, featureType))
5859 getViewport().hideSelectedColumns();
5867 protected void selectHighlightedColumns_actionPerformed(
5868 ActionEvent actionEvent)
5870 // include key modifier check in case user selects from menu
5871 avc.markHighlightedColumns(
5872 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5873 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5874 | ActionEvent.CTRL_MASK)) != 0);
5878 * Rebuilds the Colour menu, including any user-defined colours which have
5879 * been loaded either on startup or during the session
5881 public void buildColourMenu()
5883 colourMenu.removeAll();
5885 colourMenu.add(applyToAllGroups);
5886 colourMenu.add(textColour);
5887 colourMenu.addSeparator();
5889 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
5890 viewport.getAlignment(), false);
5892 colourMenu.add(annotationColour);
5893 bg.add(annotationColour);
5894 colourMenu.addSeparator();
5895 colourMenu.add(conservationMenuItem);
5896 colourMenu.add(modifyConservation);
5897 colourMenu.add(abovePIDThreshold);
5898 colourMenu.add(modifyPID);
5900 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5901 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5905 * Open a dialog (if not already open) that allows the user to select and
5906 * calculate PCA or Tree analysis
5908 protected void openTreePcaDialog()
5910 if (alignPanel.getCalculationDialog() == null)
5912 new CalculationChooser(AlignFrame.this);
5917 protected void loadVcf_actionPerformed()
5919 JalviewFileChooser chooser = new JalviewFileChooser(
5920 Cache.getProperty("LAST_DIRECTORY"));
5921 chooser.setFileView(new JalviewFileView());
5922 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
5923 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
5924 final AlignFrame us = this;
5925 chooser.setResponseHandler(0, new Runnable()
5930 String choice = chooser.getSelectedFile().getPath();
5931 Cache.setProperty("LAST_DIRECTORY", choice);
5932 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
5933 new VCFLoader(choice).loadVCF(seqs, us);
5936 chooser.showOpenDialog(null);
5940 private Rectangle lastFeatureSettingsBounds = null;
5943 public void setFeatureSettingsGeometry(Rectangle bounds)
5945 lastFeatureSettingsBounds = bounds;
5949 public Rectangle getFeatureSettingsGeometry()
5951 return lastFeatureSettingsBounds;
5955 * Caching hashmaps for jalview.rest.API
5957 private static Map<String, AlignFrame> alignFrameMap = null;
5959 public static AlignFrame getAlignFrameFromRestId(String id)
5961 if (id == null || alignFrameMap == null)
5963 return alignFrameMap.get(id);
5966 public void cacheAlignFrameFromRestId(String id)
5970 if (alignFrameMap == null)
5971 alignFrameMap = new HashMap<>();
5972 alignFrameMap.put(id, this);
5976 class PrintThread extends Thread
5980 public PrintThread(AlignmentPanel ap)
5985 static PageFormat pf;
5990 PrinterJob printJob = PrinterJob.getPrinterJob();
5994 printJob.setPrintable(ap, pf);
5998 printJob.setPrintable(ap);
6001 if (printJob.printDialog())
6006 } catch (Exception PrintException)
6008 PrintException.printStackTrace();