2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.ParseProperties;
28 import jalview.analysis.SequenceIdMatcher;
29 import jalview.api.AlignExportSettingI;
30 import jalview.api.AlignViewControllerGuiI;
31 import jalview.api.AlignViewControllerI;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureSettingsControllerI;
35 import jalview.api.FeatureSettingsModelI;
36 import jalview.api.SplitContainerI;
37 import jalview.api.ViewStyleI;
38 import jalview.api.analysis.ScoreModelI;
39 import jalview.bin.Cache;
40 import jalview.bin.Jalview;
41 import jalview.commands.CommandI;
42 import jalview.commands.EditCommand;
43 import jalview.commands.EditCommand.Action;
44 import jalview.commands.OrderCommand;
45 import jalview.commands.RemoveGapColCommand;
46 import jalview.commands.RemoveGapsCommand;
47 import jalview.commands.SlideSequencesCommand;
48 import jalview.commands.TrimRegionCommand;
49 import jalview.datamodel.AlignedCodonFrame;
50 import jalview.datamodel.Alignment;
51 import jalview.datamodel.AlignmentAnnotation;
52 import jalview.datamodel.AlignmentExportData;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.AlignmentOrder;
55 import jalview.datamodel.AlignmentView;
56 import jalview.datamodel.ColumnSelection;
57 import jalview.datamodel.DBRefSource;
58 import jalview.datamodel.HiddenSequences;
59 import jalview.datamodel.PDBEntry;
60 import jalview.datamodel.SeqCigar;
61 import jalview.datamodel.Sequence;
62 import jalview.datamodel.SequenceGroup;
63 import jalview.datamodel.SequenceI;
64 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
65 import jalview.io.AlignmentProperties;
66 import jalview.io.AnnotationFile;
67 import jalview.io.BioJsHTMLOutput;
68 import jalview.io.FileLoader;
69 import jalview.io.FormatAdapter;
70 import jalview.io.HtmlSvgOutput;
71 import jalview.io.IdentifyFile;
72 import jalview.io.JalviewFileChooser;
73 import jalview.io.JalviewFileView;
74 import jalview.io.JnetAnnotationMaker;
75 import jalview.io.NewickFile;
76 import jalview.io.TCoffeeScoreFile;
77 import jalview.jbgui.GAlignFrame;
78 import jalview.schemes.Blosum62ColourScheme;
79 import jalview.schemes.BuriedColourScheme;
80 import jalview.schemes.ClustalxColourScheme;
81 import jalview.schemes.ColourSchemeI;
82 import jalview.schemes.ColourSchemeProperty;
83 import jalview.schemes.HelixColourScheme;
84 import jalview.schemes.HydrophobicColourScheme;
85 import jalview.schemes.NucleotideColourScheme;
86 import jalview.schemes.PIDColourScheme;
87 import jalview.schemes.PurinePyrimidineColourScheme;
88 import jalview.schemes.RNAHelicesColourChooser;
89 import jalview.schemes.ResidueProperties;
90 import jalview.schemes.StrandColourScheme;
91 import jalview.schemes.TCoffeeColourScheme;
92 import jalview.schemes.TaylorColourScheme;
93 import jalview.schemes.TurnColourScheme;
94 import jalview.schemes.UserColourScheme;
95 import jalview.schemes.ZappoColourScheme;
96 import jalview.structure.StructureSelectionManager;
97 import jalview.util.MessageManager;
98 import jalview.viewmodel.AlignmentViewport;
99 import jalview.ws.DBRefFetcher;
100 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
101 import jalview.ws.SequenceFetcher;
102 import jalview.ws.jws1.Discoverer;
103 import jalview.ws.jws2.Jws2Discoverer;
104 import jalview.ws.jws2.jabaws2.Jws2Instance;
105 import jalview.ws.seqfetcher.DbSourceProxy;
107 import java.awt.BorderLayout;
108 import java.awt.Component;
109 import java.awt.Rectangle;
110 import java.awt.Toolkit;
111 import java.awt.datatransfer.Clipboard;
112 import java.awt.datatransfer.DataFlavor;
113 import java.awt.datatransfer.StringSelection;
114 import java.awt.datatransfer.Transferable;
115 import java.awt.dnd.DnDConstants;
116 import java.awt.dnd.DropTargetDragEvent;
117 import java.awt.dnd.DropTargetDropEvent;
118 import java.awt.dnd.DropTargetEvent;
119 import java.awt.dnd.DropTargetListener;
120 import java.awt.event.ActionEvent;
121 import java.awt.event.ActionListener;
122 import java.awt.event.ItemEvent;
123 import java.awt.event.ItemListener;
124 import java.awt.event.KeyAdapter;
125 import java.awt.event.KeyEvent;
126 import java.awt.event.MouseAdapter;
127 import java.awt.event.MouseEvent;
128 import java.awt.print.PageFormat;
129 import java.awt.print.PrinterJob;
130 import java.beans.PropertyChangeEvent;
133 import java.util.ArrayList;
134 import java.util.Arrays;
135 import java.util.Deque;
136 import java.util.Enumeration;
137 import java.util.Hashtable;
138 import java.util.List;
139 import java.util.Vector;
141 import javax.swing.JCheckBoxMenuItem;
142 import javax.swing.JEditorPane;
143 import javax.swing.JInternalFrame;
144 import javax.swing.JLayeredPane;
145 import javax.swing.JMenu;
146 import javax.swing.JMenuItem;
147 import javax.swing.JOptionPane;
148 import javax.swing.JRadioButtonMenuItem;
149 import javax.swing.JScrollPane;
150 import javax.swing.SwingUtilities;
156 * @version $Revision$
158 public class AlignFrame extends GAlignFrame implements DropTargetListener,
159 IProgressIndicator, AlignViewControllerGuiI
162 public static final int DEFAULT_WIDTH = 700;
164 public static final int DEFAULT_HEIGHT = 500;
167 * The currently displayed panel (selected tabbed view if more than one)
169 public AlignmentPanel alignPanel;
171 AlignViewport viewport;
173 public AlignViewControllerI avc;
175 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
178 * Last format used to load or save alignments in this window
180 String currentFileFormat = null;
183 * Current filename for this alignment
185 String fileName = null;
188 * Creates a new AlignFrame object with specific width and height.
194 public AlignFrame(AlignmentI al, int width, int height)
196 this(al, null, width, height);
200 * Creates a new AlignFrame object with specific width, height and
206 * @param sequenceSetId
208 public AlignFrame(AlignmentI al, int width, int height,
209 String sequenceSetId)
211 this(al, null, width, height, sequenceSetId);
215 * Creates a new AlignFrame object with specific width, height and
221 * @param sequenceSetId
224 public AlignFrame(AlignmentI al, int width, int height,
225 String sequenceSetId, String viewId)
227 this(al, null, width, height, sequenceSetId, viewId);
231 * new alignment window with hidden columns
235 * @param hiddenColumns
236 * ColumnSelection or null
238 * Width of alignment frame
242 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
243 int width, int height)
245 this(al, hiddenColumns, width, height, null);
249 * Create alignment frame for al with hiddenColumns, a specific width and
250 * height, and specific sequenceId
253 * @param hiddenColumns
256 * @param sequenceSetId
259 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
260 int width, int height, String sequenceSetId)
262 this(al, hiddenColumns, width, height, sequenceSetId, null);
266 * Create alignment frame for al with hiddenColumns, a specific width and
267 * height, and specific sequenceId
270 * @param hiddenColumns
273 * @param sequenceSetId
278 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
279 int width, int height, String sequenceSetId, String viewId)
281 setSize(width, height);
283 if (al.getDataset() == null)
288 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
290 alignPanel = new AlignmentPanel(this, viewport);
292 addAlignmentPanel(alignPanel, true);
296 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
297 ColumnSelection hiddenColumns, int width, int height)
299 setSize(width, height);
301 if (al.getDataset() == null)
306 viewport = new AlignViewport(al, hiddenColumns);
308 if (hiddenSeqs != null && hiddenSeqs.length > 0)
310 viewport.hideSequence(hiddenSeqs);
312 alignPanel = new AlignmentPanel(this, viewport);
313 addAlignmentPanel(alignPanel, true);
318 * Make a new AlignFrame from existing alignmentPanels
325 public AlignFrame(AlignmentPanel ap)
329 addAlignmentPanel(ap, false);
334 * initalise the alignframe from the underlying viewport data and the
339 if (!Jalview.isHeadlessMode())
341 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
344 avc = new jalview.controller.AlignViewController(this, viewport,
346 if (viewport.getAlignmentConservationAnnotation() == null)
348 BLOSUM62Colour.setEnabled(false);
349 conservationMenuItem.setEnabled(false);
350 modifyConservation.setEnabled(false);
351 // PIDColour.setEnabled(false);
352 // abovePIDThreshold.setEnabled(false);
353 // modifyPID.setEnabled(false);
356 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
359 if (sortby.equals("Id"))
361 sortIDMenuItem_actionPerformed(null);
363 else if (sortby.equals("Pairwise Identity"))
365 sortPairwiseMenuItem_actionPerformed(null);
368 if (Desktop.desktop != null)
370 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
371 addServiceListeners();
372 setGUINucleotide(viewport.getAlignment().isNucleotide());
376 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
378 setMenusFromViewport(viewport);
379 buildSortByAnnotationScoresMenu();
382 if (viewport.getWrapAlignment())
384 wrapMenuItem_actionPerformed(null);
387 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
389 this.overviewMenuItem_actionPerformed(null);
394 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
395 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
396 final String menuLabel = MessageManager
397 .getString("label.copy_format_from");
398 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
399 new ViewSetProvider()
403 public AlignmentPanel[] getAllAlignmentPanels()
406 origview.add(alignPanel);
407 // make an array of all alignment panels except for this one
408 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
409 Arrays.asList(Desktop.getAlignmentPanels(null)));
410 aps.remove(AlignFrame.this.alignPanel);
411 return aps.toArray(new AlignmentPanel[aps.size()]);
413 }, selviews, new ItemListener()
417 public void itemStateChanged(ItemEvent e)
419 if (origview.size() > 0)
421 final AlignmentPanel ap = origview.get(0);
424 * Copy the ViewStyle of the selected panel to 'this one'.
425 * Don't change value of 'scaleProteinAsCdna' unless copying
428 ViewStyleI vs = selviews.get(0).getAlignViewport()
430 boolean fromSplitFrame = selviews.get(0)
431 .getAlignViewport().getCodingComplement() != null;
434 vs.setScaleProteinAsCdna(ap.getAlignViewport()
435 .getViewStyle().isScaleProteinAsCdna());
437 ap.getAlignViewport().setViewStyle(vs);
440 * Also rescale ViewStyle of SplitFrame complement if there is
441 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
442 * the whole ViewStyle (allow cDNA protein to have different
445 AlignViewportI complement = ap.getAlignViewport()
446 .getCodingComplement();
447 if (complement != null && vs.isScaleProteinAsCdna())
449 AlignFrame af = Desktop.getAlignFrameFor(complement);
450 ((SplitFrame) af.getSplitViewContainer())
452 af.setMenusForViewport();
456 ap.setSelected(true);
457 ap.alignFrame.setMenusForViewport();
462 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
463 .indexOf("devel") > -1
464 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
465 .indexOf("test") > -1)
467 formatMenu.add(vsel);
473 * Change the filename and format for the alignment, and enable the 'reload'
474 * button functionality.
481 public void setFileName(String file, String format)
484 setFileFormat(format);
485 reload.setEnabled(true);
489 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
492 void addKeyListener()
494 addKeyListener(new KeyAdapter()
497 public void keyPressed(KeyEvent evt)
499 if (viewport.cursorMode
500 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
501 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
502 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
503 && Character.isDigit(evt.getKeyChar()))
505 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
508 switch (evt.getKeyCode())
511 case 27: // escape key
512 deselectAllSequenceMenuItem_actionPerformed(null);
516 case KeyEvent.VK_DOWN:
517 if (evt.isAltDown() || !viewport.cursorMode)
519 moveSelectedSequences(false);
521 if (viewport.cursorMode)
523 alignPanel.getSeqPanel().moveCursor(0, 1);
528 if (evt.isAltDown() || !viewport.cursorMode)
530 moveSelectedSequences(true);
532 if (viewport.cursorMode)
534 alignPanel.getSeqPanel().moveCursor(0, -1);
539 case KeyEvent.VK_LEFT:
540 if (evt.isAltDown() || !viewport.cursorMode)
542 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
546 alignPanel.getSeqPanel().moveCursor(-1, 0);
551 case KeyEvent.VK_RIGHT:
552 if (evt.isAltDown() || !viewport.cursorMode)
554 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
558 alignPanel.getSeqPanel().moveCursor(1, 0);
562 case KeyEvent.VK_SPACE:
563 if (viewport.cursorMode)
565 alignPanel.getSeqPanel().insertGapAtCursor(
566 evt.isControlDown() || evt.isShiftDown()
571 // case KeyEvent.VK_A:
572 // if (viewport.cursorMode)
574 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
575 // //System.out.println("A");
579 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
580 * System.out.println("closing bracket"); } break;
582 case KeyEvent.VK_DELETE:
583 case KeyEvent.VK_BACK_SPACE:
584 if (!viewport.cursorMode)
586 cut_actionPerformed(null);
590 alignPanel.getSeqPanel().deleteGapAtCursor(
591 evt.isControlDown() || evt.isShiftDown()
598 if (viewport.cursorMode)
600 alignPanel.getSeqPanel().setCursorRow();
604 if (viewport.cursorMode && !evt.isControlDown())
606 alignPanel.getSeqPanel().setCursorColumn();
610 if (viewport.cursorMode)
612 alignPanel.getSeqPanel().setCursorPosition();
616 case KeyEvent.VK_ENTER:
617 case KeyEvent.VK_COMMA:
618 if (viewport.cursorMode)
620 alignPanel.getSeqPanel().setCursorRowAndColumn();
625 if (viewport.cursorMode)
627 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
631 if (viewport.cursorMode)
633 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
638 viewport.cursorMode = !viewport.cursorMode;
639 statusBar.setText(MessageManager.formatMessage(
640 "label.keyboard_editing_mode",
641 new String[] { (viewport.cursorMode ? "on" : "off") }));
642 if (viewport.cursorMode)
644 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
645 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
647 alignPanel.getSeqPanel().seqCanvas.repaint();
653 Help.showHelpWindow();
654 } catch (Exception ex)
656 ex.printStackTrace();
661 boolean toggleSeqs = !evt.isControlDown();
662 boolean toggleCols = !evt.isShiftDown();
663 toggleHiddenRegions(toggleSeqs, toggleCols);
666 case KeyEvent.VK_PAGE_UP:
667 if (viewport.getWrapAlignment())
669 alignPanel.scrollUp(true);
673 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
674 - viewport.endSeq + viewport.startSeq);
677 case KeyEvent.VK_PAGE_DOWN:
678 if (viewport.getWrapAlignment())
680 alignPanel.scrollUp(false);
684 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
685 + viewport.endSeq - viewport.startSeq);
692 public void keyReleased(KeyEvent evt)
694 switch (evt.getKeyCode())
696 case KeyEvent.VK_LEFT:
697 if (evt.isAltDown() || !viewport.cursorMode)
699 viewport.firePropertyChange("alignment", null, viewport
700 .getAlignment().getSequences());
704 case KeyEvent.VK_RIGHT:
705 if (evt.isAltDown() || !viewport.cursorMode)
707 viewport.firePropertyChange("alignment", null, viewport
708 .getAlignment().getSequences());
716 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
718 ap.alignFrame = this;
719 avc = new jalview.controller.AlignViewController(this, viewport,
724 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
726 int aSize = alignPanels.size();
728 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
730 if (aSize == 1 && ap.av.viewName == null)
732 this.getContentPane().add(ap, BorderLayout.CENTER);
738 setInitialTabVisible();
741 expandViews.setEnabled(true);
742 gatherViews.setEnabled(true);
743 tabbedPane.addTab(ap.av.viewName, ap);
745 ap.setVisible(false);
750 if (ap.av.isPadGaps())
752 ap.av.getAlignment().padGaps();
754 ap.av.updateConservation(ap);
755 ap.av.updateConsensus(ap);
756 ap.av.updateStrucConsensus(ap);
760 public void setInitialTabVisible()
762 expandViews.setEnabled(true);
763 gatherViews.setEnabled(true);
764 tabbedPane.setVisible(true);
765 AlignmentPanel first = alignPanels.get(0);
766 tabbedPane.addTab(first.av.viewName, first);
767 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
770 public AlignViewport getViewport()
775 /* Set up intrinsic listeners for dynamically generated GUI bits. */
776 private void addServiceListeners()
778 final java.beans.PropertyChangeListener thisListener;
779 Desktop.instance.addJalviewPropertyChangeListener("services",
780 thisListener = new java.beans.PropertyChangeListener()
783 public void propertyChange(PropertyChangeEvent evt)
785 // // System.out.println("Discoverer property change.");
786 // if (evt.getPropertyName().equals("services"))
788 SwingUtilities.invokeLater(new Runnable()
795 .println("Rebuild WS Menu for service change");
796 BuildWebServiceMenu();
803 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
806 public void internalFrameClosed(
807 javax.swing.event.InternalFrameEvent evt)
809 // System.out.println("deregistering discoverer listener");
810 Desktop.instance.removeJalviewPropertyChangeListener("services",
812 closeMenuItem_actionPerformed(true);
815 // Finally, build the menu once to get current service state
816 new Thread(new Runnable()
821 BuildWebServiceMenu();
827 * Configure menu items that vary according to whether the alignment is
828 * nucleotide or protein
832 public void setGUINucleotide(boolean nucleotide)
834 showTranslation.setVisible(nucleotide);
835 showReverse.setVisible(nucleotide);
836 showReverseComplement.setVisible(nucleotide);
837 conservationMenuItem.setEnabled(!nucleotide);
838 modifyConservation.setEnabled(!nucleotide);
839 showGroupConservation.setEnabled(!nucleotide);
840 rnahelicesColour.setEnabled(nucleotide);
841 purinePyrimidineColour.setEnabled(nucleotide);
842 showComplementMenuItem.setText(MessageManager
843 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
844 setColourSelected(jalview.bin.Cache.getDefault(
845 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
846 : Preferences.DEFAULT_COLOUR_PROT, "None"));
850 * set up menus for the current viewport. This may be called after any
851 * operation that affects the data in the current view (selection changed,
852 * etc) to update the menus to reflect the new state.
855 public void setMenusForViewport()
857 setMenusFromViewport(viewport);
861 * Need to call this method when tabs are selected for multiple views, or when
862 * loading from Jalview2XML.java
867 void setMenusFromViewport(AlignViewport av)
869 padGapsMenuitem.setSelected(av.isPadGaps());
870 colourTextMenuItem.setSelected(av.isShowColourText());
871 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
872 conservationMenuItem.setSelected(av.getConservationSelected());
873 seqLimits.setSelected(av.getShowJVSuffix());
874 idRightAlign.setSelected(av.isRightAlignIds());
875 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
876 renderGapsMenuItem.setSelected(av.isRenderGaps());
877 wrapMenuItem.setSelected(av.getWrapAlignment());
878 scaleAbove.setVisible(av.getWrapAlignment());
879 scaleLeft.setVisible(av.getWrapAlignment());
880 scaleRight.setVisible(av.getWrapAlignment());
881 annotationPanelMenuItem.setState(av.isShowAnnotation());
883 * Show/hide annotations only enabled if annotation panel is shown
885 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
886 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
887 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
888 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
889 viewBoxesMenuItem.setSelected(av.getShowBoxes());
890 viewTextMenuItem.setSelected(av.getShowText());
891 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
892 showGroupConsensus.setSelected(av.isShowGroupConsensus());
893 showGroupConservation.setSelected(av.isShowGroupConservation());
894 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
895 showSequenceLogo.setSelected(av.isShowSequenceLogo());
896 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
898 setColourSelected(ColourSchemeProperty.getColourName(av
899 .getGlobalColourScheme()));
901 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
902 hiddenMarkers.setState(av.getShowHiddenMarkers());
903 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
904 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
905 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
906 autoCalculate.setSelected(av.autoCalculateConsensus);
907 sortByTree.setSelected(av.sortByTree);
908 listenToViewSelections.setSelected(av.followSelection);
909 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
911 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
913 showProducts.setEnabled(canShowProducts());
918 private IProgressIndicator progressBar;
923 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
926 public void setProgressBar(String message, long id)
928 progressBar.setProgressBar(message, id);
932 public void registerHandler(final long id,
933 final IProgressIndicatorHandler handler)
935 progressBar.registerHandler(id, handler);
940 * @return true if any progress bars are still active
943 public boolean operationInProgress()
945 return progressBar.operationInProgress();
949 public void setStatus(String text)
951 statusBar.setText(text);
955 * Added so Castor Mapping file can obtain Jalview Version
957 public String getVersion()
959 return jalview.bin.Cache.getProperty("VERSION");
962 public FeatureRenderer getFeatureRenderer()
964 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
968 public void fetchSequence_actionPerformed(ActionEvent e)
970 new jalview.gui.SequenceFetcher(this);
974 public void addFromFile_actionPerformed(ActionEvent e)
976 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
980 public void reload_actionPerformed(ActionEvent e)
982 if (fileName != null)
984 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
985 // originating file's format
986 // TODO: work out how to recover feature settings for correct view(s) when
988 if (currentFileFormat.equals("Jalview"))
990 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
991 for (int i = 0; i < frames.length; i++)
993 if (frames[i] instanceof AlignFrame && frames[i] != this
994 && ((AlignFrame) frames[i]).fileName != null
995 && ((AlignFrame) frames[i]).fileName.equals(fileName))
999 frames[i].setSelected(true);
1000 Desktop.instance.closeAssociatedWindows();
1001 } catch (java.beans.PropertyVetoException ex)
1007 Desktop.instance.closeAssociatedWindows();
1009 FileLoader loader = new FileLoader();
1010 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1011 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1015 Rectangle bounds = this.getBounds();
1017 FileLoader loader = new FileLoader();
1018 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1019 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1020 protocol, currentFileFormat);
1022 newframe.setBounds(bounds);
1023 if (featureSettings != null && featureSettings.isShowing())
1025 final Rectangle fspos = featureSettings.frame.getBounds();
1026 // TODO: need a 'show feature settings' function that takes bounds -
1027 // need to refactor Desktop.addFrame
1028 newframe.featureSettings_actionPerformed(null);
1029 final FeatureSettings nfs = newframe.featureSettings;
1030 SwingUtilities.invokeLater(new Runnable()
1035 nfs.frame.setBounds(fspos);
1038 this.featureSettings.close();
1039 this.featureSettings = null;
1041 this.closeMenuItem_actionPerformed(true);
1047 public void addFromText_actionPerformed(ActionEvent e)
1049 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport
1054 public void addFromURL_actionPerformed(ActionEvent e)
1056 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1060 public void save_actionPerformed(ActionEvent e)
1062 if (fileName == null
1063 || (currentFileFormat == null || !jalview.io.FormatAdapter
1064 .isValidIOFormat(currentFileFormat, true))
1065 || fileName.startsWith("http"))
1067 saveAs_actionPerformed(null);
1071 saveAlignment(fileName, currentFileFormat);
1082 public void saveAs_actionPerformed(ActionEvent e)
1084 JalviewFileChooser chooser = new JalviewFileChooser(
1085 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1086 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1087 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1088 currentFileFormat, false);
1090 chooser.setFileView(new JalviewFileView());
1091 chooser.setDialogTitle(MessageManager
1092 .getString("label.save_alignment_to_file"));
1093 chooser.setToolTipText(MessageManager.getString("action.save"));
1095 int value = chooser.showSaveDialog(this);
1097 if (value == JalviewFileChooser.APPROVE_OPTION)
1099 currentFileFormat = chooser.getSelectedFormat();
1100 while (currentFileFormat == null)
1103 .showInternalMessageDialog(
1106 .getString("label.select_file_format_before_saving"),
1108 .getString("label.file_format_not_specified"),
1109 JOptionPane.WARNING_MESSAGE);
1110 currentFileFormat = chooser.getSelectedFormat();
1111 value = chooser.showSaveDialog(this);
1112 if (value != JalviewFileChooser.APPROVE_OPTION)
1118 fileName = chooser.getSelectedFile().getPath();
1120 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1123 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1124 if (currentFileFormat.indexOf(" ") > -1)
1126 currentFileFormat = currentFileFormat.substring(0,
1127 currentFileFormat.indexOf(" "));
1129 saveAlignment(fileName, currentFileFormat);
1133 public boolean saveAlignment(String file, String format)
1135 boolean success = true;
1137 if (format.equalsIgnoreCase("Jalview"))
1139 String shortName = title;
1141 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1143 shortName = shortName.substring(shortName
1144 .lastIndexOf(java.io.File.separatorChar) + 1);
1147 success = new Jalview2XML().saveAlignment(this, file, shortName);
1149 statusBar.setText(MessageManager.formatMessage(
1150 "label.successfully_saved_to_file_in_format", new Object[] {
1151 fileName, format }));
1156 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1158 warningMessage("Cannot save file " + fileName + " using format "
1159 + format, "Alignment output format not supported");
1160 if (!Jalview.isHeadlessMode())
1162 saveAs_actionPerformed(null);
1167 AlignmentExportData exportData = getAlignmentForExport(format,
1169 if (exportData.getSettings().isCancelled())
1173 FormatAdapter f = new FormatAdapter(alignPanel,
1174 exportData.getSettings());
1175 String output = f.formatSequences(
1177 exportData.getAlignment(), // class cast exceptions will
1178 // occur in the distant future
1179 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1180 f.getCacheSuffixDefault(format),
1181 viewport.getColumnSelection());
1191 java.io.PrintWriter out = new java.io.PrintWriter(
1192 new java.io.FileWriter(file));
1196 this.setTitle(file);
1197 statusBar.setText(MessageManager.formatMessage(
1198 "label.successfully_saved_to_file_in_format",
1199 new Object[] { fileName, format }));
1200 } catch (Exception ex)
1203 ex.printStackTrace();
1210 JOptionPane.showInternalMessageDialog(this, MessageManager
1211 .formatMessage("label.couldnt_save_file",
1212 new Object[] { fileName }), MessageManager
1213 .getString("label.error_saving_file"),
1214 JOptionPane.WARNING_MESSAGE);
1220 private void warningMessage(String warning, String title)
1222 if (new jalview.util.Platform().isHeadless())
1224 System.err.println("Warning: " + title + "\nWarning: " + warning);
1229 JOptionPane.showInternalMessageDialog(this, warning, title,
1230 JOptionPane.WARNING_MESSAGE);
1242 protected void outputText_actionPerformed(ActionEvent e)
1245 AlignmentExportData exportData = getAlignmentForExport(
1246 e.getActionCommand(), viewport, null);
1247 if (exportData.getSettings().isCancelled())
1251 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1252 cap.setForInput(null);
1255 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1256 .formatSequences(e.getActionCommand(),
1257 exportData.getAlignment(),
1258 exportData.getOmitHidden(),
1259 exportData.getStartEndPostions(),
1260 viewport.getColumnSelection()));
1261 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1262 "label.alignment_output_command",
1263 new Object[] { e.getActionCommand() }), 600, 500);
1264 } catch (OutOfMemoryError oom)
1266 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1272 public static AlignmentExportData getAlignmentForExport(
1273 String exportFormat, AlignViewportI viewport,
1274 AlignExportSettingI exportSettings)
1276 AlignmentI alignmentToExport = null;
1277 AlignExportSettingI settings = exportSettings;
1278 String[] omitHidden = null;
1280 HiddenSequences hiddenSeqs = viewport.getAlignment()
1281 .getHiddenSequences();
1283 alignmentToExport = viewport.getAlignment();
1285 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1286 if (settings == null)
1288 settings = new AlignExportSettings(hasHiddenSeqs,
1289 viewport.hasHiddenColumns(), exportFormat);
1291 // settings.isExportAnnotations();
1293 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1295 omitHidden = viewport.getViewAsString(false);
1298 int[] alignmentStartEnd = new int[2];
1299 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1301 alignmentToExport = hiddenSeqs.getFullAlignment();
1305 alignmentToExport = viewport.getAlignment();
1306 alignmentStartEnd = viewport.getAlignment()
1307 .getVisibleStartAndEndIndex(
1309 .getColumnSelection().getHiddenColumns());
1311 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1312 omitHidden, alignmentStartEnd, settings);
1324 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1326 new HtmlSvgOutput(null, alignPanel);
1330 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1332 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this);
1333 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1336 public void createImageMap(File file, String image)
1338 alignPanel.makePNGImageMap(file, image);
1348 public void createPNG(File f)
1350 alignPanel.makePNG(f);
1360 public void createEPS(File f)
1362 alignPanel.makeEPS(f);
1366 public void createSVG(File f)
1368 alignPanel.makeSVG(f);
1372 public void pageSetup_actionPerformed(ActionEvent e)
1374 PrinterJob printJob = PrinterJob.getPrinterJob();
1375 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1385 public void printMenuItem_actionPerformed(ActionEvent e)
1387 // Putting in a thread avoids Swing painting problems
1388 PrintThread thread = new PrintThread(alignPanel);
1393 public void exportFeatures_actionPerformed(ActionEvent e)
1395 new AnnotationExporter().exportFeatures(alignPanel);
1399 public void exportAnnotations_actionPerformed(ActionEvent e)
1401 new AnnotationExporter().exportAnnotations(alignPanel);
1405 public void associatedData_actionPerformed(ActionEvent e)
1407 // Pick the tree file
1408 JalviewFileChooser chooser = new JalviewFileChooser(
1409 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1410 chooser.setFileView(new JalviewFileView());
1411 chooser.setDialogTitle(MessageManager
1412 .getString("label.load_jalview_annotations"));
1413 chooser.setToolTipText(MessageManager
1414 .getString("label.load_jalview_annotations"));
1416 int value = chooser.showOpenDialog(null);
1418 if (value == JalviewFileChooser.APPROVE_OPTION)
1420 String choice = chooser.getSelectedFile().getPath();
1421 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1422 loadJalviewDataFile(choice, null, null, null);
1428 * Close the current view or all views in the alignment frame. If the frame
1429 * only contains one view then the alignment will be removed from memory.
1431 * @param closeAllTabs
1434 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1436 if (alignPanels != null && alignPanels.size() < 2)
1438 closeAllTabs = true;
1443 if (alignPanels != null)
1447 if (this.isClosed())
1449 // really close all the windows - otherwise wait till
1450 // setClosed(true) is called
1451 for (int i = 0; i < alignPanels.size(); i++)
1453 AlignmentPanel ap = alignPanels.get(i);
1460 closeView(alignPanel);
1467 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1468 * be called recursively, with the frame now in 'closed' state
1470 this.setClosed(true);
1472 } catch (Exception ex)
1474 ex.printStackTrace();
1479 * Close the specified panel and close up tabs appropriately.
1481 * @param panelToClose
1483 public void closeView(AlignmentPanel panelToClose)
1485 int index = tabbedPane.getSelectedIndex();
1486 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1487 alignPanels.remove(panelToClose);
1488 panelToClose.closePanel();
1489 panelToClose = null;
1491 tabbedPane.removeTabAt(closedindex);
1492 tabbedPane.validate();
1494 if (index > closedindex || index == tabbedPane.getTabCount())
1496 // modify currently selected tab index if necessary.
1500 this.tabSelectionChanged(index);
1506 void updateEditMenuBar()
1509 if (viewport.getHistoryList().size() > 0)
1511 undoMenuItem.setEnabled(true);
1512 CommandI command = viewport.getHistoryList().peek();
1513 undoMenuItem.setText(MessageManager.formatMessage(
1514 "label.undo_command",
1515 new Object[] { command.getDescription() }));
1519 undoMenuItem.setEnabled(false);
1520 undoMenuItem.setText(MessageManager.getString("action.undo"));
1523 if (viewport.getRedoList().size() > 0)
1525 redoMenuItem.setEnabled(true);
1527 CommandI command = viewport.getRedoList().peek();
1528 redoMenuItem.setText(MessageManager.formatMessage(
1529 "label.redo_command",
1530 new Object[] { command.getDescription() }));
1534 redoMenuItem.setEnabled(false);
1535 redoMenuItem.setText(MessageManager.getString("action.redo"));
1540 public void addHistoryItem(CommandI command)
1542 if (command.getSize() > 0)
1544 viewport.addToHistoryList(command);
1545 viewport.clearRedoList();
1546 updateEditMenuBar();
1547 viewport.updateHiddenColumns();
1548 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1549 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1550 // viewport.getColumnSelection()
1551 // .getHiddenColumns().size() > 0);
1557 * @return alignment objects for all views
1559 AlignmentI[] getViewAlignments()
1561 if (alignPanels != null)
1563 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1565 for (AlignmentPanel ap : alignPanels)
1567 als[i++] = ap.av.getAlignment();
1571 if (viewport != null)
1573 return new AlignmentI[] { viewport.getAlignment() };
1585 protected void undoMenuItem_actionPerformed(ActionEvent e)
1587 if (viewport.getHistoryList().isEmpty())
1591 CommandI command = viewport.getHistoryList().pop();
1592 viewport.addToRedoList(command);
1593 command.undoCommand(getViewAlignments());
1595 AlignmentViewport originalSource = getOriginatingSource(command);
1596 updateEditMenuBar();
1598 if (originalSource != null)
1600 if (originalSource != viewport)
1603 .warn("Implementation worry: mismatch of viewport origin for undo");
1605 originalSource.updateHiddenColumns();
1606 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1608 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1609 // viewport.getColumnSelection()
1610 // .getHiddenColumns().size() > 0);
1611 originalSource.firePropertyChange("alignment", null, originalSource
1612 .getAlignment().getSequences());
1623 protected void redoMenuItem_actionPerformed(ActionEvent e)
1625 if (viewport.getRedoList().size() < 1)
1630 CommandI command = viewport.getRedoList().pop();
1631 viewport.addToHistoryList(command);
1632 command.doCommand(getViewAlignments());
1634 AlignmentViewport originalSource = getOriginatingSource(command);
1635 updateEditMenuBar();
1637 if (originalSource != null)
1640 if (originalSource != viewport)
1643 .warn("Implementation worry: mismatch of viewport origin for redo");
1645 originalSource.updateHiddenColumns();
1646 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1648 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1649 // viewport.getColumnSelection()
1650 // .getHiddenColumns().size() > 0);
1651 originalSource.firePropertyChange("alignment", null, originalSource
1652 .getAlignment().getSequences());
1656 AlignmentViewport getOriginatingSource(CommandI command)
1658 AlignmentViewport originalSource = null;
1659 // For sequence removal and addition, we need to fire
1660 // the property change event FROM the viewport where the
1661 // original alignment was altered
1662 AlignmentI al = null;
1663 if (command instanceof EditCommand)
1665 EditCommand editCommand = (EditCommand) command;
1666 al = editCommand.getAlignment();
1667 List<Component> comps = PaintRefresher.components.get(viewport
1668 .getSequenceSetId());
1670 for (Component comp : comps)
1672 if (comp instanceof AlignmentPanel)
1674 if (al == ((AlignmentPanel) comp).av.getAlignment())
1676 originalSource = ((AlignmentPanel) comp).av;
1683 if (originalSource == null)
1685 // The original view is closed, we must validate
1686 // the current view against the closed view first
1689 PaintRefresher.validateSequences(al, viewport.getAlignment());
1692 originalSource = viewport;
1695 return originalSource;
1704 public void moveSelectedSequences(boolean up)
1706 SequenceGroup sg = viewport.getSelectionGroup();
1712 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1713 viewport.getHiddenRepSequences(), up);
1714 alignPanel.paintAlignment(true);
1717 synchronized void slideSequences(boolean right, int size)
1719 List<SequenceI> sg = new ArrayList<SequenceI>();
1720 if (viewport.cursorMode)
1722 sg.add(viewport.getAlignment().getSequenceAt(
1723 alignPanel.getSeqPanel().seqCanvas.cursorY));
1725 else if (viewport.getSelectionGroup() != null
1726 && viewport.getSelectionGroup().getSize() != viewport
1727 .getAlignment().getHeight())
1729 sg = viewport.getSelectionGroup().getSequences(
1730 viewport.getHiddenRepSequences());
1738 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1740 for (SequenceI seq : viewport.getAlignment().getSequences())
1742 if (!sg.contains(seq))
1744 invertGroup.add(seq);
1748 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1750 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1751 for (int i = 0; i < invertGroup.size(); i++)
1753 seqs2[i] = invertGroup.get(i);
1756 SlideSequencesCommand ssc;
1759 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1760 size, viewport.getGapCharacter());
1764 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1765 size, viewport.getGapCharacter());
1768 int groupAdjustment = 0;
1769 if (ssc.getGapsInsertedBegin() && right)
1771 if (viewport.cursorMode)
1773 alignPanel.getSeqPanel().moveCursor(size, 0);
1777 groupAdjustment = size;
1780 else if (!ssc.getGapsInsertedBegin() && !right)
1782 if (viewport.cursorMode)
1784 alignPanel.getSeqPanel().moveCursor(-size, 0);
1788 groupAdjustment = -size;
1792 if (groupAdjustment != 0)
1794 viewport.getSelectionGroup().setStartRes(
1795 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1796 viewport.getSelectionGroup().setEndRes(
1797 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1801 * just extend the last slide command if compatible; but not if in
1802 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1804 boolean appendHistoryItem = false;
1805 Deque<CommandI> historyList = viewport.getHistoryList();
1806 boolean inSplitFrame = getSplitViewContainer() != null;
1807 if (!inSplitFrame && historyList != null && historyList.size() > 0
1808 && historyList.peek() instanceof SlideSequencesCommand)
1810 appendHistoryItem = ssc
1811 .appendSlideCommand((SlideSequencesCommand) historyList
1815 if (!appendHistoryItem)
1817 addHistoryItem(ssc);
1830 protected void copy_actionPerformed(ActionEvent e)
1833 if (viewport.getSelectionGroup() == null)
1837 // TODO: preserve the ordering of displayed alignment annotation in any
1838 // internal paste (particularly sequence associated annotation)
1839 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1840 String[] omitHidden = null;
1842 if (viewport.hasHiddenColumns())
1844 omitHidden = viewport.getViewAsString(true);
1847 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1850 StringSelection ss = new StringSelection(output);
1854 jalview.gui.Desktop.internalCopy = true;
1855 // Its really worth setting the clipboard contents
1856 // to empty before setting the large StringSelection!!
1857 Toolkit.getDefaultToolkit().getSystemClipboard()
1858 .setContents(new StringSelection(""), null);
1860 Toolkit.getDefaultToolkit().getSystemClipboard()
1861 .setContents(ss, Desktop.instance);
1862 } catch (OutOfMemoryError er)
1864 new OOMWarning("copying region", er);
1868 ArrayList<int[]> hiddenColumns = null;
1869 if (viewport.hasHiddenColumns())
1871 hiddenColumns = new ArrayList<int[]>();
1872 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1873 .getSelectionGroup().getEndRes();
1874 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1876 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1878 hiddenColumns.add(new int[] { region[0] - hiddenOffset,
1879 region[1] - hiddenOffset });
1884 Desktop.jalviewClipboard = new Object[] { seqs,
1885 viewport.getAlignment().getDataset(), hiddenColumns };
1886 statusBar.setText(MessageManager.formatMessage(
1887 "label.copied_sequences_to_clipboard", new Object[] { Integer
1888 .valueOf(seqs.length).toString() }));
1898 protected void pasteNew_actionPerformed(ActionEvent e)
1910 protected void pasteThis_actionPerformed(ActionEvent e)
1916 * Paste contents of Jalview clipboard
1918 * @param newAlignment
1919 * true to paste to a new alignment, otherwise add to this.
1921 void paste(boolean newAlignment)
1923 boolean externalPaste = true;
1926 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1927 Transferable contents = c.getContents(this);
1929 if (contents == null)
1937 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1938 if (str.length() < 1)
1943 format = new IdentifyFile().identify(str, "Paste");
1945 } catch (OutOfMemoryError er)
1947 new OOMWarning("Out of memory pasting sequences!!", er);
1951 SequenceI[] sequences;
1952 boolean annotationAdded = false;
1953 AlignmentI alignment = null;
1955 if (Desktop.jalviewClipboard != null)
1957 // The clipboard was filled from within Jalview, we must use the
1959 // And dataset from the copied alignment
1960 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1961 // be doubly sure that we create *new* sequence objects.
1962 sequences = new SequenceI[newseq.length];
1963 for (int i = 0; i < newseq.length; i++)
1965 sequences[i] = new Sequence(newseq[i]);
1967 alignment = new Alignment(sequences);
1968 externalPaste = false;
1972 // parse the clipboard as an alignment.
1973 alignment = new FormatAdapter().readFile(str, "Paste", format);
1974 sequences = alignment.getSequencesArray();
1978 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1984 if (Desktop.jalviewClipboard != null)
1986 // dataset is inherited
1987 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1991 // new dataset is constructed
1992 alignment.setDataset(null);
1994 alwidth = alignment.getWidth() + 1;
1998 AlignmentI pastedal = alignment; // preserve pasted alignment object
1999 // Add pasted sequences and dataset into existing alignment.
2000 alignment = viewport.getAlignment();
2001 alwidth = alignment.getWidth() + 1;
2002 // decide if we need to import sequences from an existing dataset
2003 boolean importDs = Desktop.jalviewClipboard != null
2004 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2005 // importDs==true instructs us to copy over new dataset sequences from
2006 // an existing alignment
2007 Vector newDs = (importDs) ? new Vector() : null; // used to create
2008 // minimum dataset set
2010 for (int i = 0; i < sequences.length; i++)
2014 newDs.addElement(null);
2016 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2018 if (importDs && ds != null)
2020 if (!newDs.contains(ds))
2022 newDs.setElementAt(ds, i);
2023 ds = new Sequence(ds);
2024 // update with new dataset sequence
2025 sequences[i].setDatasetSequence(ds);
2029 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2034 // copy and derive new dataset sequence
2035 sequences[i] = sequences[i].deriveSequence();
2036 alignment.getDataset().addSequence(
2037 sequences[i].getDatasetSequence());
2038 // TODO: avoid creation of duplicate dataset sequences with a
2039 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2041 alignment.addSequence(sequences[i]); // merges dataset
2045 newDs.clear(); // tidy up
2047 if (alignment.getAlignmentAnnotation() != null)
2049 for (AlignmentAnnotation alan : alignment
2050 .getAlignmentAnnotation())
2052 if (alan.graphGroup > fgroup)
2054 fgroup = alan.graphGroup;
2058 if (pastedal.getAlignmentAnnotation() != null)
2060 // Add any annotation attached to alignment.
2061 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2062 for (int i = 0; i < alann.length; i++)
2064 annotationAdded = true;
2065 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2067 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2068 if (newann.graphGroup > -1)
2070 if (newGraphGroups.size() <= newann.graphGroup
2071 || newGraphGroups.get(newann.graphGroup) == null)
2073 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2075 newGraphGroups.add(q, null);
2077 newGraphGroups.set(newann.graphGroup, new Integer(
2080 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2084 newann.padAnnotation(alwidth);
2085 alignment.addAnnotation(newann);
2095 addHistoryItem(new EditCommand(
2096 MessageManager.getString("label.add_sequences"),
2097 Action.PASTE, sequences, 0, alignment.getWidth(), alignment));
2099 // Add any annotations attached to sequences
2100 for (int i = 0; i < sequences.length; i++)
2102 if (sequences[i].getAnnotation() != null)
2104 AlignmentAnnotation newann;
2105 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2107 annotationAdded = true;
2108 newann = sequences[i].getAnnotation()[a];
2109 newann.adjustForAlignment();
2110 newann.padAnnotation(alwidth);
2111 if (newann.graphGroup > -1)
2113 if (newann.graphGroup > -1)
2115 if (newGraphGroups.size() <= newann.graphGroup
2116 || newGraphGroups.get(newann.graphGroup) == null)
2118 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2120 newGraphGroups.add(q, null);
2122 newGraphGroups.set(newann.graphGroup, new Integer(
2125 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2129 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2134 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2141 // propagate alignment changed.
2142 viewport.setEndSeq(alignment.getHeight());
2143 if (annotationAdded)
2145 // Duplicate sequence annotation in all views.
2146 AlignmentI[] alview = this.getViewAlignments();
2147 for (int i = 0; i < sequences.length; i++)
2149 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2154 for (int avnum = 0; avnum < alview.length; avnum++)
2156 if (alview[avnum] != alignment)
2158 // duplicate in a view other than the one with input focus
2159 int avwidth = alview[avnum].getWidth() + 1;
2160 // this relies on sann being preserved after we
2161 // modify the sequence's annotation array for each duplication
2162 for (int a = 0; a < sann.length; a++)
2164 AlignmentAnnotation newann = new AlignmentAnnotation(
2166 sequences[i].addAlignmentAnnotation(newann);
2167 newann.padAnnotation(avwidth);
2168 alview[avnum].addAnnotation(newann); // annotation was
2169 // duplicated earlier
2170 // TODO JAL-1145 graphGroups are not updated for sequence
2171 // annotation added to several views. This may cause
2173 alview[avnum].setAnnotationIndex(newann, a);
2178 buildSortByAnnotationScoresMenu();
2180 viewport.firePropertyChange("alignment", null,
2181 alignment.getSequences());
2182 if (alignPanels != null)
2184 for (AlignmentPanel ap : alignPanels)
2186 ap.validateAnnotationDimensions(false);
2191 alignPanel.validateAnnotationDimensions(false);
2197 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2199 String newtitle = new String("Copied sequences");
2201 if (Desktop.jalviewClipboard != null
2202 && Desktop.jalviewClipboard[2] != null)
2204 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2205 for (int[] region : hc)
2207 af.viewport.hideColumns(region[0], region[1]);
2211 // >>>This is a fix for the moment, until a better solution is
2213 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2215 alignPanel.getSeqPanel().seqCanvas
2216 .getFeatureRenderer());
2218 // TODO: maintain provenance of an alignment, rather than just make the
2219 // title a concatenation of operations.
2222 if (title.startsWith("Copied sequences"))
2228 newtitle = newtitle.concat("- from " + title);
2233 newtitle = new String("Pasted sequences");
2236 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2241 } catch (Exception ex)
2243 ex.printStackTrace();
2244 System.out.println("Exception whilst pasting: " + ex);
2245 // could be anything being pasted in here
2251 protected void expand_newalign(ActionEvent e)
2255 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2256 .getAlignment(), -1);
2257 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2259 String newtitle = new String("Flanking alignment");
2261 if (Desktop.jalviewClipboard != null
2262 && Desktop.jalviewClipboard[2] != null)
2264 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2265 for (int region[] : hc)
2267 af.viewport.hideColumns(region[0], region[1]);
2271 // >>>This is a fix for the moment, until a better solution is
2273 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2275 alignPanel.getSeqPanel().seqCanvas
2276 .getFeatureRenderer());
2278 // TODO: maintain provenance of an alignment, rather than just make the
2279 // title a concatenation of operations.
2281 if (title.startsWith("Copied sequences"))
2287 newtitle = newtitle.concat("- from " + title);
2291 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2293 } catch (Exception ex)
2295 ex.printStackTrace();
2296 System.out.println("Exception whilst pasting: " + ex);
2297 // could be anything being pasted in here
2298 } catch (OutOfMemoryError oom)
2300 new OOMWarning("Viewing flanking region of alignment", oom);
2311 protected void cut_actionPerformed(ActionEvent e)
2313 copy_actionPerformed(null);
2314 delete_actionPerformed(null);
2324 protected void delete_actionPerformed(ActionEvent evt)
2327 SequenceGroup sg = viewport.getSelectionGroup();
2334 * If the cut affects all sequences, warn, remove highlighted columns
2336 if (sg.getSize() == viewport.getAlignment().getHeight())
2338 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2339 .getAlignment().getWidth()) ? true : false;
2340 if (isEntireAlignWidth)
2342 int confirm = JOptionPane.showConfirmDialog(this,
2343 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2344 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2345 JOptionPane.OK_CANCEL_OPTION);
2347 if (confirm == JOptionPane.CANCEL_OPTION
2348 || confirm == JOptionPane.CLOSED_OPTION)
2353 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2354 sg.getEndRes() + 1);
2356 SequenceI[] cut = sg.getSequences()
2357 .toArray(new SequenceI[sg.getSize()]);
2359 addHistoryItem(new EditCommand(
2360 MessageManager.getString("label.cut_sequences"), Action.CUT,
2361 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2362 viewport.getAlignment()));
2364 viewport.setSelectionGroup(null);
2365 viewport.sendSelection();
2366 viewport.getAlignment().deleteGroup(sg);
2368 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2370 if (viewport.getAlignment().getHeight() < 1)
2374 this.setClosed(true);
2375 } catch (Exception ex)
2388 protected void deleteGroups_actionPerformed(ActionEvent e)
2390 if (avc.deleteGroups())
2392 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2393 alignPanel.updateAnnotation();
2394 alignPanel.paintAlignment(true);
2405 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2407 SequenceGroup sg = new SequenceGroup();
2409 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2411 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2414 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2415 viewport.setSelectionGroup(sg);
2416 viewport.sendSelection();
2417 alignPanel.paintAlignment(true);
2418 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2428 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2430 if (viewport.cursorMode)
2432 alignPanel.getSeqPanel().keyboardNo1 = null;
2433 alignPanel.getSeqPanel().keyboardNo2 = null;
2435 viewport.setSelectionGroup(null);
2436 viewport.getColumnSelection().clear();
2437 viewport.setSelectionGroup(null);
2438 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2439 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2440 alignPanel.paintAlignment(true);
2441 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2442 viewport.sendSelection();
2452 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2454 SequenceGroup sg = viewport.getSelectionGroup();
2458 selectAllSequenceMenuItem_actionPerformed(null);
2463 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2465 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2468 alignPanel.paintAlignment(true);
2469 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2470 viewport.sendSelection();
2474 public void invertColSel_actionPerformed(ActionEvent e)
2476 viewport.invertColumnSelection();
2477 alignPanel.paintAlignment(true);
2478 viewport.sendSelection();
2488 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2490 trimAlignment(true);
2500 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2502 trimAlignment(false);
2505 void trimAlignment(boolean trimLeft)
2507 ColumnSelection colSel = viewport.getColumnSelection();
2510 if (!colSel.isEmpty())
2514 column = colSel.getMin();
2518 column = colSel.getMax();
2522 if (viewport.getSelectionGroup() != null)
2524 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2525 viewport.getHiddenRepSequences());
2529 seqs = viewport.getAlignment().getSequencesArray();
2532 TrimRegionCommand trimRegion;
2535 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2536 column, viewport.getAlignment());
2537 viewport.setStartRes(0);
2541 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2542 column, viewport.getAlignment());
2545 statusBar.setText(MessageManager.formatMessage(
2546 "label.removed_columns",
2547 new String[] { Integer.valueOf(trimRegion.getSize())
2550 addHistoryItem(trimRegion);
2552 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2554 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2555 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2557 viewport.getAlignment().deleteGroup(sg);
2561 viewport.firePropertyChange("alignment", null, viewport
2562 .getAlignment().getSequences());
2573 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2575 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2578 if (viewport.getSelectionGroup() != null)
2580 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2581 viewport.getHiddenRepSequences());
2582 start = viewport.getSelectionGroup().getStartRes();
2583 end = viewport.getSelectionGroup().getEndRes();
2587 seqs = viewport.getAlignment().getSequencesArray();
2590 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2591 "Remove Gapped Columns", seqs, start, end,
2592 viewport.getAlignment());
2594 addHistoryItem(removeGapCols);
2596 statusBar.setText(MessageManager.formatMessage(
2597 "label.removed_empty_columns",
2598 new Object[] { Integer.valueOf(removeGapCols.getSize())
2601 // This is to maintain viewport position on first residue
2602 // of first sequence
2603 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2604 int startRes = seq.findPosition(viewport.startRes);
2605 // ShiftList shifts;
2606 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2607 // edit.alColumnChanges=shifts.getInverse();
2608 // if (viewport.hasHiddenColumns)
2609 // viewport.getColumnSelection().compensateForEdits(shifts);
2610 viewport.setStartRes(seq.findIndex(startRes) - 1);
2611 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2623 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2625 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2628 if (viewport.getSelectionGroup() != null)
2630 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2631 viewport.getHiddenRepSequences());
2632 start = viewport.getSelectionGroup().getStartRes();
2633 end = viewport.getSelectionGroup().getEndRes();
2637 seqs = viewport.getAlignment().getSequencesArray();
2640 // This is to maintain viewport position on first residue
2641 // of first sequence
2642 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2643 int startRes = seq.findPosition(viewport.startRes);
2645 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2646 viewport.getAlignment()));
2648 viewport.setStartRes(seq.findIndex(startRes) - 1);
2650 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2662 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2664 viewport.setPadGaps(padGapsMenuitem.isSelected());
2665 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2676 public void findMenuItem_actionPerformed(ActionEvent e)
2682 * Create a new view of the current alignment.
2685 public void newView_actionPerformed(ActionEvent e)
2687 newView(null, true);
2691 * Creates and shows a new view of the current alignment.
2694 * title of newly created view; if null, one will be generated
2695 * @param copyAnnotation
2696 * if true then duplicate all annnotation, groups and settings
2697 * @return new alignment panel, already displayed.
2699 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2702 * Create a new AlignmentPanel (with its own, new Viewport)
2704 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2706 if (!copyAnnotation)
2709 * remove all groups and annotation except for the automatic stuff
2711 newap.av.getAlignment().deleteAllGroups();
2712 newap.av.getAlignment().deleteAllAnnotations(false);
2715 newap.av.setGatherViewsHere(false);
2717 if (viewport.viewName == null)
2719 viewport.viewName = MessageManager
2720 .getString("label.view_name_original");
2724 * Views share the same edits undo and redo stacks
2726 newap.av.setHistoryList(viewport.getHistoryList());
2727 newap.av.setRedoList(viewport.getRedoList());
2730 * Views share the same mappings; need to deregister any new mappings
2731 * created by copyAlignPanel, and register the new reference to the shared
2734 newap.av.replaceMappings(viewport.getAlignment());
2736 newap.av.viewName = getNewViewName(viewTitle);
2738 addAlignmentPanel(newap, true);
2739 newap.alignmentChanged();
2741 if (alignPanels.size() == 2)
2743 viewport.setGatherViewsHere(true);
2745 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2750 * Make a new name for the view, ensuring it is unique within the current
2751 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2752 * these now use viewId. Unique view names are still desirable for usability.)
2757 protected String getNewViewName(String viewTitle)
2759 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2760 boolean addFirstIndex = false;
2761 if (viewTitle == null || viewTitle.trim().length() == 0)
2763 viewTitle = MessageManager.getString("action.view");
2764 addFirstIndex = true;
2768 index = 1;// we count from 1 if given a specific name
2770 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2772 List<Component> comps = PaintRefresher.components.get(viewport
2773 .getSequenceSetId());
2775 List<String> existingNames = getExistingViewNames(comps);
2777 while (existingNames.contains(newViewName))
2779 newViewName = viewTitle + " " + (++index);
2785 * Returns a list of distinct view names found in the given list of
2786 * components. View names are held on the viewport of an AlignmentPanel.
2791 protected List<String> getExistingViewNames(List<Component> comps)
2793 List<String> existingNames = new ArrayList<String>();
2794 for (Component comp : comps)
2796 if (comp instanceof AlignmentPanel)
2798 AlignmentPanel ap = (AlignmentPanel) comp;
2799 if (!existingNames.contains(ap.av.viewName))
2801 existingNames.add(ap.av.viewName);
2805 return existingNames;
2809 * Explode tabbed views into separate windows.
2812 public void expandViews_actionPerformed(ActionEvent e)
2814 Desktop.instance.explodeViews(this);
2818 * Gather views in separate windows back into a tabbed presentation.
2821 public void gatherViews_actionPerformed(ActionEvent e)
2823 Desktop.instance.gatherViews(this);
2833 public void font_actionPerformed(ActionEvent e)
2835 new FontChooser(alignPanel);
2845 protected void seqLimit_actionPerformed(ActionEvent e)
2847 viewport.setShowJVSuffix(seqLimits.isSelected());
2849 alignPanel.getIdPanel().getIdCanvas()
2850 .setPreferredSize(alignPanel.calculateIdWidth());
2851 alignPanel.paintAlignment(true);
2855 public void idRightAlign_actionPerformed(ActionEvent e)
2857 viewport.setRightAlignIds(idRightAlign.isSelected());
2858 alignPanel.paintAlignment(true);
2862 public void centreColumnLabels_actionPerformed(ActionEvent e)
2864 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2865 alignPanel.paintAlignment(true);
2871 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2874 protected void followHighlight_actionPerformed()
2877 * Set the 'follow' flag on the Viewport (and scroll to position if now
2880 final boolean state = this.followHighlightMenuItem.getState();
2881 viewport.setFollowHighlight(state);
2884 alignPanel.scrollToPosition(
2885 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2896 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2898 viewport.setColourText(colourTextMenuItem.isSelected());
2899 alignPanel.paintAlignment(true);
2909 public void wrapMenuItem_actionPerformed(ActionEvent e)
2911 scaleAbove.setVisible(wrapMenuItem.isSelected());
2912 scaleLeft.setVisible(wrapMenuItem.isSelected());
2913 scaleRight.setVisible(wrapMenuItem.isSelected());
2914 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2915 alignPanel.updateLayout();
2919 public void showAllSeqs_actionPerformed(ActionEvent e)
2921 viewport.showAllHiddenSeqs();
2925 public void showAllColumns_actionPerformed(ActionEvent e)
2927 viewport.showAllHiddenColumns();
2929 viewport.sendSelection();
2933 public void hideSelSequences_actionPerformed(ActionEvent e)
2935 viewport.hideAllSelectedSeqs();
2936 // alignPanel.paintAlignment(true);
2940 * called by key handler and the hide all/show all menu items
2945 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2948 boolean hide = false;
2949 SequenceGroup sg = viewport.getSelectionGroup();
2950 if (!toggleSeqs && !toggleCols)
2952 // Hide everything by the current selection - this is a hack - we do the
2953 // invert and then hide
2954 // first check that there will be visible columns after the invert.
2955 if ((viewport.getColumnSelection() != null
2956 && viewport.getColumnSelection().getSelected() != null && viewport
2957 .getColumnSelection().getSelected().size() > 0)
2958 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2961 // now invert the sequence set, if required - empty selection implies
2962 // that no hiding is required.
2965 invertSequenceMenuItem_actionPerformed(null);
2966 sg = viewport.getSelectionGroup();
2970 viewport.expandColSelection(sg, true);
2971 // finally invert the column selection and get the new sequence
2973 invertColSel_actionPerformed(null);
2980 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2982 hideSelSequences_actionPerformed(null);
2985 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2988 showAllSeqs_actionPerformed(null);
2994 if (viewport.getColumnSelection().getSelected().size() > 0)
2996 hideSelColumns_actionPerformed(null);
2999 viewport.setSelectionGroup(sg);
3004 showAllColumns_actionPerformed(null);
3013 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3014 * event.ActionEvent)
3017 public void hideAllButSelection_actionPerformed(ActionEvent e)
3019 toggleHiddenRegions(false, false);
3020 viewport.sendSelection();
3027 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3031 public void hideAllSelection_actionPerformed(ActionEvent e)
3033 SequenceGroup sg = viewport.getSelectionGroup();
3034 viewport.expandColSelection(sg, false);
3035 viewport.hideAllSelectedSeqs();
3036 viewport.hideSelectedColumns();
3037 alignPanel.paintAlignment(true);
3038 viewport.sendSelection();
3045 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3049 public void showAllhidden_actionPerformed(ActionEvent e)
3051 viewport.showAllHiddenColumns();
3052 viewport.showAllHiddenSeqs();
3053 alignPanel.paintAlignment(true);
3054 viewport.sendSelection();
3058 public void hideSelColumns_actionPerformed(ActionEvent e)
3060 viewport.hideSelectedColumns();
3061 alignPanel.paintAlignment(true);
3062 viewport.sendSelection();
3066 public void hiddenMarkers_actionPerformed(ActionEvent e)
3068 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3079 protected void scaleAbove_actionPerformed(ActionEvent e)
3081 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3082 alignPanel.paintAlignment(true);
3092 protected void scaleLeft_actionPerformed(ActionEvent e)
3094 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3095 alignPanel.paintAlignment(true);
3105 protected void scaleRight_actionPerformed(ActionEvent e)
3107 viewport.setScaleRightWrapped(scaleRight.isSelected());
3108 alignPanel.paintAlignment(true);
3118 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3120 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3121 alignPanel.paintAlignment(true);
3131 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3133 viewport.setShowText(viewTextMenuItem.isSelected());
3134 alignPanel.paintAlignment(true);
3144 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3146 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3147 alignPanel.paintAlignment(true);
3150 public FeatureSettings featureSettings;
3153 public FeatureSettingsControllerI getFeatureSettingsUI()
3155 return featureSettings;
3159 public void featureSettings_actionPerformed(ActionEvent e)
3161 if (featureSettings != null)
3163 featureSettings.close();
3164 featureSettings = null;
3166 if (!showSeqFeatures.isSelected())
3168 // make sure features are actually displayed
3169 showSeqFeatures.setSelected(true);
3170 showSeqFeatures_actionPerformed(null);
3172 featureSettings = new FeatureSettings(this);
3176 * Set or clear 'Show Sequence Features'
3182 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3184 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3185 alignPanel.paintAlignment(true);
3186 if (alignPanel.getOverviewPanel() != null)
3188 alignPanel.getOverviewPanel().updateOverviewImage();
3193 * Set or clear 'Show Sequence Features'
3199 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3201 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3203 if (viewport.isShowSequenceFeaturesHeight())
3205 // ensure we're actually displaying features
3206 viewport.setShowSequenceFeatures(true);
3207 showSeqFeatures.setSelected(true);
3209 alignPanel.paintAlignment(true);
3210 if (alignPanel.getOverviewPanel() != null)
3212 alignPanel.getOverviewPanel().updateOverviewImage();
3217 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3218 * the annotations panel as a whole.
3220 * The options to show/hide all annotations should be enabled when the panel
3221 * is shown, and disabled when the panel is hidden.
3226 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3228 final boolean setVisible = annotationPanelMenuItem.isSelected();
3229 viewport.setShowAnnotation(setVisible);
3230 this.showAllSeqAnnotations.setEnabled(setVisible);
3231 this.hideAllSeqAnnotations.setEnabled(setVisible);
3232 this.showAllAlAnnotations.setEnabled(setVisible);
3233 this.hideAllAlAnnotations.setEnabled(setVisible);
3234 alignPanel.updateLayout();
3238 public void alignmentProperties()
3240 JEditorPane editPane = new JEditorPane("text/html", "");
3241 editPane.setEditable(false);
3242 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3244 editPane.setText(MessageManager.formatMessage("label.html_content",
3245 new Object[] { contents.toString() }));
3246 JInternalFrame frame = new JInternalFrame();
3247 frame.getContentPane().add(new JScrollPane(editPane));
3249 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3250 "label.alignment_properties", new Object[] { getTitle() }),
3261 public void overviewMenuItem_actionPerformed(ActionEvent e)
3263 if (alignPanel.overviewPanel != null)
3268 JInternalFrame frame = new JInternalFrame();
3269 OverviewPanel overview = new OverviewPanel(alignPanel);
3270 frame.setContentPane(overview);
3271 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3272 "label.overview_params", new Object[] { this.getTitle() }),
3273 frame.getWidth(), frame.getHeight());
3275 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3276 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3279 public void internalFrameClosed(
3280 javax.swing.event.InternalFrameEvent evt)
3282 alignPanel.setOverviewPanel(null);
3286 alignPanel.setOverviewPanel(overview);
3290 public void textColour_actionPerformed(ActionEvent e)
3292 new TextColourChooser().chooseColour(alignPanel, null);
3302 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3314 public void clustalColour_actionPerformed(ActionEvent e)
3316 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3317 viewport.getHiddenRepSequences()));
3327 public void zappoColour_actionPerformed(ActionEvent e)
3329 changeColour(new ZappoColourScheme());
3339 public void taylorColour_actionPerformed(ActionEvent e)
3341 changeColour(new TaylorColourScheme());
3351 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3353 changeColour(new HydrophobicColourScheme());
3363 public void helixColour_actionPerformed(ActionEvent e)
3365 changeColour(new HelixColourScheme());
3375 public void strandColour_actionPerformed(ActionEvent e)
3377 changeColour(new StrandColourScheme());
3387 public void turnColour_actionPerformed(ActionEvent e)
3389 changeColour(new TurnColourScheme());
3399 public void buriedColour_actionPerformed(ActionEvent e)
3401 changeColour(new BuriedColourScheme());
3411 public void nucleotideColour_actionPerformed(ActionEvent e)
3413 changeColour(new NucleotideColourScheme());
3417 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3419 changeColour(new PurinePyrimidineColourScheme());
3423 * public void covariationColour_actionPerformed(ActionEvent e) {
3425 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3429 public void annotationColour_actionPerformed(ActionEvent e)
3431 new AnnotationColourChooser(viewport, alignPanel);
3435 public void annotationColumn_actionPerformed(ActionEvent e)
3437 new AnnotationColumnChooser(viewport, alignPanel);
3441 public void rnahelicesColour_actionPerformed(ActionEvent e)
3443 new RNAHelicesColourChooser(viewport, alignPanel);
3453 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3455 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3465 public void changeColour(ColourSchemeI cs)
3467 // TODO: pull up to controller method
3471 // Make sure viewport is up to date w.r.t. any sliders
3472 if (viewport.getAbovePIDThreshold())
3474 int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3476 viewport.setThreshold(threshold);
3479 if (viewport.getConservationSelected())
3481 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3484 if (cs instanceof TCoffeeColourScheme)
3486 tcoffeeColour.setEnabled(true);
3487 tcoffeeColour.setSelected(true);
3491 viewport.setGlobalColourScheme(cs);
3493 alignPanel.paintAlignment(true);
3503 protected void modifyPID_actionPerformed(ActionEvent e)
3505 if (viewport.getAbovePIDThreshold()
3506 && viewport.getGlobalColourScheme() != null)
3508 SliderPanel.setPIDSliderSource(alignPanel,
3509 viewport.getGlobalColourScheme(), "Background");
3510 SliderPanel.showPIDSlider();
3521 protected void modifyConservation_actionPerformed(ActionEvent e)
3523 if (viewport.getConservationSelected()
3524 && viewport.getGlobalColourScheme() != null)
3526 SliderPanel.setConservationSlider(alignPanel,
3527 viewport.getGlobalColourScheme(), "Background");
3528 SliderPanel.showConservationSlider();
3539 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3541 viewport.setConservationSelected(conservationMenuItem.isSelected());
3543 viewport.setAbovePIDThreshold(false);
3544 abovePIDThreshold.setSelected(false);
3546 changeColour(viewport.getGlobalColourScheme());
3548 modifyConservation_actionPerformed(null);
3558 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3560 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3562 conservationMenuItem.setSelected(false);
3563 viewport.setConservationSelected(false);
3565 changeColour(viewport.getGlobalColourScheme());
3567 modifyPID_actionPerformed(null);
3577 public void userDefinedColour_actionPerformed(ActionEvent e)
3579 if (e.getActionCommand().equals(
3580 MessageManager.getString("action.user_defined")))
3582 new UserDefinedColours(alignPanel, null);
3586 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3587 .getUserColourSchemes().get(e.getActionCommand());
3593 public void updateUserColourMenu()
3596 Component[] menuItems = colourMenu.getMenuComponents();
3597 int iSize = menuItems.length;
3598 for (int i = 0; i < iSize; i++)
3600 if (menuItems[i].getName() != null
3601 && menuItems[i].getName().equals("USER_DEFINED"))
3603 colourMenu.remove(menuItems[i]);
3607 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3609 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3610 .getUserColourSchemes().keys();
3612 while (userColours.hasMoreElements())
3614 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3615 userColours.nextElement().toString());
3616 radioItem.setName("USER_DEFINED");
3617 radioItem.addMouseListener(new MouseAdapter()
3620 public void mousePressed(MouseEvent evt)
3622 if (evt.isControlDown()
3623 || SwingUtilities.isRightMouseButton(evt))
3625 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3627 int option = JOptionPane.showInternalConfirmDialog(
3628 jalview.gui.Desktop.desktop,
3630 .getString("label.remove_from_default_list"),
3632 .getString("label.remove_user_defined_colour"),
3633 JOptionPane.YES_NO_OPTION);
3634 if (option == JOptionPane.YES_OPTION)
3636 jalview.gui.UserDefinedColours
3637 .removeColourFromDefaults(radioItem.getText());
3638 colourMenu.remove(radioItem);
3642 radioItem.addActionListener(new ActionListener()
3645 public void actionPerformed(ActionEvent evt)
3647 userDefinedColour_actionPerformed(evt);
3654 radioItem.addActionListener(new ActionListener()
3657 public void actionPerformed(ActionEvent evt)
3659 userDefinedColour_actionPerformed(evt);
3663 colourMenu.insert(radioItem, 15);
3664 colours.add(radioItem);
3676 public void PIDColour_actionPerformed(ActionEvent e)
3678 changeColour(new PIDColourScheme());
3688 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3690 changeColour(new Blosum62ColourScheme());
3700 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3702 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3703 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3704 .getAlignment().getSequenceAt(0), null);
3705 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3706 viewport.getAlignment()));
3707 alignPanel.paintAlignment(true);
3717 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3719 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3720 AlignmentSorter.sortByID(viewport.getAlignment());
3721 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3722 viewport.getAlignment()));
3723 alignPanel.paintAlignment(true);
3733 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3735 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3736 AlignmentSorter.sortByLength(viewport.getAlignment());
3737 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3738 viewport.getAlignment()));
3739 alignPanel.paintAlignment(true);
3749 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3751 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3752 AlignmentSorter.sortByGroup(viewport.getAlignment());
3753 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3754 viewport.getAlignment()));
3756 alignPanel.paintAlignment(true);
3766 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3768 new RedundancyPanel(alignPanel, this);
3778 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3780 if ((viewport.getSelectionGroup() == null)
3781 || (viewport.getSelectionGroup().getSize() < 2))
3783 JOptionPane.showInternalMessageDialog(this, MessageManager
3784 .getString("label.you_must_select_least_two_sequences"),
3785 MessageManager.getString("label.invalid_selection"),
3786 JOptionPane.WARNING_MESSAGE);
3790 JInternalFrame frame = new JInternalFrame();
3791 frame.setContentPane(new PairwiseAlignPanel(viewport));
3792 Desktop.addInternalFrame(frame,
3793 MessageManager.getString("action.pairwise_alignment"), 600,
3805 public void PCAMenuItem_actionPerformed(ActionEvent e)
3807 if (((viewport.getSelectionGroup() != null)
3808 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3809 .getSelectionGroup().getSize() > 0))
3810 || (viewport.getAlignment().getHeight() < 4))
3813 .showInternalMessageDialog(
3816 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3818 .getString("label.sequence_selection_insufficient"),
3819 JOptionPane.WARNING_MESSAGE);
3824 new PCAPanel(alignPanel);
3828 public void autoCalculate_actionPerformed(ActionEvent e)
3830 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3831 if (viewport.autoCalculateConsensus)
3833 viewport.firePropertyChange("alignment", null, viewport
3834 .getAlignment().getSequences());
3839 public void sortByTreeOption_actionPerformed(ActionEvent e)
3841 viewport.sortByTree = sortByTree.isSelected();
3845 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3847 viewport.followSelection = listenToViewSelections.isSelected();
3857 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3859 newTreePanel("AV", "PID", "Average distance tree using PID");
3869 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3871 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3881 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3883 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3893 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3895 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3908 void newTreePanel(String type, String pwType, String title)
3912 if (viewport.getSelectionGroup() != null
3913 && viewport.getSelectionGroup().getSize() > 0)
3915 if (viewport.getSelectionGroup().getSize() < 3)
3921 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3923 .getString("label.not_enough_sequences"),
3924 JOptionPane.WARNING_MESSAGE);
3928 SequenceGroup sg = viewport.getSelectionGroup();
3930 /* Decide if the selection is a column region */
3931 for (SequenceI _s : sg.getSequences())
3933 if (_s.getLength() < sg.getEndRes())
3939 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3941 .getString("label.sequences_selection_not_aligned"),
3942 JOptionPane.WARNING_MESSAGE);
3948 title = title + " on region";
3949 tp = new TreePanel(alignPanel, type, pwType);
3953 // are the visible sequences aligned?
3954 if (!viewport.getAlignment().isAligned(false))
3960 .getString("label.sequences_must_be_aligned_before_creating_tree"),
3962 .getString("label.sequences_not_aligned"),
3963 JOptionPane.WARNING_MESSAGE);
3968 if (viewport.getAlignment().getHeight() < 2)
3973 tp = new TreePanel(alignPanel, type, pwType);
3978 if (viewport.viewName != null)
3980 title += viewport.viewName + " of ";
3983 title += this.title;
3985 Desktop.addInternalFrame(tp, title, 600, 500);
3996 public void addSortByOrderMenuItem(String title,
3997 final AlignmentOrder order)
3999 final JMenuItem item = new JMenuItem(MessageManager.formatMessage(
4000 "action.by_title_param", new Object[] { title }));
4002 item.addActionListener(new java.awt.event.ActionListener()
4005 public void actionPerformed(ActionEvent e)
4007 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4009 // TODO: JBPNote - have to map order entries to curent SequenceI
4011 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4013 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4016 alignPanel.paintAlignment(true);
4022 * Add a new sort by annotation score menu item
4025 * the menu to add the option to
4027 * the label used to retrieve scores for each sequence on the
4030 public void addSortByAnnotScoreMenuItem(JMenu sort,
4031 final String scoreLabel)
4033 final JMenuItem item = new JMenuItem(scoreLabel);
4035 item.addActionListener(new java.awt.event.ActionListener()
4038 public void actionPerformed(ActionEvent e)
4040 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4041 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4042 viewport.getAlignment());// ,viewport.getSelectionGroup());
4043 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4044 viewport.getAlignment()));
4045 alignPanel.paintAlignment(true);
4051 * last hash for alignment's annotation array - used to minimise cost of
4054 protected int _annotationScoreVectorHash;
4057 * search the alignment and rebuild the sort by annotation score submenu the
4058 * last alignment annotation vector hash is stored to minimize cost of
4059 * rebuilding in subsequence calls.
4063 public void buildSortByAnnotationScoresMenu()
4065 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4070 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4072 sortByAnnotScore.removeAll();
4073 // almost certainly a quicker way to do this - but we keep it simple
4074 Hashtable scoreSorts = new Hashtable();
4075 AlignmentAnnotation aann[];
4076 for (SequenceI sqa : viewport.getAlignment().getSequences())
4078 aann = sqa.getAnnotation();
4079 for (int i = 0; aann != null && i < aann.length; i++)
4081 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4083 scoreSorts.put(aann[i].label, aann[i].label);
4087 Enumeration labels = scoreSorts.keys();
4088 while (labels.hasMoreElements())
4090 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4091 (String) labels.nextElement());
4093 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4096 _annotationScoreVectorHash = viewport.getAlignment()
4097 .getAlignmentAnnotation().hashCode();
4102 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4103 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4104 * call. Listeners are added to remove the menu item when the treePanel is
4105 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4109 * Displayed tree window.
4111 * SortBy menu item title.
4114 public void buildTreeMenu()
4116 calculateTree.removeAll();
4117 // build the calculate menu
4119 for (final String type : new String[] { "NJ", "AV" })
4121 String treecalcnm = MessageManager.getString("label.tree_calc_"
4122 + type.toLowerCase());
4123 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4125 JMenuItem tm = new JMenuItem();
4126 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4127 if (sm.isDNA() == viewport.getAlignment().isNucleotide()
4128 || sm.isProtein() == !viewport.getAlignment()
4131 String smn = MessageManager.getStringOrReturn(
4132 "label.score_model_", sm.getName());
4133 final String title = MessageManager.formatMessage(
4134 "label.treecalc_title", treecalcnm, smn);
4135 tm.setText(title);//
4136 tm.addActionListener(new java.awt.event.ActionListener()
4139 public void actionPerformed(ActionEvent e)
4141 newTreePanel(type, pwtype, title);
4144 calculateTree.add(tm);
4149 sortByTreeMenu.removeAll();
4151 List<Component> comps = PaintRefresher.components.get(viewport
4152 .getSequenceSetId());
4153 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4154 for (Component comp : comps)
4156 if (comp instanceof TreePanel)
4158 treePanels.add((TreePanel) comp);
4162 if (treePanels.size() < 1)
4164 sortByTreeMenu.setVisible(false);
4168 sortByTreeMenu.setVisible(true);
4170 for (final TreePanel tp : treePanels)
4172 final JMenuItem item = new JMenuItem(tp.getTitle());
4173 item.addActionListener(new java.awt.event.ActionListener()
4176 public void actionPerformed(ActionEvent e)
4178 tp.sortByTree_actionPerformed();
4179 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4184 sortByTreeMenu.add(item);
4188 public boolean sortBy(AlignmentOrder alorder, String undoname)
4190 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4191 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4192 if (undoname != null)
4194 addHistoryItem(new OrderCommand(undoname, oldOrder,
4195 viewport.getAlignment()));
4197 alignPanel.paintAlignment(true);
4202 * Work out whether the whole set of sequences or just the selected set will
4203 * be submitted for multiple alignment.
4206 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4208 // Now, check we have enough sequences
4209 AlignmentView msa = null;
4211 if ((viewport.getSelectionGroup() != null)
4212 && (viewport.getSelectionGroup().getSize() > 1))
4214 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4215 // some common interface!
4217 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4218 * SequenceI[sz = seqs.getSize(false)];
4220 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4221 * seqs.getSequenceAt(i); }
4223 msa = viewport.getAlignmentView(true);
4225 else if (viewport.getSelectionGroup() != null
4226 && viewport.getSelectionGroup().getSize() == 1)
4228 int option = JOptionPane.showConfirmDialog(this,
4229 MessageManager.getString("warn.oneseq_msainput_selection"),
4230 MessageManager.getString("label.invalid_selection"),
4231 JOptionPane.OK_CANCEL_OPTION);
4232 if (option == JOptionPane.OK_OPTION)
4234 msa = viewport.getAlignmentView(false);
4239 msa = viewport.getAlignmentView(false);
4245 * Decides what is submitted to a secondary structure prediction service: the
4246 * first sequence in the alignment, or in the current selection, or, if the
4247 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4248 * region or the whole alignment. (where the first sequence in the set is the
4249 * one that the prediction will be for).
4251 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4253 AlignmentView seqs = null;
4255 if ((viewport.getSelectionGroup() != null)
4256 && (viewport.getSelectionGroup().getSize() > 0))
4258 seqs = viewport.getAlignmentView(true);
4262 seqs = viewport.getAlignmentView(false);
4264 // limit sequences - JBPNote in future - could spawn multiple prediction
4266 // TODO: viewport.getAlignment().isAligned is a global state - the local
4267 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4268 if (!viewport.getAlignment().isAligned(false))
4270 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4271 // TODO: if seqs.getSequences().length>1 then should really have warned
4285 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4287 // Pick the tree file
4288 JalviewFileChooser chooser = new JalviewFileChooser(
4289 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4290 chooser.setFileView(new JalviewFileView());
4291 chooser.setDialogTitle(MessageManager
4292 .getString("label.select_newick_like_tree_file"));
4293 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4295 int value = chooser.showOpenDialog(null);
4297 if (value == JalviewFileChooser.APPROVE_OPTION)
4299 String choice = chooser.getSelectedFile().getPath();
4300 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4301 jalview.io.NewickFile fin = null;
4304 fin = new jalview.io.NewickFile(choice, "File");
4305 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4306 } catch (Exception ex)
4313 .getString("label.problem_reading_tree_file"),
4314 JOptionPane.WARNING_MESSAGE);
4315 ex.printStackTrace();
4317 if (fin != null && fin.hasWarningMessage())
4319 JOptionPane.showMessageDialog(Desktop.desktop, fin
4320 .getWarningMessage(), MessageManager
4321 .getString("label.possible_problem_with_tree_file"),
4322 JOptionPane.WARNING_MESSAGE);
4328 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4330 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4333 public TreePanel ShowNewickTree(NewickFile nf, String title)
4335 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4338 public TreePanel ShowNewickTree(NewickFile nf, String title,
4339 AlignmentView input)
4341 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4344 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4345 int h, int x, int y)
4347 return ShowNewickTree(nf, title, null, w, h, x, y);
4351 * Add a treeviewer for the tree extracted from a newick file object to the
4352 * current alignment view
4359 * Associated alignment input data (or null)
4368 * @return TreePanel handle
4370 public TreePanel ShowNewickTree(NewickFile nf, String title,
4371 AlignmentView input, int w, int h, int x, int y)
4373 TreePanel tp = null;
4379 if (nf.getTree() != null)
4381 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4387 tp.setLocation(x, y);
4390 Desktop.addInternalFrame(tp, title, w, h);
4392 } catch (Exception ex)
4394 ex.printStackTrace();
4400 private boolean buildingMenu = false;
4403 * Generates menu items and listener event actions for web service clients
4406 public void BuildWebServiceMenu()
4408 while (buildingMenu)
4412 System.err.println("Waiting for building menu to finish.");
4414 } catch (Exception e)
4418 final AlignFrame me = this;
4419 buildingMenu = true;
4420 new Thread(new Runnable()
4425 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4428 // System.err.println("Building ws menu again "
4429 // + Thread.currentThread());
4430 // TODO: add support for context dependent disabling of services based
4432 // alignment and current selection
4433 // TODO: add additional serviceHandle parameter to specify abstract
4435 // class independently of AbstractName
4436 // TODO: add in rediscovery GUI function to restart discoverer
4437 // TODO: group services by location as well as function and/or
4439 // object broker mechanism.
4440 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4441 final IProgressIndicator af = me;
4442 final JMenu msawsmenu = new JMenu("Alignment");
4443 final JMenu secstrmenu = new JMenu(
4444 "Secondary Structure Prediction");
4445 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4446 final JMenu analymenu = new JMenu("Analysis");
4447 final JMenu dismenu = new JMenu("Protein Disorder");
4448 // final JMenu msawsmenu = new
4449 // JMenu(MessageManager.getString("label.alignment"));
4450 // final JMenu secstrmenu = new
4451 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4452 // final JMenu seqsrchmenu = new
4453 // JMenu(MessageManager.getString("label.sequence_database_search"));
4454 // final JMenu analymenu = new
4455 // JMenu(MessageManager.getString("label.analysis"));
4456 // final JMenu dismenu = new
4457 // JMenu(MessageManager.getString("label.protein_disorder"));
4458 // JAL-940 - only show secondary structure prediction services from
4459 // the legacy server
4460 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4462 Discoverer.services != null && (Discoverer.services.size() > 0))
4464 // TODO: refactor to allow list of AbstractName/Handler bindings to
4466 // stored or retrieved from elsewhere
4467 // No MSAWS used any more:
4468 // Vector msaws = null; // (Vector)
4469 // Discoverer.services.get("MsaWS");
4470 Vector secstrpr = (Vector) Discoverer.services
4472 if (secstrpr != null)
4474 // Add any secondary structure prediction services
4475 for (int i = 0, j = secstrpr.size(); i < j; i++)
4477 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4479 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4480 .getServiceClient(sh);
4481 int p = secstrmenu.getItemCount();
4482 impl.attachWSMenuEntry(secstrmenu, me);
4483 int q = secstrmenu.getItemCount();
4484 for (int litm = p; litm < q; litm++)
4486 legacyItems.add(secstrmenu.getItem(litm));
4492 // Add all submenus in the order they should appear on the web
4494 wsmenu.add(msawsmenu);
4495 wsmenu.add(secstrmenu);
4496 wsmenu.add(dismenu);
4497 wsmenu.add(analymenu);
4498 // No search services yet
4499 // wsmenu.add(seqsrchmenu);
4501 javax.swing.SwingUtilities.invokeLater(new Runnable()
4508 webService.removeAll();
4509 // first, add discovered services onto the webservices menu
4510 if (wsmenu.size() > 0)
4512 for (int i = 0, j = wsmenu.size(); i < j; i++)
4514 webService.add(wsmenu.get(i));
4519 webService.add(me.webServiceNoServices);
4521 // TODO: move into separate menu builder class.
4522 boolean new_sspred = false;
4523 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4525 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4526 if (jws2servs != null)
4528 if (jws2servs.hasServices())
4530 jws2servs.attachWSMenuEntry(webService, me);
4531 for (Jws2Instance sv : jws2servs.getServices())
4533 if (sv.description.toLowerCase().contains("jpred"))
4535 for (JMenuItem jmi : legacyItems)
4537 jmi.setVisible(false);
4543 if (jws2servs.isRunning())
4545 JMenuItem tm = new JMenuItem(
4546 "Still discovering JABA Services");
4547 tm.setEnabled(false);
4552 build_urlServiceMenu(me.webService);
4553 build_fetchdbmenu(webService);
4554 for (JMenu item : wsmenu)
4556 if (item.getItemCount() == 0)
4558 item.setEnabled(false);
4562 item.setEnabled(true);
4565 } catch (Exception e)
4568 .debug("Exception during web service menu building process.",
4573 } catch (Exception e)
4576 buildingMenu = false;
4583 * construct any groupURL type service menu entries.
4587 private void build_urlServiceMenu(JMenu webService)
4589 // TODO: remove this code when 2.7 is released
4590 // DEBUG - alignmentView
4592 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4593 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4595 * @Override public void actionPerformed(ActionEvent e) {
4596 * jalview.datamodel.AlignmentView
4597 * .testSelectionViews(af.viewport.getAlignment(),
4598 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4600 * }); webService.add(testAlView);
4602 // TODO: refactor to RestClient discoverer and merge menu entries for
4603 // rest-style services with other types of analysis/calculation service
4604 // SHmmr test client - still being implemented.
4605 // DEBUG - alignmentView
4607 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4610 client.attachWSMenuEntry(
4611 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4617 * Searches selected sequences for xRef products and builds the Show
4618 * Cross-References menu (formerly called Show Products)
4620 * @return true if Show Cross-references menu should be enabled.
4622 public boolean canShowProducts()
4624 SequenceI[] selection = viewport.getSequenceSelection();
4625 AlignmentI dataset = viewport.getAlignment().getDataset();
4626 boolean showp = false;
4629 showProducts.removeAll();
4630 final boolean dna = viewport.getAlignment().isNucleotide();
4631 String[] ptypes = (selection == null || selection.length == 0) ? null
4632 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4634 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4637 final AlignFrame af = this;
4638 final String source = ptypes[t];
4639 JMenuItem xtype = new JMenuItem(ptypes[t]);
4640 xtype.addActionListener(new ActionListener()
4644 public void actionPerformed(ActionEvent e)
4646 showProductsFor(af.viewport.getSequenceSelection(), dna, source);
4650 showProducts.add(xtype);
4652 showProducts.setVisible(showp);
4653 showProducts.setEnabled(showp);
4654 } catch (Exception e)
4656 jalview.bin.Cache.log
4657 .warn("canShowProducts threw an exception - please report to help@jalview.org",
4664 protected void showProductsFor(final SequenceI[] sel, final boolean dna,
4665 final String source)
4667 Runnable foo = new Runnable()
4673 final long sttime = System.currentTimeMillis();
4674 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4675 "status.searching_for_sequences_from",
4676 new Object[] { source }), sttime);
4679 AlignmentI alignment = AlignFrame.this.getViewport()
4681 AlignmentI xrefs = CrossRef.findXrefSequences(sel, dna, source,
4686 * get display scheme (if any) to apply to features
4688 FeatureSettingsModelI featureColourScheme = new SequenceFetcher()
4689 .getFeatureColourScheme(source);
4691 AlignmentI al = makeCrossReferencesAlignment(
4692 alignment.getDataset(), xrefs);
4694 AlignFrame newFrame = new AlignFrame(al, DEFAULT_WIDTH,
4696 String newtitle = String.format("%s %s %s",
4697 MessageManager.getString(dna ? "label.proteins"
4698 : "label.nucleotides"), MessageManager
4699 .getString("label.for"), getTitle());
4700 newFrame.setTitle(newtitle);
4702 if (!Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4705 * split frame display is turned off in preferences file
4707 Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
4709 return; // via finally clause
4713 * Make a copy of this alignment (sharing the same dataset
4714 * sequences). If we are DNA, drop introns and update mappings
4716 AlignmentI copyAlignment = null;
4717 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4718 .getSequenceSelection();
4719 List<AlignedCodonFrame> cf = xrefs.getCodonFrames();
4720 boolean copyAlignmentIsAligned = false;
4723 copyAlignment = AlignmentUtils.makeCdsAlignment(
4724 sequenceSelection, cf, alignment);
4725 if (copyAlignment.getHeight() == 0)
4727 System.err.println("Failed to make CDS alignment");
4729 al.getCodonFrames().clear();
4730 al.getCodonFrames().addAll(copyAlignment.getCodonFrames());
4733 * pending getting Embl transcripts to 'align',
4734 * we are only doing this for Ensembl
4736 // TODO proper criteria for 'can align as cdna'
4737 if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
4738 || AlignmentUtils.looksLikeEnsembl(alignment))
4740 copyAlignment.alignAs(alignment);
4741 copyAlignmentIsAligned = true;
4746 copyAlignment = AlignmentUtils.makeCopyAlignment(
4747 sequenceSelection, xrefs.getSequencesArray());
4748 copyAlignment.getCodonFrames().addAll(cf);
4750 copyAlignment.setGapCharacter(AlignFrame.this.viewport
4751 .getGapCharacter());
4753 StructureSelectionManager ssm = StructureSelectionManager
4754 .getStructureSelectionManager(Desktop.instance);
4755 ssm.registerMappings(cf);
4757 if (copyAlignment.getHeight() <= 0)
4759 System.err.println("No Sequences generated for xRef type "
4764 * align protein to dna
4766 if (dna && copyAlignmentIsAligned)
4768 al.alignAs(copyAlignment);
4773 * align cdna to protein - currently only if
4774 * fetching and aligning Ensembl transcripts!
4776 if (DBRefSource.ENSEMBL.equalsIgnoreCase(source))
4778 copyAlignment.alignAs(al);
4782 AlignFrame copyThis = new AlignFrame(copyAlignment,
4783 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4784 copyThis.setTitle(AlignFrame.this.getTitle());
4786 boolean showSequenceFeatures = viewport
4787 .isShowSequenceFeatures();
4788 newFrame.setShowSeqFeatures(showSequenceFeatures);
4789 copyThis.setShowSeqFeatures(showSequenceFeatures);
4790 FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas
4791 .getFeatureRenderer();
4794 * copy feature rendering settings to split frame
4796 newFrame.alignPanel.getSeqPanel().seqCanvas
4797 .getFeatureRenderer()
4798 .transferSettings(myFeatureStyling);
4799 copyThis.alignPanel.getSeqPanel().seqCanvas
4800 .getFeatureRenderer()
4801 .transferSettings(myFeatureStyling);
4804 * apply 'database source' feature configuration
4807 // TODO is this the feature colouring for the original
4808 // alignment or the fetched xrefs? either could be Ensembl
4809 newFrame.getViewport().applyFeaturesStyle(featureColourScheme);
4810 copyThis.getViewport().applyFeaturesStyle(featureColourScheme);
4812 SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame,
4813 dna ? newFrame : copyThis);
4814 newFrame.setVisible(true);
4815 copyThis.setVisible(true);
4816 String linkedTitle = MessageManager
4817 .getString("label.linked_view_title");
4818 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4821 } catch (Exception e)
4824 "Exception when finding crossreferences", e);
4825 } catch (OutOfMemoryError e)
4827 new OOMWarning("whilst fetching crossreferences", e);
4828 } catch (Throwable e)
4830 Cache.log.error("Error when finding crossreferences",
4834 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4835 "status.finished_searching_for_sequences_from",
4836 new Object[] { source }), sttime);
4841 * Makes an alignment containing the given sequences. If this is of the
4842 * same type as the given dataset (nucleotide/protein), then the new
4843 * alignment shares the same dataset, and its dataset sequences are added
4844 * to it. Otherwise a new dataset sequence is created for the
4851 protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,
4854 boolean sameType = dataset.isNucleotide() == seqs.isNucleotide();
4856 SequenceI[] sprods = new SequenceI[seqs.getHeight()];
4857 for (int s = 0; s < sprods.length; s++)
4859 sprods[s] = (seqs.getSequenceAt(s)).deriveSequence();
4862 if (dataset.getSequences() == null
4863 || !dataset.getSequences().contains(
4864 sprods[s].getDatasetSequence()))
4866 dataset.addSequence(sprods[s].getDatasetSequence());
4869 sprods[s].updatePDBIds();
4871 Alignment al = new Alignment(sprods);
4874 al.setDataset((Alignment) dataset);
4878 al.createDatasetAlignment();
4884 Thread frunner = new Thread(foo);
4889 * Construct and display a new frame containing the translation of this
4890 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4893 public void showTranslation_actionPerformed(ActionEvent e)
4895 AlignmentI al = null;
4898 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4900 al = dna.translateCdna();
4901 } catch (Exception ex)
4903 jalview.bin.Cache.log.error(
4904 "Exception during translation. Please report this !", ex);
4905 final String msg = MessageManager
4906 .getString("label.error_when_translating_sequences_submit_bug_report");
4907 final String errorTitle = MessageManager
4908 .getString("label.implementation_error")
4909 + MessageManager.getString("translation_failed");
4910 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4911 JOptionPane.ERROR_MESSAGE);
4914 if (al == null || al.getHeight() == 0)
4916 final String msg = MessageManager
4917 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4918 final String errorTitle = MessageManager
4919 .getString("label.translation_failed");
4920 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4921 JOptionPane.WARNING_MESSAGE);
4925 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4926 af.setFileFormat(this.currentFileFormat);
4927 final String newTitle = MessageManager.formatMessage(
4928 "label.translation_of_params",
4929 new Object[] { this.getTitle() });
4930 af.setTitle(newTitle);
4931 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4933 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4934 viewport.openSplitFrame(af, new Alignment(seqs));
4938 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4945 * Set the file format
4949 public void setFileFormat(String fileFormat)
4951 this.currentFileFormat = fileFormat;
4955 * Try to load a features file onto the alignment.
4958 * contents or path to retrieve file
4960 * access mode of file (see jalview.io.AlignFile)
4961 * @return true if features file was parsed correctly.
4963 public boolean parseFeaturesFile(String file, String type)
4965 return avc.parseFeaturesFile(file, type,
4966 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4971 public void refreshFeatureUI(boolean enableIfNecessary)
4973 // note - currently this is only still here rather than in the controller
4974 // because of the featureSettings hard reference that is yet to be
4976 if (enableIfNecessary)
4978 viewport.setShowSequenceFeatures(true);
4979 showSeqFeatures.setSelected(true);
4985 public void dragEnter(DropTargetDragEvent evt)
4990 public void dragExit(DropTargetEvent evt)
4995 public void dragOver(DropTargetDragEvent evt)
5000 public void dropActionChanged(DropTargetDragEvent evt)
5005 public void drop(DropTargetDropEvent evt)
5007 Transferable t = evt.getTransferable();
5008 java.util.List files = null;
5012 DataFlavor uriListFlavor = new DataFlavor(
5013 "text/uri-list;class=java.lang.String");
5014 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5016 // Works on Windows and MacOSX
5017 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5018 files = (java.util.List) t
5019 .getTransferData(DataFlavor.javaFileListFlavor);
5021 else if (t.isDataFlavorSupported(uriListFlavor))
5023 // This is used by Unix drag system
5024 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5025 String data = (String) t.getTransferData(uriListFlavor);
5026 files = new java.util.ArrayList(1);
5027 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5028 data, "\r\n"); st.hasMoreTokens();)
5030 String s = st.nextToken();
5031 if (s.startsWith("#"))
5033 // the line is a comment (as per the RFC 2483)
5037 java.net.URI uri = new java.net.URI(s);
5038 // check to see if we can handle this kind of URI
5039 if (uri.getScheme().toLowerCase().startsWith("http"))
5041 files.add(uri.toString());
5045 // otherwise preserve old behaviour: catch all for file objects
5046 java.io.File file = new java.io.File(uri);
5047 files.add(file.toString());
5051 } catch (Exception e)
5053 e.printStackTrace();
5059 // check to see if any of these files have names matching sequences in
5061 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5062 .getAlignment().getSequencesArray());
5064 * Object[] { String,SequenceI}
5066 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5067 ArrayList<String> filesnotmatched = new ArrayList<String>();
5068 for (int i = 0; i < files.size(); i++)
5070 String file = files.get(i).toString();
5072 String protocol = FormatAdapter.checkProtocol(file);
5073 if (protocol == jalview.io.FormatAdapter.FILE)
5075 File fl = new File(file);
5076 pdbfn = fl.getName();
5078 else if (protocol == jalview.io.FormatAdapter.URL)
5080 URL url = new URL(file);
5081 pdbfn = url.getFile();
5083 if (pdbfn.length() > 0)
5085 // attempt to find a match in the alignment
5086 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5087 int l = 0, c = pdbfn.indexOf(".");
5088 while (mtch == null && c != -1)
5093 } while ((c = pdbfn.indexOf(".", l)) > l);
5096 pdbfn = pdbfn.substring(0, l);
5098 mtch = idm.findAllIdMatches(pdbfn);
5105 type = new IdentifyFile().identify(file, protocol);
5106 } catch (Exception ex)
5112 if (type.equalsIgnoreCase("PDB"))
5114 filesmatched.add(new Object[] { file, protocol, mtch });
5119 // File wasn't named like one of the sequences or wasn't a PDB file.
5120 filesnotmatched.add(file);
5124 if (filesmatched.size() > 0)
5126 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5132 "label.automatically_associate_pdb_files_with_sequences_same_name",
5133 new Object[] { Integer
5139 .getString("label.automatically_associate_pdb_files_by_name"),
5140 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5143 for (Object[] fm : filesmatched)
5145 // try and associate
5146 // TODO: may want to set a standard ID naming formalism for
5147 // associating PDB files which have no IDs.
5148 for (SequenceI toassoc : (SequenceI[]) fm[2])
5150 PDBEntry pe = new AssociatePdbFileWithSeq()
5151 .associatePdbWithSeq((String) fm[0],
5152 (String) fm[1], toassoc, false,
5156 System.err.println("Associated file : "
5157 + ((String) fm[0]) + " with "
5158 + toassoc.getDisplayId(true));
5162 alignPanel.paintAlignment(true);
5166 if (filesnotmatched.size() > 0)
5169 && (Cache.getDefault(
5170 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5176 "label.ignore_unmatched_dropped_files_info",
5177 new Object[] { Integer
5184 .getString("label.ignore_unmatched_dropped_files"),
5185 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5189 for (String fn : filesnotmatched)
5191 loadJalviewDataFile(fn, null, null, null);
5195 } catch (Exception ex)
5197 ex.printStackTrace();
5203 * Attempt to load a "dropped" file or URL string: First by testing whether
5204 * it's an Annotation file, then a JNet file, and finally a features file. If
5205 * all are false then the user may have dropped an alignment file onto this
5209 * either a filename or a URL string.
5211 public void loadJalviewDataFile(String file, String protocol,
5212 String format, SequenceI assocSeq)
5216 if (protocol == null)
5218 protocol = FormatAdapter.checkProtocol(file);
5220 // if the file isn't identified, or not positively identified as some
5221 // other filetype (PFAM is default unidentified alignment file type) then
5222 // try to parse as annotation.
5223 boolean isAnnotation = (format == null || format
5224 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5225 .annotateAlignmentView(viewport, file, protocol) : false;
5229 // first see if its a T-COFFEE score file
5230 TCoffeeScoreFile tcf = null;
5233 tcf = new TCoffeeScoreFile(file, protocol);
5236 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5238 tcoffeeColour.setEnabled(true);
5239 tcoffeeColour.setSelected(true);
5240 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5241 isAnnotation = true;
5243 .setText(MessageManager
5244 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5248 // some problem - if no warning its probable that the ID matching
5249 // process didn't work
5253 tcf.getWarningMessage() == null ? MessageManager
5254 .getString("label.check_file_matches_sequence_ids_alignment")
5255 : tcf.getWarningMessage(),
5257 .getString("label.problem_reading_tcoffee_score_file"),
5258 JOptionPane.WARNING_MESSAGE);
5265 } catch (Exception x)
5268 .debug("Exception when processing data source as T-COFFEE score file",
5274 // try to see if its a JNet 'concise' style annotation file *before*
5276 // try to parse it as a features file
5279 format = new IdentifyFile().identify(file, protocol);
5281 if (format.equalsIgnoreCase("JnetFile"))
5283 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5285 new JnetAnnotationMaker();
5286 JnetAnnotationMaker.add_annotation(predictions,
5287 viewport.getAlignment(), 0, false);
5288 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5289 viewport.getAlignment().setSeqrep(repseq);
5290 ColumnSelection cs = new ColumnSelection();
5291 cs.hideInsertionsFor(repseq);
5292 viewport.setColumnSelection(cs);
5293 isAnnotation = true;
5295 else if (IdentifyFile.FeaturesFile.equals(format))
5297 if (parseFeaturesFile(file, protocol))
5299 alignPanel.paintAlignment(true);
5304 new FileLoader().LoadFile(viewport, file, protocol, format);
5311 alignPanel.adjustAnnotationHeight();
5312 viewport.updateSequenceIdColours();
5313 buildSortByAnnotationScoresMenu();
5314 alignPanel.paintAlignment(true);
5316 } catch (Exception ex)
5318 ex.printStackTrace();
5319 } catch (OutOfMemoryError oom)
5324 } catch (Exception x)
5329 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5330 : "using " + protocol + " from " + file)
5332 + (format != null ? "(parsing as '" + format
5333 + "' file)" : ""), oom, Desktop.desktop);
5338 * Method invoked by the ChangeListener on the tabbed pane, in other words
5339 * when a different tabbed pane is selected by the user or programmatically.
5342 public void tabSelectionChanged(int index)
5346 alignPanel = alignPanels.get(index);
5347 viewport = alignPanel.av;
5348 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5349 setMenusFromViewport(viewport);
5353 * If there is a frame linked to this one in a SplitPane, switch it to the
5354 * same view tab index. No infinite recursion of calls should happen, since
5355 * tabSelectionChanged() should not get invoked on setting the selected
5356 * index to an unchanged value. Guard against setting an invalid index
5357 * before the new view peer tab has been created.
5359 final AlignViewportI peer = viewport.getCodingComplement();
5362 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5363 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5365 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5371 * On right mouse click on view tab, prompt for and set new view name.
5374 public void tabbedPane_mousePressed(MouseEvent e)
5376 if (SwingUtilities.isRightMouseButton(e))
5378 String msg = MessageManager.getString("label.enter_view_name");
5379 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5380 JOptionPane.QUESTION_MESSAGE);
5384 viewport.viewName = reply;
5385 // TODO warn if reply is in getExistingViewNames()?
5386 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5391 public AlignViewport getCurrentView()
5397 * Open the dialog for regex description parsing.
5400 protected void extractScores_actionPerformed(ActionEvent e)
5402 ParseProperties pp = new jalview.analysis.ParseProperties(
5403 viewport.getAlignment());
5404 // TODO: verify regex and introduce GUI dialog for version 2.5
5405 // if (pp.getScoresFromDescription("col", "score column ",
5406 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5408 if (pp.getScoresFromDescription("description column",
5409 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5411 buildSortByAnnotationScoresMenu();
5419 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5423 protected void showDbRefs_actionPerformed(ActionEvent e)
5425 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5431 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5435 protected void showNpFeats_actionPerformed(ActionEvent e)
5437 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5441 * find the viewport amongst the tabs in this alignment frame and close that
5446 public boolean closeView(AlignViewportI av)
5450 this.closeMenuItem_actionPerformed(false);
5453 Component[] comp = tabbedPane.getComponents();
5454 for (int i = 0; comp != null && i < comp.length; i++)
5456 if (comp[i] instanceof AlignmentPanel)
5458 if (((AlignmentPanel) comp[i]).av == av)
5461 closeView((AlignmentPanel) comp[i]);
5469 protected void build_fetchdbmenu(JMenu webService)
5471 // Temporary hack - DBRef Fetcher always top level ws entry.
5472 // TODO We probably want to store a sequence database checklist in
5473 // preferences and have checkboxes.. rather than individual sources selected
5475 final JMenu rfetch = new JMenu(
5476 MessageManager.getString("action.fetch_db_references"));
5477 rfetch.setToolTipText(MessageManager
5478 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5479 webService.add(rfetch);
5481 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5482 MessageManager.getString("option.trim_retrieved_seqs"));
5483 trimrs.setToolTipText(MessageManager
5484 .getString("label.trim_retrieved_sequences"));
5485 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5486 trimrs.addActionListener(new ActionListener()
5489 public void actionPerformed(ActionEvent e)
5491 trimrs.setSelected(trimrs.isSelected());
5492 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5493 Boolean.valueOf(trimrs.isSelected()).toString());
5497 JMenuItem fetchr = new JMenuItem(
5498 MessageManager.getString("label.standard_databases"));
5499 fetchr.setToolTipText(MessageManager
5500 .getString("label.fetch_embl_uniprot"));
5501 fetchr.addActionListener(new ActionListener()
5505 public void actionPerformed(ActionEvent e)
5507 new Thread(new Runnable()
5512 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5513 .getAlignment().isNucleotide();
5514 DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av
5515 .getSequenceSelection(), alignPanel.alignFrame, null,
5516 alignPanel.alignFrame.featureSettings, isNucleotide);
5517 dbRefFetcher.addListener(new FetchFinishedListenerI()
5520 public void finished()
5522 AlignFrame.this.setMenusForViewport();
5526 .fetchDBRefs(false);
5534 final AlignFrame me = this;
5535 new Thread(new Runnable()
5540 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5541 .getSequenceFetcherSingleton(me);
5542 javax.swing.SwingUtilities.invokeLater(new Runnable()
5547 String[] dbclasses = sf.getOrderedSupportedSources();
5548 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5549 // jalview.util.QuickSort.sort(otherdb, otherdb);
5550 List<DbSourceProxy> otherdb;
5551 JMenu dfetch = new JMenu();
5552 JMenu ifetch = new JMenu();
5553 JMenuItem fetchr = null;
5554 int comp = 0, icomp = 0, mcomp = 15;
5555 String mname = null;
5557 for (String dbclass : dbclasses)
5559 otherdb = sf.getSourceProxy(dbclass);
5560 // add a single entry for this class, or submenu allowing 'fetch
5562 if (otherdb == null || otherdb.size() < 1)
5566 // List<DbSourceProxy> dbs=otherdb;
5567 // otherdb=new ArrayList<DbSourceProxy>();
5568 // for (DbSourceProxy db:dbs)
5570 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5574 mname = "From " + dbclass;
5576 if (otherdb.size() == 1)
5578 final DbSourceProxy[] dassource = otherdb
5579 .toArray(new DbSourceProxy[0]);
5580 DbSourceProxy src = otherdb.get(0);
5581 fetchr = new JMenuItem(src.getDbSource());
5582 fetchr.addActionListener(new ActionListener()
5586 public void actionPerformed(ActionEvent e)
5588 new Thread(new Runnable()
5594 boolean isNucleotide = alignPanel.alignFrame
5595 .getViewport().getAlignment()
5597 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5598 alignPanel.av.getSequenceSelection(),
5599 alignPanel.alignFrame, dassource,
5600 alignPanel.alignFrame.featureSettings,
5603 .addListener(new FetchFinishedListenerI()
5606 public void finished()
5608 AlignFrame.this.setMenusForViewport();
5611 dbRefFetcher.fetchDBRefs(false);
5617 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5618 MessageManager.formatMessage(
5619 "label.fetch_retrieve_from",
5620 new Object[] { src.getDbName() })));
5626 final DbSourceProxy[] dassource = otherdb
5627 .toArray(new DbSourceProxy[0]);
5629 DbSourceProxy src = otherdb.get(0);
5630 fetchr = new JMenuItem(MessageManager.formatMessage(
5631 "label.fetch_all_param",
5632 new Object[] { src.getDbSource() }));
5633 fetchr.addActionListener(new ActionListener()
5636 public void actionPerformed(ActionEvent e)
5638 new Thread(new Runnable()
5644 boolean isNucleotide = alignPanel.alignFrame
5645 .getViewport().getAlignment()
5647 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5648 alignPanel.av.getSequenceSelection(),
5649 alignPanel.alignFrame, dassource,
5650 alignPanel.alignFrame.featureSettings,
5653 .addListener(new FetchFinishedListenerI()
5656 public void finished()
5658 AlignFrame.this.setMenusForViewport();
5661 dbRefFetcher.fetchDBRefs(false);
5667 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5668 MessageManager.formatMessage(
5669 "label.fetch_retrieve_from_all_sources",
5671 Integer.valueOf(otherdb.size())
5672 .toString(), src.getDbSource(),
5673 src.getDbName() })));
5676 // and then build the rest of the individual menus
5677 ifetch = new JMenu(MessageManager.formatMessage(
5678 "label.source_from_db_source",
5679 new Object[] { src.getDbSource() }));
5681 String imname = null;
5683 for (DbSourceProxy sproxy : otherdb)
5685 String dbname = sproxy.getDbName();
5686 String sname = dbname.length() > 5 ? dbname.substring(0,
5687 5) + "..." : dbname;
5688 String msname = dbname.length() > 10 ? dbname.substring(
5689 0, 10) + "..." : dbname;
5692 imname = MessageManager.formatMessage(
5693 "label.from_msname", new Object[] { sname });
5695 fetchr = new JMenuItem(msname);
5696 final DbSourceProxy[] dassrc = { sproxy };
5697 fetchr.addActionListener(new ActionListener()
5701 public void actionPerformed(ActionEvent e)
5703 new Thread(new Runnable()
5709 boolean isNucleotide = alignPanel.alignFrame
5710 .getViewport().getAlignment()
5712 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5713 alignPanel.av.getSequenceSelection(),
5714 alignPanel.alignFrame, dassrc,
5715 alignPanel.alignFrame.featureSettings,
5718 .addListener(new FetchFinishedListenerI()
5721 public void finished()
5723 AlignFrame.this.setMenusForViewport();
5726 dbRefFetcher.fetchDBRefs(false);
5732 fetchr.setToolTipText("<html>"
5733 + MessageManager.formatMessage(
5734 "label.fetch_retrieve_from", new Object[]
5738 if (++icomp >= mcomp || i == (otherdb.size()))
5740 ifetch.setText(MessageManager.formatMessage(
5741 "label.source_to_target", imname, sname));
5743 ifetch = new JMenu();
5751 if (comp >= mcomp || dbi >= (dbclasses.length))
5753 dfetch.setText(MessageManager.formatMessage(
5754 "label.source_to_target", mname, dbclass));
5756 dfetch = new JMenu();
5769 * Left justify the whole alignment.
5772 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5774 AlignmentI al = viewport.getAlignment();
5776 viewport.firePropertyChange("alignment", null, al);
5780 * Right justify the whole alignment.
5783 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5785 AlignmentI al = viewport.getAlignment();
5787 viewport.firePropertyChange("alignment", null, al);
5791 public void setShowSeqFeatures(boolean b)
5793 showSeqFeatures.setSelected(b);
5794 viewport.setShowSequenceFeatures(b);
5801 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5802 * awt.event.ActionEvent)
5805 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5807 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5808 alignPanel.paintAlignment(true);
5815 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5819 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5821 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5822 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5830 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5831 * .event.ActionEvent)
5834 protected void showGroupConservation_actionPerformed(ActionEvent e)
5836 viewport.setShowGroupConservation(showGroupConservation.getState());
5837 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5844 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5845 * .event.ActionEvent)
5848 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5850 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5851 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5858 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5859 * .event.ActionEvent)
5862 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5864 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5865 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5869 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5871 showSequenceLogo.setState(true);
5872 viewport.setShowSequenceLogo(true);
5873 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5874 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5878 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5880 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5887 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5888 * .event.ActionEvent)
5891 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5893 if (avc.makeGroupsFromSelection())
5895 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5896 alignPanel.updateAnnotation();
5897 alignPanel.paintAlignment(true);
5901 public void clearAlignmentSeqRep()
5903 // TODO refactor alignmentseqrep to controller
5904 if (viewport.getAlignment().hasSeqrep())
5906 viewport.getAlignment().setSeqrep(null);
5907 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5908 alignPanel.updateAnnotation();
5909 alignPanel.paintAlignment(true);
5914 protected void createGroup_actionPerformed(ActionEvent e)
5916 if (avc.createGroup())
5918 alignPanel.alignmentChanged();
5923 protected void unGroup_actionPerformed(ActionEvent e)
5927 alignPanel.alignmentChanged();
5932 * make the given alignmentPanel the currently selected tab
5934 * @param alignmentPanel
5936 public void setDisplayedView(AlignmentPanel alignmentPanel)
5938 if (!viewport.getSequenceSetId().equals(
5939 alignmentPanel.av.getSequenceSetId()))
5943 .getString("error.implementation_error_cannot_show_view_alignment_frame"));
5945 if (tabbedPane != null
5946 && tabbedPane.getTabCount() > 0
5947 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5948 .getSelectedIndex())
5950 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5955 * Action on selection of menu options to Show or Hide annotations.
5958 * @param forSequences
5959 * update sequence-related annotations
5960 * @param forAlignment
5961 * update non-sequence-related annotations
5964 protected void setAnnotationsVisibility(boolean visible,
5965 boolean forSequences, boolean forAlignment)
5967 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5968 .getAlignmentAnnotation())
5971 * don't display non-positional annotations on an alignment
5973 if (aa.annotations == null)
5977 boolean apply = (aa.sequenceRef == null && forAlignment)
5978 || (aa.sequenceRef != null && forSequences);
5981 aa.visible = visible;
5984 alignPanel.validateAnnotationDimensions(true);
5985 alignPanel.alignmentChanged();
5989 * Store selected annotation sort order for the view and repaint.
5992 protected void sortAnnotations_actionPerformed()
5994 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5996 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5997 alignPanel.paintAlignment(true);
6002 * @return alignment panels in this alignment frame
6004 public List<? extends AlignmentViewPanel> getAlignPanels()
6006 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
6010 * Open a new alignment window, with the cDNA associated with this (protein)
6011 * alignment, aligned as is the protein.
6013 protected void viewAsCdna_actionPerformed()
6015 // TODO no longer a menu action - refactor as required
6016 final AlignmentI alignment = getViewport().getAlignment();
6017 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6018 if (mappings == null)
6022 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6023 for (SequenceI aaSeq : alignment.getSequences())
6025 for (AlignedCodonFrame acf : mappings)
6027 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6031 * There is a cDNA mapping for this protein sequence - add to new
6032 * alignment. It will share the same dataset sequence as other mapped
6033 * cDNA (no new mappings need to be created).
6035 final Sequence newSeq = new Sequence(dnaSeq);
6036 newSeq.setDatasetSequence(dnaSeq);
6037 cdnaSeqs.add(newSeq);
6041 if (cdnaSeqs.size() == 0)
6043 // show a warning dialog no mapped cDNA
6046 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6048 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6049 AlignFrame.DEFAULT_HEIGHT);
6050 cdna.alignAs(alignment);
6051 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6053 Desktop.addInternalFrame(alignFrame, newtitle,
6054 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
6058 * Set visibility of dna/protein complement view (available when shown in a
6064 protected void showComplement_actionPerformed(boolean show)
6066 SplitContainerI sf = getSplitViewContainer();
6069 sf.setComplementVisible(this, show);
6074 * Generate the reverse (optionally complemented) of the selected sequences,
6075 * and add them to the alignment
6078 protected void showReverse_actionPerformed(boolean complement)
6080 AlignmentI al = null;
6083 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
6085 al = dna.reverseCdna(complement);
6086 viewport.addAlignment(al, "");
6087 } catch (Exception ex)
6089 System.err.println(ex.getMessage());
6095 class PrintThread extends Thread
6099 public PrintThread(AlignmentPanel ap)
6104 static PageFormat pf;
6109 PrinterJob printJob = PrinterJob.getPrinterJob();
6113 printJob.setPrintable(ap, pf);
6117 printJob.setPrintable(ap);
6120 if (printJob.printDialog())
6125 } catch (Exception PrintException)
6127 PrintException.printStackTrace();