2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.ParseProperties;
28 import jalview.analysis.SequenceIdMatcher;
29 import jalview.api.AlignExportSettingI;
30 import jalview.api.AlignViewControllerGuiI;
31 import jalview.api.AlignViewControllerI;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureSettingsControllerI;
35 import jalview.api.FeatureSettingsModelI;
36 import jalview.api.SplitContainerI;
37 import jalview.api.ViewStyleI;
38 import jalview.api.analysis.ScoreModelI;
39 import jalview.bin.Cache;
40 import jalview.bin.Jalview;
41 import jalview.commands.CommandI;
42 import jalview.commands.EditCommand;
43 import jalview.commands.EditCommand.Action;
44 import jalview.commands.OrderCommand;
45 import jalview.commands.RemoveGapColCommand;
46 import jalview.commands.RemoveGapsCommand;
47 import jalview.commands.SlideSequencesCommand;
48 import jalview.commands.TrimRegionCommand;
49 import jalview.datamodel.AlignedCodonFrame;
50 import jalview.datamodel.Alignment;
51 import jalview.datamodel.AlignmentAnnotation;
52 import jalview.datamodel.AlignmentExportData;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.AlignmentOrder;
55 import jalview.datamodel.AlignmentView;
56 import jalview.datamodel.ColumnSelection;
57 import jalview.datamodel.DBRefSource;
58 import jalview.datamodel.HiddenSequences;
59 import jalview.datamodel.PDBEntry;
60 import jalview.datamodel.SeqCigar;
61 import jalview.datamodel.Sequence;
62 import jalview.datamodel.SequenceGroup;
63 import jalview.datamodel.SequenceI;
64 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
65 import jalview.io.AlignmentProperties;
66 import jalview.io.AnnotationFile;
67 import jalview.io.BioJsHTMLOutput;
68 import jalview.io.DataSourceType;
69 import jalview.io.FileFormat;
70 import jalview.io.FileFormatI;
71 import jalview.io.FileLoader;
72 import jalview.io.FormatAdapter;
73 import jalview.io.HtmlSvgOutput;
74 import jalview.io.IdentifyFile;
75 import jalview.io.JPredFile;
76 import jalview.io.JalviewFileChooser;
77 import jalview.io.JalviewFileView;
78 import jalview.io.JnetAnnotationMaker;
79 import jalview.io.NewickFile;
80 import jalview.io.TCoffeeScoreFile;
81 import jalview.io.gff.SequenceOntologyI;
82 import jalview.jbgui.GAlignFrame;
83 import jalview.schemes.Blosum62ColourScheme;
84 import jalview.schemes.BuriedColourScheme;
85 import jalview.schemes.ClustalxColourScheme;
86 import jalview.schemes.ColourSchemeI;
87 import jalview.schemes.ColourSchemeProperty;
88 import jalview.schemes.HelixColourScheme;
89 import jalview.schemes.HydrophobicColourScheme;
90 import jalview.schemes.NucleotideColourScheme;
91 import jalview.schemes.PIDColourScheme;
92 import jalview.schemes.PurinePyrimidineColourScheme;
93 import jalview.schemes.RNAHelicesColourChooser;
94 import jalview.schemes.ResidueProperties;
95 import jalview.schemes.StrandColourScheme;
96 import jalview.schemes.TCoffeeColourScheme;
97 import jalview.schemes.TaylorColourScheme;
98 import jalview.schemes.TurnColourScheme;
99 import jalview.schemes.UserColourScheme;
100 import jalview.schemes.ZappoColourScheme;
101 import jalview.structure.StructureSelectionManager;
102 import jalview.util.MessageManager;
103 import jalview.viewmodel.AlignmentViewport;
104 import jalview.ws.DBRefFetcher;
105 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
106 import jalview.ws.SequenceFetcher;
107 import jalview.ws.jws1.Discoverer;
108 import jalview.ws.jws2.Jws2Discoverer;
109 import jalview.ws.jws2.jabaws2.Jws2Instance;
110 import jalview.ws.seqfetcher.DbSourceProxy;
112 import java.awt.BorderLayout;
113 import java.awt.Component;
114 import java.awt.Rectangle;
115 import java.awt.Toolkit;
116 import java.awt.datatransfer.Clipboard;
117 import java.awt.datatransfer.DataFlavor;
118 import java.awt.datatransfer.StringSelection;
119 import java.awt.datatransfer.Transferable;
120 import java.awt.dnd.DropTargetDragEvent;
121 import java.awt.dnd.DropTargetDropEvent;
122 import java.awt.dnd.DropTargetEvent;
123 import java.awt.dnd.DropTargetListener;
124 import java.awt.event.ActionEvent;
125 import java.awt.event.ActionListener;
126 import java.awt.event.FocusAdapter;
127 import java.awt.event.FocusEvent;
128 import java.awt.event.ItemEvent;
129 import java.awt.event.ItemListener;
130 import java.awt.event.KeyAdapter;
131 import java.awt.event.KeyEvent;
132 import java.awt.event.MouseAdapter;
133 import java.awt.event.MouseEvent;
134 import java.awt.print.PageFormat;
135 import java.awt.print.PrinterJob;
136 import java.beans.PropertyChangeEvent;
139 import java.util.ArrayList;
140 import java.util.Arrays;
141 import java.util.Deque;
142 import java.util.Enumeration;
143 import java.util.Hashtable;
144 import java.util.List;
145 import java.util.Vector;
147 import javax.swing.JCheckBoxMenuItem;
148 import javax.swing.JEditorPane;
149 import javax.swing.JInternalFrame;
150 import javax.swing.JLayeredPane;
151 import javax.swing.JMenu;
152 import javax.swing.JMenuItem;
153 import javax.swing.JOptionPane;
154 import javax.swing.JRadioButtonMenuItem;
155 import javax.swing.JScrollPane;
156 import javax.swing.SwingUtilities;
162 * @version $Revision$
164 public class AlignFrame extends GAlignFrame implements DropTargetListener,
165 IProgressIndicator, AlignViewControllerGuiI
168 public static final int DEFAULT_WIDTH = 700;
170 public static final int DEFAULT_HEIGHT = 500;
173 * The currently displayed panel (selected tabbed view if more than one)
175 public AlignmentPanel alignPanel;
177 AlignViewport viewport;
179 public AlignViewControllerI avc;
181 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
184 * Last format used to load or save alignments in this window
186 FileFormatI currentFileFormat = null;
189 * Current filename for this alignment
191 String fileName = null;
194 * Creates a new AlignFrame object with specific width and height.
200 public AlignFrame(AlignmentI al, int width, int height)
202 this(al, null, width, height);
206 * Creates a new AlignFrame object with specific width, height and
212 * @param sequenceSetId
214 public AlignFrame(AlignmentI al, int width, int height,
215 String sequenceSetId)
217 this(al, null, width, height, sequenceSetId);
221 * Creates a new AlignFrame object with specific width, height and
227 * @param sequenceSetId
230 public AlignFrame(AlignmentI al, int width, int height,
231 String sequenceSetId, String viewId)
233 this(al, null, width, height, sequenceSetId, viewId);
237 * new alignment window with hidden columns
241 * @param hiddenColumns
242 * ColumnSelection or null
244 * Width of alignment frame
248 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
249 int width, int height)
251 this(al, hiddenColumns, width, height, null);
255 * Create alignment frame for al with hiddenColumns, a specific width and
256 * height, and specific sequenceId
259 * @param hiddenColumns
262 * @param sequenceSetId
265 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
266 int width, int height, String sequenceSetId)
268 this(al, hiddenColumns, width, height, sequenceSetId, null);
272 * Create alignment frame for al with hiddenColumns, a specific width and
273 * height, and specific sequenceId
276 * @param hiddenColumns
279 * @param sequenceSetId
284 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
285 int width, int height, String sequenceSetId, String viewId)
287 setSize(width, height);
289 if (al.getDataset() == null)
294 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
296 alignPanel = new AlignmentPanel(this, viewport);
298 addAlignmentPanel(alignPanel, true);
302 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
303 ColumnSelection hiddenColumns, int width, int height)
305 setSize(width, height);
307 if (al.getDataset() == null)
312 viewport = new AlignViewport(al, hiddenColumns);
314 if (hiddenSeqs != null && hiddenSeqs.length > 0)
316 viewport.hideSequence(hiddenSeqs);
318 alignPanel = new AlignmentPanel(this, viewport);
319 addAlignmentPanel(alignPanel, true);
324 * Make a new AlignFrame from existing alignmentPanels
331 public AlignFrame(AlignmentPanel ap)
335 addAlignmentPanel(ap, false);
340 * initalise the alignframe from the underlying viewport data and the
345 if (!Jalview.isHeadlessMode())
347 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
350 avc = new jalview.controller.AlignViewController(this, viewport,
352 if (viewport.getAlignmentConservationAnnotation() == null)
354 BLOSUM62Colour.setEnabled(false);
355 conservationMenuItem.setEnabled(false);
356 modifyConservation.setEnabled(false);
357 // PIDColour.setEnabled(false);
358 // abovePIDThreshold.setEnabled(false);
359 // modifyPID.setEnabled(false);
362 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
365 if (sortby.equals("Id"))
367 sortIDMenuItem_actionPerformed(null);
369 else if (sortby.equals("Pairwise Identity"))
371 sortPairwiseMenuItem_actionPerformed(null);
374 if (Desktop.desktop != null)
376 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
377 addServiceListeners();
378 setGUINucleotide(viewport.getAlignment().isNucleotide());
382 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
384 setMenusFromViewport(viewport);
385 buildSortByAnnotationScoresMenu();
388 if (viewport.getWrapAlignment())
390 wrapMenuItem_actionPerformed(null);
393 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
395 this.overviewMenuItem_actionPerformed(null);
400 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
401 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
402 final String menuLabel = MessageManager
403 .getString("label.copy_format_from");
404 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
405 new ViewSetProvider()
409 public AlignmentPanel[] getAllAlignmentPanels()
412 origview.add(alignPanel);
413 // make an array of all alignment panels except for this one
414 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
415 Arrays.asList(Desktop.getAlignmentPanels(null)));
416 aps.remove(AlignFrame.this.alignPanel);
417 return aps.toArray(new AlignmentPanel[aps.size()]);
419 }, selviews, new ItemListener()
423 public void itemStateChanged(ItemEvent e)
425 if (origview.size() > 0)
427 final AlignmentPanel ap = origview.get(0);
430 * Copy the ViewStyle of the selected panel to 'this one'.
431 * Don't change value of 'scaleProteinAsCdna' unless copying
434 ViewStyleI vs = selviews.get(0).getAlignViewport()
436 boolean fromSplitFrame = selviews.get(0)
437 .getAlignViewport().getCodingComplement() != null;
440 vs.setScaleProteinAsCdna(ap.getAlignViewport()
441 .getViewStyle().isScaleProteinAsCdna());
443 ap.getAlignViewport().setViewStyle(vs);
446 * Also rescale ViewStyle of SplitFrame complement if there is
447 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
448 * the whole ViewStyle (allow cDNA protein to have different
451 AlignViewportI complement = ap.getAlignViewport()
452 .getCodingComplement();
453 if (complement != null && vs.isScaleProteinAsCdna())
455 AlignFrame af = Desktop.getAlignFrameFor(complement);
456 ((SplitFrame) af.getSplitViewContainer())
458 af.setMenusForViewport();
462 ap.setSelected(true);
463 ap.alignFrame.setMenusForViewport();
468 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
469 .indexOf("devel") > -1
470 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
471 .indexOf("test") > -1)
473 formatMenu.add(vsel);
475 addFocusListener(new FocusAdapter()
478 public void focusGained(FocusEvent e)
480 Jalview.setCurrentAlignFrame(AlignFrame.this);
487 * Change the filename and format for the alignment, and enable the 'reload'
488 * button functionality.
495 public void setFileName(String file, FileFormatI format)
498 setFileFormat(format);
499 reload.setEnabled(true);
503 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
506 void addKeyListener()
508 addKeyListener(new KeyAdapter()
511 public void keyPressed(KeyEvent evt)
513 if (viewport.cursorMode
514 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
515 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
516 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
517 && Character.isDigit(evt.getKeyChar()))
519 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
522 switch (evt.getKeyCode())
525 case 27: // escape key
526 deselectAllSequenceMenuItem_actionPerformed(null);
530 case KeyEvent.VK_DOWN:
531 if (evt.isAltDown() || !viewport.cursorMode)
533 moveSelectedSequences(false);
535 if (viewport.cursorMode)
537 alignPanel.getSeqPanel().moveCursor(0, 1);
542 if (evt.isAltDown() || !viewport.cursorMode)
544 moveSelectedSequences(true);
546 if (viewport.cursorMode)
548 alignPanel.getSeqPanel().moveCursor(0, -1);
553 case KeyEvent.VK_LEFT:
554 if (evt.isAltDown() || !viewport.cursorMode)
556 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
560 alignPanel.getSeqPanel().moveCursor(-1, 0);
565 case KeyEvent.VK_RIGHT:
566 if (evt.isAltDown() || !viewport.cursorMode)
568 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
572 alignPanel.getSeqPanel().moveCursor(1, 0);
576 case KeyEvent.VK_SPACE:
577 if (viewport.cursorMode)
579 alignPanel.getSeqPanel().insertGapAtCursor(
580 evt.isControlDown() || evt.isShiftDown()
585 // case KeyEvent.VK_A:
586 // if (viewport.cursorMode)
588 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
589 // //System.out.println("A");
593 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
594 * System.out.println("closing bracket"); } break;
596 case KeyEvent.VK_DELETE:
597 case KeyEvent.VK_BACK_SPACE:
598 if (!viewport.cursorMode)
600 cut_actionPerformed(null);
604 alignPanel.getSeqPanel().deleteGapAtCursor(
605 evt.isControlDown() || evt.isShiftDown()
612 if (viewport.cursorMode)
614 alignPanel.getSeqPanel().setCursorRow();
618 if (viewport.cursorMode && !evt.isControlDown())
620 alignPanel.getSeqPanel().setCursorColumn();
624 if (viewport.cursorMode)
626 alignPanel.getSeqPanel().setCursorPosition();
630 case KeyEvent.VK_ENTER:
631 case KeyEvent.VK_COMMA:
632 if (viewport.cursorMode)
634 alignPanel.getSeqPanel().setCursorRowAndColumn();
639 if (viewport.cursorMode)
641 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
645 if (viewport.cursorMode)
647 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
652 viewport.cursorMode = !viewport.cursorMode;
653 statusBar.setText(MessageManager.formatMessage(
654 "label.keyboard_editing_mode",
655 new String[] { (viewport.cursorMode ? "on" : "off") }));
656 if (viewport.cursorMode)
658 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
659 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
661 alignPanel.getSeqPanel().seqCanvas.repaint();
667 Help.showHelpWindow();
668 } catch (Exception ex)
670 ex.printStackTrace();
675 boolean toggleSeqs = !evt.isControlDown();
676 boolean toggleCols = !evt.isShiftDown();
677 toggleHiddenRegions(toggleSeqs, toggleCols);
680 case KeyEvent.VK_PAGE_UP:
681 if (viewport.getWrapAlignment())
683 alignPanel.scrollUp(true);
687 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
688 - viewport.endSeq + viewport.startSeq);
691 case KeyEvent.VK_PAGE_DOWN:
692 if (viewport.getWrapAlignment())
694 alignPanel.scrollUp(false);
698 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
699 + viewport.endSeq - viewport.startSeq);
706 public void keyReleased(KeyEvent evt)
708 switch (evt.getKeyCode())
710 case KeyEvent.VK_LEFT:
711 if (evt.isAltDown() || !viewport.cursorMode)
713 viewport.firePropertyChange("alignment", null, viewport
714 .getAlignment().getSequences());
718 case KeyEvent.VK_RIGHT:
719 if (evt.isAltDown() || !viewport.cursorMode)
721 viewport.firePropertyChange("alignment", null, viewport
722 .getAlignment().getSequences());
730 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
732 ap.alignFrame = this;
733 avc = new jalview.controller.AlignViewController(this, viewport,
738 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
740 int aSize = alignPanels.size();
742 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
744 if (aSize == 1 && ap.av.viewName == null)
746 this.getContentPane().add(ap, BorderLayout.CENTER);
752 setInitialTabVisible();
755 expandViews.setEnabled(true);
756 gatherViews.setEnabled(true);
757 tabbedPane.addTab(ap.av.viewName, ap);
759 ap.setVisible(false);
764 if (ap.av.isPadGaps())
766 ap.av.getAlignment().padGaps();
768 ap.av.updateConservation(ap);
769 ap.av.updateConsensus(ap);
770 ap.av.updateStrucConsensus(ap);
774 public void setInitialTabVisible()
776 expandViews.setEnabled(true);
777 gatherViews.setEnabled(true);
778 tabbedPane.setVisible(true);
779 AlignmentPanel first = alignPanels.get(0);
780 tabbedPane.addTab(first.av.viewName, first);
781 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
784 public AlignViewport getViewport()
789 /* Set up intrinsic listeners for dynamically generated GUI bits. */
790 private void addServiceListeners()
792 final java.beans.PropertyChangeListener thisListener;
793 Desktop.instance.addJalviewPropertyChangeListener("services",
794 thisListener = new java.beans.PropertyChangeListener()
797 public void propertyChange(PropertyChangeEvent evt)
799 // // System.out.println("Discoverer property change.");
800 // if (evt.getPropertyName().equals("services"))
802 SwingUtilities.invokeLater(new Runnable()
809 .println("Rebuild WS Menu for service change");
810 BuildWebServiceMenu();
817 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
820 public void internalFrameClosed(
821 javax.swing.event.InternalFrameEvent evt)
823 // System.out.println("deregistering discoverer listener");
824 Desktop.instance.removeJalviewPropertyChangeListener("services",
826 closeMenuItem_actionPerformed(true);
829 // Finally, build the menu once to get current service state
830 new Thread(new Runnable()
835 BuildWebServiceMenu();
841 * Configure menu items that vary according to whether the alignment is
842 * nucleotide or protein
846 public void setGUINucleotide(boolean nucleotide)
848 showTranslation.setVisible(nucleotide);
849 showReverse.setVisible(nucleotide);
850 showReverseComplement.setVisible(nucleotide);
851 conservationMenuItem.setEnabled(!nucleotide);
852 modifyConservation.setEnabled(!nucleotide);
853 showGroupConservation.setEnabled(!nucleotide);
854 rnahelicesColour.setEnabled(nucleotide);
855 purinePyrimidineColour.setEnabled(nucleotide);
856 showComplementMenuItem.setText(nucleotide ? MessageManager
857 .getString("label.protein") : MessageManager
858 .getString("label.nucleotide"));
859 setColourSelected(jalview.bin.Cache.getDefault(
860 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
861 : Preferences.DEFAULT_COLOUR_PROT, "None"));
865 * set up menus for the current viewport. This may be called after any
866 * operation that affects the data in the current view (selection changed,
867 * etc) to update the menus to reflect the new state.
870 public void setMenusForViewport()
872 setMenusFromViewport(viewport);
876 * Need to call this method when tabs are selected for multiple views, or when
877 * loading from Jalview2XML.java
882 void setMenusFromViewport(AlignViewport av)
884 padGapsMenuitem.setSelected(av.isPadGaps());
885 colourTextMenuItem.setSelected(av.isShowColourText());
886 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
887 conservationMenuItem.setSelected(av.getConservationSelected());
888 seqLimits.setSelected(av.getShowJVSuffix());
889 idRightAlign.setSelected(av.isRightAlignIds());
890 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
891 renderGapsMenuItem.setSelected(av.isRenderGaps());
892 wrapMenuItem.setSelected(av.getWrapAlignment());
893 scaleAbove.setVisible(av.getWrapAlignment());
894 scaleLeft.setVisible(av.getWrapAlignment());
895 scaleRight.setVisible(av.getWrapAlignment());
896 annotationPanelMenuItem.setState(av.isShowAnnotation());
898 * Show/hide annotations only enabled if annotation panel is shown
900 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
901 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
902 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
903 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
904 viewBoxesMenuItem.setSelected(av.getShowBoxes());
905 viewTextMenuItem.setSelected(av.getShowText());
906 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
907 showGroupConsensus.setSelected(av.isShowGroupConsensus());
908 showGroupConservation.setSelected(av.isShowGroupConservation());
909 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
910 showSequenceLogo.setSelected(av.isShowSequenceLogo());
911 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
913 setColourSelected(ColourSchemeProperty.getColourName(av
914 .getGlobalColourScheme()));
916 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
917 hiddenMarkers.setState(av.getShowHiddenMarkers());
918 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
919 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
920 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
921 autoCalculate.setSelected(av.autoCalculateConsensus);
922 sortByTree.setSelected(av.sortByTree);
923 listenToViewSelections.setSelected(av.followSelection);
924 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
926 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
928 showProducts.setEnabled(canShowProducts());
929 setGroovyEnabled(Desktop.getGroovyConsole() != null);
935 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
939 public void setGroovyEnabled(boolean b)
941 runGroovy.setEnabled(b);
944 private IProgressIndicator progressBar;
949 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
952 public void setProgressBar(String message, long id)
954 progressBar.setProgressBar(message, id);
958 public void registerHandler(final long id,
959 final IProgressIndicatorHandler handler)
961 progressBar.registerHandler(id, handler);
966 * @return true if any progress bars are still active
969 public boolean operationInProgress()
971 return progressBar.operationInProgress();
975 public void setStatus(String text)
977 statusBar.setText(text);
981 * Added so Castor Mapping file can obtain Jalview Version
983 public String getVersion()
985 return jalview.bin.Cache.getProperty("VERSION");
988 public FeatureRenderer getFeatureRenderer()
990 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
994 public void fetchSequence_actionPerformed(ActionEvent e)
996 new jalview.gui.SequenceFetcher(this);
1000 public void addFromFile_actionPerformed(ActionEvent e)
1002 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1006 public void reload_actionPerformed(ActionEvent e)
1008 if (fileName != null)
1010 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1011 // originating file's format
1012 // TODO: work out how to recover feature settings for correct view(s) when
1013 // file is reloaded.
1014 if (currentFileFormat == FileFormat.Jalview)
1016 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1017 for (int i = 0; i < frames.length; i++)
1019 if (frames[i] instanceof AlignFrame && frames[i] != this
1020 && ((AlignFrame) frames[i]).fileName != null
1021 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1025 frames[i].setSelected(true);
1026 Desktop.instance.closeAssociatedWindows();
1027 } catch (java.beans.PropertyVetoException ex)
1033 Desktop.instance.closeAssociatedWindows();
1035 FileLoader loader = new FileLoader();
1036 DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL
1037 : DataSourceType.FILE;
1038 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1042 Rectangle bounds = this.getBounds();
1044 FileLoader loader = new FileLoader();
1045 DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL
1046 : DataSourceType.FILE;
1047 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1048 protocol, currentFileFormat);
1050 newframe.setBounds(bounds);
1051 if (featureSettings != null && featureSettings.isShowing())
1053 final Rectangle fspos = featureSettings.frame.getBounds();
1054 // TODO: need a 'show feature settings' function that takes bounds -
1055 // need to refactor Desktop.addFrame
1056 newframe.featureSettings_actionPerformed(null);
1057 final FeatureSettings nfs = newframe.featureSettings;
1058 SwingUtilities.invokeLater(new Runnable()
1063 nfs.frame.setBounds(fspos);
1066 this.featureSettings.close();
1067 this.featureSettings = null;
1069 this.closeMenuItem_actionPerformed(true);
1075 public void addFromText_actionPerformed(ActionEvent e)
1077 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport
1082 public void addFromURL_actionPerformed(ActionEvent e)
1084 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1088 public void save_actionPerformed(ActionEvent e)
1090 if (fileName == null || (currentFileFormat == null)
1091 || fileName.startsWith("http"))
1093 saveAs_actionPerformed(null);
1097 saveAlignment(fileName, currentFileFormat);
1108 public void saveAs_actionPerformed(ActionEvent e)
1110 JalviewFileChooser chooser = JalviewFileChooser.forWrite(
1111 Cache.getProperty("LAST_DIRECTORY"),
1112 // AppletFormatAdapter.WRITABLE_EXTENSIONS,
1113 // AppletFormatAdapter.WRITABLE_FNAMES,
1114 currentFileFormat.toString(), false);
1116 chooser.setFileView(new JalviewFileView());
1117 chooser.setDialogTitle(MessageManager
1118 .getString("label.save_alignment_to_file"));
1119 chooser.setToolTipText(MessageManager.getString("action.save"));
1121 int value = chooser.showSaveDialog(this);
1123 if (value == JalviewFileChooser.APPROVE_OPTION)
1125 currentFileFormat = chooser.getSelectedFormat();
1126 while (currentFileFormat == null)
1129 .showInternalMessageDialog(
1132 .getString("label.select_file_format_before_saving"),
1134 .getString("label.file_format_not_specified"),
1135 JOptionPane.WARNING_MESSAGE);
1136 currentFileFormat = chooser.getSelectedFormat();
1137 value = chooser.showSaveDialog(this);
1138 if (value != JalviewFileChooser.APPROVE_OPTION)
1144 fileName = chooser.getSelectedFile().getPath();
1146 Cache.setProperty("DEFAULT_FILE_FORMAT",
1147 currentFileFormat.toString());
1149 Cache.setProperty("LAST_DIRECTORY", fileName);
1150 saveAlignment(fileName, currentFileFormat);
1154 public boolean saveAlignment(String file, FileFormatI format)
1156 boolean success = true;
1158 if (format == FileFormat.Jalview)
1160 String shortName = title;
1162 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1164 shortName = shortName.substring(shortName
1165 .lastIndexOf(java.io.File.separatorChar) + 1);
1168 success = new Jalview2XML().saveAlignment(this, file, shortName);
1170 statusBar.setText(MessageManager.formatMessage(
1171 "label.successfully_saved_to_file_in_format", new Object[] {
1172 fileName, format }));
1177 // if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1179 // warningMessage("Cannot save file " + fileName + " using format "
1180 // + format, "Alignment output format not supported");
1181 // if (!Jalview.isHeadlessMode())
1183 // saveAs_actionPerformed(null);
1188 AlignmentExportData exportData = getAlignmentForExport(format,
1190 if (exportData.getSettings().isCancelled())
1194 FormatAdapter f = new FormatAdapter(alignPanel,
1195 exportData.getSettings());
1196 String output = f.formatSequences(
1198 exportData.getAlignment(), // class cast exceptions will
1199 // occur in the distant future
1200 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1201 f.getCacheSuffixDefault(format),
1202 viewport.getColumnSelection());
1212 java.io.PrintWriter out = new java.io.PrintWriter(
1213 new java.io.FileWriter(file));
1217 this.setTitle(file);
1218 statusBar.setText(MessageManager.formatMessage(
1219 "label.successfully_saved_to_file_in_format",
1220 new Object[] { fileName, format }));
1221 } catch (Exception ex)
1224 ex.printStackTrace();
1231 JOptionPane.showInternalMessageDialog(this, MessageManager
1232 .formatMessage("label.couldnt_save_file",
1233 new Object[] { fileName }), MessageManager
1234 .getString("label.error_saving_file"),
1235 JOptionPane.WARNING_MESSAGE);
1241 private void warningMessage(String warning, String title)
1243 if (new jalview.util.Platform().isHeadless())
1245 System.err.println("Warning: " + title + "\nWarning: " + warning);
1250 JOptionPane.showInternalMessageDialog(this, warning, title,
1251 JOptionPane.WARNING_MESSAGE);
1263 protected void outputText_actionPerformed(ActionEvent e)
1266 FileFormat fileFormat = FileFormat.valueOf(e.getActionCommand());
1267 AlignmentExportData exportData = getAlignmentForExport(
1270 if (exportData.getSettings().isCancelled())
1274 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1275 cap.setForInput(null);
1278 FileFormatI format = fileFormat;
1279 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1280 .formatSequences(format,
1281 exportData.getAlignment(),
1282 exportData.getOmitHidden(),
1283 exportData.getStartEndPostions(),
1284 viewport.getColumnSelection()));
1285 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1286 "label.alignment_output_command",
1287 new Object[] { e.getActionCommand() }), 600, 500);
1288 } catch (OutOfMemoryError oom)
1290 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1296 public static AlignmentExportData getAlignmentForExport(
1297 FileFormatI format, AlignViewportI viewport,
1298 AlignExportSettingI exportSettings)
1300 AlignmentI alignmentToExport = null;
1301 AlignExportSettingI settings = exportSettings;
1302 String[] omitHidden = null;
1304 HiddenSequences hiddenSeqs = viewport.getAlignment()
1305 .getHiddenSequences();
1307 alignmentToExport = viewport.getAlignment();
1309 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1310 if (settings == null)
1312 settings = new AlignExportSettings(hasHiddenSeqs,
1313 viewport.hasHiddenColumns(), format);
1315 // settings.isExportAnnotations();
1317 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1319 omitHidden = viewport.getViewAsString(false,
1320 settings.isExportHiddenSequences());
1323 int[] alignmentStartEnd = new int[2];
1324 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1326 alignmentToExport = hiddenSeqs.getFullAlignment();
1330 alignmentToExport = viewport.getAlignment();
1332 alignmentStartEnd = alignmentToExport
1333 .getVisibleStartAndEndIndex(viewport.getColumnSelection()
1334 .getHiddenColumns());
1335 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1336 omitHidden, alignmentStartEnd, settings);
1347 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1349 new HtmlSvgOutput(null, alignPanel);
1353 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1355 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this);
1356 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1359 public void createImageMap(File file, String image)
1361 alignPanel.makePNGImageMap(file, image);
1371 public void createPNG(File f)
1373 alignPanel.makePNG(f);
1383 public void createEPS(File f)
1385 alignPanel.makeEPS(f);
1389 public void createSVG(File f)
1391 alignPanel.makeSVG(f);
1395 public void pageSetup_actionPerformed(ActionEvent e)
1397 PrinterJob printJob = PrinterJob.getPrinterJob();
1398 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1408 public void printMenuItem_actionPerformed(ActionEvent e)
1410 // Putting in a thread avoids Swing painting problems
1411 PrintThread thread = new PrintThread(alignPanel);
1416 public void exportFeatures_actionPerformed(ActionEvent e)
1418 new AnnotationExporter().exportFeatures(alignPanel);
1422 public void exportAnnotations_actionPerformed(ActionEvent e)
1424 new AnnotationExporter().exportAnnotations(alignPanel);
1428 public void associatedData_actionPerformed(ActionEvent e)
1430 // Pick the tree file
1431 JalviewFileChooser chooser = new JalviewFileChooser(
1432 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1433 chooser.setFileView(new JalviewFileView());
1434 chooser.setDialogTitle(MessageManager
1435 .getString("label.load_jalview_annotations"));
1436 chooser.setToolTipText(MessageManager
1437 .getString("label.load_jalview_annotations"));
1439 int value = chooser.showOpenDialog(null);
1441 if (value == JalviewFileChooser.APPROVE_OPTION)
1443 String choice = chooser.getSelectedFile().getPath();
1444 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1445 loadJalviewDataFile(choice, null, null, null);
1451 * Close the current view or all views in the alignment frame. If the frame
1452 * only contains one view then the alignment will be removed from memory.
1454 * @param closeAllTabs
1457 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1459 if (alignPanels != null && alignPanels.size() < 2)
1461 closeAllTabs = true;
1466 if (alignPanels != null)
1470 if (this.isClosed())
1472 // really close all the windows - otherwise wait till
1473 // setClosed(true) is called
1474 for (int i = 0; i < alignPanels.size(); i++)
1476 AlignmentPanel ap = alignPanels.get(i);
1483 closeView(alignPanel);
1490 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1491 * be called recursively, with the frame now in 'closed' state
1493 this.setClosed(true);
1495 } catch (Exception ex)
1497 ex.printStackTrace();
1502 * Close the specified panel and close up tabs appropriately.
1504 * @param panelToClose
1506 public void closeView(AlignmentPanel panelToClose)
1508 int index = tabbedPane.getSelectedIndex();
1509 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1510 alignPanels.remove(panelToClose);
1511 panelToClose.closePanel();
1512 panelToClose = null;
1514 tabbedPane.removeTabAt(closedindex);
1515 tabbedPane.validate();
1517 if (index > closedindex || index == tabbedPane.getTabCount())
1519 // modify currently selected tab index if necessary.
1523 this.tabSelectionChanged(index);
1529 void updateEditMenuBar()
1532 if (viewport.getHistoryList().size() > 0)
1534 undoMenuItem.setEnabled(true);
1535 CommandI command = viewport.getHistoryList().peek();
1536 undoMenuItem.setText(MessageManager.formatMessage(
1537 "label.undo_command",
1538 new Object[] { command.getDescription() }));
1542 undoMenuItem.setEnabled(false);
1543 undoMenuItem.setText(MessageManager.getString("action.undo"));
1546 if (viewport.getRedoList().size() > 0)
1548 redoMenuItem.setEnabled(true);
1550 CommandI command = viewport.getRedoList().peek();
1551 redoMenuItem.setText(MessageManager.formatMessage(
1552 "label.redo_command",
1553 new Object[] { command.getDescription() }));
1557 redoMenuItem.setEnabled(false);
1558 redoMenuItem.setText(MessageManager.getString("action.redo"));
1563 public void addHistoryItem(CommandI command)
1565 if (command.getSize() > 0)
1567 viewport.addToHistoryList(command);
1568 viewport.clearRedoList();
1569 updateEditMenuBar();
1570 viewport.updateHiddenColumns();
1571 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1572 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1573 // viewport.getColumnSelection()
1574 // .getHiddenColumns().size() > 0);
1580 * @return alignment objects for all views
1582 AlignmentI[] getViewAlignments()
1584 if (alignPanels != null)
1586 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1588 for (AlignmentPanel ap : alignPanels)
1590 als[i++] = ap.av.getAlignment();
1594 if (viewport != null)
1596 return new AlignmentI[] { viewport.getAlignment() };
1608 protected void undoMenuItem_actionPerformed(ActionEvent e)
1610 if (viewport.getHistoryList().isEmpty())
1614 CommandI command = viewport.getHistoryList().pop();
1615 viewport.addToRedoList(command);
1616 command.undoCommand(getViewAlignments());
1618 AlignmentViewport originalSource = getOriginatingSource(command);
1619 updateEditMenuBar();
1621 if (originalSource != null)
1623 if (originalSource != viewport)
1626 .warn("Implementation worry: mismatch of viewport origin for undo");
1628 originalSource.updateHiddenColumns();
1629 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1631 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1632 // viewport.getColumnSelection()
1633 // .getHiddenColumns().size() > 0);
1634 originalSource.firePropertyChange("alignment", null, originalSource
1635 .getAlignment().getSequences());
1646 protected void redoMenuItem_actionPerformed(ActionEvent e)
1648 if (viewport.getRedoList().size() < 1)
1653 CommandI command = viewport.getRedoList().pop();
1654 viewport.addToHistoryList(command);
1655 command.doCommand(getViewAlignments());
1657 AlignmentViewport originalSource = getOriginatingSource(command);
1658 updateEditMenuBar();
1660 if (originalSource != null)
1663 if (originalSource != viewport)
1666 .warn("Implementation worry: mismatch of viewport origin for redo");
1668 originalSource.updateHiddenColumns();
1669 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1671 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1672 // viewport.getColumnSelection()
1673 // .getHiddenColumns().size() > 0);
1674 originalSource.firePropertyChange("alignment", null, originalSource
1675 .getAlignment().getSequences());
1679 AlignmentViewport getOriginatingSource(CommandI command)
1681 AlignmentViewport originalSource = null;
1682 // For sequence removal and addition, we need to fire
1683 // the property change event FROM the viewport where the
1684 // original alignment was altered
1685 AlignmentI al = null;
1686 if (command instanceof EditCommand)
1688 EditCommand editCommand = (EditCommand) command;
1689 al = editCommand.getAlignment();
1690 List<Component> comps = PaintRefresher.components.get(viewport
1691 .getSequenceSetId());
1693 for (Component comp : comps)
1695 if (comp instanceof AlignmentPanel)
1697 if (al == ((AlignmentPanel) comp).av.getAlignment())
1699 originalSource = ((AlignmentPanel) comp).av;
1706 if (originalSource == null)
1708 // The original view is closed, we must validate
1709 // the current view against the closed view first
1712 PaintRefresher.validateSequences(al, viewport.getAlignment());
1715 originalSource = viewport;
1718 return originalSource;
1727 public void moveSelectedSequences(boolean up)
1729 SequenceGroup sg = viewport.getSelectionGroup();
1735 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1736 viewport.getHiddenRepSequences(), up);
1737 alignPanel.paintAlignment(true);
1740 synchronized void slideSequences(boolean right, int size)
1742 List<SequenceI> sg = new ArrayList<SequenceI>();
1743 if (viewport.cursorMode)
1745 sg.add(viewport.getAlignment().getSequenceAt(
1746 alignPanel.getSeqPanel().seqCanvas.cursorY));
1748 else if (viewport.getSelectionGroup() != null
1749 && viewport.getSelectionGroup().getSize() != viewport
1750 .getAlignment().getHeight())
1752 sg = viewport.getSelectionGroup().getSequences(
1753 viewport.getHiddenRepSequences());
1761 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1763 for (SequenceI seq : viewport.getAlignment().getSequences())
1765 if (!sg.contains(seq))
1767 invertGroup.add(seq);
1771 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1773 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1774 for (int i = 0; i < invertGroup.size(); i++)
1776 seqs2[i] = invertGroup.get(i);
1779 SlideSequencesCommand ssc;
1782 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1783 size, viewport.getGapCharacter());
1787 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1788 size, viewport.getGapCharacter());
1791 int groupAdjustment = 0;
1792 if (ssc.getGapsInsertedBegin() && right)
1794 if (viewport.cursorMode)
1796 alignPanel.getSeqPanel().moveCursor(size, 0);
1800 groupAdjustment = size;
1803 else if (!ssc.getGapsInsertedBegin() && !right)
1805 if (viewport.cursorMode)
1807 alignPanel.getSeqPanel().moveCursor(-size, 0);
1811 groupAdjustment = -size;
1815 if (groupAdjustment != 0)
1817 viewport.getSelectionGroup().setStartRes(
1818 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1819 viewport.getSelectionGroup().setEndRes(
1820 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1824 * just extend the last slide command if compatible; but not if in
1825 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1827 boolean appendHistoryItem = false;
1828 Deque<CommandI> historyList = viewport.getHistoryList();
1829 boolean inSplitFrame = getSplitViewContainer() != null;
1830 if (!inSplitFrame && historyList != null && historyList.size() > 0
1831 && historyList.peek() instanceof SlideSequencesCommand)
1833 appendHistoryItem = ssc
1834 .appendSlideCommand((SlideSequencesCommand) historyList
1838 if (!appendHistoryItem)
1840 addHistoryItem(ssc);
1853 protected void copy_actionPerformed(ActionEvent e)
1856 if (viewport.getSelectionGroup() == null)
1860 // TODO: preserve the ordering of displayed alignment annotation in any
1861 // internal paste (particularly sequence associated annotation)
1862 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1863 String[] omitHidden = null;
1865 if (viewport.hasHiddenColumns())
1867 omitHidden = viewport.getViewAsString(true);
1870 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1874 StringSelection ss = new StringSelection(output);
1878 jalview.gui.Desktop.internalCopy = true;
1879 // Its really worth setting the clipboard contents
1880 // to empty before setting the large StringSelection!!
1881 Toolkit.getDefaultToolkit().getSystemClipboard()
1882 .setContents(new StringSelection(""), null);
1884 Toolkit.getDefaultToolkit().getSystemClipboard()
1885 .setContents(ss, Desktop.instance);
1886 } catch (OutOfMemoryError er)
1888 new OOMWarning("copying region", er);
1892 ArrayList<int[]> hiddenColumns = null;
1893 if (viewport.hasHiddenColumns())
1895 hiddenColumns = new ArrayList<int[]>();
1896 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1897 .getSelectionGroup().getEndRes();
1898 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1900 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1902 hiddenColumns.add(new int[] { region[0] - hiddenOffset,
1903 region[1] - hiddenOffset });
1908 Desktop.jalviewClipboard = new Object[] { seqs,
1909 viewport.getAlignment().getDataset(), hiddenColumns };
1910 statusBar.setText(MessageManager.formatMessage(
1911 "label.copied_sequences_to_clipboard", new Object[] { Integer
1912 .valueOf(seqs.length).toString() }));
1922 protected void pasteNew_actionPerformed(ActionEvent e)
1934 protected void pasteThis_actionPerformed(ActionEvent e)
1940 * Paste contents of Jalview clipboard
1942 * @param newAlignment
1943 * true to paste to a new alignment, otherwise add to this.
1945 void paste(boolean newAlignment)
1947 boolean externalPaste = true;
1950 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1951 Transferable contents = c.getContents(this);
1953 if (contents == null)
1962 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1963 if (str.length() < 1)
1968 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
1970 } catch (OutOfMemoryError er)
1972 new OOMWarning("Out of memory pasting sequences!!", er);
1976 SequenceI[] sequences;
1977 boolean annotationAdded = false;
1978 AlignmentI alignment = null;
1980 if (Desktop.jalviewClipboard != null)
1982 // The clipboard was filled from within Jalview, we must use the
1984 // And dataset from the copied alignment
1985 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1986 // be doubly sure that we create *new* sequence objects.
1987 sequences = new SequenceI[newseq.length];
1988 for (int i = 0; i < newseq.length; i++)
1990 sequences[i] = new Sequence(newseq[i]);
1992 alignment = new Alignment(sequences);
1993 externalPaste = false;
1997 // parse the clipboard as an alignment.
1998 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2000 sequences = alignment.getSequencesArray();
2004 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2010 if (Desktop.jalviewClipboard != null)
2012 // dataset is inherited
2013 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2017 // new dataset is constructed
2018 alignment.setDataset(null);
2020 alwidth = alignment.getWidth() + 1;
2024 AlignmentI pastedal = alignment; // preserve pasted alignment object
2025 // Add pasted sequences and dataset into existing alignment.
2026 alignment = viewport.getAlignment();
2027 alwidth = alignment.getWidth() + 1;
2028 // decide if we need to import sequences from an existing dataset
2029 boolean importDs = Desktop.jalviewClipboard != null
2030 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2031 // importDs==true instructs us to copy over new dataset sequences from
2032 // an existing alignment
2033 Vector newDs = (importDs) ? new Vector() : null; // used to create
2034 // minimum dataset set
2036 for (int i = 0; i < sequences.length; i++)
2040 newDs.addElement(null);
2042 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2044 if (importDs && ds != null)
2046 if (!newDs.contains(ds))
2048 newDs.setElementAt(ds, i);
2049 ds = new Sequence(ds);
2050 // update with new dataset sequence
2051 sequences[i].setDatasetSequence(ds);
2055 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2060 // copy and derive new dataset sequence
2061 sequences[i] = sequences[i].deriveSequence();
2062 alignment.getDataset().addSequence(
2063 sequences[i].getDatasetSequence());
2064 // TODO: avoid creation of duplicate dataset sequences with a
2065 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2067 alignment.addSequence(sequences[i]); // merges dataset
2071 newDs.clear(); // tidy up
2073 if (alignment.getAlignmentAnnotation() != null)
2075 for (AlignmentAnnotation alan : alignment
2076 .getAlignmentAnnotation())
2078 if (alan.graphGroup > fgroup)
2080 fgroup = alan.graphGroup;
2084 if (pastedal.getAlignmentAnnotation() != null)
2086 // Add any annotation attached to alignment.
2087 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2088 for (int i = 0; i < alann.length; i++)
2090 annotationAdded = true;
2091 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2093 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2094 if (newann.graphGroup > -1)
2096 if (newGraphGroups.size() <= newann.graphGroup
2097 || newGraphGroups.get(newann.graphGroup) == null)
2099 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2101 newGraphGroups.add(q, null);
2103 newGraphGroups.set(newann.graphGroup, new Integer(
2106 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2110 newann.padAnnotation(alwidth);
2111 alignment.addAnnotation(newann);
2121 addHistoryItem(new EditCommand(
2122 MessageManager.getString("label.add_sequences"),
2123 Action.PASTE, sequences, 0, alignment.getWidth(), alignment));
2125 // Add any annotations attached to sequences
2126 for (int i = 0; i < sequences.length; i++)
2128 if (sequences[i].getAnnotation() != null)
2130 AlignmentAnnotation newann;
2131 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2133 annotationAdded = true;
2134 newann = sequences[i].getAnnotation()[a];
2135 newann.adjustForAlignment();
2136 newann.padAnnotation(alwidth);
2137 if (newann.graphGroup > -1)
2139 if (newann.graphGroup > -1)
2141 if (newGraphGroups.size() <= newann.graphGroup
2142 || newGraphGroups.get(newann.graphGroup) == null)
2144 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2146 newGraphGroups.add(q, null);
2148 newGraphGroups.set(newann.graphGroup, new Integer(
2151 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2155 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2160 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2167 // propagate alignment changed.
2168 viewport.setEndSeq(alignment.getHeight());
2169 if (annotationAdded)
2171 // Duplicate sequence annotation in all views.
2172 AlignmentI[] alview = this.getViewAlignments();
2173 for (int i = 0; i < sequences.length; i++)
2175 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2180 for (int avnum = 0; avnum < alview.length; avnum++)
2182 if (alview[avnum] != alignment)
2184 // duplicate in a view other than the one with input focus
2185 int avwidth = alview[avnum].getWidth() + 1;
2186 // this relies on sann being preserved after we
2187 // modify the sequence's annotation array for each duplication
2188 for (int a = 0; a < sann.length; a++)
2190 AlignmentAnnotation newann = new AlignmentAnnotation(
2192 sequences[i].addAlignmentAnnotation(newann);
2193 newann.padAnnotation(avwidth);
2194 alview[avnum].addAnnotation(newann); // annotation was
2195 // duplicated earlier
2196 // TODO JAL-1145 graphGroups are not updated for sequence
2197 // annotation added to several views. This may cause
2199 alview[avnum].setAnnotationIndex(newann, a);
2204 buildSortByAnnotationScoresMenu();
2206 viewport.firePropertyChange("alignment", null,
2207 alignment.getSequences());
2208 if (alignPanels != null)
2210 for (AlignmentPanel ap : alignPanels)
2212 ap.validateAnnotationDimensions(false);
2217 alignPanel.validateAnnotationDimensions(false);
2223 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2225 String newtitle = new String("Copied sequences");
2227 if (Desktop.jalviewClipboard != null
2228 && Desktop.jalviewClipboard[2] != null)
2230 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2231 for (int[] region : hc)
2233 af.viewport.hideColumns(region[0], region[1]);
2237 // >>>This is a fix for the moment, until a better solution is
2239 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2241 alignPanel.getSeqPanel().seqCanvas
2242 .getFeatureRenderer());
2244 // TODO: maintain provenance of an alignment, rather than just make the
2245 // title a concatenation of operations.
2248 if (title.startsWith("Copied sequences"))
2254 newtitle = newtitle.concat("- from " + title);
2259 newtitle = new String("Pasted sequences");
2262 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2267 } catch (Exception ex)
2269 ex.printStackTrace();
2270 System.out.println("Exception whilst pasting: " + ex);
2271 // could be anything being pasted in here
2277 protected void expand_newalign(ActionEvent e)
2281 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2282 .getAlignment(), -1);
2283 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2285 String newtitle = new String("Flanking alignment");
2287 if (Desktop.jalviewClipboard != null
2288 && Desktop.jalviewClipboard[2] != null)
2290 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2291 for (int region[] : hc)
2293 af.viewport.hideColumns(region[0], region[1]);
2297 // >>>This is a fix for the moment, until a better solution is
2299 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2301 alignPanel.getSeqPanel().seqCanvas
2302 .getFeatureRenderer());
2304 // TODO: maintain provenance of an alignment, rather than just make the
2305 // title a concatenation of operations.
2307 if (title.startsWith("Copied sequences"))
2313 newtitle = newtitle.concat("- from " + title);
2317 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2319 } catch (Exception ex)
2321 ex.printStackTrace();
2322 System.out.println("Exception whilst pasting: " + ex);
2323 // could be anything being pasted in here
2324 } catch (OutOfMemoryError oom)
2326 new OOMWarning("Viewing flanking region of alignment", oom);
2337 protected void cut_actionPerformed(ActionEvent e)
2339 copy_actionPerformed(null);
2340 delete_actionPerformed(null);
2350 protected void delete_actionPerformed(ActionEvent evt)
2353 SequenceGroup sg = viewport.getSelectionGroup();
2360 * If the cut affects all sequences, warn, remove highlighted columns
2362 if (sg.getSize() == viewport.getAlignment().getHeight())
2364 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2365 .getAlignment().getWidth()) ? true : false;
2366 if (isEntireAlignWidth)
2368 int confirm = JOptionPane.showConfirmDialog(this,
2369 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2370 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2371 JOptionPane.OK_CANCEL_OPTION);
2373 if (confirm == JOptionPane.CANCEL_OPTION
2374 || confirm == JOptionPane.CLOSED_OPTION)
2379 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2380 sg.getEndRes() + 1);
2382 SequenceI[] cut = sg.getSequences()
2383 .toArray(new SequenceI[sg.getSize()]);
2385 addHistoryItem(new EditCommand(
2386 MessageManager.getString("label.cut_sequences"), Action.CUT,
2387 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2388 viewport.getAlignment()));
2390 viewport.setSelectionGroup(null);
2391 viewport.sendSelection();
2392 viewport.getAlignment().deleteGroup(sg);
2394 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2396 if (viewport.getAlignment().getHeight() < 1)
2400 this.setClosed(true);
2401 } catch (Exception ex)
2414 protected void deleteGroups_actionPerformed(ActionEvent e)
2416 if (avc.deleteGroups())
2418 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2419 alignPanel.updateAnnotation();
2420 alignPanel.paintAlignment(true);
2431 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2433 SequenceGroup sg = new SequenceGroup();
2435 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2437 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2440 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2441 viewport.setSelectionGroup(sg);
2442 viewport.sendSelection();
2443 // JAL-2034 - should delegate to
2444 // alignPanel to decide if overview needs
2446 alignPanel.paintAlignment(false);
2447 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2457 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2459 if (viewport.cursorMode)
2461 alignPanel.getSeqPanel().keyboardNo1 = null;
2462 alignPanel.getSeqPanel().keyboardNo2 = null;
2464 viewport.setSelectionGroup(null);
2465 viewport.getColumnSelection().clear();
2466 viewport.setSelectionGroup(null);
2467 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2468 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2469 // JAL-2034 - should delegate to
2470 // alignPanel to decide if overview needs
2472 alignPanel.paintAlignment(false);
2473 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2474 viewport.sendSelection();
2484 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2486 SequenceGroup sg = viewport.getSelectionGroup();
2490 selectAllSequenceMenuItem_actionPerformed(null);
2495 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2497 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2499 // JAL-2034 - should delegate to
2500 // alignPanel to decide if overview needs
2503 alignPanel.paintAlignment(true);
2504 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2505 viewport.sendSelection();
2509 public void invertColSel_actionPerformed(ActionEvent e)
2511 viewport.invertColumnSelection();
2512 alignPanel.paintAlignment(true);
2513 viewport.sendSelection();
2523 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2525 trimAlignment(true);
2535 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2537 trimAlignment(false);
2540 void trimAlignment(boolean trimLeft)
2542 ColumnSelection colSel = viewport.getColumnSelection();
2545 if (!colSel.isEmpty())
2549 column = colSel.getMin();
2553 column = colSel.getMax();
2557 if (viewport.getSelectionGroup() != null)
2559 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2560 viewport.getHiddenRepSequences());
2564 seqs = viewport.getAlignment().getSequencesArray();
2567 TrimRegionCommand trimRegion;
2570 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2571 column, viewport.getAlignment());
2572 viewport.setStartRes(0);
2576 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2577 column, viewport.getAlignment());
2580 statusBar.setText(MessageManager.formatMessage(
2581 "label.removed_columns",
2582 new String[] { Integer.valueOf(trimRegion.getSize())
2585 addHistoryItem(trimRegion);
2587 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2589 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2590 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2592 viewport.getAlignment().deleteGroup(sg);
2596 viewport.firePropertyChange("alignment", null, viewport
2597 .getAlignment().getSequences());
2608 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2610 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2613 if (viewport.getSelectionGroup() != null)
2615 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2616 viewport.getHiddenRepSequences());
2617 start = viewport.getSelectionGroup().getStartRes();
2618 end = viewport.getSelectionGroup().getEndRes();
2622 seqs = viewport.getAlignment().getSequencesArray();
2625 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2626 "Remove Gapped Columns", seqs, start, end,
2627 viewport.getAlignment());
2629 addHistoryItem(removeGapCols);
2631 statusBar.setText(MessageManager.formatMessage(
2632 "label.removed_empty_columns",
2633 new Object[] { Integer.valueOf(removeGapCols.getSize())
2636 // This is to maintain viewport position on first residue
2637 // of first sequence
2638 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2639 int startRes = seq.findPosition(viewport.startRes);
2640 // ShiftList shifts;
2641 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2642 // edit.alColumnChanges=shifts.getInverse();
2643 // if (viewport.hasHiddenColumns)
2644 // viewport.getColumnSelection().compensateForEdits(shifts);
2645 viewport.setStartRes(seq.findIndex(startRes) - 1);
2646 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2658 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2660 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2663 if (viewport.getSelectionGroup() != null)
2665 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2666 viewport.getHiddenRepSequences());
2667 start = viewport.getSelectionGroup().getStartRes();
2668 end = viewport.getSelectionGroup().getEndRes();
2672 seqs = viewport.getAlignment().getSequencesArray();
2675 // This is to maintain viewport position on first residue
2676 // of first sequence
2677 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2678 int startRes = seq.findPosition(viewport.startRes);
2680 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2681 viewport.getAlignment()));
2683 viewport.setStartRes(seq.findIndex(startRes) - 1);
2685 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2697 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2699 viewport.setPadGaps(padGapsMenuitem.isSelected());
2700 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2711 public void findMenuItem_actionPerformed(ActionEvent e)
2717 * Create a new view of the current alignment.
2720 public void newView_actionPerformed(ActionEvent e)
2722 newView(null, true);
2726 * Creates and shows a new view of the current alignment.
2729 * title of newly created view; if null, one will be generated
2730 * @param copyAnnotation
2731 * if true then duplicate all annnotation, groups and settings
2732 * @return new alignment panel, already displayed.
2734 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2737 * Create a new AlignmentPanel (with its own, new Viewport)
2739 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2741 if (!copyAnnotation)
2744 * remove all groups and annotation except for the automatic stuff
2746 newap.av.getAlignment().deleteAllGroups();
2747 newap.av.getAlignment().deleteAllAnnotations(false);
2750 newap.av.setGatherViewsHere(false);
2752 if (viewport.viewName == null)
2754 viewport.viewName = MessageManager
2755 .getString("label.view_name_original");
2759 * Views share the same edits undo and redo stacks
2761 newap.av.setHistoryList(viewport.getHistoryList());
2762 newap.av.setRedoList(viewport.getRedoList());
2765 * Views share the same mappings; need to deregister any new mappings
2766 * created by copyAlignPanel, and register the new reference to the shared
2769 newap.av.replaceMappings(viewport.getAlignment());
2771 newap.av.viewName = getNewViewName(viewTitle);
2773 addAlignmentPanel(newap, true);
2774 newap.alignmentChanged();
2776 if (alignPanels.size() == 2)
2778 viewport.setGatherViewsHere(true);
2780 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2785 * Make a new name for the view, ensuring it is unique within the current
2786 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2787 * these now use viewId. Unique view names are still desirable for usability.)
2792 protected String getNewViewName(String viewTitle)
2794 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2795 boolean addFirstIndex = false;
2796 if (viewTitle == null || viewTitle.trim().length() == 0)
2798 viewTitle = MessageManager.getString("action.view");
2799 addFirstIndex = true;
2803 index = 1;// we count from 1 if given a specific name
2805 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2807 List<Component> comps = PaintRefresher.components.get(viewport
2808 .getSequenceSetId());
2810 List<String> existingNames = getExistingViewNames(comps);
2812 while (existingNames.contains(newViewName))
2814 newViewName = viewTitle + " " + (++index);
2820 * Returns a list of distinct view names found in the given list of
2821 * components. View names are held on the viewport of an AlignmentPanel.
2826 protected List<String> getExistingViewNames(List<Component> comps)
2828 List<String> existingNames = new ArrayList<String>();
2829 for (Component comp : comps)
2831 if (comp instanceof AlignmentPanel)
2833 AlignmentPanel ap = (AlignmentPanel) comp;
2834 if (!existingNames.contains(ap.av.viewName))
2836 existingNames.add(ap.av.viewName);
2840 return existingNames;
2844 * Explode tabbed views into separate windows.
2847 public void expandViews_actionPerformed(ActionEvent e)
2849 Desktop.explodeViews(this);
2853 * Gather views in separate windows back into a tabbed presentation.
2856 public void gatherViews_actionPerformed(ActionEvent e)
2858 Desktop.instance.gatherViews(this);
2868 public void font_actionPerformed(ActionEvent e)
2870 new FontChooser(alignPanel);
2880 protected void seqLimit_actionPerformed(ActionEvent e)
2882 viewport.setShowJVSuffix(seqLimits.isSelected());
2884 alignPanel.getIdPanel().getIdCanvas()
2885 .setPreferredSize(alignPanel.calculateIdWidth());
2886 alignPanel.paintAlignment(true);
2890 public void idRightAlign_actionPerformed(ActionEvent e)
2892 viewport.setRightAlignIds(idRightAlign.isSelected());
2893 alignPanel.paintAlignment(true);
2897 public void centreColumnLabels_actionPerformed(ActionEvent e)
2899 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2900 alignPanel.paintAlignment(true);
2906 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2909 protected void followHighlight_actionPerformed()
2912 * Set the 'follow' flag on the Viewport (and scroll to position if now
2915 final boolean state = this.followHighlightMenuItem.getState();
2916 viewport.setFollowHighlight(state);
2919 alignPanel.scrollToPosition(
2920 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2931 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2933 viewport.setColourText(colourTextMenuItem.isSelected());
2934 alignPanel.paintAlignment(true);
2944 public void wrapMenuItem_actionPerformed(ActionEvent e)
2946 scaleAbove.setVisible(wrapMenuItem.isSelected());
2947 scaleLeft.setVisible(wrapMenuItem.isSelected());
2948 scaleRight.setVisible(wrapMenuItem.isSelected());
2949 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2950 alignPanel.updateLayout();
2954 public void showAllSeqs_actionPerformed(ActionEvent e)
2956 viewport.showAllHiddenSeqs();
2960 public void showAllColumns_actionPerformed(ActionEvent e)
2962 viewport.showAllHiddenColumns();
2964 viewport.sendSelection();
2968 public void hideSelSequences_actionPerformed(ActionEvent e)
2970 viewport.hideAllSelectedSeqs();
2971 // alignPanel.paintAlignment(true);
2975 * called by key handler and the hide all/show all menu items
2980 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2983 boolean hide = false;
2984 SequenceGroup sg = viewport.getSelectionGroup();
2985 if (!toggleSeqs && !toggleCols)
2987 // Hide everything by the current selection - this is a hack - we do the
2988 // invert and then hide
2989 // first check that there will be visible columns after the invert.
2990 if ((viewport.getColumnSelection() != null
2991 && viewport.getColumnSelection().getSelected() != null && viewport
2992 .getColumnSelection().getSelected().size() > 0)
2993 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2996 // now invert the sequence set, if required - empty selection implies
2997 // that no hiding is required.
3000 invertSequenceMenuItem_actionPerformed(null);
3001 sg = viewport.getSelectionGroup();
3005 viewport.expandColSelection(sg, true);
3006 // finally invert the column selection and get the new sequence
3008 invertColSel_actionPerformed(null);
3015 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3017 hideSelSequences_actionPerformed(null);
3020 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3023 showAllSeqs_actionPerformed(null);
3029 if (viewport.getColumnSelection().getSelected().size() > 0)
3031 hideSelColumns_actionPerformed(null);
3034 viewport.setSelectionGroup(sg);
3039 showAllColumns_actionPerformed(null);
3048 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3049 * event.ActionEvent)
3052 public void hideAllButSelection_actionPerformed(ActionEvent e)
3054 toggleHiddenRegions(false, false);
3055 viewport.sendSelection();
3062 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3066 public void hideAllSelection_actionPerformed(ActionEvent e)
3068 SequenceGroup sg = viewport.getSelectionGroup();
3069 viewport.expandColSelection(sg, false);
3070 viewport.hideAllSelectedSeqs();
3071 viewport.hideSelectedColumns();
3072 alignPanel.paintAlignment(true);
3073 viewport.sendSelection();
3080 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3084 public void showAllhidden_actionPerformed(ActionEvent e)
3086 viewport.showAllHiddenColumns();
3087 viewport.showAllHiddenSeqs();
3088 alignPanel.paintAlignment(true);
3089 viewport.sendSelection();
3093 public void hideSelColumns_actionPerformed(ActionEvent e)
3095 viewport.hideSelectedColumns();
3096 alignPanel.paintAlignment(true);
3097 viewport.sendSelection();
3101 public void hiddenMarkers_actionPerformed(ActionEvent e)
3103 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3114 protected void scaleAbove_actionPerformed(ActionEvent e)
3116 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3117 alignPanel.paintAlignment(true);
3127 protected void scaleLeft_actionPerformed(ActionEvent e)
3129 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3130 alignPanel.paintAlignment(true);
3140 protected void scaleRight_actionPerformed(ActionEvent e)
3142 viewport.setScaleRightWrapped(scaleRight.isSelected());
3143 alignPanel.paintAlignment(true);
3153 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3155 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3156 alignPanel.paintAlignment(true);
3166 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3168 viewport.setShowText(viewTextMenuItem.isSelected());
3169 alignPanel.paintAlignment(true);
3179 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3181 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3182 alignPanel.paintAlignment(true);
3185 public FeatureSettings featureSettings;
3188 public FeatureSettingsControllerI getFeatureSettingsUI()
3190 return featureSettings;
3194 public void featureSettings_actionPerformed(ActionEvent e)
3196 if (featureSettings != null)
3198 featureSettings.close();
3199 featureSettings = null;
3201 if (!showSeqFeatures.isSelected())
3203 // make sure features are actually displayed
3204 showSeqFeatures.setSelected(true);
3205 showSeqFeatures_actionPerformed(null);
3207 featureSettings = new FeatureSettings(this);
3211 * Set or clear 'Show Sequence Features'
3217 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3219 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3220 alignPanel.paintAlignment(true);
3221 if (alignPanel.getOverviewPanel() != null)
3223 alignPanel.getOverviewPanel().updateOverviewImage();
3228 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3229 * the annotations panel as a whole.
3231 * The options to show/hide all annotations should be enabled when the panel
3232 * is shown, and disabled when the panel is hidden.
3237 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3239 final boolean setVisible = annotationPanelMenuItem.isSelected();
3240 viewport.setShowAnnotation(setVisible);
3241 this.showAllSeqAnnotations.setEnabled(setVisible);
3242 this.hideAllSeqAnnotations.setEnabled(setVisible);
3243 this.showAllAlAnnotations.setEnabled(setVisible);
3244 this.hideAllAlAnnotations.setEnabled(setVisible);
3245 alignPanel.updateLayout();
3249 public void alignmentProperties()
3251 JEditorPane editPane = new JEditorPane("text/html", "");
3252 editPane.setEditable(false);
3253 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3255 editPane.setText(MessageManager.formatMessage("label.html_content",
3256 new Object[] { contents.toString() }));
3257 JInternalFrame frame = new JInternalFrame();
3258 frame.getContentPane().add(new JScrollPane(editPane));
3260 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3261 "label.alignment_properties", new Object[] { getTitle() }),
3272 public void overviewMenuItem_actionPerformed(ActionEvent e)
3274 if (alignPanel.overviewPanel != null)
3279 JInternalFrame frame = new JInternalFrame();
3280 OverviewPanel overview = new OverviewPanel(alignPanel);
3281 frame.setContentPane(overview);
3282 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3283 "label.overview_params", new Object[] { this.getTitle() }),
3284 frame.getWidth(), frame.getHeight());
3286 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3287 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3290 public void internalFrameClosed(
3291 javax.swing.event.InternalFrameEvent evt)
3293 alignPanel.setOverviewPanel(null);
3297 alignPanel.setOverviewPanel(overview);
3301 public void textColour_actionPerformed(ActionEvent e)
3303 new TextColourChooser().chooseColour(alignPanel, null);
3313 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3325 public void clustalColour_actionPerformed(ActionEvent e)
3327 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3328 viewport.getHiddenRepSequences()));
3338 public void zappoColour_actionPerformed(ActionEvent e)
3340 changeColour(new ZappoColourScheme());
3350 public void taylorColour_actionPerformed(ActionEvent e)
3352 changeColour(new TaylorColourScheme());
3362 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3364 changeColour(new HydrophobicColourScheme());
3374 public void helixColour_actionPerformed(ActionEvent e)
3376 changeColour(new HelixColourScheme());
3386 public void strandColour_actionPerformed(ActionEvent e)
3388 changeColour(new StrandColourScheme());
3398 public void turnColour_actionPerformed(ActionEvent e)
3400 changeColour(new TurnColourScheme());
3410 public void buriedColour_actionPerformed(ActionEvent e)
3412 changeColour(new BuriedColourScheme());
3422 public void nucleotideColour_actionPerformed(ActionEvent e)
3424 changeColour(new NucleotideColourScheme());
3428 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3430 changeColour(new PurinePyrimidineColourScheme());
3434 * public void covariationColour_actionPerformed(ActionEvent e) {
3436 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3440 public void annotationColour_actionPerformed(ActionEvent e)
3442 new AnnotationColourChooser(viewport, alignPanel);
3446 public void annotationColumn_actionPerformed(ActionEvent e)
3448 new AnnotationColumnChooser(viewport, alignPanel);
3452 public void rnahelicesColour_actionPerformed(ActionEvent e)
3454 new RNAHelicesColourChooser(viewport, alignPanel);
3464 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3466 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3476 public void changeColour(ColourSchemeI cs)
3478 // TODO: pull up to controller method
3482 // Make sure viewport is up to date w.r.t. any sliders
3483 if (viewport.getAbovePIDThreshold())
3485 int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3487 viewport.setThreshold(threshold);
3490 if (viewport.getConservationSelected())
3492 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3495 if (cs instanceof TCoffeeColourScheme)
3497 tcoffeeColour.setEnabled(true);
3498 tcoffeeColour.setSelected(true);
3502 viewport.setGlobalColourScheme(cs);
3504 alignPanel.paintAlignment(true);
3514 protected void modifyPID_actionPerformed(ActionEvent e)
3516 if (viewport.getAbovePIDThreshold()
3517 && viewport.getGlobalColourScheme() != null)
3519 SliderPanel.setPIDSliderSource(alignPanel,
3520 viewport.getGlobalColourScheme(), "Background");
3521 SliderPanel.showPIDSlider();
3532 protected void modifyConservation_actionPerformed(ActionEvent e)
3534 if (viewport.getConservationSelected()
3535 && viewport.getGlobalColourScheme() != null)
3537 SliderPanel.setConservationSlider(alignPanel,
3538 viewport.getGlobalColourScheme(), "Background");
3539 SliderPanel.showConservationSlider();
3550 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3552 viewport.setConservationSelected(conservationMenuItem.isSelected());
3554 viewport.setAbovePIDThreshold(false);
3555 abovePIDThreshold.setSelected(false);
3557 changeColour(viewport.getGlobalColourScheme());
3559 modifyConservation_actionPerformed(null);
3569 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3571 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3573 conservationMenuItem.setSelected(false);
3574 viewport.setConservationSelected(false);
3576 changeColour(viewport.getGlobalColourScheme());
3578 modifyPID_actionPerformed(null);
3588 public void userDefinedColour_actionPerformed(ActionEvent e)
3590 if (e.getActionCommand().equals(
3591 MessageManager.getString("action.user_defined")))
3593 new UserDefinedColours(alignPanel, null);
3597 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3598 .getUserColourSchemes().get(e.getActionCommand());
3604 public void updateUserColourMenu()
3607 Component[] menuItems = colourMenu.getMenuComponents();
3608 int iSize = menuItems.length;
3609 for (int i = 0; i < iSize; i++)
3611 if (menuItems[i].getName() != null
3612 && menuItems[i].getName().equals("USER_DEFINED"))
3614 colourMenu.remove(menuItems[i]);
3618 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3620 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3621 .getUserColourSchemes().keys();
3623 while (userColours.hasMoreElements())
3625 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3626 userColours.nextElement().toString());
3627 radioItem.setName("USER_DEFINED");
3628 radioItem.addMouseListener(new MouseAdapter()
3631 public void mousePressed(MouseEvent evt)
3633 if (evt.isPopupTrigger())
3635 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3637 int option = JOptionPane.showInternalConfirmDialog(
3638 jalview.gui.Desktop.desktop,
3640 .getString("label.remove_from_default_list"),
3642 .getString("label.remove_user_defined_colour"),
3643 JOptionPane.YES_NO_OPTION);
3644 if (option == JOptionPane.YES_OPTION)
3646 jalview.gui.UserDefinedColours
3647 .removeColourFromDefaults(radioItem.getText());
3648 colourMenu.remove(radioItem);
3652 radioItem.addActionListener(new ActionListener()
3655 public void actionPerformed(ActionEvent evt)
3657 userDefinedColour_actionPerformed(evt);
3664 radioItem.addActionListener(new ActionListener()
3667 public void actionPerformed(ActionEvent evt)
3669 userDefinedColour_actionPerformed(evt);
3673 colourMenu.insert(radioItem, 15);
3674 colours.add(radioItem);
3686 public void PIDColour_actionPerformed(ActionEvent e)
3688 changeColour(new PIDColourScheme());
3698 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3700 changeColour(new Blosum62ColourScheme());
3710 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3712 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3713 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3714 .getAlignment().getSequenceAt(0), null);
3715 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3716 viewport.getAlignment()));
3717 alignPanel.paintAlignment(true);
3727 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3729 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3730 AlignmentSorter.sortByID(viewport.getAlignment());
3731 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3732 viewport.getAlignment()));
3733 alignPanel.paintAlignment(true);
3743 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3745 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3746 AlignmentSorter.sortByLength(viewport.getAlignment());
3747 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3748 viewport.getAlignment()));
3749 alignPanel.paintAlignment(true);
3759 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3761 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3762 AlignmentSorter.sortByGroup(viewport.getAlignment());
3763 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3764 viewport.getAlignment()));
3766 alignPanel.paintAlignment(true);
3776 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3778 new RedundancyPanel(alignPanel, this);
3788 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3790 if ((viewport.getSelectionGroup() == null)
3791 || (viewport.getSelectionGroup().getSize() < 2))
3793 JOptionPane.showInternalMessageDialog(this, MessageManager
3794 .getString("label.you_must_select_least_two_sequences"),
3795 MessageManager.getString("label.invalid_selection"),
3796 JOptionPane.WARNING_MESSAGE);
3800 JInternalFrame frame = new JInternalFrame();
3801 frame.setContentPane(new PairwiseAlignPanel(viewport));
3802 Desktop.addInternalFrame(frame,
3803 MessageManager.getString("action.pairwise_alignment"), 600,
3815 public void PCAMenuItem_actionPerformed(ActionEvent e)
3817 if (((viewport.getSelectionGroup() != null)
3818 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3819 .getSelectionGroup().getSize() > 0))
3820 || (viewport.getAlignment().getHeight() < 4))
3823 .showInternalMessageDialog(
3826 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3828 .getString("label.sequence_selection_insufficient"),
3829 JOptionPane.WARNING_MESSAGE);
3834 new PCAPanel(alignPanel);
3838 public void autoCalculate_actionPerformed(ActionEvent e)
3840 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3841 if (viewport.autoCalculateConsensus)
3843 viewport.firePropertyChange("alignment", null, viewport
3844 .getAlignment().getSequences());
3849 public void sortByTreeOption_actionPerformed(ActionEvent e)
3851 viewport.sortByTree = sortByTree.isSelected();
3855 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3857 viewport.followSelection = listenToViewSelections.isSelected();
3867 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3869 newTreePanel("AV", "PID", "Average distance tree using PID");
3879 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3881 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3891 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3893 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3903 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3905 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3918 void newTreePanel(String type, String pwType, String title)
3922 if (viewport.getSelectionGroup() != null
3923 && viewport.getSelectionGroup().getSize() > 0)
3925 if (viewport.getSelectionGroup().getSize() < 3)
3931 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3933 .getString("label.not_enough_sequences"),
3934 JOptionPane.WARNING_MESSAGE);
3938 SequenceGroup sg = viewport.getSelectionGroup();
3940 /* Decide if the selection is a column region */
3941 for (SequenceI _s : sg.getSequences())
3943 if (_s.getLength() < sg.getEndRes())
3949 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3951 .getString("label.sequences_selection_not_aligned"),
3952 JOptionPane.WARNING_MESSAGE);
3958 title = title + " on region";
3959 tp = new TreePanel(alignPanel, type, pwType);
3963 // are the visible sequences aligned?
3964 if (!viewport.getAlignment().isAligned(false))
3970 .getString("label.sequences_must_be_aligned_before_creating_tree"),
3972 .getString("label.sequences_not_aligned"),
3973 JOptionPane.WARNING_MESSAGE);
3978 if (viewport.getAlignment().getHeight() < 2)
3983 tp = new TreePanel(alignPanel, type, pwType);
3988 if (viewport.viewName != null)
3990 title += viewport.viewName + " of ";
3993 title += this.title;
3995 Desktop.addInternalFrame(tp, title, 600, 500);
4006 public void addSortByOrderMenuItem(String title,
4007 final AlignmentOrder order)
4009 final JMenuItem item = new JMenuItem(MessageManager.formatMessage(
4010 "action.by_title_param", new Object[] { title }));
4012 item.addActionListener(new java.awt.event.ActionListener()
4015 public void actionPerformed(ActionEvent e)
4017 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4019 // TODO: JBPNote - have to map order entries to curent SequenceI
4021 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4023 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4026 alignPanel.paintAlignment(true);
4032 * Add a new sort by annotation score menu item
4035 * the menu to add the option to
4037 * the label used to retrieve scores for each sequence on the
4040 public void addSortByAnnotScoreMenuItem(JMenu sort,
4041 final String scoreLabel)
4043 final JMenuItem item = new JMenuItem(scoreLabel);
4045 item.addActionListener(new java.awt.event.ActionListener()
4048 public void actionPerformed(ActionEvent e)
4050 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4051 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4052 viewport.getAlignment());// ,viewport.getSelectionGroup());
4053 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4054 viewport.getAlignment()));
4055 alignPanel.paintAlignment(true);
4061 * last hash for alignment's annotation array - used to minimise cost of
4064 protected int _annotationScoreVectorHash;
4067 * search the alignment and rebuild the sort by annotation score submenu the
4068 * last alignment annotation vector hash is stored to minimize cost of
4069 * rebuilding in subsequence calls.
4073 public void buildSortByAnnotationScoresMenu()
4075 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4080 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4082 sortByAnnotScore.removeAll();
4083 // almost certainly a quicker way to do this - but we keep it simple
4084 Hashtable scoreSorts = new Hashtable();
4085 AlignmentAnnotation aann[];
4086 for (SequenceI sqa : viewport.getAlignment().getSequences())
4088 aann = sqa.getAnnotation();
4089 for (int i = 0; aann != null && i < aann.length; i++)
4091 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4093 scoreSorts.put(aann[i].label, aann[i].label);
4097 Enumeration labels = scoreSorts.keys();
4098 while (labels.hasMoreElements())
4100 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4101 (String) labels.nextElement());
4103 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4106 _annotationScoreVectorHash = viewport.getAlignment()
4107 .getAlignmentAnnotation().hashCode();
4112 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4113 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4114 * call. Listeners are added to remove the menu item when the treePanel is
4115 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4119 * Displayed tree window.
4121 * SortBy menu item title.
4124 public void buildTreeMenu()
4126 calculateTree.removeAll();
4127 // build the calculate menu
4129 for (final String type : new String[] { "NJ", "AV" })
4131 String treecalcnm = MessageManager.getString("label.tree_calc_"
4132 + type.toLowerCase());
4133 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4135 JMenuItem tm = new JMenuItem();
4136 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4137 if (sm.isDNA() == viewport.getAlignment().isNucleotide()
4138 || sm.isProtein() == !viewport.getAlignment()
4141 String smn = MessageManager.getStringOrReturn(
4142 "label.score_model_", sm.getName());
4143 final String title = MessageManager.formatMessage(
4144 "label.treecalc_title", treecalcnm, smn);
4145 tm.setText(title);//
4146 tm.addActionListener(new java.awt.event.ActionListener()
4149 public void actionPerformed(ActionEvent e)
4151 newTreePanel(type, pwtype, title);
4154 calculateTree.add(tm);
4159 sortByTreeMenu.removeAll();
4161 List<Component> comps = PaintRefresher.components.get(viewport
4162 .getSequenceSetId());
4163 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4164 for (Component comp : comps)
4166 if (comp instanceof TreePanel)
4168 treePanels.add((TreePanel) comp);
4172 if (treePanels.size() < 1)
4174 sortByTreeMenu.setVisible(false);
4178 sortByTreeMenu.setVisible(true);
4180 for (final TreePanel tp : treePanels)
4182 final JMenuItem item = new JMenuItem(tp.getTitle());
4183 item.addActionListener(new java.awt.event.ActionListener()
4186 public void actionPerformed(ActionEvent e)
4188 tp.sortByTree_actionPerformed();
4189 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4194 sortByTreeMenu.add(item);
4198 public boolean sortBy(AlignmentOrder alorder, String undoname)
4200 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4201 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4202 if (undoname != null)
4204 addHistoryItem(new OrderCommand(undoname, oldOrder,
4205 viewport.getAlignment()));
4207 alignPanel.paintAlignment(true);
4212 * Work out whether the whole set of sequences or just the selected set will
4213 * be submitted for multiple alignment.
4216 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4218 // Now, check we have enough sequences
4219 AlignmentView msa = null;
4221 if ((viewport.getSelectionGroup() != null)
4222 && (viewport.getSelectionGroup().getSize() > 1))
4224 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4225 // some common interface!
4227 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4228 * SequenceI[sz = seqs.getSize(false)];
4230 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4231 * seqs.getSequenceAt(i); }
4233 msa = viewport.getAlignmentView(true);
4235 else if (viewport.getSelectionGroup() != null
4236 && viewport.getSelectionGroup().getSize() == 1)
4238 int option = JOptionPane.showConfirmDialog(this,
4239 MessageManager.getString("warn.oneseq_msainput_selection"),
4240 MessageManager.getString("label.invalid_selection"),
4241 JOptionPane.OK_CANCEL_OPTION);
4242 if (option == JOptionPane.OK_OPTION)
4244 msa = viewport.getAlignmentView(false);
4249 msa = viewport.getAlignmentView(false);
4255 * Decides what is submitted to a secondary structure prediction service: the
4256 * first sequence in the alignment, or in the current selection, or, if the
4257 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4258 * region or the whole alignment. (where the first sequence in the set is the
4259 * one that the prediction will be for).
4261 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4263 AlignmentView seqs = null;
4265 if ((viewport.getSelectionGroup() != null)
4266 && (viewport.getSelectionGroup().getSize() > 0))
4268 seqs = viewport.getAlignmentView(true);
4272 seqs = viewport.getAlignmentView(false);
4274 // limit sequences - JBPNote in future - could spawn multiple prediction
4276 // TODO: viewport.getAlignment().isAligned is a global state - the local
4277 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4278 if (!viewport.getAlignment().isAligned(false))
4280 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4281 // TODO: if seqs.getSequences().length>1 then should really have warned
4295 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4297 // Pick the tree file
4298 JalviewFileChooser chooser = new JalviewFileChooser(
4299 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4300 chooser.setFileView(new JalviewFileView());
4301 chooser.setDialogTitle(MessageManager
4302 .getString("label.select_newick_like_tree_file"));
4303 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4305 int value = chooser.showOpenDialog(null);
4307 if (value == JalviewFileChooser.APPROVE_OPTION)
4309 String choice = chooser.getSelectedFile().getPath();
4310 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4311 jalview.io.NewickFile fin = null;
4314 fin = new NewickFile(choice, DataSourceType.FILE);
4315 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4316 } catch (Exception ex)
4323 .getString("label.problem_reading_tree_file"),
4324 JOptionPane.WARNING_MESSAGE);
4325 ex.printStackTrace();
4327 if (fin != null && fin.hasWarningMessage())
4329 JOptionPane.showMessageDialog(Desktop.desktop, fin
4330 .getWarningMessage(), MessageManager
4331 .getString("label.possible_problem_with_tree_file"),
4332 JOptionPane.WARNING_MESSAGE);
4338 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4340 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4343 public TreePanel ShowNewickTree(NewickFile nf, String title)
4345 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4348 public TreePanel ShowNewickTree(NewickFile nf, String title,
4349 AlignmentView input)
4351 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4354 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4355 int h, int x, int y)
4357 return ShowNewickTree(nf, title, null, w, h, x, y);
4361 * Add a treeviewer for the tree extracted from a newick file object to the
4362 * current alignment view
4369 * Associated alignment input data (or null)
4378 * @return TreePanel handle
4380 public TreePanel ShowNewickTree(NewickFile nf, String title,
4381 AlignmentView input, int w, int h, int x, int y)
4383 TreePanel tp = null;
4389 if (nf.getTree() != null)
4391 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4397 tp.setLocation(x, y);
4400 Desktop.addInternalFrame(tp, title, w, h);
4402 } catch (Exception ex)
4404 ex.printStackTrace();
4410 private boolean buildingMenu = false;
4413 * Generates menu items and listener event actions for web service clients
4416 public void BuildWebServiceMenu()
4418 while (buildingMenu)
4422 System.err.println("Waiting for building menu to finish.");
4424 } catch (Exception e)
4428 final AlignFrame me = this;
4429 buildingMenu = true;
4430 new Thread(new Runnable()
4435 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4438 // System.err.println("Building ws menu again "
4439 // + Thread.currentThread());
4440 // TODO: add support for context dependent disabling of services based
4442 // alignment and current selection
4443 // TODO: add additional serviceHandle parameter to specify abstract
4445 // class independently of AbstractName
4446 // TODO: add in rediscovery GUI function to restart discoverer
4447 // TODO: group services by location as well as function and/or
4449 // object broker mechanism.
4450 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4451 final IProgressIndicator af = me;
4454 * do not i18n these strings - they are hard-coded in class
4455 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4456 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4458 final JMenu msawsmenu = new JMenu("Alignment");
4459 final JMenu secstrmenu = new JMenu(
4460 "Secondary Structure Prediction");
4461 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4462 final JMenu analymenu = new JMenu("Analysis");
4463 final JMenu dismenu = new JMenu("Protein Disorder");
4464 // JAL-940 - only show secondary structure prediction services from
4465 // the legacy server
4466 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4468 Discoverer.services != null && (Discoverer.services.size() > 0))
4470 // TODO: refactor to allow list of AbstractName/Handler bindings to
4472 // stored or retrieved from elsewhere
4473 // No MSAWS used any more:
4474 // Vector msaws = null; // (Vector)
4475 // Discoverer.services.get("MsaWS");
4476 Vector secstrpr = (Vector) Discoverer.services
4478 if (secstrpr != null)
4480 // Add any secondary structure prediction services
4481 for (int i = 0, j = secstrpr.size(); i < j; i++)
4483 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4485 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4486 .getServiceClient(sh);
4487 int p = secstrmenu.getItemCount();
4488 impl.attachWSMenuEntry(secstrmenu, me);
4489 int q = secstrmenu.getItemCount();
4490 for (int litm = p; litm < q; litm++)
4492 legacyItems.add(secstrmenu.getItem(litm));
4498 // Add all submenus in the order they should appear on the web
4500 wsmenu.add(msawsmenu);
4501 wsmenu.add(secstrmenu);
4502 wsmenu.add(dismenu);
4503 wsmenu.add(analymenu);
4504 // No search services yet
4505 // wsmenu.add(seqsrchmenu);
4507 javax.swing.SwingUtilities.invokeLater(new Runnable()
4514 webService.removeAll();
4515 // first, add discovered services onto the webservices menu
4516 if (wsmenu.size() > 0)
4518 for (int i = 0, j = wsmenu.size(); i < j; i++)
4520 webService.add(wsmenu.get(i));
4525 webService.add(me.webServiceNoServices);
4527 // TODO: move into separate menu builder class.
4528 boolean new_sspred = false;
4529 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4531 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4532 if (jws2servs != null)
4534 if (jws2servs.hasServices())
4536 jws2servs.attachWSMenuEntry(webService, me);
4537 for (Jws2Instance sv : jws2servs.getServices())
4539 if (sv.description.toLowerCase().contains("jpred"))
4541 for (JMenuItem jmi : legacyItems)
4543 jmi.setVisible(false);
4549 if (jws2servs.isRunning())
4551 JMenuItem tm = new JMenuItem(
4552 "Still discovering JABA Services");
4553 tm.setEnabled(false);
4558 build_urlServiceMenu(me.webService);
4559 build_fetchdbmenu(webService);
4560 for (JMenu item : wsmenu)
4562 if (item.getItemCount() == 0)
4564 item.setEnabled(false);
4568 item.setEnabled(true);
4571 } catch (Exception e)
4574 .debug("Exception during web service menu building process.",
4579 } catch (Exception e)
4582 buildingMenu = false;
4589 * construct any groupURL type service menu entries.
4593 private void build_urlServiceMenu(JMenu webService)
4595 // TODO: remove this code when 2.7 is released
4596 // DEBUG - alignmentView
4598 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4599 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4601 * @Override public void actionPerformed(ActionEvent e) {
4602 * jalview.datamodel.AlignmentView
4603 * .testSelectionViews(af.viewport.getAlignment(),
4604 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4606 * }); webService.add(testAlView);
4608 // TODO: refactor to RestClient discoverer and merge menu entries for
4609 // rest-style services with other types of analysis/calculation service
4610 // SHmmr test client - still being implemented.
4611 // DEBUG - alignmentView
4613 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4616 client.attachWSMenuEntry(
4617 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4623 * Searches the alignment sequences for xRefs and builds the Show
4624 * Cross-References menu (formerly called Show Products), with database
4625 * sources for which cross-references are found (protein sources for a
4626 * nucleotide alignment and vice versa)
4628 * @return true if Show Cross-references menu should be enabled
4630 public boolean canShowProducts()
4632 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4633 AlignmentI dataset = viewport.getAlignment().getDataset();
4634 boolean showp = false;
4637 showProducts.removeAll();
4638 final boolean dna = viewport.getAlignment().isNucleotide();
4639 List<String> ptypes = (seqs == null || seqs.length == 0) ? null
4640 : new CrossRef(seqs, dataset)
4641 .findXrefSourcesForSequences(dna);
4643 for (final String source : ptypes)
4646 final AlignFrame af = this;
4647 JMenuItem xtype = new JMenuItem(source);
4648 xtype.addActionListener(new ActionListener()
4651 public void actionPerformed(ActionEvent e)
4653 showProductsFor(af.viewport.getSequenceSelection(), dna, source);
4656 showProducts.add(xtype);
4658 showProducts.setVisible(showp);
4659 showProducts.setEnabled(showp);
4660 } catch (Exception e)
4663 .warn("canShowProducts threw an exception - please report to help@jalview.org",
4671 * Finds and displays cross-references for the selected sequences (protein
4672 * products for nucleotide sequences, dna coding sequences for peptides).
4675 * the sequences to show cross-references for
4677 * true if from a nucleotide alignment (so showing proteins)
4679 * the database to show cross-references for
4681 protected void showProductsFor(final SequenceI[] sel,
4682 final boolean _odna, final String source)
4684 Runnable foo = new Runnable()
4690 final long sttime = System.currentTimeMillis();
4691 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4692 "status.searching_for_sequences_from",
4693 new Object[] { source }), sttime);
4696 AlignmentI alignment = AlignFrame.this.getViewport()
4698 AlignmentI dataset = alignment.getDataset() == null ? alignment
4699 : alignment.getDataset();
4700 boolean dna = alignment.isNucleotide();
4704 .println("Conflict: showProducts for alignment originally "
4706 + (_odna ? "DNA" : "Protein")
4707 + " now searching for "
4708 + (dna ? "DNA" : "Protein") + " Context.");
4710 AlignmentI xrefs = new CrossRef(sel, dataset).findXrefSequences(
4717 * get display scheme (if any) to apply to features
4719 FeatureSettingsModelI featureColourScheme = new SequenceFetcher()
4720 .getFeatureColourScheme(source);
4722 AlignmentI xrefsAlignment = makeCrossReferencesAlignment(dataset,
4726 xrefsAlignment = AlignmentUtils.makeCdsAlignment(
4727 xrefsAlignment.getSequencesArray(), dataset, sel);
4728 xrefsAlignment.alignAs(alignment);
4732 * If we are opening a splitframe, make a copy of this alignment (sharing the same dataset
4733 * sequences). If we are DNA, drop introns and update mappings
4735 AlignmentI copyAlignment = null;
4737 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4739 boolean copyAlignmentIsAligned = false;
4742 copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset,
4743 xrefsAlignment.getSequencesArray());
4744 if (copyAlignment.getHeight() == 0)
4746 JOptionPane.showMessageDialog(AlignFrame.this,
4747 MessageManager.getString("label.cant_map_cds"),
4748 MessageManager.getString("label.operation_failed"),
4749 JOptionPane.OK_OPTION);
4750 System.err.println("Failed to make CDS alignment");
4754 * pending getting Embl transcripts to 'align',
4755 * we are only doing this for Ensembl
4757 // TODO proper criteria for 'can align as cdna'
4758 if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
4759 || AlignmentUtils.looksLikeEnsembl(alignment))
4761 copyAlignment.alignAs(alignment);
4762 copyAlignmentIsAligned = true;
4767 copyAlignment = AlignmentUtils.makeCopyAlignment(sel,
4768 xrefs.getSequencesArray(), dataset);
4770 copyAlignment.setGapCharacter(AlignFrame.this.viewport
4771 .getGapCharacter());
4773 StructureSelectionManager ssm = StructureSelectionManager
4774 .getStructureSelectionManager(Desktop.instance);
4777 * register any new mappings for sequence mouseover etc
4778 * (will not duplicate any previously registered mappings)
4780 ssm.registerMappings(dataset.getCodonFrames());
4782 if (copyAlignment.getHeight() <= 0)
4784 System.err.println("No Sequences generated for xRef type "
4789 * align protein to dna
4791 if (dna && copyAlignmentIsAligned)
4793 xrefsAlignment.alignAs(copyAlignment);
4798 * align cdna to protein - currently only if
4799 * fetching and aligning Ensembl transcripts!
4801 // TODO: generalise for other sources of locus/transcript/cds data
4802 if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source))
4804 copyAlignment.alignAs(xrefsAlignment);
4809 * build AlignFrame(s) according to available alignment data
4811 AlignFrame newFrame = new AlignFrame(xrefsAlignment,
4812 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4813 if (Cache.getDefault("HIDE_INTRONS", true))
4815 newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false);
4817 String newtitle = String.format("%s %s %s",
4818 dna ? MessageManager.getString("label.proteins")
4819 : MessageManager.getString("label.nucleotides"),
4820 MessageManager.getString("label.for"), getTitle());
4821 newFrame.setTitle(newtitle);
4823 if (copyAlignment == null)
4826 * split frame display is turned off in preferences file
4828 Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
4830 return; // via finally clause
4832 AlignFrame copyThis = new AlignFrame(copyAlignment,
4833 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4834 copyThis.setTitle(AlignFrame.this.getTitle());
4836 boolean showSequenceFeatures = viewport.isShowSequenceFeatures();
4837 newFrame.setShowSeqFeatures(showSequenceFeatures);
4838 copyThis.setShowSeqFeatures(showSequenceFeatures);
4839 FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas
4840 .getFeatureRenderer();
4843 * copy feature rendering settings to split frame
4845 newFrame.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
4846 .transferSettings(myFeatureStyling);
4847 copyThis.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
4848 .transferSettings(myFeatureStyling);
4851 * apply 'database source' feature configuration
4854 // TODO is this the feature colouring for the original
4855 // alignment or the fetched xrefs? either could be Ensembl
4856 newFrame.getViewport().applyFeaturesStyle(featureColourScheme);
4857 copyThis.getViewport().applyFeaturesStyle(featureColourScheme);
4859 SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame,
4860 dna ? newFrame : copyThis);
4861 newFrame.setVisible(true);
4862 copyThis.setVisible(true);
4863 String linkedTitle = MessageManager
4864 .getString("label.linked_view_title");
4865 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4867 } catch (OutOfMemoryError e)
4869 new OOMWarning("whilst fetching crossreferences", e);
4870 } catch (Throwable e)
4872 Cache.log.error("Error when finding crossreferences", e);
4875 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4876 "status.finished_searching_for_sequences_from",
4877 new Object[] { source }), sttime);
4882 * Makes an alignment containing the given sequences, and adds them to the
4883 * given dataset, which is also set as the dataset for the new alignment
4885 * TODO: refactor to DatasetI method
4891 protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,
4894 SequenceI[] sprods = new SequenceI[seqs.getHeight()];
4895 for (int s = 0; s < sprods.length; s++)
4897 sprods[s] = (seqs.getSequenceAt(s)).deriveSequence();
4898 if (dataset.getSequences() == null
4899 || !dataset.getSequences().contains(
4900 sprods[s].getDatasetSequence()))
4902 dataset.addSequence(sprods[s].getDatasetSequence());
4904 sprods[s].updatePDBIds();
4906 Alignment al = new Alignment(sprods);
4907 al.setDataset(dataset);
4912 Thread frunner = new Thread(foo);
4917 * Construct and display a new frame containing the translation of this
4918 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4921 public void showTranslation_actionPerformed(ActionEvent e)
4923 AlignmentI al = null;
4926 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4928 al = dna.translateCdna();
4929 } catch (Exception ex)
4931 jalview.bin.Cache.log.error(
4932 "Exception during translation. Please report this !", ex);
4933 final String msg = MessageManager
4934 .getString("label.error_when_translating_sequences_submit_bug_report");
4935 final String errorTitle = MessageManager
4936 .getString("label.implementation_error")
4937 + MessageManager.getString("label.translation_failed");
4938 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4939 JOptionPane.ERROR_MESSAGE);
4942 if (al == null || al.getHeight() == 0)
4944 final String msg = MessageManager
4945 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4946 final String errorTitle = MessageManager
4947 .getString("label.translation_failed");
4948 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4949 JOptionPane.WARNING_MESSAGE);
4953 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4954 af.setFileFormat(this.currentFileFormat);
4955 final String newTitle = MessageManager.formatMessage(
4956 "label.translation_of_params",
4957 new Object[] { this.getTitle() });
4958 af.setTitle(newTitle);
4959 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4961 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4962 viewport.openSplitFrame(af, new Alignment(seqs));
4966 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4973 * Set the file format
4977 public void setFileFormat(FileFormatI format)
4979 this.currentFileFormat = format;
4983 * Try to load a features file onto the alignment.
4986 * contents or path to retrieve file
4988 * access mode of file (see jalview.io.AlignFile)
4989 * @return true if features file was parsed correctly.
4991 public boolean parseFeaturesFile(String file, DataSourceType sourceType)
4993 return avc.parseFeaturesFile(file, sourceType,
4994 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4999 public void refreshFeatureUI(boolean enableIfNecessary)
5001 // note - currently this is only still here rather than in the controller
5002 // because of the featureSettings hard reference that is yet to be
5004 if (enableIfNecessary)
5006 viewport.setShowSequenceFeatures(true);
5007 showSeqFeatures.setSelected(true);
5013 public void dragEnter(DropTargetDragEvent evt)
5018 public void dragExit(DropTargetEvent evt)
5023 public void dragOver(DropTargetDragEvent evt)
5028 public void dropActionChanged(DropTargetDragEvent evt)
5033 public void drop(DropTargetDropEvent evt)
5035 Transferable t = evt.getTransferable();
5036 List<String> files = new ArrayList<String>();
5037 List<DataSourceType> protocols = new ArrayList<DataSourceType>();
5041 Desktop.transferFromDropTarget(files, protocols, evt, t);
5042 } catch (Exception e)
5044 e.printStackTrace();
5050 // check to see if any of these files have names matching sequences in
5052 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5053 .getAlignment().getSequencesArray());
5055 * Object[] { String,SequenceI}
5057 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5058 ArrayList<String> filesnotmatched = new ArrayList<String>();
5059 for (int i = 0; i < files.size(); i++)
5061 String file = files.get(i).toString();
5063 DataSourceType protocol = FormatAdapter.checkProtocol(file);
5064 if (protocol == DataSourceType.FILE)
5066 File fl = new File(file);
5067 pdbfn = fl.getName();
5069 else if (protocol == DataSourceType.URL)
5071 URL url = new URL(file);
5072 pdbfn = url.getFile();
5074 if (pdbfn.length() > 0)
5076 // attempt to find a match in the alignment
5077 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5078 int l = 0, c = pdbfn.indexOf(".");
5079 while (mtch == null && c != -1)
5084 } while ((c = pdbfn.indexOf(".", l)) > l);
5087 pdbfn = pdbfn.substring(0, l);
5089 mtch = idm.findAllIdMatches(pdbfn);
5093 FileFormatI type = null;
5096 type = new IdentifyFile().identify(file, protocol);
5097 } catch (Exception ex)
5103 if (type == FileFormat.PDB)
5105 filesmatched.add(new Object[] { file, protocol, mtch });
5110 // File wasn't named like one of the sequences or wasn't a PDB file.
5111 filesnotmatched.add(file);
5115 if (filesmatched.size() > 0)
5117 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5123 "label.automatically_associate_pdb_files_with_sequences_same_name",
5124 new Object[] { Integer
5130 .getString("label.automatically_associate_pdb_files_by_name"),
5131 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5134 for (Object[] fm : filesmatched)
5136 // try and associate
5137 // TODO: may want to set a standard ID naming formalism for
5138 // associating PDB files which have no IDs.
5139 for (SequenceI toassoc : (SequenceI[]) fm[2])
5141 PDBEntry pe = new AssociatePdbFileWithSeq()
5142 .associatePdbWithSeq((String) fm[0],
5143 (DataSourceType) fm[1], toassoc, false,
5147 System.err.println("Associated file : "
5148 + ((String) fm[0]) + " with "
5149 + toassoc.getDisplayId(true));
5153 alignPanel.paintAlignment(true);
5157 if (filesnotmatched.size() > 0)
5160 && (Cache.getDefault(
5161 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5167 "label.ignore_unmatched_dropped_files_info",
5168 new Object[] { Integer
5175 .getString("label.ignore_unmatched_dropped_files"),
5176 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5180 for (String fn : filesnotmatched)
5182 loadJalviewDataFile(fn, null, null, null);
5186 } catch (Exception ex)
5188 ex.printStackTrace();
5194 * Attempt to load a "dropped" file or URL string: First by testing whether
5195 * it's an Annotation file, then a JNet file, and finally a features file. If
5196 * all are false then the user may have dropped an alignment file onto this
5200 * either a filename or a URL string.
5202 public void loadJalviewDataFile(String file, DataSourceType sourceType,
5203 FileFormatI format, SequenceI assocSeq)
5207 if (sourceType == null)
5209 sourceType = FormatAdapter.checkProtocol(file);
5211 // if the file isn't identified, or not positively identified as some
5212 // other filetype (PFAM is default unidentified alignment file type) then
5213 // try to parse as annotation.
5214 boolean isAnnotation = (format == null || format == FileFormat.Pfam) ? new AnnotationFile()
5215 .annotateAlignmentView(viewport, file, sourceType) : false;
5219 // first see if its a T-COFFEE score file
5220 TCoffeeScoreFile tcf = null;
5223 tcf = new TCoffeeScoreFile(file, sourceType);
5226 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5228 tcoffeeColour.setEnabled(true);
5229 tcoffeeColour.setSelected(true);
5230 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5231 isAnnotation = true;
5233 .setText(MessageManager
5234 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5238 // some problem - if no warning its probable that the ID matching
5239 // process didn't work
5243 tcf.getWarningMessage() == null ? MessageManager
5244 .getString("label.check_file_matches_sequence_ids_alignment")
5245 : tcf.getWarningMessage(),
5247 .getString("label.problem_reading_tcoffee_score_file"),
5248 JOptionPane.WARNING_MESSAGE);
5255 } catch (Exception x)
5258 .debug("Exception when processing data source as T-COFFEE score file",
5264 // try to see if its a JNet 'concise' style annotation file *before*
5266 // try to parse it as a features file
5269 format = new IdentifyFile().identify(file, sourceType);
5271 if (format == FileFormat.Jnet)
5273 JPredFile predictions = new JPredFile(
5275 new JnetAnnotationMaker();
5276 JnetAnnotationMaker.add_annotation(predictions,
5277 viewport.getAlignment(), 0, false);
5278 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5279 viewport.getAlignment().setSeqrep(repseq);
5280 ColumnSelection cs = new ColumnSelection();
5281 cs.hideInsertionsFor(repseq);
5282 viewport.setColumnSelection(cs);
5283 isAnnotation = true;
5285 else if (IdentifyFile.FeaturesFile.equals(format))
5287 if (parseFeaturesFile(file, sourceType))
5289 alignPanel.paintAlignment(true);
5294 new FileLoader().LoadFile(viewport, file, sourceType, format);
5301 alignPanel.adjustAnnotationHeight();
5302 viewport.updateSequenceIdColours();
5303 buildSortByAnnotationScoresMenu();
5304 alignPanel.paintAlignment(true);
5306 } catch (Exception ex)
5308 ex.printStackTrace();
5309 } catch (OutOfMemoryError oom)
5314 } catch (Exception x)
5319 + (sourceType != null ? (sourceType == DataSourceType.PASTE ? "from clipboard."
5320 : "using " + sourceType + " from " + file)
5322 + (format != null ? "(parsing as '" + format
5323 + "' file)" : ""), oom, Desktop.desktop);
5328 * Method invoked by the ChangeListener on the tabbed pane, in other words
5329 * when a different tabbed pane is selected by the user or programmatically.
5332 public void tabSelectionChanged(int index)
5336 alignPanel = alignPanels.get(index);
5337 viewport = alignPanel.av;
5338 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5339 setMenusFromViewport(viewport);
5343 * If there is a frame linked to this one in a SplitPane, switch it to the
5344 * same view tab index. No infinite recursion of calls should happen, since
5345 * tabSelectionChanged() should not get invoked on setting the selected
5346 * index to an unchanged value. Guard against setting an invalid index
5347 * before the new view peer tab has been created.
5349 final AlignViewportI peer = viewport.getCodingComplement();
5352 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5353 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5355 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5361 * On right mouse click on view tab, prompt for and set new view name.
5364 public void tabbedPane_mousePressed(MouseEvent e)
5366 if (e.isPopupTrigger())
5368 String msg = MessageManager.getString("label.enter_view_name");
5369 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5370 JOptionPane.QUESTION_MESSAGE);
5374 viewport.viewName = reply;
5375 // TODO warn if reply is in getExistingViewNames()?
5376 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5381 public AlignViewport getCurrentView()
5387 * Open the dialog for regex description parsing.
5390 protected void extractScores_actionPerformed(ActionEvent e)
5392 ParseProperties pp = new jalview.analysis.ParseProperties(
5393 viewport.getAlignment());
5394 // TODO: verify regex and introduce GUI dialog for version 2.5
5395 // if (pp.getScoresFromDescription("col", "score column ",
5396 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5398 if (pp.getScoresFromDescription("description column",
5399 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5401 buildSortByAnnotationScoresMenu();
5409 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5413 protected void showDbRefs_actionPerformed(ActionEvent e)
5415 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5421 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5425 protected void showNpFeats_actionPerformed(ActionEvent e)
5427 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5431 * find the viewport amongst the tabs in this alignment frame and close that
5436 public boolean closeView(AlignViewportI av)
5440 this.closeMenuItem_actionPerformed(false);
5443 Component[] comp = tabbedPane.getComponents();
5444 for (int i = 0; comp != null && i < comp.length; i++)
5446 if (comp[i] instanceof AlignmentPanel)
5448 if (((AlignmentPanel) comp[i]).av == av)
5451 closeView((AlignmentPanel) comp[i]);
5459 protected void build_fetchdbmenu(JMenu webService)
5461 // Temporary hack - DBRef Fetcher always top level ws entry.
5462 // TODO We probably want to store a sequence database checklist in
5463 // preferences and have checkboxes.. rather than individual sources selected
5465 final JMenu rfetch = new JMenu(
5466 MessageManager.getString("action.fetch_db_references"));
5467 rfetch.setToolTipText(MessageManager
5468 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5469 webService.add(rfetch);
5471 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5472 MessageManager.getString("option.trim_retrieved_seqs"));
5473 trimrs.setToolTipText(MessageManager
5474 .getString("label.trim_retrieved_sequences"));
5475 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5476 trimrs.addActionListener(new ActionListener()
5479 public void actionPerformed(ActionEvent e)
5481 trimrs.setSelected(trimrs.isSelected());
5482 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5483 Boolean.valueOf(trimrs.isSelected()).toString());
5487 JMenuItem fetchr = new JMenuItem(
5488 MessageManager.getString("label.standard_databases"));
5489 fetchr.setToolTipText(MessageManager
5490 .getString("label.fetch_embl_uniprot"));
5491 fetchr.addActionListener(new ActionListener()
5495 public void actionPerformed(ActionEvent e)
5497 new Thread(new Runnable()
5502 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5503 .getAlignment().isNucleotide();
5504 DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av
5505 .getSequenceSelection(), alignPanel.alignFrame, null,
5506 alignPanel.alignFrame.featureSettings, isNucleotide);
5507 dbRefFetcher.addListener(new FetchFinishedListenerI()
5510 public void finished()
5512 AlignFrame.this.setMenusForViewport();
5515 dbRefFetcher.fetchDBRefs(false);
5523 final AlignFrame me = this;
5524 new Thread(new Runnable()
5529 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5530 .getSequenceFetcherSingleton(me);
5531 javax.swing.SwingUtilities.invokeLater(new Runnable()
5536 String[] dbclasses = sf.getOrderedSupportedSources();
5537 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5538 // jalview.util.QuickSort.sort(otherdb, otherdb);
5539 List<DbSourceProxy> otherdb;
5540 JMenu dfetch = new JMenu();
5541 JMenu ifetch = new JMenu();
5542 JMenuItem fetchr = null;
5543 int comp = 0, icomp = 0, mcomp = 15;
5544 String mname = null;
5546 for (String dbclass : dbclasses)
5548 otherdb = sf.getSourceProxy(dbclass);
5549 // add a single entry for this class, or submenu allowing 'fetch
5551 if (otherdb == null || otherdb.size() < 1)
5555 // List<DbSourceProxy> dbs=otherdb;
5556 // otherdb=new ArrayList<DbSourceProxy>();
5557 // for (DbSourceProxy db:dbs)
5559 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5563 mname = "From " + dbclass;
5565 if (otherdb.size() == 1)
5567 final DbSourceProxy[] dassource = otherdb
5568 .toArray(new DbSourceProxy[0]);
5569 DbSourceProxy src = otherdb.get(0);
5570 fetchr = new JMenuItem(src.getDbSource());
5571 fetchr.addActionListener(new ActionListener()
5575 public void actionPerformed(ActionEvent e)
5577 new Thread(new Runnable()
5583 boolean isNucleotide = alignPanel.alignFrame
5584 .getViewport().getAlignment()
5586 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5587 alignPanel.av.getSequenceSelection(),
5588 alignPanel.alignFrame, dassource,
5589 alignPanel.alignFrame.featureSettings,
5592 .addListener(new FetchFinishedListenerI()
5595 public void finished()
5597 AlignFrame.this.setMenusForViewport();
5600 dbRefFetcher.fetchDBRefs(false);
5606 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5607 MessageManager.formatMessage(
5608 "label.fetch_retrieve_from",
5609 new Object[] { src.getDbName() })));
5615 final DbSourceProxy[] dassource = otherdb
5616 .toArray(new DbSourceProxy[0]);
5618 DbSourceProxy src = otherdb.get(0);
5619 fetchr = new JMenuItem(MessageManager.formatMessage(
5620 "label.fetch_all_param",
5621 new Object[] { src.getDbSource() }));
5622 fetchr.addActionListener(new ActionListener()
5625 public void actionPerformed(ActionEvent e)
5627 new Thread(new Runnable()
5633 boolean isNucleotide = alignPanel.alignFrame
5634 .getViewport().getAlignment()
5636 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5637 alignPanel.av.getSequenceSelection(),
5638 alignPanel.alignFrame, dassource,
5639 alignPanel.alignFrame.featureSettings,
5642 .addListener(new FetchFinishedListenerI()
5645 public void finished()
5647 AlignFrame.this.setMenusForViewport();
5650 dbRefFetcher.fetchDBRefs(false);
5656 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5657 MessageManager.formatMessage(
5658 "label.fetch_retrieve_from_all_sources",
5660 Integer.valueOf(otherdb.size())
5661 .toString(), src.getDbSource(),
5662 src.getDbName() })));
5665 // and then build the rest of the individual menus
5666 ifetch = new JMenu(MessageManager.formatMessage(
5667 "label.source_from_db_source",
5668 new Object[] { src.getDbSource() }));
5670 String imname = null;
5672 for (DbSourceProxy sproxy : otherdb)
5674 String dbname = sproxy.getDbName();
5675 String sname = dbname.length() > 5 ? dbname.substring(0,
5676 5) + "..." : dbname;
5677 String msname = dbname.length() > 10 ? dbname.substring(
5678 0, 10) + "..." : dbname;
5681 imname = MessageManager.formatMessage(
5682 "label.from_msname", new Object[] { sname });
5684 fetchr = new JMenuItem(msname);
5685 final DbSourceProxy[] dassrc = { sproxy };
5686 fetchr.addActionListener(new ActionListener()
5690 public void actionPerformed(ActionEvent e)
5692 new Thread(new Runnable()
5698 boolean isNucleotide = alignPanel.alignFrame
5699 .getViewport().getAlignment()
5701 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5702 alignPanel.av.getSequenceSelection(),
5703 alignPanel.alignFrame, dassrc,
5704 alignPanel.alignFrame.featureSettings,
5707 .addListener(new FetchFinishedListenerI()
5710 public void finished()
5712 AlignFrame.this.setMenusForViewport();
5715 dbRefFetcher.fetchDBRefs(false);
5721 fetchr.setToolTipText("<html>"
5722 + MessageManager.formatMessage(
5723 "label.fetch_retrieve_from", new Object[]
5727 if (++icomp >= mcomp || i == (otherdb.size()))
5729 ifetch.setText(MessageManager.formatMessage(
5730 "label.source_to_target", imname, sname));
5732 ifetch = new JMenu();
5740 if (comp >= mcomp || dbi >= (dbclasses.length))
5742 dfetch.setText(MessageManager.formatMessage(
5743 "label.source_to_target", mname, dbclass));
5745 dfetch = new JMenu();
5758 * Left justify the whole alignment.
5761 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5763 AlignmentI al = viewport.getAlignment();
5765 viewport.firePropertyChange("alignment", null, al);
5769 * Right justify the whole alignment.
5772 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5774 AlignmentI al = viewport.getAlignment();
5776 viewport.firePropertyChange("alignment", null, al);
5780 public void setShowSeqFeatures(boolean b)
5782 showSeqFeatures.setSelected(b);
5783 viewport.setShowSequenceFeatures(b);
5790 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5791 * awt.event.ActionEvent)
5794 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5796 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5797 alignPanel.paintAlignment(true);
5804 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5808 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5810 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5811 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5819 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5820 * .event.ActionEvent)
5823 protected void showGroupConservation_actionPerformed(ActionEvent e)
5825 viewport.setShowGroupConservation(showGroupConservation.getState());
5826 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5833 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5834 * .event.ActionEvent)
5837 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5839 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5840 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5847 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5848 * .event.ActionEvent)
5851 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5853 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5854 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5858 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5860 showSequenceLogo.setState(true);
5861 viewport.setShowSequenceLogo(true);
5862 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5863 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5867 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5869 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5876 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5877 * .event.ActionEvent)
5880 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5882 if (avc.makeGroupsFromSelection())
5884 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5885 alignPanel.updateAnnotation();
5886 alignPanel.paintAlignment(true);
5890 public void clearAlignmentSeqRep()
5892 // TODO refactor alignmentseqrep to controller
5893 if (viewport.getAlignment().hasSeqrep())
5895 viewport.getAlignment().setSeqrep(null);
5896 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5897 alignPanel.updateAnnotation();
5898 alignPanel.paintAlignment(true);
5903 protected void createGroup_actionPerformed(ActionEvent e)
5905 if (avc.createGroup())
5907 alignPanel.alignmentChanged();
5912 protected void unGroup_actionPerformed(ActionEvent e)
5916 alignPanel.alignmentChanged();
5921 * make the given alignmentPanel the currently selected tab
5923 * @param alignmentPanel
5925 public void setDisplayedView(AlignmentPanel alignmentPanel)
5927 if (!viewport.getSequenceSetId().equals(
5928 alignmentPanel.av.getSequenceSetId()))
5932 .getString("error.implementation_error_cannot_show_view_alignment_frame"));
5934 if (tabbedPane != null
5935 && tabbedPane.getTabCount() > 0
5936 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5937 .getSelectedIndex())
5939 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5944 * Action on selection of menu options to Show or Hide annotations.
5947 * @param forSequences
5948 * update sequence-related annotations
5949 * @param forAlignment
5950 * update non-sequence-related annotations
5953 protected void setAnnotationsVisibility(boolean visible,
5954 boolean forSequences, boolean forAlignment)
5956 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5957 .getAlignmentAnnotation();
5962 for (AlignmentAnnotation aa : anns)
5965 * don't display non-positional annotations on an alignment
5967 if (aa.annotations == null)
5971 boolean apply = (aa.sequenceRef == null && forAlignment)
5972 || (aa.sequenceRef != null && forSequences);
5975 aa.visible = visible;
5978 alignPanel.validateAnnotationDimensions(true);
5979 alignPanel.alignmentChanged();
5983 * Store selected annotation sort order for the view and repaint.
5986 protected void sortAnnotations_actionPerformed()
5988 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5990 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5991 alignPanel.paintAlignment(true);
5996 * @return alignment panels in this alignment frame
5998 public List<? extends AlignmentViewPanel> getAlignPanels()
6000 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
6004 * Open a new alignment window, with the cDNA associated with this (protein)
6005 * alignment, aligned as is the protein.
6007 protected void viewAsCdna_actionPerformed()
6009 // TODO no longer a menu action - refactor as required
6010 final AlignmentI alignment = getViewport().getAlignment();
6011 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6012 if (mappings == null)
6016 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6017 for (SequenceI aaSeq : alignment.getSequences())
6019 for (AlignedCodonFrame acf : mappings)
6021 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6025 * There is a cDNA mapping for this protein sequence - add to new
6026 * alignment. It will share the same dataset sequence as other mapped
6027 * cDNA (no new mappings need to be created).
6029 final Sequence newSeq = new Sequence(dnaSeq);
6030 newSeq.setDatasetSequence(dnaSeq);
6031 cdnaSeqs.add(newSeq);
6035 if (cdnaSeqs.size() == 0)
6037 // show a warning dialog no mapped cDNA
6040 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6042 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6043 AlignFrame.DEFAULT_HEIGHT);
6044 cdna.alignAs(alignment);
6045 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6047 Desktop.addInternalFrame(alignFrame, newtitle,
6048 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
6052 * Set visibility of dna/protein complement view (available when shown in a
6058 protected void showComplement_actionPerformed(boolean show)
6060 SplitContainerI sf = getSplitViewContainer();
6063 sf.setComplementVisible(this, show);
6068 * Generate the reverse (optionally complemented) of the selected sequences,
6069 * and add them to the alignment
6072 protected void showReverse_actionPerformed(boolean complement)
6074 AlignmentI al = null;
6077 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
6078 al = dna.reverseCdna(complement);
6079 viewport.addAlignment(al, "");
6080 addHistoryItem(new EditCommand(
6081 MessageManager.getString("label.add_sequences"),
6082 Action.PASTE, al.getSequencesArray(), 0, al.getWidth(),
6083 viewport.getAlignment()));
6084 } catch (Exception ex)
6086 System.err.println(ex.getMessage());
6092 * Try to run a script in the Groovy console, having first ensured that this
6093 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
6094 * be targeted at this alignment.
6097 protected void runGroovy_actionPerformed()
6099 Jalview.setCurrentAlignFrame(this);
6100 groovy.ui.Console console = Desktop.getGroovyConsole();
6101 if (console != null)
6105 console.runScript();
6106 } catch (Exception ex)
6108 System.err.println((ex.toString()));
6110 .showInternalMessageDialog(Desktop.desktop, MessageManager
6111 .getString("label.couldnt_run_groovy_script"),
6113 .getString("label.groovy_support_failed"),
6114 JOptionPane.ERROR_MESSAGE);
6119 System.err.println("Can't run Groovy script as console not found");
6124 * Hides columns containing (or not containing) a specified feature, provided
6125 * that would not leave all columns hidden
6127 * @param featureType
6128 * @param columnsContaining
6131 public boolean hideFeatureColumns(String featureType,
6132 boolean columnsContaining)
6134 boolean notForHiding = avc.markColumnsContainingFeatures(
6135 columnsContaining, false, false, featureType);
6138 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
6139 false, featureType))
6141 getViewport().hideSelectedColumns();
6149 class PrintThread extends Thread
6153 public PrintThread(AlignmentPanel ap)
6158 static PageFormat pf;
6163 PrinterJob printJob = PrinterJob.getPrinterJob();
6167 printJob.setPrintable(ap, pf);
6171 printJob.setPrintable(ap);
6174 if (printJob.printDialog())
6179 } catch (Exception PrintException)
6181 PrintException.printStackTrace();