2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.ParseProperties;
28 import jalview.analysis.SequenceIdMatcher;
29 import jalview.api.AlignExportSettingI;
30 import jalview.api.AlignViewControllerGuiI;
31 import jalview.api.AlignViewControllerI;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureSettingsControllerI;
35 import jalview.api.SplitContainerI;
36 import jalview.api.ViewStyleI;
37 import jalview.api.analysis.ScoreModelI;
38 import jalview.bin.Cache;
39 import jalview.bin.Jalview;
40 import jalview.commands.CommandI;
41 import jalview.commands.EditCommand;
42 import jalview.commands.EditCommand.Action;
43 import jalview.commands.OrderCommand;
44 import jalview.commands.RemoveGapColCommand;
45 import jalview.commands.RemoveGapsCommand;
46 import jalview.commands.SlideSequencesCommand;
47 import jalview.commands.TrimRegionCommand;
48 import jalview.datamodel.AlignedCodonFrame;
49 import jalview.datamodel.Alignment;
50 import jalview.datamodel.AlignmentAnnotation;
51 import jalview.datamodel.AlignmentExportData;
52 import jalview.datamodel.AlignmentI;
53 import jalview.datamodel.AlignmentOrder;
54 import jalview.datamodel.AlignmentView;
55 import jalview.datamodel.ColumnSelection;
56 import jalview.datamodel.HiddenSequences;
57 import jalview.datamodel.PDBEntry;
58 import jalview.datamodel.SeqCigar;
59 import jalview.datamodel.Sequence;
60 import jalview.datamodel.SequenceGroup;
61 import jalview.datamodel.SequenceI;
62 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
63 import jalview.io.AlignmentProperties;
64 import jalview.io.AnnotationFile;
65 import jalview.io.BioJsHTMLOutput;
66 import jalview.io.FileLoader;
67 import jalview.io.FormatAdapter;
68 import jalview.io.HtmlSvgOutput;
69 import jalview.io.IdentifyFile;
70 import jalview.io.JalviewFileChooser;
71 import jalview.io.JalviewFileView;
72 import jalview.io.JnetAnnotationMaker;
73 import jalview.io.NewickFile;
74 import jalview.io.TCoffeeScoreFile;
75 import jalview.jbgui.GAlignFrame;
76 import jalview.schemes.Blosum62ColourScheme;
77 import jalview.schemes.BuriedColourScheme;
78 import jalview.schemes.ClustalxColourScheme;
79 import jalview.schemes.ColourSchemeI;
80 import jalview.schemes.ColourSchemeProperty;
81 import jalview.schemes.HelixColourScheme;
82 import jalview.schemes.HydrophobicColourScheme;
83 import jalview.schemes.NucleotideColourScheme;
84 import jalview.schemes.PIDColourScheme;
85 import jalview.schemes.PurinePyrimidineColourScheme;
86 import jalview.schemes.RNAHelicesColourChooser;
87 import jalview.schemes.ResidueProperties;
88 import jalview.schemes.StrandColourScheme;
89 import jalview.schemes.TCoffeeColourScheme;
90 import jalview.schemes.TaylorColourScheme;
91 import jalview.schemes.TurnColourScheme;
92 import jalview.schemes.UserColourScheme;
93 import jalview.schemes.ZappoColourScheme;
94 import jalview.structure.StructureSelectionManager;
95 import jalview.util.MessageManager;
96 import jalview.viewmodel.AlignmentViewport;
97 import jalview.ws.jws1.Discoverer;
98 import jalview.ws.jws2.Jws2Discoverer;
99 import jalview.ws.jws2.jabaws2.Jws2Instance;
100 import jalview.ws.seqfetcher.DbSourceProxy;
102 import java.awt.BorderLayout;
103 import java.awt.Component;
104 import java.awt.Rectangle;
105 import java.awt.Toolkit;
106 import java.awt.datatransfer.Clipboard;
107 import java.awt.datatransfer.DataFlavor;
108 import java.awt.datatransfer.StringSelection;
109 import java.awt.datatransfer.Transferable;
110 import java.awt.dnd.DnDConstants;
111 import java.awt.dnd.DropTargetDragEvent;
112 import java.awt.dnd.DropTargetDropEvent;
113 import java.awt.dnd.DropTargetEvent;
114 import java.awt.dnd.DropTargetListener;
115 import java.awt.event.ActionEvent;
116 import java.awt.event.ActionListener;
117 import java.awt.event.ItemEvent;
118 import java.awt.event.ItemListener;
119 import java.awt.event.KeyAdapter;
120 import java.awt.event.KeyEvent;
121 import java.awt.event.MouseAdapter;
122 import java.awt.event.MouseEvent;
123 import java.awt.print.PageFormat;
124 import java.awt.print.PrinterJob;
125 import java.beans.PropertyChangeEvent;
128 import java.util.ArrayList;
129 import java.util.Arrays;
130 import java.util.Deque;
131 import java.util.Enumeration;
132 import java.util.Hashtable;
133 import java.util.List;
134 import java.util.Set;
135 import java.util.Vector;
137 import javax.swing.JCheckBoxMenuItem;
138 import javax.swing.JEditorPane;
139 import javax.swing.JInternalFrame;
140 import javax.swing.JLayeredPane;
141 import javax.swing.JMenu;
142 import javax.swing.JMenuItem;
143 import javax.swing.JOptionPane;
144 import javax.swing.JRadioButtonMenuItem;
145 import javax.swing.JScrollPane;
146 import javax.swing.SwingUtilities;
152 * @version $Revision$
154 public class AlignFrame extends GAlignFrame implements DropTargetListener,
155 IProgressIndicator, AlignViewControllerGuiI
158 public static final int DEFAULT_WIDTH = 700;
160 public static final int DEFAULT_HEIGHT = 500;
163 * The currently displayed panel (selected tabbed view if more than one)
165 public AlignmentPanel alignPanel;
167 AlignViewport viewport;
169 public AlignViewControllerI avc;
171 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
174 * Last format used to load or save alignments in this window
176 String currentFileFormat = null;
179 * Current filename for this alignment
181 String fileName = null;
184 * Creates a new AlignFrame object with specific width and height.
190 public AlignFrame(AlignmentI al, int width, int height)
192 this(al, null, width, height);
196 * Creates a new AlignFrame object with specific width, height and
202 * @param sequenceSetId
204 public AlignFrame(AlignmentI al, int width, int height,
205 String sequenceSetId)
207 this(al, null, width, height, sequenceSetId);
211 * Creates a new AlignFrame object with specific width, height and
217 * @param sequenceSetId
220 public AlignFrame(AlignmentI al, int width, int height,
221 String sequenceSetId, String viewId)
223 this(al, null, width, height, sequenceSetId, viewId);
227 * new alignment window with hidden columns
231 * @param hiddenColumns
232 * ColumnSelection or null
234 * Width of alignment frame
238 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
239 int width, int height)
241 this(al, hiddenColumns, width, height, null);
246 * Create alignment frame for al with hiddenColumns, a specific width and
247 * height, and specific sequenceId
250 * @param hiddenColumns
253 * @param sequenceSetId
256 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
257 int width, int height, String sequenceSetId)
259 this(al, hiddenColumns, width, height, sequenceSetId, null);
263 * Create alignment frame for al with hiddenColumns, a specific width and
264 * height, and specific sequenceId
267 * @param hiddenColumns
270 * @param sequenceSetId
275 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
276 int width, int height, String sequenceSetId, String viewId)
278 setSize(width, height);
280 if (al.getDataset() == null)
285 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
287 alignPanel = new AlignmentPanel(this, viewport);
290 addAlignmentPanel(alignPanel, true);
294 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
295 ColumnSelection hiddenColumns, int width, int height)
297 setSize(width, height);
299 if (al.getDataset() == null)
304 viewport = new AlignViewport(al, hiddenColumns);
306 if (hiddenSeqs != null && hiddenSeqs.length > 0)
308 viewport.hideSequence(hiddenSeqs);
310 alignPanel = new AlignmentPanel(this, viewport);
311 addAlignmentPanel(alignPanel, true);
317 * Make a new AlignFrame from existing alignmentPanels
324 public AlignFrame(AlignmentPanel ap)
328 addAlignmentPanel(ap, false);
333 * initalise the alignframe from the underlying viewport data and the
338 if (!Jalview.isHeadlessMode())
340 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
343 avc = new jalview.controller.AlignViewController(this, viewport,
345 if (viewport.getAlignmentConservationAnnotation() == null)
347 BLOSUM62Colour.setEnabled(false);
348 conservationMenuItem.setEnabled(false);
349 modifyConservation.setEnabled(false);
350 // PIDColour.setEnabled(false);
351 // abovePIDThreshold.setEnabled(false);
352 // modifyPID.setEnabled(false);
355 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
358 if (sortby.equals("Id"))
360 sortIDMenuItem_actionPerformed(null);
362 else if (sortby.equals("Pairwise Identity"))
364 sortPairwiseMenuItem_actionPerformed(null);
367 if (Desktop.desktop != null)
369 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
370 addServiceListeners();
371 setGUINucleotide(viewport.getAlignment().isNucleotide());
374 setMenusFromViewport(viewport);
375 buildSortByAnnotationScoresMenu();
378 if (viewport.getWrapAlignment())
380 wrapMenuItem_actionPerformed(null);
383 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
385 this.overviewMenuItem_actionPerformed(null);
390 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
391 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
392 final String menuLabel = MessageManager
393 .getString("label.copy_format_from");
394 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
395 new ViewSetProvider()
399 public AlignmentPanel[] getAllAlignmentPanels()
402 origview.add(alignPanel);
403 // make an array of all alignment panels except for this one
404 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
405 Arrays.asList(Desktop.getAlignmentPanels(null)));
406 aps.remove(AlignFrame.this.alignPanel);
407 return aps.toArray(new AlignmentPanel[aps.size()]);
409 }, selviews, new ItemListener()
413 public void itemStateChanged(ItemEvent e)
415 if (origview.size() > 0)
417 final AlignmentPanel ap = origview.get(0);
420 * Copy the ViewStyle of the selected panel to 'this one'.
421 * Don't change value of 'scaleProteinAsCdna' unless copying
424 ViewStyleI vs = selviews.get(0).getAlignViewport()
426 boolean fromSplitFrame = selviews.get(0)
427 .getAlignViewport().getCodingComplement() != null;
430 vs.setScaleProteinAsCdna(ap.getAlignViewport()
431 .getViewStyle().isScaleProteinAsCdna());
433 ap.getAlignViewport().setViewStyle(vs);
436 * Also rescale ViewStyle of SplitFrame complement if there is
437 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
438 * the whole ViewStyle (allow cDNA protein to have different
441 AlignViewportI complement = ap.getAlignViewport()
442 .getCodingComplement();
443 if (complement != null && vs.isScaleProteinAsCdna())
445 AlignFrame af = Desktop.getAlignFrameFor(complement);
446 ((SplitFrame) af.getSplitViewContainer())
448 af.setMenusForViewport();
452 ap.setSelected(true);
453 ap.alignFrame.setMenusForViewport();
458 formatMenu.add(vsel);
463 * Change the filename and format for the alignment, and enable the 'reload'
464 * button functionality.
471 public void setFileName(String file, String format)
474 setFileFormat(format);
475 reload.setEnabled(true);
479 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
482 void addKeyListener()
484 addKeyListener(new KeyAdapter()
487 public void keyPressed(KeyEvent evt)
489 if (viewport.cursorMode
490 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
491 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
492 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
493 && Character.isDigit(evt.getKeyChar()))
495 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
498 switch (evt.getKeyCode())
501 case 27: // escape key
502 deselectAllSequenceMenuItem_actionPerformed(null);
506 case KeyEvent.VK_DOWN:
507 if (evt.isAltDown() || !viewport.cursorMode)
509 moveSelectedSequences(false);
511 if (viewport.cursorMode)
513 alignPanel.getSeqPanel().moveCursor(0, 1);
518 if (evt.isAltDown() || !viewport.cursorMode)
520 moveSelectedSequences(true);
522 if (viewport.cursorMode)
524 alignPanel.getSeqPanel().moveCursor(0, -1);
529 case KeyEvent.VK_LEFT:
530 if (evt.isAltDown() || !viewport.cursorMode)
532 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
536 alignPanel.getSeqPanel().moveCursor(-1, 0);
541 case KeyEvent.VK_RIGHT:
542 if (evt.isAltDown() || !viewport.cursorMode)
544 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
548 alignPanel.getSeqPanel().moveCursor(1, 0);
552 case KeyEvent.VK_SPACE:
553 if (viewport.cursorMode)
555 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
556 || evt.isShiftDown() || evt.isAltDown());
560 // case KeyEvent.VK_A:
561 // if (viewport.cursorMode)
563 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
564 // //System.out.println("A");
568 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
569 * System.out.println("closing bracket"); } break;
571 case KeyEvent.VK_DELETE:
572 case KeyEvent.VK_BACK_SPACE:
573 if (!viewport.cursorMode)
575 cut_actionPerformed(null);
579 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
580 || evt.isShiftDown() || evt.isAltDown());
586 if (viewport.cursorMode)
588 alignPanel.getSeqPanel().setCursorRow();
592 if (viewport.cursorMode && !evt.isControlDown())
594 alignPanel.getSeqPanel().setCursorColumn();
598 if (viewport.cursorMode)
600 alignPanel.getSeqPanel().setCursorPosition();
604 case KeyEvent.VK_ENTER:
605 case KeyEvent.VK_COMMA:
606 if (viewport.cursorMode)
608 alignPanel.getSeqPanel().setCursorRowAndColumn();
613 if (viewport.cursorMode)
615 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
619 if (viewport.cursorMode)
621 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
626 viewport.cursorMode = !viewport.cursorMode;
627 statusBar.setText(MessageManager.formatMessage(
628 "label.keyboard_editing_mode", new String[]
629 { (viewport.cursorMode ? "on" : "off") }));
630 if (viewport.cursorMode)
632 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
633 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
635 alignPanel.getSeqPanel().seqCanvas.repaint();
641 Help.showHelpWindow();
642 } catch (Exception ex)
644 ex.printStackTrace();
649 boolean toggleSeqs = !evt.isControlDown();
650 boolean toggleCols = !evt.isShiftDown();
651 toggleHiddenRegions(toggleSeqs, toggleCols);
654 case KeyEvent.VK_PAGE_UP:
655 if (viewport.getWrapAlignment())
657 alignPanel.scrollUp(true);
661 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
662 - viewport.endSeq + viewport.startSeq);
665 case KeyEvent.VK_PAGE_DOWN:
666 if (viewport.getWrapAlignment())
668 alignPanel.scrollUp(false);
672 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
673 + viewport.endSeq - viewport.startSeq);
680 public void keyReleased(KeyEvent evt)
682 switch (evt.getKeyCode())
684 case KeyEvent.VK_LEFT:
685 if (evt.isAltDown() || !viewport.cursorMode)
687 viewport.firePropertyChange("alignment", null, viewport
688 .getAlignment().getSequences());
692 case KeyEvent.VK_RIGHT:
693 if (evt.isAltDown() || !viewport.cursorMode)
695 viewport.firePropertyChange("alignment", null, viewport
696 .getAlignment().getSequences());
704 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
706 ap.alignFrame = this;
707 avc = new jalview.controller.AlignViewController(this, viewport,
712 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
714 int aSize = alignPanels.size();
716 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
718 if (aSize == 1 && ap.av.viewName == null)
720 this.getContentPane().add(ap, BorderLayout.CENTER);
726 setInitialTabVisible();
729 expandViews.setEnabled(true);
730 gatherViews.setEnabled(true);
731 tabbedPane.addTab(ap.av.viewName, ap);
733 ap.setVisible(false);
738 if (ap.av.isPadGaps())
740 ap.av.getAlignment().padGaps();
742 ap.av.updateConservation(ap);
743 ap.av.updateConsensus(ap);
744 ap.av.updateStrucConsensus(ap);
748 public void setInitialTabVisible()
750 expandViews.setEnabled(true);
751 gatherViews.setEnabled(true);
752 tabbedPane.setVisible(true);
753 AlignmentPanel first = alignPanels.get(0);
754 tabbedPane.addTab(first.av.viewName, first);
755 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
758 public AlignViewport getViewport()
763 /* Set up intrinsic listeners for dynamically generated GUI bits. */
764 private void addServiceListeners()
766 final java.beans.PropertyChangeListener thisListener;
767 Desktop.instance.addJalviewPropertyChangeListener("services",
768 thisListener = new java.beans.PropertyChangeListener()
771 public void propertyChange(PropertyChangeEvent evt)
773 // // System.out.println("Discoverer property change.");
774 // if (evt.getPropertyName().equals("services"))
776 SwingUtilities.invokeLater(new Runnable()
783 .println("Rebuild WS Menu for service change");
784 BuildWebServiceMenu();
791 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
794 public void internalFrameClosed(
795 javax.swing.event.InternalFrameEvent evt)
797 // System.out.println("deregistering discoverer listener");
798 Desktop.instance.removeJalviewPropertyChangeListener("services",
800 closeMenuItem_actionPerformed(true);
803 // Finally, build the menu once to get current service state
804 new Thread(new Runnable()
809 BuildWebServiceMenu();
815 * Configure menu items that vary according to whether the alignment is
816 * nucleotide or protein
820 public void setGUINucleotide(boolean nucleotide)
822 showTranslation.setVisible(nucleotide);
823 conservationMenuItem.setEnabled(!nucleotide);
824 modifyConservation.setEnabled(!nucleotide);
825 showGroupConservation.setEnabled(!nucleotide);
826 rnahelicesColour.setEnabled(nucleotide);
827 purinePyrimidineColour.setEnabled(nucleotide);
828 showComplementMenuItem.setText(MessageManager
829 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
830 setColourSelected(jalview.bin.Cache.getDefault(
831 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
832 : Preferences.DEFAULT_COLOUR_PROT, "None"));
836 * set up menus for the current viewport. This may be called after any
837 * operation that affects the data in the current view (selection changed,
838 * etc) to update the menus to reflect the new state.
840 public void setMenusForViewport()
842 setMenusFromViewport(viewport);
846 * Need to call this method when tabs are selected for multiple views, or when
847 * loading from Jalview2XML.java
852 void setMenusFromViewport(AlignViewport av)
854 padGapsMenuitem.setSelected(av.isPadGaps());
855 colourTextMenuItem.setSelected(av.isShowColourText());
856 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
857 conservationMenuItem.setSelected(av.getConservationSelected());
858 seqLimits.setSelected(av.getShowJVSuffix());
859 idRightAlign.setSelected(av.isRightAlignIds());
860 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
861 renderGapsMenuItem.setSelected(av.isRenderGaps());
862 wrapMenuItem.setSelected(av.getWrapAlignment());
863 scaleAbove.setVisible(av.getWrapAlignment());
864 scaleLeft.setVisible(av.getWrapAlignment());
865 scaleRight.setVisible(av.getWrapAlignment());
866 annotationPanelMenuItem.setState(av.isShowAnnotation());
868 * Show/hide annotations only enabled if annotation panel is shown
870 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
871 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
872 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
873 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
874 viewBoxesMenuItem.setSelected(av.getShowBoxes());
875 viewTextMenuItem.setSelected(av.getShowText());
876 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
877 showGroupConsensus.setSelected(av.isShowGroupConsensus());
878 showGroupConservation.setSelected(av.isShowGroupConservation());
879 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
880 showSequenceLogo.setSelected(av.isShowSequenceLogo());
881 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
883 setColourSelected(ColourSchemeProperty.getColourName(av
884 .getGlobalColourScheme()));
886 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
887 hiddenMarkers.setState(av.getShowHiddenMarkers());
888 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
889 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
890 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
891 autoCalculate.setSelected(av.autoCalculateConsensus);
892 sortByTree.setSelected(av.sortByTree);
893 listenToViewSelections.setSelected(av.followSelection);
894 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
896 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
897 setShowProductsEnabled();
901 private IProgressIndicator progressBar;
906 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
909 public void setProgressBar(String message, long id)
911 progressBar.setProgressBar(message, id);
915 public void registerHandler(final long id,
916 final IProgressIndicatorHandler handler)
918 progressBar.registerHandler(id, handler);
923 * @return true if any progress bars are still active
926 public boolean operationInProgress()
928 return progressBar.operationInProgress();
932 public void setStatus(String text)
934 statusBar.setText(text);
938 * Added so Castor Mapping file can obtain Jalview Version
940 public String getVersion()
942 return jalview.bin.Cache.getProperty("VERSION");
945 public FeatureRenderer getFeatureRenderer()
947 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
951 public void fetchSequence_actionPerformed(ActionEvent e)
953 new SequenceFetcher(this);
957 public void addFromFile_actionPerformed(ActionEvent e)
959 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
963 public void reload_actionPerformed(ActionEvent e)
965 if (fileName != null)
967 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
968 // originating file's format
969 // TODO: work out how to recover feature settings for correct view(s) when
971 if (currentFileFormat.equals("Jalview"))
973 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
974 for (int i = 0; i < frames.length; i++)
976 if (frames[i] instanceof AlignFrame && frames[i] != this
977 && ((AlignFrame) frames[i]).fileName != null
978 && ((AlignFrame) frames[i]).fileName.equals(fileName))
982 frames[i].setSelected(true);
983 Desktop.instance.closeAssociatedWindows();
984 } catch (java.beans.PropertyVetoException ex)
990 Desktop.instance.closeAssociatedWindows();
992 FileLoader loader = new FileLoader();
993 String protocol = fileName.startsWith("http:") ? "URL" : "File";
994 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
998 Rectangle bounds = this.getBounds();
1000 FileLoader loader = new FileLoader();
1001 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1002 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1003 protocol, currentFileFormat);
1005 newframe.setBounds(bounds);
1006 if (featureSettings != null && featureSettings.isShowing())
1008 final Rectangle fspos = featureSettings.frame.getBounds();
1009 // TODO: need a 'show feature settings' function that takes bounds -
1010 // need to refactor Desktop.addFrame
1011 newframe.featureSettings_actionPerformed(null);
1012 final FeatureSettings nfs = newframe.featureSettings;
1013 SwingUtilities.invokeLater(new Runnable()
1018 nfs.frame.setBounds(fspos);
1021 this.featureSettings.close();
1022 this.featureSettings = null;
1024 this.closeMenuItem_actionPerformed(true);
1030 public void addFromText_actionPerformed(ActionEvent e)
1032 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport
1037 public void addFromURL_actionPerformed(ActionEvent e)
1039 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1043 public void save_actionPerformed(ActionEvent e)
1045 if (fileName == null
1046 || (currentFileFormat == null || !jalview.io.FormatAdapter
1047 .isValidIOFormat(currentFileFormat, true))
1048 || fileName.startsWith("http"))
1050 saveAs_actionPerformed(null);
1054 saveAlignment(fileName, currentFileFormat);
1065 public void saveAs_actionPerformed(ActionEvent e)
1067 JalviewFileChooser chooser = new JalviewFileChooser(
1068 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1069 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1070 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1071 currentFileFormat, false);
1073 chooser.setFileView(new JalviewFileView());
1074 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1075 chooser.setToolTipText(MessageManager.getString("action.save"));
1077 int value = chooser.showSaveDialog(this);
1079 if (value == JalviewFileChooser.APPROVE_OPTION)
1081 currentFileFormat = chooser.getSelectedFormat();
1082 while (currentFileFormat == null)
1085 .showInternalMessageDialog(
1088 .getString("label.select_file_format_before_saving"),
1090 .getString("label.file_format_not_specified"),
1091 JOptionPane.WARNING_MESSAGE);
1092 currentFileFormat = chooser.getSelectedFormat();
1093 value = chooser.showSaveDialog(this);
1094 if (value != JalviewFileChooser.APPROVE_OPTION)
1100 fileName = chooser.getSelectedFile().getPath();
1102 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1105 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1106 if (currentFileFormat.indexOf(" ") > -1)
1108 currentFileFormat = currentFileFormat.substring(0,
1109 currentFileFormat.indexOf(" "));
1111 saveAlignment(fileName, currentFileFormat);
1115 public boolean saveAlignment(String file, String format)
1117 boolean success = true;
1119 if (format.equalsIgnoreCase("Jalview"))
1121 String shortName = title;
1123 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1125 shortName = shortName.substring(shortName
1126 .lastIndexOf(java.io.File.separatorChar) + 1);
1129 success = new Jalview2XML().saveAlignment(this, file, shortName);
1131 statusBar.setText(MessageManager.formatMessage(
1132 "label.successfully_saved_to_file_in_format", new Object[]
1133 { fileName, format }));
1138 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1140 warningMessage("Cannot save file " + fileName + " using format "
1141 + format, "Alignment output format not supported");
1142 if (!Jalview.isHeadlessMode())
1144 saveAs_actionPerformed(null);
1149 AlignmentExportData exportData = getAlignmentForExport(format,
1151 if (exportData.getSettings().isCancelled())
1155 FormatAdapter f = new FormatAdapter(alignPanel,
1156 exportData.getSettings());
1157 String output = f.formatSequences(format,
1158 exportData.getAlignment(), // class cast exceptions will
1159 // occur in the distant future
1160 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1161 f.getCacheSuffixDefault(format),
1162 viewport.getColumnSelection());
1172 java.io.PrintWriter out = new java.io.PrintWriter(
1173 new java.io.FileWriter(file));
1177 this.setTitle(file);
1178 statusBar.setText(MessageManager.formatMessage(
1179 "label.successfully_saved_to_file_in_format",
1181 { fileName, format }));
1182 } catch (Exception ex)
1185 ex.printStackTrace();
1192 JOptionPane.showInternalMessageDialog(this, MessageManager
1193 .formatMessage("label.couldnt_save_file", new Object[]
1194 { fileName }), MessageManager
1195 .getString("label.error_saving_file"),
1196 JOptionPane.WARNING_MESSAGE);
1203 private void warningMessage(String warning, String title)
1205 if (new jalview.util.Platform().isHeadless())
1207 System.err.println("Warning: " + title + "\nWarning: " + warning);
1212 JOptionPane.showInternalMessageDialog(this, warning, title,
1213 JOptionPane.WARNING_MESSAGE);
1225 protected void outputText_actionPerformed(ActionEvent e)
1228 AlignmentExportData exportData = getAlignmentForExport(
1229 e.getActionCommand(), viewport, null);
1230 if (exportData.getSettings().isCancelled())
1234 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1235 cap.setForInput(null);
1238 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1240 e.getActionCommand(),
1241 exportData.getAlignment(),
1242 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1243 viewport.getColumnSelection()));
1244 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1245 "label.alignment_output_command", new Object[]
1246 { e.getActionCommand() }), 600, 500);
1247 } catch (OutOfMemoryError oom)
1249 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1255 public static AlignmentExportData getAlignmentForExport(String exportFormat,
1256 AlignViewportI viewport,
1257 AlignExportSettingI exportSettings)
1259 AlignmentI alignmentToExport = null;
1260 AlignExportSettingI settings = exportSettings;
1261 String[] omitHidden = null;
1262 int[] alignmentStartEnd = new int[2];
1264 HiddenSequences hiddenSeqs = viewport.getAlignment()
1265 .getHiddenSequences();
1268 alignmentToExport = viewport.getAlignment();
1269 alignmentStartEnd = new int[]
1270 { 0, alignmentToExport.getWidth() - 1 };
1272 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1273 if (settings == null)
1275 settings = new AlignExportSettings(hasHiddenSeqs,
1276 viewport.hasHiddenColumns(), exportFormat);
1278 // settings.isExportAnnotations();
1280 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1282 omitHidden = viewport.getViewAsString(false);
1285 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1287 alignmentToExport = hiddenSeqs.getFullAlignment();
1291 alignmentToExport = viewport.getAlignment();
1292 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1293 .getColumnSelection().getHiddenColumns());
1295 AlignmentExportData ed = new AlignmentExportData(alignmentToExport, omitHidden, alignmentStartEnd,
1300 public static int[] getStartEnd(int[] aligmentStartEnd,
1301 List<int[]> hiddenCols)
1303 int startPos = aligmentStartEnd[0];
1304 int endPos = aligmentStartEnd[1];
1306 int[] lowestRange = new int[2];
1307 int[] higestRange = new int[2];
1309 for (int[] hiddenCol : hiddenCols)
1311 // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
1312 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1313 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1315 // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
1316 // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
1318 if (lowestRange[0] == 0 && lowestRange[1] == 0)
1320 startPos = aligmentStartEnd[0];
1324 startPos = lowestRange[1] + 1;
1327 if (higestRange[0] == 0 && higestRange[1] == 0)
1329 endPos = aligmentStartEnd[1];
1333 endPos = higestRange[0];
1336 // System.out.println("Export range : " + minPos + " - " + maxPos);
1338 { startPos, endPos };
1341 public static void main(String[] args)
1343 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1344 hiddenCols.add(new int[]
1346 hiddenCols.add(new int[]
1348 hiddenCols.add(new int[]
1350 hiddenCols.add(new int[]
1352 hiddenCols.add(new int[]
1355 int[] x = getStartEnd(new int[]
1356 { 0, 50 }, hiddenCols);
1357 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1367 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1369 new HtmlSvgOutput(null, alignPanel);
1373 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1375 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1376 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1378 public void createImageMap(File file, String image)
1380 alignPanel.makePNGImageMap(file, image);
1390 public void createPNG(File f)
1392 alignPanel.makePNG(f);
1402 public void createEPS(File f)
1404 alignPanel.makeEPS(f);
1407 public void createSVG(File f)
1409 alignPanel.makeSVG(f);
1412 public void pageSetup_actionPerformed(ActionEvent e)
1414 PrinterJob printJob = PrinterJob.getPrinterJob();
1415 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1425 public void printMenuItem_actionPerformed(ActionEvent e)
1427 // Putting in a thread avoids Swing painting problems
1428 PrintThread thread = new PrintThread(alignPanel);
1433 public void exportFeatures_actionPerformed(ActionEvent e)
1435 new AnnotationExporter().exportFeatures(alignPanel);
1439 public void exportAnnotations_actionPerformed(ActionEvent e)
1441 new AnnotationExporter().exportAnnotations(alignPanel);
1445 public void associatedData_actionPerformed(ActionEvent e)
1447 // Pick the tree file
1448 JalviewFileChooser chooser = new JalviewFileChooser(
1449 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1450 chooser.setFileView(new JalviewFileView());
1451 chooser.setDialogTitle(MessageManager
1452 .getString("label.load_jalview_annotations"));
1453 chooser.setToolTipText(MessageManager
1454 .getString("label.load_jalview_annotations"));
1456 int value = chooser.showOpenDialog(null);
1458 if (value == JalviewFileChooser.APPROVE_OPTION)
1460 String choice = chooser.getSelectedFile().getPath();
1461 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1462 loadJalviewDataFile(choice, null, null, null);
1468 * Close the current view or all views in the alignment frame. If the frame
1469 * only contains one view then the alignment will be removed from memory.
1471 * @param closeAllTabs
1474 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1476 if (alignPanels != null && alignPanels.size() < 2)
1478 closeAllTabs = true;
1483 if (alignPanels != null)
1487 if (this.isClosed())
1489 // really close all the windows - otherwise wait till
1490 // setClosed(true) is called
1491 for (int i = 0; i < alignPanels.size(); i++)
1493 AlignmentPanel ap = alignPanels.get(i);
1500 closeView(alignPanel);
1507 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1508 * be called recursively, with the frame now in 'closed' state
1510 this.setClosed(true);
1512 } catch (Exception ex)
1514 ex.printStackTrace();
1519 * Close the specified panel and close up tabs appropriately.
1521 * @param panelToClose
1523 public void closeView(AlignmentPanel panelToClose)
1525 int index = tabbedPane.getSelectedIndex();
1526 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1527 alignPanels.remove(panelToClose);
1528 panelToClose.closePanel();
1529 panelToClose = null;
1531 tabbedPane.removeTabAt(closedindex);
1532 tabbedPane.validate();
1534 if (index > closedindex || index == tabbedPane.getTabCount())
1536 // modify currently selected tab index if necessary.
1540 this.tabSelectionChanged(index);
1546 void updateEditMenuBar()
1549 if (viewport.getHistoryList().size() > 0)
1551 undoMenuItem.setEnabled(true);
1552 CommandI command = viewport.getHistoryList().peek();
1553 undoMenuItem.setText(MessageManager.formatMessage(
1554 "label.undo_command", new Object[]
1555 { command.getDescription() }));
1559 undoMenuItem.setEnabled(false);
1560 undoMenuItem.setText(MessageManager.getString("action.undo"));
1563 if (viewport.getRedoList().size() > 0)
1565 redoMenuItem.setEnabled(true);
1567 CommandI command = viewport.getRedoList().peek();
1568 redoMenuItem.setText(MessageManager.formatMessage(
1569 "label.redo_command", new Object[]
1570 { command.getDescription() }));
1574 redoMenuItem.setEnabled(false);
1575 redoMenuItem.setText(MessageManager.getString("action.redo"));
1579 public void addHistoryItem(CommandI command)
1581 if (command.getSize() > 0)
1583 viewport.addToHistoryList(command);
1584 viewport.clearRedoList();
1585 updateEditMenuBar();
1586 viewport.updateHiddenColumns();
1587 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1588 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1589 // viewport.getColumnSelection()
1590 // .getHiddenColumns().size() > 0);
1596 * @return alignment objects for all views
1598 AlignmentI[] getViewAlignments()
1600 if (alignPanels != null)
1602 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1604 for (AlignmentPanel ap : alignPanels)
1606 als[i++] = ap.av.getAlignment();
1610 if (viewport != null)
1612 return new AlignmentI[]
1613 { viewport.getAlignment() };
1625 protected void undoMenuItem_actionPerformed(ActionEvent e)
1627 if (viewport.getHistoryList().isEmpty())
1631 CommandI command = viewport.getHistoryList().pop();
1632 viewport.addToRedoList(command);
1633 command.undoCommand(getViewAlignments());
1635 AlignmentViewport originalSource = getOriginatingSource(command);
1636 updateEditMenuBar();
1638 if (originalSource != null)
1640 if (originalSource != viewport)
1643 .warn("Implementation worry: mismatch of viewport origin for undo");
1645 originalSource.updateHiddenColumns();
1646 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1648 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1649 // viewport.getColumnSelection()
1650 // .getHiddenColumns().size() > 0);
1651 originalSource.firePropertyChange("alignment", null, originalSource
1652 .getAlignment().getSequences());
1663 protected void redoMenuItem_actionPerformed(ActionEvent e)
1665 if (viewport.getRedoList().size() < 1)
1670 CommandI command = viewport.getRedoList().pop();
1671 viewport.addToHistoryList(command);
1672 command.doCommand(getViewAlignments());
1674 AlignmentViewport originalSource = getOriginatingSource(command);
1675 updateEditMenuBar();
1677 if (originalSource != null)
1680 if (originalSource != viewport)
1683 .warn("Implementation worry: mismatch of viewport origin for redo");
1685 originalSource.updateHiddenColumns();
1686 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1688 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1689 // viewport.getColumnSelection()
1690 // .getHiddenColumns().size() > 0);
1691 originalSource.firePropertyChange("alignment", null, originalSource
1692 .getAlignment().getSequences());
1696 AlignmentViewport getOriginatingSource(CommandI command)
1698 AlignmentViewport originalSource = null;
1699 // For sequence removal and addition, we need to fire
1700 // the property change event FROM the viewport where the
1701 // original alignment was altered
1702 AlignmentI al = null;
1703 if (command instanceof EditCommand)
1705 EditCommand editCommand = (EditCommand) command;
1706 al = editCommand.getAlignment();
1707 List<Component> comps = PaintRefresher.components.get(viewport
1708 .getSequenceSetId());
1710 for (Component comp : comps)
1712 if (comp instanceof AlignmentPanel)
1714 if (al == ((AlignmentPanel) comp).av.getAlignment())
1716 originalSource = ((AlignmentPanel) comp).av;
1723 if (originalSource == null)
1725 // The original view is closed, we must validate
1726 // the current view against the closed view first
1729 PaintRefresher.validateSequences(al, viewport.getAlignment());
1732 originalSource = viewport;
1735 return originalSource;
1744 public void moveSelectedSequences(boolean up)
1746 SequenceGroup sg = viewport.getSelectionGroup();
1752 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1753 viewport.getHiddenRepSequences(), up);
1754 alignPanel.paintAlignment(true);
1757 synchronized void slideSequences(boolean right, int size)
1759 List<SequenceI> sg = new ArrayList<SequenceI>();
1760 if (viewport.cursorMode)
1762 sg.add(viewport.getAlignment().getSequenceAt(
1763 alignPanel.getSeqPanel().seqCanvas.cursorY));
1765 else if (viewport.getSelectionGroup() != null
1766 && viewport.getSelectionGroup().getSize() != viewport
1767 .getAlignment().getHeight())
1769 sg = viewport.getSelectionGroup().getSequences(
1770 viewport.getHiddenRepSequences());
1778 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1780 for (SequenceI seq : viewport.getAlignment().getSequences())
1782 if (!sg.contains(seq))
1784 invertGroup.add(seq);
1788 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1790 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1791 for (int i = 0; i < invertGroup.size(); i++)
1793 seqs2[i] = invertGroup.get(i);
1796 SlideSequencesCommand ssc;
1799 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1800 size, viewport.getGapCharacter());
1804 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1805 size, viewport.getGapCharacter());
1808 int groupAdjustment = 0;
1809 if (ssc.getGapsInsertedBegin() && right)
1811 if (viewport.cursorMode)
1813 alignPanel.getSeqPanel().moveCursor(size, 0);
1817 groupAdjustment = size;
1820 else if (!ssc.getGapsInsertedBegin() && !right)
1822 if (viewport.cursorMode)
1824 alignPanel.getSeqPanel().moveCursor(-size, 0);
1828 groupAdjustment = -size;
1832 if (groupAdjustment != 0)
1834 viewport.getSelectionGroup().setStartRes(
1835 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1836 viewport.getSelectionGroup().setEndRes(
1837 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1841 * just extend the last slide command if compatible; but not if in
1842 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
1844 boolean appendHistoryItem = false;
1845 Deque<CommandI> historyList = viewport.getHistoryList();
1846 boolean inSplitFrame = getSplitViewContainer() != null;
1847 if (!inSplitFrame && historyList != null
1848 && historyList.size() > 0
1849 && historyList.peek() instanceof SlideSequencesCommand)
1851 appendHistoryItem = ssc
1852 .appendSlideCommand((SlideSequencesCommand) historyList
1856 if (!appendHistoryItem)
1858 addHistoryItem(ssc);
1871 protected void copy_actionPerformed(ActionEvent e)
1874 if (viewport.getSelectionGroup() == null)
1878 // TODO: preserve the ordering of displayed alignment annotation in any
1879 // internal paste (particularly sequence associated annotation)
1880 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1881 String[] omitHidden = null;
1883 if (viewport.hasHiddenColumns())
1885 omitHidden = viewport.getViewAsString(true);
1888 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1891 StringSelection ss = new StringSelection(output);
1895 jalview.gui.Desktop.internalCopy = true;
1896 // Its really worth setting the clipboard contents
1897 // to empty before setting the large StringSelection!!
1898 Toolkit.getDefaultToolkit().getSystemClipboard()
1899 .setContents(new StringSelection(""), null);
1901 Toolkit.getDefaultToolkit().getSystemClipboard()
1902 .setContents(ss, Desktop.instance);
1903 } catch (OutOfMemoryError er)
1905 new OOMWarning("copying region", er);
1909 ArrayList<int[]> hiddenColumns = null;
1910 if (viewport.hasHiddenColumns())
1912 hiddenColumns = new ArrayList<int[]>();
1913 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1914 .getSelectionGroup().getEndRes();
1915 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1917 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1919 hiddenColumns.add(new int[]
1920 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1925 Desktop.jalviewClipboard = new Object[]
1926 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1927 statusBar.setText(MessageManager.formatMessage(
1928 "label.copied_sequences_to_clipboard", new Object[]
1929 { Integer.valueOf(seqs.length).toString() }));
1939 protected void pasteNew_actionPerformed(ActionEvent e)
1951 protected void pasteThis_actionPerformed(ActionEvent e)
1957 * Paste contents of Jalview clipboard
1959 * @param newAlignment
1960 * true to paste to a new alignment, otherwise add to this.
1962 void paste(boolean newAlignment)
1964 boolean externalPaste = true;
1967 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1968 Transferable contents = c.getContents(this);
1970 if (contents == null)
1978 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1979 if (str.length() < 1)
1984 format = new IdentifyFile().Identify(str, "Paste");
1986 } catch (OutOfMemoryError er)
1988 new OOMWarning("Out of memory pasting sequences!!", er);
1992 SequenceI[] sequences;
1993 boolean annotationAdded = false;
1994 AlignmentI alignment = null;
1996 if (Desktop.jalviewClipboard != null)
1998 // The clipboard was filled from within Jalview, we must use the
2000 // And dataset from the copied alignment
2001 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2002 // be doubly sure that we create *new* sequence objects.
2003 sequences = new SequenceI[newseq.length];
2004 for (int i = 0; i < newseq.length; i++)
2006 sequences[i] = new Sequence(newseq[i]);
2008 alignment = new Alignment(sequences);
2009 externalPaste = false;
2013 // parse the clipboard as an alignment.
2014 alignment = new FormatAdapter().readFile(str, "Paste", format);
2015 sequences = alignment.getSequencesArray();
2019 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2025 if (Desktop.jalviewClipboard != null)
2027 // dataset is inherited
2028 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2032 // new dataset is constructed
2033 alignment.setDataset(null);
2035 alwidth = alignment.getWidth() + 1;
2039 AlignmentI pastedal = alignment; // preserve pasted alignment object
2040 // Add pasted sequences and dataset into existing alignment.
2041 alignment = viewport.getAlignment();
2042 alwidth = alignment.getWidth() + 1;
2043 // decide if we need to import sequences from an existing dataset
2044 boolean importDs = Desktop.jalviewClipboard != null
2045 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2046 // importDs==true instructs us to copy over new dataset sequences from
2047 // an existing alignment
2048 Vector newDs = (importDs) ? new Vector() : null; // used to create
2049 // minimum dataset set
2051 for (int i = 0; i < sequences.length; i++)
2055 newDs.addElement(null);
2057 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2059 if (importDs && ds != null)
2061 if (!newDs.contains(ds))
2063 newDs.setElementAt(ds, i);
2064 ds = new Sequence(ds);
2065 // update with new dataset sequence
2066 sequences[i].setDatasetSequence(ds);
2070 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2075 // copy and derive new dataset sequence
2076 sequences[i] = sequences[i].deriveSequence();
2077 alignment.getDataset().addSequence(
2078 sequences[i].getDatasetSequence());
2079 // TODO: avoid creation of duplicate dataset sequences with a
2080 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2082 alignment.addSequence(sequences[i]); // merges dataset
2086 newDs.clear(); // tidy up
2088 if (alignment.getAlignmentAnnotation() != null)
2090 for (AlignmentAnnotation alan : alignment
2091 .getAlignmentAnnotation())
2093 if (alan.graphGroup > fgroup)
2095 fgroup = alan.graphGroup;
2099 if (pastedal.getAlignmentAnnotation() != null)
2101 // Add any annotation attached to alignment.
2102 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2103 for (int i = 0; i < alann.length; i++)
2105 annotationAdded = true;
2106 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2108 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2109 if (newann.graphGroup > -1)
2111 if (newGraphGroups.size() <= newann.graphGroup
2112 || newGraphGroups.get(newann.graphGroup) == null)
2114 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2116 newGraphGroups.add(q, null);
2118 newGraphGroups.set(newann.graphGroup, new Integer(
2121 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2125 newann.padAnnotation(alwidth);
2126 alignment.addAnnotation(newann);
2136 addHistoryItem(new EditCommand(
2137 MessageManager.getString("label.add_sequences"),
2139 sequences, 0, alignment.getWidth(), alignment));
2141 // Add any annotations attached to sequences
2142 for (int i = 0; i < sequences.length; i++)
2144 if (sequences[i].getAnnotation() != null)
2146 AlignmentAnnotation newann;
2147 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2149 annotationAdded = true;
2150 newann = sequences[i].getAnnotation()[a];
2151 newann.adjustForAlignment();
2152 newann.padAnnotation(alwidth);
2153 if (newann.graphGroup > -1)
2155 if (newann.graphGroup > -1)
2157 if (newGraphGroups.size() <= newann.graphGroup
2158 || newGraphGroups.get(newann.graphGroup) == null)
2160 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2162 newGraphGroups.add(q, null);
2164 newGraphGroups.set(newann.graphGroup, new Integer(
2167 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2171 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2176 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2183 // propagate alignment changed.
2184 viewport.setEndSeq(alignment.getHeight());
2185 if (annotationAdded)
2187 // Duplicate sequence annotation in all views.
2188 AlignmentI[] alview = this.getViewAlignments();
2189 for (int i = 0; i < sequences.length; i++)
2191 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2196 for (int avnum = 0; avnum < alview.length; avnum++)
2198 if (alview[avnum] != alignment)
2200 // duplicate in a view other than the one with input focus
2201 int avwidth = alview[avnum].getWidth() + 1;
2202 // this relies on sann being preserved after we
2203 // modify the sequence's annotation array for each duplication
2204 for (int a = 0; a < sann.length; a++)
2206 AlignmentAnnotation newann = new AlignmentAnnotation(
2208 sequences[i].addAlignmentAnnotation(newann);
2209 newann.padAnnotation(avwidth);
2210 alview[avnum].addAnnotation(newann); // annotation was
2211 // duplicated earlier
2212 // TODO JAL-1145 graphGroups are not updated for sequence
2213 // annotation added to several views. This may cause
2215 alview[avnum].setAnnotationIndex(newann, a);
2220 buildSortByAnnotationScoresMenu();
2222 viewport.firePropertyChange("alignment", null,
2223 alignment.getSequences());
2224 if (alignPanels != null)
2226 for (AlignmentPanel ap : alignPanels)
2228 ap.validateAnnotationDimensions(false);
2233 alignPanel.validateAnnotationDimensions(false);
2239 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2241 String newtitle = new String("Copied sequences");
2243 if (Desktop.jalviewClipboard != null
2244 && Desktop.jalviewClipboard[2] != null)
2246 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2247 for (int[] region : hc)
2249 af.viewport.hideColumns(region[0], region[1]);
2253 // >>>This is a fix for the moment, until a better solution is
2255 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2257 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2259 // TODO: maintain provenance of an alignment, rather than just make the
2260 // title a concatenation of operations.
2263 if (title.startsWith("Copied sequences"))
2269 newtitle = newtitle.concat("- from " + title);
2274 newtitle = new String("Pasted sequences");
2277 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2282 } catch (Exception ex)
2284 ex.printStackTrace();
2285 System.out.println("Exception whilst pasting: " + ex);
2286 // could be anything being pasted in here
2292 protected void expand_newalign(ActionEvent e)
2296 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2297 .getAlignment(), -1);
2298 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2300 String newtitle = new String("Flanking alignment");
2302 if (Desktop.jalviewClipboard != null
2303 && Desktop.jalviewClipboard[2] != null)
2305 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2306 for (int region[] : hc)
2308 af.viewport.hideColumns(region[0], region[1]);
2312 // >>>This is a fix for the moment, until a better solution is
2314 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2316 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2318 // TODO: maintain provenance of an alignment, rather than just make the
2319 // title a concatenation of operations.
2321 if (title.startsWith("Copied sequences"))
2327 newtitle = newtitle.concat("- from " + title);
2331 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2333 } catch (Exception ex)
2335 ex.printStackTrace();
2336 System.out.println("Exception whilst pasting: " + ex);
2337 // could be anything being pasted in here
2338 } catch (OutOfMemoryError oom)
2340 new OOMWarning("Viewing flanking region of alignment", oom);
2351 protected void cut_actionPerformed(ActionEvent e)
2353 copy_actionPerformed(null);
2354 delete_actionPerformed(null);
2364 protected void delete_actionPerformed(ActionEvent evt)
2367 SequenceGroup sg = viewport.getSelectionGroup();
2374 * If the cut affects all sequences, warn, remove highlighted columns
2376 if (sg.getSize() == viewport.getAlignment().getHeight())
2378 int confirm = JOptionPane.showConfirmDialog(this,
2379 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2380 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2381 JOptionPane.OK_CANCEL_OPTION);
2383 if (confirm == JOptionPane.CANCEL_OPTION
2384 || confirm == JOptionPane.CLOSED_OPTION)
2388 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2389 sg.getEndRes() + 1);
2392 SequenceI[] cut = sg.getSequences()
2393 .toArray(new SequenceI[sg.getSize()]);
2395 addHistoryItem(new EditCommand(
2396 MessageManager.getString("label.cut_sequences"), Action.CUT,
2397 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2398 viewport.getAlignment()));
2400 viewport.setSelectionGroup(null);
2401 viewport.sendSelection();
2402 viewport.getAlignment().deleteGroup(sg);
2404 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2406 if (viewport.getAlignment().getHeight() < 1)
2410 this.setClosed(true);
2411 } catch (Exception ex)
2424 protected void deleteGroups_actionPerformed(ActionEvent e)
2426 if (avc.deleteGroups())
2428 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2429 alignPanel.updateAnnotation();
2430 alignPanel.paintAlignment(true);
2441 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2443 SequenceGroup sg = new SequenceGroup();
2445 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2447 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2450 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2451 viewport.setSelectionGroup(sg);
2452 viewport.sendSelection();
2453 alignPanel.paintAlignment(true);
2454 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2464 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2466 if (viewport.cursorMode)
2468 alignPanel.getSeqPanel().keyboardNo1 = null;
2469 alignPanel.getSeqPanel().keyboardNo2 = null;
2471 viewport.setSelectionGroup(null);
2472 viewport.getColumnSelection().clear();
2473 viewport.setSelectionGroup(null);
2474 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2475 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2476 alignPanel.paintAlignment(true);
2477 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2478 viewport.sendSelection();
2488 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2490 SequenceGroup sg = viewport.getSelectionGroup();
2494 selectAllSequenceMenuItem_actionPerformed(null);
2499 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2501 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2504 alignPanel.paintAlignment(true);
2505 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2506 viewport.sendSelection();
2510 public void invertColSel_actionPerformed(ActionEvent e)
2512 viewport.invertColumnSelection();
2513 alignPanel.paintAlignment(true);
2514 viewport.sendSelection();
2524 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2526 trimAlignment(true);
2536 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2538 trimAlignment(false);
2541 void trimAlignment(boolean trimLeft)
2543 ColumnSelection colSel = viewport.getColumnSelection();
2546 if (colSel.size() > 0)
2550 column = colSel.getMin();
2554 column = colSel.getMax();
2558 if (viewport.getSelectionGroup() != null)
2560 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2561 viewport.getHiddenRepSequences());
2565 seqs = viewport.getAlignment().getSequencesArray();
2568 TrimRegionCommand trimRegion;
2571 trimRegion = new TrimRegionCommand("Remove Left",
2572 TrimRegionCommand.TRIM_LEFT, seqs, column,
2573 viewport.getAlignment(), viewport.getColumnSelection(),
2574 viewport.getSelectionGroup());
2575 viewport.setStartRes(0);
2579 trimRegion = new TrimRegionCommand("Remove Right",
2580 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2581 viewport.getAlignment(), viewport.getColumnSelection(),
2582 viewport.getSelectionGroup());
2585 statusBar.setText(MessageManager.formatMessage(
2586 "label.removed_columns", new String[]
2587 { Integer.valueOf(trimRegion.getSize()).toString() }));
2589 addHistoryItem(trimRegion);
2591 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2593 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2594 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2596 viewport.getAlignment().deleteGroup(sg);
2600 viewport.firePropertyChange("alignment", null, viewport
2601 .getAlignment().getSequences());
2612 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2614 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2617 if (viewport.getSelectionGroup() != null)
2619 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2620 viewport.getHiddenRepSequences());
2621 start = viewport.getSelectionGroup().getStartRes();
2622 end = viewport.getSelectionGroup().getEndRes();
2626 seqs = viewport.getAlignment().getSequencesArray();
2629 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2630 "Remove Gapped Columns", seqs, start, end,
2631 viewport.getAlignment());
2633 addHistoryItem(removeGapCols);
2635 statusBar.setText(MessageManager.formatMessage(
2636 "label.removed_empty_columns", new Object[]
2637 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2639 // This is to maintain viewport position on first residue
2640 // of first sequence
2641 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2642 int startRes = seq.findPosition(viewport.startRes);
2643 // ShiftList shifts;
2644 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2645 // edit.alColumnChanges=shifts.getInverse();
2646 // if (viewport.hasHiddenColumns)
2647 // viewport.getColumnSelection().compensateForEdits(shifts);
2648 viewport.setStartRes(seq.findIndex(startRes) - 1);
2649 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2661 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2663 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2666 if (viewport.getSelectionGroup() != null)
2668 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2669 viewport.getHiddenRepSequences());
2670 start = viewport.getSelectionGroup().getStartRes();
2671 end = viewport.getSelectionGroup().getEndRes();
2675 seqs = viewport.getAlignment().getSequencesArray();
2678 // This is to maintain viewport position on first residue
2679 // of first sequence
2680 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2681 int startRes = seq.findPosition(viewport.startRes);
2683 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2684 viewport.getAlignment()));
2686 viewport.setStartRes(seq.findIndex(startRes) - 1);
2688 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2700 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2702 viewport.setPadGaps(padGapsMenuitem.isSelected());
2703 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2714 public void findMenuItem_actionPerformed(ActionEvent e)
2720 * Create a new view of the current alignment.
2723 public void newView_actionPerformed(ActionEvent e)
2725 newView(null, true);
2729 * Creates and shows a new view of the current alignment.
2732 * title of newly created view; if null, one will be generated
2733 * @param copyAnnotation
2734 * if true then duplicate all annnotation, groups and settings
2735 * @return new alignment panel, already displayed.
2737 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2740 * Create a new AlignmentPanel (with its own, new Viewport)
2742 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2744 if (!copyAnnotation)
2747 * remove all groups and annotation except for the automatic stuff
2749 newap.av.getAlignment().deleteAllGroups();
2750 newap.av.getAlignment().deleteAllAnnotations(false);
2753 newap.av.setGatherViewsHere(false);
2755 if (viewport.viewName == null)
2757 viewport.viewName = MessageManager
2758 .getString("label.view_name_original");
2762 * Views share the same edits undo and redo stacks
2764 newap.av.setHistoryList(viewport.getHistoryList());
2765 newap.av.setRedoList(viewport.getRedoList());
2768 * Views share the same mappings; need to deregister any new mappings
2769 * created by copyAlignPanel, and register the new reference to the shared
2772 newap.av.replaceMappings(viewport.getAlignment());
2774 newap.av.viewName = getNewViewName(viewTitle);
2776 addAlignmentPanel(newap, true);
2777 newap.alignmentChanged();
2779 if (alignPanels.size() == 2)
2781 viewport.setGatherViewsHere(true);
2783 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2788 * Make a new name for the view, ensuring it is unique within the current
2789 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2790 * these now use viewId. Unique view names are still desirable for usability.)
2795 protected String getNewViewName(String viewTitle)
2797 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2798 boolean addFirstIndex = false;
2799 if (viewTitle == null || viewTitle.trim().length() == 0)
2801 viewTitle = MessageManager.getString("action.view");
2802 addFirstIndex = true;
2806 index = 1;// we count from 1 if given a specific name
2808 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2810 List<Component> comps = PaintRefresher.components.get(viewport
2811 .getSequenceSetId());
2813 List<String> existingNames = getExistingViewNames(comps);
2815 while (existingNames.contains(newViewName))
2817 newViewName = viewTitle + " " + (++index);
2823 * Returns a list of distinct view names found in the given list of
2824 * components. View names are held on the viewport of an AlignmentPanel.
2829 protected List<String> getExistingViewNames(List<Component> comps)
2831 List<String> existingNames = new ArrayList<String>();
2832 for (Component comp : comps)
2834 if (comp instanceof AlignmentPanel)
2836 AlignmentPanel ap = (AlignmentPanel) comp;
2837 if (!existingNames.contains(ap.av.viewName))
2839 existingNames.add(ap.av.viewName);
2843 return existingNames;
2847 * Explode tabbed views into separate windows.
2850 public void expandViews_actionPerformed(ActionEvent e)
2852 Desktop.instance.explodeViews(this);
2856 * Gather views in separate windows back into a tabbed presentation.
2859 public void gatherViews_actionPerformed(ActionEvent e)
2861 Desktop.instance.gatherViews(this);
2871 public void font_actionPerformed(ActionEvent e)
2873 new FontChooser(alignPanel);
2883 protected void seqLimit_actionPerformed(ActionEvent e)
2885 viewport.setShowJVSuffix(seqLimits.isSelected());
2887 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2888 .calculateIdWidth());
2889 alignPanel.paintAlignment(true);
2893 public void idRightAlign_actionPerformed(ActionEvent e)
2895 viewport.setRightAlignIds(idRightAlign.isSelected());
2896 alignPanel.paintAlignment(true);
2900 public void centreColumnLabels_actionPerformed(ActionEvent e)
2902 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2903 alignPanel.paintAlignment(true);
2909 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2912 protected void followHighlight_actionPerformed()
2915 * Set the 'follow' flag on the Viewport (and scroll to position if now
2918 final boolean state = this.followHighlightMenuItem.getState();
2919 viewport.setFollowHighlight(state);
2922 alignPanel.scrollToPosition(
2923 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2934 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2936 viewport.setColourText(colourTextMenuItem.isSelected());
2937 alignPanel.paintAlignment(true);
2947 public void wrapMenuItem_actionPerformed(ActionEvent e)
2949 scaleAbove.setVisible(wrapMenuItem.isSelected());
2950 scaleLeft.setVisible(wrapMenuItem.isSelected());
2951 scaleRight.setVisible(wrapMenuItem.isSelected());
2952 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2953 alignPanel.updateLayout();
2957 public void showAllSeqs_actionPerformed(ActionEvent e)
2959 viewport.showAllHiddenSeqs();
2963 public void showAllColumns_actionPerformed(ActionEvent e)
2965 viewport.showAllHiddenColumns();
2970 public void hideSelSequences_actionPerformed(ActionEvent e)
2972 viewport.hideAllSelectedSeqs();
2973 // alignPanel.paintAlignment(true);
2977 * called by key handler and the hide all/show all menu items
2982 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2985 boolean hide = false;
2986 SequenceGroup sg = viewport.getSelectionGroup();
2987 if (!toggleSeqs && !toggleCols)
2989 // Hide everything by the current selection - this is a hack - we do the
2990 // invert and then hide
2991 // first check that there will be visible columns after the invert.
2992 if ((viewport.getColumnSelection() != null
2993 && viewport.getColumnSelection().getSelected() != null && viewport
2994 .getColumnSelection().getSelected().size() > 0)
2995 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2998 // now invert the sequence set, if required - empty selection implies
2999 // that no hiding is required.
3002 invertSequenceMenuItem_actionPerformed(null);
3003 sg = viewport.getSelectionGroup();
3007 viewport.expandColSelection(sg, true);
3008 // finally invert the column selection and get the new sequence
3010 invertColSel_actionPerformed(null);
3017 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3019 hideSelSequences_actionPerformed(null);
3022 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3025 showAllSeqs_actionPerformed(null);
3031 if (viewport.getColumnSelection().getSelected().size() > 0)
3033 hideSelColumns_actionPerformed(null);
3036 viewport.setSelectionGroup(sg);
3041 showAllColumns_actionPerformed(null);
3050 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3051 * event.ActionEvent)
3054 public void hideAllButSelection_actionPerformed(ActionEvent e)
3056 toggleHiddenRegions(false, false);
3063 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3067 public void hideAllSelection_actionPerformed(ActionEvent e)
3069 SequenceGroup sg = viewport.getSelectionGroup();
3070 viewport.expandColSelection(sg, false);
3071 viewport.hideAllSelectedSeqs();
3072 viewport.hideSelectedColumns();
3073 alignPanel.paintAlignment(true);
3080 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3084 public void showAllhidden_actionPerformed(ActionEvent e)
3086 viewport.showAllHiddenColumns();
3087 viewport.showAllHiddenSeqs();
3088 alignPanel.paintAlignment(true);
3092 public void hideSelColumns_actionPerformed(ActionEvent e)
3094 viewport.hideSelectedColumns();
3095 alignPanel.paintAlignment(true);
3099 public void hiddenMarkers_actionPerformed(ActionEvent e)
3101 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3112 protected void scaleAbove_actionPerformed(ActionEvent e)
3114 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3115 alignPanel.paintAlignment(true);
3125 protected void scaleLeft_actionPerformed(ActionEvent e)
3127 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3128 alignPanel.paintAlignment(true);
3138 protected void scaleRight_actionPerformed(ActionEvent e)
3140 viewport.setScaleRightWrapped(scaleRight.isSelected());
3141 alignPanel.paintAlignment(true);
3151 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3153 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3154 alignPanel.paintAlignment(true);
3164 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3166 viewport.setShowText(viewTextMenuItem.isSelected());
3167 alignPanel.paintAlignment(true);
3177 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3179 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3180 alignPanel.paintAlignment(true);
3183 public FeatureSettings featureSettings;
3186 public FeatureSettingsControllerI getFeatureSettingsUI()
3188 return featureSettings;
3192 public void featureSettings_actionPerformed(ActionEvent e)
3194 if (featureSettings != null)
3196 featureSettings.close();
3197 featureSettings = null;
3199 if (!showSeqFeatures.isSelected())
3201 // make sure features are actually displayed
3202 showSeqFeatures.setSelected(true);
3203 showSeqFeatures_actionPerformed(null);
3205 featureSettings = new FeatureSettings(this);
3209 * Set or clear 'Show Sequence Features'
3215 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3217 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3218 alignPanel.paintAlignment(true);
3219 if (alignPanel.getOverviewPanel() != null)
3221 alignPanel.getOverviewPanel().updateOverviewImage();
3226 * Set or clear 'Show Sequence Features'
3232 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3234 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3236 if (viewport.isShowSequenceFeaturesHeight())
3238 // ensure we're actually displaying features
3239 viewport.setShowSequenceFeatures(true);
3240 showSeqFeatures.setSelected(true);
3242 alignPanel.paintAlignment(true);
3243 if (alignPanel.getOverviewPanel() != null)
3245 alignPanel.getOverviewPanel().updateOverviewImage();
3250 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3251 * the annotations panel as a whole.
3253 * The options to show/hide all annotations should be enabled when the panel
3254 * is shown, and disabled when the panel is hidden.
3259 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3261 final boolean setVisible = annotationPanelMenuItem.isSelected();
3262 viewport.setShowAnnotation(setVisible);
3263 this.showAllSeqAnnotations.setEnabled(setVisible);
3264 this.hideAllSeqAnnotations.setEnabled(setVisible);
3265 this.showAllAlAnnotations.setEnabled(setVisible);
3266 this.hideAllAlAnnotations.setEnabled(setVisible);
3267 alignPanel.updateLayout();
3271 public void alignmentProperties()
3273 JEditorPane editPane = new JEditorPane("text/html", "");
3274 editPane.setEditable(false);
3275 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3277 editPane.setText(MessageManager.formatMessage("label.html_content",
3279 { contents.toString() }));
3280 JInternalFrame frame = new JInternalFrame();
3281 frame.getContentPane().add(new JScrollPane(editPane));
3283 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3284 "label.alignment_properties", new Object[]
3285 { getTitle() }), 500, 400);
3295 public void overviewMenuItem_actionPerformed(ActionEvent e)
3297 if (alignPanel.overviewPanel != null)
3302 JInternalFrame frame = new JInternalFrame();
3303 OverviewPanel overview = new OverviewPanel(alignPanel);
3304 frame.setContentPane(overview);
3305 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3306 "label.overview_params", new Object[]
3307 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3309 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3310 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3313 public void internalFrameClosed(
3314 javax.swing.event.InternalFrameEvent evt)
3316 alignPanel.setOverviewPanel(null);
3320 alignPanel.setOverviewPanel(overview);
3324 public void textColour_actionPerformed(ActionEvent e)
3326 new TextColourChooser().chooseColour(alignPanel, null);
3336 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3348 public void clustalColour_actionPerformed(ActionEvent e)
3350 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3351 viewport.getHiddenRepSequences()));
3361 public void zappoColour_actionPerformed(ActionEvent e)
3363 changeColour(new ZappoColourScheme());
3373 public void taylorColour_actionPerformed(ActionEvent e)
3375 changeColour(new TaylorColourScheme());
3385 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3387 changeColour(new HydrophobicColourScheme());
3397 public void helixColour_actionPerformed(ActionEvent e)
3399 changeColour(new HelixColourScheme());
3409 public void strandColour_actionPerformed(ActionEvent e)
3411 changeColour(new StrandColourScheme());
3421 public void turnColour_actionPerformed(ActionEvent e)
3423 changeColour(new TurnColourScheme());
3433 public void buriedColour_actionPerformed(ActionEvent e)
3435 changeColour(new BuriedColourScheme());
3445 public void nucleotideColour_actionPerformed(ActionEvent e)
3447 changeColour(new NucleotideColourScheme());
3451 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3453 changeColour(new PurinePyrimidineColourScheme());
3457 * public void covariationColour_actionPerformed(ActionEvent e) {
3459 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3463 public void annotationColour_actionPerformed(ActionEvent e)
3465 new AnnotationColourChooser(viewport, alignPanel);
3469 public void annotationColumn_actionPerformed(ActionEvent e)
3471 new AnnotationColumnChooser(viewport, alignPanel);
3475 public void rnahelicesColour_actionPerformed(ActionEvent e)
3477 new RNAHelicesColourChooser(viewport, alignPanel);
3487 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3489 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3498 public void changeColour(ColourSchemeI cs)
3500 // TODO: pull up to controller method
3504 // Make sure viewport is up to date w.r.t. any sliders
3505 if (viewport.getAbovePIDThreshold())
3507 int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3509 viewport.setThreshold(threshold);
3512 if (viewport.getConservationSelected())
3514 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3519 viewport.setGlobalColourScheme(cs);
3521 alignPanel.paintAlignment(true);
3531 protected void modifyPID_actionPerformed(ActionEvent e)
3533 if (viewport.getAbovePIDThreshold()
3534 && viewport.getGlobalColourScheme() != null)
3536 SliderPanel.setPIDSliderSource(alignPanel,
3537 viewport.getGlobalColourScheme(), "Background");
3538 SliderPanel.showPIDSlider();
3549 protected void modifyConservation_actionPerformed(ActionEvent e)
3551 if (viewport.getConservationSelected()
3552 && viewport.getGlobalColourScheme() != null)
3554 SliderPanel.setConservationSlider(alignPanel,
3555 viewport.getGlobalColourScheme(), "Background");
3556 SliderPanel.showConservationSlider();
3567 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3569 viewport.setConservationSelected(conservationMenuItem.isSelected());
3571 viewport.setAbovePIDThreshold(false);
3572 abovePIDThreshold.setSelected(false);
3574 changeColour(viewport.getGlobalColourScheme());
3576 modifyConservation_actionPerformed(null);
3586 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3588 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3590 conservationMenuItem.setSelected(false);
3591 viewport.setConservationSelected(false);
3593 changeColour(viewport.getGlobalColourScheme());
3595 modifyPID_actionPerformed(null);
3605 public void userDefinedColour_actionPerformed(ActionEvent e)
3607 if (e.getActionCommand().equals(
3608 MessageManager.getString("action.user_defined")))
3610 new UserDefinedColours(alignPanel, null);
3614 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3615 .getUserColourSchemes().get(e.getActionCommand());
3621 public void updateUserColourMenu()
3624 Component[] menuItems = colourMenu.getMenuComponents();
3625 int iSize = menuItems.length;
3626 for (int i = 0; i < iSize; i++)
3628 if (menuItems[i].getName() != null
3629 && menuItems[i].getName().equals("USER_DEFINED"))
3631 colourMenu.remove(menuItems[i]);
3635 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3637 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3638 .getUserColourSchemes().keys();
3640 while (userColours.hasMoreElements())
3642 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3643 userColours.nextElement().toString());
3644 radioItem.setName("USER_DEFINED");
3645 radioItem.addMouseListener(new MouseAdapter()
3648 public void mousePressed(MouseEvent evt)
3650 if (evt.isControlDown()
3651 || SwingUtilities.isRightMouseButton(evt))
3653 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3655 int option = JOptionPane.showInternalConfirmDialog(
3656 jalview.gui.Desktop.desktop,
3658 .getString("label.remove_from_default_list"),
3660 .getString("label.remove_user_defined_colour"),
3661 JOptionPane.YES_NO_OPTION);
3662 if (option == JOptionPane.YES_OPTION)
3664 jalview.gui.UserDefinedColours
3665 .removeColourFromDefaults(radioItem.getText());
3666 colourMenu.remove(radioItem);
3670 radioItem.addActionListener(new ActionListener()
3673 public void actionPerformed(ActionEvent evt)
3675 userDefinedColour_actionPerformed(evt);
3682 radioItem.addActionListener(new ActionListener()
3685 public void actionPerformed(ActionEvent evt)
3687 userDefinedColour_actionPerformed(evt);
3691 colourMenu.insert(radioItem, 15);
3692 colours.add(radioItem);
3704 public void PIDColour_actionPerformed(ActionEvent e)
3706 changeColour(new PIDColourScheme());
3716 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3718 changeColour(new Blosum62ColourScheme());
3728 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3730 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3731 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3732 .getAlignment().getSequenceAt(0), null);
3733 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3734 viewport.getAlignment()));
3735 alignPanel.paintAlignment(true);
3745 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3747 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3748 AlignmentSorter.sortByID(viewport.getAlignment());
3749 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3750 viewport.getAlignment()));
3751 alignPanel.paintAlignment(true);
3761 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3763 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3764 AlignmentSorter.sortByLength(viewport.getAlignment());
3765 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3766 viewport.getAlignment()));
3767 alignPanel.paintAlignment(true);
3777 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3779 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3780 AlignmentSorter.sortByGroup(viewport.getAlignment());
3781 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3782 viewport.getAlignment()));
3784 alignPanel.paintAlignment(true);
3794 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3796 new RedundancyPanel(alignPanel, this);
3806 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3808 if ((viewport.getSelectionGroup() == null)
3809 || (viewport.getSelectionGroup().getSize() < 2))
3811 JOptionPane.showInternalMessageDialog(this, MessageManager
3812 .getString("label.you_must_select_least_two_sequences"),
3813 MessageManager.getString("label.invalid_selection"),
3814 JOptionPane.WARNING_MESSAGE);
3818 JInternalFrame frame = new JInternalFrame();
3819 frame.setContentPane(new PairwiseAlignPanel(viewport));
3820 Desktop.addInternalFrame(frame,
3821 MessageManager.getString("action.pairwise_alignment"), 600,
3833 public void PCAMenuItem_actionPerformed(ActionEvent e)
3835 if (((viewport.getSelectionGroup() != null)
3836 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3837 .getSelectionGroup().getSize() > 0))
3838 || (viewport.getAlignment().getHeight() < 4))
3841 .showInternalMessageDialog(
3844 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3846 .getString("label.sequence_selection_insufficient"),
3847 JOptionPane.WARNING_MESSAGE);
3852 new PCAPanel(alignPanel);
3856 public void autoCalculate_actionPerformed(ActionEvent e)
3858 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3859 if (viewport.autoCalculateConsensus)
3861 viewport.firePropertyChange("alignment", null, viewport
3862 .getAlignment().getSequences());
3867 public void sortByTreeOption_actionPerformed(ActionEvent e)
3869 viewport.sortByTree = sortByTree.isSelected();
3873 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3875 viewport.followSelection = listenToViewSelections.isSelected();
3885 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3887 newTreePanel("AV", "PID", "Average distance tree using PID");
3897 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3899 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3909 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3911 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3921 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3923 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3936 void newTreePanel(String type, String pwType, String title)
3940 if (viewport.getSelectionGroup() != null
3941 && viewport.getSelectionGroup().getSize() > 0)
3943 if (viewport.getSelectionGroup().getSize() < 3)
3949 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3951 .getString("label.not_enough_sequences"),
3952 JOptionPane.WARNING_MESSAGE);
3956 SequenceGroup sg = viewport.getSelectionGroup();
3958 /* Decide if the selection is a column region */
3959 for (SequenceI _s : sg.getSequences())
3961 if (_s.getLength() < sg.getEndRes())
3967 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3969 .getString("label.sequences_selection_not_aligned"),
3970 JOptionPane.WARNING_MESSAGE);
3976 title = title + " on region";
3977 tp = new TreePanel(alignPanel, type, pwType);
3981 // are the visible sequences aligned?
3982 if (!viewport.getAlignment().isAligned(false))
3988 .getString("label.sequences_must_be_aligned_before_creating_tree"),
3990 .getString("label.sequences_not_aligned"),
3991 JOptionPane.WARNING_MESSAGE);
3996 if (viewport.getAlignment().getHeight() < 2)
4001 tp = new TreePanel(alignPanel, type, pwType);
4006 if (viewport.viewName != null)
4008 title += viewport.viewName + " of ";
4011 title += this.title;
4013 Desktop.addInternalFrame(tp, title, 600, 500);
4024 public void addSortByOrderMenuItem(String title,
4025 final AlignmentOrder order)
4027 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4029 item.addActionListener(new java.awt.event.ActionListener()
4032 public void actionPerformed(ActionEvent e)
4034 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4036 // TODO: JBPNote - have to map order entries to curent SequenceI
4038 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4040 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4043 alignPanel.paintAlignment(true);
4049 * Add a new sort by annotation score menu item
4052 * the menu to add the option to
4054 * the label used to retrieve scores for each sequence on the
4057 public void addSortByAnnotScoreMenuItem(JMenu sort,
4058 final String scoreLabel)
4060 final JMenuItem item = new JMenuItem(scoreLabel);
4062 item.addActionListener(new java.awt.event.ActionListener()
4065 public void actionPerformed(ActionEvent e)
4067 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4068 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4069 viewport.getAlignment());// ,viewport.getSelectionGroup());
4070 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4071 viewport.getAlignment()));
4072 alignPanel.paintAlignment(true);
4078 * last hash for alignment's annotation array - used to minimise cost of
4081 protected int _annotationScoreVectorHash;
4084 * search the alignment and rebuild the sort by annotation score submenu the
4085 * last alignment annotation vector hash is stored to minimize cost of
4086 * rebuilding in subsequence calls.
4090 public void buildSortByAnnotationScoresMenu()
4092 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4097 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4099 sortByAnnotScore.removeAll();
4100 // almost certainly a quicker way to do this - but we keep it simple
4101 Hashtable scoreSorts = new Hashtable();
4102 AlignmentAnnotation aann[];
4103 for (SequenceI sqa : viewport.getAlignment().getSequences())
4105 aann = sqa.getAnnotation();
4106 for (int i = 0; aann != null && i < aann.length; i++)
4108 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4110 scoreSorts.put(aann[i].label, aann[i].label);
4114 Enumeration labels = scoreSorts.keys();
4115 while (labels.hasMoreElements())
4117 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4118 (String) labels.nextElement());
4120 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4123 _annotationScoreVectorHash = viewport.getAlignment()
4124 .getAlignmentAnnotation().hashCode();
4129 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4130 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4131 * call. Listeners are added to remove the menu item when the treePanel is
4132 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4136 * Displayed tree window.
4138 * SortBy menu item title.
4141 public void buildTreeMenu()
4143 calculateTree.removeAll();
4144 // build the calculate menu
4146 for (final String type : new String[]
4149 String treecalcnm = MessageManager.getString("label.tree_calc_"
4150 + type.toLowerCase());
4151 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4153 JMenuItem tm = new JMenuItem();
4154 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4155 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4157 String smn = MessageManager.getStringOrReturn(
4158 "label.score_model_", sm.getName());
4159 final String title = MessageManager.formatMessage(
4160 "label.treecalc_title", treecalcnm, smn);
4161 tm.setText(title);//
4162 tm.addActionListener(new java.awt.event.ActionListener()
4165 public void actionPerformed(ActionEvent e)
4167 newTreePanel(type, pwtype, title);
4170 calculateTree.add(tm);
4175 sortByTreeMenu.removeAll();
4177 List<Component> comps = PaintRefresher.components.get(viewport
4178 .getSequenceSetId());
4179 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4180 for (Component comp : comps)
4182 if (comp instanceof TreePanel)
4184 treePanels.add((TreePanel) comp);
4188 if (treePanels.size() < 1)
4190 sortByTreeMenu.setVisible(false);
4194 sortByTreeMenu.setVisible(true);
4196 for (final TreePanel tp : treePanels)
4198 final JMenuItem item = new JMenuItem(tp.getTitle());
4199 item.addActionListener(new java.awt.event.ActionListener()
4202 public void actionPerformed(ActionEvent e)
4204 tp.sortByTree_actionPerformed();
4205 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4210 sortByTreeMenu.add(item);
4214 public boolean sortBy(AlignmentOrder alorder, String undoname)
4216 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4217 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4218 if (undoname != null)
4220 addHistoryItem(new OrderCommand(undoname, oldOrder,
4221 viewport.getAlignment()));
4223 alignPanel.paintAlignment(true);
4228 * Work out whether the whole set of sequences or just the selected set will
4229 * be submitted for multiple alignment.
4232 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4234 // Now, check we have enough sequences
4235 AlignmentView msa = null;
4237 if ((viewport.getSelectionGroup() != null)
4238 && (viewport.getSelectionGroup().getSize() > 1))
4240 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4241 // some common interface!
4243 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4244 * SequenceI[sz = seqs.getSize(false)];
4246 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4247 * seqs.getSequenceAt(i); }
4249 msa = viewport.getAlignmentView(true);
4251 else if (viewport.getSelectionGroup() != null
4252 && viewport.getSelectionGroup().getSize() == 1)
4254 int option = JOptionPane.showConfirmDialog(this,
4255 MessageManager.getString("warn.oneseq_msainput_selection"),
4256 MessageManager.getString("label.invalid_selection"),
4257 JOptionPane.OK_CANCEL_OPTION);
4258 if (option == JOptionPane.OK_OPTION)
4260 msa = viewport.getAlignmentView(false);
4265 msa = viewport.getAlignmentView(false);
4271 * Decides what is submitted to a secondary structure prediction service: the
4272 * first sequence in the alignment, or in the current selection, or, if the
4273 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4274 * region or the whole alignment. (where the first sequence in the set is the
4275 * one that the prediction will be for).
4277 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4279 AlignmentView seqs = null;
4281 if ((viewport.getSelectionGroup() != null)
4282 && (viewport.getSelectionGroup().getSize() > 0))
4284 seqs = viewport.getAlignmentView(true);
4288 seqs = viewport.getAlignmentView(false);
4290 // limit sequences - JBPNote in future - could spawn multiple prediction
4292 // TODO: viewport.getAlignment().isAligned is a global state - the local
4293 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4294 if (!viewport.getAlignment().isAligned(false))
4296 seqs.setSequences(new SeqCigar[]
4297 { seqs.getSequences()[0] });
4298 // TODO: if seqs.getSequences().length>1 then should really have warned
4312 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4314 // Pick the tree file
4315 JalviewFileChooser chooser = new JalviewFileChooser(
4316 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4317 chooser.setFileView(new JalviewFileView());
4318 chooser.setDialogTitle(MessageManager
4319 .getString("label.select_newick_like_tree_file"));
4320 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4322 int value = chooser.showOpenDialog(null);
4324 if (value == JalviewFileChooser.APPROVE_OPTION)
4326 String choice = chooser.getSelectedFile().getPath();
4327 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4328 jalview.io.NewickFile fin = null;
4331 fin = new jalview.io.NewickFile(choice, "File");
4332 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4333 } catch (Exception ex)
4340 .getString("label.problem_reading_tree_file"),
4341 JOptionPane.WARNING_MESSAGE);
4342 ex.printStackTrace();
4344 if (fin != null && fin.hasWarningMessage())
4346 JOptionPane.showMessageDialog(Desktop.desktop, fin
4347 .getWarningMessage(), MessageManager
4348 .getString("label.possible_problem_with_tree_file"),
4349 JOptionPane.WARNING_MESSAGE);
4355 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4357 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4360 public TreePanel ShowNewickTree(NewickFile nf, String title)
4362 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4365 public TreePanel ShowNewickTree(NewickFile nf, String title,
4366 AlignmentView input)
4368 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4371 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4372 int h, int x, int y)
4374 return ShowNewickTree(nf, title, null, w, h, x, y);
4378 * Add a treeviewer for the tree extracted from a newick file object to the
4379 * current alignment view
4386 * Associated alignment input data (or null)
4395 * @return TreePanel handle
4397 public TreePanel ShowNewickTree(NewickFile nf, String title,
4398 AlignmentView input, int w, int h, int x, int y)
4400 TreePanel tp = null;
4406 if (nf.getTree() != null)
4408 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4414 tp.setLocation(x, y);
4417 Desktop.addInternalFrame(tp, title, w, h);
4419 } catch (Exception ex)
4421 ex.printStackTrace();
4427 private boolean buildingMenu = false;
4430 * Generates menu items and listener event actions for web service clients
4433 public void BuildWebServiceMenu()
4435 while (buildingMenu)
4439 System.err.println("Waiting for building menu to finish.");
4441 } catch (Exception e)
4445 final AlignFrame me = this;
4446 buildingMenu = true;
4447 new Thread(new Runnable()
4452 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4455 // System.err.println("Building ws menu again "
4456 // + Thread.currentThread());
4457 // TODO: add support for context dependent disabling of services based
4459 // alignment and current selection
4460 // TODO: add additional serviceHandle parameter to specify abstract
4462 // class independently of AbstractName
4463 // TODO: add in rediscovery GUI function to restart discoverer
4464 // TODO: group services by location as well as function and/or
4466 // object broker mechanism.
4467 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4468 final IProgressIndicator af = me;
4469 final JMenu msawsmenu = new JMenu("Alignment");
4470 final JMenu secstrmenu = new JMenu(
4471 "Secondary Structure Prediction");
4472 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4473 final JMenu analymenu = new JMenu("Analysis");
4474 final JMenu dismenu = new JMenu("Protein Disorder");
4475 // final JMenu msawsmenu = new
4476 // JMenu(MessageManager.getString("label.alignment"));
4477 // final JMenu secstrmenu = new
4478 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4479 // final JMenu seqsrchmenu = new
4480 // JMenu(MessageManager.getString("label.sequence_database_search"));
4481 // final JMenu analymenu = new
4482 // JMenu(MessageManager.getString("label.analysis"));
4483 // final JMenu dismenu = new
4484 // JMenu(MessageManager.getString("label.protein_disorder"));
4485 // JAL-940 - only show secondary structure prediction services from
4486 // the legacy server
4487 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4489 Discoverer.services != null && (Discoverer.services.size() > 0))
4491 // TODO: refactor to allow list of AbstractName/Handler bindings to
4493 // stored or retrieved from elsewhere
4494 // No MSAWS used any more:
4495 // Vector msaws = null; // (Vector)
4496 // Discoverer.services.get("MsaWS");
4497 Vector secstrpr = (Vector) Discoverer.services
4499 if (secstrpr != null)
4501 // Add any secondary structure prediction services
4502 for (int i = 0, j = secstrpr.size(); i < j; i++)
4504 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4506 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4507 .getServiceClient(sh);
4508 int p = secstrmenu.getItemCount();
4509 impl.attachWSMenuEntry(secstrmenu, me);
4510 int q = secstrmenu.getItemCount();
4511 for (int litm = p; litm < q; litm++)
4513 legacyItems.add(secstrmenu.getItem(litm));
4519 // Add all submenus in the order they should appear on the web
4521 wsmenu.add(msawsmenu);
4522 wsmenu.add(secstrmenu);
4523 wsmenu.add(dismenu);
4524 wsmenu.add(analymenu);
4525 // No search services yet
4526 // wsmenu.add(seqsrchmenu);
4528 javax.swing.SwingUtilities.invokeLater(new Runnable()
4535 webService.removeAll();
4536 // first, add discovered services onto the webservices menu
4537 if (wsmenu.size() > 0)
4539 for (int i = 0, j = wsmenu.size(); i < j; i++)
4541 webService.add(wsmenu.get(i));
4546 webService.add(me.webServiceNoServices);
4548 // TODO: move into separate menu builder class.
4549 boolean new_sspred = false;
4550 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4552 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4553 if (jws2servs != null)
4555 if (jws2servs.hasServices())
4557 jws2servs.attachWSMenuEntry(webService, me);
4558 for (Jws2Instance sv : jws2servs.getServices())
4560 if (sv.description.toLowerCase().contains("jpred"))
4562 for (JMenuItem jmi : legacyItems)
4564 jmi.setVisible(false);
4570 if (jws2servs.isRunning())
4572 JMenuItem tm = new JMenuItem(
4573 "Still discovering JABA Services");
4574 tm.setEnabled(false);
4579 build_urlServiceMenu(me.webService);
4580 build_fetchdbmenu(webService);
4581 for (JMenu item : wsmenu)
4583 if (item.getItemCount() == 0)
4585 item.setEnabled(false);
4589 item.setEnabled(true);
4592 } catch (Exception e)
4595 .debug("Exception during web service menu building process.",
4600 } catch (Exception e)
4603 buildingMenu = false;
4610 * construct any groupURL type service menu entries.
4614 private void build_urlServiceMenu(JMenu webService)
4616 // TODO: remove this code when 2.7 is released
4617 // DEBUG - alignmentView
4619 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4620 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4622 * @Override public void actionPerformed(ActionEvent e) {
4623 * jalview.datamodel.AlignmentView
4624 * .testSelectionViews(af.viewport.getAlignment(),
4625 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4627 * }); webService.add(testAlView);
4629 // TODO: refactor to RestClient discoverer and merge menu entries for
4630 // rest-style services with other types of analysis/calculation service
4631 // SHmmr test client - still being implemented.
4632 // DEBUG - alignmentView
4634 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4637 client.attachWSMenuEntry(
4638 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4644 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4645 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4646 * getProperty("LAST_DIRECTORY"));
4648 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4649 * to Vamsas file"); chooser.setToolTipText("Export");
4651 * int value = chooser.showSaveDialog(this);
4653 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4654 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4655 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4656 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4659 * prototype of an automatically enabled/disabled analysis function
4662 protected void setShowProductsEnabled()
4664 SequenceI[] selection = viewport.getSequenceSelection();
4665 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4666 viewport.getAlignment().getDataset()))
4668 showProducts.setEnabled(true);
4673 showProducts.setEnabled(false);
4678 * search selection for sequence xRef products and build the show products
4683 * @return true if showProducts menu should be enabled.
4685 public boolean canShowProducts(SequenceI[] selection,
4686 boolean isRegionSelection, Alignment dataset)
4688 boolean showp = false;
4691 showProducts.removeAll();
4692 final boolean dna = viewport.getAlignment().isNucleotide();
4693 final Alignment ds = dataset;
4694 String[] ptypes = (selection == null || selection.length == 0) ? null
4695 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4697 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4698 // selection, dataset, true);
4699 final SequenceI[] sel = selection;
4700 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4703 final boolean isRegSel = isRegionSelection;
4704 final AlignFrame af = this;
4705 final String source = ptypes[t];
4706 JMenuItem xtype = new JMenuItem(ptypes[t]);
4707 xtype.addActionListener(new ActionListener()
4711 public void actionPerformed(ActionEvent e)
4713 // TODO: new thread for this call with vis-delay
4714 af.showProductsFor(af.viewport.getSequenceSelection(),
4715 isRegSel, dna, source);
4719 showProducts.add(xtype);
4721 showProducts.setVisible(showp);
4722 showProducts.setEnabled(showp);
4723 } catch (Exception e)
4725 jalview.bin.Cache.log
4726 .warn("canTranslate threw an exception - please report to help@jalview.org",
4733 protected void showProductsFor(final SequenceI[] sel,
4734 final boolean isRegSel, final boolean dna, final String source)
4736 Runnable foo = new Runnable()
4742 final long sttime = System.currentTimeMillis();
4743 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4744 "status.searching_for_sequences_from", new Object[]
4745 { source }), sttime);
4748 // update our local dataset reference
4749 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4751 Alignment prods = CrossRef
4752 .findXrefSequences(sel, dna, source, ds);
4755 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4756 for (int s = 0; s < sprods.length; s++)
4758 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4759 if (ds.getSequences() == null
4760 || !ds.getSequences().contains(
4761 sprods[s].getDatasetSequence()))
4763 ds.addSequence(sprods[s].getDatasetSequence());
4765 sprods[s].updatePDBIds();
4767 Alignment al = new Alignment(sprods);
4771 * Copy dna-to-protein mappings to new alignment
4773 // TODO 1: no mappings are set up for EMBL product
4774 // TODO 2: if they were, should add them to protein alignment, not
4776 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4777 for (AlignedCodonFrame acf : cf)
4779 al.addCodonFrame(acf);
4781 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4783 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4784 + " for " + ((isRegSel) ? "selected region of " : "")
4786 naf.setTitle(newtitle);
4788 // temporary flag until SplitFrame is released
4789 boolean asSplitFrame = Cache.getDefault(
4790 Preferences.ENABLE_SPLIT_FRAME, true);
4794 * Make a copy of this alignment (sharing the same dataset
4795 * sequences). If we are DNA, drop introns and update mappings
4797 AlignmentI copyAlignment = null;
4798 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4799 .getSequenceSelection();
4802 copyAlignment = AlignmentUtils.makeExonAlignment(
4803 sequenceSelection, cf);
4804 al.getCodonFrames().clear();
4805 al.getCodonFrames().addAll(cf);
4806 final StructureSelectionManager ssm = StructureSelectionManager
4807 .getStructureSelectionManager(Desktop.instance);
4808 ssm.registerMappings(cf);
4812 copyAlignment = new Alignment(new Alignment(
4813 sequenceSelection));
4815 AlignFrame copyThis = new AlignFrame(copyAlignment,
4816 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4817 copyThis.setTitle(AlignFrame.this.getTitle());
4818 // SplitFrame with dna above, protein below
4819 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4820 dna ? naf : copyThis);
4821 naf.setVisible(true);
4822 copyThis.setVisible(true);
4823 String linkedTitle = MessageManager
4824 .getString("label.linked_view_title");
4825 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4829 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4835 System.err.println("No Sequences generated for xRef type "
4838 } catch (Exception e)
4840 jalview.bin.Cache.log.error(
4841 "Exception when finding crossreferences", e);
4842 } catch (OutOfMemoryError e)
4844 new OOMWarning("whilst fetching crossreferences", e);
4847 jalview.bin.Cache.log.error("Error when finding crossreferences",
4850 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4851 "status.finished_searching_for_sequences_from",
4858 Thread frunner = new Thread(foo);
4862 public boolean canShowTranslationProducts(SequenceI[] selection,
4863 AlignmentI alignment)
4868 return (jalview.analysis.Dna.canTranslate(selection,
4869 viewport.getViewAsVisibleContigs(true)));
4870 } catch (Exception e)
4872 jalview.bin.Cache.log
4873 .warn("canTranslate threw an exception - please report to help@jalview.org",
4880 * Construct and display a new frame containing the translation of this
4881 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4884 public void showTranslation_actionPerformed(ActionEvent e)
4886 AlignmentI al = null;
4889 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4891 al = dna.translateCdna();
4892 } catch (Exception ex)
4894 jalview.bin.Cache.log.error(
4895 "Exception during translation. Please report this !", ex);
4896 final String msg = MessageManager
4897 .getString("label.error_when_translating_sequences_submit_bug_report");
4898 final String errorTitle = MessageManager
4899 .getString("label.implementation_error")
4900 + MessageManager.getString("translation_failed");
4901 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4902 JOptionPane.ERROR_MESSAGE);
4905 if (al == null || al.getHeight() == 0)
4907 final String msg = MessageManager
4908 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4909 final String errorTitle = MessageManager
4910 .getString("label.translation_failed");
4911 JOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4912 JOptionPane.WARNING_MESSAGE);
4916 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4917 af.setFileFormat(this.currentFileFormat);
4918 final String newTitle = MessageManager.formatMessage(
4919 "label.translation_of_params", new Object[]
4920 { this.getTitle() });
4921 af.setTitle(newTitle);
4922 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4924 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4925 viewport.openSplitFrame(af, new Alignment(seqs));
4929 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4936 * Set the file format
4940 public void setFileFormat(String fileFormat)
4942 this.currentFileFormat = fileFormat;
4946 * Try to load a features file onto the alignment.
4949 * contents or path to retrieve file
4951 * access mode of file (see jalview.io.AlignFile)
4952 * @return true if features file was parsed correctly.
4954 public boolean parseFeaturesFile(String file, String type)
4956 return avc.parseFeaturesFile(file, type,
4957 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4962 public void refreshFeatureUI(boolean enableIfNecessary)
4964 // note - currently this is only still here rather than in the controller
4965 // because of the featureSettings hard reference that is yet to be
4967 if (enableIfNecessary)
4969 viewport.setShowSequenceFeatures(true);
4970 showSeqFeatures.setSelected(true);
4976 public void dragEnter(DropTargetDragEvent evt)
4981 public void dragExit(DropTargetEvent evt)
4986 public void dragOver(DropTargetDragEvent evt)
4991 public void dropActionChanged(DropTargetDragEvent evt)
4996 public void drop(DropTargetDropEvent evt)
4998 Transferable t = evt.getTransferable();
4999 java.util.List files = null;
5003 DataFlavor uriListFlavor = new DataFlavor(
5004 "text/uri-list;class=java.lang.String");
5005 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5007 // Works on Windows and MacOSX
5008 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5009 files = (java.util.List) t
5010 .getTransferData(DataFlavor.javaFileListFlavor);
5012 else if (t.isDataFlavorSupported(uriListFlavor))
5014 // This is used by Unix drag system
5015 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5016 String data = (String) t.getTransferData(uriListFlavor);
5017 files = new java.util.ArrayList(1);
5018 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5019 data, "\r\n"); st.hasMoreTokens();)
5021 String s = st.nextToken();
5022 if (s.startsWith("#"))
5024 // the line is a comment (as per the RFC 2483)
5028 java.net.URI uri = new java.net.URI(s);
5029 // check to see if we can handle this kind of URI
5030 if (uri.getScheme().toLowerCase().startsWith("http"))
5032 files.add(uri.toString());
5036 // otherwise preserve old behaviour: catch all for file objects
5037 java.io.File file = new java.io.File(uri);
5038 files.add(file.toString());
5042 } catch (Exception e)
5044 e.printStackTrace();
5050 // check to see if any of these files have names matching sequences in
5052 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5053 .getAlignment().getSequencesArray());
5055 * Object[] { String,SequenceI}
5057 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5058 ArrayList<String> filesnotmatched = new ArrayList<String>();
5059 for (int i = 0; i < files.size(); i++)
5061 String file = files.get(i).toString();
5063 String protocol = FormatAdapter.checkProtocol(file);
5064 if (protocol == jalview.io.FormatAdapter.FILE)
5066 File fl = new File(file);
5067 pdbfn = fl.getName();
5069 else if (protocol == jalview.io.FormatAdapter.URL)
5071 URL url = new URL(file);
5072 pdbfn = url.getFile();
5074 if (pdbfn.length() > 0)
5076 // attempt to find a match in the alignment
5077 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5078 int l = 0, c = pdbfn.indexOf(".");
5079 while (mtch == null && c != -1)
5084 } while ((c = pdbfn.indexOf(".", l)) > l);
5087 pdbfn = pdbfn.substring(0, l);
5089 mtch = idm.findAllIdMatches(pdbfn);
5096 type = new IdentifyFile().Identify(file, protocol);
5097 } catch (Exception ex)
5103 if (type.equalsIgnoreCase("PDB"))
5105 filesmatched.add(new Object[]
5106 { file, protocol, mtch });
5111 // File wasn't named like one of the sequences or wasn't a PDB file.
5112 filesnotmatched.add(file);
5116 if (filesmatched.size() > 0)
5118 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5124 "label.automatically_associate_pdb_files_with_sequences_same_name",
5131 .getString("label.automatically_associate_pdb_files_by_name"),
5132 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5135 for (Object[] fm : filesmatched)
5137 // try and associate
5138 // TODO: may want to set a standard ID naming formalism for
5139 // associating PDB files which have no IDs.
5140 for (SequenceI toassoc : (SequenceI[]) fm[2])
5142 PDBEntry pe = new AssociatePdbFileWithSeq()
5143 .associatePdbWithSeq((String) fm[0],
5144 (String) fm[1], toassoc, false,
5148 System.err.println("Associated file : "
5149 + ((String) fm[0]) + " with "
5150 + toassoc.getDisplayId(true));
5154 alignPanel.paintAlignment(true);
5158 if (filesnotmatched.size() > 0)
5161 && (Cache.getDefault(
5162 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5165 "<html>"+MessageManager
5167 "label.ignore_unmatched_dropped_files_info",
5172 .toString() })+"</html>",
5174 .getString("label.ignore_unmatched_dropped_files"),
5175 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5179 for (String fn : filesnotmatched)
5181 loadJalviewDataFile(fn, null, null, null);
5185 } catch (Exception ex)
5187 ex.printStackTrace();
5193 * Attempt to load a "dropped" file or URL string: First by testing whether
5194 * it's and Annotation file, then a JNet file, and finally a features file. If
5195 * all are false then the user may have dropped an alignment file onto this
5199 * either a filename or a URL string.
5201 public void loadJalviewDataFile(String file, String protocol,
5202 String format, SequenceI assocSeq)
5206 if (protocol == null)
5208 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5210 // if the file isn't identified, or not positively identified as some
5211 // other filetype (PFAM is default unidentified alignment file type) then
5212 // try to parse as annotation.
5213 boolean isAnnotation = (format == null || format
5214 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5215 .annotateAlignmentView(viewport, file, protocol)
5220 // first see if its a T-COFFEE score file
5221 TCoffeeScoreFile tcf = null;
5224 tcf = new TCoffeeScoreFile(file, protocol);
5227 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5229 tcoffeeColour.setEnabled(true);
5230 tcoffeeColour.setSelected(true);
5231 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5232 isAnnotation = true;
5234 .setText(MessageManager
5235 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5239 // some problem - if no warning its probable that the ID matching
5240 // process didn't work
5244 tcf.getWarningMessage() == null ? MessageManager
5245 .getString("label.check_file_matches_sequence_ids_alignment")
5246 : tcf.getWarningMessage(),
5248 .getString("label.problem_reading_tcoffee_score_file"),
5249 JOptionPane.WARNING_MESSAGE);
5256 } catch (Exception x)
5259 .debug("Exception when processing data source as T-COFFEE score file",
5265 // try to see if its a JNet 'concise' style annotation file *before*
5267 // try to parse it as a features file
5270 format = new IdentifyFile().Identify(file, protocol);
5272 if (format.equalsIgnoreCase("JnetFile"))
5274 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5276 new JnetAnnotationMaker();
5277 JnetAnnotationMaker.add_annotation(predictions,
5278 viewport.getAlignment(), 0, false);
5279 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5280 viewport.getAlignment().setSeqrep(repseq);
5281 ColumnSelection cs = new ColumnSelection();
5282 cs.hideInsertionsFor(repseq);
5283 viewport.setColumnSelection(cs);
5284 isAnnotation = true;
5289 * if (format.equalsIgnoreCase("PDB")) {
5291 * String pdbfn = ""; // try to match up filename with sequence id
5292 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5293 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5294 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5295 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5296 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5297 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5298 * // attempt to find a match in the alignment SequenceI mtch =
5299 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5300 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5301 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5302 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5303 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5304 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5305 * { System.err.println("Associated file : " + file + " with " +
5306 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5307 * TODO: maybe need to load as normal otherwise return; } }
5309 // try to parse it as a features file
5310 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5311 // if it wasn't a features file then we just treat it as a general
5312 // alignment file to load into the current view.
5315 new FileLoader().LoadFile(viewport, file, protocol, format);
5319 alignPanel.paintAlignment(true);
5327 alignPanel.adjustAnnotationHeight();
5328 viewport.updateSequenceIdColours();
5329 buildSortByAnnotationScoresMenu();
5330 alignPanel.paintAlignment(true);
5332 } catch (Exception ex)
5334 ex.printStackTrace();
5335 } catch (OutOfMemoryError oom)
5340 } catch (Exception x)
5346 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5347 : "using " + protocol + " from " + file)
5349 + (format != null ? "(parsing as '" + format
5350 + "' file)" : ""), oom, Desktop.desktop);
5355 * Method invoked by the ChangeListener on the tabbed pane, in other words
5356 * when a different tabbed pane is selected by the user or programmatically.
5359 public void tabSelectionChanged(int index)
5363 alignPanel = alignPanels.get(index);
5364 viewport = alignPanel.av;
5365 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5366 setMenusFromViewport(viewport);
5370 * If there is a frame linked to this one in a SplitPane, switch it to the
5371 * same view tab index. No infinite recursion of calls should happen, since
5372 * tabSelectionChanged() should not get invoked on setting the selected
5373 * index to an unchanged value. Guard against setting an invalid index
5374 * before the new view peer tab has been created.
5376 final AlignViewportI peer = viewport.getCodingComplement();
5379 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5380 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5382 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5388 * On right mouse click on view tab, prompt for and set new view name.
5391 public void tabbedPane_mousePressed(MouseEvent e)
5393 if (SwingUtilities.isRightMouseButton(e))
5395 String msg = MessageManager.getString("label.enter_view_name");
5396 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5397 JOptionPane.QUESTION_MESSAGE);
5401 viewport.viewName = reply;
5402 // TODO warn if reply is in getExistingViewNames()?
5403 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5408 public AlignViewport getCurrentView()
5414 * Open the dialog for regex description parsing.
5417 protected void extractScores_actionPerformed(ActionEvent e)
5419 ParseProperties pp = new jalview.analysis.ParseProperties(
5420 viewport.getAlignment());
5421 // TODO: verify regex and introduce GUI dialog for version 2.5
5422 // if (pp.getScoresFromDescription("col", "score column ",
5423 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5425 if (pp.getScoresFromDescription("description column",
5426 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5428 buildSortByAnnotationScoresMenu();
5436 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5440 protected void showDbRefs_actionPerformed(ActionEvent e)
5442 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5448 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5452 protected void showNpFeats_actionPerformed(ActionEvent e)
5454 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5458 * find the viewport amongst the tabs in this alignment frame and close that
5463 public boolean closeView(AlignViewportI av)
5467 this.closeMenuItem_actionPerformed(false);
5470 Component[] comp = tabbedPane.getComponents();
5471 for (int i = 0; comp != null && i < comp.length; i++)
5473 if (comp[i] instanceof AlignmentPanel)
5475 if (((AlignmentPanel) comp[i]).av == av)
5478 closeView((AlignmentPanel) comp[i]);
5486 protected void build_fetchdbmenu(JMenu webService)
5488 // Temporary hack - DBRef Fetcher always top level ws entry.
5489 // TODO We probably want to store a sequence database checklist in
5490 // preferences and have checkboxes.. rather than individual sources selected
5492 final JMenu rfetch = new JMenu(
5493 MessageManager.getString("action.fetch_db_references"));
5494 rfetch.setToolTipText(MessageManager
5495 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5496 webService.add(rfetch);
5498 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5499 MessageManager.getString("option.trim_retrieved_seqs"));
5500 trimrs.setToolTipText(MessageManager
5501 .getString("label.trim_retrieved_sequences"));
5502 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5503 trimrs.addActionListener(new ActionListener()
5506 public void actionPerformed(ActionEvent e)
5508 trimrs.setSelected(trimrs.isSelected());
5509 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5510 Boolean.valueOf(trimrs.isSelected()).toString());
5514 JMenuItem fetchr = new JMenuItem(
5515 MessageManager.getString("label.standard_databases"));
5516 fetchr.setToolTipText(MessageManager
5517 .getString("label.fetch_embl_uniprot"));
5518 fetchr.addActionListener(new ActionListener()
5522 public void actionPerformed(ActionEvent e)
5524 new Thread(new Runnable()
5530 new jalview.ws.DBRefFetcher(alignPanel.av
5531 .getSequenceSelection(), alignPanel.alignFrame)
5532 .fetchDBRefs(false);
5540 final AlignFrame me = this;
5541 new Thread(new Runnable()
5546 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5547 .getSequenceFetcherSingleton(me);
5548 javax.swing.SwingUtilities.invokeLater(new Runnable()
5553 String[] dbclasses = sf.getOrderedSupportedSources();
5554 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5555 // jalview.util.QuickSort.sort(otherdb, otherdb);
5556 List<DbSourceProxy> otherdb;
5557 JMenu dfetch = new JMenu();
5558 JMenu ifetch = new JMenu();
5559 JMenuItem fetchr = null;
5560 int comp = 0, icomp = 0, mcomp = 15;
5561 String mname = null;
5563 for (String dbclass : dbclasses)
5565 otherdb = sf.getSourceProxy(dbclass);
5566 // add a single entry for this class, or submenu allowing 'fetch
5568 if (otherdb == null || otherdb.size() < 1)
5572 // List<DbSourceProxy> dbs=otherdb;
5573 // otherdb=new ArrayList<DbSourceProxy>();
5574 // for (DbSourceProxy db:dbs)
5576 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5580 mname = "From " + dbclass;
5582 if (otherdb.size() == 1)
5584 final DbSourceProxy[] dassource = otherdb
5585 .toArray(new DbSourceProxy[0]);
5586 DbSourceProxy src = otherdb.get(0);
5587 fetchr = new JMenuItem(src.getDbSource());
5588 fetchr.addActionListener(new ActionListener()
5592 public void actionPerformed(ActionEvent e)
5594 new Thread(new Runnable()
5600 new jalview.ws.DBRefFetcher(alignPanel.av
5601 .getSequenceSelection(),
5602 alignPanel.alignFrame, dassource)
5603 .fetchDBRefs(false);
5609 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5615 final DbSourceProxy[] dassource = otherdb
5616 .toArray(new DbSourceProxy[0]);
5618 DbSourceProxy src = otherdb.get(0);
5619 fetchr = new JMenuItem(MessageManager.formatMessage(
5620 "label.fetch_all_param", new Object[]
5621 { src.getDbSource() }));
5622 fetchr.addActionListener(new ActionListener()
5625 public void actionPerformed(ActionEvent e)
5627 new Thread(new Runnable()
5633 new jalview.ws.DBRefFetcher(alignPanel.av
5634 .getSequenceSelection(),
5635 alignPanel.alignFrame, dassource)
5636 .fetchDBRefs(false);
5642 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5645 // and then build the rest of the individual menus
5646 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5648 String imname = null;
5650 for (DbSourceProxy sproxy : otherdb)
5652 String dbname = sproxy.getDbName();
5653 String sname = dbname.length() > 5 ? dbname.substring(0,
5654 5) + "..." : dbname;
5655 String msname = dbname.length() > 10 ? dbname.substring(
5656 0, 10) + "..." : dbname;
5659 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5661 fetchr = new JMenuItem(msname);
5662 final DbSourceProxy[] dassrc =
5664 fetchr.addActionListener(new ActionListener()
5668 public void actionPerformed(ActionEvent e)
5670 new Thread(new Runnable()
5676 new jalview.ws.DBRefFetcher(alignPanel.av
5677 .getSequenceSelection(),
5678 alignPanel.alignFrame, dassrc)
5679 .fetchDBRefs(false);
5685 fetchr.setToolTipText("<html>"
5686 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5689 if (++icomp >= mcomp || i == (otherdb.size()))
5691 ifetch.setText(MessageManager.formatMessage(
5692 "label.source_to_target", imname, sname));
5694 ifetch = new JMenu();
5702 if (comp >= mcomp || dbi >= (dbclasses.length))
5704 dfetch.setText(MessageManager.formatMessage(
5705 "label.source_to_target", mname, dbclass));
5707 dfetch = new JMenu();
5720 * Left justify the whole alignment.
5723 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5725 AlignmentI al = viewport.getAlignment();
5727 viewport.firePropertyChange("alignment", null, al);
5731 * Right justify the whole alignment.
5734 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5736 AlignmentI al = viewport.getAlignment();
5738 viewport.firePropertyChange("alignment", null, al);
5741 public void setShowSeqFeatures(boolean b)
5743 showSeqFeatures.setSelected(b);
5744 viewport.setShowSequenceFeatures(b);
5751 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5752 * awt.event.ActionEvent)
5755 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5757 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5758 alignPanel.paintAlignment(true);
5765 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5769 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5771 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5772 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5780 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5781 * .event.ActionEvent)
5784 protected void showGroupConservation_actionPerformed(ActionEvent e)
5786 viewport.setShowGroupConservation(showGroupConservation.getState());
5787 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5794 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5795 * .event.ActionEvent)
5798 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5800 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5801 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5808 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5809 * .event.ActionEvent)
5812 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5814 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5815 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5819 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5821 showSequenceLogo.setState(true);
5822 viewport.setShowSequenceLogo(true);
5823 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5824 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5828 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5830 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5837 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5838 * .event.ActionEvent)
5841 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5843 if (avc.makeGroupsFromSelection())
5845 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5846 alignPanel.updateAnnotation();
5847 alignPanel.paintAlignment(true);
5850 public void clearAlignmentSeqRep()
5852 // TODO refactor alignmentseqrep to controller
5853 if (viewport.getAlignment().hasSeqrep()) {
5854 viewport.getAlignment().setSeqrep(null);
5855 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5856 alignPanel.updateAnnotation();
5857 alignPanel.paintAlignment(true);
5862 protected void createGroup_actionPerformed(ActionEvent e)
5864 if (avc.createGroup())
5866 alignPanel.alignmentChanged();
5871 protected void unGroup_actionPerformed(ActionEvent e)
5875 alignPanel.alignmentChanged();
5880 * make the given alignmentPanel the currently selected tab
5882 * @param alignmentPanel
5884 public void setDisplayedView(AlignmentPanel alignmentPanel)
5886 if (!viewport.getSequenceSetId().equals(
5887 alignmentPanel.av.getSequenceSetId()))
5889 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5891 if (tabbedPane != null
5892 && tabbedPane.getTabCount() > 0
5893 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5894 .getSelectedIndex())
5896 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5901 * Action on selection of menu options to Show or Hide annotations.
5904 * @param forSequences
5905 * update sequence-related annotations
5906 * @param forAlignment
5907 * update non-sequence-related annotations
5910 protected void setAnnotationsVisibility(boolean visible,
5911 boolean forSequences, boolean forAlignment)
5913 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5914 .getAlignmentAnnotation())
5917 * don't display non-positional annotations on an alignment
5919 if (aa.annotations == null)
5923 boolean apply = (aa.sequenceRef == null && forAlignment)
5924 || (aa.sequenceRef != null && forSequences);
5927 aa.visible = visible;
5930 alignPanel.validateAnnotationDimensions(true);
5931 alignPanel.alignmentChanged();
5935 * Store selected annotation sort order for the view and repaint.
5938 protected void sortAnnotations_actionPerformed()
5940 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5942 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5943 alignPanel.paintAlignment(true);
5948 * @return alignment panels in this alignment frame
5950 public List<? extends AlignmentViewPanel> getAlignPanels()
5952 return alignPanels == null ? Arrays.asList(alignPanel)
5957 * Open a new alignment window, with the cDNA associated with this (protein)
5958 * alignment, aligned as is the protein.
5960 protected void viewAsCdna_actionPerformed()
5962 // TODO no longer a menu action - refactor as required
5963 final AlignmentI alignment = getViewport().getAlignment();
5964 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5965 if (mappings == null)
5969 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
5970 for (SequenceI aaSeq : alignment.getSequences()) {
5971 for (AlignedCodonFrame acf : mappings) {
5972 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5976 * There is a cDNA mapping for this protein sequence - add to new
5977 * alignment. It will share the same dataset sequence as other mapped
5978 * cDNA (no new mappings need to be created).
5980 final Sequence newSeq = new Sequence(dnaSeq);
5981 newSeq.setDatasetSequence(dnaSeq);
5982 cdnaSeqs.add(newSeq);
5986 if (cdnaSeqs.size() == 0)
5988 // show a warning dialog no mapped cDNA
5991 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
5993 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5994 AlignFrame.DEFAULT_HEIGHT);
5995 cdna.alignAs(alignment);
5996 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5998 Desktop.addInternalFrame(alignFrame, newtitle,
5999 AlignFrame.DEFAULT_WIDTH,
6000 AlignFrame.DEFAULT_HEIGHT);
6004 * Set visibility of dna/protein complement view (available when shown in a
6010 protected void showComplement_actionPerformed(boolean show)
6012 SplitContainerI sf = getSplitViewContainer();
6014 sf.setComplementVisible(this, show);
6019 class PrintThread extends Thread
6023 public PrintThread(AlignmentPanel ap)
6028 static PageFormat pf;
6033 PrinterJob printJob = PrinterJob.getPrinterJob();
6037 printJob.setPrintable(ap, pf);
6041 printJob.setPrintable(ap);
6044 if (printJob.printDialog())
6049 } catch (Exception PrintException)
6051 PrintException.printStackTrace();