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.SplitContainerI;
36 import jalview.api.ViewStyleI;
37 import jalview.api.analysis.ScoreModelI;
38 import jalview.bin.Cache;
39 import jalview.bin.Jalview;
40 import jalview.commands.CommandI;
41 import jalview.commands.EditCommand;
42 import jalview.commands.EditCommand.Action;
43 import jalview.commands.OrderCommand;
44 import jalview.commands.RemoveGapColCommand;
45 import jalview.commands.RemoveGapsCommand;
46 import jalview.commands.SlideSequencesCommand;
47 import jalview.commands.TrimRegionCommand;
48 import jalview.datamodel.AlignedCodonFrame;
49 import jalview.datamodel.Alignment;
50 import jalview.datamodel.AlignmentAnnotation;
51 import jalview.datamodel.AlignmentExportData;
52 import jalview.datamodel.AlignmentI;
53 import jalview.datamodel.AlignmentOrder;
54 import jalview.datamodel.AlignmentView;
55 import jalview.datamodel.ColumnSelection;
56 import jalview.datamodel.HiddenSequences;
57 import jalview.datamodel.PDBEntry;
58 import jalview.datamodel.SeqCigar;
59 import jalview.datamodel.Sequence;
60 import jalview.datamodel.SequenceGroup;
61 import jalview.datamodel.SequenceI;
62 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
63 import jalview.io.AlignmentProperties;
64 import jalview.io.AnnotationFile;
65 import jalview.io.BioJsHTMLOutput;
66 import jalview.io.FileLoader;
67 import jalview.io.FormatAdapter;
68 import jalview.io.HtmlSvgOutput;
69 import jalview.io.IdentifyFile;
70 import jalview.io.JalviewFileChooser;
71 import jalview.io.JalviewFileView;
72 import jalview.io.JnetAnnotationMaker;
73 import jalview.io.NewickFile;
74 import jalview.io.TCoffeeScoreFile;
75 import jalview.jbgui.GAlignFrame;
76 import jalview.schemes.Blosum62ColourScheme;
77 import jalview.schemes.BuriedColourScheme;
78 import jalview.schemes.ClustalxColourScheme;
79 import jalview.schemes.ColourSchemeI;
80 import jalview.schemes.ColourSchemeProperty;
81 import jalview.schemes.HelixColourScheme;
82 import jalview.schemes.HydrophobicColourScheme;
83 import jalview.schemes.NucleotideColourScheme;
84 import jalview.schemes.PIDColourScheme;
85 import jalview.schemes.PurinePyrimidineColourScheme;
86 import jalview.schemes.RNAHelicesColourChooser;
87 import jalview.schemes.ResidueProperties;
88 import jalview.schemes.StrandColourScheme;
89 import jalview.schemes.TCoffeeColourScheme;
90 import jalview.schemes.TaylorColourScheme;
91 import jalview.schemes.TurnColourScheme;
92 import jalview.schemes.UserColourScheme;
93 import jalview.schemes.ZappoColourScheme;
94 import jalview.structure.StructureSelectionManager;
95 import jalview.util.MessageManager;
96 import jalview.viewmodel.AlignmentViewport;
97 import jalview.ws.jws1.Discoverer;
98 import jalview.ws.jws2.Jws2Discoverer;
99 import jalview.ws.jws2.jabaws2.Jws2Instance;
100 import jalview.ws.seqfetcher.DbSourceProxy;
102 import java.awt.BorderLayout;
103 import java.awt.Component;
104 import java.awt.Rectangle;
105 import java.awt.Toolkit;
106 import java.awt.datatransfer.Clipboard;
107 import java.awt.datatransfer.DataFlavor;
108 import java.awt.datatransfer.StringSelection;
109 import java.awt.datatransfer.Transferable;
110 import java.awt.dnd.DnDConstants;
111 import java.awt.dnd.DropTargetDragEvent;
112 import java.awt.dnd.DropTargetDropEvent;
113 import java.awt.dnd.DropTargetEvent;
114 import java.awt.dnd.DropTargetListener;
115 import java.awt.event.ActionEvent;
116 import java.awt.event.ActionListener;
117 import java.awt.event.ItemEvent;
118 import java.awt.event.ItemListener;
119 import java.awt.event.KeyAdapter;
120 import java.awt.event.KeyEvent;
121 import java.awt.event.MouseAdapter;
122 import java.awt.event.MouseEvent;
123 import java.awt.print.PageFormat;
124 import java.awt.print.PrinterJob;
125 import java.beans.PropertyChangeEvent;
128 import java.util.ArrayList;
129 import java.util.Arrays;
130 import java.util.Deque;
131 import java.util.Enumeration;
132 import java.util.Hashtable;
133 import java.util.List;
134 import java.util.Set;
135 import java.util.Vector;
137 import javax.swing.JCheckBoxMenuItem;
138 import javax.swing.JEditorPane;
139 import javax.swing.JInternalFrame;
140 import javax.swing.JLayeredPane;
141 import javax.swing.JMenu;
142 import javax.swing.JMenuItem;
143 import javax.swing.JOptionPane;
144 import javax.swing.JRadioButtonMenuItem;
145 import javax.swing.JScrollPane;
146 import javax.swing.SwingUtilities;
152 * @version $Revision$
154 public class AlignFrame extends GAlignFrame implements DropTargetListener,
155 IProgressIndicator, AlignViewControllerGuiI
158 public static final int DEFAULT_WIDTH = 700;
160 public static final int DEFAULT_HEIGHT = 500;
163 * The currently displayed panel (selected tabbed view if more than one)
165 public AlignmentPanel alignPanel;
167 AlignViewport viewport;
169 public AlignViewControllerI avc;
171 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
174 * Last format used to load or save alignments in this window
176 String currentFileFormat = null;
179 * Current filename for this alignment
181 String fileName = null;
184 * Creates a new AlignFrame object with specific width and height.
190 public AlignFrame(AlignmentI al, int width, int height)
192 this(al, null, width, height);
196 * Creates a new AlignFrame object with specific width, height and
202 * @param sequenceSetId
204 public AlignFrame(AlignmentI al, int width, int height,
205 String sequenceSetId)
207 this(al, null, width, height, sequenceSetId);
211 * Creates a new AlignFrame object with specific width, height and
217 * @param sequenceSetId
220 public AlignFrame(AlignmentI al, int width, int height,
221 String sequenceSetId, String viewId)
223 this(al, null, width, height, sequenceSetId, viewId);
227 * new alignment window with hidden columns
231 * @param hiddenColumns
232 * ColumnSelection or null
234 * Width of alignment frame
238 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
239 int width, int height)
241 this(al, hiddenColumns, width, height, null);
245 * Create alignment frame for al with hiddenColumns, a specific width and
246 * height, and specific sequenceId
249 * @param hiddenColumns
252 * @param sequenceSetId
255 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
256 int width, int height, String sequenceSetId)
258 this(al, hiddenColumns, width, height, sequenceSetId, null);
262 * Create alignment frame for al with hiddenColumns, a specific width and
263 * height, and specific sequenceId
266 * @param hiddenColumns
269 * @param sequenceSetId
274 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
275 int width, int height, String sequenceSetId, String viewId)
277 setSize(width, height);
279 if (al.getDataset() == null)
284 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
286 alignPanel = new AlignmentPanel(this, viewport);
288 addAlignmentPanel(alignPanel, true);
292 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
293 ColumnSelection hiddenColumns, int width, int height)
295 setSize(width, height);
297 if (al.getDataset() == null)
302 viewport = new AlignViewport(al, hiddenColumns);
304 if (hiddenSeqs != null && hiddenSeqs.length > 0)
306 viewport.hideSequence(hiddenSeqs);
308 alignPanel = new AlignmentPanel(this, viewport);
309 addAlignmentPanel(alignPanel, true);
314 * Make a new AlignFrame from existing alignmentPanels
321 public AlignFrame(AlignmentPanel ap)
325 addAlignmentPanel(ap, false);
330 * initalise the alignframe from the underlying viewport data and the
335 if (!Jalview.isHeadlessMode())
337 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
340 avc = new jalview.controller.AlignViewController(this, viewport,
342 if (viewport.getAlignmentConservationAnnotation() == null)
344 BLOSUM62Colour.setEnabled(false);
345 conservationMenuItem.setEnabled(false);
346 modifyConservation.setEnabled(false);
347 // PIDColour.setEnabled(false);
348 // abovePIDThreshold.setEnabled(false);
349 // modifyPID.setEnabled(false);
352 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
355 if (sortby.equals("Id"))
357 sortIDMenuItem_actionPerformed(null);
359 else if (sortby.equals("Pairwise Identity"))
361 sortPairwiseMenuItem_actionPerformed(null);
364 if (Desktop.desktop != null)
366 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
367 addServiceListeners();
368 setGUINucleotide(viewport.getAlignment().isNucleotide());
372 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
374 setMenusFromViewport(viewport);
375 buildSortByAnnotationScoresMenu();
378 if (viewport.getWrapAlignment())
380 wrapMenuItem_actionPerformed(null);
383 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
385 this.overviewMenuItem_actionPerformed(null);
390 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
391 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
392 final String menuLabel = MessageManager
393 .getString("label.copy_format_from");
394 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
395 new ViewSetProvider()
399 public AlignmentPanel[] getAllAlignmentPanels()
402 origview.add(alignPanel);
403 // make an array of all alignment panels except for this one
404 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
405 Arrays.asList(Desktop.getAlignmentPanels(null)));
406 aps.remove(AlignFrame.this.alignPanel);
407 return aps.toArray(new AlignmentPanel[aps.size()]);
409 }, selviews, new ItemListener()
413 public void itemStateChanged(ItemEvent e)
415 if (origview.size() > 0)
417 final AlignmentPanel ap = origview.get(0);
420 * Copy the ViewStyle of the selected panel to 'this one'.
421 * Don't change value of 'scaleProteinAsCdna' unless copying
424 ViewStyleI vs = selviews.get(0).getAlignViewport()
426 boolean fromSplitFrame = selviews.get(0)
427 .getAlignViewport().getCodingComplement() != null;
430 vs.setScaleProteinAsCdna(ap.getAlignViewport()
431 .getViewStyle().isScaleProteinAsCdna());
433 ap.getAlignViewport().setViewStyle(vs);
436 * Also rescale ViewStyle of SplitFrame complement if there is
437 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
438 * the whole ViewStyle (allow cDNA protein to have different
441 AlignViewportI complement = ap.getAlignViewport()
442 .getCodingComplement();
443 if (complement != null && vs.isScaleProteinAsCdna())
445 AlignFrame af = Desktop.getAlignFrameFor(complement);
446 ((SplitFrame) af.getSplitViewContainer())
448 af.setMenusForViewport();
452 ap.setSelected(true);
453 ap.alignFrame.setMenusForViewport();
458 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
459 .indexOf("devel") > -1
460 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
461 .indexOf("test") > -1)
463 formatMenu.add(vsel);
469 * Change the filename and format for the alignment, and enable the 'reload'
470 * button functionality.
477 public void setFileName(String file, String format)
480 setFileFormat(format);
481 reload.setEnabled(true);
485 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
488 void addKeyListener()
490 addKeyListener(new KeyAdapter()
493 public void keyPressed(KeyEvent evt)
495 if (viewport.cursorMode
496 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
497 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
498 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
499 && Character.isDigit(evt.getKeyChar()))
501 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
504 switch (evt.getKeyCode())
507 case 27: // escape key
508 deselectAllSequenceMenuItem_actionPerformed(null);
512 case KeyEvent.VK_DOWN:
513 if (evt.isAltDown() || !viewport.cursorMode)
515 moveSelectedSequences(false);
517 if (viewport.cursorMode)
519 alignPanel.getSeqPanel().moveCursor(0, 1);
524 if (evt.isAltDown() || !viewport.cursorMode)
526 moveSelectedSequences(true);
528 if (viewport.cursorMode)
530 alignPanel.getSeqPanel().moveCursor(0, -1);
535 case KeyEvent.VK_LEFT:
536 if (evt.isAltDown() || !viewport.cursorMode)
538 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
542 alignPanel.getSeqPanel().moveCursor(-1, 0);
547 case KeyEvent.VK_RIGHT:
548 if (evt.isAltDown() || !viewport.cursorMode)
550 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
554 alignPanel.getSeqPanel().moveCursor(1, 0);
558 case KeyEvent.VK_SPACE:
559 if (viewport.cursorMode)
561 alignPanel.getSeqPanel().insertGapAtCursor(
562 evt.isControlDown() || evt.isShiftDown()
567 // case KeyEvent.VK_A:
568 // if (viewport.cursorMode)
570 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
571 // //System.out.println("A");
575 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
576 * System.out.println("closing bracket"); } break;
578 case KeyEvent.VK_DELETE:
579 case KeyEvent.VK_BACK_SPACE:
580 if (!viewport.cursorMode)
582 cut_actionPerformed(null);
586 alignPanel.getSeqPanel().deleteGapAtCursor(
587 evt.isControlDown() || evt.isShiftDown()
594 if (viewport.cursorMode)
596 alignPanel.getSeqPanel().setCursorRow();
600 if (viewport.cursorMode && !evt.isControlDown())
602 alignPanel.getSeqPanel().setCursorColumn();
606 if (viewport.cursorMode)
608 alignPanel.getSeqPanel().setCursorPosition();
612 case KeyEvent.VK_ENTER:
613 case KeyEvent.VK_COMMA:
614 if (viewport.cursorMode)
616 alignPanel.getSeqPanel().setCursorRowAndColumn();
621 if (viewport.cursorMode)
623 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
627 if (viewport.cursorMode)
629 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
634 viewport.cursorMode = !viewport.cursorMode;
635 statusBar.setText(MessageManager.formatMessage(
636 "label.keyboard_editing_mode",
637 new String[] { (viewport.cursorMode ? "on" : "off") }));
638 if (viewport.cursorMode)
640 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
641 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
643 alignPanel.getSeqPanel().seqCanvas.repaint();
649 Help.showHelpWindow();
650 } catch (Exception ex)
652 ex.printStackTrace();
657 boolean toggleSeqs = !evt.isControlDown();
658 boolean toggleCols = !evt.isShiftDown();
659 toggleHiddenRegions(toggleSeqs, toggleCols);
662 case KeyEvent.VK_PAGE_UP:
663 if (viewport.getWrapAlignment())
665 alignPanel.scrollUp(true);
669 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
670 - viewport.endSeq + viewport.startSeq);
673 case KeyEvent.VK_PAGE_DOWN:
674 if (viewport.getWrapAlignment())
676 alignPanel.scrollUp(false);
680 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
681 + viewport.endSeq - viewport.startSeq);
688 public void keyReleased(KeyEvent evt)
690 switch (evt.getKeyCode())
692 case KeyEvent.VK_LEFT:
693 if (evt.isAltDown() || !viewport.cursorMode)
695 viewport.firePropertyChange("alignment", null, viewport
696 .getAlignment().getSequences());
700 case KeyEvent.VK_RIGHT:
701 if (evt.isAltDown() || !viewport.cursorMode)
703 viewport.firePropertyChange("alignment", null, viewport
704 .getAlignment().getSequences());
712 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
714 ap.alignFrame = this;
715 avc = new jalview.controller.AlignViewController(this, viewport,
720 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
722 int aSize = alignPanels.size();
724 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
726 if (aSize == 1 && ap.av.viewName == null)
728 this.getContentPane().add(ap, BorderLayout.CENTER);
734 setInitialTabVisible();
737 expandViews.setEnabled(true);
738 gatherViews.setEnabled(true);
739 tabbedPane.addTab(ap.av.viewName, ap);
741 ap.setVisible(false);
746 if (ap.av.isPadGaps())
748 ap.av.getAlignment().padGaps();
750 ap.av.updateConservation(ap);
751 ap.av.updateConsensus(ap);
752 ap.av.updateStrucConsensus(ap);
756 public void setInitialTabVisible()
758 expandViews.setEnabled(true);
759 gatherViews.setEnabled(true);
760 tabbedPane.setVisible(true);
761 AlignmentPanel first = alignPanels.get(0);
762 tabbedPane.addTab(first.av.viewName, first);
763 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
766 public AlignViewport getViewport()
771 /* Set up intrinsic listeners for dynamically generated GUI bits. */
772 private void addServiceListeners()
774 final java.beans.PropertyChangeListener thisListener;
775 Desktop.instance.addJalviewPropertyChangeListener("services",
776 thisListener = new java.beans.PropertyChangeListener()
779 public void propertyChange(PropertyChangeEvent evt)
781 // // System.out.println("Discoverer property change.");
782 // if (evt.getPropertyName().equals("services"))
784 SwingUtilities.invokeLater(new Runnable()
791 .println("Rebuild WS Menu for service change");
792 BuildWebServiceMenu();
799 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
802 public void internalFrameClosed(
803 javax.swing.event.InternalFrameEvent evt)
805 // System.out.println("deregistering discoverer listener");
806 Desktop.instance.removeJalviewPropertyChangeListener("services",
808 closeMenuItem_actionPerformed(true);
811 // Finally, build the menu once to get current service state
812 new Thread(new Runnable()
817 BuildWebServiceMenu();
823 * Configure menu items that vary according to whether the alignment is
824 * nucleotide or protein
828 public void setGUINucleotide(boolean nucleotide)
830 showTranslation.setVisible(nucleotide);
831 conservationMenuItem.setEnabled(!nucleotide);
832 modifyConservation.setEnabled(!nucleotide);
833 showGroupConservation.setEnabled(!nucleotide);
834 rnahelicesColour.setEnabled(nucleotide);
835 purinePyrimidineColour.setEnabled(nucleotide);
836 showComplementMenuItem.setText(MessageManager
837 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
838 setColourSelected(jalview.bin.Cache.getDefault(
839 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
840 : Preferences.DEFAULT_COLOUR_PROT, "None"));
844 * set up menus for the current viewport. This may be called after any
845 * operation that affects the data in the current view (selection changed,
846 * etc) to update the menus to reflect the new state.
848 public void setMenusForViewport()
850 setMenusFromViewport(viewport);
854 * Need to call this method when tabs are selected for multiple views, or when
855 * loading from Jalview2XML.java
860 void setMenusFromViewport(AlignViewport av)
862 padGapsMenuitem.setSelected(av.isPadGaps());
863 colourTextMenuItem.setSelected(av.isShowColourText());
864 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
865 conservationMenuItem.setSelected(av.getConservationSelected());
866 seqLimits.setSelected(av.getShowJVSuffix());
867 idRightAlign.setSelected(av.isRightAlignIds());
868 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
869 renderGapsMenuItem.setSelected(av.isRenderGaps());
870 wrapMenuItem.setSelected(av.getWrapAlignment());
871 scaleAbove.setVisible(av.getWrapAlignment());
872 scaleLeft.setVisible(av.getWrapAlignment());
873 scaleRight.setVisible(av.getWrapAlignment());
874 annotationPanelMenuItem.setState(av.isShowAnnotation());
876 * Show/hide annotations only enabled if annotation panel is shown
878 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
879 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
880 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
881 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
882 viewBoxesMenuItem.setSelected(av.getShowBoxes());
883 viewTextMenuItem.setSelected(av.getShowText());
884 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
885 showGroupConsensus.setSelected(av.isShowGroupConsensus());
886 showGroupConservation.setSelected(av.isShowGroupConservation());
887 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
888 showSequenceLogo.setSelected(av.isShowSequenceLogo());
889 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
891 setColourSelected(ColourSchemeProperty.getColourName(av
892 .getGlobalColourScheme()));
894 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
895 hiddenMarkers.setState(av.getShowHiddenMarkers());
896 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
897 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
898 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
899 autoCalculate.setSelected(av.autoCalculateConsensus);
900 sortByTree.setSelected(av.sortByTree);
901 listenToViewSelections.setSelected(av.followSelection);
902 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
904 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
905 setShowProductsEnabled();
909 private IProgressIndicator progressBar;
914 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
917 public void setProgressBar(String message, long id)
919 progressBar.setProgressBar(message, id);
923 public void registerHandler(final long id,
924 final IProgressIndicatorHandler handler)
926 progressBar.registerHandler(id, handler);
931 * @return true if any progress bars are still active
934 public boolean operationInProgress()
936 return progressBar.operationInProgress();
940 public void setStatus(String text)
942 statusBar.setText(text);
946 * Added so Castor Mapping file can obtain Jalview Version
948 public String getVersion()
950 return jalview.bin.Cache.getProperty("VERSION");
953 public FeatureRenderer getFeatureRenderer()
955 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
959 public void fetchSequence_actionPerformed(ActionEvent e)
961 new SequenceFetcher(this);
965 public void addFromFile_actionPerformed(ActionEvent e)
967 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
971 public void reload_actionPerformed(ActionEvent e)
973 if (fileName != null)
975 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
976 // originating file's format
977 // TODO: work out how to recover feature settings for correct view(s) when
979 if (currentFileFormat.equals("Jalview"))
981 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
982 for (int i = 0; i < frames.length; i++)
984 if (frames[i] instanceof AlignFrame && frames[i] != this
985 && ((AlignFrame) frames[i]).fileName != null
986 && ((AlignFrame) frames[i]).fileName.equals(fileName))
990 frames[i].setSelected(true);
991 Desktop.instance.closeAssociatedWindows();
992 } catch (java.beans.PropertyVetoException ex)
998 Desktop.instance.closeAssociatedWindows();
1000 FileLoader loader = new FileLoader();
1001 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1002 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1006 Rectangle bounds = this.getBounds();
1008 FileLoader loader = new FileLoader();
1009 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1010 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1011 protocol, currentFileFormat);
1013 newframe.setBounds(bounds);
1014 if (featureSettings != null && featureSettings.isShowing())
1016 final Rectangle fspos = featureSettings.frame.getBounds();
1017 // TODO: need a 'show feature settings' function that takes bounds -
1018 // need to refactor Desktop.addFrame
1019 newframe.featureSettings_actionPerformed(null);
1020 final FeatureSettings nfs = newframe.featureSettings;
1021 SwingUtilities.invokeLater(new Runnable()
1026 nfs.frame.setBounds(fspos);
1029 this.featureSettings.close();
1030 this.featureSettings = null;
1032 this.closeMenuItem_actionPerformed(true);
1038 public void addFromText_actionPerformed(ActionEvent e)
1040 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport
1045 public void addFromURL_actionPerformed(ActionEvent e)
1047 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1051 public void save_actionPerformed(ActionEvent e)
1053 if (fileName == null
1054 || (currentFileFormat == null || !jalview.io.FormatAdapter
1055 .isValidIOFormat(currentFileFormat, true))
1056 || fileName.startsWith("http"))
1058 saveAs_actionPerformed(null);
1062 saveAlignment(fileName, currentFileFormat);
1073 public void saveAs_actionPerformed(ActionEvent e)
1075 JalviewFileChooser chooser = new JalviewFileChooser(
1076 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1077 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1078 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1079 currentFileFormat, false);
1081 chooser.setFileView(new JalviewFileView());
1082 chooser.setDialogTitle(MessageManager
1083 .getString("label.save_alignment_to_file"));
1084 chooser.setToolTipText(MessageManager.getString("action.save"));
1086 int value = chooser.showSaveDialog(this);
1088 if (value == JalviewFileChooser.APPROVE_OPTION)
1090 currentFileFormat = chooser.getSelectedFormat();
1091 while (currentFileFormat == null)
1094 .showInternalMessageDialog(
1097 .getString("label.select_file_format_before_saving"),
1099 .getString("label.file_format_not_specified"),
1100 JOptionPane.WARNING_MESSAGE);
1101 currentFileFormat = chooser.getSelectedFormat();
1102 value = chooser.showSaveDialog(this);
1103 if (value != JalviewFileChooser.APPROVE_OPTION)
1109 fileName = chooser.getSelectedFile().getPath();
1111 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1114 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1115 if (currentFileFormat.indexOf(" ") > -1)
1117 currentFileFormat = currentFileFormat.substring(0,
1118 currentFileFormat.indexOf(" "));
1120 saveAlignment(fileName, currentFileFormat);
1124 public boolean saveAlignment(String file, String format)
1126 boolean success = true;
1128 if (format.equalsIgnoreCase("Jalview"))
1130 String shortName = title;
1132 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1134 shortName = shortName.substring(shortName
1135 .lastIndexOf(java.io.File.separatorChar) + 1);
1138 success = new Jalview2XML().saveAlignment(this, file, shortName);
1140 statusBar.setText(MessageManager.formatMessage(
1141 "label.successfully_saved_to_file_in_format", new Object[] {
1142 fileName, format }));
1147 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1149 warningMessage("Cannot save file " + fileName + " using format "
1150 + format, "Alignment output format not supported");
1151 if (!Jalview.isHeadlessMode())
1153 saveAs_actionPerformed(null);
1158 AlignmentExportData exportData = getAlignmentForExport(format,
1160 if (exportData.getSettings().isCancelled())
1164 FormatAdapter f = new FormatAdapter(alignPanel,
1165 exportData.getSettings());
1166 String output = f.formatSequences(
1168 exportData.getAlignment(), // class cast exceptions will
1169 // occur in the distant future
1170 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1171 f.getCacheSuffixDefault(format),
1172 viewport.getColumnSelection());
1182 java.io.PrintWriter out = new java.io.PrintWriter(
1183 new java.io.FileWriter(file));
1187 this.setTitle(file);
1188 statusBar.setText(MessageManager.formatMessage(
1189 "label.successfully_saved_to_file_in_format",
1190 new Object[] { fileName, format }));
1191 } catch (Exception ex)
1194 ex.printStackTrace();
1201 JOptionPane.showInternalMessageDialog(this, MessageManager
1202 .formatMessage("label.couldnt_save_file",
1203 new Object[] { fileName }), MessageManager
1204 .getString("label.error_saving_file"),
1205 JOptionPane.WARNING_MESSAGE);
1211 private void warningMessage(String warning, String title)
1213 if (new jalview.util.Platform().isHeadless())
1215 System.err.println("Warning: " + title + "\nWarning: " + warning);
1220 JOptionPane.showInternalMessageDialog(this, warning, title,
1221 JOptionPane.WARNING_MESSAGE);
1233 protected void outputText_actionPerformed(ActionEvent e)
1236 AlignmentExportData exportData = getAlignmentForExport(
1237 e.getActionCommand(), viewport, null);
1238 if (exportData.getSettings().isCancelled())
1242 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1243 cap.setForInput(null);
1246 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1247 .formatSequences(e.getActionCommand(),
1248 exportData.getAlignment(),
1249 exportData.getOmitHidden(),
1250 exportData.getStartEndPostions(),
1251 viewport.getColumnSelection()));
1252 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1253 "label.alignment_output_command",
1254 new Object[] { e.getActionCommand() }), 600, 500);
1255 } catch (OutOfMemoryError oom)
1257 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1263 public static AlignmentExportData getAlignmentForExport(
1264 String exportFormat, AlignViewportI viewport,
1265 AlignExportSettingI exportSettings)
1267 AlignmentI alignmentToExport = null;
1268 AlignExportSettingI settings = exportSettings;
1269 String[] omitHidden = null;
1270 int[] alignmentStartEnd = new int[2];
1272 HiddenSequences hiddenSeqs = viewport.getAlignment()
1273 .getHiddenSequences();
1275 alignmentToExport = viewport.getAlignment();
1276 alignmentStartEnd = new int[] { 0, alignmentToExport.getWidth() - 1 };
1278 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1279 if (settings == null)
1281 settings = new AlignExportSettings(hasHiddenSeqs,
1282 viewport.hasHiddenColumns(), exportFormat);
1284 // settings.isExportAnnotations();
1286 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1288 omitHidden = viewport.getViewAsString(false);
1291 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1293 alignmentToExport = hiddenSeqs.getFullAlignment();
1297 alignmentToExport = viewport.getAlignment();
1298 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1299 .getColumnSelection().getHiddenColumns());
1301 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1302 omitHidden, alignmentStartEnd, settings);
1306 public static int[] getStartEnd(int[] aligmentStartEnd,
1307 List<int[]> hiddenCols)
1309 int startPos = aligmentStartEnd[0];
1310 int endPos = aligmentStartEnd[1];
1312 int[] lowestRange = new int[] { -1, -1 };
1313 int[] higestRange = new int[] { -1, -1 };
1315 for (int[] hiddenCol : hiddenCols)
1317 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1318 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1321 if (lowestRange[0] == -1 && lowestRange[1] == -1)
1323 startPos = aligmentStartEnd[0];
1327 startPos = lowestRange[1] + 1;
1330 if (higestRange[0] == -1 && higestRange[1] == -1)
1332 endPos = aligmentStartEnd[1];
1336 endPos = higestRange[0] - 1;
1339 // System.out.println("Export range : " + startPos + " - " + endPos);
1340 return new int[] { startPos, endPos };
1343 public static void main(String[] args)
1345 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1346 hiddenCols.add(new int[] { 0, 0 });
1347 hiddenCols.add(new int[] { 6, 9 });
1348 hiddenCols.add(new int[] { 11, 12 });
1349 hiddenCols.add(new int[] { 33, 33 });
1350 hiddenCols.add(new int[] { 50, 50 });
1352 int[] x = getStartEnd(new int[] { 0, 50 }, hiddenCols);
1353 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1363 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1365 new HtmlSvgOutput(null, alignPanel);
1369 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1371 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1372 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1375 public void createImageMap(File file, String image)
1377 alignPanel.makePNGImageMap(file, image);
1387 public void createPNG(File f)
1389 alignPanel.makePNG(f);
1399 public void createEPS(File f)
1401 alignPanel.makeEPS(f);
1404 public void createSVG(File f)
1406 alignPanel.makeSVG(f);
1410 public void pageSetup_actionPerformed(ActionEvent e)
1412 PrinterJob printJob = PrinterJob.getPrinterJob();
1413 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1423 public void printMenuItem_actionPerformed(ActionEvent e)
1425 // Putting in a thread avoids Swing painting problems
1426 PrintThread thread = new PrintThread(alignPanel);
1431 public void exportFeatures_actionPerformed(ActionEvent e)
1433 new AnnotationExporter().exportFeatures(alignPanel);
1437 public void exportAnnotations_actionPerformed(ActionEvent e)
1439 new AnnotationExporter().exportAnnotations(alignPanel);
1443 public void associatedData_actionPerformed(ActionEvent e)
1445 // Pick the tree file
1446 JalviewFileChooser chooser = new JalviewFileChooser(
1447 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1448 chooser.setFileView(new JalviewFileView());
1449 chooser.setDialogTitle(MessageManager
1450 .getString("label.load_jalview_annotations"));
1451 chooser.setToolTipText(MessageManager
1452 .getString("label.load_jalview_annotations"));
1454 int value = chooser.showOpenDialog(null);
1456 if (value == JalviewFileChooser.APPROVE_OPTION)
1458 String choice = chooser.getSelectedFile().getPath();
1459 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1460 loadJalviewDataFile(choice, null, null, null);
1466 * Close the current view or all views in the alignment frame. If the frame
1467 * only contains one view then the alignment will be removed from memory.
1469 * @param closeAllTabs
1472 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1474 if (alignPanels != null && alignPanels.size() < 2)
1476 closeAllTabs = true;
1481 if (alignPanels != null)
1485 if (this.isClosed())
1487 // really close all the windows - otherwise wait till
1488 // setClosed(true) is called
1489 for (int i = 0; i < alignPanels.size(); i++)
1491 AlignmentPanel ap = alignPanels.get(i);
1498 closeView(alignPanel);
1505 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1506 * be called recursively, with the frame now in 'closed' state
1508 this.setClosed(true);
1510 } catch (Exception ex)
1512 ex.printStackTrace();
1517 * Close the specified panel and close up tabs appropriately.
1519 * @param panelToClose
1521 public void closeView(AlignmentPanel panelToClose)
1523 int index = tabbedPane.getSelectedIndex();
1524 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1525 alignPanels.remove(panelToClose);
1526 panelToClose.closePanel();
1527 panelToClose = null;
1529 tabbedPane.removeTabAt(closedindex);
1530 tabbedPane.validate();
1532 if (index > closedindex || index == tabbedPane.getTabCount())
1534 // modify currently selected tab index if necessary.
1538 this.tabSelectionChanged(index);
1544 void updateEditMenuBar()
1547 if (viewport.getHistoryList().size() > 0)
1549 undoMenuItem.setEnabled(true);
1550 CommandI command = viewport.getHistoryList().peek();
1551 undoMenuItem.setText(MessageManager.formatMessage(
1552 "label.undo_command",
1553 new Object[] { command.getDescription() }));
1557 undoMenuItem.setEnabled(false);
1558 undoMenuItem.setText(MessageManager.getString("action.undo"));
1561 if (viewport.getRedoList().size() > 0)
1563 redoMenuItem.setEnabled(true);
1565 CommandI command = viewport.getRedoList().peek();
1566 redoMenuItem.setText(MessageManager.formatMessage(
1567 "label.redo_command",
1568 new Object[] { command.getDescription() }));
1572 redoMenuItem.setEnabled(false);
1573 redoMenuItem.setText(MessageManager.getString("action.redo"));
1577 public void addHistoryItem(CommandI command)
1579 if (command.getSize() > 0)
1581 viewport.addToHistoryList(command);
1582 viewport.clearRedoList();
1583 updateEditMenuBar();
1584 viewport.updateHiddenColumns();
1585 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1586 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1587 // viewport.getColumnSelection()
1588 // .getHiddenColumns().size() > 0);
1594 * @return alignment objects for all views
1596 AlignmentI[] getViewAlignments()
1598 if (alignPanels != null)
1600 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1602 for (AlignmentPanel ap : alignPanels)
1604 als[i++] = ap.av.getAlignment();
1608 if (viewport != null)
1610 return new AlignmentI[] { viewport.getAlignment() };
1622 protected void undoMenuItem_actionPerformed(ActionEvent e)
1624 if (viewport.getHistoryList().isEmpty())
1628 CommandI command = viewport.getHistoryList().pop();
1629 viewport.addToRedoList(command);
1630 command.undoCommand(getViewAlignments());
1632 AlignmentViewport originalSource = getOriginatingSource(command);
1633 updateEditMenuBar();
1635 if (originalSource != null)
1637 if (originalSource != viewport)
1640 .warn("Implementation worry: mismatch of viewport origin for undo");
1642 originalSource.updateHiddenColumns();
1643 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1645 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1646 // viewport.getColumnSelection()
1647 // .getHiddenColumns().size() > 0);
1648 originalSource.firePropertyChange("alignment", null, originalSource
1649 .getAlignment().getSequences());
1660 protected void redoMenuItem_actionPerformed(ActionEvent e)
1662 if (viewport.getRedoList().size() < 1)
1667 CommandI command = viewport.getRedoList().pop();
1668 viewport.addToHistoryList(command);
1669 command.doCommand(getViewAlignments());
1671 AlignmentViewport originalSource = getOriginatingSource(command);
1672 updateEditMenuBar();
1674 if (originalSource != null)
1677 if (originalSource != viewport)
1680 .warn("Implementation worry: mismatch of viewport origin for redo");
1682 originalSource.updateHiddenColumns();
1683 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1685 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1686 // viewport.getColumnSelection()
1687 // .getHiddenColumns().size() > 0);
1688 originalSource.firePropertyChange("alignment", null, originalSource
1689 .getAlignment().getSequences());
1693 AlignmentViewport getOriginatingSource(CommandI command)
1695 AlignmentViewport originalSource = null;
1696 // For sequence removal and addition, we need to fire
1697 // the property change event FROM the viewport where the
1698 // original alignment was altered
1699 AlignmentI al = null;
1700 if (command instanceof EditCommand)
1702 EditCommand editCommand = (EditCommand) command;
1703 al = editCommand.getAlignment();
1704 List<Component> comps = PaintRefresher.components.get(viewport
1705 .getSequenceSetId());
1707 for (Component comp : comps)
1709 if (comp instanceof AlignmentPanel)
1711 if (al == ((AlignmentPanel) comp).av.getAlignment())
1713 originalSource = ((AlignmentPanel) comp).av;
1720 if (originalSource == null)
1722 // The original view is closed, we must validate
1723 // the current view against the closed view first
1726 PaintRefresher.validateSequences(al, viewport.getAlignment());
1729 originalSource = viewport;
1732 return originalSource;
1741 public void moveSelectedSequences(boolean up)
1743 SequenceGroup sg = viewport.getSelectionGroup();
1749 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1750 viewport.getHiddenRepSequences(), up);
1751 alignPanel.paintAlignment(true);
1754 synchronized void slideSequences(boolean right, int size)
1756 List<SequenceI> sg = new ArrayList<SequenceI>();
1757 if (viewport.cursorMode)
1759 sg.add(viewport.getAlignment().getSequenceAt(
1760 alignPanel.getSeqPanel().seqCanvas.cursorY));
1762 else if (viewport.getSelectionGroup() != null
1763 && viewport.getSelectionGroup().getSize() != viewport
1764 .getAlignment().getHeight())
1766 sg = viewport.getSelectionGroup().getSequences(
1767 viewport.getHiddenRepSequences());
1775 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1777 for (SequenceI seq : viewport.getAlignment().getSequences())
1779 if (!sg.contains(seq))
1781 invertGroup.add(seq);
1785 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1787 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1788 for (int i = 0; i < invertGroup.size(); i++)
1790 seqs2[i] = invertGroup.get(i);
1793 SlideSequencesCommand ssc;
1796 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1797 size, viewport.getGapCharacter());
1801 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1802 size, viewport.getGapCharacter());
1805 int groupAdjustment = 0;
1806 if (ssc.getGapsInsertedBegin() && right)
1808 if (viewport.cursorMode)
1810 alignPanel.getSeqPanel().moveCursor(size, 0);
1814 groupAdjustment = size;
1817 else if (!ssc.getGapsInsertedBegin() && !right)
1819 if (viewport.cursorMode)
1821 alignPanel.getSeqPanel().moveCursor(-size, 0);
1825 groupAdjustment = -size;
1829 if (groupAdjustment != 0)
1831 viewport.getSelectionGroup().setStartRes(
1832 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1833 viewport.getSelectionGroup().setEndRes(
1834 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1838 * just extend the last slide command if compatible; but not if in
1839 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1841 boolean appendHistoryItem = false;
1842 Deque<CommandI> historyList = viewport.getHistoryList();
1843 boolean inSplitFrame = getSplitViewContainer() != null;
1844 if (!inSplitFrame && historyList != null && historyList.size() > 0
1845 && historyList.peek() instanceof SlideSequencesCommand)
1847 appendHistoryItem = ssc
1848 .appendSlideCommand((SlideSequencesCommand) historyList
1852 if (!appendHistoryItem)
1854 addHistoryItem(ssc);
1867 protected void copy_actionPerformed(ActionEvent e)
1870 if (viewport.getSelectionGroup() == null)
1874 // TODO: preserve the ordering of displayed alignment annotation in any
1875 // internal paste (particularly sequence associated annotation)
1876 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1877 String[] omitHidden = null;
1879 if (viewport.hasHiddenColumns())
1881 omitHidden = viewport.getViewAsString(true);
1884 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1887 StringSelection ss = new StringSelection(output);
1891 jalview.gui.Desktop.internalCopy = true;
1892 // Its really worth setting the clipboard contents
1893 // to empty before setting the large StringSelection!!
1894 Toolkit.getDefaultToolkit().getSystemClipboard()
1895 .setContents(new StringSelection(""), null);
1897 Toolkit.getDefaultToolkit().getSystemClipboard()
1898 .setContents(ss, Desktop.instance);
1899 } catch (OutOfMemoryError er)
1901 new OOMWarning("copying region", er);
1905 ArrayList<int[]> hiddenColumns = null;
1906 if (viewport.hasHiddenColumns())
1908 hiddenColumns = new ArrayList<int[]>();
1909 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1910 .getSelectionGroup().getEndRes();
1911 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1913 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1915 hiddenColumns.add(new int[] { region[0] - hiddenOffset,
1916 region[1] - hiddenOffset });
1921 Desktop.jalviewClipboard = new Object[] { seqs,
1922 viewport.getAlignment().getDataset(), hiddenColumns };
1923 statusBar.setText(MessageManager.formatMessage(
1924 "label.copied_sequences_to_clipboard", new Object[] { Integer
1925 .valueOf(seqs.length).toString() }));
1935 protected void pasteNew_actionPerformed(ActionEvent e)
1947 protected void pasteThis_actionPerformed(ActionEvent e)
1953 * Paste contents of Jalview clipboard
1955 * @param newAlignment
1956 * true to paste to a new alignment, otherwise add to this.
1958 void paste(boolean newAlignment)
1960 boolean externalPaste = true;
1963 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1964 Transferable contents = c.getContents(this);
1966 if (contents == null)
1974 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1975 if (str.length() < 1)
1980 format = new IdentifyFile().Identify(str, "Paste");
1982 } catch (OutOfMemoryError er)
1984 new OOMWarning("Out of memory pasting sequences!!", er);
1988 SequenceI[] sequences;
1989 boolean annotationAdded = false;
1990 AlignmentI alignment = null;
1992 if (Desktop.jalviewClipboard != null)
1994 // The clipboard was filled from within Jalview, we must use the
1996 // And dataset from the copied alignment
1997 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1998 // be doubly sure that we create *new* sequence objects.
1999 sequences = new SequenceI[newseq.length];
2000 for (int i = 0; i < newseq.length; i++)
2002 sequences[i] = new Sequence(newseq[i]);
2004 alignment = new Alignment(sequences);
2005 externalPaste = false;
2009 // parse the clipboard as an alignment.
2010 alignment = new FormatAdapter().readFile(str, "Paste", format);
2011 sequences = alignment.getSequencesArray();
2015 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2021 if (Desktop.jalviewClipboard != null)
2023 // dataset is inherited
2024 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2028 // new dataset is constructed
2029 alignment.setDataset(null);
2031 alwidth = alignment.getWidth() + 1;
2035 AlignmentI pastedal = alignment; // preserve pasted alignment object
2036 // Add pasted sequences and dataset into existing alignment.
2037 alignment = viewport.getAlignment();
2038 alwidth = alignment.getWidth() + 1;
2039 // decide if we need to import sequences from an existing dataset
2040 boolean importDs = Desktop.jalviewClipboard != null
2041 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2042 // importDs==true instructs us to copy over new dataset sequences from
2043 // an existing alignment
2044 Vector newDs = (importDs) ? new Vector() : null; // used to create
2045 // minimum dataset set
2047 for (int i = 0; i < sequences.length; i++)
2051 newDs.addElement(null);
2053 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2055 if (importDs && ds != null)
2057 if (!newDs.contains(ds))
2059 newDs.setElementAt(ds, i);
2060 ds = new Sequence(ds);
2061 // update with new dataset sequence
2062 sequences[i].setDatasetSequence(ds);
2066 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2071 // copy and derive new dataset sequence
2072 sequences[i] = sequences[i].deriveSequence();
2073 alignment.getDataset().addSequence(
2074 sequences[i].getDatasetSequence());
2075 // TODO: avoid creation of duplicate dataset sequences with a
2076 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2078 alignment.addSequence(sequences[i]); // merges dataset
2082 newDs.clear(); // tidy up
2084 if (alignment.getAlignmentAnnotation() != null)
2086 for (AlignmentAnnotation alan : alignment
2087 .getAlignmentAnnotation())
2089 if (alan.graphGroup > fgroup)
2091 fgroup = alan.graphGroup;
2095 if (pastedal.getAlignmentAnnotation() != null)
2097 // Add any annotation attached to alignment.
2098 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2099 for (int i = 0; i < alann.length; i++)
2101 annotationAdded = true;
2102 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2104 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2105 if (newann.graphGroup > -1)
2107 if (newGraphGroups.size() <= newann.graphGroup
2108 || newGraphGroups.get(newann.graphGroup) == null)
2110 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2112 newGraphGroups.add(q, null);
2114 newGraphGroups.set(newann.graphGroup, new Integer(
2117 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2121 newann.padAnnotation(alwidth);
2122 alignment.addAnnotation(newann);
2132 addHistoryItem(new EditCommand(
2133 MessageManager.getString("label.add_sequences"),
2134 Action.PASTE, sequences, 0, alignment.getWidth(), alignment));
2136 // Add any annotations attached to sequences
2137 for (int i = 0; i < sequences.length; i++)
2139 if (sequences[i].getAnnotation() != null)
2141 AlignmentAnnotation newann;
2142 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2144 annotationAdded = true;
2145 newann = sequences[i].getAnnotation()[a];
2146 newann.adjustForAlignment();
2147 newann.padAnnotation(alwidth);
2148 if (newann.graphGroup > -1)
2150 if (newann.graphGroup > -1)
2152 if (newGraphGroups.size() <= newann.graphGroup
2153 || newGraphGroups.get(newann.graphGroup) == null)
2155 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2157 newGraphGroups.add(q, null);
2159 newGraphGroups.set(newann.graphGroup, new Integer(
2162 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2166 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2171 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2178 // propagate alignment changed.
2179 viewport.setEndSeq(alignment.getHeight());
2180 if (annotationAdded)
2182 // Duplicate sequence annotation in all views.
2183 AlignmentI[] alview = this.getViewAlignments();
2184 for (int i = 0; i < sequences.length; i++)
2186 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2191 for (int avnum = 0; avnum < alview.length; avnum++)
2193 if (alview[avnum] != alignment)
2195 // duplicate in a view other than the one with input focus
2196 int avwidth = alview[avnum].getWidth() + 1;
2197 // this relies on sann being preserved after we
2198 // modify the sequence's annotation array for each duplication
2199 for (int a = 0; a < sann.length; a++)
2201 AlignmentAnnotation newann = new AlignmentAnnotation(
2203 sequences[i].addAlignmentAnnotation(newann);
2204 newann.padAnnotation(avwidth);
2205 alview[avnum].addAnnotation(newann); // annotation was
2206 // duplicated earlier
2207 // TODO JAL-1145 graphGroups are not updated for sequence
2208 // annotation added to several views. This may cause
2210 alview[avnum].setAnnotationIndex(newann, a);
2215 buildSortByAnnotationScoresMenu();
2217 viewport.firePropertyChange("alignment", null,
2218 alignment.getSequences());
2219 if (alignPanels != null)
2221 for (AlignmentPanel ap : alignPanels)
2223 ap.validateAnnotationDimensions(false);
2228 alignPanel.validateAnnotationDimensions(false);
2234 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2236 String newtitle = new String("Copied sequences");
2238 if (Desktop.jalviewClipboard != null
2239 && Desktop.jalviewClipboard[2] != null)
2241 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2242 for (int[] region : hc)
2244 af.viewport.hideColumns(region[0], region[1]);
2248 // >>>This is a fix for the moment, until a better solution is
2250 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2252 alignPanel.getSeqPanel().seqCanvas
2253 .getFeatureRenderer());
2255 // TODO: maintain provenance of an alignment, rather than just make the
2256 // title a concatenation of operations.
2259 if (title.startsWith("Copied sequences"))
2265 newtitle = newtitle.concat("- from " + title);
2270 newtitle = new String("Pasted sequences");
2273 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2278 } catch (Exception ex)
2280 ex.printStackTrace();
2281 System.out.println("Exception whilst pasting: " + ex);
2282 // could be anything being pasted in here
2288 protected void expand_newalign(ActionEvent e)
2292 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2293 .getAlignment(), -1);
2294 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2296 String newtitle = new String("Flanking alignment");
2298 if (Desktop.jalviewClipboard != null
2299 && Desktop.jalviewClipboard[2] != null)
2301 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2302 for (int region[] : hc)
2304 af.viewport.hideColumns(region[0], region[1]);
2308 // >>>This is a fix for the moment, until a better solution is
2310 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2312 alignPanel.getSeqPanel().seqCanvas
2313 .getFeatureRenderer());
2315 // TODO: maintain provenance of an alignment, rather than just make the
2316 // title a concatenation of operations.
2318 if (title.startsWith("Copied sequences"))
2324 newtitle = newtitle.concat("- from " + title);
2328 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2330 } catch (Exception ex)
2332 ex.printStackTrace();
2333 System.out.println("Exception whilst pasting: " + ex);
2334 // could be anything being pasted in here
2335 } catch (OutOfMemoryError oom)
2337 new OOMWarning("Viewing flanking region of alignment", oom);
2348 protected void cut_actionPerformed(ActionEvent e)
2350 copy_actionPerformed(null);
2351 delete_actionPerformed(null);
2361 protected void delete_actionPerformed(ActionEvent evt)
2364 SequenceGroup sg = viewport.getSelectionGroup();
2371 * If the cut affects all sequences, warn, remove highlighted columns
2373 if (sg.getSize() == viewport.getAlignment().getHeight())
2375 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2376 .getAlignment().getWidth()) ? true : false;
2377 if (isEntireAlignWidth)
2379 int confirm = JOptionPane.showConfirmDialog(this,
2380 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2381 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2382 JOptionPane.OK_CANCEL_OPTION);
2384 if (confirm == JOptionPane.CANCEL_OPTION
2385 || confirm == JOptionPane.CLOSED_OPTION)
2390 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2391 sg.getEndRes() + 1);
2393 SequenceI[] cut = sg.getSequences()
2394 .toArray(new SequenceI[sg.getSize()]);
2396 addHistoryItem(new EditCommand(
2397 MessageManager.getString("label.cut_sequences"), Action.CUT,
2398 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2399 viewport.getAlignment()));
2401 viewport.setSelectionGroup(null);
2402 viewport.sendSelection();
2403 viewport.getAlignment().deleteGroup(sg);
2405 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2407 if (viewport.getAlignment().getHeight() < 1)
2411 this.setClosed(true);
2412 } catch (Exception ex)
2426 protected void deleteGroups_actionPerformed(ActionEvent e)
2428 if (avc.deleteGroups())
2430 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2431 alignPanel.updateAnnotation();
2432 alignPanel.paintAlignment(true);
2443 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2445 SequenceGroup sg = new SequenceGroup();
2447 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2449 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2452 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2453 viewport.setSelectionGroup(sg);
2454 viewport.sendSelection();
2455 alignPanel.paintAlignment(true);
2456 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2466 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2468 if (viewport.cursorMode)
2470 alignPanel.getSeqPanel().keyboardNo1 = null;
2471 alignPanel.getSeqPanel().keyboardNo2 = null;
2473 viewport.setSelectionGroup(null);
2474 viewport.getColumnSelection().clear();
2475 viewport.setSelectionGroup(null);
2476 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2477 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2478 alignPanel.paintAlignment(true);
2479 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2480 viewport.sendSelection();
2490 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2492 SequenceGroup sg = viewport.getSelectionGroup();
2496 selectAllSequenceMenuItem_actionPerformed(null);
2501 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2503 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2506 alignPanel.paintAlignment(true);
2507 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2508 viewport.sendSelection();
2512 public void invertColSel_actionPerformed(ActionEvent e)
2514 viewport.invertColumnSelection();
2515 alignPanel.paintAlignment(true);
2516 viewport.sendSelection();
2526 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2528 trimAlignment(true);
2538 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2540 trimAlignment(false);
2543 void trimAlignment(boolean trimLeft)
2545 ColumnSelection colSel = viewport.getColumnSelection();
2548 if (colSel.size() > 0)
2552 column = colSel.getMin();
2556 column = colSel.getMax();
2560 if (viewport.getSelectionGroup() != null)
2562 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2563 viewport.getHiddenRepSequences());
2567 seqs = viewport.getAlignment().getSequencesArray();
2570 TrimRegionCommand trimRegion;
2573 trimRegion = new TrimRegionCommand("Remove Left",
2574 TrimRegionCommand.TRIM_LEFT, seqs, column,
2575 viewport.getAlignment(), viewport.getColumnSelection(),
2576 viewport.getSelectionGroup());
2577 viewport.setStartRes(0);
2581 trimRegion = new TrimRegionCommand("Remove Right",
2582 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2583 viewport.getAlignment(), viewport.getColumnSelection(),
2584 viewport.getSelectionGroup());
2587 statusBar.setText(MessageManager.formatMessage(
2588 "label.removed_columns",
2589 new String[] { Integer.valueOf(trimRegion.getSize())
2592 addHistoryItem(trimRegion);
2594 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2596 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2597 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2599 viewport.getAlignment().deleteGroup(sg);
2603 viewport.firePropertyChange("alignment", null, viewport
2604 .getAlignment().getSequences());
2615 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2617 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2620 if (viewport.getSelectionGroup() != null)
2622 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2623 viewport.getHiddenRepSequences());
2624 start = viewport.getSelectionGroup().getStartRes();
2625 end = viewport.getSelectionGroup().getEndRes();
2629 seqs = viewport.getAlignment().getSequencesArray();
2632 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2633 "Remove Gapped Columns", seqs, start, end,
2634 viewport.getAlignment());
2636 addHistoryItem(removeGapCols);
2638 statusBar.setText(MessageManager.formatMessage(
2639 "label.removed_empty_columns",
2640 new Object[] { Integer.valueOf(removeGapCols.getSize())
2643 // This is to maintain viewport position on first residue
2644 // of first sequence
2645 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2646 int startRes = seq.findPosition(viewport.startRes);
2647 // ShiftList shifts;
2648 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2649 // edit.alColumnChanges=shifts.getInverse();
2650 // if (viewport.hasHiddenColumns)
2651 // viewport.getColumnSelection().compensateForEdits(shifts);
2652 viewport.setStartRes(seq.findIndex(startRes) - 1);
2653 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2665 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2667 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2670 if (viewport.getSelectionGroup() != null)
2672 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2673 viewport.getHiddenRepSequences());
2674 start = viewport.getSelectionGroup().getStartRes();
2675 end = viewport.getSelectionGroup().getEndRes();
2679 seqs = viewport.getAlignment().getSequencesArray();
2682 // This is to maintain viewport position on first residue
2683 // of first sequence
2684 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2685 int startRes = seq.findPosition(viewport.startRes);
2687 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2688 viewport.getAlignment()));
2690 viewport.setStartRes(seq.findIndex(startRes) - 1);
2692 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2704 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2706 viewport.setPadGaps(padGapsMenuitem.isSelected());
2707 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2718 public void findMenuItem_actionPerformed(ActionEvent e)
2724 * Create a new view of the current alignment.
2727 public void newView_actionPerformed(ActionEvent e)
2729 newView(null, true);
2733 * Creates and shows a new view of the current alignment.
2736 * title of newly created view; if null, one will be generated
2737 * @param copyAnnotation
2738 * if true then duplicate all annnotation, groups and settings
2739 * @return new alignment panel, already displayed.
2741 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2744 * Create a new AlignmentPanel (with its own, new Viewport)
2746 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2748 if (!copyAnnotation)
2751 * remove all groups and annotation except for the automatic stuff
2753 newap.av.getAlignment().deleteAllGroups();
2754 newap.av.getAlignment().deleteAllAnnotations(false);
2757 newap.av.setGatherViewsHere(false);
2759 if (viewport.viewName == null)
2761 viewport.viewName = MessageManager
2762 .getString("label.view_name_original");
2766 * Views share the same edits undo and redo stacks
2768 newap.av.setHistoryList(viewport.getHistoryList());
2769 newap.av.setRedoList(viewport.getRedoList());
2772 * Views share the same mappings; need to deregister any new mappings
2773 * created by copyAlignPanel, and register the new reference to the shared
2776 newap.av.replaceMappings(viewport.getAlignment());
2778 newap.av.viewName = getNewViewName(viewTitle);
2780 addAlignmentPanel(newap, true);
2781 newap.alignmentChanged();
2783 if (alignPanels.size() == 2)
2785 viewport.setGatherViewsHere(true);
2787 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2792 * Make a new name for the view, ensuring it is unique within the current
2793 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2794 * these now use viewId. Unique view names are still desirable for usability.)
2799 protected String getNewViewName(String viewTitle)
2801 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2802 boolean addFirstIndex = false;
2803 if (viewTitle == null || viewTitle.trim().length() == 0)
2805 viewTitle = MessageManager.getString("action.view");
2806 addFirstIndex = true;
2810 index = 1;// we count from 1 if given a specific name
2812 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2814 List<Component> comps = PaintRefresher.components.get(viewport
2815 .getSequenceSetId());
2817 List<String> existingNames = getExistingViewNames(comps);
2819 while (existingNames.contains(newViewName))
2821 newViewName = viewTitle + " " + (++index);
2827 * Returns a list of distinct view names found in the given list of
2828 * components. View names are held on the viewport of an AlignmentPanel.
2833 protected List<String> getExistingViewNames(List<Component> comps)
2835 List<String> existingNames = new ArrayList<String>();
2836 for (Component comp : comps)
2838 if (comp instanceof AlignmentPanel)
2840 AlignmentPanel ap = (AlignmentPanel) comp;
2841 if (!existingNames.contains(ap.av.viewName))
2843 existingNames.add(ap.av.viewName);
2847 return existingNames;
2851 * Explode tabbed views into separate windows.
2854 public void expandViews_actionPerformed(ActionEvent e)
2856 Desktop.instance.explodeViews(this);
2860 * Gather views in separate windows back into a tabbed presentation.
2863 public void gatherViews_actionPerformed(ActionEvent e)
2865 Desktop.instance.gatherViews(this);
2875 public void font_actionPerformed(ActionEvent e)
2877 new FontChooser(alignPanel);
2887 protected void seqLimit_actionPerformed(ActionEvent e)
2889 viewport.setShowJVSuffix(seqLimits.isSelected());
2891 alignPanel.getIdPanel().getIdCanvas()
2892 .setPreferredSize(alignPanel.calculateIdWidth());
2893 alignPanel.paintAlignment(true);
2897 public void idRightAlign_actionPerformed(ActionEvent e)
2899 viewport.setRightAlignIds(idRightAlign.isSelected());
2900 alignPanel.paintAlignment(true);
2904 public void centreColumnLabels_actionPerformed(ActionEvent e)
2906 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2907 alignPanel.paintAlignment(true);
2913 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2916 protected void followHighlight_actionPerformed()
2919 * Set the 'follow' flag on the Viewport (and scroll to position if now
2922 final boolean state = this.followHighlightMenuItem.getState();
2923 viewport.setFollowHighlight(state);
2926 alignPanel.scrollToPosition(
2927 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2938 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2940 viewport.setColourText(colourTextMenuItem.isSelected());
2941 alignPanel.paintAlignment(true);
2951 public void wrapMenuItem_actionPerformed(ActionEvent e)
2953 scaleAbove.setVisible(wrapMenuItem.isSelected());
2954 scaleLeft.setVisible(wrapMenuItem.isSelected());
2955 scaleRight.setVisible(wrapMenuItem.isSelected());
2956 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2957 alignPanel.updateLayout();
2961 public void showAllSeqs_actionPerformed(ActionEvent e)
2963 viewport.showAllHiddenSeqs();
2967 public void showAllColumns_actionPerformed(ActionEvent e)
2969 viewport.showAllHiddenColumns();
2974 public void hideSelSequences_actionPerformed(ActionEvent e)
2976 viewport.hideAllSelectedSeqs();
2977 // alignPanel.paintAlignment(true);
2981 * called by key handler and the hide all/show all menu items
2986 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2989 boolean hide = false;
2990 SequenceGroup sg = viewport.getSelectionGroup();
2991 if (!toggleSeqs && !toggleCols)
2993 // Hide everything by the current selection - this is a hack - we do the
2994 // invert and then hide
2995 // first check that there will be visible columns after the invert.
2996 if ((viewport.getColumnSelection() != null
2997 && viewport.getColumnSelection().getSelected() != null && viewport
2998 .getColumnSelection().getSelected().size() > 0)
2999 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
3002 // now invert the sequence set, if required - empty selection implies
3003 // that no hiding is required.
3006 invertSequenceMenuItem_actionPerformed(null);
3007 sg = viewport.getSelectionGroup();
3011 viewport.expandColSelection(sg, true);
3012 // finally invert the column selection and get the new sequence
3014 invertColSel_actionPerformed(null);
3021 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3023 hideSelSequences_actionPerformed(null);
3026 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3029 showAllSeqs_actionPerformed(null);
3035 if (viewport.getColumnSelection().getSelected().size() > 0)
3037 hideSelColumns_actionPerformed(null);
3040 viewport.setSelectionGroup(sg);
3045 showAllColumns_actionPerformed(null);
3054 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3055 * event.ActionEvent)
3058 public void hideAllButSelection_actionPerformed(ActionEvent e)
3060 toggleHiddenRegions(false, false);
3067 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3071 public void hideAllSelection_actionPerformed(ActionEvent e)
3073 SequenceGroup sg = viewport.getSelectionGroup();
3074 viewport.expandColSelection(sg, false);
3075 viewport.hideAllSelectedSeqs();
3076 viewport.hideSelectedColumns();
3077 alignPanel.paintAlignment(true);
3084 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3088 public void showAllhidden_actionPerformed(ActionEvent e)
3090 viewport.showAllHiddenColumns();
3091 viewport.showAllHiddenSeqs();
3092 alignPanel.paintAlignment(true);
3096 public void hideSelColumns_actionPerformed(ActionEvent e)
3098 viewport.hideSelectedColumns();
3099 alignPanel.paintAlignment(true);
3103 public void hiddenMarkers_actionPerformed(ActionEvent e)
3105 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3116 protected void scaleAbove_actionPerformed(ActionEvent e)
3118 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3119 alignPanel.paintAlignment(true);
3129 protected void scaleLeft_actionPerformed(ActionEvent e)
3131 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3132 alignPanel.paintAlignment(true);
3142 protected void scaleRight_actionPerformed(ActionEvent e)
3144 viewport.setScaleRightWrapped(scaleRight.isSelected());
3145 alignPanel.paintAlignment(true);
3155 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3157 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3158 alignPanel.paintAlignment(true);
3168 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3170 viewport.setShowText(viewTextMenuItem.isSelected());
3171 alignPanel.paintAlignment(true);
3181 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3183 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3184 alignPanel.paintAlignment(true);
3187 public FeatureSettings featureSettings;
3190 public FeatureSettingsControllerI getFeatureSettingsUI()
3192 return featureSettings;
3196 public void featureSettings_actionPerformed(ActionEvent e)
3198 if (featureSettings != null)
3200 featureSettings.close();
3201 featureSettings = null;
3203 if (!showSeqFeatures.isSelected())
3205 // make sure features are actually displayed
3206 showSeqFeatures.setSelected(true);
3207 showSeqFeatures_actionPerformed(null);
3209 featureSettings = new FeatureSettings(this);
3213 * Set or clear 'Show Sequence Features'
3219 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3221 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3222 alignPanel.paintAlignment(true);
3223 if (alignPanel.getOverviewPanel() != null)
3225 alignPanel.getOverviewPanel().updateOverviewImage();
3230 * Set or clear 'Show Sequence Features'
3236 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3238 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3240 if (viewport.isShowSequenceFeaturesHeight())
3242 // ensure we're actually displaying features
3243 viewport.setShowSequenceFeatures(true);
3244 showSeqFeatures.setSelected(true);
3246 alignPanel.paintAlignment(true);
3247 if (alignPanel.getOverviewPanel() != null)
3249 alignPanel.getOverviewPanel().updateOverviewImage();
3254 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3255 * the annotations panel as a whole.
3257 * The options to show/hide all annotations should be enabled when the panel
3258 * is shown, and disabled when the panel is hidden.
3263 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3265 final boolean setVisible = annotationPanelMenuItem.isSelected();
3266 viewport.setShowAnnotation(setVisible);
3267 this.showAllSeqAnnotations.setEnabled(setVisible);
3268 this.hideAllSeqAnnotations.setEnabled(setVisible);
3269 this.showAllAlAnnotations.setEnabled(setVisible);
3270 this.hideAllAlAnnotations.setEnabled(setVisible);
3271 alignPanel.updateLayout();
3275 public void alignmentProperties()
3277 JEditorPane editPane = new JEditorPane("text/html", "");
3278 editPane.setEditable(false);
3279 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3281 editPane.setText(MessageManager.formatMessage("label.html_content",
3282 new Object[] { contents.toString() }));
3283 JInternalFrame frame = new JInternalFrame();
3284 frame.getContentPane().add(new JScrollPane(editPane));
3286 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3287 "label.alignment_properties", new Object[] { getTitle() }),
3298 public void overviewMenuItem_actionPerformed(ActionEvent e)
3300 if (alignPanel.overviewPanel != null)
3305 JInternalFrame frame = new JInternalFrame();
3306 OverviewPanel overview = new OverviewPanel(alignPanel);
3307 frame.setContentPane(overview);
3308 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3309 "label.overview_params", new Object[] { this.getTitle() }),
3310 frame.getWidth(), frame.getHeight());
3312 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3313 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3316 public void internalFrameClosed(
3317 javax.swing.event.InternalFrameEvent evt)
3319 alignPanel.setOverviewPanel(null);
3323 alignPanel.setOverviewPanel(overview);
3327 public void textColour_actionPerformed(ActionEvent e)
3329 new TextColourChooser().chooseColour(alignPanel, null);
3339 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3351 public void clustalColour_actionPerformed(ActionEvent e)
3353 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3354 viewport.getHiddenRepSequences()));
3364 public void zappoColour_actionPerformed(ActionEvent e)
3366 changeColour(new ZappoColourScheme());
3376 public void taylorColour_actionPerformed(ActionEvent e)
3378 changeColour(new TaylorColourScheme());
3388 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3390 changeColour(new HydrophobicColourScheme());
3400 public void helixColour_actionPerformed(ActionEvent e)
3402 changeColour(new HelixColourScheme());
3412 public void strandColour_actionPerformed(ActionEvent e)
3414 changeColour(new StrandColourScheme());
3424 public void turnColour_actionPerformed(ActionEvent e)
3426 changeColour(new TurnColourScheme());
3436 public void buriedColour_actionPerformed(ActionEvent e)
3438 changeColour(new BuriedColourScheme());
3448 public void nucleotideColour_actionPerformed(ActionEvent e)
3450 changeColour(new NucleotideColourScheme());
3454 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3456 changeColour(new PurinePyrimidineColourScheme());
3460 * public void covariationColour_actionPerformed(ActionEvent e) {
3462 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3466 public void annotationColour_actionPerformed(ActionEvent e)
3468 new AnnotationColourChooser(viewport, alignPanel);
3472 public void annotationColumn_actionPerformed(ActionEvent e)
3474 new AnnotationColumnChooser(viewport, alignPanel);
3478 public void rnahelicesColour_actionPerformed(ActionEvent e)
3480 new RNAHelicesColourChooser(viewport, alignPanel);
3490 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3492 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3501 public void changeColour(ColourSchemeI cs)
3503 // TODO: pull up to controller method
3507 // Make sure viewport is up to date w.r.t. any sliders
3508 if (viewport.getAbovePIDThreshold())
3510 int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3512 viewport.setThreshold(threshold);
3515 if (viewport.getConservationSelected())
3517 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3520 if (cs instanceof TCoffeeColourScheme)
3522 tcoffeeColour.setEnabled(true);
3523 tcoffeeColour.setSelected(true);
3527 viewport.setGlobalColourScheme(cs);
3529 alignPanel.paintAlignment(true);
3539 protected void modifyPID_actionPerformed(ActionEvent e)
3541 if (viewport.getAbovePIDThreshold()
3542 && viewport.getGlobalColourScheme() != null)
3544 SliderPanel.setPIDSliderSource(alignPanel,
3545 viewport.getGlobalColourScheme(), "Background");
3546 SliderPanel.showPIDSlider();
3557 protected void modifyConservation_actionPerformed(ActionEvent e)
3559 if (viewport.getConservationSelected()
3560 && viewport.getGlobalColourScheme() != null)
3562 SliderPanel.setConservationSlider(alignPanel,
3563 viewport.getGlobalColourScheme(), "Background");
3564 SliderPanel.showConservationSlider();
3575 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3577 viewport.setConservationSelected(conservationMenuItem.isSelected());
3579 viewport.setAbovePIDThreshold(false);
3580 abovePIDThreshold.setSelected(false);
3582 changeColour(viewport.getGlobalColourScheme());
3584 modifyConservation_actionPerformed(null);
3594 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3596 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3598 conservationMenuItem.setSelected(false);
3599 viewport.setConservationSelected(false);
3601 changeColour(viewport.getGlobalColourScheme());
3603 modifyPID_actionPerformed(null);
3613 public void userDefinedColour_actionPerformed(ActionEvent e)
3615 if (e.getActionCommand().equals(
3616 MessageManager.getString("action.user_defined")))
3618 new UserDefinedColours(alignPanel, null);
3622 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3623 .getUserColourSchemes().get(e.getActionCommand());
3629 public void updateUserColourMenu()
3632 Component[] menuItems = colourMenu.getMenuComponents();
3633 int iSize = menuItems.length;
3634 for (int i = 0; i < iSize; i++)
3636 if (menuItems[i].getName() != null
3637 && menuItems[i].getName().equals("USER_DEFINED"))
3639 colourMenu.remove(menuItems[i]);
3643 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3645 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3646 .getUserColourSchemes().keys();
3648 while (userColours.hasMoreElements())
3650 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3651 userColours.nextElement().toString());
3652 radioItem.setName("USER_DEFINED");
3653 radioItem.addMouseListener(new MouseAdapter()
3656 public void mousePressed(MouseEvent evt)
3658 if (evt.isControlDown()
3659 || SwingUtilities.isRightMouseButton(evt))
3661 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3663 int option = JOptionPane.showInternalConfirmDialog(
3664 jalview.gui.Desktop.desktop,
3666 .getString("label.remove_from_default_list"),
3668 .getString("label.remove_user_defined_colour"),
3669 JOptionPane.YES_NO_OPTION);
3670 if (option == JOptionPane.YES_OPTION)
3672 jalview.gui.UserDefinedColours
3673 .removeColourFromDefaults(radioItem.getText());
3674 colourMenu.remove(radioItem);
3678 radioItem.addActionListener(new ActionListener()
3681 public void actionPerformed(ActionEvent evt)
3683 userDefinedColour_actionPerformed(evt);
3690 radioItem.addActionListener(new ActionListener()
3693 public void actionPerformed(ActionEvent evt)
3695 userDefinedColour_actionPerformed(evt);
3699 colourMenu.insert(radioItem, 15);
3700 colours.add(radioItem);
3712 public void PIDColour_actionPerformed(ActionEvent e)
3714 changeColour(new PIDColourScheme());
3724 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3726 changeColour(new Blosum62ColourScheme());
3736 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3738 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3739 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3740 .getAlignment().getSequenceAt(0), null);
3741 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3742 viewport.getAlignment()));
3743 alignPanel.paintAlignment(true);
3753 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3755 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3756 AlignmentSorter.sortByID(viewport.getAlignment());
3757 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3758 viewport.getAlignment()));
3759 alignPanel.paintAlignment(true);
3769 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3771 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3772 AlignmentSorter.sortByLength(viewport.getAlignment());
3773 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3774 viewport.getAlignment()));
3775 alignPanel.paintAlignment(true);
3785 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3787 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3788 AlignmentSorter.sortByGroup(viewport.getAlignment());
3789 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3790 viewport.getAlignment()));
3792 alignPanel.paintAlignment(true);
3802 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3804 new RedundancyPanel(alignPanel, this);
3814 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3816 if ((viewport.getSelectionGroup() == null)
3817 || (viewport.getSelectionGroup().getSize() < 2))
3819 JOptionPane.showInternalMessageDialog(this, MessageManager
3820 .getString("label.you_must_select_least_two_sequences"),
3821 MessageManager.getString("label.invalid_selection"),
3822 JOptionPane.WARNING_MESSAGE);
3826 JInternalFrame frame = new JInternalFrame();
3827 frame.setContentPane(new PairwiseAlignPanel(viewport));
3828 Desktop.addInternalFrame(frame,
3829 MessageManager.getString("action.pairwise_alignment"), 600,
3841 public void PCAMenuItem_actionPerformed(ActionEvent e)
3843 if (((viewport.getSelectionGroup() != null)
3844 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3845 .getSelectionGroup().getSize() > 0))
3846 || (viewport.getAlignment().getHeight() < 4))
3849 .showInternalMessageDialog(
3852 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3854 .getString("label.sequence_selection_insufficient"),
3855 JOptionPane.WARNING_MESSAGE);
3860 new PCAPanel(alignPanel);
3864 public void autoCalculate_actionPerformed(ActionEvent e)
3866 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3867 if (viewport.autoCalculateConsensus)
3869 viewport.firePropertyChange("alignment", null, viewport
3870 .getAlignment().getSequences());
3875 public void sortByTreeOption_actionPerformed(ActionEvent e)
3877 viewport.sortByTree = sortByTree.isSelected();
3881 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3883 viewport.followSelection = listenToViewSelections.isSelected();
3893 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3895 newTreePanel("AV", "PID", "Average distance tree using PID");
3905 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3907 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3917 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3919 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3929 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3931 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3944 void newTreePanel(String type, String pwType, String title)
3948 if (viewport.getSelectionGroup() != null
3949 && viewport.getSelectionGroup().getSize() > 0)
3951 if (viewport.getSelectionGroup().getSize() < 3)
3957 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3959 .getString("label.not_enough_sequences"),
3960 JOptionPane.WARNING_MESSAGE);
3964 SequenceGroup sg = viewport.getSelectionGroup();
3966 /* Decide if the selection is a column region */
3967 for (SequenceI _s : sg.getSequences())
3969 if (_s.getLength() < sg.getEndRes())
3975 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3977 .getString("label.sequences_selection_not_aligned"),
3978 JOptionPane.WARNING_MESSAGE);
3984 title = title + " on region";
3985 tp = new TreePanel(alignPanel, type, pwType);
3989 // are the visible sequences aligned?
3990 if (!viewport.getAlignment().isAligned(false))
3996 .getString("label.sequences_must_be_aligned_before_creating_tree"),
3998 .getString("label.sequences_not_aligned"),
3999 JOptionPane.WARNING_MESSAGE);
4004 if (viewport.getAlignment().getHeight() < 2)
4009 tp = new TreePanel(alignPanel, type, pwType);
4014 if (viewport.viewName != null)
4016 title += viewport.viewName + " of ";
4019 title += this.title;
4021 Desktop.addInternalFrame(tp, title, 600, 500);
4032 public void addSortByOrderMenuItem(String title,
4033 final AlignmentOrder order)
4035 final JMenuItem item = new JMenuItem(MessageManager.formatMessage(
4036 "action.by_title_param", new Object[] { title }));
4038 item.addActionListener(new java.awt.event.ActionListener()
4041 public void actionPerformed(ActionEvent e)
4043 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4045 // TODO: JBPNote - have to map order entries to curent SequenceI
4047 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4049 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4052 alignPanel.paintAlignment(true);
4058 * Add a new sort by annotation score menu item
4061 * the menu to add the option to
4063 * the label used to retrieve scores for each sequence on the
4066 public void addSortByAnnotScoreMenuItem(JMenu sort,
4067 final String scoreLabel)
4069 final JMenuItem item = new JMenuItem(scoreLabel);
4071 item.addActionListener(new java.awt.event.ActionListener()
4074 public void actionPerformed(ActionEvent e)
4076 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4077 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4078 viewport.getAlignment());// ,viewport.getSelectionGroup());
4079 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4080 viewport.getAlignment()));
4081 alignPanel.paintAlignment(true);
4087 * last hash for alignment's annotation array - used to minimise cost of
4090 protected int _annotationScoreVectorHash;
4093 * search the alignment and rebuild the sort by annotation score submenu the
4094 * last alignment annotation vector hash is stored to minimize cost of
4095 * rebuilding in subsequence calls.
4099 public void buildSortByAnnotationScoresMenu()
4101 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4106 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4108 sortByAnnotScore.removeAll();
4109 // almost certainly a quicker way to do this - but we keep it simple
4110 Hashtable scoreSorts = new Hashtable();
4111 AlignmentAnnotation aann[];
4112 for (SequenceI sqa : viewport.getAlignment().getSequences())
4114 aann = sqa.getAnnotation();
4115 for (int i = 0; aann != null && i < aann.length; i++)
4117 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4119 scoreSorts.put(aann[i].label, aann[i].label);
4123 Enumeration labels = scoreSorts.keys();
4124 while (labels.hasMoreElements())
4126 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4127 (String) labels.nextElement());
4129 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4132 _annotationScoreVectorHash = viewport.getAlignment()
4133 .getAlignmentAnnotation().hashCode();
4138 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4139 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4140 * call. Listeners are added to remove the menu item when the treePanel is
4141 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4145 * Displayed tree window.
4147 * SortBy menu item title.
4150 public void buildTreeMenu()
4152 calculateTree.removeAll();
4153 // build the calculate menu
4155 for (final String type : new String[] { "NJ", "AV" })
4157 String treecalcnm = MessageManager.getString("label.tree_calc_"
4158 + type.toLowerCase());
4159 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4161 JMenuItem tm = new JMenuItem();
4162 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4163 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4165 String smn = MessageManager.getStringOrReturn(
4166 "label.score_model_", sm.getName());
4167 final String title = MessageManager.formatMessage(
4168 "label.treecalc_title", treecalcnm, smn);
4169 tm.setText(title);//
4170 tm.addActionListener(new java.awt.event.ActionListener()
4173 public void actionPerformed(ActionEvent e)
4175 newTreePanel(type, pwtype, title);
4178 calculateTree.add(tm);
4183 sortByTreeMenu.removeAll();
4185 List<Component> comps = PaintRefresher.components.get(viewport
4186 .getSequenceSetId());
4187 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4188 for (Component comp : comps)
4190 if (comp instanceof TreePanel)
4192 treePanels.add((TreePanel) comp);
4196 if (treePanels.size() < 1)
4198 sortByTreeMenu.setVisible(false);
4202 sortByTreeMenu.setVisible(true);
4204 for (final TreePanel tp : treePanels)
4206 final JMenuItem item = new JMenuItem(tp.getTitle());
4207 item.addActionListener(new java.awt.event.ActionListener()
4210 public void actionPerformed(ActionEvent e)
4212 tp.sortByTree_actionPerformed();
4213 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4218 sortByTreeMenu.add(item);
4222 public boolean sortBy(AlignmentOrder alorder, String undoname)
4224 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4225 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4226 if (undoname != null)
4228 addHistoryItem(new OrderCommand(undoname, oldOrder,
4229 viewport.getAlignment()));
4231 alignPanel.paintAlignment(true);
4236 * Work out whether the whole set of sequences or just the selected set will
4237 * be submitted for multiple alignment.
4240 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4242 // Now, check we have enough sequences
4243 AlignmentView msa = null;
4245 if ((viewport.getSelectionGroup() != null)
4246 && (viewport.getSelectionGroup().getSize() > 1))
4248 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4249 // some common interface!
4251 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4252 * SequenceI[sz = seqs.getSize(false)];
4254 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4255 * seqs.getSequenceAt(i); }
4257 msa = viewport.getAlignmentView(true);
4259 else if (viewport.getSelectionGroup() != null
4260 && viewport.getSelectionGroup().getSize() == 1)
4262 int option = JOptionPane.showConfirmDialog(this,
4263 MessageManager.getString("warn.oneseq_msainput_selection"),
4264 MessageManager.getString("label.invalid_selection"),
4265 JOptionPane.OK_CANCEL_OPTION);
4266 if (option == JOptionPane.OK_OPTION)
4268 msa = viewport.getAlignmentView(false);
4273 msa = viewport.getAlignmentView(false);
4279 * Decides what is submitted to a secondary structure prediction service: the
4280 * first sequence in the alignment, or in the current selection, or, if the
4281 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4282 * region or the whole alignment. (where the first sequence in the set is the
4283 * one that the prediction will be for).
4285 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4287 AlignmentView seqs = null;
4289 if ((viewport.getSelectionGroup() != null)
4290 && (viewport.getSelectionGroup().getSize() > 0))
4292 seqs = viewport.getAlignmentView(true);
4296 seqs = viewport.getAlignmentView(false);
4298 // limit sequences - JBPNote in future - could spawn multiple prediction
4300 // TODO: viewport.getAlignment().isAligned is a global state - the local
4301 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4302 if (!viewport.getAlignment().isAligned(false))
4304 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4305 // TODO: if seqs.getSequences().length>1 then should really have warned
4319 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4321 // Pick the tree file
4322 JalviewFileChooser chooser = new JalviewFileChooser(
4323 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4324 chooser.setFileView(new JalviewFileView());
4325 chooser.setDialogTitle(MessageManager
4326 .getString("label.select_newick_like_tree_file"));
4327 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4329 int value = chooser.showOpenDialog(null);
4331 if (value == JalviewFileChooser.APPROVE_OPTION)
4333 String choice = chooser.getSelectedFile().getPath();
4334 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4335 jalview.io.NewickFile fin = null;
4338 fin = new jalview.io.NewickFile(choice, "File");
4339 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4340 } catch (Exception ex)
4347 .getString("label.problem_reading_tree_file"),
4348 JOptionPane.WARNING_MESSAGE);
4349 ex.printStackTrace();
4351 if (fin != null && fin.hasWarningMessage())
4353 JOptionPane.showMessageDialog(Desktop.desktop, fin
4354 .getWarningMessage(), MessageManager
4355 .getString("label.possible_problem_with_tree_file"),
4356 JOptionPane.WARNING_MESSAGE);
4362 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4364 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4367 public TreePanel ShowNewickTree(NewickFile nf, String title)
4369 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4372 public TreePanel ShowNewickTree(NewickFile nf, String title,
4373 AlignmentView input)
4375 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4378 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4379 int h, int x, int y)
4381 return ShowNewickTree(nf, title, null, w, h, x, y);
4385 * Add a treeviewer for the tree extracted from a newick file object to the
4386 * current alignment view
4393 * Associated alignment input data (or null)
4402 * @return TreePanel handle
4404 public TreePanel ShowNewickTree(NewickFile nf, String title,
4405 AlignmentView input, int w, int h, int x, int y)
4407 TreePanel tp = null;
4413 if (nf.getTree() != null)
4415 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4421 tp.setLocation(x, y);
4424 Desktop.addInternalFrame(tp, title, w, h);
4426 } catch (Exception ex)
4428 ex.printStackTrace();
4434 private boolean buildingMenu = false;
4437 * Generates menu items and listener event actions for web service clients
4440 public void BuildWebServiceMenu()
4442 while (buildingMenu)
4446 System.err.println("Waiting for building menu to finish.");
4448 } catch (Exception e)
4452 final AlignFrame me = this;
4453 buildingMenu = true;
4454 new Thread(new Runnable()
4459 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4462 // System.err.println("Building ws menu again "
4463 // + Thread.currentThread());
4464 // TODO: add support for context dependent disabling of services based
4466 // alignment and current selection
4467 // TODO: add additional serviceHandle parameter to specify abstract
4469 // class independently of AbstractName
4470 // TODO: add in rediscovery GUI function to restart discoverer
4471 // TODO: group services by location as well as function and/or
4473 // object broker mechanism.
4474 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4475 final IProgressIndicator af = me;
4476 final JMenu msawsmenu = new JMenu("Alignment");
4477 final JMenu secstrmenu = new JMenu(
4478 "Secondary Structure Prediction");
4479 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4480 final JMenu analymenu = new JMenu("Analysis");
4481 final JMenu dismenu = new JMenu("Protein Disorder");
4482 // final JMenu msawsmenu = new
4483 // JMenu(MessageManager.getString("label.alignment"));
4484 // final JMenu secstrmenu = new
4485 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4486 // final JMenu seqsrchmenu = new
4487 // JMenu(MessageManager.getString("label.sequence_database_search"));
4488 // final JMenu analymenu = new
4489 // JMenu(MessageManager.getString("label.analysis"));
4490 // final JMenu dismenu = new
4491 // JMenu(MessageManager.getString("label.protein_disorder"));
4492 // JAL-940 - only show secondary structure prediction services from
4493 // the legacy server
4494 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4496 Discoverer.services != null && (Discoverer.services.size() > 0))
4498 // TODO: refactor to allow list of AbstractName/Handler bindings to
4500 // stored or retrieved from elsewhere
4501 // No MSAWS used any more:
4502 // Vector msaws = null; // (Vector)
4503 // Discoverer.services.get("MsaWS");
4504 Vector secstrpr = (Vector) Discoverer.services
4506 if (secstrpr != null)
4508 // Add any secondary structure prediction services
4509 for (int i = 0, j = secstrpr.size(); i < j; i++)
4511 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4513 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4514 .getServiceClient(sh);
4515 int p = secstrmenu.getItemCount();
4516 impl.attachWSMenuEntry(secstrmenu, me);
4517 int q = secstrmenu.getItemCount();
4518 for (int litm = p; litm < q; litm++)
4520 legacyItems.add(secstrmenu.getItem(litm));
4526 // Add all submenus in the order they should appear on the web
4528 wsmenu.add(msawsmenu);
4529 wsmenu.add(secstrmenu);
4530 wsmenu.add(dismenu);
4531 wsmenu.add(analymenu);
4532 // No search services yet
4533 // wsmenu.add(seqsrchmenu);
4535 javax.swing.SwingUtilities.invokeLater(new Runnable()
4542 webService.removeAll();
4543 // first, add discovered services onto the webservices menu
4544 if (wsmenu.size() > 0)
4546 for (int i = 0, j = wsmenu.size(); i < j; i++)
4548 webService.add(wsmenu.get(i));
4553 webService.add(me.webServiceNoServices);
4555 // TODO: move into separate menu builder class.
4556 boolean new_sspred = false;
4557 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4559 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4560 if (jws2servs != null)
4562 if (jws2servs.hasServices())
4564 jws2servs.attachWSMenuEntry(webService, me);
4565 for (Jws2Instance sv : jws2servs.getServices())
4567 if (sv.description.toLowerCase().contains("jpred"))
4569 for (JMenuItem jmi : legacyItems)
4571 jmi.setVisible(false);
4577 if (jws2servs.isRunning())
4579 JMenuItem tm = new JMenuItem(
4580 "Still discovering JABA Services");
4581 tm.setEnabled(false);
4586 build_urlServiceMenu(me.webService);
4587 build_fetchdbmenu(webService);
4588 for (JMenu item : wsmenu)
4590 if (item.getItemCount() == 0)
4592 item.setEnabled(false);
4596 item.setEnabled(true);
4599 } catch (Exception e)
4602 .debug("Exception during web service menu building process.",
4607 } catch (Exception e)
4610 buildingMenu = false;
4617 * construct any groupURL type service menu entries.
4621 private void build_urlServiceMenu(JMenu webService)
4623 // TODO: remove this code when 2.7 is released
4624 // DEBUG - alignmentView
4626 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4627 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4629 * @Override public void actionPerformed(ActionEvent e) {
4630 * jalview.datamodel.AlignmentView
4631 * .testSelectionViews(af.viewport.getAlignment(),
4632 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4634 * }); webService.add(testAlView);
4636 // TODO: refactor to RestClient discoverer and merge menu entries for
4637 // rest-style services with other types of analysis/calculation service
4638 // SHmmr test client - still being implemented.
4639 // DEBUG - alignmentView
4641 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4644 client.attachWSMenuEntry(
4645 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4651 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4652 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4653 * getProperty("LAST_DIRECTORY"));
4655 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4656 * to Vamsas file"); chooser.setToolTipText("Export");
4658 * int value = chooser.showSaveDialog(this);
4660 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4661 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4662 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4663 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4666 * prototype of an automatically enabled/disabled analysis function
4669 protected void setShowProductsEnabled()
4671 SequenceI[] selection = viewport.getSequenceSelection();
4672 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4673 viewport.getAlignment().getDataset()))
4675 showProducts.setEnabled(true);
4680 showProducts.setEnabled(false);
4685 * search selection for sequence xRef products and build the show products
4690 * @return true if showProducts menu should be enabled.
4692 public boolean canShowProducts(SequenceI[] selection,
4693 boolean isRegionSelection, Alignment dataset)
4695 boolean showp = false;
4698 showProducts.removeAll();
4699 final boolean dna = viewport.getAlignment().isNucleotide();
4700 final Alignment ds = dataset;
4701 String[] ptypes = (selection == null || selection.length == 0) ? null
4702 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4704 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4705 // selection, dataset, true);
4706 final SequenceI[] sel = selection;
4707 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4710 final boolean isRegSel = isRegionSelection;
4711 final AlignFrame af = this;
4712 final String source = ptypes[t];
4713 JMenuItem xtype = new JMenuItem(ptypes[t]);
4714 xtype.addActionListener(new ActionListener()
4718 public void actionPerformed(ActionEvent e)
4720 // TODO: new thread for this call with vis-delay
4721 af.showProductsFor(af.viewport.getSequenceSelection(),
4722 isRegSel, dna, source);
4726 showProducts.add(xtype);
4728 showProducts.setVisible(showp);
4729 showProducts.setEnabled(showp);
4730 } catch (Exception e)
4732 jalview.bin.Cache.log
4733 .warn("canTranslate threw an exception - please report to help@jalview.org",
4740 protected void showProductsFor(final SequenceI[] sel,
4741 final boolean isRegSel, final boolean dna, final String source)
4743 Runnable foo = new Runnable()
4749 final long sttime = System.currentTimeMillis();
4750 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4751 "status.searching_for_sequences_from",
4752 new Object[] { source }), sttime);
4755 // update our local dataset reference
4756 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4758 Alignment prods = CrossRef
4759 .findXrefSequences(sel, dna, source, ds);
4762 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4763 for (int s = 0; s < sprods.length; s++)
4765 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4766 if (ds.getSequences() == null
4767 || !ds.getSequences().contains(
4768 sprods[s].getDatasetSequence()))
4770 ds.addSequence(sprods[s].getDatasetSequence());
4772 sprods[s].updatePDBIds();
4774 Alignment al = new Alignment(sprods);
4778 * Copy dna-to-protein mappings to new alignment
4780 // TODO 1: no mappings are set up for EMBL product
4781 // TODO 2: if they were, should add them to protein alignment, not
4783 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4784 for (AlignedCodonFrame acf : cf)
4786 al.addCodonFrame(acf);
4788 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4790 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4791 + " for " + ((isRegSel) ? "selected region of " : "")
4793 naf.setTitle(newtitle);
4795 // temporary flag until SplitFrame is released
4796 boolean asSplitFrame = Cache.getDefault(
4797 Preferences.ENABLE_SPLIT_FRAME, true);
4801 * Make a copy of this alignment (sharing the same dataset
4802 * sequences). If we are DNA, drop introns and update mappings
4804 AlignmentI copyAlignment = null;
4805 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4806 .getSequenceSelection();
4809 copyAlignment = AlignmentUtils.makeExonAlignment(
4810 sequenceSelection, cf);
4811 al.getCodonFrames().clear();
4812 al.getCodonFrames().addAll(cf);
4813 final StructureSelectionManager ssm = StructureSelectionManager
4814 .getStructureSelectionManager(Desktop.instance);
4815 ssm.registerMappings(cf);
4819 copyAlignment = new Alignment(new Alignment(
4820 sequenceSelection));
4822 AlignFrame copyThis = new AlignFrame(copyAlignment,
4823 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4824 copyThis.setTitle(AlignFrame.this.getTitle());
4825 // SplitFrame with dna above, protein below
4826 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4827 dna ? naf : copyThis);
4828 naf.setVisible(true);
4829 copyThis.setVisible(true);
4830 String linkedTitle = MessageManager
4831 .getString("label.linked_view_title");
4832 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4836 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4842 System.err.println("No Sequences generated for xRef type "
4845 } catch (Exception e)
4847 jalview.bin.Cache.log.error(
4848 "Exception when finding crossreferences", e);
4849 } catch (OutOfMemoryError e)
4851 new OOMWarning("whilst fetching crossreferences", e);
4854 jalview.bin.Cache.log.error("Error when finding crossreferences",
4857 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4858 "status.finished_searching_for_sequences_from",
4859 new Object[] { source }), sttime);
4863 Thread frunner = new Thread(foo);
4867 public boolean canShowTranslationProducts(SequenceI[] selection,
4868 AlignmentI alignment)
4873 return (jalview.analysis.Dna.canTranslate(selection,
4874 viewport.getViewAsVisibleContigs(true)));
4875 } catch (Exception e)
4877 jalview.bin.Cache.log
4878 .warn("canTranslate threw an exception - please report to help@jalview.org",
4885 * Construct and display a new frame containing the translation of this
4886 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4889 public void showTranslation_actionPerformed(ActionEvent e)
4891 AlignmentI al = null;
4894 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4896 al = dna.translateCdna();
4897 } catch (Exception ex)
4899 jalview.bin.Cache.log.error(
4900 "Exception during translation. Please report this !", ex);
4901 final String msg = MessageManager
4902 .getString("label.error_when_translating_sequences_submit_bug_report");
4903 final String errorTitle = MessageManager
4904 .getString("label.implementation_error")
4905 + MessageManager.getString("translation_failed");
4906 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4907 JOptionPane.ERROR_MESSAGE);
4910 if (al == null || al.getHeight() == 0)
4912 final String msg = MessageManager
4913 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4914 final String errorTitle = MessageManager
4915 .getString("label.translation_failed");
4916 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4917 JOptionPane.WARNING_MESSAGE);
4921 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4922 af.setFileFormat(this.currentFileFormat);
4923 final String newTitle = MessageManager.formatMessage(
4924 "label.translation_of_params",
4925 new Object[] { this.getTitle() });
4926 af.setTitle(newTitle);
4927 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4929 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4930 viewport.openSplitFrame(af, new Alignment(seqs));
4934 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4941 * Set the file format
4945 public void setFileFormat(String fileFormat)
4947 this.currentFileFormat = fileFormat;
4951 * Try to load a features file onto the alignment.
4954 * contents or path to retrieve file
4956 * access mode of file (see jalview.io.AlignFile)
4957 * @return true if features file was parsed correctly.
4959 public boolean parseFeaturesFile(String file, String type)
4961 return avc.parseFeaturesFile(file, type,
4962 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4967 public void refreshFeatureUI(boolean enableIfNecessary)
4969 // note - currently this is only still here rather than in the controller
4970 // because of the featureSettings hard reference that is yet to be
4972 if (enableIfNecessary)
4974 viewport.setShowSequenceFeatures(true);
4975 showSeqFeatures.setSelected(true);
4981 public void dragEnter(DropTargetDragEvent evt)
4986 public void dragExit(DropTargetEvent evt)
4991 public void dragOver(DropTargetDragEvent evt)
4996 public void dropActionChanged(DropTargetDragEvent evt)
5001 public void drop(DropTargetDropEvent evt)
5003 Transferable t = evt.getTransferable();
5004 java.util.List files = null;
5008 DataFlavor uriListFlavor = new DataFlavor(
5009 "text/uri-list;class=java.lang.String");
5010 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5012 // Works on Windows and MacOSX
5013 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5014 files = (java.util.List) t
5015 .getTransferData(DataFlavor.javaFileListFlavor);
5017 else if (t.isDataFlavorSupported(uriListFlavor))
5019 // This is used by Unix drag system
5020 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5021 String data = (String) t.getTransferData(uriListFlavor);
5022 files = new java.util.ArrayList(1);
5023 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5024 data, "\r\n"); st.hasMoreTokens();)
5026 String s = st.nextToken();
5027 if (s.startsWith("#"))
5029 // the line is a comment (as per the RFC 2483)
5033 java.net.URI uri = new java.net.URI(s);
5034 // check to see if we can handle this kind of URI
5035 if (uri.getScheme().toLowerCase().startsWith("http"))
5037 files.add(uri.toString());
5041 // otherwise preserve old behaviour: catch all for file objects
5042 java.io.File file = new java.io.File(uri);
5043 files.add(file.toString());
5047 } catch (Exception e)
5049 e.printStackTrace();
5055 // check to see if any of these files have names matching sequences in
5057 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5058 .getAlignment().getSequencesArray());
5060 * Object[] { String,SequenceI}
5062 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5063 ArrayList<String> filesnotmatched = new ArrayList<String>();
5064 for (int i = 0; i < files.size(); i++)
5066 String file = files.get(i).toString();
5068 String protocol = FormatAdapter.checkProtocol(file);
5069 if (protocol == jalview.io.FormatAdapter.FILE)
5071 File fl = new File(file);
5072 pdbfn = fl.getName();
5074 else if (protocol == jalview.io.FormatAdapter.URL)
5076 URL url = new URL(file);
5077 pdbfn = url.getFile();
5079 if (pdbfn.length() > 0)
5081 // attempt to find a match in the alignment
5082 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5083 int l = 0, c = pdbfn.indexOf(".");
5084 while (mtch == null && c != -1)
5089 } while ((c = pdbfn.indexOf(".", l)) > l);
5092 pdbfn = pdbfn.substring(0, l);
5094 mtch = idm.findAllIdMatches(pdbfn);
5101 type = new IdentifyFile().Identify(file, protocol);
5102 } catch (Exception ex)
5108 if (type.equalsIgnoreCase("PDB"))
5110 filesmatched.add(new Object[] { file, protocol, mtch });
5115 // File wasn't named like one of the sequences or wasn't a PDB file.
5116 filesnotmatched.add(file);
5120 if (filesmatched.size() > 0)
5122 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5128 "label.automatically_associate_pdb_files_with_sequences_same_name",
5129 new Object[] { Integer
5135 .getString("label.automatically_associate_pdb_files_by_name"),
5136 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5139 for (Object[] fm : filesmatched)
5141 // try and associate
5142 // TODO: may want to set a standard ID naming formalism for
5143 // associating PDB files which have no IDs.
5144 for (SequenceI toassoc : (SequenceI[]) fm[2])
5146 PDBEntry pe = new AssociatePdbFileWithSeq()
5147 .associatePdbWithSeq((String) fm[0],
5148 (String) fm[1], toassoc, false,
5152 System.err.println("Associated file : "
5153 + ((String) fm[0]) + " with "
5154 + toassoc.getDisplayId(true));
5158 alignPanel.paintAlignment(true);
5162 if (filesnotmatched.size() > 0)
5165 && (Cache.getDefault(
5166 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5172 "label.ignore_unmatched_dropped_files_info",
5173 new Object[] { Integer
5180 .getString("label.ignore_unmatched_dropped_files"),
5181 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5185 for (String fn : filesnotmatched)
5187 loadJalviewDataFile(fn, null, null, null);
5191 } catch (Exception ex)
5193 ex.printStackTrace();
5199 * Attempt to load a "dropped" file or URL string: First by testing whether
5200 * it's and Annotation file, then a JNet file, and finally a features file. If
5201 * all are false then the user may have dropped an alignment file onto this
5205 * either a filename or a URL string.
5207 public void loadJalviewDataFile(String file, String protocol,
5208 String format, SequenceI assocSeq)
5212 if (protocol == null)
5214 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5216 // if the file isn't identified, or not positively identified as some
5217 // other filetype (PFAM is default unidentified alignment file type) then
5218 // try to parse as annotation.
5219 boolean isAnnotation = (format == null || format
5220 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5221 .annotateAlignmentView(viewport, file, protocol) : false;
5225 // first see if its a T-COFFEE score file
5226 TCoffeeScoreFile tcf = null;
5229 tcf = new TCoffeeScoreFile(file, protocol);
5232 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5234 tcoffeeColour.setEnabled(true);
5235 tcoffeeColour.setSelected(true);
5236 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5237 isAnnotation = true;
5239 .setText(MessageManager
5240 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5244 // some problem - if no warning its probable that the ID matching
5245 // process didn't work
5249 tcf.getWarningMessage() == null ? MessageManager
5250 .getString("label.check_file_matches_sequence_ids_alignment")
5251 : tcf.getWarningMessage(),
5253 .getString("label.problem_reading_tcoffee_score_file"),
5254 JOptionPane.WARNING_MESSAGE);
5261 } catch (Exception x)
5264 .debug("Exception when processing data source as T-COFFEE score file",
5270 // try to see if its a JNet 'concise' style annotation file *before*
5272 // try to parse it as a features file
5275 format = new IdentifyFile().Identify(file, protocol);
5277 if (format.equalsIgnoreCase("JnetFile"))
5279 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5281 new JnetAnnotationMaker();
5282 JnetAnnotationMaker.add_annotation(predictions,
5283 viewport.getAlignment(), 0, false);
5284 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5285 viewport.getAlignment().setSeqrep(repseq);
5286 ColumnSelection cs = new ColumnSelection();
5287 cs.hideInsertionsFor(repseq);
5288 viewport.setColumnSelection(cs);
5289 isAnnotation = true;
5294 * if (format.equalsIgnoreCase("PDB")) {
5296 * String pdbfn = ""; // try to match up filename with sequence id
5297 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5298 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5299 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5300 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5301 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5302 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5303 * // attempt to find a match in the alignment SequenceI mtch =
5304 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5305 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5306 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5307 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5308 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5309 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5310 * { System.err.println("Associated file : " + file + " with " +
5311 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5312 * TODO: maybe need to load as normal otherwise return; } }
5314 // try to parse it as a features file
5315 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5316 // if it wasn't a features file then we just treat it as a general
5317 // alignment file to load into the current view.
5320 new FileLoader().LoadFile(viewport, file, protocol, format);
5324 alignPanel.paintAlignment(true);
5332 alignPanel.adjustAnnotationHeight();
5333 viewport.updateSequenceIdColours();
5334 buildSortByAnnotationScoresMenu();
5335 alignPanel.paintAlignment(true);
5337 } catch (Exception ex)
5339 ex.printStackTrace();
5340 } catch (OutOfMemoryError oom)
5345 } catch (Exception x)
5351 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5352 : "using " + protocol + " from " + file)
5354 + (format != null ? "(parsing as '" + format
5355 + "' file)" : ""), oom, Desktop.desktop);
5360 * Method invoked by the ChangeListener on the tabbed pane, in other words
5361 * when a different tabbed pane is selected by the user or programmatically.
5364 public void tabSelectionChanged(int index)
5368 alignPanel = alignPanels.get(index);
5369 viewport = alignPanel.av;
5370 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5371 setMenusFromViewport(viewport);
5375 * If there is a frame linked to this one in a SplitPane, switch it to the
5376 * same view tab index. No infinite recursion of calls should happen, since
5377 * tabSelectionChanged() should not get invoked on setting the selected
5378 * index to an unchanged value. Guard against setting an invalid index
5379 * before the new view peer tab has been created.
5381 final AlignViewportI peer = viewport.getCodingComplement();
5384 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5385 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5387 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5393 * On right mouse click on view tab, prompt for and set new view name.
5396 public void tabbedPane_mousePressed(MouseEvent e)
5398 if (SwingUtilities.isRightMouseButton(e))
5400 String msg = MessageManager.getString("label.enter_view_name");
5401 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5402 JOptionPane.QUESTION_MESSAGE);
5406 viewport.viewName = reply;
5407 // TODO warn if reply is in getExistingViewNames()?
5408 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5413 public AlignViewport getCurrentView()
5419 * Open the dialog for regex description parsing.
5422 protected void extractScores_actionPerformed(ActionEvent e)
5424 ParseProperties pp = new jalview.analysis.ParseProperties(
5425 viewport.getAlignment());
5426 // TODO: verify regex and introduce GUI dialog for version 2.5
5427 // if (pp.getScoresFromDescription("col", "score column ",
5428 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5430 if (pp.getScoresFromDescription("description column",
5431 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5433 buildSortByAnnotationScoresMenu();
5441 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5445 protected void showDbRefs_actionPerformed(ActionEvent e)
5447 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5453 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5457 protected void showNpFeats_actionPerformed(ActionEvent e)
5459 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5463 * find the viewport amongst the tabs in this alignment frame and close that
5468 public boolean closeView(AlignViewportI av)
5472 this.closeMenuItem_actionPerformed(false);
5475 Component[] comp = tabbedPane.getComponents();
5476 for (int i = 0; comp != null && i < comp.length; i++)
5478 if (comp[i] instanceof AlignmentPanel)
5480 if (((AlignmentPanel) comp[i]).av == av)
5483 closeView((AlignmentPanel) comp[i]);
5491 protected void build_fetchdbmenu(JMenu webService)
5493 // Temporary hack - DBRef Fetcher always top level ws entry.
5494 // TODO We probably want to store a sequence database checklist in
5495 // preferences and have checkboxes.. rather than individual sources selected
5497 final JMenu rfetch = new JMenu(
5498 MessageManager.getString("action.fetch_db_references"));
5499 rfetch.setToolTipText(MessageManager
5500 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5501 webService.add(rfetch);
5503 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5504 MessageManager.getString("option.trim_retrieved_seqs"));
5505 trimrs.setToolTipText(MessageManager
5506 .getString("label.trim_retrieved_sequences"));
5507 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5508 trimrs.addActionListener(new ActionListener()
5511 public void actionPerformed(ActionEvent e)
5513 trimrs.setSelected(trimrs.isSelected());
5514 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5515 Boolean.valueOf(trimrs.isSelected()).toString());
5519 JMenuItem fetchr = new JMenuItem(
5520 MessageManager.getString("label.standard_databases"));
5521 fetchr.setToolTipText(MessageManager
5522 .getString("label.fetch_embl_uniprot"));
5523 fetchr.addActionListener(new ActionListener()
5527 public void actionPerformed(ActionEvent e)
5529 new Thread(new Runnable()
5535 new jalview.ws.DBRefFetcher(alignPanel.av
5536 .getSequenceSelection(), alignPanel.alignFrame)
5537 .fetchDBRefs(false);
5545 final AlignFrame me = this;
5546 new Thread(new Runnable()
5551 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5552 .getSequenceFetcherSingleton(me);
5553 javax.swing.SwingUtilities.invokeLater(new Runnable()
5558 String[] dbclasses = sf.getOrderedSupportedSources();
5559 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5560 // jalview.util.QuickSort.sort(otherdb, otherdb);
5561 List<DbSourceProxy> otherdb;
5562 JMenu dfetch = new JMenu();
5563 JMenu ifetch = new JMenu();
5564 JMenuItem fetchr = null;
5565 int comp = 0, icomp = 0, mcomp = 15;
5566 String mname = null;
5568 for (String dbclass : dbclasses)
5570 otherdb = sf.getSourceProxy(dbclass);
5571 // add a single entry for this class, or submenu allowing 'fetch
5573 if (otherdb == null || otherdb.size() < 1)
5577 // List<DbSourceProxy> dbs=otherdb;
5578 // otherdb=new ArrayList<DbSourceProxy>();
5579 // for (DbSourceProxy db:dbs)
5581 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5585 mname = "From " + dbclass;
5587 if (otherdb.size() == 1)
5589 final DbSourceProxy[] dassource = otherdb
5590 .toArray(new DbSourceProxy[0]);
5591 DbSourceProxy src = otherdb.get(0);
5592 fetchr = new JMenuItem(src.getDbSource());
5593 fetchr.addActionListener(new ActionListener()
5597 public void actionPerformed(ActionEvent e)
5599 new Thread(new Runnable()
5605 new jalview.ws.DBRefFetcher(alignPanel.av
5606 .getSequenceSelection(),
5607 alignPanel.alignFrame, dassource)
5608 .fetchDBRefs(false);
5614 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5615 MessageManager.formatMessage(
5616 "label.fetch_retrieve_from",
5617 new Object[] { src.getDbName() })));
5623 final DbSourceProxy[] dassource = otherdb
5624 .toArray(new DbSourceProxy[0]);
5626 DbSourceProxy src = otherdb.get(0);
5627 fetchr = new JMenuItem(MessageManager.formatMessage(
5628 "label.fetch_all_param",
5629 new Object[] { src.getDbSource() }));
5630 fetchr.addActionListener(new ActionListener()
5633 public void actionPerformed(ActionEvent e)
5635 new Thread(new Runnable()
5641 new jalview.ws.DBRefFetcher(alignPanel.av
5642 .getSequenceSelection(),
5643 alignPanel.alignFrame, dassource)
5644 .fetchDBRefs(false);
5650 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5651 MessageManager.formatMessage(
5652 "label.fetch_retrieve_from_all_sources",
5654 Integer.valueOf(otherdb.size())
5655 .toString(), src.getDbSource(),
5656 src.getDbName() })));
5659 // and then build the rest of the individual menus
5660 ifetch = new JMenu(MessageManager.formatMessage(
5661 "label.source_from_db_source",
5662 new Object[] { src.getDbSource() }));
5664 String imname = null;
5666 for (DbSourceProxy sproxy : otherdb)
5668 String dbname = sproxy.getDbName();
5669 String sname = dbname.length() > 5 ? dbname.substring(0,
5670 5) + "..." : dbname;
5671 String msname = dbname.length() > 10 ? dbname.substring(
5672 0, 10) + "..." : dbname;
5675 imname = MessageManager.formatMessage(
5676 "label.from_msname", new Object[] { sname });
5678 fetchr = new JMenuItem(msname);
5679 final DbSourceProxy[] dassrc = { sproxy };
5680 fetchr.addActionListener(new ActionListener()
5684 public void actionPerformed(ActionEvent e)
5686 new Thread(new Runnable()
5692 new jalview.ws.DBRefFetcher(alignPanel.av
5693 .getSequenceSelection(),
5694 alignPanel.alignFrame, dassrc)
5695 .fetchDBRefs(false);
5701 fetchr.setToolTipText("<html>"
5702 + MessageManager.formatMessage(
5703 "label.fetch_retrieve_from", new Object[]
5707 if (++icomp >= mcomp || i == (otherdb.size()))
5709 ifetch.setText(MessageManager.formatMessage(
5710 "label.source_to_target", imname, sname));
5712 ifetch = new JMenu();
5720 if (comp >= mcomp || dbi >= (dbclasses.length))
5722 dfetch.setText(MessageManager.formatMessage(
5723 "label.source_to_target", mname, dbclass));
5725 dfetch = new JMenu();
5738 * Left justify the whole alignment.
5741 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5743 AlignmentI al = viewport.getAlignment();
5745 viewport.firePropertyChange("alignment", null, al);
5749 * Right justify the whole alignment.
5752 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5754 AlignmentI al = viewport.getAlignment();
5756 viewport.firePropertyChange("alignment", null, al);
5759 public void setShowSeqFeatures(boolean b)
5761 showSeqFeatures.setSelected(b);
5762 viewport.setShowSequenceFeatures(b);
5769 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5770 * awt.event.ActionEvent)
5773 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5775 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5776 alignPanel.paintAlignment(true);
5783 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5787 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5789 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5790 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5798 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5799 * .event.ActionEvent)
5802 protected void showGroupConservation_actionPerformed(ActionEvent e)
5804 viewport.setShowGroupConservation(showGroupConservation.getState());
5805 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5812 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5813 * .event.ActionEvent)
5816 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5818 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5819 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5826 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5827 * .event.ActionEvent)
5830 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5832 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5833 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5837 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5839 showSequenceLogo.setState(true);
5840 viewport.setShowSequenceLogo(true);
5841 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5842 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5846 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5848 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5855 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5856 * .event.ActionEvent)
5859 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5861 if (avc.makeGroupsFromSelection())
5863 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5864 alignPanel.updateAnnotation();
5865 alignPanel.paintAlignment(true);
5869 public void clearAlignmentSeqRep()
5871 // TODO refactor alignmentseqrep to controller
5872 if (viewport.getAlignment().hasSeqrep())
5874 viewport.getAlignment().setSeqrep(null);
5875 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5876 alignPanel.updateAnnotation();
5877 alignPanel.paintAlignment(true);
5882 protected void createGroup_actionPerformed(ActionEvent e)
5884 if (avc.createGroup())
5886 alignPanel.alignmentChanged();
5891 protected void unGroup_actionPerformed(ActionEvent e)
5895 alignPanel.alignmentChanged();
5900 * make the given alignmentPanel the currently selected tab
5902 * @param alignmentPanel
5904 public void setDisplayedView(AlignmentPanel alignmentPanel)
5906 if (!viewport.getSequenceSetId().equals(
5907 alignmentPanel.av.getSequenceSetId()))
5911 .getString("error.implementation_error_cannot_show_view_alignment_frame"));
5913 if (tabbedPane != null
5914 && tabbedPane.getTabCount() > 0
5915 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5916 .getSelectedIndex())
5918 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5923 * Action on selection of menu options to Show or Hide annotations.
5926 * @param forSequences
5927 * update sequence-related annotations
5928 * @param forAlignment
5929 * update non-sequence-related annotations
5932 protected void setAnnotationsVisibility(boolean visible,
5933 boolean forSequences, boolean forAlignment)
5935 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5936 .getAlignmentAnnotation())
5939 * don't display non-positional annotations on an alignment
5941 if (aa.annotations == null)
5945 boolean apply = (aa.sequenceRef == null && forAlignment)
5946 || (aa.sequenceRef != null && forSequences);
5949 aa.visible = visible;
5952 alignPanel.validateAnnotationDimensions(true);
5953 alignPanel.alignmentChanged();
5957 * Store selected annotation sort order for the view and repaint.
5960 protected void sortAnnotations_actionPerformed()
5962 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5964 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5965 alignPanel.paintAlignment(true);
5970 * @return alignment panels in this alignment frame
5972 public List<? extends AlignmentViewPanel> getAlignPanels()
5974 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5978 * Open a new alignment window, with the cDNA associated with this (protein)
5979 * alignment, aligned as is the protein.
5981 protected void viewAsCdna_actionPerformed()
5983 // TODO no longer a menu action - refactor as required
5984 final AlignmentI alignment = getViewport().getAlignment();
5985 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5986 if (mappings == null)
5990 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
5991 for (SequenceI aaSeq : alignment.getSequences())
5993 for (AlignedCodonFrame acf : mappings)
5995 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5999 * There is a cDNA mapping for this protein sequence - add to new
6000 * alignment. It will share the same dataset sequence as other mapped
6001 * cDNA (no new mappings need to be created).
6003 final Sequence newSeq = new Sequence(dnaSeq);
6004 newSeq.setDatasetSequence(dnaSeq);
6005 cdnaSeqs.add(newSeq);
6009 if (cdnaSeqs.size() == 0)
6011 // show a warning dialog no mapped cDNA
6014 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6016 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6017 AlignFrame.DEFAULT_HEIGHT);
6018 cdna.alignAs(alignment);
6019 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6021 Desktop.addInternalFrame(alignFrame, newtitle,
6022 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
6026 * Set visibility of dna/protein complement view (available when shown in a
6032 protected void showComplement_actionPerformed(boolean show)
6034 SplitContainerI sf = getSplitViewContainer();
6037 sf.setComplementVisible(this, show);
6042 class PrintThread extends Thread
6046 public PrintThread(AlignmentPanel ap)
6051 static PageFormat pf;
6056 PrinterJob printJob = PrinterJob.getPrinterJob();
6060 printJob.setPrintable(ap, pf);
6064 printJob.setPrintable(ap);
6067 if (printJob.printDialog())
6072 } catch (Exception PrintException)
6074 PrintException.printStackTrace();