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 jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.GeneticCodeI;
28 import jalview.analysis.ParseProperties;
29 import jalview.analysis.SequenceIdMatcher;
30 import jalview.api.AlignExportSettingsI;
31 import jalview.api.AlignFrameI;
32 import jalview.api.AlignViewControllerGuiI;
33 import jalview.api.AlignViewControllerI;
34 import jalview.api.AlignViewportI;
35 import jalview.api.AlignmentViewPanel;
36 import jalview.api.FeatureSettingsControllerI;
37 import jalview.api.FeatureSettingsModelI;
38 import jalview.api.SplitContainerI;
39 import jalview.api.ViewStyleI;
40 import jalview.api.analysis.SimilarityParamsI;
41 import jalview.bin.Cache;
42 import jalview.bin.Jalview;
43 import jalview.commands.CommandI;
44 import jalview.commands.EditCommand;
45 import jalview.commands.EditCommand.Action;
46 import jalview.commands.OrderCommand;
47 import jalview.commands.RemoveGapColCommand;
48 import jalview.commands.RemoveGapsCommand;
49 import jalview.commands.SlideSequencesCommand;
50 import jalview.commands.TrimRegionCommand;
51 import jalview.datamodel.AlignExportSettingsAdapter;
52 import jalview.datamodel.AlignedCodonFrame;
53 import jalview.datamodel.Alignment;
54 import jalview.datamodel.AlignmentAnnotation;
55 import jalview.datamodel.AlignmentExportData;
56 import jalview.datamodel.AlignmentI;
57 import jalview.datamodel.AlignmentOrder;
58 import jalview.datamodel.AlignmentView;
59 import jalview.datamodel.ColumnSelection;
60 import jalview.datamodel.HiddenColumns;
61 import jalview.datamodel.PDBEntry;
62 import jalview.datamodel.SeqCigar;
63 import jalview.datamodel.Sequence;
64 import jalview.datamodel.SequenceGroup;
65 import jalview.datamodel.SequenceI;
66 import jalview.gui.ColourMenuHelper.ColourChangeListener;
67 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
68 import jalview.io.AlignmentProperties;
69 import jalview.io.AnnotationFile;
70 import jalview.io.BackupFiles;
71 import jalview.io.BioJsHTMLOutput;
72 import jalview.io.DataSourceType;
73 import jalview.io.FileFormat;
74 import jalview.io.FileFormatI;
75 import jalview.io.FileFormats;
76 import jalview.io.FileLoader;
77 import jalview.io.FileParse;
78 import jalview.io.FormatAdapter;
79 import jalview.io.HtmlSvgOutput;
80 import jalview.io.IdentifyFile;
81 import jalview.io.JPredFile;
82 import jalview.io.JalviewFileChooser;
83 import jalview.io.JalviewFileView;
84 import jalview.io.JnetAnnotationMaker;
85 import jalview.io.NewickFile;
86 import jalview.io.ScoreMatrixFile;
87 import jalview.io.TCoffeeScoreFile;
88 import jalview.io.vcf.VCFLoader;
89 import jalview.jbgui.GAlignFrame;
90 import jalview.project.Jalview2XML;
91 import jalview.schemes.ColourSchemeI;
92 import jalview.schemes.ColourSchemes;
93 import jalview.schemes.ResidueColourScheme;
94 import jalview.schemes.TCoffeeColourScheme;
95 import jalview.util.ImageMaker.TYPE;
96 import jalview.util.MessageManager;
97 import jalview.util.Platform;
98 import jalview.viewmodel.AlignmentViewport;
99 import jalview.viewmodel.ViewportRanges;
100 import jalview.ws.DBRefFetcher;
101 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
102 import jalview.ws.jws1.Discoverer;
103 import jalview.ws.jws2.Jws2Discoverer;
104 import jalview.ws.jws2.jabaws2.Jws2Instance;
105 import jalview.ws.seqfetcher.DbSourceProxy;
107 import java.awt.BorderLayout;
108 import java.awt.Color;
109 import java.awt.Component;
110 import java.awt.Dimension;
111 import java.awt.Rectangle;
112 import java.awt.Toolkit;
113 import java.awt.datatransfer.Clipboard;
114 import java.awt.datatransfer.DataFlavor;
115 import java.awt.datatransfer.StringSelection;
116 import java.awt.datatransfer.Transferable;
117 import java.awt.dnd.DnDConstants;
118 import java.awt.dnd.DropTargetDragEvent;
119 import java.awt.dnd.DropTargetDropEvent;
120 import java.awt.dnd.DropTargetEvent;
121 import java.awt.dnd.DropTargetListener;
122 import java.awt.event.ActionEvent;
123 import java.awt.event.ActionListener;
124 import java.awt.event.FocusAdapter;
125 import java.awt.event.FocusEvent;
126 import java.awt.event.ItemEvent;
127 import java.awt.event.ItemListener;
128 import java.awt.event.KeyAdapter;
129 import java.awt.event.KeyEvent;
130 import java.awt.event.MouseEvent;
131 import java.awt.print.PageFormat;
132 import java.awt.print.PrinterJob;
133 import java.beans.PropertyChangeEvent;
134 import java.beans.PropertyChangeListener;
136 import java.io.FileWriter;
137 import java.io.PrintWriter;
139 import java.util.ArrayList;
140 import java.util.Arrays;
141 import java.util.Deque;
142 import java.util.Enumeration;
143 import java.util.Hashtable;
144 import java.util.List;
145 import java.util.Vector;
147 import javax.swing.ButtonGroup;
148 import javax.swing.JCheckBoxMenuItem;
149 import javax.swing.JComponent;
150 import javax.swing.JEditorPane;
151 import javax.swing.JInternalFrame;
152 import javax.swing.JLabel;
153 import javax.swing.JLayeredPane;
154 import javax.swing.JMenu;
155 import javax.swing.JMenuItem;
156 import javax.swing.JPanel;
157 import javax.swing.JScrollPane;
158 import javax.swing.SwingUtilities;
160 import ext.vamsas.ServiceHandle;
166 * @version $Revision$
168 @SuppressWarnings("serial")
169 public class AlignFrame extends GAlignFrame
170 implements AlignFrameI, DropTargetListener,
171 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
174 public static final int DEFAULT_WIDTH = 700;
176 public static final int DEFAULT_HEIGHT = 500;
179 * The currently displayed panel (selected tabbed view if more than one)
181 public AlignmentPanel alignPanel;
183 AlignViewport viewport;
185 public AlignViewControllerI avc;
187 List<AlignmentPanel> alignPanels = new ArrayList<>();
190 * Last format used to load or save alignments in this window
192 FileFormatI currentFileFormat = null;
195 * Current filename for this alignment
197 private String fileName = null;
199 private File fileObject;
202 * Creates a new AlignFrame object with specific width and height.
208 public AlignFrame(AlignmentI al, int width, int height)
210 this(al, null, width, height);
214 * Creates a new AlignFrame object with specific width, height and
220 * @param sequenceSetId
222 public AlignFrame(AlignmentI al, int width, int height,
223 String sequenceSetId)
225 this(al, null, width, height, sequenceSetId);
229 * Creates a new AlignFrame object with specific width, height and
235 * @param sequenceSetId
238 public AlignFrame(AlignmentI al, int width, int height,
239 String sequenceSetId, String viewId)
241 this(al, null, width, height, sequenceSetId, viewId);
245 * new alignment window with hidden columns
249 * @param hiddenColumns
250 * ColumnSelection or null
252 * Width of alignment frame
256 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
259 this(al, hiddenColumns, width, height, null);
263 * Create alignment frame for al with hiddenColumns, a specific width and
264 * height, and specific sequenceId
267 * @param hiddenColumns
270 * @param sequenceSetId
273 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
274 int height, String sequenceSetId)
276 this(al, hiddenColumns, width, height, sequenceSetId, null);
280 * Create alignment frame for al with hiddenColumns, a specific width and
281 * height, and specific sequenceId
284 * @param hiddenColumns
287 * @param sequenceSetId
292 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
293 int height, String sequenceSetId, String viewId)
295 setSize(width, height);
297 if (al.getDataset() == null)
302 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
303 // BH! new alignPanel must come later
304 // alignPanel = new AlignmentPanel(this, viewport);
305 // addAlignmentPanel(alignPanel, true);
310 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
311 HiddenColumns hiddenColumns, int width, int height)
313 setSize(width, height);
315 if (al.getDataset() == null)
320 viewport = new AlignViewport(al, hiddenColumns);
322 if (hiddenSeqs != null && hiddenSeqs.length > 0)
324 viewport.hideSequence(hiddenSeqs);
326 // BH! new alignPanel must come later
327 //alignPanel = new AlignmentPanel(this, viewport);
328 //addAlignmentPanel(alignPanel, true);
333 * Make a new AlignFrame from existing alignmentPanels
340 public AlignFrame(AlignmentPanel ap)
344 // BH! adding must come later
345 // addAlignmentPanel(ap, false);
350 * initalise the alignframe from the underlying viewport data and the
355 // BH! Here is where we create the panel; note the sequence
356 boolean newPanel = (alignPanel == null);
357 viewport.setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
362 // need to set this up front if NOANNOTATION is
363 // used in conjunction with SHOWOVERVIEW.
365 // I have not determined if this is appropriate for
366 // Jalview/Java, as it means we are setting this flag
367 // for all subsequent AlignFrames. For now, at least,
368 // I am setting it to be JalviewJS-only.
370 boolean showAnnotation = Jalview.getInstance().getShowAnnotation();
371 viewport.setShowAnnotation(showAnnotation);
373 alignPanel = new AlignmentPanel(this, viewport);
375 addAlignmentPanel(alignPanel, newPanel);
377 // setBackground(Color.white); // BH 2019
379 // BH meaning "without display, one way or another"
380 if (!Jalview.isHeadlessMode())
382 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
383 statusPanel.setVisible(Jalview.getInstance().getShowStatus());
384 alignFrameMenuBar.setVisible(Jalview.getInstance().getAllowMenuBar());
387 avc = new jalview.controller.AlignViewController(this, viewport,
389 if (viewport.getAlignmentConservationAnnotation() == null)
391 // BLOSUM62Colour.setEnabled(false);
392 conservationMenuItem.setEnabled(false);
393 modifyConservation.setEnabled(false);
394 // PIDColour.setEnabled(false);
395 // abovePIDThreshold.setEnabled(false);
396 // modifyPID.setEnabled(false);
399 String sortby = Cache.getDefault(Preferences.SORT_ALIGNMENT,
402 if (sortby.equals("Id"))
404 sortIDMenuItem_actionPerformed(null);
406 else if (sortby.equals("Pairwise Identity"))
408 sortPairwiseMenuItem_actionPerformed(null);
412 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
414 setMenusFromViewport(viewport);
415 buildSortByAnnotationScoresMenu();
416 calculateTree.addActionListener(new ActionListener()
420 public void actionPerformed(ActionEvent e)
427 if (Desktop.getDesktopPane() != null)
429 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
430 if (!Platform.isJS())
432 addServiceListeners();
437 if (viewport.getWrapAlignment())
439 wrapMenuItem_actionPerformed(null);
442 if (jalview.bin.Cache.getDefault(Preferences.SHOW_OVERVIEW, false))
444 this.overviewMenuItem_actionPerformed(null);
449 final List<AlignmentPanel> selviews = new ArrayList<>();
450 final List<AlignmentPanel> origview = new ArrayList<>();
451 final String menuLabel = MessageManager
452 .getString("label.copy_format_from");
453 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
454 new ViewSetProvider()
458 public AlignmentPanel[] getAllAlignmentPanels()
461 origview.add(alignPanel);
462 // make an array of all alignment panels except for this one
463 List<AlignmentPanel> aps = new ArrayList<>(
464 Arrays.asList(Desktop.getAlignmentPanels(null)));
465 aps.remove(AlignFrame.this.alignPanel);
466 return aps.toArray(new AlignmentPanel[aps.size()]);
468 }, selviews, new ItemListener()
472 public void itemStateChanged(ItemEvent e)
474 if (origview.size() > 0)
476 final AlignmentPanel ap = origview.get(0);
479 * Copy the ViewStyle of the selected panel to 'this one'.
480 * Don't change value of 'scaleProteinAsCdna' unless copying
483 ViewStyleI vs = selviews.get(0).getAlignViewport()
485 boolean fromSplitFrame = selviews.get(0)
486 .getAlignViewport().getCodingComplement() != null;
489 vs.setScaleProteinAsCdna(ap.getAlignViewport()
490 .getViewStyle().isScaleProteinAsCdna());
492 ap.getAlignViewport().setViewStyle(vs);
495 * Also rescale ViewStyle of SplitFrame complement if there is
496 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
497 * the whole ViewStyle (allow cDNA protein to have different
500 AlignViewportI complement = ap.getAlignViewport()
501 .getCodingComplement();
502 if (complement != null && vs.isScaleProteinAsCdna())
504 AlignFrame af = Desktop.getAlignFrameFor(complement);
505 ((SplitFrame) af.getSplitViewContainer())
507 af.setMenusForViewport();
511 ap.setSelected(true);
512 ap.alignFrame.setMenusForViewport();
517 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
518 .indexOf("devel") > -1
519 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
520 .indexOf("test") > -1)
522 formatMenu.add(vsel);
524 addFocusListener(new FocusAdapter()
527 public void focusGained(FocusEvent e)
529 Jalview.setCurrentAlignFrame(AlignFrame.this);
536 * Change the filename and format for the alignment, and enable the 'reload'
537 * button functionality.
544 public void setFileName(String file, FileFormatI format)
547 setFileFormat(format);
548 reload.setEnabled(true);
552 * JavaScript will have this, maybe others. More dependable than a file name
553 * and maintains a reference to the actual bytes loaded.
557 public void setFileObject(File file)
559 this.fileObject = file;
563 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
566 void addKeyListener()
568 addKeyListener(new KeyAdapter()
571 public void keyPressed(KeyEvent evt)
573 if (viewport.cursorMode
574 && ((evt.getKeyCode() >= KeyEvent.VK_0
575 && evt.getKeyCode() <= KeyEvent.VK_9)
576 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
577 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
578 && Character.isDigit(evt.getKeyChar()))
580 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
583 switch (evt.getKeyCode())
586 case KeyEvent.VK_ESCAPE: // escape key
587 deselectAllSequenceMenuItem_actionPerformed(null);
591 case KeyEvent.VK_DOWN:
592 if (evt.isAltDown() || !viewport.cursorMode)
594 moveSelectedSequences(false);
596 if (viewport.cursorMode)
598 alignPanel.getSeqPanel().moveCursor(0, 1);
603 if (evt.isAltDown() || !viewport.cursorMode)
605 moveSelectedSequences(true);
607 if (viewport.cursorMode)
609 alignPanel.getSeqPanel().moveCursor(0, -1);
614 case KeyEvent.VK_LEFT:
615 if (evt.isAltDown() || !viewport.cursorMode)
617 slideSequences(false,
618 alignPanel.getSeqPanel().getKeyboardNo1());
622 alignPanel.getSeqPanel().moveCursor(-1, 0);
627 case KeyEvent.VK_RIGHT:
628 if (evt.isAltDown() || !viewport.cursorMode)
630 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
634 alignPanel.getSeqPanel().moveCursor(1, 0);
638 case KeyEvent.VK_SPACE:
639 if (viewport.cursorMode)
641 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
642 || evt.isShiftDown() || evt.isAltDown());
646 // case KeyEvent.VK_A:
647 // if (viewport.cursorMode)
649 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
650 // //System.out.println("A");
654 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
655 * System.out.println("closing bracket"); } break;
657 case KeyEvent.VK_DELETE:
658 case KeyEvent.VK_BACK_SPACE:
659 if (!viewport.cursorMode)
661 cut_actionPerformed();
665 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
666 || evt.isShiftDown() || evt.isAltDown());
672 if (viewport.cursorMode)
674 alignPanel.getSeqPanel().setCursorRow();
678 if (viewport.cursorMode && !evt.isControlDown())
680 alignPanel.getSeqPanel().setCursorColumn();
684 if (viewport.cursorMode)
686 alignPanel.getSeqPanel().setCursorPosition();
690 case KeyEvent.VK_ENTER:
691 case KeyEvent.VK_COMMA:
692 if (viewport.cursorMode)
694 alignPanel.getSeqPanel().setCursorRowAndColumn();
699 if (viewport.cursorMode)
701 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
705 if (viewport.cursorMode)
707 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
712 viewport.cursorMode = !viewport.cursorMode;
713 setStatus(MessageManager
714 .formatMessage("label.keyboard_editing_mode", new String[]
715 { (viewport.cursorMode ? "on" : "off") }));
716 if (viewport.cursorMode)
718 ViewportRanges ranges = viewport.getRanges();
719 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
721 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
724 alignPanel.getSeqPanel().seqCanvas.repaint();
730 Help.showHelpWindow();
731 } catch (Exception ex)
733 ex.printStackTrace();
738 boolean toggleSeqs = !evt.isControlDown();
739 boolean toggleCols = !evt.isShiftDown();
740 toggleHiddenRegions(toggleSeqs, toggleCols);
745 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
746 boolean modifyExisting = true; // always modify, don't clear
747 // evt.isShiftDown();
748 boolean invertHighlighted = evt.isAltDown();
749 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
753 case KeyEvent.VK_PAGE_UP:
754 viewport.getRanges().pageUp();
756 case KeyEvent.VK_PAGE_DOWN:
757 viewport.getRanges().pageDown();
763 public void keyReleased(KeyEvent evt)
765 switch (evt.getKeyCode())
767 case KeyEvent.VK_LEFT:
768 if (evt.isAltDown() || !viewport.cursorMode)
770 viewport.firePropertyChange("alignment", null,
771 viewport.getAlignment().getSequences());
775 case KeyEvent.VK_RIGHT:
776 if (evt.isAltDown() || !viewport.cursorMode)
778 viewport.firePropertyChange("alignment", null,
779 viewport.getAlignment().getSequences());
787 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
789 ap.alignFrame = this;
790 avc = new jalview.controller.AlignViewController(this, viewport,
795 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
797 int aSize = alignPanels.size();
799 tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
801 if (aSize == 1 && ap.av.getViewName() == null)
803 this.getContentPane().add(ap, BorderLayout.CENTER);
809 setInitialTabVisible();
812 expandViews.setEnabled(true);
813 gatherViews.setEnabled(true);
814 tabbedPane.addTab(ap.av.getViewName(), ap);
816 ap.setVisible(false);
821 if (ap.av.isPadGaps())
823 ap.av.getAlignment().padGaps();
825 // BH! important option for JalviewJS
826 if (Jalview.getInstance().getStartCalculations())
828 ap.av.updateConservation(ap);
829 ap.av.updateConsensus(ap);
830 ap.av.updateStrucConsensus(ap);
835 public void setInitialTabVisible()
837 expandViews.setEnabled(true);
838 gatherViews.setEnabled(true);
839 tabbedPane.setVisible(true);
840 AlignmentPanel first = alignPanels.get(0);
841 tabbedPane.addTab(first.av.getViewName(), first);
842 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
845 public AlignViewport getViewport()
850 /* Set up intrinsic listeners for dynamically generated GUI bits. */
851 private void addServiceListeners()
853 PropertyChangeListener thisListener;
854 Desktop.getInstance().addJalviewPropertyChangeListener("services",
855 thisListener = new PropertyChangeListener()
858 public void propertyChange(PropertyChangeEvent evt)
861 SwingUtilities.invokeLater(new Runnable()
868 "Rebuild WS Menu for service change");
869 BuildWebServiceMenu();
875 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
878 public void internalFrameClosed(
879 javax.swing.event.InternalFrameEvent evt)
881 // System.out.println("deregistering discoverer listener");
882 Desktop.getInstance().removeJalviewPropertyChangeListener("services",
884 closeMenuItem_actionPerformed(true);
887 // Finally, build the menu once to get current service state
888 new Thread(new Runnable()
893 BuildWebServiceMenu();
899 * Configure menu items that vary according to whether the alignment is
900 * nucleotide or protein
902 public void setGUINucleotide()
904 AlignmentI al = getViewport().getAlignment();
905 boolean nucleotide = al.isNucleotide();
907 loadVcf.setVisible(nucleotide);
908 showTranslation.setVisible(nucleotide);
909 showReverse.setVisible(nucleotide);
910 showReverseComplement.setVisible(nucleotide);
911 conservationMenuItem.setEnabled(!nucleotide);
913 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
914 showGroupConservation.setEnabled(!nucleotide);
916 showComplementMenuItem
917 .setText(nucleotide ? MessageManager.getString("label.protein")
918 : MessageManager.getString("label.nucleotide"));
922 * set up menus for the current viewport. This may be called after any
923 * operation that affects the data in the current view (selection changed,
924 * etc) to update the menus to reflect the new state.
927 public void setMenusForViewport()
929 setMenusFromViewport(viewport);
933 * Need to call this method when tabs are selected for multiple views, or when
934 * loading from Jalview2XML.java
939 public void setMenusFromViewport(AlignViewport av)
941 padGapsMenuitem.setSelected(av.isPadGaps());
942 colourTextMenuItem.setSelected(av.isShowColourText());
943 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
944 modifyPID.setEnabled(abovePIDThreshold.isSelected());
945 conservationMenuItem.setSelected(av.getConservationSelected());
946 modifyConservation.setEnabled(conservationMenuItem.isSelected());
947 seqLimits.setSelected(av.getShowJVSuffix());
948 idRightAlign.setSelected(av.isRightAlignIds());
949 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
950 renderGapsMenuItem.setSelected(av.isRenderGaps());
951 wrapMenuItem.setSelected(av.getWrapAlignment());
952 scaleAbove.setVisible(av.getWrapAlignment());
953 scaleLeft.setVisible(av.getWrapAlignment());
954 scaleRight.setVisible(av.getWrapAlignment());
955 annotationPanelMenuItem.setState(av.isShowAnnotation());
956 // Show/hide annotations only enabled if annotation panel is shown
958 syncAnnotationMenuItems();
960 viewBoxesMenuItem.setSelected(av.getShowBoxes());
961 viewTextMenuItem.setSelected(av.getShowText());
962 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
963 showGroupConsensus.setSelected(av.isShowGroupConsensus());
964 showGroupConservation.setSelected(av.isShowGroupConservation());
965 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
966 showSequenceLogo.setSelected(av.isShowSequenceLogo());
967 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
969 ColourMenuHelper.setColourSelected(colourMenu,
970 av.getGlobalColourScheme());
972 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
973 hiddenMarkers.setState(av.getShowHiddenMarkers());
974 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
975 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
976 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
977 autoCalculate.setSelected(av.getAutoCalculateConsensusAndConservation());
978 sortByTree.setSelected(av.sortByTree);
979 listenToViewSelections.setSelected(av.followSelection);
981 showProducts.setEnabled(canShowProducts());
982 setGroovyEnabled(Desktop.getGroovyConsole() != null);
988 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
992 public void setGroovyEnabled(boolean b)
994 runGroovy.setEnabled(b);
997 private IProgressIndicator progressBar;
1002 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1005 public void setProgressBar(String message, long id)
1007 progressBar.setProgressBar(message, id);
1011 public void registerHandler(final long id,
1012 final IProgressIndicatorHandler handler)
1014 progressBar.registerHandler(id, handler);
1019 * @return true if any progress bars are still active
1022 public boolean operationInProgress()
1024 return progressBar.operationInProgress();
1028 * Sets the text of the status bar. Note that setting a null or empty value
1029 * will cause the status bar to be hidden, with possibly undesirable flicker
1030 * of the screen layout.
1033 public void setStatus(String text)
1035 statusBar.setText(text == null || text.isEmpty() ? " " : text);
1039 * Added so Castor Mapping file can obtain Jalview Version
1041 public String getVersion()
1043 return jalview.bin.Cache.getProperty("VERSION");
1046 public FeatureRenderer getFeatureRenderer()
1048 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1052 public void fetchSequence_actionPerformed()
1054 new SequenceFetcher(this);
1058 public void addFromFile_actionPerformed(ActionEvent e)
1060 Desktop.getInstance().inputLocalFileMenuItem_actionPerformed(viewport);
1064 public void reload_actionPerformed(ActionEvent e)
1066 if (fileName == null)
1070 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1071 // originating file's format
1072 // TODO: work out how to recover feature settings for correct view(s) when
1073 // file is reloaded.
1074 if (FileFormat.Jalview.equals(currentFileFormat))
1076 JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
1077 for (int i = 0; i < frames.length; i++)
1079 if (frames[i] instanceof AlignFrame && frames[i] != this
1080 && ((AlignFrame) frames[i]).fileName != null
1081 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1085 frames[i].setSelected(true);
1086 Desktop.getInstance().closeAssociatedWindows();
1087 } catch (java.beans.PropertyVetoException ex)
1093 Desktop.getInstance().closeAssociatedWindows();
1095 FileLoader loader = new FileLoader();
1096 DataSourceType protocol = fileName.startsWith("http:")
1097 ? DataSourceType.URL
1098 : DataSourceType.FILE;
1099 if (fileObject == null)
1101 loader.LoadFile(fileName, protocol, currentFileFormat);
1105 loader.loadFile(null, fileObject, protocol, currentFileFormat);
1110 Rectangle bounds = this.getBounds();
1112 FileLoader loader = new FileLoader();
1114 AlignFrame newframe = null;
1116 if (fileObject == null)
1118 // BH! Q: What about https?
1119 DataSourceType protocol = (fileName.startsWith("http:")
1120 ? DataSourceType.URL
1121 : DataSourceType.FILE);
1122 newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
1127 newframe = loader.loadFileWaitTillLoaded(fileObject,
1128 DataSourceType.FILE, currentFileFormat);
1131 newframe.setBounds(bounds);
1132 if (featureSettings != null && featureSettings.isShowing())
1134 final Rectangle fspos = featureSettings.frame.getBounds();
1135 // TODO: need a 'show feature settings' function that takes bounds -
1136 // need to refactor Desktop.addFrame
1137 newframe.featureSettings_actionPerformed(null);
1138 final FeatureSettings nfs = newframe.featureSettings;
1139 Jalview.execRunnable(new Runnable()
1144 nfs.frame.setBounds(fspos);
1147 this.featureSettings.close();
1148 this.featureSettings = null;
1150 this.closeMenuItem_actionPerformed(true);
1155 public void addFromText_actionPerformed(ActionEvent e)
1157 Desktop.getInstance()
1158 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1162 public void addFromURL_actionPerformed(ActionEvent e)
1164 Desktop.getInstance().inputURLMenuItem_actionPerformed(viewport);
1168 public void save_actionPerformed(ActionEvent e)
1170 if (fileName == null || (currentFileFormat == null)
1171 || fileName.startsWith("http"))
1173 saveAs_actionPerformed();
1177 saveAlignment(fileName, currentFileFormat);
1182 * Saves the alignment to a file with a name chosen by the user, if necessary
1183 * warning if a file would be overwritten
1186 public void saveAs_actionPerformed()
1188 String format = currentFileFormat == null ? null
1189 : currentFileFormat.getName();
1190 JalviewFileChooser chooser = JalviewFileChooser
1191 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1193 chooser.setFileView(new JalviewFileView());
1194 chooser.setDialogTitle(
1195 MessageManager.getString("label.save_alignment_to_file"));
1196 chooser.setToolTipText(MessageManager.getString("action.save"));
1198 int value = chooser.showSaveDialog(this);
1200 if (value != JalviewFileChooser.APPROVE_OPTION)
1204 currentFileFormat = chooser.getSelectedFormat();
1205 // todo is this (2005) test now obsolete - value is never null?
1206 while (currentFileFormat == null)
1208 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1210 .getString("label.select_file_format_before_saving"),
1211 MessageManager.getString("label.file_format_not_specified"),
1212 JvOptionPane.WARNING_MESSAGE);
1213 currentFileFormat = chooser.getSelectedFormat();
1214 value = chooser.showSaveDialog(this);
1215 if (value != JalviewFileChooser.APPROVE_OPTION)
1221 fileName = chooser.getSelectedFile().getPath();
1223 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1224 Cache.setProperty("LAST_DIRECTORY", fileName);
1225 saveAlignment(fileName, currentFileFormat);
1228 boolean lastSaveSuccessful = false;
1230 FileFormatI lastFormatSaved;
1232 String lastFilenameSaved;
1235 * Raise a dialog or status message for the last call to saveAlignment.
1237 * @return true if last call to saveAlignment(file, format) was successful.
1239 public boolean isSaveAlignmentSuccessful()
1242 if (!lastSaveSuccessful)
1244 JvOptionPane.showInternalMessageDialog(this, MessageManager
1245 .formatMessage("label.couldnt_save_file", new Object[]
1246 { lastFilenameSaved }),
1247 MessageManager.getString("label.error_saving_file"),
1248 JvOptionPane.WARNING_MESSAGE);
1253 setStatus(MessageManager.formatMessage(
1254 "label.successfully_saved_to_file_in_format", new Object[]
1255 { lastFilenameSaved, lastFormatSaved }));
1258 return lastSaveSuccessful;
1262 * Saves the alignment to the specified file path, in the specified format,
1263 * which may be an alignment format, or Jalview project format. If the
1264 * alignment has hidden regions, or the format is one capable of including
1265 * non-sequence data (features, annotations, groups), then the user may be
1266 * prompted to specify what to include in the output.
1271 public void saveAlignment(String file, FileFormatI format)
1273 lastSaveSuccessful = true;
1274 lastFilenameSaved = file;
1275 lastFormatSaved = format;
1277 if (FileFormat.Jalview.equals(format))
1279 String shortName = title;
1280 if (shortName.indexOf(File.separatorChar) > -1)
1282 shortName = shortName.substring(
1283 shortName.lastIndexOf(File.separatorChar) + 1);
1285 lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file, shortName);
1287 statusBar.setText(MessageManager.formatMessage(
1288 "label.successfully_saved_to_file_in_format", new Object[]
1289 { fileName, format }));
1294 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1295 Runnable cancelAction = new Runnable()
1300 lastSaveSuccessful = false;
1303 Runnable outputAction = new Runnable()
1308 // todo defer this to inside formatSequences (or later)
1309 AlignmentExportData exportData = viewport
1310 .getAlignExportData(options);
1311 String output = new FormatAdapter(alignPanel, options)
1312 .formatSequences(format, exportData.getAlignment(),
1313 exportData.getOmitHidden(),
1314 exportData.getStartEndPostions(),
1315 viewport.getAlignment().getHiddenColumns());
1318 lastSaveSuccessful = false;
1322 // create backupfiles object and get new temp filename destination
1323 boolean doBackup = BackupFiles.getEnabled();
1324 BackupFiles backupfiles = doBackup ? new BackupFiles(file) : null;
1327 String tempFilePath = doBackup ? backupfiles.getTempFilePath() : file;
1328 PrintWriter out = new PrintWriter(
1329 new FileWriter(tempFilePath));
1333 AlignFrame.this.setTitle(file);
1334 statusBar.setText(MessageManager.formatMessage(
1335 "label.successfully_saved_to_file_in_format", new Object[]
1336 { fileName, format.getName() }));
1337 lastSaveSuccessful = true;
1338 } catch (Exception ex)
1340 lastSaveSuccessful = false;
1341 ex.printStackTrace();
1346 backupfiles.setWriteSuccess(lastSaveSuccessful);
1347 // do the backup file roll and rename the temp file to actual file
1348 lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
1355 * show dialog with export options if applicable; else just do it
1357 if (AlignExportOptions.isNeeded(viewport, format))
1359 AlignExportOptions choices = new AlignExportOptions(
1360 alignPanel.getAlignViewport(), format, options);
1361 choices.setResponseAction(0, outputAction);
1362 choices.setResponseAction(1, cancelAction);
1363 choices.showDialog();
1372 * Outputs the alignment to textbox in the requested format, if necessary
1373 * first prompting the user for whether to include hidden regions or
1376 * @param fileFormatName
1379 protected void outputText_actionPerformed(String fileFormatName)
1381 FileFormatI fileFormat = FileFormats.getInstance()
1382 .forName(fileFormatName);
1383 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1384 Runnable outputAction = new Runnable()
1389 // todo defer this to inside formatSequences (or later)
1390 AlignmentExportData exportData = viewport
1391 .getAlignExportData(options);
1392 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1393 cap.setForInput(null);
1396 FileFormatI format = fileFormat;
1397 cap.setText(new FormatAdapter(alignPanel, options)
1398 .formatSequences(format, exportData.getAlignment(),
1399 exportData.getOmitHidden(),
1400 exportData.getStartEndPostions(),
1401 viewport.getAlignment().getHiddenColumns()));
1402 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1403 "label.alignment_output_command", new Object[]
1404 { fileFormat.getName() }), 600, 500);
1405 } catch (OutOfMemoryError oom)
1407 new OOMWarning("Outputting alignment as " + fileFormat.getName(),
1415 * show dialog with export options if applicable; else just do it
1417 if (AlignExportOptions.isNeeded(viewport, fileFormat))
1419 AlignExportOptions choices = new AlignExportOptions(
1420 alignPanel.getAlignViewport(), fileFormat, options);
1421 choices.setResponseAction(0, outputAction);
1422 choices.showDialog();
1437 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1439 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1440 htmlSVG.exportHTML(null);
1444 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1446 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1447 bjs.exportHTML(null);
1450 public void createImageMap(File file, String image)
1452 alignPanel.makePNGImageMap(file, image);
1456 * Creates a PNG image of the alignment and writes it to the given file. If
1457 * the file is null, the user is prompted to choose a file.
1462 public void createPNG(File f)
1464 alignPanel.makeAlignmentImage(TYPE.PNG, f);
1468 * Creates an EPS 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 createEPS(File f)
1476 alignPanel.makeAlignmentImage(TYPE.EPS, f);
1480 * Creates an SVG 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 createSVG(File f)
1488 alignPanel.makeAlignmentImage(TYPE.SVG, f);
1492 public void pageSetup_actionPerformed(ActionEvent e)
1494 PrinterJob printJob = PrinterJob.getPrinterJob();
1495 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1505 public void printMenuItem_actionPerformed(ActionEvent e)
1507 // Putting in a thread avoids Swing painting problems
1508 PrintThread thread = new PrintThread(alignPanel);
1513 public void exportFeatures_actionPerformed(ActionEvent e)
1515 new AnnotationExporter(alignPanel).exportFeatures();
1519 public void exportAnnotations_actionPerformed(ActionEvent e)
1521 new AnnotationExporter(alignPanel).exportAnnotations();
1525 public void associatedData_actionPerformed(ActionEvent e)
1527 final JalviewFileChooser chooser = new JalviewFileChooser(
1528 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1529 chooser.setFileView(new JalviewFileView());
1530 chooser.setDialogTitle(
1531 MessageManager.getString("label.load_jalview_annotations"));
1532 chooser.setToolTipText(
1533 MessageManager.getString("label.load_jalview_annotations"));
1534 chooser.setResponseHandler(0, new Runnable()
1539 String choice = chooser.getSelectedFile().getPath();
1540 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1541 loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
1545 chooser.showOpenDialog(this);
1549 * Close the current view or all views in the alignment frame. If the frame
1550 * only contains one view then the alignment will be removed from memory.
1552 * @param closeAllTabs
1555 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1557 if (alignPanels != null && alignPanels.size() < 2)
1559 closeAllTabs = true;
1564 if (alignPanels != null)
1568 if (this.isClosed())
1570 // really close all the windows - otherwise wait till
1571 // setClosed(true) is called
1572 for (int i = 0; i < alignPanels.size(); i++)
1574 AlignmentPanel ap = alignPanels.get(i);
1581 closeView(alignPanel);
1587 if (featureSettings != null && featureSettings.isOpen())
1589 featureSettings.close();
1590 featureSettings = null;
1593 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1594 * be called recursively, with the frame now in 'closed' state
1596 this.setClosed(true);
1598 } catch (Exception ex)
1600 ex.printStackTrace();
1605 * Close the specified panel and close up tabs appropriately.
1607 * @param panelToClose
1609 public void closeView(AlignmentPanel panelToClose)
1611 int index = tabbedPane.getSelectedIndex();
1612 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1613 alignPanels.remove(panelToClose);
1614 panelToClose.closePanel();
1615 panelToClose = null;
1617 tabbedPane.removeTabAt(closedindex);
1618 tabbedPane.validate();
1620 if (index > closedindex || index == tabbedPane.getTabCount())
1622 // modify currently selected tab index if necessary.
1626 this.tabSelectionChanged(index);
1632 void updateEditMenuBar()
1635 if (viewport.getHistoryList().size() > 0)
1637 undoMenuItem.setEnabled(true);
1638 CommandI command = viewport.getHistoryList().peek();
1639 undoMenuItem.setText(MessageManager
1640 .formatMessage("label.undo_command", new Object[]
1641 { command.getDescription() }));
1645 undoMenuItem.setEnabled(false);
1646 undoMenuItem.setText(MessageManager.getString("action.undo"));
1649 if (viewport.getRedoList().size() > 0)
1651 redoMenuItem.setEnabled(true);
1653 CommandI command = viewport.getRedoList().peek();
1654 redoMenuItem.setText(MessageManager
1655 .formatMessage("label.redo_command", new Object[]
1656 { command.getDescription() }));
1660 redoMenuItem.setEnabled(false);
1661 redoMenuItem.setText(MessageManager.getString("action.redo"));
1666 public void addHistoryItem(CommandI command)
1668 if (command.getSize() > 0)
1670 viewport.addToHistoryList(command);
1671 viewport.clearRedoList();
1672 updateEditMenuBar();
1673 viewport.updateHiddenColumns();
1674 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1675 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1676 // viewport.getColumnSelection()
1677 // .getHiddenColumns().size() > 0);
1683 * @return alignment objects for all views
1685 AlignmentI[] getViewAlignments()
1687 if (alignPanels != null)
1689 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1691 for (AlignmentPanel ap : alignPanels)
1693 als[i++] = ap.av.getAlignment();
1697 if (viewport != null)
1699 return new AlignmentI[] { viewport.getAlignment() };
1711 protected void undoMenuItem_actionPerformed(ActionEvent e)
1713 if (viewport.getHistoryList().isEmpty())
1717 CommandI command = viewport.getHistoryList().pop();
1718 viewport.addToRedoList(command);
1719 command.undoCommand(getViewAlignments());
1721 AlignmentViewport originalSource = getOriginatingSource(command);
1722 updateEditMenuBar();
1724 if (originalSource != null)
1726 if (originalSource != viewport)
1729 "Implementation worry: mismatch of viewport origin for undo");
1731 originalSource.updateHiddenColumns();
1732 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1734 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1735 // viewport.getColumnSelection()
1736 // .getHiddenColumns().size() > 0);
1737 originalSource.firePropertyChange("alignment", null,
1738 originalSource.getAlignment().getSequences());
1749 protected void redoMenuItem_actionPerformed(ActionEvent e)
1751 if (viewport.getRedoList().size() < 1)
1756 CommandI command = viewport.getRedoList().pop();
1757 viewport.addToHistoryList(command);
1758 command.doCommand(getViewAlignments());
1760 AlignmentViewport originalSource = getOriginatingSource(command);
1761 updateEditMenuBar();
1763 if (originalSource != null)
1766 if (originalSource != viewport)
1769 "Implementation worry: mismatch of viewport origin for redo");
1771 originalSource.updateHiddenColumns();
1772 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1774 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1775 // viewport.getColumnSelection()
1776 // .getHiddenColumns().size() > 0);
1777 originalSource.firePropertyChange("alignment", null,
1778 originalSource.getAlignment().getSequences());
1782 AlignmentViewport getOriginatingSource(CommandI command)
1784 AlignmentViewport originalSource = null;
1785 // For sequence removal and addition, we need to fire
1786 // the property change event FROM the viewport where the
1787 // original alignment was altered
1788 AlignmentI al = null;
1789 if (command instanceof EditCommand)
1791 EditCommand editCommand = (EditCommand) command;
1792 al = editCommand.getAlignment();
1793 List<Component> comps = PaintRefresher.components
1794 .get(viewport.getSequenceSetId());
1796 for (Component comp : comps)
1798 if (comp instanceof AlignmentPanel)
1800 if (al == ((AlignmentPanel) comp).av.getAlignment())
1802 originalSource = ((AlignmentPanel) comp).av;
1809 if (originalSource == null)
1811 // The original view is closed, we must validate
1812 // the current view against the closed view first
1815 PaintRefresher.validateSequences(al, viewport.getAlignment());
1818 originalSource = viewport;
1821 return originalSource;
1830 public void moveSelectedSequences(boolean up)
1832 SequenceGroup sg = viewport.getSelectionGroup();
1838 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1839 viewport.getHiddenRepSequences(), up);
1840 alignPanel.paintAlignment(true, false);
1843 synchronized void slideSequences(boolean right, int size)
1845 List<SequenceI> sg = new ArrayList<>();
1846 if (viewport.cursorMode)
1848 sg.add(viewport.getAlignment()
1849 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
1851 else if (viewport.getSelectionGroup() != null
1852 && viewport.getSelectionGroup().getSize() != viewport
1853 .getAlignment().getHeight())
1855 sg = viewport.getSelectionGroup()
1856 .getSequences(viewport.getHiddenRepSequences());
1864 List<SequenceI> invertGroup = new ArrayList<>();
1866 for (SequenceI seq : viewport.getAlignment().getSequences())
1868 if (!sg.contains(seq))
1870 invertGroup.add(seq);
1874 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1876 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1877 for (int i = 0; i < invertGroup.size(); i++)
1879 seqs2[i] = invertGroup.get(i);
1882 SlideSequencesCommand ssc;
1885 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1886 viewport.getGapCharacter());
1890 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1891 viewport.getGapCharacter());
1894 int groupAdjustment = 0;
1895 if (ssc.getGapsInsertedBegin() && right)
1897 if (viewport.cursorMode)
1899 alignPanel.getSeqPanel().moveCursor(size, 0);
1903 groupAdjustment = size;
1906 else if (!ssc.getGapsInsertedBegin() && !right)
1908 if (viewport.cursorMode)
1910 alignPanel.getSeqPanel().moveCursor(-size, 0);
1914 groupAdjustment = -size;
1918 if (groupAdjustment != 0)
1920 viewport.getSelectionGroup().setStartRes(
1921 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1922 viewport.getSelectionGroup().setEndRes(
1923 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1927 * just extend the last slide command if compatible; but not if in
1928 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1930 boolean appendHistoryItem = false;
1931 Deque<CommandI> historyList = viewport.getHistoryList();
1932 boolean inSplitFrame = getSplitViewContainer() != null;
1933 if (!inSplitFrame && historyList != null && historyList.size() > 0
1934 && historyList.peek() instanceof SlideSequencesCommand)
1936 appendHistoryItem = ssc.appendSlideCommand(
1937 (SlideSequencesCommand) historyList.peek());
1940 if (!appendHistoryItem)
1942 addHistoryItem(ssc);
1955 protected void copy_actionPerformed()
1957 if (viewport.getSelectionGroup() == null)
1961 // TODO: preserve the ordering of displayed alignment annotation in any
1962 // internal paste (particularly sequence associated annotation)
1963 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1964 String[] omitHidden = null;
1966 if (viewport.hasHiddenColumns())
1968 omitHidden = viewport.getViewAsString(true);
1971 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1972 seqs, omitHidden, null);
1974 StringSelection ss = new StringSelection(output);
1976 Desktop d = Desktop.getInstance();
1979 d.internalCopy = true;
1980 // Its really worth setting the clipboard contents
1981 // to empty before setting the large StringSelection!!
1982 Toolkit.getDefaultToolkit().getSystemClipboard()
1983 .setContents(new StringSelection(""), null);
1985 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
1986 Desktop.getInstance());
1987 } catch (OutOfMemoryError er)
1989 new OOMWarning("copying region", er);
1993 HiddenColumns hiddenColumns = null;
1994 if (viewport.hasHiddenColumns())
1996 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1997 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
1999 // create new HiddenColumns object with copy of hidden regions
2000 // between startRes and endRes, offset by startRes
2001 hiddenColumns = new HiddenColumns(
2002 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
2003 hiddenCutoff, hiddenOffset);
2006 d.jalviewClipboard = new Object[] { seqs,
2007 viewport.getAlignment().getDataset(), hiddenColumns };
2008 setStatus(MessageManager.formatMessage(
2009 "label.copied_sequences_to_clipboard", new Object[]
2010 { Integer.valueOf(seqs.length).toString() }));
2020 protected void pasteNew_actionPerformed(ActionEvent e)
2032 protected void pasteThis_actionPerformed(ActionEvent e)
2038 * Paste contents of Jalview clipboard
2040 * @param newAlignment
2041 * true to paste to a new alignment, otherwise add to this.
2043 void paste(boolean newAlignment)
2045 boolean externalPaste = true;
2048 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2049 Transferable contents = c.getContents(this);
2051 if (contents == null)
2060 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2061 if (str.length() < 1)
2066 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2068 } catch (OutOfMemoryError er)
2070 new OOMWarning("Out of memory pasting sequences!!", er);
2074 SequenceI[] sequences;
2075 boolean annotationAdded = false;
2076 AlignmentI alignment = null;
2078 Desktop d = Desktop.getInstance();
2080 if (d.jalviewClipboard != null)
2082 // The clipboard was filled from within Jalview, we must use the
2084 // And dataset from the copied alignment
2085 SequenceI[] newseq = (SequenceI[]) d.jalviewClipboard[0];
2086 // be doubly sure that we create *new* sequence objects.
2087 sequences = new SequenceI[newseq.length];
2088 for (int i = 0; i < newseq.length; i++)
2090 sequences[i] = new Sequence(newseq[i]);
2092 alignment = new Alignment(sequences);
2093 externalPaste = false;
2097 // parse the clipboard as an alignment.
2098 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2100 sequences = alignment.getSequencesArray();
2104 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2110 if (d.jalviewClipboard != null)
2112 // dataset is inherited
2113 alignment.setDataset((Alignment) d.jalviewClipboard[1]);
2117 // new dataset is constructed
2118 alignment.setDataset(null);
2120 alwidth = alignment.getWidth() + 1;
2124 AlignmentI pastedal = alignment; // preserve pasted alignment object
2125 // Add pasted sequences and dataset into existing alignment.
2126 alignment = viewport.getAlignment();
2127 alwidth = alignment.getWidth() + 1;
2128 // decide if we need to import sequences from an existing dataset
2129 boolean importDs = d.jalviewClipboard != null
2130 && d.jalviewClipboard[1] != alignment.getDataset();
2131 // importDs==true instructs us to copy over new dataset sequences from
2132 // an existing alignment
2133 Vector<SequenceI> newDs = (importDs) ? new Vector<>() : null; // used to
2135 // minimum dataset set
2137 for (int i = 0; i < sequences.length; i++)
2141 newDs.addElement(null);
2143 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2145 if (importDs && ds != null)
2147 if (!newDs.contains(ds))
2149 newDs.setElementAt(ds, i);
2150 ds = new Sequence(ds);
2151 // update with new dataset sequence
2152 sequences[i].setDatasetSequence(ds);
2156 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2161 // copy and derive new dataset sequence
2162 sequences[i] = sequences[i].deriveSequence();
2163 alignment.getDataset()
2164 .addSequence(sequences[i].getDatasetSequence());
2165 // TODO: avoid creation of duplicate dataset sequences with a
2166 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2168 alignment.addSequence(sequences[i]); // merges dataset
2172 newDs.clear(); // tidy up
2174 if (alignment.getAlignmentAnnotation() != null)
2176 for (AlignmentAnnotation alan : alignment
2177 .getAlignmentAnnotation())
2179 if (alan.graphGroup > fgroup)
2181 fgroup = alan.graphGroup;
2185 if (pastedal.getAlignmentAnnotation() != null)
2187 // Add any annotation attached to alignment.
2188 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2189 for (int i = 0; i < alann.length; i++)
2191 annotationAdded = true;
2192 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2194 AlignmentAnnotation newann = new AlignmentAnnotation(
2196 if (newann.graphGroup > -1)
2198 if (newGraphGroups.size() <= newann.graphGroup
2199 || newGraphGroups.get(newann.graphGroup) == null)
2201 for (int q = newGraphGroups
2202 .size(); q <= newann.graphGroup; q++)
2204 newGraphGroups.add(q, null);
2206 newGraphGroups.set(newann.graphGroup,
2207 Integer.valueOf(++fgroup));
2209 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2213 newann.padAnnotation(alwidth);
2214 alignment.addAnnotation(newann);
2224 addHistoryItem(new EditCommand(
2225 MessageManager.getString("label.add_sequences"),
2226 Action.PASTE, sequences, 0, alignment.getWidth(),
2229 // Add any annotations attached to sequences
2230 for (int i = 0; i < sequences.length; i++)
2232 if (sequences[i].getAnnotation() != null)
2234 AlignmentAnnotation newann;
2235 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2237 annotationAdded = true;
2238 newann = sequences[i].getAnnotation()[a];
2239 newann.adjustForAlignment();
2240 newann.padAnnotation(alwidth);
2241 if (newann.graphGroup > -1)
2243 if (newann.graphGroup > -1)
2245 if (newGraphGroups.size() <= newann.graphGroup
2246 || newGraphGroups.get(newann.graphGroup) == null)
2248 for (int q = newGraphGroups
2249 .size(); q <= newann.graphGroup; q++)
2251 newGraphGroups.add(q, null);
2253 newGraphGroups.set(newann.graphGroup,
2254 Integer.valueOf(++fgroup));
2256 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2260 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2264 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2272 // propagate alignment changed.
2273 viewport.getRanges().setEndSeq(alignment.getHeight() - 1);
2274 if (annotationAdded)
2276 // Duplicate sequence annotation in all views.
2277 AlignmentI[] alview = this.getViewAlignments();
2278 for (int i = 0; i < sequences.length; i++)
2280 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2285 for (int avnum = 0; avnum < alview.length; avnum++)
2287 if (alview[avnum] != alignment)
2289 // duplicate in a view other than the one with input focus
2290 int avwidth = alview[avnum].getWidth() + 1;
2291 // this relies on sann being preserved after we
2292 // modify the sequence's annotation array for each duplication
2293 for (int a = 0; a < sann.length; a++)
2295 AlignmentAnnotation newann = new AlignmentAnnotation(
2297 sequences[i].addAlignmentAnnotation(newann);
2298 newann.padAnnotation(avwidth);
2299 alview[avnum].addAnnotation(newann); // annotation was
2300 // duplicated earlier
2301 // TODO JAL-1145 graphGroups are not updated for sequence
2302 // annotation added to several views. This may cause
2304 alview[avnum].setAnnotationIndex(newann, a);
2309 buildSortByAnnotationScoresMenu();
2311 viewport.firePropertyChange("alignment", null,
2312 alignment.getSequences());
2313 if (alignPanels != null)
2315 for (AlignmentPanel ap : alignPanels)
2317 ap.validateAnnotationDimensions(false);
2322 alignPanel.validateAnnotationDimensions(false);
2328 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2330 String newtitle = new String("Copied sequences");
2332 if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null)
2334 HiddenColumns hc = (HiddenColumns) d.jalviewClipboard[2];
2335 af.viewport.setHiddenColumns(hc);
2338 // >>>This is a fix for the moment, until a better solution is
2340 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2341 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2342 .getFeatureRenderer());
2344 // TODO: maintain provenance of an alignment, rather than just make the
2345 // title a concatenation of operations.
2348 if (title.startsWith("Copied sequences"))
2354 newtitle = newtitle.concat("- from " + title);
2359 newtitle = new String("Pasted sequences");
2362 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2367 } catch (Exception ex)
2369 ex.printStackTrace();
2370 System.out.println("Exception whilst pasting: " + ex);
2371 // could be anything being pasted in here
2377 protected void expand_newalign(ActionEvent e)
2381 AlignmentI alignment = AlignmentUtils
2382 .expandContext(getViewport().getAlignment(), -1);
2383 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2385 String newtitle = new String("Flanking alignment");
2387 Desktop d = Desktop.getInstance();
2389 if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null)
2391 HiddenColumns hc = (HiddenColumns) d.jalviewClipboard[2];
2392 af.viewport.setHiddenColumns(hc);
2395 // >>>This is a fix for the moment, until a better solution is
2397 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2398 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2399 .getFeatureRenderer());
2401 // TODO: maintain provenance of an alignment, rather than just make the
2402 // title a concatenation of operations.
2404 if (title.startsWith("Copied sequences"))
2410 newtitle = newtitle.concat("- from " + title);
2414 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2416 } catch (Exception ex)
2418 ex.printStackTrace();
2419 System.out.println("Exception whilst pasting: " + ex);
2420 // could be anything being pasted in here
2421 } catch (OutOfMemoryError oom)
2423 new OOMWarning("Viewing flanking region of alignment", oom);
2428 * Action Cut (delete and copy) the selected region
2431 protected void cut_actionPerformed()
2433 copy_actionPerformed();
2434 delete_actionPerformed();
2438 * Performs menu option to Delete the currently selected region
2441 protected void delete_actionPerformed()
2444 SequenceGroup sg = viewport.getSelectionGroup();
2450 Runnable okAction = new Runnable()
2455 SequenceI[] cut = sg.getSequences()
2456 .toArray(new SequenceI[sg.getSize()]);
2458 addHistoryItem(new EditCommand(
2459 MessageManager.getString("label.cut_sequences"), Action.CUT,
2460 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2461 viewport.getAlignment()));
2463 viewport.setSelectionGroup(null);
2464 viewport.sendSelection();
2465 viewport.getAlignment().deleteGroup(sg);
2467 viewport.firePropertyChange("alignment", null,
2468 viewport.getAlignment().getSequences());
2469 if (viewport.getAlignment().getHeight() < 1)
2473 AlignFrame.this.setClosed(true);
2474 } catch (Exception ex)
2481 * If the cut affects all sequences, prompt for confirmation
2483 boolean wholeHeight = sg.getSize() == viewport.getAlignment().getHeight();
2484 boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes())
2485 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2486 if (wholeHeight && wholeWidth)
2488 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.getDesktopPane());
2489 dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
2490 Object[] options = new Object[] { MessageManager.getString("action.ok"),
2491 MessageManager.getString("action.cancel") };
2492 dialog.showDialog(MessageManager.getString("warn.delete_all"),
2493 MessageManager.getString("label.delete_all"),
2494 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
2495 options, options[0]);
2509 protected void deleteGroups_actionPerformed(ActionEvent e)
2511 if (avc.deleteGroups())
2513 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2514 alignPanel.updateAnnotation();
2515 alignPanel.paintAlignment(true, true);
2526 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2528 SequenceGroup sg = new SequenceGroup(
2529 viewport.getAlignment().getSequences());
2531 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2532 viewport.setSelectionGroup(sg);
2533 viewport.isSelectionGroupChanged(true);
2534 viewport.sendSelection();
2535 // JAL-2034 - should delegate to
2536 // alignPanel to decide if overview needs
2538 alignPanel.paintAlignment(false, false);
2539 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2549 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2551 if (viewport.cursorMode)
2553 alignPanel.getSeqPanel().keyboardNo1 = null;
2554 alignPanel.getSeqPanel().keyboardNo2 = null;
2556 viewport.setSelectionGroup(null);
2557 viewport.getColumnSelection().clear();
2558 viewport.setSelectionGroup(null);
2559 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2560 // JAL-2034 - should delegate to
2561 // alignPanel to decide if overview needs
2563 alignPanel.paintAlignment(false, false);
2564 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2565 viewport.sendSelection();
2575 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2577 SequenceGroup sg = viewport.getSelectionGroup();
2581 selectAllSequenceMenuItem_actionPerformed(null);
2586 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2588 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2590 // JAL-2034 - should delegate to
2591 // alignPanel to decide if overview needs
2594 alignPanel.paintAlignment(true, false);
2595 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2596 viewport.sendSelection();
2600 public void invertColSel_actionPerformed(ActionEvent e)
2602 viewport.invertColumnSelection();
2603 alignPanel.paintAlignment(true, false);
2604 viewport.sendSelection();
2614 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2616 trimAlignment(true);
2626 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2628 trimAlignment(false);
2631 void trimAlignment(boolean trimLeft)
2633 ColumnSelection colSel = viewport.getColumnSelection();
2636 if (!colSel.isEmpty())
2640 column = colSel.getMin();
2644 column = colSel.getMax();
2648 if (viewport.getSelectionGroup() != null)
2650 seqs = viewport.getSelectionGroup()
2651 .getSequencesAsArray(viewport.getHiddenRepSequences());
2655 seqs = viewport.getAlignment().getSequencesArray();
2658 TrimRegionCommand trimRegion;
2661 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2662 column, viewport.getAlignment());
2663 viewport.getRanges().setStartRes(0);
2667 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2668 column, viewport.getAlignment());
2671 setStatus(MessageManager
2672 .formatMessage("label.removed_columns", new String[]
2673 { Integer.valueOf(trimRegion.getSize()).toString() }));
2675 addHistoryItem(trimRegion);
2677 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2679 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2680 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2682 viewport.getAlignment().deleteGroup(sg);
2686 viewport.firePropertyChange("alignment", null,
2687 viewport.getAlignment().getSequences());
2698 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2700 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2703 if (viewport.getSelectionGroup() != null)
2705 seqs = viewport.getSelectionGroup()
2706 .getSequencesAsArray(viewport.getHiddenRepSequences());
2707 start = viewport.getSelectionGroup().getStartRes();
2708 end = viewport.getSelectionGroup().getEndRes();
2712 seqs = viewport.getAlignment().getSequencesArray();
2715 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2716 "Remove Gapped Columns", seqs, start, end,
2717 viewport.getAlignment());
2719 addHistoryItem(removeGapCols);
2721 setStatus(MessageManager
2722 .formatMessage("label.removed_empty_columns", new Object[]
2723 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2725 // This is to maintain viewport position on first residue
2726 // of first sequence
2727 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2728 ViewportRanges ranges = viewport.getRanges();
2729 int startRes = seq.findPosition(ranges.getStartRes());
2730 // ShiftList shifts;
2731 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2732 // edit.alColumnChanges=shifts.getInverse();
2733 // if (viewport.hasHiddenColumns)
2734 // viewport.getColumnSelection().compensateForEdits(shifts);
2735 ranges.setStartRes(seq.findIndex(startRes) - 1);
2736 viewport.firePropertyChange("alignment", null,
2737 viewport.getAlignment().getSequences());
2748 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2750 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2753 if (viewport.getSelectionGroup() != null)
2755 seqs = viewport.getSelectionGroup()
2756 .getSequencesAsArray(viewport.getHiddenRepSequences());
2757 start = viewport.getSelectionGroup().getStartRes();
2758 end = viewport.getSelectionGroup().getEndRes();
2762 seqs = viewport.getAlignment().getSequencesArray();
2765 // This is to maintain viewport position on first residue
2766 // of first sequence
2767 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2768 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2770 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2771 viewport.getAlignment()));
2773 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2775 viewport.firePropertyChange("alignment", null,
2776 viewport.getAlignment().getSequences());
2787 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2789 viewport.setPadGaps(padGapsMenuitem.isSelected());
2790 viewport.firePropertyChange("alignment", null,
2791 viewport.getAlignment().getSequences());
2801 public void findMenuItem_actionPerformed(ActionEvent e)
2807 * Create a new view of the current alignment.
2810 public void newView_actionPerformed(ActionEvent e)
2812 newView(null, true);
2816 * Creates and shows a new view of the current alignment.
2819 * title of newly created view; if null, one will be generated
2820 * @param copyAnnotation
2821 * if true then duplicate all annnotation, groups and settings
2822 * @return new alignment panel, already displayed.
2824 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2827 * Create a new AlignmentPanel (with its own, new Viewport)
2829 AlignmentPanel newap = new jalview.project.Jalview2XML()
2830 .copyAlignPanel(alignPanel);
2831 if (!copyAnnotation)
2834 * remove all groups and annotation except for the automatic stuff
2836 newap.av.getAlignment().deleteAllGroups();
2837 newap.av.getAlignment().deleteAllAnnotations(false);
2840 newap.av.setGatherViewsHere(false);
2842 if (viewport.getViewName() == null)
2844 viewport.setViewName(MessageManager
2845 .getString("label.view_name_original"));
2849 * Views share the same edits undo and redo stacks
2851 newap.av.setHistoryList(viewport.getHistoryList());
2852 newap.av.setRedoList(viewport.getRedoList());
2855 * copy any visualisation settings that are not saved in the project
2857 newap.av.setColourAppliesToAllGroups(
2858 viewport.getColourAppliesToAllGroups());
2861 * Views share the same mappings; need to deregister any new mappings
2862 * created by copyAlignPanel, and register the new reference to the shared
2865 newap.av.replaceMappings(viewport.getAlignment());
2868 * start up cDNA consensus (if applicable) now mappings are in place
2870 if (newap.av.initComplementConsensus())
2872 newap.refresh(true); // adjust layout of annotations
2875 newap.av.setViewName(getNewViewName(viewTitle));
2877 addAlignmentPanel(newap, true);
2878 newap.alignmentChanged();
2880 if (alignPanels.size() == 2)
2882 viewport.setGatherViewsHere(true);
2884 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2889 * Make a new name for the view, ensuring it is unique within the current
2890 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2891 * these now use viewId. Unique view names are still desirable for usability.)
2896 protected String getNewViewName(String viewTitle)
2898 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2899 boolean addFirstIndex = false;
2900 if (viewTitle == null || viewTitle.trim().length() == 0)
2902 viewTitle = MessageManager.getString("action.view");
2903 addFirstIndex = true;
2907 index = 1;// we count from 1 if given a specific name
2909 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2911 List<Component> comps = PaintRefresher.components
2912 .get(viewport.getSequenceSetId());
2914 List<String> existingNames = getExistingViewNames(comps);
2916 while (existingNames.contains(newViewName))
2918 newViewName = viewTitle + " " + (++index);
2924 * Returns a list of distinct view names found in the given list of
2925 * components. View names are held on the viewport of an AlignmentPanel.
2930 protected List<String> getExistingViewNames(List<Component> comps)
2932 List<String> existingNames = new ArrayList<>();
2933 for (Component comp : comps)
2935 if (comp instanceof AlignmentPanel)
2937 AlignmentPanel ap = (AlignmentPanel) comp;
2938 if (!existingNames.contains(ap.av.getViewName()))
2940 existingNames.add(ap.av.getViewName());
2944 return existingNames;
2948 * Explode tabbed views into separate windows.
2951 public void expandViews_actionPerformed(ActionEvent e)
2953 Desktop.explodeViews(this);
2957 * Gather views in separate windows back into a tabbed presentation.
2960 public void gatherViews_actionPerformed(ActionEvent e)
2962 Desktop.getInstance().gatherViews(this);
2972 public void font_actionPerformed(ActionEvent e)
2974 new FontChooser(alignPanel);
2984 protected void seqLimit_actionPerformed(ActionEvent e)
2986 viewport.setShowJVSuffix(seqLimits.isSelected());
2988 alignPanel.getIdPanel().getIdCanvas()
2989 .setPreferredSize(alignPanel.calculateIdWidth());
2990 alignPanel.paintAlignment(true, false);
2994 public void idRightAlign_actionPerformed(ActionEvent e)
2996 viewport.setRightAlignIds(idRightAlign.isSelected());
2997 alignPanel.paintAlignment(false, false);
3001 public void centreColumnLabels_actionPerformed(ActionEvent e)
3003 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
3004 alignPanel.paintAlignment(false, false);
3010 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3013 protected void followHighlight_actionPerformed()
3016 * Set the 'follow' flag on the Viewport (and scroll to position if now
3019 final boolean state = this.followHighlightMenuItem.getState();
3020 viewport.setFollowHighlight(state);
3023 alignPanel.scrollToPosition(viewport.getSearchResults());
3034 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3036 viewport.setColourText(colourTextMenuItem.isSelected());
3037 alignPanel.paintAlignment(false, false);
3047 public void wrapMenuItem_actionPerformed(ActionEvent e)
3049 scaleAbove.setVisible(wrapMenuItem.isSelected());
3050 scaleLeft.setVisible(wrapMenuItem.isSelected());
3051 scaleRight.setVisible(wrapMenuItem.isSelected());
3052 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3053 alignPanel.updateLayout();
3057 public void showAllSeqs_actionPerformed(ActionEvent e)
3059 viewport.showAllHiddenSeqs();
3063 public void showAllColumns_actionPerformed(ActionEvent e)
3065 viewport.showAllHiddenColumns();
3066 alignPanel.paintAlignment(true, true);
3067 viewport.sendSelection();
3071 public void hideSelSequences_actionPerformed(ActionEvent e)
3073 viewport.hideAllSelectedSeqs();
3077 * called by key handler and the hide all/show all menu items
3082 protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3085 boolean hide = false;
3086 SequenceGroup sg = viewport.getSelectionGroup();
3087 if (!toggleSeqs && !toggleCols)
3089 // Hide everything by the current selection - this is a hack - we do the
3090 // invert and then hide
3091 // first check that there will be visible columns after the invert.
3092 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3093 && sg.getStartRes() <= sg.getEndRes()))
3095 // now invert the sequence set, if required - empty selection implies
3096 // that no hiding is required.
3099 invertSequenceMenuItem_actionPerformed(null);
3100 sg = viewport.getSelectionGroup();
3104 viewport.expandColSelection(sg, true);
3105 // finally invert the column selection and get the new sequence
3107 invertColSel_actionPerformed(null);
3114 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3116 hideSelSequences_actionPerformed(null);
3119 else if (!(toggleCols && viewport.hasSelectedColumns()))
3121 showAllSeqs_actionPerformed(null);
3127 if (viewport.hasSelectedColumns())
3129 hideSelColumns_actionPerformed(null);
3132 viewport.setSelectionGroup(sg);
3137 showAllColumns_actionPerformed(null);
3146 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3147 * event.ActionEvent)
3150 public void hideAllButSelection_actionPerformed(ActionEvent e)
3152 toggleHiddenRegions(false, false);
3153 viewport.sendSelection();
3160 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3164 public void hideAllSelection_actionPerformed(ActionEvent e)
3166 SequenceGroup sg = viewport.getSelectionGroup();
3167 viewport.expandColSelection(sg, false);
3168 viewport.hideAllSelectedSeqs();
3169 viewport.hideSelectedColumns();
3170 alignPanel.updateLayout();
3171 alignPanel.paintAlignment(true, true);
3172 viewport.sendSelection();
3179 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3183 public void showAllhidden_actionPerformed(ActionEvent e)
3185 viewport.showAllHiddenColumns();
3186 viewport.showAllHiddenSeqs();
3187 alignPanel.paintAlignment(true, true);
3188 viewport.sendSelection();
3192 public void hideSelColumns_actionPerformed(ActionEvent e)
3194 viewport.hideSelectedColumns();
3195 alignPanel.updateLayout();
3196 alignPanel.paintAlignment(true, true);
3197 viewport.sendSelection();
3201 public void hiddenMarkers_actionPerformed(ActionEvent e)
3203 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3214 protected void scaleAbove_actionPerformed(ActionEvent e)
3216 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3217 alignPanel.updateLayout();
3218 alignPanel.paintAlignment(true, false);
3228 protected void scaleLeft_actionPerformed(ActionEvent e)
3230 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3231 alignPanel.updateLayout();
3232 alignPanel.paintAlignment(true, false);
3242 protected void scaleRight_actionPerformed(ActionEvent e)
3244 viewport.setScaleRightWrapped(scaleRight.isSelected());
3245 alignPanel.updateLayout();
3246 alignPanel.paintAlignment(true, false);
3256 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3258 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3259 alignPanel.paintAlignment(false, false);
3269 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3271 viewport.setShowText(viewTextMenuItem.isSelected());
3272 alignPanel.paintAlignment(false, false);
3282 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3284 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3285 alignPanel.paintAlignment(false, false);
3288 public FeatureSettings featureSettings;
3291 public FeatureSettingsControllerI getFeatureSettingsUI()
3293 return featureSettings;
3297 public void featureSettings_actionPerformed(ActionEvent e)
3299 showFeatureSettingsUI();
3303 public FeatureSettingsControllerI showFeatureSettingsUI()
3305 if (featureSettings != null)
3307 featureSettings.closeOldSettings();
3308 featureSettings = null;
3310 if (!showSeqFeatures.isSelected())
3312 // make sure features are actually displayed
3313 showSeqFeatures.setSelected(true);
3314 showSeqFeatures_actionPerformed(null);
3316 featureSettings = new FeatureSettings(this);
3317 return featureSettings;
3321 * Set or clear 'Show Sequence Features'
3327 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3329 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3330 alignPanel.paintAlignment(true, true);
3334 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3335 * the annotations panel as a whole.
3337 * The options to show/hide all annotations should be enabled when the panel
3338 * is shown, and disabled when the panel is hidden.
3343 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3345 final boolean setVisible = annotationPanelMenuItem.isSelected();
3346 viewport.setShowAnnotation(setVisible);
3347 syncAnnotationMenuItems();
3348 alignPanel.updateLayout();
3351 private void syncAnnotationMenuItems()
3353 final boolean setVisible = annotationPanelMenuItem.isSelected();
3354 showAllSeqAnnotations.setEnabled(setVisible);
3355 hideAllSeqAnnotations.setEnabled(setVisible);
3356 showAllAlAnnotations.setEnabled(setVisible);
3357 hideAllAlAnnotations.setEnabled(setVisible);
3362 public void alignmentProperties()
3365 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3368 String content = MessageManager.formatMessage("label.html_content",
3370 { contents.toString() });
3373 if (Platform.isJS())
3375 JLabel textLabel = new JLabel();
3376 textLabel.setText(content);
3377 textLabel.setBackground(Color.WHITE);
3379 pane = new JPanel(new BorderLayout());
3380 ((JPanel) pane).setOpaque(true);
3381 pane.setBackground(Color.WHITE);
3382 ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
3391 JEditorPane editPane = new JEditorPane("text/html", "");
3392 editPane.setEditable(false);
3393 editPane.setText(content);
3397 JInternalFrame frame = new JInternalFrame();
3399 frame.getContentPane().add(new JScrollPane(pane));
3401 Desktop.addInternalFrame(frame, MessageManager
3402 .formatMessage("label.alignment_properties", new Object[]
3403 { getTitle() }), 500, 400);
3413 public void overviewMenuItem_actionPerformed(ActionEvent e)
3415 if (alignPanel.overviewPanel != null)
3420 JInternalFrame frame = new JInternalFrame();
3422 // BH 2019.07.26 we allow for an embedded
3423 // undecorated overview with defined size
3424 frame.setName(Jalview.getAppID("overview"));
3426 Dimension dim = Platform.getDimIfEmbedded(frame, -1, -1);
3427 if (dim != null && dim.width == 0)
3429 dim = null; // hidden, not embedded
3431 OverviewPanel overview = new OverviewPanel(alignPanel, dim);
3433 frame.setContentPane(overview);
3436 dim = new Dimension();
3437 // was frame.getSize(), but that is 0,0 at this point;
3441 // we are imbedding, and so we have an undecorated frame
3442 // and we can set the the frame dimensions accordingly.
3444 // allowing for unresizable option using, style="resize:none"
3445 boolean resizable = (Platform.getEmbeddedAttribute(frame,
3446 "resize") != "none");
3447 Desktop.addInternalFrame(frame, MessageManager
3448 .formatMessage("label.overview_params", new Object[]
3449 { this.getTitle() }), true, dim.width, dim.height, resizable,
3452 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3453 frame.addInternalFrameListener(
3454 new javax.swing.event.InternalFrameAdapter()
3457 public void internalFrameClosed(
3458 javax.swing.event.InternalFrameEvent evt)
3461 alignPanel.setOverviewPanel(null);
3464 if (getKeyListeners().length > 0)
3466 frame.addKeyListener(getKeyListeners()[0]);
3469 alignPanel.setOverviewPanel(overview);
3473 public void textColour_actionPerformed()
3475 new TextColourChooser().chooseColour(alignPanel, null);
3479 * public void covariationColour_actionPerformed() {
3481 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3485 public void annotationColour_actionPerformed()
3487 new AnnotationColourChooser(viewport, alignPanel);
3491 public void annotationColumn_actionPerformed(ActionEvent e)
3493 new AnnotationColumnChooser(viewport, alignPanel);
3497 * Action on the user checking or unchecking the option to apply the selected
3498 * colour scheme to all groups. If unchecked, groups may have their own
3499 * independent colour schemes.
3504 public void applyToAllGroups_actionPerformed(boolean selected)
3506 viewport.setColourAppliesToAllGroups(selected);
3510 * Action on user selecting a colour from the colour menu
3513 * the name (not the menu item label!) of the colour scheme
3516 public void changeColour_actionPerformed(String name)
3519 * 'User Defined' opens a panel to configure or load a
3520 * user-defined colour scheme
3522 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3524 new UserDefinedColours(alignPanel);
3529 * otherwise set the chosen colour scheme (or null for 'None')
3531 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3533 viewport.getAlignment(), viewport.getHiddenRepSequences());
3538 * Actions on setting or changing the alignment colour scheme
3543 public void changeColour(ColourSchemeI cs)
3545 // TODO: pull up to controller method
3546 ColourMenuHelper.setColourSelected(colourMenu, cs);
3548 viewport.setGlobalColourScheme(cs);
3550 alignPanel.paintAlignment(true, true);
3554 * Show the PID threshold slider panel
3557 protected void modifyPID_actionPerformed()
3559 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3560 alignPanel.getViewName());
3561 SliderPanel.showPIDSlider();
3565 * Show the Conservation slider panel
3568 protected void modifyConservation_actionPerformed()
3570 SliderPanel.setConservationSlider(alignPanel,
3571 viewport.getResidueShading(), alignPanel.getViewName());
3572 SliderPanel.showConservationSlider();
3576 * Action on selecting or deselecting (Colour) By Conservation
3579 public void conservationMenuItem_actionPerformed(boolean selected)
3581 modifyConservation.setEnabled(selected);
3582 viewport.setConservationSelected(selected);
3583 viewport.getResidueShading().setConservationApplied(selected);
3585 changeColour(viewport.getGlobalColourScheme());
3588 modifyConservation_actionPerformed();
3592 SliderPanel.hideConservationSlider();
3597 * Action on selecting or deselecting (Colour) Above PID Threshold
3600 public void abovePIDThreshold_actionPerformed(boolean selected)
3602 modifyPID.setEnabled(selected);
3603 viewport.setAbovePIDThreshold(selected);
3606 viewport.getResidueShading().setThreshold(0,
3607 viewport.isIgnoreGapsConsensus());
3610 changeColour(viewport.getGlobalColourScheme());
3613 modifyPID_actionPerformed();
3617 SliderPanel.hidePIDSlider();
3628 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3630 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3631 AlignmentSorter.sortByPID(viewport.getAlignment(),
3632 viewport.getAlignment().getSequenceAt(0));
3633 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3634 viewport.getAlignment()));
3635 alignPanel.paintAlignment(true, false);
3645 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3647 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3648 AlignmentSorter.sortByID(viewport.getAlignment());
3650 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3651 alignPanel.paintAlignment(true, false);
3661 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3663 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3664 AlignmentSorter.sortByLength(viewport.getAlignment());
3665 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3666 viewport.getAlignment()));
3667 alignPanel.paintAlignment(true, false);
3677 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3679 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3680 AlignmentSorter.sortByGroup(viewport.getAlignment());
3681 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3682 viewport.getAlignment()));
3684 alignPanel.paintAlignment(true, false);
3694 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3696 new RedundancyPanel(alignPanel, this);
3706 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3708 if ((viewport.getSelectionGroup() == null)
3709 || (viewport.getSelectionGroup().getSize() < 2))
3711 JvOptionPane.showInternalMessageDialog(this,
3712 MessageManager.getString(
3713 "label.you_must_select_least_two_sequences"),
3714 MessageManager.getString("label.invalid_selection"),
3715 JvOptionPane.WARNING_MESSAGE);
3719 JInternalFrame frame = new JInternalFrame();
3720 frame.setContentPane(new PairwiseAlignPanel(viewport));
3721 Desktop.addInternalFrame(frame,
3722 MessageManager.getString("action.pairwise_alignment"), 600,
3728 public void autoCalculate_actionPerformed(ActionEvent e)
3730 viewport.setAutoCalculateConsensusAndConservation(autoCalculate.isSelected());
3731 if (viewport.getAutoCalculateConsensusAndConservation())
3733 viewport.firePropertyChange("alignment", null,
3734 viewport.getAlignment().getSequences());
3739 public void sortByTreeOption_actionPerformed(ActionEvent e)
3741 viewport.sortByTree = sortByTree.isSelected();
3745 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3747 viewport.followSelection = listenToViewSelections.isSelected();
3751 * Constructs a tree panel and adds it to the desktop
3754 * tree type (NJ or AV)
3756 * name of score model used to compute the tree
3758 * parameters for the distance or similarity calculation
3760 void newTreePanel(String type, String modelName,
3761 SimilarityParamsI options)
3763 String frameTitle = "";
3766 boolean onSelection = false;
3767 if (viewport.getSelectionGroup() != null
3768 && viewport.getSelectionGroup().getSize() > 0)
3770 SequenceGroup sg = viewport.getSelectionGroup();
3772 /* Decide if the selection is a column region */
3773 for (SequenceI _s : sg.getSequences())
3775 if (_s.getLength() < sg.getEndRes())
3777 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
3778 MessageManager.getString(
3779 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3780 MessageManager.getString(
3781 "label.sequences_selection_not_aligned"),
3782 JvOptionPane.WARNING_MESSAGE);
3791 if (viewport.getAlignment().getHeight() < 2)
3797 tp = new TreePanel(alignPanel, type, modelName, options);
3798 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3800 frameTitle += " from ";
3802 if (viewport.getViewName() != null)
3804 frameTitle += viewport.getViewName() + " of ";
3807 frameTitle += this.title;
3809 Dimension dim = Platform.getDimIfEmbedded(tp, 600, 500);
3810 Desktop.addInternalFrame(tp, frameTitle, dim.width, dim.height);
3821 public void addSortByOrderMenuItem(String title,
3822 final AlignmentOrder order)
3824 final JMenuItem item = new JMenuItem(MessageManager
3825 .formatMessage("action.by_title_param", new Object[]
3828 item.addActionListener(new java.awt.event.ActionListener()
3831 public void actionPerformed(ActionEvent e)
3833 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3835 // TODO: JBPNote - have to map order entries to curent SequenceI
3837 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3839 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3840 viewport.getAlignment()));
3842 alignPanel.paintAlignment(true, false);
3848 * Add a new sort by annotation score menu item
3851 * the menu to add the option to
3853 * the label used to retrieve scores for each sequence on the
3856 public void addSortByAnnotScoreMenuItem(JMenu sort,
3857 final String scoreLabel)
3859 final JMenuItem item = new JMenuItem(scoreLabel);
3861 item.addActionListener(new java.awt.event.ActionListener()
3864 public void actionPerformed(ActionEvent e)
3866 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3867 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3868 viewport.getAlignment());// ,viewport.getSelectionGroup());
3869 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3870 viewport.getAlignment()));
3871 alignPanel.paintAlignment(true, false);
3877 * last hash for alignment's annotation array - used to minimise cost of
3880 protected int _annotationScoreVectorHash;
3883 * search the alignment and rebuild the sort by annotation score submenu the
3884 * last alignment annotation vector hash is stored to minimize cost of
3885 * rebuilding in subsequence calls.
3889 public void buildSortByAnnotationScoresMenu()
3891 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3896 if (viewport.getAlignment().getAlignmentAnnotation()
3897 .hashCode() != _annotationScoreVectorHash)
3899 sortByAnnotScore.removeAll();
3900 // almost certainly a quicker way to do this - but we keep it simple
3901 Hashtable<String, String> scoreSorts = new Hashtable<>();
3902 AlignmentAnnotation aann[];
3903 for (SequenceI sqa : viewport.getAlignment().getSequences())
3905 aann = sqa.getAnnotation();
3906 for (int i = 0; aann != null && i < aann.length; i++)
3908 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3910 scoreSorts.put(aann[i].label, aann[i].label);
3914 Enumeration<String> labels = scoreSorts.keys();
3915 while (labels.hasMoreElements())
3917 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3918 labels.nextElement());
3920 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3923 _annotationScoreVectorHash = viewport.getAlignment()
3924 .getAlignmentAnnotation().hashCode();
3929 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3930 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3931 * call. Listeners are added to remove the menu item when the treePanel is
3932 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3936 public void buildTreeSortMenu()
3938 sortByTreeMenu.removeAll();
3940 List<Component> comps = PaintRefresher.components
3941 .get(viewport.getSequenceSetId());
3942 List<TreePanel> treePanels = new ArrayList<>();
3943 for (Component comp : comps)
3945 if (comp instanceof TreePanel)
3947 treePanels.add((TreePanel) comp);
3951 if (treePanels.size() < 1)
3953 sortByTreeMenu.setVisible(false);
3957 sortByTreeMenu.setVisible(true);
3959 for (final TreePanel tp : treePanels)
3961 final JMenuItem item = new JMenuItem(tp.getTitle());
3962 item.addActionListener(new java.awt.event.ActionListener()
3965 public void actionPerformed(ActionEvent e)
3967 tp.sortByTree_actionPerformed();
3968 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3973 sortByTreeMenu.add(item);
3977 public boolean sortBy(AlignmentOrder alorder, String undoname)
3979 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3980 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3981 if (undoname != null)
3983 addHistoryItem(new OrderCommand(undoname, oldOrder,
3984 viewport.getAlignment()));
3986 alignPanel.paintAlignment(true, false);
3991 * Work out whether the whole set of sequences or just the selected set will
3992 * be submitted for multiple alignment.
3995 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3997 // Now, check we have enough sequences
3998 AlignmentView msa = null;
4000 if ((viewport.getSelectionGroup() != null)
4001 && (viewport.getSelectionGroup().getSize() > 1))
4003 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4004 // some common interface!
4006 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4007 * SequenceI[sz = seqs.getSize(false)];
4009 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4010 * seqs.getSequenceAt(i); }
4012 msa = viewport.getAlignmentView(true);
4014 else if (viewport.getSelectionGroup() != null
4015 && viewport.getSelectionGroup().getSize() == 1)
4017 int option = JvOptionPane.showConfirmDialog(this,
4018 MessageManager.getString("warn.oneseq_msainput_selection"),
4019 MessageManager.getString("label.invalid_selection"),
4020 JvOptionPane.OK_CANCEL_OPTION);
4021 if (option == JvOptionPane.OK_OPTION)
4023 msa = viewport.getAlignmentView(false);
4028 msa = viewport.getAlignmentView(false);
4034 * Decides what is submitted to a secondary structure prediction service: the
4035 * first sequence in the alignment, or in the current selection, or, if the
4036 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4037 * region or the whole alignment. (where the first sequence in the set is the
4038 * one that the prediction will be for).
4040 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4042 AlignmentView seqs = null;
4044 if ((viewport.getSelectionGroup() != null)
4045 && (viewport.getSelectionGroup().getSize() > 0))
4047 seqs = viewport.getAlignmentView(true);
4051 seqs = viewport.getAlignmentView(false);
4053 // limit sequences - JBPNote in future - could spawn multiple prediction
4055 // TODO: viewport.getAlignment().isAligned is a global state - the local
4056 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4057 if (!viewport.getAlignment().isAligned(false))
4059 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4060 // TODO: if seqs.getSequences().length>1 then should really have warned
4074 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4076 // Pick the tree file
4077 JalviewFileChooser chooser = new JalviewFileChooser(
4078 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4079 chooser.setFileView(new JalviewFileView());
4080 chooser.setDialogTitle(
4081 MessageManager.getString("label.select_newick_like_tree_file"));
4082 chooser.setToolTipText(
4083 MessageManager.getString("label.load_tree_file"));
4085 chooser.setResponseHandler(0,new Runnable()
4090 String filePath = chooser.getSelectedFile().getPath();
4091 Cache.setProperty("LAST_DIRECTORY", filePath);
4092 NewickFile fin = null;
4095 fin = new NewickFile(new FileParse(chooser.getSelectedFile(),
4096 DataSourceType.FILE));
4097 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4098 } catch (Exception ex)
4100 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), ex.getMessage(),
4102 .getString("label.problem_reading_tree_file"),
4103 JvOptionPane.WARNING_MESSAGE);
4104 ex.printStackTrace();
4106 if (fin != null && fin.hasWarningMessage())
4108 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
4109 fin.getWarningMessage(),
4110 MessageManager.getString(
4111 "label.possible_problem_with_tree_file"),
4112 JvOptionPane.WARNING_MESSAGE);
4116 chooser.showOpenDialog(this);
4119 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4121 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4124 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4125 int h, int x, int y)
4127 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4131 * Add a treeviewer for the tree extracted from a Newick file object to the
4132 * current alignment view
4139 * Associated alignment input data (or null)
4148 * @return TreePanel handle
4150 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4151 AlignmentView input, int w, int h, int x, int y)
4153 TreePanel tp = null;
4159 if (nf.getTree() != null)
4161 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4162 Dimension dim = Platform.getDimIfEmbedded(tp, -1, -1);
4165 dim = new Dimension(w, h);
4169 // no offset, either
4172 tp.setSize(dim.width, dim.height);
4176 tp.setLocation(x, y);
4179 Desktop.addInternalFrame(tp, treeTitle, dim.width, dim.height);
4181 } catch (Exception ex)
4183 ex.printStackTrace();
4189 private boolean buildingMenu = false;
4192 * Generates menu items and listener event actions for web service clients
4195 public void BuildWebServiceMenu()
4197 if (Jalview.isSynchronous())
4201 while (buildingMenu)
4205 System.err.println("Waiting for building menu to finish.");
4207 } catch (Exception e)
4211 final AlignFrame me = this;
4212 buildingMenu = true;
4213 new Thread(new Runnable()
4218 final List<JMenuItem> legacyItems = new ArrayList<>();
4221 // System.err.println("Building ws menu again "
4222 // + Thread.currentThread());
4223 // TODO: add support for context dependent disabling of services based
4225 // alignment and current selection
4226 // TODO: add additional serviceHandle parameter to specify abstract
4228 // class independently of AbstractName
4229 // TODO: add in rediscovery GUI function to restart discoverer
4230 // TODO: group services by location as well as function and/or
4232 // object broker mechanism.
4233 final Vector<JMenu> wsmenu = new Vector<>();
4234 final IProgressIndicator af = me;
4237 * do not i18n these strings - they are hard-coded in class
4238 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4239 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4241 final JMenu msawsmenu = new JMenu("Alignment");
4242 final JMenu secstrmenu = new JMenu(
4243 "Secondary Structure Prediction");
4244 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4245 final JMenu analymenu = new JMenu("Analysis");
4246 final JMenu dismenu = new JMenu("Protein Disorder");
4247 // JAL-940 - only show secondary structure prediction services from
4248 // the legacy server
4249 Hashtable<String, Vector<ServiceHandle>> services = Discoverer
4250 .getInstance().getServices();
4251 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4253 services != null && (services.size() > 0))
4255 // TODO: refactor to allow list of AbstractName/Handler bindings to
4257 // stored or retrieved from elsewhere
4258 // No MSAWS used any more:
4259 // Vector msaws = null; // (Vector)
4260 // Discoverer.services.get("MsaWS");
4261 Vector<ServiceHandle> secstrpr = services.get("SecStrPred");
4262 if (secstrpr != null)
4264 // Add any secondary structure prediction services
4265 for (int i = 0, j = secstrpr.size(); i < j; i++)
4267 final ext.vamsas.ServiceHandle sh = secstrpr
4269 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4270 .getServiceClient(sh);
4271 int p = secstrmenu.getItemCount();
4272 impl.attachWSMenuEntry(secstrmenu, me);
4273 int q = secstrmenu.getItemCount();
4274 for (int litm = p; litm < q; litm++)
4276 legacyItems.add(secstrmenu.getItem(litm));
4282 // Add all submenus in the order they should appear on the web
4284 wsmenu.add(msawsmenu);
4285 wsmenu.add(secstrmenu);
4286 wsmenu.add(dismenu);
4287 wsmenu.add(analymenu);
4288 // No search services yet
4289 // wsmenu.add(seqsrchmenu);
4291 javax.swing.SwingUtilities.invokeLater(new Runnable()
4298 webService.removeAll();
4299 // first, add discovered services onto the webservices menu
4300 if (wsmenu.size() > 0)
4302 for (int i = 0, j = wsmenu.size(); i < j; i++)
4304 webService.add(wsmenu.get(i));
4309 webService.add(me.webServiceNoServices);
4311 // TODO: move into separate menu builder class.
4312 // boolean new_sspred = false;
4313 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4315 Jws2Discoverer jws2servs = Jws2Discoverer.getInstance();
4316 if (jws2servs != null)
4318 if (jws2servs.hasServices())
4320 jws2servs.attachWSMenuEntry(webService, me);
4321 for (Jws2Instance sv : jws2servs.getServices())
4323 if (sv.description.toLowerCase().contains("jpred"))
4325 for (JMenuItem jmi : legacyItems)
4327 jmi.setVisible(false);
4333 if (jws2servs.isRunning())
4335 JMenuItem tm = new JMenuItem(
4336 "Still discovering JABA Services");
4337 tm.setEnabled(false);
4342 build_urlServiceMenu(me.webService);
4343 build_fetchdbmenu(webService);
4344 for (JMenu item : wsmenu)
4346 if (item.getItemCount() == 0)
4348 item.setEnabled(false);
4352 item.setEnabled(true);
4355 } catch (Exception e)
4358 "Exception during web service menu building process.",
4363 } catch (Exception e)
4366 buildingMenu = false;
4373 * construct any groupURL type service menu entries.
4377 protected void build_urlServiceMenu(JMenu webService)
4379 // TODO: remove this code when 2.7 is released
4380 // DEBUG - alignmentView
4382 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4383 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4385 * @Override public void actionPerformed(ActionEvent e) {
4386 * jalview.datamodel.AlignmentView
4387 * .testSelectionViews(af.viewport.getAlignment(),
4388 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4390 * }); webService.add(testAlView);
4392 // TODO: refactor to RestClient discoverer and merge menu entries for
4393 // rest-style services with other types of analysis/calculation service
4394 // SHmmr test client - still being implemented.
4395 // DEBUG - alignmentView
4397 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4400 client.attachWSMenuEntry(
4401 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4407 * Searches the alignment sequences for xRefs and builds the Show
4408 * Cross-References menu (formerly called Show Products), with database
4409 * sources for which cross-references are found (protein sources for a
4410 * nucleotide alignment and vice versa)
4412 * @return true if Show Cross-references menu should be enabled
4414 public boolean canShowProducts()
4416 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4417 AlignmentI dataset = viewport.getAlignment().getDataset();
4419 showProducts.removeAll();
4420 final boolean dna = viewport.getAlignment().isNucleotide();
4422 if (seqs == null || seqs.length == 0)
4424 // nothing to see here.
4428 boolean showp = false;
4431 List<String> ptypes = new CrossRef(seqs, dataset)
4432 .findXrefSourcesForSequences(dna);
4434 for (final String source : ptypes)
4437 final AlignFrame af = this;
4438 JMenuItem xtype = new JMenuItem(source);
4439 xtype.addActionListener(new ActionListener()
4442 public void actionPerformed(ActionEvent e)
4444 showProductsFor(af.viewport.getSequenceSelection(), dna,
4448 showProducts.add(xtype);
4450 showProducts.setVisible(showp);
4451 showProducts.setEnabled(showp);
4452 } catch (Exception e)
4455 "canShowProducts threw an exception - please report to help@jalview.org",
4463 * Finds and displays cross-references for the selected sequences (protein
4464 * products for nucleotide sequences, dna coding sequences for peptides).
4467 * the sequences to show cross-references for
4469 * true if from a nucleotide alignment (so showing proteins)
4471 * the database to show cross-references for
4473 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4474 final String source)
4476 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4481 * Construct and display a new frame containing the translation of this
4482 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4485 public void showTranslation_actionPerformed(GeneticCodeI codeTable)
4487 AlignmentI al = null;
4490 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4492 al = dna.translateCdna(codeTable);
4493 } catch (Exception ex)
4495 jalview.bin.Cache.log.error(
4496 "Exception during translation. Please report this !", ex);
4497 final String msg = MessageManager.getString(
4498 "label.error_when_translating_sequences_submit_bug_report");
4499 final String errorTitle = MessageManager
4500 .getString("label.implementation_error")
4501 + MessageManager.getString("label.translation_failed");
4502 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msg, errorTitle,
4503 JvOptionPane.ERROR_MESSAGE);
4506 if (al == null || al.getHeight() == 0)
4508 final String msg = MessageManager.getString(
4509 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4510 final String errorTitle = MessageManager
4511 .getString("label.translation_failed");
4512 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msg, errorTitle,
4513 JvOptionPane.WARNING_MESSAGE);
4517 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4518 af.setFileFormat(this.currentFileFormat);
4519 final String newTitle = MessageManager
4520 .formatMessage("label.translation_of_params", new Object[]
4521 { this.getTitle(), codeTable.getId() });
4522 af.setTitle(newTitle);
4523 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4525 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4526 AlignViewport.openSplitFrame(this, af, new Alignment(seqs));
4530 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4537 * Set the file format
4541 public void setFileFormat(FileFormatI format)
4543 this.currentFileFormat = format;
4547 * Try to load a features file onto the alignment.
4550 * contents or path to retrieve file or a File object
4552 * access mode of file (see jalview.io.AlignFile)
4553 * @return true if features file was parsed correctly.
4555 public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
4558 return avc.parseFeaturesFile(file, sourceType,
4559 Cache.getDefault(Preferences.RELAXEDSEQIDMATCHING, false));
4564 public void refreshFeatureUI(boolean enableIfNecessary)
4566 // note - currently this is only still here rather than in the controller
4567 // because of the featureSettings hard reference that is yet to be
4569 if (enableIfNecessary)
4571 viewport.setShowSequenceFeatures(true);
4572 showSeqFeatures.setSelected(true);
4578 public void dragEnter(DropTargetDragEvent evt)
4583 public void dragExit(DropTargetEvent evt)
4588 public void dragOver(DropTargetDragEvent evt)
4593 public void dropActionChanged(DropTargetDragEvent evt)
4598 public void drop(DropTargetDropEvent evt)
4600 // JAL-1552 - acceptDrop required before getTransferable call for
4601 // Java's Transferable for native dnd
4602 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4603 Transferable t = evt.getTransferable();
4605 final AlignFrame thisaf = this;
4606 final List<Object> files = new ArrayList<>();
4607 List<DataSourceType> protocols = new ArrayList<>();
4611 Desktop.transferFromDropTarget(files, protocols, evt, t);
4612 } catch (Exception e)
4614 e.printStackTrace();
4618 new Thread(new Runnable()
4625 // check to see if any of these files have names matching sequences
4628 SequenceIdMatcher idm = new SequenceIdMatcher(
4629 viewport.getAlignment().getSequencesArray());
4631 * Object[] { String,SequenceI}
4633 ArrayList<Object[]> filesmatched = new ArrayList<>();
4634 ArrayList<Object> filesnotmatched = new ArrayList<>();
4635 for (int i = 0; i < files.size(); i++)
4638 Object file = files.get(i);
4639 String fileName = file.toString();
4641 DataSourceType protocol = (file instanceof File
4642 ? DataSourceType.FILE
4643 : FormatAdapter.checkProtocol(fileName));
4644 if (protocol == DataSourceType.FILE)
4647 if (file instanceof File) {
4649 Platform.cacheFileData(fl);
4651 fl = new File(fileName);
4653 pdbfn = fl.getName();
4655 else if (protocol == DataSourceType.URL)
4657 URL url = new URL(fileName);
4658 pdbfn = url.getFile();
4660 if (pdbfn.length() > 0)
4662 // attempt to find a match in the alignment
4663 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4664 int l = 0, c = pdbfn.indexOf(".");
4665 while (mtch == null && c != -1)
4670 } while ((c = pdbfn.indexOf(".", l)) > l);
4673 pdbfn = pdbfn.substring(0, l);
4675 mtch = idm.findAllIdMatches(pdbfn);
4682 type = new IdentifyFile().identify(file, protocol);
4683 } catch (Exception ex)
4687 if (type != null && type.isStructureFile())
4689 filesmatched.add(new Object[] { file, protocol, mtch });
4693 // File wasn't named like one of the sequences or wasn't a PDB
4695 filesnotmatched.add(file);
4699 if (filesmatched.size() > 0)
4701 boolean autoAssociate = Cache
4702 .getDefault(Preferences.AUTOASSOCIATE_PDBANDSEQS, false);
4705 String msg = MessageManager.formatMessage(
4706 "label.automatically_associate_structure_files_with_sequences_same_name",
4708 { Integer.valueOf(filesmatched.size())
4710 String ttl = MessageManager.getString(
4711 "label.automatically_associate_structure_files_by_name");
4712 int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
4713 ttl, JvOptionPane.YES_NO_OPTION);
4714 autoAssociate = choice == JvOptionPane.YES_OPTION;
4718 for (Object[] fm : filesmatched)
4720 // try and associate
4721 // TODO: may want to set a standard ID naming formalism for
4722 // associating PDB files which have no IDs.
4723 for (SequenceI toassoc : (SequenceI[]) fm[2])
4726 PDBEntry pe = AssociatePdbFileWithSeq
4727 .associatePdbWithSeq(fm[0].toString(),
4728 (DataSourceType) fm[1], toassoc, false);
4731 System.err.println("Associated file : "
4732 + (fm[0].toString()) + " with "
4733 + toassoc.getDisplayId(true));
4737 // TODO: do we need to update overview ? only if features are
4739 alignPanel.paintAlignment(true, false);
4745 * add declined structures as sequences
4747 for (Object[] o : filesmatched)
4749 filesnotmatched.add(o[0]);
4753 if (filesnotmatched.size() > 0)
4755 if (assocfiles > 0 && (Cache.getDefault(
4756 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4757 || JvOptionPane.showConfirmDialog(thisaf,
4758 "<html>" + MessageManager.formatMessage(
4759 "label.ignore_unmatched_dropped_files_info",
4762 filesnotmatched.size())
4765 MessageManager.getString(
4766 "label.ignore_unmatched_dropped_files"),
4767 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4771 for (Object fn : filesnotmatched)
4773 loadJalviewDataFile(fn, null, null, null);
4777 } catch (Exception ex)
4779 ex.printStackTrace();
4787 * Attempt to load a "dropped" file or URL string, by testing in turn for
4789 * <li>an Annotation file</li>
4790 * <li>a JNet file</li>
4791 * <li>a features file</li>
4792 * <li>else try to interpret as an alignment file</li>
4796 * either a filename or a URL string.
4798 public void loadJalviewDataFile(Object file, DataSourceType sourceType,
4799 FileFormatI format, SequenceI assocSeq)
4801 // BH 2018 was String file
4804 if (sourceType == null)
4806 sourceType = FormatAdapter.checkProtocol(file);
4808 // if the file isn't identified, or not positively identified as some
4809 // other filetype (PFAM is default unidentified alignment file type) then
4810 // try to parse as annotation.
4811 boolean isAnnotation = (format == null
4812 || FileFormat.Pfam.equals(format))
4813 ? new AnnotationFile().annotateAlignmentView(viewport,
4819 // first see if its a T-COFFEE score file
4820 TCoffeeScoreFile tcf = null;
4823 tcf = new TCoffeeScoreFile(file, sourceType);
4826 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4830 new TCoffeeColourScheme(viewport.getAlignment()));
4831 isAnnotation = true;
4832 setStatus(MessageManager.getString(
4833 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4837 // some problem - if no warning its probable that the ID matching
4838 // process didn't work
4839 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
4840 tcf.getWarningMessage() == null
4841 ? MessageManager.getString(
4842 "label.check_file_matches_sequence_ids_alignment")
4843 : tcf.getWarningMessage(),
4844 MessageManager.getString(
4845 "label.problem_reading_tcoffee_score_file"),
4846 JvOptionPane.WARNING_MESSAGE);
4853 } catch (Exception x)
4856 "Exception when processing data source as T-COFFEE score file",
4862 // try to see if its a JNet 'concise' style annotation file *before*
4864 // try to parse it as a features file
4867 format = new IdentifyFile().identify(file, sourceType);
4869 if (FileFormat.ScoreMatrix == format)
4871 ScoreMatrixFile sm = new ScoreMatrixFile(
4872 new FileParse(file, sourceType));
4874 // todo: i18n this message
4875 setStatus(MessageManager.formatMessage(
4876 "label.successfully_loaded_matrix",
4877 sm.getMatrixName()));
4879 else if (FileFormat.Jnet.equals(format))
4881 JPredFile predictions = new JPredFile(file, sourceType);
4882 new JnetAnnotationMaker();
4883 JnetAnnotationMaker.add_annotation(predictions,
4884 viewport.getAlignment(), 0, false);
4885 viewport.getAlignment().setupJPredAlignment();
4886 isAnnotation = true;
4888 // else if (IdentifyFile.FeaturesFile.equals(format))
4889 else if (FileFormat.Features.equals(format))
4891 if (parseFeaturesFile(file, sourceType))
4893 SplitFrame splitFrame = (SplitFrame) getSplitViewContainer();
4894 if (splitFrame != null)
4896 splitFrame.repaint();
4900 alignPanel.paintAlignment(true, true);
4906 if (file instanceof File) {
4907 new FileLoader().loadFile(viewport, (File) file, sourceType, format);
4909 new FileLoader().LoadFile(viewport, (String) file, sourceType, format);
4916 updateForAnnotations();
4918 } catch (Exception ex)
4920 ex.printStackTrace();
4921 } catch (OutOfMemoryError oom)
4926 } catch (Exception x)
4931 + (sourceType != null
4932 ? (sourceType == DataSourceType.PASTE
4934 : "using " + sourceType + " from "
4938 ? "(parsing as '" + format + "' file)"
4940 oom, Desktop.getDesktopPane());
4945 * Do all updates necessary after an annotation file such as jnet. Also called
4946 * from Jalview.loadAppletParams for "annotations", "jnetFile"
4948 public void updateForAnnotations()
4950 alignPanel.adjustAnnotationHeight();
4951 viewport.updateSequenceIdColours();
4952 buildSortByAnnotationScoresMenu();
4953 alignPanel.paintAlignment(true, true);
4957 * Method invoked by the ChangeListener on the tabbed pane, in other words
4958 * when a different tabbed pane is selected by the user or programmatically.
4961 public void tabSelectionChanged(int index)
4965 alignPanel = alignPanels.get(index);
4966 viewport = alignPanel.av;
4967 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
4968 setMenusFromViewport(viewport);
4969 if (featureSettings != null && featureSettings.isOpen()
4970 && featureSettings.fr.getViewport() != viewport)
4972 if (viewport.isShowSequenceFeatures())
4974 // refresh the featureSettings to reflect UI change
4975 showFeatureSettingsUI();
4979 // close feature settings for this view.
4980 featureSettings.close();
4987 * 'focus' any colour slider that is open to the selected viewport
4989 if (viewport.getConservationSelected())
4991 SliderPanel.setConservationSlider(alignPanel,
4992 viewport.getResidueShading(), alignPanel.getViewName());
4996 SliderPanel.hideConservationSlider();
4998 if (viewport.getAbovePIDThreshold())
5000 SliderPanel.setPIDSliderSource(alignPanel,
5001 viewport.getResidueShading(), alignPanel.getViewName());
5005 SliderPanel.hidePIDSlider();
5009 * If there is a frame linked to this one in a SplitPane, switch it to the
5010 * same view tab index. No infinite recursion of calls should happen, since
5011 * tabSelectionChanged() should not get invoked on setting the selected
5012 * index to an unchanged value. Guard against setting an invalid index
5013 * before the new view peer tab has been created.
5015 final AlignViewportI peer = viewport.getCodingComplement();
5018 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
5019 .getAlignPanel().alignFrame;
5020 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5022 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5028 * On right mouse click on view tab, prompt for and set new view name.
5031 public void tabbedPane_mousePressed(MouseEvent e)
5033 if (e.isPopupTrigger())
5035 String msg = MessageManager.getString("label.enter_view_name");
5036 String ttl = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
5037 String reply = JvOptionPane.showInputDialog(msg, ttl);
5041 viewport.setViewName(reply);
5042 // TODO warn if reply is in getExistingViewNames()?
5043 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5048 public AlignViewport getCurrentView()
5054 * Change the display state for the given feature groups -- Added by BH from
5058 * list of group strings
5060 * visible or invisible
5062 public void setFeatureGroupState(String[] groups, boolean state)
5064 jalview.api.FeatureRenderer fr = null;
5065 viewport.setShowSequenceFeatures(true);
5066 if (alignPanel != null
5067 && (fr = alignPanel.getFeatureRenderer()) != null)
5070 fr.setGroupVisibility(Arrays.asList(groups), state);
5071 alignPanel.getSeqPanel().seqCanvas.repaint();
5072 if (alignPanel.overviewPanel != null)
5074 alignPanel.overviewPanel.updateOverviewImage();
5080 * Open the dialog for regex description parsing.
5083 protected void extractScores_actionPerformed(ActionEvent e)
5085 ParseProperties pp = new jalview.analysis.ParseProperties(
5086 viewport.getAlignment());
5087 // TODO: verify regex and introduce GUI dialog for version 2.5
5088 // if (pp.getScoresFromDescription("col", "score column ",
5089 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5091 if (pp.getScoresFromDescription("description column",
5092 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5094 buildSortByAnnotationScoresMenu();
5102 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5106 protected void showDbRefs_actionPerformed(ActionEvent e)
5108 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5114 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5118 protected void showNpFeats_actionPerformed(ActionEvent e)
5120 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5124 * find the viewport amongst the tabs in this alignment frame and close that
5129 public boolean closeView(AlignViewportI av)
5133 this.closeMenuItem_actionPerformed(false);
5136 Component[] comp = tabbedPane.getComponents();
5137 for (int i = 0; comp != null && i < comp.length; i++)
5139 if (comp[i] instanceof AlignmentPanel)
5141 if (((AlignmentPanel) comp[i]).av == av)
5144 closeView((AlignmentPanel) comp[i]);
5152 protected void build_fetchdbmenu(JMenu webService)
5154 // Temporary hack - DBRef Fetcher always top level ws entry.
5155 // TODO We probably want to store a sequence database checklist in
5156 // preferences and have checkboxes.. rather than individual sources selected
5158 final JMenu rfetch = new JMenu(
5159 MessageManager.getString("action.fetch_db_references"));
5160 rfetch.setToolTipText(MessageManager.getString(
5161 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5162 webService.add(rfetch);
5164 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5165 MessageManager.getString("option.trim_retrieved_seqs"));
5166 trimrs.setToolTipText(
5167 MessageManager.getString("label.trim_retrieved_sequences"));
5169 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5170 trimrs.addActionListener(new ActionListener()
5173 public void actionPerformed(ActionEvent e)
5175 trimrs.setSelected(trimrs.isSelected());
5176 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5177 Boolean.valueOf(trimrs.isSelected()).toString());
5181 JMenuItem fetchr = new JMenuItem(
5182 MessageManager.getString("label.standard_databases"));
5183 fetchr.setToolTipText(
5184 MessageManager.getString("label.fetch_embl_uniprot"));
5185 fetchr.addActionListener(new ActionListener()
5189 public void actionPerformed(ActionEvent e)
5191 new Thread(new Runnable()
5196 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5197 .getAlignment().isNucleotide();
5198 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5199 alignPanel.av.getSequenceSelection(),
5200 alignPanel.alignFrame, null,
5201 alignPanel.alignFrame.featureSettings, isNucleotide);
5202 dbRefFetcher.addListener(new FetchFinishedListenerI()
5205 public void finished()
5208 for (FeatureSettingsModelI srcSettings : dbRefFetcher
5209 .getFeatureSettingsModels())
5212 alignPanel.av.mergeFeaturesStyle(srcSettings);
5214 AlignFrame.this.setMenusForViewport();
5217 dbRefFetcher.fetchDBRefs(false);
5225 Jalview.execThread(new Thread(new Runnable()
5230 Jalview.execRunnable(new Runnable()
5235 String[] dbclasses = jalview.ws.SequenceFetcher.getInstance()
5236 .getNonAlignmentSources();
5237 List<DbSourceProxy> otherdb;
5238 JMenu dfetch = new JMenu();
5239 JMenu ifetch = new JMenu();
5240 JMenuItem fetchr = null;
5241 int comp = 0, icomp = 0, mcomp = 15;
5242 String mname = null;
5244 for (String dbclass : dbclasses)
5246 otherdb = jalview.ws.SequenceFetcher.getInstance()
5247 .getSourceProxy(dbclass);
5248 // add a single entry for this class, or submenu allowing 'fetch
5250 if (otherdb == null || otherdb.size() < 1)
5256 mname = "From " + dbclass;
5258 if (otherdb.size() == 1)
5261 DbSourceProxy src = otherdb.get(0);
5262 DbSourceProxy[] dassource = new DbSourceProxy[] {
5264 fetchr = new JMenuItem(src.getDbSource());
5265 fetchr.addActionListener(new ActionListener()
5269 public void actionPerformed(ActionEvent e)
5271 new Thread(new Runnable()
5277 boolean isNucleotide = alignPanel.alignFrame
5278 .getViewport().getAlignment()
5280 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5281 alignPanel.av.getSequenceSelection(),
5282 alignPanel.alignFrame, dassource,
5283 alignPanel.alignFrame.featureSettings,
5286 .addListener(new FetchFinishedListenerI()
5289 public void finished()
5291 FeatureSettingsModelI srcSettings = dassource[0]
5292 .getFeatureColourScheme();
5293 alignPanel.av.mergeFeaturesStyle(
5295 AlignFrame.this.setMenusForViewport();
5298 dbRefFetcher.fetchDBRefs(false);
5304 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5305 MessageManager.formatMessage(
5306 "label.fetch_retrieve_from", new Object[]
5307 { src.getDbName() })));
5313 final DbSourceProxy[] dassource = otherdb
5314 .toArray(new DbSourceProxy[0]);
5316 DbSourceProxy src = otherdb.get(0);
5317 fetchr = new JMenuItem(MessageManager
5318 .formatMessage("label.fetch_all_param", new Object[]
5319 { src.getDbSource() }));
5320 fetchr.addActionListener(new ActionListener()
5323 public void actionPerformed(ActionEvent e)
5325 new Thread(new Runnable()
5331 boolean isNucleotide = alignPanel.alignFrame
5332 .getViewport().getAlignment()
5334 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5335 alignPanel.av.getSequenceSelection(),
5336 alignPanel.alignFrame, dassource,
5337 alignPanel.alignFrame.featureSettings,
5340 .addListener(new FetchFinishedListenerI()
5343 public void finished()
5345 AlignFrame.this.setMenusForViewport();
5348 dbRefFetcher.fetchDBRefs(false);
5354 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5355 MessageManager.formatMessage(
5356 "label.fetch_retrieve_from_all_sources",
5358 { Integer.valueOf(otherdb.size())
5360 src.getDbSource(), src.getDbName() })));
5363 // and then build the rest of the individual menus
5364 ifetch = new JMenu(MessageManager.formatMessage(
5365 "label.source_from_db_source", new Object[]
5366 { src.getDbSource() }));
5368 String imname = null;
5370 for (DbSourceProxy sproxy : otherdb)
5372 String dbname = sproxy.getDbName();
5373 String sname = dbname.length() > 5
5374 ? dbname.substring(0, 5) + "..."
5376 String msname = dbname.length() > 10
5377 ? dbname.substring(0, 10) + "..."
5381 imname = MessageManager
5382 .formatMessage("label.from_msname", new Object[]
5385 fetchr = new JMenuItem(msname);
5386 final DbSourceProxy[] dassrc = { sproxy };
5387 fetchr.addActionListener(new ActionListener()
5391 public void actionPerformed(ActionEvent e)
5393 new Thread(new Runnable()
5399 boolean isNucleotide = alignPanel.alignFrame
5400 .getViewport().getAlignment()
5402 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5403 alignPanel.av.getSequenceSelection(),
5404 alignPanel.alignFrame, dassrc,
5405 alignPanel.alignFrame.featureSettings,
5408 .addListener(new FetchFinishedListenerI()
5411 public void finished()
5413 AlignFrame.this.setMenusForViewport();
5416 dbRefFetcher.fetchDBRefs(false);
5422 fetchr.setToolTipText(
5423 "<html>" + MessageManager.formatMessage(
5424 "label.fetch_retrieve_from", new Object[]
5428 if (++icomp >= mcomp || i == (otherdb.size()))
5430 ifetch.setText(MessageManager.formatMessage(
5431 "label.source_to_target", imname, sname));
5433 ifetch = new JMenu();
5441 if (comp >= mcomp || dbi >= (dbclasses.length))
5443 dfetch.setText(MessageManager.formatMessage(
5444 "label.source_to_target", mname, dbclass));
5446 dfetch = new JMenu();
5459 * Left justify the whole alignment.
5462 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5464 AlignmentI al = viewport.getAlignment();
5466 viewport.firePropertyChange("alignment", null, al);
5470 * Right justify the whole alignment.
5473 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5475 AlignmentI al = viewport.getAlignment();
5477 viewport.firePropertyChange("alignment", null, al);
5481 public void setShowSeqFeatures(boolean b)
5483 showSeqFeatures.setSelected(b);
5484 viewport.setShowSequenceFeatures(b);
5491 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5492 * awt.event.ActionEvent)
5495 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5497 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5498 alignPanel.paintAlignment(false, false);
5505 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5509 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5511 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5512 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5520 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5521 * .event.ActionEvent)
5524 protected void showGroupConservation_actionPerformed(ActionEvent e)
5526 viewport.setShowGroupConservation(showGroupConservation.getState());
5527 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5534 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5535 * .event.ActionEvent)
5538 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5540 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5541 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5548 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5549 * .event.ActionEvent)
5552 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5554 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5555 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5559 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5561 showSequenceLogo.setState(true);
5562 viewport.setShowSequenceLogo(true);
5563 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5564 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5568 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5570 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5577 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5578 * .event.ActionEvent)
5581 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5583 if (avc.makeGroupsFromSelection())
5585 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5586 alignPanel.updateAnnotation();
5587 alignPanel.paintAlignment(true,
5588 viewport.needToUpdateStructureViews());
5592 public void clearAlignmentSeqRep()
5594 // TODO refactor alignmentseqrep to controller
5595 if (viewport.getAlignment().hasSeqrep())
5597 viewport.getAlignment().setSeqrep(null);
5598 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5599 alignPanel.updateAnnotation();
5600 alignPanel.paintAlignment(true, true);
5605 protected void createGroup_actionPerformed(ActionEvent e)
5607 if (avc.createGroup())
5609 if (applyAutoAnnotationSettings.isSelected())
5611 alignPanel.updateAnnotation(true, false);
5613 alignPanel.alignmentChanged();
5618 protected void unGroup_actionPerformed(ActionEvent e)
5622 alignPanel.alignmentChanged();
5627 * make the given alignmentPanel the currently selected tab
5629 * @param alignmentPanel
5631 public void setDisplayedView(AlignmentPanel alignmentPanel)
5633 if (!viewport.getSequenceSetId()
5634 .equals(alignmentPanel.av.getSequenceSetId()))
5636 throw new Error(MessageManager.getString(
5637 "error.implementation_error_cannot_show_view_alignment_frame"));
5639 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5640 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5642 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5647 * Action on selection of menu options to Show or Hide annotations.
5650 * @param forSequences
5651 * update sequence-related annotations
5652 * @param forAlignment
5653 * update non-sequence-related annotations
5656 protected void setAnnotationsVisibility(boolean visible,
5657 boolean forSequences, boolean forAlignment)
5659 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5660 .getAlignmentAnnotation();
5665 for (AlignmentAnnotation aa : anns)
5668 * don't display non-positional annotations on an alignment
5670 if (aa.annotations == null)
5674 boolean apply = (aa.sequenceRef == null && forAlignment)
5675 || (aa.sequenceRef != null && forSequences);
5678 aa.visible = visible;
5681 alignPanel.validateAnnotationDimensions(true);
5682 alignPanel.alignmentChanged();
5686 * Store selected annotation sort order for the view and repaint.
5689 protected void sortAnnotations_actionPerformed()
5691 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5693 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5694 alignPanel.paintAlignment(false, false);
5699 * @return alignment panels in this alignment frame
5701 public List<? extends AlignmentViewPanel> getAlignPanels()
5703 // alignPanels is never null
5704 // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5709 * Open a new alignment window, with the cDNA associated with this (protein)
5710 * alignment, aligned as is the protein.
5712 protected void viewAsCdna_actionPerformed()
5714 // TODO no longer a menu action - refactor as required
5715 final AlignmentI alignment = getViewport().getAlignment();
5716 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5717 if (mappings == null)
5721 List<SequenceI> cdnaSeqs = new ArrayList<>();
5722 for (SequenceI aaSeq : alignment.getSequences())
5724 for (AlignedCodonFrame acf : mappings)
5726 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5730 * There is a cDNA mapping for this protein sequence - add to new
5731 * alignment. It will share the same dataset sequence as other mapped
5732 * cDNA (no new mappings need to be created).
5734 final Sequence newSeq = new Sequence(dnaSeq);
5735 newSeq.setDatasetSequence(dnaSeq);
5736 cdnaSeqs.add(newSeq);
5740 if (cdnaSeqs.size() == 0)
5742 // show a warning dialog no mapped cDNA
5745 AlignmentI cdna = new Alignment(
5746 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5747 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5748 AlignFrame.DEFAULT_HEIGHT);
5749 cdna.alignAs(alignment);
5750 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5752 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5753 AlignFrame.DEFAULT_HEIGHT);
5757 * Set visibility of dna/protein complement view (available when shown in a
5763 protected void showComplement_actionPerformed(boolean show)
5765 SplitContainerI sf = getSplitViewContainer();
5768 sf.setComplementVisible(this, show);
5773 * Generate the reverse (optionally complemented) of the selected sequences,
5774 * and add them to the alignment
5777 protected void showReverse_actionPerformed(boolean complement)
5779 AlignmentI al = null;
5782 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5783 al = dna.reverseCdna(complement);
5784 viewport.addAlignment(al, "");
5785 addHistoryItem(new EditCommand(
5786 MessageManager.getString("label.add_sequences"), Action.PASTE,
5787 al.getSequencesArray(), 0, al.getWidth(),
5788 viewport.getAlignment()));
5789 } catch (Exception ex)
5791 System.err.println(ex.getMessage());
5797 * Try to run a script in the Groovy console, having first ensured that this
5798 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5799 * be targeted at this alignment.
5802 protected void runGroovy_actionPerformed()
5804 Jalview.setCurrentAlignFrame(this);
5805 groovy.ui.Console console = Desktop.getGroovyConsole();
5806 if (console != null)
5810 console.runScript();
5811 } catch (Exception ex)
5813 System.err.println((ex.toString()));
5814 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
5815 MessageManager.getString("label.couldnt_run_groovy_script"),
5816 MessageManager.getString("label.groovy_support_failed"),
5817 JvOptionPane.ERROR_MESSAGE);
5822 System.err.println("Can't run Groovy script as console not found");
5827 * Hides columns containing (or not containing) a specified feature, provided
5828 * that would not leave all columns hidden
5830 * @param featureType
5831 * @param columnsContaining
5834 public boolean hideFeatureColumns(String featureType,
5835 boolean columnsContaining)
5837 boolean notForHiding = avc.markColumnsContainingFeatures(
5838 columnsContaining, false, false, featureType);
5841 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5842 false, featureType))
5844 getViewport().hideSelectedColumns();
5852 protected void selectHighlightedColumns_actionPerformed(
5853 ActionEvent actionEvent)
5855 // include key modifier check in case user selects from menu
5856 avc.markHighlightedColumns(
5857 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5858 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5859 | ActionEvent.CTRL_MASK)) != 0);
5863 * Rebuilds the Colour menu, including any user-defined colours which have
5864 * been loaded either on startup or during the session
5866 public void buildColourMenu()
5868 colourMenu.removeAll();
5870 colourMenu.add(applyToAllGroups);
5871 colourMenu.add(textColour);
5872 colourMenu.addSeparator();
5874 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
5875 viewport.getAlignment(), false);
5877 colourMenu.add(annotationColour);
5878 bg.add(annotationColour);
5879 colourMenu.addSeparator();
5880 colourMenu.add(conservationMenuItem);
5881 colourMenu.add(modifyConservation);
5882 colourMenu.add(abovePIDThreshold);
5883 colourMenu.add(modifyPID);
5885 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5886 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5890 * Open a dialog (if not already open) that allows the user to select and
5891 * calculate PCA or Tree analysis
5893 protected void openTreePcaDialog()
5895 if (alignPanel.getCalculationDialog() == null)
5897 new CalculationChooser(AlignFrame.this);
5902 protected void loadVcf_actionPerformed()
5904 JalviewFileChooser chooser = new JalviewFileChooser(
5905 Cache.getProperty("LAST_DIRECTORY"));
5906 chooser.setFileView(new JalviewFileView());
5907 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
5908 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
5909 final AlignFrame us = this;
5910 chooser.setResponseHandler(0, new Runnable()
5915 String choice = chooser.getSelectedFile().getPath();
5916 Cache.setProperty("LAST_DIRECTORY", choice);
5917 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
5918 new VCFLoader(choice).loadVCF(seqs, us);
5921 chooser.showOpenDialog(null);
5926 private Rectangle lastFeatureSettingsBounds = null;
5928 public void setFeatureSettingsGeometry(Rectangle bounds)
5930 lastFeatureSettingsBounds = bounds;
5934 public Rectangle getFeatureSettingsGeometry()
5936 return lastFeatureSettingsBounds;
5940 * BH 2019 from JalviewLite
5942 * get sequence feature groups that are hidden or shown
5948 public String[] getFeatureGroupsOfState(boolean visible)
5950 jalview.api.FeatureRenderer fr = null;
5951 if (alignPanel != null
5953 .getFeatureRenderer()) != null)
5955 List<String> gps = fr.getGroups(visible);
5956 String[] _gps = gps.toArray(new String[gps.size()]);
5962 public void scrollTo(int row, int column)
5964 alignPanel.getSeqPanel().scrollTo(row, column);
5967 public void scrollToRow(int row)
5969 alignPanel.getSeqPanel().scrollToRow(row);
5972 public void scrollToColumn(int column)
5974 alignPanel.getSeqPanel().scrollToColumn(column);
5979 * @return list of feature groups on the view
5981 public String[] getFeatureGroups()
5983 jalview.api.FeatureRenderer fr = null;
5984 if (alignPanel != null
5985 && (fr = alignPanel.getFeatureRenderer()) != null)
5987 List<String> gps = fr.getFeatureGroups();
5988 String[] _gps = gps.toArray(new String[gps.size()]);
5994 public void select(SequenceGroup sel, ColumnSelection csel,
5995 HiddenColumns hidden)
5997 alignPanel.getSeqPanel().selection(sel, csel, hidden, null);
6002 class PrintThread extends Thread
6006 public PrintThread(AlignmentPanel ap)
6011 static PageFormat pf;
6016 PrinterJob printJob = PrinterJob.getPrinterJob();
6020 printJob.setPrintable(ap, pf);
6024 printJob.setPrintable(ap);
6027 if (printJob.printDialog())
6032 } catch (Exception PrintException)
6034 PrintException.printStackTrace();