2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Dimension;
27 import java.awt.Rectangle;
28 import java.awt.Toolkit;
29 import java.awt.datatransfer.Clipboard;
30 import java.awt.datatransfer.DataFlavor;
31 import java.awt.datatransfer.StringSelection;
32 import java.awt.datatransfer.Transferable;
33 import java.awt.dnd.DnDConstants;
34 import java.awt.dnd.DropTargetDragEvent;
35 import java.awt.dnd.DropTargetDropEvent;
36 import java.awt.dnd.DropTargetEvent;
37 import java.awt.dnd.DropTargetListener;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.awt.event.FocusAdapter;
41 import java.awt.event.FocusEvent;
42 import java.awt.event.ItemEvent;
43 import java.awt.event.ItemListener;
44 import java.awt.event.KeyAdapter;
45 import java.awt.event.KeyEvent;
46 import java.awt.event.MouseEvent;
47 import java.awt.print.PageFormat;
48 import java.awt.print.PrinterJob;
49 import java.beans.PropertyChangeEvent;
50 import java.beans.PropertyChangeListener;
52 import java.io.FileWriter;
53 import java.io.PrintWriter;
55 import java.util.ArrayList;
56 import java.util.Arrays;
57 import java.util.Deque;
58 import java.util.Enumeration;
59 import java.util.Hashtable;
60 import java.util.List;
61 import java.util.Vector;
63 import javax.swing.ButtonGroup;
64 import javax.swing.JCheckBoxMenuItem;
65 import javax.swing.JComponent;
66 import javax.swing.JEditorPane;
67 import javax.swing.JInternalFrame;
68 import javax.swing.JLabel;
69 import javax.swing.JLayeredPane;
70 import javax.swing.JMenu;
71 import javax.swing.JMenuItem;
72 import javax.swing.JPanel;
73 import javax.swing.JScrollPane;
74 import javax.swing.SwingUtilities;
76 import ext.vamsas.ServiceHandle;
77 import jalview.analysis.AlignmentSorter;
78 import jalview.analysis.AlignmentUtils;
79 import jalview.analysis.CrossRef;
80 import jalview.analysis.Dna;
81 import jalview.analysis.GeneticCodeI;
82 import jalview.analysis.ParseProperties;
83 import jalview.analysis.SequenceIdMatcher;
84 import jalview.api.AlignExportSettingsI;
85 import jalview.api.AlignFrameI;
86 import jalview.api.AlignViewControllerGuiI;
87 import jalview.api.AlignViewControllerI;
88 import jalview.api.AlignViewportI;
89 import jalview.api.AlignmentViewPanel;
90 import jalview.api.FeatureSettingsControllerI;
91 import jalview.api.FeatureSettingsModelI;
92 import jalview.api.SplitContainerI;
93 import jalview.api.ViewStyleI;
94 import jalview.api.analysis.SimilarityParamsI;
95 import jalview.bin.Cache;
96 import jalview.bin.Jalview;
97 import jalview.commands.CommandI;
98 import jalview.commands.EditCommand;
99 import jalview.commands.EditCommand.Action;
100 import jalview.commands.OrderCommand;
101 import jalview.commands.RemoveGapColCommand;
102 import jalview.commands.RemoveGapsCommand;
103 import jalview.commands.SlideSequencesCommand;
104 import jalview.commands.TrimRegionCommand;
105 import jalview.datamodel.AlignExportSettingsAdapter;
106 import jalview.datamodel.AlignedCodonFrame;
107 import jalview.datamodel.Alignment;
108 import jalview.datamodel.AlignmentAnnotation;
109 import jalview.datamodel.AlignmentExportData;
110 import jalview.datamodel.AlignmentI;
111 import jalview.datamodel.AlignmentOrder;
112 import jalview.datamodel.AlignmentView;
113 import jalview.datamodel.ColumnSelection;
114 import jalview.datamodel.HiddenColumns;
115 import jalview.datamodel.PDBEntry;
116 import jalview.datamodel.SeqCigar;
117 import jalview.datamodel.Sequence;
118 import jalview.datamodel.SequenceGroup;
119 import jalview.datamodel.SequenceI;
120 import jalview.gui.ColourMenuHelper.ColourChangeListener;
121 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
122 import jalview.io.AlignmentProperties;
123 import jalview.io.AnnotationFile;
124 import jalview.io.BackupFiles;
125 import jalview.io.BioJsHTMLOutput;
126 import jalview.io.DataSourceType;
127 import jalview.io.FileFormat;
128 import jalview.io.FileFormatI;
129 import jalview.io.FileFormats;
130 import jalview.io.FileLoader;
131 import jalview.io.FileParse;
132 import jalview.io.FormatAdapter;
133 import jalview.io.HtmlSvgOutput;
134 import jalview.io.IdentifyFile;
135 import jalview.io.JPredFile;
136 import jalview.io.JalviewFileChooser;
137 import jalview.io.JalviewFileView;
138 import jalview.io.JnetAnnotationMaker;
139 import jalview.io.NewickFile;
140 import jalview.io.ScoreMatrixFile;
141 import jalview.io.TCoffeeScoreFile;
142 import jalview.io.vcf.VCFLoader;
143 import jalview.jbgui.GAlignFrame;
144 import jalview.project.Jalview2XML;
145 import jalview.schemes.ColourSchemeI;
146 import jalview.schemes.ColourSchemes;
147 import jalview.schemes.ResidueColourScheme;
148 import jalview.schemes.TCoffeeColourScheme;
149 import jalview.util.ImageMaker.TYPE;
150 import jalview.util.MessageManager;
151 import jalview.util.Platform;
152 import jalview.viewmodel.AlignmentViewport;
153 import jalview.viewmodel.ViewportRanges;
154 import jalview.ws.DBRefFetcher;
155 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
156 import jalview.ws.jws1.Discoverer;
157 import jalview.ws.jws2.Jws2Discoverer;
158 import jalview.ws.jws2.jabaws2.Jws2Instance;
159 import jalview.ws.seqfetcher.DbSourceProxy;
165 * @version $Revision$
167 @SuppressWarnings("serial")
168 public class AlignFrame extends GAlignFrame
169 implements AlignFrameI, DropTargetListener,
170 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
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 private String fileName = null;
198 private File fileObject;
201 * Creates a new AlignFrame object with specific width and height.
207 public AlignFrame(AlignmentI al, int width, int height)
209 this(al, null, width, height);
213 * Creates a new AlignFrame object with specific width, height and
219 * @param sequenceSetId
221 public AlignFrame(AlignmentI al, int width, int height,
222 String sequenceSetId)
224 this(al, null, width, height, sequenceSetId);
228 * Creates a new AlignFrame object with specific width, height and
234 * @param sequenceSetId
237 public AlignFrame(AlignmentI al, int width, int height,
238 String sequenceSetId, String viewId)
240 this(al, null, width, height, sequenceSetId, viewId);
244 * new alignment window with hidden columns
248 * @param hiddenColumns
249 * ColumnSelection or null
251 * Width of alignment frame
255 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
258 this(al, hiddenColumns, width, height, null);
262 * Create alignment frame for al with hiddenColumns, a specific width and
263 * height, and specific sequenceId
266 * @param hiddenColumns
269 * @param sequenceSetId
272 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
273 int height, String sequenceSetId)
275 this(al, hiddenColumns, width, height, sequenceSetId, null);
279 * Create alignment frame for al with hiddenColumns, a specific width and
280 * height, and specific sequenceId
283 * @param hiddenColumns
286 * @param sequenceSetId
291 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
292 int height, String sequenceSetId, String viewId)
294 setSize(width, height);
296 if (al.getDataset() == null)
301 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
302 // BH! new alignPanel must come later
303 // alignPanel = new AlignmentPanel(this, viewport);
304 // addAlignmentPanel(alignPanel, true);
309 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
310 HiddenColumns hiddenColumns, int width, int height)
312 setSize(width, height);
314 if (al.getDataset() == null)
319 viewport = new AlignViewport(al, hiddenColumns);
321 if (hiddenSeqs != null && hiddenSeqs.length > 0)
323 viewport.hideSequence(hiddenSeqs);
325 // BH! new alignPanel must come later
326 //alignPanel = new AlignmentPanel(this, viewport);
327 //addAlignmentPanel(alignPanel, true);
332 * Make a new AlignFrame from existing alignmentPanels
339 public AlignFrame(AlignmentPanel ap)
343 // BH! adding must come later
344 // addAlignmentPanel(ap, false);
349 * initalise the alignframe from the underlying viewport data and the
354 // BH! Here is where we create the panel; note the sequence
355 boolean newPanel = (alignPanel == null);
356 viewport.setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
361 // need to set this up front if NOANNOTATION is
362 // used in conjunction with SHOWOVERVIEW.
364 // I have not determined if this is appropriate for
365 // Jalview/Java, as it means we are setting this flag
366 // for all subsequent AlignFrames. For now, at least,
367 // I am setting it to be JalviewJS-only.
369 boolean showAnnotation = Jalview.getInstance().getShowAnnotation();
370 viewport.setShowAnnotation(showAnnotation);
372 alignPanel = new AlignmentPanel(this, viewport);
374 addAlignmentPanel(alignPanel, newPanel);
376 // setBackground(Color.white); // BH 2019
378 // BH meaning "without display, one way or another"
379 if (!Jalview.isHeadlessMode())
381 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
382 statusPanel.setVisible(Jalview.getInstance().getShowStatus());
383 alignFrameMenuBar.setVisible(Jalview.getInstance().getAllowMenuBar());
386 avc = new jalview.controller.AlignViewController(this, viewport,
388 if (viewport.getAlignmentConservationAnnotation() == null)
390 // BLOSUM62Colour.setEnabled(false);
391 conservationMenuItem.setEnabled(false);
392 modifyConservation.setEnabled(false);
393 // PIDColour.setEnabled(false);
394 // abovePIDThreshold.setEnabled(false);
395 // modifyPID.setEnabled(false);
398 String sortby = Cache.getDefault(Preferences.SORT_ALIGNMENT,
401 if (sortby.equals("Id"))
403 sortIDMenuItem_actionPerformed(null);
405 else if (sortby.equals("Pairwise Identity"))
407 sortPairwiseMenuItem_actionPerformed(null);
411 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
413 setMenusFromViewport(viewport);
414 buildSortByAnnotationScoresMenu();
415 calculateTree.addActionListener(new ActionListener()
419 public void actionPerformed(ActionEvent e)
426 if (Desktop.getDesktopPane() != null)
428 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
429 if (!Platform.isJS())
431 addServiceListeners();
436 if (viewport.getWrapAlignment())
438 wrapMenuItem_actionPerformed(null);
441 if (jalview.bin.Cache.getDefault(Preferences.SHOW_OVERVIEW, false))
443 this.overviewMenuItem_actionPerformed(null);
448 final List<AlignmentPanel> selviews = new ArrayList<>();
449 final List<AlignmentPanel> origview = new ArrayList<>();
450 final String menuLabel = MessageManager
451 .getString("label.copy_format_from");
452 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
453 new ViewSetProvider()
457 public AlignmentPanel[] getAllAlignmentPanels()
460 origview.add(alignPanel);
461 // make an array of all alignment panels except for this one
462 List<AlignmentPanel> aps = new ArrayList<>(
463 Arrays.asList(Desktop.getAlignmentPanels(null)));
464 aps.remove(AlignFrame.this.alignPanel);
465 return aps.toArray(new AlignmentPanel[aps.size()]);
467 }, selviews, new ItemListener()
471 public void itemStateChanged(ItemEvent e)
473 if (origview.size() > 0)
475 final AlignmentPanel ap = origview.get(0);
478 * Copy the ViewStyle of the selected panel to 'this one'.
479 * Don't change value of 'scaleProteinAsCdna' unless copying
482 ViewStyleI vs = selviews.get(0).getAlignViewport()
484 boolean fromSplitFrame = selviews.get(0)
485 .getAlignViewport().getCodingComplement() != null;
488 vs.setScaleProteinAsCdna(ap.getAlignViewport()
489 .getViewStyle().isScaleProteinAsCdna());
491 ap.getAlignViewport().setViewStyle(vs);
494 * Also rescale ViewStyle of SplitFrame complement if there is
495 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
496 * the whole ViewStyle (allow cDNA protein to have different
499 AlignViewportI complement = ap.getAlignViewport()
500 .getCodingComplement();
501 if (complement != null && vs.isScaleProteinAsCdna())
503 AlignFrame af = Desktop.getAlignFrameFor(complement);
504 ((SplitFrame) af.getSplitViewContainer())
506 af.setMenusForViewport();
510 ap.setSelected(true);
511 ap.alignFrame.setMenusForViewport();
516 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
517 .indexOf("devel") > -1
518 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
519 .indexOf("test") > -1)
521 formatMenu.add(vsel);
523 addFocusListener(new FocusAdapter()
526 public void focusGained(FocusEvent e)
528 Jalview.setCurrentAlignFrame(AlignFrame.this);
535 * Change the filename and format for the alignment, and enable the 'reload'
536 * button functionality.
543 public void setFileName(String file, FileFormatI format)
546 setFileFormat(format);
547 reload.setEnabled(true);
551 * JavaScript will have this, maybe others. More dependable than a file name
552 * and maintains a reference to the actual bytes loaded.
556 public void setFileObject(File file)
558 this.fileObject = file;
562 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
565 void addKeyListener()
567 addKeyListener(new KeyAdapter()
570 public void keyPressed(KeyEvent evt)
572 if (viewport.cursorMode
573 && ((evt.getKeyCode() >= KeyEvent.VK_0
574 && evt.getKeyCode() <= KeyEvent.VK_9)
575 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
576 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
577 && Character.isDigit(evt.getKeyChar()))
579 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
582 switch (evt.getKeyCode())
585 case KeyEvent.VK_ESCAPE: // escape key
586 deselectAllSequenceMenuItem_actionPerformed(null);
590 case KeyEvent.VK_DOWN:
591 if (evt.isAltDown() || !viewport.cursorMode)
593 moveSelectedSequences(false);
595 if (viewport.cursorMode)
597 alignPanel.getSeqPanel().moveCursor(0, 1);
602 if (evt.isAltDown() || !viewport.cursorMode)
604 moveSelectedSequences(true);
606 if (viewport.cursorMode)
608 alignPanel.getSeqPanel().moveCursor(0, -1);
613 case KeyEvent.VK_LEFT:
614 if (evt.isAltDown() || !viewport.cursorMode)
616 slideSequences(false,
617 alignPanel.getSeqPanel().getKeyboardNo1());
621 alignPanel.getSeqPanel().moveCursor(-1, 0);
626 case KeyEvent.VK_RIGHT:
627 if (evt.isAltDown() || !viewport.cursorMode)
629 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
633 alignPanel.getSeqPanel().moveCursor(1, 0);
637 case KeyEvent.VK_SPACE:
638 if (viewport.cursorMode)
640 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
641 || evt.isShiftDown() || evt.isAltDown());
645 // case KeyEvent.VK_A:
646 // if (viewport.cursorMode)
648 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
649 // //System.out.println("A");
653 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
654 * System.out.println("closing bracket"); } break;
656 case KeyEvent.VK_DELETE:
657 case KeyEvent.VK_BACK_SPACE:
658 if (!viewport.cursorMode)
660 cut_actionPerformed();
664 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
665 || evt.isShiftDown() || evt.isAltDown());
671 if (viewport.cursorMode)
673 alignPanel.getSeqPanel().setCursorRow();
677 if (viewport.cursorMode && !evt.isControlDown())
679 alignPanel.getSeqPanel().setCursorColumn();
683 if (viewport.cursorMode)
685 alignPanel.getSeqPanel().setCursorPosition();
689 case KeyEvent.VK_ENTER:
690 case KeyEvent.VK_COMMA:
691 if (viewport.cursorMode)
693 alignPanel.getSeqPanel().setCursorRowAndColumn();
698 if (viewport.cursorMode)
700 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
704 if (viewport.cursorMode)
706 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
711 viewport.cursorMode = !viewport.cursorMode;
712 setStatus(MessageManager
713 .formatMessage("label.keyboard_editing_mode", new String[]
714 { (viewport.cursorMode ? "on" : "off") }));
715 if (viewport.cursorMode)
717 ViewportRanges ranges = viewport.getRanges();
718 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
720 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
723 alignPanel.getSeqPanel().seqCanvas.repaint();
729 Help.showHelpWindow();
730 } catch (Exception ex)
732 ex.printStackTrace();
737 boolean toggleSeqs = !evt.isControlDown();
738 boolean toggleCols = !evt.isShiftDown();
739 toggleHiddenRegions(toggleSeqs, toggleCols);
744 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
745 boolean modifyExisting = true; // always modify, don't clear
746 // evt.isShiftDown();
747 boolean invertHighlighted = evt.isAltDown();
748 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
752 case KeyEvent.VK_PAGE_UP:
753 viewport.getRanges().pageUp();
755 case KeyEvent.VK_PAGE_DOWN:
756 viewport.getRanges().pageDown();
762 public void keyReleased(KeyEvent evt)
764 switch (evt.getKeyCode())
766 case KeyEvent.VK_LEFT:
767 if (evt.isAltDown() || !viewport.cursorMode)
769 viewport.firePropertyChange("alignment", null,
770 viewport.getAlignment().getSequences());
774 case KeyEvent.VK_RIGHT:
775 if (evt.isAltDown() || !viewport.cursorMode)
777 viewport.firePropertyChange("alignment", null,
778 viewport.getAlignment().getSequences());
786 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
788 ap.alignFrame = this;
789 avc = new jalview.controller.AlignViewController(this, viewport,
794 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
796 int aSize = alignPanels.size();
798 tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null);
800 if (aSize == 1 && ap.av.getViewName() == null)
802 this.getContentPane().add(ap, BorderLayout.CENTER);
808 setInitialTabVisible();
811 expandViews.setEnabled(true);
812 gatherViews.setEnabled(true);
813 tabbedPane.addTab(ap.av.getViewName(), ap);
815 ap.setVisible(false);
820 if (ap.av.isPadGaps())
822 ap.av.getAlignment().padGaps();
824 // BH! important option for JalviewJS
825 if (Jalview.getInstance().getStartCalculations())
827 ap.av.updateConservation(ap);
828 ap.av.updateConsensus(ap);
829 ap.av.updateStrucConsensus(ap);
834 public void setInitialTabVisible()
836 expandViews.setEnabled(true);
837 gatherViews.setEnabled(true);
838 tabbedPane.setVisible(true);
839 AlignmentPanel first = alignPanels.get(0);
840 tabbedPane.addTab(first.av.getViewName(), first);
841 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
844 public AlignViewport getViewport()
849 /* Set up intrinsic listeners for dynamically generated GUI bits. */
850 private void addServiceListeners()
852 PropertyChangeListener thisListener;
853 Desktop.getInstance().addJalviewPropertyChangeListener("services",
854 thisListener = new PropertyChangeListener()
857 public void propertyChange(PropertyChangeEvent evt)
860 SwingUtilities.invokeLater(new Runnable()
867 "Rebuild WS Menu for service change");
868 BuildWebServiceMenu();
874 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
877 public void internalFrameClosed(
878 javax.swing.event.InternalFrameEvent evt)
880 // System.out.println("deregistering discoverer listener");
881 Desktop.getInstance().removeJalviewPropertyChangeListener("services",
883 closeMenuItem_actionPerformed(true);
886 // Finally, build the menu once to get current service state
887 new Thread(new Runnable()
892 BuildWebServiceMenu();
898 * Configure menu items that vary according to whether the alignment is
899 * nucleotide or protein
901 public void setGUINucleotide()
903 AlignmentI al = getViewport().getAlignment();
904 boolean nucleotide = al.isNucleotide();
906 loadVcf.setVisible(nucleotide);
907 showTranslation.setVisible(nucleotide);
908 showReverse.setVisible(nucleotide);
909 showReverseComplement.setVisible(nucleotide);
910 conservationMenuItem.setEnabled(!nucleotide);
912 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
913 showGroupConservation.setEnabled(!nucleotide);
915 showComplementMenuItem
916 .setText(nucleotide ? MessageManager.getString("label.protein")
917 : MessageManager.getString("label.nucleotide"));
921 * set up menus for the current viewport. This may be called after any
922 * operation that affects the data in the current view (selection changed,
923 * etc) to update the menus to reflect the new state.
926 public void setMenusForViewport()
928 setMenusFromViewport(viewport);
932 * Need to call this method when tabs are selected for multiple views, or when
933 * loading from Jalview2XML.java
938 public void setMenusFromViewport(AlignViewport av)
940 padGapsMenuitem.setSelected(av.isPadGaps());
941 colourTextMenuItem.setSelected(av.isShowColourText());
942 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
943 modifyPID.setEnabled(abovePIDThreshold.isSelected());
944 conservationMenuItem.setSelected(av.getConservationSelected());
945 modifyConservation.setEnabled(conservationMenuItem.isSelected());
946 seqLimits.setSelected(av.getShowJVSuffix());
947 idRightAlign.setSelected(av.isRightAlignIds());
948 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
949 renderGapsMenuItem.setSelected(av.isRenderGaps());
950 wrapMenuItem.setSelected(av.getWrapAlignment());
951 scaleAbove.setVisible(av.getWrapAlignment());
952 scaleLeft.setVisible(av.getWrapAlignment());
953 scaleRight.setVisible(av.getWrapAlignment());
954 annotationPanelMenuItem.setState(av.isShowAnnotation());
955 // Show/hide annotations only enabled if annotation panel is shown
957 syncAnnotationMenuItems();
959 viewBoxesMenuItem.setSelected(av.getShowBoxes());
960 viewTextMenuItem.setSelected(av.getShowText());
961 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
962 showGroupConsensus.setSelected(av.isShowGroupConsensus());
963 showGroupConservation.setSelected(av.isShowGroupConservation());
964 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
965 showSequenceLogo.setSelected(av.isShowSequenceLogo());
966 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
968 ColourMenuHelper.setColourSelected(colourMenu,
969 av.getGlobalColourScheme());
971 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
972 hiddenMarkers.setState(av.getShowHiddenMarkers());
973 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
974 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
975 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
976 autoCalculate.setSelected(av.getAutoCalculateConsensusAndConservation());
977 sortByTree.setSelected(av.sortByTree);
978 listenToViewSelections.setSelected(av.followSelection);
980 showProducts.setEnabled(canShowProducts());
981 setGroovyEnabled(Desktop.getGroovyConsole() != null);
987 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
991 public void setGroovyEnabled(boolean b)
993 runGroovy.setEnabled(b);
996 private IProgressIndicator progressBar;
1001 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1004 public void setProgressBar(String message, long id)
1006 progressBar.setProgressBar(message, id);
1010 public void registerHandler(final long id,
1011 final IProgressIndicatorHandler handler)
1013 progressBar.registerHandler(id, handler);
1018 * @return true if any progress bars are still active
1021 public boolean operationInProgress()
1023 return progressBar.operationInProgress();
1027 * Sets the text of the status bar. Note that setting a null or empty value
1028 * will cause the status bar to be hidden, with possibly undesirable flicker
1029 * of the screen layout.
1032 public void setStatus(String text)
1034 statusBar.setText(text == null || text.isEmpty() ? " " : text);
1038 * Added so Castor Mapping file can obtain Jalview Version
1040 public String getVersion()
1042 return jalview.bin.Cache.getProperty("VERSION");
1045 public FeatureRenderer getFeatureRenderer()
1047 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1051 public void fetchSequence_actionPerformed()
1053 new SequenceFetcher(this);
1057 public void addFromFile_actionPerformed(ActionEvent e)
1059 Desktop.getInstance().inputLocalFileMenuItem_actionPerformed(viewport);
1063 public void reload_actionPerformed(ActionEvent e)
1065 if (fileName == null)
1069 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1070 // originating file's format
1071 // TODO: work out how to recover feature settings for correct view(s) when
1072 // file is reloaded.
1073 if (FileFormat.Jalview.equals(currentFileFormat))
1075 JInternalFrame[] frames = Desktop.getDesktopPane().getAllFrames();
1076 for (int i = 0; i < frames.length; i++)
1078 if (frames[i] instanceof AlignFrame && frames[i] != this
1079 && ((AlignFrame) frames[i]).fileName != null
1080 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1084 frames[i].setSelected(true);
1085 Desktop.getInstance().closeAssociatedWindows();
1086 } catch (java.beans.PropertyVetoException ex)
1092 Desktop.getInstance().closeAssociatedWindows();
1094 FileLoader loader = new FileLoader();
1095 DataSourceType protocol = fileName.startsWith("http:")
1096 ? DataSourceType.URL
1097 : DataSourceType.FILE;
1098 if (fileObject == null)
1099 loader.LoadFile(fileName, protocol, currentFileFormat);
1101 loader.loadFile(null, (File) fileObject, protocol, currentFileFormat);
1105 Rectangle bounds = this.getBounds();
1107 FileLoader loader = new FileLoader();
1109 AlignFrame newframe = null;
1111 if (fileObject == null)
1113 // BH! Q: What about https?
1114 DataSourceType protocol = (fileName.startsWith("http:")
1115 ? DataSourceType.URL
1116 : DataSourceType.FILE);
1117 newframe = loader.LoadFileWaitTillLoaded(fileName, protocol,
1122 newframe = loader.loadFileWaitTillLoaded((File) fileObject,
1123 DataSourceType.FILE, currentFileFormat);
1126 newframe.setBounds(bounds);
1127 if (featureSettings != null && featureSettings.isShowing())
1129 final Rectangle fspos = featureSettings.frame.getBounds();
1130 // TODO: need a 'show feature settings' function that takes bounds -
1131 // need to refactor Desktop.addFrame
1132 newframe.featureSettings_actionPerformed(null);
1133 final FeatureSettings nfs = newframe.featureSettings;
1134 Jalview.execRunnable(new Runnable()
1139 nfs.frame.setBounds(fspos);
1142 this.featureSettings.close();
1143 this.featureSettings = null;
1145 this.closeMenuItem_actionPerformed(true);
1150 public void addFromText_actionPerformed(ActionEvent e)
1152 Desktop.getInstance()
1153 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1157 public void addFromURL_actionPerformed(ActionEvent e)
1159 Desktop.getInstance().inputURLMenuItem_actionPerformed(viewport);
1163 public void save_actionPerformed(ActionEvent e)
1165 if (fileName == null || (currentFileFormat == null)
1166 || fileName.startsWith("http"))
1168 saveAs_actionPerformed();
1172 saveAlignment(fileName, currentFileFormat);
1177 * Saves the alignment to a file with a name chosen by the user, if necessary
1178 * warning if a file would be overwritten
1181 public void saveAs_actionPerformed()
1183 String format = currentFileFormat == null ? null
1184 : currentFileFormat.getName();
1185 JalviewFileChooser chooser = JalviewFileChooser
1186 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1188 chooser.setFileView(new JalviewFileView());
1189 chooser.setDialogTitle(
1190 MessageManager.getString("label.save_alignment_to_file"));
1191 chooser.setToolTipText(MessageManager.getString("action.save"));
1193 int value = chooser.showSaveDialog(this);
1195 if (value != JalviewFileChooser.APPROVE_OPTION)
1199 currentFileFormat = chooser.getSelectedFormat();
1200 // todo is this (2005) test now obsolete - value is never null?
1201 while (currentFileFormat == null)
1203 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1205 .getString("label.select_file_format_before_saving"),
1206 MessageManager.getString("label.file_format_not_specified"),
1207 JvOptionPane.WARNING_MESSAGE);
1208 currentFileFormat = chooser.getSelectedFormat();
1209 value = chooser.showSaveDialog(this);
1210 if (value != JalviewFileChooser.APPROVE_OPTION)
1216 fileName = chooser.getSelectedFile().getPath();
1218 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1219 Cache.setProperty("LAST_DIRECTORY", fileName);
1220 saveAlignment(fileName, currentFileFormat);
1223 boolean lastSaveSuccessful = false;
1225 FileFormatI lastFormatSaved;
1227 String lastFilenameSaved;
1230 * Raise a dialog or status message for the last call to saveAlignment.
1232 * @return true if last call to saveAlignment(file, format) was successful.
1234 public boolean isSaveAlignmentSuccessful()
1237 if (!lastSaveSuccessful)
1239 JvOptionPane.showInternalMessageDialog(this, MessageManager
1240 .formatMessage("label.couldnt_save_file", new Object[]
1241 { lastFilenameSaved }),
1242 MessageManager.getString("label.error_saving_file"),
1243 JvOptionPane.WARNING_MESSAGE);
1248 setStatus(MessageManager.formatMessage(
1249 "label.successfully_saved_to_file_in_format", new Object[]
1250 { lastFilenameSaved, lastFormatSaved }));
1253 return lastSaveSuccessful;
1257 * Saves the alignment to the specified file path, in the specified format,
1258 * which may be an alignment format, or Jalview project format. If the
1259 * alignment has hidden regions, or the format is one capable of including
1260 * non-sequence data (features, annotations, groups), then the user may be
1261 * prompted to specify what to include in the output.
1266 public void saveAlignment(String file, FileFormatI format)
1268 lastSaveSuccessful = true;
1269 lastFilenameSaved = file;
1270 lastFormatSaved = format;
1272 if (FileFormat.Jalview.equals(format))
1274 String shortName = title;
1275 if (shortName.indexOf(File.separatorChar) > -1)
1277 shortName = shortName.substring(
1278 shortName.lastIndexOf(File.separatorChar) + 1);
1280 lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file, shortName);
1282 statusBar.setText(MessageManager.formatMessage(
1283 "label.successfully_saved_to_file_in_format", new Object[]
1284 { fileName, format }));
1289 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1290 Runnable cancelAction = new Runnable()
1295 lastSaveSuccessful = false;
1298 Runnable outputAction = new Runnable()
1303 // todo defer this to inside formatSequences (or later)
1304 AlignmentExportData exportData = viewport
1305 .getAlignExportData(options);
1306 String output = new FormatAdapter(alignPanel, options)
1307 .formatSequences(format, exportData.getAlignment(),
1308 exportData.getOmitHidden(),
1309 exportData.getStartEndPostions(),
1310 viewport.getAlignment().getHiddenColumns());
1313 lastSaveSuccessful = false;
1317 // create backupfiles object and get new temp filename destination
1318 boolean doBackup = BackupFiles.getEnabled();
1319 BackupFiles backupfiles = doBackup ? new BackupFiles(file) : null;
1322 String tempFilePath = doBackup ? backupfiles.getTempFilePath() : file;
1323 PrintWriter out = new PrintWriter(
1324 new FileWriter(tempFilePath));
1328 AlignFrame.this.setTitle(file);
1329 statusBar.setText(MessageManager.formatMessage(
1330 "label.successfully_saved_to_file_in_format", new Object[]
1331 { fileName, format.getName() }));
1332 lastSaveSuccessful = true;
1333 } catch (Exception ex)
1335 lastSaveSuccessful = false;
1336 ex.printStackTrace();
1341 backupfiles.setWriteSuccess(lastSaveSuccessful);
1342 // do the backup file roll and rename the temp file to actual file
1343 lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
1350 * show dialog with export options if applicable; else just do it
1352 if (AlignExportOptions.isNeeded(viewport, format))
1354 AlignExportOptions choices = new AlignExportOptions(
1355 alignPanel.getAlignViewport(), format, options);
1356 choices.setResponseAction(0, outputAction);
1357 choices.setResponseAction(1, cancelAction);
1358 choices.showDialog();
1367 * Outputs the alignment to textbox in the requested format, if necessary
1368 * first prompting the user for whether to include hidden regions or
1371 * @param fileFormatName
1374 protected void outputText_actionPerformed(String fileFormatName)
1376 FileFormatI fileFormat = FileFormats.getInstance()
1377 .forName(fileFormatName);
1378 AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
1379 Runnable outputAction = new Runnable()
1384 // todo defer this to inside formatSequences (or later)
1385 AlignmentExportData exportData = viewport
1386 .getAlignExportData(options);
1387 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1388 cap.setForInput(null);
1391 FileFormatI format = fileFormat;
1392 cap.setText(new FormatAdapter(alignPanel, options)
1393 .formatSequences(format, exportData.getAlignment(),
1394 exportData.getOmitHidden(),
1395 exportData.getStartEndPostions(),
1396 viewport.getAlignment().getHiddenColumns()));
1397 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1398 "label.alignment_output_command", new Object[]
1399 { fileFormat.getName() }), 600, 500);
1400 } catch (OutOfMemoryError oom)
1402 new OOMWarning("Outputting alignment as " + fileFormat.getName(),
1410 * show dialog with export options if applicable; else just do it
1412 if (AlignExportOptions.isNeeded(viewport, fileFormat))
1414 AlignExportOptions choices = new AlignExportOptions(
1415 alignPanel.getAlignViewport(), fileFormat, options);
1416 choices.setResponseAction(0, outputAction);
1417 choices.showDialog();
1432 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1434 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1435 htmlSVG.exportHTML(null);
1439 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1441 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1442 bjs.exportHTML(null);
1445 public void createImageMap(File file, String image)
1447 alignPanel.makePNGImageMap(file, image);
1451 * Creates a PNG image of the alignment and writes it to the given file. If
1452 * the file is null, the user is prompted to choose a file.
1457 public void createPNG(File f)
1459 alignPanel.makeAlignmentImage(TYPE.PNG, f);
1463 * Creates an EPS image of the alignment and writes it to the given file. If
1464 * the file is null, the user is prompted to choose a file.
1469 public void createEPS(File f)
1471 alignPanel.makeAlignmentImage(TYPE.EPS, f);
1475 * Creates an SVG image of the alignment and writes it to the given file. If
1476 * the file is null, the user is prompted to choose a file.
1481 public void createSVG(File f)
1483 alignPanel.makeAlignmentImage(TYPE.SVG, f);
1487 public void pageSetup_actionPerformed(ActionEvent e)
1489 PrinterJob printJob = PrinterJob.getPrinterJob();
1490 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1500 public void printMenuItem_actionPerformed(ActionEvent e)
1502 // Putting in a thread avoids Swing painting problems
1503 PrintThread thread = new PrintThread(alignPanel);
1508 public void exportFeatures_actionPerformed(ActionEvent e)
1510 new AnnotationExporter(alignPanel).exportFeatures();
1514 public void exportAnnotations_actionPerformed(ActionEvent e)
1516 new AnnotationExporter(alignPanel).exportAnnotations();
1520 public void associatedData_actionPerformed(ActionEvent e)
1522 final JalviewFileChooser chooser = new JalviewFileChooser(
1523 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1524 chooser.setFileView(new JalviewFileView());
1525 chooser.setDialogTitle(
1526 MessageManager.getString("label.load_jalview_annotations"));
1527 chooser.setToolTipText(
1528 MessageManager.getString("label.load_jalview_annotations"));
1529 chooser.setResponseHandler(0, new Runnable()
1534 String choice = chooser.getSelectedFile().getPath();
1535 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1536 loadJalviewDataFile(chooser.getSelectedFile(), null, null, null);
1540 chooser.showOpenDialog(this);
1544 * Close the current view or all views in the alignment frame. If the frame
1545 * only contains one view then the alignment will be removed from memory.
1547 * @param closeAllTabs
1550 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1552 if (alignPanels != null && alignPanels.size() < 2)
1554 closeAllTabs = true;
1559 if (alignPanels != null)
1563 if (this.isClosed())
1565 // really close all the windows - otherwise wait till
1566 // setClosed(true) is called
1567 for (int i = 0; i < alignPanels.size(); i++)
1569 AlignmentPanel ap = alignPanels.get(i);
1576 closeView(alignPanel);
1582 if (featureSettings != null && featureSettings.isOpen())
1584 featureSettings.close();
1585 featureSettings = null;
1588 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1589 * be called recursively, with the frame now in 'closed' state
1591 this.setClosed(true);
1593 } catch (Exception ex)
1595 ex.printStackTrace();
1600 * Close the specified panel and close up tabs appropriately.
1602 * @param panelToClose
1604 public void closeView(AlignmentPanel panelToClose)
1606 int index = tabbedPane.getSelectedIndex();
1607 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1608 alignPanels.remove(panelToClose);
1609 panelToClose.closePanel();
1610 panelToClose = null;
1612 tabbedPane.removeTabAt(closedindex);
1613 tabbedPane.validate();
1615 if (index > closedindex || index == tabbedPane.getTabCount())
1617 // modify currently selected tab index if necessary.
1621 this.tabSelectionChanged(index);
1627 void updateEditMenuBar()
1630 if (viewport.getHistoryList().size() > 0)
1632 undoMenuItem.setEnabled(true);
1633 CommandI command = viewport.getHistoryList().peek();
1634 undoMenuItem.setText(MessageManager
1635 .formatMessage("label.undo_command", new Object[]
1636 { command.getDescription() }));
1640 undoMenuItem.setEnabled(false);
1641 undoMenuItem.setText(MessageManager.getString("action.undo"));
1644 if (viewport.getRedoList().size() > 0)
1646 redoMenuItem.setEnabled(true);
1648 CommandI command = viewport.getRedoList().peek();
1649 redoMenuItem.setText(MessageManager
1650 .formatMessage("label.redo_command", new Object[]
1651 { command.getDescription() }));
1655 redoMenuItem.setEnabled(false);
1656 redoMenuItem.setText(MessageManager.getString("action.redo"));
1661 public void addHistoryItem(CommandI command)
1663 if (command.getSize() > 0)
1665 viewport.addToHistoryList(command);
1666 viewport.clearRedoList();
1667 updateEditMenuBar();
1668 viewport.updateHiddenColumns();
1669 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1670 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1671 // viewport.getColumnSelection()
1672 // .getHiddenColumns().size() > 0);
1678 * @return alignment objects for all views
1680 AlignmentI[] getViewAlignments()
1682 if (alignPanels != null)
1684 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1686 for (AlignmentPanel ap : alignPanels)
1688 als[i++] = ap.av.getAlignment();
1692 if (viewport != null)
1694 return new AlignmentI[] { viewport.getAlignment() };
1706 protected void undoMenuItem_actionPerformed(ActionEvent e)
1708 if (viewport.getHistoryList().isEmpty())
1712 CommandI command = viewport.getHistoryList().pop();
1713 viewport.addToRedoList(command);
1714 command.undoCommand(getViewAlignments());
1716 AlignmentViewport originalSource = getOriginatingSource(command);
1717 updateEditMenuBar();
1719 if (originalSource != null)
1721 if (originalSource != viewport)
1724 "Implementation worry: mismatch of viewport origin for undo");
1726 originalSource.updateHiddenColumns();
1727 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1729 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1730 // viewport.getColumnSelection()
1731 // .getHiddenColumns().size() > 0);
1732 originalSource.firePropertyChange("alignment", null,
1733 originalSource.getAlignment().getSequences());
1744 protected void redoMenuItem_actionPerformed(ActionEvent e)
1746 if (viewport.getRedoList().size() < 1)
1751 CommandI command = viewport.getRedoList().pop();
1752 viewport.addToHistoryList(command);
1753 command.doCommand(getViewAlignments());
1755 AlignmentViewport originalSource = getOriginatingSource(command);
1756 updateEditMenuBar();
1758 if (originalSource != null)
1761 if (originalSource != viewport)
1764 "Implementation worry: mismatch of viewport origin for redo");
1766 originalSource.updateHiddenColumns();
1767 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1769 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1770 // viewport.getColumnSelection()
1771 // .getHiddenColumns().size() > 0);
1772 originalSource.firePropertyChange("alignment", null,
1773 originalSource.getAlignment().getSequences());
1777 AlignmentViewport getOriginatingSource(CommandI command)
1779 AlignmentViewport originalSource = null;
1780 // For sequence removal and addition, we need to fire
1781 // the property change event FROM the viewport where the
1782 // original alignment was altered
1783 AlignmentI al = null;
1784 if (command instanceof EditCommand)
1786 EditCommand editCommand = (EditCommand) command;
1787 al = editCommand.getAlignment();
1788 List<Component> comps = PaintRefresher.components
1789 .get(viewport.getSequenceSetId());
1791 for (Component comp : comps)
1793 if (comp instanceof AlignmentPanel)
1795 if (al == ((AlignmentPanel) comp).av.getAlignment())
1797 originalSource = ((AlignmentPanel) comp).av;
1804 if (originalSource == null)
1806 // The original view is closed, we must validate
1807 // the current view against the closed view first
1810 PaintRefresher.validateSequences(al, viewport.getAlignment());
1813 originalSource = viewport;
1816 return originalSource;
1825 public void moveSelectedSequences(boolean up)
1827 SequenceGroup sg = viewport.getSelectionGroup();
1833 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1834 viewport.getHiddenRepSequences(), up);
1835 alignPanel.paintAlignment(true, false);
1838 synchronized void slideSequences(boolean right, int size)
1840 List<SequenceI> sg = new ArrayList<>();
1841 if (viewport.cursorMode)
1843 sg.add(viewport.getAlignment()
1844 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
1846 else if (viewport.getSelectionGroup() != null
1847 && viewport.getSelectionGroup().getSize() != viewport
1848 .getAlignment().getHeight())
1850 sg = viewport.getSelectionGroup()
1851 .getSequences(viewport.getHiddenRepSequences());
1859 List<SequenceI> invertGroup = new ArrayList<>();
1861 for (SequenceI seq : viewport.getAlignment().getSequences())
1863 if (!sg.contains(seq))
1865 invertGroup.add(seq);
1869 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1871 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1872 for (int i = 0; i < invertGroup.size(); i++)
1874 seqs2[i] = invertGroup.get(i);
1877 SlideSequencesCommand ssc;
1880 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1881 viewport.getGapCharacter());
1885 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1886 viewport.getGapCharacter());
1889 int groupAdjustment = 0;
1890 if (ssc.getGapsInsertedBegin() && right)
1892 if (viewport.cursorMode)
1894 alignPanel.getSeqPanel().moveCursor(size, 0);
1898 groupAdjustment = size;
1901 else if (!ssc.getGapsInsertedBegin() && !right)
1903 if (viewport.cursorMode)
1905 alignPanel.getSeqPanel().moveCursor(-size, 0);
1909 groupAdjustment = -size;
1913 if (groupAdjustment != 0)
1915 viewport.getSelectionGroup().setStartRes(
1916 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1917 viewport.getSelectionGroup().setEndRes(
1918 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1922 * just extend the last slide command if compatible; but not if in
1923 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1925 boolean appendHistoryItem = false;
1926 Deque<CommandI> historyList = viewport.getHistoryList();
1927 boolean inSplitFrame = getSplitViewContainer() != null;
1928 if (!inSplitFrame && historyList != null && historyList.size() > 0
1929 && historyList.peek() instanceof SlideSequencesCommand)
1931 appendHistoryItem = ssc.appendSlideCommand(
1932 (SlideSequencesCommand) historyList.peek());
1935 if (!appendHistoryItem)
1937 addHistoryItem(ssc);
1950 protected void copy_actionPerformed()
1952 if (viewport.getSelectionGroup() == null)
1956 // TODO: preserve the ordering of displayed alignment annotation in any
1957 // internal paste (particularly sequence associated annotation)
1958 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1959 String[] omitHidden = null;
1961 if (viewport.hasHiddenColumns())
1963 omitHidden = viewport.getViewAsString(true);
1966 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1967 seqs, omitHidden, null);
1969 StringSelection ss = new StringSelection(output);
1971 Desktop d = Desktop.getInstance();
1974 d.internalCopy = true;
1975 // Its really worth setting the clipboard contents
1976 // to empty before setting the large StringSelection!!
1977 Toolkit.getDefaultToolkit().getSystemClipboard()
1978 .setContents(new StringSelection(""), null);
1980 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
1981 Desktop.getInstance());
1982 } catch (OutOfMemoryError er)
1984 new OOMWarning("copying region", er);
1988 HiddenColumns hiddenColumns = null;
1989 if (viewport.hasHiddenColumns())
1991 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1992 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
1994 // create new HiddenColumns object with copy of hidden regions
1995 // between startRes and endRes, offset by startRes
1996 hiddenColumns = new HiddenColumns(
1997 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
1998 hiddenCutoff, hiddenOffset);
2001 d.jalviewClipboard = new Object[] { seqs,
2002 viewport.getAlignment().getDataset(), hiddenColumns };
2003 setStatus(MessageManager.formatMessage(
2004 "label.copied_sequences_to_clipboard", new Object[]
2005 { Integer.valueOf(seqs.length).toString() }));
2015 protected void pasteNew_actionPerformed(ActionEvent e)
2027 protected void pasteThis_actionPerformed(ActionEvent e)
2033 * Paste contents of Jalview clipboard
2035 * @param newAlignment
2036 * true to paste to a new alignment, otherwise add to this.
2038 void paste(boolean newAlignment)
2040 boolean externalPaste = true;
2043 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2044 Transferable contents = c.getContents(this);
2046 if (contents == null)
2055 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2056 if (str.length() < 1)
2061 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2063 } catch (OutOfMemoryError er)
2065 new OOMWarning("Out of memory pasting sequences!!", er);
2069 SequenceI[] sequences;
2070 boolean annotationAdded = false;
2071 AlignmentI alignment = null;
2073 Desktop d = Desktop.getInstance();
2075 if (d.jalviewClipboard != null)
2077 // The clipboard was filled from within Jalview, we must use the
2079 // And dataset from the copied alignment
2080 SequenceI[] newseq = (SequenceI[]) d.jalviewClipboard[0];
2081 // be doubly sure that we create *new* sequence objects.
2082 sequences = new SequenceI[newseq.length];
2083 for (int i = 0; i < newseq.length; i++)
2085 sequences[i] = new Sequence(newseq[i]);
2087 alignment = new Alignment(sequences);
2088 externalPaste = false;
2092 // parse the clipboard as an alignment.
2093 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2095 sequences = alignment.getSequencesArray();
2099 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2105 if (d.jalviewClipboard != null)
2107 // dataset is inherited
2108 alignment.setDataset((Alignment) d.jalviewClipboard[1]);
2112 // new dataset is constructed
2113 alignment.setDataset(null);
2115 alwidth = alignment.getWidth() + 1;
2119 AlignmentI pastedal = alignment; // preserve pasted alignment object
2120 // Add pasted sequences and dataset into existing alignment.
2121 alignment = viewport.getAlignment();
2122 alwidth = alignment.getWidth() + 1;
2123 // decide if we need to import sequences from an existing dataset
2124 boolean importDs = d.jalviewClipboard != null
2125 && d.jalviewClipboard[1] != alignment.getDataset();
2126 // importDs==true instructs us to copy over new dataset sequences from
2127 // an existing alignment
2128 Vector<SequenceI> newDs = (importDs) ? new Vector<>() : null; // used to
2130 // minimum dataset set
2132 for (int i = 0; i < sequences.length; i++)
2136 newDs.addElement(null);
2138 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2140 if (importDs && ds != null)
2142 if (!newDs.contains(ds))
2144 newDs.setElementAt(ds, i);
2145 ds = new Sequence(ds);
2146 // update with new dataset sequence
2147 sequences[i].setDatasetSequence(ds);
2151 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2156 // copy and derive new dataset sequence
2157 sequences[i] = sequences[i].deriveSequence();
2158 alignment.getDataset()
2159 .addSequence(sequences[i].getDatasetSequence());
2160 // TODO: avoid creation of duplicate dataset sequences with a
2161 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2163 alignment.addSequence(sequences[i]); // merges dataset
2167 newDs.clear(); // tidy up
2169 if (alignment.getAlignmentAnnotation() != null)
2171 for (AlignmentAnnotation alan : alignment
2172 .getAlignmentAnnotation())
2174 if (alan.graphGroup > fgroup)
2176 fgroup = alan.graphGroup;
2180 if (pastedal.getAlignmentAnnotation() != null)
2182 // Add any annotation attached to alignment.
2183 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2184 for (int i = 0; i < alann.length; i++)
2186 annotationAdded = true;
2187 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2189 AlignmentAnnotation newann = new AlignmentAnnotation(
2191 if (newann.graphGroup > -1)
2193 if (newGraphGroups.size() <= newann.graphGroup
2194 || newGraphGroups.get(newann.graphGroup) == null)
2196 for (int q = newGraphGroups
2197 .size(); q <= newann.graphGroup; q++)
2199 newGraphGroups.add(q, null);
2201 newGraphGroups.set(newann.graphGroup,
2202 Integer.valueOf(++fgroup));
2204 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2208 newann.padAnnotation(alwidth);
2209 alignment.addAnnotation(newann);
2219 addHistoryItem(new EditCommand(
2220 MessageManager.getString("label.add_sequences"),
2221 Action.PASTE, sequences, 0, alignment.getWidth(),
2224 // Add any annotations attached to sequences
2225 for (int i = 0; i < sequences.length; i++)
2227 if (sequences[i].getAnnotation() != null)
2229 AlignmentAnnotation newann;
2230 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2232 annotationAdded = true;
2233 newann = sequences[i].getAnnotation()[a];
2234 newann.adjustForAlignment();
2235 newann.padAnnotation(alwidth);
2236 if (newann.graphGroup > -1)
2238 if (newann.graphGroup > -1)
2240 if (newGraphGroups.size() <= newann.graphGroup
2241 || newGraphGroups.get(newann.graphGroup) == null)
2243 for (int q = newGraphGroups
2244 .size(); q <= newann.graphGroup; q++)
2246 newGraphGroups.add(q, null);
2248 newGraphGroups.set(newann.graphGroup,
2249 Integer.valueOf(++fgroup));
2251 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2255 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2259 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2267 // propagate alignment changed.
2268 viewport.getRanges().setEndSeq(alignment.getHeight() - 1);
2269 if (annotationAdded)
2271 // Duplicate sequence annotation in all views.
2272 AlignmentI[] alview = this.getViewAlignments();
2273 for (int i = 0; i < sequences.length; i++)
2275 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2280 for (int avnum = 0; avnum < alview.length; avnum++)
2282 if (alview[avnum] != alignment)
2284 // duplicate in a view other than the one with input focus
2285 int avwidth = alview[avnum].getWidth() + 1;
2286 // this relies on sann being preserved after we
2287 // modify the sequence's annotation array for each duplication
2288 for (int a = 0; a < sann.length; a++)
2290 AlignmentAnnotation newann = new AlignmentAnnotation(
2292 sequences[i].addAlignmentAnnotation(newann);
2293 newann.padAnnotation(avwidth);
2294 alview[avnum].addAnnotation(newann); // annotation was
2295 // duplicated earlier
2296 // TODO JAL-1145 graphGroups are not updated for sequence
2297 // annotation added to several views. This may cause
2299 alview[avnum].setAnnotationIndex(newann, a);
2304 buildSortByAnnotationScoresMenu();
2306 viewport.firePropertyChange("alignment", null,
2307 alignment.getSequences());
2308 if (alignPanels != null)
2310 for (AlignmentPanel ap : alignPanels)
2312 ap.validateAnnotationDimensions(false);
2317 alignPanel.validateAnnotationDimensions(false);
2323 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2325 String newtitle = new String("Copied sequences");
2327 if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null)
2329 HiddenColumns hc = (HiddenColumns) d.jalviewClipboard[2];
2330 af.viewport.setHiddenColumns(hc);
2333 // >>>This is a fix for the moment, until a better solution is
2335 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2336 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2337 .getFeatureRenderer());
2339 // TODO: maintain provenance of an alignment, rather than just make the
2340 // title a concatenation of operations.
2343 if (title.startsWith("Copied sequences"))
2349 newtitle = newtitle.concat("- from " + title);
2354 newtitle = new String("Pasted sequences");
2357 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2362 } catch (Exception ex)
2364 ex.printStackTrace();
2365 System.out.println("Exception whilst pasting: " + ex);
2366 // could be anything being pasted in here
2372 protected void expand_newalign(ActionEvent e)
2376 AlignmentI alignment = AlignmentUtils
2377 .expandContext(getViewport().getAlignment(), -1);
2378 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2380 String newtitle = new String("Flanking alignment");
2382 Desktop d = Desktop.getInstance();
2384 if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null)
2386 HiddenColumns hc = (HiddenColumns) d.jalviewClipboard[2];
2387 af.viewport.setHiddenColumns(hc);
2390 // >>>This is a fix for the moment, until a better solution is
2392 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2393 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2394 .getFeatureRenderer());
2396 // TODO: maintain provenance of an alignment, rather than just make the
2397 // title a concatenation of operations.
2399 if (title.startsWith("Copied sequences"))
2405 newtitle = newtitle.concat("- from " + title);
2409 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2411 } catch (Exception ex)
2413 ex.printStackTrace();
2414 System.out.println("Exception whilst pasting: " + ex);
2415 // could be anything being pasted in here
2416 } catch (OutOfMemoryError oom)
2418 new OOMWarning("Viewing flanking region of alignment", oom);
2423 * Action Cut (delete and copy) the selected region
2426 protected void cut_actionPerformed()
2428 copy_actionPerformed();
2429 delete_actionPerformed();
2433 * Performs menu option to Delete the currently selected region
2436 protected void delete_actionPerformed()
2439 SequenceGroup sg = viewport.getSelectionGroup();
2445 Runnable okAction = new Runnable()
2450 SequenceI[] cut = sg.getSequences()
2451 .toArray(new SequenceI[sg.getSize()]);
2453 addHistoryItem(new EditCommand(
2454 MessageManager.getString("label.cut_sequences"), Action.CUT,
2455 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2456 viewport.getAlignment()));
2458 viewport.setSelectionGroup(null);
2459 viewport.sendSelection();
2460 viewport.getAlignment().deleteGroup(sg);
2462 viewport.firePropertyChange("alignment", null,
2463 viewport.getAlignment().getSequences());
2464 if (viewport.getAlignment().getHeight() < 1)
2468 AlignFrame.this.setClosed(true);
2469 } catch (Exception ex)
2476 * If the cut affects all sequences, prompt for confirmation
2478 boolean wholeHeight = sg.getSize() == viewport.getAlignment().getHeight();
2479 boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes())
2480 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2481 if (wholeHeight && wholeWidth)
2483 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.getDesktopPane());
2484 dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION
2485 Object[] options = new Object[] { MessageManager.getString("action.ok"),
2486 MessageManager.getString("action.cancel") };
2487 dialog.showDialog(MessageManager.getString("warn.delete_all"),
2488 MessageManager.getString("label.delete_all"),
2489 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
2490 options, options[0]);
2504 protected void deleteGroups_actionPerformed(ActionEvent e)
2506 if (avc.deleteGroups())
2508 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2509 alignPanel.updateAnnotation();
2510 alignPanel.paintAlignment(true, true);
2521 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2523 SequenceGroup sg = new SequenceGroup(
2524 viewport.getAlignment().getSequences());
2526 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2527 viewport.setSelectionGroup(sg);
2528 viewport.isSelectionGroupChanged(true);
2529 viewport.sendSelection();
2530 // JAL-2034 - should delegate to
2531 // alignPanel to decide if overview needs
2533 alignPanel.paintAlignment(false, false);
2534 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2544 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2546 if (viewport.cursorMode)
2548 alignPanel.getSeqPanel().keyboardNo1 = null;
2549 alignPanel.getSeqPanel().keyboardNo2 = null;
2551 viewport.setSelectionGroup(null);
2552 viewport.getColumnSelection().clear();
2553 viewport.setSelectionGroup(null);
2554 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2555 // JAL-2034 - should delegate to
2556 // alignPanel to decide if overview needs
2558 alignPanel.paintAlignment(false, false);
2559 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2560 viewport.sendSelection();
2570 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2572 SequenceGroup sg = viewport.getSelectionGroup();
2576 selectAllSequenceMenuItem_actionPerformed(null);
2581 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2583 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2585 // JAL-2034 - should delegate to
2586 // alignPanel to decide if overview needs
2589 alignPanel.paintAlignment(true, false);
2590 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2591 viewport.sendSelection();
2595 public void invertColSel_actionPerformed(ActionEvent e)
2597 viewport.invertColumnSelection();
2598 alignPanel.paintAlignment(true, false);
2599 viewport.sendSelection();
2609 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2611 trimAlignment(true);
2621 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2623 trimAlignment(false);
2626 void trimAlignment(boolean trimLeft)
2628 ColumnSelection colSel = viewport.getColumnSelection();
2631 if (!colSel.isEmpty())
2635 column = colSel.getMin();
2639 column = colSel.getMax();
2643 if (viewport.getSelectionGroup() != null)
2645 seqs = viewport.getSelectionGroup()
2646 .getSequencesAsArray(viewport.getHiddenRepSequences());
2650 seqs = viewport.getAlignment().getSequencesArray();
2653 TrimRegionCommand trimRegion;
2656 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2657 column, viewport.getAlignment());
2658 viewport.getRanges().setStartRes(0);
2662 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2663 column, viewport.getAlignment());
2666 setStatus(MessageManager
2667 .formatMessage("label.removed_columns", new String[]
2668 { Integer.valueOf(trimRegion.getSize()).toString() }));
2670 addHistoryItem(trimRegion);
2672 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2674 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2675 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2677 viewport.getAlignment().deleteGroup(sg);
2681 viewport.firePropertyChange("alignment", null,
2682 viewport.getAlignment().getSequences());
2693 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2695 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2698 if (viewport.getSelectionGroup() != null)
2700 seqs = viewport.getSelectionGroup()
2701 .getSequencesAsArray(viewport.getHiddenRepSequences());
2702 start = viewport.getSelectionGroup().getStartRes();
2703 end = viewport.getSelectionGroup().getEndRes();
2707 seqs = viewport.getAlignment().getSequencesArray();
2710 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2711 "Remove Gapped Columns", seqs, start, end,
2712 viewport.getAlignment());
2714 addHistoryItem(removeGapCols);
2716 setStatus(MessageManager
2717 .formatMessage("label.removed_empty_columns", new Object[]
2718 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2720 // This is to maintain viewport position on first residue
2721 // of first sequence
2722 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2723 ViewportRanges ranges = viewport.getRanges();
2724 int startRes = seq.findPosition(ranges.getStartRes());
2725 // ShiftList shifts;
2726 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2727 // edit.alColumnChanges=shifts.getInverse();
2728 // if (viewport.hasHiddenColumns)
2729 // viewport.getColumnSelection().compensateForEdits(shifts);
2730 ranges.setStartRes(seq.findIndex(startRes) - 1);
2731 viewport.firePropertyChange("alignment", null,
2732 viewport.getAlignment().getSequences());
2743 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2745 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2748 if (viewport.getSelectionGroup() != null)
2750 seqs = viewport.getSelectionGroup()
2751 .getSequencesAsArray(viewport.getHiddenRepSequences());
2752 start = viewport.getSelectionGroup().getStartRes();
2753 end = viewport.getSelectionGroup().getEndRes();
2757 seqs = viewport.getAlignment().getSequencesArray();
2760 // This is to maintain viewport position on first residue
2761 // of first sequence
2762 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2763 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2765 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2766 viewport.getAlignment()));
2768 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2770 viewport.firePropertyChange("alignment", null,
2771 viewport.getAlignment().getSequences());
2782 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2784 viewport.setPadGaps(padGapsMenuitem.isSelected());
2785 viewport.firePropertyChange("alignment", null,
2786 viewport.getAlignment().getSequences());
2796 public void findMenuItem_actionPerformed(ActionEvent e)
2802 * Create a new view of the current alignment.
2805 public void newView_actionPerformed(ActionEvent e)
2807 newView(null, true);
2811 * Creates and shows a new view of the current alignment.
2814 * title of newly created view; if null, one will be generated
2815 * @param copyAnnotation
2816 * if true then duplicate all annnotation, groups and settings
2817 * @return new alignment panel, already displayed.
2819 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2822 * Create a new AlignmentPanel (with its own, new Viewport)
2824 AlignmentPanel newap = new jalview.project.Jalview2XML()
2825 .copyAlignPanel(alignPanel);
2826 if (!copyAnnotation)
2829 * remove all groups and annotation except for the automatic stuff
2831 newap.av.getAlignment().deleteAllGroups();
2832 newap.av.getAlignment().deleteAllAnnotations(false);
2835 newap.av.setGatherViewsHere(false);
2837 if (viewport.getViewName() == null)
2839 viewport.setViewName(MessageManager
2840 .getString("label.view_name_original"));
2844 * Views share the same edits undo and redo stacks
2846 newap.av.setHistoryList(viewport.getHistoryList());
2847 newap.av.setRedoList(viewport.getRedoList());
2850 * copy any visualisation settings that are not saved in the project
2852 newap.av.setColourAppliesToAllGroups(
2853 viewport.getColourAppliesToAllGroups());
2856 * Views share the same mappings; need to deregister any new mappings
2857 * created by copyAlignPanel, and register the new reference to the shared
2860 newap.av.replaceMappings(viewport.getAlignment());
2863 * start up cDNA consensus (if applicable) now mappings are in place
2865 if (newap.av.initComplementConsensus())
2867 newap.refresh(true); // adjust layout of annotations
2870 newap.av.setViewName(getNewViewName(viewTitle));
2872 addAlignmentPanel(newap, true);
2873 newap.alignmentChanged();
2875 if (alignPanels.size() == 2)
2877 viewport.setGatherViewsHere(true);
2879 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2884 * Make a new name for the view, ensuring it is unique within the current
2885 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2886 * these now use viewId. Unique view names are still desirable for usability.)
2891 protected String getNewViewName(String viewTitle)
2893 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2894 boolean addFirstIndex = false;
2895 if (viewTitle == null || viewTitle.trim().length() == 0)
2897 viewTitle = MessageManager.getString("action.view");
2898 addFirstIndex = true;
2902 index = 1;// we count from 1 if given a specific name
2904 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2906 List<Component> comps = PaintRefresher.components
2907 .get(viewport.getSequenceSetId());
2909 List<String> existingNames = getExistingViewNames(comps);
2911 while (existingNames.contains(newViewName))
2913 newViewName = viewTitle + " " + (++index);
2919 * Returns a list of distinct view names found in the given list of
2920 * components. View names are held on the viewport of an AlignmentPanel.
2925 protected List<String> getExistingViewNames(List<Component> comps)
2927 List<String> existingNames = new ArrayList<>();
2928 for (Component comp : comps)
2930 if (comp instanceof AlignmentPanel)
2932 AlignmentPanel ap = (AlignmentPanel) comp;
2933 if (!existingNames.contains(ap.av.getViewName()))
2935 existingNames.add(ap.av.getViewName());
2939 return existingNames;
2943 * Explode tabbed views into separate windows.
2946 public void expandViews_actionPerformed(ActionEvent e)
2948 Desktop.explodeViews(this);
2952 * Gather views in separate windows back into a tabbed presentation.
2955 public void gatherViews_actionPerformed(ActionEvent e)
2957 Desktop.getInstance().gatherViews(this);
2967 public void font_actionPerformed(ActionEvent e)
2969 new FontChooser(alignPanel);
2979 protected void seqLimit_actionPerformed(ActionEvent e)
2981 viewport.setShowJVSuffix(seqLimits.isSelected());
2983 alignPanel.getIdPanel().getIdCanvas()
2984 .setPreferredSize(alignPanel.calculateIdWidth());
2985 alignPanel.paintAlignment(true, false);
2989 public void idRightAlign_actionPerformed(ActionEvent e)
2991 viewport.setRightAlignIds(idRightAlign.isSelected());
2992 alignPanel.paintAlignment(false, false);
2996 public void centreColumnLabels_actionPerformed(ActionEvent e)
2998 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2999 alignPanel.paintAlignment(false, false);
3005 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3008 protected void followHighlight_actionPerformed()
3011 * Set the 'follow' flag on the Viewport (and scroll to position if now
3014 final boolean state = this.followHighlightMenuItem.getState();
3015 viewport.setFollowHighlight(state);
3018 alignPanel.scrollToPosition(viewport.getSearchResults());
3029 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3031 viewport.setColourText(colourTextMenuItem.isSelected());
3032 alignPanel.paintAlignment(false, false);
3042 public void wrapMenuItem_actionPerformed(ActionEvent e)
3044 scaleAbove.setVisible(wrapMenuItem.isSelected());
3045 scaleLeft.setVisible(wrapMenuItem.isSelected());
3046 scaleRight.setVisible(wrapMenuItem.isSelected());
3047 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3048 alignPanel.updateLayout();
3052 public void showAllSeqs_actionPerformed(ActionEvent e)
3054 viewport.showAllHiddenSeqs();
3058 public void showAllColumns_actionPerformed(ActionEvent e)
3060 viewport.showAllHiddenColumns();
3061 alignPanel.paintAlignment(true, true);
3062 viewport.sendSelection();
3066 public void hideSelSequences_actionPerformed(ActionEvent e)
3068 viewport.hideAllSelectedSeqs();
3072 * called by key handler and the hide all/show all menu items
3077 protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3080 boolean hide = false;
3081 SequenceGroup sg = viewport.getSelectionGroup();
3082 if (!toggleSeqs && !toggleCols)
3084 // Hide everything by the current selection - this is a hack - we do the
3085 // invert and then hide
3086 // first check that there will be visible columns after the invert.
3087 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3088 && sg.getStartRes() <= sg.getEndRes()))
3090 // now invert the sequence set, if required - empty selection implies
3091 // that no hiding is required.
3094 invertSequenceMenuItem_actionPerformed(null);
3095 sg = viewport.getSelectionGroup();
3099 viewport.expandColSelection(sg, true);
3100 // finally invert the column selection and get the new sequence
3102 invertColSel_actionPerformed(null);
3109 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3111 hideSelSequences_actionPerformed(null);
3114 else if (!(toggleCols && viewport.hasSelectedColumns()))
3116 showAllSeqs_actionPerformed(null);
3122 if (viewport.hasSelectedColumns())
3124 hideSelColumns_actionPerformed(null);
3127 viewport.setSelectionGroup(sg);
3132 showAllColumns_actionPerformed(null);
3141 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3142 * event.ActionEvent)
3145 public void hideAllButSelection_actionPerformed(ActionEvent e)
3147 toggleHiddenRegions(false, false);
3148 viewport.sendSelection();
3155 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3159 public void hideAllSelection_actionPerformed(ActionEvent e)
3161 SequenceGroup sg = viewport.getSelectionGroup();
3162 viewport.expandColSelection(sg, false);
3163 viewport.hideAllSelectedSeqs();
3164 viewport.hideSelectedColumns();
3165 alignPanel.updateLayout();
3166 alignPanel.paintAlignment(true, true);
3167 viewport.sendSelection();
3174 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3178 public void showAllhidden_actionPerformed(ActionEvent e)
3180 viewport.showAllHiddenColumns();
3181 viewport.showAllHiddenSeqs();
3182 alignPanel.paintAlignment(true, true);
3183 viewport.sendSelection();
3187 public void hideSelColumns_actionPerformed(ActionEvent e)
3189 viewport.hideSelectedColumns();
3190 alignPanel.updateLayout();
3191 alignPanel.paintAlignment(true, true);
3192 viewport.sendSelection();
3196 public void hiddenMarkers_actionPerformed(ActionEvent e)
3198 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3209 protected void scaleAbove_actionPerformed(ActionEvent e)
3211 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3212 alignPanel.updateLayout();
3213 alignPanel.paintAlignment(true, false);
3223 protected void scaleLeft_actionPerformed(ActionEvent e)
3225 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3226 alignPanel.updateLayout();
3227 alignPanel.paintAlignment(true, false);
3237 protected void scaleRight_actionPerformed(ActionEvent e)
3239 viewport.setScaleRightWrapped(scaleRight.isSelected());
3240 alignPanel.updateLayout();
3241 alignPanel.paintAlignment(true, false);
3251 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3253 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3254 alignPanel.paintAlignment(false, false);
3264 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3266 viewport.setShowText(viewTextMenuItem.isSelected());
3267 alignPanel.paintAlignment(false, false);
3277 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3279 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3280 alignPanel.paintAlignment(false, false);
3283 public FeatureSettings featureSettings;
3286 public FeatureSettingsControllerI getFeatureSettingsUI()
3288 return featureSettings;
3292 public void featureSettings_actionPerformed(ActionEvent e)
3294 showFeatureSettingsUI();
3298 public FeatureSettingsControllerI showFeatureSettingsUI()
3300 if (featureSettings != null)
3302 featureSettings.closeOldSettings();
3303 featureSettings = null;
3305 if (!showSeqFeatures.isSelected())
3307 // make sure features are actually displayed
3308 showSeqFeatures.setSelected(true);
3309 showSeqFeatures_actionPerformed(null);
3311 featureSettings = new FeatureSettings(this);
3312 return featureSettings;
3316 * Set or clear 'Show Sequence Features'
3322 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3324 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3325 alignPanel.paintAlignment(true, true);
3329 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3330 * the annotations panel as a whole.
3332 * The options to show/hide all annotations should be enabled when the panel
3333 * is shown, and disabled when the panel is hidden.
3338 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3340 final boolean setVisible = annotationPanelMenuItem.isSelected();
3341 viewport.setShowAnnotation(setVisible);
3342 syncAnnotationMenuItems();
3343 alignPanel.updateLayout();
3346 private void syncAnnotationMenuItems()
3348 final boolean setVisible = annotationPanelMenuItem.isSelected();
3349 showAllSeqAnnotations.setEnabled(setVisible);
3350 hideAllSeqAnnotations.setEnabled(setVisible);
3351 showAllAlAnnotations.setEnabled(setVisible);
3352 hideAllAlAnnotations.setEnabled(setVisible);
3357 public void alignmentProperties()
3360 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3363 String content = MessageManager.formatMessage("label.html_content",
3365 { contents.toString() });
3368 if (Platform.isJS())
3370 JLabel textLabel = new JLabel();
3371 textLabel.setText(content);
3372 textLabel.setBackground(Color.WHITE);
3374 pane = new JPanel(new BorderLayout());
3375 ((JPanel) pane).setOpaque(true);
3376 pane.setBackground(Color.WHITE);
3377 ((JPanel) pane).add(textLabel, BorderLayout.NORTH);
3386 JEditorPane editPane = new JEditorPane("text/html", "");
3387 editPane.setEditable(false);
3388 editPane.setText(content);
3392 JInternalFrame frame = new JInternalFrame();
3394 frame.getContentPane().add(new JScrollPane(pane));
3396 Desktop.addInternalFrame(frame, MessageManager
3397 .formatMessage("label.alignment_properties", new Object[]
3398 { getTitle() }), 500, 400);
3408 public void overviewMenuItem_actionPerformed(ActionEvent e)
3410 if (alignPanel.overviewPanel != null)
3415 JInternalFrame frame = new JInternalFrame();
3417 // BH 2019.07.26 we allow for an embedded
3418 // undecorated overview with defined size
3419 frame.setName(Jalview.getAppID("overview"));
3421 Dimension dim = Platform.getDimIfEmbedded(frame, -1, -1);
3422 if (dim != null && dim.width == 0)
3424 dim = null; // hidden, not embedded
3426 OverviewPanel overview = new OverviewPanel(alignPanel, dim);
3428 frame.setContentPane(overview);
3431 dim = new Dimension();
3432 // was frame.getSize(), but that is 0,0 at this point;
3436 // we are imbedding, and so we have an undecorated frame
3437 // and we can set the the frame dimensions accordingly.
3439 // allowing for unresizable option using, style="resize:none"
3440 boolean resizable = (Platform.getEmbeddedAttribute(frame,
3441 "resize") != "none");
3442 Desktop.addInternalFrame(frame, MessageManager
3443 .formatMessage("label.overview_params", new Object[]
3444 { this.getTitle() }), true, dim.width, dim.height, resizable,
3447 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3448 frame.addInternalFrameListener(
3449 new javax.swing.event.InternalFrameAdapter()
3452 public void internalFrameClosed(
3453 javax.swing.event.InternalFrameEvent evt)
3456 alignPanel.setOverviewPanel(null);
3459 if (getKeyListeners().length > 0)
3461 frame.addKeyListener(getKeyListeners()[0]);
3464 alignPanel.setOverviewPanel(overview);
3468 public void textColour_actionPerformed()
3470 new TextColourChooser().chooseColour(alignPanel, null);
3474 * public void covariationColour_actionPerformed() {
3476 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3480 public void annotationColour_actionPerformed()
3482 new AnnotationColourChooser(viewport, alignPanel);
3486 public void annotationColumn_actionPerformed(ActionEvent e)
3488 new AnnotationColumnChooser(viewport, alignPanel);
3492 * Action on the user checking or unchecking the option to apply the selected
3493 * colour scheme to all groups. If unchecked, groups may have their own
3494 * independent colour schemes.
3499 public void applyToAllGroups_actionPerformed(boolean selected)
3501 viewport.setColourAppliesToAllGroups(selected);
3505 * Action on user selecting a colour from the colour menu
3508 * the name (not the menu item label!) of the colour scheme
3511 public void changeColour_actionPerformed(String name)
3514 * 'User Defined' opens a panel to configure or load a
3515 * user-defined colour scheme
3517 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3519 new UserDefinedColours(alignPanel);
3524 * otherwise set the chosen colour scheme (or null for 'None')
3526 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3528 viewport.getAlignment(), viewport.getHiddenRepSequences());
3533 * Actions on setting or changing the alignment colour scheme
3538 public void changeColour(ColourSchemeI cs)
3540 // TODO: pull up to controller method
3541 ColourMenuHelper.setColourSelected(colourMenu, cs);
3543 viewport.setGlobalColourScheme(cs);
3545 alignPanel.paintAlignment(true, true);
3549 * Show the PID threshold slider panel
3552 protected void modifyPID_actionPerformed()
3554 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3555 alignPanel.getViewName());
3556 SliderPanel.showPIDSlider();
3560 * Show the Conservation slider panel
3563 protected void modifyConservation_actionPerformed()
3565 SliderPanel.setConservationSlider(alignPanel,
3566 viewport.getResidueShading(), alignPanel.getViewName());
3567 SliderPanel.showConservationSlider();
3571 * Action on selecting or deselecting (Colour) By Conservation
3574 public void conservationMenuItem_actionPerformed(boolean selected)
3576 modifyConservation.setEnabled(selected);
3577 viewport.setConservationSelected(selected);
3578 viewport.getResidueShading().setConservationApplied(selected);
3580 changeColour(viewport.getGlobalColourScheme());
3583 modifyConservation_actionPerformed();
3587 SliderPanel.hideConservationSlider();
3592 * Action on selecting or deselecting (Colour) Above PID Threshold
3595 public void abovePIDThreshold_actionPerformed(boolean selected)
3597 modifyPID.setEnabled(selected);
3598 viewport.setAbovePIDThreshold(selected);
3601 viewport.getResidueShading().setThreshold(0,
3602 viewport.isIgnoreGapsConsensus());
3605 changeColour(viewport.getGlobalColourScheme());
3608 modifyPID_actionPerformed();
3612 SliderPanel.hidePIDSlider();
3623 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3625 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3626 AlignmentSorter.sortByPID(viewport.getAlignment(),
3627 viewport.getAlignment().getSequenceAt(0));
3628 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3629 viewport.getAlignment()));
3630 alignPanel.paintAlignment(true, false);
3640 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3642 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3643 AlignmentSorter.sortByID(viewport.getAlignment());
3645 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3646 alignPanel.paintAlignment(true, false);
3656 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3658 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3659 AlignmentSorter.sortByLength(viewport.getAlignment());
3660 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3661 viewport.getAlignment()));
3662 alignPanel.paintAlignment(true, false);
3672 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3674 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3675 AlignmentSorter.sortByGroup(viewport.getAlignment());
3676 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3677 viewport.getAlignment()));
3679 alignPanel.paintAlignment(true, false);
3689 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3691 new RedundancyPanel(alignPanel, this);
3701 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3703 if ((viewport.getSelectionGroup() == null)
3704 || (viewport.getSelectionGroup().getSize() < 2))
3706 JvOptionPane.showInternalMessageDialog(this,
3707 MessageManager.getString(
3708 "label.you_must_select_least_two_sequences"),
3709 MessageManager.getString("label.invalid_selection"),
3710 JvOptionPane.WARNING_MESSAGE);
3714 JInternalFrame frame = new JInternalFrame();
3715 frame.setContentPane(new PairwiseAlignPanel(viewport));
3716 Desktop.addInternalFrame(frame,
3717 MessageManager.getString("action.pairwise_alignment"), 600,
3723 public void autoCalculate_actionPerformed(ActionEvent e)
3725 viewport.setAutoCalculateConsensusAndConservation(autoCalculate.isSelected());
3726 if (viewport.getAutoCalculateConsensusAndConservation())
3728 viewport.firePropertyChange("alignment", null,
3729 viewport.getAlignment().getSequences());
3734 public void sortByTreeOption_actionPerformed(ActionEvent e)
3736 viewport.sortByTree = sortByTree.isSelected();
3740 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3742 viewport.followSelection = listenToViewSelections.isSelected();
3746 * Constructs a tree panel and adds it to the desktop
3749 * tree type (NJ or AV)
3751 * name of score model used to compute the tree
3753 * parameters for the distance or similarity calculation
3755 void newTreePanel(String type, String modelName,
3756 SimilarityParamsI options)
3758 String frameTitle = "";
3761 boolean onSelection = false;
3762 if (viewport.getSelectionGroup() != null
3763 && viewport.getSelectionGroup().getSize() > 0)
3765 SequenceGroup sg = viewport.getSelectionGroup();
3767 /* Decide if the selection is a column region */
3768 for (SequenceI _s : sg.getSequences())
3770 if (_s.getLength() < sg.getEndRes())
3772 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
3773 MessageManager.getString(
3774 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3775 MessageManager.getString(
3776 "label.sequences_selection_not_aligned"),
3777 JvOptionPane.WARNING_MESSAGE);
3786 if (viewport.getAlignment().getHeight() < 2)
3792 tp = new TreePanel(alignPanel, type, modelName, options);
3793 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3795 frameTitle += " from ";
3797 if (viewport.getViewName() != null)
3799 frameTitle += viewport.getViewName() + " of ";
3802 frameTitle += this.title;
3804 Dimension dim = Platform.getDimIfEmbedded(tp, 600, 500);
3805 Desktop.addInternalFrame(tp, frameTitle, dim.width, dim.height);
3816 public void addSortByOrderMenuItem(String title,
3817 final AlignmentOrder order)
3819 final JMenuItem item = new JMenuItem(MessageManager
3820 .formatMessage("action.by_title_param", new Object[]
3823 item.addActionListener(new java.awt.event.ActionListener()
3826 public void actionPerformed(ActionEvent e)
3828 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3830 // TODO: JBPNote - have to map order entries to curent SequenceI
3832 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3834 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3835 viewport.getAlignment()));
3837 alignPanel.paintAlignment(true, false);
3843 * Add a new sort by annotation score menu item
3846 * the menu to add the option to
3848 * the label used to retrieve scores for each sequence on the
3851 public void addSortByAnnotScoreMenuItem(JMenu sort,
3852 final String scoreLabel)
3854 final JMenuItem item = new JMenuItem(scoreLabel);
3856 item.addActionListener(new java.awt.event.ActionListener()
3859 public void actionPerformed(ActionEvent e)
3861 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3862 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3863 viewport.getAlignment());// ,viewport.getSelectionGroup());
3864 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3865 viewport.getAlignment()));
3866 alignPanel.paintAlignment(true, false);
3872 * last hash for alignment's annotation array - used to minimise cost of
3875 protected int _annotationScoreVectorHash;
3878 * search the alignment and rebuild the sort by annotation score submenu the
3879 * last alignment annotation vector hash is stored to minimize cost of
3880 * rebuilding in subsequence calls.
3884 public void buildSortByAnnotationScoresMenu()
3886 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3891 if (viewport.getAlignment().getAlignmentAnnotation()
3892 .hashCode() != _annotationScoreVectorHash)
3894 sortByAnnotScore.removeAll();
3895 // almost certainly a quicker way to do this - but we keep it simple
3896 Hashtable<String, String> scoreSorts = new Hashtable<>();
3897 AlignmentAnnotation aann[];
3898 for (SequenceI sqa : viewport.getAlignment().getSequences())
3900 aann = sqa.getAnnotation();
3901 for (int i = 0; aann != null && i < aann.length; i++)
3903 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3905 scoreSorts.put(aann[i].label, aann[i].label);
3909 Enumeration<String> labels = scoreSorts.keys();
3910 while (labels.hasMoreElements())
3912 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3913 labels.nextElement());
3915 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3918 _annotationScoreVectorHash = viewport.getAlignment()
3919 .getAlignmentAnnotation().hashCode();
3924 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3925 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3926 * call. Listeners are added to remove the menu item when the treePanel is
3927 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3931 public void buildTreeSortMenu()
3933 sortByTreeMenu.removeAll();
3935 List<Component> comps = PaintRefresher.components
3936 .get(viewport.getSequenceSetId());
3937 List<TreePanel> treePanels = new ArrayList<>();
3938 for (Component comp : comps)
3940 if (comp instanceof TreePanel)
3942 treePanels.add((TreePanel) comp);
3946 if (treePanels.size() < 1)
3948 sortByTreeMenu.setVisible(false);
3952 sortByTreeMenu.setVisible(true);
3954 for (final TreePanel tp : treePanels)
3956 final JMenuItem item = new JMenuItem(tp.getTitle());
3957 item.addActionListener(new java.awt.event.ActionListener()
3960 public void actionPerformed(ActionEvent e)
3962 tp.sortByTree_actionPerformed();
3963 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3968 sortByTreeMenu.add(item);
3972 public boolean sortBy(AlignmentOrder alorder, String undoname)
3974 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3975 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3976 if (undoname != null)
3978 addHistoryItem(new OrderCommand(undoname, oldOrder,
3979 viewport.getAlignment()));
3981 alignPanel.paintAlignment(true, false);
3986 * Work out whether the whole set of sequences or just the selected set will
3987 * be submitted for multiple alignment.
3990 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3992 // Now, check we have enough sequences
3993 AlignmentView msa = null;
3995 if ((viewport.getSelectionGroup() != null)
3996 && (viewport.getSelectionGroup().getSize() > 1))
3998 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3999 // some common interface!
4001 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4002 * SequenceI[sz = seqs.getSize(false)];
4004 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4005 * seqs.getSequenceAt(i); }
4007 msa = viewport.getAlignmentView(true);
4009 else if (viewport.getSelectionGroup() != null
4010 && viewport.getSelectionGroup().getSize() == 1)
4012 int option = JvOptionPane.showConfirmDialog(this,
4013 MessageManager.getString("warn.oneseq_msainput_selection"),
4014 MessageManager.getString("label.invalid_selection"),
4015 JvOptionPane.OK_CANCEL_OPTION);
4016 if (option == JvOptionPane.OK_OPTION)
4018 msa = viewport.getAlignmentView(false);
4023 msa = viewport.getAlignmentView(false);
4029 * Decides what is submitted to a secondary structure prediction service: the
4030 * first sequence in the alignment, or in the current selection, or, if the
4031 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4032 * region or the whole alignment. (where the first sequence in the set is the
4033 * one that the prediction will be for).
4035 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4037 AlignmentView seqs = null;
4039 if ((viewport.getSelectionGroup() != null)
4040 && (viewport.getSelectionGroup().getSize() > 0))
4042 seqs = viewport.getAlignmentView(true);
4046 seqs = viewport.getAlignmentView(false);
4048 // limit sequences - JBPNote in future - could spawn multiple prediction
4050 // TODO: viewport.getAlignment().isAligned is a global state - the local
4051 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4052 if (!viewport.getAlignment().isAligned(false))
4054 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4055 // TODO: if seqs.getSequences().length>1 then should really have warned
4069 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4071 // Pick the tree file
4072 JalviewFileChooser chooser = new JalviewFileChooser(
4073 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4074 chooser.setFileView(new JalviewFileView());
4075 chooser.setDialogTitle(
4076 MessageManager.getString("label.select_newick_like_tree_file"));
4077 chooser.setToolTipText(
4078 MessageManager.getString("label.load_tree_file"));
4080 chooser.setResponseHandler(0,new Runnable()
4085 String filePath = chooser.getSelectedFile().getPath();
4086 Cache.setProperty("LAST_DIRECTORY", filePath);
4087 NewickFile fin = null;
4090 fin = new NewickFile(new FileParse(chooser.getSelectedFile(),
4091 DataSourceType.FILE));
4092 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4093 } catch (Exception ex)
4095 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), ex.getMessage(),
4097 .getString("label.problem_reading_tree_file"),
4098 JvOptionPane.WARNING_MESSAGE);
4099 ex.printStackTrace();
4101 if (fin != null && fin.hasWarningMessage())
4103 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
4104 fin.getWarningMessage(),
4105 MessageManager.getString(
4106 "label.possible_problem_with_tree_file"),
4107 JvOptionPane.WARNING_MESSAGE);
4111 chooser.showOpenDialog(this);
4114 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4116 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4119 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4120 int h, int x, int y)
4122 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4126 * Add a treeviewer for the tree extracted from a Newick file object to the
4127 * current alignment view
4134 * Associated alignment input data (or null)
4143 * @return TreePanel handle
4145 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4146 AlignmentView input, int w, int h, int x, int y)
4148 TreePanel tp = null;
4154 if (nf.getTree() != null)
4156 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4157 Dimension dim = Platform.getDimIfEmbedded(tp, -1, -1);
4160 dim = new Dimension(w, h);
4164 // no offset, either
4167 tp.setSize(dim.width, dim.height);
4171 tp.setLocation(x, y);
4174 Desktop.addInternalFrame(tp, treeTitle, dim.width, dim.height);
4176 } catch (Exception ex)
4178 ex.printStackTrace();
4184 private boolean buildingMenu = false;
4187 * Generates menu items and listener event actions for web service clients
4190 public void BuildWebServiceMenu()
4192 if (Jalview.isSynchronous())
4196 while (buildingMenu)
4200 System.err.println("Waiting for building menu to finish.");
4202 } catch (Exception e)
4206 final AlignFrame me = this;
4207 buildingMenu = true;
4208 new Thread(new Runnable()
4213 final List<JMenuItem> legacyItems = new ArrayList<>();
4216 // System.err.println("Building ws menu again "
4217 // + Thread.currentThread());
4218 // TODO: add support for context dependent disabling of services based
4220 // alignment and current selection
4221 // TODO: add additional serviceHandle parameter to specify abstract
4223 // class independently of AbstractName
4224 // TODO: add in rediscovery GUI function to restart discoverer
4225 // TODO: group services by location as well as function and/or
4227 // object broker mechanism.
4228 final Vector<JMenu> wsmenu = new Vector<>();
4229 final IProgressIndicator af = me;
4232 * do not i18n these strings - they are hard-coded in class
4233 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4234 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4236 final JMenu msawsmenu = new JMenu("Alignment");
4237 final JMenu secstrmenu = new JMenu(
4238 "Secondary Structure Prediction");
4239 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4240 final JMenu analymenu = new JMenu("Analysis");
4241 final JMenu dismenu = new JMenu("Protein Disorder");
4242 // JAL-940 - only show secondary structure prediction services from
4243 // the legacy server
4244 Hashtable<String, Vector<ServiceHandle>> services = Discoverer
4245 .getInstance().getServices();
4246 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4248 services != null && (services.size() > 0))
4250 // TODO: refactor to allow list of AbstractName/Handler bindings to
4252 // stored or retrieved from elsewhere
4253 // No MSAWS used any more:
4254 // Vector msaws = null; // (Vector)
4255 // Discoverer.services.get("MsaWS");
4256 Vector<ServiceHandle> secstrpr = services.get("SecStrPred");
4257 if (secstrpr != null)
4259 // Add any secondary structure prediction services
4260 for (int i = 0, j = secstrpr.size(); i < j; i++)
4262 final ext.vamsas.ServiceHandle sh = secstrpr
4264 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4265 .getServiceClient(sh);
4266 int p = secstrmenu.getItemCount();
4267 impl.attachWSMenuEntry(secstrmenu, me);
4268 int q = secstrmenu.getItemCount();
4269 for (int litm = p; litm < q; litm++)
4271 legacyItems.add(secstrmenu.getItem(litm));
4277 // Add all submenus in the order they should appear on the web
4279 wsmenu.add(msawsmenu);
4280 wsmenu.add(secstrmenu);
4281 wsmenu.add(dismenu);
4282 wsmenu.add(analymenu);
4283 // No search services yet
4284 // wsmenu.add(seqsrchmenu);
4286 javax.swing.SwingUtilities.invokeLater(new Runnable()
4293 webService.removeAll();
4294 // first, add discovered services onto the webservices menu
4295 if (wsmenu.size() > 0)
4297 for (int i = 0, j = wsmenu.size(); i < j; i++)
4299 webService.add(wsmenu.get(i));
4304 webService.add(me.webServiceNoServices);
4306 // TODO: move into separate menu builder class.
4307 // boolean new_sspred = false;
4308 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4310 Jws2Discoverer jws2servs = Jws2Discoverer.getInstance();
4311 if (jws2servs != null)
4313 if (jws2servs.hasServices())
4315 jws2servs.attachWSMenuEntry(webService, me);
4316 for (Jws2Instance sv : jws2servs.getServices())
4318 if (sv.description.toLowerCase().contains("jpred"))
4320 for (JMenuItem jmi : legacyItems)
4322 jmi.setVisible(false);
4328 if (jws2servs.isRunning())
4330 JMenuItem tm = new JMenuItem(
4331 "Still discovering JABA Services");
4332 tm.setEnabled(false);
4337 build_urlServiceMenu(me.webService);
4338 build_fetchdbmenu(webService);
4339 for (JMenu item : wsmenu)
4341 if (item.getItemCount() == 0)
4343 item.setEnabled(false);
4347 item.setEnabled(true);
4350 } catch (Exception e)
4353 "Exception during web service menu building process.",
4358 } catch (Exception e)
4361 buildingMenu = false;
4368 * construct any groupURL type service menu entries.
4372 protected void build_urlServiceMenu(JMenu webService)
4374 // TODO: remove this code when 2.7 is released
4375 // DEBUG - alignmentView
4377 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4378 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4380 * @Override public void actionPerformed(ActionEvent e) {
4381 * jalview.datamodel.AlignmentView
4382 * .testSelectionViews(af.viewport.getAlignment(),
4383 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4385 * }); webService.add(testAlView);
4387 // TODO: refactor to RestClient discoverer and merge menu entries for
4388 // rest-style services with other types of analysis/calculation service
4389 // SHmmr test client - still being implemented.
4390 // DEBUG - alignmentView
4392 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4395 client.attachWSMenuEntry(
4396 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4402 * Searches the alignment sequences for xRefs and builds the Show
4403 * Cross-References menu (formerly called Show Products), with database
4404 * sources for which cross-references are found (protein sources for a
4405 * nucleotide alignment and vice versa)
4407 * @return true if Show Cross-references menu should be enabled
4409 public boolean canShowProducts()
4411 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4412 AlignmentI dataset = viewport.getAlignment().getDataset();
4414 showProducts.removeAll();
4415 final boolean dna = viewport.getAlignment().isNucleotide();
4417 if (seqs == null || seqs.length == 0)
4419 // nothing to see here.
4423 boolean showp = false;
4426 List<String> ptypes = new CrossRef(seqs, dataset)
4427 .findXrefSourcesForSequences(dna);
4429 for (final String source : ptypes)
4432 final AlignFrame af = this;
4433 JMenuItem xtype = new JMenuItem(source);
4434 xtype.addActionListener(new ActionListener()
4437 public void actionPerformed(ActionEvent e)
4439 showProductsFor(af.viewport.getSequenceSelection(), dna,
4443 showProducts.add(xtype);
4445 showProducts.setVisible(showp);
4446 showProducts.setEnabled(showp);
4447 } catch (Exception e)
4450 "canShowProducts threw an exception - please report to help@jalview.org",
4458 * Finds and displays cross-references for the selected sequences (protein
4459 * products for nucleotide sequences, dna coding sequences for peptides).
4462 * the sequences to show cross-references for
4464 * true if from a nucleotide alignment (so showing proteins)
4466 * the database to show cross-references for
4468 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4469 final String source)
4471 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4476 * Construct and display a new frame containing the translation of this
4477 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4480 public void showTranslation_actionPerformed(GeneticCodeI codeTable)
4482 AlignmentI al = null;
4485 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4487 al = dna.translateCdna(codeTable);
4488 } catch (Exception ex)
4490 jalview.bin.Cache.log.error(
4491 "Exception during translation. Please report this !", ex);
4492 final String msg = MessageManager.getString(
4493 "label.error_when_translating_sequences_submit_bug_report");
4494 final String errorTitle = MessageManager
4495 .getString("label.implementation_error")
4496 + MessageManager.getString("label.translation_failed");
4497 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msg, errorTitle,
4498 JvOptionPane.ERROR_MESSAGE);
4501 if (al == null || al.getHeight() == 0)
4503 final String msg = MessageManager.getString(
4504 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4505 final String errorTitle = MessageManager
4506 .getString("label.translation_failed");
4507 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msg, errorTitle,
4508 JvOptionPane.WARNING_MESSAGE);
4512 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4513 af.setFileFormat(this.currentFileFormat);
4514 final String newTitle = MessageManager
4515 .formatMessage("label.translation_of_params", new Object[]
4516 { this.getTitle(), codeTable.getId() });
4517 af.setTitle(newTitle);
4518 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4520 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4521 AlignViewport.openSplitFrame(this, af, new Alignment(seqs));
4525 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4532 * Set the file format
4536 public void setFileFormat(FileFormatI format)
4538 this.currentFileFormat = format;
4542 * Try to load a features file onto the alignment.
4545 * contents or path to retrieve file or a File object
4547 * access mode of file (see jalview.io.AlignFile)
4548 * @return true if features file was parsed correctly.
4550 public boolean parseFeaturesFile(Object file, DataSourceType sourceType)
4553 return avc.parseFeaturesFile(file, sourceType,
4554 Cache.getDefault(Preferences.RELAXEDSEQIDMATCHING, false));
4559 public void refreshFeatureUI(boolean enableIfNecessary)
4561 // note - currently this is only still here rather than in the controller
4562 // because of the featureSettings hard reference that is yet to be
4564 if (enableIfNecessary)
4566 viewport.setShowSequenceFeatures(true);
4567 showSeqFeatures.setSelected(true);
4573 public void dragEnter(DropTargetDragEvent evt)
4578 public void dragExit(DropTargetEvent evt)
4583 public void dragOver(DropTargetDragEvent evt)
4588 public void dropActionChanged(DropTargetDragEvent evt)
4593 public void drop(DropTargetDropEvent evt)
4595 // JAL-1552 - acceptDrop required before getTransferable call for
4596 // Java's Transferable for native dnd
4597 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4598 Transferable t = evt.getTransferable();
4600 final AlignFrame thisaf = this;
4601 final List<Object> files = new ArrayList<>();
4602 List<DataSourceType> protocols = new ArrayList<>();
4606 Desktop.transferFromDropTarget(files, protocols, evt, t);
4607 } catch (Exception e)
4609 e.printStackTrace();
4613 new Thread(new Runnable()
4620 // check to see if any of these files have names matching sequences
4623 SequenceIdMatcher idm = new SequenceIdMatcher(
4624 viewport.getAlignment().getSequencesArray());
4626 * Object[] { String,SequenceI}
4628 ArrayList<Object[]> filesmatched = new ArrayList<>();
4629 ArrayList<Object> filesnotmatched = new ArrayList<>();
4630 for (int i = 0; i < files.size(); i++)
4633 Object file = files.get(i);
4634 String fileName = file.toString();
4636 DataSourceType protocol = (file instanceof File
4637 ? DataSourceType.FILE
4638 : FormatAdapter.checkProtocol(fileName));
4639 if (protocol == DataSourceType.FILE)
4642 if (file instanceof File) {
4644 Platform.cacheFileData(fl);
4646 fl = new File(fileName);
4648 pdbfn = fl.getName();
4650 else if (protocol == DataSourceType.URL)
4652 URL url = new URL(fileName);
4653 pdbfn = url.getFile();
4655 if (pdbfn.length() > 0)
4657 // attempt to find a match in the alignment
4658 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4659 int l = 0, c = pdbfn.indexOf(".");
4660 while (mtch == null && c != -1)
4665 } while ((c = pdbfn.indexOf(".", l)) > l);
4668 pdbfn = pdbfn.substring(0, l);
4670 mtch = idm.findAllIdMatches(pdbfn);
4677 type = new IdentifyFile().identify(file, protocol);
4678 } catch (Exception ex)
4682 if (type != null && type.isStructureFile())
4684 filesmatched.add(new Object[] { file, protocol, mtch });
4688 // File wasn't named like one of the sequences or wasn't a PDB
4690 filesnotmatched.add(file);
4694 if (filesmatched.size() > 0)
4696 boolean autoAssociate = Cache
4697 .getDefault(Preferences.AUTOASSOCIATE_PDBANDSEQS, false);
4700 String msg = MessageManager.formatMessage(
4701 "label.automatically_associate_structure_files_with_sequences_same_name",
4703 { Integer.valueOf(filesmatched.size())
4705 String ttl = MessageManager.getString(
4706 "label.automatically_associate_structure_files_by_name");
4707 int choice = JvOptionPane.showConfirmDialog(thisaf, msg,
4708 ttl, JvOptionPane.YES_NO_OPTION);
4709 autoAssociate = choice == JvOptionPane.YES_OPTION;
4713 for (Object[] fm : filesmatched)
4715 // try and associate
4716 // TODO: may want to set a standard ID naming formalism for
4717 // associating PDB files which have no IDs.
4718 for (SequenceI toassoc : (SequenceI[]) fm[2])
4721 PDBEntry pe = AssociatePdbFileWithSeq
4722 .associatePdbWithSeq(fm[0].toString(),
4723 (DataSourceType) fm[1], toassoc, false);
4726 System.err.println("Associated file : "
4727 + (fm[0].toString()) + " with "
4728 + toassoc.getDisplayId(true));
4732 // TODO: do we need to update overview ? only if features are
4734 alignPanel.paintAlignment(true, false);
4740 * add declined structures as sequences
4742 for (Object[] o : filesmatched)
4744 filesnotmatched.add(o[0]);
4748 if (filesnotmatched.size() > 0)
4750 if (assocfiles > 0 && (Cache.getDefault(
4751 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4752 || JvOptionPane.showConfirmDialog(thisaf,
4753 "<html>" + MessageManager.formatMessage(
4754 "label.ignore_unmatched_dropped_files_info",
4757 filesnotmatched.size())
4760 MessageManager.getString(
4761 "label.ignore_unmatched_dropped_files"),
4762 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4766 for (Object fn : filesnotmatched)
4768 loadJalviewDataFile(fn, null, null, null);
4772 } catch (Exception ex)
4774 ex.printStackTrace();
4782 * Attempt to load a "dropped" file or URL string, by testing in turn for
4784 * <li>an Annotation file</li>
4785 * <li>a JNet file</li>
4786 * <li>a features file</li>
4787 * <li>else try to interpret as an alignment file</li>
4791 * either a filename or a URL string.
4793 public void loadJalviewDataFile(Object file, DataSourceType sourceType,
4794 FileFormatI format, SequenceI assocSeq)
4796 // BH 2018 was String file
4799 if (sourceType == null)
4801 sourceType = FormatAdapter.checkProtocol(file);
4803 // if the file isn't identified, or not positively identified as some
4804 // other filetype (PFAM is default unidentified alignment file type) then
4805 // try to parse as annotation.
4806 boolean isAnnotation = (format == null
4807 || FileFormat.Pfam.equals(format))
4808 ? new AnnotationFile().annotateAlignmentView(viewport,
4814 // first see if its a T-COFFEE score file
4815 TCoffeeScoreFile tcf = null;
4818 tcf = new TCoffeeScoreFile(file, sourceType);
4821 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4825 new TCoffeeColourScheme(viewport.getAlignment()));
4826 isAnnotation = true;
4827 setStatus(MessageManager.getString(
4828 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4832 // some problem - if no warning its probable that the ID matching
4833 // process didn't work
4834 JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
4835 tcf.getWarningMessage() == null
4836 ? MessageManager.getString(
4837 "label.check_file_matches_sequence_ids_alignment")
4838 : tcf.getWarningMessage(),
4839 MessageManager.getString(
4840 "label.problem_reading_tcoffee_score_file"),
4841 JvOptionPane.WARNING_MESSAGE);
4848 } catch (Exception x)
4851 "Exception when processing data source as T-COFFEE score file",
4857 // try to see if its a JNet 'concise' style annotation file *before*
4859 // try to parse it as a features file
4862 format = new IdentifyFile().identify(file, sourceType);
4864 if (FileFormat.ScoreMatrix == format)
4866 ScoreMatrixFile sm = new ScoreMatrixFile(
4867 new FileParse(file, sourceType));
4869 // todo: i18n this message
4870 setStatus(MessageManager.formatMessage(
4871 "label.successfully_loaded_matrix",
4872 sm.getMatrixName()));
4874 else if (FileFormat.Jnet.equals(format))
4876 JPredFile predictions = new JPredFile(file, sourceType);
4877 new JnetAnnotationMaker();
4878 JnetAnnotationMaker.add_annotation(predictions,
4879 viewport.getAlignment(), 0, false);
4880 viewport.getAlignment().setupJPredAlignment();
4881 isAnnotation = true;
4883 // else if (IdentifyFile.FeaturesFile.equals(format))
4884 else if (FileFormat.Features.equals(format))
4886 if (parseFeaturesFile(file, sourceType))
4888 SplitFrame splitFrame = (SplitFrame) getSplitViewContainer();
4889 if (splitFrame != null)
4891 splitFrame.repaint();
4895 alignPanel.paintAlignment(true, true);
4901 if (file instanceof File) {
4902 new FileLoader().loadFile(viewport, (File) file, sourceType, format);
4904 new FileLoader().LoadFile(viewport, (String) file, sourceType, format);
4911 updateForAnnotations();
4913 } catch (Exception ex)
4915 ex.printStackTrace();
4916 } catch (OutOfMemoryError oom)
4921 } catch (Exception x)
4926 + (sourceType != null
4927 ? (sourceType == DataSourceType.PASTE
4929 : "using " + sourceType + " from "
4933 ? "(parsing as '" + format + "' file)"
4935 oom, Desktop.getDesktopPane());
4940 * Do all updates necessary after an annotation file such as jnet. Also called
4941 * from Jalview.loadAppletParams for "annotations", "jnetFile"
4943 public void updateForAnnotations()
4945 alignPanel.adjustAnnotationHeight();
4946 viewport.updateSequenceIdColours();
4947 buildSortByAnnotationScoresMenu();
4948 alignPanel.paintAlignment(true, true);
4952 * Method invoked by the ChangeListener on the tabbed pane, in other words
4953 * when a different tabbed pane is selected by the user or programmatically.
4956 public void tabSelectionChanged(int index)
4960 alignPanel = alignPanels.get(index);
4961 viewport = alignPanel.av;
4962 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
4963 setMenusFromViewport(viewport);
4964 if (featureSettings != null && featureSettings.isOpen()
4965 && featureSettings.fr.getViewport() != viewport)
4967 if (viewport.isShowSequenceFeatures())
4969 // refresh the featureSettings to reflect UI change
4970 showFeatureSettingsUI();
4974 // close feature settings for this view.
4975 featureSettings.close();
4982 * 'focus' any colour slider that is open to the selected viewport
4984 if (viewport.getConservationSelected())
4986 SliderPanel.setConservationSlider(alignPanel,
4987 viewport.getResidueShading(), alignPanel.getViewName());
4991 SliderPanel.hideConservationSlider();
4993 if (viewport.getAbovePIDThreshold())
4995 SliderPanel.setPIDSliderSource(alignPanel,
4996 viewport.getResidueShading(), alignPanel.getViewName());
5000 SliderPanel.hidePIDSlider();
5004 * If there is a frame linked to this one in a SplitPane, switch it to the
5005 * same view tab index. No infinite recursion of calls should happen, since
5006 * tabSelectionChanged() should not get invoked on setting the selected
5007 * index to an unchanged value. Guard against setting an invalid index
5008 * before the new view peer tab has been created.
5010 final AlignViewportI peer = viewport.getCodingComplement();
5013 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
5014 .getAlignPanel().alignFrame;
5015 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5017 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5023 * On right mouse click on view tab, prompt for and set new view name.
5026 public void tabbedPane_mousePressed(MouseEvent e)
5028 if (e.isPopupTrigger())
5030 String msg = MessageManager.getString("label.enter_view_name");
5031 String ttl = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
5032 String reply = JvOptionPane.showInputDialog(msg, ttl);
5036 viewport.setViewName(reply);
5037 // TODO warn if reply is in getExistingViewNames()?
5038 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5043 public AlignViewport getCurrentView()
5049 * Change the display state for the given feature groups -- Added by BH from
5053 * list of group strings
5055 * visible or invisible
5057 public void setFeatureGroupState(String[] groups, boolean state)
5059 jalview.api.FeatureRenderer fr = null;
5060 viewport.setShowSequenceFeatures(true);
5061 if (alignPanel != null
5062 && (fr = alignPanel.getFeatureRenderer()) != null)
5065 fr.setGroupVisibility(Arrays.asList(groups), state);
5066 alignPanel.getSeqPanel().seqCanvas.repaint();
5067 if (alignPanel.overviewPanel != null)
5069 alignPanel.overviewPanel.updateOverviewImage();
5075 * Open the dialog for regex description parsing.
5078 protected void extractScores_actionPerformed(ActionEvent e)
5080 ParseProperties pp = new jalview.analysis.ParseProperties(
5081 viewport.getAlignment());
5082 // TODO: verify regex and introduce GUI dialog for version 2.5
5083 // if (pp.getScoresFromDescription("col", "score column ",
5084 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5086 if (pp.getScoresFromDescription("description column",
5087 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5089 buildSortByAnnotationScoresMenu();
5097 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5101 protected void showDbRefs_actionPerformed(ActionEvent e)
5103 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5109 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5113 protected void showNpFeats_actionPerformed(ActionEvent e)
5115 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5119 * find the viewport amongst the tabs in this alignment frame and close that
5124 public boolean closeView(AlignViewportI av)
5128 this.closeMenuItem_actionPerformed(false);
5131 Component[] comp = tabbedPane.getComponents();
5132 for (int i = 0; comp != null && i < comp.length; i++)
5134 if (comp[i] instanceof AlignmentPanel)
5136 if (((AlignmentPanel) comp[i]).av == av)
5139 closeView((AlignmentPanel) comp[i]);
5147 protected void build_fetchdbmenu(JMenu webService)
5149 // Temporary hack - DBRef Fetcher always top level ws entry.
5150 // TODO We probably want to store a sequence database checklist in
5151 // preferences and have checkboxes.. rather than individual sources selected
5153 final JMenu rfetch = new JMenu(
5154 MessageManager.getString("action.fetch_db_references"));
5155 rfetch.setToolTipText(MessageManager.getString(
5156 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5157 webService.add(rfetch);
5159 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5160 MessageManager.getString("option.trim_retrieved_seqs"));
5161 trimrs.setToolTipText(
5162 MessageManager.getString("label.trim_retrieved_sequences"));
5164 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5165 trimrs.addActionListener(new ActionListener()
5168 public void actionPerformed(ActionEvent e)
5170 trimrs.setSelected(trimrs.isSelected());
5171 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5172 Boolean.valueOf(trimrs.isSelected()).toString());
5176 JMenuItem fetchr = new JMenuItem(
5177 MessageManager.getString("label.standard_databases"));
5178 fetchr.setToolTipText(
5179 MessageManager.getString("label.fetch_embl_uniprot"));
5180 fetchr.addActionListener(new ActionListener()
5184 public void actionPerformed(ActionEvent e)
5186 new Thread(new Runnable()
5191 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5192 .getAlignment().isNucleotide();
5193 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5194 alignPanel.av.getSequenceSelection(),
5195 alignPanel.alignFrame, null,
5196 alignPanel.alignFrame.featureSettings, isNucleotide);
5197 dbRefFetcher.addListener(new FetchFinishedListenerI()
5200 public void finished()
5203 for (FeatureSettingsModelI srcSettings : dbRefFetcher
5204 .getFeatureSettingsModels())
5207 alignPanel.av.mergeFeaturesStyle(srcSettings);
5209 AlignFrame.this.setMenusForViewport();
5212 dbRefFetcher.fetchDBRefs(false);
5220 Jalview.execThread(new Thread(new Runnable()
5225 Jalview.execRunnable(new Runnable()
5230 String[] dbclasses = jalview.ws.SequenceFetcher.getInstance()
5231 .getNonAlignmentSources();
5232 List<DbSourceProxy> otherdb;
5233 JMenu dfetch = new JMenu();
5234 JMenu ifetch = new JMenu();
5235 JMenuItem fetchr = null;
5236 int comp = 0, icomp = 0, mcomp = 15;
5237 String mname = null;
5239 for (String dbclass : dbclasses)
5241 otherdb = jalview.ws.SequenceFetcher.getInstance()
5242 .getSourceProxy(dbclass);
5243 // add a single entry for this class, or submenu allowing 'fetch
5245 if (otherdb == null || otherdb.size() < 1)
5251 mname = "From " + dbclass;
5253 if (otherdb.size() == 1)
5256 DbSourceProxy src = otherdb.get(0);
5257 DbSourceProxy[] dassource = new DbSourceProxy[] {
5259 fetchr = new JMenuItem(src.getDbSource());
5260 fetchr.addActionListener(new ActionListener()
5264 public void actionPerformed(ActionEvent e)
5266 new Thread(new Runnable()
5272 boolean isNucleotide = alignPanel.alignFrame
5273 .getViewport().getAlignment()
5275 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5276 alignPanel.av.getSequenceSelection(),
5277 alignPanel.alignFrame, dassource,
5278 alignPanel.alignFrame.featureSettings,
5281 .addListener(new FetchFinishedListenerI()
5284 public void finished()
5286 FeatureSettingsModelI srcSettings = dassource[0]
5287 .getFeatureColourScheme();
5288 alignPanel.av.mergeFeaturesStyle(
5290 AlignFrame.this.setMenusForViewport();
5293 dbRefFetcher.fetchDBRefs(false);
5299 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5300 MessageManager.formatMessage(
5301 "label.fetch_retrieve_from", new Object[]
5302 { src.getDbName() })));
5308 final DbSourceProxy[] dassource = otherdb
5309 .toArray(new DbSourceProxy[0]);
5311 DbSourceProxy src = otherdb.get(0);
5312 fetchr = new JMenuItem(MessageManager
5313 .formatMessage("label.fetch_all_param", new Object[]
5314 { src.getDbSource() }));
5315 fetchr.addActionListener(new ActionListener()
5318 public void actionPerformed(ActionEvent e)
5320 new Thread(new Runnable()
5326 boolean isNucleotide = alignPanel.alignFrame
5327 .getViewport().getAlignment()
5329 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5330 alignPanel.av.getSequenceSelection(),
5331 alignPanel.alignFrame, dassource,
5332 alignPanel.alignFrame.featureSettings,
5335 .addListener(new FetchFinishedListenerI()
5338 public void finished()
5340 AlignFrame.this.setMenusForViewport();
5343 dbRefFetcher.fetchDBRefs(false);
5349 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5350 MessageManager.formatMessage(
5351 "label.fetch_retrieve_from_all_sources",
5353 { Integer.valueOf(otherdb.size())
5355 src.getDbSource(), src.getDbName() })));
5358 // and then build the rest of the individual menus
5359 ifetch = new JMenu(MessageManager.formatMessage(
5360 "label.source_from_db_source", new Object[]
5361 { src.getDbSource() }));
5363 String imname = null;
5365 for (DbSourceProxy sproxy : otherdb)
5367 String dbname = sproxy.getDbName();
5368 String sname = dbname.length() > 5
5369 ? dbname.substring(0, 5) + "..."
5371 String msname = dbname.length() > 10
5372 ? dbname.substring(0, 10) + "..."
5376 imname = MessageManager
5377 .formatMessage("label.from_msname", new Object[]
5380 fetchr = new JMenuItem(msname);
5381 final DbSourceProxy[] dassrc = { sproxy };
5382 fetchr.addActionListener(new ActionListener()
5386 public void actionPerformed(ActionEvent e)
5388 new Thread(new Runnable()
5394 boolean isNucleotide = alignPanel.alignFrame
5395 .getViewport().getAlignment()
5397 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5398 alignPanel.av.getSequenceSelection(),
5399 alignPanel.alignFrame, dassrc,
5400 alignPanel.alignFrame.featureSettings,
5403 .addListener(new FetchFinishedListenerI()
5406 public void finished()
5408 AlignFrame.this.setMenusForViewport();
5411 dbRefFetcher.fetchDBRefs(false);
5417 fetchr.setToolTipText(
5418 "<html>" + MessageManager.formatMessage(
5419 "label.fetch_retrieve_from", new Object[]
5423 if (++icomp >= mcomp || i == (otherdb.size()))
5425 ifetch.setText(MessageManager.formatMessage(
5426 "label.source_to_target", imname, sname));
5428 ifetch = new JMenu();
5436 if (comp >= mcomp || dbi >= (dbclasses.length))
5438 dfetch.setText(MessageManager.formatMessage(
5439 "label.source_to_target", mname, dbclass));
5441 dfetch = new JMenu();
5454 * Left justify the whole alignment.
5457 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5459 AlignmentI al = viewport.getAlignment();
5461 viewport.firePropertyChange("alignment", null, al);
5465 * Right justify the whole alignment.
5468 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5470 AlignmentI al = viewport.getAlignment();
5472 viewport.firePropertyChange("alignment", null, al);
5476 public void setShowSeqFeatures(boolean b)
5478 showSeqFeatures.setSelected(b);
5479 viewport.setShowSequenceFeatures(b);
5486 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5487 * awt.event.ActionEvent)
5490 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5492 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5493 alignPanel.paintAlignment(false, false);
5500 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5504 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5506 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5507 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5515 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5516 * .event.ActionEvent)
5519 protected void showGroupConservation_actionPerformed(ActionEvent e)
5521 viewport.setShowGroupConservation(showGroupConservation.getState());
5522 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5529 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5530 * .event.ActionEvent)
5533 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5535 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5536 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5543 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5544 * .event.ActionEvent)
5547 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5549 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5550 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5554 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5556 showSequenceLogo.setState(true);
5557 viewport.setShowSequenceLogo(true);
5558 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5559 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5563 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5565 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5572 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5573 * .event.ActionEvent)
5576 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5578 if (avc.makeGroupsFromSelection())
5580 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5581 alignPanel.updateAnnotation();
5582 alignPanel.paintAlignment(true,
5583 viewport.needToUpdateStructureViews());
5587 public void clearAlignmentSeqRep()
5589 // TODO refactor alignmentseqrep to controller
5590 if (viewport.getAlignment().hasSeqrep())
5592 viewport.getAlignment().setSeqrep(null);
5593 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5594 alignPanel.updateAnnotation();
5595 alignPanel.paintAlignment(true, true);
5600 protected void createGroup_actionPerformed(ActionEvent e)
5602 if (avc.createGroup())
5604 if (applyAutoAnnotationSettings.isSelected())
5606 alignPanel.updateAnnotation(true, false);
5608 alignPanel.alignmentChanged();
5613 protected void unGroup_actionPerformed(ActionEvent e)
5617 alignPanel.alignmentChanged();
5622 * make the given alignmentPanel the currently selected tab
5624 * @param alignmentPanel
5626 public void setDisplayedView(AlignmentPanel alignmentPanel)
5628 if (!viewport.getSequenceSetId()
5629 .equals(alignmentPanel.av.getSequenceSetId()))
5631 throw new Error(MessageManager.getString(
5632 "error.implementation_error_cannot_show_view_alignment_frame"));
5634 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5635 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5637 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5642 * Action on selection of menu options to Show or Hide annotations.
5645 * @param forSequences
5646 * update sequence-related annotations
5647 * @param forAlignment
5648 * update non-sequence-related annotations
5651 protected void setAnnotationsVisibility(boolean visible,
5652 boolean forSequences, boolean forAlignment)
5654 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5655 .getAlignmentAnnotation();
5660 for (AlignmentAnnotation aa : anns)
5663 * don't display non-positional annotations on an alignment
5665 if (aa.annotations == null)
5669 boolean apply = (aa.sequenceRef == null && forAlignment)
5670 || (aa.sequenceRef != null && forSequences);
5673 aa.visible = visible;
5676 alignPanel.validateAnnotationDimensions(true);
5677 alignPanel.alignmentChanged();
5681 * Store selected annotation sort order for the view and repaint.
5684 protected void sortAnnotations_actionPerformed()
5686 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5688 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5689 alignPanel.paintAlignment(false, false);
5694 * @return alignment panels in this alignment frame
5696 public List<? extends AlignmentViewPanel> getAlignPanels()
5698 // alignPanels is never null
5699 // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5704 * Open a new alignment window, with the cDNA associated with this (protein)
5705 * alignment, aligned as is the protein.
5707 protected void viewAsCdna_actionPerformed()
5709 // TODO no longer a menu action - refactor as required
5710 final AlignmentI alignment = getViewport().getAlignment();
5711 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5712 if (mappings == null)
5716 List<SequenceI> cdnaSeqs = new ArrayList<>();
5717 for (SequenceI aaSeq : alignment.getSequences())
5719 for (AlignedCodonFrame acf : mappings)
5721 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5725 * There is a cDNA mapping for this protein sequence - add to new
5726 * alignment. It will share the same dataset sequence as other mapped
5727 * cDNA (no new mappings need to be created).
5729 final Sequence newSeq = new Sequence(dnaSeq);
5730 newSeq.setDatasetSequence(dnaSeq);
5731 cdnaSeqs.add(newSeq);
5735 if (cdnaSeqs.size() == 0)
5737 // show a warning dialog no mapped cDNA
5740 AlignmentI cdna = new Alignment(
5741 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5742 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5743 AlignFrame.DEFAULT_HEIGHT);
5744 cdna.alignAs(alignment);
5745 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5747 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5748 AlignFrame.DEFAULT_HEIGHT);
5752 * Set visibility of dna/protein complement view (available when shown in a
5758 protected void showComplement_actionPerformed(boolean show)
5760 SplitContainerI sf = getSplitViewContainer();
5763 sf.setComplementVisible(this, show);
5768 * Generate the reverse (optionally complemented) of the selected sequences,
5769 * and add them to the alignment
5772 protected void showReverse_actionPerformed(boolean complement)
5774 AlignmentI al = null;
5777 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5778 al = dna.reverseCdna(complement);
5779 viewport.addAlignment(al, "");
5780 addHistoryItem(new EditCommand(
5781 MessageManager.getString("label.add_sequences"), Action.PASTE,
5782 al.getSequencesArray(), 0, al.getWidth(),
5783 viewport.getAlignment()));
5784 } catch (Exception ex)
5786 System.err.println(ex.getMessage());
5792 * Try to run a script in the Groovy console, having first ensured that this
5793 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5794 * be targeted at this alignment.
5797 protected void runGroovy_actionPerformed()
5799 Jalview.setCurrentAlignFrame(this);
5800 groovy.ui.Console console = Desktop.getGroovyConsole();
5801 if (console != null)
5805 console.runScript();
5806 } catch (Exception ex)
5808 System.err.println((ex.toString()));
5809 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
5810 MessageManager.getString("label.couldnt_run_groovy_script"),
5811 MessageManager.getString("label.groovy_support_failed"),
5812 JvOptionPane.ERROR_MESSAGE);
5817 System.err.println("Can't run Groovy script as console not found");
5822 * Hides columns containing (or not containing) a specified feature, provided
5823 * that would not leave all columns hidden
5825 * @param featureType
5826 * @param columnsContaining
5829 public boolean hideFeatureColumns(String featureType,
5830 boolean columnsContaining)
5832 boolean notForHiding = avc.markColumnsContainingFeatures(
5833 columnsContaining, false, false, featureType);
5836 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5837 false, featureType))
5839 getViewport().hideSelectedColumns();
5847 protected void selectHighlightedColumns_actionPerformed(
5848 ActionEvent actionEvent)
5850 // include key modifier check in case user selects from menu
5851 avc.markHighlightedColumns(
5852 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5853 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5854 | ActionEvent.CTRL_MASK)) != 0);
5858 * Rebuilds the Colour menu, including any user-defined colours which have
5859 * been loaded either on startup or during the session
5861 public void buildColourMenu()
5863 colourMenu.removeAll();
5865 colourMenu.add(applyToAllGroups);
5866 colourMenu.add(textColour);
5867 colourMenu.addSeparator();
5869 ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this,
5870 viewport.getAlignment(), false);
5872 colourMenu.add(annotationColour);
5873 bg.add(annotationColour);
5874 colourMenu.addSeparator();
5875 colourMenu.add(conservationMenuItem);
5876 colourMenu.add(modifyConservation);
5877 colourMenu.add(abovePIDThreshold);
5878 colourMenu.add(modifyPID);
5880 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5881 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5885 * Open a dialog (if not already open) that allows the user to select and
5886 * calculate PCA or Tree analysis
5888 protected void openTreePcaDialog()
5890 if (alignPanel.getCalculationDialog() == null)
5892 new CalculationChooser(AlignFrame.this);
5897 protected void loadVcf_actionPerformed()
5899 JalviewFileChooser chooser = new JalviewFileChooser(
5900 Cache.getProperty("LAST_DIRECTORY"));
5901 chooser.setFileView(new JalviewFileView());
5902 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
5903 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
5904 final AlignFrame us = this;
5905 chooser.setResponseHandler(0, new Runnable()
5910 String choice = chooser.getSelectedFile().getPath();
5911 Cache.setProperty("LAST_DIRECTORY", choice);
5912 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
5913 new VCFLoader(choice).loadVCF(seqs, us);
5916 chooser.showOpenDialog(null);
5921 private Rectangle lastFeatureSettingsBounds = null;
5923 public void setFeatureSettingsGeometry(Rectangle bounds)
5925 lastFeatureSettingsBounds = bounds;
5929 public Rectangle getFeatureSettingsGeometry()
5931 return lastFeatureSettingsBounds;
5935 * BH 2019 from JalviewLite
5937 * get sequence feature groups that are hidden or shown
5943 public String[] getFeatureGroupsOfState(boolean visible)
5945 jalview.api.FeatureRenderer fr = null;
5946 if (alignPanel != null
5948 .getFeatureRenderer()) != null)
5950 List<String> gps = fr.getGroups(visible);
5951 String[] _gps = gps.toArray(new String[gps.size()]);
5957 public void scrollTo(int row, int column)
5959 alignPanel.getSeqPanel().scrollTo(row, column);
5962 public void scrollToRow(int row)
5964 alignPanel.getSeqPanel().scrollToRow(row);
5967 public void scrollToColumn(int column)
5969 alignPanel.getSeqPanel().scrollToColumn(column);
5974 * @return list of feature groups on the view
5976 public String[] getFeatureGroups()
5978 jalview.api.FeatureRenderer fr = null;
5979 if (alignPanel != null
5980 && (fr = alignPanel.getFeatureRenderer()) != null)
5982 List<String> gps = fr.getFeatureGroups();
5983 String[] _gps = gps.toArray(new String[gps.size()]);
5989 public void select(SequenceGroup sel, ColumnSelection csel,
5990 HiddenColumns hidden)
5992 alignPanel.getSeqPanel().selection(sel, csel, hidden, null);
5997 class PrintThread extends Thread
6001 public PrintThread(AlignmentPanel ap)
6006 static PageFormat pf;
6011 PrinterJob printJob = PrinterJob.getPrinterJob();
6015 printJob.setPrintable(ap, pf);
6019 printJob.setPrintable(ap);
6022 if (printJob.printDialog())
6027 } catch (Exception PrintException)
6029 PrintException.printStackTrace();