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.FeatureSettingsControllerI;
82 import jalview.api.SplitContainerI;
83 import jalview.api.ViewStyleI;
84 import jalview.api.analysis.ScoreModelI;
85 import jalview.bin.Cache;
86 import jalview.commands.CommandI;
87 import jalview.commands.EditCommand;
88 import jalview.commands.EditCommand.Action;
89 import jalview.commands.OrderCommand;
90 import jalview.commands.RemoveGapColCommand;
91 import jalview.commands.RemoveGapsCommand;
92 import jalview.commands.SlideSequencesCommand;
93 import jalview.commands.TrimRegionCommand;
94 import jalview.datamodel.AlignedCodonFrame;
95 import jalview.datamodel.Alignment;
96 import jalview.datamodel.AlignmentAnnotation;
97 import jalview.datamodel.AlignmentI;
98 import jalview.datamodel.AlignmentOrder;
99 import jalview.datamodel.AlignmentView;
100 import jalview.datamodel.ColumnSelection;
101 import jalview.datamodel.HiddenSequences;
102 import jalview.datamodel.PDBEntry;
103 import jalview.datamodel.SeqCigar;
104 import jalview.datamodel.Sequence;
105 import jalview.datamodel.SequenceGroup;
106 import jalview.datamodel.SequenceI;
107 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
108 import jalview.io.AlignmentProperties;
109 import jalview.io.AnnotationFile;
110 import jalview.io.BioJsHTMLOutput;
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 FeatureSettingsControllerI getFeatureSettingsUI()
3164 return featureSettings;
3168 public void featureSettings_actionPerformed(ActionEvent e)
3170 if (featureSettings != null)
3172 featureSettings.close();
3173 featureSettings = null;
3175 if (!showSeqFeatures.isSelected())
3177 // make sure features are actually displayed
3178 showSeqFeatures.setSelected(true);
3179 showSeqFeatures_actionPerformed(null);
3181 featureSettings = new FeatureSettings(this);
3185 * Set or clear 'Show Sequence Features'
3191 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3193 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3194 alignPanel.paintAlignment(true);
3195 if (alignPanel.getOverviewPanel() != null)
3197 alignPanel.getOverviewPanel().updateOverviewImage();
3202 * Set or clear 'Show Sequence Features'
3208 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3210 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3212 if (viewport.isShowSequenceFeaturesHeight())
3214 // ensure we're actually displaying features
3215 viewport.setShowSequenceFeatures(true);
3216 showSeqFeatures.setSelected(true);
3218 alignPanel.paintAlignment(true);
3219 if (alignPanel.getOverviewPanel() != null)
3221 alignPanel.getOverviewPanel().updateOverviewImage();
3226 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3227 * the annotations panel as a whole.
3229 * The options to show/hide all annotations should be enabled when the panel
3230 * is shown, and disabled when the panel is hidden.
3235 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3237 final boolean setVisible = annotationPanelMenuItem.isSelected();
3238 viewport.setShowAnnotation(setVisible);
3239 this.showAllSeqAnnotations.setEnabled(setVisible);
3240 this.hideAllSeqAnnotations.setEnabled(setVisible);
3241 this.showAllAlAnnotations.setEnabled(setVisible);
3242 this.hideAllAlAnnotations.setEnabled(setVisible);
3243 alignPanel.updateLayout();
3247 public void alignmentProperties()
3249 JEditorPane editPane = new JEditorPane("text/html", "");
3250 editPane.setEditable(false);
3251 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3253 editPane.setText(MessageManager.formatMessage("label.html_content",
3255 { contents.toString() }));
3256 JInternalFrame frame = new JInternalFrame();
3257 frame.getContentPane().add(new JScrollPane(editPane));
3259 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3260 "label.alignment_properties", new Object[]
3261 { getTitle() }), 500, 400);
3271 public void overviewMenuItem_actionPerformed(ActionEvent e)
3273 if (alignPanel.overviewPanel != null)
3278 JInternalFrame frame = new JInternalFrame();
3279 OverviewPanel overview = new OverviewPanel(alignPanel);
3280 frame.setContentPane(overview);
3281 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3282 "label.overview_params", new Object[]
3283 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3285 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3286 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3289 public void internalFrameClosed(
3290 javax.swing.event.InternalFrameEvent evt)
3292 alignPanel.setOverviewPanel(null);
3296 alignPanel.setOverviewPanel(overview);
3300 public void textColour_actionPerformed(ActionEvent e)
3302 new TextColourChooser().chooseColour(alignPanel, null);
3312 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3324 public void clustalColour_actionPerformed(ActionEvent e)
3326 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3327 viewport.getHiddenRepSequences()));
3337 public void zappoColour_actionPerformed(ActionEvent e)
3339 changeColour(new ZappoColourScheme());
3349 public void taylorColour_actionPerformed(ActionEvent e)
3351 changeColour(new TaylorColourScheme());
3361 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3363 changeColour(new HydrophobicColourScheme());
3373 public void helixColour_actionPerformed(ActionEvent e)
3375 changeColour(new HelixColourScheme());
3385 public void strandColour_actionPerformed(ActionEvent e)
3387 changeColour(new StrandColourScheme());
3397 public void turnColour_actionPerformed(ActionEvent e)
3399 changeColour(new TurnColourScheme());
3409 public void buriedColour_actionPerformed(ActionEvent e)
3411 changeColour(new BuriedColourScheme());
3421 public void nucleotideColour_actionPerformed(ActionEvent e)
3423 changeColour(new NucleotideColourScheme());
3427 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3429 changeColour(new PurinePyrimidineColourScheme());
3433 * public void covariationColour_actionPerformed(ActionEvent e) {
3435 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3439 public void annotationColour_actionPerformed(ActionEvent e)
3441 new AnnotationColourChooser(viewport, alignPanel);
3445 public void annotationColumn_actionPerformed(ActionEvent e)
3447 new AnnotationColumnChooser(viewport, alignPanel);
3451 public void rnahelicesColour_actionPerformed(ActionEvent e)
3453 new RNAHelicesColourChooser(viewport, alignPanel);
3463 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3465 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3474 public void changeColour(ColourSchemeI cs)
3476 // TODO: compare with applet and pull up to model method
3481 if (viewport.getAbovePIDThreshold())
3483 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3485 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3489 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3492 if (viewport.getConservationSelected())
3495 Alignment al = (Alignment) viewport.getAlignment();
3496 Conservation c = new Conservation("All",
3497 ResidueProperties.propHash, 3, al.getSequences(), 0,
3501 c.verdict(false, viewport.getConsPercGaps());
3503 cs.setConservation(c);
3505 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3510 cs.setConservation(null);
3513 cs.setConsensus(viewport.getSequenceConsensusHash());
3516 viewport.setGlobalColourScheme(cs);
3518 if (viewport.getColourAppliesToAllGroups())
3521 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3529 if (cs instanceof ClustalxColourScheme)
3531 sg.cs = new ClustalxColourScheme(sg,
3532 viewport.getHiddenRepSequences());
3534 else if (cs instanceof UserColourScheme)
3536 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3542 sg.cs = cs.getClass().newInstance();
3543 } catch (Exception ex)
3548 if (viewport.getAbovePIDThreshold()
3549 || cs instanceof PIDColourScheme
3550 || cs instanceof Blosum62ColourScheme)
3552 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3554 sg.cs.setConsensus(AAFrequency.calculate(
3555 sg.getSequences(viewport.getHiddenRepSequences()),
3556 sg.getStartRes(), sg.getEndRes() + 1));
3560 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3563 if (viewport.getConservationSelected())
3565 Conservation c = new Conservation("Group",
3566 ResidueProperties.propHash, 3, sg.getSequences(viewport
3567 .getHiddenRepSequences()), sg.getStartRes(),
3568 sg.getEndRes() + 1);
3570 c.verdict(false, viewport.getConsPercGaps());
3571 sg.cs.setConservation(c);
3575 sg.cs.setConservation(null);
3580 if (alignPanel.getOverviewPanel() != null)
3582 alignPanel.getOverviewPanel().updateOverviewImage();
3585 alignPanel.paintAlignment(true);
3595 protected void modifyPID_actionPerformed(ActionEvent e)
3597 if (viewport.getAbovePIDThreshold()
3598 && viewport.getGlobalColourScheme() != null)
3600 SliderPanel.setPIDSliderSource(alignPanel,
3601 viewport.getGlobalColourScheme(), "Background");
3602 SliderPanel.showPIDSlider();
3613 protected void modifyConservation_actionPerformed(ActionEvent e)
3615 if (viewport.getConservationSelected()
3616 && viewport.getGlobalColourScheme() != null)
3618 SliderPanel.setConservationSlider(alignPanel,
3619 viewport.getGlobalColourScheme(), "Background");
3620 SliderPanel.showConservationSlider();
3631 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3633 viewport.setConservationSelected(conservationMenuItem.isSelected());
3635 viewport.setAbovePIDThreshold(false);
3636 abovePIDThreshold.setSelected(false);
3638 changeColour(viewport.getGlobalColourScheme());
3640 modifyConservation_actionPerformed(null);
3650 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3652 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3654 conservationMenuItem.setSelected(false);
3655 viewport.setConservationSelected(false);
3657 changeColour(viewport.getGlobalColourScheme());
3659 modifyPID_actionPerformed(null);
3669 public void userDefinedColour_actionPerformed(ActionEvent e)
3671 if (e.getActionCommand().equals(
3672 MessageManager.getString("action.user_defined")))
3674 new UserDefinedColours(alignPanel, null);
3678 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3679 .getUserColourSchemes().get(e.getActionCommand());
3685 public void updateUserColourMenu()
3688 Component[] menuItems = colourMenu.getMenuComponents();
3689 int iSize = menuItems.length;
3690 for (int i = 0; i < iSize; i++)
3692 if (menuItems[i].getName() != null
3693 && menuItems[i].getName().equals("USER_DEFINED"))
3695 colourMenu.remove(menuItems[i]);
3699 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3701 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3702 .getUserColourSchemes().keys();
3704 while (userColours.hasMoreElements())
3706 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3707 userColours.nextElement().toString());
3708 radioItem.setName("USER_DEFINED");
3709 radioItem.addMouseListener(new MouseAdapter()
3712 public void mousePressed(MouseEvent evt)
3714 if (evt.isControlDown()
3715 || SwingUtilities.isRightMouseButton(evt))
3717 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3719 int option = JOptionPane.showInternalConfirmDialog(
3720 jalview.gui.Desktop.desktop,
3722 .getString("label.remove_from_default_list"),
3724 .getString("label.remove_user_defined_colour"),
3725 JOptionPane.YES_NO_OPTION);
3726 if (option == JOptionPane.YES_OPTION)
3728 jalview.gui.UserDefinedColours
3729 .removeColourFromDefaults(radioItem.getText());
3730 colourMenu.remove(radioItem);
3734 radioItem.addActionListener(new ActionListener()
3737 public void actionPerformed(ActionEvent evt)
3739 userDefinedColour_actionPerformed(evt);
3746 radioItem.addActionListener(new ActionListener()
3749 public void actionPerformed(ActionEvent evt)
3751 userDefinedColour_actionPerformed(evt);
3755 colourMenu.insert(radioItem, 15);
3756 colours.add(radioItem);
3768 public void PIDColour_actionPerformed(ActionEvent e)
3770 changeColour(new PIDColourScheme());
3780 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3782 changeColour(new Blosum62ColourScheme());
3792 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3794 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3795 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3796 .getAlignment().getSequenceAt(0), null);
3797 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3798 viewport.getAlignment()));
3799 alignPanel.paintAlignment(true);
3809 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3811 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3812 AlignmentSorter.sortByID(viewport.getAlignment());
3813 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3814 viewport.getAlignment()));
3815 alignPanel.paintAlignment(true);
3825 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3827 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3828 AlignmentSorter.sortByLength(viewport.getAlignment());
3829 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3830 viewport.getAlignment()));
3831 alignPanel.paintAlignment(true);
3841 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3843 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3844 AlignmentSorter.sortByGroup(viewport.getAlignment());
3845 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3846 viewport.getAlignment()));
3848 alignPanel.paintAlignment(true);
3858 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3860 new RedundancyPanel(alignPanel, this);
3870 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3872 if ((viewport.getSelectionGroup() == null)
3873 || (viewport.getSelectionGroup().getSize() < 2))
3875 JOptionPane.showInternalMessageDialog(this, MessageManager
3876 .getString("label.you_must_select_least_two_sequences"),
3877 MessageManager.getString("label.invalid_selection"),
3878 JOptionPane.WARNING_MESSAGE);
3882 JInternalFrame frame = new JInternalFrame();
3883 frame.setContentPane(new PairwiseAlignPanel(viewport));
3884 Desktop.addInternalFrame(frame,
3885 MessageManager.getString("action.pairwise_alignment"), 600,
3897 public void PCAMenuItem_actionPerformed(ActionEvent e)
3899 if (((viewport.getSelectionGroup() != null)
3900 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3901 .getSelectionGroup().getSize() > 0))
3902 || (viewport.getAlignment().getHeight() < 4))
3905 .showInternalMessageDialog(
3908 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3910 .getString("label.sequence_selection_insufficient"),
3911 JOptionPane.WARNING_MESSAGE);
3916 new PCAPanel(alignPanel);
3920 public void autoCalculate_actionPerformed(ActionEvent e)
3922 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3923 if (viewport.autoCalculateConsensus)
3925 viewport.firePropertyChange("alignment", null, viewport
3926 .getAlignment().getSequences());
3931 public void sortByTreeOption_actionPerformed(ActionEvent e)
3933 viewport.sortByTree = sortByTree.isSelected();
3937 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3939 viewport.followSelection = listenToViewSelections.isSelected();
3949 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3951 newTreePanel("AV", "PID", "Average distance tree using PID");
3961 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3963 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3973 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3975 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3985 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3987 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
4000 void newTreePanel(String type, String pwType, String title)
4004 if (viewport.getSelectionGroup() != null
4005 && viewport.getSelectionGroup().getSize() > 0)
4007 if (viewport.getSelectionGroup().getSize() < 3)
4013 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4015 .getString("label.not_enough_sequences"),
4016 JOptionPane.WARNING_MESSAGE);
4020 SequenceGroup sg = viewport.getSelectionGroup();
4022 /* Decide if the selection is a column region */
4023 for (SequenceI _s : sg.getSequences())
4025 if (_s.getLength() < sg.getEndRes())
4031 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4033 .getString("label.sequences_selection_not_aligned"),
4034 JOptionPane.WARNING_MESSAGE);
4040 title = title + " on region";
4041 tp = new TreePanel(alignPanel, type, pwType);
4045 // are the visible sequences aligned?
4046 if (!viewport.getAlignment().isAligned(false))
4052 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4054 .getString("label.sequences_not_aligned"),
4055 JOptionPane.WARNING_MESSAGE);
4060 if (viewport.getAlignment().getHeight() < 2)
4065 tp = new TreePanel(alignPanel, type, pwType);
4070 if (viewport.viewName != null)
4072 title += viewport.viewName + " of ";
4075 title += this.title;
4077 Desktop.addInternalFrame(tp, title, 600, 500);
4088 public void addSortByOrderMenuItem(String title,
4089 final AlignmentOrder order)
4091 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4093 item.addActionListener(new java.awt.event.ActionListener()
4096 public void actionPerformed(ActionEvent e)
4098 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4100 // TODO: JBPNote - have to map order entries to curent SequenceI
4102 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4104 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4107 alignPanel.paintAlignment(true);
4113 * Add a new sort by annotation score menu item
4116 * the menu to add the option to
4118 * the label used to retrieve scores for each sequence on the
4121 public void addSortByAnnotScoreMenuItem(JMenu sort,
4122 final String scoreLabel)
4124 final JMenuItem item = new JMenuItem(scoreLabel);
4126 item.addActionListener(new java.awt.event.ActionListener()
4129 public void actionPerformed(ActionEvent e)
4131 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4132 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4133 viewport.getAlignment());// ,viewport.getSelectionGroup());
4134 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4135 viewport.getAlignment()));
4136 alignPanel.paintAlignment(true);
4142 * last hash for alignment's annotation array - used to minimise cost of
4145 protected int _annotationScoreVectorHash;
4148 * search the alignment and rebuild the sort by annotation score submenu the
4149 * last alignment annotation vector hash is stored to minimize cost of
4150 * rebuilding in subsequence calls.
4154 public void buildSortByAnnotationScoresMenu()
4156 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4161 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4163 sortByAnnotScore.removeAll();
4164 // almost certainly a quicker way to do this - but we keep it simple
4165 Hashtable scoreSorts = new Hashtable();
4166 AlignmentAnnotation aann[];
4167 for (SequenceI sqa : viewport.getAlignment().getSequences())
4169 aann = sqa.getAnnotation();
4170 for (int i = 0; aann != null && i < aann.length; i++)
4172 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4174 scoreSorts.put(aann[i].label, aann[i].label);
4178 Enumeration labels = scoreSorts.keys();
4179 while (labels.hasMoreElements())
4181 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4182 (String) labels.nextElement());
4184 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4187 _annotationScoreVectorHash = viewport.getAlignment()
4188 .getAlignmentAnnotation().hashCode();
4193 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4194 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4195 * call. Listeners are added to remove the menu item when the treePanel is
4196 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4200 * Displayed tree window.
4202 * SortBy menu item title.
4205 public void buildTreeMenu()
4207 calculateTree.removeAll();
4208 // build the calculate menu
4210 for (final String type : new String[]
4213 String treecalcnm = MessageManager.getString("label.tree_calc_"
4214 + type.toLowerCase());
4215 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4217 JMenuItem tm = new JMenuItem();
4218 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4219 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4221 String smn = MessageManager.getStringOrReturn(
4222 "label.score_model_", sm.getName());
4223 final String title = MessageManager.formatMessage(
4224 "label.treecalc_title", treecalcnm, smn);
4225 tm.setText(title);//
4226 tm.addActionListener(new java.awt.event.ActionListener()
4229 public void actionPerformed(ActionEvent e)
4231 newTreePanel(type, pwtype, title);
4234 calculateTree.add(tm);
4239 sortByTreeMenu.removeAll();
4241 List<Component> comps = PaintRefresher.components.get(viewport
4242 .getSequenceSetId());
4243 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4244 for (Component comp : comps)
4246 if (comp instanceof TreePanel)
4248 treePanels.add((TreePanel) comp);
4252 if (treePanels.size() < 1)
4254 sortByTreeMenu.setVisible(false);
4258 sortByTreeMenu.setVisible(true);
4260 for (final TreePanel tp : treePanels)
4262 final JMenuItem item = new JMenuItem(tp.getTitle());
4263 item.addActionListener(new java.awt.event.ActionListener()
4266 public void actionPerformed(ActionEvent e)
4268 tp.sortByTree_actionPerformed();
4269 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4274 sortByTreeMenu.add(item);
4278 public boolean sortBy(AlignmentOrder alorder, String undoname)
4280 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4281 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4282 if (undoname != null)
4284 addHistoryItem(new OrderCommand(undoname, oldOrder,
4285 viewport.getAlignment()));
4287 alignPanel.paintAlignment(true);
4292 * Work out whether the whole set of sequences or just the selected set will
4293 * be submitted for multiple alignment.
4296 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4298 // Now, check we have enough sequences
4299 AlignmentView msa = null;
4301 if ((viewport.getSelectionGroup() != null)
4302 && (viewport.getSelectionGroup().getSize() > 1))
4304 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4305 // some common interface!
4307 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4308 * SequenceI[sz = seqs.getSize(false)];
4310 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4311 * seqs.getSequenceAt(i); }
4313 msa = viewport.getAlignmentView(true);
4315 else if (viewport.getSelectionGroup() != null
4316 && viewport.getSelectionGroup().getSize() == 1)
4318 int option = JOptionPane.showConfirmDialog(this,
4319 MessageManager.getString("warn.oneseq_msainput_selection"),
4320 MessageManager.getString("label.invalid_selection"),
4321 JOptionPane.OK_CANCEL_OPTION);
4322 if (option == JOptionPane.OK_OPTION)
4324 msa = viewport.getAlignmentView(false);
4329 msa = viewport.getAlignmentView(false);
4335 * Decides what is submitted to a secondary structure prediction service: the
4336 * first sequence in the alignment, or in the current selection, or, if the
4337 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4338 * region or the whole alignment. (where the first sequence in the set is the
4339 * one that the prediction will be for).
4341 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4343 AlignmentView seqs = null;
4345 if ((viewport.getSelectionGroup() != null)
4346 && (viewport.getSelectionGroup().getSize() > 0))
4348 seqs = viewport.getAlignmentView(true);
4352 seqs = viewport.getAlignmentView(false);
4354 // limit sequences - JBPNote in future - could spawn multiple prediction
4356 // TODO: viewport.getAlignment().isAligned is a global state - the local
4357 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4358 if (!viewport.getAlignment().isAligned(false))
4360 seqs.setSequences(new SeqCigar[]
4361 { seqs.getSequences()[0] });
4362 // TODO: if seqs.getSequences().length>1 then should really have warned
4376 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4378 // Pick the tree file
4379 JalviewFileChooser chooser = new JalviewFileChooser(
4380 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4381 chooser.setFileView(new JalviewFileView());
4382 chooser.setDialogTitle(MessageManager
4383 .getString("label.select_newick_like_tree_file"));
4384 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4386 int value = chooser.showOpenDialog(null);
4388 if (value == JalviewFileChooser.APPROVE_OPTION)
4390 String choice = chooser.getSelectedFile().getPath();
4391 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4392 jalview.io.NewickFile fin = null;
4395 fin = new jalview.io.NewickFile(choice, "File");
4396 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4397 } catch (Exception ex)
4404 .getString("label.problem_reading_tree_file"),
4405 JOptionPane.WARNING_MESSAGE);
4406 ex.printStackTrace();
4408 if (fin != null && fin.hasWarningMessage())
4410 JOptionPane.showMessageDialog(Desktop.desktop, fin
4411 .getWarningMessage(), MessageManager
4412 .getString("label.possible_problem_with_tree_file"),
4413 JOptionPane.WARNING_MESSAGE);
4419 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4421 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4424 public TreePanel ShowNewickTree(NewickFile nf, String title)
4426 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4429 public TreePanel ShowNewickTree(NewickFile nf, String title,
4430 AlignmentView input)
4432 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4435 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4436 int h, int x, int y)
4438 return ShowNewickTree(nf, title, null, w, h, x, y);
4442 * Add a treeviewer for the tree extracted from a newick file object to the
4443 * current alignment view
4450 * Associated alignment input data (or null)
4459 * @return TreePanel handle
4461 public TreePanel ShowNewickTree(NewickFile nf, String title,
4462 AlignmentView input, int w, int h, int x, int y)
4464 TreePanel tp = null;
4470 if (nf.getTree() != null)
4472 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4478 tp.setLocation(x, y);
4481 Desktop.addInternalFrame(tp, title, w, h);
4483 } catch (Exception ex)
4485 ex.printStackTrace();
4491 private boolean buildingMenu = false;
4494 * Generates menu items and listener event actions for web service clients
4497 public void BuildWebServiceMenu()
4499 while (buildingMenu)
4503 System.err.println("Waiting for building menu to finish.");
4505 } catch (Exception e)
4509 final AlignFrame me = this;
4510 buildingMenu = true;
4511 new Thread(new Runnable()
4516 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4519 System.err.println("Building ws menu again "
4520 + Thread.currentThread());
4521 // TODO: add support for context dependent disabling of services based
4523 // alignment and current selection
4524 // TODO: add additional serviceHandle parameter to specify abstract
4526 // class independently of AbstractName
4527 // TODO: add in rediscovery GUI function to restart discoverer
4528 // TODO: group services by location as well as function and/or
4530 // object broker mechanism.
4531 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4532 final IProgressIndicator af = me;
4533 final JMenu msawsmenu = new JMenu("Alignment");
4534 final JMenu secstrmenu = new JMenu(
4535 "Secondary Structure Prediction");
4536 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4537 final JMenu analymenu = new JMenu("Analysis");
4538 final JMenu dismenu = new JMenu("Protein Disorder");
4539 // final JMenu msawsmenu = new
4540 // JMenu(MessageManager.getString("label.alignment"));
4541 // final JMenu secstrmenu = new
4542 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4543 // final JMenu seqsrchmenu = new
4544 // JMenu(MessageManager.getString("label.sequence_database_search"));
4545 // final JMenu analymenu = new
4546 // JMenu(MessageManager.getString("label.analysis"));
4547 // final JMenu dismenu = new
4548 // JMenu(MessageManager.getString("label.protein_disorder"));
4549 // JAL-940 - only show secondary structure prediction services from
4550 // the legacy server
4551 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4553 Discoverer.services != null && (Discoverer.services.size() > 0))
4555 // TODO: refactor to allow list of AbstractName/Handler bindings to
4557 // stored or retrieved from elsewhere
4558 // No MSAWS used any more:
4559 // Vector msaws = null; // (Vector)
4560 // Discoverer.services.get("MsaWS");
4561 Vector secstrpr = (Vector) Discoverer.services
4563 if (secstrpr != null)
4565 // Add any secondary structure prediction services
4566 for (int i = 0, j = secstrpr.size(); i < j; i++)
4568 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4570 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4571 .getServiceClient(sh);
4572 int p = secstrmenu.getItemCount();
4573 impl.attachWSMenuEntry(secstrmenu, me);
4574 int q = secstrmenu.getItemCount();
4575 for (int litm = p; litm < q; litm++)
4577 legacyItems.add(secstrmenu.getItem(litm));
4583 // Add all submenus in the order they should appear on the web
4585 wsmenu.add(msawsmenu);
4586 wsmenu.add(secstrmenu);
4587 wsmenu.add(dismenu);
4588 wsmenu.add(analymenu);
4589 // No search services yet
4590 // wsmenu.add(seqsrchmenu);
4592 javax.swing.SwingUtilities.invokeLater(new Runnable()
4599 webService.removeAll();
4600 // first, add discovered services onto the webservices menu
4601 if (wsmenu.size() > 0)
4603 for (int i = 0, j = wsmenu.size(); i < j; i++)
4605 webService.add(wsmenu.get(i));
4610 webService.add(me.webServiceNoServices);
4612 // TODO: move into separate menu builder class.
4613 boolean new_sspred = false;
4614 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4616 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4617 if (jws2servs != null)
4619 if (jws2servs.hasServices())
4621 jws2servs.attachWSMenuEntry(webService, me);
4622 for (Jws2Instance sv : jws2servs.getServices())
4624 if (sv.description.toLowerCase().contains("jpred"))
4626 for (JMenuItem jmi : legacyItems)
4628 jmi.setVisible(false);
4634 if (jws2servs.isRunning())
4636 JMenuItem tm = new JMenuItem(
4637 "Still discovering JABA Services");
4638 tm.setEnabled(false);
4643 build_urlServiceMenu(me.webService);
4644 build_fetchdbmenu(webService);
4645 for (JMenu item : wsmenu)
4647 if (item.getItemCount() == 0)
4649 item.setEnabled(false);
4653 item.setEnabled(true);
4656 } catch (Exception e)
4659 .debug("Exception during web service menu building process.",
4664 } catch (Exception e)
4667 buildingMenu = false;
4674 * construct any groupURL type service menu entries.
4678 private void build_urlServiceMenu(JMenu webService)
4680 // TODO: remove this code when 2.7 is released
4681 // DEBUG - alignmentView
4683 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4684 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4686 * @Override public void actionPerformed(ActionEvent e) {
4687 * jalview.datamodel.AlignmentView
4688 * .testSelectionViews(af.viewport.getAlignment(),
4689 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4691 * }); webService.add(testAlView);
4693 // TODO: refactor to RestClient discoverer and merge menu entries for
4694 // rest-style services with other types of analysis/calculation service
4695 // SHmmr test client - still being implemented.
4696 // DEBUG - alignmentView
4698 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4701 client.attachWSMenuEntry(
4702 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4708 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4709 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4710 * getProperty("LAST_DIRECTORY"));
4712 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4713 * to Vamsas file"); chooser.setToolTipText("Export");
4715 * int value = chooser.showSaveDialog(this);
4717 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4718 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4719 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4720 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4723 * prototype of an automatically enabled/disabled analysis function
4726 protected void setShowProductsEnabled()
4728 SequenceI[] selection = viewport.getSequenceSelection();
4729 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4730 viewport.getAlignment().getDataset()))
4732 showProducts.setEnabled(true);
4737 showProducts.setEnabled(false);
4742 * search selection for sequence xRef products and build the show products
4747 * @return true if showProducts menu should be enabled.
4749 public boolean canShowProducts(SequenceI[] selection,
4750 boolean isRegionSelection, Alignment dataset)
4752 boolean showp = false;
4755 showProducts.removeAll();
4756 final boolean dna = viewport.getAlignment().isNucleotide();
4757 final Alignment ds = dataset;
4758 String[] ptypes = (selection == null || selection.length == 0) ? null
4759 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4761 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4762 // selection, dataset, true);
4763 final SequenceI[] sel = selection;
4764 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4767 final boolean isRegSel = isRegionSelection;
4768 final AlignFrame af = this;
4769 final String source = ptypes[t];
4770 JMenuItem xtype = new JMenuItem(ptypes[t]);
4771 xtype.addActionListener(new ActionListener()
4775 public void actionPerformed(ActionEvent e)
4777 // TODO: new thread for this call with vis-delay
4778 af.showProductsFor(af.viewport.getSequenceSelection(),
4779 isRegSel, dna, source);
4783 showProducts.add(xtype);
4785 showProducts.setVisible(showp);
4786 showProducts.setEnabled(showp);
4787 } catch (Exception e)
4789 jalview.bin.Cache.log
4790 .warn("canTranslate threw an exception - please report to help@jalview.org",
4797 protected void showProductsFor(final SequenceI[] sel,
4798 final boolean isRegSel, final boolean dna, final String source)
4800 Runnable foo = new Runnable()
4806 final long sttime = System.currentTimeMillis();
4807 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4808 "status.searching_for_sequences_from", new Object[]
4809 { source }), sttime);
4812 // update our local dataset reference
4813 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4815 Alignment prods = CrossRef
4816 .findXrefSequences(sel, dna, source, ds);
4819 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4820 for (int s = 0; s < sprods.length; s++)
4822 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4823 if (ds.getSequences() == null
4824 || !ds.getSequences().contains(
4825 sprods[s].getDatasetSequence()))
4827 ds.addSequence(sprods[s].getDatasetSequence());
4829 sprods[s].updatePDBIds();
4831 Alignment al = new Alignment(sprods);
4835 * Copy dna-to-protein mappings to new alignment
4837 // TODO 1: no mappings are set up for EMBL product
4838 // TODO 2: if they were, should add them to protein alignment, not
4840 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4841 for (AlignedCodonFrame acf : cf)
4843 al.addCodonFrame(acf);
4845 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4847 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4848 + " for " + ((isRegSel) ? "selected region of " : "")
4850 naf.setTitle(newtitle);
4852 // temporary flag until SplitFrame is released
4853 boolean asSplitFrame = Cache.getDefault(
4854 Preferences.ENABLE_SPLIT_FRAME, false);
4858 * Make a copy of this alignment (sharing the same dataset
4859 * sequences). If we are DNA, drop introns and update mappings
4861 AlignmentI copyAlignment = null;
4862 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4863 .getSequenceSelection();
4866 copyAlignment = AlignmentUtils.makeExonAlignment(
4867 sequenceSelection, cf);
4868 al.getCodonFrames().clear();
4869 al.getCodonFrames().addAll(cf);
4870 final StructureSelectionManager ssm = StructureSelectionManager
4871 .getStructureSelectionManager(Desktop.instance);
4872 ssm.addMappings(cf);
4876 copyAlignment = new Alignment(new Alignment(
4877 sequenceSelection));
4879 AlignFrame copyThis = new AlignFrame(copyAlignment,
4880 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4881 copyThis.setTitle(AlignFrame.this.getTitle());
4882 // SplitFrame with dna above, protein below
4883 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4884 dna ? naf : copyThis);
4885 naf.setVisible(true);
4886 copyThis.setVisible(true);
4887 String linkedTitle = MessageManager
4888 .getString("label.linked_view_title");
4889 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4893 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4899 System.err.println("No Sequences generated for xRef type "
4902 } catch (Exception e)
4904 jalview.bin.Cache.log.error(
4905 "Exception when finding crossreferences", e);
4906 } catch (OutOfMemoryError e)
4908 new OOMWarning("whilst fetching crossreferences", e);
4911 jalview.bin.Cache.log.error("Error when finding crossreferences",
4914 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4915 "status.finished_searching_for_sequences_from",
4922 Thread frunner = new Thread(foo);
4926 public boolean canShowTranslationProducts(SequenceI[] selection,
4927 AlignmentI alignment)
4932 return (jalview.analysis.Dna.canTranslate(selection,
4933 viewport.getViewAsVisibleContigs(true)));
4934 } catch (Exception e)
4936 jalview.bin.Cache.log
4937 .warn("canTranslate threw an exception - please report to help@jalview.org",
4944 * Construct and display a new frame containing the translation of this
4945 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4948 public void showTranslation_actionPerformed(ActionEvent e)
4950 AlignmentI al = null;
4953 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4955 al = dna.translateCdna();
4956 } catch (Exception ex)
4958 jalview.bin.Cache.log.error(
4959 "Exception during translation. Please report this !", ex);
4960 final String msg = MessageManager
4961 .getString("label.error_when_translating_sequences_submit_bug_report");
4962 final String title = MessageManager
4963 .getString("label.implementation_error")
4964 + MessageManager.getString("translation_failed");
4965 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4966 JOptionPane.ERROR_MESSAGE);
4969 if (al == null || al.getHeight() == 0)
4971 final String msg = MessageManager
4972 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4973 final String title = MessageManager
4974 .getString("label.translation_failed");
4975 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4976 JOptionPane.WARNING_MESSAGE);
4980 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4981 af.setFileFormat(this.currentFileFormat);
4982 final String newTitle = MessageManager.formatMessage(
4983 "label.translation_of_params", new Object[]
4984 { this.getTitle() });
4985 af.setTitle(newTitle);
4986 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
4988 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4989 viewport.openSplitFrame(af, new Alignment(seqs),
4990 al.getCodonFrames());
4994 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
5001 * Set the file format
5005 public void setFileFormat(String fileFormat)
5007 this.currentFileFormat = fileFormat;
5011 * Try to load a features file onto the alignment.
5014 * contents or path to retrieve file
5016 * access mode of file (see jalview.io.AlignFile)
5017 * @return true if features file was parsed correctly.
5019 public boolean parseFeaturesFile(String file, String type)
5021 return avc.parseFeaturesFile(file, type,
5022 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5027 public void refreshFeatureUI(boolean enableIfNecessary)
5029 // note - currently this is only still here rather than in the controller
5030 // because of the featureSettings hard reference that is yet to be
5032 if (enableIfNecessary)
5034 viewport.setShowSequenceFeatures(true);
5035 showSeqFeatures.setSelected(true);
5041 public void dragEnter(DropTargetDragEvent evt)
5046 public void dragExit(DropTargetEvent evt)
5051 public void dragOver(DropTargetDragEvent evt)
5056 public void dropActionChanged(DropTargetDragEvent evt)
5061 public void drop(DropTargetDropEvent evt)
5063 Transferable t = evt.getTransferable();
5064 java.util.List files = null;
5068 DataFlavor uriListFlavor = new DataFlavor(
5069 "text/uri-list;class=java.lang.String");
5070 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5072 // Works on Windows and MacOSX
5073 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5074 files = (java.util.List) t
5075 .getTransferData(DataFlavor.javaFileListFlavor);
5077 else if (t.isDataFlavorSupported(uriListFlavor))
5079 // This is used by Unix drag system
5080 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5081 String data = (String) t.getTransferData(uriListFlavor);
5082 files = new java.util.ArrayList(1);
5083 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5084 data, "\r\n"); st.hasMoreTokens();)
5086 String s = st.nextToken();
5087 if (s.startsWith("#"))
5089 // the line is a comment (as per the RFC 2483)
5093 java.net.URI uri = new java.net.URI(s);
5094 // check to see if we can handle this kind of URI
5095 if (uri.getScheme().toLowerCase().startsWith("http"))
5097 files.add(uri.toString());
5101 // otherwise preserve old behaviour: catch all for file objects
5102 java.io.File file = new java.io.File(uri);
5103 files.add(file.toString());
5107 } catch (Exception e)
5109 e.printStackTrace();
5115 // check to see if any of these files have names matching sequences in
5117 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5118 .getAlignment().getSequencesArray());
5120 * Object[] { String,SequenceI}
5122 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5123 ArrayList<String> filesnotmatched = new ArrayList<String>();
5124 for (int i = 0; i < files.size(); i++)
5126 String file = files.get(i).toString();
5128 String protocol = FormatAdapter.checkProtocol(file);
5129 if (protocol == jalview.io.FormatAdapter.FILE)
5131 File fl = new File(file);
5132 pdbfn = fl.getName();
5134 else if (protocol == jalview.io.FormatAdapter.URL)
5136 URL url = new URL(file);
5137 pdbfn = url.getFile();
5139 if (pdbfn.length() > 0)
5141 // attempt to find a match in the alignment
5142 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5143 int l = 0, c = pdbfn.indexOf(".");
5144 while (mtch == null && c != -1)
5149 } while ((c = pdbfn.indexOf(".", l)) > l);
5152 pdbfn = pdbfn.substring(0, l);
5154 mtch = idm.findAllIdMatches(pdbfn);
5161 type = new IdentifyFile().Identify(file, protocol);
5162 } catch (Exception ex)
5168 if (type.equalsIgnoreCase("PDB"))
5170 filesmatched.add(new Object[]
5171 { file, protocol, mtch });
5176 // File wasn't named like one of the sequences or wasn't a PDB file.
5177 filesnotmatched.add(file);
5181 if (filesmatched.size() > 0)
5183 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5189 "label.automatically_associate_pdb_files_with_sequences_same_name",
5196 .getString("label.automatically_associate_pdb_files_by_name"),
5197 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5200 for (Object[] fm : filesmatched)
5202 // try and associate
5203 // TODO: may want to set a standard ID naming formalism for
5204 // associating PDB files which have no IDs.
5205 for (SequenceI toassoc : (SequenceI[]) fm[2])
5207 PDBEntry pe = new AssociatePdbFileWithSeq()
5208 .associatePdbWithSeq((String) fm[0],
5209 (String) fm[1], toassoc, false,
5213 System.err.println("Associated file : "
5214 + ((String) fm[0]) + " with "
5215 + toassoc.getDisplayId(true));
5219 alignPanel.paintAlignment(true);
5223 if (filesnotmatched.size() > 0)
5226 && (Cache.getDefault(
5227 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5230 "<html>"+MessageManager
5232 "label.ignore_unmatched_dropped_files_info",
5237 .toString() })+"</html>",
5239 .getString("label.ignore_unmatched_dropped_files"),
5240 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5244 for (String fn : filesnotmatched)
5246 loadJalviewDataFile(fn, null, null, null);
5250 } catch (Exception ex)
5252 ex.printStackTrace();
5258 * Attempt to load a "dropped" file or URL string: First by testing whether
5259 * it's and Annotation file, then a JNet file, and finally a features file. If
5260 * all are false then the user may have dropped an alignment file onto this
5264 * either a filename or a URL string.
5266 public void loadJalviewDataFile(String file, String protocol,
5267 String format, SequenceI assocSeq)
5271 if (protocol == null)
5273 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5275 // if the file isn't identified, or not positively identified as some
5276 // other filetype (PFAM is default unidentified alignment file type) then
5277 // try to parse as annotation.
5278 boolean isAnnotation = (format == null || format
5279 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5280 .annotateAlignmentView(viewport, file, protocol)
5285 // first see if its a T-COFFEE score file
5286 TCoffeeScoreFile tcf = null;
5289 tcf = new TCoffeeScoreFile(file, protocol);
5292 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5294 tcoffeeColour.setEnabled(true);
5295 tcoffeeColour.setSelected(true);
5296 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5297 isAnnotation = true;
5299 .setText(MessageManager
5300 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5304 // some problem - if no warning its probable that the ID matching
5305 // process didn't work
5309 tcf.getWarningMessage() == null ? MessageManager
5310 .getString("label.check_file_matches_sequence_ids_alignment")
5311 : tcf.getWarningMessage(),
5313 .getString("label.problem_reading_tcoffee_score_file"),
5314 JOptionPane.WARNING_MESSAGE);
5321 } catch (Exception x)
5324 .debug("Exception when processing data source as T-COFFEE score file",
5330 // try to see if its a JNet 'concise' style annotation file *before*
5332 // try to parse it as a features file
5335 format = new IdentifyFile().Identify(file, protocol);
5337 if (format.equalsIgnoreCase("JnetFile"))
5339 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5341 new JnetAnnotationMaker();
5342 JnetAnnotationMaker.add_annotation(predictions,
5343 viewport.getAlignment(), 0, false);
5344 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5345 viewport.getAlignment().setSeqrep(repseq);
5346 ColumnSelection cs = new ColumnSelection();
5347 cs.hideInsertionsFor(repseq);
5348 viewport.setColumnSelection(cs);
5349 isAnnotation = true;
5354 * if (format.equalsIgnoreCase("PDB")) {
5356 * String pdbfn = ""; // try to match up filename with sequence id
5357 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5358 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5359 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5360 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5361 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5362 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5363 * // attempt to find a match in the alignment SequenceI mtch =
5364 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5365 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5366 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5367 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5368 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5369 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5370 * { System.err.println("Associated file : " + file + " with " +
5371 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5372 * TODO: maybe need to load as normal otherwise return; } }
5374 // try to parse it as a features file
5375 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5376 // if it wasn't a features file then we just treat it as a general
5377 // alignment file to load into the current view.
5380 new FileLoader().LoadFile(viewport, file, protocol, format);
5384 alignPanel.paintAlignment(true);
5392 alignPanel.adjustAnnotationHeight();
5393 viewport.updateSequenceIdColours();
5394 buildSortByAnnotationScoresMenu();
5395 alignPanel.paintAlignment(true);
5397 } catch (Exception ex)
5399 ex.printStackTrace();
5400 } catch (OutOfMemoryError oom)
5405 } catch (Exception x)
5411 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5412 : "using " + protocol + " from " + file)
5414 + (format != null ? "(parsing as '" + format
5415 + "' file)" : ""), oom, Desktop.desktop);
5420 * Method invoked by the ChangeListener on the tabbed pane, in other words
5421 * when a different tabbed pane is selected by the user or programmatically.
5424 public void tabSelectionChanged(int index)
5428 alignPanel = alignPanels.get(index);
5429 viewport = alignPanel.av;
5430 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5431 setMenusFromViewport(viewport);
5435 * If there is a frame linked to this one in a SplitPane, switch it to the
5436 * same view tab index. No infinite recursion of calls should happen, since
5437 * tabSelectionChanged() should not get invoked on setting the selected
5438 * index to an unchanged value. Guard against setting an invalid index
5439 * before the new view peer tab has been created.
5441 final AlignViewportI peer = viewport.getCodingComplement();
5444 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5445 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5447 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5453 * On right mouse click on view tab, prompt for and set new view name.
5456 public void tabbedPane_mousePressed(MouseEvent e)
5458 if (SwingUtilities.isRightMouseButton(e))
5460 String msg = MessageManager.getString("label.enter_view_name");
5461 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5462 JOptionPane.QUESTION_MESSAGE);
5466 viewport.viewName = reply;
5467 // TODO warn if reply is in getExistingViewNames()?
5468 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5473 public AlignViewport getCurrentView()
5479 * Open the dialog for regex description parsing.
5482 protected void extractScores_actionPerformed(ActionEvent e)
5484 ParseProperties pp = new jalview.analysis.ParseProperties(
5485 viewport.getAlignment());
5486 // TODO: verify regex and introduce GUI dialog for version 2.5
5487 // if (pp.getScoresFromDescription("col", "score column ",
5488 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5490 if (pp.getScoresFromDescription("description column",
5491 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5493 buildSortByAnnotationScoresMenu();
5501 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5505 protected void showDbRefs_actionPerformed(ActionEvent e)
5507 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5513 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5517 protected void showNpFeats_actionPerformed(ActionEvent e)
5519 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5523 * find the viewport amongst the tabs in this alignment frame and close that
5528 public boolean closeView(AlignViewportI av)
5532 this.closeMenuItem_actionPerformed(false);
5535 Component[] comp = tabbedPane.getComponents();
5536 for (int i = 0; comp != null && i < comp.length; i++)
5538 if (comp[i] instanceof AlignmentPanel)
5540 if (((AlignmentPanel) comp[i]).av == av)
5543 closeView((AlignmentPanel) comp[i]);
5551 protected void build_fetchdbmenu(JMenu webService)
5553 // Temporary hack - DBRef Fetcher always top level ws entry.
5554 // TODO We probably want to store a sequence database checklist in
5555 // preferences and have checkboxes.. rather than individual sources selected
5557 final JMenu rfetch = new JMenu(
5558 MessageManager.getString("action.fetch_db_references"));
5559 rfetch.setToolTipText(MessageManager
5560 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5561 webService.add(rfetch);
5563 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5564 MessageManager.getString("option.trim_retrieved_seqs"));
5565 trimrs.setToolTipText(MessageManager
5566 .getString("label.trim_retrieved_sequences"));
5567 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5568 trimrs.addActionListener(new ActionListener()
5571 public void actionPerformed(ActionEvent e)
5573 trimrs.setSelected(trimrs.isSelected());
5574 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5575 Boolean.valueOf(trimrs.isSelected()).toString());
5579 JMenuItem fetchr = new JMenuItem(
5580 MessageManager.getString("label.standard_databases"));
5581 fetchr.setToolTipText(MessageManager
5582 .getString("label.fetch_embl_uniprot"));
5583 fetchr.addActionListener(new ActionListener()
5587 public void actionPerformed(ActionEvent e)
5589 new Thread(new Runnable()
5595 new jalview.ws.DBRefFetcher(alignPanel.av
5596 .getSequenceSelection(), alignPanel.alignFrame)
5597 .fetchDBRefs(false);
5605 final AlignFrame me = this;
5606 new Thread(new Runnable()
5611 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5612 .getSequenceFetcherSingleton(me);
5613 javax.swing.SwingUtilities.invokeLater(new Runnable()
5618 String[] dbclasses = sf.getOrderedSupportedSources();
5619 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5620 // jalview.util.QuickSort.sort(otherdb, otherdb);
5621 List<DbSourceProxy> otherdb;
5622 JMenu dfetch = new JMenu();
5623 JMenu ifetch = new JMenu();
5624 JMenuItem fetchr = null;
5625 int comp = 0, icomp = 0, mcomp = 15;
5626 String mname = null;
5628 for (String dbclass : dbclasses)
5630 otherdb = sf.getSourceProxy(dbclass);
5631 // add a single entry for this class, or submenu allowing 'fetch
5633 if (otherdb == null || otherdb.size() < 1)
5637 // List<DbSourceProxy> dbs=otherdb;
5638 // otherdb=new ArrayList<DbSourceProxy>();
5639 // for (DbSourceProxy db:dbs)
5641 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5645 mname = "From " + dbclass;
5647 if (otherdb.size() == 1)
5649 final DbSourceProxy[] dassource = otherdb
5650 .toArray(new DbSourceProxy[0]);
5651 DbSourceProxy src = otherdb.get(0);
5652 fetchr = new JMenuItem(src.getDbSource());
5653 fetchr.addActionListener(new ActionListener()
5657 public void actionPerformed(ActionEvent e)
5659 new Thread(new Runnable()
5665 new jalview.ws.DBRefFetcher(alignPanel.av
5666 .getSequenceSelection(),
5667 alignPanel.alignFrame, dassource)
5668 .fetchDBRefs(false);
5674 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5680 final DbSourceProxy[] dassource = otherdb
5681 .toArray(new DbSourceProxy[0]);
5683 DbSourceProxy src = otherdb.get(0);
5684 fetchr = new JMenuItem(MessageManager.formatMessage(
5685 "label.fetch_all_param", new Object[]
5686 { src.getDbSource() }));
5687 fetchr.addActionListener(new ActionListener()
5690 public void actionPerformed(ActionEvent e)
5692 new Thread(new Runnable()
5698 new jalview.ws.DBRefFetcher(alignPanel.av
5699 .getSequenceSelection(),
5700 alignPanel.alignFrame, dassource)
5701 .fetchDBRefs(false);
5707 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5710 // and then build the rest of the individual menus
5711 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5713 String imname = null;
5715 for (DbSourceProxy sproxy : otherdb)
5717 String dbname = sproxy.getDbName();
5718 String sname = dbname.length() > 5 ? dbname.substring(0,
5719 5) + "..." : dbname;
5720 String msname = dbname.length() > 10 ? dbname.substring(
5721 0, 10) + "..." : dbname;
5724 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5726 fetchr = new JMenuItem(msname);
5727 final DbSourceProxy[] dassrc =
5729 fetchr.addActionListener(new ActionListener()
5733 public void actionPerformed(ActionEvent e)
5735 new Thread(new Runnable()
5741 new jalview.ws.DBRefFetcher(alignPanel.av
5742 .getSequenceSelection(),
5743 alignPanel.alignFrame, dassrc)
5744 .fetchDBRefs(false);
5750 fetchr.setToolTipText("<html>"
5751 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5754 if (++icomp >= mcomp || i == (otherdb.size()))
5756 ifetch.setText(MessageManager.formatMessage(
5757 "label.source_to_target", imname, sname));
5759 ifetch = new JMenu();
5767 if (comp >= mcomp || dbi >= (dbclasses.length))
5769 dfetch.setText(MessageManager.formatMessage(
5770 "label.source_to_target", mname, dbclass));
5772 dfetch = new JMenu();
5785 * Left justify the whole alignment.
5788 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5790 AlignmentI al = viewport.getAlignment();
5792 viewport.firePropertyChange("alignment", null, al);
5796 * Right justify the whole alignment.
5799 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5801 AlignmentI al = viewport.getAlignment();
5803 viewport.firePropertyChange("alignment", null, al);
5806 public void setShowSeqFeatures(boolean b)
5808 showSeqFeatures.setSelected(b);
5809 viewport.setShowSequenceFeatures(b);
5816 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5817 * awt.event.ActionEvent)
5820 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5822 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5823 alignPanel.paintAlignment(true);
5830 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5834 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5836 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5837 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5845 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5846 * .event.ActionEvent)
5849 protected void showGroupConservation_actionPerformed(ActionEvent e)
5851 viewport.setShowGroupConservation(showGroupConservation.getState());
5852 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5859 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5860 * .event.ActionEvent)
5863 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5865 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5866 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5873 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5874 * .event.ActionEvent)
5877 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5879 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5880 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5884 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5886 showSequenceLogo.setState(true);
5887 viewport.setShowSequenceLogo(true);
5888 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5889 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5893 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5895 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5902 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5903 * .event.ActionEvent)
5906 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5908 if (avc.makeGroupsFromSelection())
5910 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5911 alignPanel.updateAnnotation();
5912 alignPanel.paintAlignment(true);
5915 public void clearAlignmentSeqRep()
5917 // TODO refactor alignmentseqrep to controller
5918 if (viewport.getAlignment().hasSeqrep()) {
5919 viewport.getAlignment().setSeqrep(null);
5920 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5921 alignPanel.updateAnnotation();
5922 alignPanel.paintAlignment(true);
5927 protected void createGroup_actionPerformed(ActionEvent e)
5929 if (avc.createGroup())
5931 alignPanel.alignmentChanged();
5936 protected void unGroup_actionPerformed(ActionEvent e)
5940 alignPanel.alignmentChanged();
5945 * make the given alignmentPanel the currently selected tab
5947 * @param alignmentPanel
5949 public void setDisplayedView(AlignmentPanel alignmentPanel)
5951 if (!viewport.getSequenceSetId().equals(
5952 alignmentPanel.av.getSequenceSetId()))
5954 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5956 if (tabbedPane != null
5957 && tabbedPane.getTabCount() > 0
5958 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5959 .getSelectedIndex())
5961 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5966 * Action on selection of menu options to Show or Hide annotations.
5969 * @param forSequences
5970 * update sequence-related annotations
5971 * @param forAlignment
5972 * update non-sequence-related annotations
5975 protected void setAnnotationsVisibility(boolean visible,
5976 boolean forSequences, boolean forAlignment)
5978 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5979 .getAlignmentAnnotation())
5982 * don't display non-positional annotations on an alignment
5984 if (aa.annotations == null)
5988 boolean apply = (aa.sequenceRef == null && forAlignment)
5989 || (aa.sequenceRef != null && forSequences);
5992 aa.visible = visible;
5995 alignPanel.validateAnnotationDimensions(false);
5996 alignPanel.alignmentChanged();
6000 * Store selected annotation sort order for the view and repaint.
6003 protected void sortAnnotations_actionPerformed()
6005 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
6007 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
6008 alignPanel.paintAlignment(true);
6013 * @return alignment panels in this alignment frame
6015 public List<? extends AlignmentViewPanel> getAlignPanels()
6017 return alignPanels == null ? Arrays.asList(alignPanel)
6022 * Open a new alignment window, with the cDNA associated with this (protein)
6023 * alignment, aligned as is the protein.
6025 protected void viewAsCdna_actionPerformed()
6027 // TODO no longer a menu action - refactor as required
6028 final AlignmentI alignment = getViewport().getAlignment();
6029 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6030 if (mappings == null)
6034 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6035 for (SequenceI aaSeq : alignment.getSequences()) {
6036 for (AlignedCodonFrame acf : mappings) {
6037 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6041 * There is a cDNA mapping for this protein sequence - add to new
6042 * alignment. It will share the same dataset sequence as other mapped
6043 * cDNA (no new mappings need to be created).
6045 final Sequence newSeq = new Sequence(dnaSeq);
6046 newSeq.setDatasetSequence(dnaSeq);
6047 cdnaSeqs.add(newSeq);
6051 if (cdnaSeqs.size() == 0)
6053 // show a warning dialog no mapped cDNA
6056 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6058 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6059 AlignFrame.DEFAULT_HEIGHT);
6060 cdna.alignAs(alignment);
6061 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6063 Desktop.addInternalFrame(alignFrame, newtitle,
6064 AlignFrame.DEFAULT_WIDTH,
6065 AlignFrame.DEFAULT_HEIGHT);
6069 * Set visibility of dna/protein complement view (available when shown in a
6075 protected void showComplement_actionPerformed(boolean show)
6077 SplitContainerI sf = getSplitViewContainer();
6079 sf.setComplementVisible(this, show);
6083 public class ExportData
6085 private AlignmentI alignment;
6087 private String[] omitHidden;
6089 private int[] startEnd;
6091 public ExportData(AlignmentI align, String[] ommit, int[] startEnd)
6093 this.alignment = align;
6094 this.omitHidden = ommit;
6095 this.startEnd = startEnd;
6098 public AlignmentI getAlignment()
6103 public void setAlignment(AlignmentI alignment)
6105 this.alignment = alignment;
6108 public String[] getOmitHidden()
6113 public void setOmitHidden(String[] omitHidden)
6115 this.omitHidden = omitHidden;
6118 public int[] getStartEndPostions()
6123 public void setStartEndPostions(int[] startEnd)
6125 this.startEnd = startEnd;
6131 class PrintThread extends Thread
6135 public PrintThread(AlignmentPanel ap)
6140 static PageFormat pf;
6145 PrinterJob printJob = PrinterJob.getPrinterJob();
6149 printJob.setPrintable(ap, pf);
6153 printJob.setPrintable(ap);
6156 if (printJob.printDialog())
6161 } catch (Exception PrintException)
6163 PrintException.printStackTrace();