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.AlignViewControllerGuiI;
32 import jalview.api.AlignViewControllerI;
33 import jalview.api.AlignViewportI;
34 import jalview.api.AlignmentViewPanel;
35 import jalview.api.FeatureSettingsControllerI;
36 import jalview.api.FeatureSettingsModelI;
37 import jalview.api.SplitContainerI;
38 import jalview.api.ViewStyleI;
39 import jalview.api.analysis.SimilarityParamsI;
40 import jalview.bin.Cache;
41 import jalview.bin.Jalview;
42 import jalview.commands.CommandI;
43 import jalview.commands.EditCommand;
44 import jalview.commands.EditCommand.Action;
45 import jalview.commands.OrderCommand;
46 import jalview.commands.RemoveGapColCommand;
47 import jalview.commands.RemoveGapsCommand;
48 import jalview.commands.SlideSequencesCommand;
49 import jalview.commands.TrimRegionCommand;
50 import jalview.datamodel.AlignExportSettingsAdapter;
51 import jalview.datamodel.AlignedCodonFrame;
52 import jalview.datamodel.Alignment;
53 import jalview.datamodel.AlignmentAnnotation;
54 import jalview.datamodel.AlignmentExportData;
55 import jalview.datamodel.AlignmentI;
56 import jalview.datamodel.AlignmentOrder;
57 import jalview.datamodel.AlignmentView;
58 import jalview.datamodel.ColumnSelection;
59 import jalview.datamodel.HiddenColumns;
60 import jalview.datamodel.PDBEntry;
61 import jalview.datamodel.SeqCigar;
62 import jalview.datamodel.Sequence;
63 import jalview.datamodel.SequenceGroup;
64 import jalview.datamodel.SequenceI;
65 import jalview.gui.ColourMenuHelper.ColourChangeListener;
66 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
67 import jalview.io.AlignmentProperties;
68 import jalview.io.AnnotationFile;
69 import jalview.io.BackupFiles;
70 import jalview.io.BioJsHTMLOutput;
71 import jalview.io.DataSourceType;
72 import jalview.io.FileFormat;
73 import jalview.io.FileFormatI;
74 import jalview.io.FileFormats;
75 import jalview.io.FileLoader;
76 import jalview.io.FileParse;
77 import jalview.io.FormatAdapter;
78 import jalview.io.HtmlSvgOutput;
79 import jalview.io.IdentifyFile;
80 import jalview.io.JPredFile;
81 import jalview.io.JalviewFileChooser;
82 import jalview.io.JalviewFileView;
83 import jalview.io.JnetAnnotationMaker;
84 import jalview.io.NewickFile;
85 import jalview.io.ScoreMatrixFile;
86 import jalview.io.TCoffeeScoreFile;
87 import jalview.io.vcf.VCFLoader;
88 import jalview.jbgui.GAlignFrame;
89 import jalview.project.Jalview2XML;
90 import jalview.schemes.ColourSchemeI;
91 import jalview.schemes.ColourSchemes;
92 import jalview.schemes.ResidueColourScheme;
93 import jalview.schemes.TCoffeeColourScheme;
94 import jalview.util.ImageMaker.TYPE;
95 import jalview.util.MessageManager;
96 import jalview.util.Platform;
97 import jalview.viewmodel.AlignmentViewport;
98 import jalview.viewmodel.ViewportRanges;
99 import jalview.ws.DBRefFetcher;
100 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
101 import jalview.ws.jws1.Discoverer;
102 import jalview.ws.jws2.Jws2Discoverer;
103 import jalview.ws.jws2.jabaws2.Jws2Instance;
104 import jalview.ws.seqfetcher.DbSourceProxy;
106 import java.awt.BorderLayout;
107 import java.awt.Color;
108 import java.awt.Component;
109 import java.awt.Dimension;
110 import java.awt.Rectangle;
111 import java.awt.Toolkit;
112 import java.awt.datatransfer.Clipboard;
113 import java.awt.datatransfer.DataFlavor;
114 import java.awt.datatransfer.StringSelection;
115 import java.awt.datatransfer.Transferable;
116 import java.awt.dnd.DnDConstants;
117 import java.awt.dnd.DropTargetDragEvent;
118 import java.awt.dnd.DropTargetDropEvent;
119 import java.awt.dnd.DropTargetEvent;
120 import java.awt.dnd.DropTargetListener;
121 import java.awt.event.ActionEvent;
122 import java.awt.event.ActionListener;
123 import java.awt.event.FocusAdapter;
124 import java.awt.event.FocusEvent;
125 import java.awt.event.ItemEvent;
126 import java.awt.event.ItemListener;
127 import java.awt.event.KeyAdapter;
128 import java.awt.event.KeyEvent;
129 import java.awt.event.MouseEvent;
130 import java.awt.print.PageFormat;
131 import java.awt.print.PrinterJob;
132 import java.beans.PropertyChangeEvent;
134 import java.io.FileWriter;
135 import java.io.PrintWriter;
137 import java.util.ArrayList;
138 import java.util.Arrays;
139 import java.util.Deque;
140 import java.util.Enumeration;
141 import java.util.Hashtable;
142 import java.util.List;
143 import java.util.Vector;
145 import javax.swing.ButtonGroup;
146 import javax.swing.JCheckBoxMenuItem;
147 import javax.swing.JComponent;
148 import javax.swing.JEditorPane;
149 import javax.swing.JInternalFrame;
150 import javax.swing.JLabel;
151 import javax.swing.JLayeredPane;
152 import javax.swing.JMenu;
153 import javax.swing.JMenuItem;
154 import javax.swing.JPanel;
155 import javax.swing.JScrollPane;
156 import javax.swing.SwingUtilities;
158 import ext.vamsas.ServiceHandle;
164 * @version $Revision$
166 @SuppressWarnings("serial")
167 public class AlignFrame extends GAlignFrame implements DropTargetListener,
168 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
171 public static int frameCount;
173 public static final int DEFAULT_WIDTH = 700;
175 public static final int DEFAULT_HEIGHT = 500;
178 * The currently displayed panel (selected tabbed view if more than one)
180 public AlignmentPanel alignPanel;
182 AlignViewport viewport;
184 public AlignViewControllerI avc;
186 List<AlignmentPanel> alignPanels = new ArrayList<>();
189 * Last format used to load or save alignments in this window
191 FileFormatI currentFileFormat = null;
194 * Current filename for this alignment
196 String fileName = null;
202 private DataSourceType protocol ;
205 * Creates a new AlignFrame object with specific width and height.
211 public AlignFrame(AlignmentI al, int width, int height)
213 this(al, null, width, height);
217 * Creates a new AlignFrame object with specific width, height and
223 * @param sequenceSetId
225 public AlignFrame(AlignmentI al, int width, int height,
226 String sequenceSetId)
228 this(al, null, width, height, sequenceSetId);
232 * Creates a new AlignFrame object with specific width, height and
238 * @param sequenceSetId
241 public AlignFrame(AlignmentI al, int width, int height,
242 String sequenceSetId, String viewId)
244 this(al, null, width, height, sequenceSetId, viewId);
248 * new alignment window with hidden columns
252 * @param hiddenColumns
253 * ColumnSelection or null
255 * Width of alignment frame
259 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
262 this(al, hiddenColumns, width, height, null);
266 * Create alignment frame for al with hiddenColumns, a specific width and
267 * height, and specific sequenceId
270 * @param hiddenColumns
273 * @param sequenceSetId
276 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
277 int height, String sequenceSetId)
279 this(al, hiddenColumns, width, height, sequenceSetId, null);
283 * Create alignment frame for al with hiddenColumns, a specific width and
284 * height, and specific sequenceId
287 * @param hiddenColumns
290 * @param sequenceSetId
295 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
296 int height, String sequenceSetId, String viewId)
301 setSize(width, height);
303 if (al.getDataset() == null)
308 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
310 // JalviewJS needs to distinguish a new panel from an old one in init()
311 // alignPanel = new AlignmentPanel(this, viewport);
312 // addAlignmentPanel(alignPanel, true);
316 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
317 HiddenColumns hiddenColumns, int width, int height)
319 setSize(width, height);
321 if (al.getDataset() == null)
326 viewport = new AlignViewport(al, hiddenColumns);
328 if (hiddenSeqs != null && hiddenSeqs.length > 0)
330 viewport.hideSequence(hiddenSeqs);
332 // alignPanel = new AlignmentPanel(this, viewport);
333 // addAlignmentPanel(alignPanel, true);
338 * Make a new AlignFrame from existing alignmentPanels
345 public AlignFrame(AlignmentPanel ap)
349 // addAlignmentPanel(ap, false);
354 * initalise the alignframe from the underlying viewport data and the
361 boolean newPanel = (alignPanel == null);
362 viewport.setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
367 // need to set this up front if NOANNOTATION is
368 // used in conjunction with SHOWOVERVIEW.
370 // I have not determined if this is appropriate for
371 // Jalview/Java, as it means we are setting this flag
372 // for all subsequent AlignFrames. For now, at least,
373 // I am setting it to be JalviewJS-only.
375 boolean showAnnotation = Jalview.getInstance().getShowAnnotation();
376 viewport.setShowAnnotation(showAnnotation);
378 alignPanel = new AlignmentPanel(this, viewport);
380 addAlignmentPanel(alignPanel, newPanel);
382 // setBackground(Color.white); // BH 2019
384 if (!Jalview.isHeadlessMode())
386 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
388 statusPanel.setVisible(Jalview.getInstance().getShowStatus());
389 alignFrameMenuBar.setVisible(Jalview.getInstance().getAllowMenuBar());
392 avc = new jalview.controller.AlignViewController(this, viewport,
394 if (viewport.getAlignmentConservationAnnotation() == null)
396 // BLOSUM62Colour.setEnabled(false);
397 conservationMenuItem.setEnabled(false);
398 modifyConservation.setEnabled(false);
399 // PIDColour.setEnabled(false);
400 // abovePIDThreshold.setEnabled(false);
401 // modifyPID.setEnabled(false);
404 String sortby = jalview.bin.Cache.getDefault(Preferences.SORT_ALIGNMENT,
407 if (sortby.equals("Id"))
409 sortIDMenuItem_actionPerformed(null);
411 else if (sortby.equals("Pairwise Identity"))
413 sortPairwiseMenuItem_actionPerformed(null);
418 // this.alignPanel.av
419 // .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
421 setMenusFromViewport(viewport);
422 buildSortByAnnotationScoresMenu();
423 calculateTree.addActionListener(new ActionListener()
427 public void actionPerformed(ActionEvent e)
434 if (Desktop.getDesktopPane() != null)
436 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
437 if (!Platform.isJS())
439 addServiceListeners();
444 if (viewport.getWrapAlignment())
446 wrapMenuItem_actionPerformed(null);
449 if (jalview.bin.Cache.getDefault(Preferences.SHOW_OVERVIEW, false))
451 this.overviewMenuItem_actionPerformed(null);
456 final List<AlignmentPanel> selviews = new ArrayList<>();
457 final List<AlignmentPanel> origview = new ArrayList<>();
458 final String menuLabel = MessageManager
459 .getString("label.copy_format_from");
460 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
461 new ViewSetProvider()
465 public AlignmentPanel[] getAllAlignmentPanels()
468 origview.add(alignPanel);
469 // make an array of all alignment panels except for this one
470 List<AlignmentPanel> aps = new ArrayList<>(
471 Arrays.asList(Desktop.getAlignmentPanels(null)));
472 aps.remove(AlignFrame.this.alignPanel);
473 return aps.toArray(new AlignmentPanel[aps.size()]);
475 }, selviews, new ItemListener()
479 public void itemStateChanged(ItemEvent e)
481 if (origview.size() > 0)
483 final AlignmentPanel ap = origview.get(0);
486 * Copy the ViewStyle of the selected panel to 'this one'.
487 * Don't change value of 'scaleProteinAsCdna' unless copying
490 ViewStyleI vs = selviews.get(0).getAlignViewport()
492 boolean fromSplitFrame = selviews.get(0)
493 .getAlignViewport().getCodingComplement() != null;
496 vs.setScaleProteinAsCdna(ap.getAlignViewport()
497 .getViewStyle().isScaleProteinAsCdna());
499 ap.getAlignViewport().setViewStyle(vs);
502 * Also rescale ViewStyle of SplitFrame complement if there is
503 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
504 * the whole ViewStyle (allow cDNA protein to have different
507 AlignViewportI complement = ap.getAlignViewport()
508 .getCodingComplement();
509 if (complement != null && vs.isScaleProteinAsCdna())
511 AlignFrame af = Desktop.getAlignFrameFor(complement);
512 ((SplitFrame) af.getSplitViewContainer())
514 af.setMenusForViewport();
518 ap.setSelected(true);
519 ap.alignFrame.setMenusForViewport();
524 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
525 .indexOf("devel") > -1
526 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
527 .indexOf("test") > -1)
529 formatMenu.add(vsel);
531 addFocusListener(new FocusAdapter()
535 public void focusGained(FocusEvent e)
537 Jalview.setCurrentAlignFrame(AlignFrame.this);
544 * Change the filename and format for the alignment, and enable the 'reload'
545 * button functionality.
554 public void setFileName(String file, FileFormatI format)
557 setFileFormat(format);
558 reload.setEnabled(true);
564 * @param file from SwingJS; may contain bytes -- for reload
565 * @param protocol from SwingJS; may be RELATIVE_URL
568 public void setFile(String fileName, File file, DataSourceType protocol, FileFormatI format)
570 this.fileName = fileName;
571 this.fileObject = file;
572 this.protocol = protocol;
573 setFileFormat(format);
574 reload.setEnabled(true);
578 * JavaScript will have this, maybe others. More dependable than a file name
579 * and maintains a reference to the actual bytes loaded.
584 public void setFileObject(File file)
586 this.fileObject = file;
590 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
594 void addKeyListener()
596 addKeyListener(new KeyAdapter()
600 public void keyPressed(KeyEvent evt)
602 if (viewport.cursorMode
603 && ((evt.getKeyCode() >= KeyEvent.VK_0
604 && evt.getKeyCode() <= KeyEvent.VK_9)
605 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
606 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
607 && Character.isDigit(evt.getKeyChar()))
609 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
612 switch (evt.getKeyCode())
615 case KeyEvent.VK_ESCAPE: // escape key
616 // alignPanel.deselectAllSequences();
617 alignPanel.deselectAllSequences();
621 case KeyEvent.VK_DOWN:
622 if (evt.isAltDown() || !viewport.cursorMode)
624 moveSelectedSequences(false);
626 if (viewport.cursorMode)
628 alignPanel.getSeqPanel().moveCursor(0, 1);
633 if (evt.isAltDown() || !viewport.cursorMode)
635 moveSelectedSequences(true);
637 if (viewport.cursorMode)
639 alignPanel.getSeqPanel().moveCursor(0, -1);
644 case KeyEvent.VK_LEFT:
645 if (evt.isAltDown() || !viewport.cursorMode)
647 slideSequences(false,
648 alignPanel.getSeqPanel().getKeyboardNo1());
652 alignPanel.getSeqPanel().moveCursor(-1, 0);
657 case KeyEvent.VK_RIGHT:
658 if (evt.isAltDown() || !viewport.cursorMode)
660 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
664 alignPanel.getSeqPanel().moveCursor(1, 0);
668 case KeyEvent.VK_SPACE:
669 if (viewport.cursorMode)
671 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
672 || evt.isShiftDown() || evt.isAltDown());
676 // case KeyEvent.VK_A:
677 // if (viewport.cursorMode)
679 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
680 // //System.out.println("A");
684 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
685 * System.out.println("closing bracket"); } break;
687 case KeyEvent.VK_DELETE:
688 case KeyEvent.VK_BACK_SPACE:
689 if (!viewport.cursorMode)
691 cut_actionPerformed();
695 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
696 || evt.isShiftDown() || evt.isAltDown());
702 if (viewport.cursorMode)
704 alignPanel.getSeqPanel().setCursorRow();
708 if (viewport.cursorMode && !evt.isControlDown())
710 alignPanel.getSeqPanel().setCursorColumn();
714 if (viewport.cursorMode)
716 alignPanel.getSeqPanel().setCursorPosition();
720 case KeyEvent.VK_ENTER:
721 case KeyEvent.VK_COMMA:
722 if (viewport.cursorMode)
724 alignPanel.getSeqPanel().setCursorRowAndColumn();
729 if (viewport.cursorMode)
731 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
735 if (viewport.cursorMode)
737 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
742 viewport.cursorMode = !viewport.cursorMode;
743 setStatus(MessageManager
744 .formatMessage("label.keyboard_editing_mode", new String[]
745 { (viewport.cursorMode ? "on" : "off") }));
746 if (viewport.cursorMode)
748 ViewportRanges ranges = viewport.getRanges();
749 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
751 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
754 alignPanel.getSeqPanel().seqCanvas.repaint();
760 Help.showHelpWindow();
761 } catch (Exception ex)
763 ex.printStackTrace();
768 boolean toggleSeqs = !evt.isControlDown();
769 boolean toggleCols = !evt.isShiftDown();
770 toggleHiddenRegions(toggleSeqs, toggleCols);
775 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
776 boolean modifyExisting = true; // always modify, don't clear
777 // evt.isShiftDown();
778 boolean invertHighlighted = evt.isAltDown();
779 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
783 case KeyEvent.VK_PAGE_UP:
784 viewport.getRanges().pageUp();
786 case KeyEvent.VK_PAGE_DOWN:
787 viewport.getRanges().pageDown();
793 public void keyReleased(KeyEvent evt)
795 switch (evt.getKeyCode())
797 case KeyEvent.VK_LEFT:
798 if (evt.isAltDown() || !viewport.cursorMode)
800 viewport.notifyAlignment();
804 case KeyEvent.VK_RIGHT:
805 if (evt.isAltDown() || !viewport.cursorMode)
807 viewport.notifyAlignment();
815 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
817 ap.alignFrame = this;
818 avc = new jalview.controller.AlignViewController(this, viewport,
823 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
825 int aSize = alignPanels.size();
827 tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
829 if (aSize == 1 && ap.av.getViewName() == null)
831 this.getContentPane().add(ap, BorderLayout.CENTER);
837 setInitialTabVisible();
840 expandViews.setEnabled(true);
841 gatherViews.setEnabled(true);
842 tabbedPane.addTab(ap.av.getViewName(), ap);
844 ap.setVisible(false);
849 if (ap.av.isPadGaps())
851 ap.av.getAlignment().padGaps();
853 if (Jalview.getInstance().getStartCalculations())
855 ap.av.updateConservation(ap);
856 ap.av.updateConsensus(ap);
857 ap.av.updateStrucConsensus(ap);
862 public void setInitialTabVisible()
864 expandViews.setEnabled(true);
865 gatherViews.setEnabled(true);
866 tabbedPane.setVisible(true);
867 AlignmentPanel first = alignPanels.get(0);
868 tabbedPane.addTab(first.av.getViewName(), first);
869 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
872 public AlignViewport getViewport()
877 /* Set up intrinsic listeners for dynamically generated GUI bits. */
878 private void addServiceListeners()
880 final java.beans.PropertyChangeListener thisListener;
881 Desktop.getInstance().addJalviewPropertyChangeListener("services",
882 thisListener = new java.beans.PropertyChangeListener()
886 public void propertyChange(PropertyChangeEvent evt)
888 // // System.out.println("Discoverer property change.");
889 // if (evt.getPropertyName().equals("services"))
891 SwingUtilities.invokeLater(new Runnable()
898 "Rebuild WS Menu for service change");
899 BuildWebServiceMenu();
906 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
910 public void internalFrameClosed(
911 javax.swing.event.InternalFrameEvent evt)
913 // System.out.println("deregistering discoverer listener");
914 Desktop.getInstance().removeJalviewPropertyChangeListener(
915 "services", thisListener);
916 closeMenuItem_actionPerformed(true);
919 // Finally, build the menu once to get current service state
920 new Thread(new Runnable()
926 BuildWebServiceMenu();
932 * Configure menu items that vary according to whether the alignment is
933 * nucleotide or protein
936 public void setGUINucleotide()
938 AlignmentI al = getViewport().getAlignment();
939 boolean nucleotide = al.isNucleotide();
941 loadVcf.setVisible(nucleotide);
942 showTranslation.setVisible(nucleotide);
943 showReverse.setVisible(nucleotide);
944 showReverseComplement.setVisible(nucleotide);
945 conservationMenuItem.setEnabled(!nucleotide);
947 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
948 showGroupConservation.setEnabled(!nucleotide);
950 showComplementMenuItem
951 .setText(nucleotide ? MessageManager.getString("label.protein")
952 : MessageManager.getString("label.nucleotide"));
956 * set up menus for the current viewport. This may be called after any
957 * operation that affects the data in the current view (selection changed,
958 * etc) to update the menus to reflect the new state.
962 public void setMenusForViewport()
964 setMenusFromViewport(viewport);
968 * Need to call this method when tabs are selected for multiple views, or when
969 * loading from Jalview2XML.java
975 public void setMenusFromViewport(AlignViewport av)
977 padGapsMenuitem.setSelected(av.isPadGaps());
978 colourTextMenuItem.setSelected(av.isShowColourText());
979 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
980 modifyPID.setEnabled(abovePIDThreshold.isSelected());
981 conservationMenuItem.setSelected(av.getConservationSelected());
982 modifyConservation.setEnabled(conservationMenuItem.isSelected());
983 seqLimits.setSelected(av.getShowJVSuffix());
984 idRightAlign.setSelected(av.isRightAlignIds());
985 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
986 renderGapsMenuItem.setSelected(av.isRenderGaps());
987 wrapMenuItem.setSelected(av.getWrapAlignment());
988 scaleAbove.setVisible(av.getWrapAlignment());
989 scaleLeft.setVisible(av.getWrapAlignment());
990 scaleRight.setVisible(av.getWrapAlignment());
991 annotationPanelMenuItem.setState(av.isShowAnnotation());
992 // Show/hide annotations only enabled if annotation panel is shown
993 syncAnnotationMenuItems(av.isShowAnnotation());
994 viewBoxesMenuItem.setSelected(av.getShowBoxes());
995 viewTextMenuItem.setSelected(av.getShowText());
996 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
997 showGroupConsensus.setSelected(av.isShowGroupConsensus());
998 showGroupConservation.setSelected(av.isShowGroupConservation());
999 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
1000 showSequenceLogo.setSelected(av.isShowSequenceLogo());
1001 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
1003 ColourMenuHelper.setColourSelected(colourMenu,
1004 av.getGlobalColourScheme());
1006 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
1007 hiddenMarkers.setState(av.getShowHiddenMarkers());
1008 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
1009 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
1010 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
1012 .setSelected(av.getAutoCalculateConsensusAndConservation());
1013 sortByTree.setSelected(av.sortByTree);
1014 listenToViewSelections.setSelected(av.followSelection);
1016 showProducts.setEnabled(canShowProducts());
1017 setGroovyEnabled(Desktop.getGroovyConsole() != null);
1019 updateEditMenuBar();
1023 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
1028 public void setGroovyEnabled(boolean b)
1030 runGroovy.setEnabled(b);
1033 private IProgressIndicator progressBar;
1038 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1042 public void setProgressBar(String message, long id)
1044 progressBar.setProgressBar(message, id);
1048 public void registerHandler(final long id,
1049 final IProgressIndicatorHandler handler)
1051 progressBar.registerHandler(id, handler);
1056 * @return true if any progress bars are still active
1060 public boolean operationInProgress()
1062 return progressBar.operationInProgress();
1066 * Sets the text of the status bar. Note that setting a null or empty value
1067 * will cause the status bar to be hidden, with possibly undesirable flicker
1068 * of the screen layout.
1072 public void setStatus(String text)
1074 statusBar.setText(text == null || text.isEmpty() ? " " : text);
1078 * Added so Castor Mapping file can obtain Jalview Version
1081 public String getVersion()
1083 return jalview.bin.Cache.getProperty("VERSION");
1086 public FeatureRenderer getFeatureRenderer()
1088 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1092 public void fetchSequence_actionPerformed()
1094 new SequenceFetcher(this);
1098 public void addFromFile_actionPerformed(ActionEvent e)
1100 Desktop.getInstance().inputLocalFileMenuItem_actionPerformed(viewport);
1104 public void reload_actionPerformed(ActionEvent e)
1106 if (fileName == null && fileObject == null)
1110 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1111 // originating file's format
1112 // TODO: work out how to recover feature settings for correct view(s) when
1113 // file is reloaded.
1114 if (FileFormat.Jalview.equals(currentFileFormat))
1116 JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
1117 for (int i = 0; i < frames.length; i++)
1119 if (frames[i] instanceof AlignFrame && frames[i] != this
1120 && ((AlignFrame) frames[i]).fileName != null
1121 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1125 frames[i].setSelected(true);
1126 Desktop.getInstance().closeAssociatedWindows();
1127 } catch (java.beans.PropertyVetoException ex)
1133 Desktop.getInstance().closeAssociatedWindows();
1135 FileLoader loader = new FileLoader();
1136 // DataSourceType protocol = fileName.startsWith("http:")
1137 // ? DataSourceType.URL
1138 // : DataSourceType.FILE;
1139 loader.LoadFile(viewport, (fileObject == null ? fileName : fileObject), protocol, currentFileFormat);
1143 Rectangle bounds = this.getBounds();
1145 FileLoader loader = new FileLoader();
1147 AlignFrame newframe = null;
1149 if (fileObject == null)
1151 newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
1156 newframe = loader.LoadFileWaitTillLoaded(fileObject,
1157 DataSourceType.FILE, currentFileFormat);
1160 newframe.setBounds(bounds);
1161 if (featureSettings != null && featureSettings.isShowing())
1163 final Rectangle fspos = featureSettings.frame.getBounds();
1164 // TODO: need a 'show feature settings' function that takes bounds -
1165 // need to refactor Desktop.addFrame
1166 newframe.featureSettings_actionPerformed(null);
1167 final FeatureSettings nfs = newframe.featureSettings;
1168 SwingUtilities.invokeLater(new Runnable()
1174 nfs.frame.setBounds(fspos);
1177 this.featureSettings.close();
1178 this.featureSettings = null;
1180 this.closeMenuItem_actionPerformed(true);
1186 public void addFromText_actionPerformed(ActionEvent e)
1188 Desktop.getInstance()
1189 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1193 public void addFromURL_actionPerformed(ActionEvent e)
1195 Desktop.getInstance().inputURLMenuItem_actionPerformed(viewport);
1199 public void save_actionPerformed(ActionEvent e)
1201 if (fileName == null || (currentFileFormat == null)
1202 || fileName.startsWith("http"))
1204 saveAs_actionPerformed();
1208 saveAlignment(fileName, currentFileFormat);
1213 * Saves the alignment to a file with a name chosen by the user, if necessary
1214 * warning if a file would be overwritten
1218 public void saveAs_actionPerformed()
1220 String format = currentFileFormat == null ? null
1221 : currentFileFormat.getName();
1222 JalviewFileChooser chooser = JalviewFileChooser
1223 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1225 chooser.setFileView(new JalviewFileView());
1226 chooser.setDialogTitle(
1227 MessageManager.getString("label.save_alignment_to_file"));
1228 chooser.setToolTipText(MessageManager.getString("action.save"));
1230 int value = chooser.showSaveDialog(this);
1232 if (value != JalviewFileChooser.APPROVE_OPTION)
1236 currentFileFormat = chooser.getSelectedFormat();
1237 // todo is this (2005) test now obsolete - value is never null?
1238 while (currentFileFormat == null)
1240 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1242 .getString("label.select_file_format_before_saving"),
1243 MessageManager.getString("label.file_format_not_specified"),
1244 JvOptionPane.WARNING_MESSAGE);
1245 currentFileFormat = chooser.getSelectedFormat();
1246 value = chooser.showSaveDialog(this);
1247 if (value != JalviewFileChooser.APPROVE_OPTION)
1253 fileName = chooser.getSelectedFile().getPath();
1255 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1256 Cache.setProperty("LAST_DIRECTORY", fileName);
1257 saveAlignment(fileName, currentFileFormat);
1260 boolean lastSaveSuccessful = false;
1262 FileFormatI lastFormatSaved;
1264 String lastFilenameSaved;
1267 * Raise a dialog or status message for the last call to saveAlignment.
1269 * @return true if last call to saveAlignment(file, format) was successful.
1272 public boolean isSaveAlignmentSuccessful()
1275 if (!lastSaveSuccessful)
1277 JvOptionPane.showInternalMessageDialog(this, MessageManager
1278 .formatMessage("label.couldnt_save_file", new Object[]
1279 { lastFilenameSaved }),
1280 MessageManager.getString("label.error_saving_file"),
1281 JvOptionPane.WARNING_MESSAGE);
1286 setStatus(MessageManager.formatMessage(
1287 "label.successfully_saved_to_file_in_format", new Object[]
1288 { lastFilenameSaved, lastFormatSaved }));
1291 return lastSaveSuccessful;
1295 * Saves the alignment to the specified file path, in the specified format,
1296 * which may be an alignment format, or Jalview project format. If the
1297 * alignment has hidden regions, or the format is one capable of including
1298 * non-sequence data (features, annotations, groups), then the user may be
1299 * prompted to specify what to include in the output.
1305 public void saveAlignment(String file, FileFormatI format)
1307 lastSaveSuccessful = true;
1308 lastFilenameSaved = file;
1309 lastFormatSaved = format;
1311 if (FileFormat.Jalview.equals(format))
1313 String shortName = title;
1314 if (shortName.indexOf(File.separatorChar) > -1)
1316 shortName = shortName
1317 .substring(shortName.lastIndexOf(File.separatorChar) + 1);
1319 lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
1322 statusBar.setText(MessageManager.formatMessage(
1323 "label.successfully_saved_to_file_in_format", new Object[]
1324 { fileName, format }));
1329 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1330 Runnable cancelAction = new Runnable()
1336 lastSaveSuccessful = false;
1339 Runnable outputAction = new Runnable()
1345 // todo defer this to inside formatSequences (or later)
1346 AlignmentExportData exportData = viewport
1347 .getAlignExportData(options);
1348 String output = new FormatAdapter(alignPanel, options)
1349 .formatSequences(format, exportData.getAlignment(),
1350 exportData.getOmitHidden(),
1351 exportData.getStartEndPostions(),
1352 viewport.getAlignment().getHiddenColumns());
1355 lastSaveSuccessful = false;
1359 // create backupfiles object and get new temp filename destination
1360 boolean doBackup = BackupFiles.getEnabled();
1361 BackupFiles backupfiles = doBackup ? new BackupFiles(file) : null;
1364 String tempFilePath = doBackup ? backupfiles.getTempFilePath()
1366 PrintWriter out = new PrintWriter(new FileWriter(tempFilePath));
1370 AlignFrame.this.setTitle(file);
1371 statusBar.setText(MessageManager.formatMessage(
1372 "label.successfully_saved_to_file_in_format",
1374 { fileName, format.getName() }));
1375 lastSaveSuccessful = true;
1376 } catch (Exception ex)
1378 lastSaveSuccessful = false;
1379 ex.printStackTrace();
1384 backupfiles.setWriteSuccess(lastSaveSuccessful);
1385 // do the backup file roll and rename the temp file to actual file
1386 lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
1393 * show dialog with export options if applicable; else just do it
1395 if (AlignExportOptions.isNeeded(viewport, format))
1397 AlignExportOptions choices = new AlignExportOptions(
1398 alignPanel.getAlignViewport(), format, options);
1399 choices.setResponseAction(0, outputAction);
1400 choices.setResponseAction(1, cancelAction);
1401 choices.showDialog();
1410 * Outputs the alignment to textbox in the requested format, if necessary
1411 * first prompting the user for whether to include hidden regions or
1414 * @param fileFormatName
1418 protected void outputText_actionPerformed(String fileFormatName)
1420 FileFormatI fileFormat = FileFormats.getInstance()
1421 .forName(fileFormatName);
1422 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1423 Runnable outputAction = new Runnable()
1429 // todo defer this to inside formatSequences (or later)
1430 AlignmentExportData exportData = viewport
1431 .getAlignExportData(options);
1432 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1433 cap.setForInput(null);
1436 FileFormatI format = fileFormat;
1437 cap.setText(new FormatAdapter(alignPanel, options)
1438 .formatSequences(format, exportData.getAlignment(),
1439 exportData.getOmitHidden(),
1440 exportData.getStartEndPostions(),
1441 viewport.getAlignment().getHiddenColumns()));
1442 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1443 "label.alignment_output_command", new Object[]
1444 { fileFormat.getName() }), 600, 500);
1445 } catch (OutOfMemoryError oom)
1447 new OOMWarning("Outputting alignment as " + fileFormat.getName(),
1455 * show dialog with export options if applicable; else just do it
1457 if (AlignExportOptions.isNeeded(viewport, fileFormat))
1459 AlignExportOptions choices = new AlignExportOptions(
1460 alignPanel.getAlignViewport(), fileFormat, options);
1461 choices.setResponseAction(0, outputAction);
1462 choices.showDialog();
1478 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1480 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1481 htmlSVG.exportHTML(null);
1485 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1487 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1488 bjs.exportHTML(null);
1493 public void createImageMap(File file, String image)
1495 alignPanel.makePNGImageMap(file, image);
1499 * Creates a PNG image of the alignment and writes it to the given file. If
1500 * the file is null, the user is prompted to choose a file.
1506 public void createPNG(File f)
1508 alignPanel.makeAlignmentImage(TYPE.PNG, f);
1512 * Creates an EPS image of the alignment and writes it to the given file. If
1513 * the file is null, the user is prompted to choose a file.
1519 public void createEPS(File f)
1521 alignPanel.makeAlignmentImage(TYPE.EPS, f);
1525 * Creates an SVG image of the alignment and writes it to the given file. If
1526 * the file is null, the user is prompted to choose a file.
1532 public void createSVG(File f)
1534 alignPanel.makeAlignmentImage(TYPE.SVG, f);
1538 public void pageSetup_actionPerformed(ActionEvent e)
1540 PrinterJob printJob = PrinterJob.getPrinterJob();
1541 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1552 public void printMenuItem_actionPerformed(ActionEvent e)
1554 // Putting in a thread avoids Swing painting problems
1555 PrintThread thread = new PrintThread(alignPanel);
1560 public void exportFeatures_actionPerformed(ActionEvent e)
1562 new AnnotationExporter(alignPanel).exportFeatures();
1566 public void exportAnnotations_actionPerformed(ActionEvent e)
1568 new AnnotationExporter(alignPanel).exportAnnotations();
1572 public void associatedData_actionPerformed(ActionEvent e)
1574 final JalviewFileChooser chooser = new JalviewFileChooser(
1575 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1576 chooser.setFileView(new JalviewFileView());
1577 String tooltip = MessageManager
1578 .getString("label.load_jalview_annotations");
1579 chooser.setDialogTitle(tooltip);
1580 chooser.setToolTipText(tooltip);
1581 chooser.setResponseHandler(0, new Runnable()
1587 String choice = chooser.getSelectedFile().getPath();
1588 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1589 loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
1593 chooser.showOpenDialog(this);
1597 * Close the current view or all views in the alignment frame. If the frame
1598 * only contains one view then the alignment will be removed from memory.
1600 * @param closeAllTabs
1604 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1606 if (alignPanels != null && alignPanels.size() < 2)
1608 closeAllTabs = true;
1613 if (alignPanels != null)
1617 if (this.isClosed())
1619 // really close all the windows - otherwise wait till
1620 // setClosed(true) is called
1621 for (int i = 0; i < alignPanels.size(); i++)
1623 AlignmentPanel ap = alignPanels.get(i);
1630 closeView(alignPanel);
1635 if (featureSettings != null && featureSettings.isOpen())
1637 featureSettings.close();
1638 featureSettings = null;
1641 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1642 * be called recursively, with the frame now in 'closed' state
1644 this.setClosed(true);
1646 } catch (Exception ex)
1648 ex.printStackTrace();
1653 * Close the specified panel and close up tabs appropriately.
1655 * @param panelToClose
1658 public void closeView(AlignmentPanel panelToClose)
1660 int index = tabbedPane.getSelectedIndex();
1661 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1662 alignPanels.remove(panelToClose);
1663 panelToClose.closePanel();
1664 panelToClose = null;
1666 tabbedPane.removeTabAt(closedindex);
1667 tabbedPane.validate();
1669 if (index > closedindex || index == tabbedPane.getTabCount())
1671 // modify currently selected tab index if necessary.
1675 this.tabSelectionChanged(index);
1682 void updateEditMenuBar()
1685 if (viewport.getHistoryList().size() > 0)
1687 undoMenuItem.setEnabled(true);
1688 CommandI command = viewport.getHistoryList().peek();
1689 undoMenuItem.setText(MessageManager
1690 .formatMessage("label.undo_command", new Object[]
1691 { command.getDescription() }));
1695 undoMenuItem.setEnabled(false);
1696 undoMenuItem.setText(MessageManager.getString("action.undo"));
1699 if (viewport.getRedoList().size() > 0)
1701 redoMenuItem.setEnabled(true);
1703 CommandI command = viewport.getRedoList().peek();
1704 redoMenuItem.setText(MessageManager
1705 .formatMessage("label.redo_command", new Object[]
1706 { command.getDescription() }));
1710 redoMenuItem.setEnabled(false);
1711 redoMenuItem.setText(MessageManager.getString("action.redo"));
1716 public void addHistoryItem(CommandI command)
1718 if (command.getSize() > 0)
1720 viewport.addToHistoryList(command);
1721 viewport.clearRedoList();
1722 updateEditMenuBar();
1723 viewport.updateHiddenColumns();
1724 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1725 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1726 // viewport.getColumnSelection()
1727 // .getHiddenColumns().size() > 0);
1733 * @return alignment objects for all views
1736 AlignmentI[] getViewAlignments()
1738 if (alignPanels != null)
1740 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1742 for (AlignmentPanel ap : alignPanels)
1744 als[i++] = ap.av.getAlignment();
1748 if (viewport != null)
1750 return new AlignmentI[] { viewport.getAlignment() };
1763 protected void undoMenuItem_actionPerformed(ActionEvent e)
1765 if (viewport.getHistoryList().isEmpty())
1769 CommandI command = viewport.getHistoryList().pop();
1770 viewport.addToRedoList(command);
1771 command.undoCommand(getViewAlignments());
1773 AlignmentViewport originalSource = getOriginatingSource(command);
1774 updateEditMenuBar();
1776 if (originalSource != null)
1778 if (originalSource != viewport)
1781 "Implementation worry: mismatch of viewport origin for undo");
1783 originalSource.updateHiddenColumns();
1784 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1786 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1787 // viewport.getColumnSelection()
1788 // .getHiddenColumns().size() > 0);
1789 originalSource.notifyAlignment();
1802 protected void redoMenuItem_actionPerformed(ActionEvent e)
1804 if (viewport.getRedoList().size() < 1)
1809 CommandI command = viewport.getRedoList().pop();
1810 viewport.addToHistoryList(command);
1811 command.doCommand(getViewAlignments());
1813 AlignmentViewport originalSource = getOriginatingSource(command);
1814 updateEditMenuBar();
1816 if (originalSource != null)
1819 if (originalSource != viewport)
1822 "Implementation worry: mismatch of viewport origin for redo");
1824 originalSource.updateHiddenColumns();
1825 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1827 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1828 // viewport.getColumnSelection()
1829 // .getHiddenColumns().size() > 0);
1830 originalSource.notifyAlignment();
1835 AlignmentViewport getOriginatingSource(CommandI command)
1837 AlignmentViewport originalSource = null;
1838 // For sequence removal and addition, we need to fire
1839 // the property change event FROM the viewport where the
1840 // original alignment was altered
1841 AlignmentI al = null;
1842 if (command instanceof EditCommand)
1844 EditCommand editCommand = (EditCommand) command;
1845 al = editCommand.getAlignment();
1846 List<Component> comps = PaintRefresher.components
1847 .get(viewport.getSequenceSetId());
1849 for (Component comp : comps)
1851 if (comp instanceof AlignmentPanel)
1853 if (al == ((AlignmentPanel) comp).av.getAlignment())
1855 originalSource = ((AlignmentPanel) comp).av;
1862 if (originalSource == null)
1864 // The original view is closed, we must validate
1865 // the current view against the closed view first
1868 PaintRefresher.validateSequences(al, viewport.getAlignment());
1871 originalSource = viewport;
1874 return originalSource;
1884 public void moveSelectedSequences(boolean up)
1886 SequenceGroup sg = viewport.getSelectionGroup();
1892 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1893 viewport.getHiddenRepSequences(), up);
1894 alignPanel.paintAlignment(true, false);
1897 synchronized void slideSequences(boolean right, int size)
1899 List<SequenceI> sg = new ArrayList<>();
1900 if (viewport.cursorMode)
1902 sg.add(viewport.getAlignment()
1903 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
1905 else if (viewport.getSelectionGroup() != null
1906 && viewport.getSelectionGroup().getSize() != viewport
1907 .getAlignment().getHeight())
1909 sg = viewport.getSelectionGroup()
1910 .getSequences(viewport.getHiddenRepSequences());
1918 List<SequenceI> invertGroup = new ArrayList<>();
1920 for (SequenceI seq : viewport.getAlignment().getSequences())
1922 if (!sg.contains(seq))
1924 invertGroup.add(seq);
1928 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1930 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1931 for (int i = 0; i < invertGroup.size(); i++)
1933 seqs2[i] = invertGroup.get(i);
1936 SlideSequencesCommand ssc;
1939 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1940 viewport.getGapCharacter());
1944 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1945 viewport.getGapCharacter());
1948 int groupAdjustment = 0;
1949 if (ssc.getGapsInsertedBegin() && right)
1951 if (viewport.cursorMode)
1953 alignPanel.getSeqPanel().moveCursor(size, 0);
1957 groupAdjustment = size;
1960 else if (!ssc.getGapsInsertedBegin() && !right)
1962 if (viewport.cursorMode)
1964 alignPanel.getSeqPanel().moveCursor(-size, 0);
1968 groupAdjustment = -size;
1972 if (groupAdjustment != 0)
1974 viewport.getSelectionGroup().setStartRes(
1975 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1976 viewport.getSelectionGroup().setEndRes(
1977 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1981 * just extend the last slide command if compatible; but not if in
1982 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1984 boolean appendHistoryItem = false;
1985 Deque<CommandI> historyList = viewport.getHistoryList();
1986 boolean inSplitFrame = getSplitViewContainer() != null;
1987 if (!inSplitFrame && historyList != null && historyList.size() > 0
1988 && historyList.peek() instanceof SlideSequencesCommand)
1990 appendHistoryItem = ssc.appendSlideCommand(
1991 (SlideSequencesCommand) historyList.peek());
1994 if (!appendHistoryItem)
1996 addHistoryItem(ssc);
2010 protected void copy_actionPerformed()
2012 if (viewport.getSelectionGroup() == null)
2016 // TODO: preserve the ordering of displayed alignment annotation in any
2017 // internal paste (particularly sequence associated annotation)
2018 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
2019 String[] omitHidden = null;
2021 if (viewport.hasHiddenColumns())
2023 omitHidden = viewport.getViewAsString(true);
2026 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
2027 seqs, omitHidden, null);
2029 StringSelection ss = new StringSelection(output);
2031 Desktop d = Desktop.getInstance();
2034 d.internalCopy = true;
2035 // Its really worth setting the clipboard contents
2036 // to empty before setting the large StringSelection!!
2037 Toolkit.getDefaultToolkit().getSystemClipboard()
2038 .setContents(new StringSelection(""), null);
2040 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
2041 Desktop.getInstance());
2042 } catch (OutOfMemoryError er)
2044 new OOMWarning("copying region", er);
2048 HiddenColumns hiddenColumns = null;
2049 if (viewport.hasHiddenColumns())
2051 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
2052 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
2054 // create new HiddenColumns object with copy of hidden regions
2055 // between startRes and endRes, offset by startRes
2056 hiddenColumns = new HiddenColumns(
2057 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
2058 hiddenCutoff, hiddenOffset);
2061 d.jalviewClipboard = new Object[] { seqs,
2062 viewport.getAlignment().getDataset(), hiddenColumns };
2063 setStatus(MessageManager.formatMessage(
2064 "label.copied_sequences_to_clipboard", new Object[]
2065 { Integer.valueOf(seqs.length).toString() }));
2076 protected void pasteNew_actionPerformed(ActionEvent e)
2089 protected void pasteThis_actionPerformed(ActionEvent e)
2095 * Paste contents of Jalview clipboard
2097 * @param newAlignment
2098 * true to paste to a new alignment, otherwise add to this.
2101 void paste(boolean newAlignment)
2103 boolean externalPaste = true;
2106 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2107 Transferable contents = c.getContents(this);
2109 if (contents == null)
2118 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2119 if (str.length() < 1)
2124 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2126 } catch (OutOfMemoryError er)
2128 new OOMWarning("Out of memory pasting sequences!!", er);
2132 SequenceI[] sequences;
2133 boolean annotationAdded = false;
2134 AlignmentI alignment = null;
2136 Desktop d = Desktop.getInstance();
2138 if (d.jalviewClipboard != null)
2140 // The clipboard was filled from within Jalview, we must use the
2142 // And dataset from the copied alignment
2143 SequenceI[] newseq = (SequenceI[]) d.jalviewClipboard[0];
2144 // be doubly sure that we create *new* sequence objects.
2145 sequences = new SequenceI[newseq.length];
2146 for (int i = 0; i < newseq.length; i++)
2148 sequences[i] = new Sequence(newseq[i]);
2150 alignment = new Alignment(sequences);
2151 externalPaste = false;
2155 // parse the clipboard as an alignment.
2156 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2158 sequences = alignment.getSequencesArray();
2162 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2168 if (d.jalviewClipboard != null)
2170 // dataset is inherited
2171 alignment.setDataset((Alignment) d.jalviewClipboard[1]);
2175 // new dataset is constructed
2176 alignment.setDataset(null);
2178 alwidth = alignment.getWidth() + 1;
2182 AlignmentI pastedal = alignment; // preserve pasted alignment object
2183 // Add pasted sequences and dataset into existing alignment.
2184 alignment = viewport.getAlignment();
2185 alwidth = alignment.getWidth() + 1;
2186 // decide if we need to import sequences from an existing dataset
2187 boolean importDs = d.jalviewClipboard != null
2188 && d.jalviewClipboard[1] != alignment.getDataset();
2189 // importDs==true instructs us to copy over new dataset sequences from
2190 // an existing alignment
2191 Vector<SequenceI> newDs = (importDs) ? new Vector<>() : null; // used to
2193 // minimum dataset set
2195 for (int i = 0; i < sequences.length; i++)
2199 newDs.addElement(null);
2201 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2203 if (importDs && ds != null)
2205 if (!newDs.contains(ds))
2207 newDs.setElementAt(ds, i);
2208 ds = new Sequence(ds);
2209 // update with new dataset sequence
2210 sequences[i].setDatasetSequence(ds);
2214 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2219 // copy and derive new dataset sequence
2220 sequences[i] = sequences[i].deriveSequence();
2221 alignment.getDataset()
2222 .addSequence(sequences[i].getDatasetSequence());
2223 // TODO: avoid creation of duplicate dataset sequences with a
2224 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2226 alignment.addSequence(sequences[i]); // merges dataset
2230 newDs.clear(); // tidy up
2232 if (alignment.getAlignmentAnnotation() != null)
2234 for (AlignmentAnnotation alan : alignment
2235 .getAlignmentAnnotation())
2237 if (alan.graphGroup > fgroup)
2239 fgroup = alan.graphGroup;
2243 if (pastedal.getAlignmentAnnotation() != null)
2245 // Add any annotation attached to alignment.
2246 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2247 for (int i = 0; i < alann.length; i++)
2249 annotationAdded = true;
2250 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2252 AlignmentAnnotation newann = new AlignmentAnnotation(
2254 if (newann.graphGroup > -1)
2256 if (newGraphGroups.size() <= newann.graphGroup
2257 || newGraphGroups.get(newann.graphGroup) == null)
2259 for (int q = newGraphGroups
2260 .size(); q <= newann.graphGroup; q++)
2262 newGraphGroups.add(q, null);
2264 newGraphGroups.set(newann.graphGroup,
2265 Integer.valueOf(++fgroup));
2267 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2271 newann.padAnnotation(alwidth);
2272 alignment.addAnnotation(newann);
2282 addHistoryItem(new EditCommand(
2283 MessageManager.getString("label.add_sequences"),
2284 Action.PASTE, sequences, 0, alignment.getWidth(),
2287 // Add any annotations attached to sequences
2288 for (int i = 0; i < sequences.length; i++)
2290 if (sequences[i].getAnnotation() != null)
2292 AlignmentAnnotation newann;
2293 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2295 annotationAdded = true;
2296 newann = sequences[i].getAnnotation()[a];
2297 newann.adjustForAlignment();
2298 newann.padAnnotation(alwidth);
2299 if (newann.graphGroup > -1)
2301 if (newann.graphGroup > -1)
2303 if (newGraphGroups.size() <= newann.graphGroup
2304 || newGraphGroups.get(newann.graphGroup) == null)
2306 for (int q = newGraphGroups
2307 .size(); q <= newann.graphGroup; q++)
2309 newGraphGroups.add(q, null);
2311 newGraphGroups.set(newann.graphGroup,
2312 Integer.valueOf(++fgroup));
2314 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2318 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2322 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2330 // propagate alignment changed.
2331 viewport.getRanges().setEndSeq(alignment.getHeight() - 1);
2332 if (annotationAdded)
2334 // Duplicate sequence annotation in all views.
2335 AlignmentI[] alview = this.getViewAlignments();
2336 for (int i = 0; i < sequences.length; i++)
2338 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2343 for (int avnum = 0; avnum < alview.length; avnum++)
2345 if (alview[avnum] != alignment)
2347 // duplicate in a view other than the one with input focus
2348 int avwidth = alview[avnum].getWidth() + 1;
2349 // this relies on sann being preserved after we
2350 // modify the sequence's annotation array for each duplication
2351 for (int a = 0; a < sann.length; a++)
2353 AlignmentAnnotation newann = new AlignmentAnnotation(
2355 sequences[i].addAlignmentAnnotation(newann);
2356 newann.padAnnotation(avwidth);
2357 alview[avnum].addAnnotation(newann); // annotation was
2358 // duplicated earlier
2359 // TODO JAL-1145 graphGroups are not updated for sequence
2360 // annotation added to several views. This may cause
2362 alview[avnum].setAnnotationIndex(newann, a);
2367 buildSortByAnnotationScoresMenu();
2369 viewport.notifyAlignment();
2370 if (alignPanels != null)
2372 for (AlignmentPanel ap : alignPanels)
2374 ap.validateAnnotationDimensions(false);
2379 alignPanel.validateAnnotationDimensions(false);
2385 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2387 String newtitle = new String("Copied sequences");
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.
2405 if (title.startsWith("Copied sequences"))
2411 newtitle = newtitle.concat("- from " + title);
2416 newtitle = new String("Pasted sequences");
2419 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2424 } catch (Exception ex)
2426 ex.printStackTrace();
2427 System.out.println("Exception whilst pasting: " + ex);
2428 // could be anything being pasted in here
2434 protected void expand_newalign(ActionEvent e)
2438 AlignmentI alignment = AlignmentUtils
2439 .expandContext(getViewport().getAlignment(), -1);
2440 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2442 String newtitle = new String("Flanking alignment");
2443 Desktop d = Desktop.getInstance();
2444 if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null)
2446 HiddenColumns hc = (HiddenColumns) d.jalviewClipboard[2];
2447 af.viewport.setHiddenColumns(hc);
2450 // >>>This is a fix for the moment, until a better solution is
2452 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2453 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2454 .getFeatureRenderer());
2456 // TODO: maintain provenance of an alignment, rather than just make the
2457 // title a concatenation of operations.
2459 if (title.startsWith("Copied sequences"))
2465 newtitle = newtitle.concat("- from " + title);
2469 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2471 } catch (Exception ex)
2473 ex.printStackTrace();
2474 System.out.println("Exception whilst pasting: " + ex);
2475 // could be anything being pasted in here
2476 } catch (OutOfMemoryError oom)
2478 new OOMWarning("Viewing flanking region of alignment", oom);
2483 * Action Cut (delete and copy) the selected region
2487 protected void cut_actionPerformed()
2489 copy_actionPerformed();
2490 delete_actionPerformed();
2494 * Performs menu option to Delete the currently selected region
2498 protected void delete_actionPerformed()
2501 SequenceGroup sg = viewport.getSelectionGroup();
2507 Runnable okAction = new Runnable()
2513 SequenceI[] cut = sg.getSequences()
2514 .toArray(new SequenceI[sg.getSize()]);
2516 addHistoryItem(new EditCommand(
2517 MessageManager.getString("label.cut_sequences"), Action.CUT,
2518 cut, sg.getStartRes(),
2519 sg.getEndRes() - sg.getStartRes() + 1,
2520 viewport.getAlignment()));
2522 viewport.setSelectionGroup(null);
2523 viewport.sendSelection();
2524 viewport.getAlignment().deleteGroup(sg);
2526 viewport.notifyAlignment();
2528 if (viewport.getAlignment().getHeight() < 1)
2532 AlignFrame.this.setClosed(true);
2533 } catch (Exception ex)
2543 * If the cut affects all sequences, prompt for confirmation
2545 boolean wholeHeight = sg.getSize() == viewport.getAlignment()
2547 boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes())
2548 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2549 if (wholeHeight && wholeWidth)
2551 JvOptionPane dialog = JvOptionPane
2552 .newOptionDialog(Desktop.getDesktopPane());
2553 dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
2554 Object[] options = new Object[] {
2555 MessageManager.getString("action.ok"),
2556 MessageManager.getString("action.cancel") };
2557 dialog.showDialog(MessageManager.getString("warn.delete_all"),
2558 MessageManager.getString("label.delete_all"),
2559 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
2560 options, options[0]);
2576 protected void deleteGroups_actionPerformed(ActionEvent e)
2578 if (avc.deleteGroups())
2580 updateAll(viewport.getSequenceSetId());
2584 private void updateAll(String id)
2588 // this will force a non-fast repaint of both the IdPanel and SeqPanel
2589 alignPanel.getIdPanel().getIdCanvas().setNoFastPaint();
2590 alignPanel.getSeqPanel().seqCanvas.setNoFastPaint();
2591 alignPanel.repaint();
2596 PaintRefresher.Refresh(this, id);
2597 alignPanel.paintAlignment(true, true);
2599 alignPanel.updateAnnotation();
2610 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2612 alignPanel.selectAllSequences();
2623 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2625 alignPanel.deselectAllSequences();
2636 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2638 SequenceGroup sg = viewport.getSelectionGroup();
2642 alignPanel.selectAllSequences();
2647 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2649 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2651 // JAL-2034 - should delegate to
2652 // alignPanel to decide if overview needs
2655 alignPanel.paintAlignment(true, false);
2656 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2657 viewport.sendSelection();
2661 public void invertColSel_actionPerformed(ActionEvent e)
2663 viewport.invertColumnSelection();
2664 alignPanel.paintAlignment(true, false);
2665 viewport.sendSelection();
2676 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2678 trimAlignment(true);
2689 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2691 trimAlignment(false);
2694 void trimAlignment(boolean trimLeft)
2696 ColumnSelection colSel = viewport.getColumnSelection();
2699 if (!colSel.isEmpty())
2703 column = colSel.getMin();
2707 column = colSel.getMax();
2711 if (viewport.getSelectionGroup() != null)
2713 seqs = viewport.getSelectionGroup()
2714 .getSequencesAsArray(viewport.getHiddenRepSequences());
2718 seqs = viewport.getAlignment().getSequencesArray();
2721 TrimRegionCommand trimRegion;
2724 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2725 column, viewport.getAlignment());
2726 viewport.getRanges().setStartRes(0);
2730 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2731 column, viewport.getAlignment());
2734 setStatus(MessageManager.formatMessage("label.removed_columns",
2736 { Integer.valueOf(trimRegion.getSize()).toString() }));
2738 addHistoryItem(trimRegion);
2740 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2742 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2743 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2745 viewport.getAlignment().deleteGroup(sg);
2749 viewport.notifyAlignment();
2762 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2764 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2767 if (viewport.getSelectionGroup() != null)
2769 seqs = viewport.getSelectionGroup()
2770 .getSequencesAsArray(viewport.getHiddenRepSequences());
2771 start = viewport.getSelectionGroup().getStartRes();
2772 end = viewport.getSelectionGroup().getEndRes();
2776 seqs = viewport.getAlignment().getSequencesArray();
2779 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2780 "Remove Gapped Columns", seqs, start, end,
2781 viewport.getAlignment());
2783 addHistoryItem(removeGapCols);
2785 setStatus(MessageManager.formatMessage("label.removed_empty_columns",
2787 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2789 // This is to maintain viewport position on first residue
2790 // of first sequence
2791 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2792 ViewportRanges ranges = viewport.getRanges();
2793 int startRes = seq.findPosition(ranges.getStartRes());
2794 // ShiftList shifts;
2795 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2796 // edit.alColumnChanges=shifts.getInverse();
2797 // if (viewport.hasHiddenColumns)
2798 // viewport.getColumnSelection().compensateForEdits(shifts);
2799 ranges.setStartRes(seq.findIndex(startRes) - 1);
2800 viewport.notifyAlignment();
2813 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2815 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2818 if (viewport.getSelectionGroup() != null)
2820 seqs = viewport.getSelectionGroup()
2821 .getSequencesAsArray(viewport.getHiddenRepSequences());
2822 start = viewport.getSelectionGroup().getStartRes();
2823 end = viewport.getSelectionGroup().getEndRes();
2827 seqs = viewport.getAlignment().getSequencesArray();
2830 // This is to maintain viewport position on first residue
2831 // of first sequence
2832 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2833 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2835 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2836 viewport.getAlignment()));
2838 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2839 viewport.notifyAlignment();
2851 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2853 viewport.setPadGaps(padGapsMenuitem.isSelected());
2854 viewport.notifyAlignment();
2866 public void findMenuItem_actionPerformed(ActionEvent e)
2872 * Create a new view of the current alignment.
2876 public void newView_actionPerformed(ActionEvent e)
2878 newView(null, true);
2882 * Creates and shows a new view of the current alignment.
2885 * title of newly created view; if null, one will be generated
2886 * @param copyAnnotation
2887 * if true then duplicate all annnotation, groups and settings
2888 * @return new alignment panel, already displayed.
2891 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2894 * Create a new AlignmentPanel (with its own, new Viewport)
2896 AlignmentPanel newap = new jalview.project.Jalview2XML()
2897 .copyAlignPanel(alignPanel);
2898 if (!copyAnnotation)
2901 * remove all groups and annotation except for the automatic stuff
2903 newap.av.getAlignment().deleteAllGroups();
2904 newap.av.getAlignment().deleteAllAnnotations(false);
2907 newap.av.setGatherViewsHere(false);
2909 if (viewport.getViewName() == null)
2911 viewport.setViewName(
2912 MessageManager.getString("label.view_name_original"));
2916 * Views share the same edits undo and redo stacks
2918 newap.av.setHistoryList(viewport.getHistoryList());
2919 newap.av.setRedoList(viewport.getRedoList());
2922 * copy any visualisation settings that are not saved in the project
2924 newap.av.setColourAppliesToAllGroups(
2925 viewport.getColourAppliesToAllGroups());
2928 * Views share the same mappings; need to deregister any new mappings
2929 * created by copyAlignPanel, and register the new reference to the shared
2932 newap.av.replaceMappings(viewport.getAlignment());
2935 * start up cDNA consensus (if applicable) now mappings are in place
2937 if (newap.av.initComplementConsensus())
2939 newap.refresh(true); // adjust layout of annotations
2942 newap.av.setViewName(getNewViewName(viewTitle));
2944 addAlignmentPanel(newap, true);
2945 newap.alignmentChanged();
2947 if (alignPanels.size() == 2)
2949 viewport.setGatherViewsHere(true);
2951 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2956 * Make a new name for the view, ensuring it is unique within the current
2957 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2958 * these now use viewId. Unique view names are still desirable for usability.)
2964 protected String getNewViewName(String viewTitle)
2966 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2967 boolean addFirstIndex = false;
2968 if (viewTitle == null || viewTitle.trim().length() == 0)
2970 viewTitle = MessageManager.getString("action.view");
2971 addFirstIndex = true;
2975 index = 1;// we count from 1 if given a specific name
2977 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2979 List<Component> comps = PaintRefresher.components
2980 .get(viewport.getSequenceSetId());
2982 List<String> existingNames = getExistingViewNames(comps);
2984 while (existingNames.contains(newViewName))
2986 newViewName = viewTitle + " " + (++index);
2992 * Returns a list of distinct view names found in the given list of
2993 * components. View names are held on the viewport of an AlignmentPanel.
2999 protected List<String> getExistingViewNames(List<Component> comps)
3001 List<String> existingNames = new ArrayList<>();
3002 for (Component comp : comps)
3004 if (comp instanceof AlignmentPanel)
3006 AlignmentPanel ap = (AlignmentPanel) comp;
3007 if (!existingNames.contains(ap.av.getViewName()))
3009 existingNames.add(ap.av.getViewName());
3013 return existingNames;
3017 * Explode tabbed views into separate windows.
3021 public void expandViews_actionPerformed(ActionEvent e)
3023 Desktop.explodeViews(this);
3027 * Gather views in separate windows back into a tabbed presentation.
3031 public void gatherViews_actionPerformed(ActionEvent e)
3033 Desktop.getInstance().gatherViews(this);
3044 public void font_actionPerformed(ActionEvent e)
3046 new FontChooser(alignPanel);
3057 protected void seqLimit_actionPerformed(ActionEvent e)
3059 viewport.setShowJVSuffix(seqLimits.isSelected());
3061 alignPanel.getIdPanel().getIdCanvas()
3062 .setPreferredSize(alignPanel.calculateIdWidth());
3063 alignPanel.paintAlignment(true, false);
3067 public void idRightAlign_actionPerformed(ActionEvent e)
3069 viewport.setRightAlignIds(idRightAlign.isSelected());
3070 alignPanel.paintAlignment(false, false);
3074 public void centreColumnLabels_actionPerformed(ActionEvent e)
3076 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
3077 alignPanel.paintAlignment(false, false);
3083 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3087 protected void followHighlight_actionPerformed()
3090 * Set the 'follow' flag on the Viewport (and scroll to position if now
3093 final boolean state = this.followHighlightMenuItem.getState();
3094 viewport.setFollowHighlight(state);
3097 alignPanel.scrollToPosition(viewport.getSearchResults());
3109 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3111 viewport.setColourText(colourTextMenuItem.isSelected());
3112 alignPanel.paintAlignment(false, false);
3123 public void wrapMenuItem_actionPerformed(ActionEvent e)
3125 scaleAbove.setVisible(wrapMenuItem.isSelected());
3126 scaleLeft.setVisible(wrapMenuItem.isSelected());
3127 scaleRight.setVisible(wrapMenuItem.isSelected());
3128 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3129 alignPanel.updateLayout();
3133 public void showAllSeqs_actionPerformed(ActionEvent e)
3135 viewport.showAllHiddenSeqs();
3139 public void showAllColumns_actionPerformed(ActionEvent e)
3141 viewport.showAllHiddenColumns();
3142 alignPanel.paintAlignment(true, true);
3143 viewport.sendSelection();
3147 public void hideSelSequences_actionPerformed(ActionEvent e)
3149 viewport.hideAllSelectedSeqs();
3153 * called by key handler and the hide all/show all menu items
3159 protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3162 boolean hide = false;
3163 SequenceGroup sg = viewport.getSelectionGroup();
3164 if (!toggleSeqs && !toggleCols)
3166 // Hide everything by the current selection - this is a hack - we do the
3167 // invert and then hide
3168 // first check that there will be visible columns after the invert.
3169 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3170 && sg.getStartRes() <= sg.getEndRes()))
3172 // now invert the sequence set, if required - empty selection implies
3173 // that no hiding is required.
3176 invertSequenceMenuItem_actionPerformed(null);
3177 sg = viewport.getSelectionGroup();
3181 viewport.expandColSelection(sg, true);
3182 // finally invert the column selection and get the new sequence
3184 invertColSel_actionPerformed(null);
3191 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3193 hideSelSequences_actionPerformed(null);
3196 else if (!(toggleCols && viewport.hasSelectedColumns()))
3198 showAllSeqs_actionPerformed(null);
3204 if (viewport.hasSelectedColumns())
3206 hideSelColumns_actionPerformed(null);
3209 viewport.setSelectionGroup(sg);
3214 showAllColumns_actionPerformed(null);
3223 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3224 * event.ActionEvent)
3228 public void hideAllButSelection_actionPerformed(ActionEvent e)
3230 toggleHiddenRegions(false, false);
3231 viewport.sendSelection();
3238 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3243 public void hideAllSelection_actionPerformed(ActionEvent e)
3245 SequenceGroup sg = viewport.getSelectionGroup();
3246 viewport.expandColSelection(sg, false);
3247 viewport.hideAllSelectedSeqs();
3248 viewport.hideSelectedColumns();
3249 alignPanel.updateLayout();
3250 alignPanel.paintAlignment(true, true);
3251 viewport.sendSelection();
3258 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3263 public void showAllhidden_actionPerformed(ActionEvent e)
3265 viewport.showAllHiddenColumns();
3266 viewport.showAllHiddenSeqs();
3267 alignPanel.paintAlignment(true, true);
3268 viewport.sendSelection();
3272 public void hideSelColumns_actionPerformed(ActionEvent e)
3274 viewport.hideSelectedColumns();
3275 alignPanel.updateLayout();
3276 alignPanel.paintAlignment(true, true);
3277 viewport.sendSelection();
3281 public void hiddenMarkers_actionPerformed(ActionEvent e)
3283 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3295 protected void scaleAbove_actionPerformed(ActionEvent e)
3297 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3298 alignPanel.updateLayout();
3299 alignPanel.paintAlignment(true, false);
3310 protected void scaleLeft_actionPerformed(ActionEvent e)
3312 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3313 alignPanel.updateLayout();
3314 alignPanel.paintAlignment(true, false);
3325 protected void scaleRight_actionPerformed(ActionEvent e)
3327 viewport.setScaleRightWrapped(scaleRight.isSelected());
3328 alignPanel.updateLayout();
3329 alignPanel.paintAlignment(true, false);
3340 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3342 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3343 alignPanel.paintAlignment(false, false);
3354 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3356 viewport.setShowText(viewTextMenuItem.isSelected());
3357 alignPanel.paintAlignment(false, false);
3368 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3370 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3371 alignPanel.paintAlignment(false, false);
3374 public FeatureSettings featureSettings;
3377 public FeatureSettingsControllerI getFeatureSettingsUI()
3379 return featureSettings;
3383 public void featureSettings_actionPerformed(ActionEvent e)
3385 showFeatureSettingsUI();
3389 public FeatureSettingsControllerI showFeatureSettingsUI()
3391 if (featureSettings != null)
3393 featureSettings.closeOldSettings();
3394 featureSettings = null;
3396 if (!showSeqFeatures.isSelected())
3398 // make sure features are actually displayed
3399 showSeqFeatures.setSelected(true);
3400 showSeqFeatures_actionPerformed(null);
3402 featureSettings = new FeatureSettings(this);
3403 return featureSettings;
3407 * Set or clear 'Show Sequence Features'
3414 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3416 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3417 alignPanel.paintAlignment(true, true);
3421 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3422 * the annotations panel as a whole.
3424 * The options to show/hide all annotations should be enabled when the panel
3425 * is shown, and disabled when the panel is hidden.
3431 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3433 final boolean setVisible = annotationPanelMenuItem.isSelected();
3434 viewport.setShowAnnotation(setVisible);
3435 syncAnnotationMenuItems(setVisible);
3436 alignPanel.updateLayout();
3438 SwingUtilities.invokeLater(new Runnable() {
3443 alignPanel.updateScrollBarsFromRanges();
3449 private void syncAnnotationMenuItems(boolean setVisible)
3451 showAllSeqAnnotations.setEnabled(setVisible);
3452 hideAllSeqAnnotations.setEnabled(setVisible);
3453 showAllAlAnnotations.setEnabled(setVisible);
3454 hideAllAlAnnotations.setEnabled(setVisible);
3458 public void alignmentProperties()
3461 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3464 String content = MessageManager.formatMessage("label.html_content",
3466 { contents.toString() });
3469 if (Platform.isJS())
3471 JLabel textLabel = new JLabel();
3472 textLabel.setText(content);
3473 textLabel.setBackground(Color.WHITE);
3475 pane = new JPanel(new BorderLayout());
3476 ((JPanel) pane).setOpaque(true);
3477 pane.setBackground(Color.WHITE);
3478 ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
3487 JEditorPane editPane = new JEditorPane("text/html", "");
3488 editPane.setEditable(false);
3489 editPane.setText(content);
3493 JInternalFrame frame = new JInternalFrame();
3495 frame.getContentPane().add(new JScrollPane(pane));
3497 Desktop.addInternalFrame(frame, MessageManager
3498 .formatMessage("label.alignment_properties", new Object[]
3499 { getTitle() }), 500, 400);
3510 public void overviewMenuItem_actionPerformed(ActionEvent e)
3512 if (alignPanel.overviewPanel != null)
3517 JInternalFrame frame = new JInternalFrame();
3519 // BH 2019.07.26 we allow for an embedded
3520 // undecorated overview with defined size
3521 frame.setName(Platform.getAppID("overview"));
3523 Dimension dim = Platform.getDimIfEmbedded(frame, -1, -1);
3524 if (dim != null && dim.width == 0)
3526 dim = null; // hidden, not embedded
3528 OverviewPanel overview = new OverviewPanel(alignPanel, dim);
3530 frame.setContentPane(overview);
3533 dim = new Dimension();
3534 // was frame.getSize(), but that is 0,0 at this point;
3538 // we are imbedding, and so we have an undecorated frame
3539 // and we can set the the frame dimensions accordingly.
3541 // allowing for unresizable option using, style="resize:none"
3542 boolean resizable = (Platform.getEmbeddedAttribute(frame,
3543 "resize") != "none");
3544 Desktop.addInternalFrame(frame, MessageManager
3545 .formatMessage("label.overview_params", new Object[]
3546 { this.getTitle() }), Desktop.FRAME_MAKE_VISIBLE, dim.width,
3547 dim.height, resizable, Desktop.FRAME_ALLOW_ANY_SIZE);
3549 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3550 frame.addInternalFrameListener(
3551 new javax.swing.event.InternalFrameAdapter()
3555 public void internalFrameClosed(
3556 javax.swing.event.InternalFrameEvent evt)
3559 alignPanel.setOverviewPanel(null);
3562 if (getKeyListeners().length > 0)
3564 frame.addKeyListener(getKeyListeners()[0]);
3567 alignPanel.setOverviewPanel(overview);
3571 public void textColour_actionPerformed()
3573 new TextColourChooser().chooseColour(alignPanel, null);
3577 * public void covariationColour_actionPerformed() {
3579 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3584 public void annotationColour_actionPerformed()
3586 new AnnotationColourChooser(viewport, alignPanel);
3590 public void annotationColumn_actionPerformed(ActionEvent e)
3592 new AnnotationColumnChooser(viewport, alignPanel);
3596 * Action on the user checking or unchecking the option to apply the selected
3597 * colour scheme to all groups. If unchecked, groups may have their own
3598 * independent colour schemes.
3604 public void applyToAllGroups_actionPerformed(boolean selected)
3606 viewport.setColourAppliesToAllGroups(selected);
3610 * Action on user selecting a colour from the colour menu
3613 * the name (not the menu item label!) of the colour scheme
3617 public void changeColour_actionPerformed(String name)
3620 * 'User Defined' opens a panel to configure or load a
3621 * user-defined colour scheme
3623 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3625 new UserDefinedColours(alignPanel);
3630 * otherwise set the chosen colour scheme (or null for 'None')
3632 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3633 viewport, viewport.getAlignment(),
3634 viewport.getHiddenRepSequences());
3639 * Actions on setting or changing the alignment colour scheme
3645 public void changeColour(ColourSchemeI cs)
3647 // TODO: pull up to controller method
3648 ColourMenuHelper.setColourSelected(colourMenu, cs);
3650 viewport.setGlobalColourScheme(cs);
3652 alignPanel.paintAlignment(true, true);
3656 * Show the PID threshold slider panel
3660 protected void modifyPID_actionPerformed()
3662 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3663 alignPanel.getViewName());
3664 SliderPanel.showPIDSlider();
3668 * Show the Conservation slider panel
3672 protected void modifyConservation_actionPerformed()
3674 SliderPanel.setConservationSlider(alignPanel,
3675 viewport.getResidueShading(), alignPanel.getViewName());
3676 SliderPanel.showConservationSlider();
3680 * Action on selecting or deselecting (Colour) By Conservation
3684 public void conservationMenuItem_actionPerformed(boolean selected)
3686 modifyConservation.setEnabled(selected);
3687 viewport.setConservationSelected(selected);
3688 viewport.getResidueShading().setConservationApplied(selected);
3690 changeColour(viewport.getGlobalColourScheme());
3693 modifyConservation_actionPerformed();
3697 SliderPanel.hideConservationSlider();
3702 * Action on selecting or deselecting (Colour) Above PID Threshold
3706 public void abovePIDThreshold_actionPerformed(boolean selected)
3708 modifyPID.setEnabled(selected);
3709 viewport.setAbovePIDThreshold(selected);
3712 viewport.getResidueShading().setThreshold(0,
3713 viewport.isIgnoreGapsConsensus());
3716 changeColour(viewport.getGlobalColourScheme());
3719 modifyPID_actionPerformed();
3723 SliderPanel.hidePIDSlider();
3735 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3737 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3738 AlignmentSorter.sortByPID(viewport.getAlignment(),
3739 viewport.getAlignment().getSequenceAt(0));
3740 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3741 viewport.getAlignment()));
3742 alignPanel.paintAlignment(true, false);
3753 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3755 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3756 AlignmentSorter.sortByID(viewport.getAlignment());
3758 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3759 alignPanel.paintAlignment(true, false);
3770 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3772 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3773 AlignmentSorter.sortByLength(viewport.getAlignment());
3774 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3775 viewport.getAlignment()));
3776 alignPanel.paintAlignment(true, false);
3787 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3789 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3790 AlignmentSorter.sortByGroup(viewport.getAlignment());
3791 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3792 viewport.getAlignment()));
3794 alignPanel.paintAlignment(true, false);
3805 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3807 new RedundancyPanel(alignPanel, this);
3818 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3820 if ((viewport.getSelectionGroup() == null)
3821 || (viewport.getSelectionGroup().getSize() < 2))
3823 JvOptionPane.showInternalMessageDialog(this,
3824 MessageManager.getString(
3825 "label.you_must_select_least_two_sequences"),
3826 MessageManager.getString("label.invalid_selection"),
3827 JvOptionPane.WARNING_MESSAGE);
3831 JInternalFrame frame = new JInternalFrame();
3832 frame.setContentPane(new PairwiseAlignPanel(viewport));
3833 Desktop.addInternalFrame(frame,
3834 MessageManager.getString("action.pairwise_alignment"), 600,
3840 public void autoCalculate_actionPerformed(ActionEvent e)
3842 viewport.setAutoCalculateConsensusAndConservation(
3843 autoCalculate.isSelected());
3844 if (viewport.getAutoCalculateConsensusAndConservation())
3846 // viewport.autoCalculateConsensus = autoCalculate.isSelected();
3847 // if (viewport.autoCalculateConsensus)
3849 viewport.notifyAlignment();
3854 public void sortByTreeOption_actionPerformed(ActionEvent e)
3856 viewport.sortByTree = sortByTree.isSelected();
3860 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3862 viewport.followSelection = listenToViewSelections.isSelected();
3866 * Constructs a tree panel and adds it to the desktop
3869 * tree type (NJ or AV)
3871 * name of score model used to compute the tree
3873 * parameters for the distance or similarity calculation
3876 void newTreePanel(String type, String modelName,
3877 SimilarityParamsI options)
3879 String frameTitle = "";
3882 boolean onSelection = false;
3883 if (viewport.getSelectionGroup() != null
3884 && viewport.getSelectionGroup().getSize() > 0)
3886 SequenceGroup sg = viewport.getSelectionGroup();
3888 /* Decide if the selection is a column region */
3889 for (SequenceI _s : sg.getSequences())
3891 if (_s.getLength() < sg.getEndRes())
3893 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
3894 MessageManager.getString(
3895 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3896 MessageManager.getString(
3897 "label.sequences_selection_not_aligned"),
3898 JvOptionPane.WARNING_MESSAGE);
3907 if (viewport.getAlignment().getHeight() < 2)
3913 tp = new TreePanel(alignPanel, type, modelName, options);
3914 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3916 frameTitle += " from ";
3918 if (viewport.getViewName() != null)
3920 frameTitle += viewport.getViewName() + " of ";
3923 frameTitle += this.title;
3925 Dimension dim = Platform.getDimIfEmbedded(tp, 600, 500);
3926 Desktop.addInternalFrame(tp, frameTitle, dim.width, dim.height);
3938 public void addSortByOrderMenuItem(String title,
3939 final AlignmentOrder order)
3941 final JMenuItem item = new JMenuItem(MessageManager
3942 .formatMessage("action.by_title_param", new Object[]
3945 item.addActionListener(new java.awt.event.ActionListener()
3949 public void actionPerformed(ActionEvent e)
3951 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3953 // TODO: JBPNote - have to map order entries to curent SequenceI
3955 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3957 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3958 viewport.getAlignment()));
3960 alignPanel.paintAlignment(true, false);
3966 * Add a new sort by annotation score menu item
3969 * the menu to add the option to
3971 * the label used to retrieve scores for each sequence on the
3975 public void addSortByAnnotScoreMenuItem(JMenu sort,
3976 final String scoreLabel)
3978 final JMenuItem item = new JMenuItem(scoreLabel);
3980 item.addActionListener(new java.awt.event.ActionListener()
3984 public void actionPerformed(ActionEvent e)
3986 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3987 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3988 viewport.getAlignment());// ,viewport.getSelectionGroup());
3989 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3990 viewport.getAlignment()));
3991 alignPanel.paintAlignment(true, false);
3997 * last hash for alignment's annotation array - used to minimise cost of
4000 protected int _annotationScoreVectorHash;
4003 * search the alignment and rebuild the sort by annotation score submenu the
4004 * last alignment annotation vector hash is stored to minimize cost of
4005 * rebuilding in subsequence calls.
4010 public void buildSortByAnnotationScoresMenu()
4012 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4017 if (viewport.getAlignment().getAlignmentAnnotation()
4018 .hashCode() != _annotationScoreVectorHash)
4020 sortByAnnotScore.removeAll();
4021 // almost certainly a quicker way to do this - but we keep it simple
4022 Hashtable<String, String> scoreSorts = new Hashtable<>();
4023 AlignmentAnnotation aann[];
4024 for (SequenceI sqa : viewport.getAlignment().getSequences())
4026 aann = sqa.getAnnotation();
4027 for (int i = 0; aann != null && i < aann.length; i++)
4029 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4031 scoreSorts.put(aann[i].label, aann[i].label);
4035 Enumeration<String> labels = scoreSorts.keys();
4036 while (labels.hasMoreElements())
4038 addSortByAnnotScoreMenuItem(sortByAnnotScore, labels.nextElement());
4040 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4043 _annotationScoreVectorHash = viewport.getAlignment()
4044 .getAlignmentAnnotation().hashCode();
4049 * Enable (or, if desired, make visible) the By Tree
4050 * submenu only if it has at least one element (or will have).
4054 protected void enableSortMenuOptions()
4056 List<TreePanel> treePanels = getTreePanels();
4057 sortByTreeMenu.setEnabled(!treePanels.isEmpty());
4061 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4062 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4063 * call. Listeners are added to remove the menu item when the treePanel is
4064 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4069 public void buildTreeSortMenu()
4071 sortByTreeMenu.removeAll();
4073 List<TreePanel> treePanels = getTreePanels();
4075 for (final TreePanel tp : treePanels)
4077 final JMenuItem item = new JMenuItem(tp.getTitle());
4078 item.addActionListener(new java.awt.event.ActionListener()
4082 public void actionPerformed(ActionEvent e)
4084 tp.sortByTree_actionPerformed();
4085 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4090 sortByTreeMenu.add(item);
4094 private List<TreePanel> getTreePanels()
4096 List<Component> comps = PaintRefresher.components
4097 .get(viewport.getSequenceSetId());
4098 List<TreePanel> treePanels = new ArrayList<>();
4099 for (Component comp : comps)
4101 if (comp instanceof TreePanel)
4103 treePanels.add((TreePanel) comp);
4109 public boolean sortBy(AlignmentOrder alorder, String undoname)
4111 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4112 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4113 if (undoname != null)
4115 addHistoryItem(new OrderCommand(undoname, oldOrder,
4116 viewport.getAlignment()));
4118 alignPanel.paintAlignment(true, false);
4123 * Work out whether the whole set of sequences or just the selected set will
4124 * be submitted for multiple alignment.
4128 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4130 // Now, check we have enough sequences
4131 AlignmentView msa = null;
4133 if ((viewport.getSelectionGroup() != null)
4134 && (viewport.getSelectionGroup().getSize() > 1))
4136 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4137 // some common interface!
4139 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4140 * SequenceI[sz = seqs.getSize(false)];
4142 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4143 * seqs.getSequenceAt(i); }
4145 msa = viewport.getAlignmentView(true);
4147 else if (viewport.getSelectionGroup() != null
4148 && viewport.getSelectionGroup().getSize() == 1)
4150 int option = JvOptionPane.showConfirmDialog(this,
4151 MessageManager.getString("warn.oneseq_msainput_selection"),
4152 MessageManager.getString("label.invalid_selection"),
4153 JvOptionPane.OK_CANCEL_OPTION);
4154 if (option == JvOptionPane.OK_OPTION)
4156 msa = viewport.getAlignmentView(false);
4161 msa = viewport.getAlignmentView(false);
4167 * Decides what is submitted to a secondary structure prediction service: the
4168 * first sequence in the alignment, or in the current selection, or, if the
4169 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4170 * region or the whole alignment. (where the first sequence in the set is the
4171 * one that the prediction will be for).
4174 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4176 AlignmentView seqs = null;
4178 if ((viewport.getSelectionGroup() != null)
4179 && (viewport.getSelectionGroup().getSize() > 0))
4181 seqs = viewport.getAlignmentView(true);
4185 seqs = viewport.getAlignmentView(false);
4187 // limit sequences - JBPNote in future - could spawn multiple prediction
4189 // TODO: viewport.getAlignment().isAligned is a global state - the local
4190 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4191 if (!viewport.getAlignment().isAligned(false))
4193 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4194 // TODO: if seqs.getSequences().length>1 then should really have warned
4209 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4211 // Pick the tree file
4212 JalviewFileChooser chooser = new JalviewFileChooser(
4213 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4214 chooser.setFileView(new JalviewFileView());
4215 chooser.setDialogTitle(
4216 MessageManager.getString("label.select_newick_like_tree_file"));
4217 chooser.setToolTipText(
4218 MessageManager.getString("label.load_tree_file"));
4220 chooser.setResponseHandler(0, new Runnable()
4226 String filePath = chooser.getSelectedFile().getPath();
4227 Cache.setProperty("LAST_DIRECTORY", filePath);
4228 NewickFile fin = null;
4231 fin = new NewickFile(new FileParse(chooser.getSelectedFile(),
4232 DataSourceType.FILE));
4233 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4234 } catch (Exception ex)
4236 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
4239 .getString("label.problem_reading_tree_file"),
4240 JvOptionPane.WARNING_MESSAGE);
4241 ex.printStackTrace();
4243 if (fin != null && fin.hasWarningMessage())
4245 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
4246 fin.getWarningMessage(),
4247 MessageManager.getString(
4248 "label.possible_problem_with_tree_file"),
4249 JvOptionPane.WARNING_MESSAGE);
4253 chooser.showOpenDialog(this);
4256 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4258 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4261 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4262 int h, int x, int y)
4264 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4268 * Add a treeviewer for the tree extracted from a Newick file object to the
4269 * current alignment view
4276 * Associated alignment input data (or null)
4285 * @return TreePanel handle
4288 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4289 AlignmentView input, int w, int h, int x, int y)
4291 TreePanel tp = null;
4297 if (nf.getTree() != null)
4299 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4300 Dimension dim = Platform.getDimIfEmbedded(tp, -1, -1);
4303 dim = new Dimension(w, h);
4307 // no offset, either
4310 tp.setSize(dim.width, dim.height);
4314 tp.setLocation(x, y);
4317 Desktop.addInternalFrame(tp, treeTitle, dim.width, dim.height);
4319 } catch (Exception ex)
4321 ex.printStackTrace();
4327 private boolean buildingMenu = false;
4330 * Generates menu items and listener event actions for web service clients
4334 public void BuildWebServiceMenu()
4336 while (buildingMenu)
4340 System.err.println("Waiting for building menu to finish.");
4342 } catch (Exception e)
4346 final AlignFrame me = this;
4347 buildingMenu = true;
4348 new Thread(new Runnable()
4354 final List<JMenuItem> legacyItems = new ArrayList<>();
4357 // System.err.println("Building ws menu again "
4358 // + Thread.currentThread());
4359 // TODO: add support for context dependent disabling of services based
4361 // alignment and current selection
4362 // TODO: add additional serviceHandle parameter to specify abstract
4364 // class independently of AbstractName
4365 // TODO: add in rediscovery GUI function to restart discoverer
4366 // TODO: group services by location as well as function and/or
4368 // object broker mechanism.
4369 final Vector<JMenu> wsmenu = new Vector<>();
4370 final IProgressIndicator af = me;
4373 * do not i18n these strings - they are hard-coded in class
4374 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4375 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4377 final JMenu msawsmenu = new JMenu("Alignment");
4378 final JMenu secstrmenu = new JMenu(
4379 "Secondary Structure Prediction");
4380 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4381 final JMenu analymenu = new JMenu("Analysis");
4382 final JMenu dismenu = new JMenu("Protein Disorder");
4383 // JAL-940 - only show secondary structure prediction services from
4384 // the legacy server
4385 Hashtable<String, Vector<ServiceHandle>> ds = Discoverer
4386 .getInstance().getServices();
4387 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4389 ds != null && (ds.size() > 0))
4391 // TODO: refactor to allow list of AbstractName/Handler bindings to
4393 // stored or retrieved from elsewhere
4394 // No MSAWS used any more:
4395 // Vector msaws = null; // (Vector)
4396 // Discoverer.services.get("MsaWS");
4397 Vector<ServiceHandle> secstrpr = ds.get("SecStrPred");
4398 if (secstrpr != null)
4400 // Add any secondary structure prediction services
4401 for (int i = 0, j = secstrpr.size(); i < j; i++)
4403 final ext.vamsas.ServiceHandle sh = secstrpr.get(i);
4404 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4405 .getServiceClient(sh);
4406 int p = secstrmenu.getItemCount();
4407 impl.attachWSMenuEntry(secstrmenu, me);
4408 int q = secstrmenu.getItemCount();
4409 for (int litm = p; litm < q; litm++)
4411 legacyItems.add(secstrmenu.getItem(litm));
4417 // Add all submenus in the order they should appear on the web
4419 wsmenu.add(msawsmenu);
4420 wsmenu.add(secstrmenu);
4421 wsmenu.add(dismenu);
4422 wsmenu.add(analymenu);
4423 // No search services yet
4424 // wsmenu.add(seqsrchmenu);
4426 javax.swing.SwingUtilities.invokeLater(new Runnable()
4434 webService.removeAll();
4435 // first, add discovered services onto the webservices menu
4436 if (wsmenu.size() > 0)
4438 for (int i = 0, j = wsmenu.size(); i < j; i++)
4440 webService.add(wsmenu.get(i));
4445 webService.add(me.webServiceNoServices);
4447 // TODO: move into separate menu builder class.
4448 // boolean new_sspred = false;
4449 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4451 Jws2Discoverer jws2servs = Jws2Discoverer.getInstance();
4452 if (jws2servs != null)
4454 if (jws2servs.hasServices())
4456 jws2servs.attachWSMenuEntry(webService, me);
4457 for (Jws2Instance sv : jws2servs.getServices())
4459 if (sv.description.toLowerCase().contains("jpred"))
4461 for (JMenuItem jmi : legacyItems)
4463 jmi.setVisible(false);
4469 if (jws2servs.isRunning())
4471 JMenuItem tm = new JMenuItem(
4472 "Still discovering JABA Services");
4473 tm.setEnabled(false);
4478 build_urlServiceMenu(me.webService);
4479 build_fetchdbmenu(webService);
4480 for (JMenu item : wsmenu)
4482 if (item.getItemCount() == 0)
4484 item.setEnabled(false);
4488 item.setEnabled(true);
4491 } catch (Exception e)
4494 "Exception during web service menu building process.",
4499 } catch (Exception e)
4502 buildingMenu = false;
4509 * construct any groupURL type service menu entries.
4514 protected void build_urlServiceMenu(JMenu webService)
4516 // TODO: remove this code when 2.7 is released
4517 // DEBUG - alignmentView
4519 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4520 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4522 * public void actionPerformed(ActionEvent e) {
4523 * jalview.datamodel.AlignmentView
4524 * .testSelectionViews(af.viewport.getAlignment(),
4525 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4527 * }); webService.add(testAlView);
4529 // TODO: refactor to RestClient discoverer and merge menu entries for
4530 // rest-style services with other types of analysis/calculation service
4531 // SHmmr test client - still being implemented.
4532 // DEBUG - alignmentView
4534 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4537 client.attachWSMenuEntry(
4538 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4544 * Searches the alignment sequences for xRefs and builds the Show
4545 * Cross-References menu (formerly called Show Products), with database
4546 * sources for which cross-references are found (protein sources for a
4547 * nucleotide alignment and vice versa)
4549 * @return true if Show Cross-references menu should be enabled
4552 public boolean canShowProducts()
4554 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4555 AlignmentI dataset = viewport.getAlignment().getDataset();
4557 showProducts.removeAll();
4558 final boolean dna = viewport.getAlignment().isNucleotide();
4560 if (seqs == null || seqs.length == 0)
4562 // nothing to see here.
4566 boolean showp = false;
4569 List<String> ptypes = new CrossRef(seqs, dataset)
4570 .findXrefSourcesForSequences(dna);
4572 for (final String source : ptypes)
4575 final AlignFrame af = this;
4576 JMenuItem xtype = new JMenuItem(source);
4577 xtype.addActionListener(new ActionListener()
4581 public void actionPerformed(ActionEvent e)
4583 showProductsFor(af.viewport.getSequenceSelection(), dna,
4587 showProducts.add(xtype);
4589 showProducts.setVisible(showp);
4590 showProducts.setEnabled(showp);
4591 } catch (Exception e)
4594 "canShowProducts threw an exception - please report to help@jalview.org",
4602 * Finds and displays cross-references for the selected sequences (protein
4603 * products for nucleotide sequences, dna coding sequences for peptides).
4606 * the sequences to show cross-references for
4608 * true if from a nucleotide alignment (so showing proteins)
4610 * the database to show cross-references for
4613 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4614 final String source)
4616 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4621 * Construct and display a new frame containing the translation of this
4622 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4626 public void showTranslation_actionPerformed(GeneticCodeI codeTable)
4628 AlignmentI al = null;
4631 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4633 al = dna.translateCdna(codeTable);
4634 } catch (Exception ex)
4636 jalview.bin.Cache.log.error(
4637 "Exception during translation. Please report this !", ex);
4638 final String msg = MessageManager.getString(
4639 "label.error_when_translating_sequences_submit_bug_report");
4640 final String errorTitle = MessageManager
4641 .getString("label.implementation_error")
4642 + MessageManager.getString("label.translation_failed");
4643 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msg,
4644 errorTitle, JvOptionPane.ERROR_MESSAGE);
4647 if (al == null || al.getHeight() == 0)
4649 final String msg = MessageManager.getString(
4650 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4651 final String errorTitle = MessageManager
4652 .getString("label.translation_failed");
4653 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msg,
4654 errorTitle, JvOptionPane.WARNING_MESSAGE);
4658 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4659 af.setFileFormat(this.currentFileFormat);
4660 final String newTitle = MessageManager
4661 .formatMessage("label.translation_of_params", new Object[]
4662 { this.getTitle(), codeTable.getId() });
4663 af.setTitle(newTitle);
4664 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4666 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4667 AlignViewport.openSplitFrame(this, af, new Alignment(seqs));
4671 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4678 * Set the file format
4683 public void setFileFormat(FileFormatI format)
4685 this.currentFileFormat = format;
4689 * Try to load a features file onto the alignment.
4692 * contents or path to retrieve file or a File object
4694 * access mode of file (see jalview.io.AlignFile)
4695 * @return true if features file was parsed correctly.
4698 public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
4701 return avc.parseFeaturesFile(file, sourceType,
4702 Cache.getDefault(Preferences.RELAXEDSEQIDMATCHING, false));
4707 public void refreshFeatureUI(boolean enableIfNecessary)
4709 // note - currently this is only still here rather than in the controller
4710 // because of the featureSettings hard reference that is yet to be
4712 if (enableIfNecessary)
4714 viewport.setShowSequenceFeatures(true);
4715 showSeqFeatures.setSelected(true);
4721 public void dragEnter(DropTargetDragEvent evt)
4726 public void dragExit(DropTargetEvent evt)
4731 public void dragOver(DropTargetDragEvent evt)
4736 public void dropActionChanged(DropTargetDragEvent evt)
4741 public void drop(DropTargetDropEvent evt)
4743 // JAL-1552 - acceptDrop required before getTransferable call for
4744 // Java's Transferable for native dnd
4745 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4746 Transferable t = evt.getTransferable();
4748 final List<Object> files = new ArrayList<>();
4749 List<DataSourceType> protocols = new ArrayList<>();
4753 Desktop.transferFromDropTarget(files, protocols, evt, t);
4754 if (files.size() > 0)
4756 new Thread(new Runnable()
4762 loadDroppedFiles(files, protocols, evt, t);
4766 } catch (Exception e)
4768 e.printStackTrace();
4772 protected void loadDroppedFiles(List<Object> files,
4773 List<DataSourceType> protocols, DropTargetDropEvent evt,
4778 // check to see if any of these files have names matching sequences
4781 SequenceIdMatcher idm = new SequenceIdMatcher(
4782 viewport.getAlignment().getSequencesArray());
4784 * Object[] { String,SequenceI}
4786 ArrayList<Object[]> filesmatched = new ArrayList<>();
4787 ArrayList<Object> filesnotmatched = new ArrayList<>();
4788 for (int i = 0; i < files.size(); i++)
4791 Object fileObj = files.get(i);
4792 String fileName = fileObj.toString();
4794 DataSourceType protocol = (fileObj instanceof File
4795 ? DataSourceType.FILE
4796 : FormatAdapter.checkProtocol(fileName));
4797 if (protocol == DataSourceType.FILE)
4800 if (fileObj instanceof File)
4802 file = (File) fileObj;
4803 Platform.cacheFileData(file);
4807 file = new File(fileName);
4809 pdbfn = file.getName();
4811 else if (protocol == DataSourceType.URL)
4813 URL url = new URL(fileName);
4814 pdbfn = url.getFile();
4816 if (pdbfn.length() > 0)
4818 // attempt to find a match in the alignment
4819 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4820 int l = 0, c = pdbfn.indexOf(".");
4821 while (mtch == null && c != -1)
4826 } while ((c = pdbfn.indexOf(".", l)) > l);
4829 pdbfn = pdbfn.substring(0, l);
4831 mtch = idm.findAllIdMatches(pdbfn);
4838 type = new IdentifyFile().identify(fileObj, protocol);
4839 } catch (Exception ex)
4843 if (type != null && type.isStructureFile())
4845 filesmatched.add(new Object[] { fileObj, protocol, mtch });
4849 // File wasn't named like one of the sequences or wasn't a PDB
4851 filesnotmatched.add(fileObj);
4855 if (filesmatched.size() > 0)
4857 boolean autoAssociate = Cache
4858 .getDefault(Preferences.AUTOASSOCIATE_PDBANDSEQS, false);
4861 String msg = MessageManager.formatMessage(
4862 "label.automatically_associate_structure_files_with_sequences_same_name",
4864 { Integer.valueOf(filesmatched.size()).toString() });
4865 String ttl = MessageManager.getString(
4866 "label.automatically_associate_structure_files_by_name");
4867 int choice = JvOptionPane.showConfirmDialog(this, msg, ttl,
4868 JvOptionPane.YES_NO_OPTION);
4869 autoAssociate = choice == JvOptionPane.YES_OPTION;
4873 for (Object[] fm : filesmatched)
4875 // try and associate
4876 // TODO: may want to set a standard ID naming formalism for
4877 // associating PDB files which have no IDs.
4878 for (SequenceI toassoc : (SequenceI[]) fm[2])
4880 PDBEntry pe = AssociatePdbFileWithSeq.associatePdbWithSeq(
4881 fm[0].toString(), (DataSourceType) fm[1], toassoc,
4885 System.err.println("Associated file : " + (fm[0].toString())
4886 + " with " + toassoc.getDisplayId(true));
4890 // TODO: do we need to update overview ? only if features are
4892 alignPanel.paintAlignment(true, false);
4898 * add declined structures as sequences
4900 for (Object[] o : filesmatched)
4902 filesnotmatched.add(o[0]);
4906 if (filesnotmatched.size() > 0)
4908 if (assocfiles > 0 && (Cache
4909 .getDefault("AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4910 || JvOptionPane.showConfirmDialog(this,
4911 "<html>" + MessageManager.formatMessage(
4912 "label.ignore_unmatched_dropped_files_info",
4914 { Integer.valueOf(filesnotmatched.size())
4917 MessageManager.getString(
4918 "label.ignore_unmatched_dropped_files"),
4919 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4923 for (Object fn : filesnotmatched)
4925 loadJalviewDataFile(fn, null, null, null);
4929 } catch (Exception ex)
4931 ex.printStackTrace();
4936 * Attempt to load a "dropped" file or URL string, by testing in turn for
4938 * <li>an Annotation file</li>
4939 * <li>a JNet file</li>
4940 * <li>a features file</li>
4941 * <li>else try to interpret as an alignment file</li>
4945 * either a filename or a URL string.
4948 public void loadJalviewDataFile(Object file, DataSourceType sourceType,
4949 FileFormatI format, SequenceI assocSeq)
4951 // BH 2018 was String file
4954 if (sourceType == null)
4956 sourceType = FormatAdapter.checkProtocol(file);
4958 // if the file isn't identified, or not positively identified as some
4959 // other filetype (PFAM is default unidentified alignment file type) then
4960 // try to parse as annotation.
4961 boolean isAnnotation = (format == null
4962 || FileFormat.Pfam.equals(format))
4963 ? new AnnotationFile().annotateAlignmentView(viewport,
4969 // first see if its a T-COFFEE score file
4970 TCoffeeScoreFile tcf = null;
4973 tcf = new TCoffeeScoreFile(file, sourceType);
4976 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4980 new TCoffeeColourScheme(viewport.getAlignment()));
4981 isAnnotation = true;
4982 setStatus(MessageManager.getString(
4983 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4987 // some problem - if no warning its probable that the ID matching
4988 // process didn't work
4989 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
4990 tcf.getWarningMessage() == null
4991 ? MessageManager.getString(
4992 "label.check_file_matches_sequence_ids_alignment")
4993 : tcf.getWarningMessage(),
4994 MessageManager.getString(
4995 "label.problem_reading_tcoffee_score_file"),
4996 JvOptionPane.WARNING_MESSAGE);
5003 } catch (Exception x)
5006 "Exception when processing data source as T-COFFEE score file",
5012 // try to see if its a JNet 'concise' style annotation file *before*
5014 // try to parse it as a features file
5017 format = new IdentifyFile().identify(file, sourceType);
5019 if (FileFormat.ScoreMatrix == format)
5021 ScoreMatrixFile sm = new ScoreMatrixFile(
5022 new FileParse(file, sourceType));
5024 // todo: i18n this message
5025 setStatus(MessageManager.formatMessage(
5026 "label.successfully_loaded_matrix",
5027 sm.getMatrixName()));
5029 else if (FileFormat.Jnet.equals(format))
5031 JPredFile predictions = new JPredFile(file, sourceType);
5032 new JnetAnnotationMaker();
5033 JnetAnnotationMaker.add_annotation(predictions,
5034 viewport.getAlignment(), 0, false);
5035 viewport.getAlignment().setupJPredAlignment();
5036 isAnnotation = true;
5038 // else if (IdentifyFile.FeaturesFile.equals(format))
5039 else if (FileFormat.Features.equals(format))
5041 if (parseFeaturesFile(file, sourceType))
5043 SplitFrame splitFrame = (SplitFrame) getSplitViewContainer();
5044 if (splitFrame != null)
5046 splitFrame.repaint();
5050 alignPanel.paintAlignment(true, true);
5056 new FileLoader().LoadFile(viewport, file, sourceType, format);
5062 updateForAnnotations();
5064 } catch (Exception ex)
5066 ex.printStackTrace();
5067 } catch (OutOfMemoryError oom)
5072 } catch (Exception x)
5077 + (sourceType != null
5078 ? (sourceType == DataSourceType.PASTE
5080 : "using " + sourceType + " from "
5084 ? "(parsing as '" + format + "' file)"
5086 oom, Desktop.getDesktopPane());
5091 * Do all updates necessary after an annotation file such as jnet. Also called
5092 * from Jalview.loadAppletParams for "annotations", "jnetFile"
5095 public void updateForAnnotations()
5097 alignPanel.adjustAnnotationHeight();
5098 viewport.updateSequenceIdColours();
5099 buildSortByAnnotationScoresMenu();
5100 alignPanel.paintAlignment(true, true);
5104 * Change the display state for the given feature groups -- Added by BH from
5108 * list of group strings
5110 * visible or invisible
5113 public void setFeatureGroupState(String[] groups, boolean state)
5115 jalview.api.FeatureRenderer fr = null;
5116 viewport.setShowSequenceFeatures(true);
5117 if (alignPanel != null
5118 && (fr = alignPanel.getFeatureRenderer()) != null)
5121 fr.setGroupVisibility(Arrays.asList(groups), state);
5122 alignPanel.getSeqPanel().seqCanvas.repaint();
5123 if (alignPanel.overviewPanel != null)
5125 alignPanel.overviewPanel.updateOverviewImage();
5131 * Method invoked by the ChangeListener on the tabbed pane, in other words
5132 * when a different tabbed pane is selected by the user or programmatically.
5136 public void tabSelectionChanged(int index)
5140 alignPanel = alignPanels.get(index);
5141 viewport = alignPanel.av;
5142 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5143 setMenusFromViewport(viewport);
5144 if (featureSettings != null && featureSettings.isOpen()
5145 && featureSettings.fr.getViewport() != viewport)
5147 if (viewport.isShowSequenceFeatures())
5149 // refresh the featureSettings to reflect UI change
5150 showFeatureSettingsUI();
5154 // close feature settings for this view.
5155 featureSettings.close();
5162 * 'focus' any colour slider that is open to the selected viewport
5164 if (viewport.getConservationSelected())
5166 SliderPanel.setConservationSlider(alignPanel,
5167 viewport.getResidueShading(), alignPanel.getViewName());
5171 SliderPanel.hideConservationSlider();
5173 if (viewport.getAbovePIDThreshold())
5175 SliderPanel.setPIDSliderSource(alignPanel,
5176 viewport.getResidueShading(), alignPanel.getViewName());
5180 SliderPanel.hidePIDSlider();
5184 * If there is a frame linked to this one in a SplitPane, switch it to the
5185 * same view tab index. No infinite recursion of calls should happen, since
5186 * tabSelectionChanged() should not get invoked on setting the selected
5187 * index to an unchanged value. Guard against setting an invalid index
5188 * before the new view peer tab has been created.
5190 final AlignViewportI peer = viewport.getCodingComplement();
5193 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
5194 .getAlignPanel().alignFrame;
5195 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5197 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5203 * On right mouse click on view tab, prompt for and set new view name.
5207 public void tabbedPane_mousePressed(MouseEvent e)
5209 if (e.isPopupTrigger())
5211 String msg = MessageManager.getString("label.enter_view_name");
5212 String ttl = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
5213 String reply = JvOptionPane.showInputDialog(msg, ttl);
5217 viewport.setViewName(reply);
5218 // TODO warn if reply is in getExistingViewNames()?
5219 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5224 public AlignViewport getCurrentView()
5230 * Open the dialog for regex description parsing.
5234 protected void extractScores_actionPerformed(ActionEvent e)
5236 ParseProperties pp = new jalview.analysis.ParseProperties(
5237 viewport.getAlignment());
5238 // TODO: verify regex and introduce GUI dialog for version 2.5
5239 // if (pp.getScoresFromDescription("col", "score column ",
5240 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5242 if (pp.getScoresFromDescription("description column",
5243 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5245 buildSortByAnnotationScoresMenu();
5253 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5258 protected void showDbRefs_actionPerformed(ActionEvent e)
5260 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5266 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5271 protected void showNpFeats_actionPerformed(ActionEvent e)
5273 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5277 * find the viewport amongst the tabs in this alignment frame and close that
5283 public boolean closeView(AlignViewportI av)
5287 this.closeMenuItem_actionPerformed(false);
5290 Component[] comp = tabbedPane.getComponents();
5291 for (int i = 0; comp != null && i < comp.length; i++)
5293 if (comp[i] instanceof AlignmentPanel)
5295 if (((AlignmentPanel) comp[i]).av == av)
5298 closeView((AlignmentPanel) comp[i]);
5306 protected void build_fetchdbmenu(JMenu webService)
5308 // Temporary hack - DBRef Fetcher always top level ws entry.
5309 // TODO We probably want to store a sequence database checklist in
5310 // preferences and have checkboxes.. rather than individual sources selected
5312 final JMenu rfetch = new JMenu(
5313 MessageManager.getString("action.fetch_db_references"));
5314 rfetch.setToolTipText(MessageManager.getString(
5315 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5316 webService.add(rfetch);
5318 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5319 MessageManager.getString("option.trim_retrieved_seqs"));
5320 trimrs.setToolTipText(
5321 MessageManager.getString("label.trim_retrieved_sequences"));
5323 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5324 trimrs.addActionListener(new ActionListener()
5328 public void actionPerformed(ActionEvent e)
5330 trimrs.setSelected(trimrs.isSelected());
5331 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5332 Boolean.valueOf(trimrs.isSelected()).toString());
5336 JMenuItem fetchr = new JMenuItem(
5337 MessageManager.getString("label.standard_databases"));
5338 fetchr.setToolTipText(
5339 MessageManager.getString("label.fetch_embl_uniprot"));
5340 fetchr.addActionListener(new ActionListener()
5344 public void actionPerformed(ActionEvent e)
5346 new Thread(new Runnable()
5352 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5353 .getAlignment().isNucleotide();
5354 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5355 alignPanel.av.getSequenceSelection(),
5356 alignPanel.alignFrame, null,
5357 alignPanel.alignFrame.featureSettings, isNucleotide);
5358 dbRefFetcher.addListener(new FetchFinishedListenerI()
5362 public void finished()
5365 for (FeatureSettingsModelI srcSettings : dbRefFetcher
5366 .getFeatureSettingsModels())
5369 alignPanel.av.mergeFeaturesStyle(srcSettings);
5371 AlignFrame.this.setMenusForViewport();
5374 dbRefFetcher.fetchDBRefs(false);
5382 new Thread(new Runnable()
5389 // final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5390 // .getSequenceFetcherSingleton();
5391 javax.swing.SwingUtilities.invokeLater(new Runnable()
5397 jalview.ws.SequenceFetcher sf = jalview.ws.SequenceFetcher
5399 String[] dbclasses = sf.getNonAlignmentSources();
5400 List<DbSourceProxy> otherdb;
5401 JMenu dfetch = new JMenu();
5402 JMenu ifetch = new JMenu();
5403 JMenuItem fetchr = null;
5404 int comp = 0, icomp = 0, mcomp = 15;
5405 String mname = null;
5407 for (String dbclass : dbclasses)
5409 otherdb = sf.getSourceProxy(dbclass);
5410 // add a single entry for this class, or submenu allowing 'fetch
5412 if (otherdb == null || otherdb.size() < 1)
5418 mname = "From " + dbclass;
5420 if (otherdb.size() == 1)
5422 DbSourceProxy src = otherdb.get(0);
5423 DbSourceProxy[] dassource = new DbSourceProxy[] { src };
5424 fetchr = new JMenuItem(src.getDbSource());
5425 fetchr.addActionListener(new ActionListener()
5429 public void actionPerformed(ActionEvent e)
5431 new Thread(new Runnable()
5437 boolean isNucleotide = alignPanel.alignFrame
5438 .getViewport().getAlignment()
5440 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5441 alignPanel.av.getSequenceSelection(),
5442 alignPanel.alignFrame, dassource,
5443 alignPanel.alignFrame.featureSettings,
5446 .addListener(new FetchFinishedListenerI()
5450 public void finished()
5452 FeatureSettingsModelI srcSettings = dassource[0]
5453 .getFeatureColourScheme();
5454 alignPanel.av.mergeFeaturesStyle(
5456 AlignFrame.this.setMenusForViewport();
5459 dbRefFetcher.fetchDBRefs(false);
5465 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5466 MessageManager.formatMessage(
5467 "label.fetch_retrieve_from", new Object[]
5468 { src.getDbName() })));
5474 final DbSourceProxy[] dassource = otherdb
5475 .toArray(new DbSourceProxy[0]);
5477 DbSourceProxy src = otherdb.get(0);
5478 fetchr = new JMenuItem(MessageManager
5479 .formatMessage("label.fetch_all_param", new Object[]
5480 { src.getDbSource() }));
5481 fetchr.addActionListener(new ActionListener()
5485 public void actionPerformed(ActionEvent e)
5487 new Thread(new Runnable()
5493 boolean isNucleotide = alignPanel.alignFrame
5494 .getViewport().getAlignment()
5496 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5497 alignPanel.av.getSequenceSelection(),
5498 alignPanel.alignFrame, dassource,
5499 alignPanel.alignFrame.featureSettings,
5502 .addListener(new FetchFinishedListenerI()
5506 public void finished()
5508 AlignFrame.this.setMenusForViewport();
5511 dbRefFetcher.fetchDBRefs(false);
5517 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5518 MessageManager.formatMessage(
5519 "label.fetch_retrieve_from_all_sources",
5521 { Integer.valueOf(otherdb.size())
5523 src.getDbSource(), src.getDbName() })));
5526 // and then build the rest of the individual menus
5527 ifetch = new JMenu(MessageManager.formatMessage(
5528 "label.source_from_db_source", new Object[]
5529 { src.getDbSource() }));
5531 String imname = null;
5533 for (DbSourceProxy sproxy : otherdb)
5535 String dbname = sproxy.getDbName();
5536 String sname = dbname.length() > 5
5537 ? dbname.substring(0, 5) + "..."
5539 String msname = dbname.length() > 10
5540 ? dbname.substring(0, 10) + "..."
5544 imname = MessageManager
5545 .formatMessage("label.from_msname", new Object[]
5548 fetchr = new JMenuItem(msname);
5549 final DbSourceProxy[] dassrc = { sproxy };
5550 fetchr.addActionListener(new ActionListener()
5554 public void actionPerformed(ActionEvent e)
5556 new Thread(new Runnable()
5562 boolean isNucleotide = alignPanel.alignFrame
5563 .getViewport().getAlignment()
5565 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5566 alignPanel.av.getSequenceSelection(),
5567 alignPanel.alignFrame, dassrc,
5568 alignPanel.alignFrame.featureSettings,
5571 .addListener(new FetchFinishedListenerI()
5575 public void finished()
5577 AlignFrame.this.setMenusForViewport();
5580 dbRefFetcher.fetchDBRefs(false);
5586 fetchr.setToolTipText(
5587 "<html>" + MessageManager.formatMessage(
5588 "label.fetch_retrieve_from", new Object[]
5592 if (++icomp >= mcomp || i == (otherdb.size()))
5594 ifetch.setText(MessageManager.formatMessage(
5595 "label.source_to_target", imname, sname));
5597 ifetch = new JMenu();
5605 if (comp >= mcomp || dbi >= (dbclasses.length))
5607 dfetch.setText(MessageManager.formatMessage(
5608 "label.source_to_target", mname, dbclass));
5610 dfetch = new JMenu();
5623 * Left justify the whole alignment.
5627 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5629 viewport.getAlignment().justify(false);
5630 viewport.notifyAlignment();
5634 * Right justify the whole alignment.
5638 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5640 viewport.getAlignment().justify(true);
5641 viewport.notifyAlignment();
5645 public void setShowSeqFeatures(boolean b)
5647 showSeqFeatures.setSelected(b);
5648 viewport.setShowSequenceFeatures(b);
5655 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5656 * awt.event.ActionEvent)
5660 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5662 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5663 alignPanel.paintAlignment(false, false);
5670 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5675 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5677 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5678 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5686 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5687 * .event.ActionEvent)
5691 protected void showGroupConservation_actionPerformed(ActionEvent e)
5693 viewport.setShowGroupConservation(showGroupConservation.getState());
5694 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5701 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5702 * .event.ActionEvent)
5706 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5708 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5709 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5716 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5717 * .event.ActionEvent)
5721 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5723 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5724 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5728 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5730 showSequenceLogo.setState(true);
5731 viewport.setShowSequenceLogo(true);
5732 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5733 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5737 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5739 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5746 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5747 * .event.ActionEvent)
5751 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5753 if (avc.makeGroupsFromSelection())
5755 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5756 alignPanel.updateAnnotation();
5757 alignPanel.paintAlignment(true,
5758 viewport.needToUpdateStructureViews());
5762 public void clearAlignmentSeqRep()
5764 // TODO refactor alignmentseqrep to controller
5765 if (viewport.getAlignment().hasSeqrep())
5767 viewport.getAlignment().setSeqrep(null);
5768 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5769 alignPanel.updateAnnotation();
5770 alignPanel.paintAlignment(true, true);
5775 protected void createGroup_actionPerformed(ActionEvent e)
5777 if (avc.createGroup())
5779 if (applyAutoAnnotationSettings.isSelected())
5781 alignPanel.updateAnnotation(true, false);
5783 alignPanel.alignmentChanged();
5788 protected void unGroup_actionPerformed(ActionEvent e)
5792 alignPanel.alignmentChanged();
5797 * make the given alignmentPanel the currently selected tab
5799 * @param alignmentPanel
5802 public void setDisplayedView(AlignmentPanel alignmentPanel)
5804 if (!viewport.getSequenceSetId()
5805 .equals(alignmentPanel.av.getSequenceSetId()))
5807 throw new Error(MessageManager.getString(
5808 "error.implementation_error_cannot_show_view_alignment_frame"));
5810 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5811 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5813 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5818 * Action on selection of menu options to Show or Hide annotations.
5821 * @param forSequences
5822 * update sequence-related annotations
5823 * @param forAlignment
5824 * update non-sequence-related annotations
5828 protected void setAnnotationsVisibility(boolean visible,
5829 boolean forSequences, boolean forAlignment)
5831 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5832 .getAlignmentAnnotation();
5837 for (AlignmentAnnotation aa : anns)
5840 * don't display non-positional annotations on an alignment
5842 if (aa.annotations == null)
5846 boolean apply = (aa.sequenceRef == null && forAlignment)
5847 || (aa.sequenceRef != null && forSequences);
5850 aa.visible = visible;
5853 alignPanel.validateAnnotationDimensions(true);
5854 alignPanel.alignmentChanged();
5858 * Store selected annotation sort order for the view and repaint.
5862 protected void sortAnnotations_actionPerformed()
5864 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5866 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5867 alignPanel.paintAlignment(false, false);
5872 * @return alignment panels in this alignment frame
5875 public List<? extends AlignmentViewPanel> getAlignPanels()
5877 // alignPanels is never null
5878 // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5883 * Open a new alignment window, with the cDNA associated with this (protein)
5884 * alignment, aligned as is the protein.
5887 protected void viewAsCdna_actionPerformed()
5889 // TODO no longer a menu action - refactor as required
5890 final AlignmentI alignment = getViewport().getAlignment();
5891 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5892 if (mappings == null)
5896 List<SequenceI> cdnaSeqs = new ArrayList<>();
5897 for (SequenceI aaSeq : alignment.getSequences())
5899 for (AlignedCodonFrame acf : mappings)
5901 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5905 * There is a cDNA mapping for this protein sequence - add to new
5906 * alignment. It will share the same dataset sequence as other mapped
5907 * cDNA (no new mappings need to be created).
5909 final Sequence newSeq = new Sequence(dnaSeq);
5910 newSeq.setDatasetSequence(dnaSeq);
5911 cdnaSeqs.add(newSeq);
5915 if (cdnaSeqs.size() == 0)
5917 // show a warning dialog no mapped cDNA
5920 AlignmentI cdna = new Alignment(
5921 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5922 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5923 AlignFrame.DEFAULT_HEIGHT);
5924 cdna.alignAs(alignment);
5925 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5927 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5928 AlignFrame.DEFAULT_HEIGHT);
5932 * Set visibility of dna/protein complement view (available when shown in a
5939 protected void showComplement_actionPerformed(boolean show)
5941 SplitContainerI sf = getSplitViewContainer();
5944 sf.setComplementVisible(this, show);
5949 * Generate the reverse (optionally complemented) of the selected sequences,
5950 * and add them to the alignment
5954 protected void showReverse_actionPerformed(boolean complement)
5956 AlignmentI al = null;
5959 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5960 al = dna.reverseCdna(complement);
5961 viewport.addAlignment(al, "");
5962 addHistoryItem(new EditCommand(
5963 MessageManager.getString("label.add_sequences"), Action.PASTE,
5964 al.getSequencesArray(), 0, al.getWidth(),
5965 viewport.getAlignment()));
5966 } catch (Exception ex)
5968 System.err.println(ex.getMessage());
5974 * Try to run a script in the Groovy console, having first ensured that this
5975 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5976 * be targeted at this alignment.
5980 protected void runGroovy_actionPerformed()
5982 Jalview.setCurrentAlignFrame(this);
5983 groovy.ui.Console console = Desktop.getGroovyConsole();
5984 if (console != null)
5988 console.runScript();
5989 } catch (Exception ex)
5991 System.err.println((ex.toString()));
5992 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
5993 MessageManager.getString("label.couldnt_run_groovy_script"),
5994 MessageManager.getString("label.groovy_support_failed"),
5995 JvOptionPane.ERROR_MESSAGE);
6000 System.err.println("Can't run Groovy script as console not found");
6005 * Hides columns containing (or not containing) a specified feature, provided
6006 * that would not leave all columns hidden
6008 * @param featureType
6009 * @param columnsContaining
6013 public boolean hideFeatureColumns(String featureType,
6014 boolean columnsContaining)
6016 boolean notForHiding = avc.markColumnsContainingFeatures(
6017 columnsContaining, false, false, featureType);
6020 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
6021 false, featureType))
6023 getViewport().hideSelectedColumns();
6031 protected void selectHighlightedColumns_actionPerformed(
6032 ActionEvent actionEvent)
6034 // include key modifier check in case user selects from menu
6035 avc.markHighlightedColumns(
6036 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
6037 (actionEvent.getModifiers() & (ActionEvent.META_MASK
6038 | ActionEvent.CTRL_MASK)) != 0);
6042 * Rebuilds the Colour menu, including any user-defined colours which have
6043 * been loaded either on startup or during the session
6046 public void buildColourMenu()
6048 colourMenu.removeAll();
6050 colourMenu.add(applyToAllGroups);
6051 colourMenu.add(textColour);
6052 colourMenu.addSeparator();
6054 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
6055 viewport.getAlignment(), false);
6057 colourMenu.add(annotationColour);
6058 bg.add(annotationColour);
6059 colourMenu.addSeparator();
6060 colourMenu.add(conservationMenuItem);
6061 colourMenu.add(modifyConservation);
6062 colourMenu.add(abovePIDThreshold);
6063 colourMenu.add(modifyPID);
6065 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
6066 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
6070 * Open a dialog (if not already open) that allows the user to select and
6071 * calculate PCA or Tree analysis
6074 protected void openTreePcaDialog()
6076 if (alignPanel.getCalculationDialog() == null)
6078 new CalculationChooser(AlignFrame.this);
6083 protected void loadVcf_actionPerformed()
6085 JalviewFileChooser chooser = new JalviewFileChooser(
6086 Cache.getProperty("LAST_DIRECTORY"));
6087 chooser.setFileView(new JalviewFileView());
6088 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
6089 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
6090 final AlignFrame us = this;
6091 chooser.setResponseHandler(0, new Runnable()
6097 String choice = chooser.getSelectedFile().getPath();
6098 Cache.setProperty("LAST_DIRECTORY", choice);
6099 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
6100 new VCFLoader(choice).loadVCF(seqs, us);
6103 chooser.showOpenDialog(null);
6107 private Rectangle lastFeatureSettingsBounds = null;
6110 public void setFeatureSettingsGeometry(Rectangle bounds)
6112 lastFeatureSettingsBounds = bounds;
6116 public Rectangle getFeatureSettingsGeometry()
6118 return lastFeatureSettingsBounds;
6121 public void scrollTo(int row, int column)
6123 alignPanel.getSeqPanel().scrollTo(row, column);
6126 public void scrollToRow(int row)
6128 alignPanel.getSeqPanel().scrollToRow(row);
6131 public void scrollToColumn(int column)
6133 alignPanel.getSeqPanel().scrollToColumn(column);
6137 * BH 2019 from JalviewLite
6139 * get sequence feature groups that are hidden or shown
6146 public String[] getFeatureGroupsOfState(boolean visible)
6148 jalview.api.FeatureRenderer fr = null;
6149 if (alignPanel != null
6150 && (fr = alignPanel.getFeatureRenderer()) != null)
6152 List<String> gps = fr.getGroups(visible);
6153 String[] _gps = gps.toArray(new String[gps.size()]);
6161 * @return list of feature groups on the view
6164 public String[] getFeatureGroups()
6166 jalview.api.FeatureRenderer fr = null;
6167 if (alignPanel != null
6168 && (fr = alignPanel.getFeatureRenderer()) != null)
6170 List<String> gps = fr.getFeatureGroups();
6171 String[] _gps = gps.toArray(new String[gps.size()]);
6177 public void select(SequenceGroup sel, ColumnSelection csel,
6178 HiddenColumns hidden)
6180 alignPanel.getSeqPanel().selection(sel, csel, hidden, null);
6188 static class PrintThread extends Thread
6192 public PrintThread(AlignmentPanel ap)
6197 static PageFormat pf;
6202 PrinterJob printJob = PrinterJob.getPrinterJob();
6206 printJob.setPrintable(ap, pf);
6210 printJob.setPrintable(ap);
6213 if (printJob.printDialog())
6218 } catch (Exception PrintException)
6220 PrintException.printStackTrace();