2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.ParseProperties;
28 import jalview.analysis.SequenceIdMatcher;
29 import jalview.api.AlignExportSettingI;
30 import jalview.api.AlignViewControllerGuiI;
31 import jalview.api.AlignViewControllerI;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureSettingsControllerI;
35 import jalview.api.FeatureSettingsModelI;
36 import jalview.api.SplitContainerI;
37 import jalview.api.ViewStyleI;
38 import jalview.api.analysis.ScoreModelI;
39 import jalview.bin.Cache;
40 import jalview.bin.Jalview;
41 import jalview.commands.CommandI;
42 import jalview.commands.EditCommand;
43 import jalview.commands.EditCommand.Action;
44 import jalview.commands.OrderCommand;
45 import jalview.commands.RemoveGapColCommand;
46 import jalview.commands.RemoveGapsCommand;
47 import jalview.commands.SlideSequencesCommand;
48 import jalview.commands.TrimRegionCommand;
49 import jalview.datamodel.AlignedCodonFrame;
50 import jalview.datamodel.Alignment;
51 import jalview.datamodel.AlignmentAnnotation;
52 import jalview.datamodel.AlignmentExportData;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.AlignmentOrder;
55 import jalview.datamodel.AlignmentView;
56 import jalview.datamodel.ColumnSelection;
57 import jalview.datamodel.DBRefSource;
58 import jalview.datamodel.HiddenSequences;
59 import jalview.datamodel.PDBEntry;
60 import jalview.datamodel.SeqCigar;
61 import jalview.datamodel.Sequence;
62 import jalview.datamodel.SequenceGroup;
63 import jalview.datamodel.SequenceI;
64 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
65 import jalview.io.AlignmentProperties;
66 import jalview.io.AnnotationFile;
67 import jalview.io.BioJsHTMLOutput;
68 import jalview.io.FileLoader;
69 import jalview.io.FormatAdapter;
70 import jalview.io.HtmlSvgOutput;
71 import jalview.io.IdentifyFile;
72 import jalview.io.JalviewFileChooser;
73 import jalview.io.JalviewFileView;
74 import jalview.io.JnetAnnotationMaker;
75 import jalview.io.NewickFile;
76 import jalview.io.TCoffeeScoreFile;
77 import jalview.io.gff.SequenceOntologyI;
78 import jalview.jbgui.GAlignFrame;
79 import jalview.schemes.Blosum62ColourScheme;
80 import jalview.schemes.BuriedColourScheme;
81 import jalview.schemes.ClustalxColourScheme;
82 import jalview.schemes.ColourSchemeI;
83 import jalview.schemes.ColourSchemeProperty;
84 import jalview.schemes.HelixColourScheme;
85 import jalview.schemes.HydrophobicColourScheme;
86 import jalview.schemes.NucleotideColourScheme;
87 import jalview.schemes.PIDColourScheme;
88 import jalview.schemes.PurinePyrimidineColourScheme;
89 import jalview.schemes.RNAHelicesColourChooser;
90 import jalview.schemes.ResidueProperties;
91 import jalview.schemes.StrandColourScheme;
92 import jalview.schemes.TCoffeeColourScheme;
93 import jalview.schemes.TaylorColourScheme;
94 import jalview.schemes.TurnColourScheme;
95 import jalview.schemes.UserColourScheme;
96 import jalview.schemes.ZappoColourScheme;
97 import jalview.structure.StructureSelectionManager;
98 import jalview.util.MessageManager;
99 import jalview.viewmodel.AlignmentViewport;
100 import jalview.ws.DBRefFetcher;
101 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
102 import jalview.ws.SequenceFetcher;
103 import jalview.ws.jws1.Discoverer;
104 import jalview.ws.jws2.Jws2Discoverer;
105 import jalview.ws.jws2.jabaws2.Jws2Instance;
106 import jalview.ws.seqfetcher.DbSourceProxy;
108 import java.awt.BorderLayout;
109 import java.awt.Component;
110 import java.awt.Rectangle;
111 import java.awt.Toolkit;
112 import java.awt.datatransfer.Clipboard;
113 import java.awt.datatransfer.DataFlavor;
114 import java.awt.datatransfer.StringSelection;
115 import java.awt.datatransfer.Transferable;
116 import java.awt.dnd.DropTargetDragEvent;
117 import java.awt.dnd.DropTargetDropEvent;
118 import java.awt.dnd.DropTargetEvent;
119 import java.awt.dnd.DropTargetListener;
120 import java.awt.event.ActionEvent;
121 import java.awt.event.ActionListener;
122 import java.awt.event.FocusAdapter;
123 import java.awt.event.FocusEvent;
124 import java.awt.event.ItemEvent;
125 import java.awt.event.ItemListener;
126 import java.awt.event.KeyAdapter;
127 import java.awt.event.KeyEvent;
128 import java.awt.event.MouseAdapter;
129 import java.awt.event.MouseEvent;
130 import java.awt.print.PageFormat;
131 import java.awt.print.PrinterJob;
132 import java.beans.PropertyChangeEvent;
135 import java.util.ArrayList;
136 import java.util.Arrays;
137 import java.util.Deque;
138 import java.util.Enumeration;
139 import java.util.Hashtable;
140 import java.util.List;
141 import java.util.Vector;
143 import javax.swing.JCheckBoxMenuItem;
144 import javax.swing.JEditorPane;
145 import javax.swing.JInternalFrame;
146 import javax.swing.JLayeredPane;
147 import javax.swing.JMenu;
148 import javax.swing.JMenuItem;
149 import javax.swing.JOptionPane;
150 import javax.swing.JRadioButtonMenuItem;
151 import javax.swing.JScrollPane;
152 import javax.swing.SwingUtilities;
158 * @version $Revision$
160 public class AlignFrame extends GAlignFrame implements DropTargetListener,
161 IProgressIndicator, AlignViewControllerGuiI
164 public static final int DEFAULT_WIDTH = 700;
166 public static final int DEFAULT_HEIGHT = 500;
169 * The currently displayed panel (selected tabbed view if more than one)
171 public AlignmentPanel alignPanel;
173 AlignViewport viewport;
175 public AlignViewControllerI avc;
177 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
180 * Last format used to load or save alignments in this window
182 String currentFileFormat = null;
185 * Current filename for this alignment
187 String fileName = null;
190 * Creates a new AlignFrame object with specific width and height.
196 public AlignFrame(AlignmentI al, int width, int height)
198 this(al, null, width, height);
202 * Creates a new AlignFrame object with specific width, height and
208 * @param sequenceSetId
210 public AlignFrame(AlignmentI al, int width, int height,
211 String sequenceSetId)
213 this(al, null, width, height, sequenceSetId);
217 * Creates a new AlignFrame object with specific width, height and
223 * @param sequenceSetId
226 public AlignFrame(AlignmentI al, int width, int height,
227 String sequenceSetId, String viewId)
229 this(al, null, width, height, sequenceSetId, viewId);
233 * new alignment window with hidden columns
237 * @param hiddenColumns
238 * ColumnSelection or null
240 * Width of alignment frame
244 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
245 int width, int height)
247 this(al, hiddenColumns, width, height, null);
251 * Create alignment frame for al with hiddenColumns, a specific width and
252 * height, and specific sequenceId
255 * @param hiddenColumns
258 * @param sequenceSetId
261 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
262 int width, int height, String sequenceSetId)
264 this(al, hiddenColumns, width, height, sequenceSetId, null);
268 * Create alignment frame for al with hiddenColumns, a specific width and
269 * height, and specific sequenceId
272 * @param hiddenColumns
275 * @param sequenceSetId
280 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
281 int width, int height, String sequenceSetId, String viewId)
283 setSize(width, height);
285 if (al.getDataset() == null)
290 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
292 alignPanel = new AlignmentPanel(this, viewport);
294 addAlignmentPanel(alignPanel, true);
298 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
299 ColumnSelection hiddenColumns, int width, int height)
301 setSize(width, height);
303 if (al.getDataset() == null)
308 viewport = new AlignViewport(al, hiddenColumns);
310 if (hiddenSeqs != null && hiddenSeqs.length > 0)
312 viewport.hideSequence(hiddenSeqs);
314 alignPanel = new AlignmentPanel(this, viewport);
315 addAlignmentPanel(alignPanel, true);
320 * Make a new AlignFrame from existing alignmentPanels
327 public AlignFrame(AlignmentPanel ap)
331 addAlignmentPanel(ap, false);
336 * initalise the alignframe from the underlying viewport data and the
341 if (!Jalview.isHeadlessMode())
343 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
346 avc = new jalview.controller.AlignViewController(this, viewport,
348 if (viewport.getAlignmentConservationAnnotation() == null)
350 BLOSUM62Colour.setEnabled(false);
351 conservationMenuItem.setEnabled(false);
352 modifyConservation.setEnabled(false);
353 // PIDColour.setEnabled(false);
354 // abovePIDThreshold.setEnabled(false);
355 // modifyPID.setEnabled(false);
358 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
361 if (sortby.equals("Id"))
363 sortIDMenuItem_actionPerformed(null);
365 else if (sortby.equals("Pairwise Identity"))
367 sortPairwiseMenuItem_actionPerformed(null);
370 if (Desktop.desktop != null)
372 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
373 addServiceListeners();
374 setGUINucleotide(viewport.getAlignment().isNucleotide());
378 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
380 setMenusFromViewport(viewport);
381 buildSortByAnnotationScoresMenu();
384 if (viewport.getWrapAlignment())
386 wrapMenuItem_actionPerformed(null);
389 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
391 this.overviewMenuItem_actionPerformed(null);
396 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
397 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
398 final String menuLabel = MessageManager
399 .getString("label.copy_format_from");
400 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
401 new ViewSetProvider()
405 public AlignmentPanel[] getAllAlignmentPanels()
408 origview.add(alignPanel);
409 // make an array of all alignment panels except for this one
410 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
411 Arrays.asList(Desktop.getAlignmentPanels(null)));
412 aps.remove(AlignFrame.this.alignPanel);
413 return aps.toArray(new AlignmentPanel[aps.size()]);
415 }, selviews, new ItemListener()
419 public void itemStateChanged(ItemEvent e)
421 if (origview.size() > 0)
423 final AlignmentPanel ap = origview.get(0);
426 * Copy the ViewStyle of the selected panel to 'this one'.
427 * Don't change value of 'scaleProteinAsCdna' unless copying
430 ViewStyleI vs = selviews.get(0).getAlignViewport()
432 boolean fromSplitFrame = selviews.get(0)
433 .getAlignViewport().getCodingComplement() != null;
436 vs.setScaleProteinAsCdna(ap.getAlignViewport()
437 .getViewStyle().isScaleProteinAsCdna());
439 ap.getAlignViewport().setViewStyle(vs);
442 * Also rescale ViewStyle of SplitFrame complement if there is
443 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
444 * the whole ViewStyle (allow cDNA protein to have different
447 AlignViewportI complement = ap.getAlignViewport()
448 .getCodingComplement();
449 if (complement != null && vs.isScaleProteinAsCdna())
451 AlignFrame af = Desktop.getAlignFrameFor(complement);
452 ((SplitFrame) af.getSplitViewContainer())
454 af.setMenusForViewport();
458 ap.setSelected(true);
459 ap.alignFrame.setMenusForViewport();
464 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
465 .indexOf("devel") > -1
466 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
467 .indexOf("test") > -1)
469 formatMenu.add(vsel);
471 addFocusListener(new FocusAdapter()
474 public void focusGained(FocusEvent e)
476 Jalview.setCurrentAlignFrame(AlignFrame.this);
483 * Change the filename and format for the alignment, and enable the 'reload'
484 * button functionality.
491 public void setFileName(String file, String format)
494 setFileFormat(format);
495 reload.setEnabled(true);
499 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
502 void addKeyListener()
504 addKeyListener(new KeyAdapter()
507 public void keyPressed(KeyEvent evt)
509 if (viewport.cursorMode
510 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
511 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
512 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
513 && Character.isDigit(evt.getKeyChar()))
515 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
518 switch (evt.getKeyCode())
521 case 27: // escape key
522 deselectAllSequenceMenuItem_actionPerformed(null);
526 case KeyEvent.VK_DOWN:
527 if (evt.isAltDown() || !viewport.cursorMode)
529 moveSelectedSequences(false);
531 if (viewport.cursorMode)
533 alignPanel.getSeqPanel().moveCursor(0, 1);
538 if (evt.isAltDown() || !viewport.cursorMode)
540 moveSelectedSequences(true);
542 if (viewport.cursorMode)
544 alignPanel.getSeqPanel().moveCursor(0, -1);
549 case KeyEvent.VK_LEFT:
550 if (evt.isAltDown() || !viewport.cursorMode)
552 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
556 alignPanel.getSeqPanel().moveCursor(-1, 0);
561 case KeyEvent.VK_RIGHT:
562 if (evt.isAltDown() || !viewport.cursorMode)
564 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
568 alignPanel.getSeqPanel().moveCursor(1, 0);
572 case KeyEvent.VK_SPACE:
573 if (viewport.cursorMode)
575 alignPanel.getSeqPanel().insertGapAtCursor(
576 evt.isControlDown() || evt.isShiftDown()
581 // case KeyEvent.VK_A:
582 // if (viewport.cursorMode)
584 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
585 // //System.out.println("A");
589 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
590 * System.out.println("closing bracket"); } break;
592 case KeyEvent.VK_DELETE:
593 case KeyEvent.VK_BACK_SPACE:
594 if (!viewport.cursorMode)
596 cut_actionPerformed(null);
600 alignPanel.getSeqPanel().deleteGapAtCursor(
601 evt.isControlDown() || evt.isShiftDown()
608 if (viewport.cursorMode)
610 alignPanel.getSeqPanel().setCursorRow();
614 if (viewport.cursorMode && !evt.isControlDown())
616 alignPanel.getSeqPanel().setCursorColumn();
620 if (viewport.cursorMode)
622 alignPanel.getSeqPanel().setCursorPosition();
626 case KeyEvent.VK_ENTER:
627 case KeyEvent.VK_COMMA:
628 if (viewport.cursorMode)
630 alignPanel.getSeqPanel().setCursorRowAndColumn();
635 if (viewport.cursorMode)
637 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
641 if (viewport.cursorMode)
643 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
648 viewport.cursorMode = !viewport.cursorMode;
649 statusBar.setText(MessageManager.formatMessage(
650 "label.keyboard_editing_mode",
651 new String[] { (viewport.cursorMode ? "on" : "off") }));
652 if (viewport.cursorMode)
654 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
655 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
657 alignPanel.getSeqPanel().seqCanvas.repaint();
663 Help.showHelpWindow();
664 } catch (Exception ex)
666 ex.printStackTrace();
671 boolean toggleSeqs = !evt.isControlDown();
672 boolean toggleCols = !evt.isShiftDown();
673 toggleHiddenRegions(toggleSeqs, toggleCols);
676 case KeyEvent.VK_PAGE_UP:
677 if (viewport.getWrapAlignment())
679 alignPanel.scrollUp(true);
683 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
684 - viewport.endSeq + viewport.startSeq);
687 case KeyEvent.VK_PAGE_DOWN:
688 if (viewport.getWrapAlignment())
690 alignPanel.scrollUp(false);
694 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
695 + viewport.endSeq - viewport.startSeq);
702 public void keyReleased(KeyEvent evt)
704 switch (evt.getKeyCode())
706 case KeyEvent.VK_LEFT:
707 if (evt.isAltDown() || !viewport.cursorMode)
709 viewport.firePropertyChange("alignment", null, viewport
710 .getAlignment().getSequences());
714 case KeyEvent.VK_RIGHT:
715 if (evt.isAltDown() || !viewport.cursorMode)
717 viewport.firePropertyChange("alignment", null, viewport
718 .getAlignment().getSequences());
726 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
728 ap.alignFrame = this;
729 avc = new jalview.controller.AlignViewController(this, viewport,
734 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
736 int aSize = alignPanels.size();
738 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
740 if (aSize == 1 && ap.av.viewName == null)
742 this.getContentPane().add(ap, BorderLayout.CENTER);
748 setInitialTabVisible();
751 expandViews.setEnabled(true);
752 gatherViews.setEnabled(true);
753 tabbedPane.addTab(ap.av.viewName, ap);
755 ap.setVisible(false);
760 if (ap.av.isPadGaps())
762 ap.av.getAlignment().padGaps();
764 ap.av.updateConservation(ap);
765 ap.av.updateConsensus(ap);
766 ap.av.updateStrucConsensus(ap);
770 public void setInitialTabVisible()
772 expandViews.setEnabled(true);
773 gatherViews.setEnabled(true);
774 tabbedPane.setVisible(true);
775 AlignmentPanel first = alignPanels.get(0);
776 tabbedPane.addTab(first.av.viewName, first);
777 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
780 public AlignViewport getViewport()
785 /* Set up intrinsic listeners for dynamically generated GUI bits. */
786 private void addServiceListeners()
788 final java.beans.PropertyChangeListener thisListener;
789 Desktop.instance.addJalviewPropertyChangeListener("services",
790 thisListener = new java.beans.PropertyChangeListener()
793 public void propertyChange(PropertyChangeEvent evt)
795 // // System.out.println("Discoverer property change.");
796 // if (evt.getPropertyName().equals("services"))
798 SwingUtilities.invokeLater(new Runnable()
805 .println("Rebuild WS Menu for service change");
806 BuildWebServiceMenu();
813 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
816 public void internalFrameClosed(
817 javax.swing.event.InternalFrameEvent evt)
819 // System.out.println("deregistering discoverer listener");
820 Desktop.instance.removeJalviewPropertyChangeListener("services",
822 closeMenuItem_actionPerformed(true);
825 // Finally, build the menu once to get current service state
826 new Thread(new Runnable()
831 BuildWebServiceMenu();
837 * Configure menu items that vary according to whether the alignment is
838 * nucleotide or protein
842 public void setGUINucleotide(boolean nucleotide)
844 showTranslation.setVisible(nucleotide);
845 showReverse.setVisible(nucleotide);
846 showReverseComplement.setVisible(nucleotide);
847 conservationMenuItem.setEnabled(!nucleotide);
848 modifyConservation.setEnabled(!nucleotide);
849 showGroupConservation.setEnabled(!nucleotide);
850 rnahelicesColour.setEnabled(nucleotide);
851 purinePyrimidineColour.setEnabled(nucleotide);
852 showComplementMenuItem.setText(MessageManager
853 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
854 setColourSelected(jalview.bin.Cache.getDefault(
855 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
856 : Preferences.DEFAULT_COLOUR_PROT, "None"));
860 * set up menus for the current viewport. This may be called after any
861 * operation that affects the data in the current view (selection changed,
862 * etc) to update the menus to reflect the new state.
865 public void setMenusForViewport()
867 setMenusFromViewport(viewport);
871 * Need to call this method when tabs are selected for multiple views, or when
872 * loading from Jalview2XML.java
877 void setMenusFromViewport(AlignViewport av)
879 padGapsMenuitem.setSelected(av.isPadGaps());
880 colourTextMenuItem.setSelected(av.isShowColourText());
881 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
882 conservationMenuItem.setSelected(av.getConservationSelected());
883 seqLimits.setSelected(av.getShowJVSuffix());
884 idRightAlign.setSelected(av.isRightAlignIds());
885 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
886 renderGapsMenuItem.setSelected(av.isRenderGaps());
887 wrapMenuItem.setSelected(av.getWrapAlignment());
888 scaleAbove.setVisible(av.getWrapAlignment());
889 scaleLeft.setVisible(av.getWrapAlignment());
890 scaleRight.setVisible(av.getWrapAlignment());
891 annotationPanelMenuItem.setState(av.isShowAnnotation());
893 * Show/hide annotations only enabled if annotation panel is shown
895 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
896 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
897 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
898 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
899 viewBoxesMenuItem.setSelected(av.getShowBoxes());
900 viewTextMenuItem.setSelected(av.getShowText());
901 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
902 showGroupConsensus.setSelected(av.isShowGroupConsensus());
903 showGroupConservation.setSelected(av.isShowGroupConservation());
904 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
905 showSequenceLogo.setSelected(av.isShowSequenceLogo());
906 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
908 setColourSelected(ColourSchemeProperty.getColourName(av
909 .getGlobalColourScheme()));
911 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
912 hiddenMarkers.setState(av.getShowHiddenMarkers());
913 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
914 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
915 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
916 autoCalculate.setSelected(av.autoCalculateConsensus);
917 sortByTree.setSelected(av.sortByTree);
918 listenToViewSelections.setSelected(av.followSelection);
919 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
921 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
923 showProducts.setEnabled(canShowProducts());
924 setGroovyEnabled(Desktop.getGroovyConsole() != null);
930 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
934 public void setGroovyEnabled(boolean b)
936 runGroovy.setEnabled(b);
939 private IProgressIndicator progressBar;
944 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
947 public void setProgressBar(String message, long id)
949 progressBar.setProgressBar(message, id);
953 public void registerHandler(final long id,
954 final IProgressIndicatorHandler handler)
956 progressBar.registerHandler(id, handler);
961 * @return true if any progress bars are still active
964 public boolean operationInProgress()
966 return progressBar.operationInProgress();
970 public void setStatus(String text)
972 statusBar.setText(text);
976 * Added so Castor Mapping file can obtain Jalview Version
978 public String getVersion()
980 return jalview.bin.Cache.getProperty("VERSION");
983 public FeatureRenderer getFeatureRenderer()
985 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
989 public void fetchSequence_actionPerformed(ActionEvent e)
991 new jalview.gui.SequenceFetcher(this);
995 public void addFromFile_actionPerformed(ActionEvent e)
997 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1001 public void reload_actionPerformed(ActionEvent e)
1003 if (fileName != null)
1005 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1006 // originating file's format
1007 // TODO: work out how to recover feature settings for correct view(s) when
1008 // file is reloaded.
1009 if (currentFileFormat.equals("Jalview"))
1011 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1012 for (int i = 0; i < frames.length; i++)
1014 if (frames[i] instanceof AlignFrame && frames[i] != this
1015 && ((AlignFrame) frames[i]).fileName != null
1016 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1020 frames[i].setSelected(true);
1021 Desktop.instance.closeAssociatedWindows();
1022 } catch (java.beans.PropertyVetoException ex)
1028 Desktop.instance.closeAssociatedWindows();
1030 FileLoader loader = new FileLoader();
1031 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1032 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1036 Rectangle bounds = this.getBounds();
1038 FileLoader loader = new FileLoader();
1039 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1040 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1041 protocol, currentFileFormat);
1043 newframe.setBounds(bounds);
1044 if (featureSettings != null && featureSettings.isShowing())
1046 final Rectangle fspos = featureSettings.frame.getBounds();
1047 // TODO: need a 'show feature settings' function that takes bounds -
1048 // need to refactor Desktop.addFrame
1049 newframe.featureSettings_actionPerformed(null);
1050 final FeatureSettings nfs = newframe.featureSettings;
1051 SwingUtilities.invokeLater(new Runnable()
1056 nfs.frame.setBounds(fspos);
1059 this.featureSettings.close();
1060 this.featureSettings = null;
1062 this.closeMenuItem_actionPerformed(true);
1068 public void addFromText_actionPerformed(ActionEvent e)
1070 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport
1075 public void addFromURL_actionPerformed(ActionEvent e)
1077 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1081 public void save_actionPerformed(ActionEvent e)
1083 if (fileName == null
1084 || (currentFileFormat == null || !jalview.io.FormatAdapter
1085 .isValidIOFormat(currentFileFormat, true))
1086 || fileName.startsWith("http"))
1088 saveAs_actionPerformed(null);
1092 saveAlignment(fileName, currentFileFormat);
1103 public void saveAs_actionPerformed(ActionEvent e)
1105 JalviewFileChooser chooser = new JalviewFileChooser(
1106 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1107 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1108 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1109 currentFileFormat, false);
1111 chooser.setFileView(new JalviewFileView());
1112 chooser.setDialogTitle(MessageManager
1113 .getString("label.save_alignment_to_file"));
1114 chooser.setToolTipText(MessageManager.getString("action.save"));
1116 int value = chooser.showSaveDialog(this);
1118 if (value == JalviewFileChooser.APPROVE_OPTION)
1120 currentFileFormat = chooser.getSelectedFormat();
1121 while (currentFileFormat == null)
1124 .showInternalMessageDialog(
1127 .getString("label.select_file_format_before_saving"),
1129 .getString("label.file_format_not_specified"),
1130 JOptionPane.WARNING_MESSAGE);
1131 currentFileFormat = chooser.getSelectedFormat();
1132 value = chooser.showSaveDialog(this);
1133 if (value != JalviewFileChooser.APPROVE_OPTION)
1139 fileName = chooser.getSelectedFile().getPath();
1141 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1144 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1145 if (currentFileFormat.indexOf(" ") > -1)
1147 currentFileFormat = currentFileFormat.substring(0,
1148 currentFileFormat.indexOf(" "));
1150 saveAlignment(fileName, currentFileFormat);
1154 public boolean saveAlignment(String file, String format)
1156 boolean success = true;
1158 if (format.equalsIgnoreCase("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 AlignmentExportData exportData = getAlignmentForExport(
1267 e.getActionCommand(), viewport, null);
1268 if (exportData.getSettings().isCancelled())
1272 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1273 cap.setForInput(null);
1276 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1277 .formatSequences(e.getActionCommand(),
1278 exportData.getAlignment(),
1279 exportData.getOmitHidden(),
1280 exportData.getStartEndPostions(),
1281 viewport.getColumnSelection()));
1282 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1283 "label.alignment_output_command",
1284 new Object[] { e.getActionCommand() }), 600, 500);
1285 } catch (OutOfMemoryError oom)
1287 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1293 public static AlignmentExportData getAlignmentForExport(
1294 String exportFormat, AlignViewportI viewport,
1295 AlignExportSettingI exportSettings)
1297 AlignmentI alignmentToExport = null;
1298 AlignExportSettingI settings = exportSettings;
1299 String[] omitHidden = null;
1301 HiddenSequences hiddenSeqs = viewport.getAlignment()
1302 .getHiddenSequences();
1304 alignmentToExport = viewport.getAlignment();
1306 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1307 if (settings == null)
1309 settings = new AlignExportSettings(hasHiddenSeqs,
1310 viewport.hasHiddenColumns(), exportFormat);
1312 // settings.isExportAnnotations();
1314 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1316 omitHidden = viewport.getViewAsString(false,
1317 settings.isExportHiddenSequences());
1320 int[] alignmentStartEnd = new int[2];
1321 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1323 alignmentToExport = hiddenSeqs.getFullAlignment();
1327 alignmentToExport = viewport.getAlignment();
1329 alignmentStartEnd = alignmentToExport
1330 .getVisibleStartAndEndIndex(viewport.getColumnSelection()
1331 .getHiddenColumns());
1332 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1333 omitHidden, alignmentStartEnd, settings);
1344 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1346 new HtmlSvgOutput(null, alignPanel);
1350 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1352 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel, this);
1353 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1356 public void createImageMap(File file, String image)
1358 alignPanel.makePNGImageMap(file, image);
1368 public void createPNG(File f)
1370 alignPanel.makePNG(f);
1380 public void createEPS(File f)
1382 alignPanel.makeEPS(f);
1386 public void createSVG(File f)
1388 alignPanel.makeSVG(f);
1392 public void pageSetup_actionPerformed(ActionEvent e)
1394 PrinterJob printJob = PrinterJob.getPrinterJob();
1395 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1405 public void printMenuItem_actionPerformed(ActionEvent e)
1407 // Putting in a thread avoids Swing painting problems
1408 PrintThread thread = new PrintThread(alignPanel);
1413 public void exportFeatures_actionPerformed(ActionEvent e)
1415 new AnnotationExporter().exportFeatures(alignPanel);
1419 public void exportAnnotations_actionPerformed(ActionEvent e)
1421 new AnnotationExporter().exportAnnotations(alignPanel);
1425 public void associatedData_actionPerformed(ActionEvent e)
1427 // Pick the tree file
1428 JalviewFileChooser chooser = new JalviewFileChooser(
1429 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1430 chooser.setFileView(new JalviewFileView());
1431 chooser.setDialogTitle(MessageManager
1432 .getString("label.load_jalview_annotations"));
1433 chooser.setToolTipText(MessageManager
1434 .getString("label.load_jalview_annotations"));
1436 int value = chooser.showOpenDialog(null);
1438 if (value == JalviewFileChooser.APPROVE_OPTION)
1440 String choice = chooser.getSelectedFile().getPath();
1441 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1442 loadJalviewDataFile(choice, null, null, null);
1448 * Close the current view or all views in the alignment frame. If the frame
1449 * only contains one view then the alignment will be removed from memory.
1451 * @param closeAllTabs
1454 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1456 if (alignPanels != null && alignPanels.size() < 2)
1458 closeAllTabs = true;
1463 if (alignPanels != null)
1467 if (this.isClosed())
1469 // really close all the windows - otherwise wait till
1470 // setClosed(true) is called
1471 for (int i = 0; i < alignPanels.size(); i++)
1473 AlignmentPanel ap = alignPanels.get(i);
1480 closeView(alignPanel);
1487 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1488 * be called recursively, with the frame now in 'closed' state
1490 this.setClosed(true);
1492 } catch (Exception ex)
1494 ex.printStackTrace();
1499 * Close the specified panel and close up tabs appropriately.
1501 * @param panelToClose
1503 public void closeView(AlignmentPanel panelToClose)
1505 int index = tabbedPane.getSelectedIndex();
1506 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1507 alignPanels.remove(panelToClose);
1508 panelToClose.closePanel();
1509 panelToClose = null;
1511 tabbedPane.removeTabAt(closedindex);
1512 tabbedPane.validate();
1514 if (index > closedindex || index == tabbedPane.getTabCount())
1516 // modify currently selected tab index if necessary.
1520 this.tabSelectionChanged(index);
1526 void updateEditMenuBar()
1529 if (viewport.getHistoryList().size() > 0)
1531 undoMenuItem.setEnabled(true);
1532 CommandI command = viewport.getHistoryList().peek();
1533 undoMenuItem.setText(MessageManager.formatMessage(
1534 "label.undo_command",
1535 new Object[] { command.getDescription() }));
1539 undoMenuItem.setEnabled(false);
1540 undoMenuItem.setText(MessageManager.getString("action.undo"));
1543 if (viewport.getRedoList().size() > 0)
1545 redoMenuItem.setEnabled(true);
1547 CommandI command = viewport.getRedoList().peek();
1548 redoMenuItem.setText(MessageManager.formatMessage(
1549 "label.redo_command",
1550 new Object[] { command.getDescription() }));
1554 redoMenuItem.setEnabled(false);
1555 redoMenuItem.setText(MessageManager.getString("action.redo"));
1560 public void addHistoryItem(CommandI command)
1562 if (command.getSize() > 0)
1564 viewport.addToHistoryList(command);
1565 viewport.clearRedoList();
1566 updateEditMenuBar();
1567 viewport.updateHiddenColumns();
1568 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1569 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1570 // viewport.getColumnSelection()
1571 // .getHiddenColumns().size() > 0);
1577 * @return alignment objects for all views
1579 AlignmentI[] getViewAlignments()
1581 if (alignPanels != null)
1583 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1585 for (AlignmentPanel ap : alignPanels)
1587 als[i++] = ap.av.getAlignment();
1591 if (viewport != null)
1593 return new AlignmentI[] { viewport.getAlignment() };
1605 protected void undoMenuItem_actionPerformed(ActionEvent e)
1607 if (viewport.getHistoryList().isEmpty())
1611 CommandI command = viewport.getHistoryList().pop();
1612 viewport.addToRedoList(command);
1613 command.undoCommand(getViewAlignments());
1615 AlignmentViewport originalSource = getOriginatingSource(command);
1616 updateEditMenuBar();
1618 if (originalSource != null)
1620 if (originalSource != viewport)
1623 .warn("Implementation worry: mismatch of viewport origin for undo");
1625 originalSource.updateHiddenColumns();
1626 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1628 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1629 // viewport.getColumnSelection()
1630 // .getHiddenColumns().size() > 0);
1631 originalSource.firePropertyChange("alignment", null, originalSource
1632 .getAlignment().getSequences());
1643 protected void redoMenuItem_actionPerformed(ActionEvent e)
1645 if (viewport.getRedoList().size() < 1)
1650 CommandI command = viewport.getRedoList().pop();
1651 viewport.addToHistoryList(command);
1652 command.doCommand(getViewAlignments());
1654 AlignmentViewport originalSource = getOriginatingSource(command);
1655 updateEditMenuBar();
1657 if (originalSource != null)
1660 if (originalSource != viewport)
1663 .warn("Implementation worry: mismatch of viewport origin for redo");
1665 originalSource.updateHiddenColumns();
1666 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1668 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1669 // viewport.getColumnSelection()
1670 // .getHiddenColumns().size() > 0);
1671 originalSource.firePropertyChange("alignment", null, originalSource
1672 .getAlignment().getSequences());
1676 AlignmentViewport getOriginatingSource(CommandI command)
1678 AlignmentViewport originalSource = null;
1679 // For sequence removal and addition, we need to fire
1680 // the property change event FROM the viewport where the
1681 // original alignment was altered
1682 AlignmentI al = null;
1683 if (command instanceof EditCommand)
1685 EditCommand editCommand = (EditCommand) command;
1686 al = editCommand.getAlignment();
1687 List<Component> comps = PaintRefresher.components.get(viewport
1688 .getSequenceSetId());
1690 for (Component comp : comps)
1692 if (comp instanceof AlignmentPanel)
1694 if (al == ((AlignmentPanel) comp).av.getAlignment())
1696 originalSource = ((AlignmentPanel) comp).av;
1703 if (originalSource == null)
1705 // The original view is closed, we must validate
1706 // the current view against the closed view first
1709 PaintRefresher.validateSequences(al, viewport.getAlignment());
1712 originalSource = viewport;
1715 return originalSource;
1724 public void moveSelectedSequences(boolean up)
1726 SequenceGroup sg = viewport.getSelectionGroup();
1732 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1733 viewport.getHiddenRepSequences(), up);
1734 alignPanel.paintAlignment(true);
1737 synchronized void slideSequences(boolean right, int size)
1739 List<SequenceI> sg = new ArrayList<SequenceI>();
1740 if (viewport.cursorMode)
1742 sg.add(viewport.getAlignment().getSequenceAt(
1743 alignPanel.getSeqPanel().seqCanvas.cursorY));
1745 else if (viewport.getSelectionGroup() != null
1746 && viewport.getSelectionGroup().getSize() != viewport
1747 .getAlignment().getHeight())
1749 sg = viewport.getSelectionGroup().getSequences(
1750 viewport.getHiddenRepSequences());
1758 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1760 for (SequenceI seq : viewport.getAlignment().getSequences())
1762 if (!sg.contains(seq))
1764 invertGroup.add(seq);
1768 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1770 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1771 for (int i = 0; i < invertGroup.size(); i++)
1773 seqs2[i] = invertGroup.get(i);
1776 SlideSequencesCommand ssc;
1779 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1780 size, viewport.getGapCharacter());
1784 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1785 size, viewport.getGapCharacter());
1788 int groupAdjustment = 0;
1789 if (ssc.getGapsInsertedBegin() && right)
1791 if (viewport.cursorMode)
1793 alignPanel.getSeqPanel().moveCursor(size, 0);
1797 groupAdjustment = size;
1800 else if (!ssc.getGapsInsertedBegin() && !right)
1802 if (viewport.cursorMode)
1804 alignPanel.getSeqPanel().moveCursor(-size, 0);
1808 groupAdjustment = -size;
1812 if (groupAdjustment != 0)
1814 viewport.getSelectionGroup().setStartRes(
1815 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1816 viewport.getSelectionGroup().setEndRes(
1817 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1821 * just extend the last slide command if compatible; but not if in
1822 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1824 boolean appendHistoryItem = false;
1825 Deque<CommandI> historyList = viewport.getHistoryList();
1826 boolean inSplitFrame = getSplitViewContainer() != null;
1827 if (!inSplitFrame && historyList != null && historyList.size() > 0
1828 && historyList.peek() instanceof SlideSequencesCommand)
1830 appendHistoryItem = ssc
1831 .appendSlideCommand((SlideSequencesCommand) historyList
1835 if (!appendHistoryItem)
1837 addHistoryItem(ssc);
1850 protected void copy_actionPerformed(ActionEvent e)
1853 if (viewport.getSelectionGroup() == null)
1857 // TODO: preserve the ordering of displayed alignment annotation in any
1858 // internal paste (particularly sequence associated annotation)
1859 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1860 String[] omitHidden = null;
1862 if (viewport.hasHiddenColumns())
1864 omitHidden = viewport.getViewAsString(true);
1867 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1870 StringSelection ss = new StringSelection(output);
1874 jalview.gui.Desktop.internalCopy = true;
1875 // Its really worth setting the clipboard contents
1876 // to empty before setting the large StringSelection!!
1877 Toolkit.getDefaultToolkit().getSystemClipboard()
1878 .setContents(new StringSelection(""), null);
1880 Toolkit.getDefaultToolkit().getSystemClipboard()
1881 .setContents(ss, Desktop.instance);
1882 } catch (OutOfMemoryError er)
1884 new OOMWarning("copying region", er);
1888 ArrayList<int[]> hiddenColumns = null;
1889 if (viewport.hasHiddenColumns())
1891 hiddenColumns = new ArrayList<int[]>();
1892 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1893 .getSelectionGroup().getEndRes();
1894 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1896 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1898 hiddenColumns.add(new int[] { region[0] - hiddenOffset,
1899 region[1] - hiddenOffset });
1904 Desktop.jalviewClipboard = new Object[] { seqs,
1905 viewport.getAlignment().getDataset(), hiddenColumns };
1906 statusBar.setText(MessageManager.formatMessage(
1907 "label.copied_sequences_to_clipboard", new Object[] { Integer
1908 .valueOf(seqs.length).toString() }));
1918 protected void pasteNew_actionPerformed(ActionEvent e)
1930 protected void pasteThis_actionPerformed(ActionEvent e)
1936 * Paste contents of Jalview clipboard
1938 * @param newAlignment
1939 * true to paste to a new alignment, otherwise add to this.
1941 void paste(boolean newAlignment)
1943 boolean externalPaste = true;
1946 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1947 Transferable contents = c.getContents(this);
1949 if (contents == null)
1957 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1958 if (str.length() < 1)
1963 format = new IdentifyFile().identify(str, "Paste");
1965 } catch (OutOfMemoryError er)
1967 new OOMWarning("Out of memory pasting sequences!!", er);
1971 SequenceI[] sequences;
1972 boolean annotationAdded = false;
1973 AlignmentI alignment = null;
1975 if (Desktop.jalviewClipboard != null)
1977 // The clipboard was filled from within Jalview, we must use the
1979 // And dataset from the copied alignment
1980 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1981 // be doubly sure that we create *new* sequence objects.
1982 sequences = new SequenceI[newseq.length];
1983 for (int i = 0; i < newseq.length; i++)
1985 sequences[i] = new Sequence(newseq[i]);
1987 alignment = new Alignment(sequences);
1988 externalPaste = false;
1992 // parse the clipboard as an alignment.
1993 alignment = new FormatAdapter().readFile(str, "Paste", format);
1994 sequences = alignment.getSequencesArray();
1998 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2004 if (Desktop.jalviewClipboard != null)
2006 // dataset is inherited
2007 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2011 // new dataset is constructed
2012 alignment.setDataset(null);
2014 alwidth = alignment.getWidth() + 1;
2018 AlignmentI pastedal = alignment; // preserve pasted alignment object
2019 // Add pasted sequences and dataset into existing alignment.
2020 alignment = viewport.getAlignment();
2021 alwidth = alignment.getWidth() + 1;
2022 // decide if we need to import sequences from an existing dataset
2023 boolean importDs = Desktop.jalviewClipboard != null
2024 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2025 // importDs==true instructs us to copy over new dataset sequences from
2026 // an existing alignment
2027 Vector newDs = (importDs) ? new Vector() : null; // used to create
2028 // minimum dataset set
2030 for (int i = 0; i < sequences.length; i++)
2034 newDs.addElement(null);
2036 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2038 if (importDs && ds != null)
2040 if (!newDs.contains(ds))
2042 newDs.setElementAt(ds, i);
2043 ds = new Sequence(ds);
2044 // update with new dataset sequence
2045 sequences[i].setDatasetSequence(ds);
2049 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2054 // copy and derive new dataset sequence
2055 sequences[i] = sequences[i].deriveSequence();
2056 alignment.getDataset().addSequence(
2057 sequences[i].getDatasetSequence());
2058 // TODO: avoid creation of duplicate dataset sequences with a
2059 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2061 alignment.addSequence(sequences[i]); // merges dataset
2065 newDs.clear(); // tidy up
2067 if (alignment.getAlignmentAnnotation() != null)
2069 for (AlignmentAnnotation alan : alignment
2070 .getAlignmentAnnotation())
2072 if (alan.graphGroup > fgroup)
2074 fgroup = alan.graphGroup;
2078 if (pastedal.getAlignmentAnnotation() != null)
2080 // Add any annotation attached to alignment.
2081 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2082 for (int i = 0; i < alann.length; i++)
2084 annotationAdded = true;
2085 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2087 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2088 if (newann.graphGroup > -1)
2090 if (newGraphGroups.size() <= newann.graphGroup
2091 || newGraphGroups.get(newann.graphGroup) == null)
2093 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2095 newGraphGroups.add(q, null);
2097 newGraphGroups.set(newann.graphGroup, new Integer(
2100 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2104 newann.padAnnotation(alwidth);
2105 alignment.addAnnotation(newann);
2115 addHistoryItem(new EditCommand(
2116 MessageManager.getString("label.add_sequences"),
2117 Action.PASTE, sequences, 0, alignment.getWidth(), alignment));
2119 // Add any annotations attached to sequences
2120 for (int i = 0; i < sequences.length; i++)
2122 if (sequences[i].getAnnotation() != null)
2124 AlignmentAnnotation newann;
2125 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2127 annotationAdded = true;
2128 newann = sequences[i].getAnnotation()[a];
2129 newann.adjustForAlignment();
2130 newann.padAnnotation(alwidth);
2131 if (newann.graphGroup > -1)
2133 if (newann.graphGroup > -1)
2135 if (newGraphGroups.size() <= newann.graphGroup
2136 || newGraphGroups.get(newann.graphGroup) == null)
2138 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2140 newGraphGroups.add(q, null);
2142 newGraphGroups.set(newann.graphGroup, new Integer(
2145 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2149 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2154 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2161 // propagate alignment changed.
2162 viewport.setEndSeq(alignment.getHeight());
2163 if (annotationAdded)
2165 // Duplicate sequence annotation in all views.
2166 AlignmentI[] alview = this.getViewAlignments();
2167 for (int i = 0; i < sequences.length; i++)
2169 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2174 for (int avnum = 0; avnum < alview.length; avnum++)
2176 if (alview[avnum] != alignment)
2178 // duplicate in a view other than the one with input focus
2179 int avwidth = alview[avnum].getWidth() + 1;
2180 // this relies on sann being preserved after we
2181 // modify the sequence's annotation array for each duplication
2182 for (int a = 0; a < sann.length; a++)
2184 AlignmentAnnotation newann = new AlignmentAnnotation(
2186 sequences[i].addAlignmentAnnotation(newann);
2187 newann.padAnnotation(avwidth);
2188 alview[avnum].addAnnotation(newann); // annotation was
2189 // duplicated earlier
2190 // TODO JAL-1145 graphGroups are not updated for sequence
2191 // annotation added to several views. This may cause
2193 alview[avnum].setAnnotationIndex(newann, a);
2198 buildSortByAnnotationScoresMenu();
2200 viewport.firePropertyChange("alignment", null,
2201 alignment.getSequences());
2202 if (alignPanels != null)
2204 for (AlignmentPanel ap : alignPanels)
2206 ap.validateAnnotationDimensions(false);
2211 alignPanel.validateAnnotationDimensions(false);
2217 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2219 String newtitle = new String("Copied sequences");
2221 if (Desktop.jalviewClipboard != null
2222 && Desktop.jalviewClipboard[2] != null)
2224 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2225 for (int[] region : hc)
2227 af.viewport.hideColumns(region[0], region[1]);
2231 // >>>This is a fix for the moment, until a better solution is
2233 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2235 alignPanel.getSeqPanel().seqCanvas
2236 .getFeatureRenderer());
2238 // TODO: maintain provenance of an alignment, rather than just make the
2239 // title a concatenation of operations.
2242 if (title.startsWith("Copied sequences"))
2248 newtitle = newtitle.concat("- from " + title);
2253 newtitle = new String("Pasted sequences");
2256 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2261 } catch (Exception ex)
2263 ex.printStackTrace();
2264 System.out.println("Exception whilst pasting: " + ex);
2265 // could be anything being pasted in here
2271 protected void expand_newalign(ActionEvent e)
2275 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2276 .getAlignment(), -1);
2277 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2279 String newtitle = new String("Flanking alignment");
2281 if (Desktop.jalviewClipboard != null
2282 && Desktop.jalviewClipboard[2] != null)
2284 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2285 for (int region[] : hc)
2287 af.viewport.hideColumns(region[0], region[1]);
2291 // >>>This is a fix for the moment, until a better solution is
2293 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2295 alignPanel.getSeqPanel().seqCanvas
2296 .getFeatureRenderer());
2298 // TODO: maintain provenance of an alignment, rather than just make the
2299 // title a concatenation of operations.
2301 if (title.startsWith("Copied sequences"))
2307 newtitle = newtitle.concat("- from " + title);
2311 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2313 } catch (Exception ex)
2315 ex.printStackTrace();
2316 System.out.println("Exception whilst pasting: " + ex);
2317 // could be anything being pasted in here
2318 } catch (OutOfMemoryError oom)
2320 new OOMWarning("Viewing flanking region of alignment", oom);
2331 protected void cut_actionPerformed(ActionEvent e)
2333 copy_actionPerformed(null);
2334 delete_actionPerformed(null);
2344 protected void delete_actionPerformed(ActionEvent evt)
2347 SequenceGroup sg = viewport.getSelectionGroup();
2354 * If the cut affects all sequences, warn, remove highlighted columns
2356 if (sg.getSize() == viewport.getAlignment().getHeight())
2358 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport
2359 .getAlignment().getWidth()) ? true : false;
2360 if (isEntireAlignWidth)
2362 int confirm = JOptionPane.showConfirmDialog(this,
2363 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2364 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2365 JOptionPane.OK_CANCEL_OPTION);
2367 if (confirm == JOptionPane.CANCEL_OPTION
2368 || confirm == JOptionPane.CLOSED_OPTION)
2373 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2374 sg.getEndRes() + 1);
2376 SequenceI[] cut = sg.getSequences()
2377 .toArray(new SequenceI[sg.getSize()]);
2379 addHistoryItem(new EditCommand(
2380 MessageManager.getString("label.cut_sequences"), Action.CUT,
2381 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2382 viewport.getAlignment()));
2384 viewport.setSelectionGroup(null);
2385 viewport.sendSelection();
2386 viewport.getAlignment().deleteGroup(sg);
2388 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2390 if (viewport.getAlignment().getHeight() < 1)
2394 this.setClosed(true);
2395 } catch (Exception ex)
2408 protected void deleteGroups_actionPerformed(ActionEvent e)
2410 if (avc.deleteGroups())
2412 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2413 alignPanel.updateAnnotation();
2414 alignPanel.paintAlignment(true);
2425 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2427 SequenceGroup sg = new SequenceGroup();
2429 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2431 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2434 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2435 viewport.setSelectionGroup(sg);
2436 viewport.sendSelection();
2437 alignPanel.paintAlignment(true);
2438 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2448 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2450 if (viewport.cursorMode)
2452 alignPanel.getSeqPanel().keyboardNo1 = null;
2453 alignPanel.getSeqPanel().keyboardNo2 = null;
2455 viewport.setSelectionGroup(null);
2456 viewport.getColumnSelection().clear();
2457 viewport.setSelectionGroup(null);
2458 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2459 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2460 alignPanel.paintAlignment(true);
2461 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2462 viewport.sendSelection();
2472 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2474 SequenceGroup sg = viewport.getSelectionGroup();
2478 selectAllSequenceMenuItem_actionPerformed(null);
2483 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2485 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2488 alignPanel.paintAlignment(true);
2489 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2490 viewport.sendSelection();
2494 public void invertColSel_actionPerformed(ActionEvent e)
2496 viewport.invertColumnSelection();
2497 alignPanel.paintAlignment(true);
2498 viewport.sendSelection();
2508 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2510 trimAlignment(true);
2520 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2522 trimAlignment(false);
2525 void trimAlignment(boolean trimLeft)
2527 ColumnSelection colSel = viewport.getColumnSelection();
2530 if (!colSel.isEmpty())
2534 column = colSel.getMin();
2538 column = colSel.getMax();
2542 if (viewport.getSelectionGroup() != null)
2544 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2545 viewport.getHiddenRepSequences());
2549 seqs = viewport.getAlignment().getSequencesArray();
2552 TrimRegionCommand trimRegion;
2555 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2556 column, viewport.getAlignment());
2557 viewport.setStartRes(0);
2561 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2562 column, viewport.getAlignment());
2565 statusBar.setText(MessageManager.formatMessage(
2566 "label.removed_columns",
2567 new String[] { Integer.valueOf(trimRegion.getSize())
2570 addHistoryItem(trimRegion);
2572 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2574 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2575 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2577 viewport.getAlignment().deleteGroup(sg);
2581 viewport.firePropertyChange("alignment", null, viewport
2582 .getAlignment().getSequences());
2593 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2595 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2598 if (viewport.getSelectionGroup() != null)
2600 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2601 viewport.getHiddenRepSequences());
2602 start = viewport.getSelectionGroup().getStartRes();
2603 end = viewport.getSelectionGroup().getEndRes();
2607 seqs = viewport.getAlignment().getSequencesArray();
2610 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2611 "Remove Gapped Columns", seqs, start, end,
2612 viewport.getAlignment());
2614 addHistoryItem(removeGapCols);
2616 statusBar.setText(MessageManager.formatMessage(
2617 "label.removed_empty_columns",
2618 new Object[] { Integer.valueOf(removeGapCols.getSize())
2621 // This is to maintain viewport position on first residue
2622 // of first sequence
2623 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2624 int startRes = seq.findPosition(viewport.startRes);
2625 // ShiftList shifts;
2626 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2627 // edit.alColumnChanges=shifts.getInverse();
2628 // if (viewport.hasHiddenColumns)
2629 // viewport.getColumnSelection().compensateForEdits(shifts);
2630 viewport.setStartRes(seq.findIndex(startRes) - 1);
2631 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2643 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2645 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2648 if (viewport.getSelectionGroup() != null)
2650 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2651 viewport.getHiddenRepSequences());
2652 start = viewport.getSelectionGroup().getStartRes();
2653 end = viewport.getSelectionGroup().getEndRes();
2657 seqs = viewport.getAlignment().getSequencesArray();
2660 // This is to maintain viewport position on first residue
2661 // of first sequence
2662 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2663 int startRes = seq.findPosition(viewport.startRes);
2665 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2666 viewport.getAlignment()));
2668 viewport.setStartRes(seq.findIndex(startRes) - 1);
2670 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2682 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2684 viewport.setPadGaps(padGapsMenuitem.isSelected());
2685 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2696 public void findMenuItem_actionPerformed(ActionEvent e)
2702 * Create a new view of the current alignment.
2705 public void newView_actionPerformed(ActionEvent e)
2707 newView(null, true);
2711 * Creates and shows a new view of the current alignment.
2714 * title of newly created view; if null, one will be generated
2715 * @param copyAnnotation
2716 * if true then duplicate all annnotation, groups and settings
2717 * @return new alignment panel, already displayed.
2719 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2722 * Create a new AlignmentPanel (with its own, new Viewport)
2724 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2726 if (!copyAnnotation)
2729 * remove all groups and annotation except for the automatic stuff
2731 newap.av.getAlignment().deleteAllGroups();
2732 newap.av.getAlignment().deleteAllAnnotations(false);
2735 newap.av.setGatherViewsHere(false);
2737 if (viewport.viewName == null)
2739 viewport.viewName = MessageManager
2740 .getString("label.view_name_original");
2744 * Views share the same edits undo and redo stacks
2746 newap.av.setHistoryList(viewport.getHistoryList());
2747 newap.av.setRedoList(viewport.getRedoList());
2750 * Views share the same mappings; need to deregister any new mappings
2751 * created by copyAlignPanel, and register the new reference to the shared
2754 newap.av.replaceMappings(viewport.getAlignment());
2756 newap.av.viewName = getNewViewName(viewTitle);
2758 addAlignmentPanel(newap, true);
2759 newap.alignmentChanged();
2761 if (alignPanels.size() == 2)
2763 viewport.setGatherViewsHere(true);
2765 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2770 * Make a new name for the view, ensuring it is unique within the current
2771 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2772 * these now use viewId. Unique view names are still desirable for usability.)
2777 protected String getNewViewName(String viewTitle)
2779 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2780 boolean addFirstIndex = false;
2781 if (viewTitle == null || viewTitle.trim().length() == 0)
2783 viewTitle = MessageManager.getString("action.view");
2784 addFirstIndex = true;
2788 index = 1;// we count from 1 if given a specific name
2790 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2792 List<Component> comps = PaintRefresher.components.get(viewport
2793 .getSequenceSetId());
2795 List<String> existingNames = getExistingViewNames(comps);
2797 while (existingNames.contains(newViewName))
2799 newViewName = viewTitle + " " + (++index);
2805 * Returns a list of distinct view names found in the given list of
2806 * components. View names are held on the viewport of an AlignmentPanel.
2811 protected List<String> getExistingViewNames(List<Component> comps)
2813 List<String> existingNames = new ArrayList<String>();
2814 for (Component comp : comps)
2816 if (comp instanceof AlignmentPanel)
2818 AlignmentPanel ap = (AlignmentPanel) comp;
2819 if (!existingNames.contains(ap.av.viewName))
2821 existingNames.add(ap.av.viewName);
2825 return existingNames;
2829 * Explode tabbed views into separate windows.
2832 public void expandViews_actionPerformed(ActionEvent e)
2834 Desktop.instance.explodeViews(this);
2838 * Gather views in separate windows back into a tabbed presentation.
2841 public void gatherViews_actionPerformed(ActionEvent e)
2843 Desktop.instance.gatherViews(this);
2853 public void font_actionPerformed(ActionEvent e)
2855 new FontChooser(alignPanel);
2865 protected void seqLimit_actionPerformed(ActionEvent e)
2867 viewport.setShowJVSuffix(seqLimits.isSelected());
2869 alignPanel.getIdPanel().getIdCanvas()
2870 .setPreferredSize(alignPanel.calculateIdWidth());
2871 alignPanel.paintAlignment(true);
2875 public void idRightAlign_actionPerformed(ActionEvent e)
2877 viewport.setRightAlignIds(idRightAlign.isSelected());
2878 alignPanel.paintAlignment(true);
2882 public void centreColumnLabels_actionPerformed(ActionEvent e)
2884 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2885 alignPanel.paintAlignment(true);
2891 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2894 protected void followHighlight_actionPerformed()
2897 * Set the 'follow' flag on the Viewport (and scroll to position if now
2900 final boolean state = this.followHighlightMenuItem.getState();
2901 viewport.setFollowHighlight(state);
2904 alignPanel.scrollToPosition(
2905 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2916 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2918 viewport.setColourText(colourTextMenuItem.isSelected());
2919 alignPanel.paintAlignment(true);
2929 public void wrapMenuItem_actionPerformed(ActionEvent e)
2931 scaleAbove.setVisible(wrapMenuItem.isSelected());
2932 scaleLeft.setVisible(wrapMenuItem.isSelected());
2933 scaleRight.setVisible(wrapMenuItem.isSelected());
2934 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2935 alignPanel.updateLayout();
2939 public void showAllSeqs_actionPerformed(ActionEvent e)
2941 viewport.showAllHiddenSeqs();
2945 public void showAllColumns_actionPerformed(ActionEvent e)
2947 viewport.showAllHiddenColumns();
2949 viewport.sendSelection();
2953 public void hideSelSequences_actionPerformed(ActionEvent e)
2955 viewport.hideAllSelectedSeqs();
2956 // alignPanel.paintAlignment(true);
2960 * called by key handler and the hide all/show all menu items
2965 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2968 boolean hide = false;
2969 SequenceGroup sg = viewport.getSelectionGroup();
2970 if (!toggleSeqs && !toggleCols)
2972 // Hide everything by the current selection - this is a hack - we do the
2973 // invert and then hide
2974 // first check that there will be visible columns after the invert.
2975 if ((viewport.getColumnSelection() != null
2976 && viewport.getColumnSelection().getSelected() != null && viewport
2977 .getColumnSelection().getSelected().size() > 0)
2978 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2981 // now invert the sequence set, if required - empty selection implies
2982 // that no hiding is required.
2985 invertSequenceMenuItem_actionPerformed(null);
2986 sg = viewport.getSelectionGroup();
2990 viewport.expandColSelection(sg, true);
2991 // finally invert the column selection and get the new sequence
2993 invertColSel_actionPerformed(null);
3000 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3002 hideSelSequences_actionPerformed(null);
3005 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3008 showAllSeqs_actionPerformed(null);
3014 if (viewport.getColumnSelection().getSelected().size() > 0)
3016 hideSelColumns_actionPerformed(null);
3019 viewport.setSelectionGroup(sg);
3024 showAllColumns_actionPerformed(null);
3033 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3034 * event.ActionEvent)
3037 public void hideAllButSelection_actionPerformed(ActionEvent e)
3039 toggleHiddenRegions(false, false);
3040 viewport.sendSelection();
3047 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3051 public void hideAllSelection_actionPerformed(ActionEvent e)
3053 SequenceGroup sg = viewport.getSelectionGroup();
3054 viewport.expandColSelection(sg, false);
3055 viewport.hideAllSelectedSeqs();
3056 viewport.hideSelectedColumns();
3057 alignPanel.paintAlignment(true);
3058 viewport.sendSelection();
3065 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3069 public void showAllhidden_actionPerformed(ActionEvent e)
3071 viewport.showAllHiddenColumns();
3072 viewport.showAllHiddenSeqs();
3073 alignPanel.paintAlignment(true);
3074 viewport.sendSelection();
3078 public void hideSelColumns_actionPerformed(ActionEvent e)
3080 viewport.hideSelectedColumns();
3081 alignPanel.paintAlignment(true);
3082 viewport.sendSelection();
3086 public void hiddenMarkers_actionPerformed(ActionEvent e)
3088 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3099 protected void scaleAbove_actionPerformed(ActionEvent e)
3101 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3102 alignPanel.paintAlignment(true);
3112 protected void scaleLeft_actionPerformed(ActionEvent e)
3114 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3115 alignPanel.paintAlignment(true);
3125 protected void scaleRight_actionPerformed(ActionEvent e)
3127 viewport.setScaleRightWrapped(scaleRight.isSelected());
3128 alignPanel.paintAlignment(true);
3138 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3140 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3141 alignPanel.paintAlignment(true);
3151 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3153 viewport.setShowText(viewTextMenuItem.isSelected());
3154 alignPanel.paintAlignment(true);
3164 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3166 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3167 alignPanel.paintAlignment(true);
3170 public FeatureSettings featureSettings;
3173 public FeatureSettingsControllerI getFeatureSettingsUI()
3175 return featureSettings;
3179 public void featureSettings_actionPerformed(ActionEvent e)
3181 if (featureSettings != null)
3183 featureSettings.close();
3184 featureSettings = null;
3186 if (!showSeqFeatures.isSelected())
3188 // make sure features are actually displayed
3189 showSeqFeatures.setSelected(true);
3190 showSeqFeatures_actionPerformed(null);
3192 featureSettings = new FeatureSettings(this);
3196 * Set or clear 'Show Sequence Features'
3202 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3204 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3205 alignPanel.paintAlignment(true);
3206 if (alignPanel.getOverviewPanel() != null)
3208 alignPanel.getOverviewPanel().updateOverviewImage();
3213 * Set or clear 'Show Sequence Features'
3219 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3221 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3223 if (viewport.isShowSequenceFeaturesHeight())
3225 // ensure we're actually displaying features
3226 viewport.setShowSequenceFeatures(true);
3227 showSeqFeatures.setSelected(true);
3229 alignPanel.paintAlignment(true);
3230 if (alignPanel.getOverviewPanel() != null)
3232 alignPanel.getOverviewPanel().updateOverviewImage();
3237 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3238 * the annotations panel as a whole.
3240 * The options to show/hide all annotations should be enabled when the panel
3241 * is shown, and disabled when the panel is hidden.
3246 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3248 final boolean setVisible = annotationPanelMenuItem.isSelected();
3249 viewport.setShowAnnotation(setVisible);
3250 this.showAllSeqAnnotations.setEnabled(setVisible);
3251 this.hideAllSeqAnnotations.setEnabled(setVisible);
3252 this.showAllAlAnnotations.setEnabled(setVisible);
3253 this.hideAllAlAnnotations.setEnabled(setVisible);
3254 alignPanel.updateLayout();
3258 public void alignmentProperties()
3260 JEditorPane editPane = new JEditorPane("text/html", "");
3261 editPane.setEditable(false);
3262 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3264 editPane.setText(MessageManager.formatMessage("label.html_content",
3265 new Object[] { contents.toString() }));
3266 JInternalFrame frame = new JInternalFrame();
3267 frame.getContentPane().add(new JScrollPane(editPane));
3269 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3270 "label.alignment_properties", new Object[] { getTitle() }),
3281 public void overviewMenuItem_actionPerformed(ActionEvent e)
3283 if (alignPanel.overviewPanel != null)
3288 JInternalFrame frame = new JInternalFrame();
3289 OverviewPanel overview = new OverviewPanel(alignPanel);
3290 frame.setContentPane(overview);
3291 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3292 "label.overview_params", new Object[] { this.getTitle() }),
3293 frame.getWidth(), frame.getHeight());
3295 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3296 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3299 public void internalFrameClosed(
3300 javax.swing.event.InternalFrameEvent evt)
3302 alignPanel.setOverviewPanel(null);
3306 alignPanel.setOverviewPanel(overview);
3310 public void textColour_actionPerformed(ActionEvent e)
3312 new TextColourChooser().chooseColour(alignPanel, null);
3322 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3334 public void clustalColour_actionPerformed(ActionEvent e)
3336 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3337 viewport.getHiddenRepSequences()));
3347 public void zappoColour_actionPerformed(ActionEvent e)
3349 changeColour(new ZappoColourScheme());
3359 public void taylorColour_actionPerformed(ActionEvent e)
3361 changeColour(new TaylorColourScheme());
3371 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3373 changeColour(new HydrophobicColourScheme());
3383 public void helixColour_actionPerformed(ActionEvent e)
3385 changeColour(new HelixColourScheme());
3395 public void strandColour_actionPerformed(ActionEvent e)
3397 changeColour(new StrandColourScheme());
3407 public void turnColour_actionPerformed(ActionEvent e)
3409 changeColour(new TurnColourScheme());
3419 public void buriedColour_actionPerformed(ActionEvent e)
3421 changeColour(new BuriedColourScheme());
3431 public void nucleotideColour_actionPerformed(ActionEvent e)
3433 changeColour(new NucleotideColourScheme());
3437 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3439 changeColour(new PurinePyrimidineColourScheme());
3443 * public void covariationColour_actionPerformed(ActionEvent e) {
3445 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3449 public void annotationColour_actionPerformed(ActionEvent e)
3451 new AnnotationColourChooser(viewport, alignPanel);
3455 public void annotationColumn_actionPerformed(ActionEvent e)
3457 new AnnotationColumnChooser(viewport, alignPanel);
3461 public void rnahelicesColour_actionPerformed(ActionEvent e)
3463 new RNAHelicesColourChooser(viewport, alignPanel);
3473 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3475 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3485 public void changeColour(ColourSchemeI cs)
3487 // TODO: pull up to controller method
3491 // Make sure viewport is up to date w.r.t. any sliders
3492 if (viewport.getAbovePIDThreshold())
3494 int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3496 viewport.setThreshold(threshold);
3499 if (viewport.getConservationSelected())
3501 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3504 if (cs instanceof TCoffeeColourScheme)
3506 tcoffeeColour.setEnabled(true);
3507 tcoffeeColour.setSelected(true);
3511 viewport.setGlobalColourScheme(cs);
3513 alignPanel.paintAlignment(true);
3523 protected void modifyPID_actionPerformed(ActionEvent e)
3525 if (viewport.getAbovePIDThreshold()
3526 && viewport.getGlobalColourScheme() != null)
3528 SliderPanel.setPIDSliderSource(alignPanel,
3529 viewport.getGlobalColourScheme(), "Background");
3530 SliderPanel.showPIDSlider();
3541 protected void modifyConservation_actionPerformed(ActionEvent e)
3543 if (viewport.getConservationSelected()
3544 && viewport.getGlobalColourScheme() != null)
3546 SliderPanel.setConservationSlider(alignPanel,
3547 viewport.getGlobalColourScheme(), "Background");
3548 SliderPanel.showConservationSlider();
3559 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3561 viewport.setConservationSelected(conservationMenuItem.isSelected());
3563 viewport.setAbovePIDThreshold(false);
3564 abovePIDThreshold.setSelected(false);
3566 changeColour(viewport.getGlobalColourScheme());
3568 modifyConservation_actionPerformed(null);
3578 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3580 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3582 conservationMenuItem.setSelected(false);
3583 viewport.setConservationSelected(false);
3585 changeColour(viewport.getGlobalColourScheme());
3587 modifyPID_actionPerformed(null);
3597 public void userDefinedColour_actionPerformed(ActionEvent e)
3599 if (e.getActionCommand().equals(
3600 MessageManager.getString("action.user_defined")))
3602 new UserDefinedColours(alignPanel, null);
3606 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3607 .getUserColourSchemes().get(e.getActionCommand());
3613 public void updateUserColourMenu()
3616 Component[] menuItems = colourMenu.getMenuComponents();
3617 int iSize = menuItems.length;
3618 for (int i = 0; i < iSize; i++)
3620 if (menuItems[i].getName() != null
3621 && menuItems[i].getName().equals("USER_DEFINED"))
3623 colourMenu.remove(menuItems[i]);
3627 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3629 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3630 .getUserColourSchemes().keys();
3632 while (userColours.hasMoreElements())
3634 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3635 userColours.nextElement().toString());
3636 radioItem.setName("USER_DEFINED");
3637 radioItem.addMouseListener(new MouseAdapter()
3640 public void mousePressed(MouseEvent evt)
3642 if (evt.isPopupTrigger())
3644 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3646 int option = JOptionPane.showInternalConfirmDialog(
3647 jalview.gui.Desktop.desktop,
3649 .getString("label.remove_from_default_list"),
3651 .getString("label.remove_user_defined_colour"),
3652 JOptionPane.YES_NO_OPTION);
3653 if (option == JOptionPane.YES_OPTION)
3655 jalview.gui.UserDefinedColours
3656 .removeColourFromDefaults(radioItem.getText());
3657 colourMenu.remove(radioItem);
3661 radioItem.addActionListener(new ActionListener()
3664 public void actionPerformed(ActionEvent evt)
3666 userDefinedColour_actionPerformed(evt);
3673 radioItem.addActionListener(new ActionListener()
3676 public void actionPerformed(ActionEvent evt)
3678 userDefinedColour_actionPerformed(evt);
3682 colourMenu.insert(radioItem, 15);
3683 colours.add(radioItem);
3695 public void PIDColour_actionPerformed(ActionEvent e)
3697 changeColour(new PIDColourScheme());
3707 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3709 changeColour(new Blosum62ColourScheme());
3719 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3721 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3722 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3723 .getAlignment().getSequenceAt(0), null);
3724 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3725 viewport.getAlignment()));
3726 alignPanel.paintAlignment(true);
3736 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3738 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3739 AlignmentSorter.sortByID(viewport.getAlignment());
3740 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3741 viewport.getAlignment()));
3742 alignPanel.paintAlignment(true);
3752 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3754 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3755 AlignmentSorter.sortByLength(viewport.getAlignment());
3756 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3757 viewport.getAlignment()));
3758 alignPanel.paintAlignment(true);
3768 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3770 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3771 AlignmentSorter.sortByGroup(viewport.getAlignment());
3772 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3773 viewport.getAlignment()));
3775 alignPanel.paintAlignment(true);
3785 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3787 new RedundancyPanel(alignPanel, this);
3797 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3799 if ((viewport.getSelectionGroup() == null)
3800 || (viewport.getSelectionGroup().getSize() < 2))
3802 JOptionPane.showInternalMessageDialog(this, MessageManager
3803 .getString("label.you_must_select_least_two_sequences"),
3804 MessageManager.getString("label.invalid_selection"),
3805 JOptionPane.WARNING_MESSAGE);
3809 JInternalFrame frame = new JInternalFrame();
3810 frame.setContentPane(new PairwiseAlignPanel(viewport));
3811 Desktop.addInternalFrame(frame,
3812 MessageManager.getString("action.pairwise_alignment"), 600,
3824 public void PCAMenuItem_actionPerformed(ActionEvent e)
3826 if (((viewport.getSelectionGroup() != null)
3827 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3828 .getSelectionGroup().getSize() > 0))
3829 || (viewport.getAlignment().getHeight() < 4))
3832 .showInternalMessageDialog(
3835 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3837 .getString("label.sequence_selection_insufficient"),
3838 JOptionPane.WARNING_MESSAGE);
3843 new PCAPanel(alignPanel);
3847 public void autoCalculate_actionPerformed(ActionEvent e)
3849 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3850 if (viewport.autoCalculateConsensus)
3852 viewport.firePropertyChange("alignment", null, viewport
3853 .getAlignment().getSequences());
3858 public void sortByTreeOption_actionPerformed(ActionEvent e)
3860 viewport.sortByTree = sortByTree.isSelected();
3864 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3866 viewport.followSelection = listenToViewSelections.isSelected();
3876 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3878 newTreePanel("AV", "PID", "Average distance tree using PID");
3888 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3890 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3900 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3902 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3912 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3914 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3927 void newTreePanel(String type, String pwType, String title)
3931 if (viewport.getSelectionGroup() != null
3932 && viewport.getSelectionGroup().getSize() > 0)
3934 if (viewport.getSelectionGroup().getSize() < 3)
3940 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3942 .getString("label.not_enough_sequences"),
3943 JOptionPane.WARNING_MESSAGE);
3947 SequenceGroup sg = viewport.getSelectionGroup();
3949 /* Decide if the selection is a column region */
3950 for (SequenceI _s : sg.getSequences())
3952 if (_s.getLength() < sg.getEndRes())
3958 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3960 .getString("label.sequences_selection_not_aligned"),
3961 JOptionPane.WARNING_MESSAGE);
3967 title = title + " on region";
3968 tp = new TreePanel(alignPanel, type, pwType);
3972 // are the visible sequences aligned?
3973 if (!viewport.getAlignment().isAligned(false))
3979 .getString("label.sequences_must_be_aligned_before_creating_tree"),
3981 .getString("label.sequences_not_aligned"),
3982 JOptionPane.WARNING_MESSAGE);
3987 if (viewport.getAlignment().getHeight() < 2)
3992 tp = new TreePanel(alignPanel, type, pwType);
3997 if (viewport.viewName != null)
3999 title += viewport.viewName + " of ";
4002 title += this.title;
4004 Desktop.addInternalFrame(tp, title, 600, 500);
4015 public void addSortByOrderMenuItem(String title,
4016 final AlignmentOrder order)
4018 final JMenuItem item = new JMenuItem(MessageManager.formatMessage(
4019 "action.by_title_param", new Object[] { title }));
4021 item.addActionListener(new java.awt.event.ActionListener()
4024 public void actionPerformed(ActionEvent e)
4026 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4028 // TODO: JBPNote - have to map order entries to curent SequenceI
4030 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4032 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4035 alignPanel.paintAlignment(true);
4041 * Add a new sort by annotation score menu item
4044 * the menu to add the option to
4046 * the label used to retrieve scores for each sequence on the
4049 public void addSortByAnnotScoreMenuItem(JMenu sort,
4050 final String scoreLabel)
4052 final JMenuItem item = new JMenuItem(scoreLabel);
4054 item.addActionListener(new java.awt.event.ActionListener()
4057 public void actionPerformed(ActionEvent e)
4059 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4060 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4061 viewport.getAlignment());// ,viewport.getSelectionGroup());
4062 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4063 viewport.getAlignment()));
4064 alignPanel.paintAlignment(true);
4070 * last hash for alignment's annotation array - used to minimise cost of
4073 protected int _annotationScoreVectorHash;
4076 * search the alignment and rebuild the sort by annotation score submenu the
4077 * last alignment annotation vector hash is stored to minimize cost of
4078 * rebuilding in subsequence calls.
4082 public void buildSortByAnnotationScoresMenu()
4084 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4089 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4091 sortByAnnotScore.removeAll();
4092 // almost certainly a quicker way to do this - but we keep it simple
4093 Hashtable scoreSorts = new Hashtable();
4094 AlignmentAnnotation aann[];
4095 for (SequenceI sqa : viewport.getAlignment().getSequences())
4097 aann = sqa.getAnnotation();
4098 for (int i = 0; aann != null && i < aann.length; i++)
4100 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4102 scoreSorts.put(aann[i].label, aann[i].label);
4106 Enumeration labels = scoreSorts.keys();
4107 while (labels.hasMoreElements())
4109 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4110 (String) labels.nextElement());
4112 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4115 _annotationScoreVectorHash = viewport.getAlignment()
4116 .getAlignmentAnnotation().hashCode();
4121 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4122 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4123 * call. Listeners are added to remove the menu item when the treePanel is
4124 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4128 * Displayed tree window.
4130 * SortBy menu item title.
4133 public void buildTreeMenu()
4135 calculateTree.removeAll();
4136 // build the calculate menu
4138 for (final String type : new String[] { "NJ", "AV" })
4140 String treecalcnm = MessageManager.getString("label.tree_calc_"
4141 + type.toLowerCase());
4142 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4144 JMenuItem tm = new JMenuItem();
4145 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4146 if (sm.isDNA() == viewport.getAlignment().isNucleotide()
4147 || sm.isProtein() == !viewport.getAlignment()
4150 String smn = MessageManager.getStringOrReturn(
4151 "label.score_model_", sm.getName());
4152 final String title = MessageManager.formatMessage(
4153 "label.treecalc_title", treecalcnm, smn);
4154 tm.setText(title);//
4155 tm.addActionListener(new java.awt.event.ActionListener()
4158 public void actionPerformed(ActionEvent e)
4160 newTreePanel(type, pwtype, title);
4163 calculateTree.add(tm);
4168 sortByTreeMenu.removeAll();
4170 List<Component> comps = PaintRefresher.components.get(viewport
4171 .getSequenceSetId());
4172 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4173 for (Component comp : comps)
4175 if (comp instanceof TreePanel)
4177 treePanels.add((TreePanel) comp);
4181 if (treePanels.size() < 1)
4183 sortByTreeMenu.setVisible(false);
4187 sortByTreeMenu.setVisible(true);
4189 for (final TreePanel tp : treePanels)
4191 final JMenuItem item = new JMenuItem(tp.getTitle());
4192 item.addActionListener(new java.awt.event.ActionListener()
4195 public void actionPerformed(ActionEvent e)
4197 tp.sortByTree_actionPerformed();
4198 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4203 sortByTreeMenu.add(item);
4207 public boolean sortBy(AlignmentOrder alorder, String undoname)
4209 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4210 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4211 if (undoname != null)
4213 addHistoryItem(new OrderCommand(undoname, oldOrder,
4214 viewport.getAlignment()));
4216 alignPanel.paintAlignment(true);
4221 * Work out whether the whole set of sequences or just the selected set will
4222 * be submitted for multiple alignment.
4225 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4227 // Now, check we have enough sequences
4228 AlignmentView msa = null;
4230 if ((viewport.getSelectionGroup() != null)
4231 && (viewport.getSelectionGroup().getSize() > 1))
4233 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4234 // some common interface!
4236 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4237 * SequenceI[sz = seqs.getSize(false)];
4239 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4240 * seqs.getSequenceAt(i); }
4242 msa = viewport.getAlignmentView(true);
4244 else if (viewport.getSelectionGroup() != null
4245 && viewport.getSelectionGroup().getSize() == 1)
4247 int option = JOptionPane.showConfirmDialog(this,
4248 MessageManager.getString("warn.oneseq_msainput_selection"),
4249 MessageManager.getString("label.invalid_selection"),
4250 JOptionPane.OK_CANCEL_OPTION);
4251 if (option == JOptionPane.OK_OPTION)
4253 msa = viewport.getAlignmentView(false);
4258 msa = viewport.getAlignmentView(false);
4264 * Decides what is submitted to a secondary structure prediction service: the
4265 * first sequence in the alignment, or in the current selection, or, if the
4266 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4267 * region or the whole alignment. (where the first sequence in the set is the
4268 * one that the prediction will be for).
4270 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4272 AlignmentView seqs = null;
4274 if ((viewport.getSelectionGroup() != null)
4275 && (viewport.getSelectionGroup().getSize() > 0))
4277 seqs = viewport.getAlignmentView(true);
4281 seqs = viewport.getAlignmentView(false);
4283 // limit sequences - JBPNote in future - could spawn multiple prediction
4285 // TODO: viewport.getAlignment().isAligned is a global state - the local
4286 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4287 if (!viewport.getAlignment().isAligned(false))
4289 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4290 // TODO: if seqs.getSequences().length>1 then should really have warned
4304 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4306 // Pick the tree file
4307 JalviewFileChooser chooser = new JalviewFileChooser(
4308 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4309 chooser.setFileView(new JalviewFileView());
4310 chooser.setDialogTitle(MessageManager
4311 .getString("label.select_newick_like_tree_file"));
4312 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4314 int value = chooser.showOpenDialog(null);
4316 if (value == JalviewFileChooser.APPROVE_OPTION)
4318 String choice = chooser.getSelectedFile().getPath();
4319 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4320 jalview.io.NewickFile fin = null;
4323 fin = new jalview.io.NewickFile(choice, "File");
4324 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4325 } catch (Exception ex)
4332 .getString("label.problem_reading_tree_file"),
4333 JOptionPane.WARNING_MESSAGE);
4334 ex.printStackTrace();
4336 if (fin != null && fin.hasWarningMessage())
4338 JOptionPane.showMessageDialog(Desktop.desktop, fin
4339 .getWarningMessage(), MessageManager
4340 .getString("label.possible_problem_with_tree_file"),
4341 JOptionPane.WARNING_MESSAGE);
4347 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4349 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4352 public TreePanel ShowNewickTree(NewickFile nf, String title)
4354 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4357 public TreePanel ShowNewickTree(NewickFile nf, String title,
4358 AlignmentView input)
4360 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4363 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4364 int h, int x, int y)
4366 return ShowNewickTree(nf, title, null, w, h, x, y);
4370 * Add a treeviewer for the tree extracted from a newick file object to the
4371 * current alignment view
4378 * Associated alignment input data (or null)
4387 * @return TreePanel handle
4389 public TreePanel ShowNewickTree(NewickFile nf, String title,
4390 AlignmentView input, int w, int h, int x, int y)
4392 TreePanel tp = null;
4398 if (nf.getTree() != null)
4400 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4406 tp.setLocation(x, y);
4409 Desktop.addInternalFrame(tp, title, w, h);
4411 } catch (Exception ex)
4413 ex.printStackTrace();
4419 private boolean buildingMenu = false;
4422 * Generates menu items and listener event actions for web service clients
4425 public void BuildWebServiceMenu()
4427 while (buildingMenu)
4431 System.err.println("Waiting for building menu to finish.");
4433 } catch (Exception e)
4437 final AlignFrame me = this;
4438 buildingMenu = true;
4439 new Thread(new Runnable()
4444 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4447 // System.err.println("Building ws menu again "
4448 // + Thread.currentThread());
4449 // TODO: add support for context dependent disabling of services based
4451 // alignment and current selection
4452 // TODO: add additional serviceHandle parameter to specify abstract
4454 // class independently of AbstractName
4455 // TODO: add in rediscovery GUI function to restart discoverer
4456 // TODO: group services by location as well as function and/or
4458 // object broker mechanism.
4459 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4460 final IProgressIndicator af = me;
4461 final JMenu msawsmenu = new JMenu("Alignment");
4462 final JMenu secstrmenu = new JMenu(
4463 "Secondary Structure Prediction");
4464 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4465 final JMenu analymenu = new JMenu("Analysis");
4466 final JMenu dismenu = new JMenu("Protein Disorder");
4467 // final JMenu msawsmenu = new
4468 // JMenu(MessageManager.getString("label.alignment"));
4469 // final JMenu secstrmenu = new
4470 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4471 // final JMenu seqsrchmenu = new
4472 // JMenu(MessageManager.getString("label.sequence_database_search"));
4473 // final JMenu analymenu = new
4474 // JMenu(MessageManager.getString("label.analysis"));
4475 // final JMenu dismenu = new
4476 // JMenu(MessageManager.getString("label.protein_disorder"));
4477 // JAL-940 - only show secondary structure prediction services from
4478 // the legacy server
4479 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4481 Discoverer.services != null && (Discoverer.services.size() > 0))
4483 // TODO: refactor to allow list of AbstractName/Handler bindings to
4485 // stored or retrieved from elsewhere
4486 // No MSAWS used any more:
4487 // Vector msaws = null; // (Vector)
4488 // Discoverer.services.get("MsaWS");
4489 Vector secstrpr = (Vector) Discoverer.services
4491 if (secstrpr != null)
4493 // Add any secondary structure prediction services
4494 for (int i = 0, j = secstrpr.size(); i < j; i++)
4496 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4498 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4499 .getServiceClient(sh);
4500 int p = secstrmenu.getItemCount();
4501 impl.attachWSMenuEntry(secstrmenu, me);
4502 int q = secstrmenu.getItemCount();
4503 for (int litm = p; litm < q; litm++)
4505 legacyItems.add(secstrmenu.getItem(litm));
4511 // Add all submenus in the order they should appear on the web
4513 wsmenu.add(msawsmenu);
4514 wsmenu.add(secstrmenu);
4515 wsmenu.add(dismenu);
4516 wsmenu.add(analymenu);
4517 // No search services yet
4518 // wsmenu.add(seqsrchmenu);
4520 javax.swing.SwingUtilities.invokeLater(new Runnable()
4527 webService.removeAll();
4528 // first, add discovered services onto the webservices menu
4529 if (wsmenu.size() > 0)
4531 for (int i = 0, j = wsmenu.size(); i < j; i++)
4533 webService.add(wsmenu.get(i));
4538 webService.add(me.webServiceNoServices);
4540 // TODO: move into separate menu builder class.
4541 boolean new_sspred = false;
4542 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4544 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4545 if (jws2servs != null)
4547 if (jws2servs.hasServices())
4549 jws2servs.attachWSMenuEntry(webService, me);
4550 for (Jws2Instance sv : jws2servs.getServices())
4552 if (sv.description.toLowerCase().contains("jpred"))
4554 for (JMenuItem jmi : legacyItems)
4556 jmi.setVisible(false);
4562 if (jws2servs.isRunning())
4564 JMenuItem tm = new JMenuItem(
4565 "Still discovering JABA Services");
4566 tm.setEnabled(false);
4571 build_urlServiceMenu(me.webService);
4572 build_fetchdbmenu(webService);
4573 for (JMenu item : wsmenu)
4575 if (item.getItemCount() == 0)
4577 item.setEnabled(false);
4581 item.setEnabled(true);
4584 } catch (Exception e)
4587 .debug("Exception during web service menu building process.",
4592 } catch (Exception e)
4595 buildingMenu = false;
4602 * construct any groupURL type service menu entries.
4606 private void build_urlServiceMenu(JMenu webService)
4608 // TODO: remove this code when 2.7 is released
4609 // DEBUG - alignmentView
4611 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4612 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4614 * @Override public void actionPerformed(ActionEvent e) {
4615 * jalview.datamodel.AlignmentView
4616 * .testSelectionViews(af.viewport.getAlignment(),
4617 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4619 * }); webService.add(testAlView);
4621 // TODO: refactor to RestClient discoverer and merge menu entries for
4622 // rest-style services with other types of analysis/calculation service
4623 // SHmmr test client - still being implemented.
4624 // DEBUG - alignmentView
4626 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4629 client.attachWSMenuEntry(
4630 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4636 * Searches the alignment sequences for xRefs and builds the Show
4637 * Cross-References menu (formerly called Show Products), with database
4638 * sources for which cross-references are found (protein sources for a
4639 * nucleotide alignment and vice versa)
4641 * @return true if Show Cross-references menu should be enabled
4643 public boolean canShowProducts()
4645 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4646 AlignmentI dataset = viewport.getAlignment().getDataset();
4647 boolean showp = false;
4650 showProducts.removeAll();
4651 final boolean dna = viewport.getAlignment().isNucleotide();
4652 List<String> ptypes = (seqs == null || seqs.length == 0) ? null
4653 : new CrossRef(seqs, dataset)
4654 .findXrefSourcesForSequences(dna);
4656 for (final String source : ptypes)
4659 final AlignFrame af = this;
4660 JMenuItem xtype = new JMenuItem(source);
4661 xtype.addActionListener(new ActionListener()
4664 public void actionPerformed(ActionEvent e)
4666 showProductsFor(af.viewport.getSequenceSelection(), dna, source);
4669 showProducts.add(xtype);
4671 showProducts.setVisible(showp);
4672 showProducts.setEnabled(showp);
4673 } catch (Exception e)
4676 .warn("canShowProducts threw an exception - please report to help@jalview.org",
4684 * Finds and displays cross-references for the selected sequences (protein
4685 * products for nucleotide sequences, dna coding sequences for peptides).
4688 * the sequences to show cross-references for
4690 * true if from a nucleotide alignment (so showing proteins)
4692 * the database to show cross-references for
4694 protected void showProductsFor(final SequenceI[] sel,
4695 final boolean _odna, final String source)
4697 Runnable foo = new Runnable()
4703 final long sttime = System.currentTimeMillis();
4704 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4705 "status.searching_for_sequences_from",
4706 new Object[] { source }), sttime);
4709 AlignmentI alignment = AlignFrame.this.getViewport()
4711 AlignmentI dataset = alignment.getDataset() == null ? alignment
4712 : alignment.getDataset();
4713 boolean dna = alignment.isNucleotide();
4717 .println("Conflict: showProducts for alignment originally "
4719 + (_odna ? "DNA" : "Protein")
4720 + " now searching for "
4721 + (dna ? "DNA" : "Protein") + " Context.");
4723 AlignmentI xrefs = new CrossRef(sel, dataset).findXrefSequences(
4730 * get display scheme (if any) to apply to features
4732 FeatureSettingsModelI featureColourScheme = new SequenceFetcher()
4733 .getFeatureColourScheme(source);
4735 AlignmentI xrefsAlignment = makeCrossReferencesAlignment(dataset,
4739 xrefsAlignment = AlignmentUtils.makeCdsAlignment(
4740 xrefsAlignment.getSequencesArray(), dataset, sel);
4741 xrefsAlignment.alignAs(alignment);
4745 * If we are opening a splitframe, make a copy of this alignment (sharing the same dataset
4746 * sequences). If we are DNA, drop introns and update mappings
4748 AlignmentI copyAlignment = null;
4750 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4752 boolean copyAlignmentIsAligned = false;
4755 copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset,
4756 xrefsAlignment.getSequencesArray());
4757 if (copyAlignment.getHeight() == 0)
4759 System.err.println("Failed to make CDS alignment");
4763 * pending getting Embl transcripts to 'align',
4764 * we are only doing this for Ensembl
4766 // TODO proper criteria for 'can align as cdna'
4767 if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
4768 || AlignmentUtils.looksLikeEnsembl(alignment))
4770 copyAlignment.alignAs(alignment);
4771 copyAlignmentIsAligned = true;
4776 copyAlignment = AlignmentUtils.makeCopyAlignment(sel,
4777 xrefs.getSequencesArray(), dataset);
4779 copyAlignment.setGapCharacter(AlignFrame.this.viewport
4780 .getGapCharacter());
4782 StructureSelectionManager ssm = StructureSelectionManager
4783 .getStructureSelectionManager(Desktop.instance);
4786 * register any new mappings for sequence mouseover etc
4787 * (will not duplicate any previously registered mappings)
4789 ssm.registerMappings(dataset.getCodonFrames());
4791 if (copyAlignment.getHeight() <= 0)
4793 System.err.println("No Sequences generated for xRef type "
4798 * align protein to dna
4800 if (dna && copyAlignmentIsAligned)
4802 xrefsAlignment.alignAs(copyAlignment);
4807 * align cdna to protein - currently only if
4808 * fetching and aligning Ensembl transcripts!
4810 // TODO: generalise for other sources of locus/transcript/cds data
4811 if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source))
4813 copyAlignment.alignAs(xrefsAlignment);
4818 * build AlignFrame(s) according to available alignment data
4820 AlignFrame newFrame = new AlignFrame(xrefsAlignment,
4821 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4822 if (Cache.getDefault("HIDE_INTRONS", true))
4824 newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false);
4826 String newtitle = String.format("%s %s %s", MessageManager
4827 .getString(dna ? "label.proteins" : "label.nucleotides"),
4828 MessageManager.getString("label.for"), getTitle());
4829 newFrame.setTitle(newtitle);
4831 if (copyAlignment == null)
4834 * split frame display is turned off in preferences file
4836 Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
4838 return; // via finally clause
4840 AlignFrame copyThis = new AlignFrame(copyAlignment,
4841 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4842 copyThis.setTitle(AlignFrame.this.getTitle());
4844 boolean showSequenceFeatures = viewport.isShowSequenceFeatures();
4845 newFrame.setShowSeqFeatures(showSequenceFeatures);
4846 copyThis.setShowSeqFeatures(showSequenceFeatures);
4847 FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas
4848 .getFeatureRenderer();
4851 * copy feature rendering settings to split frame
4853 newFrame.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
4854 .transferSettings(myFeatureStyling);
4855 copyThis.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
4856 .transferSettings(myFeatureStyling);
4859 * apply 'database source' feature configuration
4862 // TODO is this the feature colouring for the original
4863 // alignment or the fetched xrefs? either could be Ensembl
4864 newFrame.getViewport().applyFeaturesStyle(featureColourScheme);
4865 copyThis.getViewport().applyFeaturesStyle(featureColourScheme);
4867 SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame,
4868 dna ? newFrame : copyThis);
4869 newFrame.setVisible(true);
4870 copyThis.setVisible(true);
4871 String linkedTitle = MessageManager
4872 .getString("label.linked_view_title");
4873 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4875 } catch (OutOfMemoryError e)
4877 new OOMWarning("whilst fetching crossreferences", e);
4878 } catch (Throwable e)
4880 Cache.log.error("Error when finding crossreferences", e);
4883 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4884 "status.finished_searching_for_sequences_from",
4885 new Object[] { source }), sttime);
4890 * Makes an alignment containing the given sequences, and adds them to the
4891 * given dataset, which is also set as the dataset for the new alignment
4893 * TODO: refactor to DatasetI method
4899 protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,
4902 SequenceI[] sprods = new SequenceI[seqs.getHeight()];
4903 for (int s = 0; s < sprods.length; s++)
4905 sprods[s] = (seqs.getSequenceAt(s)).deriveSequence();
4906 if (dataset.getSequences() == null
4907 || !dataset.getSequences().contains(
4908 sprods[s].getDatasetSequence()))
4910 dataset.addSequence(sprods[s].getDatasetSequence());
4912 sprods[s].updatePDBIds();
4914 Alignment al = new Alignment(sprods);
4915 al.setDataset(dataset);
4920 Thread frunner = new Thread(foo);
4925 * Construct and display a new frame containing the translation of this
4926 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4929 public void showTranslation_actionPerformed(ActionEvent e)
4931 AlignmentI al = null;
4934 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4936 al = dna.translateCdna();
4937 } catch (Exception ex)
4939 jalview.bin.Cache.log.error(
4940 "Exception during translation. Please report this !", ex);
4941 final String msg = MessageManager
4942 .getString("label.error_when_translating_sequences_submit_bug_report");
4943 final String errorTitle = MessageManager
4944 .getString("label.implementation_error")
4945 + MessageManager.getString("label.translation_failed");
4946 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4947 JOptionPane.ERROR_MESSAGE);
4950 if (al == null || al.getHeight() == 0)
4952 final String msg = MessageManager
4953 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4954 final String errorTitle = MessageManager
4955 .getString("label.translation_failed");
4956 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4957 JOptionPane.WARNING_MESSAGE);
4961 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4962 af.setFileFormat(this.currentFileFormat);
4963 final String newTitle = MessageManager.formatMessage(
4964 "label.translation_of_params",
4965 new Object[] { this.getTitle() });
4966 af.setTitle(newTitle);
4967 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4969 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4970 viewport.openSplitFrame(af, new Alignment(seqs));
4974 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4981 * Set the file format
4985 public void setFileFormat(String fileFormat)
4987 this.currentFileFormat = fileFormat;
4991 * Try to load a features file onto the alignment.
4994 * contents or path to retrieve file
4996 * access mode of file (see jalview.io.AlignFile)
4997 * @return true if features file was parsed correctly.
4999 public boolean parseFeaturesFile(String file, String type)
5001 return avc.parseFeaturesFile(file, type,
5002 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5007 public void refreshFeatureUI(boolean enableIfNecessary)
5009 // note - currently this is only still here rather than in the controller
5010 // because of the featureSettings hard reference that is yet to be
5012 if (enableIfNecessary)
5014 viewport.setShowSequenceFeatures(true);
5015 showSeqFeatures.setSelected(true);
5021 public void dragEnter(DropTargetDragEvent evt)
5026 public void dragExit(DropTargetEvent evt)
5031 public void dragOver(DropTargetDragEvent evt)
5036 public void dropActionChanged(DropTargetDragEvent evt)
5041 public void drop(DropTargetDropEvent evt)
5043 Transferable t = evt.getTransferable();
5044 java.util.List<String> files = new ArrayList<String>(), protocols = new ArrayList<String>();
5048 Desktop.transferFromDropTarget(files, protocols, evt, t);
5049 } catch (Exception e)
5051 e.printStackTrace();
5057 // check to see if any of these files have names matching sequences in
5059 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5060 .getAlignment().getSequencesArray());
5062 * Object[] { String,SequenceI}
5064 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5065 ArrayList<String> filesnotmatched = new ArrayList<String>();
5066 for (int i = 0; i < files.size(); i++)
5068 String file = files.get(i).toString();
5070 String protocol = FormatAdapter.checkProtocol(file);
5071 if (protocol == jalview.io.FormatAdapter.FILE)
5073 File fl = new File(file);
5074 pdbfn = fl.getName();
5076 else if (protocol == jalview.io.FormatAdapter.URL)
5078 URL url = new URL(file);
5079 pdbfn = url.getFile();
5081 if (pdbfn.length() > 0)
5083 // attempt to find a match in the alignment
5084 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5085 int l = 0, c = pdbfn.indexOf(".");
5086 while (mtch == null && c != -1)
5091 } while ((c = pdbfn.indexOf(".", l)) > l);
5094 pdbfn = pdbfn.substring(0, l);
5096 mtch = idm.findAllIdMatches(pdbfn);
5103 type = new IdentifyFile().identify(file, protocol);
5104 } catch (Exception ex)
5110 if (type.equalsIgnoreCase("PDB"))
5112 filesmatched.add(new Object[] { file, protocol, mtch });
5117 // File wasn't named like one of the sequences or wasn't a PDB file.
5118 filesnotmatched.add(file);
5122 if (filesmatched.size() > 0)
5124 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5130 "label.automatically_associate_pdb_files_with_sequences_same_name",
5131 new Object[] { Integer
5137 .getString("label.automatically_associate_pdb_files_by_name"),
5138 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5141 for (Object[] fm : filesmatched)
5143 // try and associate
5144 // TODO: may want to set a standard ID naming formalism for
5145 // associating PDB files which have no IDs.
5146 for (SequenceI toassoc : (SequenceI[]) fm[2])
5148 PDBEntry pe = new AssociatePdbFileWithSeq()
5149 .associatePdbWithSeq((String) fm[0],
5150 (String) fm[1], toassoc, false,
5154 System.err.println("Associated file : "
5155 + ((String) fm[0]) + " with "
5156 + toassoc.getDisplayId(true));
5160 alignPanel.paintAlignment(true);
5164 if (filesnotmatched.size() > 0)
5167 && (Cache.getDefault(
5168 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5174 "label.ignore_unmatched_dropped_files_info",
5175 new Object[] { Integer
5182 .getString("label.ignore_unmatched_dropped_files"),
5183 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5187 for (String fn : filesnotmatched)
5189 loadJalviewDataFile(fn, null, null, null);
5193 } catch (Exception ex)
5195 ex.printStackTrace();
5201 * Attempt to load a "dropped" file or URL string: First by testing whether
5202 * it's an Annotation file, then a JNet file, and finally a features file. If
5203 * all are false then the user may have dropped an alignment file onto this
5207 * either a filename or a URL string.
5209 public void loadJalviewDataFile(String file, String protocol,
5210 String format, SequenceI assocSeq)
5214 if (protocol == null)
5216 protocol = FormatAdapter.checkProtocol(file);
5218 // if the file isn't identified, or not positively identified as some
5219 // other filetype (PFAM is default unidentified alignment file type) then
5220 // try to parse as annotation.
5221 boolean isAnnotation = (format == null || format
5222 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5223 .annotateAlignmentView(viewport, file, protocol) : false;
5227 // first see if its a T-COFFEE score file
5228 TCoffeeScoreFile tcf = null;
5231 tcf = new TCoffeeScoreFile(file, protocol);
5234 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5236 tcoffeeColour.setEnabled(true);
5237 tcoffeeColour.setSelected(true);
5238 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5239 isAnnotation = true;
5241 .setText(MessageManager
5242 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5246 // some problem - if no warning its probable that the ID matching
5247 // process didn't work
5251 tcf.getWarningMessage() == null ? MessageManager
5252 .getString("label.check_file_matches_sequence_ids_alignment")
5253 : tcf.getWarningMessage(),
5255 .getString("label.problem_reading_tcoffee_score_file"),
5256 JOptionPane.WARNING_MESSAGE);
5263 } catch (Exception x)
5266 .debug("Exception when processing data source as T-COFFEE score file",
5272 // try to see if its a JNet 'concise' style annotation file *before*
5274 // try to parse it as a features file
5277 format = new IdentifyFile().identify(file, protocol);
5279 if (format.equalsIgnoreCase("JnetFile"))
5281 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5283 new JnetAnnotationMaker();
5284 JnetAnnotationMaker.add_annotation(predictions,
5285 viewport.getAlignment(), 0, false);
5286 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5287 viewport.getAlignment().setSeqrep(repseq);
5288 ColumnSelection cs = new ColumnSelection();
5289 cs.hideInsertionsFor(repseq);
5290 viewport.setColumnSelection(cs);
5291 isAnnotation = true;
5293 else if (IdentifyFile.FeaturesFile.equals(format))
5295 if (parseFeaturesFile(file, protocol))
5297 alignPanel.paintAlignment(true);
5302 new FileLoader().LoadFile(viewport, file, protocol, format);
5309 alignPanel.adjustAnnotationHeight();
5310 viewport.updateSequenceIdColours();
5311 buildSortByAnnotationScoresMenu();
5312 alignPanel.paintAlignment(true);
5314 } catch (Exception ex)
5316 ex.printStackTrace();
5317 } catch (OutOfMemoryError oom)
5322 } catch (Exception x)
5327 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5328 : "using " + protocol + " from " + file)
5330 + (format != null ? "(parsing as '" + format
5331 + "' file)" : ""), oom, Desktop.desktop);
5336 * Method invoked by the ChangeListener on the tabbed pane, in other words
5337 * when a different tabbed pane is selected by the user or programmatically.
5340 public void tabSelectionChanged(int index)
5344 alignPanel = alignPanels.get(index);
5345 viewport = alignPanel.av;
5346 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5347 setMenusFromViewport(viewport);
5351 * If there is a frame linked to this one in a SplitPane, switch it to the
5352 * same view tab index. No infinite recursion of calls should happen, since
5353 * tabSelectionChanged() should not get invoked on setting the selected
5354 * index to an unchanged value. Guard against setting an invalid index
5355 * before the new view peer tab has been created.
5357 final AlignViewportI peer = viewport.getCodingComplement();
5360 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5361 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5363 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5369 * On right mouse click on view tab, prompt for and set new view name.
5372 public void tabbedPane_mousePressed(MouseEvent e)
5374 if (e.isPopupTrigger())
5376 String msg = MessageManager.getString("label.enter_view_name");
5377 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5378 JOptionPane.QUESTION_MESSAGE);
5382 viewport.viewName = reply;
5383 // TODO warn if reply is in getExistingViewNames()?
5384 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5389 public AlignViewport getCurrentView()
5395 * Open the dialog for regex description parsing.
5398 protected void extractScores_actionPerformed(ActionEvent e)
5400 ParseProperties pp = new jalview.analysis.ParseProperties(
5401 viewport.getAlignment());
5402 // TODO: verify regex and introduce GUI dialog for version 2.5
5403 // if (pp.getScoresFromDescription("col", "score column ",
5404 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5406 if (pp.getScoresFromDescription("description column",
5407 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5409 buildSortByAnnotationScoresMenu();
5417 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5421 protected void showDbRefs_actionPerformed(ActionEvent e)
5423 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5429 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5433 protected void showNpFeats_actionPerformed(ActionEvent e)
5435 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5439 * find the viewport amongst the tabs in this alignment frame and close that
5444 public boolean closeView(AlignViewportI av)
5448 this.closeMenuItem_actionPerformed(false);
5451 Component[] comp = tabbedPane.getComponents();
5452 for (int i = 0; comp != null && i < comp.length; i++)
5454 if (comp[i] instanceof AlignmentPanel)
5456 if (((AlignmentPanel) comp[i]).av == av)
5459 closeView((AlignmentPanel) comp[i]);
5467 protected void build_fetchdbmenu(JMenu webService)
5469 // Temporary hack - DBRef Fetcher always top level ws entry.
5470 // TODO We probably want to store a sequence database checklist in
5471 // preferences and have checkboxes.. rather than individual sources selected
5473 final JMenu rfetch = new JMenu(
5474 MessageManager.getString("action.fetch_db_references"));
5475 rfetch.setToolTipText(MessageManager
5476 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5477 webService.add(rfetch);
5479 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5480 MessageManager.getString("option.trim_retrieved_seqs"));
5481 trimrs.setToolTipText(MessageManager
5482 .getString("label.trim_retrieved_sequences"));
5483 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5484 trimrs.addActionListener(new ActionListener()
5487 public void actionPerformed(ActionEvent e)
5489 trimrs.setSelected(trimrs.isSelected());
5490 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5491 Boolean.valueOf(trimrs.isSelected()).toString());
5495 JMenuItem fetchr = new JMenuItem(
5496 MessageManager.getString("label.standard_databases"));
5497 fetchr.setToolTipText(MessageManager
5498 .getString("label.fetch_embl_uniprot"));
5499 fetchr.addActionListener(new ActionListener()
5503 public void actionPerformed(ActionEvent e)
5505 new Thread(new Runnable()
5510 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5511 .getAlignment().isNucleotide();
5512 DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av
5513 .getSequenceSelection(), alignPanel.alignFrame, null,
5514 alignPanel.alignFrame.featureSettings, isNucleotide);
5515 dbRefFetcher.addListener(new FetchFinishedListenerI()
5518 public void finished()
5520 AlignFrame.this.setMenusForViewport();
5523 dbRefFetcher.fetchDBRefs(false);
5531 final AlignFrame me = this;
5532 new Thread(new Runnable()
5537 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5538 .getSequenceFetcherSingleton(me);
5539 javax.swing.SwingUtilities.invokeLater(new Runnable()
5544 String[] dbclasses = sf.getOrderedSupportedSources();
5545 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5546 // jalview.util.QuickSort.sort(otherdb, otherdb);
5547 List<DbSourceProxy> otherdb;
5548 JMenu dfetch = new JMenu();
5549 JMenu ifetch = new JMenu();
5550 JMenuItem fetchr = null;
5551 int comp = 0, icomp = 0, mcomp = 15;
5552 String mname = null;
5554 for (String dbclass : dbclasses)
5556 otherdb = sf.getSourceProxy(dbclass);
5557 // add a single entry for this class, or submenu allowing 'fetch
5559 if (otherdb == null || otherdb.size() < 1)
5563 // List<DbSourceProxy> dbs=otherdb;
5564 // otherdb=new ArrayList<DbSourceProxy>();
5565 // for (DbSourceProxy db:dbs)
5567 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5571 mname = "From " + dbclass;
5573 if (otherdb.size() == 1)
5575 final DbSourceProxy[] dassource = otherdb
5576 .toArray(new DbSourceProxy[0]);
5577 DbSourceProxy src = otherdb.get(0);
5578 fetchr = new JMenuItem(src.getDbSource());
5579 fetchr.addActionListener(new ActionListener()
5583 public void actionPerformed(ActionEvent e)
5585 new Thread(new Runnable()
5591 boolean isNucleotide = alignPanel.alignFrame
5592 .getViewport().getAlignment()
5594 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5595 alignPanel.av.getSequenceSelection(),
5596 alignPanel.alignFrame, dassource,
5597 alignPanel.alignFrame.featureSettings,
5600 .addListener(new FetchFinishedListenerI()
5603 public void finished()
5605 AlignFrame.this.setMenusForViewport();
5608 dbRefFetcher.fetchDBRefs(false);
5614 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5615 MessageManager.formatMessage(
5616 "label.fetch_retrieve_from",
5617 new Object[] { src.getDbName() })));
5623 final DbSourceProxy[] dassource = otherdb
5624 .toArray(new DbSourceProxy[0]);
5626 DbSourceProxy src = otherdb.get(0);
5627 fetchr = new JMenuItem(MessageManager.formatMessage(
5628 "label.fetch_all_param",
5629 new Object[] { src.getDbSource() }));
5630 fetchr.addActionListener(new ActionListener()
5633 public void actionPerformed(ActionEvent e)
5635 new Thread(new Runnable()
5641 boolean isNucleotide = alignPanel.alignFrame
5642 .getViewport().getAlignment()
5644 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5645 alignPanel.av.getSequenceSelection(),
5646 alignPanel.alignFrame, dassource,
5647 alignPanel.alignFrame.featureSettings,
5650 .addListener(new FetchFinishedListenerI()
5653 public void finished()
5655 AlignFrame.this.setMenusForViewport();
5658 dbRefFetcher.fetchDBRefs(false);
5664 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5665 MessageManager.formatMessage(
5666 "label.fetch_retrieve_from_all_sources",
5668 Integer.valueOf(otherdb.size())
5669 .toString(), src.getDbSource(),
5670 src.getDbName() })));
5673 // and then build the rest of the individual menus
5674 ifetch = new JMenu(MessageManager.formatMessage(
5675 "label.source_from_db_source",
5676 new Object[] { src.getDbSource() }));
5678 String imname = null;
5680 for (DbSourceProxy sproxy : otherdb)
5682 String dbname = sproxy.getDbName();
5683 String sname = dbname.length() > 5 ? dbname.substring(0,
5684 5) + "..." : dbname;
5685 String msname = dbname.length() > 10 ? dbname.substring(
5686 0, 10) + "..." : dbname;
5689 imname = MessageManager.formatMessage(
5690 "label.from_msname", new Object[] { sname });
5692 fetchr = new JMenuItem(msname);
5693 final DbSourceProxy[] dassrc = { sproxy };
5694 fetchr.addActionListener(new ActionListener()
5698 public void actionPerformed(ActionEvent e)
5700 new Thread(new Runnable()
5706 boolean isNucleotide = alignPanel.alignFrame
5707 .getViewport().getAlignment()
5709 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5710 alignPanel.av.getSequenceSelection(),
5711 alignPanel.alignFrame, dassrc,
5712 alignPanel.alignFrame.featureSettings,
5715 .addListener(new FetchFinishedListenerI()
5718 public void finished()
5720 AlignFrame.this.setMenusForViewport();
5723 dbRefFetcher.fetchDBRefs(false);
5729 fetchr.setToolTipText("<html>"
5730 + MessageManager.formatMessage(
5731 "label.fetch_retrieve_from", new Object[]
5735 if (++icomp >= mcomp || i == (otherdb.size()))
5737 ifetch.setText(MessageManager.formatMessage(
5738 "label.source_to_target", imname, sname));
5740 ifetch = new JMenu();
5748 if (comp >= mcomp || dbi >= (dbclasses.length))
5750 dfetch.setText(MessageManager.formatMessage(
5751 "label.source_to_target", mname, dbclass));
5753 dfetch = new JMenu();
5766 * Left justify the whole alignment.
5769 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5771 AlignmentI al = viewport.getAlignment();
5773 viewport.firePropertyChange("alignment", null, al);
5777 * Right justify the whole alignment.
5780 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5782 AlignmentI al = viewport.getAlignment();
5784 viewport.firePropertyChange("alignment", null, al);
5788 public void setShowSeqFeatures(boolean b)
5790 showSeqFeatures.setSelected(b);
5791 viewport.setShowSequenceFeatures(b);
5798 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5799 * awt.event.ActionEvent)
5802 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5804 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5805 alignPanel.paintAlignment(true);
5812 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5816 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5818 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5819 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5827 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5828 * .event.ActionEvent)
5831 protected void showGroupConservation_actionPerformed(ActionEvent e)
5833 viewport.setShowGroupConservation(showGroupConservation.getState());
5834 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5841 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5842 * .event.ActionEvent)
5845 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5847 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5848 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5855 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5856 * .event.ActionEvent)
5859 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5861 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5862 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5866 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5868 showSequenceLogo.setState(true);
5869 viewport.setShowSequenceLogo(true);
5870 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5871 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5875 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5877 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5884 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5885 * .event.ActionEvent)
5888 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5890 if (avc.makeGroupsFromSelection())
5892 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5893 alignPanel.updateAnnotation();
5894 alignPanel.paintAlignment(true);
5898 public void clearAlignmentSeqRep()
5900 // TODO refactor alignmentseqrep to controller
5901 if (viewport.getAlignment().hasSeqrep())
5903 viewport.getAlignment().setSeqrep(null);
5904 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5905 alignPanel.updateAnnotation();
5906 alignPanel.paintAlignment(true);
5911 protected void createGroup_actionPerformed(ActionEvent e)
5913 if (avc.createGroup())
5915 alignPanel.alignmentChanged();
5920 protected void unGroup_actionPerformed(ActionEvent e)
5924 alignPanel.alignmentChanged();
5929 * make the given alignmentPanel the currently selected tab
5931 * @param alignmentPanel
5933 public void setDisplayedView(AlignmentPanel alignmentPanel)
5935 if (!viewport.getSequenceSetId().equals(
5936 alignmentPanel.av.getSequenceSetId()))
5940 .getString("error.implementation_error_cannot_show_view_alignment_frame"));
5942 if (tabbedPane != null
5943 && tabbedPane.getTabCount() > 0
5944 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5945 .getSelectedIndex())
5947 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5952 * Action on selection of menu options to Show or Hide annotations.
5955 * @param forSequences
5956 * update sequence-related annotations
5957 * @param forAlignment
5958 * update non-sequence-related annotations
5961 protected void setAnnotationsVisibility(boolean visible,
5962 boolean forSequences, boolean forAlignment)
5964 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5965 .getAlignmentAnnotation();
5970 for (AlignmentAnnotation aa : anns)
5973 * don't display non-positional annotations on an alignment
5975 if (aa.annotations == null)
5979 boolean apply = (aa.sequenceRef == null && forAlignment)
5980 || (aa.sequenceRef != null && forSequences);
5983 aa.visible = visible;
5986 alignPanel.validateAnnotationDimensions(true);
5987 alignPanel.alignmentChanged();
5991 * Store selected annotation sort order for the view and repaint.
5994 protected void sortAnnotations_actionPerformed()
5996 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5998 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5999 alignPanel.paintAlignment(true);
6004 * @return alignment panels in this alignment frame
6006 public List<? extends AlignmentViewPanel> getAlignPanels()
6008 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
6012 * Open a new alignment window, with the cDNA associated with this (protein)
6013 * alignment, aligned as is the protein.
6015 protected void viewAsCdna_actionPerformed()
6017 // TODO no longer a menu action - refactor as required
6018 final AlignmentI alignment = getViewport().getAlignment();
6019 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6020 if (mappings == null)
6024 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6025 for (SequenceI aaSeq : alignment.getSequences())
6027 for (AlignedCodonFrame acf : mappings)
6029 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6033 * There is a cDNA mapping for this protein sequence - add to new
6034 * alignment. It will share the same dataset sequence as other mapped
6035 * cDNA (no new mappings need to be created).
6037 final Sequence newSeq = new Sequence(dnaSeq);
6038 newSeq.setDatasetSequence(dnaSeq);
6039 cdnaSeqs.add(newSeq);
6043 if (cdnaSeqs.size() == 0)
6045 // show a warning dialog no mapped cDNA
6048 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6050 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6051 AlignFrame.DEFAULT_HEIGHT);
6052 cdna.alignAs(alignment);
6053 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6055 Desktop.addInternalFrame(alignFrame, newtitle,
6056 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
6060 * Set visibility of dna/protein complement view (available when shown in a
6066 protected void showComplement_actionPerformed(boolean show)
6068 SplitContainerI sf = getSplitViewContainer();
6071 sf.setComplementVisible(this, show);
6076 * Generate the reverse (optionally complemented) of the selected sequences,
6077 * and add them to the alignment
6080 protected void showReverse_actionPerformed(boolean complement)
6082 AlignmentI al = null;
6085 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
6086 al = dna.reverseCdna(complement);
6087 viewport.addAlignment(al, "");
6088 addHistoryItem(new EditCommand(
6089 MessageManager.getString("label.add_sequences"),
6090 Action.PASTE, al.getSequencesArray(), 0, al.getWidth(),
6091 viewport.getAlignment()));
6092 } catch (Exception ex)
6094 System.err.println(ex.getMessage());
6100 * Try to run a script in the Groovy console, having first ensured that this
6101 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
6102 * be targeted at this alignment.
6105 protected void runGroovy_actionPerformed()
6107 Jalview.setCurrentAlignFrame(this);
6108 groovy.ui.Console console = Desktop.getGroovyConsole();
6109 if (console != null)
6113 console.runScript();
6114 } catch (Exception ex)
6116 System.err.println((ex.toString()));
6118 .showInternalMessageDialog(Desktop.desktop, MessageManager
6119 .getString("label.couldnt_run_groovy_script"),
6121 .getString("label.groovy_support_failed"),
6122 JOptionPane.ERROR_MESSAGE);
6127 System.err.println("Can't run Groovy script as console not found");
6132 * Hides columns containing (or not containing) a specified feature, provided
6133 * that would not leave all columns hidden
6135 * @param featureType
6136 * @param columnsContaining
6139 public boolean hideFeatureColumns(String featureType,
6140 boolean columnsContaining)
6142 boolean notForHiding = avc.markColumnsContainingFeatures(
6143 columnsContaining, false, false, featureType);
6146 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
6147 false, featureType))
6149 getViewport().hideSelectedColumns();
6157 class PrintThread extends Thread
6161 public PrintThread(AlignmentPanel ap)
6166 static PageFormat pf;
6171 PrinterJob printJob = PrinterJob.getPrinterJob();
6175 printJob.setPrintable(ap, pf);
6179 printJob.setPrintable(ap);
6182 if (printJob.printDialog())
6187 } catch (Exception PrintException)
6189 PrintException.printStackTrace();