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 java.awt.BorderLayout;
24 import java.awt.Component;
25 import java.awt.Rectangle;
26 import java.awt.Toolkit;
27 import java.awt.datatransfer.Clipboard;
28 import java.awt.datatransfer.DataFlavor;
29 import java.awt.datatransfer.StringSelection;
30 import java.awt.datatransfer.Transferable;
31 import java.awt.dnd.DnDConstants;
32 import java.awt.dnd.DropTargetDragEvent;
33 import java.awt.dnd.DropTargetDropEvent;
34 import java.awt.dnd.DropTargetEvent;
35 import java.awt.dnd.DropTargetListener;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.ItemEvent;
39 import java.awt.event.ItemListener;
40 import java.awt.event.KeyAdapter;
41 import java.awt.event.KeyEvent;
42 import java.awt.event.MouseAdapter;
43 import java.awt.event.MouseEvent;
44 import java.awt.print.PageFormat;
45 import java.awt.print.PrinterJob;
46 import java.beans.PropertyChangeEvent;
49 import java.util.ArrayList;
50 import java.util.Arrays;
51 import java.util.Deque;
52 import java.util.Enumeration;
53 import java.util.Hashtable;
54 import java.util.List;
56 import java.util.Vector;
58 import javax.swing.JCheckBoxMenuItem;
59 import javax.swing.JEditorPane;
60 import javax.swing.JInternalFrame;
61 import javax.swing.JLayeredPane;
62 import javax.swing.JMenu;
63 import javax.swing.JMenuItem;
64 import javax.swing.JOptionPane;
65 import javax.swing.JRadioButtonMenuItem;
66 import javax.swing.JScrollPane;
67 import javax.swing.SwingUtilities;
69 import jalview.analysis.AAFrequency;
70 import jalview.analysis.AlignmentSorter;
71 import jalview.analysis.AlignmentUtils;
72 import jalview.analysis.Conservation;
73 import jalview.analysis.CrossRef;
74 import jalview.analysis.Dna;
75 import jalview.analysis.ParseProperties;
76 import jalview.analysis.SequenceIdMatcher;
77 import jalview.api.AlignViewControllerGuiI;
78 import jalview.api.AlignViewControllerI;
79 import jalview.api.AlignViewportI;
80 import jalview.api.AlignmentViewPanel;
81 import jalview.api.SplitContainerI;
82 import jalview.api.ViewStyleI;
83 import jalview.api.analysis.ScoreModelI;
84 import jalview.bin.Cache;
85 import jalview.commands.CommandI;
86 import jalview.commands.EditCommand;
87 import jalview.commands.EditCommand.Action;
88 import jalview.commands.OrderCommand;
89 import jalview.commands.RemoveGapColCommand;
90 import jalview.commands.RemoveGapsCommand;
91 import jalview.commands.SlideSequencesCommand;
92 import jalview.commands.TrimRegionCommand;
93 import jalview.datamodel.AlignedCodonFrame;
94 import jalview.datamodel.Alignment;
95 import jalview.datamodel.AlignmentAnnotation;
96 import jalview.datamodel.AlignmentI;
97 import jalview.datamodel.AlignmentOrder;
98 import jalview.datamodel.AlignmentView;
99 import jalview.datamodel.ColumnSelection;
100 import jalview.datamodel.HiddenSequences;
101 import jalview.datamodel.PDBEntry;
102 import jalview.datamodel.SeqCigar;
103 import jalview.datamodel.Sequence;
104 import jalview.datamodel.SequenceGroup;
105 import jalview.datamodel.SequenceI;
106 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
107 import jalview.io.AlignmentProperties;
108 import jalview.io.AnnotationFile;
109 import jalview.io.BioJsHTMLOutput;
110 import jalview.io.FeaturesFile;
111 import jalview.io.FileLoader;
112 import jalview.io.FormatAdapter;
113 import jalview.io.HtmlSvgOutput;
114 import jalview.io.IdentifyFile;
115 import jalview.io.JalviewFileChooser;
116 import jalview.io.JalviewFileView;
117 import jalview.io.JnetAnnotationMaker;
118 import jalview.io.NewickFile;
119 import jalview.io.TCoffeeScoreFile;
120 import jalview.jbgui.GAlignFrame;
121 import jalview.schemes.Blosum62ColourScheme;
122 import jalview.schemes.BuriedColourScheme;
123 import jalview.schemes.ClustalxColourScheme;
124 import jalview.schemes.ColourSchemeI;
125 import jalview.schemes.ColourSchemeProperty;
126 import jalview.schemes.HelixColourScheme;
127 import jalview.schemes.HydrophobicColourScheme;
128 import jalview.schemes.NucleotideColourScheme;
129 import jalview.schemes.PIDColourScheme;
130 import jalview.schemes.PurinePyrimidineColourScheme;
131 import jalview.schemes.RNAHelicesColourChooser;
132 import jalview.schemes.ResidueProperties;
133 import jalview.schemes.StrandColourScheme;
134 import jalview.schemes.TCoffeeColourScheme;
135 import jalview.schemes.TaylorColourScheme;
136 import jalview.schemes.TurnColourScheme;
137 import jalview.schemes.UserColourScheme;
138 import jalview.schemes.ZappoColourScheme;
139 import jalview.structure.StructureSelectionManager;
140 import jalview.util.MessageManager;
141 import jalview.viewmodel.AlignmentViewport;
142 import jalview.ws.jws1.Discoverer;
143 import jalview.ws.jws2.Jws2Discoverer;
144 import jalview.ws.jws2.jabaws2.Jws2Instance;
145 import jalview.ws.seqfetcher.DbSourceProxy;
151 * @version $Revision$
153 public class AlignFrame extends GAlignFrame implements DropTargetListener,
154 IProgressIndicator, AlignViewControllerGuiI
157 public static final int DEFAULT_WIDTH = 700;
159 public static final int DEFAULT_HEIGHT = 500;
162 * The currently displayed panel (selected tabbed view if more than one)
164 public AlignmentPanel alignPanel;
166 AlignViewport viewport;
168 public AlignViewControllerI avc;
170 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
173 * Last format used to load or save alignments in this window
175 String currentFileFormat = null;
178 * Current filename for this alignment
180 String fileName = null;
183 * Creates a new AlignFrame object with specific width and height.
189 public AlignFrame(AlignmentI al, int width, int height)
191 this(al, null, width, height);
195 * Creates a new AlignFrame object with specific width, height and
201 * @param sequenceSetId
203 public AlignFrame(AlignmentI al, int width, int height,
204 String sequenceSetId)
206 this(al, null, width, height, sequenceSetId);
210 * Creates a new AlignFrame object with specific width, height and
216 * @param sequenceSetId
219 public AlignFrame(AlignmentI al, int width, int height,
220 String sequenceSetId, String viewId)
222 this(al, null, width, height, sequenceSetId, viewId);
226 * new alignment window with hidden columns
230 * @param hiddenColumns
231 * ColumnSelection or null
233 * Width of alignment frame
237 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
238 int width, int height)
240 this(al, hiddenColumns, width, height, null);
245 * Create alignment frame for al with hiddenColumns, a specific width and
246 * height, and specific sequenceId
249 * @param hiddenColumns
252 * @param sequenceSetId
255 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
256 int width, int height, String sequenceSetId)
258 this(al, hiddenColumns, width, height, sequenceSetId, null);
262 * Create alignment frame for al with hiddenColumns, a specific width and
263 * height, and specific sequenceId
266 * @param hiddenColumns
269 * @param sequenceSetId
274 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
275 int width, int height, String sequenceSetId, String viewId)
277 setSize(width, height);
279 if (al.getDataset() == null)
284 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
286 alignPanel = new AlignmentPanel(this, viewport);
289 addAlignmentPanel(alignPanel, true);
293 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
294 ColumnSelection hiddenColumns, int width, int height)
296 setSize(width, height);
298 if (al.getDataset() == null)
303 viewport = new AlignViewport(al, hiddenColumns);
305 if (hiddenSeqs != null && hiddenSeqs.length > 0)
307 viewport.hideSequence(hiddenSeqs);
308 viewport.setHasHiddenRows(true);
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 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
340 avc = new jalview.controller.AlignViewController(this, viewport,
342 if (viewport.getAlignmentConservationAnnotation() == null)
344 BLOSUM62Colour.setEnabled(false);
345 conservationMenuItem.setEnabled(false);
346 modifyConservation.setEnabled(false);
347 // PIDColour.setEnabled(false);
348 // abovePIDThreshold.setEnabled(false);
349 // modifyPID.setEnabled(false);
352 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
355 if (sortby.equals("Id"))
357 sortIDMenuItem_actionPerformed(null);
359 else if (sortby.equals("Pairwise Identity"))
361 sortPairwiseMenuItem_actionPerformed(null);
364 if (Desktop.desktop != null)
366 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
367 addServiceListeners();
368 setGUINucleotide(viewport.getAlignment().isNucleotide());
371 setMenusFromViewport(viewport);
372 buildSortByAnnotationScoresMenu();
375 if (viewport.getWrapAlignment())
377 wrapMenuItem_actionPerformed(null);
380 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
382 this.overviewMenuItem_actionPerformed(null);
387 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
388 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
389 final String menuLabel = MessageManager
390 .getString("label.copy_format_from");
391 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
392 new ViewSetProvider()
396 public AlignmentPanel[] getAllAlignmentPanels()
399 origview.add(alignPanel);
400 // make an array of all alignment panels except for this one
401 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
402 Arrays.asList(Desktop.getAlignmentPanels(null)));
403 aps.remove(AlignFrame.this.alignPanel);
404 return aps.toArray(new AlignmentPanel[aps.size()]);
406 }, selviews, new ItemListener()
410 public void itemStateChanged(ItemEvent e)
412 if (origview.size() > 0)
414 final AlignmentPanel ap = origview.get(0);
417 * Copy the ViewStyle of the selected panel to 'this one'.
418 * Don't change value of 'scaleProteinAsCdna' unless copying
421 ViewStyleI vs = selviews.get(0).getAlignViewport()
423 boolean fromSplitFrame = selviews.get(0)
424 .getAlignViewport().getCodingComplement() != null;
427 vs.setScaleProteinAsCdna(ap.getAlignViewport()
428 .getViewStyle().isScaleProteinAsCdna());
430 ap.getAlignViewport().setViewStyle(vs);
433 * Also rescale ViewStyle of SplitFrame complement if there is
434 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
435 * the whole ViewStyle (allow cDNA protein to have different
438 AlignViewportI complement = ap.getAlignViewport()
439 .getCodingComplement();
440 if (complement != null && vs.isScaleProteinAsCdna())
442 AlignFrame af = Desktop.getAlignFrameFor(complement);
443 ((SplitFrame) af.getSplitViewContainer())
445 af.setMenusForViewport();
449 ap.setSelected(true);
450 ap.alignFrame.setMenusForViewport();
455 formatMenu.add(vsel);
460 * Change the filename and format for the alignment, and enable the 'reload'
461 * button functionality.
468 public void setFileName(String file, String format)
471 setFileFormat(format);
472 reload.setEnabled(true);
476 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
479 void addKeyListener()
481 addKeyListener(new KeyAdapter()
484 public void keyPressed(KeyEvent evt)
486 if (viewport.cursorMode
487 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
488 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
489 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
490 && Character.isDigit(evt.getKeyChar()))
492 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
495 switch (evt.getKeyCode())
498 case 27: // escape key
499 deselectAllSequenceMenuItem_actionPerformed(null);
503 case KeyEvent.VK_DOWN:
504 if (evt.isAltDown() || !viewport.cursorMode)
506 moveSelectedSequences(false);
508 if (viewport.cursorMode)
510 alignPanel.getSeqPanel().moveCursor(0, 1);
515 if (evt.isAltDown() || !viewport.cursorMode)
517 moveSelectedSequences(true);
519 if (viewport.cursorMode)
521 alignPanel.getSeqPanel().moveCursor(0, -1);
526 case KeyEvent.VK_LEFT:
527 if (evt.isAltDown() || !viewport.cursorMode)
529 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
533 alignPanel.getSeqPanel().moveCursor(-1, 0);
538 case KeyEvent.VK_RIGHT:
539 if (evt.isAltDown() || !viewport.cursorMode)
541 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
545 alignPanel.getSeqPanel().moveCursor(1, 0);
549 case KeyEvent.VK_SPACE:
550 if (viewport.cursorMode)
552 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
553 || evt.isShiftDown() || evt.isAltDown());
557 // case KeyEvent.VK_A:
558 // if (viewport.cursorMode)
560 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
561 // //System.out.println("A");
565 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
566 * System.out.println("closing bracket"); } break;
568 case KeyEvent.VK_DELETE:
569 case KeyEvent.VK_BACK_SPACE:
570 if (!viewport.cursorMode)
572 cut_actionPerformed(null);
576 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
577 || evt.isShiftDown() || evt.isAltDown());
583 if (viewport.cursorMode)
585 alignPanel.getSeqPanel().setCursorRow();
589 if (viewport.cursorMode && !evt.isControlDown())
591 alignPanel.getSeqPanel().setCursorColumn();
595 if (viewport.cursorMode)
597 alignPanel.getSeqPanel().setCursorPosition();
601 case KeyEvent.VK_ENTER:
602 case KeyEvent.VK_COMMA:
603 if (viewport.cursorMode)
605 alignPanel.getSeqPanel().setCursorRowAndColumn();
610 if (viewport.cursorMode)
612 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
616 if (viewport.cursorMode)
618 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
623 viewport.cursorMode = !viewport.cursorMode;
624 statusBar.setText(MessageManager.formatMessage(
625 "label.keyboard_editing_mode", new String[]
626 { (viewport.cursorMode ? "on" : "off") }));
627 if (viewport.cursorMode)
629 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
630 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
632 alignPanel.getSeqPanel().seqCanvas.repaint();
638 Help.showHelpWindow();
639 } catch (Exception ex)
641 ex.printStackTrace();
646 boolean toggleSeqs = !evt.isControlDown();
647 boolean toggleCols = !evt.isShiftDown();
648 toggleHiddenRegions(toggleSeqs, toggleCols);
651 case KeyEvent.VK_PAGE_UP:
652 if (viewport.getWrapAlignment())
654 alignPanel.scrollUp(true);
658 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
659 - viewport.endSeq + viewport.startSeq);
662 case KeyEvent.VK_PAGE_DOWN:
663 if (viewport.getWrapAlignment())
665 alignPanel.scrollUp(false);
669 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
670 + viewport.endSeq - viewport.startSeq);
677 public void keyReleased(KeyEvent evt)
679 switch (evt.getKeyCode())
681 case KeyEvent.VK_LEFT:
682 if (evt.isAltDown() || !viewport.cursorMode)
684 viewport.firePropertyChange("alignment", null, viewport
685 .getAlignment().getSequences());
689 case KeyEvent.VK_RIGHT:
690 if (evt.isAltDown() || !viewport.cursorMode)
692 viewport.firePropertyChange("alignment", null, viewport
693 .getAlignment().getSequences());
701 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
703 ap.alignFrame = this;
704 avc = new jalview.controller.AlignViewController(this, viewport,
709 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
711 int aSize = alignPanels.size();
713 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
715 if (aSize == 1 && ap.av.viewName == null)
717 this.getContentPane().add(ap, BorderLayout.CENTER);
723 setInitialTabVisible();
726 expandViews.setEnabled(true);
727 gatherViews.setEnabled(true);
728 tabbedPane.addTab(ap.av.viewName, ap);
730 ap.setVisible(false);
735 if (ap.av.isPadGaps())
737 ap.av.getAlignment().padGaps();
739 ap.av.updateConservation(ap);
740 ap.av.updateConsensus(ap);
741 ap.av.updateStrucConsensus(ap);
745 public void setInitialTabVisible()
747 expandViews.setEnabled(true);
748 gatherViews.setEnabled(true);
749 tabbedPane.setVisible(true);
750 AlignmentPanel first = alignPanels.get(0);
751 tabbedPane.addTab(first.av.viewName, first);
752 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
755 public AlignViewport getViewport()
760 /* Set up intrinsic listeners for dynamically generated GUI bits. */
761 private void addServiceListeners()
763 final java.beans.PropertyChangeListener thisListener;
764 Desktop.instance.addJalviewPropertyChangeListener("services",
765 thisListener = new java.beans.PropertyChangeListener()
768 public void propertyChange(PropertyChangeEvent evt)
770 // // System.out.println("Discoverer property change.");
771 // if (evt.getPropertyName().equals("services"))
773 SwingUtilities.invokeLater(new Runnable()
780 .println("Rebuild WS Menu for service change");
781 BuildWebServiceMenu();
788 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
791 public void internalFrameClosed(
792 javax.swing.event.InternalFrameEvent evt)
794 System.out.println("deregistering discoverer listener");
795 Desktop.instance.removeJalviewPropertyChangeListener("services",
797 closeMenuItem_actionPerformed(true);
800 // Finally, build the menu once to get current service state
801 new Thread(new Runnable()
806 BuildWebServiceMenu();
812 * Configure menu items that vary according to whether the alignment is
813 * nucleotide or protein
817 public void setGUINucleotide(boolean nucleotide)
819 showTranslation.setVisible(nucleotide);
820 conservationMenuItem.setEnabled(!nucleotide);
821 modifyConservation.setEnabled(!nucleotide);
822 showGroupConservation.setEnabled(!nucleotide);
823 rnahelicesColour.setEnabled(nucleotide);
824 purinePyrimidineColour.setEnabled(nucleotide);
825 showComplementMenuItem.setText(MessageManager
826 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
827 setColourSelected(jalview.bin.Cache.getDefault(
828 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
829 : Preferences.DEFAULT_COLOUR_PROT, "None"));
833 * set up menus for the current viewport. This may be called after any
834 * operation that affects the data in the current view (selection changed,
835 * etc) to update the menus to reflect the new state.
837 public void setMenusForViewport()
839 setMenusFromViewport(viewport);
843 * Need to call this method when tabs are selected for multiple views, or when
844 * loading from Jalview2XML.java
849 void setMenusFromViewport(AlignViewport av)
851 padGapsMenuitem.setSelected(av.isPadGaps());
852 colourTextMenuItem.setSelected(av.isShowColourText());
853 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
854 conservationMenuItem.setSelected(av.getConservationSelected());
855 seqLimits.setSelected(av.getShowJVSuffix());
856 idRightAlign.setSelected(av.isRightAlignIds());
857 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
858 renderGapsMenuItem.setSelected(av.isRenderGaps());
859 wrapMenuItem.setSelected(av.getWrapAlignment());
860 scaleAbove.setVisible(av.getWrapAlignment());
861 scaleLeft.setVisible(av.getWrapAlignment());
862 scaleRight.setVisible(av.getWrapAlignment());
863 annotationPanelMenuItem.setState(av.isShowAnnotation());
865 * Show/hide annotations only enabled if annotation panel is shown
867 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
868 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
869 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
870 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
871 viewBoxesMenuItem.setSelected(av.getShowBoxes());
872 viewTextMenuItem.setSelected(av.getShowText());
873 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
874 showGroupConsensus.setSelected(av.isShowGroupConsensus());
875 showGroupConservation.setSelected(av.isShowGroupConservation());
876 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
877 showSequenceLogo.setSelected(av.isShowSequenceLogo());
878 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
880 setColourSelected(ColourSchemeProperty.getColourName(av
881 .getGlobalColourScheme()));
883 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
884 hiddenMarkers.setState(av.getShowHiddenMarkers());
885 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
886 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
887 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
888 autoCalculate.setSelected(av.autoCalculateConsensus);
889 sortByTree.setSelected(av.sortByTree);
890 listenToViewSelections.setSelected(av.followSelection);
891 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
893 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
894 setShowProductsEnabled();
898 private IProgressIndicator progressBar;
903 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
906 public void setProgressBar(String message, long id)
908 progressBar.setProgressBar(message, id);
912 public void registerHandler(final long id,
913 final IProgressIndicatorHandler handler)
915 progressBar.registerHandler(id, handler);
920 * @return true if any progress bars are still active
923 public boolean operationInProgress()
925 return progressBar.operationInProgress();
929 public void setStatus(String text)
931 statusBar.setText(text);
935 * Added so Castor Mapping file can obtain Jalview Version
937 public String getVersion()
939 return jalview.bin.Cache.getProperty("VERSION");
942 public FeatureRenderer getFeatureRenderer()
944 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
948 public void fetchSequence_actionPerformed(ActionEvent e)
950 new SequenceFetcher(this);
954 public void addFromFile_actionPerformed(ActionEvent e)
956 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
960 public void reload_actionPerformed(ActionEvent e)
962 if (fileName != null)
964 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
965 // originating file's format
966 // TODO: work out how to recover feature settings for correct view(s) when
968 if (currentFileFormat.equals("Jalview"))
970 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
971 for (int i = 0; i < frames.length; i++)
973 if (frames[i] instanceof AlignFrame && frames[i] != this
974 && ((AlignFrame) frames[i]).fileName != null
975 && ((AlignFrame) frames[i]).fileName.equals(fileName))
979 frames[i].setSelected(true);
980 Desktop.instance.closeAssociatedWindows();
981 } catch (java.beans.PropertyVetoException ex)
987 Desktop.instance.closeAssociatedWindows();
989 FileLoader loader = new FileLoader();
990 String protocol = fileName.startsWith("http:") ? "URL" : "File";
991 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
995 Rectangle bounds = this.getBounds();
997 FileLoader loader = new FileLoader();
998 String protocol = fileName.startsWith("http:") ? "URL" : "File";
999 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1000 protocol, currentFileFormat);
1002 newframe.setBounds(bounds);
1003 if (featureSettings != null && featureSettings.isShowing())
1005 final Rectangle fspos = featureSettings.frame.getBounds();
1006 // TODO: need a 'show feature settings' function that takes bounds -
1007 // need to refactor Desktop.addFrame
1008 newframe.featureSettings_actionPerformed(null);
1009 final FeatureSettings nfs = newframe.featureSettings;
1010 SwingUtilities.invokeLater(new Runnable()
1015 nfs.frame.setBounds(fspos);
1018 this.featureSettings.close();
1019 this.featureSettings = null;
1021 this.closeMenuItem_actionPerformed(true);
1027 public void addFromText_actionPerformed(ActionEvent e)
1029 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
1033 public void addFromURL_actionPerformed(ActionEvent e)
1035 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1039 public void save_actionPerformed(ActionEvent e)
1041 if (fileName == null
1042 || (currentFileFormat == null || !jalview.io.FormatAdapter
1043 .isValidIOFormat(currentFileFormat, true))
1044 || fileName.startsWith("http"))
1046 saveAs_actionPerformed(null);
1050 saveAlignment(fileName, currentFileFormat);
1061 public void saveAs_actionPerformed(ActionEvent e)
1063 JalviewFileChooser chooser = new JalviewFileChooser(
1064 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1065 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1066 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1067 currentFileFormat, false);
1069 chooser.setFileView(new JalviewFileView());
1070 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1071 chooser.setToolTipText(MessageManager.getString("action.save"));
1073 int value = chooser.showSaveDialog(this);
1075 if (value == JalviewFileChooser.APPROVE_OPTION)
1077 currentFileFormat = chooser.getSelectedFormat();
1078 while (currentFileFormat == null)
1081 .showInternalMessageDialog(
1084 .getString("label.select_file_format_before_saving"),
1086 .getString("label.file_format_not_specified"),
1087 JOptionPane.WARNING_MESSAGE);
1088 currentFileFormat = chooser.getSelectedFormat();
1089 value = chooser.showSaveDialog(this);
1090 if (value != JalviewFileChooser.APPROVE_OPTION)
1096 fileName = chooser.getSelectedFile().getPath();
1098 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1101 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1102 if (currentFileFormat.indexOf(" ") > -1)
1104 currentFileFormat = currentFileFormat.substring(0,
1105 currentFileFormat.indexOf(" "));
1107 saveAlignment(fileName, currentFileFormat);
1111 public boolean saveAlignment(String file, String format)
1113 boolean success = true;
1115 if (format.equalsIgnoreCase("Jalview"))
1117 String shortName = title;
1119 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1121 shortName = shortName.substring(shortName
1122 .lastIndexOf(java.io.File.separatorChar) + 1);
1125 success = new Jalview2XML().saveAlignment(this, file, shortName);
1127 statusBar.setText(MessageManager.formatMessage(
1128 "label.successfully_saved_to_file_in_format", new Object[]
1129 { fileName, format }));
1134 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1136 warningMessage("Cannot save file " + fileName + " using format "
1137 + format, "Alignment output format not supported");
1138 saveAs_actionPerformed(null);
1139 // JBPNote need to have a raise_gui flag here
1143 ExportData exportData = getAlignmentForExport();
1144 FormatAdapter f = new FormatAdapter(viewport);
1145 String output = f.formatSequences(format,
1146 exportData.getAlignment(), // class cast exceptions will
1147 // occur in the distant future
1148 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1149 f.getCacheSuffixDefault(format),
1150 viewport.getColumnSelection());
1160 java.io.PrintWriter out = new java.io.PrintWriter(
1161 new java.io.FileWriter(file));
1165 this.setTitle(file);
1166 statusBar.setText(MessageManager.formatMessage(
1167 "label.successfully_saved_to_file_in_format",
1169 { fileName, format }));
1170 } catch (Exception ex)
1173 ex.printStackTrace();
1180 JOptionPane.showInternalMessageDialog(this, MessageManager
1181 .formatMessage("label.couldnt_save_file", new Object[]
1182 { fileName }), MessageManager
1183 .getString("label.error_saving_file"),
1184 JOptionPane.WARNING_MESSAGE);
1191 private void warningMessage(String warning, String title)
1193 if (new jalview.util.Platform().isHeadless())
1195 System.err.println("Warning: " + title + "\nWarning: " + warning);
1200 JOptionPane.showInternalMessageDialog(this, warning, title,
1201 JOptionPane.WARNING_MESSAGE);
1213 protected void outputText_actionPerformed(ActionEvent e)
1216 ExportData exportData = getAlignmentForExport();
1217 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1218 cap.setForInput(null);
1222 cap.setText(new FormatAdapter(viewport).formatSequences(
1223 e.getActionCommand(),
1224 exportData.getAlignment(),
1225 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1226 viewport.getColumnSelection()));
1227 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1228 "label.alignment_output_command", new Object[]
1229 { e.getActionCommand() }), 600, 500);
1230 } catch (OutOfMemoryError oom)
1232 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1238 public ExportData getAlignmentForExport()
1240 AlignmentI alignmentToExport = null;
1241 String[] omitHidden = null;
1242 int[] alignmentStartEnd = new int[2];
1243 FeatureRenderer fr = new FeatureRenderer(this.alignPanel);
1244 viewport.setFeatureRenderer(fr);
1245 HiddenSequences hiddenSeqs = viewport.getAlignment()
1246 .getHiddenSequences();
1249 alignmentToExport = viewport.getAlignment();
1250 alignmentStartEnd = new int[]
1251 { 0, alignmentToExport.getWidth() - 1 };
1253 if (viewport.hasHiddenColumns() || hiddenSeqs.getSize() > 0)
1255 int reply = JOptionPane
1256 .showInternalConfirmDialog(
1259 .getString("label.alignment_contains_hidden_columns"),
1261 .getString("action.save_omit_hidden_columns"),
1262 JOptionPane.YES_NO_OPTION,
1263 JOptionPane.QUESTION_MESSAGE);
1265 if (reply == JOptionPane.YES_OPTION)
1267 // export only visible region
1268 omitHidden = viewport.getViewAsString(false);
1269 alignmentToExport = viewport.getAlignment();
1270 alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport
1271 .getColumnSelection().getHiddenColumns());
1272 viewport.setIncludeHiddenRegion(false);
1276 // export all region including visible
1277 alignmentToExport = hiddenSeqs.getFullAlignment();
1278 viewport.setIncludeHiddenRegion(true);
1282 return new ExportData(alignmentToExport, omitHidden, alignmentStartEnd);
1285 private static int[] getStartEnd(int[] aligmentStartEnd,
1286 List<int[]> hiddenCols)
1288 int startPos = aligmentStartEnd[0];
1289 int endPos = aligmentStartEnd[1];
1291 int[] lowestRange = new int[2];
1292 int[] higestRange = new int[2];
1294 for (int[] hiddenCol : hiddenCols)
1296 // System.out.println("comparing : " + hiddenCol[0] + "-" + hiddenCol[1]);
1298 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1299 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1301 // System.out.println("min : " + lowestRange[0] + "-" + lowestRange[1]);
1302 // System.out.println("max : " + higestRange[0] + "-" + higestRange[1]);
1304 if (lowestRange[0] == 0 && lowestRange[1] == 0)
1306 startPos = aligmentStartEnd[0];
1310 startPos = lowestRange[1] + 1;
1313 if (higestRange[0] == 0 && higestRange[1] == 0)
1315 endPos = aligmentStartEnd[1];
1319 endPos = higestRange[0];
1322 // System.out.println("Export range : " + minPos + " - " + maxPos);
1324 { startPos, endPos };
1327 public static void main(String[] args)
1329 ArrayList<int[]> hiddenCols = new ArrayList<int[]>();
1330 hiddenCols.add(new int[]
1332 hiddenCols.add(new int[]
1334 hiddenCols.add(new int[]
1336 hiddenCols.add(new int[]
1338 hiddenCols.add(new int[]
1341 int[] x = getStartEnd(new int[]
1342 { 0, 50 }, hiddenCols);
1343 // System.out.println("Export range : " + x[0] + " - " + x[1]);
1353 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1355 // new HTMLOutput(alignPanel,
1356 // alignPanel.getSeqPanel().seqCanvas.getSequenceRenderer(),
1357 // alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
1358 new HtmlSvgOutput(null, alignPanel);
1362 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1364 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel,
1365 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
1366 bjs.exportJalviewAlignmentAsBioJsHtmlFile();
1368 public void createImageMap(File file, String image)
1370 alignPanel.makePNGImageMap(file, image);
1380 public void createPNG(File f)
1382 alignPanel.makePNG(f);
1392 public void createEPS(File f)
1394 alignPanel.makeEPS(f);
1397 public void createSVG(File f)
1399 alignPanel.makeSVG(f);
1402 public void pageSetup_actionPerformed(ActionEvent e)
1404 PrinterJob printJob = PrinterJob.getPrinterJob();
1405 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1415 public void printMenuItem_actionPerformed(ActionEvent e)
1417 // Putting in a thread avoids Swing painting problems
1418 PrintThread thread = new PrintThread(alignPanel);
1423 public void exportFeatures_actionPerformed(ActionEvent e)
1425 new AnnotationExporter().exportFeatures(alignPanel);
1429 public void exportAnnotations_actionPerformed(ActionEvent e)
1431 new AnnotationExporter().exportAnnotations(alignPanel);
1435 public void associatedData_actionPerformed(ActionEvent e)
1437 // Pick the tree file
1438 JalviewFileChooser chooser = new JalviewFileChooser(
1439 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1440 chooser.setFileView(new JalviewFileView());
1441 chooser.setDialogTitle(MessageManager
1442 .getString("label.load_jalview_annotations"));
1443 chooser.setToolTipText(MessageManager
1444 .getString("label.load_jalview_annotations"));
1446 int value = chooser.showOpenDialog(null);
1448 if (value == JalviewFileChooser.APPROVE_OPTION)
1450 String choice = chooser.getSelectedFile().getPath();
1451 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1452 loadJalviewDataFile(choice, null, null, null);
1458 * Close the current view or all views in the alignment frame. If the frame
1459 * only contains one view then the alignment will be removed from memory.
1461 * @param closeAllTabs
1464 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1466 if (alignPanels != null && alignPanels.size() < 2)
1468 closeAllTabs = true;
1473 if (alignPanels != null)
1477 if (this.isClosed())
1479 // really close all the windows - otherwise wait till
1480 // setClosed(true) is called
1481 for (int i = 0; i < alignPanels.size(); i++)
1483 AlignmentPanel ap = alignPanels.get(i);
1490 closeView(alignPanel);
1496 this.setClosed(true);
1498 } catch (Exception ex)
1500 ex.printStackTrace();
1505 * Close the specified panel and close up tabs appropriately.
1507 * @param panelToClose
1509 public void closeView(AlignmentPanel panelToClose)
1511 int index = tabbedPane.getSelectedIndex();
1512 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1513 alignPanels.remove(panelToClose);
1514 panelToClose.closePanel();
1515 panelToClose = null;
1517 tabbedPane.removeTabAt(closedindex);
1518 tabbedPane.validate();
1520 if (index > closedindex || index == tabbedPane.getTabCount())
1522 // modify currently selected tab index if necessary.
1526 this.tabSelectionChanged(index);
1532 void updateEditMenuBar()
1535 if (viewport.getHistoryList().size() > 0)
1537 undoMenuItem.setEnabled(true);
1538 CommandI command = viewport.getHistoryList().peek();
1539 undoMenuItem.setText(MessageManager.formatMessage(
1540 "label.undo_command", new Object[]
1541 { command.getDescription() }));
1545 undoMenuItem.setEnabled(false);
1546 undoMenuItem.setText(MessageManager.getString("action.undo"));
1549 if (viewport.getRedoList().size() > 0)
1551 redoMenuItem.setEnabled(true);
1553 CommandI command = viewport.getRedoList().peek();
1554 redoMenuItem.setText(MessageManager.formatMessage(
1555 "label.redo_command", new Object[]
1556 { command.getDescription() }));
1560 redoMenuItem.setEnabled(false);
1561 redoMenuItem.setText(MessageManager.getString("action.redo"));
1565 public void addHistoryItem(CommandI command)
1567 if (command.getSize() > 0)
1569 viewport.addToHistoryList(command);
1570 viewport.clearRedoList();
1571 updateEditMenuBar();
1572 viewport.updateHiddenColumns();
1573 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1574 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1575 // viewport.getColumnSelection()
1576 // .getHiddenColumns().size() > 0);
1582 * @return alignment objects for all views
1584 AlignmentI[] getViewAlignments()
1586 if (alignPanels != null)
1588 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1590 for (AlignmentPanel ap : alignPanels)
1592 als[i++] = ap.av.getAlignment();
1596 if (viewport != null)
1598 return new AlignmentI[]
1599 { viewport.getAlignment() };
1611 protected void undoMenuItem_actionPerformed(ActionEvent e)
1613 if (viewport.getHistoryList().isEmpty())
1617 CommandI command = viewport.getHistoryList().pop();
1618 viewport.addToRedoList(command);
1619 command.undoCommand(getViewAlignments());
1621 AlignmentViewport originalSource = getOriginatingSource(command);
1622 updateEditMenuBar();
1624 if (originalSource != null)
1626 if (originalSource != viewport)
1629 .warn("Implementation worry: mismatch of viewport origin for undo");
1631 originalSource.updateHiddenColumns();
1632 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1634 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1635 // viewport.getColumnSelection()
1636 // .getHiddenColumns().size() > 0);
1637 originalSource.firePropertyChange("alignment", null, originalSource
1638 .getAlignment().getSequences());
1649 protected void redoMenuItem_actionPerformed(ActionEvent e)
1651 if (viewport.getRedoList().size() < 1)
1656 CommandI command = viewport.getRedoList().pop();
1657 viewport.addToHistoryList(command);
1658 command.doCommand(getViewAlignments());
1660 AlignmentViewport originalSource = getOriginatingSource(command);
1661 updateEditMenuBar();
1663 if (originalSource != null)
1666 if (originalSource != viewport)
1669 .warn("Implementation worry: mismatch of viewport origin for redo");
1671 originalSource.updateHiddenColumns();
1672 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1674 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1675 // viewport.getColumnSelection()
1676 // .getHiddenColumns().size() > 0);
1677 originalSource.firePropertyChange("alignment", null, originalSource
1678 .getAlignment().getSequences());
1682 AlignmentViewport getOriginatingSource(CommandI command)
1684 AlignmentViewport originalSource = null;
1685 // For sequence removal and addition, we need to fire
1686 // the property change event FROM the viewport where the
1687 // original alignment was altered
1688 AlignmentI al = null;
1689 if (command instanceof EditCommand)
1691 EditCommand editCommand = (EditCommand) command;
1692 al = editCommand.getAlignment();
1693 List<Component> comps = PaintRefresher.components.get(viewport
1694 .getSequenceSetId());
1696 for (Component comp : comps)
1698 if (comp instanceof AlignmentPanel)
1700 if (al == ((AlignmentPanel) comp).av.getAlignment())
1702 originalSource = ((AlignmentPanel) comp).av;
1709 if (originalSource == null)
1711 // The original view is closed, we must validate
1712 // the current view against the closed view first
1715 PaintRefresher.validateSequences(al, viewport.getAlignment());
1718 originalSource = viewport;
1721 return originalSource;
1730 public void moveSelectedSequences(boolean up)
1732 SequenceGroup sg = viewport.getSelectionGroup();
1738 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1739 viewport.getHiddenRepSequences(), up);
1740 alignPanel.paintAlignment(true);
1743 synchronized void slideSequences(boolean right, int size)
1745 List<SequenceI> sg = new ArrayList<SequenceI>();
1746 if (viewport.cursorMode)
1748 sg.add(viewport.getAlignment().getSequenceAt(
1749 alignPanel.getSeqPanel().seqCanvas.cursorY));
1751 else if (viewport.getSelectionGroup() != null
1752 && viewport.getSelectionGroup().getSize() != viewport
1753 .getAlignment().getHeight())
1755 sg = viewport.getSelectionGroup().getSequences(
1756 viewport.getHiddenRepSequences());
1764 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1766 for (SequenceI seq : viewport.getAlignment().getSequences())
1768 if (!sg.contains(seq))
1770 invertGroup.add(seq);
1774 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1776 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1777 for (int i = 0; i < invertGroup.size(); i++)
1779 seqs2[i] = invertGroup.get(i);
1782 SlideSequencesCommand ssc;
1785 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1786 size, viewport.getGapCharacter());
1790 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1791 size, viewport.getGapCharacter());
1794 int groupAdjustment = 0;
1795 if (ssc.getGapsInsertedBegin() && right)
1797 if (viewport.cursorMode)
1799 alignPanel.getSeqPanel().moveCursor(size, 0);
1803 groupAdjustment = size;
1806 else if (!ssc.getGapsInsertedBegin() && !right)
1808 if (viewport.cursorMode)
1810 alignPanel.getSeqPanel().moveCursor(-size, 0);
1814 groupAdjustment = -size;
1818 if (groupAdjustment != 0)
1820 viewport.getSelectionGroup().setStartRes(
1821 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1822 viewport.getSelectionGroup().setEndRes(
1823 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1826 boolean appendHistoryItem = false;
1827 Deque<CommandI> historyList = viewport.getHistoryList();
1828 if (historyList != null
1829 && historyList.size() > 0
1830 && historyList.peek() instanceof SlideSequencesCommand)
1832 appendHistoryItem = ssc
1833 .appendSlideCommand((SlideSequencesCommand) historyList
1837 if (!appendHistoryItem)
1839 addHistoryItem(ssc);
1852 protected void copy_actionPerformed(ActionEvent e)
1855 if (viewport.getSelectionGroup() == null)
1859 // TODO: preserve the ordering of displayed alignment annotation in any
1860 // internal paste (particularly sequence associated annotation)
1861 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1862 String[] omitHidden = null;
1864 if (viewport.hasHiddenColumns())
1866 omitHidden = viewport.getViewAsString(true);
1869 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1872 StringSelection ss = new StringSelection(output);
1876 jalview.gui.Desktop.internalCopy = true;
1877 // Its really worth setting the clipboard contents
1878 // to empty before setting the large StringSelection!!
1879 Toolkit.getDefaultToolkit().getSystemClipboard()
1880 .setContents(new StringSelection(""), null);
1882 Toolkit.getDefaultToolkit().getSystemClipboard()
1883 .setContents(ss, Desktop.instance);
1884 } catch (OutOfMemoryError er)
1886 new OOMWarning("copying region", er);
1890 ArrayList<int[]> hiddenColumns = null;
1891 if (viewport.hasHiddenColumns())
1893 hiddenColumns = new ArrayList<int[]>();
1894 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1895 .getSelectionGroup().getEndRes();
1896 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1898 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1900 hiddenColumns.add(new int[]
1901 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1906 Desktop.jalviewClipboard = new Object[]
1907 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1908 statusBar.setText(MessageManager.formatMessage(
1909 "label.copied_sequences_to_clipboard", new Object[]
1910 { Integer.valueOf(seqs.length).toString() }));
1920 protected void pasteNew_actionPerformed(ActionEvent e)
1932 protected void pasteThis_actionPerformed(ActionEvent e)
1938 * Paste contents of Jalview clipboard
1940 * @param newAlignment
1941 * true to paste to a new alignment, otherwise add to this.
1943 void paste(boolean newAlignment)
1945 boolean externalPaste = true;
1948 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1949 Transferable contents = c.getContents(this);
1951 if (contents == null)
1959 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1960 if (str.length() < 1)
1965 format = new IdentifyFile().Identify(str, "Paste");
1967 } catch (OutOfMemoryError er)
1969 new OOMWarning("Out of memory pasting sequences!!", er);
1973 SequenceI[] sequences;
1974 boolean annotationAdded = false;
1975 AlignmentI alignment = null;
1977 if (Desktop.jalviewClipboard != null)
1979 // The clipboard was filled from within Jalview, we must use the
1981 // And dataset from the copied alignment
1982 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1983 // be doubly sure that we create *new* sequence objects.
1984 sequences = new SequenceI[newseq.length];
1985 for (int i = 0; i < newseq.length; i++)
1987 sequences[i] = new Sequence(newseq[i]);
1989 alignment = new Alignment(sequences);
1990 externalPaste = false;
1994 // parse the clipboard as an alignment.
1995 alignment = new FormatAdapter().readFile(str, "Paste", format);
1996 sequences = alignment.getSequencesArray();
2000 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2006 if (Desktop.jalviewClipboard != null)
2008 // dataset is inherited
2009 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2013 // new dataset is constructed
2014 alignment.setDataset(null);
2016 alwidth = alignment.getWidth() + 1;
2020 AlignmentI pastedal = alignment; // preserve pasted alignment object
2021 // Add pasted sequences and dataset into existing alignment.
2022 alignment = viewport.getAlignment();
2023 alwidth = alignment.getWidth() + 1;
2024 // decide if we need to import sequences from an existing dataset
2025 boolean importDs = Desktop.jalviewClipboard != null
2026 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2027 // importDs==true instructs us to copy over new dataset sequences from
2028 // an existing alignment
2029 Vector newDs = (importDs) ? new Vector() : null; // used to create
2030 // minimum dataset set
2032 for (int i = 0; i < sequences.length; i++)
2036 newDs.addElement(null);
2038 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2040 if (importDs && ds != null)
2042 if (!newDs.contains(ds))
2044 newDs.setElementAt(ds, i);
2045 ds = new Sequence(ds);
2046 // update with new dataset sequence
2047 sequences[i].setDatasetSequence(ds);
2051 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2056 // copy and derive new dataset sequence
2057 sequences[i] = sequences[i].deriveSequence();
2058 alignment.getDataset().addSequence(
2059 sequences[i].getDatasetSequence());
2060 // TODO: avoid creation of duplicate dataset sequences with a
2061 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2063 alignment.addSequence(sequences[i]); // merges dataset
2067 newDs.clear(); // tidy up
2069 if (alignment.getAlignmentAnnotation() != null)
2071 for (AlignmentAnnotation alan : alignment
2072 .getAlignmentAnnotation())
2074 if (alan.graphGroup > fgroup)
2076 fgroup = alan.graphGroup;
2080 if (pastedal.getAlignmentAnnotation() != null)
2082 // Add any annotation attached to alignment.
2083 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2084 for (int i = 0; i < alann.length; i++)
2086 annotationAdded = true;
2087 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2089 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2090 if (newann.graphGroup > -1)
2092 if (newGraphGroups.size() <= newann.graphGroup
2093 || newGraphGroups.get(newann.graphGroup) == null)
2095 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2097 newGraphGroups.add(q, null);
2099 newGraphGroups.set(newann.graphGroup, new Integer(
2102 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2106 newann.padAnnotation(alwidth);
2107 alignment.addAnnotation(newann);
2117 addHistoryItem(new EditCommand(
2118 MessageManager.getString("label.add_sequences"),
2120 sequences, 0, alignment.getWidth(), alignment));
2122 // Add any annotations attached to sequences
2123 for (int i = 0; i < sequences.length; i++)
2125 if (sequences[i].getAnnotation() != null)
2127 AlignmentAnnotation newann;
2128 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2130 annotationAdded = true;
2131 newann = sequences[i].getAnnotation()[a];
2132 newann.adjustForAlignment();
2133 newann.padAnnotation(alwidth);
2134 if (newann.graphGroup > -1)
2136 if (newann.graphGroup > -1)
2138 if (newGraphGroups.size() <= newann.graphGroup
2139 || newGraphGroups.get(newann.graphGroup) == null)
2141 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2143 newGraphGroups.add(q, null);
2145 newGraphGroups.set(newann.graphGroup, new Integer(
2148 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2152 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2157 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2164 // propagate alignment changed.
2165 viewport.setEndSeq(alignment.getHeight());
2166 if (annotationAdded)
2168 // Duplicate sequence annotation in all views.
2169 AlignmentI[] alview = this.getViewAlignments();
2170 for (int i = 0; i < sequences.length; i++)
2172 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2177 for (int avnum = 0; avnum < alview.length; avnum++)
2179 if (alview[avnum] != alignment)
2181 // duplicate in a view other than the one with input focus
2182 int avwidth = alview[avnum].getWidth() + 1;
2183 // this relies on sann being preserved after we
2184 // modify the sequence's annotation array for each duplication
2185 for (int a = 0; a < sann.length; a++)
2187 AlignmentAnnotation newann = new AlignmentAnnotation(
2189 sequences[i].addAlignmentAnnotation(newann);
2190 newann.padAnnotation(avwidth);
2191 alview[avnum].addAnnotation(newann); // annotation was
2192 // duplicated earlier
2193 // TODO JAL-1145 graphGroups are not updated for sequence
2194 // annotation added to several views. This may cause
2196 alview[avnum].setAnnotationIndex(newann, a);
2201 buildSortByAnnotationScoresMenu();
2203 viewport.firePropertyChange("alignment", null,
2204 alignment.getSequences());
2205 if (alignPanels != null)
2207 for (AlignmentPanel ap : alignPanels)
2209 ap.validateAnnotationDimensions(false);
2214 alignPanel.validateAnnotationDimensions(false);
2220 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2222 String newtitle = new String("Copied sequences");
2224 if (Desktop.jalviewClipboard != null
2225 && Desktop.jalviewClipboard[2] != null)
2227 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2228 for (int[] region : hc)
2230 af.viewport.hideColumns(region[0], region[1]);
2234 // >>>This is a fix for the moment, until a better solution is
2236 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2238 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2240 // TODO: maintain provenance of an alignment, rather than just make the
2241 // title a concatenation of operations.
2244 if (title.startsWith("Copied sequences"))
2250 newtitle = newtitle.concat("- from " + title);
2255 newtitle = new String("Pasted sequences");
2258 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2263 } catch (Exception ex)
2265 ex.printStackTrace();
2266 System.out.println("Exception whilst pasting: " + ex);
2267 // could be anything being pasted in here
2273 protected void expand_newalign(ActionEvent e)
2277 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2278 .getAlignment(), -1);
2279 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2281 String newtitle = new String("Flanking alignment");
2283 if (Desktop.jalviewClipboard != null
2284 && Desktop.jalviewClipboard[2] != null)
2286 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2287 for (int region[] : hc)
2289 af.viewport.hideColumns(region[0], region[1]);
2293 // >>>This is a fix for the moment, until a better solution is
2295 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2297 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2299 // TODO: maintain provenance of an alignment, rather than just make the
2300 // title a concatenation of operations.
2302 if (title.startsWith("Copied sequences"))
2308 newtitle = newtitle.concat("- from " + title);
2312 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2314 } catch (Exception ex)
2316 ex.printStackTrace();
2317 System.out.println("Exception whilst pasting: " + ex);
2318 // could be anything being pasted in here
2319 } catch (OutOfMemoryError oom)
2321 new OOMWarning("Viewing flanking region of alignment", oom);
2332 protected void cut_actionPerformed(ActionEvent e)
2334 copy_actionPerformed(null);
2335 delete_actionPerformed(null);
2345 protected void delete_actionPerformed(ActionEvent evt)
2348 SequenceGroup sg = viewport.getSelectionGroup();
2355 * If the cut affects all sequences, warn, remove highlighted columns
2357 if (sg.getSize() == viewport.getAlignment().getHeight())
2359 int confirm = JOptionPane.showConfirmDialog(this,
2360 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2361 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2362 JOptionPane.OK_CANCEL_OPTION);
2364 if (confirm == JOptionPane.CANCEL_OPTION
2365 || confirm == JOptionPane.CLOSED_OPTION)
2369 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2370 sg.getEndRes() + 1);
2373 SequenceI[] cut = sg.getSequences()
2374 .toArray(new SequenceI[sg.getSize()]);
2376 addHistoryItem(new EditCommand(
2377 MessageManager.getString("label.cut_sequences"), Action.CUT,
2378 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2379 viewport.getAlignment()));
2381 viewport.setSelectionGroup(null);
2382 viewport.sendSelection();
2383 viewport.getAlignment().deleteGroup(sg);
2385 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2387 if (viewport.getAlignment().getHeight() < 1)
2391 this.setClosed(true);
2392 } catch (Exception ex)
2405 protected void deleteGroups_actionPerformed(ActionEvent e)
2407 if (avc.deleteGroups())
2409 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2410 alignPanel.updateAnnotation();
2411 alignPanel.paintAlignment(true);
2422 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2424 SequenceGroup sg = new SequenceGroup();
2426 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2428 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2431 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2432 viewport.setSelectionGroup(sg);
2433 viewport.sendSelection();
2434 alignPanel.paintAlignment(true);
2435 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2445 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2447 if (viewport.cursorMode)
2449 alignPanel.getSeqPanel().keyboardNo1 = null;
2450 alignPanel.getSeqPanel().keyboardNo2 = null;
2452 viewport.setSelectionGroup(null);
2453 viewport.getColumnSelection().clear();
2454 viewport.setSelectionGroup(null);
2455 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2456 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2457 alignPanel.paintAlignment(true);
2458 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2459 viewport.sendSelection();
2469 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2471 SequenceGroup sg = viewport.getSelectionGroup();
2475 selectAllSequenceMenuItem_actionPerformed(null);
2480 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2482 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2485 alignPanel.paintAlignment(true);
2486 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2487 viewport.sendSelection();
2491 public void invertColSel_actionPerformed(ActionEvent e)
2493 viewport.invertColumnSelection();
2494 alignPanel.paintAlignment(true);
2495 viewport.sendSelection();
2505 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2507 trimAlignment(true);
2517 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2519 trimAlignment(false);
2522 void trimAlignment(boolean trimLeft)
2524 ColumnSelection colSel = viewport.getColumnSelection();
2527 if (colSel.size() > 0)
2531 column = colSel.getMin();
2535 column = colSel.getMax();
2539 if (viewport.getSelectionGroup() != null)
2541 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2542 viewport.getHiddenRepSequences());
2546 seqs = viewport.getAlignment().getSequencesArray();
2549 TrimRegionCommand trimRegion;
2552 trimRegion = new TrimRegionCommand("Remove Left",
2553 TrimRegionCommand.TRIM_LEFT, seqs, column,
2554 viewport.getAlignment(), viewport.getColumnSelection(),
2555 viewport.getSelectionGroup());
2556 viewport.setStartRes(0);
2560 trimRegion = new TrimRegionCommand("Remove Right",
2561 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2562 viewport.getAlignment(), viewport.getColumnSelection(),
2563 viewport.getSelectionGroup());
2566 statusBar.setText(MessageManager.formatMessage(
2567 "label.removed_columns", new String[]
2568 { Integer.valueOf(trimRegion.getSize()).toString() }));
2570 addHistoryItem(trimRegion);
2572 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2574 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2575 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2577 viewport.getAlignment().deleteGroup(sg);
2581 viewport.firePropertyChange("alignment", null, viewport
2582 .getAlignment().getSequences());
2593 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2595 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2598 if (viewport.getSelectionGroup() != null)
2600 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2601 viewport.getHiddenRepSequences());
2602 start = viewport.getSelectionGroup().getStartRes();
2603 end = viewport.getSelectionGroup().getEndRes();
2607 seqs = viewport.getAlignment().getSequencesArray();
2610 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2611 "Remove Gapped Columns", seqs, start, end,
2612 viewport.getAlignment());
2614 addHistoryItem(removeGapCols);
2616 statusBar.setText(MessageManager.formatMessage(
2617 "label.removed_empty_columns", new Object[]
2618 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2620 // This is to maintain viewport position on first residue
2621 // of first sequence
2622 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2623 int startRes = seq.findPosition(viewport.startRes);
2624 // ShiftList shifts;
2625 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2626 // edit.alColumnChanges=shifts.getInverse();
2627 // if (viewport.hasHiddenColumns)
2628 // viewport.getColumnSelection().compensateForEdits(shifts);
2629 viewport.setStartRes(seq.findIndex(startRes) - 1);
2630 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2642 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2644 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2647 if (viewport.getSelectionGroup() != null)
2649 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2650 viewport.getHiddenRepSequences());
2651 start = viewport.getSelectionGroup().getStartRes();
2652 end = viewport.getSelectionGroup().getEndRes();
2656 seqs = viewport.getAlignment().getSequencesArray();
2659 // This is to maintain viewport position on first residue
2660 // of first sequence
2661 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2662 int startRes = seq.findPosition(viewport.startRes);
2664 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2665 viewport.getAlignment()));
2667 viewport.setStartRes(seq.findIndex(startRes) - 1);
2669 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2681 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2683 viewport.setPadGaps(padGapsMenuitem.isSelected());
2684 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2695 public void findMenuItem_actionPerformed(ActionEvent e)
2701 * Create a new view of the current alignment.
2704 public void newView_actionPerformed(ActionEvent e)
2706 newView(null, true);
2710 * Creates and shows a new view of the current alignment.
2713 * title of newly created view; if null, one will be generated
2714 * @param copyAnnotation
2715 * if true then duplicate all annnotation, groups and settings
2716 * @return new alignment panel, already displayed.
2718 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2721 * Create a new AlignmentPanel (with its own, new Viewport)
2723 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2725 if (!copyAnnotation)
2728 * remove all groups and annotation except for the automatic stuff
2730 newap.av.getAlignment().deleteAllGroups();
2731 newap.av.getAlignment().deleteAllAnnotations(false);
2734 newap.av.setGatherViewsHere(false);
2736 if (viewport.viewName == null)
2738 viewport.viewName = MessageManager
2739 .getString("label.view_name_original");
2743 * Views share the same edits, undo and redo stacks, mappings.
2745 newap.av.setHistoryList(viewport.getHistoryList());
2746 newap.av.setRedoList(viewport.getRedoList());
2747 newap.av.getAlignment().setCodonFrames(
2748 viewport.getAlignment().getCodonFrames());
2750 newap.av.viewName = getNewViewName(viewTitle);
2752 addAlignmentPanel(newap, true);
2753 newap.alignmentChanged();
2755 if (alignPanels.size() == 2)
2757 viewport.setGatherViewsHere(true);
2759 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2764 * Make a new name for the view, ensuring it is unique within the current
2765 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2766 * these now use viewId. Unique view names are still desirable for usability.)
2771 protected String getNewViewName(String viewTitle)
2773 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2774 boolean addFirstIndex = false;
2775 if (viewTitle == null || viewTitle.trim().length() == 0)
2777 viewTitle = MessageManager.getString("action.view");
2778 addFirstIndex = true;
2782 index = 1;// we count from 1 if given a specific name
2784 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2786 List<Component> comps = PaintRefresher.components.get(viewport
2787 .getSequenceSetId());
2789 List<String> existingNames = getExistingViewNames(comps);
2791 while (existingNames.contains(newViewName))
2793 newViewName = viewTitle + " " + (++index);
2799 * Returns a list of distinct view names found in the given list of
2800 * components. View names are held on the viewport of an AlignmentPanel.
2805 protected List<String> getExistingViewNames(List<Component> comps)
2807 List<String> existingNames = new ArrayList<String>();
2808 for (Component comp : comps)
2810 if (comp instanceof AlignmentPanel)
2812 AlignmentPanel ap = (AlignmentPanel) comp;
2813 if (!existingNames.contains(ap.av.viewName))
2815 existingNames.add(ap.av.viewName);
2819 return existingNames;
2823 * Explode tabbed views into separate windows.
2826 public void expandViews_actionPerformed(ActionEvent e)
2828 Desktop.instance.explodeViews(this);
2832 * Gather views in separate windows back into a tabbed presentation.
2835 public void gatherViews_actionPerformed(ActionEvent e)
2837 Desktop.instance.gatherViews(this);
2847 public void font_actionPerformed(ActionEvent e)
2849 new FontChooser(alignPanel);
2859 protected void seqLimit_actionPerformed(ActionEvent e)
2861 viewport.setShowJVSuffix(seqLimits.isSelected());
2863 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2864 .calculateIdWidth());
2865 alignPanel.paintAlignment(true);
2869 public void idRightAlign_actionPerformed(ActionEvent e)
2871 viewport.setRightAlignIds(idRightAlign.isSelected());
2872 alignPanel.paintAlignment(true);
2876 public void centreColumnLabels_actionPerformed(ActionEvent e)
2878 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2879 alignPanel.paintAlignment(true);
2885 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2888 protected void followHighlight_actionPerformed()
2891 * Set the 'follow' flag on the Viewport (and scroll to position if now
2894 final boolean state = this.followHighlightMenuItem.getState();
2895 viewport.setFollowHighlight(state);
2898 alignPanel.scrollToPosition(
2899 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2910 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2912 viewport.setColourText(colourTextMenuItem.isSelected());
2913 alignPanel.paintAlignment(true);
2923 public void wrapMenuItem_actionPerformed(ActionEvent e)
2925 scaleAbove.setVisible(wrapMenuItem.isSelected());
2926 scaleLeft.setVisible(wrapMenuItem.isSelected());
2927 scaleRight.setVisible(wrapMenuItem.isSelected());
2928 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2929 alignPanel.updateLayout();
2933 public void showAllSeqs_actionPerformed(ActionEvent e)
2935 viewport.showAllHiddenSeqs();
2939 public void showAllColumns_actionPerformed(ActionEvent e)
2941 viewport.showAllHiddenColumns();
2946 public void hideSelSequences_actionPerformed(ActionEvent e)
2948 viewport.hideAllSelectedSeqs();
2949 // alignPanel.paintAlignment(true);
2953 * called by key handler and the hide all/show all menu items
2958 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2961 boolean hide = false;
2962 SequenceGroup sg = viewport.getSelectionGroup();
2963 if (!toggleSeqs && !toggleCols)
2965 // Hide everything by the current selection - this is a hack - we do the
2966 // invert and then hide
2967 // first check that there will be visible columns after the invert.
2968 if ((viewport.getColumnSelection() != null
2969 && viewport.getColumnSelection().getSelected() != null && viewport
2970 .getColumnSelection().getSelected().size() > 0)
2971 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2974 // now invert the sequence set, if required - empty selection implies
2975 // that no hiding is required.
2978 invertSequenceMenuItem_actionPerformed(null);
2979 sg = viewport.getSelectionGroup();
2983 viewport.expandColSelection(sg, true);
2984 // finally invert the column selection and get the new sequence
2986 invertColSel_actionPerformed(null);
2993 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2995 hideSelSequences_actionPerformed(null);
2998 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3001 showAllSeqs_actionPerformed(null);
3007 if (viewport.getColumnSelection().getSelected().size() > 0)
3009 hideSelColumns_actionPerformed(null);
3012 viewport.setSelectionGroup(sg);
3017 showAllColumns_actionPerformed(null);
3026 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3027 * event.ActionEvent)
3030 public void hideAllButSelection_actionPerformed(ActionEvent e)
3032 toggleHiddenRegions(false, false);
3039 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3043 public void hideAllSelection_actionPerformed(ActionEvent e)
3045 SequenceGroup sg = viewport.getSelectionGroup();
3046 viewport.expandColSelection(sg, false);
3047 viewport.hideAllSelectedSeqs();
3048 viewport.hideSelectedColumns();
3049 alignPanel.paintAlignment(true);
3056 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3060 public void showAllhidden_actionPerformed(ActionEvent e)
3062 viewport.showAllHiddenColumns();
3063 viewport.showAllHiddenSeqs();
3064 alignPanel.paintAlignment(true);
3068 public void hideSelColumns_actionPerformed(ActionEvent e)
3070 viewport.hideSelectedColumns();
3071 alignPanel.paintAlignment(true);
3075 public void hiddenMarkers_actionPerformed(ActionEvent e)
3077 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3088 protected void scaleAbove_actionPerformed(ActionEvent e)
3090 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3091 alignPanel.paintAlignment(true);
3101 protected void scaleLeft_actionPerformed(ActionEvent e)
3103 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3104 alignPanel.paintAlignment(true);
3114 protected void scaleRight_actionPerformed(ActionEvent e)
3116 viewport.setScaleRightWrapped(scaleRight.isSelected());
3117 alignPanel.paintAlignment(true);
3127 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3129 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3130 alignPanel.paintAlignment(true);
3140 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3142 viewport.setShowText(viewTextMenuItem.isSelected());
3143 alignPanel.paintAlignment(true);
3153 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3155 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3156 alignPanel.paintAlignment(true);
3159 public FeatureSettings featureSettings;
3162 public void featureSettings_actionPerformed(ActionEvent e)
3164 if (featureSettings != null)
3166 featureSettings.close();
3167 featureSettings = null;
3169 if (!showSeqFeatures.isSelected())
3171 // make sure features are actually displayed
3172 showSeqFeatures.setSelected(true);
3173 showSeqFeatures_actionPerformed(null);
3175 featureSettings = new FeatureSettings(this);
3179 * Set or clear 'Show Sequence Features'
3185 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3187 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3188 alignPanel.paintAlignment(true);
3189 if (alignPanel.getOverviewPanel() != null)
3191 alignPanel.getOverviewPanel().updateOverviewImage();
3196 * Set or clear 'Show Sequence Features'
3202 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3204 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3206 if (viewport.isShowSequenceFeaturesHeight())
3208 // ensure we're actually displaying features
3209 viewport.setShowSequenceFeatures(true);
3210 showSeqFeatures.setSelected(true);
3212 alignPanel.paintAlignment(true);
3213 if (alignPanel.getOverviewPanel() != null)
3215 alignPanel.getOverviewPanel().updateOverviewImage();
3220 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3221 * the annotations panel as a whole.
3223 * The options to show/hide all annotations should be enabled when the panel
3224 * is shown, and disabled when the panel is hidden.
3229 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3231 final boolean setVisible = annotationPanelMenuItem.isSelected();
3232 viewport.setShowAnnotation(setVisible);
3233 this.showAllSeqAnnotations.setEnabled(setVisible);
3234 this.hideAllSeqAnnotations.setEnabled(setVisible);
3235 this.showAllAlAnnotations.setEnabled(setVisible);
3236 this.hideAllAlAnnotations.setEnabled(setVisible);
3237 alignPanel.updateLayout();
3241 public void alignmentProperties()
3243 JEditorPane editPane = new JEditorPane("text/html", "");
3244 editPane.setEditable(false);
3245 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3247 editPane.setText(MessageManager.formatMessage("label.html_content",
3249 { contents.toString() }));
3250 JInternalFrame frame = new JInternalFrame();
3251 frame.getContentPane().add(new JScrollPane(editPane));
3253 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3254 "label.alignment_properties", new Object[]
3255 { getTitle() }), 500, 400);
3265 public void overviewMenuItem_actionPerformed(ActionEvent e)
3267 if (alignPanel.overviewPanel != null)
3272 JInternalFrame frame = new JInternalFrame();
3273 OverviewPanel overview = new OverviewPanel(alignPanel);
3274 frame.setContentPane(overview);
3275 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3276 "label.overview_params", new Object[]
3277 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3279 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3280 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3283 public void internalFrameClosed(
3284 javax.swing.event.InternalFrameEvent evt)
3286 alignPanel.setOverviewPanel(null);
3290 alignPanel.setOverviewPanel(overview);
3294 public void textColour_actionPerformed(ActionEvent e)
3296 new TextColourChooser().chooseColour(alignPanel, null);
3306 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3318 public void clustalColour_actionPerformed(ActionEvent e)
3320 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3321 viewport.getHiddenRepSequences()));
3331 public void zappoColour_actionPerformed(ActionEvent e)
3333 changeColour(new ZappoColourScheme());
3343 public void taylorColour_actionPerformed(ActionEvent e)
3345 changeColour(new TaylorColourScheme());
3355 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3357 changeColour(new HydrophobicColourScheme());
3367 public void helixColour_actionPerformed(ActionEvent e)
3369 changeColour(new HelixColourScheme());
3379 public void strandColour_actionPerformed(ActionEvent e)
3381 changeColour(new StrandColourScheme());
3391 public void turnColour_actionPerformed(ActionEvent e)
3393 changeColour(new TurnColourScheme());
3403 public void buriedColour_actionPerformed(ActionEvent e)
3405 changeColour(new BuriedColourScheme());
3415 public void nucleotideColour_actionPerformed(ActionEvent e)
3417 changeColour(new NucleotideColourScheme());
3421 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3423 changeColour(new PurinePyrimidineColourScheme());
3427 * public void covariationColour_actionPerformed(ActionEvent e) {
3429 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3433 public void annotationColour_actionPerformed(ActionEvent e)
3435 new AnnotationColourChooser(viewport, alignPanel);
3439 public void annotationColumn_actionPerformed(ActionEvent e)
3441 new AnnotationColumnChooser(viewport, alignPanel);
3445 public void rnahelicesColour_actionPerformed(ActionEvent e)
3447 new RNAHelicesColourChooser(viewport, alignPanel);
3457 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3459 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3468 public void changeColour(ColourSchemeI cs)
3470 // TODO: compare with applet and pull up to model method
3475 if (viewport.getAbovePIDThreshold())
3477 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3479 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3483 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3486 if (viewport.getConservationSelected())
3489 Alignment al = (Alignment) viewport.getAlignment();
3490 Conservation c = new Conservation("All",
3491 ResidueProperties.propHash, 3, al.getSequences(), 0,
3495 c.verdict(false, viewport.getConsPercGaps());
3497 cs.setConservation(c);
3499 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3504 cs.setConservation(null);
3507 cs.setConsensus(viewport.getSequenceConsensusHash());
3510 viewport.setGlobalColourScheme(cs);
3512 if (viewport.getColourAppliesToAllGroups())
3515 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3523 if (cs instanceof ClustalxColourScheme)
3525 sg.cs = new ClustalxColourScheme(sg,
3526 viewport.getHiddenRepSequences());
3528 else if (cs instanceof UserColourScheme)
3530 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3536 sg.cs = cs.getClass().newInstance();
3537 } catch (Exception ex)
3542 if (viewport.getAbovePIDThreshold()
3543 || cs instanceof PIDColourScheme
3544 || cs instanceof Blosum62ColourScheme)
3546 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3548 sg.cs.setConsensus(AAFrequency.calculate(
3549 sg.getSequences(viewport.getHiddenRepSequences()),
3550 sg.getStartRes(), sg.getEndRes() + 1));
3554 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3557 if (viewport.getConservationSelected())
3559 Conservation c = new Conservation("Group",
3560 ResidueProperties.propHash, 3, sg.getSequences(viewport
3561 .getHiddenRepSequences()), sg.getStartRes(),
3562 sg.getEndRes() + 1);
3564 c.verdict(false, viewport.getConsPercGaps());
3565 sg.cs.setConservation(c);
3569 sg.cs.setConservation(null);
3574 if (alignPanel.getOverviewPanel() != null)
3576 alignPanel.getOverviewPanel().updateOverviewImage();
3579 alignPanel.paintAlignment(true);
3589 protected void modifyPID_actionPerformed(ActionEvent e)
3591 if (viewport.getAbovePIDThreshold()
3592 && viewport.getGlobalColourScheme() != null)
3594 SliderPanel.setPIDSliderSource(alignPanel,
3595 viewport.getGlobalColourScheme(), "Background");
3596 SliderPanel.showPIDSlider();
3607 protected void modifyConservation_actionPerformed(ActionEvent e)
3609 if (viewport.getConservationSelected()
3610 && viewport.getGlobalColourScheme() != null)
3612 SliderPanel.setConservationSlider(alignPanel,
3613 viewport.getGlobalColourScheme(), "Background");
3614 SliderPanel.showConservationSlider();
3625 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3627 viewport.setConservationSelected(conservationMenuItem.isSelected());
3629 viewport.setAbovePIDThreshold(false);
3630 abovePIDThreshold.setSelected(false);
3632 changeColour(viewport.getGlobalColourScheme());
3634 modifyConservation_actionPerformed(null);
3644 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3646 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3648 conservationMenuItem.setSelected(false);
3649 viewport.setConservationSelected(false);
3651 changeColour(viewport.getGlobalColourScheme());
3653 modifyPID_actionPerformed(null);
3663 public void userDefinedColour_actionPerformed(ActionEvent e)
3665 if (e.getActionCommand().equals(
3666 MessageManager.getString("action.user_defined")))
3668 new UserDefinedColours(alignPanel, null);
3672 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3673 .getUserColourSchemes().get(e.getActionCommand());
3679 public void updateUserColourMenu()
3682 Component[] menuItems = colourMenu.getMenuComponents();
3683 int iSize = menuItems.length;
3684 for (int i = 0; i < iSize; i++)
3686 if (menuItems[i].getName() != null
3687 && menuItems[i].getName().equals("USER_DEFINED"))
3689 colourMenu.remove(menuItems[i]);
3693 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3695 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3696 .getUserColourSchemes().keys();
3698 while (userColours.hasMoreElements())
3700 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3701 userColours.nextElement().toString());
3702 radioItem.setName("USER_DEFINED");
3703 radioItem.addMouseListener(new MouseAdapter()
3706 public void mousePressed(MouseEvent evt)
3708 if (evt.isControlDown()
3709 || SwingUtilities.isRightMouseButton(evt))
3711 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3713 int option = JOptionPane.showInternalConfirmDialog(
3714 jalview.gui.Desktop.desktop,
3716 .getString("label.remove_from_default_list"),
3718 .getString("label.remove_user_defined_colour"),
3719 JOptionPane.YES_NO_OPTION);
3720 if (option == JOptionPane.YES_OPTION)
3722 jalview.gui.UserDefinedColours
3723 .removeColourFromDefaults(radioItem.getText());
3724 colourMenu.remove(radioItem);
3728 radioItem.addActionListener(new ActionListener()
3731 public void actionPerformed(ActionEvent evt)
3733 userDefinedColour_actionPerformed(evt);
3740 radioItem.addActionListener(new ActionListener()
3743 public void actionPerformed(ActionEvent evt)
3745 userDefinedColour_actionPerformed(evt);
3749 colourMenu.insert(radioItem, 15);
3750 colours.add(radioItem);
3762 public void PIDColour_actionPerformed(ActionEvent e)
3764 changeColour(new PIDColourScheme());
3774 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3776 changeColour(new Blosum62ColourScheme());
3786 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3788 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3789 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3790 .getAlignment().getSequenceAt(0), null);
3791 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3792 viewport.getAlignment()));
3793 alignPanel.paintAlignment(true);
3803 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3805 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3806 AlignmentSorter.sortByID(viewport.getAlignment());
3807 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3808 viewport.getAlignment()));
3809 alignPanel.paintAlignment(true);
3819 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3821 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3822 AlignmentSorter.sortByLength(viewport.getAlignment());
3823 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3824 viewport.getAlignment()));
3825 alignPanel.paintAlignment(true);
3835 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3837 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3838 AlignmentSorter.sortByGroup(viewport.getAlignment());
3839 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3840 viewport.getAlignment()));
3842 alignPanel.paintAlignment(true);
3852 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3854 new RedundancyPanel(alignPanel, this);
3864 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3866 if ((viewport.getSelectionGroup() == null)
3867 || (viewport.getSelectionGroup().getSize() < 2))
3869 JOptionPane.showInternalMessageDialog(this, MessageManager
3870 .getString("label.you_must_select_least_two_sequences"),
3871 MessageManager.getString("label.invalid_selection"),
3872 JOptionPane.WARNING_MESSAGE);
3876 JInternalFrame frame = new JInternalFrame();
3877 frame.setContentPane(new PairwiseAlignPanel(viewport));
3878 Desktop.addInternalFrame(frame,
3879 MessageManager.getString("action.pairwise_alignment"), 600,
3891 public void PCAMenuItem_actionPerformed(ActionEvent e)
3893 if (((viewport.getSelectionGroup() != null)
3894 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3895 .getSelectionGroup().getSize() > 0))
3896 || (viewport.getAlignment().getHeight() < 4))
3899 .showInternalMessageDialog(
3902 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3904 .getString("label.sequence_selection_insufficient"),
3905 JOptionPane.WARNING_MESSAGE);
3910 new PCAPanel(alignPanel);
3914 public void autoCalculate_actionPerformed(ActionEvent e)
3916 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3917 if (viewport.autoCalculateConsensus)
3919 viewport.firePropertyChange("alignment", null, viewport
3920 .getAlignment().getSequences());
3925 public void sortByTreeOption_actionPerformed(ActionEvent e)
3927 viewport.sortByTree = sortByTree.isSelected();
3931 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3933 viewport.followSelection = listenToViewSelections.isSelected();
3943 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3945 newTreePanel("AV", "PID", "Average distance tree using PID");
3955 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3957 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3967 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3969 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3979 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3981 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3994 void newTreePanel(String type, String pwType, String title)
3998 if (viewport.getSelectionGroup() != null
3999 && viewport.getSelectionGroup().getSize() > 0)
4001 if (viewport.getSelectionGroup().getSize() < 3)
4007 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4009 .getString("label.not_enough_sequences"),
4010 JOptionPane.WARNING_MESSAGE);
4014 SequenceGroup sg = viewport.getSelectionGroup();
4016 /* Decide if the selection is a column region */
4017 for (SequenceI _s : sg.getSequences())
4019 if (_s.getLength() < sg.getEndRes())
4025 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4027 .getString("label.sequences_selection_not_aligned"),
4028 JOptionPane.WARNING_MESSAGE);
4034 title = title + " on region";
4035 tp = new TreePanel(alignPanel, type, pwType);
4039 // are the visible sequences aligned?
4040 if (!viewport.getAlignment().isAligned(false))
4046 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4048 .getString("label.sequences_not_aligned"),
4049 JOptionPane.WARNING_MESSAGE);
4054 if (viewport.getAlignment().getHeight() < 2)
4059 tp = new TreePanel(alignPanel, type, pwType);
4064 if (viewport.viewName != null)
4066 title += viewport.viewName + " of ";
4069 title += this.title;
4071 Desktop.addInternalFrame(tp, title, 600, 500);
4082 public void addSortByOrderMenuItem(String title,
4083 final AlignmentOrder order)
4085 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4087 item.addActionListener(new java.awt.event.ActionListener()
4090 public void actionPerformed(ActionEvent e)
4092 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4094 // TODO: JBPNote - have to map order entries to curent SequenceI
4096 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4098 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4101 alignPanel.paintAlignment(true);
4107 * Add a new sort by annotation score menu item
4110 * the menu to add the option to
4112 * the label used to retrieve scores for each sequence on the
4115 public void addSortByAnnotScoreMenuItem(JMenu sort,
4116 final String scoreLabel)
4118 final JMenuItem item = new JMenuItem(scoreLabel);
4120 item.addActionListener(new java.awt.event.ActionListener()
4123 public void actionPerformed(ActionEvent e)
4125 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4126 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4127 viewport.getAlignment());// ,viewport.getSelectionGroup());
4128 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4129 viewport.getAlignment()));
4130 alignPanel.paintAlignment(true);
4136 * last hash for alignment's annotation array - used to minimise cost of
4139 protected int _annotationScoreVectorHash;
4142 * search the alignment and rebuild the sort by annotation score submenu the
4143 * last alignment annotation vector hash is stored to minimize cost of
4144 * rebuilding in subsequence calls.
4148 public void buildSortByAnnotationScoresMenu()
4150 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4155 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4157 sortByAnnotScore.removeAll();
4158 // almost certainly a quicker way to do this - but we keep it simple
4159 Hashtable scoreSorts = new Hashtable();
4160 AlignmentAnnotation aann[];
4161 for (SequenceI sqa : viewport.getAlignment().getSequences())
4163 aann = sqa.getAnnotation();
4164 for (int i = 0; aann != null && i < aann.length; i++)
4166 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4168 scoreSorts.put(aann[i].label, aann[i].label);
4172 Enumeration labels = scoreSorts.keys();
4173 while (labels.hasMoreElements())
4175 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4176 (String) labels.nextElement());
4178 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4181 _annotationScoreVectorHash = viewport.getAlignment()
4182 .getAlignmentAnnotation().hashCode();
4187 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4188 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4189 * call. Listeners are added to remove the menu item when the treePanel is
4190 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4194 * Displayed tree window.
4196 * SortBy menu item title.
4199 public void buildTreeMenu()
4201 calculateTree.removeAll();
4202 // build the calculate menu
4204 for (final String type : new String[]
4207 String treecalcnm = MessageManager.getString("label.tree_calc_"
4208 + type.toLowerCase());
4209 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4211 JMenuItem tm = new JMenuItem();
4212 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4213 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4215 String smn = MessageManager.getStringOrReturn(
4216 "label.score_model_", sm.getName());
4217 final String title = MessageManager.formatMessage(
4218 "label.treecalc_title", treecalcnm, smn);
4219 tm.setText(title);//
4220 tm.addActionListener(new java.awt.event.ActionListener()
4223 public void actionPerformed(ActionEvent e)
4225 newTreePanel(type, pwtype, title);
4228 calculateTree.add(tm);
4233 sortByTreeMenu.removeAll();
4235 List<Component> comps = PaintRefresher.components.get(viewport
4236 .getSequenceSetId());
4237 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4238 for (Component comp : comps)
4240 if (comp instanceof TreePanel)
4242 treePanels.add((TreePanel) comp);
4246 if (treePanels.size() < 1)
4248 sortByTreeMenu.setVisible(false);
4252 sortByTreeMenu.setVisible(true);
4254 for (final TreePanel tp : treePanels)
4256 final JMenuItem item = new JMenuItem(tp.getTitle());
4257 item.addActionListener(new java.awt.event.ActionListener()
4260 public void actionPerformed(ActionEvent e)
4262 tp.sortByTree_actionPerformed();
4263 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4268 sortByTreeMenu.add(item);
4272 public boolean sortBy(AlignmentOrder alorder, String undoname)
4274 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4275 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4276 if (undoname != null)
4278 addHistoryItem(new OrderCommand(undoname, oldOrder,
4279 viewport.getAlignment()));
4281 alignPanel.paintAlignment(true);
4286 * Work out whether the whole set of sequences or just the selected set will
4287 * be submitted for multiple alignment.
4290 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4292 // Now, check we have enough sequences
4293 AlignmentView msa = null;
4295 if ((viewport.getSelectionGroup() != null)
4296 && (viewport.getSelectionGroup().getSize() > 1))
4298 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4299 // some common interface!
4301 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4302 * SequenceI[sz = seqs.getSize(false)];
4304 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4305 * seqs.getSequenceAt(i); }
4307 msa = viewport.getAlignmentView(true);
4309 else if (viewport.getSelectionGroup() != null
4310 && viewport.getSelectionGroup().getSize() == 1)
4312 int option = JOptionPane.showConfirmDialog(this,
4313 MessageManager.getString("warn.oneseq_msainput_selection"),
4314 MessageManager.getString("label.invalid_selection"),
4315 JOptionPane.OK_CANCEL_OPTION);
4316 if (option == JOptionPane.OK_OPTION)
4318 msa = viewport.getAlignmentView(false);
4323 msa = viewport.getAlignmentView(false);
4329 * Decides what is submitted to a secondary structure prediction service: the
4330 * first sequence in the alignment, or in the current selection, or, if the
4331 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4332 * region or the whole alignment. (where the first sequence in the set is the
4333 * one that the prediction will be for).
4335 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4337 AlignmentView seqs = null;
4339 if ((viewport.getSelectionGroup() != null)
4340 && (viewport.getSelectionGroup().getSize() > 0))
4342 seqs = viewport.getAlignmentView(true);
4346 seqs = viewport.getAlignmentView(false);
4348 // limit sequences - JBPNote in future - could spawn multiple prediction
4350 // TODO: viewport.getAlignment().isAligned is a global state - the local
4351 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4352 if (!viewport.getAlignment().isAligned(false))
4354 seqs.setSequences(new SeqCigar[]
4355 { seqs.getSequences()[0] });
4356 // TODO: if seqs.getSequences().length>1 then should really have warned
4370 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4372 // Pick the tree file
4373 JalviewFileChooser chooser = new JalviewFileChooser(
4374 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4375 chooser.setFileView(new JalviewFileView());
4376 chooser.setDialogTitle(MessageManager
4377 .getString("label.select_newick_like_tree_file"));
4378 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4380 int value = chooser.showOpenDialog(null);
4382 if (value == JalviewFileChooser.APPROVE_OPTION)
4384 String choice = chooser.getSelectedFile().getPath();
4385 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4386 jalview.io.NewickFile fin = null;
4389 fin = new jalview.io.NewickFile(choice, "File");
4390 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4391 } catch (Exception ex)
4398 .getString("label.problem_reading_tree_file"),
4399 JOptionPane.WARNING_MESSAGE);
4400 ex.printStackTrace();
4402 if (fin != null && fin.hasWarningMessage())
4404 JOptionPane.showMessageDialog(Desktop.desktop, fin
4405 .getWarningMessage(), MessageManager
4406 .getString("label.possible_problem_with_tree_file"),
4407 JOptionPane.WARNING_MESSAGE);
4413 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4415 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4418 public TreePanel ShowNewickTree(NewickFile nf, String title)
4420 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4423 public TreePanel ShowNewickTree(NewickFile nf, String title,
4424 AlignmentView input)
4426 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4429 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4430 int h, int x, int y)
4432 return ShowNewickTree(nf, title, null, w, h, x, y);
4436 * Add a treeviewer for the tree extracted from a newick file object to the
4437 * current alignment view
4444 * Associated alignment input data (or null)
4453 * @return TreePanel handle
4455 public TreePanel ShowNewickTree(NewickFile nf, String title,
4456 AlignmentView input, int w, int h, int x, int y)
4458 TreePanel tp = null;
4464 if (nf.getTree() != null)
4466 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4472 tp.setLocation(x, y);
4475 Desktop.addInternalFrame(tp, title, w, h);
4477 } catch (Exception ex)
4479 ex.printStackTrace();
4485 private boolean buildingMenu = false;
4488 * Generates menu items and listener event actions for web service clients
4491 public void BuildWebServiceMenu()
4493 while (buildingMenu)
4497 System.err.println("Waiting for building menu to finish.");
4499 } catch (Exception e)
4503 final AlignFrame me = this;
4504 buildingMenu = true;
4505 new Thread(new Runnable()
4510 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4513 System.err.println("Building ws menu again "
4514 + Thread.currentThread());
4515 // TODO: add support for context dependent disabling of services based
4517 // alignment and current selection
4518 // TODO: add additional serviceHandle parameter to specify abstract
4520 // class independently of AbstractName
4521 // TODO: add in rediscovery GUI function to restart discoverer
4522 // TODO: group services by location as well as function and/or
4524 // object broker mechanism.
4525 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4526 final IProgressIndicator af = me;
4527 final JMenu msawsmenu = new JMenu("Alignment");
4528 final JMenu secstrmenu = new JMenu(
4529 "Secondary Structure Prediction");
4530 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4531 final JMenu analymenu = new JMenu("Analysis");
4532 final JMenu dismenu = new JMenu("Protein Disorder");
4533 // final JMenu msawsmenu = new
4534 // JMenu(MessageManager.getString("label.alignment"));
4535 // final JMenu secstrmenu = new
4536 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4537 // final JMenu seqsrchmenu = new
4538 // JMenu(MessageManager.getString("label.sequence_database_search"));
4539 // final JMenu analymenu = new
4540 // JMenu(MessageManager.getString("label.analysis"));
4541 // final JMenu dismenu = new
4542 // JMenu(MessageManager.getString("label.protein_disorder"));
4543 // JAL-940 - only show secondary structure prediction services from
4544 // the legacy server
4545 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4547 Discoverer.services != null && (Discoverer.services.size() > 0))
4549 // TODO: refactor to allow list of AbstractName/Handler bindings to
4551 // stored or retrieved from elsewhere
4552 // No MSAWS used any more:
4553 // Vector msaws = null; // (Vector)
4554 // Discoverer.services.get("MsaWS");
4555 Vector secstrpr = (Vector) Discoverer.services
4557 if (secstrpr != null)
4559 // Add any secondary structure prediction services
4560 for (int i = 0, j = secstrpr.size(); i < j; i++)
4562 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4564 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4565 .getServiceClient(sh);
4566 int p = secstrmenu.getItemCount();
4567 impl.attachWSMenuEntry(secstrmenu, me);
4568 int q = secstrmenu.getItemCount();
4569 for (int litm = p; litm < q; litm++)
4571 legacyItems.add(secstrmenu.getItem(litm));
4577 // Add all submenus in the order they should appear on the web
4579 wsmenu.add(msawsmenu);
4580 wsmenu.add(secstrmenu);
4581 wsmenu.add(dismenu);
4582 wsmenu.add(analymenu);
4583 // No search services yet
4584 // wsmenu.add(seqsrchmenu);
4586 javax.swing.SwingUtilities.invokeLater(new Runnable()
4593 webService.removeAll();
4594 // first, add discovered services onto the webservices menu
4595 if (wsmenu.size() > 0)
4597 for (int i = 0, j = wsmenu.size(); i < j; i++)
4599 webService.add(wsmenu.get(i));
4604 webService.add(me.webServiceNoServices);
4606 // TODO: move into separate menu builder class.
4607 boolean new_sspred = false;
4608 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4610 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4611 if (jws2servs != null)
4613 if (jws2servs.hasServices())
4615 jws2servs.attachWSMenuEntry(webService, me);
4616 for (Jws2Instance sv : jws2servs.getServices())
4618 if (sv.description.toLowerCase().contains("jpred"))
4620 for (JMenuItem jmi : legacyItems)
4622 jmi.setVisible(false);
4628 if (jws2servs.isRunning())
4630 JMenuItem tm = new JMenuItem(
4631 "Still discovering JABA Services");
4632 tm.setEnabled(false);
4637 build_urlServiceMenu(me.webService);
4638 build_fetchdbmenu(webService);
4639 for (JMenu item : wsmenu)
4641 if (item.getItemCount() == 0)
4643 item.setEnabled(false);
4647 item.setEnabled(true);
4650 } catch (Exception e)
4653 .debug("Exception during web service menu building process.",
4658 } catch (Exception e)
4661 buildingMenu = false;
4668 * construct any groupURL type service menu entries.
4672 private void build_urlServiceMenu(JMenu webService)
4674 // TODO: remove this code when 2.7 is released
4675 // DEBUG - alignmentView
4677 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4678 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4680 * @Override public void actionPerformed(ActionEvent e) {
4681 * jalview.datamodel.AlignmentView
4682 * .testSelectionViews(af.viewport.getAlignment(),
4683 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4685 * }); webService.add(testAlView);
4687 // TODO: refactor to RestClient discoverer and merge menu entries for
4688 // rest-style services with other types of analysis/calculation service
4689 // SHmmr test client - still being implemented.
4690 // DEBUG - alignmentView
4692 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4695 client.attachWSMenuEntry(
4696 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4702 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4703 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4704 * getProperty("LAST_DIRECTORY"));
4706 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4707 * to Vamsas file"); chooser.setToolTipText("Export");
4709 * int value = chooser.showSaveDialog(this);
4711 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4712 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4713 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4714 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4717 * prototype of an automatically enabled/disabled analysis function
4720 protected void setShowProductsEnabled()
4722 SequenceI[] selection = viewport.getSequenceSelection();
4723 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4724 viewport.getAlignment().getDataset()))
4726 showProducts.setEnabled(true);
4731 showProducts.setEnabled(false);
4736 * search selection for sequence xRef products and build the show products
4741 * @return true if showProducts menu should be enabled.
4743 public boolean canShowProducts(SequenceI[] selection,
4744 boolean isRegionSelection, Alignment dataset)
4746 boolean showp = false;
4749 showProducts.removeAll();
4750 final boolean dna = viewport.getAlignment().isNucleotide();
4751 final Alignment ds = dataset;
4752 String[] ptypes = (selection == null || selection.length == 0) ? null
4753 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4755 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4756 // selection, dataset, true);
4757 final SequenceI[] sel = selection;
4758 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4761 final boolean isRegSel = isRegionSelection;
4762 final AlignFrame af = this;
4763 final String source = ptypes[t];
4764 JMenuItem xtype = new JMenuItem(ptypes[t]);
4765 xtype.addActionListener(new ActionListener()
4769 public void actionPerformed(ActionEvent e)
4771 // TODO: new thread for this call with vis-delay
4772 af.showProductsFor(af.viewport.getSequenceSelection(),
4773 isRegSel, dna, source);
4777 showProducts.add(xtype);
4779 showProducts.setVisible(showp);
4780 showProducts.setEnabled(showp);
4781 } catch (Exception e)
4783 jalview.bin.Cache.log
4784 .warn("canTranslate threw an exception - please report to help@jalview.org",
4791 protected void showProductsFor(final SequenceI[] sel,
4792 final boolean isRegSel, final boolean dna, final String source)
4794 Runnable foo = new Runnable()
4800 final long sttime = System.currentTimeMillis();
4801 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4802 "status.searching_for_sequences_from", new Object[]
4803 { source }), sttime);
4806 // update our local dataset reference
4807 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4809 Alignment prods = CrossRef
4810 .findXrefSequences(sel, dna, source, ds);
4813 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4814 for (int s = 0; s < sprods.length; s++)
4816 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4817 if (ds.getSequences() == null
4818 || !ds.getSequences().contains(
4819 sprods[s].getDatasetSequence()))
4821 ds.addSequence(sprods[s].getDatasetSequence());
4823 sprods[s].updatePDBIds();
4825 Alignment al = new Alignment(sprods);
4829 * Copy dna-to-protein mappings to new alignment
4831 // TODO 1: no mappings are set up for EMBL product
4832 // TODO 2: if they were, should add them to protein alignment, not
4834 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4835 for (AlignedCodonFrame acf : cf)
4837 al.addCodonFrame(acf);
4839 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4841 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4842 + " for " + ((isRegSel) ? "selected region of " : "")
4844 naf.setTitle(newtitle);
4846 // temporary flag until SplitFrame is released
4847 boolean asSplitFrame = Cache.getDefault(
4848 Preferences.ENABLE_SPLIT_FRAME, false);
4852 * Make a copy of this alignment (sharing the same dataset
4853 * sequences). If we are DNA, drop introns and update mappings
4855 AlignmentI copyAlignment = null;
4856 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4857 .getSequenceSelection();
4860 copyAlignment = AlignmentUtils.makeExonAlignment(
4861 sequenceSelection, cf);
4862 al.getCodonFrames().clear();
4863 al.getCodonFrames().addAll(cf);
4864 final StructureSelectionManager ssm = StructureSelectionManager
4865 .getStructureSelectionManager(Desktop.instance);
4866 ssm.addMappings(cf);
4870 copyAlignment = new Alignment(new Alignment(
4871 sequenceSelection));
4873 AlignFrame copyThis = new AlignFrame(copyAlignment,
4874 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4875 copyThis.setTitle(AlignFrame.this.getTitle());
4876 // SplitFrame with dna above, protein below
4877 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4878 dna ? naf : copyThis);
4879 naf.setVisible(true);
4880 copyThis.setVisible(true);
4881 String linkedTitle = MessageManager
4882 .getString("label.linked_view_title");
4883 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4887 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4893 System.err.println("No Sequences generated for xRef type "
4896 } catch (Exception e)
4898 jalview.bin.Cache.log.error(
4899 "Exception when finding crossreferences", e);
4900 } catch (OutOfMemoryError e)
4902 new OOMWarning("whilst fetching crossreferences", e);
4905 jalview.bin.Cache.log.error("Error when finding crossreferences",
4908 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4909 "status.finished_searching_for_sequences_from",
4916 Thread frunner = new Thread(foo);
4920 public boolean canShowTranslationProducts(SequenceI[] selection,
4921 AlignmentI alignment)
4926 return (jalview.analysis.Dna.canTranslate(selection,
4927 viewport.getViewAsVisibleContigs(true)));
4928 } catch (Exception e)
4930 jalview.bin.Cache.log
4931 .warn("canTranslate threw an exception - please report to help@jalview.org",
4938 * Construct and display a new frame containing the translation of this
4939 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4942 public void showTranslation_actionPerformed(ActionEvent e)
4944 AlignmentI al = null;
4947 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4949 al = dna.translateCdna();
4950 } catch (Exception ex)
4952 jalview.bin.Cache.log.error(
4953 "Exception during translation. Please report this !", ex);
4954 final String msg = MessageManager
4955 .getString("label.error_when_translating_sequences_submit_bug_report");
4956 final String title = MessageManager
4957 .getString("label.implementation_error")
4958 + MessageManager.getString("translation_failed");
4959 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4960 JOptionPane.ERROR_MESSAGE);
4963 if (al == null || al.getHeight() == 0)
4965 final String msg = MessageManager
4966 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4967 final String title = MessageManager
4968 .getString("label.translation_failed");
4969 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4970 JOptionPane.WARNING_MESSAGE);
4974 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4975 af.setFileFormat(this.currentFileFormat);
4976 final String newTitle = MessageManager.formatMessage(
4977 "label.translation_of_params", new Object[]
4978 { this.getTitle() });
4979 af.setTitle(newTitle);
4980 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
4982 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4983 viewport.openSplitFrame(af, new Alignment(seqs),
4984 al.getCodonFrames());
4988 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4995 * Set the file format
4999 public void setFileFormat(String fileFormat)
5001 this.currentFileFormat = fileFormat;
5005 * Try to load a features file onto the alignment.
5008 * contents or path to retrieve file
5010 * access mode of file (see jalview.io.AlignFile)
5011 * @return true if features file was parsed corectly.
5013 public boolean parseFeaturesFile(String file, String type)
5015 boolean featuresFile = false;
5018 featuresFile = new FeaturesFile(file, type).parse(viewport
5019 .getAlignment().getDataset(), alignPanel.getSeqPanel().seqCanvas
5020 .getFeatureRenderer().getFeatureColours(), false,
5021 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5022 } catch (Exception ex)
5024 ex.printStackTrace();
5029 viewport.setShowSequenceFeatures(true);
5030 showSeqFeatures.setSelected(true);
5031 if (alignPanel.getSeqPanel().seqCanvas.fr != null)
5033 // update the min/max ranges where necessary
5034 alignPanel.getSeqPanel().seqCanvas.fr.findAllFeatures(true);
5036 if (featureSettings != null)
5038 featureSettings.setTableData();
5040 alignPanel.paintAlignment(true);
5043 return featuresFile;
5047 public void dragEnter(DropTargetDragEvent evt)
5052 public void dragExit(DropTargetEvent evt)
5057 public void dragOver(DropTargetDragEvent evt)
5062 public void dropActionChanged(DropTargetDragEvent evt)
5067 public void drop(DropTargetDropEvent evt)
5069 Transferable t = evt.getTransferable();
5070 java.util.List files = null;
5074 DataFlavor uriListFlavor = new DataFlavor(
5075 "text/uri-list;class=java.lang.String");
5076 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5078 // Works on Windows and MacOSX
5079 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5080 files = (java.util.List) t
5081 .getTransferData(DataFlavor.javaFileListFlavor);
5083 else if (t.isDataFlavorSupported(uriListFlavor))
5085 // This is used by Unix drag system
5086 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5087 String data = (String) t.getTransferData(uriListFlavor);
5088 files = new java.util.ArrayList(1);
5089 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5090 data, "\r\n"); st.hasMoreTokens();)
5092 String s = st.nextToken();
5093 if (s.startsWith("#"))
5095 // the line is a comment (as per the RFC 2483)
5099 java.net.URI uri = new java.net.URI(s);
5100 // check to see if we can handle this kind of URI
5101 if (uri.getScheme().toLowerCase().startsWith("http"))
5103 files.add(uri.toString());
5107 // otherwise preserve old behaviour: catch all for file objects
5108 java.io.File file = new java.io.File(uri);
5109 files.add(file.toString());
5113 } catch (Exception e)
5115 e.printStackTrace();
5121 // check to see if any of these files have names matching sequences in
5123 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5124 .getAlignment().getSequencesArray());
5126 * Object[] { String,SequenceI}
5128 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5129 ArrayList<String> filesnotmatched = new ArrayList<String>();
5130 for (int i = 0; i < files.size(); i++)
5132 String file = files.get(i).toString();
5134 String protocol = FormatAdapter.checkProtocol(file);
5135 if (protocol == jalview.io.FormatAdapter.FILE)
5137 File fl = new File(file);
5138 pdbfn = fl.getName();
5140 else if (protocol == jalview.io.FormatAdapter.URL)
5142 URL url = new URL(file);
5143 pdbfn = url.getFile();
5145 if (pdbfn.length() > 0)
5147 // attempt to find a match in the alignment
5148 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5149 int l = 0, c = pdbfn.indexOf(".");
5150 while (mtch == null && c != -1)
5155 } while ((c = pdbfn.indexOf(".", l)) > l);
5158 pdbfn = pdbfn.substring(0, l);
5160 mtch = idm.findAllIdMatches(pdbfn);
5167 type = new IdentifyFile().Identify(file, protocol);
5168 } catch (Exception ex)
5174 if (type.equalsIgnoreCase("PDB"))
5176 filesmatched.add(new Object[]
5177 { file, protocol, mtch });
5182 // File wasn't named like one of the sequences or wasn't a PDB file.
5183 filesnotmatched.add(file);
5187 if (filesmatched.size() > 0)
5189 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5195 "label.automatically_associate_pdb_files_with_sequences_same_name",
5202 .getString("label.automatically_associate_pdb_files_by_name"),
5203 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5206 for (Object[] fm : filesmatched)
5208 // try and associate
5209 // TODO: may want to set a standard ID naming formalism for
5210 // associating PDB files which have no IDs.
5211 for (SequenceI toassoc : (SequenceI[]) fm[2])
5213 PDBEntry pe = new AssociatePdbFileWithSeq()
5214 .associatePdbWithSeq((String) fm[0],
5215 (String) fm[1], toassoc, false,
5219 System.err.println("Associated file : "
5220 + ((String) fm[0]) + " with "
5221 + toassoc.getDisplayId(true));
5225 alignPanel.paintAlignment(true);
5229 if (filesnotmatched.size() > 0)
5232 && (Cache.getDefault(
5233 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5236 "<html>"+MessageManager
5238 "label.ignore_unmatched_dropped_files_info",
5243 .toString() })+"</html>",
5245 .getString("label.ignore_unmatched_dropped_files"),
5246 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5250 for (String fn : filesnotmatched)
5252 loadJalviewDataFile(fn, null, null, null);
5256 } catch (Exception ex)
5258 ex.printStackTrace();
5264 * Attempt to load a "dropped" file or URL string: First by testing whether
5265 * it's and Annotation file, then a JNet file, and finally a features file. If
5266 * all are false then the user may have dropped an alignment file onto this
5270 * either a filename or a URL string.
5272 public void loadJalviewDataFile(String file, String protocol,
5273 String format, SequenceI assocSeq)
5277 if (protocol == null)
5279 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5281 // if the file isn't identified, or not positively identified as some
5282 // other filetype (PFAM is default unidentified alignment file type) then
5283 // try to parse as annotation.
5284 boolean isAnnotation = (format == null || format
5285 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5286 .annotateAlignmentView(viewport, file, protocol)
5291 // first see if its a T-COFFEE score file
5292 TCoffeeScoreFile tcf = null;
5295 tcf = new TCoffeeScoreFile(file, protocol);
5298 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5300 tcoffeeColour.setEnabled(true);
5301 tcoffeeColour.setSelected(true);
5302 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5303 isAnnotation = true;
5305 .setText(MessageManager
5306 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5310 // some problem - if no warning its probable that the ID matching
5311 // process didn't work
5315 tcf.getWarningMessage() == null ? MessageManager
5316 .getString("label.check_file_matches_sequence_ids_alignment")
5317 : tcf.getWarningMessage(),
5319 .getString("label.problem_reading_tcoffee_score_file"),
5320 JOptionPane.WARNING_MESSAGE);
5327 } catch (Exception x)
5330 .debug("Exception when processing data source as T-COFFEE score file",
5336 // try to see if its a JNet 'concise' style annotation file *before*
5338 // try to parse it as a features file
5341 format = new IdentifyFile().Identify(file, protocol);
5343 if (format.equalsIgnoreCase("JnetFile"))
5345 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5347 new JnetAnnotationMaker();
5348 JnetAnnotationMaker.add_annotation(predictions,
5349 viewport.getAlignment(), 0, false);
5350 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5351 viewport.getAlignment().setSeqrep(repseq);
5352 ColumnSelection cs = new ColumnSelection();
5353 cs.hideInsertionsFor(repseq);
5354 viewport.setColumnSelection(cs);
5355 isAnnotation = true;
5360 * if (format.equalsIgnoreCase("PDB")) {
5362 * String pdbfn = ""; // try to match up filename with sequence id
5363 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5364 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5365 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5366 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5367 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5368 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5369 * // attempt to find a match in the alignment SequenceI mtch =
5370 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5371 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5372 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5373 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5374 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5375 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5376 * { System.err.println("Associated file : " + file + " with " +
5377 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5378 * TODO: maybe need to load as normal otherwise return; } }
5380 // try to parse it as a features file
5381 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5382 // if it wasn't a features file then we just treat it as a general
5383 // alignment file to load into the current view.
5386 new FileLoader().LoadFile(viewport, file, protocol, format);
5390 alignPanel.paintAlignment(true);
5398 alignPanel.adjustAnnotationHeight();
5399 viewport.updateSequenceIdColours();
5400 buildSortByAnnotationScoresMenu();
5401 alignPanel.paintAlignment(true);
5403 } catch (Exception ex)
5405 ex.printStackTrace();
5406 } catch (OutOfMemoryError oom)
5411 } catch (Exception x)
5417 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5418 : "using " + protocol + " from " + file)
5420 + (format != null ? "(parsing as '" + format
5421 + "' file)" : ""), oom, Desktop.desktop);
5426 * Method invoked by the ChangeListener on the tabbed pane, in other words
5427 * when a different tabbed pane is selected by the user or programmatically.
5430 public void tabSelectionChanged(int index)
5434 alignPanel = alignPanels.get(index);
5435 viewport = alignPanel.av;
5436 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5437 setMenusFromViewport(viewport);
5441 * If there is a frame linked to this one in a SplitPane, switch it to the
5442 * same view tab index. No infinite recursion of calls should happen, since
5443 * tabSelectionChanged() should not get invoked on setting the selected
5444 * index to an unchanged value. Guard against setting an invalid index
5445 * before the new view peer tab has been created.
5447 final AlignViewportI peer = viewport.getCodingComplement();
5450 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5451 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5453 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5459 * On right mouse click on view tab, prompt for and set new view name.
5462 public void tabbedPane_mousePressed(MouseEvent e)
5464 if (SwingUtilities.isRightMouseButton(e))
5466 String msg = MessageManager.getString("label.enter_view_name");
5467 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5468 JOptionPane.QUESTION_MESSAGE);
5472 viewport.viewName = reply;
5473 // TODO warn if reply is in getExistingViewNames()?
5474 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5479 public AlignViewport getCurrentView()
5485 * Open the dialog for regex description parsing.
5488 protected void extractScores_actionPerformed(ActionEvent e)
5490 ParseProperties pp = new jalview.analysis.ParseProperties(
5491 viewport.getAlignment());
5492 // TODO: verify regex and introduce GUI dialog for version 2.5
5493 // if (pp.getScoresFromDescription("col", "score column ",
5494 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5496 if (pp.getScoresFromDescription("description column",
5497 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5499 buildSortByAnnotationScoresMenu();
5507 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5511 protected void showDbRefs_actionPerformed(ActionEvent e)
5513 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5519 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5523 protected void showNpFeats_actionPerformed(ActionEvent e)
5525 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5529 * find the viewport amongst the tabs in this alignment frame and close that
5534 public boolean closeView(AlignViewportI av)
5538 this.closeMenuItem_actionPerformed(false);
5541 Component[] comp = tabbedPane.getComponents();
5542 for (int i = 0; comp != null && i < comp.length; i++)
5544 if (comp[i] instanceof AlignmentPanel)
5546 if (((AlignmentPanel) comp[i]).av == av)
5549 closeView((AlignmentPanel) comp[i]);
5557 protected void build_fetchdbmenu(JMenu webService)
5559 // Temporary hack - DBRef Fetcher always top level ws entry.
5560 // TODO We probably want to store a sequence database checklist in
5561 // preferences and have checkboxes.. rather than individual sources selected
5563 final JMenu rfetch = new JMenu(
5564 MessageManager.getString("action.fetch_db_references"));
5565 rfetch.setToolTipText(MessageManager
5566 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5567 webService.add(rfetch);
5569 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5570 MessageManager.getString("option.trim_retrieved_seqs"));
5571 trimrs.setToolTipText(MessageManager
5572 .getString("label.trim_retrieved_sequences"));
5573 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5574 trimrs.addActionListener(new ActionListener()
5577 public void actionPerformed(ActionEvent e)
5579 trimrs.setSelected(trimrs.isSelected());
5580 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5581 Boolean.valueOf(trimrs.isSelected()).toString());
5585 JMenuItem fetchr = new JMenuItem(
5586 MessageManager.getString("label.standard_databases"));
5587 fetchr.setToolTipText(MessageManager
5588 .getString("label.fetch_embl_uniprot"));
5589 fetchr.addActionListener(new ActionListener()
5593 public void actionPerformed(ActionEvent e)
5595 new Thread(new Runnable()
5601 new jalview.ws.DBRefFetcher(alignPanel.av
5602 .getSequenceSelection(), alignPanel.alignFrame)
5603 .fetchDBRefs(false);
5611 final AlignFrame me = this;
5612 new Thread(new Runnable()
5617 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5618 .getSequenceFetcherSingleton(me);
5619 javax.swing.SwingUtilities.invokeLater(new Runnable()
5624 String[] dbclasses = sf.getOrderedSupportedSources();
5625 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5626 // jalview.util.QuickSort.sort(otherdb, otherdb);
5627 List<DbSourceProxy> otherdb;
5628 JMenu dfetch = new JMenu();
5629 JMenu ifetch = new JMenu();
5630 JMenuItem fetchr = null;
5631 int comp = 0, icomp = 0, mcomp = 15;
5632 String mname = null;
5634 for (String dbclass : dbclasses)
5636 otherdb = sf.getSourceProxy(dbclass);
5637 // add a single entry for this class, or submenu allowing 'fetch
5639 if (otherdb == null || otherdb.size() < 1)
5643 // List<DbSourceProxy> dbs=otherdb;
5644 // otherdb=new ArrayList<DbSourceProxy>();
5645 // for (DbSourceProxy db:dbs)
5647 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5651 mname = "From " + dbclass;
5653 if (otherdb.size() == 1)
5655 final DbSourceProxy[] dassource = otherdb
5656 .toArray(new DbSourceProxy[0]);
5657 DbSourceProxy src = otherdb.get(0);
5658 fetchr = new JMenuItem(src.getDbSource());
5659 fetchr.addActionListener(new ActionListener()
5663 public void actionPerformed(ActionEvent e)
5665 new Thread(new Runnable()
5671 new jalview.ws.DBRefFetcher(alignPanel.av
5672 .getSequenceSelection(),
5673 alignPanel.alignFrame, dassource)
5674 .fetchDBRefs(false);
5680 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5686 final DbSourceProxy[] dassource = otherdb
5687 .toArray(new DbSourceProxy[0]);
5689 DbSourceProxy src = otherdb.get(0);
5690 fetchr = new JMenuItem(MessageManager.formatMessage(
5691 "label.fetch_all_param", new Object[]
5692 { src.getDbSource() }));
5693 fetchr.addActionListener(new ActionListener()
5696 public void actionPerformed(ActionEvent e)
5698 new Thread(new Runnable()
5704 new jalview.ws.DBRefFetcher(alignPanel.av
5705 .getSequenceSelection(),
5706 alignPanel.alignFrame, dassource)
5707 .fetchDBRefs(false);
5713 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5716 // and then build the rest of the individual menus
5717 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5719 String imname = null;
5721 for (DbSourceProxy sproxy : otherdb)
5723 String dbname = sproxy.getDbName();
5724 String sname = dbname.length() > 5 ? dbname.substring(0,
5725 5) + "..." : dbname;
5726 String msname = dbname.length() > 10 ? dbname.substring(
5727 0, 10) + "..." : dbname;
5730 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5732 fetchr = new JMenuItem(msname);
5733 final DbSourceProxy[] dassrc =
5735 fetchr.addActionListener(new ActionListener()
5739 public void actionPerformed(ActionEvent e)
5741 new Thread(new Runnable()
5747 new jalview.ws.DBRefFetcher(alignPanel.av
5748 .getSequenceSelection(),
5749 alignPanel.alignFrame, dassrc)
5750 .fetchDBRefs(false);
5756 fetchr.setToolTipText("<html>"
5757 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5760 if (++icomp >= mcomp || i == (otherdb.size()))
5762 ifetch.setText(MessageManager.formatMessage(
5763 "label.source_to_target", imname, sname));
5765 ifetch = new JMenu();
5773 if (comp >= mcomp || dbi >= (dbclasses.length))
5775 dfetch.setText(MessageManager.formatMessage(
5776 "label.source_to_target", mname, dbclass));
5778 dfetch = new JMenu();
5791 * Left justify the whole alignment.
5794 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5796 AlignmentI al = viewport.getAlignment();
5798 viewport.firePropertyChange("alignment", null, al);
5802 * Right justify the whole alignment.
5805 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5807 AlignmentI al = viewport.getAlignment();
5809 viewport.firePropertyChange("alignment", null, al);
5812 public void setShowSeqFeatures(boolean b)
5814 showSeqFeatures.setSelected(b);
5815 viewport.setShowSequenceFeatures(b);
5822 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5823 * awt.event.ActionEvent)
5826 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5828 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5829 alignPanel.paintAlignment(true);
5836 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5840 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5842 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5843 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5851 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5852 * .event.ActionEvent)
5855 protected void showGroupConservation_actionPerformed(ActionEvent e)
5857 viewport.setShowGroupConservation(showGroupConservation.getState());
5858 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5865 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5866 * .event.ActionEvent)
5869 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5871 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5872 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5879 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5880 * .event.ActionEvent)
5883 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5885 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5886 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5890 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5892 showSequenceLogo.setState(true);
5893 viewport.setShowSequenceLogo(true);
5894 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5895 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5899 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5901 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5908 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5909 * .event.ActionEvent)
5912 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5914 if (avc.makeGroupsFromSelection())
5916 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5917 alignPanel.updateAnnotation();
5918 alignPanel.paintAlignment(true);
5921 public void clearAlignmentSeqRep()
5923 // TODO refactor alignmentseqrep to controller
5924 if (viewport.getAlignment().hasSeqrep()) {
5925 viewport.getAlignment().setSeqrep(null);
5926 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5927 alignPanel.updateAnnotation();
5928 alignPanel.paintAlignment(true);
5933 protected void createGroup_actionPerformed(ActionEvent e)
5935 if (avc.createGroup())
5937 alignPanel.alignmentChanged();
5942 protected void unGroup_actionPerformed(ActionEvent e)
5946 alignPanel.alignmentChanged();
5951 * make the given alignmentPanel the currently selected tab
5953 * @param alignmentPanel
5955 public void setDisplayedView(AlignmentPanel alignmentPanel)
5957 if (!viewport.getSequenceSetId().equals(
5958 alignmentPanel.av.getSequenceSetId()))
5960 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5962 if (tabbedPane != null
5963 && tabbedPane.getTabCount() > 0
5964 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5965 .getSelectedIndex())
5967 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5972 * Action on selection of menu options to Show or Hide annotations.
5975 * @param forSequences
5976 * update sequence-related annotations
5977 * @param forAlignment
5978 * update non-sequence-related annotations
5981 protected void setAnnotationsVisibility(boolean visible,
5982 boolean forSequences, boolean forAlignment)
5984 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5985 .getAlignmentAnnotation())
5988 * don't display non-positional annotations on an alignment
5990 if (aa.annotations == null)
5994 boolean apply = (aa.sequenceRef == null && forAlignment)
5995 || (aa.sequenceRef != null && forSequences);
5998 aa.visible = visible;
6001 alignPanel.validateAnnotationDimensions(false);
6002 alignPanel.alignmentChanged();
6006 * Store selected annotation sort order for the view and repaint.
6009 protected void sortAnnotations_actionPerformed()
6011 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
6013 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
6014 alignPanel.paintAlignment(true);
6019 * @return alignment panels in this alignment frame
6021 public List<? extends AlignmentViewPanel> getAlignPanels()
6023 return alignPanels == null ? Arrays.asList(alignPanel)
6028 * Open a new alignment window, with the cDNA associated with this (protein)
6029 * alignment, aligned as is the protein.
6031 protected void viewAsCdna_actionPerformed()
6033 // TODO no longer a menu action - refactor as required
6034 final AlignmentI alignment = getViewport().getAlignment();
6035 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6036 if (mappings == null)
6040 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6041 for (SequenceI aaSeq : alignment.getSequences()) {
6042 for (AlignedCodonFrame acf : mappings) {
6043 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6047 * There is a cDNA mapping for this protein sequence - add to new
6048 * alignment. It will share the same dataset sequence as other mapped
6049 * cDNA (no new mappings need to be created).
6051 final Sequence newSeq = new Sequence(dnaSeq);
6052 newSeq.setDatasetSequence(dnaSeq);
6053 cdnaSeqs.add(newSeq);
6057 if (cdnaSeqs.size() == 0)
6059 // show a warning dialog no mapped cDNA
6062 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6064 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6065 AlignFrame.DEFAULT_HEIGHT);
6066 cdna.alignAs(alignment);
6067 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6069 Desktop.addInternalFrame(alignFrame, newtitle,
6070 AlignFrame.DEFAULT_WIDTH,
6071 AlignFrame.DEFAULT_HEIGHT);
6075 * Set visibility of dna/protein complement view (available when shown in a
6081 protected void showComplement_actionPerformed(boolean show)
6083 SplitContainerI sf = getSplitViewContainer();
6085 sf.setComplementVisible(this, show);
6089 public class ExportData
6091 private AlignmentI alignment;
6093 private String[] omitHidden;
6095 private int[] startEnd;
6097 public ExportData(AlignmentI align, String[] ommit, int[] startEnd)
6099 this.alignment = align;
6100 this.omitHidden = ommit;
6101 this.startEnd = startEnd;
6104 public AlignmentI getAlignment()
6109 public void setAlignment(AlignmentI alignment)
6111 this.alignment = alignment;
6114 public String[] getOmitHidden()
6119 public void setOmitHidden(String[] omitHidden)
6121 this.omitHidden = omitHidden;
6124 public int[] getStartEndPostions()
6129 public void setStartEndPostions(int[] startEnd)
6131 this.startEnd = startEnd;
6137 class PrintThread extends Thread
6141 public PrintThread(AlignmentPanel ap)
6146 static PageFormat pf;
6151 PrinterJob printJob = PrinterJob.getPrinterJob();
6155 printJob.setPrintable(ap, pf);
6159 printJob.setPrintable(ap);
6162 if (printJob.printDialog())
6167 } catch (Exception PrintException)
6169 PrintException.printStackTrace();