2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AAFrequency;
24 import jalview.analysis.AlignmentSorter;
25 import jalview.analysis.AlignmentUtils;
26 import jalview.analysis.Conservation;
27 import jalview.analysis.CrossRef;
28 import jalview.analysis.Dna;
29 import jalview.analysis.ParseProperties;
30 import jalview.analysis.SequenceIdMatcher;
31 import jalview.api.AlignViewControllerGuiI;
32 import jalview.api.AlignViewControllerI;
33 import jalview.api.AlignViewportI;
34 import jalview.api.AlignmentViewPanel;
35 import jalview.api.SplitContainerI;
36 import jalview.api.ViewStyleI;
37 import jalview.api.analysis.ScoreModelI;
38 import jalview.bin.Cache;
39 import jalview.commands.CommandI;
40 import jalview.commands.EditCommand;
41 import jalview.commands.EditCommand.Action;
42 import jalview.commands.OrderCommand;
43 import jalview.commands.RemoveGapColCommand;
44 import jalview.commands.RemoveGapsCommand;
45 import jalview.commands.SlideSequencesCommand;
46 import jalview.commands.TrimRegionCommand;
47 import jalview.datamodel.AlignedCodonFrame;
48 import jalview.datamodel.Alignment;
49 import jalview.datamodel.AlignmentAnnotation;
50 import jalview.datamodel.AlignmentI;
51 import jalview.datamodel.AlignmentOrder;
52 import jalview.datamodel.AlignmentView;
53 import jalview.datamodel.ColumnSelection;
54 import jalview.datamodel.PDBEntry;
55 import jalview.datamodel.SeqCigar;
56 import jalview.datamodel.Sequence;
57 import jalview.datamodel.SequenceGroup;
58 import jalview.datamodel.SequenceI;
59 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
60 import jalview.io.AlignmentProperties;
61 import jalview.io.AnnotationFile;
62 import jalview.io.BioJsHTMLOutput;
63 import jalview.io.FeaturesFile;
64 import jalview.io.FileLoader;
65 import jalview.io.FormatAdapter;
66 import jalview.io.HtmlSvgOutput;
67 import jalview.io.IdentifyFile;
68 import jalview.io.JalviewFileChooser;
69 import jalview.io.JalviewFileView;
70 import jalview.io.JnetAnnotationMaker;
71 import jalview.io.NewickFile;
72 import jalview.io.TCoffeeScoreFile;
73 import jalview.jbgui.GAlignFrame;
74 import jalview.schemes.Blosum62ColourScheme;
75 import jalview.schemes.BuriedColourScheme;
76 import jalview.schemes.ClustalxColourScheme;
77 import jalview.schemes.ColourSchemeI;
78 import jalview.schemes.ColourSchemeProperty;
79 import jalview.schemes.HelixColourScheme;
80 import jalview.schemes.HydrophobicColourScheme;
81 import jalview.schemes.NucleotideColourScheme;
82 import jalview.schemes.PIDColourScheme;
83 import jalview.schemes.PurinePyrimidineColourScheme;
84 import jalview.schemes.RNAHelicesColourChooser;
85 import jalview.schemes.ResidueProperties;
86 import jalview.schemes.StrandColourScheme;
87 import jalview.schemes.TCoffeeColourScheme;
88 import jalview.schemes.TaylorColourScheme;
89 import jalview.schemes.TurnColourScheme;
90 import jalview.schemes.UserColourScheme;
91 import jalview.schemes.ZappoColourScheme;
92 import jalview.structure.StructureSelectionManager;
93 import jalview.util.MessageManager;
94 import jalview.viewmodel.AlignmentViewport;
95 import jalview.ws.jws1.Discoverer;
96 import jalview.ws.jws2.Jws2Discoverer;
97 import jalview.ws.jws2.jabaws2.Jws2Instance;
98 import jalview.ws.seqfetcher.DbSourceProxy;
100 import java.awt.BorderLayout;
101 import java.awt.Component;
102 import java.awt.GridLayout;
103 import java.awt.Rectangle;
104 import java.awt.Toolkit;
105 import java.awt.datatransfer.Clipboard;
106 import java.awt.datatransfer.DataFlavor;
107 import java.awt.datatransfer.StringSelection;
108 import java.awt.datatransfer.Transferable;
109 import java.awt.dnd.DnDConstants;
110 import java.awt.dnd.DropTargetDragEvent;
111 import java.awt.dnd.DropTargetDropEvent;
112 import java.awt.dnd.DropTargetEvent;
113 import java.awt.dnd.DropTargetListener;
114 import java.awt.event.ActionEvent;
115 import java.awt.event.ActionListener;
116 import java.awt.event.ItemEvent;
117 import java.awt.event.ItemListener;
118 import java.awt.event.KeyAdapter;
119 import java.awt.event.KeyEvent;
120 import java.awt.event.MouseAdapter;
121 import java.awt.event.MouseEvent;
122 import java.awt.print.PageFormat;
123 import java.awt.print.PrinterJob;
124 import java.beans.PropertyChangeEvent;
127 import java.util.ArrayList;
128 import java.util.Arrays;
129 import java.util.Deque;
130 import java.util.Enumeration;
131 import java.util.Hashtable;
132 import java.util.List;
133 import java.util.Set;
134 import java.util.Vector;
136 import javax.swing.JButton;
137 import javax.swing.JCheckBoxMenuItem;
138 import javax.swing.JEditorPane;
139 import javax.swing.JInternalFrame;
140 import javax.swing.JLabel;
141 import javax.swing.JLayeredPane;
142 import javax.swing.JMenu;
143 import javax.swing.JMenuItem;
144 import javax.swing.JOptionPane;
145 import javax.swing.JPanel;
146 import javax.swing.JProgressBar;
147 import javax.swing.JRadioButtonMenuItem;
148 import javax.swing.JScrollPane;
149 import javax.swing.SwingUtilities;
155 * @version $Revision$
157 public class AlignFrame extends GAlignFrame implements DropTargetListener,
158 IProgressIndicator, AlignViewControllerGuiI
161 public static final int DEFAULT_WIDTH = 700;
163 public static final int DEFAULT_HEIGHT = 500;
166 * The currently displayed panel (selected tabbed view if more than one)
168 public AlignmentPanel alignPanel;
170 AlignViewport viewport;
172 public AlignViewControllerI avc;
174 List<AlignmentPanel> alignPanels = new ArrayList<AlignmentPanel>();
177 * Last format used to load or save alignments in this window
179 String currentFileFormat = null;
182 * Current filename for this alignment
184 String fileName = null;
187 * Creates a new AlignFrame object with specific width and height.
193 public AlignFrame(AlignmentI al, int width, int height)
195 this(al, null, width, height);
199 * Creates a new AlignFrame object with specific width, height and
205 * @param sequenceSetId
207 public AlignFrame(AlignmentI al, int width, int height,
208 String sequenceSetId)
210 this(al, null, width, height, sequenceSetId);
214 * Creates a new AlignFrame object with specific width, height and
220 * @param sequenceSetId
223 public AlignFrame(AlignmentI al, int width, int height,
224 String sequenceSetId, String viewId)
226 this(al, null, width, height, sequenceSetId, viewId);
230 * new alignment window with hidden columns
234 * @param hiddenColumns
235 * ColumnSelection or null
237 * Width of alignment frame
241 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
242 int width, int height)
244 this(al, hiddenColumns, width, height, null);
248 * Create alignment frame for al with hiddenColumns, a specific width and
249 * height, and specific sequenceId
252 * @param hiddenColumns
255 * @param sequenceSetId
258 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
259 int width, int height, String sequenceSetId)
261 this(al, hiddenColumns, width, height, sequenceSetId, null);
265 * Create alignment frame for al with hiddenColumns, a specific width and
266 * height, and specific sequenceId
269 * @param hiddenColumns
272 * @param sequenceSetId
277 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
278 int width, int height, String sequenceSetId, String viewId)
280 setSize(width, height);
282 if (al.getDataset() == null)
287 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
289 alignPanel = new AlignmentPanel(this, viewport);
292 addAlignmentPanel(alignPanel, true);
297 * Make a new AlignFrame from existing alignmentPanels
304 public AlignFrame(AlignmentPanel ap)
308 addAlignmentPanel(ap, false);
313 * initalise the alignframe from the underlying viewport data and the
318 avc = new jalview.controller.AlignViewController(this, viewport,
320 if (viewport.getAlignmentConservationAnnotation() == null)
322 BLOSUM62Colour.setEnabled(false);
323 conservationMenuItem.setEnabled(false);
324 modifyConservation.setEnabled(false);
325 // PIDColour.setEnabled(false);
326 // abovePIDThreshold.setEnabled(false);
327 // modifyPID.setEnabled(false);
330 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
333 if (sortby.equals("Id"))
335 sortIDMenuItem_actionPerformed(null);
337 else if (sortby.equals("Pairwise Identity"))
339 sortPairwiseMenuItem_actionPerformed(null);
342 if (Desktop.desktop != null)
344 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
345 addServiceListeners();
346 setGUINucleotide(viewport.getAlignment().isNucleotide());
349 setMenusFromViewport(viewport);
350 buildSortByAnnotationScoresMenu();
353 if (viewport.getWrapAlignment())
355 wrapMenuItem_actionPerformed(null);
358 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
360 this.overviewMenuItem_actionPerformed(null);
365 final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
366 final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
367 final String menuLabel = MessageManager
368 .getString("label.copy_format_from");
369 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
370 new ViewSetProvider()
374 public AlignmentPanel[] getAllAlignmentPanels()
377 origview.add(alignPanel);
378 // make an array of all alignment panels except for this one
379 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
380 Arrays.asList(Desktop.getAlignmentPanels(null)));
381 aps.remove(AlignFrame.this.alignPanel);
382 return aps.toArray(new AlignmentPanel[aps.size()]);
384 }, selviews, new ItemListener()
388 public void itemStateChanged(ItemEvent e)
390 if (origview.size() > 0)
392 final AlignmentPanel ap = origview.get(0);
395 * Copy the ViewStyle of the selected panel to 'this one'.
396 * Don't change value of 'scaleProteinAsCdna' unless copying
399 ViewStyleI vs = selviews.get(0).getAlignViewport()
401 boolean fromSplitFrame = selviews.get(0)
402 .getAlignViewport().getCodingComplement() != null;
405 vs.setScaleProteinAsCdna(ap.getAlignViewport()
406 .getViewStyle().isScaleProteinAsCdna());
408 ap.getAlignViewport().setViewStyle(vs);
411 * Also rescale ViewStyle of SplitFrame complement if there is
412 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
413 * the whole ViewStyle (allow cDNA protein to have different
416 AlignViewportI complement = ap.getAlignViewport()
417 .getCodingComplement();
418 if (complement != null && vs.isScaleProteinAsCdna())
420 AlignFrame af = Desktop.getAlignFrameFor(complement);
421 ((SplitFrame) af.getSplitViewContainer())
423 af.setMenusForViewport();
427 ap.setSelected(true);
428 ap.alignFrame.setMenusForViewport();
433 formatMenu.add(vsel);
438 * Change the filename and format for the alignment, and enable the 'reload'
439 * button functionality.
446 public void setFileName(String file, String format)
449 setFileFormat(format);
450 reload.setEnabled(true);
454 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
457 void addKeyListener()
459 addKeyListener(new KeyAdapter()
462 public void keyPressed(KeyEvent evt)
464 if (viewport.cursorMode
465 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
466 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
467 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
468 && Character.isDigit(evt.getKeyChar()))
470 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
473 switch (evt.getKeyCode())
476 case 27: // escape key
477 deselectAllSequenceMenuItem_actionPerformed(null);
481 case KeyEvent.VK_DOWN:
482 if (evt.isAltDown() || !viewport.cursorMode)
484 moveSelectedSequences(false);
486 if (viewport.cursorMode)
488 alignPanel.getSeqPanel().moveCursor(0, 1);
493 if (evt.isAltDown() || !viewport.cursorMode)
495 moveSelectedSequences(true);
497 if (viewport.cursorMode)
499 alignPanel.getSeqPanel().moveCursor(0, -1);
504 case KeyEvent.VK_LEFT:
505 if (evt.isAltDown() || !viewport.cursorMode)
507 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
511 alignPanel.getSeqPanel().moveCursor(-1, 0);
516 case KeyEvent.VK_RIGHT:
517 if (evt.isAltDown() || !viewport.cursorMode)
519 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
523 alignPanel.getSeqPanel().moveCursor(1, 0);
527 case KeyEvent.VK_SPACE:
528 if (viewport.cursorMode)
530 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
531 || evt.isShiftDown() || evt.isAltDown());
535 // case KeyEvent.VK_A:
536 // if (viewport.cursorMode)
538 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
539 // //System.out.println("A");
543 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
544 * System.out.println("closing bracket"); } break;
546 case KeyEvent.VK_DELETE:
547 case KeyEvent.VK_BACK_SPACE:
548 if (!viewport.cursorMode)
550 cut_actionPerformed(null);
554 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
555 || evt.isShiftDown() || evt.isAltDown());
561 if (viewport.cursorMode)
563 alignPanel.getSeqPanel().setCursorRow();
567 if (viewport.cursorMode && !evt.isControlDown())
569 alignPanel.getSeqPanel().setCursorColumn();
573 if (viewport.cursorMode)
575 alignPanel.getSeqPanel().setCursorPosition();
579 case KeyEvent.VK_ENTER:
580 case KeyEvent.VK_COMMA:
581 if (viewport.cursorMode)
583 alignPanel.getSeqPanel().setCursorRowAndColumn();
588 if (viewport.cursorMode)
590 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
594 if (viewport.cursorMode)
596 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
601 viewport.cursorMode = !viewport.cursorMode;
602 statusBar.setText(MessageManager.formatMessage(
603 "label.keyboard_editing_mode", new String[]
604 { (viewport.cursorMode ? "on" : "off") }));
605 if (viewport.cursorMode)
607 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
608 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
610 alignPanel.getSeqPanel().seqCanvas.repaint();
616 Help.showHelpWindow();
617 } catch (Exception ex)
619 ex.printStackTrace();
624 boolean toggleSeqs = !evt.isControlDown();
625 boolean toggleCols = !evt.isShiftDown();
626 toggleHiddenRegions(toggleSeqs, toggleCols);
629 case KeyEvent.VK_PAGE_UP:
630 if (viewport.getWrapAlignment())
632 alignPanel.scrollUp(true);
636 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
637 - viewport.endSeq + viewport.startSeq);
640 case KeyEvent.VK_PAGE_DOWN:
641 if (viewport.getWrapAlignment())
643 alignPanel.scrollUp(false);
647 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
648 + viewport.endSeq - viewport.startSeq);
655 public void keyReleased(KeyEvent evt)
657 switch (evt.getKeyCode())
659 case KeyEvent.VK_LEFT:
660 if (evt.isAltDown() || !viewport.cursorMode)
662 viewport.firePropertyChange("alignment", null, viewport
663 .getAlignment().getSequences());
667 case KeyEvent.VK_RIGHT:
668 if (evt.isAltDown() || !viewport.cursorMode)
670 viewport.firePropertyChange("alignment", null, viewport
671 .getAlignment().getSequences());
679 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
681 ap.alignFrame = this;
682 avc = new jalview.controller.AlignViewController(this, viewport,
687 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
689 int aSize = alignPanels.size();
691 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
693 if (aSize == 1 && ap.av.viewName == null)
695 this.getContentPane().add(ap, BorderLayout.CENTER);
701 setInitialTabVisible();
704 expandViews.setEnabled(true);
705 gatherViews.setEnabled(true);
706 tabbedPane.addTab(ap.av.viewName, ap);
708 ap.setVisible(false);
713 if (ap.av.isPadGaps())
715 ap.av.getAlignment().padGaps();
717 ap.av.updateConservation(ap);
718 ap.av.updateConsensus(ap);
719 ap.av.updateStrucConsensus(ap);
723 public void setInitialTabVisible()
725 expandViews.setEnabled(true);
726 gatherViews.setEnabled(true);
727 tabbedPane.setVisible(true);
728 AlignmentPanel first = alignPanels.get(0);
729 tabbedPane.addTab(first.av.viewName, first);
730 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
733 public AlignViewport getViewport()
738 /* Set up intrinsic listeners for dynamically generated GUI bits. */
739 private void addServiceListeners()
741 final java.beans.PropertyChangeListener thisListener;
742 Desktop.instance.addJalviewPropertyChangeListener("services",
743 thisListener = new java.beans.PropertyChangeListener()
746 public void propertyChange(PropertyChangeEvent evt)
748 // // System.out.println("Discoverer property change.");
749 // if (evt.getPropertyName().equals("services"))
751 SwingUtilities.invokeLater(new Runnable()
758 .println("Rebuild WS Menu for service change");
759 BuildWebServiceMenu();
766 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
769 public void internalFrameClosed(
770 javax.swing.event.InternalFrameEvent evt)
772 System.out.println("deregistering discoverer listener");
773 Desktop.instance.removeJalviewPropertyChangeListener("services",
775 closeMenuItem_actionPerformed(true);
778 // Finally, build the menu once to get current service state
779 new Thread(new Runnable()
784 BuildWebServiceMenu();
790 * Configure menu items that vary according to whether the alignment is
791 * nucleotide or protein
795 public void setGUINucleotide(boolean nucleotide)
797 showTranslation.setVisible(nucleotide);
798 conservationMenuItem.setEnabled(!nucleotide);
799 modifyConservation.setEnabled(!nucleotide);
800 showGroupConservation.setEnabled(!nucleotide);
801 rnahelicesColour.setEnabled(nucleotide);
802 purinePyrimidineColour.setEnabled(nucleotide);
803 showComplementMenuItem.setText(MessageManager
804 .getString(nucleotide ? "label.protein" : "label.nucleotide"));
805 setColourSelected(jalview.bin.Cache.getDefault(
806 nucleotide ? Preferences.DEFAULT_COLOUR_NUC
807 : Preferences.DEFAULT_COLOUR_PROT, "None"));
811 * set up menus for the current viewport. This may be called after any
812 * operation that affects the data in the current view (selection changed,
813 * etc) to update the menus to reflect the new state.
815 public void setMenusForViewport()
817 setMenusFromViewport(viewport);
821 * Need to call this method when tabs are selected for multiple views, or when
822 * loading from Jalview2XML.java
827 void setMenusFromViewport(AlignViewport av)
829 padGapsMenuitem.setSelected(av.isPadGaps());
830 colourTextMenuItem.setSelected(av.isShowColourText());
831 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
832 conservationMenuItem.setSelected(av.getConservationSelected());
833 seqLimits.setSelected(av.getShowJVSuffix());
834 idRightAlign.setSelected(av.isRightAlignIds());
835 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
836 renderGapsMenuItem.setSelected(av.isRenderGaps());
837 wrapMenuItem.setSelected(av.getWrapAlignment());
838 scaleAbove.setVisible(av.getWrapAlignment());
839 scaleLeft.setVisible(av.getWrapAlignment());
840 scaleRight.setVisible(av.getWrapAlignment());
841 annotationPanelMenuItem.setState(av.isShowAnnotation());
843 * Show/hide annotations only enabled if annotation panel is shown
845 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
846 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
847 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
848 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
849 viewBoxesMenuItem.setSelected(av.getShowBoxes());
850 viewTextMenuItem.setSelected(av.getShowText());
851 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
852 showGroupConsensus.setSelected(av.isShowGroupConsensus());
853 showGroupConservation.setSelected(av.isShowGroupConservation());
854 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
855 showSequenceLogo.setSelected(av.isShowSequenceLogo());
856 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
858 setColourSelected(ColourSchemeProperty.getColourName(av
859 .getGlobalColourScheme()));
861 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
862 hiddenMarkers.setState(av.getShowHiddenMarkers());
863 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
864 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
865 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
866 autoCalculate.setSelected(av.autoCalculateConsensus);
867 sortByTree.setSelected(av.sortByTree);
868 listenToViewSelections.setSelected(av.followSelection);
869 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
871 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
872 setShowProductsEnabled();
876 // methods for implementing IProgressIndicator
877 // need to refactor to a reusable stub class
878 Hashtable progressBars, progressBarHandlers;
883 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
886 public void setProgressBar(String message, long id)
888 if (progressBars == null)
890 progressBars = new Hashtable();
891 progressBarHandlers = new Hashtable();
894 JPanel progressPanel;
895 Long lId = new Long(id);
896 GridLayout layout = (GridLayout) statusPanel.getLayout();
897 if (progressBars.get(lId) != null)
899 progressPanel = (JPanel) progressBars.get(new Long(id));
900 statusPanel.remove(progressPanel);
901 progressBars.remove(lId);
902 progressPanel = null;
905 statusBar.setText(message);
907 if (progressBarHandlers.contains(lId))
909 progressBarHandlers.remove(lId);
911 layout.setRows(layout.getRows() - 1);
915 progressPanel = new JPanel(new BorderLayout(10, 5));
917 JProgressBar progressBar = new JProgressBar();
918 progressBar.setIndeterminate(true);
920 progressPanel.add(new JLabel(message), BorderLayout.WEST);
921 progressPanel.add(progressBar, BorderLayout.CENTER);
923 layout.setRows(layout.getRows() + 1);
924 statusPanel.add(progressPanel);
926 progressBars.put(lId, progressPanel);
929 // setMenusForViewport();
934 public void registerHandler(final long id,
935 final IProgressIndicatorHandler handler)
937 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
939 throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler"));
941 progressBarHandlers.put(new Long(id), handler);
942 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
943 if (handler.canCancel())
945 JButton cancel = new JButton(
946 MessageManager.getString("action.cancel"));
947 final IProgressIndicator us = this;
948 cancel.addActionListener(new ActionListener()
952 public void actionPerformed(ActionEvent e)
954 handler.cancelActivity(id);
955 us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new Object[]{((JLabel) progressPanel.getComponent(0)).getText()}), id);
958 progressPanel.add(cancel, BorderLayout.EAST);
964 * @return true if any progress bars are still active
967 public boolean operationInProgress()
969 if (progressBars != null && progressBars.size() > 0)
977 public void setStatus(String text)
979 statusBar.setText(text);
983 * Added so Castor Mapping file can obtain Jalview Version
985 public String getVersion()
987 return jalview.bin.Cache.getProperty("VERSION");
990 public FeatureRenderer getFeatureRenderer()
992 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
996 public void fetchSequence_actionPerformed(ActionEvent e)
998 new SequenceFetcher(this);
1002 public void addFromFile_actionPerformed(ActionEvent e)
1004 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1008 public void reload_actionPerformed(ActionEvent e)
1010 if (fileName != null)
1012 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1013 // originating file's format
1014 // TODO: work out how to recover feature settings for correct view(s) when
1015 // file is reloaded.
1016 if (currentFileFormat.equals("Jalview"))
1018 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1019 for (int i = 0; i < frames.length; i++)
1021 if (frames[i] instanceof AlignFrame && frames[i] != this
1022 && ((AlignFrame) frames[i]).fileName != null
1023 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1027 frames[i].setSelected(true);
1028 Desktop.instance.closeAssociatedWindows();
1029 } catch (java.beans.PropertyVetoException ex)
1035 Desktop.instance.closeAssociatedWindows();
1037 FileLoader loader = new FileLoader();
1038 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1039 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1043 Rectangle bounds = this.getBounds();
1045 FileLoader loader = new FileLoader();
1046 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1047 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1048 protocol, currentFileFormat);
1050 newframe.setBounds(bounds);
1051 if (featureSettings != null && featureSettings.isShowing())
1053 final Rectangle fspos = featureSettings.frame.getBounds();
1054 // TODO: need a 'show feature settings' function that takes bounds -
1055 // need to refactor Desktop.addFrame
1056 newframe.featureSettings_actionPerformed(null);
1057 final FeatureSettings nfs = newframe.featureSettings;
1058 SwingUtilities.invokeLater(new Runnable()
1063 nfs.frame.setBounds(fspos);
1066 this.featureSettings.close();
1067 this.featureSettings = null;
1069 this.closeMenuItem_actionPerformed(true);
1075 public void addFromText_actionPerformed(ActionEvent e)
1077 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
1081 public void addFromURL_actionPerformed(ActionEvent e)
1083 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1087 public void save_actionPerformed(ActionEvent e)
1089 if (fileName == null
1090 || (currentFileFormat == null || !jalview.io.FormatAdapter
1091 .isValidIOFormat(currentFileFormat, true))
1092 || fileName.startsWith("http"))
1094 saveAs_actionPerformed(null);
1098 saveAlignment(fileName, currentFileFormat);
1109 public void saveAs_actionPerformed(ActionEvent e)
1111 JalviewFileChooser chooser = new JalviewFileChooser(
1112 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1113 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1114 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1115 currentFileFormat, false);
1117 chooser.setFileView(new JalviewFileView());
1118 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1119 chooser.setToolTipText(MessageManager.getString("action.save"));
1121 int value = chooser.showSaveDialog(this);
1123 if (value == JalviewFileChooser.APPROVE_OPTION)
1125 currentFileFormat = chooser.getSelectedFormat();
1126 while (currentFileFormat == null)
1129 .showInternalMessageDialog(
1132 .getString("label.select_file_format_before_saving"),
1134 .getString("label.file_format_not_specified"),
1135 JOptionPane.WARNING_MESSAGE);
1136 currentFileFormat = chooser.getSelectedFormat();
1137 value = chooser.showSaveDialog(this);
1138 if (value != JalviewFileChooser.APPROVE_OPTION)
1144 fileName = chooser.getSelectedFile().getPath();
1146 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1149 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1150 if (currentFileFormat.indexOf(" ") > -1)
1152 currentFileFormat = currentFileFormat.substring(0,
1153 currentFileFormat.indexOf(" "));
1155 saveAlignment(fileName, currentFileFormat);
1159 public boolean saveAlignment(String file, String format)
1161 boolean success = true;
1163 if (format.equalsIgnoreCase("Jalview"))
1165 String shortName = title;
1167 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1169 shortName = shortName.substring(shortName
1170 .lastIndexOf(java.io.File.separatorChar) + 1);
1174 * First save any linked Chimera session.
1176 Desktop.instance.saveChimeraSessions(file);
1178 success = new Jalview2XML().saveAlignment(this, file, shortName);
1180 statusBar.setText(MessageManager.formatMessage(
1181 "label.successfully_saved_to_file_in_format", new Object[]
1182 { fileName, format }));
1187 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1189 warningMessage("Cannot save file " + fileName + " using format "
1190 + format, "Alignment output format not supported");
1191 saveAs_actionPerformed(null);
1192 // JBPNote need to have a raise_gui flag here
1196 String[] omitHidden = null;
1198 if (viewport.hasHiddenColumns())
1200 int reply = JOptionPane
1201 .showInternalConfirmDialog(
1204 .getString("label.alignment_contains_hidden_columns"),
1206 .getString("action.save_omit_hidden_columns"),
1207 JOptionPane.YES_NO_OPTION,
1208 JOptionPane.QUESTION_MESSAGE);
1210 if (reply == JOptionPane.YES_OPTION)
1212 omitHidden = viewport.getViewAsString(false);
1215 FormatAdapter f = new FormatAdapter();
1216 String output = f.formatSequences(format,
1217 viewport.getAlignment(), // class cast exceptions will
1218 // occur in the distant future
1219 omitHidden, f.getCacheSuffixDefault(format),
1220 viewport.getColumnSelection());
1230 java.io.PrintWriter out = new java.io.PrintWriter(
1231 new java.io.FileWriter(file));
1235 this.setTitle(file);
1236 statusBar.setText(MessageManager.formatMessage(
1237 "label.successfully_saved_to_file_in_format",
1239 { fileName, format }));
1240 } catch (Exception ex)
1243 ex.printStackTrace();
1250 JOptionPane.showInternalMessageDialog(this, MessageManager
1251 .formatMessage("label.couldnt_save_file", new Object[]
1252 { fileName }), MessageManager
1253 .getString("label.error_saving_file"),
1254 JOptionPane.WARNING_MESSAGE);
1260 private void warningMessage(String warning, String title)
1262 if (new jalview.util.Platform().isHeadless())
1264 System.err.println("Warning: " + title + "\nWarning: " + warning);
1269 JOptionPane.showInternalMessageDialog(this, warning, title,
1270 JOptionPane.WARNING_MESSAGE);
1282 protected void outputText_actionPerformed(ActionEvent e)
1284 String[] omitHidden = null;
1286 if (viewport.hasHiddenColumns())
1288 int reply = JOptionPane
1289 .showInternalConfirmDialog(
1292 .getString("label.alignment_contains_hidden_columns"),
1294 .getString("action.save_omit_hidden_columns"),
1295 JOptionPane.YES_NO_OPTION,
1296 JOptionPane.QUESTION_MESSAGE);
1298 if (reply == JOptionPane.YES_OPTION)
1300 omitHidden = viewport.getViewAsString(false);
1304 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1305 cap.setForInput(null);
1309 Desktop.setCurrentAlignFrame(this);
1310 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1311 viewport.getAlignment(), omitHidden,
1312 viewport.getColumnSelection()));
1313 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1314 "label.alignment_output_command", new Object[]
1315 { e.getActionCommand() }), 600, 500);
1316 } catch (OutOfMemoryError oom)
1318 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1331 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1333 // new HTMLOutput(alignPanel,
1334 // alignPanel.getSeqPanel().seqCanvas.getSequenceRenderer(),
1335 // alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
1336 new HtmlSvgOutput(null, alignPanel);
1340 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1342 new BioJsHTMLOutput(alignPanel,
1343 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
1345 public void createImageMap(File file, String image)
1347 alignPanel.makePNGImageMap(file, image);
1357 public void createPNG(File f)
1359 alignPanel.makePNG(f);
1369 public void createEPS(File f)
1371 alignPanel.makeEPS(f);
1374 public void createSVG(File f)
1376 alignPanel.makeSVG(f);
1379 public void pageSetup_actionPerformed(ActionEvent e)
1381 PrinterJob printJob = PrinterJob.getPrinterJob();
1382 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1392 public void printMenuItem_actionPerformed(ActionEvent e)
1394 // Putting in a thread avoids Swing painting problems
1395 PrintThread thread = new PrintThread(alignPanel);
1400 public void exportFeatures_actionPerformed(ActionEvent e)
1402 new AnnotationExporter().exportFeatures(alignPanel);
1406 public void exportAnnotations_actionPerformed(ActionEvent e)
1408 new AnnotationExporter().exportAnnotations(alignPanel);
1412 public void associatedData_actionPerformed(ActionEvent e)
1414 // Pick the tree file
1415 JalviewFileChooser chooser = new JalviewFileChooser(
1416 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1417 chooser.setFileView(new JalviewFileView());
1418 chooser.setDialogTitle(MessageManager
1419 .getString("label.load_jalview_annotations"));
1420 chooser.setToolTipText(MessageManager
1421 .getString("label.load_jalview_annotations"));
1423 int value = chooser.showOpenDialog(null);
1425 if (value == JalviewFileChooser.APPROVE_OPTION)
1427 String choice = chooser.getSelectedFile().getPath();
1428 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1429 loadJalviewDataFile(choice, null, null, null);
1435 * Close the current view or all views in the alignment frame. If the frame
1436 * only contains one view then the alignment will be removed from memory.
1438 * @param closeAllTabs
1441 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1443 if (alignPanels != null && alignPanels.size() < 2)
1445 closeAllTabs = true;
1450 if (alignPanels != null)
1454 if (this.isClosed())
1456 // really close all the windows - otherwise wait till
1457 // setClosed(true) is called
1458 for (int i = 0; i < alignPanels.size(); i++)
1460 AlignmentPanel ap = alignPanels.get(i);
1467 closeView(alignPanel);
1473 this.setClosed(true);
1475 } catch (Exception ex)
1477 ex.printStackTrace();
1482 * Close the specified panel and close up tabs appropriately.
1484 * @param panelToClose
1486 public void closeView(AlignmentPanel panelToClose)
1488 int index = tabbedPane.getSelectedIndex();
1489 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1490 alignPanels.remove(panelToClose);
1491 panelToClose.closePanel();
1492 panelToClose = null;
1494 tabbedPane.removeTabAt(closedindex);
1495 tabbedPane.validate();
1497 if (index > closedindex || index == tabbedPane.getTabCount())
1499 // modify currently selected tab index if necessary.
1503 this.tabSelectionChanged(index);
1509 void updateEditMenuBar()
1512 if (viewport.getHistoryList().size() > 0)
1514 undoMenuItem.setEnabled(true);
1515 CommandI command = viewport.getHistoryList().peek();
1516 undoMenuItem.setText(MessageManager.formatMessage(
1517 "label.undo_command", new Object[]
1518 { command.getDescription() }));
1522 undoMenuItem.setEnabled(false);
1523 undoMenuItem.setText(MessageManager.getString("action.undo"));
1526 if (viewport.getRedoList().size() > 0)
1528 redoMenuItem.setEnabled(true);
1530 CommandI command = viewport.getRedoList().peek();
1531 redoMenuItem.setText(MessageManager.formatMessage(
1532 "label.redo_command", new Object[]
1533 { command.getDescription() }));
1537 redoMenuItem.setEnabled(false);
1538 redoMenuItem.setText(MessageManager.getString("action.redo"));
1542 public void addHistoryItem(CommandI command)
1544 if (command.getSize() > 0)
1546 viewport.addToHistoryList(command);
1547 viewport.clearRedoList();
1548 updateEditMenuBar();
1549 viewport.updateHiddenColumns();
1550 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1551 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1552 // viewport.getColumnSelection()
1553 // .getHiddenColumns().size() > 0);
1559 * @return alignment objects for all views
1561 AlignmentI[] getViewAlignments()
1563 if (alignPanels != null)
1565 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1567 for (AlignmentPanel ap : alignPanels)
1569 als[i++] = ap.av.getAlignment();
1573 if (viewport != null)
1575 return new AlignmentI[]
1576 { viewport.getAlignment() };
1588 protected void undoMenuItem_actionPerformed(ActionEvent e)
1590 if (viewport.getHistoryList().isEmpty())
1594 CommandI command = viewport.getHistoryList().pop();
1595 viewport.addToRedoList(command);
1596 command.undoCommand(getViewAlignments());
1598 AlignmentViewport originalSource = getOriginatingSource(command);
1599 updateEditMenuBar();
1601 if (originalSource != null)
1603 if (originalSource != viewport)
1606 .warn("Implementation worry: mismatch of viewport origin for undo");
1608 originalSource.updateHiddenColumns();
1609 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1611 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1612 // viewport.getColumnSelection()
1613 // .getHiddenColumns().size() > 0);
1614 originalSource.firePropertyChange("alignment", null, originalSource
1615 .getAlignment().getSequences());
1626 protected void redoMenuItem_actionPerformed(ActionEvent e)
1628 if (viewport.getRedoList().size() < 1)
1633 CommandI command = viewport.getRedoList().pop();
1634 viewport.addToHistoryList(command);
1635 command.doCommand(getViewAlignments());
1637 AlignmentViewport originalSource = getOriginatingSource(command);
1638 updateEditMenuBar();
1640 if (originalSource != null)
1643 if (originalSource != viewport)
1646 .warn("Implementation worry: mismatch of viewport origin for redo");
1648 originalSource.updateHiddenColumns();
1649 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1651 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1652 // viewport.getColumnSelection()
1653 // .getHiddenColumns().size() > 0);
1654 originalSource.firePropertyChange("alignment", null, originalSource
1655 .getAlignment().getSequences());
1659 AlignmentViewport getOriginatingSource(CommandI command)
1661 AlignmentViewport originalSource = null;
1662 // For sequence removal and addition, we need to fire
1663 // the property change event FROM the viewport where the
1664 // original alignment was altered
1665 AlignmentI al = null;
1666 if (command instanceof EditCommand)
1668 EditCommand editCommand = (EditCommand) command;
1669 al = editCommand.getAlignment();
1670 List<Component> comps = PaintRefresher.components.get(viewport
1671 .getSequenceSetId());
1673 for (Component comp : comps)
1675 if (comp instanceof AlignmentPanel)
1677 if (al == ((AlignmentPanel) comp).av.getAlignment())
1679 originalSource = ((AlignmentPanel) comp).av;
1686 if (originalSource == null)
1688 // The original view is closed, we must validate
1689 // the current view against the closed view first
1692 PaintRefresher.validateSequences(al, viewport.getAlignment());
1695 originalSource = viewport;
1698 return originalSource;
1707 public void moveSelectedSequences(boolean up)
1709 SequenceGroup sg = viewport.getSelectionGroup();
1715 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1716 viewport.getHiddenRepSequences(), up);
1717 alignPanel.paintAlignment(true);
1720 synchronized void slideSequences(boolean right, int size)
1722 List<SequenceI> sg = new ArrayList<SequenceI>();
1723 if (viewport.cursorMode)
1725 sg.add(viewport.getAlignment().getSequenceAt(
1726 alignPanel.getSeqPanel().seqCanvas.cursorY));
1728 else if (viewport.getSelectionGroup() != null
1729 && viewport.getSelectionGroup().getSize() != viewport
1730 .getAlignment().getHeight())
1732 sg = viewport.getSelectionGroup().getSequences(
1733 viewport.getHiddenRepSequences());
1741 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1743 for (SequenceI seq : viewport.getAlignment().getSequences())
1745 if (!sg.contains(seq))
1747 invertGroup.add(seq);
1751 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1753 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1754 for (int i = 0; i < invertGroup.size(); i++)
1756 seqs2[i] = invertGroup.get(i);
1759 SlideSequencesCommand ssc;
1762 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1763 size, viewport.getGapCharacter());
1767 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1768 size, viewport.getGapCharacter());
1771 int groupAdjustment = 0;
1772 if (ssc.getGapsInsertedBegin() && right)
1774 if (viewport.cursorMode)
1776 alignPanel.getSeqPanel().moveCursor(size, 0);
1780 groupAdjustment = size;
1783 else if (!ssc.getGapsInsertedBegin() && !right)
1785 if (viewport.cursorMode)
1787 alignPanel.getSeqPanel().moveCursor(-size, 0);
1791 groupAdjustment = -size;
1795 if (groupAdjustment != 0)
1797 viewport.getSelectionGroup().setStartRes(
1798 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1799 viewport.getSelectionGroup().setEndRes(
1800 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1803 boolean appendHistoryItem = false;
1804 Deque<CommandI> historyList = viewport.getHistoryList();
1805 if (historyList != null
1806 && historyList.size() > 0
1807 && historyList.peek() instanceof SlideSequencesCommand)
1809 appendHistoryItem = ssc
1810 .appendSlideCommand((SlideSequencesCommand) historyList
1814 if (!appendHistoryItem)
1816 addHistoryItem(ssc);
1829 protected void copy_actionPerformed(ActionEvent e)
1832 if (viewport.getSelectionGroup() == null)
1836 // TODO: preserve the ordering of displayed alignment annotation in any
1837 // internal paste (particularly sequence associated annotation)
1838 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1839 String[] omitHidden = null;
1841 if (viewport.hasHiddenColumns())
1843 omitHidden = viewport.getViewAsString(true);
1846 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1849 StringSelection ss = new StringSelection(output);
1853 jalview.gui.Desktop.internalCopy = true;
1854 // Its really worth setting the clipboard contents
1855 // to empty before setting the large StringSelection!!
1856 Toolkit.getDefaultToolkit().getSystemClipboard()
1857 .setContents(new StringSelection(""), null);
1859 Toolkit.getDefaultToolkit().getSystemClipboard()
1860 .setContents(ss, Desktop.instance);
1861 } catch (OutOfMemoryError er)
1863 new OOMWarning("copying region", er);
1867 ArrayList<int[]> hiddenColumns = null;
1868 if (viewport.hasHiddenColumns())
1870 hiddenColumns = new ArrayList<int[]>();
1871 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1872 .getSelectionGroup().getEndRes();
1873 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1875 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1877 hiddenColumns.add(new int[]
1878 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1883 Desktop.jalviewClipboard = new Object[]
1884 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1885 statusBar.setText(MessageManager.formatMessage(
1886 "label.copied_sequences_to_clipboard", new Object[]
1887 { Integer.valueOf(seqs.length).toString() }));
1897 protected void pasteNew_actionPerformed(ActionEvent e)
1909 protected void pasteThis_actionPerformed(ActionEvent e)
1915 * Paste contents of Jalview clipboard
1917 * @param newAlignment
1918 * true to paste to a new alignment, otherwise add to this.
1920 void paste(boolean newAlignment)
1922 boolean externalPaste = true;
1925 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1926 Transferable contents = c.getContents(this);
1928 if (contents == null)
1936 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1937 if (str.length() < 1)
1942 format = new IdentifyFile().Identify(str, "Paste");
1944 } catch (OutOfMemoryError er)
1946 new OOMWarning("Out of memory pasting sequences!!", er);
1950 SequenceI[] sequences;
1951 boolean annotationAdded = false;
1952 AlignmentI alignment = null;
1954 if (Desktop.jalviewClipboard != null)
1956 // The clipboard was filled from within Jalview, we must use the
1958 // And dataset from the copied alignment
1959 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1960 // be doubly sure that we create *new* sequence objects.
1961 sequences = new SequenceI[newseq.length];
1962 for (int i = 0; i < newseq.length; i++)
1964 sequences[i] = new Sequence(newseq[i]);
1966 alignment = new Alignment(sequences);
1967 externalPaste = false;
1971 // parse the clipboard as an alignment.
1972 alignment = new FormatAdapter().readFile(str, "Paste", format);
1973 sequences = alignment.getSequencesArray();
1977 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1983 if (Desktop.jalviewClipboard != null)
1985 // dataset is inherited
1986 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1990 // new dataset is constructed
1991 alignment.setDataset(null);
1993 alwidth = alignment.getWidth() + 1;
1997 AlignmentI pastedal = alignment; // preserve pasted alignment object
1998 // Add pasted sequences and dataset into existing alignment.
1999 alignment = viewport.getAlignment();
2000 alwidth = alignment.getWidth() + 1;
2001 // decide if we need to import sequences from an existing dataset
2002 boolean importDs = Desktop.jalviewClipboard != null
2003 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2004 // importDs==true instructs us to copy over new dataset sequences from
2005 // an existing alignment
2006 Vector newDs = (importDs) ? new Vector() : null; // used to create
2007 // minimum dataset set
2009 for (int i = 0; i < sequences.length; i++)
2013 newDs.addElement(null);
2015 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2017 if (importDs && ds != null)
2019 if (!newDs.contains(ds))
2021 newDs.setElementAt(ds, i);
2022 ds = new Sequence(ds);
2023 // update with new dataset sequence
2024 sequences[i].setDatasetSequence(ds);
2028 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2033 // copy and derive new dataset sequence
2034 sequences[i] = sequences[i].deriveSequence();
2035 alignment.getDataset().addSequence(
2036 sequences[i].getDatasetSequence());
2037 // TODO: avoid creation of duplicate dataset sequences with a
2038 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2040 alignment.addSequence(sequences[i]); // merges dataset
2044 newDs.clear(); // tidy up
2046 if (alignment.getAlignmentAnnotation() != null)
2048 for (AlignmentAnnotation alan : alignment
2049 .getAlignmentAnnotation())
2051 if (alan.graphGroup > fgroup)
2053 fgroup = alan.graphGroup;
2057 if (pastedal.getAlignmentAnnotation() != null)
2059 // Add any annotation attached to alignment.
2060 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2061 for (int i = 0; i < alann.length; i++)
2063 annotationAdded = true;
2064 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2066 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2067 if (newann.graphGroup > -1)
2069 if (newGraphGroups.size() <= newann.graphGroup
2070 || newGraphGroups.get(newann.graphGroup) == null)
2072 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2074 newGraphGroups.add(q, null);
2076 newGraphGroups.set(newann.graphGroup, new Integer(
2079 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2083 newann.padAnnotation(alwidth);
2084 alignment.addAnnotation(newann);
2094 addHistoryItem(new EditCommand(
2095 MessageManager.getString("label.add_sequences"),
2097 sequences, 0, alignment.getWidth(), alignment));
2099 // Add any annotations attached to sequences
2100 for (int i = 0; i < sequences.length; i++)
2102 if (sequences[i].getAnnotation() != null)
2104 AlignmentAnnotation newann;
2105 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2107 annotationAdded = true;
2108 newann = sequences[i].getAnnotation()[a];
2109 newann.adjustForAlignment();
2110 newann.padAnnotation(alwidth);
2111 if (newann.graphGroup > -1)
2113 if (newann.graphGroup > -1)
2115 if (newGraphGroups.size() <= newann.graphGroup
2116 || newGraphGroups.get(newann.graphGroup) == null)
2118 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2120 newGraphGroups.add(q, null);
2122 newGraphGroups.set(newann.graphGroup, new Integer(
2125 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2129 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2134 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2141 // propagate alignment changed.
2142 viewport.setEndSeq(alignment.getHeight());
2143 if (annotationAdded)
2145 // Duplicate sequence annotation in all views.
2146 AlignmentI[] alview = this.getViewAlignments();
2147 for (int i = 0; i < sequences.length; i++)
2149 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2154 for (int avnum = 0; avnum < alview.length; avnum++)
2156 if (alview[avnum] != alignment)
2158 // duplicate in a view other than the one with input focus
2159 int avwidth = alview[avnum].getWidth() + 1;
2160 // this relies on sann being preserved after we
2161 // modify the sequence's annotation array for each duplication
2162 for (int a = 0; a < sann.length; a++)
2164 AlignmentAnnotation newann = new AlignmentAnnotation(
2166 sequences[i].addAlignmentAnnotation(newann);
2167 newann.padAnnotation(avwidth);
2168 alview[avnum].addAnnotation(newann); // annotation was
2169 // duplicated earlier
2170 // TODO JAL-1145 graphGroups are not updated for sequence
2171 // annotation added to several views. This may cause
2173 alview[avnum].setAnnotationIndex(newann, a);
2178 buildSortByAnnotationScoresMenu();
2180 viewport.firePropertyChange("alignment", null,
2181 alignment.getSequences());
2182 if (alignPanels != null)
2184 for (AlignmentPanel ap : alignPanels)
2186 ap.validateAnnotationDimensions(false);
2191 alignPanel.validateAnnotationDimensions(false);
2197 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2199 String newtitle = new String("Copied sequences");
2201 if (Desktop.jalviewClipboard != null
2202 && Desktop.jalviewClipboard[2] != null)
2204 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2205 for (int[] region : hc)
2207 af.viewport.hideColumns(region[0], region[1]);
2211 // >>>This is a fix for the moment, until a better solution is
2213 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2215 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2217 // TODO: maintain provenance of an alignment, rather than just make the
2218 // title a concatenation of operations.
2221 if (title.startsWith("Copied sequences"))
2227 newtitle = newtitle.concat("- from " + title);
2232 newtitle = new String("Pasted sequences");
2235 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2240 } catch (Exception ex)
2242 ex.printStackTrace();
2243 System.out.println("Exception whilst pasting: " + ex);
2244 // could be anything being pasted in here
2250 protected void expand_newalign(ActionEvent e)
2254 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2255 .getAlignment(), -1);
2256 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2258 String newtitle = new String("Flanking alignment");
2260 if (Desktop.jalviewClipboard != null
2261 && Desktop.jalviewClipboard[2] != null)
2263 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2264 for (int region[] : hc)
2266 af.viewport.hideColumns(region[0], region[1]);
2270 // >>>This is a fix for the moment, until a better solution is
2272 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2274 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2276 // TODO: maintain provenance of an alignment, rather than just make the
2277 // title a concatenation of operations.
2279 if (title.startsWith("Copied sequences"))
2285 newtitle = newtitle.concat("- from " + title);
2289 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2291 } catch (Exception ex)
2293 ex.printStackTrace();
2294 System.out.println("Exception whilst pasting: " + ex);
2295 // could be anything being pasted in here
2296 } catch (OutOfMemoryError oom)
2298 new OOMWarning("Viewing flanking region of alignment", oom);
2309 protected void cut_actionPerformed(ActionEvent e)
2311 copy_actionPerformed(null);
2312 delete_actionPerformed(null);
2322 protected void delete_actionPerformed(ActionEvent evt)
2325 SequenceGroup sg = viewport.getSelectionGroup();
2332 * If the cut affects all sequences, warn, remove highlighted columns
2334 if (sg.getSize() == viewport.getAlignment().getHeight())
2336 int confirm = JOptionPane.showConfirmDialog(this,
2337 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2338 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2339 JOptionPane.OK_CANCEL_OPTION);
2341 if (confirm == JOptionPane.CANCEL_OPTION
2342 || confirm == JOptionPane.CLOSED_OPTION)
2346 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2347 sg.getEndRes() + 1);
2350 SequenceI[] cut = sg.getSequences()
2351 .toArray(new SequenceI[sg.getSize()]);
2353 addHistoryItem(new EditCommand(
2354 MessageManager.getString("label.cut_sequences"), Action.CUT,
2355 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2356 viewport.getAlignment()));
2358 viewport.setSelectionGroup(null);
2359 viewport.sendSelection();
2360 viewport.getAlignment().deleteGroup(sg);
2362 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2364 if (viewport.getAlignment().getHeight() < 1)
2368 this.setClosed(true);
2369 } catch (Exception ex)
2382 protected void deleteGroups_actionPerformed(ActionEvent e)
2384 if (avc.deleteGroups())
2386 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2387 alignPanel.updateAnnotation();
2388 alignPanel.paintAlignment(true);
2399 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2401 SequenceGroup sg = new SequenceGroup();
2403 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2405 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2408 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2409 viewport.setSelectionGroup(sg);
2410 viewport.sendSelection();
2411 alignPanel.paintAlignment(true);
2412 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2422 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2424 if (viewport.cursorMode)
2426 alignPanel.getSeqPanel().keyboardNo1 = null;
2427 alignPanel.getSeqPanel().keyboardNo2 = null;
2429 viewport.setSelectionGroup(null);
2430 viewport.getColumnSelection().clear();
2431 viewport.setSelectionGroup(null);
2432 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2433 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2434 alignPanel.paintAlignment(true);
2435 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2436 viewport.sendSelection();
2446 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2448 SequenceGroup sg = viewport.getSelectionGroup();
2452 selectAllSequenceMenuItem_actionPerformed(null);
2457 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2459 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2462 alignPanel.paintAlignment(true);
2463 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2464 viewport.sendSelection();
2468 public void invertColSel_actionPerformed(ActionEvent e)
2470 viewport.invertColumnSelection();
2471 alignPanel.paintAlignment(true);
2472 viewport.sendSelection();
2482 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2484 trimAlignment(true);
2494 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2496 trimAlignment(false);
2499 void trimAlignment(boolean trimLeft)
2501 ColumnSelection colSel = viewport.getColumnSelection();
2504 if (colSel.size() > 0)
2508 column = colSel.getMin();
2512 column = colSel.getMax();
2516 if (viewport.getSelectionGroup() != null)
2518 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2519 viewport.getHiddenRepSequences());
2523 seqs = viewport.getAlignment().getSequencesArray();
2526 TrimRegionCommand trimRegion;
2529 trimRegion = new TrimRegionCommand("Remove Left",
2530 TrimRegionCommand.TRIM_LEFT, seqs, column,
2531 viewport.getAlignment(), viewport.getColumnSelection(),
2532 viewport.getSelectionGroup());
2533 viewport.setStartRes(0);
2537 trimRegion = new TrimRegionCommand("Remove Right",
2538 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2539 viewport.getAlignment(), viewport.getColumnSelection(),
2540 viewport.getSelectionGroup());
2543 statusBar.setText(MessageManager.formatMessage(
2544 "label.removed_columns", new String[]
2545 { Integer.valueOf(trimRegion.getSize()).toString() }));
2547 addHistoryItem(trimRegion);
2549 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2551 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2552 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2554 viewport.getAlignment().deleteGroup(sg);
2558 viewport.firePropertyChange("alignment", null, viewport
2559 .getAlignment().getSequences());
2570 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2572 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2575 if (viewport.getSelectionGroup() != null)
2577 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2578 viewport.getHiddenRepSequences());
2579 start = viewport.getSelectionGroup().getStartRes();
2580 end = viewport.getSelectionGroup().getEndRes();
2584 seqs = viewport.getAlignment().getSequencesArray();
2587 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2588 "Remove Gapped Columns", seqs, start, end,
2589 viewport.getAlignment());
2591 addHistoryItem(removeGapCols);
2593 statusBar.setText(MessageManager.formatMessage(
2594 "label.removed_empty_columns", new Object[]
2595 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2597 // This is to maintain viewport position on first residue
2598 // of first sequence
2599 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2600 int startRes = seq.findPosition(viewport.startRes);
2601 // ShiftList shifts;
2602 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2603 // edit.alColumnChanges=shifts.getInverse();
2604 // if (viewport.hasHiddenColumns)
2605 // viewport.getColumnSelection().compensateForEdits(shifts);
2606 viewport.setStartRes(seq.findIndex(startRes) - 1);
2607 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2619 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2621 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2624 if (viewport.getSelectionGroup() != null)
2626 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2627 viewport.getHiddenRepSequences());
2628 start = viewport.getSelectionGroup().getStartRes();
2629 end = viewport.getSelectionGroup().getEndRes();
2633 seqs = viewport.getAlignment().getSequencesArray();
2636 // This is to maintain viewport position on first residue
2637 // of first sequence
2638 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2639 int startRes = seq.findPosition(viewport.startRes);
2641 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2642 viewport.getAlignment()));
2644 viewport.setStartRes(seq.findIndex(startRes) - 1);
2646 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2658 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2660 viewport.setPadGaps(padGapsMenuitem.isSelected());
2661 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2672 public void findMenuItem_actionPerformed(ActionEvent e)
2678 * Create a new view of the current alignment.
2681 public void newView_actionPerformed(ActionEvent e)
2683 newView(null, true);
2687 * Creates and shows a new view of the current alignment.
2690 * title of newly created view; if null, one will be generated
2691 * @param copyAnnotation
2692 * if true then duplicate all annnotation, groups and settings
2693 * @return new alignment panel, already displayed.
2695 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2698 * Create a new AlignmentPanel (with its own, new Viewport)
2700 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2702 if (!copyAnnotation)
2705 * remove all groups and annotation except for the automatic stuff
2707 newap.av.getAlignment().deleteAllGroups();
2708 newap.av.getAlignment().deleteAllAnnotations(false);
2711 newap.av.setGatherViewsHere(false);
2713 if (viewport.viewName == null)
2715 viewport.viewName = MessageManager
2716 .getString("label.view_name_original");
2720 * Views share the same edits, undo and redo stacks, mappings.
2722 newap.av.setHistoryList(viewport.getHistoryList());
2723 newap.av.setRedoList(viewport.getRedoList());
2724 newap.av.getAlignment().setCodonFrames(
2725 viewport.getAlignment().getCodonFrames());
2727 newap.av.viewName = getNewViewName(viewTitle);
2729 addAlignmentPanel(newap, true);
2730 newap.alignmentChanged();
2732 if (alignPanels.size() == 2)
2734 viewport.setGatherViewsHere(true);
2736 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2741 * Make a new name for the view, ensuring it is unique within the current
2742 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2743 * these now use viewId. Unique view names are still desirable for usability.)
2748 protected String getNewViewName(String viewTitle)
2750 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2751 boolean addFirstIndex = false;
2752 if (viewTitle == null || viewTitle.trim().length() == 0)
2754 viewTitle = MessageManager.getString("action.view");
2755 addFirstIndex = true;
2759 index = 1;// we count from 1 if given a specific name
2761 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2763 List<Component> comps = PaintRefresher.components.get(viewport
2764 .getSequenceSetId());
2766 List<String> existingNames = getExistingViewNames(comps);
2768 while (existingNames.contains(newViewName))
2770 newViewName = viewTitle + " " + (++index);
2776 * Returns a list of distinct view names found in the given list of
2777 * components. View names are held on the viewport of an AlignmentPanel.
2782 protected List<String> getExistingViewNames(List<Component> comps)
2784 List<String> existingNames = new ArrayList<String>();
2785 for (Component comp : comps)
2787 if (comp instanceof AlignmentPanel)
2789 AlignmentPanel ap = (AlignmentPanel) comp;
2790 if (!existingNames.contains(ap.av.viewName))
2792 existingNames.add(ap.av.viewName);
2796 return existingNames;
2800 * Explode tabbed views into separate windows.
2803 public void expandViews_actionPerformed(ActionEvent e)
2805 Desktop.instance.explodeViews(this);
2809 * Gather views in separate windows back into a tabbed presentation.
2812 public void gatherViews_actionPerformed(ActionEvent e)
2814 Desktop.instance.gatherViews(this);
2824 public void font_actionPerformed(ActionEvent e)
2826 new FontChooser(alignPanel);
2836 protected void seqLimit_actionPerformed(ActionEvent e)
2838 viewport.setShowJVSuffix(seqLimits.isSelected());
2840 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2841 .calculateIdWidth());
2842 alignPanel.paintAlignment(true);
2846 public void idRightAlign_actionPerformed(ActionEvent e)
2848 viewport.setRightAlignIds(idRightAlign.isSelected());
2849 alignPanel.paintAlignment(true);
2853 public void centreColumnLabels_actionPerformed(ActionEvent e)
2855 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2856 alignPanel.paintAlignment(true);
2862 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2865 protected void followHighlight_actionPerformed()
2868 * Set the 'follow' flag on the Viewport (and scroll to position if now
2871 final boolean state = this.followHighlightMenuItem.getState();
2872 viewport.setFollowHighlight(state);
2875 alignPanel.scrollToPosition(
2876 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2887 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2889 viewport.setColourText(colourTextMenuItem.isSelected());
2890 alignPanel.paintAlignment(true);
2900 public void wrapMenuItem_actionPerformed(ActionEvent e)
2902 scaleAbove.setVisible(wrapMenuItem.isSelected());
2903 scaleLeft.setVisible(wrapMenuItem.isSelected());
2904 scaleRight.setVisible(wrapMenuItem.isSelected());
2905 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2906 alignPanel.updateLayout();
2910 public void showAllSeqs_actionPerformed(ActionEvent e)
2912 viewport.showAllHiddenSeqs();
2916 public void showAllColumns_actionPerformed(ActionEvent e)
2918 viewport.showAllHiddenColumns();
2923 public void hideSelSequences_actionPerformed(ActionEvent e)
2925 viewport.hideAllSelectedSeqs();
2926 // alignPanel.paintAlignment(true);
2930 * called by key handler and the hide all/show all menu items
2935 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2938 boolean hide = false;
2939 SequenceGroup sg = viewport.getSelectionGroup();
2940 if (!toggleSeqs && !toggleCols)
2942 // Hide everything by the current selection - this is a hack - we do the
2943 // invert and then hide
2944 // first check that there will be visible columns after the invert.
2945 if ((viewport.getColumnSelection() != null
2946 && viewport.getColumnSelection().getSelected() != null && viewport
2947 .getColumnSelection().getSelected().size() > 0)
2948 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2951 // now invert the sequence set, if required - empty selection implies
2952 // that no hiding is required.
2955 invertSequenceMenuItem_actionPerformed(null);
2956 sg = viewport.getSelectionGroup();
2960 viewport.expandColSelection(sg, true);
2961 // finally invert the column selection and get the new sequence
2963 invertColSel_actionPerformed(null);
2970 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2972 hideSelSequences_actionPerformed(null);
2975 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2978 showAllSeqs_actionPerformed(null);
2984 if (viewport.getColumnSelection().getSelected().size() > 0)
2986 hideSelColumns_actionPerformed(null);
2989 viewport.setSelectionGroup(sg);
2994 showAllColumns_actionPerformed(null);
3003 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3004 * event.ActionEvent)
3007 public void hideAllButSelection_actionPerformed(ActionEvent e)
3009 toggleHiddenRegions(false, false);
3016 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3020 public void hideAllSelection_actionPerformed(ActionEvent e)
3022 SequenceGroup sg = viewport.getSelectionGroup();
3023 viewport.expandColSelection(sg, false);
3024 viewport.hideAllSelectedSeqs();
3025 viewport.hideSelectedColumns();
3026 alignPanel.paintAlignment(true);
3033 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3037 public void showAllhidden_actionPerformed(ActionEvent e)
3039 viewport.showAllHiddenColumns();
3040 viewport.showAllHiddenSeqs();
3041 alignPanel.paintAlignment(true);
3045 public void hideSelColumns_actionPerformed(ActionEvent e)
3047 viewport.hideSelectedColumns();
3048 alignPanel.paintAlignment(true);
3052 public void hiddenMarkers_actionPerformed(ActionEvent e)
3054 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3065 protected void scaleAbove_actionPerformed(ActionEvent e)
3067 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3068 alignPanel.paintAlignment(true);
3078 protected void scaleLeft_actionPerformed(ActionEvent e)
3080 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3081 alignPanel.paintAlignment(true);
3091 protected void scaleRight_actionPerformed(ActionEvent e)
3093 viewport.setScaleRightWrapped(scaleRight.isSelected());
3094 alignPanel.paintAlignment(true);
3104 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3106 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3107 alignPanel.paintAlignment(true);
3117 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3119 viewport.setShowText(viewTextMenuItem.isSelected());
3120 alignPanel.paintAlignment(true);
3130 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3132 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3133 alignPanel.paintAlignment(true);
3136 public FeatureSettings featureSettings;
3139 public void featureSettings_actionPerformed(ActionEvent e)
3141 if (featureSettings != null)
3143 featureSettings.close();
3144 featureSettings = null;
3146 if (!showSeqFeatures.isSelected())
3148 // make sure features are actually displayed
3149 showSeqFeatures.setSelected(true);
3150 showSeqFeatures_actionPerformed(null);
3152 featureSettings = new FeatureSettings(this);
3156 * Set or clear 'Show Sequence Features'
3162 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3164 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3165 alignPanel.paintAlignment(true);
3166 if (alignPanel.getOverviewPanel() != null)
3168 alignPanel.getOverviewPanel().updateOverviewImage();
3173 * Set or clear 'Show Sequence Features'
3179 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3181 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3183 if (viewport.isShowSequenceFeaturesHeight())
3185 // ensure we're actually displaying features
3186 viewport.setShowSequenceFeatures(true);
3187 showSeqFeatures.setSelected(true);
3189 alignPanel.paintAlignment(true);
3190 if (alignPanel.getOverviewPanel() != null)
3192 alignPanel.getOverviewPanel().updateOverviewImage();
3197 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3198 * the annotations panel as a whole.
3200 * The options to show/hide all annotations should be enabled when the panel
3201 * is shown, and disabled when the panel is hidden.
3206 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3208 final boolean setVisible = annotationPanelMenuItem.isSelected();
3209 viewport.setShowAnnotation(setVisible);
3210 this.showAllSeqAnnotations.setEnabled(setVisible);
3211 this.hideAllSeqAnnotations.setEnabled(setVisible);
3212 this.showAllAlAnnotations.setEnabled(setVisible);
3213 this.hideAllAlAnnotations.setEnabled(setVisible);
3214 alignPanel.updateLayout();
3218 public void alignmentProperties()
3220 JEditorPane editPane = new JEditorPane("text/html", "");
3221 editPane.setEditable(false);
3222 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3224 editPane.setText(MessageManager.formatMessage("label.html_content",
3226 { contents.toString() }));
3227 JInternalFrame frame = new JInternalFrame();
3228 frame.getContentPane().add(new JScrollPane(editPane));
3230 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3231 "label.alignment_properties", new Object[]
3232 { getTitle() }), 500, 400);
3242 public void overviewMenuItem_actionPerformed(ActionEvent e)
3244 if (alignPanel.overviewPanel != null)
3249 JInternalFrame frame = new JInternalFrame();
3250 OverviewPanel overview = new OverviewPanel(alignPanel);
3251 frame.setContentPane(overview);
3252 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3253 "label.overview_params", new Object[]
3254 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3256 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3257 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3260 public void internalFrameClosed(
3261 javax.swing.event.InternalFrameEvent evt)
3263 alignPanel.setOverviewPanel(null);
3267 alignPanel.setOverviewPanel(overview);
3271 public void textColour_actionPerformed(ActionEvent e)
3273 new TextColourChooser().chooseColour(alignPanel, null);
3283 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3295 public void clustalColour_actionPerformed(ActionEvent e)
3297 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3298 viewport.getHiddenRepSequences()));
3308 public void zappoColour_actionPerformed(ActionEvent e)
3310 changeColour(new ZappoColourScheme());
3320 public void taylorColour_actionPerformed(ActionEvent e)
3322 changeColour(new TaylorColourScheme());
3332 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3334 changeColour(new HydrophobicColourScheme());
3344 public void helixColour_actionPerformed(ActionEvent e)
3346 changeColour(new HelixColourScheme());
3356 public void strandColour_actionPerformed(ActionEvent e)
3358 changeColour(new StrandColourScheme());
3368 public void turnColour_actionPerformed(ActionEvent e)
3370 changeColour(new TurnColourScheme());
3380 public void buriedColour_actionPerformed(ActionEvent e)
3382 changeColour(new BuriedColourScheme());
3392 public void nucleotideColour_actionPerformed(ActionEvent e)
3394 changeColour(new NucleotideColourScheme());
3398 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3400 changeColour(new PurinePyrimidineColourScheme());
3404 * public void covariationColour_actionPerformed(ActionEvent e) {
3406 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3410 public void annotationColour_actionPerformed(ActionEvent e)
3412 new AnnotationColourChooser(viewport, alignPanel);
3416 public void annotationColumn_actionPerformed(ActionEvent e)
3418 new AnnotationColumnChooser(viewport, alignPanel);
3422 public void rnahelicesColour_actionPerformed(ActionEvent e)
3424 new RNAHelicesColourChooser(viewport, alignPanel);
3434 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3436 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3445 public void changeColour(ColourSchemeI cs)
3447 // TODO: compare with applet and pull up to model method
3452 if (viewport.getAbovePIDThreshold())
3454 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3456 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3460 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3463 if (viewport.getConservationSelected())
3466 Alignment al = (Alignment) viewport.getAlignment();
3467 Conservation c = new Conservation("All",
3468 ResidueProperties.propHash, 3, al.getSequences(), 0,
3472 c.verdict(false, viewport.getConsPercGaps());
3474 cs.setConservation(c);
3476 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3481 cs.setConservation(null);
3484 cs.setConsensus(viewport.getSequenceConsensusHash());
3487 viewport.setGlobalColourScheme(cs);
3489 if (viewport.getColourAppliesToAllGroups())
3492 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3500 if (cs instanceof ClustalxColourScheme)
3502 sg.cs = new ClustalxColourScheme(sg,
3503 viewport.getHiddenRepSequences());
3505 else if (cs instanceof UserColourScheme)
3507 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3513 sg.cs = cs.getClass().newInstance();
3514 } catch (Exception ex)
3519 if (viewport.getAbovePIDThreshold()
3520 || cs instanceof PIDColourScheme
3521 || cs instanceof Blosum62ColourScheme)
3523 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3525 sg.cs.setConsensus(AAFrequency.calculate(
3526 sg.getSequences(viewport.getHiddenRepSequences()),
3527 sg.getStartRes(), sg.getEndRes() + 1));
3531 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3534 if (viewport.getConservationSelected())
3536 Conservation c = new Conservation("Group",
3537 ResidueProperties.propHash, 3, sg.getSequences(viewport
3538 .getHiddenRepSequences()), sg.getStartRes(),
3539 sg.getEndRes() + 1);
3541 c.verdict(false, viewport.getConsPercGaps());
3542 sg.cs.setConservation(c);
3546 sg.cs.setConservation(null);
3551 if (alignPanel.getOverviewPanel() != null)
3553 alignPanel.getOverviewPanel().updateOverviewImage();
3556 alignPanel.paintAlignment(true);
3566 protected void modifyPID_actionPerformed(ActionEvent e)
3568 if (viewport.getAbovePIDThreshold()
3569 && viewport.getGlobalColourScheme() != null)
3571 SliderPanel.setPIDSliderSource(alignPanel,
3572 viewport.getGlobalColourScheme(), "Background");
3573 SliderPanel.showPIDSlider();
3584 protected void modifyConservation_actionPerformed(ActionEvent e)
3586 if (viewport.getConservationSelected()
3587 && viewport.getGlobalColourScheme() != null)
3589 SliderPanel.setConservationSlider(alignPanel,
3590 viewport.getGlobalColourScheme(), "Background");
3591 SliderPanel.showConservationSlider();
3602 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3604 viewport.setConservationSelected(conservationMenuItem.isSelected());
3606 viewport.setAbovePIDThreshold(false);
3607 abovePIDThreshold.setSelected(false);
3609 changeColour(viewport.getGlobalColourScheme());
3611 modifyConservation_actionPerformed(null);
3621 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3623 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3625 conservationMenuItem.setSelected(false);
3626 viewport.setConservationSelected(false);
3628 changeColour(viewport.getGlobalColourScheme());
3630 modifyPID_actionPerformed(null);
3640 public void userDefinedColour_actionPerformed(ActionEvent e)
3642 if (e.getActionCommand().equals(
3643 MessageManager.getString("action.user_defined")))
3645 new UserDefinedColours(alignPanel, null);
3649 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3650 .getUserColourSchemes().get(e.getActionCommand());
3656 public void updateUserColourMenu()
3659 Component[] menuItems = colourMenu.getMenuComponents();
3660 int iSize = menuItems.length;
3661 for (int i = 0; i < iSize; i++)
3663 if (menuItems[i].getName() != null
3664 && menuItems[i].getName().equals("USER_DEFINED"))
3666 colourMenu.remove(menuItems[i]);
3670 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3672 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3673 .getUserColourSchemes().keys();
3675 while (userColours.hasMoreElements())
3677 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3678 userColours.nextElement().toString());
3679 radioItem.setName("USER_DEFINED");
3680 radioItem.addMouseListener(new MouseAdapter()
3683 public void mousePressed(MouseEvent evt)
3685 if (evt.isControlDown()
3686 || SwingUtilities.isRightMouseButton(evt))
3688 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3690 int option = JOptionPane.showInternalConfirmDialog(
3691 jalview.gui.Desktop.desktop,
3693 .getString("label.remove_from_default_list"),
3695 .getString("label.remove_user_defined_colour"),
3696 JOptionPane.YES_NO_OPTION);
3697 if (option == JOptionPane.YES_OPTION)
3699 jalview.gui.UserDefinedColours
3700 .removeColourFromDefaults(radioItem.getText());
3701 colourMenu.remove(radioItem);
3705 radioItem.addActionListener(new ActionListener()
3708 public void actionPerformed(ActionEvent evt)
3710 userDefinedColour_actionPerformed(evt);
3717 radioItem.addActionListener(new ActionListener()
3720 public void actionPerformed(ActionEvent evt)
3722 userDefinedColour_actionPerformed(evt);
3726 colourMenu.insert(radioItem, 15);
3727 colours.add(radioItem);
3739 public void PIDColour_actionPerformed(ActionEvent e)
3741 changeColour(new PIDColourScheme());
3751 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3753 changeColour(new Blosum62ColourScheme());
3763 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3765 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3766 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3767 .getAlignment().getSequenceAt(0), null);
3768 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3769 viewport.getAlignment()));
3770 alignPanel.paintAlignment(true);
3780 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3782 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3783 AlignmentSorter.sortByID(viewport.getAlignment());
3784 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3785 viewport.getAlignment()));
3786 alignPanel.paintAlignment(true);
3796 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3798 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3799 AlignmentSorter.sortByLength(viewport.getAlignment());
3800 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3801 viewport.getAlignment()));
3802 alignPanel.paintAlignment(true);
3812 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3814 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3815 AlignmentSorter.sortByGroup(viewport.getAlignment());
3816 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3817 viewport.getAlignment()));
3819 alignPanel.paintAlignment(true);
3829 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3831 new RedundancyPanel(alignPanel, this);
3841 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3843 if ((viewport.getSelectionGroup() == null)
3844 || (viewport.getSelectionGroup().getSize() < 2))
3846 JOptionPane.showInternalMessageDialog(this, MessageManager
3847 .getString("label.you_must_select_least_two_sequences"),
3848 MessageManager.getString("label.invalid_selection"),
3849 JOptionPane.WARNING_MESSAGE);
3853 JInternalFrame frame = new JInternalFrame();
3854 frame.setContentPane(new PairwiseAlignPanel(viewport));
3855 Desktop.addInternalFrame(frame,
3856 MessageManager.getString("action.pairwise_alignment"), 600,
3868 public void PCAMenuItem_actionPerformed(ActionEvent e)
3870 if (((viewport.getSelectionGroup() != null)
3871 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3872 .getSelectionGroup().getSize() > 0))
3873 || (viewport.getAlignment().getHeight() < 4))
3876 .showInternalMessageDialog(
3879 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3881 .getString("label.sequence_selection_insufficient"),
3882 JOptionPane.WARNING_MESSAGE);
3887 new PCAPanel(alignPanel);
3891 public void autoCalculate_actionPerformed(ActionEvent e)
3893 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3894 if (viewport.autoCalculateConsensus)
3896 viewport.firePropertyChange("alignment", null, viewport
3897 .getAlignment().getSequences());
3902 public void sortByTreeOption_actionPerformed(ActionEvent e)
3904 viewport.sortByTree = sortByTree.isSelected();
3908 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3910 viewport.followSelection = listenToViewSelections.isSelected();
3920 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3922 newTreePanel("AV", "PID", "Average distance tree using PID");
3932 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3934 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3944 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3946 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3956 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3958 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3971 void newTreePanel(String type, String pwType, String title)
3975 if (viewport.getSelectionGroup() != null
3976 && viewport.getSelectionGroup().getSize() > 0)
3978 if (viewport.getSelectionGroup().getSize() < 3)
3984 .getString("label.you_need_more_two_sequences_selected_build_tree"),
3986 .getString("label.not_enough_sequences"),
3987 JOptionPane.WARNING_MESSAGE);
3991 SequenceGroup sg = viewport.getSelectionGroup();
3993 /* Decide if the selection is a column region */
3994 for (SequenceI _s : sg.getSequences())
3996 if (_s.getLength() < sg.getEndRes())
4002 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4004 .getString("label.sequences_selection_not_aligned"),
4005 JOptionPane.WARNING_MESSAGE);
4011 title = title + " on region";
4012 tp = new TreePanel(alignPanel, type, pwType);
4016 // are the visible sequences aligned?
4017 if (!viewport.getAlignment().isAligned(false))
4023 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4025 .getString("label.sequences_not_aligned"),
4026 JOptionPane.WARNING_MESSAGE);
4031 if (viewport.getAlignment().getHeight() < 2)
4036 tp = new TreePanel(alignPanel, type, pwType);
4041 if (viewport.viewName != null)
4043 title += viewport.viewName + " of ";
4046 title += this.title;
4048 Desktop.addInternalFrame(tp, title, 600, 500);
4059 public void addSortByOrderMenuItem(String title,
4060 final AlignmentOrder order)
4062 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4064 item.addActionListener(new java.awt.event.ActionListener()
4067 public void actionPerformed(ActionEvent e)
4069 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4071 // TODO: JBPNote - have to map order entries to curent SequenceI
4073 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4075 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4078 alignPanel.paintAlignment(true);
4084 * Add a new sort by annotation score menu item
4087 * the menu to add the option to
4089 * the label used to retrieve scores for each sequence on the
4092 public void addSortByAnnotScoreMenuItem(JMenu sort,
4093 final String scoreLabel)
4095 final JMenuItem item = new JMenuItem(scoreLabel);
4097 item.addActionListener(new java.awt.event.ActionListener()
4100 public void actionPerformed(ActionEvent e)
4102 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4103 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4104 viewport.getAlignment());// ,viewport.getSelectionGroup());
4105 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4106 viewport.getAlignment()));
4107 alignPanel.paintAlignment(true);
4113 * last hash for alignment's annotation array - used to minimise cost of
4116 protected int _annotationScoreVectorHash;
4119 * search the alignment and rebuild the sort by annotation score submenu the
4120 * last alignment annotation vector hash is stored to minimize cost of
4121 * rebuilding in subsequence calls.
4125 public void buildSortByAnnotationScoresMenu()
4127 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4132 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4134 sortByAnnotScore.removeAll();
4135 // almost certainly a quicker way to do this - but we keep it simple
4136 Hashtable scoreSorts = new Hashtable();
4137 AlignmentAnnotation aann[];
4138 for (SequenceI sqa : viewport.getAlignment().getSequences())
4140 aann = sqa.getAnnotation();
4141 for (int i = 0; aann != null && i < aann.length; i++)
4143 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4145 scoreSorts.put(aann[i].label, aann[i].label);
4149 Enumeration labels = scoreSorts.keys();
4150 while (labels.hasMoreElements())
4152 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4153 (String) labels.nextElement());
4155 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4158 _annotationScoreVectorHash = viewport.getAlignment()
4159 .getAlignmentAnnotation().hashCode();
4164 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4165 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4166 * call. Listeners are added to remove the menu item when the treePanel is
4167 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4171 * Displayed tree window.
4173 * SortBy menu item title.
4176 public void buildTreeMenu()
4178 calculateTree.removeAll();
4179 // build the calculate menu
4181 for (final String type : new String[]
4184 String treecalcnm = MessageManager.getString("label.tree_calc_"
4185 + type.toLowerCase());
4186 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4188 JMenuItem tm = new JMenuItem();
4189 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4190 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4192 String smn = MessageManager.getStringOrReturn(
4193 "label.score_model_", sm.getName());
4194 final String title = MessageManager.formatMessage(
4195 "label.treecalc_title", treecalcnm, smn);
4196 tm.setText(title);//
4197 tm.addActionListener(new java.awt.event.ActionListener()
4200 public void actionPerformed(ActionEvent e)
4202 newTreePanel(type, pwtype, title);
4205 calculateTree.add(tm);
4210 sortByTreeMenu.removeAll();
4212 List<Component> comps = PaintRefresher.components.get(viewport
4213 .getSequenceSetId());
4214 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4215 for (Component comp : comps)
4217 if (comp instanceof TreePanel)
4219 treePanels.add((TreePanel) comp);
4223 if (treePanels.size() < 1)
4225 sortByTreeMenu.setVisible(false);
4229 sortByTreeMenu.setVisible(true);
4231 for (final TreePanel tp : treePanels)
4233 final JMenuItem item = new JMenuItem(tp.getTitle());
4234 item.addActionListener(new java.awt.event.ActionListener()
4237 public void actionPerformed(ActionEvent e)
4239 tp.sortByTree_actionPerformed();
4240 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4245 sortByTreeMenu.add(item);
4249 public boolean sortBy(AlignmentOrder alorder, String undoname)
4251 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4252 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4253 if (undoname != null)
4255 addHistoryItem(new OrderCommand(undoname, oldOrder,
4256 viewport.getAlignment()));
4258 alignPanel.paintAlignment(true);
4263 * Work out whether the whole set of sequences or just the selected set will
4264 * be submitted for multiple alignment.
4267 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4269 // Now, check we have enough sequences
4270 AlignmentView msa = null;
4272 if ((viewport.getSelectionGroup() != null)
4273 && (viewport.getSelectionGroup().getSize() > 1))
4275 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4276 // some common interface!
4278 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4279 * SequenceI[sz = seqs.getSize(false)];
4281 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4282 * seqs.getSequenceAt(i); }
4284 msa = viewport.getAlignmentView(true);
4286 else if (viewport.getSelectionGroup() != null
4287 && viewport.getSelectionGroup().getSize() == 1)
4289 int option = JOptionPane.showConfirmDialog(this,
4290 MessageManager.getString("warn.oneseq_msainput_selection"),
4291 MessageManager.getString("label.invalid_selection"),
4292 JOptionPane.OK_CANCEL_OPTION);
4293 if (option == JOptionPane.OK_OPTION)
4295 msa = viewport.getAlignmentView(false);
4300 msa = viewport.getAlignmentView(false);
4306 * Decides what is submitted to a secondary structure prediction service: the
4307 * first sequence in the alignment, or in the current selection, or, if the
4308 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4309 * region or the whole alignment. (where the first sequence in the set is the
4310 * one that the prediction will be for).
4312 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4314 AlignmentView seqs = null;
4316 if ((viewport.getSelectionGroup() != null)
4317 && (viewport.getSelectionGroup().getSize() > 0))
4319 seqs = viewport.getAlignmentView(true);
4323 seqs = viewport.getAlignmentView(false);
4325 // limit sequences - JBPNote in future - could spawn multiple prediction
4327 // TODO: viewport.getAlignment().isAligned is a global state - the local
4328 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4329 if (!viewport.getAlignment().isAligned(false))
4331 seqs.setSequences(new SeqCigar[]
4332 { seqs.getSequences()[0] });
4333 // TODO: if seqs.getSequences().length>1 then should really have warned
4347 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4349 // Pick the tree file
4350 JalviewFileChooser chooser = new JalviewFileChooser(
4351 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4352 chooser.setFileView(new JalviewFileView());
4353 chooser.setDialogTitle(MessageManager
4354 .getString("label.select_newick_like_tree_file"));
4355 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4357 int value = chooser.showOpenDialog(null);
4359 if (value == JalviewFileChooser.APPROVE_OPTION)
4361 String choice = chooser.getSelectedFile().getPath();
4362 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4363 jalview.io.NewickFile fin = null;
4366 fin = new jalview.io.NewickFile(choice, "File");
4367 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4368 } catch (Exception ex)
4375 .getString("label.problem_reading_tree_file"),
4376 JOptionPane.WARNING_MESSAGE);
4377 ex.printStackTrace();
4379 if (fin != null && fin.hasWarningMessage())
4381 JOptionPane.showMessageDialog(Desktop.desktop, fin
4382 .getWarningMessage(), MessageManager
4383 .getString("label.possible_problem_with_tree_file"),
4384 JOptionPane.WARNING_MESSAGE);
4390 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4392 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4395 public TreePanel ShowNewickTree(NewickFile nf, String title)
4397 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4400 public TreePanel ShowNewickTree(NewickFile nf, String title,
4401 AlignmentView input)
4403 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4406 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4407 int h, int x, int y)
4409 return ShowNewickTree(nf, title, null, w, h, x, y);
4413 * Add a treeviewer for the tree extracted from a newick file object to the
4414 * current alignment view
4421 * Associated alignment input data (or null)
4430 * @return TreePanel handle
4432 public TreePanel ShowNewickTree(NewickFile nf, String title,
4433 AlignmentView input, int w, int h, int x, int y)
4435 TreePanel tp = null;
4441 if (nf.getTree() != null)
4443 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4449 tp.setLocation(x, y);
4452 Desktop.addInternalFrame(tp, title, w, h);
4454 } catch (Exception ex)
4456 ex.printStackTrace();
4462 private boolean buildingMenu = false;
4465 * Generates menu items and listener event actions for web service clients
4468 public void BuildWebServiceMenu()
4470 while (buildingMenu)
4474 System.err.println("Waiting for building menu to finish.");
4476 } catch (Exception e)
4480 final AlignFrame me = this;
4481 buildingMenu = true;
4482 new Thread(new Runnable()
4487 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4490 System.err.println("Building ws menu again "
4491 + Thread.currentThread());
4492 // TODO: add support for context dependent disabling of services based
4494 // alignment and current selection
4495 // TODO: add additional serviceHandle parameter to specify abstract
4497 // class independently of AbstractName
4498 // TODO: add in rediscovery GUI function to restart discoverer
4499 // TODO: group services by location as well as function and/or
4501 // object broker mechanism.
4502 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4503 final IProgressIndicator af = me;
4504 final JMenu msawsmenu = new JMenu("Alignment");
4505 final JMenu secstrmenu = new JMenu(
4506 "Secondary Structure Prediction");
4507 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4508 final JMenu analymenu = new JMenu("Analysis");
4509 final JMenu dismenu = new JMenu("Protein Disorder");
4510 // final JMenu msawsmenu = new
4511 // JMenu(MessageManager.getString("label.alignment"));
4512 // final JMenu secstrmenu = new
4513 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4514 // final JMenu seqsrchmenu = new
4515 // JMenu(MessageManager.getString("label.sequence_database_search"));
4516 // final JMenu analymenu = new
4517 // JMenu(MessageManager.getString("label.analysis"));
4518 // final JMenu dismenu = new
4519 // JMenu(MessageManager.getString("label.protein_disorder"));
4520 // JAL-940 - only show secondary structure prediction services from
4521 // the legacy server
4522 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4524 Discoverer.services != null && (Discoverer.services.size() > 0))
4526 // TODO: refactor to allow list of AbstractName/Handler bindings to
4528 // stored or retrieved from elsewhere
4529 // No MSAWS used any more:
4530 // Vector msaws = null; // (Vector)
4531 // Discoverer.services.get("MsaWS");
4532 Vector secstrpr = (Vector) Discoverer.services
4534 if (secstrpr != null)
4536 // Add any secondary structure prediction services
4537 for (int i = 0, j = secstrpr.size(); i < j; i++)
4539 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4541 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4542 .getServiceClient(sh);
4543 int p = secstrmenu.getItemCount();
4544 impl.attachWSMenuEntry(secstrmenu, me);
4545 int q = secstrmenu.getItemCount();
4546 for (int litm = p; litm < q; litm++)
4548 legacyItems.add(secstrmenu.getItem(litm));
4554 // Add all submenus in the order they should appear on the web
4556 wsmenu.add(msawsmenu);
4557 wsmenu.add(secstrmenu);
4558 wsmenu.add(dismenu);
4559 wsmenu.add(analymenu);
4560 // No search services yet
4561 // wsmenu.add(seqsrchmenu);
4563 javax.swing.SwingUtilities.invokeLater(new Runnable()
4570 webService.removeAll();
4571 // first, add discovered services onto the webservices menu
4572 if (wsmenu.size() > 0)
4574 for (int i = 0, j = wsmenu.size(); i < j; i++)
4576 webService.add(wsmenu.get(i));
4581 webService.add(me.webServiceNoServices);
4583 // TODO: move into separate menu builder class.
4584 boolean new_sspred = false;
4585 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4587 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4588 if (jws2servs != null)
4590 if (jws2servs.hasServices())
4592 jws2servs.attachWSMenuEntry(webService, me);
4593 for (Jws2Instance sv : jws2servs.getServices())
4595 if (sv.description.toLowerCase().contains("jpred"))
4597 for (JMenuItem jmi : legacyItems)
4599 jmi.setVisible(false);
4605 if (jws2servs.isRunning())
4607 JMenuItem tm = new JMenuItem(
4608 "Still discovering JABA Services");
4609 tm.setEnabled(false);
4614 build_urlServiceMenu(me.webService);
4615 build_fetchdbmenu(webService);
4616 for (JMenu item : wsmenu)
4618 if (item.getItemCount() == 0)
4620 item.setEnabled(false);
4624 item.setEnabled(true);
4627 } catch (Exception e)
4630 .debug("Exception during web service menu building process.",
4635 } catch (Exception e)
4638 buildingMenu = false;
4645 * construct any groupURL type service menu entries.
4649 private void build_urlServiceMenu(JMenu webService)
4651 // TODO: remove this code when 2.7 is released
4652 // DEBUG - alignmentView
4654 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4655 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4657 * @Override public void actionPerformed(ActionEvent e) {
4658 * jalview.datamodel.AlignmentView
4659 * .testSelectionViews(af.viewport.getAlignment(),
4660 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4662 * }); webService.add(testAlView);
4664 // TODO: refactor to RestClient discoverer and merge menu entries for
4665 // rest-style services with other types of analysis/calculation service
4666 // SHmmr test client - still being implemented.
4667 // DEBUG - alignmentView
4669 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4672 client.attachWSMenuEntry(
4673 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4679 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4680 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4681 * getProperty("LAST_DIRECTORY"));
4683 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4684 * to Vamsas file"); chooser.setToolTipText("Export");
4686 * int value = chooser.showSaveDialog(this);
4688 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4689 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4690 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4691 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4694 * prototype of an automatically enabled/disabled analysis function
4697 protected void setShowProductsEnabled()
4699 SequenceI[] selection = viewport.getSequenceSelection();
4700 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4701 viewport.getAlignment().getDataset()))
4703 showProducts.setEnabled(true);
4708 showProducts.setEnabled(false);
4713 * search selection for sequence xRef products and build the show products
4718 * @return true if showProducts menu should be enabled.
4720 public boolean canShowProducts(SequenceI[] selection,
4721 boolean isRegionSelection, Alignment dataset)
4723 boolean showp = false;
4726 showProducts.removeAll();
4727 final boolean dna = viewport.getAlignment().isNucleotide();
4728 final Alignment ds = dataset;
4729 String[] ptypes = (selection == null || selection.length == 0) ? null
4730 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4732 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4733 // selection, dataset, true);
4734 final SequenceI[] sel = selection;
4735 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4738 final boolean isRegSel = isRegionSelection;
4739 final AlignFrame af = this;
4740 final String source = ptypes[t];
4741 JMenuItem xtype = new JMenuItem(ptypes[t]);
4742 xtype.addActionListener(new ActionListener()
4746 public void actionPerformed(ActionEvent e)
4748 // TODO: new thread for this call with vis-delay
4749 af.showProductsFor(af.viewport.getSequenceSelection(),
4750 isRegSel, dna, source);
4754 showProducts.add(xtype);
4756 showProducts.setVisible(showp);
4757 showProducts.setEnabled(showp);
4758 } catch (Exception e)
4760 jalview.bin.Cache.log
4761 .warn("canTranslate threw an exception - please report to help@jalview.org",
4768 protected void showProductsFor(final SequenceI[] sel,
4769 final boolean isRegSel, final boolean dna, final String source)
4771 Runnable foo = new Runnable()
4777 final long sttime = System.currentTimeMillis();
4778 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4779 "status.searching_for_sequences_from", new Object[]
4780 { source }), sttime);
4783 // update our local dataset reference
4784 Alignment ds = AlignFrame.this.getViewport().getAlignment()
4786 Alignment prods = CrossRef
4787 .findXrefSequences(sel, dna, source, ds);
4790 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4791 for (int s = 0; s < sprods.length; s++)
4793 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4794 if (ds.getSequences() == null
4795 || !ds.getSequences().contains(
4796 sprods[s].getDatasetSequence()))
4798 ds.addSequence(sprods[s].getDatasetSequence());
4800 sprods[s].updatePDBIds();
4802 Alignment al = new Alignment(sprods);
4806 * Copy dna-to-protein mappings to new alignment
4808 // TODO 1: no mappings are set up for EMBL product
4809 // TODO 2: if they were, should add them to protein alignment, not
4811 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4812 for (AlignedCodonFrame acf : cf)
4814 al.addCodonFrame(acf);
4816 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4818 String newtitle = "" + ((dna) ? "Proteins" : "Nucleotides")
4819 + " for " + ((isRegSel) ? "selected region of " : "")
4821 naf.setTitle(newtitle);
4823 // temporary flag until SplitFrame is released
4824 boolean asSplitFrame = Cache.getDefault(
4825 Preferences.ENABLE_SPLIT_FRAME, false);
4829 * Make a copy of this alignment (sharing the same dataset
4830 * sequences). If we are DNA, drop introns and update mappings
4832 AlignmentI copyAlignment = null;
4833 final SequenceI[] sequenceSelection = AlignFrame.this.viewport
4834 .getSequenceSelection();
4837 copyAlignment = AlignmentUtils.makeExonAlignment(
4838 sequenceSelection, cf);
4839 al.getCodonFrames().clear();
4840 al.getCodonFrames().addAll(cf);
4841 final StructureSelectionManager ssm = StructureSelectionManager
4842 .getStructureSelectionManager(Desktop.instance);
4843 ssm.addMappings(cf);
4847 copyAlignment = new Alignment(new Alignment(
4848 sequenceSelection));
4850 AlignFrame copyThis = new AlignFrame(copyAlignment,
4851 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
4852 copyThis.setTitle(AlignFrame.this.getTitle());
4853 // SplitFrame with dna above, protein below
4854 SplitFrame sf = new SplitFrame(dna ? copyThis : naf,
4855 dna ? naf : copyThis);
4856 naf.setVisible(true);
4857 copyThis.setVisible(true);
4858 String linkedTitle = MessageManager
4859 .getString("label.linked_view_title");
4860 Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
4864 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4870 System.err.println("No Sequences generated for xRef type "
4873 } catch (Exception e)
4875 jalview.bin.Cache.log.error(
4876 "Exception when finding crossreferences", e);
4877 } catch (OutOfMemoryError e)
4879 new OOMWarning("whilst fetching crossreferences", e);
4882 jalview.bin.Cache.log.error("Error when finding crossreferences",
4885 AlignFrame.this.setProgressBar(MessageManager.formatMessage(
4886 "status.finished_searching_for_sequences_from",
4893 Thread frunner = new Thread(foo);
4897 public boolean canShowTranslationProducts(SequenceI[] selection,
4898 AlignmentI alignment)
4903 return (jalview.analysis.Dna.canTranslate(selection,
4904 viewport.getViewAsVisibleContigs(true)));
4905 } catch (Exception e)
4907 jalview.bin.Cache.log
4908 .warn("canTranslate threw an exception - please report to help@jalview.org",
4915 * Construct and display a new frame containing the translation of this
4916 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4919 public void showTranslation_actionPerformed(ActionEvent e)
4921 AlignmentI al = null;
4924 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4926 al = dna.translateCdna();
4927 } catch (Exception ex)
4929 jalview.bin.Cache.log.error(
4930 "Exception during translation. Please report this !", ex);
4931 final String msg = MessageManager
4932 .getString("label.error_when_translating_sequences_submit_bug_report");
4933 final String title = MessageManager
4934 .getString("label.implementation_error")
4935 + MessageManager.getString("translation_failed");
4936 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4937 JOptionPane.ERROR_MESSAGE);
4940 if (al == null || al.getHeight() == 0)
4942 final String msg = MessageManager
4943 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4944 final String title = MessageManager
4945 .getString("label.translation_failed");
4946 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4947 JOptionPane.WARNING_MESSAGE);
4951 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4952 af.setFileFormat(this.currentFileFormat);
4953 final String newTitle = MessageManager.formatMessage(
4954 "label.translation_of_params", new Object[]
4955 { this.getTitle() });
4956 af.setTitle(newTitle);
4957 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
4959 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4960 viewport.openSplitFrame(af, new Alignment(seqs),
4961 al.getCodonFrames());
4965 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4972 * Set the file format
4976 public void setFileFormat(String fileFormat)
4978 this.currentFileFormat = fileFormat;
4982 * Try to load a features file onto the alignment.
4985 * contents or path to retrieve file
4987 * access mode of file (see jalview.io.AlignFile)
4988 * @return true if features file was parsed corectly.
4990 public boolean parseFeaturesFile(String file, String type)
4992 boolean featuresFile = false;
4995 featuresFile = new FeaturesFile(file, type).parse(viewport
4996 .getAlignment().getDataset(), alignPanel.getSeqPanel().seqCanvas
4997 .getFeatureRenderer().getFeatureColours(), false,
4998 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4999 } catch (Exception ex)
5001 ex.printStackTrace();
5006 viewport.setShowSequenceFeatures(true);
5007 showSeqFeatures.setSelected(true);
5008 if (alignPanel.getSeqPanel().seqCanvas.fr != null)
5010 // update the min/max ranges where necessary
5011 alignPanel.getSeqPanel().seqCanvas.fr.findAllFeatures(true);
5013 if (featureSettings != null)
5015 featureSettings.setTableData();
5017 alignPanel.paintAlignment(true);
5020 return featuresFile;
5024 public void dragEnter(DropTargetDragEvent evt)
5029 public void dragExit(DropTargetEvent evt)
5034 public void dragOver(DropTargetDragEvent evt)
5039 public void dropActionChanged(DropTargetDragEvent evt)
5044 public void drop(DropTargetDropEvent evt)
5046 Transferable t = evt.getTransferable();
5047 java.util.List files = null;
5051 DataFlavor uriListFlavor = new DataFlavor(
5052 "text/uri-list;class=java.lang.String");
5053 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5055 // Works on Windows and MacOSX
5056 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5057 files = (java.util.List) t
5058 .getTransferData(DataFlavor.javaFileListFlavor);
5060 else if (t.isDataFlavorSupported(uriListFlavor))
5062 // This is used by Unix drag system
5063 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5064 String data = (String) t.getTransferData(uriListFlavor);
5065 files = new java.util.ArrayList(1);
5066 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5067 data, "\r\n"); st.hasMoreTokens();)
5069 String s = st.nextToken();
5070 if (s.startsWith("#"))
5072 // the line is a comment (as per the RFC 2483)
5076 java.net.URI uri = new java.net.URI(s);
5077 // check to see if we can handle this kind of URI
5078 if (uri.getScheme().toLowerCase().startsWith("http"))
5080 files.add(uri.toString());
5084 // otherwise preserve old behaviour: catch all for file objects
5085 java.io.File file = new java.io.File(uri);
5086 files.add(file.toString());
5090 } catch (Exception e)
5092 e.printStackTrace();
5098 // check to see if any of these files have names matching sequences in
5100 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5101 .getAlignment().getSequencesArray());
5103 * Object[] { String,SequenceI}
5105 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5106 ArrayList<String> filesnotmatched = new ArrayList<String>();
5107 for (int i = 0; i < files.size(); i++)
5109 String file = files.get(i).toString();
5111 String protocol = FormatAdapter.checkProtocol(file);
5112 if (protocol == jalview.io.FormatAdapter.FILE)
5114 File fl = new File(file);
5115 pdbfn = fl.getName();
5117 else if (protocol == jalview.io.FormatAdapter.URL)
5119 URL url = new URL(file);
5120 pdbfn = url.getFile();
5122 if (pdbfn.length() > 0)
5124 // attempt to find a match in the alignment
5125 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5126 int l = 0, c = pdbfn.indexOf(".");
5127 while (mtch == null && c != -1)
5132 } while ((c = pdbfn.indexOf(".", l)) > l);
5135 pdbfn = pdbfn.substring(0, l);
5137 mtch = idm.findAllIdMatches(pdbfn);
5144 type = new IdentifyFile().Identify(file, protocol);
5145 } catch (Exception ex)
5151 if (type.equalsIgnoreCase("PDB"))
5153 filesmatched.add(new Object[]
5154 { file, protocol, mtch });
5159 // File wasn't named like one of the sequences or wasn't a PDB file.
5160 filesnotmatched.add(file);
5164 if (filesmatched.size() > 0)
5166 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5172 "label.automatically_associate_pdb_files_with_sequences_same_name",
5179 .getString("label.automatically_associate_pdb_files_by_name"),
5180 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5183 for (Object[] fm : filesmatched)
5185 // try and associate
5186 // TODO: may want to set a standard ID naming formalism for
5187 // associating PDB files which have no IDs.
5188 for (SequenceI toassoc : (SequenceI[]) fm[2])
5190 PDBEntry pe = new AssociatePdbFileWithSeq()
5191 .associatePdbWithSeq((String) fm[0],
5192 (String) fm[1], toassoc, false,
5196 System.err.println("Associated file : "
5197 + ((String) fm[0]) + " with "
5198 + toassoc.getDisplayId(true));
5202 alignPanel.paintAlignment(true);
5206 if (filesnotmatched.size() > 0)
5209 && (Cache.getDefault(
5210 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5213 "<html>"+MessageManager
5215 "label.ignore_unmatched_dropped_files_info",
5220 .toString() })+"</html>",
5222 .getString("label.ignore_unmatched_dropped_files"),
5223 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5227 for (String fn : filesnotmatched)
5229 loadJalviewDataFile(fn, null, null, null);
5233 } catch (Exception ex)
5235 ex.printStackTrace();
5241 * Attempt to load a "dropped" file or URL string: First by testing whether
5242 * it's and Annotation file, then a JNet file, and finally a features file. If
5243 * all are false then the user may have dropped an alignment file onto this
5247 * either a filename or a URL string.
5249 public void loadJalviewDataFile(String file, String protocol,
5250 String format, SequenceI assocSeq)
5254 if (protocol == null)
5256 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5258 // if the file isn't identified, or not positively identified as some
5259 // other filetype (PFAM is default unidentified alignment file type) then
5260 // try to parse as annotation.
5261 boolean isAnnotation = (format == null || format
5262 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5263 .annotateAlignmentView(viewport, file, protocol)
5268 // first see if its a T-COFFEE score file
5269 TCoffeeScoreFile tcf = null;
5272 tcf = new TCoffeeScoreFile(file, protocol);
5275 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5277 tcoffeeColour.setEnabled(true);
5278 tcoffeeColour.setSelected(true);
5279 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5280 isAnnotation = true;
5282 .setText(MessageManager
5283 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5287 // some problem - if no warning its probable that the ID matching
5288 // process didn't work
5292 tcf.getWarningMessage() == null ? MessageManager
5293 .getString("label.check_file_matches_sequence_ids_alignment")
5294 : tcf.getWarningMessage(),
5296 .getString("label.problem_reading_tcoffee_score_file"),
5297 JOptionPane.WARNING_MESSAGE);
5304 } catch (Exception x)
5307 .debug("Exception when processing data source as T-COFFEE score file",
5313 // try to see if its a JNet 'concise' style annotation file *before*
5315 // try to parse it as a features file
5318 format = new IdentifyFile().Identify(file, protocol);
5320 if (format.equalsIgnoreCase("JnetFile"))
5322 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5324 new JnetAnnotationMaker();
5325 JnetAnnotationMaker.add_annotation(predictions,
5326 viewport.getAlignment(), 0, false);
5327 SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
5328 viewport.getAlignment().setSeqrep(repseq);
5329 ColumnSelection cs = new ColumnSelection();
5330 cs.hideInsertionsFor(repseq);
5331 viewport.setColumnSelection(cs);
5332 isAnnotation = true;
5337 * if (format.equalsIgnoreCase("PDB")) {
5339 * String pdbfn = ""; // try to match up filename with sequence id
5340 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5341 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5342 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5343 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5344 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5345 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5346 * // attempt to find a match in the alignment SequenceI mtch =
5347 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5348 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5349 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5350 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5351 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5352 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5353 * { System.err.println("Associated file : " + file + " with " +
5354 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5355 * TODO: maybe need to load as normal otherwise return; } }
5357 // try to parse it as a features file
5358 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5359 // if it wasn't a features file then we just treat it as a general
5360 // alignment file to load into the current view.
5363 new FileLoader().LoadFile(viewport, file, protocol, format);
5367 alignPanel.paintAlignment(true);
5375 alignPanel.adjustAnnotationHeight();
5376 viewport.updateSequenceIdColours();
5377 buildSortByAnnotationScoresMenu();
5378 alignPanel.paintAlignment(true);
5380 } catch (Exception ex)
5382 ex.printStackTrace();
5383 } catch (OutOfMemoryError oom)
5388 } catch (Exception x)
5394 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5395 : "using " + protocol + " from " + file)
5397 + (format != null ? "(parsing as '" + format
5398 + "' file)" : ""), oom, Desktop.desktop);
5403 * Method invoked by the ChangeListener on the tabbed pane, in other words
5404 * when a different tabbed pane is selected by the user or programmatically.
5407 public void tabSelectionChanged(int index)
5411 alignPanel = alignPanels.get(index);
5412 viewport = alignPanel.av;
5413 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5414 setMenusFromViewport(viewport);
5418 * If there is a frame linked to this one in a SplitPane, switch it to the
5419 * same view tab index. No infinite recursion of calls should happen, since
5420 * tabSelectionChanged() should not get invoked on setting the selected
5421 * index to an unchanged value. Guard against setting an invalid index
5422 * before the new view peer tab has been created.
5424 final AlignViewportI peer = viewport.getCodingComplement();
5427 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5428 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5430 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5436 * On right mouse click on view tab, prompt for and set new view name.
5439 public void tabbedPane_mousePressed(MouseEvent e)
5441 if (SwingUtilities.isRightMouseButton(e))
5443 String msg = MessageManager.getString("label.enter_view_name");
5444 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5445 JOptionPane.QUESTION_MESSAGE);
5449 viewport.viewName = reply;
5450 // TODO warn if reply is in getExistingViewNames()?
5451 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5456 public AlignViewport getCurrentView()
5462 * Open the dialog for regex description parsing.
5465 protected void extractScores_actionPerformed(ActionEvent e)
5467 ParseProperties pp = new jalview.analysis.ParseProperties(
5468 viewport.getAlignment());
5469 // TODO: verify regex and introduce GUI dialog for version 2.5
5470 // if (pp.getScoresFromDescription("col", "score column ",
5471 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5473 if (pp.getScoresFromDescription("description column",
5474 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5476 buildSortByAnnotationScoresMenu();
5484 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5488 protected void showDbRefs_actionPerformed(ActionEvent e)
5490 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5496 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5500 protected void showNpFeats_actionPerformed(ActionEvent e)
5502 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5506 * find the viewport amongst the tabs in this alignment frame and close that
5511 public boolean closeView(AlignViewportI av)
5515 this.closeMenuItem_actionPerformed(false);
5518 Component[] comp = tabbedPane.getComponents();
5519 for (int i = 0; comp != null && i < comp.length; i++)
5521 if (comp[i] instanceof AlignmentPanel)
5523 if (((AlignmentPanel) comp[i]).av == av)
5526 closeView((AlignmentPanel) comp[i]);
5534 protected void build_fetchdbmenu(JMenu webService)
5536 // Temporary hack - DBRef Fetcher always top level ws entry.
5537 // TODO We probably want to store a sequence database checklist in
5538 // preferences and have checkboxes.. rather than individual sources selected
5540 final JMenu rfetch = new JMenu(
5541 MessageManager.getString("action.fetch_db_references"));
5542 rfetch.setToolTipText(MessageManager
5543 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5544 webService.add(rfetch);
5546 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5547 MessageManager.getString("option.trim_retrieved_seqs"));
5548 trimrs.setToolTipText(MessageManager
5549 .getString("label.trim_retrieved_sequences"));
5550 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5551 trimrs.addActionListener(new ActionListener()
5554 public void actionPerformed(ActionEvent e)
5556 trimrs.setSelected(trimrs.isSelected());
5557 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5558 Boolean.valueOf(trimrs.isSelected()).toString());
5562 JMenuItem fetchr = new JMenuItem(
5563 MessageManager.getString("label.standard_databases"));
5564 fetchr.setToolTipText(MessageManager
5565 .getString("label.fetch_embl_uniprot"));
5566 fetchr.addActionListener(new ActionListener()
5570 public void actionPerformed(ActionEvent e)
5572 new Thread(new Runnable()
5578 new jalview.ws.DBRefFetcher(alignPanel.av
5579 .getSequenceSelection(), alignPanel.alignFrame)
5580 .fetchDBRefs(false);
5588 final AlignFrame me = this;
5589 new Thread(new Runnable()
5594 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5595 .getSequenceFetcherSingleton(me);
5596 javax.swing.SwingUtilities.invokeLater(new Runnable()
5601 String[] dbclasses = sf.getOrderedSupportedSources();
5602 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5603 // jalview.util.QuickSort.sort(otherdb, otherdb);
5604 List<DbSourceProxy> otherdb;
5605 JMenu dfetch = new JMenu();
5606 JMenu ifetch = new JMenu();
5607 JMenuItem fetchr = null;
5608 int comp = 0, icomp = 0, mcomp = 15;
5609 String mname = null;
5611 for (String dbclass : dbclasses)
5613 otherdb = sf.getSourceProxy(dbclass);
5614 // add a single entry for this class, or submenu allowing 'fetch
5616 if (otherdb == null || otherdb.size() < 1)
5620 // List<DbSourceProxy> dbs=otherdb;
5621 // otherdb=new ArrayList<DbSourceProxy>();
5622 // for (DbSourceProxy db:dbs)
5624 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5628 mname = "From " + dbclass;
5630 if (otherdb.size() == 1)
5632 final DbSourceProxy[] dassource = otherdb
5633 .toArray(new DbSourceProxy[0]);
5634 DbSourceProxy src = otherdb.get(0);
5635 fetchr = new JMenuItem(src.getDbSource());
5636 fetchr.addActionListener(new ActionListener()
5640 public void actionPerformed(ActionEvent e)
5642 new Thread(new Runnable()
5648 new jalview.ws.DBRefFetcher(alignPanel.av
5649 .getSequenceSelection(),
5650 alignPanel.alignFrame, dassource)
5651 .fetchDBRefs(false);
5657 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5663 final DbSourceProxy[] dassource = otherdb
5664 .toArray(new DbSourceProxy[0]);
5666 DbSourceProxy src = otherdb.get(0);
5667 fetchr = new JMenuItem(MessageManager.formatMessage(
5668 "label.fetch_all_param", new Object[]
5669 { src.getDbSource() }));
5670 fetchr.addActionListener(new ActionListener()
5673 public void actionPerformed(ActionEvent e)
5675 new Thread(new Runnable()
5681 new jalview.ws.DBRefFetcher(alignPanel.av
5682 .getSequenceSelection(),
5683 alignPanel.alignFrame, dassource)
5684 .fetchDBRefs(false);
5690 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5693 // and then build the rest of the individual menus
5694 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5696 String imname = null;
5698 for (DbSourceProxy sproxy : otherdb)
5700 String dbname = sproxy.getDbName();
5701 String sname = dbname.length() > 5 ? dbname.substring(0,
5702 5) + "..." : dbname;
5703 String msname = dbname.length() > 10 ? dbname.substring(
5704 0, 10) + "..." : dbname;
5707 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5709 fetchr = new JMenuItem(msname);
5710 final DbSourceProxy[] dassrc =
5712 fetchr.addActionListener(new ActionListener()
5716 public void actionPerformed(ActionEvent e)
5718 new Thread(new Runnable()
5724 new jalview.ws.DBRefFetcher(alignPanel.av
5725 .getSequenceSelection(),
5726 alignPanel.alignFrame, dassrc)
5727 .fetchDBRefs(false);
5733 fetchr.setToolTipText("<html>"
5734 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5737 if (++icomp >= mcomp || i == (otherdb.size()))
5739 ifetch.setText(MessageManager.formatMessage(
5740 "label.source_to_target", imname, sname));
5742 ifetch = new JMenu();
5750 if (comp >= mcomp || dbi >= (dbclasses.length))
5752 dfetch.setText(MessageManager.formatMessage(
5753 "label.source_to_target", mname, dbclass));
5755 dfetch = new JMenu();
5768 * Left justify the whole alignment.
5771 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5773 AlignmentI al = viewport.getAlignment();
5775 viewport.firePropertyChange("alignment", null, al);
5779 * Right justify the whole alignment.
5782 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5784 AlignmentI al = viewport.getAlignment();
5786 viewport.firePropertyChange("alignment", null, al);
5789 public void setShowSeqFeatures(boolean b)
5791 showSeqFeatures.setSelected(b);
5792 viewport.setShowSequenceFeatures(b);
5799 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5800 * awt.event.ActionEvent)
5803 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5805 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5806 alignPanel.paintAlignment(true);
5813 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5817 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5819 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5820 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5828 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5829 * .event.ActionEvent)
5832 protected void showGroupConservation_actionPerformed(ActionEvent e)
5834 viewport.setShowGroupConservation(showGroupConservation.getState());
5835 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5842 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5843 * .event.ActionEvent)
5846 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5848 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5849 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5856 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5857 * .event.ActionEvent)
5860 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5862 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5863 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5867 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5869 showSequenceLogo.setState(true);
5870 viewport.setShowSequenceLogo(true);
5871 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5872 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5876 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5878 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5885 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5886 * .event.ActionEvent)
5889 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5891 if (avc.makeGroupsFromSelection())
5893 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5894 alignPanel.updateAnnotation();
5895 alignPanel.paintAlignment(true);
5898 public void clearAlignmentSeqRep()
5900 // TODO refactor alignmentseqrep to controller
5901 if (viewport.getAlignment().hasSeqrep()) {
5902 viewport.getAlignment().setSeqrep(null);
5903 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5904 alignPanel.updateAnnotation();
5905 alignPanel.paintAlignment(true);
5910 protected void createGroup_actionPerformed(ActionEvent e)
5912 if (avc.createGroup())
5914 alignPanel.alignmentChanged();
5919 protected void unGroup_actionPerformed(ActionEvent e)
5923 alignPanel.alignmentChanged();
5928 * make the given alignmentPanel the currently selected tab
5930 * @param alignmentPanel
5932 public void setDisplayedView(AlignmentPanel alignmentPanel)
5934 if (!viewport.getSequenceSetId().equals(
5935 alignmentPanel.av.getSequenceSetId()))
5937 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5939 if (tabbedPane != null
5940 && tabbedPane.getTabCount() > 0
5941 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5942 .getSelectedIndex())
5944 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5949 * Action on selection of menu options to Show or Hide annotations.
5952 * @param forSequences
5953 * update sequence-related annotations
5954 * @param forAlignment
5955 * update non-sequence-related annotations
5958 protected void setAnnotationsVisibility(boolean visible,
5959 boolean forSequences, boolean forAlignment)
5961 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5962 .getAlignmentAnnotation())
5964 boolean apply = (aa.sequenceRef == null && forAlignment)
5965 || (aa.sequenceRef != null && forSequences);
5968 aa.visible = visible;
5971 alignPanel.validateAnnotationDimensions(false);
5972 alignPanel.alignmentChanged();
5976 * Store selected annotation sort order for the view and repaint.
5979 protected void sortAnnotations_actionPerformed()
5981 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5983 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5984 alignPanel.paintAlignment(true);
5989 * @return alignment panels in this alignment frame
5991 public List<? extends AlignmentViewPanel> getAlignPanels()
5993 return alignPanels == null ? Arrays.asList(alignPanel)
5998 * Open a new alignment window, with the cDNA associated with this (protein)
5999 * alignment, aligned as is the protein.
6001 protected void viewAsCdna_actionPerformed()
6003 // TODO no longer a menu action - refactor as required
6004 final AlignmentI alignment = getViewport().getAlignment();
6005 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6006 if (mappings == null)
6010 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6011 for (SequenceI aaSeq : alignment.getSequences()) {
6012 for (AlignedCodonFrame acf : mappings) {
6013 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6017 * There is a cDNA mapping for this protein sequence - add to new
6018 * alignment. It will share the same dataset sequence as other mapped
6019 * cDNA (no new mappings need to be created).
6021 final Sequence newSeq = new Sequence(dnaSeq);
6022 newSeq.setDatasetSequence(dnaSeq);
6023 cdnaSeqs.add(newSeq);
6027 if (cdnaSeqs.size() == 0)
6029 // show a warning dialog no mapped cDNA
6032 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6034 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6035 AlignFrame.DEFAULT_HEIGHT);
6036 cdna.alignAs(alignment);
6037 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6039 Desktop.addInternalFrame(alignFrame, newtitle,
6040 AlignFrame.DEFAULT_WIDTH,
6041 AlignFrame.DEFAULT_HEIGHT);
6045 * Set visibility of dna/protein complement view (available when shown in a
6051 protected void showComplement_actionPerformed(boolean show)
6053 SplitContainerI sf = getSplitViewContainer();
6055 sf.setComplementVisible(this, show);
6060 class PrintThread extends Thread
6064 public PrintThread(AlignmentPanel ap)
6069 static PageFormat pf;
6074 PrinterJob printJob = PrinterJob.getPrinterJob();
6078 printJob.setPrintable(ap, pf);
6082 printJob.setPrintable(ap);
6085 if (printJob.printDialog())
6090 } catch (Exception PrintException)
6092 PrintException.printStackTrace();