2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.analysis.CrossRef;
26 import jalview.analysis.Dna;
27 import jalview.analysis.ParseProperties;
28 import jalview.analysis.SequenceIdMatcher;
29 import jalview.api.AlignExportSettingI;
30 import jalview.api.AlignViewControllerGuiI;
31 import jalview.api.AlignViewControllerI;
32 import jalview.api.AlignViewportI;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.api.FeatureSettingsControllerI;
35 import jalview.api.SplitContainerI;
36 import jalview.api.ViewStyleI;
37 import jalview.api.analysis.SimilarityParamsI;
38 import jalview.bin.Cache;
39 import jalview.bin.Jalview;
40 import jalview.commands.CommandI;
41 import jalview.commands.EditCommand;
42 import jalview.commands.EditCommand.Action;
43 import jalview.commands.OrderCommand;
44 import jalview.commands.RemoveGapColCommand;
45 import jalview.commands.RemoveGapsCommand;
46 import jalview.commands.SlideSequencesCommand;
47 import jalview.commands.TrimRegionCommand;
48 import jalview.datamodel.AlignedCodonFrame;
49 import jalview.datamodel.Alignment;
50 import jalview.datamodel.AlignmentAnnotation;
51 import jalview.datamodel.AlignmentExportData;
52 import jalview.datamodel.AlignmentI;
53 import jalview.datamodel.AlignmentOrder;
54 import jalview.datamodel.AlignmentView;
55 import jalview.datamodel.ColumnSelection;
56 import jalview.datamodel.HiddenColumns;
57 import jalview.datamodel.HiddenMarkovModel;
58 import jalview.datamodel.HiddenSequences;
59 import jalview.datamodel.PDBEntry;
60 import jalview.datamodel.SeqCigar;
61 import jalview.datamodel.Sequence;
62 import jalview.datamodel.SequenceGroup;
63 import jalview.datamodel.SequenceI;
64 import jalview.gui.ColourMenuHelper.ColourChangeListener;
65 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
66 import jalview.hmmer.HMMAlign;
67 import jalview.hmmer.HMMBuild;
68 import jalview.hmmer.HMMERParamStore;
69 import jalview.hmmer.HMMERPreset;
70 import jalview.hmmer.HMMSearch;
71 import jalview.hmmer.HmmerCommand;
72 import jalview.io.AlignmentProperties;
73 import jalview.io.AnnotationFile;
74 import jalview.io.BioJsHTMLOutput;
75 import jalview.io.DataSourceType;
76 import jalview.io.FileFormat;
77 import jalview.io.FileFormatI;
78 import jalview.io.FileFormats;
79 import jalview.io.FileLoader;
80 import jalview.io.FileParse;
81 import jalview.io.FormatAdapter;
82 import jalview.io.HtmlSvgOutput;
83 import jalview.io.IdentifyFile;
84 import jalview.io.JPredFile;
85 import jalview.io.JalviewFileChooser;
86 import jalview.io.JalviewFileView;
87 import jalview.io.JnetAnnotationMaker;
88 import jalview.io.NewickFile;
89 import jalview.io.ScoreMatrixFile;
90 import jalview.io.TCoffeeScoreFile;
91 import jalview.io.vcf.VCFLoader;
92 import jalview.jbgui.GAlignFrame;
93 import jalview.schemes.ColourSchemeI;
94 import jalview.schemes.ColourSchemes;
95 import jalview.schemes.ResidueColourScheme;
96 import jalview.schemes.TCoffeeColourScheme;
97 import jalview.util.MessageManager;
98 import jalview.util.StringUtils;
99 import jalview.viewmodel.AlignmentViewport;
100 import jalview.viewmodel.ViewportRanges;
101 import jalview.ws.DBRefFetcher;
102 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
103 import jalview.ws.jws1.Discoverer;
104 import jalview.ws.jws2.Jws2Discoverer;
105 import jalview.ws.jws2.jabaws2.Jws2Instance;
106 import jalview.ws.params.ArgumentI;
107 import jalview.ws.params.ParamDatastoreI;
108 import jalview.ws.params.WsParamSetI;
109 import jalview.ws.seqfetcher.DbSourceProxy;
111 import java.awt.BorderLayout;
112 import java.awt.Component;
113 import java.awt.Rectangle;
114 import java.awt.Toolkit;
115 import java.awt.datatransfer.Clipboard;
116 import java.awt.datatransfer.DataFlavor;
117 import java.awt.datatransfer.StringSelection;
118 import java.awt.datatransfer.Transferable;
119 import java.awt.dnd.DnDConstants;
120 import java.awt.dnd.DropTargetDragEvent;
121 import java.awt.dnd.DropTargetDropEvent;
122 import java.awt.dnd.DropTargetEvent;
123 import java.awt.dnd.DropTargetListener;
124 import java.awt.event.ActionEvent;
125 import java.awt.event.ActionListener;
126 import java.awt.event.FocusAdapter;
127 import java.awt.event.FocusEvent;
128 import java.awt.event.ItemEvent;
129 import java.awt.event.ItemListener;
130 import java.awt.event.KeyAdapter;
131 import java.awt.event.KeyEvent;
132 import java.awt.event.MouseEvent;
133 import java.awt.print.PageFormat;
134 import java.awt.print.PrinterJob;
135 import java.beans.PropertyChangeEvent;
137 import java.io.FileWriter;
138 import java.io.IOException;
139 import java.io.PrintWriter;
141 import java.util.ArrayList;
142 import java.util.Arrays;
143 import java.util.Deque;
144 import java.util.Enumeration;
145 import java.util.HashMap;
146 import java.util.Hashtable;
147 import java.util.List;
148 import java.util.Map;
149 import java.util.Scanner;
150 import java.util.Vector;
152 import javax.swing.JCheckBoxMenuItem;
153 import javax.swing.JEditorPane;
154 import javax.swing.JFileChooser;
155 import javax.swing.JFrame;
156 import javax.swing.JInternalFrame;
157 import javax.swing.JLayeredPane;
158 import javax.swing.JMenu;
159 import javax.swing.JMenuItem;
160 import javax.swing.JOptionPane;
161 import javax.swing.JScrollPane;
162 import javax.swing.SwingUtilities;
168 * @version $Revision$
170 public class AlignFrame extends GAlignFrame implements DropTargetListener,
171 IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener
174 Map<String, Float> distribution = new HashMap<>(); // temporary
176 public static final int DEFAULT_WIDTH = 700;
178 public static final int DEFAULT_HEIGHT = 500;
181 * The currently displayed panel (selected tabbed view if more than one)
183 public AlignmentPanel alignPanel;
185 AlignViewport viewport;
187 public AlignViewControllerI avc;
189 * The selected HMM for this align frame
191 SequenceI selectedHMMSequence;
193 List<AlignmentPanel> alignPanels = new ArrayList<>();
196 * Last format used to load or save alignments in this window
198 FileFormatI currentFileFormat = null;
201 * Current filename for this alignment
203 String fileName = null;
207 * Creates a new AlignFrame object with specific width and height.
213 public AlignFrame(AlignmentI al, int width, int height)
215 this(al, null, width, height);
219 * Creates a new AlignFrame object with specific width, height and
225 * @param sequenceSetId
227 public AlignFrame(AlignmentI al, int width, int height,
228 String sequenceSetId)
230 this(al, null, width, height, sequenceSetId);
234 * Creates a new AlignFrame object with specific width, height and
240 * @param sequenceSetId
243 public AlignFrame(AlignmentI al, int width, int height,
244 String sequenceSetId, String viewId)
246 this(al, null, width, height, sequenceSetId, viewId);
250 * new alignment window with hidden columns
254 * @param hiddenColumns
255 * ColumnSelection or null
257 * Width of alignment frame
261 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
264 this(al, hiddenColumns, width, height, null);
268 * Create alignment frame for al with hiddenColumns, a specific width and
269 * height, and specific sequenceId
272 * @param hiddenColumns
275 * @param sequenceSetId
278 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
279 int height, String sequenceSetId)
281 this(al, hiddenColumns, width, height, sequenceSetId, null);
285 * Create alignment frame for al with hiddenColumns, a specific width and
286 * height, and specific sequenceId
289 * @param hiddenColumns
292 * @param sequenceSetId
297 public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width,
298 int height, String sequenceSetId, String viewId)
300 setSize(width, height);
302 if (al.getDataset() == null)
307 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
309 alignPanel = new AlignmentPanel(this, viewport);
311 addAlignmentPanel(alignPanel, true);
315 public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
316 HiddenColumns hiddenColumns, int width, int height)
318 setSize(width, height);
320 if (al.getDataset() == null)
325 viewport = new AlignViewport(al, hiddenColumns);
327 if (hiddenSeqs != null && hiddenSeqs.length > 0)
329 viewport.hideSequence(hiddenSeqs);
331 alignPanel = new AlignmentPanel(this, viewport);
332 addAlignmentPanel(alignPanel, true);
337 * Make a new AlignFrame from existing alignmentPanels
344 public AlignFrame(AlignmentPanel ap)
348 addAlignmentPanel(ap, false);
353 * initalise the alignframe from the underlying viewport data and the
358 if (!Jalview.isHeadlessMode())
360 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
363 avc = new jalview.controller.AlignViewController(this, viewport,
365 if (viewport.getAlignmentConservationAnnotation() == null)
367 // BLOSUM62Colour.setEnabled(false);
368 conservationMenuItem.setEnabled(false);
369 modifyConservation.setEnabled(false);
370 // PIDColour.setEnabled(false);
371 // abovePIDThreshold.setEnabled(false);
372 // modifyPID.setEnabled(false);
375 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
378 if (sortby.equals("Id"))
380 sortIDMenuItem_actionPerformed(null);
382 else if (sortby.equals("Pairwise Identity"))
384 sortPairwiseMenuItem_actionPerformed(null);
388 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
390 setMenusFromViewport(viewport);
391 buildSortByAnnotationScoresMenu();
392 calculateTree.addActionListener(new ActionListener()
396 public void actionPerformed(ActionEvent e)
403 if (Desktop.desktop != null)
405 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
406 addServiceListeners();
410 if (viewport.getWrapAlignment())
412 wrapMenuItem_actionPerformed(null);
415 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
417 this.overviewMenuItem_actionPerformed(null);
422 final List<AlignmentPanel> selviews = new ArrayList<>();
423 final List<AlignmentPanel> origview = new ArrayList<>();
424 final String menuLabel = MessageManager
425 .getString("label.copy_format_from");
426 ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
427 new ViewSetProvider()
431 public AlignmentPanel[] getAllAlignmentPanels()
434 origview.add(alignPanel);
435 // make an array of all alignment panels except for this one
436 List<AlignmentPanel> aps = new ArrayList<>(
437 Arrays.asList(Desktop.getAlignmentPanels(null)));
438 aps.remove(AlignFrame.this.alignPanel);
439 return aps.toArray(new AlignmentPanel[aps.size()]);
441 }, selviews, new ItemListener()
445 public void itemStateChanged(ItemEvent e)
447 if (origview.size() > 0)
449 final AlignmentPanel ap = origview.get(0);
452 * Copy the ViewStyle of the selected panel to 'this one'.
453 * Don't change value of 'scaleProteinAsCdna' unless copying
456 ViewStyleI vs = selviews.get(0).getAlignViewport()
458 boolean fromSplitFrame = selviews.get(0)
459 .getAlignViewport().getCodingComplement() != null;
462 vs.setScaleProteinAsCdna(ap.getAlignViewport()
463 .getViewStyle().isScaleProteinAsCdna());
465 ap.getAlignViewport().setViewStyle(vs);
468 * Also rescale ViewStyle of SplitFrame complement if there is
469 * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
470 * the whole ViewStyle (allow cDNA protein to have different
473 AlignViewportI complement = ap.getAlignViewport()
474 .getCodingComplement();
475 if (complement != null && vs.isScaleProteinAsCdna())
477 AlignFrame af = Desktop.getAlignFrameFor(complement);
478 ((SplitFrame) af.getSplitViewContainer())
480 af.setMenusForViewport();
484 ap.setSelected(true);
485 ap.alignFrame.setMenusForViewport();
490 if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
491 .indexOf("devel") > -1
492 || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase()
493 .indexOf("test") > -1)
495 formatMenu.add(vsel);
497 addFocusListener(new FocusAdapter()
500 public void focusGained(FocusEvent e)
502 Jalview.setCurrentAlignFrame(AlignFrame.this);
509 * Change the filename and format for the alignment, and enable the 'reload'
510 * button functionality.
517 public void setFileName(String file, FileFormatI format)
520 setFileFormat(format);
521 reload.setEnabled(true);
525 * Add a KeyListener with handlers for various KeyPressed and KeyReleased
528 void addKeyListener()
530 addKeyListener(new KeyAdapter()
533 public void keyPressed(KeyEvent evt)
535 if (viewport.cursorMode
536 && ((evt.getKeyCode() >= KeyEvent.VK_0
537 && evt.getKeyCode() <= KeyEvent.VK_9)
538 || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0
539 && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9))
540 && Character.isDigit(evt.getKeyChar()))
542 alignPanel.getSeqPanel().numberPressed(evt.getKeyChar());
545 switch (evt.getKeyCode())
548 case 27: // escape key
549 deselectAllSequenceMenuItem_actionPerformed(null);
553 case KeyEvent.VK_DOWN:
554 if (evt.isAltDown() || !viewport.cursorMode)
556 moveSelectedSequences(false);
558 if (viewport.cursorMode)
560 alignPanel.getSeqPanel().moveCursor(0, 1);
565 if (evt.isAltDown() || !viewport.cursorMode)
567 moveSelectedSequences(true);
569 if (viewport.cursorMode)
571 alignPanel.getSeqPanel().moveCursor(0, -1);
576 case KeyEvent.VK_LEFT:
577 if (evt.isAltDown() || !viewport.cursorMode)
579 slideSequences(false,
580 alignPanel.getSeqPanel().getKeyboardNo1());
584 alignPanel.getSeqPanel().moveCursor(-1, 0);
589 case KeyEvent.VK_RIGHT:
590 if (evt.isAltDown() || !viewport.cursorMode)
592 slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1());
596 alignPanel.getSeqPanel().moveCursor(1, 0);
600 case KeyEvent.VK_SPACE:
601 if (viewport.cursorMode)
603 alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown()
604 || evt.isShiftDown() || evt.isAltDown());
608 // case KeyEvent.VK_A:
609 // if (viewport.cursorMode)
611 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
612 // //System.out.println("A");
616 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
617 * System.out.println("closing bracket"); } break;
619 case KeyEvent.VK_DELETE:
620 case KeyEvent.VK_BACK_SPACE:
621 if (!viewport.cursorMode)
623 cut_actionPerformed(null);
627 alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown()
628 || evt.isShiftDown() || evt.isAltDown());
634 if (viewport.cursorMode)
636 alignPanel.getSeqPanel().setCursorRow();
640 if (viewport.cursorMode && !evt.isControlDown())
642 alignPanel.getSeqPanel().setCursorColumn();
646 if (viewport.cursorMode)
648 alignPanel.getSeqPanel().setCursorPosition();
652 case KeyEvent.VK_ENTER:
653 case KeyEvent.VK_COMMA:
654 if (viewport.cursorMode)
656 alignPanel.getSeqPanel().setCursorRowAndColumn();
661 if (viewport.cursorMode)
663 alignPanel.getSeqPanel().setSelectionAreaAtCursor(true);
667 if (viewport.cursorMode)
669 alignPanel.getSeqPanel().setSelectionAreaAtCursor(false);
674 viewport.cursorMode = !viewport.cursorMode;
675 statusBar.setText(MessageManager
676 .formatMessage("label.keyboard_editing_mode", new String[]
677 { (viewport.cursorMode ? "on" : "off") }));
678 if (viewport.cursorMode)
680 ViewportRanges ranges = viewport.getRanges();
681 alignPanel.getSeqPanel().seqCanvas.cursorX = ranges
683 alignPanel.getSeqPanel().seqCanvas.cursorY = ranges
686 alignPanel.getSeqPanel().seqCanvas.repaint();
692 Help.showHelpWindow();
693 } catch (Exception ex)
695 ex.printStackTrace();
700 boolean toggleSeqs = !evt.isControlDown();
701 boolean toggleCols = !evt.isShiftDown();
702 toggleHiddenRegions(toggleSeqs, toggleCols);
707 boolean toggleSel = evt.isControlDown() || evt.isMetaDown();
708 boolean modifyExisting = true; // always modify, don't clear
709 // evt.isShiftDown();
710 boolean invertHighlighted = evt.isAltDown();
711 avc.markHighlightedColumns(invertHighlighted, modifyExisting,
715 case KeyEvent.VK_PAGE_UP:
716 viewport.getRanges().pageUp();
718 case KeyEvent.VK_PAGE_DOWN:
719 viewport.getRanges().pageDown();
725 public void keyReleased(KeyEvent evt)
727 switch (evt.getKeyCode())
729 case KeyEvent.VK_LEFT:
730 if (evt.isAltDown() || !viewport.cursorMode)
732 viewport.firePropertyChange("alignment", null,
733 viewport.getAlignment().getSequences());
737 case KeyEvent.VK_RIGHT:
738 if (evt.isAltDown() || !viewport.cursorMode)
740 viewport.firePropertyChange("alignment", null,
741 viewport.getAlignment().getSequences());
749 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
751 ap.alignFrame = this;
752 avc = new jalview.controller.AlignViewController(this, viewport,
757 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
759 int aSize = alignPanels.size();
761 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
763 if (aSize == 1 && ap.av.viewName == null)
765 this.getContentPane().add(ap, BorderLayout.CENTER);
771 setInitialTabVisible();
774 expandViews.setEnabled(true);
775 gatherViews.setEnabled(true);
776 tabbedPane.addTab(ap.av.viewName, ap);
778 ap.setVisible(false);
783 if (ap.av.isPadGaps())
785 ap.av.getAlignment().padGaps();
787 ap.av.updateConservation(ap);
788 ap.av.updateConsensus(ap);
789 ap.av.updateStrucConsensus(ap);
790 ap.av.updateInformation(ap);
794 public void setInitialTabVisible()
796 expandViews.setEnabled(true);
797 gatherViews.setEnabled(true);
798 tabbedPane.setVisible(true);
799 AlignmentPanel first = alignPanels.get(0);
800 tabbedPane.addTab(first.av.viewName, first);
801 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
804 public AlignViewport getViewport()
809 /* Set up intrinsic listeners for dynamically generated GUI bits. */
810 private void addServiceListeners()
812 final java.beans.PropertyChangeListener thisListener;
813 Desktop.instance.addJalviewPropertyChangeListener("services",
814 thisListener = new java.beans.PropertyChangeListener()
817 public void propertyChange(PropertyChangeEvent evt)
819 // // System.out.println("Discoverer property change.");
820 // if (evt.getPropertyName().equals("services"))
822 SwingUtilities.invokeLater(new Runnable()
829 "Rebuild WS Menu for service change");
830 BuildWebServiceMenu();
837 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
840 public void internalFrameClosed(
841 javax.swing.event.InternalFrameEvent evt)
843 // System.out.println("deregistering discoverer listener");
844 Desktop.instance.removeJalviewPropertyChangeListener("services",
846 closeMenuItem_actionPerformed(true);
849 // Finally, build the menu once to get current service state
850 new Thread(new Runnable()
855 BuildWebServiceMenu();
861 * Configure menu items that vary according to whether the alignment is
862 * nucleotide or protein
864 public void setGUINucleotide()
866 AlignmentI al = getViewport().getAlignment();
867 boolean nucleotide = al.isNucleotide();
869 loadVcf.setVisible(nucleotide);
870 showTranslation.setVisible(nucleotide);
871 showReverse.setVisible(nucleotide);
872 showReverseComplement.setVisible(nucleotide);
873 conservationMenuItem.setEnabled(!nucleotide);
875 .setEnabled(!nucleotide && conservationMenuItem.isSelected());
876 showGroupConservation.setEnabled(!nucleotide);
878 showComplementMenuItem
879 .setText(nucleotide ? MessageManager.getString("label.protein")
880 : MessageManager.getString("label.nucleotide"));
884 * set up menus for the current viewport. This may be called after any
885 * operation that affects the data in the current view (selection changed,
886 * etc) to update the menus to reflect the new state.
889 public void setMenusForViewport()
891 setMenusFromViewport(viewport);
895 * Need to call this method when tabs are selected for multiple views, or when
896 * loading from Jalview2XML.java
901 void setMenusFromViewport(AlignViewport av)
903 padGapsMenuitem.setSelected(av.isPadGaps());
904 colourTextMenuItem.setSelected(av.isShowColourText());
905 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
906 modifyPID.setEnabled(abovePIDThreshold.isSelected());
907 conservationMenuItem.setSelected(av.getConservationSelected());
908 modifyConservation.setEnabled(conservationMenuItem.isSelected());
909 seqLimits.setSelected(av.getShowJVSuffix());
910 idRightAlign.setSelected(av.isRightAlignIds());
911 centreColumnLabelsMenuItem.setState(av.isCentreColumnLabels());
912 renderGapsMenuItem.setSelected(av.isRenderGaps());
913 wrapMenuItem.setSelected(av.getWrapAlignment());
914 scaleAbove.setVisible(av.getWrapAlignment());
915 scaleLeft.setVisible(av.getWrapAlignment());
916 scaleRight.setVisible(av.getWrapAlignment());
917 annotationPanelMenuItem.setState(av.isShowAnnotation());
919 * Show/hide annotations only enabled if annotation panel is shown
921 showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
922 hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
923 showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
924 hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
925 viewBoxesMenuItem.setSelected(av.getShowBoxes());
926 viewTextMenuItem.setSelected(av.getShowText());
927 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
928 showGroupConsensus.setSelected(av.isShowGroupConsensus());
929 showGroupConservation.setSelected(av.isShowGroupConservation());
930 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
931 showSequenceLogo.setSelected(av.isShowSequenceLogo());
932 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
933 showInformationHistogram.setSelected(av.isShowInformationHistogram());
934 showHMMSequenceLogo.setSelected(av.isShowHMMSequenceLogo());
935 normaliseHMMSequenceLogo.setSelected(av.isNormaliseHMMSequenceLogo());
937 ColourMenuHelper.setColourSelected(colourMenu,
938 av.getGlobalColourScheme());
940 showSeqFeatures.setSelected(av.isShowSequenceFeatures());
941 hiddenMarkers.setState(av.getShowHiddenMarkers());
942 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
943 showNpFeatsMenuitem.setSelected(av.isShowNPFeats());
944 showDbRefsMenuitem.setSelected(av.isShowDBRefs());
945 autoCalculate.setSelected(av.autoCalculateConsensus);
946 sortByTree.setSelected(av.sortByTree);
947 listenToViewSelections.setSelected(av.followSelection);
949 showProducts.setEnabled(canShowProducts());
950 setGroovyEnabled(Desktop.getGroovyConsole() != null);
956 * Set the enabled state of the 'Run Groovy' option in the Calculate menu
960 public void setGroovyEnabled(boolean b)
962 runGroovy.setEnabled(b);
965 private IProgressIndicator progressBar;
970 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
973 public void setProgressBar(String message, long id)
975 progressBar.setProgressBar(message, id);
979 public void registerHandler(final long id,
980 final IProgressIndicatorHandler handler)
982 progressBar.registerHandler(id, handler);
987 * @return true if any progress bars are still active
990 public boolean operationInProgress()
992 return progressBar.operationInProgress();
996 public void setStatus(String text)
998 statusBar.setText(text);
1002 * Added so Castor Mapping file can obtain Jalview Version
1004 public String getVersion()
1006 return jalview.bin.Cache.getProperty("VERSION");
1009 public FeatureRenderer getFeatureRenderer()
1011 return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer();
1015 public void fetchSequence_actionPerformed(ActionEvent e)
1017 new jalview.gui.SequenceFetcher(this);
1021 public void addFromFile_actionPerformed(ActionEvent e)
1023 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
1027 public void hmmBuildSettings_actionPerformed()
1029 if (!(alignmentIsSufficient(1)))
1033 WsParamSetI set = new HMMERPreset();
1034 List<ArgumentI> args = new ArrayList<>();
1035 ParamDatastoreI store = new HMMERParamStore("hmmbuild");
1036 WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
1038 if (params.showRunDialog())
1040 new Thread(new HMMBuild(this, params.getJobParams())).start();
1042 alignPanel.repaint();
1047 public void hmmAlignSettings_actionPerformed()
1049 if (!(checkForHMM() && alignmentIsSufficient(2)))
1053 WsParamSetI set = new HMMERPreset();
1054 List<ArgumentI> args = new ArrayList<>();
1055 ParamDatastoreI store = new HMMERParamStore("hmmalign");
1056 WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
1058 if (params.showRunDialog())
1060 new Thread(new HMMAlign(this, params.getJobParams()))
1063 alignPanel.repaint();
1067 public void hmmSearchSettings_actionPerformed()
1073 WsParamSetI set = new HMMERPreset();
1074 List<ArgumentI> args = new ArrayList<>();
1075 ParamDatastoreI store = new HMMERParamStore("hmmsearch");
1076 WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
1078 if (params.showRunDialog())
1080 new Thread(new HMMSearch(this, params.getJobParams()))
1083 alignPanel.repaint();
1087 public void hmmBuildRun_actionPerformed()
1089 if (!alignmentIsSufficient(1))
1093 new Thread(new HMMBuild(this, null))
1098 public void hmmAlignRun_actionPerformed()
1100 if (!(checkForHMM() && alignmentIsSufficient(2)))
1104 new Thread(new HMMAlign(this, null)).start();
1108 public void hmmSearchRun_actionPerformed()
1114 new Thread(new HMMSearch(this, null)).start();
1118 * Checks if the frame has a selected hidden Markov model
1122 private boolean checkForHMM()
1124 if (getSelectedHMM() == null)
1126 JOptionPane.showMessageDialog(this,
1127 MessageManager.getString("warn.no_selected_hmm"));
1134 * Checks if the alignment contains the required number of sequences.
1139 public boolean alignmentIsSufficient(int required)
1141 if (getViewport().getAlignment().getSequences().size() < required)
1143 JOptionPane.showMessageDialog(this,
1144 MessageManager.getString("warn.not_enough_sequences"));
1151 public void addDatabase_actionPerformed() throws IOException
1153 if (Cache.getProperty(Preferences.HMMSEARCH_DB_PATHS) == null)
1155 Cache.setProperty(Preferences.HMMSEARCH_DBS, "");
1156 Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, "");
1159 String path = openFileChooser(false);
1160 if (new File(path).exists())
1162 IdentifyFile identifier = new IdentifyFile();
1163 FileFormatI format = identifier.identify(path, DataSourceType.FILE);
1164 if (format == FileFormat.Fasta || format == FileFormat.Stockholm
1165 || format == FileFormat.Pfam)
1167 String currentDbs = Cache.getProperty(Preferences.HMMSEARCH_DBS);
1168 String currentDbPaths = Cache
1169 .getProperty(Preferences.HMMSEARCH_DB_PATHS);
1170 currentDbPaths += " " + path;
1172 String fileName = StringUtils.getLastToken(path, File.separator);
1173 Scanner scanner = new Scanner(fileName).useDelimiter(".");
1174 String name = scanner.next();
1176 currentDbs += " " + path; // TODO remove path from file name
1179 Cache.setProperty(Preferences.HMMSEARCH_DB_PATHS, currentDbPaths);
1180 Cache.setProperty(Preferences.HMMSEARCH_DBS, currentDbPaths);
1184 JOptionPane.showMessageDialog(this,
1185 MessageManager.getString("warn.invalid_format"));
1190 JOptionPane.showMessageDialog(this,
1191 MessageManager.getString("warn.not_enough_sequences"));
1196 * Opens a file chooser
1201 protected String openFileChooser(boolean forFolder)
1203 String choice = null;
1204 JFileChooser chooser = new JFileChooser();
1207 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1209 chooser.setDialogTitle(
1210 MessageManager.getString("label.open_local_file"));
1211 chooser.setToolTipText(MessageManager.getString("action.open"));
1213 int value = chooser.showOpenDialog(this);
1215 if (value == JFileChooser.APPROVE_OPTION)
1217 choice = chooser.getSelectedFile().getPath();
1223 public void reload_actionPerformed(ActionEvent e)
1225 if (fileName != null)
1227 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
1228 // originating file's format
1229 // TODO: work out how to recover feature settings for correct view(s) when
1230 // file is reloaded.
1231 if (FileFormat.Jalview.equals(currentFileFormat))
1233 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
1234 for (int i = 0; i < frames.length; i++)
1236 if (frames[i] instanceof AlignFrame && frames[i] != this
1237 && ((AlignFrame) frames[i]).fileName != null
1238 && ((AlignFrame) frames[i]).fileName.equals(fileName))
1242 frames[i].setSelected(true);
1243 Desktop.instance.closeAssociatedWindows();
1244 } catch (java.beans.PropertyVetoException ex)
1250 Desktop.instance.closeAssociatedWindows();
1252 FileLoader loader = new FileLoader();
1253 DataSourceType protocol = fileName.startsWith("http:")
1254 ? DataSourceType.URL
1255 : DataSourceType.FILE;
1256 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
1260 Rectangle bounds = this.getBounds();
1262 FileLoader loader = new FileLoader();
1263 DataSourceType protocol = fileName.startsWith("http:")
1264 ? DataSourceType.URL
1265 : DataSourceType.FILE;
1266 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
1267 protocol, currentFileFormat);
1269 newframe.setBounds(bounds);
1270 if (featureSettings != null && featureSettings.isShowing())
1272 final Rectangle fspos = featureSettings.frame.getBounds();
1273 // TODO: need a 'show feature settings' function that takes bounds -
1274 // need to refactor Desktop.addFrame
1275 newframe.featureSettings_actionPerformed(null);
1276 final FeatureSettings nfs = newframe.featureSettings;
1277 SwingUtilities.invokeLater(new Runnable()
1282 nfs.frame.setBounds(fspos);
1285 this.featureSettings.close();
1286 this.featureSettings = null;
1288 this.closeMenuItem_actionPerformed(true);
1294 public void addFromText_actionPerformed(ActionEvent e)
1297 .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel());
1301 public void addFromURL_actionPerformed(ActionEvent e)
1303 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
1307 public void save_actionPerformed(ActionEvent e)
1309 if (fileName == null || (currentFileFormat == null)
1310 || fileName.startsWith("http"))
1312 saveAs_actionPerformed(null);
1316 saveAlignment(fileName, currentFileFormat);
1327 public void saveAs_actionPerformed(ActionEvent e)
1329 String format = currentFileFormat == null ? null
1330 : currentFileFormat.getName();
1331 JalviewFileChooser chooser = JalviewFileChooser
1332 .forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
1334 chooser.setFileView(new JalviewFileView());
1335 chooser.setDialogTitle(
1336 MessageManager.getString("label.save_alignment_to_file"));
1337 chooser.setToolTipText(MessageManager.getString("action.save"));
1339 int value = chooser.showSaveDialog(this);
1341 if (value == JalviewFileChooser.APPROVE_OPTION)
1343 currentFileFormat = chooser.getSelectedFormat();
1344 while (currentFileFormat == null)
1346 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1347 MessageManager.getString(
1348 "label.select_file_format_before_saving"),
1349 MessageManager.getString("label.file_format_not_specified"),
1350 JvOptionPane.WARNING_MESSAGE);
1351 currentFileFormat = chooser.getSelectedFormat();
1352 value = chooser.showSaveDialog(this);
1353 if (value != JalviewFileChooser.APPROVE_OPTION)
1359 fileName = chooser.getSelectedFile().getPath();
1361 Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
1363 Cache.setProperty("LAST_DIRECTORY", fileName);
1364 saveAlignment(fileName, currentFileFormat);
1368 public boolean saveAlignment(String file, FileFormatI format)
1370 boolean success = true;
1372 if (FileFormat.Jalview.equals(format))
1374 String shortName = title;
1376 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1378 shortName = shortName.substring(
1379 shortName.lastIndexOf(java.io.File.separatorChar) + 1);
1382 success = new Jalview2XML().saveAlignment(this, file, shortName);
1384 statusBar.setText(MessageManager.formatMessage(
1385 "label.successfully_saved_to_file_in_format", new Object[]
1386 { fileName, format }));
1391 AlignmentExportData exportData = getAlignmentForExport(format,
1393 if (exportData.getSettings().isCancelled())
1397 FormatAdapter f = new FormatAdapter(alignPanel,
1398 exportData.getSettings());
1399 String output = f.formatSequences(format, exportData.getAlignment(), // class
1403 // occur in the distant future
1404 exportData.getOmitHidden(), exportData.getStartEndPostions(),
1405 f.getCacheSuffixDefault(format),
1406 viewport.getAlignment().getHiddenColumns());
1416 PrintWriter out = new PrintWriter(new FileWriter(file));
1420 this.setTitle(file);
1421 statusBar.setText(MessageManager.formatMessage(
1422 "label.successfully_saved_to_file_in_format", new Object[]
1423 { fileName, format.getName() }));
1424 } catch (Exception ex)
1427 ex.printStackTrace();
1434 JvOptionPane.showInternalMessageDialog(this, MessageManager
1435 .formatMessage("label.couldnt_save_file", new Object[]
1437 MessageManager.getString("label.error_saving_file"),
1438 JvOptionPane.WARNING_MESSAGE);
1444 private void warningMessage(String warning, String title)
1446 if (new jalview.util.Platform().isHeadless())
1448 System.err.println("Warning: " + title + "\nWarning: " + warning);
1453 JvOptionPane.showInternalMessageDialog(this, warning, title,
1454 JvOptionPane.WARNING_MESSAGE);
1466 protected void outputText_actionPerformed(ActionEvent e)
1468 FileFormatI fileFormat = FileFormats.getInstance()
1469 .forName(e.getActionCommand());
1470 AlignmentExportData exportData = getAlignmentForExport(fileFormat,
1472 if (exportData.getSettings().isCancelled())
1476 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1477 cap.setForInput(null);
1480 FileFormatI format = fileFormat;
1481 cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
1482 .formatSequences(format, exportData.getAlignment(),
1483 exportData.getOmitHidden(),
1484 exportData.getStartEndPostions(),
1485 viewport.getAlignment().getHiddenColumns()));
1486 Desktop.addInternalFrame(cap, MessageManager
1487 .formatMessage("label.alignment_output_command", new Object[]
1488 { e.getActionCommand() }), 600, 500);
1489 } catch (OutOfMemoryError oom)
1491 new OOMWarning("Outputting alignment as " + e.getActionCommand(),
1498 public static AlignmentExportData getAlignmentForExport(
1499 FileFormatI format, AlignViewportI viewport,
1500 AlignExportSettingI exportSettings)
1502 AlignmentI alignmentToExport = null;
1503 AlignExportSettingI settings = exportSettings;
1504 String[] omitHidden = null;
1506 HiddenSequences hiddenSeqs = viewport.getAlignment()
1507 .getHiddenSequences();
1509 alignmentToExport = viewport.getAlignment();
1511 boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
1512 if (settings == null)
1514 settings = new AlignExportSettings(hasHiddenSeqs,
1515 viewport.hasHiddenColumns(), format);
1517 // settings.isExportAnnotations();
1519 if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
1521 omitHidden = viewport.getViewAsString(false,
1522 settings.isExportHiddenSequences());
1525 int[] alignmentStartEnd = new int[2];
1526 if (hasHiddenSeqs && settings.isExportHiddenSequences())
1528 alignmentToExport = hiddenSeqs.getFullAlignment();
1532 alignmentToExport = viewport.getAlignment();
1534 alignmentStartEnd = viewport.getAlignment().getHiddenColumns()
1535 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
1536 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
1537 omitHidden, alignmentStartEnd, settings);
1548 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1550 HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel);
1551 htmlSVG.exportHTML(null);
1555 public void bioJSMenuItem_actionPerformed(ActionEvent e)
1557 BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
1558 bjs.exportHTML(null);
1561 public void createImageMap(File file, String image)
1563 alignPanel.makePNGImageMap(file, image);
1573 public void createPNG(File f)
1575 alignPanel.makePNG(f);
1585 public void createEPS(File f)
1587 alignPanel.makeEPS(f);
1591 public void createSVG(File f)
1593 alignPanel.makeSVG(f);
1597 public void pageSetup_actionPerformed(ActionEvent e)
1599 PrinterJob printJob = PrinterJob.getPrinterJob();
1600 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1610 public void printMenuItem_actionPerformed(ActionEvent e)
1612 // Putting in a thread avoids Swing painting problems
1613 PrintThread thread = new PrintThread(alignPanel);
1618 public void exportFeatures_actionPerformed(ActionEvent e)
1620 new AnnotationExporter(alignPanel).exportFeatures();
1624 public void exportAnnotations_actionPerformed(ActionEvent e)
1626 new AnnotationExporter(alignPanel).exportAnnotations();
1630 public void associatedData_actionPerformed(ActionEvent e)
1631 throws IOException, InterruptedException
1633 // Pick the tree file
1634 JalviewFileChooser chooser = new JalviewFileChooser(
1635 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1636 chooser.setFileView(new JalviewFileView());
1637 chooser.setDialogTitle(
1638 MessageManager.getString("label.load_jalview_annotations"));
1639 chooser.setToolTipText(
1640 MessageManager.getString("label.load_jalview_annotations"));
1642 int value = chooser.showOpenDialog(null);
1644 if (value == JalviewFileChooser.APPROVE_OPTION)
1646 String choice = chooser.getSelectedFile().getPath();
1647 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1648 loadJalviewDataFile(choice, null, null, null);
1654 * Close the current view or all views in the alignment frame. If the frame
1655 * only contains one view then the alignment will be removed from memory.
1657 * @param closeAllTabs
1660 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1662 if (alignPanels != null && alignPanels.size() < 2)
1664 closeAllTabs = true;
1669 if (alignPanels != null)
1673 if (this.isClosed())
1675 // really close all the windows - otherwise wait till
1676 // setClosed(true) is called
1677 for (int i = 0; i < alignPanels.size(); i++)
1679 AlignmentPanel ap = alignPanels.get(i);
1686 closeView(alignPanel);
1693 * this will raise an INTERNAL_FRAME_CLOSED event and this method will
1694 * be called recursively, with the frame now in 'closed' state
1696 this.setClosed(true);
1698 } catch (Exception ex)
1700 ex.printStackTrace();
1705 * Close the specified panel and close up tabs appropriately.
1707 * @param panelToClose
1709 public void closeView(AlignmentPanel panelToClose)
1711 int index = tabbedPane.getSelectedIndex();
1712 int closedindex = tabbedPane.indexOfComponent(panelToClose);
1713 alignPanels.remove(panelToClose);
1714 panelToClose.closePanel();
1715 panelToClose = null;
1717 tabbedPane.removeTabAt(closedindex);
1718 tabbedPane.validate();
1720 if (index > closedindex || index == tabbedPane.getTabCount())
1722 // modify currently selected tab index if necessary.
1726 this.tabSelectionChanged(index);
1732 void updateEditMenuBar()
1735 if (viewport.getHistoryList().size() > 0)
1737 undoMenuItem.setEnabled(true);
1738 CommandI command = viewport.getHistoryList().peek();
1739 undoMenuItem.setText(MessageManager
1740 .formatMessage("label.undo_command", new Object[]
1741 { command.getDescription() }));
1745 undoMenuItem.setEnabled(false);
1746 undoMenuItem.setText(MessageManager.getString("action.undo"));
1749 if (viewport.getRedoList().size() > 0)
1751 redoMenuItem.setEnabled(true);
1753 CommandI command = viewport.getRedoList().peek();
1754 redoMenuItem.setText(MessageManager
1755 .formatMessage("label.redo_command", new Object[]
1756 { command.getDescription() }));
1760 redoMenuItem.setEnabled(false);
1761 redoMenuItem.setText(MessageManager.getString("action.redo"));
1766 public void addHistoryItem(CommandI command)
1768 if (command.getSize() > 0)
1770 viewport.addToHistoryList(command);
1771 viewport.clearRedoList();
1772 updateEditMenuBar();
1773 viewport.updateHiddenColumns();
1774 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1775 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1776 // viewport.getColumnSelection()
1777 // .getHiddenColumns().size() > 0);
1783 * @return alignment objects for all views
1785 AlignmentI[] getViewAlignments()
1787 if (alignPanels != null)
1789 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1791 for (AlignmentPanel ap : alignPanels)
1793 als[i++] = ap.av.getAlignment();
1797 if (viewport != null)
1799 return new AlignmentI[] { viewport.getAlignment() };
1811 protected void undoMenuItem_actionPerformed(ActionEvent e)
1813 if (viewport.getHistoryList().isEmpty())
1817 CommandI command = viewport.getHistoryList().pop();
1818 viewport.addToRedoList(command);
1819 command.undoCommand(getViewAlignments());
1821 AlignmentViewport originalSource = getOriginatingSource(command);
1822 updateEditMenuBar();
1824 if (originalSource != null)
1826 if (originalSource != viewport)
1829 "Implementation worry: mismatch of viewport origin for undo");
1831 originalSource.updateHiddenColumns();
1832 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1834 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1835 // viewport.getColumnSelection()
1836 // .getHiddenColumns().size() > 0);
1837 originalSource.firePropertyChange("alignment", null,
1838 originalSource.getAlignment().getSequences());
1849 protected void redoMenuItem_actionPerformed(ActionEvent e)
1851 if (viewport.getRedoList().size() < 1)
1856 CommandI command = viewport.getRedoList().pop();
1857 viewport.addToHistoryList(command);
1858 command.doCommand(getViewAlignments());
1860 AlignmentViewport originalSource = getOriginatingSource(command);
1861 updateEditMenuBar();
1863 if (originalSource != null)
1866 if (originalSource != viewport)
1869 "Implementation worry: mismatch of viewport origin for redo");
1871 originalSource.updateHiddenColumns();
1872 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1874 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1875 // viewport.getColumnSelection()
1876 // .getHiddenColumns().size() > 0);
1877 originalSource.firePropertyChange("alignment", null,
1878 originalSource.getAlignment().getSequences());
1882 AlignmentViewport getOriginatingSource(CommandI command)
1884 AlignmentViewport originalSource = null;
1885 // For sequence removal and addition, we need to fire
1886 // the property change event FROM the viewport where the
1887 // original alignment was altered
1888 AlignmentI al = null;
1889 if (command instanceof EditCommand)
1891 EditCommand editCommand = (EditCommand) command;
1892 al = editCommand.getAlignment();
1893 List<Component> comps = PaintRefresher.components
1894 .get(viewport.getSequenceSetId());
1896 for (Component comp : comps)
1898 if (comp instanceof AlignmentPanel)
1900 if (al == ((AlignmentPanel) comp).av.getAlignment())
1902 originalSource = ((AlignmentPanel) comp).av;
1909 if (originalSource == null)
1911 // The original view is closed, we must validate
1912 // the current view against the closed view first
1915 PaintRefresher.validateSequences(al, viewport.getAlignment());
1918 originalSource = viewport;
1921 return originalSource;
1930 public void moveSelectedSequences(boolean up)
1932 SequenceGroup sg = viewport.getSelectionGroup();
1938 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1939 viewport.getHiddenRepSequences(), up);
1940 alignPanel.paintAlignment(true, false);
1943 synchronized void slideSequences(boolean right, int size)
1945 List<SequenceI> sg = new ArrayList<>();
1946 if (viewport.cursorMode)
1948 sg.add(viewport.getAlignment()
1949 .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY));
1951 else if (viewport.getSelectionGroup() != null
1952 && viewport.getSelectionGroup().getSize() != viewport
1953 .getAlignment().getHeight())
1955 sg = viewport.getSelectionGroup()
1956 .getSequences(viewport.getHiddenRepSequences());
1964 List<SequenceI> invertGroup = new ArrayList<>();
1966 for (SequenceI seq : viewport.getAlignment().getSequences())
1968 if (!sg.contains(seq))
1970 invertGroup.add(seq);
1974 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1976 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1977 for (int i = 0; i < invertGroup.size(); i++)
1979 seqs2[i] = invertGroup.get(i);
1982 SlideSequencesCommand ssc;
1985 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size,
1986 viewport.getGapCharacter());
1990 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size,
1991 viewport.getGapCharacter());
1994 int groupAdjustment = 0;
1995 if (ssc.getGapsInsertedBegin() && right)
1997 if (viewport.cursorMode)
1999 alignPanel.getSeqPanel().moveCursor(size, 0);
2003 groupAdjustment = size;
2006 else if (!ssc.getGapsInsertedBegin() && !right)
2008 if (viewport.cursorMode)
2010 alignPanel.getSeqPanel().moveCursor(-size, 0);
2014 groupAdjustment = -size;
2018 if (groupAdjustment != 0)
2020 viewport.getSelectionGroup().setStartRes(
2021 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
2022 viewport.getSelectionGroup().setEndRes(
2023 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
2027 * just extend the last slide command if compatible; but not if in
2028 * SplitFrame mode (to ensure all edits are broadcast - JAL-1802)
2030 boolean appendHistoryItem = false;
2031 Deque<CommandI> historyList = viewport.getHistoryList();
2032 boolean inSplitFrame = getSplitViewContainer() != null;
2033 if (!inSplitFrame && historyList != null && historyList.size() > 0
2034 && historyList.peek() instanceof SlideSequencesCommand)
2036 appendHistoryItem = ssc.appendSlideCommand(
2037 (SlideSequencesCommand) historyList.peek());
2040 if (!appendHistoryItem)
2042 addHistoryItem(ssc);
2055 protected void copy_actionPerformed(ActionEvent e)
2058 if (viewport.getSelectionGroup() == null)
2062 // TODO: preserve the ordering of displayed alignment annotation in any
2063 // internal paste (particularly sequence associated annotation)
2064 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
2065 String[] omitHidden = null;
2067 if (viewport.hasHiddenColumns())
2069 omitHidden = viewport.getViewAsString(true);
2072 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
2073 seqs, omitHidden, null);
2075 StringSelection ss = new StringSelection(output);
2079 jalview.gui.Desktop.internalCopy = true;
2080 // Its really worth setting the clipboard contents
2081 // to empty before setting the large StringSelection!!
2082 Toolkit.getDefaultToolkit().getSystemClipboard()
2083 .setContents(new StringSelection(""), null);
2085 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
2087 } catch (OutOfMemoryError er)
2089 new OOMWarning("copying region", er);
2093 HiddenColumns hiddenColumns = null;
2094 if (viewport.hasHiddenColumns())
2096 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
2097 int hiddenCutoff = viewport.getSelectionGroup().getEndRes();
2099 // create new HiddenColumns object with copy of hidden regions
2100 // between startRes and endRes, offset by startRes
2101 hiddenColumns = new HiddenColumns(
2102 viewport.getAlignment().getHiddenColumns(), hiddenOffset,
2103 hiddenCutoff, hiddenOffset);
2106 Desktop.jalviewClipboard = new Object[] { seqs,
2107 viewport.getAlignment().getDataset(), hiddenColumns };
2108 statusBar.setText(MessageManager.formatMessage(
2109 "label.copied_sequences_to_clipboard", new Object[]
2110 { Integer.valueOf(seqs.length).toString() }));
2118 * @throws InterruptedException
2119 * @throws IOException
2122 protected void pasteNew_actionPerformed(ActionEvent e)
2123 throws IOException, InterruptedException
2133 * @throws InterruptedException
2134 * @throws IOException
2137 protected void pasteThis_actionPerformed(ActionEvent e)
2138 throws IOException, InterruptedException
2144 * Paste contents of Jalview clipboard
2146 * @param newAlignment
2147 * true to paste to a new alignment, otherwise add to this.
2148 * @throws InterruptedException
2149 * @throws IOException
2151 void paste(boolean newAlignment) throws IOException, InterruptedException
2153 boolean externalPaste = true;
2156 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
2157 Transferable contents = c.getContents(this);
2159 if (contents == null)
2168 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
2169 if (str.length() < 1)
2174 format = new IdentifyFile().identify(str, DataSourceType.PASTE);
2176 } catch (OutOfMemoryError er)
2178 new OOMWarning("Out of memory pasting sequences!!", er);
2182 SequenceI[] sequences;
2183 boolean annotationAdded = false;
2184 AlignmentI alignment = null;
2186 if (Desktop.jalviewClipboard != null)
2188 // The clipboard was filled from within Jalview, we must use the
2190 // And dataset from the copied alignment
2191 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
2192 // be doubly sure that we create *new* sequence objects.
2193 sequences = new SequenceI[newseq.length];
2194 for (int i = 0; i < newseq.length; i++)
2196 sequences[i] = new Sequence(newseq[i]);
2198 alignment = new Alignment(sequences);
2199 externalPaste = false;
2203 // parse the clipboard as an alignment.
2204 alignment = new FormatAdapter().readFile(str, DataSourceType.PASTE,
2206 sequences = alignment.getSequencesArray();
2210 ArrayList<Integer> newGraphGroups = new ArrayList<>();
2216 if (Desktop.jalviewClipboard != null)
2218 // dataset is inherited
2219 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
2223 // new dataset is constructed
2224 alignment.setDataset(null);
2226 alwidth = alignment.getWidth() + 1;
2230 AlignmentI pastedal = alignment; // preserve pasted alignment object
2231 // Add pasted sequences and dataset into existing alignment.
2232 alignment = viewport.getAlignment();
2233 alwidth = alignment.getWidth() + 1;
2234 // decide if we need to import sequences from an existing dataset
2235 boolean importDs = Desktop.jalviewClipboard != null
2236 && Desktop.jalviewClipboard[1] != alignment.getDataset();
2237 // importDs==true instructs us to copy over new dataset sequences from
2238 // an existing alignment
2239 Vector newDs = (importDs) ? new Vector() : null; // used to create
2240 // minimum dataset set
2242 for (int i = 0; i < sequences.length; i++)
2246 newDs.addElement(null);
2248 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
2250 if (importDs && ds != null)
2252 if (!newDs.contains(ds))
2254 newDs.setElementAt(ds, i);
2255 ds = new Sequence(ds);
2256 // update with new dataset sequence
2257 sequences[i].setDatasetSequence(ds);
2261 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
2266 // copy and derive new dataset sequence
2267 sequences[i] = sequences[i].deriveSequence();
2268 alignment.getDataset()
2269 .addSequence(sequences[i].getDatasetSequence());
2270 // TODO: avoid creation of duplicate dataset sequences with a
2271 // 'contains' method using SequenceI.equals()/SequenceI.contains()
2273 alignment.addSequence(sequences[i]); // merges dataset
2277 newDs.clear(); // tidy up
2279 if (alignment.getAlignmentAnnotation() != null)
2281 for (AlignmentAnnotation alan : alignment
2282 .getAlignmentAnnotation())
2284 if (alan.graphGroup > fgroup)
2286 fgroup = alan.graphGroup;
2290 if (pastedal.getAlignmentAnnotation() != null)
2292 // Add any annotation attached to alignment.
2293 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
2294 for (int i = 0; i < alann.length; i++)
2296 annotationAdded = true;
2297 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
2299 AlignmentAnnotation newann = new AlignmentAnnotation(
2301 if (newann.graphGroup > -1)
2303 if (newGraphGroups.size() <= newann.graphGroup
2304 || newGraphGroups.get(newann.graphGroup) == null)
2306 for (int q = newGraphGroups
2307 .size(); q <= newann.graphGroup; q++)
2309 newGraphGroups.add(q, null);
2311 newGraphGroups.set(newann.graphGroup,
2312 new Integer(++fgroup));
2314 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2318 newann.padAnnotation(alwidth);
2319 alignment.addAnnotation(newann);
2329 addHistoryItem(new EditCommand(
2330 MessageManager.getString("label.add_sequences"),
2331 Action.PASTE, sequences, 0, alignment.getWidth(),
2334 // Add any annotations attached to sequences
2335 for (int i = 0; i < sequences.length; i++)
2337 if (sequences[i].getAnnotation() != null)
2339 AlignmentAnnotation newann;
2340 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
2342 annotationAdded = true;
2343 newann = sequences[i].getAnnotation()[a];
2344 newann.adjustForAlignment();
2345 newann.padAnnotation(alwidth);
2346 if (newann.graphGroup > -1)
2348 if (newann.graphGroup > -1)
2350 if (newGraphGroups.size() <= newann.graphGroup
2351 || newGraphGroups.get(newann.graphGroup) == null)
2353 for (int q = newGraphGroups
2354 .size(); q <= newann.graphGroup; q++)
2356 newGraphGroups.add(q, null);
2358 newGraphGroups.set(newann.graphGroup,
2359 new Integer(++fgroup));
2361 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
2365 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
2369 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
2377 // propagate alignment changed.
2378 viewport.getRanges().setEndSeq(alignment.getHeight());
2379 if (annotationAdded)
2381 // Duplicate sequence annotation in all views.
2382 AlignmentI[] alview = this.getViewAlignments();
2383 for (int i = 0; i < sequences.length; i++)
2385 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
2390 for (int avnum = 0; avnum < alview.length; avnum++)
2392 if (alview[avnum] != alignment)
2394 // duplicate in a view other than the one with input focus
2395 int avwidth = alview[avnum].getWidth() + 1;
2396 // this relies on sann being preserved after we
2397 // modify the sequence's annotation array for each duplication
2398 for (int a = 0; a < sann.length; a++)
2400 AlignmentAnnotation newann = new AlignmentAnnotation(
2402 sequences[i].addAlignmentAnnotation(newann);
2403 newann.padAnnotation(avwidth);
2404 alview[avnum].addAnnotation(newann); // annotation was
2405 // duplicated earlier
2406 // TODO JAL-1145 graphGroups are not updated for sequence
2407 // annotation added to several views. This may cause
2409 alview[avnum].setAnnotationIndex(newann, a);
2414 buildSortByAnnotationScoresMenu();
2416 viewport.firePropertyChange("alignment", null,
2417 alignment.getSequences());
2418 if (alignPanels != null)
2420 for (AlignmentPanel ap : alignPanels)
2422 ap.validateAnnotationDimensions(false);
2427 alignPanel.validateAnnotationDimensions(false);
2433 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2435 String newtitle = new String("Copied sequences");
2437 if (Desktop.jalviewClipboard != null
2438 && Desktop.jalviewClipboard[2] != null)
2440 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2441 af.viewport.setHiddenColumns(hc);
2444 // >>>This is a fix for the moment, until a better solution is
2446 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2447 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2448 .getFeatureRenderer());
2450 // TODO: maintain provenance of an alignment, rather than just make the
2451 // title a concatenation of operations.
2454 if (title.startsWith("Copied sequences"))
2460 newtitle = newtitle.concat("- from " + title);
2465 newtitle = new String("Pasted sequences");
2468 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2473 } catch (Exception ex)
2475 ex.printStackTrace();
2476 System.out.println("Exception whilst pasting: " + ex);
2477 // could be anything being pasted in here
2482 protected void expand_newalign(ActionEvent e)
2486 AlignmentI alignment = AlignmentUtils
2487 .expandContext(getViewport().getAlignment(), -1);
2488 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2490 String newtitle = new String("Flanking alignment");
2492 if (Desktop.jalviewClipboard != null
2493 && Desktop.jalviewClipboard[2] != null)
2495 HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2];
2496 af.viewport.setHiddenColumns(hc);
2499 // >>>This is a fix for the moment, until a better solution is
2501 af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
2502 .transferSettings(alignPanel.getSeqPanel().seqCanvas
2503 .getFeatureRenderer());
2505 // TODO: maintain provenance of an alignment, rather than just make the
2506 // title a concatenation of operations.
2508 if (title.startsWith("Copied sequences"))
2514 newtitle = newtitle.concat("- from " + title);
2518 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2520 } catch (Exception ex)
2522 ex.printStackTrace();
2523 System.out.println("Exception whilst pasting: " + ex);
2524 // could be anything being pasted in here
2525 } catch (OutOfMemoryError oom)
2527 new OOMWarning("Viewing flanking region of alignment", oom);
2538 protected void cut_actionPerformed(ActionEvent e)
2540 copy_actionPerformed(null);
2541 delete_actionPerformed(null);
2551 protected void delete_actionPerformed(ActionEvent evt)
2554 SequenceGroup sg = viewport.getSelectionGroup();
2561 * If the cut affects all sequences, warn, remove highlighted columns
2563 if (sg.getSize() == viewport.getAlignment().getHeight())
2565 boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes())
2566 + 1) == viewport.getAlignment().getWidth()) ? true : false;
2567 if (isEntireAlignWidth)
2569 int confirm = JvOptionPane.showConfirmDialog(this,
2570 MessageManager.getString("warn.delete_all"), // $NON-NLS-1$
2571 MessageManager.getString("label.delete_all"), // $NON-NLS-1$
2572 JvOptionPane.OK_CANCEL_OPTION);
2574 if (confirm == JvOptionPane.CANCEL_OPTION
2575 || confirm == JvOptionPane.CLOSED_OPTION)
2580 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2581 sg.getEndRes() + 1);
2583 SequenceI[] cut = sg.getSequences()
2584 .toArray(new SequenceI[sg.getSize()]);
2586 addHistoryItem(new EditCommand(
2587 MessageManager.getString("label.cut_sequences"), Action.CUT,
2588 cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2589 viewport.getAlignment()));
2591 viewport.setSelectionGroup(null);
2592 viewport.sendSelection();
2593 viewport.getAlignment().deleteGroup(sg);
2595 viewport.firePropertyChange("alignment", null,
2596 viewport.getAlignment().getSequences());
2597 if (viewport.getAlignment().getHeight() < 1)
2601 this.setClosed(true);
2602 } catch (Exception ex)
2615 protected void deleteGroups_actionPerformed(ActionEvent e)
2617 if (avc.deleteGroups())
2619 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2620 alignPanel.updateAnnotation();
2621 alignPanel.paintAlignment(true, true);
2632 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2634 SequenceGroup sg = new SequenceGroup();
2636 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2638 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2641 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2642 viewport.setSelectionGroup(sg);
2643 viewport.sendSelection();
2644 // JAL-2034 - should delegate to
2645 // alignPanel to decide if overview needs
2647 alignPanel.paintAlignment(false, false);
2648 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2658 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2660 if (viewport.cursorMode)
2662 alignPanel.getSeqPanel().keyboardNo1 = null;
2663 alignPanel.getSeqPanel().keyboardNo2 = null;
2665 viewport.setSelectionGroup(null);
2666 viewport.getColumnSelection().clear();
2667 viewport.setSelectionGroup(null);
2668 alignPanel.getIdPanel().getIdCanvas().searchResults = null;
2669 // JAL-2034 - should delegate to
2670 // alignPanel to decide if overview needs
2672 alignPanel.paintAlignment(false, false);
2673 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2674 viewport.sendSelection();
2684 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2686 SequenceGroup sg = viewport.getSelectionGroup();
2690 selectAllSequenceMenuItem_actionPerformed(null);
2695 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2697 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2699 // JAL-2034 - should delegate to
2700 // alignPanel to decide if overview needs
2703 alignPanel.paintAlignment(true, false);
2704 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2705 viewport.sendSelection();
2709 public void invertColSel_actionPerformed(ActionEvent e)
2711 viewport.invertColumnSelection();
2712 alignPanel.paintAlignment(true, false);
2713 viewport.sendSelection();
2723 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2725 trimAlignment(true);
2735 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2737 trimAlignment(false);
2740 void trimAlignment(boolean trimLeft)
2742 ColumnSelection colSel = viewport.getColumnSelection();
2745 if (!colSel.isEmpty())
2749 column = colSel.getMin();
2753 column = colSel.getMax();
2757 if (viewport.getSelectionGroup() != null)
2759 seqs = viewport.getSelectionGroup()
2760 .getSequencesAsArray(viewport.getHiddenRepSequences());
2764 seqs = viewport.getAlignment().getSequencesArray();
2767 TrimRegionCommand trimRegion;
2770 trimRegion = new TrimRegionCommand("Remove Left", true, seqs,
2771 column, viewport.getAlignment());
2772 viewport.getRanges().setStartRes(0);
2776 trimRegion = new TrimRegionCommand("Remove Right", false, seqs,
2777 column, viewport.getAlignment());
2780 statusBar.setText(MessageManager
2781 .formatMessage("label.removed_columns", new String[]
2782 { Integer.valueOf(trimRegion.getSize()).toString() }));
2784 addHistoryItem(trimRegion);
2786 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2788 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2789 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2791 viewport.getAlignment().deleteGroup(sg);
2795 viewport.firePropertyChange("alignment", null,
2796 viewport.getAlignment().getSequences());
2807 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2809 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2812 if (viewport.getSelectionGroup() != null)
2814 seqs = viewport.getSelectionGroup()
2815 .getSequencesAsArray(viewport.getHiddenRepSequences());
2816 start = viewport.getSelectionGroup().getStartRes();
2817 end = viewport.getSelectionGroup().getEndRes();
2821 seqs = viewport.getAlignment().getSequencesArray();
2824 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2825 "Remove Gapped Columns", seqs, start, end,
2826 viewport.getAlignment());
2828 addHistoryItem(removeGapCols);
2830 statusBar.setText(MessageManager
2831 .formatMessage("label.removed_empty_columns", new Object[]
2832 { Integer.valueOf(removeGapCols.getSize()).toString() }));
2834 // This is to maintain viewport position on first residue
2835 // of first sequence
2836 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2837 ViewportRanges ranges = viewport.getRanges();
2838 int startRes = seq.findPosition(ranges.getStartRes());
2839 // ShiftList shifts;
2840 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2841 // edit.alColumnChanges=shifts.getInverse();
2842 // if (viewport.hasHiddenColumns)
2843 // viewport.getColumnSelection().compensateForEdits(shifts);
2844 ranges.setStartRes(seq.findIndex(startRes) - 1);
2845 viewport.firePropertyChange("alignment", null,
2846 viewport.getAlignment().getSequences());
2857 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2859 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2862 if (viewport.getSelectionGroup() != null)
2864 seqs = viewport.getSelectionGroup()
2865 .getSequencesAsArray(viewport.getHiddenRepSequences());
2866 start = viewport.getSelectionGroup().getStartRes();
2867 end = viewport.getSelectionGroup().getEndRes();
2871 seqs = viewport.getAlignment().getSequencesArray();
2874 // This is to maintain viewport position on first residue
2875 // of first sequence
2876 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2877 int startRes = seq.findPosition(viewport.getRanges().getStartRes());
2879 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2880 viewport.getAlignment()));
2882 viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1);
2884 viewport.firePropertyChange("alignment", null,
2885 viewport.getAlignment().getSequences());
2896 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2898 viewport.setPadGaps(padGapsMenuitem.isSelected());
2899 viewport.firePropertyChange("alignment", null,
2900 viewport.getAlignment().getSequences());
2910 public void findMenuItem_actionPerformed(ActionEvent e)
2916 * Create a new view of the current alignment.
2919 public void newView_actionPerformed(ActionEvent e)
2921 newView(null, true);
2925 * Creates and shows a new view of the current alignment.
2928 * title of newly created view; if null, one will be generated
2929 * @param copyAnnotation
2930 * if true then duplicate all annnotation, groups and settings
2931 * @return new alignment panel, already displayed.
2933 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2936 * Create a new AlignmentPanel (with its own, new Viewport)
2938 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel);
2939 if (!copyAnnotation)
2942 * remove all groups and annotation except for the automatic stuff
2944 newap.av.getAlignment().deleteAllGroups();
2945 newap.av.getAlignment().deleteAllAnnotations(false);
2948 newap.av.setGatherViewsHere(false);
2950 if (viewport.viewName == null)
2952 viewport.viewName = MessageManager
2953 .getString("label.view_name_original");
2957 * Views share the same edits undo and redo stacks
2959 newap.av.setHistoryList(viewport.getHistoryList());
2960 newap.av.setRedoList(viewport.getRedoList());
2963 * Views share the same mappings; need to deregister any new mappings
2964 * created by copyAlignPanel, and register the new reference to the shared
2967 newap.av.replaceMappings(viewport.getAlignment());
2970 * start up cDNA consensus (if applicable) now mappings are in place
2972 if (newap.av.initComplementConsensus())
2974 newap.refresh(true); // adjust layout of annotations
2977 newap.av.viewName = getNewViewName(viewTitle);
2979 addAlignmentPanel(newap, true);
2980 newap.alignmentChanged();
2982 if (alignPanels.size() == 2)
2984 viewport.setGatherViewsHere(true);
2986 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2991 * Make a new name for the view, ensuring it is unique within the current
2992 * sequenceSetId. (This used to be essential for Jalview Project archives, but
2993 * these now use viewId. Unique view names are still desirable for usability.)
2998 protected String getNewViewName(String viewTitle)
3000 int index = Desktop.getViewCount(viewport.getSequenceSetId());
3001 boolean addFirstIndex = false;
3002 if (viewTitle == null || viewTitle.trim().length() == 0)
3004 viewTitle = MessageManager.getString("action.view");
3005 addFirstIndex = true;
3009 index = 1;// we count from 1 if given a specific name
3011 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
3013 List<Component> comps = PaintRefresher.components
3014 .get(viewport.getSequenceSetId());
3016 List<String> existingNames = getExistingViewNames(comps);
3018 while (existingNames.contains(newViewName))
3020 newViewName = viewTitle + " " + (++index);
3026 * Returns a list of distinct view names found in the given list of
3027 * components. View names are held on the viewport of an AlignmentPanel.
3032 protected List<String> getExistingViewNames(List<Component> comps)
3034 List<String> existingNames = new ArrayList<>();
3035 for (Component comp : comps)
3037 if (comp instanceof AlignmentPanel)
3039 AlignmentPanel ap = (AlignmentPanel) comp;
3040 if (!existingNames.contains(ap.av.viewName))
3042 existingNames.add(ap.av.viewName);
3046 return existingNames;
3050 * Explode tabbed views into separate windows.
3053 public void expandViews_actionPerformed(ActionEvent e)
3055 Desktop.explodeViews(this);
3059 * Gather views in separate windows back into a tabbed presentation.
3062 public void gatherViews_actionPerformed(ActionEvent e)
3064 Desktop.instance.gatherViews(this);
3074 public void font_actionPerformed(ActionEvent e)
3076 new FontChooser(alignPanel);
3086 protected void seqLimit_actionPerformed(ActionEvent e)
3088 viewport.setShowJVSuffix(seqLimits.isSelected());
3090 alignPanel.getIdPanel().getIdCanvas()
3091 .setPreferredSize(alignPanel.calculateIdWidth());
3092 alignPanel.paintAlignment(true, false);
3096 public void idRightAlign_actionPerformed(ActionEvent e)
3098 viewport.setRightAlignIds(idRightAlign.isSelected());
3099 alignPanel.paintAlignment(false, false);
3103 public void centreColumnLabels_actionPerformed(ActionEvent e)
3105 viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState());
3106 alignPanel.paintAlignment(false, false);
3112 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
3115 protected void followHighlight_actionPerformed()
3118 * Set the 'follow' flag on the Viewport (and scroll to position if now
3121 final boolean state = this.followHighlightMenuItem.getState();
3122 viewport.setFollowHighlight(state);
3125 alignPanel.scrollToPosition(viewport.getSearchResults(), false);
3136 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
3138 viewport.setColourText(colourTextMenuItem.isSelected());
3139 alignPanel.paintAlignment(false, false);
3149 public void wrapMenuItem_actionPerformed(ActionEvent e)
3151 scaleAbove.setVisible(wrapMenuItem.isSelected());
3152 scaleLeft.setVisible(wrapMenuItem.isSelected());
3153 scaleRight.setVisible(wrapMenuItem.isSelected());
3154 viewport.setWrapAlignment(wrapMenuItem.isSelected());
3155 alignPanel.updateLayout();
3159 public void showAllSeqs_actionPerformed(ActionEvent e)
3161 viewport.showAllHiddenSeqs();
3165 public void showAllColumns_actionPerformed(ActionEvent e)
3167 viewport.showAllHiddenColumns();
3168 alignPanel.paintAlignment(true, true);
3169 viewport.sendSelection();
3173 public void hideSelSequences_actionPerformed(ActionEvent e)
3175 viewport.hideAllSelectedSeqs();
3179 * called by key handler and the hide all/show all menu items
3184 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
3187 boolean hide = false;
3188 SequenceGroup sg = viewport.getSelectionGroup();
3189 if (!toggleSeqs && !toggleCols)
3191 // Hide everything by the current selection - this is a hack - we do the
3192 // invert and then hide
3193 // first check that there will be visible columns after the invert.
3194 if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0
3195 && sg.getStartRes() <= sg.getEndRes()))
3197 // now invert the sequence set, if required - empty selection implies
3198 // that no hiding is required.
3201 invertSequenceMenuItem_actionPerformed(null);
3202 sg = viewport.getSelectionGroup();
3206 viewport.expandColSelection(sg, true);
3207 // finally invert the column selection and get the new sequence
3209 invertColSel_actionPerformed(null);
3216 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
3218 hideSelSequences_actionPerformed(null);
3221 else if (!(toggleCols && viewport.hasSelectedColumns()))
3223 showAllSeqs_actionPerformed(null);
3229 if (viewport.hasSelectedColumns())
3231 hideSelColumns_actionPerformed(null);
3234 viewport.setSelectionGroup(sg);
3239 showAllColumns_actionPerformed(null);
3248 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
3249 * event.ActionEvent)
3252 public void hideAllButSelection_actionPerformed(ActionEvent e)
3254 toggleHiddenRegions(false, false);
3255 viewport.sendSelection();
3262 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
3266 public void hideAllSelection_actionPerformed(ActionEvent e)
3268 SequenceGroup sg = viewport.getSelectionGroup();
3269 viewport.expandColSelection(sg, false);
3270 viewport.hideAllSelectedSeqs();
3271 viewport.hideSelectedColumns();
3272 alignPanel.paintAlignment(true, true);
3273 viewport.sendSelection();
3280 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
3284 public void showAllhidden_actionPerformed(ActionEvent e)
3286 viewport.showAllHiddenColumns();
3287 viewport.showAllHiddenSeqs();
3288 alignPanel.paintAlignment(true, true);
3289 viewport.sendSelection();
3293 public void hideSelColumns_actionPerformed(ActionEvent e)
3295 viewport.hideSelectedColumns();
3296 alignPanel.paintAlignment(true, true);
3297 viewport.sendSelection();
3301 public void hiddenMarkers_actionPerformed(ActionEvent e)
3303 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
3314 protected void scaleAbove_actionPerformed(ActionEvent e)
3316 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
3317 // TODO: do we actually need to update overview for scale above change ?
3318 alignPanel.paintAlignment(true, false);
3328 protected void scaleLeft_actionPerformed(ActionEvent e)
3330 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
3331 alignPanel.paintAlignment(true, false);
3341 protected void scaleRight_actionPerformed(ActionEvent e)
3343 viewport.setScaleRightWrapped(scaleRight.isSelected());
3344 alignPanel.paintAlignment(true, false);
3354 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
3356 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
3357 alignPanel.paintAlignment(false, false);
3367 public void viewTextMenuItem_actionPerformed(ActionEvent e)
3369 viewport.setShowText(viewTextMenuItem.isSelected());
3370 alignPanel.paintAlignment(false, false);
3380 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
3382 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
3383 alignPanel.paintAlignment(false, false);
3386 public FeatureSettings featureSettings;
3389 public FeatureSettingsControllerI getFeatureSettingsUI()
3391 return featureSettings;
3395 public void featureSettings_actionPerformed(ActionEvent e)
3397 if (featureSettings != null)
3399 featureSettings.close();
3400 featureSettings = null;
3402 if (!showSeqFeatures.isSelected())
3404 // make sure features are actually displayed
3405 showSeqFeatures.setSelected(true);
3406 showSeqFeatures_actionPerformed(null);
3408 featureSettings = new FeatureSettings(this);
3412 * Set or clear 'Show Sequence Features'
3418 public void showSeqFeatures_actionPerformed(ActionEvent evt)
3420 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
3421 alignPanel.paintAlignment(true, true);
3425 * Action on toggle of the 'Show annotations' menu item. This shows or hides
3426 * the annotations panel as a whole.
3428 * The options to show/hide all annotations should be enabled when the panel
3429 * is shown, and disabled when the panel is hidden.
3434 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
3436 final boolean setVisible = annotationPanelMenuItem.isSelected();
3437 viewport.setShowAnnotation(setVisible);
3438 this.showAllSeqAnnotations.setEnabled(setVisible);
3439 this.hideAllSeqAnnotations.setEnabled(setVisible);
3440 this.showAllAlAnnotations.setEnabled(setVisible);
3441 this.hideAllAlAnnotations.setEnabled(setVisible);
3442 alignPanel.updateLayout();
3446 public void alignmentProperties()
3448 JEditorPane editPane = new JEditorPane("text/html", "");
3449 editPane.setEditable(false);
3450 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
3453 MessageManager.formatMessage("label.html_content", new Object[]
3454 { contents.toString() }));
3455 JInternalFrame frame = new JInternalFrame();
3456 frame.getContentPane().add(new JScrollPane(editPane));
3458 Desktop.addInternalFrame(frame, MessageManager
3459 .formatMessage("label.alignment_properties", new Object[]
3460 { getTitle() }), 500, 400);
3470 public void overviewMenuItem_actionPerformed(ActionEvent e)
3472 if (alignPanel.overviewPanel != null)
3477 JInternalFrame frame = new JInternalFrame();
3478 final OverviewPanel overview = new OverviewPanel(alignPanel);
3479 frame.setContentPane(overview);
3480 Desktop.addInternalFrame(frame, MessageManager
3481 .formatMessage("label.overview_params", new Object[]
3482 { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
3485 frame.setLayer(JLayeredPane.PALETTE_LAYER);
3486 frame.addInternalFrameListener(
3487 new javax.swing.event.InternalFrameAdapter()
3490 public void internalFrameClosed(
3491 javax.swing.event.InternalFrameEvent evt)
3494 alignPanel.setOverviewPanel(null);
3498 alignPanel.setOverviewPanel(overview);
3502 public void textColour_actionPerformed()
3504 new TextColourChooser().chooseColour(alignPanel, null);
3508 * public void covariationColour_actionPerformed() {
3510 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3514 public void annotationColour_actionPerformed()
3516 new AnnotationColourChooser(viewport, alignPanel);
3520 public void annotationColumn_actionPerformed(ActionEvent e)
3522 new AnnotationColumnChooser(viewport, alignPanel);
3526 * Action on the user checking or unchecking the option to apply the selected
3527 * colour scheme to all groups. If unchecked, groups may have their own
3528 * independent colour schemes.
3533 public void applyToAllGroups_actionPerformed(boolean selected)
3535 viewport.setColourAppliesToAllGroups(selected);
3539 * Action on user selecting a colour from the colour menu
3542 * the name (not the menu item label!) of the colour scheme
3545 public void changeColour_actionPerformed(String name)
3548 * 'User Defined' opens a panel to configure or load a
3549 * user-defined colour scheme
3551 if (ResidueColourScheme.USER_DEFINED_MENU.equals(name))
3553 new UserDefinedColours(alignPanel);
3558 * otherwise set the chosen colour scheme (or null for 'None')
3560 ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
3561 viewport.getAlignment(), viewport.getHiddenRepSequences());
3566 * Actions on setting or changing the alignment colour scheme
3571 public void changeColour(ColourSchemeI cs)
3573 // TODO: pull up to controller method
3574 ColourMenuHelper.setColourSelected(colourMenu, cs);
3576 viewport.setGlobalColourScheme(cs);
3578 alignPanel.paintAlignment(true, true);
3582 * Show the PID threshold slider panel
3585 protected void modifyPID_actionPerformed()
3587 SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(),
3588 alignPanel.getViewName());
3589 SliderPanel.showPIDSlider();
3593 * Show the Conservation slider panel
3596 protected void modifyConservation_actionPerformed()
3598 SliderPanel.setConservationSlider(alignPanel,
3599 viewport.getResidueShading(), alignPanel.getViewName());
3600 SliderPanel.showConservationSlider();
3604 * Action on selecting or deselecting (Colour) By Conservation
3607 public void conservationMenuItem_actionPerformed(boolean selected)
3609 modifyConservation.setEnabled(selected);
3610 viewport.setConservationSelected(selected);
3611 viewport.getResidueShading().setConservationApplied(selected);
3613 changeColour(viewport.getGlobalColourScheme());
3616 modifyConservation_actionPerformed();
3620 SliderPanel.hideConservationSlider();
3625 * Action on selecting or deselecting (Colour) Above PID Threshold
3628 public void abovePIDThreshold_actionPerformed(boolean selected)
3630 modifyPID.setEnabled(selected);
3631 viewport.setAbovePIDThreshold(selected);
3634 viewport.getResidueShading().setThreshold(0,
3635 viewport.isIgnoreGapsConsensus());
3638 changeColour(viewport.getGlobalColourScheme());
3641 modifyPID_actionPerformed();
3645 SliderPanel.hidePIDSlider();
3656 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3658 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3659 AlignmentSorter.sortByPID(viewport.getAlignment(),
3660 viewport.getAlignment().getSequenceAt(0));
3661 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3662 viewport.getAlignment()));
3663 alignPanel.paintAlignment(true, false);
3673 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3675 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3676 AlignmentSorter.sortByID(viewport.getAlignment());
3678 new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3679 alignPanel.paintAlignment(true, false);
3689 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3691 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3692 AlignmentSorter.sortByLength(viewport.getAlignment());
3693 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3694 viewport.getAlignment()));
3695 alignPanel.paintAlignment(true, false);
3705 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3707 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3708 AlignmentSorter.sortByGroup(viewport.getAlignment());
3709 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3710 viewport.getAlignment()));
3712 alignPanel.paintAlignment(true, false);
3722 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3724 new RedundancyPanel(alignPanel, this);
3734 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3736 if ((viewport.getSelectionGroup() == null)
3737 || (viewport.getSelectionGroup().getSize() < 2))
3739 JvOptionPane.showInternalMessageDialog(this,
3740 MessageManager.getString(
3741 "label.you_must_select_least_two_sequences"),
3742 MessageManager.getString("label.invalid_selection"),
3743 JvOptionPane.WARNING_MESSAGE);
3747 JInternalFrame frame = new JInternalFrame();
3748 frame.setContentPane(new PairwiseAlignPanel(viewport));
3749 Desktop.addInternalFrame(frame,
3750 MessageManager.getString("action.pairwise_alignment"), 600,
3756 public void autoCalculate_actionPerformed(ActionEvent e)
3758 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3759 if (viewport.autoCalculateConsensus)
3761 viewport.firePropertyChange("alignment", null,
3762 viewport.getAlignment().getSequences());
3767 public void sortByTreeOption_actionPerformed(ActionEvent e)
3769 viewport.sortByTree = sortByTree.isSelected();
3773 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3775 viewport.followSelection = listenToViewSelections.isSelected();
3779 * Constructs a tree panel and adds it to the desktop
3782 * tree type (NJ or AV)
3784 * name of score model used to compute the tree
3786 * parameters for the distance or similarity calculation
3788 void newTreePanel(String type, String modelName,
3789 SimilarityParamsI options)
3791 String frameTitle = "";
3794 boolean onSelection = false;
3795 if (viewport.getSelectionGroup() != null
3796 && viewport.getSelectionGroup().getSize() > 0)
3798 SequenceGroup sg = viewport.getSelectionGroup();
3800 /* Decide if the selection is a column region */
3801 for (SequenceI _s : sg.getSequences())
3803 if (_s.getLength() < sg.getEndRes())
3805 JvOptionPane.showMessageDialog(Desktop.desktop,
3806 MessageManager.getString(
3807 "label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3808 MessageManager.getString(
3809 "label.sequences_selection_not_aligned"),
3810 JvOptionPane.WARNING_MESSAGE);
3819 if (viewport.getAlignment().getHeight() < 2)
3825 tp = new TreePanel(alignPanel, type, modelName, options);
3826 frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : "");
3828 frameTitle += " from ";
3830 if (viewport.viewName != null)
3832 frameTitle += viewport.viewName + " of ";
3835 frameTitle += this.title;
3837 Desktop.addInternalFrame(tp, frameTitle, 600, 500);
3848 public void addSortByOrderMenuItem(String title,
3849 final AlignmentOrder order)
3851 final JMenuItem item = new JMenuItem(MessageManager
3852 .formatMessage("action.by_title_param", new Object[]
3855 item.addActionListener(new java.awt.event.ActionListener()
3858 public void actionPerformed(ActionEvent e)
3860 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3862 // TODO: JBPNote - have to map order entries to curent SequenceI
3864 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3866 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3867 viewport.getAlignment()));
3869 alignPanel.paintAlignment(true, false);
3875 * Add a new sort by annotation score menu item
3878 * the menu to add the option to
3880 * the label used to retrieve scores for each sequence on the
3883 public void addSortByAnnotScoreMenuItem(JMenu sort,
3884 final String scoreLabel)
3886 final JMenuItem item = new JMenuItem(scoreLabel);
3888 item.addActionListener(new java.awt.event.ActionListener()
3891 public void actionPerformed(ActionEvent e)
3893 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3894 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3895 viewport.getAlignment());// ,viewport.getSelectionGroup());
3896 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3897 viewport.getAlignment()));
3898 alignPanel.paintAlignment(true, false);
3904 * last hash for alignment's annotation array - used to minimise cost of
3907 protected int _annotationScoreVectorHash;
3910 * search the alignment and rebuild the sort by annotation score submenu the
3911 * last alignment annotation vector hash is stored to minimize cost of
3912 * rebuilding in subsequence calls.
3916 public void buildSortByAnnotationScoresMenu()
3918 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3923 if (viewport.getAlignment().getAlignmentAnnotation()
3924 .hashCode() != _annotationScoreVectorHash)
3926 sortByAnnotScore.removeAll();
3927 // almost certainly a quicker way to do this - but we keep it simple
3928 Hashtable scoreSorts = new Hashtable();
3929 AlignmentAnnotation aann[];
3930 for (SequenceI sqa : viewport.getAlignment().getSequences())
3932 aann = sqa.getAnnotation();
3933 for (int i = 0; aann != null && i < aann.length; i++)
3935 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3937 scoreSorts.put(aann[i].label, aann[i].label);
3941 Enumeration labels = scoreSorts.keys();
3942 while (labels.hasMoreElements())
3944 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3945 (String) labels.nextElement());
3947 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3950 _annotationScoreVectorHash = viewport.getAlignment()
3951 .getAlignmentAnnotation().hashCode();
3956 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3957 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3958 * call. Listeners are added to remove the menu item when the treePanel is
3959 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3963 public void buildTreeSortMenu()
3965 sortByTreeMenu.removeAll();
3967 List<Component> comps = PaintRefresher.components
3968 .get(viewport.getSequenceSetId());
3969 List<TreePanel> treePanels = new ArrayList<>();
3970 for (Component comp : comps)
3972 if (comp instanceof TreePanel)
3974 treePanels.add((TreePanel) comp);
3978 if (treePanels.size() < 1)
3980 sortByTreeMenu.setVisible(false);
3984 sortByTreeMenu.setVisible(true);
3986 for (final TreePanel tp : treePanels)
3988 final JMenuItem item = new JMenuItem(tp.getTitle());
3989 item.addActionListener(new java.awt.event.ActionListener()
3992 public void actionPerformed(ActionEvent e)
3994 tp.sortByTree_actionPerformed();
3995 addHistoryItem(tp.sortAlignmentIn(alignPanel));
4000 sortByTreeMenu.add(item);
4004 public boolean sortBy(AlignmentOrder alorder, String undoname)
4006 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
4007 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
4008 if (undoname != null)
4010 addHistoryItem(new OrderCommand(undoname, oldOrder,
4011 viewport.getAlignment()));
4013 alignPanel.paintAlignment(true, false);
4018 * Work out whether the whole set of sequences or just the selected set will
4019 * be submitted for multiple alignment.
4022 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
4024 // Now, check we have enough sequences
4025 AlignmentView msa = null;
4027 if ((viewport.getSelectionGroup() != null)
4028 && (viewport.getSelectionGroup().getSize() > 1))
4030 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
4031 // some common interface!
4033 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
4034 * SequenceI[sz = seqs.getSize(false)];
4036 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
4037 * seqs.getSequenceAt(i); }
4039 msa = viewport.getAlignmentView(true);
4041 else if (viewport.getSelectionGroup() != null
4042 && viewport.getSelectionGroup().getSize() == 1)
4044 int option = JvOptionPane.showConfirmDialog(this,
4045 MessageManager.getString("warn.oneseq_msainput_selection"),
4046 MessageManager.getString("label.invalid_selection"),
4047 JvOptionPane.OK_CANCEL_OPTION);
4048 if (option == JvOptionPane.OK_OPTION)
4050 msa = viewport.getAlignmentView(false);
4055 msa = viewport.getAlignmentView(false);
4061 * Decides what is submitted to a secondary structure prediction service: the
4062 * first sequence in the alignment, or in the current selection, or, if the
4063 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4064 * region or the whole alignment. (where the first sequence in the set is the
4065 * one that the prediction will be for).
4067 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4069 AlignmentView seqs = null;
4071 if ((viewport.getSelectionGroup() != null)
4072 && (viewport.getSelectionGroup().getSize() > 0))
4074 seqs = viewport.getAlignmentView(true);
4078 seqs = viewport.getAlignmentView(false);
4080 // limit sequences - JBPNote in future - could spawn multiple prediction
4082 // TODO: viewport.getAlignment().isAligned is a global state - the local
4083 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4084 if (!viewport.getAlignment().isAligned(false))
4086 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] });
4087 // TODO: if seqs.getSequences().length>1 then should really have warned
4101 protected void loadTreeMenuItem_actionPerformed(ActionEvent e)
4103 // Pick the tree file
4104 JalviewFileChooser chooser = new JalviewFileChooser(
4105 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4106 chooser.setFileView(new JalviewFileView());
4107 chooser.setDialogTitle(
4108 MessageManager.getString("label.select_newick_like_tree_file"));
4109 chooser.setToolTipText(
4110 MessageManager.getString("label.load_tree_file"));
4112 int value = chooser.showOpenDialog(null);
4114 if (value == JalviewFileChooser.APPROVE_OPTION)
4116 String filePath = chooser.getSelectedFile().getPath();
4117 Cache.setProperty("LAST_DIRECTORY", filePath);
4118 NewickFile fin = null;
4121 fin = new NewickFile(filePath, DataSourceType.FILE);
4122 viewport.setCurrentTree(showNewickTree(fin, filePath).getTree());
4123 } catch (Exception ex)
4125 JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4126 MessageManager.getString("label.problem_reading_tree_file"),
4127 JvOptionPane.WARNING_MESSAGE);
4128 ex.printStackTrace();
4130 if (fin != null && fin.hasWarningMessage())
4132 JvOptionPane.showMessageDialog(Desktop.desktop,
4133 fin.getWarningMessage(),
4135 .getString("label.possible_problem_with_tree_file"),
4136 JvOptionPane.WARNING_MESSAGE);
4141 public TreePanel showNewickTree(NewickFile nf, String treeTitle)
4143 return showNewickTree(nf, treeTitle, 600, 500, 4, 5);
4146 public TreePanel showNewickTree(NewickFile nf, String treeTitle, int w,
4147 int h, int x, int y)
4149 return showNewickTree(nf, treeTitle, null, w, h, x, y);
4153 * Add a treeviewer for the tree extracted from a Newick file object to the
4154 * current alignment view
4161 * Associated alignment input data (or null)
4170 * @return TreePanel handle
4172 public TreePanel showNewickTree(NewickFile nf, String treeTitle,
4173 AlignmentView input, int w, int h, int x, int y)
4175 TreePanel tp = null;
4181 if (nf.getTree() != null)
4183 tp = new TreePanel(alignPanel, nf, treeTitle, input);
4189 tp.setLocation(x, y);
4192 Desktop.addInternalFrame(tp, treeTitle, w, h);
4194 } catch (Exception ex)
4196 ex.printStackTrace();
4202 private boolean buildingMenu = false;
4205 * Generates menu items and listener event actions for web service clients
4208 public void BuildWebServiceMenu()
4210 while (buildingMenu)
4214 System.err.println("Waiting for building menu to finish.");
4216 } catch (Exception e)
4220 final AlignFrame me = this;
4221 buildingMenu = true;
4222 new Thread(new Runnable()
4227 final List<JMenuItem> legacyItems = new ArrayList<>();
4230 // System.err.println("Building ws menu again "
4231 // + Thread.currentThread());
4232 // TODO: add support for context dependent disabling of services based
4234 // alignment and current selection
4235 // TODO: add additional serviceHandle parameter to specify abstract
4237 // class independently of AbstractName
4238 // TODO: add in rediscovery GUI function to restart discoverer
4239 // TODO: group services by location as well as function and/or
4241 // object broker mechanism.
4242 final Vector<JMenu> wsmenu = new Vector<>();
4243 final IProgressIndicator af = me;
4246 * do not i18n these strings - they are hard-coded in class
4247 * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and
4248 * SequenceAnnotationWSClient.initSequenceAnnotationWSClient()
4250 final JMenu msawsmenu = new JMenu("Alignment");
4251 final JMenu secstrmenu = new JMenu(
4252 "Secondary Structure Prediction");
4253 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4254 final JMenu analymenu = new JMenu("Analysis");
4255 final JMenu dismenu = new JMenu("Protein Disorder");
4256 // JAL-940 - only show secondary structure prediction services from
4257 // the legacy server
4258 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4260 Discoverer.services != null && (Discoverer.services.size() > 0))
4262 // TODO: refactor to allow list of AbstractName/Handler bindings to
4264 // stored or retrieved from elsewhere
4265 // No MSAWS used any more:
4266 // Vector msaws = null; // (Vector)
4267 // Discoverer.services.get("MsaWS");
4268 Vector secstrpr = (Vector) Discoverer.services
4270 if (secstrpr != null)
4272 // Add any secondary structure prediction services
4273 for (int i = 0, j = secstrpr.size(); i < j; i++)
4275 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4277 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4278 .getServiceClient(sh);
4279 int p = secstrmenu.getItemCount();
4280 impl.attachWSMenuEntry(secstrmenu, me);
4281 int q = secstrmenu.getItemCount();
4282 for (int litm = p; litm < q; litm++)
4284 legacyItems.add(secstrmenu.getItem(litm));
4290 // Add all submenus in the order they should appear on the web
4292 wsmenu.add(msawsmenu);
4293 wsmenu.add(secstrmenu);
4294 wsmenu.add(dismenu);
4295 wsmenu.add(analymenu);
4296 // No search services yet
4297 // wsmenu.add(seqsrchmenu);
4299 javax.swing.SwingUtilities.invokeLater(new Runnable()
4306 webService.removeAll();
4307 // first, add discovered services onto the webservices menu
4308 if (wsmenu.size() > 0)
4310 for (int i = 0, j = wsmenu.size(); i < j; i++)
4312 webService.add(wsmenu.get(i));
4317 webService.add(me.webServiceNoServices);
4319 // TODO: move into separate menu builder class.
4320 boolean new_sspred = false;
4321 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4323 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4324 if (jws2servs != null)
4326 if (jws2servs.hasServices())
4328 jws2servs.attachWSMenuEntry(webService, me);
4329 for (Jws2Instance sv : jws2servs.getServices())
4331 if (sv.description.toLowerCase().contains("jpred"))
4333 for (JMenuItem jmi : legacyItems)
4335 jmi.setVisible(false);
4341 if (jws2servs.isRunning())
4343 JMenuItem tm = new JMenuItem(
4344 "Still discovering JABA Services");
4345 tm.setEnabled(false);
4350 build_urlServiceMenu(me.webService);
4351 build_fetchdbmenu(webService);
4352 for (JMenu item : wsmenu)
4354 if (item.getItemCount() == 0)
4356 item.setEnabled(false);
4360 item.setEnabled(true);
4363 } catch (Exception e)
4366 "Exception during web service menu building process.",
4371 } catch (Exception e)
4374 buildingMenu = false;
4381 * construct any groupURL type service menu entries.
4385 private void build_urlServiceMenu(JMenu webService)
4387 // TODO: remove this code when 2.7 is released
4388 // DEBUG - alignmentView
4390 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4391 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4393 * @Override public void actionPerformed(ActionEvent e) {
4394 * jalview.datamodel.AlignmentView
4395 * .testSelectionViews(af.viewport.getAlignment(),
4396 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4398 * }); webService.add(testAlView);
4400 // TODO: refactor to RestClient discoverer and merge menu entries for
4401 // rest-style services with other types of analysis/calculation service
4402 // SHmmr test client - still being implemented.
4403 // DEBUG - alignmentView
4405 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4408 client.attachWSMenuEntry(
4409 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4415 * Searches the alignment sequences for xRefs and builds the Show
4416 * Cross-References menu (formerly called Show Products), with database
4417 * sources for which cross-references are found (protein sources for a
4418 * nucleotide alignment and vice versa)
4420 * @return true if Show Cross-references menu should be enabled
4422 public boolean canShowProducts()
4424 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
4425 AlignmentI dataset = viewport.getAlignment().getDataset();
4427 showProducts.removeAll();
4428 final boolean dna = viewport.getAlignment().isNucleotide();
4430 if (seqs == null || seqs.length == 0)
4432 // nothing to see here.
4436 boolean showp = false;
4439 List<String> ptypes = new CrossRef(seqs, dataset)
4440 .findXrefSourcesForSequences(dna);
4442 for (final String source : ptypes)
4445 final AlignFrame af = this;
4446 JMenuItem xtype = new JMenuItem(source);
4447 xtype.addActionListener(new ActionListener()
4450 public void actionPerformed(ActionEvent e)
4452 showProductsFor(af.viewport.getSequenceSelection(), dna,
4456 showProducts.add(xtype);
4458 showProducts.setVisible(showp);
4459 showProducts.setEnabled(showp);
4460 } catch (Exception e)
4463 "canShowProducts threw an exception - please report to help@jalview.org",
4471 * Finds and displays cross-references for the selected sequences (protein
4472 * products for nucleotide sequences, dna coding sequences for peptides).
4475 * the sequences to show cross-references for
4477 * true if from a nucleotide alignment (so showing proteins)
4479 * the database to show cross-references for
4481 protected void showProductsFor(final SequenceI[] sel, final boolean _odna,
4482 final String source)
4484 new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this))
4489 * Construct and display a new frame containing the translation of this
4490 * frame's DNA sequences to their aligned protein (amino acid) equivalents.
4493 public void showTranslation_actionPerformed(ActionEvent e)
4495 AlignmentI al = null;
4498 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
4500 al = dna.translateCdna();
4501 } catch (Exception ex)
4503 jalview.bin.Cache.log.error(
4504 "Exception during translation. Please report this !", ex);
4505 final String msg = MessageManager.getString(
4506 "label.error_when_translating_sequences_submit_bug_report");
4507 final String errorTitle = MessageManager
4508 .getString("label.implementation_error")
4509 + MessageManager.getString("label.translation_failed");
4510 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4511 JvOptionPane.ERROR_MESSAGE);
4514 if (al == null || al.getHeight() == 0)
4516 final String msg = MessageManager.getString(
4517 "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation");
4518 final String errorTitle = MessageManager
4519 .getString("label.translation_failed");
4520 JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle,
4521 JvOptionPane.WARNING_MESSAGE);
4525 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4526 af.setFileFormat(this.currentFileFormat);
4527 final String newTitle = MessageManager
4528 .formatMessage("label.translation_of_params", new Object[]
4529 { this.getTitle() });
4530 af.setTitle(newTitle);
4531 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
4533 final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
4534 viewport.openSplitFrame(af, new Alignment(seqs));
4538 Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
4545 * Set the file format
4549 public void setFileFormat(FileFormatI format)
4551 this.currentFileFormat = format;
4555 * Try to load a features file onto the alignment.
4558 * contents or path to retrieve file
4560 * access mode of file (see jalview.io.AlignFile)
4561 * @return true if features file was parsed correctly.
4563 public boolean parseFeaturesFile(String file, DataSourceType sourceType)
4565 return avc.parseFeaturesFile(file, sourceType,
4566 Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4571 public void refreshFeatureUI(boolean enableIfNecessary)
4573 // note - currently this is only still here rather than in the controller
4574 // because of the featureSettings hard reference that is yet to be
4576 if (enableIfNecessary)
4578 viewport.setShowSequenceFeatures(true);
4579 showSeqFeatures.setSelected(true);
4585 public void dragEnter(DropTargetDragEvent evt)
4590 public void dragExit(DropTargetEvent evt)
4595 public void dragOver(DropTargetDragEvent evt)
4600 public void dropActionChanged(DropTargetDragEvent evt)
4605 public void drop(DropTargetDropEvent evt)
4607 // JAL-1552 - acceptDrop required before getTransferable call for
4608 // Java's Transferable for native dnd
4609 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4610 Transferable t = evt.getTransferable();
4611 final AlignFrame thisaf = this;
4612 final List<String> files = new ArrayList<>();
4613 List<DataSourceType> protocols = new ArrayList<>();
4617 Desktop.transferFromDropTarget(files, protocols, evt, t);
4618 } catch (Exception e)
4620 e.printStackTrace();
4624 new Thread(new Runnable()
4631 // check to see if any of these files have names matching sequences
4634 SequenceIdMatcher idm = new SequenceIdMatcher(
4635 viewport.getAlignment().getSequencesArray());
4637 * Object[] { String,SequenceI}
4639 ArrayList<Object[]> filesmatched = new ArrayList<>();
4640 ArrayList<String> filesnotmatched = new ArrayList<>();
4641 for (int i = 0; i < files.size(); i++)
4643 String file = files.get(i).toString();
4645 DataSourceType protocol = FormatAdapter.checkProtocol(file);
4646 if (protocol == DataSourceType.FILE)
4648 File fl = new File(file);
4649 pdbfn = fl.getName();
4651 else if (protocol == DataSourceType.URL)
4653 URL url = new URL(file);
4654 pdbfn = url.getFile();
4656 if (pdbfn.length() > 0)
4658 // attempt to find a match in the alignment
4659 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4660 int l = 0, c = pdbfn.indexOf(".");
4661 while (mtch == null && c != -1)
4666 } while ((c = pdbfn.indexOf(".", l)) > l);
4669 pdbfn = pdbfn.substring(0, l);
4671 mtch = idm.findAllIdMatches(pdbfn);
4675 FileFormatI type = null;
4678 type = new IdentifyFile().identify(file, protocol);
4679 } catch (Exception ex)
4683 if (type != null && type.isStructureFile())
4685 filesmatched.add(new Object[] { file, protocol, mtch });
4689 // File wasn't named like one of the sequences or wasn't a PDB
4691 filesnotmatched.add(file);
4695 if (filesmatched.size() > 0)
4697 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4698 || JvOptionPane.showConfirmDialog(thisaf,
4699 MessageManager.formatMessage(
4700 "label.automatically_associate_structure_files_with_sequences_same_name",
4702 { Integer.valueOf(filesmatched.size())
4704 MessageManager.getString(
4705 "label.automatically_associate_structure_files_by_name"),
4706 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION)
4709 for (Object[] fm : filesmatched)
4711 // try and associate
4712 // TODO: may want to set a standard ID naming formalism for
4713 // associating PDB files which have no IDs.
4714 for (SequenceI toassoc : (SequenceI[]) fm[2])
4716 PDBEntry pe = new AssociatePdbFileWithSeq()
4717 .associatePdbWithSeq((String) fm[0],
4718 (DataSourceType) fm[1], toassoc, false,
4722 System.err.println("Associated file : "
4723 + ((String) fm[0]) + " with "
4724 + toassoc.getDisplayId(true));
4728 // TODO: do we need to update overview ? only if features are
4730 alignPanel.paintAlignment(true, false);
4734 if (filesnotmatched.size() > 0)
4736 if (assocfiles > 0 && (Cache.getDefault(
4737 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false)
4738 || JvOptionPane.showConfirmDialog(thisaf,
4739 "<html>" + MessageManager.formatMessage(
4740 "label.ignore_unmatched_dropped_files_info",
4743 filesnotmatched.size())
4746 MessageManager.getString(
4747 "label.ignore_unmatched_dropped_files"),
4748 JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION))
4752 for (String fn : filesnotmatched)
4754 loadJalviewDataFile(fn, null, null, null);
4758 } catch (Exception ex)
4760 ex.printStackTrace();
4768 * Attempt to load a "dropped" file or URL string, by testing in turn for
4770 * <li>an Annotation file</li>
4771 * <li>a JNet file</li>
4772 * <li>a features file</li>
4773 * <li>else try to interpret as an alignment file</li>
4777 * either a filename or a URL string.
4778 * @throws InterruptedException
4779 * @throws IOException
4781 public void loadJalviewDataFile(String file, DataSourceType sourceType,
4782 FileFormatI format, SequenceI assocSeq)
4786 if (sourceType == null)
4788 sourceType = FormatAdapter.checkProtocol(file);
4790 // if the file isn't identified, or not positively identified as some
4791 // other filetype (PFAM is default unidentified alignment file type) then
4792 // try to parse as annotation.
4793 boolean isAnnotation = (format == null
4794 || FileFormat.Pfam.equals(format))
4795 ? new AnnotationFile().annotateAlignmentView(viewport,
4801 // first see if its a T-COFFEE score file
4802 TCoffeeScoreFile tcf = null;
4805 tcf = new TCoffeeScoreFile(file, sourceType);
4808 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4812 new TCoffeeColourScheme(viewport.getAlignment()));
4813 isAnnotation = true;
4814 statusBar.setText(MessageManager.getString(
4815 "label.successfully_pasted_tcoffee_scores_to_alignment"));
4819 // some problem - if no warning its probable that the ID matching
4820 // process didn't work
4821 JvOptionPane.showMessageDialog(Desktop.desktop,
4822 tcf.getWarningMessage() == null
4823 ? MessageManager.getString(
4824 "label.check_file_matches_sequence_ids_alignment")
4825 : tcf.getWarningMessage(),
4826 MessageManager.getString(
4827 "label.problem_reading_tcoffee_score_file"),
4828 JvOptionPane.WARNING_MESSAGE);
4835 } catch (Exception x)
4838 "Exception when processing data source as T-COFFEE score file",
4844 // try to see if its a JNet 'concise' style annotation file *before*
4846 // try to parse it as a features file
4849 format = new IdentifyFile().identify(file, sourceType);
4851 if (FileFormat.ScoreMatrix == format)
4853 ScoreMatrixFile sm = new ScoreMatrixFile(
4854 new FileParse(file, sourceType));
4856 // todo: i18n this message
4857 statusBar.setText(MessageManager.formatMessage(
4858 "label.successfully_loaded_matrix",
4859 sm.getMatrixName()));
4861 else if (FileFormat.Jnet.equals(format))
4863 JPredFile predictions = new JPredFile(file, sourceType);
4864 new JnetAnnotationMaker();
4865 JnetAnnotationMaker.add_annotation(predictions,
4866 viewport.getAlignment(), 0, false);
4867 viewport.getAlignment().setupJPredAlignment();
4868 isAnnotation = true;
4870 // else if (IdentifyFile.FeaturesFile.equals(format))
4871 else if (FileFormat.Features.equals(format))
4873 if (parseFeaturesFile(file, sourceType))
4875 alignPanel.paintAlignment(true, true);
4880 new FileLoader().LoadFile(viewport, file, sourceType, format);
4886 alignPanel.adjustAnnotationHeight();
4887 viewport.updateSequenceIdColours();
4888 buildSortByAnnotationScoresMenu();
4889 alignPanel.paintAlignment(true, true);
4891 } catch (Exception ex)
4893 ex.printStackTrace();
4894 } catch (OutOfMemoryError oom)
4899 } catch (Exception x)
4904 + (sourceType != null
4905 ? (sourceType == DataSourceType.PASTE
4907 : "using " + sourceType + " from "
4911 ? "(parsing as '" + format + "' file)"
4913 oom, Desktop.desktop);
4918 * Method invoked by the ChangeListener on the tabbed pane, in other words
4919 * when a different tabbed pane is selected by the user or programmatically.
4922 public void tabSelectionChanged(int index)
4926 alignPanel = alignPanels.get(index);
4927 viewport = alignPanel.av;
4928 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
4929 setMenusFromViewport(viewport);
4933 * 'focus' any colour slider that is open to the selected viewport
4935 if (viewport.getConservationSelected())
4937 SliderPanel.setConservationSlider(alignPanel,
4938 viewport.getResidueShading(), alignPanel.getViewName());
4942 SliderPanel.hideConservationSlider();
4944 if (viewport.getAbovePIDThreshold())
4946 SliderPanel.setPIDSliderSource(alignPanel,
4947 viewport.getResidueShading(), alignPanel.getViewName());
4951 SliderPanel.hidePIDSlider();
4955 * If there is a frame linked to this one in a SplitPane, switch it to the
4956 * same view tab index. No infinite recursion of calls should happen, since
4957 * tabSelectionChanged() should not get invoked on setting the selected
4958 * index to an unchanged value. Guard against setting an invalid index
4959 * before the new view peer tab has been created.
4961 final AlignViewportI peer = viewport.getCodingComplement();
4964 AlignFrame linkedAlignFrame = ((AlignViewport) peer)
4965 .getAlignPanel().alignFrame;
4966 if (linkedAlignFrame.tabbedPane.getTabCount() > index)
4968 linkedAlignFrame.tabbedPane.setSelectedIndex(index);
4974 * On right mouse click on view tab, prompt for and set new view name.
4977 public void tabbedPane_mousePressed(MouseEvent e)
4979 if (e.isPopupTrigger())
4981 String msg = MessageManager.getString("label.enter_view_name");
4982 String reply = JvOptionPane.showInternalInputDialog(this, msg, msg,
4983 JvOptionPane.QUESTION_MESSAGE);
4987 viewport.viewName = reply;
4988 // TODO warn if reply is in getExistingViewNames()?
4989 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4994 public AlignViewport getCurrentView()
5000 * Open the dialog for regex description parsing.
5003 protected void extractScores_actionPerformed(ActionEvent e)
5005 ParseProperties pp = new jalview.analysis.ParseProperties(
5006 viewport.getAlignment());
5007 // TODO: verify regex and introduce GUI dialog for version 2.5
5008 // if (pp.getScoresFromDescription("col", "score column ",
5009 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5011 if (pp.getScoresFromDescription("description column",
5012 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5014 buildSortByAnnotationScoresMenu();
5022 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5026 protected void showDbRefs_actionPerformed(ActionEvent e)
5028 viewport.setShowDBRefs(showDbRefsMenuitem.isSelected());
5034 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5038 protected void showNpFeats_actionPerformed(ActionEvent e)
5040 viewport.setShowNPFeats(showNpFeatsMenuitem.isSelected());
5044 * find the viewport amongst the tabs in this alignment frame and close that
5049 public boolean closeView(AlignViewportI av)
5053 this.closeMenuItem_actionPerformed(false);
5056 Component[] comp = tabbedPane.getComponents();
5057 for (int i = 0; comp != null && i < comp.length; i++)
5059 if (comp[i] instanceof AlignmentPanel)
5061 if (((AlignmentPanel) comp[i]).av == av)
5064 closeView((AlignmentPanel) comp[i]);
5072 protected void build_fetchdbmenu(JMenu webService)
5074 // Temporary hack - DBRef Fetcher always top level ws entry.
5075 // TODO We probably want to store a sequence database checklist in
5076 // preferences and have checkboxes.. rather than individual sources selected
5078 final JMenu rfetch = new JMenu(
5079 MessageManager.getString("action.fetch_db_references"));
5080 rfetch.setToolTipText(MessageManager.getString(
5081 "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
5082 webService.add(rfetch);
5084 final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem(
5085 MessageManager.getString("option.trim_retrieved_seqs"));
5086 trimrs.setToolTipText(
5087 MessageManager.getString("label.trim_retrieved_sequences"));
5089 Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true));
5090 trimrs.addActionListener(new ActionListener()
5093 public void actionPerformed(ActionEvent e)
5095 trimrs.setSelected(trimrs.isSelected());
5096 Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES,
5097 Boolean.valueOf(trimrs.isSelected()).toString());
5101 JMenuItem fetchr = new JMenuItem(
5102 MessageManager.getString("label.standard_databases"));
5103 fetchr.setToolTipText(
5104 MessageManager.getString("label.fetch_embl_uniprot"));
5105 fetchr.addActionListener(new ActionListener()
5109 public void actionPerformed(ActionEvent e)
5111 new Thread(new Runnable()
5116 boolean isNucleotide = alignPanel.alignFrame.getViewport()
5117 .getAlignment().isNucleotide();
5118 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5119 alignPanel.av.getSequenceSelection(),
5120 alignPanel.alignFrame, null,
5121 alignPanel.alignFrame.featureSettings, isNucleotide);
5122 dbRefFetcher.addListener(new FetchFinishedListenerI()
5125 public void finished()
5127 AlignFrame.this.setMenusForViewport();
5130 dbRefFetcher.fetchDBRefs(false);
5138 final AlignFrame me = this;
5139 new Thread(new Runnable()
5144 final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
5145 .getSequenceFetcherSingleton(me);
5146 javax.swing.SwingUtilities.invokeLater(new Runnable()
5151 String[] dbclasses = sf.getOrderedSupportedSources();
5152 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5153 // jalview.util.QuickSort.sort(otherdb, otherdb);
5154 List<DbSourceProxy> otherdb;
5155 JMenu dfetch = new JMenu();
5156 JMenu ifetch = new JMenu();
5157 JMenuItem fetchr = null;
5158 int comp = 0, icomp = 0, mcomp = 15;
5159 String mname = null;
5161 for (String dbclass : dbclasses)
5163 otherdb = sf.getSourceProxy(dbclass);
5164 // add a single entry for this class, or submenu allowing 'fetch
5166 if (otherdb == null || otherdb.size() < 1)
5170 // List<DbSourceProxy> dbs=otherdb;
5171 // otherdb=new ArrayList<DbSourceProxy>();
5172 // for (DbSourceProxy db:dbs)
5174 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5178 mname = "From " + dbclass;
5180 if (otherdb.size() == 1)
5182 final DbSourceProxy[] dassource = otherdb
5183 .toArray(new DbSourceProxy[0]);
5184 DbSourceProxy src = otherdb.get(0);
5185 fetchr = new JMenuItem(src.getDbSource());
5186 fetchr.addActionListener(new ActionListener()
5190 public void actionPerformed(ActionEvent e)
5192 new Thread(new Runnable()
5198 boolean isNucleotide = alignPanel.alignFrame
5199 .getViewport().getAlignment()
5201 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5202 alignPanel.av.getSequenceSelection(),
5203 alignPanel.alignFrame, dassource,
5204 alignPanel.alignFrame.featureSettings,
5207 .addListener(new FetchFinishedListenerI()
5210 public void finished()
5212 AlignFrame.this.setMenusForViewport();
5215 dbRefFetcher.fetchDBRefs(false);
5221 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5222 MessageManager.formatMessage(
5223 "label.fetch_retrieve_from", new Object[]
5224 { src.getDbName() })));
5230 final DbSourceProxy[] dassource = otherdb
5231 .toArray(new DbSourceProxy[0]);
5233 DbSourceProxy src = otherdb.get(0);
5234 fetchr = new JMenuItem(MessageManager
5235 .formatMessage("label.fetch_all_param", new Object[]
5236 { src.getDbSource() }));
5237 fetchr.addActionListener(new ActionListener()
5240 public void actionPerformed(ActionEvent e)
5242 new Thread(new Runnable()
5248 boolean isNucleotide = alignPanel.alignFrame
5249 .getViewport().getAlignment()
5251 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5252 alignPanel.av.getSequenceSelection(),
5253 alignPanel.alignFrame, dassource,
5254 alignPanel.alignFrame.featureSettings,
5257 .addListener(new FetchFinishedListenerI()
5260 public void finished()
5262 AlignFrame.this.setMenusForViewport();
5265 dbRefFetcher.fetchDBRefs(false);
5271 fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true,
5272 MessageManager.formatMessage(
5273 "label.fetch_retrieve_from_all_sources",
5275 { Integer.valueOf(otherdb.size())
5277 src.getDbSource(), src.getDbName() })));
5280 // and then build the rest of the individual menus
5281 ifetch = new JMenu(MessageManager.formatMessage(
5282 "label.source_from_db_source", new Object[]
5283 { src.getDbSource() }));
5285 String imname = null;
5287 for (DbSourceProxy sproxy : otherdb)
5289 String dbname = sproxy.getDbName();
5290 String sname = dbname.length() > 5
5291 ? dbname.substring(0, 5) + "..."
5293 String msname = dbname.length() > 10
5294 ? dbname.substring(0, 10) + "..."
5298 imname = MessageManager
5299 .formatMessage("label.from_msname", new Object[]
5302 fetchr = new JMenuItem(msname);
5303 final DbSourceProxy[] dassrc = { sproxy };
5304 fetchr.addActionListener(new ActionListener()
5308 public void actionPerformed(ActionEvent e)
5310 new Thread(new Runnable()
5316 boolean isNucleotide = alignPanel.alignFrame
5317 .getViewport().getAlignment()
5319 DBRefFetcher dbRefFetcher = new DBRefFetcher(
5320 alignPanel.av.getSequenceSelection(),
5321 alignPanel.alignFrame, dassrc,
5322 alignPanel.alignFrame.featureSettings,
5325 .addListener(new FetchFinishedListenerI()
5328 public void finished()
5330 AlignFrame.this.setMenusForViewport();
5333 dbRefFetcher.fetchDBRefs(false);
5339 fetchr.setToolTipText(
5340 "<html>" + MessageManager.formatMessage(
5341 "label.fetch_retrieve_from", new Object[]
5345 if (++icomp >= mcomp || i == (otherdb.size()))
5347 ifetch.setText(MessageManager.formatMessage(
5348 "label.source_to_target", imname, sname));
5350 ifetch = new JMenu();
5358 if (comp >= mcomp || dbi >= (dbclasses.length))
5360 dfetch.setText(MessageManager.formatMessage(
5361 "label.source_to_target", mname, dbclass));
5363 dfetch = new JMenu();
5376 * Left justify the whole alignment.
5379 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5381 AlignmentI al = viewport.getAlignment();
5383 viewport.firePropertyChange("alignment", null, al);
5387 * Right justify the whole alignment.
5390 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5392 AlignmentI al = viewport.getAlignment();
5394 viewport.firePropertyChange("alignment", null, al);
5398 public void setShowSeqFeatures(boolean b)
5400 showSeqFeatures.setSelected(b);
5401 viewport.setShowSequenceFeatures(b);
5408 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5409 * awt.event.ActionEvent)
5412 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5414 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5415 alignPanel.paintAlignment(false, false);
5422 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5426 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5428 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5429 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5437 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5438 * .event.ActionEvent)
5441 protected void showGroupConservation_actionPerformed(ActionEvent e)
5443 viewport.setShowGroupConservation(showGroupConservation.getState());
5444 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5451 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5452 * .event.ActionEvent)
5455 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5457 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5458 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5465 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5466 * .event.ActionEvent)
5469 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5471 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5472 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5476 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5478 showSequenceLogo.setState(true);
5479 viewport.setShowSequenceLogo(true);
5480 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5481 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5485 protected void showInformationHistogram_actionPerformed(ActionEvent e)
5487 viewport.setShowInformationHistogram(
5488 showInformationHistogram.getState());
5489 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5493 protected void showHMMSequenceLogo_actionPerformed(ActionEvent e)
5495 viewport.setShowHMMSequenceLogo(showHMMSequenceLogo.getState());
5496 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5500 protected void normaliseHMMSequenceLogo_actionPerformed(ActionEvent e)
5502 showHMMSequenceLogo.setState(true);
5503 viewport.setShowHMMSequenceLogo(true);
5504 viewport.setNormaliseHMMSequenceLogo(normaliseSequenceLogo.getState());
5505 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5509 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5511 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5518 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5519 * .event.ActionEvent)
5522 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5524 if (avc.makeGroupsFromSelection())
5526 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5527 alignPanel.updateAnnotation();
5528 alignPanel.paintAlignment(true, true);
5532 public void clearAlignmentSeqRep()
5534 // TODO refactor alignmentseqrep to controller
5535 if (viewport.getAlignment().hasSeqrep())
5537 viewport.getAlignment().setSeqrep(null);
5538 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5539 alignPanel.updateAnnotation();
5540 alignPanel.paintAlignment(true, true);
5545 protected void createGroup_actionPerformed(ActionEvent e)
5547 if (avc.createGroup())
5549 alignPanel.alignmentChanged();
5554 protected void unGroup_actionPerformed(ActionEvent e)
5558 alignPanel.alignmentChanged();
5563 * make the given alignmentPanel the currently selected tab
5565 * @param alignmentPanel
5567 public void setDisplayedView(AlignmentPanel alignmentPanel)
5569 if (!viewport.getSequenceSetId()
5570 .equals(alignmentPanel.av.getSequenceSetId()))
5572 throw new Error(MessageManager.getString(
5573 "error.implementation_error_cannot_show_view_alignment_frame"));
5575 if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels
5576 .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5578 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5583 * Action on selection of menu options to Show or Hide annotations.
5586 * @param forSequences
5587 * update sequence-related annotations
5588 * @param forAlignment
5589 * update non-sequence-related annotations
5592 protected void setAnnotationsVisibility(boolean visible,
5593 boolean forSequences, boolean forAlignment)
5595 AlignmentAnnotation[] anns = alignPanel.getAlignment()
5596 .getAlignmentAnnotation();
5601 for (AlignmentAnnotation aa : anns)
5604 * don't display non-positional annotations on an alignment
5606 if (aa.annotations == null)
5610 boolean apply = (aa.sequenceRef == null && forAlignment)
5611 || (aa.sequenceRef != null && forSequences);
5614 aa.visible = visible;
5617 alignPanel.validateAnnotationDimensions(true);
5618 alignPanel.alignmentChanged();
5622 * Store selected annotation sort order for the view and repaint.
5625 protected void sortAnnotations_actionPerformed()
5627 this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
5629 .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
5630 alignPanel.paintAlignment(false, false);
5635 * @return alignment panels in this alignment frame
5637 public List<? extends AlignmentViewPanel> getAlignPanels()
5639 return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels;
5643 * Open a new alignment window, with the cDNA associated with this (protein)
5644 * alignment, aligned as is the protein.
5646 protected void viewAsCdna_actionPerformed()
5648 // TODO no longer a menu action - refactor as required
5649 final AlignmentI alignment = getViewport().getAlignment();
5650 List<AlignedCodonFrame> mappings = alignment.getCodonFrames();
5651 if (mappings == null)
5655 List<SequenceI> cdnaSeqs = new ArrayList<>();
5656 for (SequenceI aaSeq : alignment.getSequences())
5658 for (AlignedCodonFrame acf : mappings)
5660 SequenceI dnaSeq = acf.getDnaForAaSeq(aaSeq.getDatasetSequence());
5664 * There is a cDNA mapping for this protein sequence - add to new
5665 * alignment. It will share the same dataset sequence as other mapped
5666 * cDNA (no new mappings need to be created).
5668 final Sequence newSeq = new Sequence(dnaSeq);
5669 newSeq.setDatasetSequence(dnaSeq);
5670 cdnaSeqs.add(newSeq);
5674 if (cdnaSeqs.size() == 0)
5676 // show a warning dialog no mapped cDNA
5679 AlignmentI cdna = new Alignment(
5680 cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()]));
5681 GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH,
5682 AlignFrame.DEFAULT_HEIGHT);
5683 cdna.alignAs(alignment);
5684 String newtitle = "cDNA " + MessageManager.getString("label.for") + " "
5686 Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH,
5687 AlignFrame.DEFAULT_HEIGHT);
5691 * Set visibility of dna/protein complement view (available when shown in a
5697 protected void showComplement_actionPerformed(boolean show)
5699 SplitContainerI sf = getSplitViewContainer();
5702 sf.setComplementVisible(this, show);
5707 * Generate the reverse (optionally complemented) of the selected sequences,
5708 * and add them to the alignment
5711 protected void showReverse_actionPerformed(boolean complement)
5713 AlignmentI al = null;
5716 Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true));
5717 al = dna.reverseCdna(complement);
5718 viewport.addAlignment(al, "");
5719 addHistoryItem(new EditCommand(
5720 MessageManager.getString("label.add_sequences"), Action.PASTE,
5721 al.getSequencesArray(), 0, al.getWidth(),
5722 viewport.getAlignment()));
5723 } catch (Exception ex)
5725 System.err.println(ex.getMessage());
5731 * Try to run a script in the Groovy console, having first ensured that this
5732 * AlignFrame is set as currentAlignFrame in Desktop, to allow the script to
5733 * be targeted at this alignment.
5736 protected void runGroovy_actionPerformed()
5738 Jalview.setCurrentAlignFrame(this);
5739 groovy.ui.Console console = Desktop.getGroovyConsole();
5740 if (console != null)
5744 console.runScript();
5745 } catch (Exception ex)
5747 System.err.println((ex.toString()));
5748 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
5749 MessageManager.getString("label.couldnt_run_groovy_script"),
5750 MessageManager.getString("label.groovy_support_failed"),
5751 JvOptionPane.ERROR_MESSAGE);
5756 System.err.println("Can't run Groovy script as console not found");
5761 * Hides columns containing (or not containing) a specified feature, provided
5762 * that would not leave all columns hidden
5764 * @param featureType
5765 * @param columnsContaining
5768 public boolean hideFeatureColumns(String featureType,
5769 boolean columnsContaining)
5771 boolean notForHiding = avc.markColumnsContainingFeatures(
5772 columnsContaining, false, false, featureType);
5775 if (avc.markColumnsContainingFeatures(!columnsContaining, false,
5776 false, featureType))
5778 getViewport().hideSelectedColumns();
5786 protected void selectHighlightedColumns_actionPerformed(
5787 ActionEvent actionEvent)
5789 // include key modifier check in case user selects from menu
5790 avc.markHighlightedColumns(
5791 (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true,
5792 (actionEvent.getModifiers() & (ActionEvent.META_MASK
5793 | ActionEvent.CTRL_MASK)) != 0);
5797 * Rebuilds the Colour menu, including any user-defined colours which have
5798 * been loaded either on startup or during the session
5800 public void buildColourMenu()
5802 colourMenu.removeAll();
5804 colourMenu.add(applyToAllGroups);
5805 colourMenu.add(textColour);
5806 colourMenu.addSeparator();
5808 ColourMenuHelper.addMenuItems(colourMenu, this, viewport.getAlignment(),
5811 colourMenu.addSeparator();
5812 colourMenu.add(conservationMenuItem);
5813 colourMenu.add(modifyConservation);
5814 colourMenu.add(abovePIDThreshold);
5815 colourMenu.add(modifyPID);
5816 colourMenu.add(annotationColour);
5818 ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
5819 ColourMenuHelper.setColourSelected(colourMenu, colourScheme);
5823 * Open a dialog (if not already open) that allows the user to select and
5824 * calculate PCA or Tree analysis
5826 protected void openTreePcaDialog()
5828 if (alignPanel.getCalculationDialog() == null)
5830 new CalculationChooser(AlignFrame.this);
5835 * Sets the status of the HMMER menu
5837 public void updateHMMERStatus()
5839 hmmerMenu.setEnabled(HmmerCommand.isHmmerAvailable());
5843 * Returns the selected hidden Markov model.
5847 public HiddenMarkovModel getSelectedHMM()
5849 if (selectedHMMSequence == null)
5853 return selectedHMMSequence.getHMM();
5857 * Returns the selected hidden Markov model.
5861 public SequenceI getSelectedHMMSequence()
5863 return selectedHMMSequence;
5867 * Sets the selected hidden Markov model
5869 * @param selectedHMM
5871 public void setSelectedHMMSequence(SequenceI selectedHMM)
5873 this.selectedHMMSequence = selectedHMM;
5874 hmmAlign.setText(MessageManager.getString("label.hmmalign") + " to "
5875 + selectedHMM.getHMM().getName());
5876 hmmSearch.setText(MessageManager.getString("label.hmmsearch") + " with "
5877 + selectedHMM.getHMM().getName());
5881 public void hmmerMenu_actionPerformed(ActionEvent e)
5883 SequenceGroup grp = getViewport().getSelectionGroup();
5886 hmmBuild.setText(MessageManager.getString("label.hmmbuild") + " from "
5891 hmmBuild.setText(MessageManager.getString("label.hmmbuild")
5892 + " from Alignment");
5897 protected void loadVcf_actionPerformed()
5899 JalviewFileChooser chooser = new JalviewFileChooser(
5900 Cache.getProperty("LAST_DIRECTORY"));
5901 chooser.setFileView(new JalviewFileView());
5902 chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file"));
5903 chooser.setToolTipText(MessageManager.getString("label.load_vcf_file"));
5905 int value = chooser.showOpenDialog(null);
5907 if (value == JalviewFileChooser.APPROVE_OPTION)
5909 String choice = chooser.getSelectedFile().getPath();
5910 Cache.setProperty("LAST_DIRECTORY", choice);
5911 SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
5912 new VCFLoader(choice).loadVCF(seqs, this);
5918 class PrintThread extends Thread
5922 public PrintThread(AlignmentPanel ap)
5927 static PageFormat pf;
5932 PrinterJob printJob = PrinterJob.getPrinterJob();
5936 printJob.setPrintable(ap, pf);
5940 printJob.setPrintable(ap);
5943 if (printJob.printDialog())
5948 } catch (Exception PrintException)
5950 PrintException.printStackTrace();