2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.AlignmentUtils.MappingResult;
27 import jalview.analysis.Conservation;
28 import jalview.analysis.CrossRef;
29 import jalview.analysis.Dna;
30 import jalview.analysis.ParseProperties;
31 import jalview.analysis.SequenceIdMatcher;
32 import jalview.api.AlignViewControllerGuiI;
33 import jalview.api.AlignViewControllerI;
34 import jalview.api.AlignViewportI;
35 import jalview.api.AlignmentViewPanel;
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 ViewSelectionMenu vsel = new ViewSelectionMenu("Transfer colours from",
368 new ViewSetProvider()
372 public AlignmentPanel[] getAllAlignmentPanels()
375 origview.add(alignPanel);
376 return Desktop.getAlignmentPanels(null);
378 }, selviews, new ItemListener()
382 public void itemStateChanged(ItemEvent e)
384 if (origview.size() > 0)
386 ViewStyleI vs = selviews.get(0).getAlignViewport()
388 origview.get(0).getAlignViewport().setViewStyle(vs);
389 AlignViewportI complement = origview.get(0)
390 .getAlignViewport().getCodingComplement();
391 if (complement != null)
393 AlignFrame af = Desktop.getAlignFrameFor(complement);
394 if (complement.isNucleotide())
396 complement.setViewStyle(vs);
397 vs.setCharWidth(vs.getCharWidth() / 3);
401 int rw = vs.getCharWidth();
402 vs.setCharWidth(rw * 3);
403 complement.setViewStyle(vs);
406 af.alignPanel.updateLayout();
407 af.setMenusForViewport();
409 origview.get(0).updateLayout();
410 origview.get(0).setSelected(true);
411 origview.get(0).alignFrame.setMenusForViewport();
416 formatMenu.add(vsel);
421 * Change the filename and format for the alignment, and enable the 'reload'
422 * button functionality.
429 public void setFileName(String file, String format)
432 setFileFormat(format);
433 reload.setEnabled(true);
437 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
440 void addKeyListener()
442 addKeyListener(new KeyAdapter()
445 public void keyPressed(KeyEvent evt)
447 if (viewport.cursorMode
448 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
449 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
450 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
451 && Character.isDigit(evt.getKeyChar()))
453 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
456 switch (evt.getKeyCode())
459 case 27: // escape key
460 deselectAllSequenceMenuItem_actionPerformed(null);
464 case KeyEvent.VK_DOWN:
465 if (evt.isAltDown() || !viewport.cursorMode)
467 moveSelectedSequences(false);
469 if (viewport.cursorMode)
471 alignPanel.getSeqPanel().moveCursor(0, 1);
476 if (evt.isAltDown() || !viewport.cursorMode)
478 moveSelectedSequences(true);
480 if (viewport.cursorMode)
482 alignPanel.getSeqPanel().moveCursor(0, -1);
487 case KeyEvent.VK_LEFT:
488 if (evt.isAltDown() || !viewport.cursorMode)
490 slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1());
494 alignPanel.getSeqPanel().moveCursor(-1, 0);
499 case KeyEvent.VK_RIGHT:
500 if (evt.isAltDown() || !viewport.cursorMode)
502 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
506 alignPanel.getSeqPanel().moveCursor(1, 0);
510 case KeyEvent.VK_SPACE:
511 if (viewport.cursorMode)
513 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
514 || evt.isShiftDown() || evt.isAltDown());
518 // case KeyEvent.VK_A:
519 // if (viewport.cursorMode)
521 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
522 // //System.out.println("A");
526 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
527 * System.out.println("closing bracket"); } break;
529 case KeyEvent.VK_DELETE:
530 case KeyEvent.VK_BACK_SPACE:
531 if (!viewport.cursorMode)
533 cut_actionPerformed(null);
537 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
538 || evt.isShiftDown() || evt.isAltDown());
544 if (viewport.cursorMode)
546 alignPanel.getSeqPanel().setCursorRow();
550 if (viewport.cursorMode && !evt.isControlDown())
552 alignPanel.getSeqPanel().setCursorColumn();
556 if (viewport.cursorMode)
558 alignPanel.getSeqPanel().setCursorPosition();
562 case KeyEvent.VK_ENTER:
563 case KeyEvent.VK_COMMA:
564 if (viewport.cursorMode)
566 alignPanel.getSeqPanel().setCursorRowAndColumn();
571 if (viewport.cursorMode)
573 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
577 if (viewport.cursorMode)
579 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
584 viewport.cursorMode = !viewport.cursorMode;
585 statusBar.setText(MessageManager.formatMessage(
586 "label.keyboard_editing_mode", new String[]
587 { (viewport.cursorMode ? "on" : "off") }));
588 if (viewport.cursorMode)
590 alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes;
591 alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq;
593 alignPanel.getSeqPanel().seqCanvas.repaint();
599 Help.showHelpWindow();
600 } catch (Exception ex)
602 ex.printStackTrace();
607 boolean toggleSeqs = !evt.isControlDown();
608 boolean toggleCols = !evt.isShiftDown();
609 toggleHiddenRegions(toggleSeqs, toggleCols);
612 case KeyEvent.VK_PAGE_UP:
613 if (viewport.getWrapAlignment())
615 alignPanel.scrollUp(true);
619 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
620 - viewport.endSeq + viewport.startSeq);
623 case KeyEvent.VK_PAGE_DOWN:
624 if (viewport.getWrapAlignment())
626 alignPanel.scrollUp(false);
630 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
631 + viewport.endSeq - viewport.startSeq);
638 public void keyReleased(KeyEvent evt)
640 switch (evt.getKeyCode())
642 case KeyEvent.VK_LEFT:
643 if (evt.isAltDown() || !viewport.cursorMode)
645 viewport.firePropertyChange("alignment", null, viewport
646 .getAlignment().getSequences());
650 case KeyEvent.VK_RIGHT:
651 if (evt.isAltDown() || !viewport.cursorMode)
653 viewport.firePropertyChange("alignment", null, viewport
654 .getAlignment().getSequences());
662 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
664 ap.alignFrame = this;
665 avc = new jalview.controller.AlignViewController(this, viewport,
670 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
672 int aSize = alignPanels.size();
674 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
676 if (aSize == 1 && ap.av.viewName == null)
678 this.getContentPane().add(ap, BorderLayout.CENTER);
684 setInitialTabVisible();
687 expandViews.setEnabled(true);
688 gatherViews.setEnabled(true);
689 tabbedPane.addTab(ap.av.viewName, ap);
691 ap.setVisible(false);
696 if (ap.av.isPadGaps())
698 ap.av.getAlignment().padGaps();
700 ap.av.updateConservation(ap);
701 ap.av.updateConsensus(ap);
702 ap.av.updateStrucConsensus(ap);
706 public void setInitialTabVisible()
708 expandViews.setEnabled(true);
709 gatherViews.setEnabled(true);
710 tabbedPane.setVisible(true);
711 AlignmentPanel first = alignPanels.get(0);
712 tabbedPane.addTab(first.av.viewName, first);
713 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
716 public AlignViewport getViewport()
721 /* Set up intrinsic listeners for dynamically generated GUI bits. */
722 private void addServiceListeners()
724 final java.beans.PropertyChangeListener thisListener;
725 Desktop.instance.addJalviewPropertyChangeListener("services",
726 thisListener = new java.beans.PropertyChangeListener()
729 public void propertyChange(PropertyChangeEvent evt)
731 // // System.out.println("Discoverer property change.");
732 // if (evt.getPropertyName().equals("services"))
734 SwingUtilities.invokeLater(new Runnable()
741 .println("Rebuild WS Menu for service change");
742 BuildWebServiceMenu();
749 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
752 public void internalFrameClosed(
753 javax.swing.event.InternalFrameEvent evt)
755 System.out.println("deregistering discoverer listener");
756 Desktop.instance.removeJalviewPropertyChangeListener("services",
758 closeMenuItem_actionPerformed(true);
761 // Finally, build the menu once to get current service state
762 new Thread(new Runnable()
767 BuildWebServiceMenu();
772 public void setGUINucleotide(boolean nucleotide)
774 showTranslation.setVisible(nucleotide);
775 cdna.setVisible(!nucleotide);
776 conservationMenuItem.setEnabled(!nucleotide);
777 modifyConservation.setEnabled(!nucleotide);
778 showGroupConservation.setEnabled(!nucleotide);
779 rnahelicesColour.setEnabled(nucleotide);
780 purinePyrimidineColour.setEnabled(nucleotide);
784 * Builds codon mappings from this (protein) alignment to any compatible
785 * nucleotide alignments. Mappings are built between sequences with the same
786 * name and compatible lengths. Also makes the cDNA alignment a
787 * CommandListener for the protein alignment so that edits are mirrored.
790 protected void linkCdna_actionPerformed()
793 int alreadyLinkedCount = 0;
794 final AlignmentI thisAlignment = this.alignPanel.getAlignment();
796 for (AlignFrame af : Desktop.getAlignFrames())
798 if (af.alignPanel != null)
800 final AlignmentI thatAlignment = af.alignPanel.getAlignment();
801 if (thatAlignment.isNucleotide())
803 MappingResult mapped = AlignmentUtils.mapProteinToCdna(
804 thisAlignment, thatAlignment);
805 if (mapped == MappingResult.AlreadyMapped)
807 alreadyLinkedCount++;
809 else if (mapped == MappingResult.Mapped)
811 final StructureSelectionManager ssm = StructureSelectionManager
812 .getStructureSelectionManager(Desktop.instance);
813 ssm.addMappings(thisAlignment.getCodonFrames());
814 // enable the next line to enable linked editing
815 // ssm.addCommandListener(af.getViewport());
822 if (linkedCount == 0 && alreadyLinkedCount == 0)
824 msg = MessageManager.getString("label.no_cdna");
826 else if (linkedCount > 0)
828 msg = MessageManager.formatMessage("label.linked_cdna", linkedCount);
832 msg = MessageManager.formatMessage("label.cdna_all_linked",
839 * Align any linked cDNA to match the alignment of this (protein) alignment.
840 * Any mapped sequence regions will be realigned, unmapped sequences are not
844 protected void alignCdna_actionPerformed()
848 final AlignmentI thisAlignment = this.alignPanel.getAlignment();
849 for (AlignFrame af : Desktop.getAlignFrames())
851 if (af.alignPanel != null)
853 final AlignmentI thatAlignment = af.alignPanel.getAlignment();
854 if (thatAlignment.isNucleotide())
856 int seqsAligned = thatAlignment.alignAs(thisAlignment);
857 seqCount += seqsAligned;
860 af.alignPanel.alignmentChanged();
866 setStatus(MessageManager.formatMessage("label.cdna_aligned", seqCount,
870 * set up menus for the current viewport. This may be called after any
871 * operation that affects the data in the current view (selection changed,
872 * etc) to update the menus to reflect the new state.
874 public void setMenusForViewport()
876 setMenusFromViewport(viewport);
880 * Need to call this method when tabs are selected for multiple views, or when
881 * loading from Jalview2XML.java
886 void setMenusFromViewport(AlignViewport av)
888 padGapsMenuitem.setSelected(av.isPadGaps());
889 colourTextMenuItem.setSelected(av.isShowColourText());
890 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
891 conservationMenuItem.setSelected(av.getConservationSelected());
892 seqLimits.setSelected(av.getShowJVSuffix());
893 idRightAlign.setSelected(av.isRightAlignIds());
894 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
895 renderGapsMenuItem.setSelected(av.isRenderGaps());
896 wrapMenuItem.setSelected(av.getWrapAlignment());
897 scaleAbove.setVisible(av.getWrapAlignment());
898 scaleLeft.setVisible(av.getWrapAlignment());
899 scaleRight.setVisible(av.getWrapAlignment());
900 annotationPanelMenuItem.setState(av.isShowAnnotation());
902 * Show/hide annotations only enabled if annotation panel is shown
904 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
905 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
906 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
907 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
908 viewBoxesMenuItem.setSelected(av.getShowBoxes());
909 viewTextMenuItem.setSelected(av.getShowText());
910 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
911 showGroupConsensus.setSelected(av.isShowGroupConsensus());
912 showGroupConservation.setSelected(av.isShowGroupConservation());
913 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
914 showSequenceLogo.setSelected(av.isShowSequenceLogo());
915 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
917 setColourSelected(ColourSchemeProperty.getColourName(av
918 .getGlobalColourScheme()));
920 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
921 hiddenMarkers.setState(av.getShowHiddenMarkers());
922 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
923 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
924 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
925 autoCalculate.setSelected(av.autoCalculateConsensus);
926 sortByTree.setSelected(av.sortByTree);
927 listenToViewSelections.setSelected(av.followSelection);
928 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
930 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
931 setShowProductsEnabled();
935 // methods for implementing IProgressIndicator
936 // need to refactor to a reusable stub class
937 Hashtable progressBars, progressBarHandlers;
942 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
945 public void setProgressBar(String message, long id)
947 if (progressBars == null)
949 progressBars = new Hashtable();
950 progressBarHandlers = new Hashtable();
953 JPanel progressPanel;
954 Long lId = new Long(id);
955 GridLayout layout = (GridLayout) statusPanel.getLayout();
956 if (progressBars.get(lId) != null)
958 progressPanel = (JPanel) progressBars.get(new Long(id));
959 statusPanel.remove(progressPanel);
960 progressBars.remove(lId);
961 progressPanel = null;
964 statusBar.setText(message);
966 if (progressBarHandlers.contains(lId))
968 progressBarHandlers.remove(lId);
970 layout.setRows(layout.getRows() - 1);
974 progressPanel = new JPanel(new BorderLayout(10, 5));
976 JProgressBar progressBar = new JProgressBar();
977 progressBar.setIndeterminate(true);
979 progressPanel.add(new JLabel(message), BorderLayout.WEST);
980 progressPanel.add(progressBar, BorderLayout.CENTER);
982 layout.setRows(layout.getRows() + 1);
983 statusPanel.add(progressPanel);
985 progressBars.put(lId, progressPanel);
988 // setMenusForViewport();
993 public void registerHandler(final long id,
994 final IProgressIndicatorHandler handler)
996 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
998 throw new Error(MessageManager.getString("error.call_setprogressbar_before_registering_handler"));
1000 progressBarHandlers.put(new Long(id), handler);
1001 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
1002 if (handler.canCancel())
1004 JButton cancel = new JButton(
1005 MessageManager.getString("action.cancel"));
1006 final IProgressIndicator us = this;
1007 cancel.addActionListener(new ActionListener()
1011 public void actionPerformed(ActionEvent e)
1013 handler.cancelActivity(id);
1014 us.setProgressBar(MessageManager.formatMessage("label.cancelled_params", new Object[]{((JLabel) progressPanel.getComponent(0)).getText()}), id);
1017 progressPanel.add(cancel, BorderLayout.EAST);
1023 * @return true if any progress bars are still active
1026 public boolean operationInProgress()
1028 if (progressBars != null && progressBars.size() > 0)
1036 public void setStatus(String text)
1038 statusBar.setText(text);
1042 * Added so Castor Mapping file can obtain Jalview Version
1044 public String getVersion()
1046 return jalview.bin.Cache.getProperty("VERSION");
1049 public FeatureRenderer getFeatureRenderer()
1051 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1055 public void fetchSequence_actionPerformed(ActionEvent e)
1057 new SequenceFetcher(this);
1061 public void addFromFile_actionPerformed(ActionEvent e)
1063 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1067 public void reload_actionPerformed(ActionEvent e)
1069 if (fileName != null)
1071 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1072 // originating file's format
1073 // TODO: work out how to recover feature settings for correct view(s) when
1074 // file is reloaded.
1075 if (currentFileFormat.equals("Jalview"))
1077 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1078 for (int i = 0; i < frames.length; i++)
1080 if (frames[i] instanceof AlignFrame && frames[i] != this
1081 && ((AlignFrame) frames[i]).fileName != null
1082 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1086 frames[i].setSelected(true);
1087 Desktop.instance.closeAssociatedWindows();
1088 } catch (java.beans.PropertyVetoException ex)
1094 Desktop.instance.closeAssociatedWindows();
1096 FileLoader loader = new FileLoader();
1097 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1098 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1102 Rectangle bounds = this.getBounds();
1104 FileLoader loader = new FileLoader();
1105 String protocol = fileName.startsWith("http:") ? "URL" : "File";
1106 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1107 protocol, currentFileFormat);
1109 newframe.setBounds(bounds);
1110 if (featureSettings != null && featureSettings.isShowing())
1112 final Rectangle fspos = featureSettings.frame.getBounds();
1113 // TODO: need a 'show feature settings' function that takes bounds -
1114 // need to refactor Desktop.addFrame
1115 newframe.featureSettings_actionPerformed(null);
1116 final FeatureSettings nfs = newframe.featureSettings;
1117 SwingUtilities.invokeLater(new Runnable()
1122 nfs.frame.setBounds(fspos);
1125 this.featureSettings.close();
1126 this.featureSettings = null;
1128 this.closeMenuItem_actionPerformed(true);
1134 public void addFromText_actionPerformed(ActionEvent e)
1136 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
1140 public void addFromURL_actionPerformed(ActionEvent e)
1142 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1146 public void save_actionPerformed(ActionEvent e)
1148 if (fileName == null
1149 || (currentFileFormat == null || !jalview.io.FormatAdapter
1150 .isValidIOFormat(currentFileFormat, true))
1151 || fileName.startsWith("http"))
1153 saveAs_actionPerformed(null);
1157 saveAlignment(fileName, currentFileFormat);
1168 public void saveAs_actionPerformed(ActionEvent e)
1170 JalviewFileChooser chooser = new JalviewFileChooser(
1171 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1172 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
1173 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
1174 currentFileFormat, false);
1176 chooser.setFileView(new JalviewFileView());
1177 chooser.setDialogTitle(MessageManager.getString("label.save_alignment_to_file"));
1178 chooser.setToolTipText(MessageManager.getString("action.save"));
1180 int value = chooser.showSaveDialog(this);
1182 if (value == JalviewFileChooser.APPROVE_OPTION)
1184 currentFileFormat = chooser.getSelectedFormat();
1185 while (currentFileFormat == null)
1188 .showInternalMessageDialog(
1191 .getString("label.select_file_format_before_saving"),
1193 .getString("label.file_format_not_specified"),
1194 JOptionPane.WARNING_MESSAGE);
1195 currentFileFormat = chooser.getSelectedFormat();
1196 value = chooser.showSaveDialog(this);
1197 if (value != JalviewFileChooser.APPROVE_OPTION)
1203 fileName = chooser.getSelectedFile().getPath();
1205 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1208 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1209 if (currentFileFormat.indexOf(" ") > -1)
1211 currentFileFormat = currentFileFormat.substring(0,
1212 currentFileFormat.indexOf(" "));
1214 saveAlignment(fileName, currentFileFormat);
1218 public boolean saveAlignment(String file, String format)
1220 boolean success = true;
1222 if (format.equalsIgnoreCase("Jalview"))
1224 String shortName = title;
1226 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1228 shortName = shortName.substring(shortName
1229 .lastIndexOf(java.io.File.separatorChar) + 1);
1233 * First save any linked Chimera session.
1235 Desktop.instance.saveChimeraSessions(file);
1237 success = new Jalview2XML().saveAlignment(this, file, shortName);
1239 statusBar.setText(MessageManager.formatMessage(
1240 "label.successfully_saved_to_file_in_format", new Object[]
1241 { fileName, format }));
1246 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1248 warningMessage("Cannot save file " + fileName + " using format "
1249 + format, "Alignment output format not supported");
1250 saveAs_actionPerformed(null);
1251 // JBPNote need to have a raise_gui flag here
1255 String[] omitHidden = null;
1257 if (viewport.hasHiddenColumns())
1259 int reply = JOptionPane
1260 .showInternalConfirmDialog(
1263 .getString("label.alignment_contains_hidden_columns"),
1265 .getString("action.save_omit_hidden_columns"),
1266 JOptionPane.YES_NO_OPTION,
1267 JOptionPane.QUESTION_MESSAGE);
1269 if (reply == JOptionPane.YES_OPTION)
1271 omitHidden = viewport.getViewAsString(false);
1274 FormatAdapter f = new FormatAdapter();
1275 String output = f.formatSequences(format,
1276 viewport.getAlignment(), // class cast exceptions will
1277 // occur in the distant future
1278 omitHidden, f.getCacheSuffixDefault(format),
1279 viewport.getColumnSelection());
1289 java.io.PrintWriter out = new java.io.PrintWriter(
1290 new java.io.FileWriter(file));
1294 this.setTitle(file);
1295 statusBar.setText(MessageManager.formatMessage(
1296 "label.successfully_saved_to_file_in_format",
1298 { fileName, format }));
1299 } catch (Exception ex)
1302 ex.printStackTrace();
1309 JOptionPane.showInternalMessageDialog(this, MessageManager
1310 .formatMessage("label.couldnt_save_file", new Object[]
1311 { fileName }), MessageManager
1312 .getString("label.error_saving_file"),
1313 JOptionPane.WARNING_MESSAGE);
1319 private void warningMessage(String warning, String title)
1321 if (new jalview.util.Platform().isHeadless())
1323 System.err.println("Warning: " + title + "\nWarning: " + warning);
1328 JOptionPane.showInternalMessageDialog(this, warning, title,
1329 JOptionPane.WARNING_MESSAGE);
1341 protected void outputText_actionPerformed(ActionEvent e)
1343 String[] omitHidden = null;
1345 if (viewport.hasHiddenColumns())
1347 int reply = JOptionPane
1348 .showInternalConfirmDialog(
1351 .getString("label.alignment_contains_hidden_columns"),
1353 .getString("action.save_omit_hidden_columns"),
1354 JOptionPane.YES_NO_OPTION,
1355 JOptionPane.QUESTION_MESSAGE);
1357 if (reply == JOptionPane.YES_OPTION)
1359 omitHidden = viewport.getViewAsString(false);
1363 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1364 cap.setForInput(null);
1368 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1369 viewport.getAlignment(), omitHidden,
1370 viewport.getColumnSelection()));
1371 Desktop.addInternalFrame(cap, MessageManager.formatMessage(
1372 "label.alignment_output_command", new Object[]
1373 { e.getActionCommand() }), 600, 500);
1374 } catch (OutOfMemoryError oom)
1376 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1389 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1391 // new HTMLOutput(alignPanel,
1392 // alignPanel.getSeqPanel().seqCanvas.getSequenceRenderer(),
1393 // alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
1394 new HtmlSvgOutput(null, alignPanel);
1398 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1400 new BioJsHTMLOutput(alignPanel,
1401 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
1403 public void createImageMap(File file, String image)
1405 alignPanel.makePNGImageMap(file, image);
1415 public void createPNG(File f)
1417 alignPanel.makePNG(f);
1427 public void createEPS(File f)
1429 alignPanel.makeEPS(f);
1432 public void createSVG(File f)
1434 alignPanel.makeSVG(f);
1437 public void pageSetup_actionPerformed(ActionEvent e)
1439 PrinterJob printJob = PrinterJob.getPrinterJob();
1440 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1450 public void printMenuItem_actionPerformed(ActionEvent e)
1452 // Putting in a thread avoids Swing painting problems
1453 PrintThread thread = new PrintThread(alignPanel);
1458 public void exportFeatures_actionPerformed(ActionEvent e)
1460 new AnnotationExporter().exportFeatures(alignPanel);
1464 public void exportAnnotations_actionPerformed(ActionEvent e)
1466 new AnnotationExporter().exportAnnotations(alignPanel);
1470 public void associatedData_actionPerformed(ActionEvent e)
1472 // Pick the tree file
1473 JalviewFileChooser chooser = new JalviewFileChooser(
1474 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1475 chooser.setFileView(new JalviewFileView());
1476 chooser.setDialogTitle(MessageManager
1477 .getString("label.load_jalview_annotations"));
1478 chooser.setToolTipText(MessageManager
1479 .getString("label.load_jalview_annotations"));
1481 int value = chooser.showOpenDialog(null);
1483 if (value == JalviewFileChooser.APPROVE_OPTION)
1485 String choice = chooser.getSelectedFile().getPath();
1486 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1487 loadJalviewDataFile(choice, null, null, null);
1493 * Close the current view or all views in the alignment frame. If the frame
1494 * only contains one view then the alignment will be removed from memory.
1496 * @param closeAllTabs
1499 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1501 if (alignPanels != null && alignPanels.size() < 2)
1503 closeAllTabs = true;
1508 if (alignPanels != null)
1512 if (this.isClosed())
1514 // really close all the windows - otherwise wait till
1515 // setClosed(true) is called
1516 for (int i = 0; i < alignPanels.size(); i++)
1518 AlignmentPanel ap = alignPanels.get(i);
1525 closeView(alignPanel);
1531 this.setClosed(true);
1533 } catch (Exception ex)
1535 ex.printStackTrace();
1540 * Close the specified panel and close up tabs appropriately.
1542 * @param panelToClose
1544 public void closeView(AlignmentPanel panelToClose)
1546 int index = tabbedPane.getSelectedIndex();
1547 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1548 alignPanels.remove(panelToClose);
1549 panelToClose.closePanel();
1550 panelToClose = null;
1552 tabbedPane.removeTabAt(closedindex);
1553 tabbedPane.validate();
1555 if (index > closedindex || index == tabbedPane.getTabCount())
1557 // modify currently selected tab index if necessary.
1561 this.tabSelectionChanged(index);
1567 void updateEditMenuBar()
1570 if (viewport.getHistoryList().size() > 0)
1572 undoMenuItem.setEnabled(true);
1573 CommandI command = viewport.getHistoryList().peek();
1574 undoMenuItem.setText(MessageManager.formatMessage(
1575 "label.undo_command", new Object[]
1576 { command.getDescription() }));
1580 undoMenuItem.setEnabled(false);
1581 undoMenuItem.setText(MessageManager.getString("action.undo"));
1584 if (viewport.getRedoList().size() > 0)
1586 redoMenuItem.setEnabled(true);
1588 CommandI command = viewport.getRedoList().peek();
1589 redoMenuItem.setText(MessageManager.formatMessage(
1590 "label.redo_command", new Object[]
1591 { command.getDescription() }));
1595 redoMenuItem.setEnabled(false);
1596 redoMenuItem.setText(MessageManager.getString("action.redo"));
1600 public void addHistoryItem(CommandI command)
1602 if (command.getSize() > 0)
1604 viewport.addToHistoryList(command);
1605 viewport.clearRedoList();
1606 updateEditMenuBar();
1607 viewport.updateHiddenColumns();
1608 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1609 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1610 // viewport.getColumnSelection()
1611 // .getHiddenColumns().size() > 0);
1617 * @return alignment objects for all views
1619 AlignmentI[] getViewAlignments()
1621 if (alignPanels != null)
1623 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1625 for (AlignmentPanel ap : alignPanels)
1627 als[i++] = ap.av.getAlignment();
1631 if (viewport != null)
1633 return new AlignmentI[]
1634 { viewport.getAlignment() };
1646 protected void undoMenuItem_actionPerformed(ActionEvent e)
1648 if (viewport.getHistoryList().isEmpty())
1652 CommandI command = viewport.getHistoryList().pop();
1653 viewport.addToRedoList(command);
1654 command.undoCommand(getViewAlignments());
1656 AlignmentViewport originalSource = getOriginatingSource(command);
1657 updateEditMenuBar();
1659 if (originalSource != null)
1661 if (originalSource != viewport)
1664 .warn("Implementation worry: mismatch of viewport origin for undo");
1666 originalSource.updateHiddenColumns();
1667 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1669 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1670 // viewport.getColumnSelection()
1671 // .getHiddenColumns().size() > 0);
1672 originalSource.firePropertyChange("alignment", null, originalSource
1673 .getAlignment().getSequences());
1684 protected void redoMenuItem_actionPerformed(ActionEvent e)
1686 if (viewport.getRedoList().size() < 1)
1691 CommandI command = viewport.getRedoList().pop();
1692 viewport.addToHistoryList(command);
1693 command.doCommand(getViewAlignments());
1695 AlignmentViewport originalSource = getOriginatingSource(command);
1696 updateEditMenuBar();
1698 if (originalSource != null)
1701 if (originalSource != viewport)
1704 .warn("Implementation worry: mismatch of viewport origin for redo");
1706 originalSource.updateHiddenColumns();
1707 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1709 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1710 // viewport.getColumnSelection()
1711 // .getHiddenColumns().size() > 0);
1712 originalSource.firePropertyChange("alignment", null, originalSource
1713 .getAlignment().getSequences());
1717 AlignmentViewport getOriginatingSource(CommandI command)
1719 AlignmentViewport originalSource = null;
1720 // For sequence removal and addition, we need to fire
1721 // the property change event FROM the viewport where the
1722 // original alignment was altered
1723 AlignmentI al = null;
1724 if (command instanceof EditCommand)
1726 EditCommand editCommand = (EditCommand) command;
1727 al = editCommand.getAlignment();
1728 List<Component> comps = PaintRefresher.components.get(viewport
1729 .getSequenceSetId());
1731 for (Component comp : comps)
1733 if (comp instanceof AlignmentPanel)
1735 if (al == ((AlignmentPanel) comp).av.getAlignment())
1737 originalSource = ((AlignmentPanel) comp).av;
1744 if (originalSource == null)
1746 // The original view is closed, we must validate
1747 // the current view against the closed view first
1750 PaintRefresher.validateSequences(al, viewport.getAlignment());
1753 originalSource = viewport;
1756 return originalSource;
1765 public void moveSelectedSequences(boolean up)
1767 SequenceGroup sg = viewport.getSelectionGroup();
1773 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1774 viewport.getHiddenRepSequences(), up);
1775 alignPanel.paintAlignment(true);
1778 synchronized void slideSequences(boolean right, int size)
1780 List<SequenceI> sg = new ArrayList<SequenceI>();
1781 if (viewport.cursorMode)
1783 sg.add(viewport.getAlignment().getSequenceAt(
1784 alignPanel.getSeqPanel().seqCanvas.cursorY));
1786 else if (viewport.getSelectionGroup() != null
1787 && viewport.getSelectionGroup().getSize() != viewport
1788 .getAlignment().getHeight())
1790 sg = viewport.getSelectionGroup().getSequences(
1791 viewport.getHiddenRepSequences());
1799 List<SequenceI> invertGroup = new ArrayList<SequenceI>();
1801 for (SequenceI seq : viewport.getAlignment().getSequences())
1803 if (!sg.contains(seq))
1805 invertGroup.add(seq);
1809 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1811 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1812 for (int i = 0; i < invertGroup.size(); i++)
1814 seqs2[i] = invertGroup.get(i);
1817 SlideSequencesCommand ssc;
1820 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1821 size, viewport.getGapCharacter());
1825 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1826 size, viewport.getGapCharacter());
1829 int groupAdjustment = 0;
1830 if (ssc.getGapsInsertedBegin() && right)
1832 if (viewport.cursorMode)
1834 alignPanel.getSeqPanel().moveCursor(size, 0);
1838 groupAdjustment = size;
1841 else if (!ssc.getGapsInsertedBegin() && !right)
1843 if (viewport.cursorMode)
1845 alignPanel.getSeqPanel().moveCursor(-size, 0);
1849 groupAdjustment = -size;
1853 if (groupAdjustment != 0)
1855 viewport.getSelectionGroup().setStartRes(
1856 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1857 viewport.getSelectionGroup().setEndRes(
1858 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1861 boolean appendHistoryItem = false;
1862 Deque<CommandI> historyList = viewport.getHistoryList();
1863 if (historyList != null
1864 && historyList.size() > 0
1865 && historyList.peek() instanceof SlideSequencesCommand)
1867 appendHistoryItem = ssc
1868 .appendSlideCommand((SlideSequencesCommand) historyList
1872 if (!appendHistoryItem)
1874 addHistoryItem(ssc);
1887 protected void copy_actionPerformed(ActionEvent e)
1890 if (viewport.getSelectionGroup() == null)
1894 // TODO: preserve the ordering of displayed alignment annotation in any
1895 // internal paste (particularly sequence associated annotation)
1896 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1897 String[] omitHidden = null;
1899 if (viewport.hasHiddenColumns())
1901 omitHidden = viewport.getViewAsString(true);
1904 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1907 StringSelection ss = new StringSelection(output);
1911 jalview.gui.Desktop.internalCopy = true;
1912 // Its really worth setting the clipboard contents
1913 // to empty before setting the large StringSelection!!
1914 Toolkit.getDefaultToolkit().getSystemClipboard()
1915 .setContents(new StringSelection(""), null);
1917 Toolkit.getDefaultToolkit().getSystemClipboard()
1918 .setContents(ss, Desktop.instance);
1919 } catch (OutOfMemoryError er)
1921 new OOMWarning("copying region", er);
1925 ArrayList<int[]> hiddenColumns = null;
1926 if (viewport.hasHiddenColumns())
1928 hiddenColumns = new ArrayList<int[]>();
1929 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1930 .getSelectionGroup().getEndRes();
1931 for (int[] region : viewport.getColumnSelection().getHiddenColumns())
1933 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1935 hiddenColumns.add(new int[]
1936 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1941 Desktop.jalviewClipboard = new Object[]
1942 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1943 statusBar.setText(MessageManager.formatMessage(
1944 "label.copied_sequences_to_clipboard", new Object[]
1945 { Integer.valueOf(seqs.length).toString() }));
1955 protected void pasteNew_actionPerformed(ActionEvent e)
1967 protected void pasteThis_actionPerformed(ActionEvent e)
1973 * Paste contents of Jalview clipboard
1975 * @param newAlignment
1976 * true to paste to a new alignment, otherwise add to this.
1978 void paste(boolean newAlignment)
1980 boolean externalPaste = true;
1983 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1984 Transferable contents = c.getContents(this);
1986 if (contents == null)
1994 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1995 if (str.length() < 1)
2000 format = new IdentifyFile().Identify(str, "Paste");
2002 } catch (OutOfMemoryError er)
2004 new OOMWarning("Out of memory pasting sequences!!", er);
2008 SequenceI[] sequences;
2009 boolean annotationAdded = false;
2010 AlignmentI alignment = null;
2012 if (Desktop.jalviewClipboard != null)
2014 // The clipboard was filled from within Jalview, we must use the
2016 // And dataset from the copied alignment
2017 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2018 // be doubly sure that we create *new* sequence objects.
2019 sequences = new SequenceI[newseq.length];
2020 for (int i = 0; i < newseq.length; i++)
2022 sequences[i] = new Sequence(newseq[i]);
2024 alignment = new Alignment(sequences);
2025 externalPaste = false;
2029 // parse the clipboard as an alignment.
2030 alignment = new FormatAdapter().readFile(str, "Paste", format);
2031 sequences = alignment.getSequencesArray();
2035 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
2041 if (Desktop.jalviewClipboard != null)
2043 // dataset is inherited
2044 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2048 // new dataset is constructed
2049 alignment.setDataset(null);
2051 alwidth = alignment.getWidth() + 1;
2055 AlignmentI pastedal = alignment; // preserve pasted alignment object
2056 // Add pasted sequences and dataset into existing alignment.
2057 alignment = viewport.getAlignment();
2058 alwidth = alignment.getWidth() + 1;
2059 // decide if we need to import sequences from an existing dataset
2060 boolean importDs = Desktop.jalviewClipboard != null
2061 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2062 // importDs==true instructs us to copy over new dataset sequences from
2063 // an existing alignment
2064 Vector newDs = (importDs) ? new Vector() : null; // used to create
2065 // minimum dataset set
2067 for (int i = 0; i < sequences.length; i++)
2071 newDs.addElement(null);
2073 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2075 if (importDs && ds != null)
2077 if (!newDs.contains(ds))
2079 newDs.setElementAt(ds, i);
2080 ds = new Sequence(ds);
2081 // update with new dataset sequence
2082 sequences[i].setDatasetSequence(ds);
2086 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2091 // copy and derive new dataset sequence
2092 sequences[i] = sequences[i].deriveSequence();
2093 alignment.getDataset().addSequence(
2094 sequences[i].getDatasetSequence());
2095 // TODO: avoid creation of duplicate dataset sequences with a
2096 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2098 alignment.addSequence(sequences[i]); // merges dataset
2102 newDs.clear(); // tidy up
2104 if (alignment.getAlignmentAnnotation() != null)
2106 for (AlignmentAnnotation alan : alignment
2107 .getAlignmentAnnotation())
2109 if (alan.graphGroup > fgroup)
2111 fgroup = alan.graphGroup;
2115 if (pastedal.getAlignmentAnnotation() != null)
2117 // Add any annotation attached to alignment.
2118 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2119 for (int i = 0; i < alann.length; i++)
2121 annotationAdded = true;
2122 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2124 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
2125 if (newann.graphGroup > -1)
2127 if (newGraphGroups.size() <= newann.graphGroup
2128 || newGraphGroups.get(newann.graphGroup) == null)
2130 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2132 newGraphGroups.add(q, null);
2134 newGraphGroups.set(newann.graphGroup, new Integer(
2137 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2141 newann.padAnnotation(alwidth);
2142 alignment.addAnnotation(newann);
2152 addHistoryItem(new EditCommand(
2153 MessageManager.getString("label.add_sequences"),
2155 sequences, 0, alignment.getWidth(), alignment));
2157 // Add any annotations attached to sequences
2158 for (int i = 0; i < sequences.length; i++)
2160 if (sequences[i].getAnnotation() != null)
2162 AlignmentAnnotation newann;
2163 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2165 annotationAdded = true;
2166 newann = sequences[i].getAnnotation()[a];
2167 newann.adjustForAlignment();
2168 newann.padAnnotation(alwidth);
2169 if (newann.graphGroup > -1)
2171 if (newann.graphGroup > -1)
2173 if (newGraphGroups.size() <= newann.graphGroup
2174 || newGraphGroups.get(newann.graphGroup) == null)
2176 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
2178 newGraphGroups.add(q, null);
2180 newGraphGroups.set(newann.graphGroup, new Integer(
2183 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2187 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2192 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
2199 // propagate alignment changed.
2200 viewport.setEndSeq(alignment.getHeight());
2201 if (annotationAdded)
2203 // Duplicate sequence annotation in all views.
2204 AlignmentI[] alview = this.getViewAlignments();
2205 for (int i = 0; i < sequences.length; i++)
2207 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2212 for (int avnum = 0; avnum < alview.length; avnum++)
2214 if (alview[avnum] != alignment)
2216 // duplicate in a view other than the one with input focus
2217 int avwidth = alview[avnum].getWidth() + 1;
2218 // this relies on sann being preserved after we
2219 // modify the sequence's annotation array for each duplication
2220 for (int a = 0; a < sann.length; a++)
2222 AlignmentAnnotation newann = new AlignmentAnnotation(
2224 sequences[i].addAlignmentAnnotation(newann);
2225 newann.padAnnotation(avwidth);
2226 alview[avnum].addAnnotation(newann); // annotation was
2227 // duplicated earlier
2228 // TODO JAL-1145 graphGroups are not updated for sequence
2229 // annotation added to several views. This may cause
2231 alview[avnum].setAnnotationIndex(newann, a);
2236 buildSortByAnnotationScoresMenu();
2238 viewport.firePropertyChange("alignment", null,
2239 alignment.getSequences());
2240 if (alignPanels != null)
2242 for (AlignmentPanel ap : alignPanels)
2244 ap.validateAnnotationDimensions(false);
2249 alignPanel.validateAnnotationDimensions(false);
2255 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2257 String newtitle = new String("Copied sequences");
2259 if (Desktop.jalviewClipboard != null
2260 && Desktop.jalviewClipboard[2] != null)
2262 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2263 for (int[] region : hc)
2265 af.viewport.hideColumns(region[0], region[1]);
2269 // >>>This is a fix for the moment, until a better solution is
2271 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2273 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2275 // TODO: maintain provenance of an alignment, rather than just make the
2276 // title a concatenation of operations.
2279 if (title.startsWith("Copied sequences"))
2285 newtitle = newtitle.concat("- from " + title);
2290 newtitle = new String("Pasted sequences");
2293 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2298 } catch (Exception ex)
2300 ex.printStackTrace();
2301 System.out.println("Exception whilst pasting: " + ex);
2302 // could be anything being pasted in here
2308 protected void expand_newalign(ActionEvent e)
2312 AlignmentI alignment = AlignmentUtils.expandContext(getViewport()
2313 .getAlignment(), -1);
2314 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2316 String newtitle = new String("Flanking alignment");
2318 if (Desktop.jalviewClipboard != null
2319 && Desktop.jalviewClipboard[2] != null)
2321 List<int[]> hc = (List<int[]>) Desktop.jalviewClipboard[2];
2322 for (int region[] : hc)
2324 af.viewport.hideColumns(region[0], region[1]);
2328 // >>>This is a fix for the moment, until a better solution is
2330 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2332 alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
2334 // TODO: maintain provenance of an alignment, rather than just make the
2335 // title a concatenation of operations.
2337 if (title.startsWith("Copied sequences"))
2343 newtitle = newtitle.concat("- from " + title);
2347 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2349 } catch (Exception ex)
2351 ex.printStackTrace();
2352 System.out.println("Exception whilst pasting: " + ex);
2353 // could be anything being pasted in here
2354 } catch (OutOfMemoryError oom)
2356 new OOMWarning("Viewing flanking region of alignment", oom);
2367 protected void cut_actionPerformed(ActionEvent e)
2369 copy_actionPerformed(null);
2370 delete_actionPerformed(null);
2380 protected void delete_actionPerformed(ActionEvent evt)
2383 SequenceGroup sg = viewport.getSelectionGroup();
2389 List<SequenceI> seqs = new ArrayList<SequenceI>(sg.getSize());
2391 for (int i = 0; i < sg.getSize(); i++)
2393 seq = sg.getSequenceAt(i);
2397 // If the cut affects all sequences, warn, remove highlighted columns
2398 if (sg.getSize() == viewport.getAlignment().getHeight())
2400 int confirm = JOptionPane.showConfirmDialog(this,
2401 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2402 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2403 JOptionPane.OK_CANCEL_OPTION);
2405 if (confirm == JOptionPane.CANCEL_OPTION
2406 || confirm == JOptionPane.CLOSED_OPTION)
2410 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2411 sg.getEndRes() + 1);
2414 SequenceI[] cut = new SequenceI[seqs.size()];
2415 for (int i = 0; i < seqs.size(); i++)
2417 cut[i] = seqs.get(i);
2421 * //ADD HISTORY ITEM
2423 addHistoryItem(new EditCommand(
2424 MessageManager.getString("label.cut_sequences"), Action.CUT,
2425 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2426 viewport.getAlignment()));
2428 viewport.setSelectionGroup(null);
2429 viewport.sendSelection();
2430 viewport.getAlignment().deleteGroup(sg);
2432 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2434 if (viewport.getAlignment().getHeight() < 1)
2438 this.setClosed(true);
2439 } catch (Exception ex)
2452 protected void deleteGroups_actionPerformed(ActionEvent e)
2454 if (avc.deleteGroups())
2456 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2457 alignPanel.updateAnnotation();
2458 alignPanel.paintAlignment(true);
2469 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2471 SequenceGroup sg = new SequenceGroup();
2473 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2475 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2478 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2479 viewport.setSelectionGroup(sg);
2480 viewport.sendSelection();
2481 alignPanel.paintAlignment(true);
2482 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2492 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2494 if (viewport.cursorMode)
2496 alignPanel.getSeqPanel().keyboardNo1 = null;
2497 alignPanel.getSeqPanel().keyboardNo2 = null;
2499 viewport.setSelectionGroup(null);
2500 viewport.getColumnSelection().clear();
2501 viewport.setSelectionGroup(null);
2502 alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null);
2503 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2504 alignPanel.paintAlignment(true);
2505 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2506 viewport.sendSelection();
2516 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2518 SequenceGroup sg = viewport.getSelectionGroup();
2522 selectAllSequenceMenuItem_actionPerformed(null);
2527 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2529 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2532 alignPanel.paintAlignment(true);
2533 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2534 viewport.sendSelection();
2538 public void invertColSel_actionPerformed(ActionEvent e)
2540 viewport.invertColumnSelection();
2541 alignPanel.paintAlignment(true);
2542 viewport.sendSelection();
2552 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2554 trimAlignment(true);
2564 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2566 trimAlignment(false);
2569 void trimAlignment(boolean trimLeft)
2571 ColumnSelection colSel = viewport.getColumnSelection();
2574 if (colSel.size() > 0)
2578 column = colSel.getMin();
2582 column = colSel.getMax();
2586 if (viewport.getSelectionGroup() != null)
2588 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2589 viewport.getHiddenRepSequences());
2593 seqs = viewport.getAlignment().getSequencesArray();
2596 TrimRegionCommand trimRegion;
2599 trimRegion = new TrimRegionCommand("Remove Left",
2600 TrimRegionCommand.TRIM_LEFT, seqs, column,
2601 viewport.getAlignment(), viewport.getColumnSelection(),
2602 viewport.getSelectionGroup());
2603 viewport.setStartRes(0);
2607 trimRegion = new TrimRegionCommand("Remove Right",
2608 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2609 viewport.getAlignment(), viewport.getColumnSelection(),
2610 viewport.getSelectionGroup());
2613 statusBar.setText(MessageManager.formatMessage(
2614 "label.removed_columns", new String[]
2615 { Integer.valueOf(trimRegion.getSize()).toString() }));
2617 addHistoryItem(trimRegion);
2619 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2621 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2622 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2624 viewport.getAlignment().deleteGroup(sg);
2628 viewport.firePropertyChange("alignment", null, viewport
2629 .getAlignment().getSequences());
2640 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2642 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2645 if (viewport.getSelectionGroup() != null)
2647 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2648 viewport.getHiddenRepSequences());
2649 start = viewport.getSelectionGroup().getStartRes();
2650 end = viewport.getSelectionGroup().getEndRes();
2654 seqs = viewport.getAlignment().getSequencesArray();
2657 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2658 "Remove Gapped Columns", seqs, start, end,
2659 viewport.getAlignment());
2661 addHistoryItem(removeGapCols);
2663 statusBar.setText(MessageManager.formatMessage(
2664 "label.removed_empty_columns", new Object[]
2665 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2667 // This is to maintain viewport position on first residue
2668 // of first sequence
2669 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2670 int startRes = seq.findPosition(viewport.startRes);
2671 // ShiftList shifts;
2672 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2673 // edit.alColumnChanges=shifts.getInverse();
2674 // if (viewport.hasHiddenColumns)
2675 // viewport.getColumnSelection().compensateForEdits(shifts);
2676 viewport.setStartRes(seq.findIndex(startRes) - 1);
2677 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2689 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2691 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2694 if (viewport.getSelectionGroup() != null)
2696 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2697 viewport.getHiddenRepSequences());
2698 start = viewport.getSelectionGroup().getStartRes();
2699 end = viewport.getSelectionGroup().getEndRes();
2703 seqs = viewport.getAlignment().getSequencesArray();
2706 // This is to maintain viewport position on first residue
2707 // of first sequence
2708 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2709 int startRes = seq.findPosition(viewport.startRes);
2711 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2712 viewport.getAlignment()));
2714 viewport.setStartRes(seq.findIndex(startRes) - 1);
2716 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2728 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2730 viewport.setPadGaps(padGapsMenuitem.isSelected());
2731 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2742 public void findMenuItem_actionPerformed(ActionEvent e)
2748 * Create a new view of the current alignment.
2751 public void newView_actionPerformed(ActionEvent e)
2753 newView(null, true);
2757 * Creates and shows a new view of the current alignment.
2760 * title of newly created view; if null, one will be generated
2761 * @param copyAnnotation
2762 * if true then duplicate all annnotation, groups and settings
2763 * @return new alignment panel, already displayed.
2765 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2768 * Create a new AlignmentPanel (with its own, new Viewport)
2770 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2772 if (!copyAnnotation)
2775 * remove all groups and annotation except for the automatic stuff
2777 newap.av.getAlignment().deleteAllGroups();
2778 newap.av.getAlignment().deleteAllAnnotations(false);
2781 newap.av.setGatherViewsHere(false);
2783 if (viewport.viewName == null)
2785 viewport.viewName = MessageManager
2786 .getString("label.view_name_original");
2790 * Views share the same edits, undo and redo stacks, mappings.
2792 newap.av.setHistoryList(viewport.getHistoryList());
2793 newap.av.setRedoList(viewport.getRedoList());
2794 newap.av.getAlignment().setCodonFrames(
2795 viewport.getAlignment().getCodonFrames());
2797 newap.av.viewName = getNewViewName(viewTitle);
2799 addAlignmentPanel(newap, true);
2800 newap.alignmentChanged();
2802 if (alignPanels.size() == 2)
2804 viewport.setGatherViewsHere(true);
2806 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2811 * Make a new name for the view, ensuring it is unique within the current
2812 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2813 * these now use viewId. Unique view names are still desirable for usability.)
2818 protected String getNewViewName(String viewTitle)
2820 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2821 boolean addFirstIndex = false;
2822 if (viewTitle == null || viewTitle.trim().length() == 0)
2824 viewTitle = MessageManager.getString("action.view");
2825 addFirstIndex = true;
2829 index = 1;// we count from 1 if given a specific name
2831 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2833 List<Component> comps = PaintRefresher.components.get(viewport
2834 .getSequenceSetId());
2836 List<String> existingNames = getExistingViewNames(comps);
2838 while (existingNames.contains(newViewName))
2840 newViewName = viewTitle + " " + (++index);
2846 * Returns a list of distinct view names found in the given list of
2847 * components. View names are held on the viewport of an AlignmentPanel.
2852 protected List<String> getExistingViewNames(List<Component> comps)
2854 List<String> existingNames = new ArrayList<String>();
2855 for (Component comp : comps)
2857 if (comp instanceof AlignmentPanel)
2859 AlignmentPanel ap = (AlignmentPanel) comp;
2860 if (!existingNames.contains(ap.av.viewName))
2862 existingNames.add(ap.av.viewName);
2866 return existingNames;
2870 * Explode tabbed views into separate windows.
2873 public void expandViews_actionPerformed(ActionEvent e)
2875 Desktop.instance.explodeViews(this);
2879 * Gather views in separate windows back into a tabbed presentation.
2882 public void gatherViews_actionPerformed(ActionEvent e)
2884 Desktop.instance.gatherViews(this);
2894 public void font_actionPerformed(ActionEvent e)
2896 new FontChooser(alignPanel);
2906 protected void seqLimit_actionPerformed(ActionEvent e)
2908 viewport.setShowJVSuffix(seqLimits.isSelected());
2910 alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel
2911 .calculateIdWidth());
2912 alignPanel.paintAlignment(true);
2916 public void idRightAlign_actionPerformed(ActionEvent e)
2918 viewport.setRightAlignIds(idRightAlign.isSelected());
2919 alignPanel.paintAlignment(true);
2923 public void centreColumnLabels_actionPerformed(ActionEvent e)
2925 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
2926 alignPanel.paintAlignment(true);
2932 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2935 protected void followHighlight_actionPerformed()
2937 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2939 alignPanel.scrollToPosition(
2940 alignPanel.getSeqPanel().seqCanvas.searchResults, false);
2951 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2953 viewport.setColourText(colourTextMenuItem.isSelected());
2954 alignPanel.paintAlignment(true);
2964 public void wrapMenuItem_actionPerformed(ActionEvent e)
2966 scaleAbove.setVisible(wrapMenuItem.isSelected());
2967 scaleLeft.setVisible(wrapMenuItem.isSelected());
2968 scaleRight.setVisible(wrapMenuItem.isSelected());
2969 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2970 alignPanel.updateLayout();
2974 public void showAllSeqs_actionPerformed(ActionEvent e)
2976 viewport.showAllHiddenSeqs();
2980 public void showAllColumns_actionPerformed(ActionEvent e)
2982 viewport.showAllHiddenColumns();
2987 public void hideSelSequences_actionPerformed(ActionEvent e)
2989 viewport.hideAllSelectedSeqs();
2990 // alignPanel.paintAlignment(true);
2994 * called by key handler and the hide all/show all menu items
2999 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3002 boolean hide = false;
3003 SequenceGroup sg = viewport.getSelectionGroup();
3004 if (!toggleSeqs && !toggleCols)
3006 // Hide everything by the current selection - this is a hack - we do the
3007 // invert and then hide
3008 // first check that there will be visible columns after the invert.
3009 if ((viewport.getColumnSelection() != null
3010 && viewport.getColumnSelection().getSelected() != null && viewport
3011 .getColumnSelection().getSelected().size() > 0)
3012 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
3015 // now invert the sequence set, if required - empty selection implies
3016 // that no hiding is required.
3019 invertSequenceMenuItem_actionPerformed(null);
3020 sg = viewport.getSelectionGroup();
3024 viewport.expandColSelection(sg, true);
3025 // finally invert the column selection and get the new sequence
3027 invertColSel_actionPerformed(null);
3034 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3036 hideSelSequences_actionPerformed(null);
3039 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
3042 showAllSeqs_actionPerformed(null);
3048 if (viewport.getColumnSelection().getSelected().size() > 0)
3050 hideSelColumns_actionPerformed(null);
3053 viewport.setSelectionGroup(sg);
3058 showAllColumns_actionPerformed(null);
3067 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3068 * event.ActionEvent)
3071 public void hideAllButSelection_actionPerformed(ActionEvent e)
3073 toggleHiddenRegions(false, false);
3080 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3084 public void hideAllSelection_actionPerformed(ActionEvent e)
3086 SequenceGroup sg = viewport.getSelectionGroup();
3087 viewport.expandColSelection(sg, false);
3088 viewport.hideAllSelectedSeqs();
3089 viewport.hideSelectedColumns();
3090 alignPanel.paintAlignment(true);
3097 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3101 public void showAllhidden_actionPerformed(ActionEvent e)
3103 viewport.showAllHiddenColumns();
3104 viewport.showAllHiddenSeqs();
3105 alignPanel.paintAlignment(true);
3109 public void hideSelColumns_actionPerformed(ActionEvent e)
3111 viewport.hideSelectedColumns();
3112 alignPanel.paintAlignment(true);
3116 public void hiddenMarkers_actionPerformed(ActionEvent e)
3118 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3129 protected void scaleAbove_actionPerformed(ActionEvent e)
3131 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3132 alignPanel.paintAlignment(true);
3142 protected void scaleLeft_actionPerformed(ActionEvent e)
3144 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3145 alignPanel.paintAlignment(true);
3155 protected void scaleRight_actionPerformed(ActionEvent e)
3157 viewport.setScaleRightWrapped(scaleRight.isSelected());
3158 alignPanel.paintAlignment(true);
3168 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3170 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3171 alignPanel.paintAlignment(true);
3181 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3183 viewport.setShowText(viewTextMenuItem.isSelected());
3184 alignPanel.paintAlignment(true);
3194 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3196 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3197 alignPanel.paintAlignment(true);
3200 public FeatureSettings featureSettings;
3203 public void featureSettings_actionPerformed(ActionEvent e)
3205 if (featureSettings != null)
3207 featureSettings.close();
3208 featureSettings = null;
3210 if (!showSeqFeatures.isSelected())
3212 // make sure features are actually displayed
3213 showSeqFeatures.setSelected(true);
3214 showSeqFeatures_actionPerformed(null);
3216 featureSettings = new FeatureSettings(this);
3220 * Set or clear 'Show Sequence Features'
3226 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3228 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3229 alignPanel.paintAlignment(true);
3230 if (alignPanel.getOverviewPanel() != null)
3232 alignPanel.getOverviewPanel().updateOverviewImage();
3237 * Set or clear 'Show Sequence Features'
3243 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
3245 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
3247 if (viewport.isShowSequenceFeaturesHeight())
3249 // ensure we're actually displaying features
3250 viewport.setShowSequenceFeatures(true);
3251 showSeqFeatures.setSelected(true);
3253 alignPanel.paintAlignment(true);
3254 if (alignPanel.getOverviewPanel() != null)
3256 alignPanel.getOverviewPanel().updateOverviewImage();
3261 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3262 * the annotations panel as a whole.
3264 * The options to show/hide all annotations should be enabled when the panel
3265 * is shown, and disabled when the panel is hidden.
3270 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3272 final boolean setVisible = annotationPanelMenuItem.isSelected();
3273 viewport.setShowAnnotation(setVisible);
3274 this.showAllSeqAnnotations.setEnabled(setVisible);
3275 this.hideAllSeqAnnotations.setEnabled(setVisible);
3276 this.showAllAlAnnotations.setEnabled(setVisible);
3277 this.hideAllAlAnnotations.setEnabled(setVisible);
3278 alignPanel.updateLayout();
3282 public void alignmentProperties()
3284 JEditorPane editPane = new JEditorPane("text/html", "");
3285 editPane.setEditable(false);
3286 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3288 editPane.setText(MessageManager.formatMessage("label.html_content",
3290 { contents.toString() }));
3291 JInternalFrame frame = new JInternalFrame();
3292 frame.getContentPane().add(new JScrollPane(editPane));
3294 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3295 "label.alignment_properties", new Object[]
3296 { getTitle() }), 500, 400);
3306 public void overviewMenuItem_actionPerformed(ActionEvent e)
3308 if (alignPanel.overviewPanel != null)
3313 JInternalFrame frame = new JInternalFrame();
3314 OverviewPanel overview = new OverviewPanel(alignPanel);
3315 frame.setContentPane(overview);
3316 Desktop.addInternalFrame(frame, MessageManager.formatMessage(
3317 "label.overview_params", new Object[]
3318 { this.getTitle() }), frame.getWidth(), frame.getHeight());
3320 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3321 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
3324 public void internalFrameClosed(
3325 javax.swing.event.InternalFrameEvent evt)
3327 alignPanel.setOverviewPanel(null);
3331 alignPanel.setOverviewPanel(overview);
3335 public void textColour_actionPerformed(ActionEvent e)
3337 new TextColourChooser().chooseColour(alignPanel, null);
3347 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3359 public void clustalColour_actionPerformed(ActionEvent e)
3361 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3362 viewport.getHiddenRepSequences()));
3372 public void zappoColour_actionPerformed(ActionEvent e)
3374 changeColour(new ZappoColourScheme());
3384 public void taylorColour_actionPerformed(ActionEvent e)
3386 changeColour(new TaylorColourScheme());
3396 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3398 changeColour(new HydrophobicColourScheme());
3408 public void helixColour_actionPerformed(ActionEvent e)
3410 changeColour(new HelixColourScheme());
3420 public void strandColour_actionPerformed(ActionEvent e)
3422 changeColour(new StrandColourScheme());
3432 public void turnColour_actionPerformed(ActionEvent e)
3434 changeColour(new TurnColourScheme());
3444 public void buriedColour_actionPerformed(ActionEvent e)
3446 changeColour(new BuriedColourScheme());
3456 public void nucleotideColour_actionPerformed(ActionEvent e)
3458 changeColour(new NucleotideColourScheme());
3462 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3464 changeColour(new PurinePyrimidineColourScheme());
3468 * public void covariationColour_actionPerformed(ActionEvent e) {
3470 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3474 public void annotationColour_actionPerformed(ActionEvent e)
3476 new AnnotationColourChooser(viewport, alignPanel);
3480 public void annotationColumn_actionPerformed(ActionEvent e)
3482 new AnnotationColumnChooser(viewport, alignPanel);
3486 public void rnahelicesColour_actionPerformed(ActionEvent e)
3488 new RNAHelicesColourChooser(viewport, alignPanel);
3498 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3500 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3509 public void changeColour(ColourSchemeI cs)
3511 // TODO: compare with applet and pull up to model method
3516 if (viewport.getAbovePIDThreshold())
3518 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3520 cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3524 cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3527 if (viewport.getConservationSelected())
3530 Alignment al = (Alignment) viewport.getAlignment();
3531 Conservation c = new Conservation("All",
3532 ResidueProperties.propHash, 3, al.getSequences(), 0,
3536 c.verdict(false, viewport.getConsPercGaps());
3538 cs.setConservation(c);
3540 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3545 cs.setConservation(null);
3548 cs.setConsensus(viewport.getSequenceConsensusHash());
3551 viewport.setGlobalColourScheme(cs);
3553 if (viewport.getColourAppliesToAllGroups())
3556 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3564 if (cs instanceof ClustalxColourScheme)
3566 sg.cs = new ClustalxColourScheme(sg,
3567 viewport.getHiddenRepSequences());
3569 else if (cs instanceof UserColourScheme)
3571 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3577 sg.cs = cs.getClass().newInstance();
3578 } catch (Exception ex)
3583 if (viewport.getAbovePIDThreshold()
3584 || cs instanceof PIDColourScheme
3585 || cs instanceof Blosum62ColourScheme)
3587 sg.cs.setThreshold(threshold, viewport.isIgnoreGapsConsensus());
3589 sg.cs.setConsensus(AAFrequency.calculate(
3590 sg.getSequences(viewport.getHiddenRepSequences()),
3591 sg.getStartRes(), sg.getEndRes() + 1));
3595 sg.cs.setThreshold(0, viewport.isIgnoreGapsConsensus());
3598 if (viewport.getConservationSelected())
3600 Conservation c = new Conservation("Group",
3601 ResidueProperties.propHash, 3, sg.getSequences(viewport
3602 .getHiddenRepSequences()), sg.getStartRes(),
3603 sg.getEndRes() + 1);
3605 c.verdict(false, viewport.getConsPercGaps());
3606 sg.cs.setConservation(c);
3610 sg.cs.setConservation(null);
3615 if (alignPanel.getOverviewPanel() != null)
3617 alignPanel.getOverviewPanel().updateOverviewImage();
3620 alignPanel.paintAlignment(true);
3630 protected void modifyPID_actionPerformed(ActionEvent e)
3632 if (viewport.getAbovePIDThreshold()
3633 && viewport.getGlobalColourScheme() != null)
3635 SliderPanel.setPIDSliderSource(alignPanel,
3636 viewport.getGlobalColourScheme(), "Background");
3637 SliderPanel.showPIDSlider();
3648 protected void modifyConservation_actionPerformed(ActionEvent e)
3650 if (viewport.getConservationSelected()
3651 && viewport.getGlobalColourScheme() != null)
3653 SliderPanel.setConservationSlider(alignPanel,
3654 viewport.getGlobalColourScheme(), "Background");
3655 SliderPanel.showConservationSlider();
3666 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3668 viewport.setConservationSelected(conservationMenuItem.isSelected());
3670 viewport.setAbovePIDThreshold(false);
3671 abovePIDThreshold.setSelected(false);
3673 changeColour(viewport.getGlobalColourScheme());
3675 modifyConservation_actionPerformed(null);
3685 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3687 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3689 conservationMenuItem.setSelected(false);
3690 viewport.setConservationSelected(false);
3692 changeColour(viewport.getGlobalColourScheme());
3694 modifyPID_actionPerformed(null);
3704 public void userDefinedColour_actionPerformed(ActionEvent e)
3706 if (e.getActionCommand().equals(
3707 MessageManager.getString("action.user_defined")))
3709 new UserDefinedColours(alignPanel, null);
3713 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3714 .getUserColourSchemes().get(e.getActionCommand());
3720 public void updateUserColourMenu()
3723 Component[] menuItems = colourMenu.getMenuComponents();
3724 int iSize = menuItems.length;
3725 for (int i = 0; i < iSize; i++)
3727 if (menuItems[i].getName() != null
3728 && menuItems[i].getName().equals("USER_DEFINED"))
3730 colourMenu.remove(menuItems[i]);
3734 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3736 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3737 .getUserColourSchemes().keys();
3739 while (userColours.hasMoreElements())
3741 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3742 userColours.nextElement().toString());
3743 radioItem.setName("USER_DEFINED");
3744 radioItem.addMouseListener(new MouseAdapter()
3747 public void mousePressed(MouseEvent evt)
3749 if (evt.isControlDown()
3750 || SwingUtilities.isRightMouseButton(evt))
3752 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3754 int option = JOptionPane.showInternalConfirmDialog(
3755 jalview.gui.Desktop.desktop,
3757 .getString("label.remove_from_default_list"),
3759 .getString("label.remove_user_defined_colour"),
3760 JOptionPane.YES_NO_OPTION);
3761 if (option == JOptionPane.YES_OPTION)
3763 jalview.gui.UserDefinedColours
3764 .removeColourFromDefaults(radioItem.getText());
3765 colourMenu.remove(radioItem);
3769 radioItem.addActionListener(new ActionListener()
3772 public void actionPerformed(ActionEvent evt)
3774 userDefinedColour_actionPerformed(evt);
3781 radioItem.addActionListener(new ActionListener()
3784 public void actionPerformed(ActionEvent evt)
3786 userDefinedColour_actionPerformed(evt);
3790 colourMenu.insert(radioItem, 15);
3791 colours.add(radioItem);
3803 public void PIDColour_actionPerformed(ActionEvent e)
3805 changeColour(new PIDColourScheme());
3815 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3817 changeColour(new Blosum62ColourScheme());
3827 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3829 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3830 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3831 .getAlignment().getSequenceAt(0), null);
3832 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3833 viewport.getAlignment()));
3834 alignPanel.paintAlignment(true);
3844 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3846 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3847 AlignmentSorter.sortByID(viewport.getAlignment());
3848 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3849 viewport.getAlignment()));
3850 alignPanel.paintAlignment(true);
3860 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3862 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3863 AlignmentSorter.sortByLength(viewport.getAlignment());
3864 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3865 viewport.getAlignment()));
3866 alignPanel.paintAlignment(true);
3876 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3878 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3879 AlignmentSorter.sortByGroup(viewport.getAlignment());
3880 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3881 viewport.getAlignment()));
3883 alignPanel.paintAlignment(true);
3893 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3895 new RedundancyPanel(alignPanel, this);
3905 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3907 if ((viewport.getSelectionGroup() == null)
3908 || (viewport.getSelectionGroup().getSize() < 2))
3910 JOptionPane.showInternalMessageDialog(this, MessageManager
3911 .getString("label.you_must_select_least_two_sequences"),
3912 MessageManager.getString("label.invalid_selection"),
3913 JOptionPane.WARNING_MESSAGE);
3917 JInternalFrame frame = new JInternalFrame();
3918 frame.setContentPane(new PairwiseAlignPanel(viewport));
3919 Desktop.addInternalFrame(frame,
3920 MessageManager.getString("action.pairwise_alignment"), 600,
3932 public void PCAMenuItem_actionPerformed(ActionEvent e)
3934 if (((viewport.getSelectionGroup() != null)
3935 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3936 .getSelectionGroup().getSize() > 0))
3937 || (viewport.getAlignment().getHeight() < 4))
3940 .showInternalMessageDialog(
3943 .getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3945 .getString("label.sequence_selection_insufficient"),
3946 JOptionPane.WARNING_MESSAGE);
3951 new PCAPanel(alignPanel);
3955 public void autoCalculate_actionPerformed(ActionEvent e)
3957 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3958 if (viewport.autoCalculateConsensus)
3960 viewport.firePropertyChange("alignment", null, viewport
3961 .getAlignment().getSequences());
3966 public void sortByTreeOption_actionPerformed(ActionEvent e)
3968 viewport.sortByTree = sortByTree.isSelected();
3972 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3974 viewport.followSelection = listenToViewSelections.isSelected();
3984 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3986 newTreePanel("AV", "PID", "Average distance tree using PID");
3996 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3998 newTreePanel("NJ", "PID", "Neighbour joining tree using PID");
4008 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
4010 newTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
4020 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
4022 newTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
4035 void newTreePanel(String type, String pwType, String title)
4039 if (viewport.getSelectionGroup() != null
4040 && viewport.getSelectionGroup().getSize() > 0)
4042 if (viewport.getSelectionGroup().getSize() < 3)
4048 .getString("label.you_need_more_two_sequences_selected_build_tree"),
4050 .getString("label.not_enough_sequences"),
4051 JOptionPane.WARNING_MESSAGE);
4055 SequenceGroup sg = viewport.getSelectionGroup();
4057 /* Decide if the selection is a column region */
4058 for (SequenceI _s : sg.getSequences())
4060 if (_s.getLength() < sg.getEndRes())
4066 .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
4068 .getString("label.sequences_selection_not_aligned"),
4069 JOptionPane.WARNING_MESSAGE);
4075 title = title + " on region";
4076 tp = new TreePanel(alignPanel, type, pwType);
4080 // are the visible sequences aligned?
4081 if (!viewport.getAlignment().isAligned(false))
4087 .getString("label.sequences_must_be_aligned_before_creating_tree"),
4089 .getString("label.sequences_not_aligned"),
4090 JOptionPane.WARNING_MESSAGE);
4095 if (viewport.getAlignment().getHeight() < 2)
4100 tp = new TreePanel(alignPanel, type, pwType);
4105 if (viewport.viewName != null)
4107 title += viewport.viewName + " of ";
4110 title += this.title;
4112 Desktop.addInternalFrame(tp, title, 600, 500);
4123 public void addSortByOrderMenuItem(String title,
4124 final AlignmentOrder order)
4126 final JMenuItem item = new JMenuItem(MessageManager.formatMessage("action.by_title_param", new Object[]{title}));
4128 item.addActionListener(new java.awt.event.ActionListener()
4131 public void actionPerformed(ActionEvent e)
4133 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4135 // TODO: JBPNote - have to map order entries to curent SequenceI
4137 AlignmentSorter.sortBy(viewport.getAlignment(), order);
4139 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
4142 alignPanel.paintAlignment(true);
4148 * Add a new sort by annotation score menu item
4151 * the menu to add the option to
4153 * the label used to retrieve scores for each sequence on the
4156 public void addSortByAnnotScoreMenuItem(JMenu sort,
4157 final String scoreLabel)
4159 final JMenuItem item = new JMenuItem(scoreLabel);
4161 item.addActionListener(new java.awt.event.ActionListener()
4164 public void actionPerformed(ActionEvent e)
4166 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4167 AlignmentSorter.sortByAnnotationScore(scoreLabel,
4168 viewport.getAlignment());// ,viewport.getSelectionGroup());
4169 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
4170 viewport.getAlignment()));
4171 alignPanel.paintAlignment(true);
4177 * last hash for alignment's annotation array - used to minimise cost of
4180 protected int _annotationScoreVectorHash;
4183 * search the alignment and rebuild the sort by annotation score submenu the
4184 * last alignment annotation vector hash is stored to minimize cost of
4185 * rebuilding in subsequence calls.
4189 public void buildSortByAnnotationScoresMenu()
4191 if (viewport.getAlignment().getAlignmentAnnotation() == null)
4196 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
4198 sortByAnnotScore.removeAll();
4199 // almost certainly a quicker way to do this - but we keep it simple
4200 Hashtable scoreSorts = new Hashtable();
4201 AlignmentAnnotation aann[];
4202 for (SequenceI sqa : viewport.getAlignment().getSequences())
4204 aann = sqa.getAnnotation();
4205 for (int i = 0; aann != null && i < aann.length; i++)
4207 if (aann[i].hasScore() && aann[i].sequenceRef != null)
4209 scoreSorts.put(aann[i].label, aann[i].label);
4213 Enumeration labels = scoreSorts.keys();
4214 while (labels.hasMoreElements())
4216 addSortByAnnotScoreMenuItem(sortByAnnotScore,
4217 (String) labels.nextElement());
4219 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
4222 _annotationScoreVectorHash = viewport.getAlignment()
4223 .getAlignmentAnnotation().hashCode();
4228 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
4229 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
4230 * call. Listeners are added to remove the menu item when the treePanel is
4231 * closed, and adjust the tree leaf to sequence mapping when the alignment is
4235 * Displayed tree window.
4237 * SortBy menu item title.
4240 public void buildTreeMenu()
4242 calculateTree.removeAll();
4243 // build the calculate menu
4245 for (final String type : new String[]
4248 String treecalcnm = MessageManager.getString("label.tree_calc_"
4249 + type.toLowerCase());
4250 for (final String pwtype : ResidueProperties.scoreMatrices.keySet())
4252 JMenuItem tm = new JMenuItem();
4253 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
4254 if (sm.isProtein() == !viewport.getAlignment().isNucleotide())
4256 String smn = MessageManager.getStringOrReturn(
4257 "label.score_model_", sm.getName());
4258 final String title = MessageManager.formatMessage(
4259 "label.treecalc_title", treecalcnm, smn);
4260 tm.setText(title);//
4261 tm.addActionListener(new java.awt.event.ActionListener()
4264 public void actionPerformed(ActionEvent e)
4266 newTreePanel(type, pwtype, title);
4269 calculateTree.add(tm);
4274 sortByTreeMenu.removeAll();
4276 List<Component> comps = PaintRefresher.components.get(viewport
4277 .getSequenceSetId());
4278 List<TreePanel> treePanels = new ArrayList<TreePanel>();
4279 for (Component comp : comps)
4281 if (comp instanceof TreePanel)
4283 treePanels.add((TreePanel) comp);
4287 if (treePanels.size() < 1)
4289 sortByTreeMenu.setVisible(false);
4293 sortByTreeMenu.setVisible(true);
4295 for (final TreePanel tp : treePanels)
4297 final JMenuItem item = new JMenuItem(tp.getTitle());
4298 item.addActionListener(new java.awt.event.ActionListener()
4301 public void actionPerformed(ActionEvent e)
4303 tp.sortByTree_actionPerformed();
4304 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4309 sortByTreeMenu.add(item);
4313 public boolean sortBy(AlignmentOrder alorder, String undoname)
4315 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4316 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4317 if (undoname != null)
4319 addHistoryItem(new OrderCommand(undoname, oldOrder,
4320 viewport.getAlignment()));
4322 alignPanel.paintAlignment(true);
4327 * Work out whether the whole set of sequences or just the selected set will
4328 * be submitted for multiple alignment.
4331 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4333 // Now, check we have enough sequences
4334 AlignmentView msa = null;
4336 if ((viewport.getSelectionGroup() != null)
4337 && (viewport.getSelectionGroup().getSize() > 1))
4339 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4340 // some common interface!
4342 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4343 * SequenceI[sz = seqs.getSize(false)];
4345 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4346 * seqs.getSequenceAt(i); }
4348 msa = viewport.getAlignmentView(true);
4350 else if (viewport.getSelectionGroup() != null
4351 && viewport.getSelectionGroup().getSize() == 1)
4353 int option = JOptionPane.showConfirmDialog(this,
4354 MessageManager.getString("warn.oneseq_msainput_selection"),
4355 MessageManager.getString("label.invalid_selection"),
4356 JOptionPane.OK_CANCEL_OPTION);
4357 if (option == JOptionPane.OK_OPTION)
4359 msa = viewport.getAlignmentView(false);
4364 msa = viewport.getAlignmentView(false);
4370 * Decides what is submitted to a secondary structure prediction service: the
4371 * first sequence in the alignment, or in the current selection, or, if the
4372 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4373 * region or the whole alignment. (where the first sequence in the set is the
4374 * one that the prediction will be for).
4376 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4378 AlignmentView seqs = null;
4380 if ((viewport.getSelectionGroup() != null)
4381 && (viewport.getSelectionGroup().getSize() > 0))
4383 seqs = viewport.getAlignmentView(true);
4387 seqs = viewport.getAlignmentView(false);
4389 // limit sequences - JBPNote in future - could spawn multiple prediction
4391 // TODO: viewport.getAlignment().isAligned is a global state - the local
4392 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4393 if (!viewport.getAlignment().isAligned(false))
4395 seqs.setSequences(new SeqCigar[]
4396 { seqs.getSequences()[0] });
4397 // TODO: if seqs.getSequences().length>1 then should really have warned
4411 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4413 // Pick the tree file
4414 JalviewFileChooser chooser = new JalviewFileChooser(
4415 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4416 chooser.setFileView(new JalviewFileView());
4417 chooser.setDialogTitle(MessageManager
4418 .getString("label.select_newick_like_tree_file"));
4419 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
4421 int value = chooser.showOpenDialog(null);
4423 if (value == JalviewFileChooser.APPROVE_OPTION)
4425 String choice = chooser.getSelectedFile().getPath();
4426 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4427 jalview.io.NewickFile fin = null;
4430 fin = new jalview.io.NewickFile(choice, "File");
4431 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4432 } catch (Exception ex)
4439 .getString("label.problem_reading_tree_file"),
4440 JOptionPane.WARNING_MESSAGE);
4441 ex.printStackTrace();
4443 if (fin != null && fin.hasWarningMessage())
4445 JOptionPane.showMessageDialog(Desktop.desktop, fin
4446 .getWarningMessage(), MessageManager
4447 .getString("label.possible_problem_with_tree_file"),
4448 JOptionPane.WARNING_MESSAGE);
4454 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4456 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4459 public TreePanel ShowNewickTree(NewickFile nf, String title)
4461 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4464 public TreePanel ShowNewickTree(NewickFile nf, String title,
4465 AlignmentView input)
4467 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4470 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4471 int h, int x, int y)
4473 return ShowNewickTree(nf, title, null, w, h, x, y);
4477 * Add a treeviewer for the tree extracted from a newick file object to the
4478 * current alignment view
4485 * Associated alignment input data (or null)
4494 * @return TreePanel handle
4496 public TreePanel ShowNewickTree(NewickFile nf, String title,
4497 AlignmentView input, int w, int h, int x, int y)
4499 TreePanel tp = null;
4505 if (nf.getTree() != null)
4507 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4513 tp.setLocation(x, y);
4516 Desktop.addInternalFrame(tp, title, w, h);
4518 } catch (Exception ex)
4520 ex.printStackTrace();
4526 private boolean buildingMenu = false;
4529 * Generates menu items and listener event actions for web service clients
4532 public void BuildWebServiceMenu()
4534 while (buildingMenu)
4538 System.err.println("Waiting for building menu to finish.");
4540 } catch (Exception e)
4544 final AlignFrame me = this;
4545 buildingMenu = true;
4546 new Thread(new Runnable()
4551 final List<JMenuItem> legacyItems = new ArrayList<JMenuItem>();
4554 System.err.println("Building ws menu again "
4555 + Thread.currentThread());
4556 // TODO: add support for context dependent disabling of services based
4558 // alignment and current selection
4559 // TODO: add additional serviceHandle parameter to specify abstract
4561 // class independently of AbstractName
4562 // TODO: add in rediscovery GUI function to restart discoverer
4563 // TODO: group services by location as well as function and/or
4565 // object broker mechanism.
4566 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4567 final IProgressIndicator af = me;
4568 final JMenu msawsmenu = new JMenu("Alignment");
4569 final JMenu secstrmenu = new JMenu(
4570 "Secondary Structure Prediction");
4571 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4572 final JMenu analymenu = new JMenu("Analysis");
4573 final JMenu dismenu = new JMenu("Protein Disorder");
4574 // final JMenu msawsmenu = new
4575 // JMenu(MessageManager.getString("label.alignment"));
4576 // final JMenu secstrmenu = new
4577 // JMenu(MessageManager.getString("label.secondary_structure_prediction"));
4578 // final JMenu seqsrchmenu = new
4579 // JMenu(MessageManager.getString("label.sequence_database_search"));
4580 // final JMenu analymenu = new
4581 // JMenu(MessageManager.getString("label.analysis"));
4582 // final JMenu dismenu = new
4583 // JMenu(MessageManager.getString("label.protein_disorder"));
4584 // JAL-940 - only show secondary structure prediction services from
4585 // the legacy server
4586 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4588 Discoverer.services != null && (Discoverer.services.size() > 0))
4590 // TODO: refactor to allow list of AbstractName/Handler bindings to
4592 // stored or retrieved from elsewhere
4593 // No MSAWS used any more:
4594 // Vector msaws = null; // (Vector)
4595 // Discoverer.services.get("MsaWS");
4596 Vector secstrpr = (Vector) Discoverer.services
4598 if (secstrpr != null)
4600 // Add any secondary structure prediction services
4601 for (int i = 0, j = secstrpr.size(); i < j; i++)
4603 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4605 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4606 .getServiceClient(sh);
4607 int p = secstrmenu.getItemCount();
4608 impl.attachWSMenuEntry(secstrmenu, me);
4609 int q = secstrmenu.getItemCount();
4610 for (int litm = p; litm < q; litm++)
4612 legacyItems.add(secstrmenu.getItem(litm));
4618 // Add all submenus in the order they should appear on the web
4620 wsmenu.add(msawsmenu);
4621 wsmenu.add(secstrmenu);
4622 wsmenu.add(dismenu);
4623 wsmenu.add(analymenu);
4624 // No search services yet
4625 // wsmenu.add(seqsrchmenu);
4627 javax.swing.SwingUtilities.invokeLater(new Runnable()
4634 webService.removeAll();
4635 // first, add discovered services onto the webservices menu
4636 if (wsmenu.size() > 0)
4638 for (int i = 0, j = wsmenu.size(); i < j; i++)
4640 webService.add(wsmenu.get(i));
4645 webService.add(me.webServiceNoServices);
4647 // TODO: move into separate menu builder class.
4648 boolean new_sspred = false;
4649 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4651 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4652 if (jws2servs != null)
4654 if (jws2servs.hasServices())
4656 jws2servs.attachWSMenuEntry(webService, me);
4657 for (Jws2Instance sv : jws2servs.getServices())
4659 if (sv.description.toLowerCase().contains("jpred"))
4661 for (JMenuItem jmi : legacyItems)
4663 jmi.setVisible(false);
4669 if (jws2servs.isRunning())
4671 JMenuItem tm = new JMenuItem(
4672 "Still discovering JABA Services");
4673 tm.setEnabled(false);
4678 build_urlServiceMenu(me.webService);
4679 build_fetchdbmenu(webService);
4680 for (JMenu item : wsmenu)
4682 if (item.getItemCount() == 0)
4684 item.setEnabled(false);
4688 item.setEnabled(true);
4691 } catch (Exception e)
4694 .debug("Exception during web service menu building process.",
4699 } catch (Exception e)
4702 buildingMenu = false;
4709 * construct any groupURL type service menu entries.
4713 private void build_urlServiceMenu(JMenu webService)
4715 // TODO: remove this code when 2.7 is released
4716 // DEBUG - alignmentView
4718 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4719 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4721 * @Override public void actionPerformed(ActionEvent e) {
4722 * jalview.datamodel.AlignmentView
4723 * .testSelectionViews(af.viewport.getAlignment(),
4724 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4726 * }); webService.add(testAlView);
4728 // TODO: refactor to RestClient discoverer and merge menu entries for
4729 // rest-style services with other types of analysis/calculation service
4730 // SHmmr test client - still being implemented.
4731 // DEBUG - alignmentView
4733 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4736 client.attachWSMenuEntry(
4737 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4743 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4744 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4745 * getProperty("LAST_DIRECTORY"));
4747 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4748 * to Vamsas file"); chooser.setToolTipText("Export");
4750 * int value = chooser.showSaveDialog(this);
4752 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4753 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4754 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4755 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4758 * prototype of an automatically enabled/disabled analysis function
4761 protected void setShowProductsEnabled()
4763 SequenceI[] selection = viewport.getSequenceSelection();
4764 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4765 viewport.getAlignment().getDataset()))
4767 showProducts.setEnabled(true);
4772 showProducts.setEnabled(false);
4777 * search selection for sequence xRef products and build the show products
4782 * @return true if showProducts menu should be enabled.
4784 public boolean canShowProducts(SequenceI[] selection,
4785 boolean isRegionSelection, Alignment dataset)
4787 boolean showp = false;
4790 showProducts.removeAll();
4791 final boolean dna = viewport.getAlignment().isNucleotide();
4792 final Alignment ds = dataset;
4793 String[] ptypes = (selection == null || selection.length == 0) ? null
4794 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4796 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4797 // selection, dataset, true);
4798 final SequenceI[] sel = selection;
4799 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4802 final boolean isRegSel = isRegionSelection;
4803 final AlignFrame af = this;
4804 final String source = ptypes[t];
4805 JMenuItem xtype = new JMenuItem(ptypes[t]);
4806 xtype.addActionListener(new ActionListener()
4810 public void actionPerformed(ActionEvent e)
4812 // TODO: new thread for this call with vis-delay
4813 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4814 isRegSel, dna, source);
4818 showProducts.add(xtype);
4820 showProducts.setVisible(showp);
4821 showProducts.setEnabled(showp);
4822 } catch (Exception e)
4824 jalview.bin.Cache.log
4825 .warn("canTranslate threw an exception - please report to help@jalview.org",
4832 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4833 boolean isRegSel, boolean dna, String source)
4835 final boolean fisRegSel = isRegSel;
4836 final boolean fdna = dna;
4837 final String fsrc = source;
4838 final AlignFrame ths = this;
4839 final SequenceI[] fsel = sel;
4840 Runnable foo = new Runnable()
4846 final long sttime = System.currentTimeMillis();
4847 ths.setProgressBar(MessageManager.formatMessage("status.searching_for_sequences_from", new Object[]{fsrc}), sttime);
4850 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4854 Alignment prods = CrossRef
4855 .findXrefSequences(fsel, fdna, fsrc, ds);
4858 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4859 for (int s = 0; s < sprods.length; s++)
4861 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4862 if (ds.getSequences() == null
4863 || !ds.getSequences().contains(
4864 sprods[s].getDatasetSequence()))
4866 ds.addSequence(sprods[s].getDatasetSequence());
4868 sprods[s].updatePDBIds();
4870 Alignment al = new Alignment(sprods);
4871 Set<AlignedCodonFrame> cf = prods.getCodonFrames();
4873 for (AlignedCodonFrame acf : cf)
4875 al.addCodonFrame(acf);
4877 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4879 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4880 + " for " + ((fisRegSel) ? "selected region of " : "")
4882 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4887 System.err.println("No Sequences generated for xRef type "
4890 } catch (Exception e)
4892 jalview.bin.Cache.log.error(
4893 "Exception when finding crossreferences", e);
4894 } catch (OutOfMemoryError e)
4896 new OOMWarning("whilst fetching crossreferences", e);
4899 jalview.bin.Cache.log.error("Error when finding crossreferences",
4902 ths.setProgressBar(MessageManager.formatMessage("status.finished_searching_for_sequences_from", new Object[]{fsrc}),
4907 Thread frunner = new Thread(foo);
4911 public boolean canShowTranslationProducts(SequenceI[] selection,
4912 AlignmentI alignment)
4917 return (jalview.analysis.Dna.canTranslate(selection,
4918 viewport.getViewAsVisibleContigs(true)));
4919 } catch (Exception e)
4921 jalview.bin.Cache.log
4922 .warn("canTranslate threw an exception - please report to help@jalview.org",
4929 * Construct and display a new frame containing the translation of this
4930 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4933 public void showTranslation_actionPerformed(ActionEvent e)
4935 AlignmentI al = null;
4938 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4940 al = dna.translateCdna();
4941 } catch (Exception ex)
4943 jalview.bin.Cache.log.error(
4944 "Exception during translation. Please report this !", ex);
4945 final String msg = MessageManager
4946 .getString("label.error_when_translating_sequences_submit_bug_report");
4947 final String title = MessageManager
4948 .getString("label.implementation_error")
4949 + MessageManager.getString("translation_failed");
4950 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4951 JOptionPane.ERROR_MESSAGE);
4954 if (al == null || al.getHeight() == 0)
4956 final String msg = MessageManager
4957 .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4958 final String title = MessageManager
4959 .getString("label.translation_failed");
4960 JOptionPane.showMessageDialog(Desktop.desktop, msg, title,
4961 JOptionPane.WARNING_MESSAGE);
4965 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4966 af.setFileFormat(this.currentFileFormat);
4967 final String newTitle = MessageManager.formatMessage(
4968 "label.translation_of_params", new Object[]
4969 { this.getTitle() });
4970 af.setTitle(newTitle);
4971 viewport.openSplitFrame(af, viewport.getAlignment());
4972 // Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4973 // // enable next line for linked editing
4974 // viewport.getStructureSelectionManager().addCommandListener(viewport);
4979 * Set the file format
4983 public void setFileFormat(String fileFormat)
4985 this.currentFileFormat = fileFormat;
4989 * Try to load a features file onto the alignment.
4992 * contents or path to retrieve file
4994 * access mode of file (see jalview.io.AlignFile)
4995 * @return true if features file was parsed corectly.
4997 public boolean parseFeaturesFile(String file, String type)
4999 boolean featuresFile = false;
5002 featuresFile = new FeaturesFile(file, type).parse(viewport
5003 .getAlignment().getDataset(), alignPanel.getSeqPanel().seqCanvas
5004 .getFeatureRenderer().getFeatureColours(), false,
5005 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
5006 } catch (Exception ex)
5008 ex.printStackTrace();
5013 viewport.setShowSequenceFeatures(true);
5014 showSeqFeatures.setSelected(true);
5015 if (alignPanel.getSeqPanel().seqCanvas.fr != null)
5017 // update the min/max ranges where necessary
5018 alignPanel.getSeqPanel().seqCanvas.fr.findAllFeatures(true);
5020 if (featureSettings != null)
5022 featureSettings.setTableData();
5024 alignPanel.paintAlignment(true);
5027 return featuresFile;
5031 public void dragEnter(DropTargetDragEvent evt)
5036 public void dragExit(DropTargetEvent evt)
5041 public void dragOver(DropTargetDragEvent evt)
5046 public void dropActionChanged(DropTargetDragEvent evt)
5051 public void drop(DropTargetDropEvent evt)
5053 Transferable t = evt.getTransferable();
5054 java.util.List files = null;
5058 DataFlavor uriListFlavor = new DataFlavor(
5059 "text/uri-list;class=java.lang.String");
5060 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
5062 // Works on Windows and MacOSX
5063 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5064 files = (java.util.List) t
5065 .getTransferData(DataFlavor.javaFileListFlavor);
5067 else if (t.isDataFlavorSupported(uriListFlavor))
5069 // This is used by Unix drag system
5070 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
5071 String data = (String) t.getTransferData(uriListFlavor);
5072 files = new java.util.ArrayList(1);
5073 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
5074 data, "\r\n"); st.hasMoreTokens();)
5076 String s = st.nextToken();
5077 if (s.startsWith("#"))
5079 // the line is a comment (as per the RFC 2483)
5083 java.net.URI uri = new java.net.URI(s);
5084 // check to see if we can handle this kind of URI
5085 if (uri.getScheme().toLowerCase().startsWith("http"))
5087 files.add(uri.toString());
5091 // otherwise preserve old behaviour: catch all for file objects
5092 java.io.File file = new java.io.File(uri);
5093 files.add(file.toString());
5097 } catch (Exception e)
5099 e.printStackTrace();
5105 // check to see if any of these files have names matching sequences in
5107 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5108 .getAlignment().getSequencesArray());
5110 * Object[] { String,SequenceI}
5112 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
5113 ArrayList<String> filesnotmatched = new ArrayList<String>();
5114 for (int i = 0; i < files.size(); i++)
5116 String file = files.get(i).toString();
5118 String protocol = FormatAdapter.checkProtocol(file);
5119 if (protocol == jalview.io.FormatAdapter.FILE)
5121 File fl = new File(file);
5122 pdbfn = fl.getName();
5124 else if (protocol == jalview.io.FormatAdapter.URL)
5126 URL url = new URL(file);
5127 pdbfn = url.getFile();
5129 if (pdbfn.length() > 0)
5131 // attempt to find a match in the alignment
5132 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
5133 int l = 0, c = pdbfn.indexOf(".");
5134 while (mtch == null && c != -1)
5139 } while ((c = pdbfn.indexOf(".", l)) > l);
5142 pdbfn = pdbfn.substring(0, l);
5144 mtch = idm.findAllIdMatches(pdbfn);
5151 type = new IdentifyFile().Identify(file, protocol);
5152 } catch (Exception ex)
5158 if (type.equalsIgnoreCase("PDB"))
5160 filesmatched.add(new Object[]
5161 { file, protocol, mtch });
5166 // File wasn't named like one of the sequences or wasn't a PDB file.
5167 filesnotmatched.add(file);
5171 if (filesmatched.size() > 0)
5173 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
5179 "label.automatically_associate_pdb_files_with_sequences_same_name",
5186 .getString("label.automatically_associate_pdb_files_by_name"),
5187 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
5190 for (Object[] fm : filesmatched)
5192 // try and associate
5193 // TODO: may want to set a standard ID naming formalism for
5194 // associating PDB files which have no IDs.
5195 for (SequenceI toassoc : (SequenceI[]) fm[2])
5197 PDBEntry pe = new AssociatePdbFileWithSeq()
5198 .associatePdbWithSeq((String) fm[0],
5199 (String) fm[1], toassoc, false,
5203 System.err.println("Associated file : "
5204 + ((String) fm[0]) + " with "
5205 + toassoc.getDisplayId(true));
5209 alignPanel.paintAlignment(true);
5213 if (filesnotmatched.size() > 0)
5216 && (Cache.getDefault(
5217 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
5220 "<html>"+MessageManager
5222 "label.ignore_unmatched_dropped_files_info",
5227 .toString() })+"</html>",
5229 .getString("label.ignore_unmatched_dropped_files"),
5230 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
5234 for (String fn : filesnotmatched)
5236 loadJalviewDataFile(fn, null, null, null);
5240 } catch (Exception ex)
5242 ex.printStackTrace();
5248 * Attempt to load a "dropped" file or URL string: First by testing whether
5249 * it's and Annotation file, then a JNet file, and finally a features file. If
5250 * all are false then the user may have dropped an alignment file onto this
5254 * either a filename or a URL string.
5256 public void loadJalviewDataFile(String file, String protocol,
5257 String format, SequenceI assocSeq)
5261 if (protocol == null)
5263 protocol = jalview.io.FormatAdapter.checkProtocol(file);
5265 // if the file isn't identified, or not positively identified as some
5266 // other filetype (PFAM is default unidentified alignment file type) then
5267 // try to parse as annotation.
5268 boolean isAnnotation = (format == null || format
5269 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
5270 .annotateAlignmentView(viewport, file, protocol)
5275 // first see if its a T-COFFEE score file
5276 TCoffeeScoreFile tcf = null;
5279 tcf = new TCoffeeScoreFile(file, protocol);
5282 if (tcf.annotateAlignment(viewport.getAlignment(), true))
5284 tcoffeeColour.setEnabled(true);
5285 tcoffeeColour.setSelected(true);
5286 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
5287 isAnnotation = true;
5289 .setText(MessageManager
5290 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
5294 // some problem - if no warning its probable that the ID matching
5295 // process didn't work
5299 tcf.getWarningMessage() == null ? MessageManager
5300 .getString("label.check_file_matches_sequence_ids_alignment")
5301 : tcf.getWarningMessage(),
5303 .getString("label.problem_reading_tcoffee_score_file"),
5304 JOptionPane.WARNING_MESSAGE);
5311 } catch (Exception x)
5314 .debug("Exception when processing data source as T-COFFEE score file",
5320 // try to see if its a JNet 'concise' style annotation file *before*
5322 // try to parse it as a features file
5325 format = new IdentifyFile().Identify(file, protocol);
5327 if (format.equalsIgnoreCase("JnetFile"))
5329 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
5331 new JnetAnnotationMaker();
5332 JnetAnnotationMaker.add_annotation(predictions,
5333 viewport.getAlignment(), 0, false);
5334 isAnnotation = true;
5339 * if (format.equalsIgnoreCase("PDB")) {
5341 * String pdbfn = ""; // try to match up filename with sequence id
5342 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
5343 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
5344 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
5345 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
5346 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
5347 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
5348 * // attempt to find a match in the alignment SequenceI mtch =
5349 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
5350 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
5351 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
5352 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
5353 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
5354 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
5355 * { System.err.println("Associated file : " + file + " with " +
5356 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
5357 * TODO: maybe need to load as normal otherwise return; } }
5359 // try to parse it as a features file
5360 boolean isGroupsFile = parseFeaturesFile(file, protocol);
5361 // if it wasn't a features file then we just treat it as a general
5362 // alignment file to load into the current view.
5365 new FileLoader().LoadFile(viewport, file, protocol, format);
5369 alignPanel.paintAlignment(true);
5377 alignPanel.adjustAnnotationHeight();
5378 viewport.updateSequenceIdColours();
5379 buildSortByAnnotationScoresMenu();
5380 alignPanel.paintAlignment(true);
5382 } catch (Exception ex)
5384 ex.printStackTrace();
5385 } catch (OutOfMemoryError oom)
5390 } catch (Exception x)
5396 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5397 : "using " + protocol + " from " + file)
5399 + (format != null ? "(parsing as '" + format
5400 + "' file)" : ""), oom, Desktop.desktop);
5405 * Method invoked by the ChangeListener on the tabbed pane, in other words
5406 * when a different tabbed pane is selected by the user or programmatically.
5409 public void tabSelectionChanged(int index)
5413 alignPanel = alignPanels.get(index);
5414 viewport = alignPanel.av;
5415 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5416 setMenusFromViewport(viewport);
5420 * If there is a frame linked to this one in a SplitPane, switch it to the
5421 * same view tab index. No infinite recursion of calls should happen, since
5422 * tabSelectionChanged() should not get invoked on setting the selected
5423 * index to an unchanged value. Guard against setting an invalid index
5424 * before the new view peer tab has been created.
5426 final AlignViewportI peer = viewport.getCodingComplement();
5429 AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame;
5430 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
5432 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
5438 * On right mouse click on view tab, prompt for and set new view name.
5441 public void tabbedPane_mousePressed(MouseEvent e)
5443 if (SwingUtilities.isRightMouseButton(e))
5445 String msg = MessageManager.getString("label.enter_view_name");
5446 String reply = JOptionPane.showInternalInputDialog(this, msg, msg,
5447 JOptionPane.QUESTION_MESSAGE);
5451 viewport.viewName = reply;
5452 // TODO warn if reply is in getExistingViewNames()?
5453 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5458 public AlignViewport getCurrentView()
5464 * Open the dialog for regex description parsing.
5467 protected void extractScores_actionPerformed(ActionEvent e)
5469 ParseProperties pp = new jalview.analysis.ParseProperties(
5470 viewport.getAlignment());
5471 // TODO: verify regex and introduce GUI dialog for version 2.5
5472 // if (pp.getScoresFromDescription("col", "score column ",
5473 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5475 if (pp.getScoresFromDescription("description column",
5476 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5478 buildSortByAnnotationScoresMenu();
5486 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5490 protected void showDbRefs_actionPerformed(ActionEvent e)
5492 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5498 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5502 protected void showNpFeats_actionPerformed(ActionEvent e)
5504 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5508 * find the viewport amongst the tabs in this alignment frame and close that
5513 public boolean closeView(AlignViewportI av)
5517 this.closeMenuItem_actionPerformed(false);
5520 Component[] comp = tabbedPane.getComponents();
5521 for (int i = 0; comp != null && i < comp.length; i++)
5523 if (comp[i] instanceof AlignmentPanel)
5525 if (((AlignmentPanel) comp[i]).av == av)
5528 closeView((AlignmentPanel) comp[i]);
5536 protected void build_fetchdbmenu(JMenu webService)
5538 // Temporary hack - DBRef Fetcher always top level ws entry.
5539 // TODO We probably want to store a sequence database checklist in
5540 // preferences and have checkboxes.. rather than individual sources selected
5542 final JMenu rfetch = new JMenu(
5543 MessageManager.getString("action.fetch_db_references"));
5544 rfetch.setToolTipText(MessageManager
5545 .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5546 webService.add(rfetch);
5548 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5549 MessageManager.getString("option.trim_retrieved_seqs"));
5550 trimrs.setToolTipText(MessageManager
5551 .getString("label.trim_retrieved_sequences"));
5552 trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true));
5553 trimrs.addActionListener(new ActionListener()
5556 public void actionPerformed(ActionEvent e)
5558 trimrs.setSelected(trimrs.isSelected());
5559 Cache.setProperty("TRIM_FETCHED_DATASET_SEQS",
5560 Boolean.valueOf(trimrs.isSelected()).toString());
5564 JMenuItem fetchr = new JMenuItem(
5565 MessageManager.getString("label.standard_databases"));
5566 fetchr.setToolTipText(MessageManager
5567 .getString("label.fetch_embl_uniprot"));
5568 fetchr.addActionListener(new ActionListener()
5572 public void actionPerformed(ActionEvent e)
5574 new Thread(new Runnable()
5580 new jalview.ws.DBRefFetcher(alignPanel.av
5581 .getSequenceSelection(), alignPanel.alignFrame)
5582 .fetchDBRefs(false);
5590 final AlignFrame me = this;
5591 new Thread(new Runnable()
5596 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5597 .getSequenceFetcherSingleton(me);
5598 javax.swing.SwingUtilities.invokeLater(new Runnable()
5603 String[] dbclasses = sf.getOrderedSupportedSources();
5604 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5605 // jalview.util.QuickSort.sort(otherdb, otherdb);
5606 List<DbSourceProxy> otherdb;
5607 JMenu dfetch = new JMenu();
5608 JMenu ifetch = new JMenu();
5609 JMenuItem fetchr = null;
5610 int comp = 0, icomp = 0, mcomp = 15;
5611 String mname = null;
5613 for (String dbclass : dbclasses)
5615 otherdb = sf.getSourceProxy(dbclass);
5616 // add a single entry for this class, or submenu allowing 'fetch
5618 if (otherdb == null || otherdb.size() < 1)
5622 // List<DbSourceProxy> dbs=otherdb;
5623 // otherdb=new ArrayList<DbSourceProxy>();
5624 // for (DbSourceProxy db:dbs)
5626 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5630 mname = "From " + dbclass;
5632 if (otherdb.size() == 1)
5634 final DbSourceProxy[] dassource = otherdb
5635 .toArray(new DbSourceProxy[0]);
5636 DbSourceProxy src = otherdb.get(0);
5637 fetchr = new JMenuItem(src.getDbSource());
5638 fetchr.addActionListener(new ActionListener()
5642 public void actionPerformed(ActionEvent e)
5644 new Thread(new Runnable()
5650 new jalview.ws.DBRefFetcher(alignPanel.av
5651 .getSequenceSelection(),
5652 alignPanel.alignFrame, dassource)
5653 .fetchDBRefs(false);
5659 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{src.getDbName()})));
5665 final DbSourceProxy[] dassource = otherdb
5666 .toArray(new DbSourceProxy[0]);
5668 DbSourceProxy src = otherdb.get(0);
5669 fetchr = new JMenuItem(MessageManager.formatMessage(
5670 "label.fetch_all_param", new Object[]
5671 { src.getDbSource() }));
5672 fetchr.addActionListener(new ActionListener()
5675 public void actionPerformed(ActionEvent e)
5677 new Thread(new Runnable()
5683 new jalview.ws.DBRefFetcher(alignPanel.av
5684 .getSequenceSelection(),
5685 alignPanel.alignFrame, dassource)
5686 .fetchDBRefs(false);
5692 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage("label.fetch_retrieve_from_all_sources", new Object[]{Integer.valueOf(otherdb.size()).toString(), src.getDbSource(), src.getDbName()})));
5695 // and then build the rest of the individual menus
5696 ifetch = new JMenu(MessageManager.formatMessage("label.source_from_db_source", new Object[]{src.getDbSource()}));
5698 String imname = null;
5700 for (DbSourceProxy sproxy : otherdb)
5702 String dbname = sproxy.getDbName();
5703 String sname = dbname.length() > 5 ? dbname.substring(0,
5704 5) + "..." : dbname;
5705 String msname = dbname.length() > 10 ? dbname.substring(
5706 0, 10) + "..." : dbname;
5709 imname = MessageManager.formatMessage("label.from_msname", new Object[]{sname});
5711 fetchr = new JMenuItem(msname);
5712 final DbSourceProxy[] dassrc =
5714 fetchr.addActionListener(new ActionListener()
5718 public void actionPerformed(ActionEvent e)
5720 new Thread(new Runnable()
5726 new jalview.ws.DBRefFetcher(alignPanel.av
5727 .getSequenceSelection(),
5728 alignPanel.alignFrame, dassrc)
5729 .fetchDBRefs(false);
5735 fetchr.setToolTipText("<html>"
5736 + MessageManager.formatMessage("label.fetch_retrieve_from", new Object[]{dbname}));
5739 if (++icomp >= mcomp || i == (otherdb.size()))
5741 ifetch.setText(MessageManager.formatMessage(
5742 "label.source_to_target", imname, sname));
5744 ifetch = new JMenu();
5752 if (comp >= mcomp || dbi >= (dbclasses.length))
5754 dfetch.setText(MessageManager.formatMessage(
5755 "label.source_to_target", mname, dbclass));
5757 dfetch = new JMenu();
5770 * Left justify the whole alignment.
5773 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5775 AlignmentI al = viewport.getAlignment();
5777 viewport.firePropertyChange("alignment", null, al);
5781 * Right justify the whole alignment.
5784 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5786 AlignmentI al = viewport.getAlignment();
5788 viewport.firePropertyChange("alignment", null, al);
5791 public void setShowSeqFeatures(boolean b)
5793 showSeqFeatures.setSelected(true);
5794 viewport.setShowSequenceFeatures(true);
5801 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5802 * awt.event.ActionEvent)
5805 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5807 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5808 alignPanel.paintAlignment(true);
5815 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5819 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5821 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5822 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5830 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5831 * .event.ActionEvent)
5834 protected void showGroupConservation_actionPerformed(ActionEvent e)
5836 viewport.setShowGroupConservation(showGroupConservation.getState());
5837 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5844 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5845 * .event.ActionEvent)
5848 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5850 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5851 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5858 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5859 * .event.ActionEvent)
5862 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5864 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5865 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5869 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5871 showSequenceLogo.setState(true);
5872 viewport.setShowSequenceLogo(true);
5873 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5874 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5878 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5880 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5887 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5888 * .event.ActionEvent)
5891 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5893 if (avc.makeGroupsFromSelection())
5895 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5896 alignPanel.updateAnnotation();
5897 alignPanel.paintAlignment(true);
5900 public void clearAlignmentSeqRep()
5902 // TODO refactor alignmentseqrep to controller
5903 if (viewport.getAlignment().hasSeqrep()) {
5904 viewport.getAlignment().setSeqrep(null);
5905 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5906 alignPanel.updateAnnotation();
5907 alignPanel.paintAlignment(true);
5912 protected void createGroup_actionPerformed(ActionEvent e)
5914 if (avc.createGroup())
5916 alignPanel.alignmentChanged();
5921 protected void unGroup_actionPerformed(ActionEvent e)
5925 alignPanel.alignmentChanged();
5930 * make the given alignmentPanel the currently selected tab
5932 * @param alignmentPanel
5934 public void setDisplayedView(AlignmentPanel alignmentPanel)
5936 if (!viewport.getSequenceSetId().equals(
5937 alignmentPanel.av.getSequenceSetId()))
5939 throw new Error(MessageManager.getString("error.implementation_error_cannot_show_view_alignment_frame"));
5941 if (tabbedPane != null
5942 && tabbedPane.getTabCount() > 0
5943 && alignPanels.indexOf(alignmentPanel) != tabbedPane
5944 .getSelectedIndex())
5946 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5951 * Action on selection of menu options to Show or Hide annotations.
5954 * @param forSequences
5955 * update sequence-related annotations
5956 * @param forAlignment
5957 * update non-sequence-related annotations
5960 protected void setAnnotationsVisibility(boolean visible,
5961 boolean forSequences, boolean forAlignment)
5963 for (AlignmentAnnotation aa : alignPanel.getAlignment()
5964 .getAlignmentAnnotation())
5966 boolean apply = (aa.sequenceRef == null && forAlignment)
5967 || (aa.sequenceRef != null && forSequences);
5970 aa.visible = visible;
5973 alignPanel.validateAnnotationDimensions(false);
5974 alignPanel.alignmentChanged();
5978 * Store selected annotation sort order for the view and repaint.
5981 protected void sortAnnotations_actionPerformed()
5983 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5985 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5986 alignPanel.paintAlignment(true);
5991 * @return alignment panels in this alignment frame
5993 public List<? extends AlignmentViewPanel> getAlignPanels()
5995 return alignPanels == null ? Arrays.asList(alignPanel)
6000 * Open a new alignment window, with the cDNA associated with this (protein)
6001 * alignment, aligned as is the protein.
6004 protected void viewAsCdna_actionPerformed()
6006 final AlignmentI alignment = getViewport().getAlignment();
6007 Set<AlignedCodonFrame> mappings = alignment.getCodonFrames();
6008 if (mappings == null)
6012 List<SequenceI> cdnaSeqs = new ArrayList<SequenceI>();
6013 for (SequenceI aaSeq : alignment.getSequences()) {
6014 for (AlignedCodonFrame acf : mappings) {
6015 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
6019 * There is a cDNA mapping for this protein sequence - add to new
6020 * alignment. It will share the same dataset sequence as other mapped
6021 * cDNA (no new mappings need to be created).
6023 final Sequence newSeq = new Sequence(dnaSeq);
6024 newSeq.setDatasetSequence(dnaSeq);
6025 cdnaSeqs.add(newSeq);
6029 if (cdnaSeqs.size() == 0)
6031 // show a warning dialog no mapped cDNA
6034 AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs
6036 AlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
6037 AlignFrame.DEFAULT_HEIGHT);
6038 cdna.alignAs(alignment);
6039 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
6041 Desktop.addInternalFrame(alignFrame, newtitle,
6042 AlignFrame.DEFAULT_WIDTH,
6043 AlignFrame.DEFAULT_HEIGHT);
6048 class PrintThread extends Thread
6052 public PrintThread(AlignmentPanel ap)
6057 static PageFormat pf;
6062 PrinterJob printJob = PrinterJob.getPrinterJob();
6066 printJob.setPrintable(ap, pf);
6070 printJob.setPrintable(ap);
6073 if (printJob.printDialog())
6078 } catch (Exception PrintException)
6080 PrintException.printStackTrace();