2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentSorter;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.analysis.CrossRef;
28 import jalview.analysis.NJTree;
29 import jalview.analysis.ParseProperties;
30 import jalview.analysis.SequenceIdMatcher;
31 import jalview.api.AlignViewControllerGuiI;
32 import jalview.api.AlignViewControllerI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.analysis.ScoreModelI;
35 import jalview.bin.Cache;
36 import jalview.commands.CommandI;
37 import jalview.commands.EditCommand;
38 import jalview.commands.EditCommand.Action;
39 import jalview.commands.OrderCommand;
40 import jalview.commands.RemoveGapColCommand;
41 import jalview.commands.RemoveGapsCommand;
42 import jalview.commands.SlideSequencesCommand;
43 import jalview.commands.TrimRegionCommand;
44 import jalview.datamodel.AlignedCodonFrame;
45 import jalview.datamodel.Alignment;
46 import jalview.datamodel.AlignmentAnnotation;
47 import jalview.datamodel.AlignmentI;
48 import jalview.datamodel.AlignmentOrder;
49 import jalview.datamodel.AlignmentView;
50 import jalview.datamodel.ColumnSelection;
51 import jalview.datamodel.PDBEntry;
52 import jalview.datamodel.SeqCigar;
53 import jalview.datamodel.Sequence;
54 import jalview.datamodel.SequenceGroup;
55 import jalview.datamodel.SequenceI;
56 import jalview.io.AlignmentProperties;
57 import jalview.io.AnnotationFile;
58 import jalview.io.FeaturesFile;
59 import jalview.io.FileLoader;
60 import jalview.io.FormatAdapter;
61 import jalview.io.HTMLOutput;
62 import jalview.io.IdentifyFile;
63 import jalview.io.JalviewFileChooser;
64 import jalview.io.JalviewFileView;
65 import jalview.io.JnetAnnotationMaker;
66 import jalview.io.NewickFile;
67 import jalview.io.TCoffeeScoreFile;
68 import jalview.jbgui.GAlignFrame;
69 import jalview.schemes.Blosum62ColourScheme;
70 import jalview.schemes.BuriedColourScheme;
71 import jalview.schemes.ClustalxColourScheme;
72 import jalview.schemes.ColourSchemeI;
73 import jalview.schemes.ColourSchemeProperty;
74 import jalview.schemes.HelixColourScheme;
75 import jalview.schemes.HydrophobicColourScheme;
76 import jalview.schemes.NucleotideColourScheme;
77 import jalview.schemes.PIDColourScheme;
78 import jalview.schemes.PurinePyrimidineColourScheme;
79 import jalview.schemes.RNAHelicesColourChooser;
80 import jalview.schemes.ResidueProperties;
81 import jalview.schemes.StrandColourScheme;
82 import jalview.schemes.TCoffeeColourScheme;
83 import jalview.schemes.TaylorColourScheme;
84 import jalview.schemes.TurnColourScheme;
85 import jalview.schemes.UserColourScheme;
86 import jalview.schemes.ZappoColourScheme;
87 import jalview.structure.StructureSelectionManager;
88 import jalview.util.MapList;
89 import jalview.util.MessageManager;
90 import jalview.ws.jws1.Discoverer;
91 import jalview.ws.jws2.Jws2Discoverer;
92 import jalview.ws.jws2.jabaws2.Jws2Instance;
93 import jalview.ws.seqfetcher.DbSourceProxy;
95 import java.awt.BorderLayout;
96 import java.awt.Component;
97 import java.awt.GridLayout;
98 import java.awt.Rectangle;
99 import java.awt.Toolkit;
100 import java.awt.datatransfer.Clipboard;
101 import java.awt.datatransfer.DataFlavor;
102 import java.awt.datatransfer.StringSelection;
103 import java.awt.datatransfer.Transferable;
104 import java.awt.dnd.DnDConstants;
105 import java.awt.dnd.DropTargetDragEvent;
106 import java.awt.dnd.DropTargetDropEvent;
107 import java.awt.dnd.DropTargetEvent;
108 import java.awt.dnd.DropTargetListener;
109 import java.awt.event.ActionEvent;
110 import java.awt.event.ActionListener;
111 import java.awt.event.KeyAdapter;
112 import java.awt.event.KeyEvent;
113 import java.awt.event.MouseAdapter;
114 import java.awt.event.MouseEvent;
115 import java.awt.print.PageFormat;
116 import java.awt.print.PrinterJob;
117 import java.beans.PropertyChangeEvent;
120 import java.util.ArrayList;
121 import java.util.Arrays;
122 import java.util.Enumeration;
123 import java.util.Hashtable;
124 import java.util.Iterator;
125 import java.util.List;
126 import java.util.Vector;
128 import javax.swing.JButton;
129 import javax.swing.JCheckBoxMenuItem;
130 import javax.swing.JEditorPane;
131 import javax.swing.JInternalFrame;
132 import javax.swing.JLabel;
133 import javax.swing.JLayeredPane;
134 import javax.swing.JMenu;
135 import javax.swing.JMenuItem;
136 import javax.swing.JOptionPane;
137 import javax.swing.JPanel;
138 import javax.swing.JProgressBar;
139 import javax.swing.JRadioButtonMenuItem;
140 import javax.swing.JScrollPane;
141 import javax.swing.SwingUtilities;
147 * @version $Revision$
149 public class AlignFrame extends GAlignFrame implements DropTargetListener,
150 IProgressIndicator, AlignViewControllerGuiI
154 public static final int DEFAULT_WIDTH = 700;
157 public static final int DEFAULT_HEIGHT = 500;
159 public AlignmentPanel alignPanel;
161 AlignViewport viewport;
163 public AlignViewControllerI avc;
165 Vector alignPanels = new Vector();
168 * Last format used to load or save alignments in this window
170 String currentFileFormat = null;
173 * Current filename for this alignment
175 String fileName = null;
178 * Creates a new AlignFrame object with specific width and height.
184 public AlignFrame(AlignmentI al, int width, int height)
186 this(al, null, width, height);
190 * Creates a new AlignFrame object with specific width, height and
196 * @param sequenceSetId
198 public AlignFrame(AlignmentI al, int width, int height,
199 String sequenceSetId)
201 this(al, null, width, height, sequenceSetId);
205 * Creates a new AlignFrame object with specific width, height and
211 * @param sequenceSetId
214 public AlignFrame(AlignmentI al, int width, int height,
215 String sequenceSetId, String viewId)
217 this(al, null, width, height, sequenceSetId, viewId);
221 * new alignment window with hidden columns
225 * @param hiddenColumns
226 * ColumnSelection or null
228 * Width of alignment frame
232 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
233 int width, int height)
235 this(al, hiddenColumns, width, height, null);
239 * Create alignment frame for al with hiddenColumns, a specific width and
240 * height, and specific sequenceId
243 * @param hiddenColumns
246 * @param sequenceSetId
249 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
250 int width, int height, String sequenceSetId)
252 this(al, hiddenColumns, width, height, sequenceSetId, null);
256 * Create alignment frame for al with hiddenColumns, a specific width and
257 * height, and specific sequenceId
260 * @param hiddenColumns
263 * @param sequenceSetId
268 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
269 int width, int height, String sequenceSetId, String viewId)
271 setSize(width, height);
273 if (al.getDataset() == null)
278 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
280 alignPanel = new AlignmentPanel(this, viewport);
283 addAlignmentPanel(alignPanel, true);
288 * Make a new AlignFrame from existing alignmentPanels
295 public AlignFrame(AlignmentPanel ap)
299 addAlignmentPanel(ap, false);
304 * initalise the alignframe from the underlying viewport data and the
309 avc = new jalview.controller.AlignViewController(this, viewport,
311 if (viewport.getAlignmentConservationAnnotation() == null)
313 BLOSUM62Colour.setEnabled(false);
314 conservationMenuItem.setEnabled(false);
315 modifyConservation.setEnabled(false);
316 // PIDColour.setEnabled(false);
317 // abovePIDThreshold.setEnabled(false);
318 // modifyPID.setEnabled(false);
321 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
324 if (sortby.equals("Id"))
326 sortIDMenuItem_actionPerformed(null);
328 else if (sortby.equals("Pairwise Identity"))
330 sortPairwiseMenuItem_actionPerformed(null);
333 if (Desktop.desktop != null)
335 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
336 addServiceListeners();
337 setGUINucleotide(viewport.getAlignment().isNucleotide());
340 setMenusFromViewport(viewport);
341 buildSortByAnnotationScoresMenu();
344 if (viewport.wrapAlignment)
346 wrapMenuItem_actionPerformed(null);
349 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
351 this.overviewMenuItem_actionPerformed(null);
359 * Change the filename and format for the alignment, and enable the 'reload'
360 * button functionality.
367 public void setFileName(String file, String format)
370 currentFileFormat = format;
371 reload.setEnabled(true);
374 void addKeyListener()
376 addKeyListener(new KeyAdapter()
379 public void keyPressed(KeyEvent evt)
381 if (viewport.cursorMode
382 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
383 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
384 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
385 && Character.isDigit(evt.getKeyChar()))
387 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
390 switch (evt.getKeyCode())
393 case 27: // escape key
394 deselectAllSequenceMenuItem_actionPerformed(null);
398 case KeyEvent.VK_DOWN:
399 if (evt.isAltDown() || !viewport.cursorMode)
401 moveSelectedSequences(false);
403 if (viewport.cursorMode)
405 alignPanel.seqPanel.moveCursor(0, 1);
410 if (evt.isAltDown() || !viewport.cursorMode)
412 moveSelectedSequences(true);
414 if (viewport.cursorMode)
416 alignPanel.seqPanel.moveCursor(0, -1);
421 case KeyEvent.VK_LEFT:
422 if (evt.isAltDown() || !viewport.cursorMode)
424 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
428 alignPanel.seqPanel.moveCursor(-1, 0);
433 case KeyEvent.VK_RIGHT:
434 if (evt.isAltDown() || !viewport.cursorMode)
436 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
440 alignPanel.seqPanel.moveCursor(1, 0);
444 case KeyEvent.VK_SPACE:
445 if (viewport.cursorMode)
447 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
448 || evt.isShiftDown() || evt.isAltDown());
452 // case KeyEvent.VK_A:
453 // if (viewport.cursorMode)
455 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
456 // //System.out.println("A");
460 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
461 * System.out.println("closing bracket"); } break;
463 case KeyEvent.VK_DELETE:
464 case KeyEvent.VK_BACK_SPACE:
465 if (!viewport.cursorMode)
467 cut_actionPerformed(null);
471 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
472 || evt.isShiftDown() || evt.isAltDown());
478 if (viewport.cursorMode)
480 alignPanel.seqPanel.setCursorRow();
484 if (viewport.cursorMode && !evt.isControlDown())
486 alignPanel.seqPanel.setCursorColumn();
490 if (viewport.cursorMode)
492 alignPanel.seqPanel.setCursorPosition();
496 case KeyEvent.VK_ENTER:
497 case KeyEvent.VK_COMMA:
498 if (viewport.cursorMode)
500 alignPanel.seqPanel.setCursorRowAndColumn();
505 if (viewport.cursorMode)
507 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
511 if (viewport.cursorMode)
513 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
518 viewport.cursorMode = !viewport.cursorMode;
519 statusBar.setText(MessageManager.formatMessage(
520 "label.keyboard_editing_mode", new String[]
521 { (viewport.cursorMode ? "on" : "off") }));
522 if (viewport.cursorMode)
524 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
525 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
527 alignPanel.seqPanel.seqCanvas.repaint();
533 Help.showHelpWindow();
534 } catch (Exception ex)
536 ex.printStackTrace();
541 boolean toggleSeqs = !evt.isControlDown();
542 boolean toggleCols = !evt.isShiftDown();
543 toggleHiddenRegions(toggleSeqs, toggleCols);
546 case KeyEvent.VK_PAGE_UP:
547 if (viewport.wrapAlignment)
549 alignPanel.scrollUp(true);
553 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
554 - viewport.endSeq + viewport.startSeq);
557 case KeyEvent.VK_PAGE_DOWN:
558 if (viewport.wrapAlignment)
560 alignPanel.scrollUp(false);
564 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
565 + viewport.endSeq - viewport.startSeq);
572 public void keyReleased(KeyEvent evt)
574 switch (evt.getKeyCode())
576 case KeyEvent.VK_LEFT:
577 if (evt.isAltDown() || !viewport.cursorMode)
579 viewport.firePropertyChange("alignment", null, viewport
580 .getAlignment().getSequences());
584 case KeyEvent.VK_RIGHT:
585 if (evt.isAltDown() || !viewport.cursorMode)
587 viewport.firePropertyChange("alignment", null, viewport
588 .getAlignment().getSequences());
596 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
598 ap.alignFrame = this;
599 avc = new jalview.controller.AlignViewController(this, viewport,
602 alignPanels.addElement(ap);
604 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
606 int aSize = alignPanels.size();
608 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
610 if (aSize == 1 && ap.av.viewName == null)
612 this.getContentPane().add(ap, BorderLayout.CENTER);
618 setInitialTabVisible();
621 expandViews.setEnabled(true);
622 gatherViews.setEnabled(true);
623 tabbedPane.addTab(ap.av.viewName, ap);
625 ap.setVisible(false);
630 if (ap.av.isPadGaps())
632 ap.av.getAlignment().padGaps();
634 ap.av.updateConservation(ap);
635 ap.av.updateConsensus(ap);
636 ap.av.updateStrucConsensus(ap);
640 public void setInitialTabVisible()
642 expandViews.setEnabled(true);
643 gatherViews.setEnabled(true);
644 tabbedPane.setVisible(true);
645 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
646 tabbedPane.addTab(first.av.viewName, first);
647 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
650 public AlignViewport getViewport()
655 /* Set up intrinsic listeners for dynamically generated GUI bits. */
656 private void addServiceListeners()
658 final java.beans.PropertyChangeListener thisListener;
659 Desktop.instance.addJalviewPropertyChangeListener("services",
660 thisListener = new java.beans.PropertyChangeListener()
663 public void propertyChange(PropertyChangeEvent evt)
665 // // System.out.println("Discoverer property change.");
666 // if (evt.getPropertyName().equals("services"))
668 SwingUtilities.invokeLater(new Runnable()
675 .println("Rebuild WS Menu for service change");
676 BuildWebServiceMenu();
683 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
686 public void internalFrameClosed(
687 javax.swing.event.InternalFrameEvent evt)
689 System.out.println("deregistering discoverer listener");
690 Desktop.instance.removeJalviewPropertyChangeListener("services",
692 closeMenuItem_actionPerformed(true);
695 // Finally, build the menu once to get current service state
696 new Thread(new Runnable()
701 BuildWebServiceMenu();
706 public void setGUINucleotide(boolean nucleotide)
708 showTranslation.setVisible(nucleotide);
709 cdna.setVisible(!nucleotide);
711 conservationMenuItem.setEnabled(!nucleotide);
712 modifyConservation.setEnabled(!nucleotide);
713 showGroupConservation.setEnabled(!nucleotide);
714 rnahelicesColour.setEnabled(nucleotide);
715 purinePyrimidineColour.setEnabled(nucleotide);
719 * Add any suitable options to the 'cDNA' sub-menu. Options may be to
720 * associate a cDNA alignment, or to align an associated alignment. To be
721 * suitable for association, an AlignFrame has to be nucleotide, and have the
722 * right number of sequences of corresponding length to this one.
724 protected void configureCdnaMenu()
729 * Identify candidates for 'associate cDNA', add to menu.
731 List<AlignFrame> candidates = getCdnaCandidates();
732 for (final AlignFrame candidate : candidates)
734 final String text = MessageManager.getString("label.associate") + " "
735 + candidate.getTitle();
736 JMenuItem option = new JMenuItem(text);
737 option.addActionListener(new ActionListener()
740 public void actionPerformed(ActionEvent e)
742 associateCdna(candidate);
749 * Identify candidates for 'align cDNA', add to menu.
751 final AlignFrame[] alignframes = Desktop.getAlignframes();
752 if (alignframes != null)
754 for (final AlignFrame af : alignframes)
758 if (this.viewport.getStructureSelectionManager()
759 .hasCommandListener(af.viewport))
761 final String text = MessageManager.getString("label.align")
762 + " " + af.getTitle();
763 JMenuItem option = new JMenuItem(text);
764 option.addActionListener(new ActionListener()
767 public void actionPerformed(ActionEvent e)
769 af.alignPanel.getAlignment().alignAs(
770 AlignFrame.this.alignPanel.getAlignment());
771 af.viewport.alignmentChanged(af.alignPanel);
780 cdna.setEnabled(cdna.getMenuComponentCount() > 0);
784 * Returns a list of AlignFrame which are valid candidates for being the cDNA
785 * to map to this (protein) alignment. Valid means a nucleotide alignment with
786 * matching number of sequences and sequence lengths (excluding gaps).
790 protected List<AlignFrame> getCdnaCandidates()
792 List<AlignFrame> result = new ArrayList<AlignFrame>();
793 if (this.alignPanel != null)
795 AlignmentI thisAlignment = this.alignPanel.getAlignment();
796 if (thisAlignment == null || thisAlignment.isNucleotide())
800 final AlignFrame[] alignframes = Desktop.getAlignframes();
801 if (alignframes != null)
803 for (AlignFrame af : alignframes)
805 if (af.alignPanel != null)
807 final AlignmentI thatAlignment = af.alignPanel.getAlignment();
808 if (thatAlignment.isNucleotide()
809 && thisAlignment.isMappableTo(thatAlignment))
811 // TODO exclude an AlignFrame which is already mapped to this one
812 // simple version: exclude if already a CommandListener (should
813 // cover most cases but not all)
814 if (!this.viewport.getStructureSelectionManager()
815 .hasCommandListener(af.viewport))
828 * Build the codon mappings between the given (nucleotide) alignment and this
829 * (protein) alignment. Also make the cDNA alignment a CommandListener for the
830 * protein alignment so that edits are mirrored. The alignments must have the
831 * same number, and equivalent lengths, of (unaligned) sequence.
834 * @throws IllegalStateException
835 * if sequence counts or lengths are incompatible
837 protected void associateCdna(AlignFrame cdna)
840 * Warn that cDNA may be realigned to match protein
842 // int confirm = JOptionPane.showConfirmDialog(
844 // JvSwingUtils.wrapTooltip(true,
845 // MessageManager.getString("warn.cdna_realign")),
846 // MessageManager.getString("label.cdna_realign"),
847 // JOptionPane.OK_CANCEL_OPTION);
848 // if (confirm == JOptionPane.CANCEL_OPTION
849 // || confirm == JOptionPane.CLOSED_OPTION)
854 final AlignmentI aaAlignment = this.alignPanel.getAlignment();
855 Iterator<SequenceI> thisSeqs = aaAlignment
856 .getSequences().iterator();
857 Iterator<SequenceI> cdnaSeqs = cdna.alignPanel.getAlignment()
858 .getSequences().iterator();
859 AlignedCodonFrame acf = new AlignedCodonFrame(aaAlignment.getWidth());
860 while (thisSeqs.hasNext())
862 if (!cdnaSeqs.hasNext())
864 throw new IllegalStateException("Too few sequences to map");
866 final SequenceI aaSeq = thisSeqs.next();
867 String aaSeqString = aaSeq.getDatasetSequence()
868 .getSequenceAsString();
869 final SequenceI cdnaSeq = cdnaSeqs.next();
870 String cdnaSeqString = cdnaSeq.getDatasetSequence()
871 .getSequenceAsString();
872 final int aaLength = aaSeqString.length();
873 final int cdnaLength = cdnaSeqString.length();
874 if (cdnaLength != 3 * aaLength)
876 throw new IllegalStateException(
877 "Protein/cDNA lengths don't match: " + aaLength + "/"
882 * Warn if mapping includes non-standard translations
884 if (!doTranslationWarningCheck(aaSeq.getName(), aaSeqString,
890 MapList map = new MapList(new int[]
891 { 1, cdnaLength }, new int[]
892 { 1, aaLength }, 3, 1);
893 acf.addMap(cdnaSeq, aaSeq, map);
895 aaAlignment.addCodonFrame(acf);
897 final StructureSelectionManager ssm = StructureSelectionManager
898 .getStructureSelectionManager(Desktop.instance);
899 ssm.addMappings(aaAlignment.getCodonFrames());
900 ssm.addCommandListener(cdna.getViewport());
903 * Rebuild 'associate cDna' menu so it now excludes the one just
911 * Show a warning if any non-standard cDNA to protein would result from
912 * mapping the sequences.
917 * @return true if no warning, or it is accepted, false if user chooses not to
920 protected boolean doTranslationWarningCheck(String aaSeqName,
921 String aaSeqString, String cdnaSeqString)
923 final int aaLength = aaSeqString.length();
924 boolean warning = false;
925 String msg = aaSeqName;
926 for (int i = 0; i < aaLength; i++)
928 String codon = cdnaSeqString.substring(i * 3, i * 3 + 3);
929 String aa = ResidueProperties.codonTranslate(codon);
930 if (!(aa.charAt(0) == aaSeqString.charAt(i)))
933 msg += ":" + (i + 1) + ":" + aaSeqString.charAt(i) + "/" + codon
940 final String txt = JvSwingUtils.wrapTooltip(true, MessageManager
941 .formatMessage("warn.nonstandard_translation", msg));
942 int confirm = JOptionPane.showConfirmDialog(this, txt,
943 MessageManager.getString("label.nonstandard_translation"),
944 JOptionPane.OK_CANCEL_OPTION);
945 if (confirm == JOptionPane.CANCEL_OPTION
946 || confirm == JOptionPane.CLOSED_OPTION)
955 * set up menus for the current viewport. This may be called after any
956 * operation that affects the data in the current view (selection changed,
957 * etc) to update the menus to reflect the new state.
959 public void setMenusForViewport()
961 setMenusFromViewport(viewport);
965 * Need to call this method when tabs are selected for multiple views, or when
966 * loading from Jalview2XML.java
971 void setMenusFromViewport(AlignViewport av)
973 padGapsMenuitem.setSelected(av.isPadGaps());
974 colourTextMenuItem.setSelected(av.showColourText);
975 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
976 conservationMenuItem.setSelected(av.getConservationSelected());
977 seqLimits.setSelected(av.getShowJVSuffix());
978 idRightAlign.setSelected(av.rightAlignIds);
979 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
980 renderGapsMenuItem.setSelected(av.renderGaps);
981 wrapMenuItem.setSelected(av.wrapAlignment);
982 scaleAbove.setVisible(av.wrapAlignment);
983 scaleLeft.setVisible(av.wrapAlignment);
984 scaleRight.setVisible(av.wrapAlignment);
985 annotationPanelMenuItem.setState(av.showAnnotation);
987 * Show/hide annotations only enabled if annotation panel is shown
989 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
990 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
991 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
992 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
993 viewBoxesMenuItem.setSelected(av.showBoxes);
994 viewTextMenuItem.setSelected(av.showText);
995 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
996 showGroupConsensus.setSelected(av.isShowGroupConsensus());
997 showGroupConservation.setSelected(av.isShowGroupConservation());
998 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
999 showSequenceLogo.setSelected(av.isShowSequenceLogo());
1000 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
1002 setColourSelected(ColourSchemeProperty.getColourName(av
1003 .getGlobalColourScheme()));
1005 showSeqFeatures.setSelected(av.showSequenceFeatures);
1006 hiddenMarkers.setState(av.showHiddenMarkers);
1007 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
1008 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
1009 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
1010 autoCalculate.setSelected(av.autoCalculateConsensus);
1011 sortByTree.setSelected(av.sortByTree);
1012 listenToViewSelections.setSelected(av.followSelection);
1013 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
1015 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
1016 setShowProductsEnabled();
1017 updateEditMenuBar();
1020 // methods for implementing IProgressIndicator
1021 // need to refactor to a reusable stub class
1022 Hashtable progressBars, progressBarHandlers;
1027 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
1030 public void setProgressBar(String message, long id)
1032 if (progressBars == null)
1034 progressBars = new Hashtable();
1035 progressBarHandlers = new Hashtable();
1038 JPanel progressPanel;
1039 Long lId = new Long(id);
1040 GridLayout layout = (GridLayout) statusPanel.getLayout();
1041 if (progressBars.get(lId) != null)
1043 progressPanel = (JPanel) progressBars.get(new Long(id));
1044 statusPanel.remove(progressPanel);
1045 progressBars.remove(lId);
1046 progressPanel = null;
1047 if (message != null)
1049 statusBar.setText(message);
1051 if (progressBarHandlers.contains(lId))
1053 progressBarHandlers.remove(lId);
1055 layout.setRows(layout.getRows() - 1);
1059 progressPanel = new JPanel(new BorderLayout(10, 5));
1061 JProgressBar progressBar = new JProgressBar();
1062 progressBar.setIndeterminate(true);
1064 progressPanel.add(new JLabel(message), BorderLayout.WEST);
1065 progressPanel.add(progressBar, BorderLayout.CENTER);
1067 layout.setRows(layout.getRows() + 1);
1068 statusPanel.add(progressPanel);
1070 progressBars.put(lId, progressPanel);
1073 // setMenusForViewport();
1078 public void registerHandler(final long id,
1079 final IProgressIndicatorHandler handler)
1081 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
1083 throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler"));
1085 progressBarHandlers.put(new Long(id), handler);
1086 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
1087 if (handler.canCancel())
1089 JButton cancel = new JButton(
1090 MessageManager.getString("action.cancel"));
1091 final IProgressIndicator us = this;
1092 cancel.addActionListener(new ActionListener()
1096 public void actionPerformed(ActionEvent e)
1098 handler.cancelActivity(id);
1099 us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new String[]{((JLabel) progressPanel.getComponent(0)).getText()}), id);
1102 progressPanel.add(cancel, BorderLayout.EAST);
1108 * @return true if any progress bars are still active
1111 public boolean operationInProgress()
1113 if (progressBars != null && progressBars.size() > 0)
1121 public void setStatus(String text)
1123 statusBar.setText(text);
1127 * Added so Castor Mapping file can obtain Jalview Version
1129 public String getVersion()
1131 return jalview.bin.Cache.getProperty("VERSION");
1134 public FeatureRenderer getFeatureRenderer()
1136 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
1140 public void fetchSequence_actionPerformed(ActionEvent e)
1142 new SequenceFetcher(this);
1146 public void addFromFile_actionPerformed(ActionEvent e)
1148 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1152 public void reload_actionPerformed(ActionEvent e)
1154 if (fileName != null)
1156 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1157 // originating file's format
1158 // TODO: work out how to recover feature settings for correct view(s) when
1159 // file is reloaded.
1160 if (currentFileFormat.equals("Jalview"))
1162 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1163 for (int i = 0; i < frames.length; i++)
1165 if (frames[i] instanceof AlignFrame && frames[i] != this
1166 && ((AlignFrame) frames[i]).fileName != null
1167 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1171 frames[i].setSelected(true);
1172 Desktop.instance.closeAssociatedWindows();
1173 } catch (java.beans.PropertyVetoException ex)
1179 Desktop.instance.closeAssociatedWindows();
1181 FileLoader loader = new FileLoader();
1182 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1183 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1187 Rectangle bounds = this.getBounds();
1189 FileLoader loader = new FileLoader();
1190 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1191 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1192 protocol, currentFileFormat);
1194 newframe.setBounds(bounds);
1195 if (featureSettings != null && featureSettings.isShowing())
1197 final Rectangle fspos = featureSettings.frame.getBounds();
1198 // TODO: need a 'show feature settings' function that takes bounds -
1199 // need to refactor Desktop.addFrame
1200 newframe.featureSettings_actionPerformed(null);
1201 final FeatureSettings nfs = newframe.featureSettings;
1202 SwingUtilities.invokeLater(new Runnable()
1207 nfs.frame.setBounds(fspos);
1210 this.featureSettings.close();
1211 this.featureSettings = null;
1213 this.closeMenuItem_actionPerformed(true);
1219 public void addFromText_actionPerformed(ActionEvent e)
1221 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
1225 public void addFromURL_actionPerformed(ActionEvent e)
1227 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1231 public void save_actionPerformed(ActionEvent e)
1233 if (fileName == null
1234 || (currentFileFormat == null || !jalview.io.FormatAdapter
1235 .isValidIOFormat(currentFileFormat, true))
1236 || fileName.startsWith("http"))
1238 saveAs_actionPerformed(null);
1242 saveAlignment(fileName, currentFileFormat);
1253 public void saveAs_actionPerformed(ActionEvent e)
1255 JalviewFileChooser chooser = new JalviewFileChooser(
1256 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1257 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1258 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1259 currentFileFormat, false);
1261 chooser.setFileView(new JalviewFileView());
1262 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1263 chooser.setToolTipText(MessageManager.getString("action.save"));
1265 int value = chooser.showSaveDialog(this);
1267 if (value == JalviewFileChooser.APPROVE_OPTION)
1269 currentFileFormat = chooser.getSelectedFormat();
1270 if (currentFileFormat == null)
1273 .showInternalMessageDialog(
1276 .getString("label.select_file_format_before_saving"),
1278 .getString("label.file_format_not_specified"),
1279 JOptionPane.WARNING_MESSAGE);
1280 value = chooser.showSaveDialog(this);
1284 fileName = chooser.getSelectedFile().getPath();
1286 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1289 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1290 if (currentFileFormat.indexOf(" ") > -1)
1292 currentFileFormat = currentFileFormat.substring(0,
1293 currentFileFormat.indexOf(" "));
1295 saveAlignment(fileName, currentFileFormat);
1299 public boolean saveAlignment(String file, String format)
1301 boolean success = true;
1303 if (format.equalsIgnoreCase("Jalview"))
1305 String shortName = title;
1307 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1309 shortName = shortName.substring(shortName
1310 .lastIndexOf(java.io.File.separatorChar) + 1);
1313 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1315 statusBar.setText(MessageManager.formatMessage(
1316 "label.successfully_saved_to_file_in_format", new String[]
1317 { fileName, format }));
1322 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1324 warningMessage("Cannot save file " + fileName + " using format "
1325 + format, "Alignment output format not supported");
1326 saveAs_actionPerformed(null);
1327 // JBPNote need to have a raise_gui flag here
1331 String[] omitHidden = null;
1333 if (viewport.hasHiddenColumns())
1335 int reply = JOptionPane
1336 .showInternalConfirmDialog(
1339 .getString("label.alignment_contains_hidden_columns"),
1341 .getString("action.save_omit_hidden_columns"),
1342 JOptionPane.YES_NO_OPTION,
1343 JOptionPane.QUESTION_MESSAGE);
1345 if (reply == JOptionPane.YES_OPTION)
1347 omitHidden = viewport.getViewAsString(false);
1350 FormatAdapter f = new FormatAdapter();
1351 String output = f.formatSequences(format,
1352 viewport.getAlignment(), // class cast exceptions will
1353 // occur in the distant future
1354 omitHidden, f.getCacheSuffixDefault(format),
1355 viewport.getColumnSelection());
1365 java.io.PrintWriter out = new java.io.PrintWriter(
1366 new java.io.FileWriter(file));
1370 this.setTitle(file);
1371 statusBar.setText(MessageManager.formatMessage(
1372 "label.successfully_saved_to_file_in_format",
1374 { fileName, format }));
1375 } catch (Exception ex)
1378 ex.printStackTrace();
1385 JOptionPane.showInternalMessageDialog(this, MessageManager
1386 .formatMessage("label.couldnt_save_file", new String[]
1387 { fileName }), MessageManager
1388 .getString("label.error_saving_file"),
1389 JOptionPane.WARNING_MESSAGE);
1395 private void warningMessage(String warning, String title)
1397 if (new jalview.util.Platform().isHeadless())
1399 System.err.println("Warning: " + title + "\nWarning: " + warning);
1404 JOptionPane.showInternalMessageDialog(this, warning, title,
1405 JOptionPane.WARNING_MESSAGE);
1417 protected void outputText_actionPerformed(ActionEvent e)
1419 String[] omitHidden = null;
1421 if (viewport.hasHiddenColumns())
1423 int reply = JOptionPane
1424 .showInternalConfirmDialog(
1427 .getString("label.alignment_contains_hidden_columns"),
1429 .getString("action.save_omit_hidden_columns"),
1430 JOptionPane.YES_NO_OPTION,
1431 JOptionPane.QUESTION_MESSAGE);
1433 if (reply == JOptionPane.YES_OPTION)
1435 omitHidden = viewport.getViewAsString(false);
1439 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1440 cap.setForInput(null);
1444 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1445 viewport.getAlignment(), omitHidden,
1446 viewport.getColumnSelection()));
1447 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1448 "label.alignment_output_command", new String[]
1449 { e.getActionCommand() }), 600, 500);
1450 } catch (OutOfMemoryError oom)
1452 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1465 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1467 new HTMLOutput(alignPanel,
1468 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1469 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1472 public void createImageMap(File file, String image)
1474 alignPanel.makePNGImageMap(file, image);
1484 public void createPNG(File f)
1486 alignPanel.makePNG(f);
1496 public void createEPS(File f)
1498 alignPanel.makeEPS(f);
1501 public void createSVG(File f)
1503 alignPanel.makeSVG(f);
1506 public void pageSetup_actionPerformed(ActionEvent e)
1508 PrinterJob printJob = PrinterJob.getPrinterJob();
1509 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1519 public void printMenuItem_actionPerformed(ActionEvent e)
1521 // Putting in a thread avoids Swing painting problems
1522 PrintThread thread = new PrintThread(alignPanel);
1527 public void exportFeatures_actionPerformed(ActionEvent e)
1529 new AnnotationExporter().exportFeatures(alignPanel);
1533 public void exportAnnotations_actionPerformed(ActionEvent e)
1535 new AnnotationExporter().exportAnnotations(alignPanel,
1536 viewport.showAnnotation ? viewport.getAlignment()
1537 .getAlignmentAnnotation() : null, viewport
1538 .getAlignment().getGroups(), ((Alignment) viewport
1539 .getAlignment()).alignmentProperties);
1543 public void associatedData_actionPerformed(ActionEvent e)
1545 // Pick the tree file
1546 JalviewFileChooser chooser = new JalviewFileChooser(
1547 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1548 chooser.setFileView(new JalviewFileView());
1549 chooser.setDialogTitle(MessageManager
1550 .getString("label.load_jalview_annotations"));
1551 chooser.setToolTipText(MessageManager
1552 .getString("label.load_jalview_annotations"));
1554 int value = chooser.showOpenDialog(null);
1556 if (value == JalviewFileChooser.APPROVE_OPTION)
1558 String choice = chooser.getSelectedFile().getPath();
1559 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1560 loadJalviewDataFile(choice, null, null, null);
1566 * Close the current view or all views in the alignment frame. If the frame
1567 * only contains one view then the alignment will be removed from memory.
1569 * @param closeAllTabs
1572 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1574 if (alignPanels != null && alignPanels.size() < 2)
1576 closeAllTabs = true;
1581 if (alignPanels != null)
1585 if (this.isClosed())
1587 // really close all the windows - otherwise wait till
1588 // setClosed(true) is called
1589 for (int i = 0; i < alignPanels.size(); i++)
1591 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1598 closeView(alignPanel);
1604 this.setClosed(true);
1606 } catch (Exception ex)
1608 ex.printStackTrace();
1613 * close alignPanel2 and shuffle tabs appropriately.
1615 * @param alignPanel2
1617 public void closeView(AlignmentPanel alignPanel2)
1619 int index = tabbedPane.getSelectedIndex();
1620 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1621 alignPanels.removeElement(alignPanel2);
1623 // if (viewport == alignPanel2.av)
1627 alignPanel2.closePanel();
1630 tabbedPane.removeTabAt(closedindex);
1631 tabbedPane.validate();
1633 if (index > closedindex || index == tabbedPane.getTabCount())
1635 // modify currently selected tab index if necessary.
1639 this.tabSelectionChanged(index);
1645 void updateEditMenuBar()
1648 if (viewport.getHistoryList().size() > 0)
1650 undoMenuItem.setEnabled(true);
1651 CommandI command = viewport.getHistoryList().peek();
1652 undoMenuItem.setText(MessageManager.formatMessage(
1653 "label.undo_command", new String[]
1654 { command.getDescription() }));
1658 undoMenuItem.setEnabled(false);
1659 undoMenuItem.setText(MessageManager.getString("action.undo"));
1662 if (viewport.getRedoList().size() > 0)
1664 redoMenuItem.setEnabled(true);
1666 CommandI command = viewport.getRedoList().peek();
1667 redoMenuItem.setText(MessageManager.formatMessage(
1668 "label.redo_command", new String[]
1669 { command.getDescription() }));
1673 redoMenuItem.setEnabled(false);
1674 redoMenuItem.setText(MessageManager.getString("action.redo"));
1678 public void addHistoryItem(CommandI command)
1680 if (command.getSize() > 0)
1682 viewport.addToHistoryList(command);
1683 viewport.clearRedoList();
1684 updateEditMenuBar();
1685 viewport.updateHiddenColumns();
1686 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1687 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1688 // viewport.getColumnSelection()
1689 // .getHiddenColumns().size() > 0);
1695 * @return alignment objects for all views
1697 AlignmentI[] getViewAlignments()
1699 if (alignPanels != null)
1701 Enumeration e = alignPanels.elements();
1702 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1703 for (int i = 0; e.hasMoreElements(); i++)
1705 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1709 if (viewport != null)
1711 return new AlignmentI[]
1712 { viewport.getAlignment() };
1724 protected void undoMenuItem_actionPerformed(ActionEvent e)
1726 if (viewport.getHistoryList().isEmpty())
1730 CommandI command = viewport.getHistoryList().pop();
1731 viewport.addToRedoList(command);
1732 // TODO: execute command before adding to redo list / broadcasting?
1733 command.undoCommand(getViewAlignments());
1735 AlignViewport originalSource = getOriginatingSource(command);
1736 updateEditMenuBar();
1738 if (originalSource != null)
1740 if (originalSource != viewport)
1743 .warn("Implementation worry: mismatch of viewport origin for undo");
1745 originalSource.updateHiddenColumns();
1746 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1748 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1749 // viewport.getColumnSelection()
1750 // .getHiddenColumns().size() > 0);
1751 originalSource.firePropertyChange("alignment", null, originalSource
1752 .getAlignment().getSequences());
1763 protected void redoMenuItem_actionPerformed(ActionEvent e)
1765 if (viewport.getRedoList().size() < 1)
1770 CommandI command = viewport.getRedoList().pop();
1771 viewport.addToHistoryList(command);
1772 command.doCommand(getViewAlignments());
1774 AlignViewport originalSource = getOriginatingSource(command);
1775 updateEditMenuBar();
1777 if (originalSource != null)
1780 if (originalSource != viewport)
1783 .warn("Implementation worry: mismatch of viewport origin for redo");
1785 originalSource.updateHiddenColumns();
1786 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1788 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1789 // viewport.getColumnSelection()
1790 // .getHiddenColumns().size() > 0);
1791 originalSource.firePropertyChange("alignment", null, originalSource
1792 .getAlignment().getSequences());
1796 AlignViewport getOriginatingSource(CommandI command)
1798 AlignViewport originalSource = null;
1799 // For sequence removal and addition, we need to fire
1800 // the property change event FROM the viewport where the
1801 // original alignment was altered
1802 AlignmentI al = null;
1803 if (command instanceof EditCommand)
1805 EditCommand editCommand = (EditCommand) command;
1806 al = editCommand.getAlignment();
1807 Vector comps = (Vector) PaintRefresher.components.get(viewport
1808 .getSequenceSetId());
1810 for (int i = 0; i < comps.size(); i++)
1812 if (comps.elementAt(i) instanceof AlignmentPanel)
1814 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1816 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1823 if (originalSource == null)
1825 // The original view is closed, we must validate
1826 // the current view against the closed view first
1829 PaintRefresher.validateSequences(al, viewport.getAlignment());
1832 originalSource = viewport;
1835 return originalSource;
1844 public void moveSelectedSequences(boolean up)
1846 SequenceGroup sg = viewport.getSelectionGroup();
1852 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1853 viewport.getHiddenRepSequences(), up);
1854 alignPanel.paintAlignment(true);
1857 synchronized void slideSequences(boolean right, int size)
1859 List<SequenceI> sg = new Vector();
1860 if (viewport.cursorMode)
1862 sg.add(viewport.getAlignment().getSequenceAt(
1863 alignPanel.seqPanel.seqCanvas.cursorY));
1865 else if (viewport.getSelectionGroup() != null
1866 && viewport.getSelectionGroup().getSize() != viewport
1867 .getAlignment().getHeight())
1869 sg = viewport.getSelectionGroup().getSequences(
1870 viewport.getHiddenRepSequences());
1878 Vector invertGroup = new Vector();
1880 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1882 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1884 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1888 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1890 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1891 for (int i = 0; i < invertGroup.size(); i++)
1893 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1896 SlideSequencesCommand ssc;
1899 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1900 size, viewport.getGapCharacter());
1904 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1905 size, viewport.getGapCharacter());
1908 int groupAdjustment = 0;
1909 if (ssc.getGapsInsertedBegin() && right)
1911 if (viewport.cursorMode)
1913 alignPanel.seqPanel.moveCursor(size, 0);
1917 groupAdjustment = size;
1920 else if (!ssc.getGapsInsertedBegin() && !right)
1922 if (viewport.cursorMode)
1924 alignPanel.seqPanel.moveCursor(-size, 0);
1928 groupAdjustment = -size;
1932 if (groupAdjustment != 0)
1934 viewport.getSelectionGroup().setStartRes(
1935 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1936 viewport.getSelectionGroup().setEndRes(
1937 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1940 boolean appendHistoryItem = false;
1941 if (viewport.getHistoryList() != null
1942 && viewport.getHistoryList().size() > 0
1943 && viewport.getHistoryList().peek() instanceof SlideSequencesCommand)
1945 appendHistoryItem = ssc
1946 .appendSlideCommand((SlideSequencesCommand) viewport
1951 if (!appendHistoryItem)
1953 addHistoryItem(ssc);
1966 protected void copy_actionPerformed(ActionEvent e)
1969 if (viewport.getSelectionGroup() == null)
1973 // TODO: preserve the ordering of displayed alignment annotation in any
1974 // internal paste (particularly sequence associated annotation)
1975 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1976 String[] omitHidden = null;
1978 if (viewport.hasHiddenColumns())
1980 omitHidden = viewport.getViewAsString(true);
1983 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1986 StringSelection ss = new StringSelection(output);
1990 jalview.gui.Desktop.internalCopy = true;
1991 // Its really worth setting the clipboard contents
1992 // to empty before setting the large StringSelection!!
1993 Toolkit.getDefaultToolkit().getSystemClipboard()
1994 .setContents(new StringSelection(""), null);
1996 Toolkit.getDefaultToolkit().getSystemClipboard()
1997 .setContents(ss, Desktop.instance);
1998 } catch (OutOfMemoryError er)
2000 new OOMWarning("copying region", er);
2004 Vector hiddenColumns = null;
2005 if (viewport.hasHiddenColumns())
2007 hiddenColumns = new Vector();
2008 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
2009 .getSelectionGroup().getEndRes();
2010 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
2013 int[] region = (int[]) viewport.getColumnSelection()
2014 .getHiddenColumns().elementAt(i);
2015 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
2017 hiddenColumns.addElement(new int[]
2018 { region[0] - hiddenOffset, region[1] - hiddenOffset });
2023 Desktop.jalviewClipboard = new Object[]
2024 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
2025 statusBar.setText(MessageManager.formatMessage(
2026 "label.copied_sequences_to_clipboard", new String[]
2027 { Integer.valueOf(seqs.length).toString() }));
2037 protected void pasteNew_actionPerformed(ActionEvent e)
2049 protected void pasteThis_actionPerformed(ActionEvent e)
2055 * Paste contents of Jalview clipboard
2057 * @param newAlignment
2058 * true to paste to a new alignment, otherwise add to this.
2060 void paste(boolean newAlignment)
2062 boolean externalPaste = true;
2065 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2066 Transferable contents = c.getContents(this);
2068 if (contents == null)
2076 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2077 if (str.length() < 1)
2082 format = new IdentifyFile().Identify(str, "Paste");
2084 } catch (OutOfMemoryError er)
2086 new OOMWarning("Out of memory pasting sequences!!", er);
2090 SequenceI[] sequences;
2091 boolean annotationAdded = false;
2092 AlignmentI alignment = null;
2094 if (Desktop.jalviewClipboard != null)
2096 // The clipboard was filled from within Jalview, we must use the
2098 // And dataset from the copied alignment
2099 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2100 // be doubly sure that we create *new* sequence objects.
2101 sequences = new SequenceI[newseq.length];
2102 for (int i = 0; i < newseq.length; i++)
2104 sequences[i] = new Sequence(newseq[i]);
2106 alignment = new Alignment(sequences);
2107 externalPaste = false;
2111 // parse the clipboard as an alignment.
2112 alignment = new FormatAdapter().readFile(str, "Paste", format);
2113 sequences = alignment.getSequencesArray();
2117 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2123 if (Desktop.jalviewClipboard != null)
2125 // dataset is inherited
2126 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2130 // new dataset is constructed
2131 alignment.setDataset(null);
2133 alwidth = alignment.getWidth() + 1;
2137 AlignmentI pastedal = alignment; // preserve pasted alignment object
2138 // Add pasted sequences and dataset into existing alignment.
2139 alignment = viewport.getAlignment();
2140 alwidth = alignment.getWidth() + 1;
2141 // decide if we need to import sequences from an existing dataset
2142 boolean importDs = Desktop.jalviewClipboard != null
2143 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2144 // importDs==true instructs us to copy over new dataset sequences from
2145 // an existing alignment
2146 Vector newDs = (importDs) ? new Vector() : null; // used to create
2147 // minimum dataset set
2149 for (int i = 0; i < sequences.length; i++)
2153 newDs.addElement(null);
2155 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2157 if (importDs && ds != null)
2159 if (!newDs.contains(ds))
2161 newDs.setElementAt(ds, i);
2162 ds = new Sequence(ds);
2163 // update with new dataset sequence
2164 sequences[i].setDatasetSequence(ds);
2168 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2173 // copy and derive new dataset sequence
2174 sequences[i] = sequences[i].deriveSequence();
2175 alignment.getDataset().addSequence(
2176 sequences[i].getDatasetSequence());
2177 // TODO: avoid creation of duplicate dataset sequences with a
2178 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2180 alignment.addSequence(sequences[i]); // merges dataset
2184 newDs.clear(); // tidy up
2186 if (alignment.getAlignmentAnnotation() != null)
2188 for (AlignmentAnnotation alan : alignment
2189 .getAlignmentAnnotation())
2191 if (alan.graphGroup > fgroup)
2193 fgroup = alan.graphGroup;
2197 if (pastedal.getAlignmentAnnotation() != null)
2199 // Add any annotation attached to alignment.
2200 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2201 for (int i = 0; i < alann.length; i++)
2203 annotationAdded = true;
2204 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2206 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2207 if (newann.graphGroup > -1)
2209 if (newGraphGroups.size() <= newann.graphGroup
2210 || newGraphGroups.get(newann.graphGroup) == null)
2212 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2214 newGraphGroups.add(q, null);
2216 newGraphGroups.set(newann.graphGroup, new Integer(
2219 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2223 newann.padAnnotation(alwidth);
2224 alignment.addAnnotation(newann);
2234 addHistoryItem(new EditCommand(
2235 MessageManager.getString("label.add_sequences"),
2237 sequences, 0, alignment.getWidth(), alignment));
2239 // Add any annotations attached to sequences
2240 for (int i = 0; i < sequences.length; i++)
2242 if (sequences[i].getAnnotation() != null)
2244 AlignmentAnnotation newann;
2245 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2247 annotationAdded = true;
2248 newann = sequences[i].getAnnotation()[a];
2249 newann.adjustForAlignment();
2250 newann.padAnnotation(alwidth);
2251 if (newann.graphGroup > -1)
2253 if (newann.graphGroup > -1)
2255 if (newGraphGroups.size() <= newann.graphGroup
2256 || newGraphGroups.get(newann.graphGroup) == null)
2258 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2260 newGraphGroups.add(q, null);
2262 newGraphGroups.set(newann.graphGroup, new Integer(
2265 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2269 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2274 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2281 // propagate alignment changed.
2282 viewport.setEndSeq(alignment.getHeight());
2283 if (annotationAdded)
2285 // Duplicate sequence annotation in all views.
2286 AlignmentI[] alview = this.getViewAlignments();
2287 for (int i = 0; i < sequences.length; i++)
2289 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2294 for (int avnum = 0; avnum < alview.length; avnum++)
2296 if (alview[avnum] != alignment)
2298 // duplicate in a view other than the one with input focus
2299 int avwidth = alview[avnum].getWidth() + 1;
2300 // this relies on sann being preserved after we
2301 // modify the sequence's annotation array for each duplication
2302 for (int a = 0; a < sann.length; a++)
2304 AlignmentAnnotation newann = new AlignmentAnnotation(
2306 sequences[i].addAlignmentAnnotation(newann);
2307 newann.padAnnotation(avwidth);
2308 alview[avnum].addAnnotation(newann); // annotation was
2309 // duplicated earlier
2310 // TODO JAL-1145 graphGroups are not updated for sequence
2311 // annotation added to several views. This may cause
2313 alview[avnum].setAnnotationIndex(newann, a);
2318 buildSortByAnnotationScoresMenu();
2320 viewport.firePropertyChange("alignment", null,
2321 alignment.getSequences());
2322 if (alignPanels != null)
2324 for (AlignmentPanel ap : ((Vector<AlignmentPanel>) alignPanels))
2326 ap.validateAnnotationDimensions(false);
2331 alignPanel.validateAnnotationDimensions(false);
2337 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2339 String newtitle = new String("Copied sequences");
2341 if (Desktop.jalviewClipboard != null
2342 && Desktop.jalviewClipboard[2] != null)
2344 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2345 for (int i = 0; i < hc.size(); i++)
2347 int[] region = (int[]) hc.elementAt(i);
2348 af.viewport.hideColumns(region[0], region[1]);
2352 // >>>This is a fix for the moment, until a better solution is
2354 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2356 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2358 // TODO: maintain provenance of an alignment, rather than just make the
2359 // title a concatenation of operations.
2362 if (title.startsWith("Copied sequences"))
2368 newtitle = newtitle.concat("- from " + title);
2373 newtitle = new String("Pasted sequences");
2376 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2381 } catch (Exception ex)
2383 ex.printStackTrace();
2384 System.out.println("Exception whilst pasting: " + ex);
2385 // could be anything being pasted in here
2391 protected void expand_newalign(ActionEvent e)
2395 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2396 .getAlignment(), -1);
2397 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2399 String newtitle = new String("Flanking alignment");
2401 if (Desktop.jalviewClipboard != null
2402 && Desktop.jalviewClipboard[2] != null)
2404 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2405 for (int i = 0; i < hc.size(); i++)
2407 int[] region = (int[]) hc.elementAt(i);
2408 af.viewport.hideColumns(region[0], region[1]);
2412 // >>>This is a fix for the moment, until a better solution is
2414 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2416 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2418 // TODO: maintain provenance of an alignment, rather than just make the
2419 // title a concatenation of operations.
2421 if (title.startsWith("Copied sequences"))
2427 newtitle = newtitle.concat("- from " + title);
2431 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2433 } catch (Exception ex)
2435 ex.printStackTrace();
2436 System.out.println("Exception whilst pasting: " + ex);
2437 // could be anything being pasted in here
2438 } catch (OutOfMemoryError oom)
2440 new OOMWarning("Viewing flanking region of alignment", oom);
2451 protected void cut_actionPerformed(ActionEvent e)
2453 copy_actionPerformed(null);
2454 delete_actionPerformed(null);
2464 protected void delete_actionPerformed(ActionEvent evt)
2467 SequenceGroup sg = viewport.getSelectionGroup();
2473 List<SequenceI> seqs = new ArrayList<SequenceI>(sg.getSize());
2475 for (int i = 0; i < sg.getSize(); i++)
2477 seq = sg.getSequenceAt(i);
2481 // If the cut affects all sequences, warn, remove highlighted columns
2482 if (sg.getSize() == viewport.getAlignment().getHeight())
2484 int confirm = JOptionPane.showConfirmDialog(this,
2485 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2486 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2487 JOptionPane.OK_CANCEL_OPTION);
2489 if (confirm == JOptionPane.CANCEL_OPTION
2490 || confirm == JOptionPane.CLOSED_OPTION)
2494 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2495 sg.getEndRes() + 1);
2498 SequenceI[] cut = new SequenceI[seqs.size()];
2499 for (int i = 0; i < seqs.size(); i++)
2501 cut[i] = seqs.get(i);
2505 * //ADD HISTORY ITEM
2507 addHistoryItem(new EditCommand(
2508 MessageManager.getString("label.cut_sequences"), Action.CUT,
2509 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2510 viewport.getAlignment()));
2512 viewport.setSelectionGroup(null);
2513 viewport.sendSelection();
2514 viewport.getAlignment().deleteGroup(sg);
2516 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2518 if (viewport.getAlignment().getHeight() < 1)
2522 this.setClosed(true);
2523 } catch (Exception ex)
2536 protected void deleteGroups_actionPerformed(ActionEvent e)
2538 if (avc.deleteGroups())
2540 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2541 alignPanel.updateAnnotation();
2542 alignPanel.paintAlignment(true);
2553 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2555 SequenceGroup sg = new SequenceGroup();
2557 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2559 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2562 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2563 viewport.setSelectionGroup(sg);
2564 viewport.sendSelection();
2565 alignPanel.paintAlignment(true);
2566 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2576 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2578 if (viewport.cursorMode)
2580 alignPanel.seqPanel.keyboardNo1 = null;
2581 alignPanel.seqPanel.keyboardNo2 = null;
2583 viewport.setSelectionGroup(null);
2584 viewport.getColumnSelection().clear();
2585 viewport.setSelectionGroup(null);
2586 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2587 alignPanel.idPanel.idCanvas.searchResults = null;
2588 alignPanel.paintAlignment(true);
2589 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2590 viewport.sendSelection();
2600 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2602 SequenceGroup sg = viewport.getSelectionGroup();
2606 selectAllSequenceMenuItem_actionPerformed(null);
2611 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2613 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2616 alignPanel.paintAlignment(true);
2617 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2618 viewport.sendSelection();
2622 public void invertColSel_actionPerformed(ActionEvent e)
2624 viewport.invertColumnSelection();
2625 alignPanel.paintAlignment(true);
2626 viewport.sendSelection();
2636 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2638 trimAlignment(true);
2648 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2650 trimAlignment(false);
2653 void trimAlignment(boolean trimLeft)
2655 ColumnSelection colSel = viewport.getColumnSelection();
2658 if (colSel.size() > 0)
2662 column = colSel.getMin();
2666 column = colSel.getMax();
2670 if (viewport.getSelectionGroup() != null)
2672 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2673 viewport.getHiddenRepSequences());
2677 seqs = viewport.getAlignment().getSequencesArray();
2680 TrimRegionCommand trimRegion;
2683 trimRegion = new TrimRegionCommand("Remove Left",
2684 TrimRegionCommand.TRIM_LEFT, seqs, column,
2685 viewport.getAlignment(), viewport.getColumnSelection(),
2686 viewport.getSelectionGroup());
2687 viewport.setStartRes(0);
2691 trimRegion = new TrimRegionCommand("Remove Right",
2692 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2693 viewport.getAlignment(), viewport.getColumnSelection(),
2694 viewport.getSelectionGroup());
2697 statusBar.setText(MessageManager.formatMessage(
2698 "label.removed_columns", new String[]
2699 { Integer.valueOf(trimRegion.getSize()).toString() }));
2701 addHistoryItem(trimRegion);
2703 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2705 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2706 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2708 viewport.getAlignment().deleteGroup(sg);
2712 viewport.firePropertyChange("alignment", null, viewport
2713 .getAlignment().getSequences());
2724 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2726 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2729 if (viewport.getSelectionGroup() != null)
2731 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2732 viewport.getHiddenRepSequences());
2733 start = viewport.getSelectionGroup().getStartRes();
2734 end = viewport.getSelectionGroup().getEndRes();
2738 seqs = viewport.getAlignment().getSequencesArray();
2741 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2742 "Remove Gapped Columns", seqs, start, end,
2743 viewport.getAlignment());
2745 addHistoryItem(removeGapCols);
2747 statusBar.setText(MessageManager.formatMessage(
2748 "label.removed_empty_columns", new String[]
2749 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2751 // This is to maintain viewport position on first residue
2752 // of first sequence
2753 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2754 int startRes = seq.findPosition(viewport.startRes);
2755 // ShiftList shifts;
2756 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2757 // edit.alColumnChanges=shifts.getInverse();
2758 // if (viewport.hasHiddenColumns)
2759 // viewport.getColumnSelection().compensateForEdits(shifts);
2760 viewport.setStartRes(seq.findIndex(startRes) - 1);
2761 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2773 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2775 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2778 if (viewport.getSelectionGroup() != null)
2780 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2781 viewport.getHiddenRepSequences());
2782 start = viewport.getSelectionGroup().getStartRes();
2783 end = viewport.getSelectionGroup().getEndRes();
2787 seqs = viewport.getAlignment().getSequencesArray();
2790 // This is to maintain viewport position on first residue
2791 // of first sequence
2792 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2793 int startRes = seq.findPosition(viewport.startRes);
2795 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2796 viewport.getAlignment()));
2798 viewport.setStartRes(seq.findIndex(startRes) - 1);
2800 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2812 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2814 viewport.setPadGaps(padGapsMenuitem.isSelected());
2815 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2821 // if (justifySeqs>0)
2823 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2836 public void findMenuItem_actionPerformed(ActionEvent e)
2842 * Create a new view of the current alignment.
2845 public void newView_actionPerformed(ActionEvent e)
2852 * @param copyAnnotation
2853 * if true then duplicate all annnotation, groups and settings
2854 * @return new alignment panel, already displayed.
2856 public AlignmentPanel newView(boolean copyAnnotation)
2858 return newView(null, copyAnnotation);
2864 * title of newly created view
2865 * @return new alignment panel, already displayed.
2867 public AlignmentPanel newView(String viewTitle)
2869 return newView(viewTitle, true);
2875 * title of newly created view
2876 * @param copyAnnotation
2877 * if true then duplicate all annnotation, groups and settings
2878 * @return new alignment panel, already displayed.
2880 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2882 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2884 if (!copyAnnotation)
2886 // just remove all the current annotation except for the automatic stuff
2887 newap.av.getAlignment().deleteAllGroups();
2888 for (AlignmentAnnotation alan : newap.av.getAlignment()
2889 .getAlignmentAnnotation())
2891 if (!alan.autoCalculated)
2893 newap.av.getAlignment().deleteAnnotation(alan);
2899 newap.av.gatherViewsHere = false;
2901 if (viewport.viewName == null)
2903 viewport.viewName = "Original";
2906 newap.av.setHistoryList(viewport.getHistoryList());
2907 newap.av.setRedoList(viewport.getRedoList());
2909 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2910 // make sure the new view has a unique name - this is essential for Jalview
2912 boolean addFirstIndex = false;
2913 if (viewTitle == null || viewTitle.trim().length() == 0)
2915 viewTitle = MessageManager.getString("action.view");
2916 addFirstIndex = true;
2920 index = 1;// we count from 1 if given a specific name
2922 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2923 Vector comps = (Vector) PaintRefresher.components.get(viewport
2924 .getSequenceSetId());
2925 Vector existingNames = new Vector();
2926 for (int i = 0; i < comps.size(); i++)
2928 if (comps.elementAt(i) instanceof AlignmentPanel)
2930 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2931 if (!existingNames.contains(ap.av.viewName))
2933 existingNames.addElement(ap.av.viewName);
2938 while (existingNames.contains(newViewName))
2940 newViewName = viewTitle + " " + (++index);
2943 newap.av.viewName = newViewName;
2945 addAlignmentPanel(newap, true);
2946 newap.alignmentChanged();
2948 if (alignPanels.size() == 2)
2950 viewport.gatherViewsHere = true;
2952 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2957 public void expandViews_actionPerformed(ActionEvent e)
2959 Desktop.instance.explodeViews(this);
2963 public void gatherViews_actionPerformed(ActionEvent e)
2965 Desktop.instance.gatherViews(this);
2975 public void font_actionPerformed(ActionEvent e)
2977 new FontChooser(alignPanel);
2987 protected void seqLimit_actionPerformed(ActionEvent e)
2989 viewport.setShowJVSuffix(seqLimits.isSelected());
2991 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2992 .calculateIdWidth());
2993 alignPanel.paintAlignment(true);
2997 public void idRightAlign_actionPerformed(ActionEvent e)
2999 viewport.rightAlignIds = idRightAlign.isSelected();
3000 alignPanel.paintAlignment(true);
3004 public void centreColumnLabels_actionPerformed(ActionEvent e)
3006 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
3007 alignPanel.paintAlignment(true);
3013 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3016 protected void followHighlight_actionPerformed()
3018 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
3020 alignPanel.scrollToPosition(
3021 alignPanel.seqPanel.seqCanvas.searchResults, false);
3032 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3034 viewport.setColourText(colourTextMenuItem.isSelected());
3035 alignPanel.paintAlignment(true);
3045 public void wrapMenuItem_actionPerformed(ActionEvent e)
3047 scaleAbove.setVisible(wrapMenuItem.isSelected());
3048 scaleLeft.setVisible(wrapMenuItem.isSelected());
3049 scaleRight.setVisible(wrapMenuItem.isSelected());
3050 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3051 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
3055 public void showAllSeqs_actionPerformed(ActionEvent e)
3057 viewport.showAllHiddenSeqs();
3061 public void showAllColumns_actionPerformed(ActionEvent e)
3063 viewport.showAllHiddenColumns();
3068 public void hideSelSequences_actionPerformed(ActionEvent e)
3070 viewport.hideAllSelectedSeqs();
3071 alignPanel.paintAlignment(true);
3075 * called by key handler and the hide all/show all menu items
3080 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3083 boolean hide = false;
3084 SequenceGroup sg = viewport.getSelectionGroup();
3085 if (!toggleSeqs && !toggleCols)
3087 // Hide everything by the current selection - this is a hack - we do the
3088 // invert and then hide
3089 // first check that there will be visible columns after the invert.
3090 if ((viewport.getColumnSelection() != null
3091 && viewport.getColumnSelection().getSelected() != null && viewport
3092 .getColumnSelection().getSelected().size() > 0)
3093 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
3096 // now invert the sequence set, if required - empty selection implies
3097 // that no hiding is required.
3100 invertSequenceMenuItem_actionPerformed(null);
3101 sg = viewport.getSelectionGroup();
3105 viewport.expandColSelection(sg, true);
3106 // finally invert the column selection and get the new sequence
3108 invertColSel_actionPerformed(null);
3115 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3117 hideSelSequences_actionPerformed(null);
3120 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3123 showAllSeqs_actionPerformed(null);
3129 if (viewport.getColumnSelection().getSelected().size() > 0)
3131 hideSelColumns_actionPerformed(null);
3134 viewport.setSelectionGroup(sg);
3139 showAllColumns_actionPerformed(null);
3148 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3149 * event.ActionEvent)
3152 public void hideAllButSelection_actionPerformed(ActionEvent e)
3154 toggleHiddenRegions(false, false);
3161 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3165 public void hideAllSelection_actionPerformed(ActionEvent e)
3167 SequenceGroup sg = viewport.getSelectionGroup();
3168 viewport.expandColSelection(sg, false);
3169 viewport.hideAllSelectedSeqs();
3170 viewport.hideSelectedColumns();
3171 alignPanel.paintAlignment(true);
3178 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3182 public void showAllhidden_actionPerformed(ActionEvent e)
3184 viewport.showAllHiddenColumns();
3185 viewport.showAllHiddenSeqs();
3186 alignPanel.paintAlignment(true);
3190 public void hideSelColumns_actionPerformed(ActionEvent e)
3192 viewport.hideSelectedColumns();
3193 alignPanel.paintAlignment(true);
3197 public void hiddenMarkers_actionPerformed(ActionEvent e)
3199 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3210 protected void scaleAbove_actionPerformed(ActionEvent e)
3212 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3213 alignPanel.paintAlignment(true);
3223 protected void scaleLeft_actionPerformed(ActionEvent e)
3225 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3226 alignPanel.paintAlignment(true);
3236 protected void scaleRight_actionPerformed(ActionEvent e)
3238 viewport.setScaleRightWrapped(scaleRight.isSelected());
3239 alignPanel.paintAlignment(true);
3249 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3251 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3252 alignPanel.paintAlignment(true);
3262 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3264 viewport.setShowText(viewTextMenuItem.isSelected());
3265 alignPanel.paintAlignment(true);
3275 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3277 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3278 alignPanel.paintAlignment(true);
3281 public FeatureSettings featureSettings;
3284 public void featureSettings_actionPerformed(ActionEvent e)
3286 if (featureSettings != null)
3288 featureSettings.close();
3289 featureSettings = null;
3291 if (!showSeqFeatures.isSelected())
3293 // make sure features are actually displayed
3294 showSeqFeatures.setSelected(true);
3295 showSeqFeatures_actionPerformed(null);
3297 featureSettings = new FeatureSettings(this);
3301 * Set or clear 'Show Sequence Features'
3307 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3309 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3310 alignPanel.paintAlignment(true);
3311 if (alignPanel.getOverviewPanel() != null)
3313 alignPanel.getOverviewPanel().updateOverviewImage();
3318 * Set or clear 'Show Sequence Features'
3324 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3326 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3328 if (viewport.getShowSequenceFeaturesHeight())
3330 // ensure we're actually displaying features
3331 viewport.setShowSequenceFeatures(true);
3332 showSeqFeatures.setSelected(true);
3334 alignPanel.paintAlignment(true);
3335 if (alignPanel.getOverviewPanel() != null)
3337 alignPanel.getOverviewPanel().updateOverviewImage();
3342 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3343 * the annotations panel as a whole.
3345 * The options to show/hide all annotations should be enabled when the panel
3346 * is shown, and disabled when the panel is hidden.
3351 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3353 final boolean setVisible = annotationPanelMenuItem.isSelected();
3354 viewport.setShowAnnotation(setVisible);
3355 alignPanel.setAnnotationVisible(setVisible);
3356 this.showAllSeqAnnotations.setEnabled(setVisible);
3357 this.hideAllSeqAnnotations.setEnabled(setVisible);
3358 this.showAllAlAnnotations.setEnabled(setVisible);
3359 this.hideAllAlAnnotations.setEnabled(setVisible);
3363 public void alignmentProperties()
3365 JEditorPane editPane = new JEditorPane("text/html", "");
3366 editPane.setEditable(false);
3367 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3369 editPane.setText(MessageManager.formatMessage("label.html_content",
3371 { contents.toString() }));
3372 JInternalFrame frame = new JInternalFrame();
3373 frame.getContentPane().add(new JScrollPane(editPane));
3375 Desktop.instance.addInternalFrame(frame, MessageManager.formatMessage(
3376 "label.alignment_properties", new String[]
3377 { getTitle() }), 500, 400);
3387 public void overviewMenuItem_actionPerformed(ActionEvent e)
3389 if (alignPanel.overviewPanel != null)
3394 JInternalFrame frame = new JInternalFrame();
3395 OverviewPanel overview = new OverviewPanel(alignPanel);
3396 frame.setContentPane(overview);
3397 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3398 "label.overview_params", new String[]
3399 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3401 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3402 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3405 public void internalFrameClosed(
3406 javax.swing.event.InternalFrameEvent evt)
3408 alignPanel.setOverviewPanel(null);
3412 alignPanel.setOverviewPanel(overview);
3416 public void textColour_actionPerformed(ActionEvent e)
3418 new TextColourChooser().chooseColour(alignPanel, null);
3428 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3440 public void clustalColour_actionPerformed(ActionEvent e)
3442 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3443 viewport.getHiddenRepSequences()));
3453 public void zappoColour_actionPerformed(ActionEvent e)
3455 changeColour(new ZappoColourScheme());
3465 public void taylorColour_actionPerformed(ActionEvent e)
3467 changeColour(new TaylorColourScheme());
3477 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3479 changeColour(new HydrophobicColourScheme());
3489 public void helixColour_actionPerformed(ActionEvent e)
3491 changeColour(new HelixColourScheme());
3501 public void strandColour_actionPerformed(ActionEvent e)
3503 changeColour(new StrandColourScheme());
3513 public void turnColour_actionPerformed(ActionEvent e)
3515 changeColour(new TurnColourScheme());
3525 public void buriedColour_actionPerformed(ActionEvent e)
3527 changeColour(new BuriedColourScheme());
3537 public void nucleotideColour_actionPerformed(ActionEvent e)
3539 changeColour(new NucleotideColourScheme());
3543 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3545 changeColour(new PurinePyrimidineColourScheme());
3549 * public void covariationColour_actionPerformed(ActionEvent e) {
3551 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3555 public void annotationColour_actionPerformed(ActionEvent e)
3557 new AnnotationColourChooser(viewport, alignPanel);
3561 public void rnahelicesColour_actionPerformed(ActionEvent e)
3563 new RNAHelicesColourChooser(viewport, alignPanel);
3573 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3575 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3584 public void changeColour(ColourSchemeI cs)
3586 // TODO: compare with applet and pull up to model method
3591 if (viewport.getAbovePIDThreshold())
3593 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3595 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3599 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3602 if (viewport.getConservationSelected())
3605 Alignment al = (Alignment) viewport.getAlignment();
3606 Conservation c = new Conservation("All",
3607 ResidueProperties.propHash, 3, al.getSequences(), 0,
3611 c.verdict(false, viewport.getConsPercGaps());
3613 cs.setConservation(c);
3615 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3620 cs.setConservation(null);
3623 cs.setConsensus(viewport.getSequenceConsensusHash());
3626 viewport.setGlobalColourScheme(cs);
3628 if (viewport.getColourAppliesToAllGroups())
3631 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3639 if (cs instanceof ClustalxColourScheme)
3641 sg.cs = new ClustalxColourScheme(sg,
3642 viewport.getHiddenRepSequences());
3644 else if (cs instanceof UserColourScheme)
3646 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3652 sg.cs = cs.getClass().newInstance();
3653 } catch (Exception ex)
3658 if (viewport.getAbovePIDThreshold()
3659 || cs instanceof PIDColourScheme
3660 || cs instanceof Blosum62ColourScheme)
3662 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3664 sg.cs.setConsensus(AAFrequency.calculate(
3665 sg.getSequences(viewport.getHiddenRepSequences()),
3666 sg.getStartRes(), sg.getEndRes() + 1));
3670 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3673 if (viewport.getConservationSelected())
3675 Conservation c = new Conservation("Group",
3676 ResidueProperties.propHash, 3, sg.getSequences(viewport
3677 .getHiddenRepSequences()), sg.getStartRes(),
3678 sg.getEndRes() + 1);
3680 c.verdict(false, viewport.getConsPercGaps());
3681 sg.cs.setConservation(c);
3685 sg.cs.setConservation(null);
3690 if (alignPanel.getOverviewPanel() != null)
3692 alignPanel.getOverviewPanel().updateOverviewImage();
3695 alignPanel.paintAlignment(true);
3705 protected void modifyPID_actionPerformed(ActionEvent e)
3707 if (viewport.getAbovePIDThreshold()
3708 && viewport.getGlobalColourScheme() != null)
3710 SliderPanel.setPIDSliderSource(alignPanel,
3711 viewport.getGlobalColourScheme(), "Background");
3712 SliderPanel.showPIDSlider();
3723 protected void modifyConservation_actionPerformed(ActionEvent e)
3725 if (viewport.getConservationSelected()
3726 && viewport.getGlobalColourScheme() != null)
3728 SliderPanel.setConservationSlider(alignPanel,
3729 viewport.getGlobalColourScheme(), "Background");
3730 SliderPanel.showConservationSlider();
3741 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3743 viewport.setConservationSelected(conservationMenuItem.isSelected());
3745 viewport.setAbovePIDThreshold(false);
3746 abovePIDThreshold.setSelected(false);
3748 changeColour(viewport.getGlobalColourScheme());
3750 modifyConservation_actionPerformed(null);
3760 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3762 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3764 conservationMenuItem.setSelected(false);
3765 viewport.setConservationSelected(false);
3767 changeColour(viewport.getGlobalColourScheme());
3769 modifyPID_actionPerformed(null);
3779 public void userDefinedColour_actionPerformed(ActionEvent e)
3781 if (e.getActionCommand().equals(
3782 MessageManager.getString("action.user_defined")))
3784 new UserDefinedColours(alignPanel, null);
3788 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3789 .getUserColourSchemes().get(e.getActionCommand());
3795 public void updateUserColourMenu()
3798 Component[] menuItems = colourMenu.getMenuComponents();
3799 int i, iSize = menuItems.length;
3800 for (i = 0; i < iSize; i++)
3802 if (menuItems[i].getName() != null
3803 && menuItems[i].getName().equals("USER_DEFINED"))
3805 colourMenu.remove(menuItems[i]);
3809 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3811 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3812 .getUserColourSchemes().keys();
3814 while (userColours.hasMoreElements())
3816 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3817 userColours.nextElement().toString());
3818 radioItem.setName("USER_DEFINED");
3819 radioItem.addMouseListener(new MouseAdapter()
3822 public void mousePressed(MouseEvent evt)
3824 if (evt.isControlDown()
3825 || SwingUtilities.isRightMouseButton(evt))
3827 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3829 int option = JOptionPane.showInternalConfirmDialog(
3830 jalview.gui.Desktop.desktop,
3832 .getString("label.remove_from_default_list"),
3834 .getString("label.remove_user_defined_colour"),
3835 JOptionPane.YES_NO_OPTION);
3836 if (option == JOptionPane.YES_OPTION)
3838 jalview.gui.UserDefinedColours
3839 .removeColourFromDefaults(radioItem.getText());
3840 colourMenu.remove(radioItem);
3844 radioItem.addActionListener(new ActionListener()
3847 public void actionPerformed(ActionEvent evt)
3849 userDefinedColour_actionPerformed(evt);
3856 radioItem.addActionListener(new ActionListener()
3859 public void actionPerformed(ActionEvent evt)
3861 userDefinedColour_actionPerformed(evt);
3865 colourMenu.insert(radioItem, 15);
3866 colours.add(radioItem);
3878 public void PIDColour_actionPerformed(ActionEvent e)
3880 changeColour(new PIDColourScheme());
3890 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3892 changeColour(new Blosum62ColourScheme());
3902 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3904 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3905 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3906 .getAlignment().getSequenceAt(0), null);
3907 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3908 viewport.getAlignment()));
3909 alignPanel.paintAlignment(true);
3919 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3921 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3922 AlignmentSorter.sortByID(viewport.getAlignment());
3923 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3924 viewport.getAlignment()));
3925 alignPanel.paintAlignment(true);
3935 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3937 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3938 AlignmentSorter.sortByLength(viewport.getAlignment());
3939 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3940 viewport.getAlignment()));
3941 alignPanel.paintAlignment(true);
3951 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3953 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3954 AlignmentSorter.sortByGroup(viewport.getAlignment());
3955 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3956 viewport.getAlignment()));
3958 alignPanel.paintAlignment(true);
3968 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3970 new RedundancyPanel(alignPanel, this);
3980 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3982 if ((viewport.getSelectionGroup() == null)
3983 || (viewport.getSelectionGroup().getSize() < 2))
3985 JOptionPane.showInternalMessageDialog(this, MessageManager
3986 .getString("label.you_must_select_least_two_sequences"),
3987 MessageManager.getString("label.invalid_selection"),
3988 JOptionPane.WARNING_MESSAGE);
3992 JInternalFrame frame = new JInternalFrame();
3993 frame.setContentPane(new PairwiseAlignPanel(viewport));
3994 Desktop.addInternalFrame(frame,
3995 MessageManager.getString("action.pairwise_alignment"), 600,
4007 public void PCAMenuItem_actionPerformed(ActionEvent e)
4009 if (((viewport.getSelectionGroup() != null)
4010 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
4011 .getSelectionGroup().getSize() > 0))
4012 || (viewport.getAlignment().getHeight() < 4))
4015 .showInternalMessageDialog(
4018 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
4020 .getString("label.sequence_selection_insufficient"),
4021 JOptionPane.WARNING_MESSAGE);
4026 new PCAPanel(alignPanel);
4030 public void autoCalculate_actionPerformed(ActionEvent e)
4032 viewport.autoCalculateConsensus = autoCalculate.isSelected();
4033 if (viewport.autoCalculateConsensus)
4035 viewport.firePropertyChange("alignment", null, viewport
4036 .getAlignment().getSequences());
4041 public void sortByTreeOption_actionPerformed(ActionEvent e)
4043 viewport.sortByTree = sortByTree.isSelected();
4047 protected void listenToViewSelections_actionPerformed(ActionEvent e)
4049 viewport.followSelection = listenToViewSelections.isSelected();
4059 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
4061 NewTreePanel("AV", "PID", "Average distance tree using PID");
4071 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
4073 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
4083 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
4085 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
4095 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
4097 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
4110 void NewTreePanel(String type, String pwType, String title)
4114 if (viewport.getSelectionGroup() != null
4115 && viewport.getSelectionGroup().getSize() > 0)
4117 if (viewport.getSelectionGroup().getSize() < 3)
4123 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4125 .getString("label.not_enough_sequences"),
4126 JOptionPane.WARNING_MESSAGE);
4130 SequenceGroup sg = viewport.getSelectionGroup();
4132 /* Decide if the selection is a column region */
4133 for (SequenceI _s : sg.getSequences())
4135 if (_s.getLength() < sg.getEndRes())
4141 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4143 .getString("label.sequences_selection_not_aligned"),
4144 JOptionPane.WARNING_MESSAGE);
4150 title = title + " on region";
4151 tp = new TreePanel(alignPanel, type, pwType);
4155 // are the visible sequences aligned?
4156 if (!viewport.getAlignment().isAligned(false))
4162 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4164 .getString("label.sequences_not_aligned"),
4165 JOptionPane.WARNING_MESSAGE);
4170 if (viewport.getAlignment().getHeight() < 2)
4175 tp = new TreePanel(alignPanel, type, pwType);
4180 if (viewport.viewName != null)
4182 title += viewport.viewName + " of ";
4185 title += this.title;
4187 Desktop.addInternalFrame(tp, title, 600, 500);
4198 public void addSortByOrderMenuItem(String title,
4199 final AlignmentOrder order)
4201 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new String[]{title}));
4203 item.addActionListener(new java.awt.event.ActionListener()
4206 public void actionPerformed(ActionEvent e)
4208 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4210 // TODO: JBPNote - have to map order entries to curent SequenceI
4212 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4214 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4217 alignPanel.paintAlignment(true);
4223 * Add a new sort by annotation score menu item
4226 * the menu to add the option to
4228 * the label used to retrieve scores for each sequence on the
4231 public void addSortByAnnotScoreMenuItem(JMenu sort,
4232 final String scoreLabel)
4234 final JMenuItem item = new JMenuItem(scoreLabel);
4236 item.addActionListener(new java.awt.event.ActionListener()
4239 public void actionPerformed(ActionEvent e)
4241 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4242 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4243 viewport.getAlignment());// ,viewport.getSelectionGroup());
4244 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4245 viewport.getAlignment()));
4246 alignPanel.paintAlignment(true);
4252 * last hash for alignment's annotation array - used to minimise cost of
4255 protected int _annotationScoreVectorHash;
4258 * search the alignment and rebuild the sort by annotation score submenu the
4259 * last alignment annotation vector hash is stored to minimize cost of
4260 * rebuilding in subsequence calls.
4264 public void buildSortByAnnotationScoresMenu()
4266 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4271 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4273 sortByAnnotScore.removeAll();
4274 // almost certainly a quicker way to do this - but we keep it simple
4275 Hashtable scoreSorts = new Hashtable();
4276 AlignmentAnnotation aann[];
4277 for (SequenceI sqa : viewport.getAlignment().getSequences())
4279 aann = sqa.getAnnotation();
4280 for (int i = 0; aann != null && i < aann.length; i++)
4282 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4284 scoreSorts.put(aann[i].label, aann[i].label);
4288 Enumeration labels = scoreSorts.keys();
4289 while (labels.hasMoreElements())
4291 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4292 (String) labels.nextElement());
4294 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4297 _annotationScoreVectorHash = viewport.getAlignment()
4298 .getAlignmentAnnotation().hashCode();
4303 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4304 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4305 * call. Listeners are added to remove the menu item when the treePanel is
4306 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4310 * Displayed tree window.
4312 * SortBy menu item title.
4315 public void buildTreeMenu()
4317 calculateTree.removeAll();
4318 // build the calculate menu
4320 for (final String type : new String[]
4323 String treecalcnm = MessageManager.getString("label.tree_calc_"
4324 + type.toLowerCase());
4325 for (final Object pwtype : ResidueProperties.scoreMatrices.keySet())
4327 JMenuItem tm = new JMenuItem();
4328 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4329 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4331 String smn = MessageManager.getStringOrReturn(
4332 "label.score_model_", sm.getName());
4333 final String title = MessageManager.formatMessage(
4334 "label.treecalc_title", treecalcnm, smn);
4335 tm.setText(title);//
4336 tm.addActionListener(new java.awt.event.ActionListener()
4339 public void actionPerformed(ActionEvent e)
4341 NewTreePanel(type, (String) pwtype, title);
4344 calculateTree.add(tm);
4349 sortByTreeMenu.removeAll();
4351 Vector comps = (Vector) PaintRefresher.components.get(viewport
4352 .getSequenceSetId());
4353 Vector treePanels = new Vector();
4354 int i, iSize = comps.size();
4355 for (i = 0; i < iSize; i++)
4357 if (comps.elementAt(i) instanceof TreePanel)
4359 treePanels.add(comps.elementAt(i));
4363 iSize = treePanels.size();
4367 sortByTreeMenu.setVisible(false);
4371 sortByTreeMenu.setVisible(true);
4373 for (i = 0; i < treePanels.size(); i++)
4375 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
4376 final JMenuItem item = new JMenuItem(tp.getTitle());
4377 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
4378 item.addActionListener(new java.awt.event.ActionListener()
4381 public void actionPerformed(ActionEvent e)
4383 tp.sortByTree_actionPerformed(null);
4384 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4389 sortByTreeMenu.add(item);
4393 public boolean sortBy(AlignmentOrder alorder, String undoname)
4395 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4396 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4397 if (undoname != null)
4399 addHistoryItem(new OrderCommand(undoname, oldOrder,
4400 viewport.getAlignment()));
4402 alignPanel.paintAlignment(true);
4407 * Work out whether the whole set of sequences or just the selected set will
4408 * be submitted for multiple alignment.
4411 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4413 // Now, check we have enough sequences
4414 AlignmentView msa = null;
4416 if ((viewport.getSelectionGroup() != null)
4417 && (viewport.getSelectionGroup().getSize() > 1))
4419 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4420 // some common interface!
4422 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4423 * SequenceI[sz = seqs.getSize(false)];
4425 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4426 * seqs.getSequenceAt(i); }
4428 msa = viewport.getAlignmentView(true);
4430 else if (viewport.getSelectionGroup() != null
4431 && viewport.getSelectionGroup().getSize() == 1)
4433 int option = JOptionPane.showConfirmDialog(this,
4434 MessageManager.getString("warn.oneseq_msainput_selection"),
4435 MessageManager.getString("label.invalid_selection"),
4436 JOptionPane.OK_CANCEL_OPTION);
4437 if (option == JOptionPane.OK_OPTION)
4439 msa = viewport.getAlignmentView(false);
4444 msa = viewport.getAlignmentView(false);
4450 * Decides what is submitted to a secondary structure prediction service: the
4451 * first sequence in the alignment, or in the current selection, or, if the
4452 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4453 * region or the whole alignment. (where the first sequence in the set is the
4454 * one that the prediction will be for).
4456 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4458 AlignmentView seqs = null;
4460 if ((viewport.getSelectionGroup() != null)
4461 && (viewport.getSelectionGroup().getSize() > 0))
4463 seqs = viewport.getAlignmentView(true);
4467 seqs = viewport.getAlignmentView(false);
4469 // limit sequences - JBPNote in future - could spawn multiple prediction
4471 // TODO: viewport.getAlignment().isAligned is a global state - the local
4472 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4473 if (!viewport.getAlignment().isAligned(false))
4475 seqs.setSequences(new SeqCigar[]
4476 { seqs.getSequences()[0] });
4477 // TODO: if seqs.getSequences().length>1 then should really have warned
4491 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4493 // Pick the tree file
4494 JalviewFileChooser chooser = new JalviewFileChooser(
4495 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4496 chooser.setFileView(new JalviewFileView());
4497 chooser.setDialogTitle(MessageManager
4498 .getString("label.select_newick_like_tree_file"));
4499 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4501 int value = chooser.showOpenDialog(null);
4503 if (value == JalviewFileChooser.APPROVE_OPTION)
4505 String choice = chooser.getSelectedFile().getPath();
4506 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4507 jalview.io.NewickFile fin = null;
4510 fin = new jalview.io.NewickFile(choice, "File");
4511 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4512 } catch (Exception ex)
4519 .getString("label.problem_reading_tree_file"),
4520 JOptionPane.WARNING_MESSAGE);
4521 ex.printStackTrace();
4523 if (fin != null && fin.hasWarningMessage())
4525 JOptionPane.showMessageDialog(Desktop.desktop, fin
4526 .getWarningMessage(), MessageManager
4527 .getString("label.possible_problem_with_tree_file"),
4528 JOptionPane.WARNING_MESSAGE);
4534 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4536 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4539 public TreePanel ShowNewickTree(NewickFile nf, String title)
4541 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4544 public TreePanel ShowNewickTree(NewickFile nf, String title,
4545 AlignmentView input)
4547 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4550 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4551 int h, int x, int y)
4553 return ShowNewickTree(nf, title, null, w, h, x, y);
4557 * Add a treeviewer for the tree extracted from a newick file object to the
4558 * current alignment view
4565 * Associated alignment input data (or null)
4574 * @return TreePanel handle
4576 public TreePanel ShowNewickTree(NewickFile nf, String title,
4577 AlignmentView input, int w, int h, int x, int y)
4579 TreePanel tp = null;
4585 if (nf.getTree() != null)
4587 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4593 tp.setLocation(x, y);
4596 Desktop.addInternalFrame(tp, title, w, h);
4598 } catch (Exception ex)
4600 ex.printStackTrace();
4606 private boolean buildingMenu = false;
4609 * Generates menu items and listener event actions for web service clients
4612 public void BuildWebServiceMenu()
4614 while (buildingMenu)
4618 System.err.println("Waiting for building menu to finish.");
4620 } catch (Exception e)
4625 final AlignFrame me = this;
4626 buildingMenu = true;
4627 new Thread(new Runnable()
4632 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4635 System.err.println("Building ws menu again "
4636 + Thread.currentThread());
4637 // TODO: add support for context dependent disabling of services based
4639 // alignment and current selection
4640 // TODO: add additional serviceHandle parameter to specify abstract
4642 // class independently of AbstractName
4643 // TODO: add in rediscovery GUI function to restart discoverer
4644 // TODO: group services by location as well as function and/or
4646 // object broker mechanism.
4647 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4648 final IProgressIndicator af = me;
4649 final JMenu msawsmenu = new JMenu("Alignment");
4650 final JMenu secstrmenu = new JMenu(
4651 "Secondary Structure Prediction");
4652 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4653 final JMenu analymenu = new JMenu("Analysis");
4654 final JMenu dismenu = new JMenu("Protein Disorder");
4655 // final JMenu msawsmenu = new
4656 // JMenu(MessageManager.getString("label.alignment"));
4657 // final JMenu secstrmenu = new
4658 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4659 // final JMenu seqsrchmenu = new
4660 // JMenu(MessageManager.getString("label.sequence_database_search"));
4661 // final JMenu analymenu = new
4662 // JMenu(MessageManager.getString("label.analysis"));
4663 // final JMenu dismenu = new
4664 // JMenu(MessageManager.getString("label.protein_disorder"));
4665 // JAL-940 - only show secondary structure prediction services from
4666 // the legacy server
4667 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4669 Discoverer.services != null && (Discoverer.services.size() > 0))
4671 // TODO: refactor to allow list of AbstractName/Handler bindings to
4673 // stored or retrieved from elsewhere
4674 // No MSAWS used any more:
4675 // Vector msaws = null; // (Vector)
4676 // Discoverer.services.get("MsaWS");
4677 Vector secstrpr = (Vector) Discoverer.services
4679 if (secstrpr != null)
4681 // Add any secondary structure prediction services
4682 for (int i = 0, j = secstrpr.size(); i < j; i++)
4684 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4686 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4687 .getServiceClient(sh);
4688 int p = secstrmenu.getItemCount();
4689 impl.attachWSMenuEntry(secstrmenu, me);
4690 int q = secstrmenu.getItemCount();
4691 for (int litm = p; litm < q; litm++)
4693 legacyItems.add(secstrmenu.getItem(litm));
4699 // Add all submenus in the order they should appear on the web
4701 wsmenu.add(msawsmenu);
4702 wsmenu.add(secstrmenu);
4703 wsmenu.add(dismenu);
4704 wsmenu.add(analymenu);
4705 // No search services yet
4706 // wsmenu.add(seqsrchmenu);
4708 javax.swing.SwingUtilities.invokeLater(new Runnable()
4715 webService.removeAll();
4716 // first, add discovered services onto the webservices menu
4717 if (wsmenu.size() > 0)
4719 for (int i = 0, j = wsmenu.size(); i < j; i++)
4721 webService.add(wsmenu.get(i));
4726 webService.add(me.webServiceNoServices);
4728 // TODO: move into separate menu builder class.
4729 boolean new_sspred = false;
4730 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4732 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4733 if (jws2servs != null)
4735 if (jws2servs.hasServices())
4737 jws2servs.attachWSMenuEntry(webService, me);
4738 for (Jws2Instance sv : jws2servs.getServices())
4740 if (sv.description.toLowerCase().contains("jpred"))
4742 for (JMenuItem jmi : legacyItems)
4744 jmi.setVisible(false);
4750 if (jws2servs.isRunning())
4752 JMenuItem tm = new JMenuItem(
4753 "Still discovering JABA Services");
4754 tm.setEnabled(false);
4759 build_urlServiceMenu(me.webService);
4760 build_fetchdbmenu(webService);
4761 for (JMenu item : wsmenu)
4763 if (item.getItemCount() == 0)
4765 item.setEnabled(false);
4769 item.setEnabled(true);
4772 } catch (Exception e)
4775 .debug("Exception during web service menu building process.",
4781 } catch (Exception e)
4786 buildingMenu = false;
4793 * construct any groupURL type service menu entries.
4797 private void build_urlServiceMenu(JMenu webService)
4799 // TODO: remove this code when 2.7 is released
4800 // DEBUG - alignmentView
4802 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4803 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4805 * @Override public void actionPerformed(ActionEvent e) {
4806 * jalview.datamodel.AlignmentView
4807 * .testSelectionViews(af.viewport.getAlignment(),
4808 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4810 * }); webService.add(testAlView);
4812 // TODO: refactor to RestClient discoverer and merge menu entries for
4813 // rest-style services with other types of analysis/calculation service
4814 // SHmmr test client - still being implemented.
4815 // DEBUG - alignmentView
4817 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4820 client.attachWSMenuEntry(
4821 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4827 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4828 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4829 * getProperty("LAST_DIRECTORY"));
4831 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4832 * to Vamsas file"); chooser.setToolTipText("Export");
4834 * int value = chooser.showSaveDialog(this);
4836 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4837 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4838 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4839 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4842 * prototype of an automatically enabled/disabled analysis function
4845 protected void setShowProductsEnabled()
4847 SequenceI[] selection = viewport.getSequenceSelection();
4848 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4849 viewport.getAlignment().getDataset()))
4851 showProducts.setEnabled(true);
4856 showProducts.setEnabled(false);
4861 * search selection for sequence xRef products and build the show products
4866 * @return true if showProducts menu should be enabled.
4868 public boolean canShowProducts(SequenceI[] selection,
4869 boolean isRegionSelection, Alignment dataset)
4871 boolean showp = false;
4874 showProducts.removeAll();
4875 final boolean dna = viewport.getAlignment().isNucleotide();
4876 final Alignment ds = dataset;
4877 String[] ptypes = (selection == null || selection.length == 0) ? null
4878 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4880 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4881 // selection, dataset, true);
4882 final SequenceI[] sel = selection;
4883 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4886 final boolean isRegSel = isRegionSelection;
4887 final AlignFrame af = this;
4888 final String source = ptypes[t];
4889 JMenuItem xtype = new JMenuItem(ptypes[t]);
4890 xtype.addActionListener(new ActionListener()
4894 public void actionPerformed(ActionEvent e)
4896 // TODO: new thread for this call with vis-delay
4897 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4898 isRegSel, dna, source);
4902 showProducts.add(xtype);
4904 showProducts.setVisible(showp);
4905 showProducts.setEnabled(showp);
4906 } catch (Exception e)
4908 jalview.bin.Cache.log
4909 .warn("canTranslate threw an exception - please report to help@jalview.org",
4916 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4917 boolean isRegSel, boolean dna, String source)
4919 final boolean fisRegSel = isRegSel;
4920 final boolean fdna = dna;
4921 final String fsrc = source;
4922 final AlignFrame ths = this;
4923 final SequenceI[] fsel = sel;
4924 Runnable foo = new Runnable()
4930 final long sttime = System.currentTimeMillis();
4931 ths.setProgressBar(MessageManager.formatMessage("status.searching_for_sequences_from", new String[]{fsrc}), sttime);
4934 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4938 Alignment prods = CrossRef
4939 .findXrefSequences(fsel, fdna, fsrc, ds);
4942 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4943 for (int s = 0; s < sprods.length; s++)
4945 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4946 if (ds.getSequences() == null
4947 || !ds.getSequences().contains(
4948 sprods[s].getDatasetSequence()))
4950 ds.addSequence(sprods[s].getDatasetSequence());
4952 sprods[s].updatePDBIds();
4954 Alignment al = new Alignment(sprods);
4955 AlignedCodonFrame[] cf = prods.getCodonFrames();
4957 for (int s = 0; cf != null && s < cf.length; s++)
4959 al.addCodonFrame(cf[s]);
4962 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4964 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4965 + " for " + ((fisRegSel) ? "selected region of " : "")
4967 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4972 System.err.println("No Sequences generated for xRef type "
4975 } catch (Exception e)
4977 jalview.bin.Cache.log.error(
4978 "Exception when finding crossreferences", e);
4979 } catch (OutOfMemoryError e)
4981 new OOMWarning("whilst fetching crossreferences", e);
4984 jalview.bin.Cache.log.error("Error when finding crossreferences",
4987 ths.setProgressBar(MessageManager.formatMessage("status.finished_searching_for_sequences_from", new String[]{fsrc}),
4992 Thread frunner = new Thread(foo);
4996 public boolean canShowTranslationProducts(SequenceI[] selection,
4997 AlignmentI alignment)
5002 return (jalview.analysis.Dna.canTranslate(selection,
5003 viewport.getViewAsVisibleContigs(true)));
5004 } catch (Exception e)
5006 jalview.bin.Cache.log
5007 .warn("canTranslate threw an exception - please report to help@jalview.org",
5014 public void showProducts_actionPerformed(ActionEvent e)
5016 // /////////////////////////////
5017 // Collect Data to be translated/transferred
5019 SequenceI[] selection = viewport.getSequenceSelection();
5020 AlignmentI al = null;
5023 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
5024 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
5025 viewport.getAlignment().getDataset());
5026 } catch (Exception ex)
5029 jalview.bin.Cache.log.debug("Exception during translation.", ex);
5037 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
5038 MessageManager.getString("label.translation_failed"),
5039 JOptionPane.WARNING_MESSAGE);
5043 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
5044 Desktop.addInternalFrame(af, MessageManager.formatMessage(
5045 "label.translation_of_params", new String[]
5046 { this.getTitle() }), DEFAULT_WIDTH, DEFAULT_HEIGHT);
5051 * Construct and display a new frame containing the translation of this
5052 * frame's cDNA sequences to their protein (amino acid) equivalents.
5055 public void showTranslation_actionPerformed(ActionEvent e)
5057 // /////////////////////////////
5058 // Collect Data to be translated/transferred
5060 SequenceI[] selection = viewport.getSequenceSelection();
5061 String[] seqstring = viewport.getViewAsString(true);
5062 AlignmentI al = null;
5065 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
5066 viewport.getViewAsVisibleContigs(true), viewport
5067 .getGapCharacter(), viewport.getAlignment()
5068 .getAlignmentAnnotation(), viewport.getAlignment()
5069 .getWidth(), viewport.getAlignment().getDataset());
5070 } catch (Exception ex)
5073 jalview.bin.Cache.log.error(
5074 "Exception during translation. Please report this !", ex);
5079 .getString("label.error_when_translating_sequences_submit_bug_report"),
5081 .getString("label.implementation_error")
5083 .getString("translation_failed"),
5084 JOptionPane.ERROR_MESSAGE);
5093 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
5094 MessageManager.getString("label.translation_failed"),
5095 JOptionPane.WARNING_MESSAGE);
5099 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
5100 Desktop.addInternalFrame(af, MessageManager.formatMessage(
5101 "label.translation_of_params", new String[]
5102 { this.getTitle() }), DEFAULT_WIDTH, DEFAULT_HEIGHT);
5103 viewport.getStructureSelectionManager().addCommandListener(viewport);
5108 * Try to load a features file onto the alignment.
5111 * contents or path to retrieve file
5113 * access mode of file (see jalview.io.AlignFile)
5114 * @return true if features file was parsed corectly.
5116 public boolean parseFeaturesFile(String file, String type)
5118 boolean featuresFile = false;
5121 featuresFile = new FeaturesFile(file, type).parse(viewport
5122 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
5123 .getFeatureRenderer().featureColours, false,
5124 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5125 } catch (Exception ex)
5127 ex.printStackTrace();
5132 viewport.showSequenceFeatures = true;
5133 showSeqFeatures.setSelected(true);
5134 if (alignPanel.seqPanel.seqCanvas.fr != null)
5136 // update the min/max ranges where necessary
5137 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
5139 if (featureSettings != null)
5141 featureSettings.setTableData();
5143 alignPanel.paintAlignment(true);
5146 return featuresFile;
5150 public void dragEnter(DropTargetDragEvent evt)
5155 public void dragExit(DropTargetEvent evt)
5160 public void dragOver(DropTargetDragEvent evt)
5165 public void dropActionChanged(DropTargetDragEvent evt)
5170 public void drop(DropTargetDropEvent evt)
5172 Transferable t = evt.getTransferable();
5173 java.util.List files = null;
5177 DataFlavor uriListFlavor = new DataFlavor(
5178 "text/uri-list;class=java.lang.String");
5179 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5181 // Works on Windows and MacOSX
5182 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5183 files = (java.util.List) t
5184 .getTransferData(DataFlavor.javaFileListFlavor);
5186 else if (t.isDataFlavorSupported(uriListFlavor))
5188 // This is used by Unix drag system
5189 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5190 String data = (String) t.getTransferData(uriListFlavor);
5191 files = new java.util.ArrayList(1);
5192 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5193 data, "\r\n"); st.hasMoreTokens();)
5195 String s = st.nextToken();
5196 if (s.startsWith("#"))
5198 // the line is a comment (as per the RFC 2483)
5202 java.net.URI uri = new java.net.URI(s);
5203 // check to see if we can handle this kind of URI
5204 if (uri.getScheme().toLowerCase().startsWith("http"))
5206 files.add(uri.toString());
5210 // otherwise preserve old behaviour: catch all for file objects
5211 java.io.File file = new java.io.File(uri);
5212 files.add(file.toString());
5216 } catch (Exception e)
5218 e.printStackTrace();
5224 // check to see if any of these files have names matching sequences in
5226 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5227 .getAlignment().getSequencesArray());
5229 * Object[] { String,SequenceI}
5231 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5232 ArrayList<String> filesnotmatched = new ArrayList<String>();
5233 for (int i = 0; i < files.size(); i++)
5235 String file = files.get(i).toString();
5237 String protocol = FormatAdapter.checkProtocol(file);
5238 if (protocol == jalview.io.FormatAdapter.FILE)
5240 File fl = new File(file);
5241 pdbfn = fl.getName();
5243 else if (protocol == jalview.io.FormatAdapter.URL)
5245 URL url = new URL(file);
5246 pdbfn = url.getFile();
5248 if (pdbfn.length() > 0)
5250 // attempt to find a match in the alignment
5251 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5252 int l = 0, c = pdbfn.indexOf(".");
5253 while (mtch == null && c != -1)
5258 } while ((c = pdbfn.indexOf(".", l)) > l);
5261 pdbfn = pdbfn.substring(0, l);
5263 mtch = idm.findAllIdMatches(pdbfn);
5270 type = new IdentifyFile().Identify(file, protocol);
5271 } catch (Exception ex)
5277 if (type.equalsIgnoreCase("PDB"))
5279 filesmatched.add(new Object[]
5280 { file, protocol, mtch });
5285 // File wasn't named like one of the sequences or wasn't a PDB file.
5286 filesnotmatched.add(file);
5290 if (filesmatched.size() > 0)
5292 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5298 "label.automatically_associate_pdb_files_with_sequences_same_name",
5305 .getString("label.automatically_associate_pdb_files_by_name"),
5306 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5309 for (Object[] fm : filesmatched)
5311 // try and associate
5312 // TODO: may want to set a standard ID naming formalism for
5313 // associating PDB files which have no IDs.
5314 for (SequenceI toassoc : (SequenceI[]) fm[2])
5316 PDBEntry pe = new AssociatePdbFileWithSeq()
5317 .associatePdbWithSeq((String) fm[0],
5318 (String) fm[1], toassoc, false,
5322 System.err.println("Associated file : "
5323 + ((String) fm[0]) + " with "
5324 + toassoc.getDisplayId(true));
5328 alignPanel.paintAlignment(true);
5332 if (filesnotmatched.size() > 0)
5335 && (Cache.getDefault(
5336 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5339 "<html>"+MessageManager
5341 "label.ignore_unmatched_dropped_files_info",
5346 .toString() })+"</html>",
5348 .getString("label.ignore_unmatched_dropped_files"),
5349 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5353 for (String fn : filesnotmatched)
5355 loadJalviewDataFile(fn, null, null, null);
5359 } catch (Exception ex)
5361 ex.printStackTrace();
5367 * Attempt to load a "dropped" file or URL string: First by testing whether
5368 * it's and Annotation file, then a JNet file, and finally a features file. If
5369 * all are false then the user may have dropped an alignment file onto this
5373 * either a filename or a URL string.
5375 public void loadJalviewDataFile(String file, String protocol,
5376 String format, SequenceI assocSeq)
5380 if (protocol == null)
5382 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5384 // if the file isn't identified, or not positively identified as some
5385 // other filetype (PFAM is default unidentified alignment file type) then
5386 // try to parse as annotation.
5387 boolean isAnnotation = (format == null || format
5388 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5389 .readAnnotationFile(viewport.getAlignment(), file, protocol)
5394 // first see if its a T-COFFEE score file
5395 TCoffeeScoreFile tcf = null;
5398 tcf = new TCoffeeScoreFile(file, protocol);
5401 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5403 tcoffeeColour.setEnabled(true);
5404 tcoffeeColour.setSelected(true);
5405 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5406 isAnnotation = true;
5408 .setText(MessageManager
5409 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5413 // some problem - if no warning its probable that the ID matching
5414 // process didn't work
5418 tcf.getWarningMessage() == null ? MessageManager
5419 .getString("label.check_file_matches_sequence_ids_alignment")
5420 : tcf.getWarningMessage(),
5422 .getString("label.problem_reading_tcoffee_score_file"),
5423 JOptionPane.WARNING_MESSAGE);
5430 } catch (Exception x)
5433 .debug("Exception when processing data source as T-COFFEE score file",
5439 // try to see if its a JNet 'concise' style annotation file *before*
5441 // try to parse it as a features file
5444 format = new IdentifyFile().Identify(file, protocol);
5446 if (format.equalsIgnoreCase("JnetFile"))
5448 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5450 new JnetAnnotationMaker().add_annotation(predictions,
5451 viewport.getAlignment(), 0, false);
5452 isAnnotation = true;
5457 * if (format.equalsIgnoreCase("PDB")) {
5459 * String pdbfn = ""; // try to match up filename with sequence id
5460 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5461 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5462 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5463 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5464 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5465 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5466 * // attempt to find a match in the alignment SequenceI mtch =
5467 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5468 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5469 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5470 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5471 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5472 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5473 * { System.err.println("Associated file : " + file + " with " +
5474 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5475 * TODO: maybe need to load as normal otherwise return; } }
5477 // try to parse it as a features file
5478 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5479 // if it wasn't a features file then we just treat it as a general
5480 // alignment file to load into the current view.
5483 new FileLoader().LoadFile(viewport, file, protocol, format);
5487 alignPanel.paintAlignment(true);
5495 alignPanel.adjustAnnotationHeight();
5496 viewport.updateSequenceIdColours();
5497 buildSortByAnnotationScoresMenu();
5498 alignPanel.paintAlignment(true);
5500 } catch (Exception ex)
5502 ex.printStackTrace();
5503 } catch (OutOfMemoryError oom)
5508 } catch (Exception x)
5514 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5515 : "using " + protocol + " from " + file)
5517 + (format != null ? "(parsing as '" + format
5518 + "' file)" : ""), oom, Desktop.desktop);
5523 public void tabSelectionChanged(int index)
5527 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5528 viewport = alignPanel.av;
5529 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5530 setMenusFromViewport(viewport);
5535 public void tabbedPane_mousePressed(MouseEvent e)
5537 if (SwingUtilities.isRightMouseButton(e))
5539 String reply = JOptionPane.showInternalInputDialog(this,
5540 MessageManager.getString("label.enter_view_name"),
5541 MessageManager.getString("label.enter_view_name"),
5542 JOptionPane.QUESTION_MESSAGE);
5546 viewport.viewName = reply;
5547 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5552 public AlignViewport getCurrentView()
5558 * Open the dialog for regex description parsing.
5561 protected void extractScores_actionPerformed(ActionEvent e)
5563 ParseProperties pp = new jalview.analysis.ParseProperties(
5564 viewport.getAlignment());
5565 // TODO: verify regex and introduce GUI dialog for version 2.5
5566 // if (pp.getScoresFromDescription("col", "score column ",
5567 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5569 if (pp.getScoresFromDescription("description column",
5570 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5572 buildSortByAnnotationScoresMenu();
5580 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5584 protected void showDbRefs_actionPerformed(ActionEvent e)
5586 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5592 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5596 protected void showNpFeats_actionPerformed(ActionEvent e)
5598 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5602 * find the viewport amongst the tabs in this alignment frame and close that
5607 public boolean closeView(AlignViewport av)
5611 this.closeMenuItem_actionPerformed(false);
5614 Component[] comp = tabbedPane.getComponents();
5615 for (int i = 0; comp != null && i < comp.length; i++)
5617 if (comp[i] instanceof AlignmentPanel)
5619 if (((AlignmentPanel) comp[i]).av == av)
5622 closeView((AlignmentPanel) comp[i]);
5630 protected void build_fetchdbmenu(JMenu webService)
5632 // Temporary hack - DBRef Fetcher always top level ws entry.
5633 // TODO We probably want to store a sequence database checklist in
5634 // preferences and have checkboxes.. rather than individual sources selected
5636 final JMenu rfetch = new JMenu(
5637 MessageManager.getString("action.fetch_db_references"));
5638 rfetch.setToolTipText(MessageManager
5639 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5640 webService.add(rfetch);
5642 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5643 MessageManager.getString("option.trim_retrieved_seqs"));
5644 trimrs.setToolTipText(MessageManager
5645 .getString("label.trim_retrieved_sequences"));
5646 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5647 trimrs.addActionListener(new ActionListener()
5650 public void actionPerformed(ActionEvent e)
5652 trimrs.setSelected(trimrs.isSelected());
5653 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5654 Boolean.valueOf(trimrs.isSelected()).toString());
5658 JMenuItem fetchr = new JMenuItem(
5659 MessageManager.getString("label.standard_databases"));
5660 fetchr.setToolTipText(MessageManager
5661 .getString("label.fetch_embl_uniprot"));
5662 fetchr.addActionListener(new ActionListener()
5666 public void actionPerformed(ActionEvent e)
5668 new Thread(new Runnable()
5674 new jalview.ws.DBRefFetcher(alignPanel.av
5675 .getSequenceSelection(), alignPanel.alignFrame)
5676 .fetchDBRefs(false);
5684 final AlignFrame me = this;
5685 new Thread(new Runnable()
5690 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5691 .getSequenceFetcherSingleton(me);
5692 javax.swing.SwingUtilities.invokeLater(new Runnable()
5697 String[] dbclasses = sf.getOrderedSupportedSources();
5698 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5699 // jalview.util.QuickSort.sort(otherdb, otherdb);
5700 List<DbSourceProxy> otherdb;
5701 JMenu dfetch = new JMenu();
5702 JMenu ifetch = new JMenu();
5703 JMenuItem fetchr = null;
5704 int comp = 0, icomp = 0, mcomp = 15;
5705 String mname = null;
5707 for (String dbclass : dbclasses)
5709 otherdb = sf.getSourceProxy(dbclass);
5710 // add a single entry for this class, or submenu allowing 'fetch
5712 if (otherdb == null || otherdb.size() < 1)
5716 // List<DbSourceProxy> dbs=otherdb;
5717 // otherdb=new ArrayList<DbSourceProxy>();
5718 // for (DbSourceProxy db:dbs)
5720 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5724 mname = "From " + dbclass;
5726 if (otherdb.size() == 1)
5728 final DbSourceProxy[] dassource = otherdb
5729 .toArray(new DbSourceProxy[0]);
5730 DbSourceProxy src = otherdb.get(0);
5731 fetchr = new JMenuItem(src.getDbSource());
5732 fetchr.addActionListener(new ActionListener()
5736 public void actionPerformed(ActionEvent e)
5738 new Thread(new Runnable()
5744 new jalview.ws.DBRefFetcher(alignPanel.av
5745 .getSequenceSelection(),
5746 alignPanel.alignFrame, dassource)
5747 .fetchDBRefs(false);
5753 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new String[]{src.getDbName()})));
5759 final DbSourceProxy[] dassource = otherdb
5760 .toArray(new DbSourceProxy[0]);
5762 DbSourceProxy src = otherdb.get(0);
5763 fetchr = new JMenuItem(MessageManager.formatMessage(
5764 "label.fetch_all_param", new String[]
5765 { src.getDbSource() }));
5766 fetchr.addActionListener(new ActionListener()
5769 public void actionPerformed(ActionEvent e)
5771 new Thread(new Runnable()
5777 new jalview.ws.DBRefFetcher(alignPanel.av
5778 .getSequenceSelection(),
5779 alignPanel.alignFrame, dassource)
5780 .fetchDBRefs(false);
5786 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new String[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5789 // and then build the rest of the individual menus
5790 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new String[]{src.getDbSource()}));
5792 String imname = null;
5794 for (DbSourceProxy sproxy : otherdb)
5796 String dbname = sproxy.getDbName();
5797 String sname = dbname.length() > 5 ? dbname.substring(0,
5798 5) + "..." : dbname;
5799 String msname = dbname.length() > 10 ? dbname.substring(
5800 0, 10) + "..." : dbname;
5803 imname = MessageManager.formatMessage("label.from_msname", new String[]{sname});
5805 fetchr = new JMenuItem(msname);
5806 final DbSourceProxy[] dassrc =
5808 fetchr.addActionListener(new ActionListener()
5812 public void actionPerformed(ActionEvent e)
5814 new Thread(new Runnable()
5820 new jalview.ws.DBRefFetcher(alignPanel.av
5821 .getSequenceSelection(),
5822 alignPanel.alignFrame, dassrc)
5823 .fetchDBRefs(false);
5829 fetchr.setToolTipText("<html>"
5830 + MessageManager.formatMessage("label.fetch_retrieve_from", new String[]{dbname}));
5833 if (++icomp >= mcomp || i == (otherdb.size()))
5835 ifetch.setText(MessageManager.formatMessage(
5836 "label.source_to_target", imname, sname));
5838 ifetch = new JMenu();
5846 if (comp >= mcomp || dbi >= (dbclasses.length))
5848 dfetch.setText(MessageManager.formatMessage(
5849 "label.source_to_target", mname, dbclass));
5851 dfetch = new JMenu();
5864 * Left justify the whole alignment.
5867 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5869 AlignmentI al = viewport.getAlignment();
5871 viewport.firePropertyChange("alignment", null, al);
5875 * Right justify the whole alignment.
5878 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5880 AlignmentI al = viewport.getAlignment();
5882 viewport.firePropertyChange("alignment", null, al);
5885 public void setShowSeqFeatures(boolean b)
5887 showSeqFeatures.setSelected(true);
5888 viewport.setShowSequenceFeatures(true);
5895 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5896 * awt.event.ActionEvent)
5899 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5901 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5902 alignPanel.paintAlignment(true);
5909 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5913 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5915 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5916 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5924 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5925 * .event.ActionEvent)
5928 protected void showGroupConservation_actionPerformed(ActionEvent e)
5930 viewport.setShowGroupConservation(showGroupConservation.getState());
5931 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5938 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5939 * .event.ActionEvent)
5942 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5944 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5945 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5952 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5953 * .event.ActionEvent)
5956 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5958 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5959 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5963 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5965 showSequenceLogo.setState(true);
5966 viewport.setShowSequenceLogo(true);
5967 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5968 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5972 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5974 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5981 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5982 * .event.ActionEvent)
5985 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5987 if (avc.makeGroupsFromSelection())
5989 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5990 alignPanel.updateAnnotation();
5991 alignPanel.paintAlignment(true);
5996 protected void createGroup_actionPerformed(ActionEvent e)
5998 if (avc.createGroup())
6000 alignPanel.alignmentChanged();
6005 protected void unGroup_actionPerformed(ActionEvent e)
6009 alignPanel.alignmentChanged();
6014 * make the given alignmentPanel the currently selected tab
6016 * @param alignmentPanel
6018 public void setDisplayedView(AlignmentPanel alignmentPanel)
6020 if (!viewport.getSequenceSetId().equals(
6021 alignmentPanel.av.getSequenceSetId()))
6023 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
6025 if (tabbedPane != null
6026 & alignPanels.indexOf(alignmentPanel) != tabbedPane
6027 .getSelectedIndex())
6029 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
6034 * Action on selection of menu options to Show or Hide annotations.
6037 * @param forSequences
6038 * update sequence-related annotations
6039 * @param forAlignment
6040 * update non-sequence-related annotations
6043 protected void setAnnotationsVisibility(boolean visible,
6044 boolean forSequences, boolean forAlignment)
6046 for (AlignmentAnnotation aa : alignPanel.getAlignment()
6047 .getAlignmentAnnotation())
6049 boolean apply = (aa.sequenceRef == null && forAlignment)
6050 || (aa.sequenceRef != null && forSequences);
6053 aa.visible = visible;
6056 alignPanel.validateAnnotationDimensions(false);
6057 alignPanel.alignmentChanged();
6061 * Store selected annotation sort order for the view and repaint.
6064 protected void sortAnnotations_actionPerformed()
6066 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
6068 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
6069 alignPanel.paintAlignment(true);
6074 * @return alignment panels in this alignemnt frame
6076 public List<AlignmentViewPanel> getAlignPanels()
6078 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
6082 class PrintThread extends Thread
6086 public PrintThread(AlignmentPanel ap)
6091 static PageFormat pf;
6096 PrinterJob printJob = PrinterJob.getPrinterJob();
6100 printJob.setPrintable(ap, pf);
6104 printJob.setPrintable(ap);
6107 if (printJob.printDialog())
6112 } catch (Exception PrintException)
6114 PrintException.printStackTrace();