2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.analysis.AAFrequency;
22 import jalview.analysis.AlignmentSorter;
23 import jalview.analysis.Conservation;
24 import jalview.analysis.CrossRef;
25 import jalview.analysis.NJTree;
26 import jalview.analysis.ParseProperties;
27 import jalview.analysis.SequenceIdMatcher;
28 import jalview.api.AlignViewControllerGuiI;
29 import jalview.api.AlignViewControllerI;
30 import jalview.bin.Cache;
31 import jalview.commands.CommandI;
32 import jalview.commands.EditCommand;
33 import jalview.commands.OrderCommand;
34 import jalview.commands.RemoveGapColCommand;
35 import jalview.commands.RemoveGapsCommand;
36 import jalview.commands.SlideSequencesCommand;
37 import jalview.commands.TrimRegionCommand;
38 import jalview.datamodel.AlignedCodonFrame;
39 import jalview.datamodel.Alignment;
40 import jalview.datamodel.AlignmentAnnotation;
41 import jalview.datamodel.AlignmentI;
42 import jalview.datamodel.AlignmentOrder;
43 import jalview.datamodel.AlignmentView;
44 import jalview.datamodel.ColumnSelection;
45 import jalview.datamodel.PDBEntry;
46 import jalview.datamodel.SeqCigar;
47 import jalview.datamodel.Sequence;
48 import jalview.datamodel.SequenceGroup;
49 import jalview.datamodel.SequenceI;
50 import jalview.io.AlignmentProperties;
51 import jalview.io.AnnotationFile;
52 import jalview.io.FeaturesFile;
53 import jalview.io.FileLoader;
54 import jalview.io.FormatAdapter;
55 import jalview.io.HTMLOutput;
56 import jalview.io.IdentifyFile;
57 import jalview.io.JalviewFileChooser;
58 import jalview.io.JalviewFileView;
59 import jalview.io.JnetAnnotationMaker;
60 import jalview.io.NewickFile;
61 import jalview.io.TCoffeeScoreFile;
62 import jalview.jbgui.GAlignFrame;
63 import jalview.schemes.Blosum62ColourScheme;
64 import jalview.schemes.BuriedColourScheme;
65 import jalview.schemes.ClustalxColourScheme;
66 import jalview.schemes.ColourSchemeI;
67 import jalview.schemes.ColourSchemeProperty;
68 import jalview.schemes.HelixColourScheme;
69 import jalview.schemes.HydrophobicColourScheme;
70 import jalview.schemes.NucleotideColourScheme;
71 import jalview.schemes.PIDColourScheme;
72 import jalview.schemes.PurinePyrimidineColourScheme;
73 import jalview.schemes.RNAHelicesColourChooser;
74 import jalview.schemes.ResidueProperties;
75 import jalview.schemes.ScoreMatrix;
76 import jalview.schemes.StrandColourScheme;
77 import jalview.schemes.TCoffeeColourScheme;
78 import jalview.schemes.TaylorColourScheme;
79 import jalview.schemes.TurnColourScheme;
80 import jalview.schemes.UserColourScheme;
81 import jalview.schemes.ZappoColourScheme;
82 import jalview.util.MessageManager;
83 import jalview.ws.jws1.Discoverer;
84 import jalview.ws.jws2.Jws2Discoverer;
85 import jalview.ws.jws2.jabaws2.Jws2Instance;
86 import jalview.ws.seqfetcher.DbSourceProxy;
88 import java.awt.BorderLayout;
89 import java.awt.Color;
90 import java.awt.Component;
91 import java.awt.GridLayout;
92 import java.awt.Rectangle;
93 import java.awt.Toolkit;
94 import java.awt.datatransfer.Clipboard;
95 import java.awt.datatransfer.DataFlavor;
96 import java.awt.datatransfer.StringSelection;
97 import java.awt.datatransfer.Transferable;
98 import java.awt.dnd.DnDConstants;
99 import java.awt.dnd.DropTargetDragEvent;
100 import java.awt.dnd.DropTargetDropEvent;
101 import java.awt.dnd.DropTargetEvent;
102 import java.awt.dnd.DropTargetListener;
103 import java.awt.event.ActionEvent;
104 import java.awt.event.ActionListener;
105 import java.awt.event.KeyAdapter;
106 import java.awt.event.KeyEvent;
107 import java.awt.event.MouseAdapter;
108 import java.awt.event.MouseEvent;
109 import java.awt.print.PageFormat;
110 import java.awt.print.PrinterJob;
111 import java.beans.PropertyChangeEvent;
114 import java.util.ArrayList;
115 import java.util.Enumeration;
116 import java.util.Hashtable;
117 import java.util.List;
118 import java.util.Vector;
120 import javax.swing.JButton;
121 import javax.swing.JEditorPane;
122 import javax.swing.JInternalFrame;
123 import javax.swing.JLabel;
124 import javax.swing.JLayeredPane;
125 import javax.swing.JMenu;
126 import javax.swing.JMenuItem;
127 import javax.swing.JOptionPane;
128 import javax.swing.JPanel;
129 import javax.swing.JProgressBar;
130 import javax.swing.JRadioButtonMenuItem;
131 import javax.swing.JScrollPane;
132 import javax.swing.SwingUtilities;
138 * @version $Revision$
140 public class AlignFrame extends GAlignFrame implements DropTargetListener,
141 IProgressIndicator, AlignViewControllerGuiI
145 public static final int DEFAULT_WIDTH = 700;
148 public static final int DEFAULT_HEIGHT = 500;
150 public AlignmentPanel alignPanel;
152 AlignViewport viewport;
154 public AlignViewControllerI avc;
157 Vector alignPanels = new Vector();
160 * Last format used to load or save alignments in this window
162 String currentFileFormat = null;
165 * Current filename for this alignment
167 String fileName = null;
170 * Creates a new AlignFrame object with specific width and height.
176 public AlignFrame(AlignmentI al, int width, int height)
178 this(al, null, width, height);
182 * Creates a new AlignFrame object with specific width, height and
188 * @param sequenceSetId
190 public AlignFrame(AlignmentI al, int width, int height,
191 String sequenceSetId)
193 this(al, null, width, height, sequenceSetId);
197 * Creates a new AlignFrame object with specific width, height and
203 * @param sequenceSetId
206 public AlignFrame(AlignmentI al, int width, int height,
207 String sequenceSetId, String viewId)
209 this(al, null, width, height, sequenceSetId, viewId);
213 * new alignment window with hidden columns
217 * @param hiddenColumns
218 * ColumnSelection or null
220 * Width of alignment frame
224 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
225 int width, int height)
227 this(al, hiddenColumns, width, height, null);
231 * Create alignment frame for al with hiddenColumns, a specific width and
232 * height, and specific sequenceId
235 * @param hiddenColumns
238 * @param sequenceSetId
241 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
242 int width, int height, String sequenceSetId)
244 this(al, hiddenColumns, width, height, sequenceSetId, null);
248 * Create alignment frame for al with hiddenColumns, a specific width and
249 * height, and specific sequenceId
252 * @param hiddenColumns
255 * @param sequenceSetId
260 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
261 int width, int height, String sequenceSetId, String viewId)
263 setSize(width, height);
264 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
266 alignPanel = new AlignmentPanel(this, viewport);
268 if (al.getDataset() == null)
273 addAlignmentPanel(alignPanel, true);
278 * Make a new AlignFrame from exisiting alignmentPanels
285 public AlignFrame(AlignmentPanel ap)
289 addAlignmentPanel(ap, false);
294 * initalise the alignframe from the underlying viewport data and the
299 avc = new jalview.controller.AlignViewController(this, viewport, alignPanel);
300 if (viewport.getAlignmentConservationAnnotation() == null)
302 BLOSUM62Colour.setEnabled(false);
303 conservationMenuItem.setEnabled(false);
304 modifyConservation.setEnabled(false);
305 // PIDColour.setEnabled(false);
306 // abovePIDThreshold.setEnabled(false);
307 // modifyPID.setEnabled(false);
310 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
313 if (sortby.equals("Id"))
315 sortIDMenuItem_actionPerformed(null);
317 else if (sortby.equals("Pairwise Identity"))
319 sortPairwiseMenuItem_actionPerformed(null);
322 if (Desktop.desktop != null)
324 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
325 addServiceListeners();
326 setGUINucleotide(viewport.getAlignment().isNucleotide());
329 setMenusFromViewport(viewport);
330 buildSortByAnnotationScoresMenu();
332 if (viewport.wrapAlignment)
334 wrapMenuItem_actionPerformed(null);
337 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
339 this.overviewMenuItem_actionPerformed(null);
347 * Change the filename and format for the alignment, and enable the 'reload'
348 * button functionality.
355 public void setFileName(String file, String format)
358 currentFileFormat = format;
359 reload.setEnabled(true);
362 void addKeyListener()
364 addKeyListener(new KeyAdapter()
367 public void keyPressed(KeyEvent evt)
369 if (viewport.cursorMode
370 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
371 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
372 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
373 && Character.isDigit(evt.getKeyChar()))
374 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
376 switch (evt.getKeyCode())
379 case 27: // escape key
380 deselectAllSequenceMenuItem_actionPerformed(null);
384 case KeyEvent.VK_DOWN:
385 if (evt.isAltDown() || !viewport.cursorMode)
386 moveSelectedSequences(false);
387 if (viewport.cursorMode)
388 alignPanel.seqPanel.moveCursor(0, 1);
392 if (evt.isAltDown() || !viewport.cursorMode)
393 moveSelectedSequences(true);
394 if (viewport.cursorMode)
395 alignPanel.seqPanel.moveCursor(0, -1);
399 case KeyEvent.VK_LEFT:
400 if (evt.isAltDown() || !viewport.cursorMode)
401 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
403 alignPanel.seqPanel.moveCursor(-1, 0);
407 case KeyEvent.VK_RIGHT:
408 if (evt.isAltDown() || !viewport.cursorMode)
409 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
411 alignPanel.seqPanel.moveCursor(1, 0);
414 case KeyEvent.VK_SPACE:
415 if (viewport.cursorMode)
417 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
418 || evt.isShiftDown() || evt.isAltDown());
422 // case KeyEvent.VK_A:
423 // if (viewport.cursorMode)
425 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
426 // //System.out.println("A");
430 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
431 * System.out.println("closing bracket"); } break;
433 case KeyEvent.VK_DELETE:
434 case KeyEvent.VK_BACK_SPACE:
435 if (!viewport.cursorMode)
437 cut_actionPerformed(null);
441 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
442 || evt.isShiftDown() || evt.isAltDown());
448 if (viewport.cursorMode)
450 alignPanel.seqPanel.setCursorRow();
454 if (viewport.cursorMode && !evt.isControlDown())
456 alignPanel.seqPanel.setCursorColumn();
460 if (viewport.cursorMode)
462 alignPanel.seqPanel.setCursorPosition();
466 case KeyEvent.VK_ENTER:
467 case KeyEvent.VK_COMMA:
468 if (viewport.cursorMode)
470 alignPanel.seqPanel.setCursorRowAndColumn();
475 if (viewport.cursorMode)
477 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
481 if (viewport.cursorMode)
483 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
488 viewport.cursorMode = !viewport.cursorMode;
489 statusBar.setText(MessageManager.formatMessage("label.keyboard_editing_mode", new String[]{(viewport.cursorMode ? "on" : "off")}));
490 if (viewport.cursorMode)
492 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
493 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
495 alignPanel.seqPanel.seqCanvas.repaint();
501 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
502 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
504 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
506 javax.help.HelpBroker hb = hs.createHelpBroker();
507 hb.setCurrentID("home");
508 hb.setDisplayed(true);
509 } catch (Exception ex)
511 ex.printStackTrace();
516 boolean toggleSeqs = !evt.isControlDown();
517 boolean toggleCols = !evt.isShiftDown();
518 toggleHiddenRegions(toggleSeqs, toggleCols);
521 case KeyEvent.VK_PAGE_UP:
522 if (viewport.wrapAlignment)
524 alignPanel.scrollUp(true);
528 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
529 - viewport.endSeq + viewport.startSeq);
532 case KeyEvent.VK_PAGE_DOWN:
533 if (viewport.wrapAlignment)
535 alignPanel.scrollUp(false);
539 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
540 + viewport.endSeq - viewport.startSeq);
547 public void keyReleased(KeyEvent evt)
549 switch (evt.getKeyCode())
551 case KeyEvent.VK_LEFT:
552 if (evt.isAltDown() || !viewport.cursorMode)
553 viewport.firePropertyChange("alignment", null, viewport
554 .getAlignment().getSequences());
557 case KeyEvent.VK_RIGHT:
558 if (evt.isAltDown() || !viewport.cursorMode)
559 viewport.firePropertyChange("alignment", null, viewport
560 .getAlignment().getSequences());
567 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
569 ap.alignFrame = this;
570 avc = new jalview.controller.AlignViewController(this, viewport, alignPanel);
572 alignPanels.addElement(ap);
574 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
576 int aSize = alignPanels.size();
578 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
580 if (aSize == 1 && ap.av.viewName == null)
582 this.getContentPane().add(ap, BorderLayout.CENTER);
588 setInitialTabVisible();
591 expandViews.setEnabled(true);
592 gatherViews.setEnabled(true);
593 tabbedPane.addTab(ap.av.viewName, ap);
595 ap.setVisible(false);
600 if (ap.av.isPadGaps())
602 ap.av.getAlignment().padGaps();
604 ap.av.updateConservation(ap);
605 ap.av.updateConsensus(ap);
606 ap.av.updateStrucConsensus(ap);
610 public void setInitialTabVisible()
612 expandViews.setEnabled(true);
613 gatherViews.setEnabled(true);
614 tabbedPane.setVisible(true);
615 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
616 tabbedPane.addTab(first.av.viewName, first);
617 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
620 public AlignViewport getViewport()
625 /* Set up intrinsic listeners for dynamically generated GUI bits. */
626 private void addServiceListeners()
628 final java.beans.PropertyChangeListener thisListener;
629 Desktop.instance.addJalviewPropertyChangeListener("services",
630 thisListener = new java.beans.PropertyChangeListener()
633 public void propertyChange(PropertyChangeEvent evt)
635 // // System.out.println("Discoverer property change.");
636 // if (evt.getPropertyName().equals("services"))
638 SwingUtilities.invokeLater(new Runnable()
645 .println("Rebuild WS Menu for service change");
646 BuildWebServiceMenu();
653 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
656 public void internalFrameClosed(
657 javax.swing.event.InternalFrameEvent evt)
659 System.out.println("deregistering discoverer listener");
660 Desktop.instance.removeJalviewPropertyChangeListener("services",
662 closeMenuItem_actionPerformed(true);
665 // Finally, build the menu once to get current service state
666 new Thread(new Runnable()
671 BuildWebServiceMenu();
676 public void setGUINucleotide(boolean nucleotide)
678 showTranslation.setVisible(nucleotide);
679 conservationMenuItem.setEnabled(!nucleotide);
680 modifyConservation.setEnabled(!nucleotide);
681 showGroupConservation.setEnabled(!nucleotide);
682 rnahelicesColour.setEnabled(nucleotide);
683 purinePyrimidineColour.setEnabled(nucleotide);
684 // Remember AlignFrame always starts as protein
688 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
693 * set up menus for the currently viewport. This may be called after any
694 * operation that affects the data in the current view (selection changed,
695 * etc) to update the menus to reflect the new state.
697 public void setMenusForViewport()
699 setMenusFromViewport(viewport);
703 * Need to call this method when tabs are selected for multiple views, or when
704 * loading from Jalview2XML.java
709 void setMenusFromViewport(AlignViewport av)
711 padGapsMenuitem.setSelected(av.isPadGaps());
712 colourTextMenuItem.setSelected(av.showColourText);
713 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
714 conservationMenuItem.setSelected(av.getConservationSelected());
715 seqLimits.setSelected(av.getShowJVSuffix());
716 idRightAlign.setSelected(av.rightAlignIds);
717 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
718 renderGapsMenuItem.setSelected(av.renderGaps);
719 wrapMenuItem.setSelected(av.wrapAlignment);
720 scaleAbove.setVisible(av.wrapAlignment);
721 scaleLeft.setVisible(av.wrapAlignment);
722 scaleRight.setVisible(av.wrapAlignment);
723 annotationPanelMenuItem.setState(av.showAnnotation);
724 viewBoxesMenuItem.setSelected(av.showBoxes);
725 viewTextMenuItem.setSelected(av.showText);
726 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
727 showGroupConsensus.setSelected(av.isShowGroupConsensus());
728 showGroupConservation.setSelected(av.isShowGroupConservation());
729 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
730 showSequenceLogo.setSelected(av.isShowSequenceLogo());
731 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
733 setColourSelected(ColourSchemeProperty.getColourName(av
734 .getGlobalColourScheme()));
736 showSeqFeatures.setSelected(av.showSequenceFeatures);
737 hiddenMarkers.setState(av.showHiddenMarkers);
738 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
739 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
740 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
741 autoCalculate.setSelected(av.autoCalculateConsensus);
742 sortByTree.setSelected(av.sortByTree);
743 listenToViewSelections.setSelected(av.followSelection);
744 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
746 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
747 setShowProductsEnabled();
751 // methods for implementing IProgressIndicator
752 // need to refactor to a reusable stub class
753 Hashtable progressBars, progressBarHandlers;
758 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
761 public void setProgressBar(String message, long id)
763 if (progressBars == null)
765 progressBars = new Hashtable();
766 progressBarHandlers = new Hashtable();
769 JPanel progressPanel;
770 Long lId = new Long(id);
771 GridLayout layout = (GridLayout) statusPanel.getLayout();
772 if (progressBars.get(lId) != null)
774 progressPanel = (JPanel) progressBars.get(new Long(id));
775 statusPanel.remove(progressPanel);
776 progressBars.remove(lId);
777 progressPanel = null;
780 statusBar.setText(message);
782 if (progressBarHandlers.contains(lId))
784 progressBarHandlers.remove(lId);
786 layout.setRows(layout.getRows() - 1);
790 progressPanel = new JPanel(new BorderLayout(10, 5));
792 JProgressBar progressBar = new JProgressBar();
793 progressBar.setIndeterminate(true);
795 progressPanel.add(new JLabel(message), BorderLayout.WEST);
796 progressPanel.add(progressBar, BorderLayout.CENTER);
798 layout.setRows(layout.getRows() + 1);
799 statusPanel.add(progressPanel);
801 progressBars.put(lId, progressPanel);
804 // setMenusForViewport();
809 public void registerHandler(final long id,
810 final IProgressIndicatorHandler handler)
812 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
815 "call setProgressBar before registering the progress bar's handler.");
817 progressBarHandlers.put(new Long(id), handler);
818 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
819 if (handler.canCancel())
821 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
822 final IProgressIndicator us = this;
823 cancel.addActionListener(new ActionListener()
827 public void actionPerformed(ActionEvent e)
829 handler.cancelActivity(id);
832 + ((JLabel) progressPanel.getComponent(0))
836 progressPanel.add(cancel, BorderLayout.EAST);
842 * @return true if any progress bars are still active
845 public boolean operationInProgress()
847 if (progressBars != null && progressBars.size() > 0)
855 public void setStatus(String text) {
856 statusBar.setText(text);
859 * Added so Castor Mapping file can obtain Jalview Version
861 public String getVersion()
863 return jalview.bin.Cache.getProperty("VERSION");
866 public FeatureRenderer getFeatureRenderer()
868 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
872 public void fetchSequence_actionPerformed(ActionEvent e)
874 new SequenceFetcher(this);
878 public void addFromFile_actionPerformed(ActionEvent e)
880 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
884 public void reload_actionPerformed(ActionEvent e)
886 if (fileName != null)
888 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
889 // originating file's format
890 // TODO: work out how to recover feature settings for correct view(s) when
892 if (currentFileFormat.equals("Jalview"))
894 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
895 for (int i = 0; i < frames.length; i++)
897 if (frames[i] instanceof AlignFrame && frames[i] != this
898 && ((AlignFrame) frames[i]).fileName != null
899 && ((AlignFrame) frames[i]).fileName.equals(fileName))
903 frames[i].setSelected(true);
904 Desktop.instance.closeAssociatedWindows();
905 } catch (java.beans.PropertyVetoException ex)
911 Desktop.instance.closeAssociatedWindows();
913 FileLoader loader = new FileLoader();
914 String protocol = fileName.startsWith("http:") ? "URL" : "File";
915 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
919 Rectangle bounds = this.getBounds();
921 FileLoader loader = new FileLoader();
922 String protocol = fileName.startsWith("http:") ? "URL" : "File";
923 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
924 protocol, currentFileFormat);
926 newframe.setBounds(bounds);
927 if (featureSettings != null && featureSettings.isShowing())
929 final Rectangle fspos = featureSettings.frame.getBounds();
930 // TODO: need a 'show feature settings' function that takes bounds -
931 // need to refactor Desktop.addFrame
932 newframe.featureSettings_actionPerformed(null);
933 final FeatureSettings nfs = newframe.featureSettings;
934 SwingUtilities.invokeLater(new Runnable()
939 nfs.frame.setBounds(fspos);
942 this.featureSettings.close();
943 this.featureSettings = null;
945 this.closeMenuItem_actionPerformed(true);
951 public void addFromText_actionPerformed(ActionEvent e)
953 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
957 public void addFromURL_actionPerformed(ActionEvent e)
959 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
963 public void save_actionPerformed(ActionEvent e)
966 || (currentFileFormat == null || !jalview.io.FormatAdapter
967 .isValidIOFormat(currentFileFormat, true))
968 || fileName.startsWith("http"))
970 saveAs_actionPerformed(null);
974 saveAlignment(fileName, currentFileFormat);
985 public void saveAs_actionPerformed(ActionEvent e)
987 JalviewFileChooser chooser = new JalviewFileChooser(
988 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
989 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
990 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
991 currentFileFormat, false);
993 chooser.setFileView(new JalviewFileView());
994 chooser.setDialogTitle("Save Alignment to file");
995 chooser.setToolTipText(MessageManager.getString("action.save"));
\r
997 int value = chooser.showSaveDialog(this);
999 if (value == JalviewFileChooser.APPROVE_OPTION)
1001 currentFileFormat = chooser.getSelectedFormat();
1002 if (currentFileFormat == null)
1004 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1005 MessageManager.getString("label.select_file_format_before_saving"),
1006 MessageManager.getString("label.file_format_not_specified"), JOptionPane.WARNING_MESSAGE);
1007 value = chooser.showSaveDialog(this);
1011 fileName = chooser.getSelectedFile().getPath();
1013 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1016 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1017 if (currentFileFormat.indexOf(" ") > -1)
1019 currentFileFormat = currentFileFormat.substring(0,
1020 currentFileFormat.indexOf(" "));
1022 saveAlignment(fileName, currentFileFormat);
1026 public boolean saveAlignment(String file, String format)
1028 boolean success = true;
1030 if (format.equalsIgnoreCase("Jalview"))
1032 String shortName = title;
1034 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1036 shortName = shortName.substring(shortName
1037 .lastIndexOf(java.io.File.separatorChar) + 1);
1040 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1042 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1048 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1050 warningMessage("Cannot save file " + fileName + " using format "
1051 + format, "Alignment output format not supported");
1052 saveAs_actionPerformed(null);
1053 // JBPNote need to have a raise_gui flag here
1057 String[] omitHidden = null;
1059 if (viewport.hasHiddenColumns())
1061 int reply = JOptionPane
1062 .showInternalConfirmDialog(
1064 MessageManager.getString("label.alignment_contains_hidden_columns"),
1065 MessageManager.getString("action.save_omit_hidden_columns"),
1066 JOptionPane.YES_NO_OPTION,
1067 JOptionPane.QUESTION_MESSAGE);
1069 if (reply == JOptionPane.YES_OPTION)
1071 omitHidden = viewport.getViewAsString(false);
1074 FormatAdapter f = new FormatAdapter();
1075 String output = f.formatSequences(format,
1076 viewport.getAlignment(), // class cast exceptions will
1077 // occur in the distant future
1078 omitHidden, f.getCacheSuffixDefault(format),
1079 viewport.getColumnSelection());
1089 java.io.PrintWriter out = new java.io.PrintWriter(
1090 new java.io.FileWriter(file));
1094 this.setTitle(file);
1095 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1096 } catch (Exception ex)
1099 ex.printStackTrace();
1106 JOptionPane.showInternalMessageDialog(this, MessageManager.formatMessage("label.couldnt_save_file", new String[]{fileName}),
1107 MessageManager.getString("label.error_saving_file"), JOptionPane.WARNING_MESSAGE);
1113 private void warningMessage(String warning, String title)
1115 if (new jalview.util.Platform().isHeadless())
1117 System.err.println("Warning: " + title + "\nWarning: " + warning);
1122 JOptionPane.showInternalMessageDialog(this, warning, title,
1123 JOptionPane.WARNING_MESSAGE);
1135 protected void outputText_actionPerformed(ActionEvent e)
1137 String[] omitHidden = null;
1139 if (viewport.hasHiddenColumns())
1141 int reply = JOptionPane
1142 .showInternalConfirmDialog(
1144 MessageManager.getString("label.alignment_contains_hidden_columns"),
1145 MessageManager.getString("action.save_omit_hidden_columns"),
1146 JOptionPane.YES_NO_OPTION,
1147 JOptionPane.QUESTION_MESSAGE);
1149 if (reply == JOptionPane.YES_OPTION)
1151 omitHidden = viewport.getViewAsString(false);
1155 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1156 cap.setForInput(null);
1160 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1161 viewport.getAlignment(), omitHidden,
1162 viewport.getColumnSelection()));
1163 Desktop.addInternalFrame(cap,
1164 MessageManager.formatMessage("label.alignment_output_command", new String[]{e.getActionCommand()}), 600, 500);
\r
1165 } catch (OutOfMemoryError oom)
1167 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1180 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1182 new HTMLOutput(alignPanel,
1183 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1184 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1187 public void createImageMap(File file, String image)
1189 alignPanel.makePNGImageMap(file, image);
1199 public void createPNG(File f)
1201 alignPanel.makePNG(f);
1211 public void createEPS(File f)
1213 alignPanel.makeEPS(f);
1217 public void pageSetup_actionPerformed(ActionEvent e)
1219 PrinterJob printJob = PrinterJob.getPrinterJob();
1220 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1230 public void printMenuItem_actionPerformed(ActionEvent e)
1232 // Putting in a thread avoids Swing painting problems
1233 PrintThread thread = new PrintThread(alignPanel);
1238 public void exportFeatures_actionPerformed(ActionEvent e)
1240 new AnnotationExporter().exportFeatures(alignPanel);
1244 public void exportAnnotations_actionPerformed(ActionEvent e)
1246 new AnnotationExporter().exportAnnotations(alignPanel,
1247 viewport.showAnnotation ? viewport.getAlignment()
1248 .getAlignmentAnnotation() : null, viewport
1249 .getAlignment().getGroups(), ((Alignment) viewport
1250 .getAlignment()).alignmentProperties);
1254 public void associatedData_actionPerformed(ActionEvent e)
1256 // Pick the tree file
1257 JalviewFileChooser chooser = new JalviewFileChooser(
1258 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1259 chooser.setFileView(new JalviewFileView());
1260 chooser.setDialogTitle(MessageManager.getString("label.load_jalview_annotations"));
\r
1261 chooser.setToolTipText(MessageManager.getString("label.load_jalview_annotations"));
\r
1263 int value = chooser.showOpenDialog(null);
1265 if (value == JalviewFileChooser.APPROVE_OPTION)
1267 String choice = chooser.getSelectedFile().getPath();
1268 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1269 loadJalviewDataFile(choice, null, null, null);
1275 * Close the current view or all views in the alignment frame. If the frame
1276 * only contains one view then the alignment will be removed from memory.
1278 * @param closeAllTabs
1281 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1283 if (alignPanels != null && alignPanels.size() < 2)
1285 closeAllTabs = true;
1290 if (alignPanels != null)
1294 if (this.isClosed())
1296 // really close all the windows - otherwise wait till
1297 // setClosed(true) is called
1298 for (int i = 0; i < alignPanels.size(); i++)
1300 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1307 closeView(alignPanel);
1313 this.setClosed(true);
1315 } catch (Exception ex)
1317 ex.printStackTrace();
1322 * close alignPanel2 and shuffle tabs appropriately.
1324 * @param alignPanel2
1326 public void closeView(AlignmentPanel alignPanel2)
1328 int index = tabbedPane.getSelectedIndex();
1329 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1330 alignPanels.removeElement(alignPanel2);
1332 // if (viewport == alignPanel2.av)
1336 alignPanel2.closePanel();
1339 tabbedPane.removeTabAt(closedindex);
1340 tabbedPane.validate();
1342 if (index > closedindex || index == tabbedPane.getTabCount())
1344 // modify currently selected tab index if necessary.
1348 this.tabSelectionChanged(index);
1354 void updateEditMenuBar()
1357 if (viewport.historyList.size() > 0)
1359 undoMenuItem.setEnabled(true);
1360 CommandI command = (CommandI) viewport.historyList.peek();
1361 undoMenuItem.setText(MessageManager.formatMessage("label.undo_command", new String[]{command.getDescription()}));
1365 undoMenuItem.setEnabled(false);
1366 undoMenuItem.setText(MessageManager.getString("action.undo"));
1369 if (viewport.redoList.size() > 0)
1371 redoMenuItem.setEnabled(true);
1373 CommandI command = (CommandI) viewport.redoList.peek();
1374 redoMenuItem.setText(MessageManager.formatMessage("label.redo_command", new String[]{command.getDescription()}));
1378 redoMenuItem.setEnabled(false);
1379 redoMenuItem.setText(MessageManager.getString("action.redo"));
1383 public void addHistoryItem(CommandI command)
1385 if (command.getSize() > 0)
1387 viewport.historyList.push(command);
1388 viewport.redoList.clear();
1389 updateEditMenuBar();
1390 viewport.updateHiddenColumns();
1391 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1392 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1393 // viewport.getColumnSelection()
1394 // .getHiddenColumns().size() > 0);
1400 * @return alignment objects for all views
1402 AlignmentI[] getViewAlignments()
1404 if (alignPanels != null)
1406 Enumeration e = alignPanels.elements();
1407 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1408 for (int i = 0; e.hasMoreElements(); i++)
1410 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1414 if (viewport != null)
1416 return new AlignmentI[]
1417 { viewport.getAlignment() };
1429 protected void undoMenuItem_actionPerformed(ActionEvent e)
1431 if (viewport.historyList.empty())
1433 CommandI command = (CommandI) viewport.historyList.pop();
1434 viewport.redoList.push(command);
1435 command.undoCommand(getViewAlignments());
1437 AlignViewport originalSource = getOriginatingSource(command);
1438 updateEditMenuBar();
1440 if (originalSource != null)
1442 if (originalSource != viewport)
1445 .warn("Implementation worry: mismatch of viewport origin for undo");
1447 originalSource.updateHiddenColumns();
1448 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1450 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1451 // viewport.getColumnSelection()
1452 // .getHiddenColumns().size() > 0);
1453 originalSource.firePropertyChange("alignment", null, originalSource
1454 .getAlignment().getSequences());
1465 protected void redoMenuItem_actionPerformed(ActionEvent e)
1467 if (viewport.redoList.size() < 1)
1472 CommandI command = (CommandI) viewport.redoList.pop();
1473 viewport.historyList.push(command);
1474 command.doCommand(getViewAlignments());
1476 AlignViewport originalSource = getOriginatingSource(command);
1477 updateEditMenuBar();
1479 if (originalSource != null)
1482 if (originalSource != viewport)
1485 .warn("Implementation worry: mismatch of viewport origin for redo");
1487 originalSource.updateHiddenColumns();
1488 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1490 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1491 // viewport.getColumnSelection()
1492 // .getHiddenColumns().size() > 0);
1493 originalSource.firePropertyChange("alignment", null, originalSource
1494 .getAlignment().getSequences());
1498 AlignViewport getOriginatingSource(CommandI command)
1500 AlignViewport originalSource = null;
1501 // For sequence removal and addition, we need to fire
1502 // the property change event FROM the viewport where the
1503 // original alignment was altered
1504 AlignmentI al = null;
1505 if (command instanceof EditCommand)
1507 EditCommand editCommand = (EditCommand) command;
1508 al = editCommand.getAlignment();
1509 Vector comps = (Vector) PaintRefresher.components.get(viewport
1510 .getSequenceSetId());
1512 for (int i = 0; i < comps.size(); i++)
1514 if (comps.elementAt(i) instanceof AlignmentPanel)
1516 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1518 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1525 if (originalSource == null)
1527 // The original view is closed, we must validate
1528 // the current view against the closed view first
1531 PaintRefresher.validateSequences(al, viewport.getAlignment());
1534 originalSource = viewport;
1537 return originalSource;
1546 public void moveSelectedSequences(boolean up)
1548 SequenceGroup sg = viewport.getSelectionGroup();
1554 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1555 viewport.getHiddenRepSequences(), up);
1556 alignPanel.paintAlignment(true);
1559 synchronized void slideSequences(boolean right, int size)
1561 List<SequenceI> sg = new Vector();
1562 if (viewport.cursorMode)
1564 sg.add(viewport.getAlignment().getSequenceAt(
1565 alignPanel.seqPanel.seqCanvas.cursorY));
1567 else if (viewport.getSelectionGroup() != null
1568 && viewport.getSelectionGroup().getSize() != viewport
1569 .getAlignment().getHeight())
1571 sg = viewport.getSelectionGroup().getSequences(
1572 viewport.getHiddenRepSequences());
1580 Vector invertGroup = new Vector();
1582 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1584 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1585 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1588 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1590 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1591 for (int i = 0; i < invertGroup.size(); i++)
1592 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1594 SlideSequencesCommand ssc;
1596 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1597 size, viewport.getGapCharacter());
1599 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1600 size, viewport.getGapCharacter());
1602 int groupAdjustment = 0;
1603 if (ssc.getGapsInsertedBegin() && right)
1605 if (viewport.cursorMode)
1606 alignPanel.seqPanel.moveCursor(size, 0);
1608 groupAdjustment = size;
1610 else if (!ssc.getGapsInsertedBegin() && !right)
1612 if (viewport.cursorMode)
1613 alignPanel.seqPanel.moveCursor(-size, 0);
1615 groupAdjustment = -size;
1618 if (groupAdjustment != 0)
1620 viewport.getSelectionGroup().setStartRes(
1621 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1622 viewport.getSelectionGroup().setEndRes(
1623 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1626 boolean appendHistoryItem = false;
1627 if (viewport.historyList != null && viewport.historyList.size() > 0
1628 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1630 appendHistoryItem = ssc
1631 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1635 if (!appendHistoryItem)
1636 addHistoryItem(ssc);
1648 protected void copy_actionPerformed(ActionEvent e)
1651 if (viewport.getSelectionGroup() == null)
1655 // TODO: preserve the ordering of displayed alignment annotation in any
1656 // internal paste (particularly sequence associated annotation)
1657 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1658 String[] omitHidden = null;
1660 if (viewport.hasHiddenColumns())
1662 omitHidden = viewport.getViewAsString(true);
1665 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1668 StringSelection ss = new StringSelection(output);
1672 jalview.gui.Desktop.internalCopy = true;
1673 // Its really worth setting the clipboard contents
1674 // to empty before setting the large StringSelection!!
1675 Toolkit.getDefaultToolkit().getSystemClipboard()
1676 .setContents(new StringSelection(""), null);
1678 Toolkit.getDefaultToolkit().getSystemClipboard()
1679 .setContents(ss, Desktop.instance);
1680 } catch (OutOfMemoryError er)
1682 new OOMWarning("copying region", er);
1686 Vector hiddenColumns = null;
1687 if (viewport.hasHiddenColumns())
1689 hiddenColumns = new Vector();
1690 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1691 .getSelectionGroup().getEndRes();
1692 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1695 int[] region = (int[]) viewport.getColumnSelection()
1696 .getHiddenColumns().elementAt(i);
1697 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1699 hiddenColumns.addElement(new int[]
1700 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1705 Desktop.jalviewClipboard = new Object[]
1706 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1707 statusBar.setText(MessageManager.formatMessage("label.copied_sequences_to_clipboard", new String[]{Integer.valueOf(seqs.length).toString()}));
1717 protected void pasteNew_actionPerformed(ActionEvent e)
1729 protected void pasteThis_actionPerformed(ActionEvent e)
1735 * Paste contents of Jalview clipboard
1737 * @param newAlignment
1738 * true to paste to a new alignment, otherwise add to this.
1740 void paste(boolean newAlignment)
1742 boolean externalPaste = true;
1745 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1746 Transferable contents = c.getContents(this);
1748 if (contents == null)
1756 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1757 if (str.length() < 1)
1762 format = new IdentifyFile().Identify(str, "Paste");
1764 } catch (OutOfMemoryError er)
1766 new OOMWarning("Out of memory pasting sequences!!", er);
1770 SequenceI[] sequences;
1771 boolean annotationAdded = false;
1772 AlignmentI alignment = null;
1774 if (Desktop.jalviewClipboard != null)
1776 // The clipboard was filled from within Jalview, we must use the
1778 // And dataset from the copied alignment
1779 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1780 // be doubly sure that we create *new* sequence objects.
1781 sequences = new SequenceI[newseq.length];
1782 for (int i = 0; i < newseq.length; i++)
1784 sequences[i] = new Sequence(newseq[i]);
1786 alignment = new Alignment(sequences);
1787 externalPaste = false;
1791 // parse the clipboard as an alignment.
1792 alignment = new FormatAdapter().readFile(str, "Paste", format);
1793 sequences = alignment.getSequencesArray();
1797 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1803 if (Desktop.jalviewClipboard != null)
1805 // dataset is inherited
1806 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1810 // new dataset is constructed
1811 alignment.setDataset(null);
1813 alwidth = alignment.getWidth() + 1;
1817 AlignmentI pastedal = alignment; // preserve pasted alignment object
1818 // Add pasted sequences and dataset into existing alignment.
1819 alignment = viewport.getAlignment();
1820 alwidth = alignment.getWidth() + 1;
1821 // decide if we need to import sequences from an existing dataset
1822 boolean importDs = Desktop.jalviewClipboard != null
1823 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1824 // importDs==true instructs us to copy over new dataset sequences from
1825 // an existing alignment
1826 Vector newDs = (importDs) ? new Vector() : null; // used to create
1827 // minimum dataset set
1829 for (int i = 0; i < sequences.length; i++)
1833 newDs.addElement(null);
1835 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1837 if (importDs && ds != null)
1839 if (!newDs.contains(ds))
1841 newDs.setElementAt(ds, i);
1842 ds = new Sequence(ds);
1843 // update with new dataset sequence
1844 sequences[i].setDatasetSequence(ds);
1848 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1853 // copy and derive new dataset sequence
1854 sequences[i] = sequences[i].deriveSequence();
1855 alignment.getDataset().addSequence(
1856 sequences[i].getDatasetSequence());
1857 // TODO: avoid creation of duplicate dataset sequences with a
1858 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1860 alignment.addSequence(sequences[i]); // merges dataset
1864 newDs.clear(); // tidy up
1866 if (alignment.getAlignmentAnnotation() != null)
1868 for (AlignmentAnnotation alan : alignment
1869 .getAlignmentAnnotation())
1871 if (alan.graphGroup > fgroup)
1873 fgroup = alan.graphGroup;
1877 if (pastedal.getAlignmentAnnotation() != null)
1879 // Add any annotation attached to alignment.
1880 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1881 for (int i = 0; i < alann.length; i++)
1883 annotationAdded = true;
1884 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1886 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1887 if (newann.graphGroup > -1)
1889 if (newGraphGroups.size() <= newann.graphGroup
1890 || newGraphGroups.get(newann.graphGroup) == null)
1892 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1894 newGraphGroups.add(q, null);
1896 newGraphGroups.set(newann.graphGroup, new Integer(
1899 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1903 newann.padAnnotation(alwidth);
1904 alignment.addAnnotation(newann);
1914 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1915 sequences, 0, alignment.getWidth(), alignment));
1917 // Add any annotations attached to sequences
1918 for (int i = 0; i < sequences.length; i++)
1920 if (sequences[i].getAnnotation() != null)
1922 AlignmentAnnotation newann;
1923 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1925 annotationAdded = true;
1926 newann = sequences[i].getAnnotation()[a];
1927 newann.adjustForAlignment();
1928 newann.padAnnotation(alwidth);
1929 if (newann.graphGroup > -1)
1931 if (newann.graphGroup > -1)
1933 if (newGraphGroups.size() <= newann.graphGroup
1934 || newGraphGroups.get(newann.graphGroup) == null)
1936 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1938 newGraphGroups.add(q, null);
1940 newGraphGroups.set(newann.graphGroup, new Integer(
1943 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1947 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1952 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1959 // propagate alignment changed.
1960 viewport.setEndSeq(alignment.getHeight());
1961 if (annotationAdded)
1963 // Duplicate sequence annotation in all views.
1964 AlignmentI[] alview = this.getViewAlignments();
1965 for (int i = 0; i < sequences.length; i++)
1967 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1970 for (int avnum = 0; avnum < alview.length; avnum++)
1972 if (alview[avnum] != alignment)
1974 // duplicate in a view other than the one with input focus
1975 int avwidth = alview[avnum].getWidth() + 1;
1976 // this relies on sann being preserved after we
1977 // modify the sequence's annotation array for each duplication
1978 for (int a = 0; a < sann.length; a++)
1980 AlignmentAnnotation newann = new AlignmentAnnotation(
1982 sequences[i].addAlignmentAnnotation(newann);
1983 newann.padAnnotation(avwidth);
1984 alview[avnum].addAnnotation(newann); // annotation was
1985 // duplicated earlier
1986 // TODO JAL-1145 graphGroups are not updated for sequence
1987 // annotation added to several views. This may cause
1989 alview[avnum].setAnnotationIndex(newann, a);
1994 buildSortByAnnotationScoresMenu();
1996 viewport.firePropertyChange("alignment", null,
1997 alignment.getSequences());
1998 if (alignPanels != null)
2000 for (AlignmentPanel ap : ((Vector<AlignmentPanel>) alignPanels))
2002 ap.validateAnnotationDimensions(false);
2007 alignPanel.validateAnnotationDimensions(false);
2013 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2015 String newtitle = new String("Copied sequences");
2017 if (Desktop.jalviewClipboard != null
2018 && Desktop.jalviewClipboard[2] != null)
2020 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2021 for (int i = 0; i < hc.size(); i++)
2023 int[] region = (int[]) hc.elementAt(i);
2024 af.viewport.hideColumns(region[0], region[1]);
2028 // >>>This is a fix for the moment, until a better solution is
2030 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2032 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2034 // TODO: maintain provenance of an alignment, rather than just make the
2035 // title a concatenation of operations.
2038 if (title.startsWith("Copied sequences"))
2044 newtitle = newtitle.concat("- from " + title);
2049 newtitle = new String("Pasted sequences");
2052 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2057 } catch (Exception ex)
2059 ex.printStackTrace();
2060 System.out.println("Exception whilst pasting: " + ex);
2061 // could be anything being pasted in here
2073 protected void cut_actionPerformed(ActionEvent e)
2075 copy_actionPerformed(null);
2076 delete_actionPerformed(null);
2086 protected void delete_actionPerformed(ActionEvent evt)
2089 SequenceGroup sg = viewport.getSelectionGroup();
2095 Vector seqs = new Vector();
2097 for (int i = 0; i < sg.getSize(); i++)
2099 seq = sg.getSequenceAt(i);
2100 seqs.addElement(seq);
2103 // If the cut affects all sequences, remove highlighted columns
2104 if (sg.getSize() == viewport.getAlignment().getHeight())
2106 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2107 sg.getEndRes() + 1);
2110 SequenceI[] cut = new SequenceI[seqs.size()];
2111 for (int i = 0; i < seqs.size(); i++)
2113 cut[i] = (SequenceI) seqs.elementAt(i);
2117 * //ADD HISTORY ITEM
2119 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2120 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2121 viewport.getAlignment()));
2123 viewport.setSelectionGroup(null);
2124 viewport.sendSelection();
2125 viewport.getAlignment().deleteGroup(sg);
2127 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2129 if (viewport.getAlignment().getHeight() < 1)
2133 this.setClosed(true);
2134 } catch (Exception ex)
2147 protected void deleteGroups_actionPerformed(ActionEvent e)
2149 if (avc.deleteGroups()) {
2150 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2151 alignPanel.updateAnnotation();
2152 alignPanel.paintAlignment(true);
2163 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2165 SequenceGroup sg = new SequenceGroup();
2167 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2169 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2172 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2173 viewport.setSelectionGroup(sg);
2174 viewport.sendSelection();
2175 alignPanel.paintAlignment(true);
2176 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2186 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2188 if (viewport.cursorMode)
2190 alignPanel.seqPanel.keyboardNo1 = null;
2191 alignPanel.seqPanel.keyboardNo2 = null;
2193 viewport.setSelectionGroup(null);
2194 viewport.getColumnSelection().clear();
2195 viewport.setSelectionGroup(null);
2196 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2197 alignPanel.idPanel.idCanvas.searchResults = null;
2198 alignPanel.paintAlignment(true);
2199 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2200 viewport.sendSelection();
2210 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2212 SequenceGroup sg = viewport.getSelectionGroup();
2216 selectAllSequenceMenuItem_actionPerformed(null);
2221 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2223 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2226 alignPanel.paintAlignment(true);
2227 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2228 viewport.sendSelection();
2232 public void invertColSel_actionPerformed(ActionEvent e)
2234 viewport.invertColumnSelection();
2235 alignPanel.paintAlignment(true);
2236 viewport.sendSelection();
2246 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2248 trimAlignment(true);
2258 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2260 trimAlignment(false);
2263 void trimAlignment(boolean trimLeft)
2265 ColumnSelection colSel = viewport.getColumnSelection();
2268 if (colSel.size() > 0)
2272 column = colSel.getMin();
2276 column = colSel.getMax();
2280 if (viewport.getSelectionGroup() != null)
2282 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2283 viewport.getHiddenRepSequences());
2287 seqs = viewport.getAlignment().getSequencesArray();
2290 TrimRegionCommand trimRegion;
2293 trimRegion = new TrimRegionCommand("Remove Left",
2294 TrimRegionCommand.TRIM_LEFT, seqs, column,
2295 viewport.getAlignment(), viewport.getColumnSelection(),
2296 viewport.getSelectionGroup());
2297 viewport.setStartRes(0);
2301 trimRegion = new TrimRegionCommand("Remove Right",
2302 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2303 viewport.getAlignment(), viewport.getColumnSelection(),
2304 viewport.getSelectionGroup());
2307 statusBar.setText(MessageManager.formatMessage("label.removed_columns", new String[]{Integer.valueOf(trimRegion.getSize()).toString()}));
2309 addHistoryItem(trimRegion);
2311 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2313 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2314 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2316 viewport.getAlignment().deleteGroup(sg);
2320 viewport.firePropertyChange("alignment", null, viewport
2321 .getAlignment().getSequences());
2332 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2334 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2337 if (viewport.getSelectionGroup() != null)
2339 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2340 viewport.getHiddenRepSequences());
2341 start = viewport.getSelectionGroup().getStartRes();
2342 end = viewport.getSelectionGroup().getEndRes();
2346 seqs = viewport.getAlignment().getSequencesArray();
2349 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2350 "Remove Gapped Columns", seqs, start, end,
2351 viewport.getAlignment());
2353 addHistoryItem(removeGapCols);
2355 statusBar.setText(MessageManager.formatMessage("label.removed_empty_columns", new String[]{Integer.valueOf(removeGapCols.getSize()).toString()}));
2357 // This is to maintain viewport position on first residue
2358 // of first sequence
2359 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2360 int startRes = seq.findPosition(viewport.startRes);
2361 // ShiftList shifts;
2362 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2363 // edit.alColumnChanges=shifts.getInverse();
2364 // if (viewport.hasHiddenColumns)
2365 // viewport.getColumnSelection().compensateForEdits(shifts);
2366 viewport.setStartRes(seq.findIndex(startRes) - 1);
2367 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2379 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2381 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2384 if (viewport.getSelectionGroup() != null)
2386 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2387 viewport.getHiddenRepSequences());
2388 start = viewport.getSelectionGroup().getStartRes();
2389 end = viewport.getSelectionGroup().getEndRes();
2393 seqs = viewport.getAlignment().getSequencesArray();
2396 // This is to maintain viewport position on first residue
2397 // of first sequence
2398 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2399 int startRes = seq.findPosition(viewport.startRes);
2401 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2402 viewport.getAlignment()));
2404 viewport.setStartRes(seq.findIndex(startRes) - 1);
2406 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2418 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2420 viewport.setPadGaps(padGapsMenuitem.isSelected());
2421 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2427 // if (justifySeqs>0)
2429 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2442 public void findMenuItem_actionPerformed(ActionEvent e)
2448 public void newView_actionPerformed(ActionEvent e)
2455 * @param copyAnnotation
2456 * if true then duplicate all annnotation, groups and settings
2457 * @return new alignment panel, already displayed.
2459 public AlignmentPanel newView(boolean copyAnnotation)
2461 return newView(null, copyAnnotation);
2467 * title of newly created view
2468 * @return new alignment panel, already displayed.
2470 public AlignmentPanel newView(String viewTitle)
2472 return newView(viewTitle, true);
2478 * title of newly created view
2479 * @param copyAnnotation
2480 * if true then duplicate all annnotation, groups and settings
2481 * @return new alignment panel, already displayed.
2483 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2485 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2487 if (!copyAnnotation)
2489 // just remove all the current annotation except for the automatic stuff
2490 newap.av.getAlignment().deleteAllGroups();
2491 for (AlignmentAnnotation alan : newap.av.getAlignment()
2492 .getAlignmentAnnotation())
2494 if (!alan.autoCalculated)
2496 newap.av.getAlignment().deleteAnnotation(alan);
2502 newap.av.gatherViewsHere = false;
2504 if (viewport.viewName == null)
2506 viewport.viewName = "Original";
2509 newap.av.historyList = viewport.historyList;
2510 newap.av.redoList = viewport.redoList;
2512 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2513 // make sure the new view has a unique name - this is essential for Jalview
2515 boolean addFirstIndex = false;
2516 if (viewTitle == null || viewTitle.trim().length() == 0)
2519 addFirstIndex = true;
2523 index = 1;// we count from 1 if given a specific name
2525 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2526 Vector comps = (Vector) PaintRefresher.components.get(viewport
2527 .getSequenceSetId());
2528 Vector existingNames = new Vector();
2529 for (int i = 0; i < comps.size(); i++)
2531 if (comps.elementAt(i) instanceof AlignmentPanel)
2533 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2534 if (!existingNames.contains(ap.av.viewName))
2536 existingNames.addElement(ap.av.viewName);
2541 while (existingNames.contains(newViewName))
2543 newViewName = viewTitle + " " + (++index);
2546 newap.av.viewName = newViewName;
2548 addAlignmentPanel(newap, true);
2549 newap.alignmentChanged();
2551 if (alignPanels.size() == 2)
2553 viewport.gatherViewsHere = true;
2555 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2560 public void expandViews_actionPerformed(ActionEvent e)
2562 Desktop.instance.explodeViews(this);
2566 public void gatherViews_actionPerformed(ActionEvent e)
2568 Desktop.instance.gatherViews(this);
2578 public void font_actionPerformed(ActionEvent e)
2580 new FontChooser(alignPanel);
2590 protected void seqLimit_actionPerformed(ActionEvent e)
2592 viewport.setShowJVSuffix(seqLimits.isSelected());
2594 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2595 .calculateIdWidth());
2596 alignPanel.paintAlignment(true);
2600 public void idRightAlign_actionPerformed(ActionEvent e)
2602 viewport.rightAlignIds = idRightAlign.isSelected();
2603 alignPanel.paintAlignment(true);
2607 public void centreColumnLabels_actionPerformed(ActionEvent e)
2609 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2610 alignPanel.paintAlignment(true);
2616 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2619 protected void followHighlight_actionPerformed()
2621 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2623 alignPanel.scrollToPosition(
2624 alignPanel.seqPanel.seqCanvas.searchResults, false);
2635 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2637 viewport.setColourText(colourTextMenuItem.isSelected());
2638 alignPanel.paintAlignment(true);
2648 public void wrapMenuItem_actionPerformed(ActionEvent e)
2650 scaleAbove.setVisible(wrapMenuItem.isSelected());
2651 scaleLeft.setVisible(wrapMenuItem.isSelected());
2652 scaleRight.setVisible(wrapMenuItem.isSelected());
2653 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2654 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2658 public void showAllSeqs_actionPerformed(ActionEvent e)
2660 viewport.showAllHiddenSeqs();
2664 public void showAllColumns_actionPerformed(ActionEvent e)
2666 viewport.showAllHiddenColumns();
2671 public void hideSelSequences_actionPerformed(ActionEvent e)
2673 viewport.hideAllSelectedSeqs();
2674 alignPanel.paintAlignment(true);
2678 * called by key handler and the hide all/show all menu items
2683 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2686 boolean hide = false;
2687 SequenceGroup sg = viewport.getSelectionGroup();
2688 if (!toggleSeqs && !toggleCols)
2690 // Hide everything by the current selection - this is a hack - we do the
2691 // invert and then hide
2692 // first check that there will be visible columns after the invert.
2693 if ((viewport.getColumnSelection() != null
2694 && viewport.getColumnSelection().getSelected() != null && viewport
2695 .getColumnSelection().getSelected().size() > 0)
2696 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2699 // now invert the sequence set, if required - empty selection implies
2700 // that no hiding is required.
2703 invertSequenceMenuItem_actionPerformed(null);
2704 sg = viewport.getSelectionGroup();
2708 viewport.expandColSelection(sg, true);
2709 // finally invert the column selection and get the new sequence
2711 invertColSel_actionPerformed(null);
2718 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2720 hideSelSequences_actionPerformed(null);
2723 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2726 showAllSeqs_actionPerformed(null);
2732 if (viewport.getColumnSelection().getSelected().size() > 0)
2734 hideSelColumns_actionPerformed(null);
2737 viewport.setSelectionGroup(sg);
2742 showAllColumns_actionPerformed(null);
2751 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2752 * event.ActionEvent)
2755 public void hideAllButSelection_actionPerformed(ActionEvent e)
2757 toggleHiddenRegions(false, false);
2764 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2768 public void hideAllSelection_actionPerformed(ActionEvent e)
2770 SequenceGroup sg = viewport.getSelectionGroup();
2771 viewport.expandColSelection(sg, false);
2772 viewport.hideAllSelectedSeqs();
2773 viewport.hideSelectedColumns();
2774 alignPanel.paintAlignment(true);
2781 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2785 public void showAllhidden_actionPerformed(ActionEvent e)
2787 viewport.showAllHiddenColumns();
2788 viewport.showAllHiddenSeqs();
2789 alignPanel.paintAlignment(true);
2793 public void hideSelColumns_actionPerformed(ActionEvent e)
2795 viewport.hideSelectedColumns();
2796 alignPanel.paintAlignment(true);
2800 public void hiddenMarkers_actionPerformed(ActionEvent e)
2802 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2813 protected void scaleAbove_actionPerformed(ActionEvent e)
2815 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2816 alignPanel.paintAlignment(true);
2826 protected void scaleLeft_actionPerformed(ActionEvent e)
2828 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2829 alignPanel.paintAlignment(true);
2839 protected void scaleRight_actionPerformed(ActionEvent e)
2841 viewport.setScaleRightWrapped(scaleRight.isSelected());
2842 alignPanel.paintAlignment(true);
2852 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2854 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2855 alignPanel.paintAlignment(true);
2865 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2867 viewport.setShowText(viewTextMenuItem.isSelected());
2868 alignPanel.paintAlignment(true);
2878 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2880 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2881 alignPanel.paintAlignment(true);
2884 public FeatureSettings featureSettings;
2887 public void featureSettings_actionPerformed(ActionEvent e)
2889 if (featureSettings != null)
2891 featureSettings.close();
2892 featureSettings = null;
2894 if (!showSeqFeatures.isSelected())
2896 // make sure features are actually displayed
2897 showSeqFeatures.setSelected(true);
2898 showSeqFeatures_actionPerformed(null);
2900 featureSettings = new FeatureSettings(this);
2904 * Set or clear 'Show Sequence Features'
2910 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2912 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2913 alignPanel.paintAlignment(true);
2914 if (alignPanel.getOverviewPanel() != null)
2916 alignPanel.getOverviewPanel().updateOverviewImage();
2921 * Set or clear 'Show Sequence Features'
2927 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2929 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2931 if (viewport.getShowSequenceFeaturesHeight())
2933 // ensure we're actually displaying features
2934 viewport.setShowSequenceFeatures(true);
2935 showSeqFeatures.setSelected(true);
2937 alignPanel.paintAlignment(true);
2938 if (alignPanel.getOverviewPanel() != null)
2940 alignPanel.getOverviewPanel().updateOverviewImage();
2951 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2953 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2954 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2958 public void alignmentProperties()
2960 JEditorPane editPane = new JEditorPane("text/html", "");
2961 editPane.setEditable(false);
2962 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2964 editPane.setText(MessageManager.formatMessage("label.html_content", new String[]{contents.toString()}));
2965 JInternalFrame frame = new JInternalFrame();
2966 frame.getContentPane().add(new JScrollPane(editPane));
2968 Desktop.instance.addInternalFrame(frame, MessageManager.formatMessage("label.alignment_properties", new String[]{getTitle()}), 500, 400);
\r
2978 public void overviewMenuItem_actionPerformed(ActionEvent e)
2980 if (alignPanel.overviewPanel != null)
2985 JInternalFrame frame = new JInternalFrame();
2986 OverviewPanel overview = new OverviewPanel(alignPanel);
2987 frame.setContentPane(overview);
2988 Desktop.addInternalFrame(frame, MessageManager.formatMessage("label.overview_params", new String[]{this.getTitle()}),
\r
2989 frame.getWidth(), frame.getHeight());
2991 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2992 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2995 public void internalFrameClosed(
2996 javax.swing.event.InternalFrameEvent evt)
2998 alignPanel.setOverviewPanel(null);
3002 alignPanel.setOverviewPanel(overview);
3006 public void textColour_actionPerformed(ActionEvent e)
3008 new TextColourChooser().chooseColour(alignPanel, null);
3018 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3030 public void clustalColour_actionPerformed(ActionEvent e)
3032 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3033 viewport.getHiddenRepSequences()));
3043 public void zappoColour_actionPerformed(ActionEvent e)
3045 changeColour(new ZappoColourScheme());
3055 public void taylorColour_actionPerformed(ActionEvent e)
3057 changeColour(new TaylorColourScheme());
3067 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3069 changeColour(new HydrophobicColourScheme());
3079 public void helixColour_actionPerformed(ActionEvent e)
3081 changeColour(new HelixColourScheme());
3091 public void strandColour_actionPerformed(ActionEvent e)
3093 changeColour(new StrandColourScheme());
3103 public void turnColour_actionPerformed(ActionEvent e)
3105 changeColour(new TurnColourScheme());
3115 public void buriedColour_actionPerformed(ActionEvent e)
3117 changeColour(new BuriedColourScheme());
3127 public void nucleotideColour_actionPerformed(ActionEvent e)
3129 changeColour(new NucleotideColourScheme());
3133 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3135 changeColour(new PurinePyrimidineColourScheme());
3139 * public void covariationColour_actionPerformed(ActionEvent e) {
3141 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3145 public void annotationColour_actionPerformed(ActionEvent e)
3147 new AnnotationColourChooser(viewport, alignPanel);
3151 public void rnahelicesColour_actionPerformed(ActionEvent e)
3153 new RNAHelicesColourChooser(viewport, alignPanel);
3163 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3165 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3174 public void changeColour(ColourSchemeI cs)
3176 // TODO: compare with applet and pull up to model method
3181 if (viewport.getAbovePIDThreshold())
3183 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3186 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3188 viewport.setGlobalColourScheme(cs);
3192 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3195 if (viewport.getConservationSelected())
3198 Alignment al = (Alignment) viewport.getAlignment();
3199 Conservation c = new Conservation("All",
3200 ResidueProperties.propHash, 3, al.getSequences(), 0,
3204 c.verdict(false, viewport.getConsPercGaps());
3206 cs.setConservation(c);
3208 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3213 cs.setConservation(null);
3216 cs.setConsensus(viewport.getSequenceConsensusHash());
3219 viewport.setGlobalColourScheme(cs);
3221 if (viewport.getColourAppliesToAllGroups())
3224 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3232 if (cs instanceof ClustalxColourScheme)
3234 sg.cs = new ClustalxColourScheme(sg,
3235 viewport.getHiddenRepSequences());
3237 else if (cs instanceof UserColourScheme)
3239 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3245 sg.cs = cs.getClass().newInstance();
3246 } catch (Exception ex)
3251 if (viewport.getAbovePIDThreshold()
3252 || cs instanceof PIDColourScheme
3253 || cs instanceof Blosum62ColourScheme)
3255 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3257 sg.cs.setConsensus(AAFrequency.calculate(
3258 sg.getSequences(viewport.getHiddenRepSequences()),
3259 sg.getStartRes(), sg.getEndRes() + 1));
3263 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3266 if (viewport.getConservationSelected())
3268 Conservation c = new Conservation("Group",
3269 ResidueProperties.propHash, 3, sg.getSequences(viewport
3270 .getHiddenRepSequences()), sg.getStartRes(),
3271 sg.getEndRes() + 1);
3273 c.verdict(false, viewport.getConsPercGaps());
3274 sg.cs.setConservation(c);
3278 sg.cs.setConservation(null);
3283 if (alignPanel.getOverviewPanel() != null)
3285 alignPanel.getOverviewPanel().updateOverviewImage();
3288 alignPanel.paintAlignment(true);
3298 protected void modifyPID_actionPerformed(ActionEvent e)
3300 if (viewport.getAbovePIDThreshold()
3301 && viewport.getGlobalColourScheme() != null)
3303 SliderPanel.setPIDSliderSource(alignPanel,
3304 viewport.getGlobalColourScheme(), "Background");
3305 SliderPanel.showPIDSlider();
3316 protected void modifyConservation_actionPerformed(ActionEvent e)
3318 if (viewport.getConservationSelected()
3319 && viewport.getGlobalColourScheme() != null)
3321 SliderPanel.setConservationSlider(alignPanel,
3322 viewport.getGlobalColourScheme(), "Background");
3323 SliderPanel.showConservationSlider();
3334 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3336 viewport.setConservationSelected(conservationMenuItem.isSelected());
3338 viewport.setAbovePIDThreshold(false);
3339 abovePIDThreshold.setSelected(false);
3341 changeColour(viewport.getGlobalColourScheme());
3343 modifyConservation_actionPerformed(null);
3353 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3355 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3357 conservationMenuItem.setSelected(false);
3358 viewport.setConservationSelected(false);
3360 changeColour(viewport.getGlobalColourScheme());
3362 modifyPID_actionPerformed(null);
3372 public void userDefinedColour_actionPerformed(ActionEvent e)
3374 if (e.getActionCommand().equals(MessageManager.getString("action.user_defined")))
\r
3376 new UserDefinedColours(alignPanel, null);
3380 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3381 .getUserColourSchemes().get(e.getActionCommand());
3387 public void updateUserColourMenu()
3390 Component[] menuItems = colourMenu.getMenuComponents();
3391 int i, iSize = menuItems.length;
3392 for (i = 0; i < iSize; i++)
3394 if (menuItems[i].getName() != null
3395 && menuItems[i].getName().equals("USER_DEFINED"))
3397 colourMenu.remove(menuItems[i]);
3401 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3403 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3404 .getUserColourSchemes().keys();
3406 while (userColours.hasMoreElements())
3408 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3409 userColours.nextElement().toString());
3410 radioItem.setName("USER_DEFINED");
3411 radioItem.addMouseListener(new MouseAdapter()
3414 public void mousePressed(MouseEvent evt)
3416 if (evt.isControlDown()
3417 || SwingUtilities.isRightMouseButton(evt))
3419 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3421 int option = JOptionPane.showInternalConfirmDialog(
3422 jalview.gui.Desktop.desktop,
3423 MessageManager.getString("label.remove_from_default_list"),
3424 MessageManager.getString("label.remove_user_defined_colour"),
3425 JOptionPane.YES_NO_OPTION);
3426 if (option == JOptionPane.YES_OPTION)
3428 jalview.gui.UserDefinedColours
3429 .removeColourFromDefaults(radioItem.getText());
3430 colourMenu.remove(radioItem);
3434 radioItem.addActionListener(new ActionListener()
3437 public void actionPerformed(ActionEvent evt)
3439 userDefinedColour_actionPerformed(evt);
3446 radioItem.addActionListener(new ActionListener()
3449 public void actionPerformed(ActionEvent evt)
3451 userDefinedColour_actionPerformed(evt);
3455 colourMenu.insert(radioItem, 15);
3456 colours.add(radioItem);
3468 public void PIDColour_actionPerformed(ActionEvent e)
3470 changeColour(new PIDColourScheme());
3480 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3482 changeColour(new Blosum62ColourScheme());
3492 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3494 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3495 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3496 .getAlignment().getSequenceAt(0), null);
3497 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3498 viewport.getAlignment()));
3499 alignPanel.paintAlignment(true);
3509 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3511 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3512 AlignmentSorter.sortByID(viewport.getAlignment());
3513 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3514 viewport.getAlignment()));
3515 alignPanel.paintAlignment(true);
3525 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3527 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3528 AlignmentSorter.sortByLength(viewport.getAlignment());
3529 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3530 viewport.getAlignment()));
3531 alignPanel.paintAlignment(true);
3541 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3543 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3544 AlignmentSorter.sortByGroup(viewport.getAlignment());
3545 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3546 viewport.getAlignment()));
3548 alignPanel.paintAlignment(true);
3558 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3560 new RedundancyPanel(alignPanel, this);
3570 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3572 if ((viewport.getSelectionGroup() == null)
3573 || (viewport.getSelectionGroup().getSize() < 2))
3575 JOptionPane.showInternalMessageDialog(this,
3576 MessageManager.getString("label.you_must_select_least_two_sequences"), MessageManager.getString("label.invalid_selection"),
3577 JOptionPane.WARNING_MESSAGE);
3581 JInternalFrame frame = new JInternalFrame();
3582 frame.setContentPane(new PairwiseAlignPanel(viewport));
3583 Desktop.addInternalFrame(frame, MessageManager.getString("action.pairwise_alignment"), 600, 500);
\r
3594 public void PCAMenuItem_actionPerformed(ActionEvent e)
3596 if (((viewport.getSelectionGroup() != null)
3597 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3598 .getSelectionGroup().getSize() > 0))
3599 || (viewport.getAlignment().getHeight() < 4))
3601 JOptionPane.showInternalMessageDialog(this,
3602 MessageManager.getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3603 MessageManager.getString("label.sequence_selection_insufficient"),
3604 JOptionPane.WARNING_MESSAGE);
3609 new PCAPanel(alignPanel);
3613 public void autoCalculate_actionPerformed(ActionEvent e)
3615 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3616 if (viewport.autoCalculateConsensus)
3618 viewport.firePropertyChange("alignment", null, viewport
3619 .getAlignment().getSequences());
3624 public void sortByTreeOption_actionPerformed(ActionEvent e)
3626 viewport.sortByTree = sortByTree.isSelected();
3630 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3632 viewport.followSelection = listenToViewSelections.isSelected();
3642 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3644 NewTreePanel("AV", "PID", "Average distance tree using PID");
3654 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3656 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3666 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3668 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3678 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3680 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3693 void NewTreePanel(String type, String pwType, String title)
3697 if (viewport.getSelectionGroup() != null
3698 && viewport.getSelectionGroup().getSize() > 0)
3700 if (viewport.getSelectionGroup().getSize() < 3)
3705 MessageManager.getString("label.you_need_more_two_sequences_selected_build_tree"),
3706 MessageManager.getString("label.not_enough_sequences"), JOptionPane.WARNING_MESSAGE);
3710 SequenceGroup sg = viewport.getSelectionGroup();
3712 /* Decide if the selection is a column region */
3713 for (SequenceI _s : sg.getSequences())
3715 if (_s.getLength() < sg.getEndRes())
3720 MessageManager.getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3721 MessageManager.getString("label.sequences_selection_not_aligned"),
3722 JOptionPane.WARNING_MESSAGE);
3728 title = title + " on region";
3729 tp = new TreePanel(alignPanel, type, pwType);
3733 // are the visible sequences aligned?
3734 if (!viewport.getAlignment().isAligned(false))
3739 MessageManager.getString("label.sequences_must_be_aligned_before_creating_tree"),
3740 MessageManager.getString("label.sequences_not_aligned"),
3741 JOptionPane.WARNING_MESSAGE);
3746 if (viewport.getAlignment().getHeight() < 2)
3751 tp = new TreePanel(alignPanel, type, pwType);
3756 if (viewport.viewName != null)
3758 title += viewport.viewName + " of ";
3761 title += this.title;
3763 Desktop.addInternalFrame(tp, title, 600, 500);
3774 public void addSortByOrderMenuItem(String title,
3775 final AlignmentOrder order)
3777 final JMenuItem item = new JMenuItem("by " + title);
3779 item.addActionListener(new java.awt.event.ActionListener()
3782 public void actionPerformed(ActionEvent e)
3784 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3786 // TODO: JBPNote - have to map order entries to curent SequenceI
3788 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3790 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3793 alignPanel.paintAlignment(true);
3799 * Add a new sort by annotation score menu item
3802 * the menu to add the option to
3804 * the label used to retrieve scores for each sequence on the
3807 public void addSortByAnnotScoreMenuItem(JMenu sort,
3808 final String scoreLabel)
3810 final JMenuItem item = new JMenuItem(scoreLabel);
3812 item.addActionListener(new java.awt.event.ActionListener()
3815 public void actionPerformed(ActionEvent e)
3817 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3818 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3819 viewport.getAlignment());// ,viewport.getSelectionGroup());
3820 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3821 viewport.getAlignment()));
3822 alignPanel.paintAlignment(true);
3828 * last hash for alignment's annotation array - used to minimise cost of
3831 protected int _annotationScoreVectorHash;
3834 * search the alignment and rebuild the sort by annotation score submenu the
3835 * last alignment annotation vector hash is stored to minimize cost of
3836 * rebuilding in subsequence calls.
3840 public void buildSortByAnnotationScoresMenu()
3842 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3847 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3849 sortByAnnotScore.removeAll();
3850 // almost certainly a quicker way to do this - but we keep it simple
3851 Hashtable scoreSorts = new Hashtable();
3852 AlignmentAnnotation aann[];
3853 for (SequenceI sqa : viewport.getAlignment().getSequences())
3855 aann = sqa.getAnnotation();
3856 for (int i = 0; aann != null && i < aann.length; i++)
3858 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3860 scoreSorts.put(aann[i].label, aann[i].label);
3864 Enumeration labels = scoreSorts.keys();
3865 while (labels.hasMoreElements())
3867 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3868 (String) labels.nextElement());
3870 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3873 _annotationScoreVectorHash = viewport.getAlignment()
3874 .getAlignmentAnnotation().hashCode();
3879 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3880 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3881 * call. Listeners are added to remove the menu item when the treePanel is
3882 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3886 * Displayed tree window.
3888 * SortBy menu item title.
3891 public void buildTreeMenu()
3893 calculateTree.removeAll();
3894 // build the calculate menu
3895 for (final String type:new String[] {"NJ", "AV"})
3897 for (final Object pwtype: ResidueProperties.scoreMatrices.keySet())
3899 JMenuItem tm = new JMenuItem();
3900 ScoreMatrix sm = (ScoreMatrix) ResidueProperties.scoreMatrices.get(pwtype);
3901 final String title="Calculate "+type+" using "+sm.getName();
3902 tm.setText(title);// MessageManager.getString("label.neighbour_blosum62"));
3904 .addActionListener(new java.awt.event.ActionListener()
3906 public void actionPerformed(ActionEvent e)
3908 NewTreePanel(type, (String) pwtype, title);
3911 calculateTree.add(tm);
3915 sortByTreeMenu.removeAll();
3917 Vector comps = (Vector) PaintRefresher.components.get(viewport
3918 .getSequenceSetId());
3919 Vector treePanels = new Vector();
3920 int i, iSize = comps.size();
3921 for (i = 0; i < iSize; i++)
3923 if (comps.elementAt(i) instanceof TreePanel)
3925 treePanels.add(comps.elementAt(i));
3929 iSize = treePanels.size();
3933 sortByTreeMenu.setVisible(false);
3937 sortByTreeMenu.setVisible(true);
3939 for (i = 0; i < treePanels.size(); i++)
3941 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3942 final JMenuItem item = new JMenuItem(tp.getTitle());
3943 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3944 item.addActionListener(new java.awt.event.ActionListener()
3947 public void actionPerformed(ActionEvent e)
3949 tp.sortByTree_actionPerformed(null);
3950 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3955 sortByTreeMenu.add(item);
3959 public boolean sortBy(AlignmentOrder alorder, String undoname)
3961 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3962 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3963 if (undoname != null)
3965 addHistoryItem(new OrderCommand(undoname, oldOrder,
3966 viewport.getAlignment()));
3968 alignPanel.paintAlignment(true);
3973 * Work out whether the whole set of sequences or just the selected set will
3974 * be submitted for multiple alignment.
3977 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3979 // Now, check we have enough sequences
3980 AlignmentView msa = null;
3982 if ((viewport.getSelectionGroup() != null)
3983 && (viewport.getSelectionGroup().getSize() > 1))
3985 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3986 // some common interface!
3988 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3989 * SequenceI[sz = seqs.getSize(false)];
3991 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3992 * seqs.getSequenceAt(i); }
3994 msa = viewport.getAlignmentView(true);
3999 * Vector seqs = viewport.getAlignment().getSequences();
4001 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
4003 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
4004 * seqs.elementAt(i); } }
4006 msa = viewport.getAlignmentView(false);
4012 * Decides what is submitted to a secondary structure prediction service: the
4013 * first sequence in the alignment, or in the current selection, or, if the
4014 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4015 * region or the whole alignment. (where the first sequence in the set is the
4016 * one that the prediction will be for).
4018 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4020 AlignmentView seqs = null;
4022 if ((viewport.getSelectionGroup() != null)
4023 && (viewport.getSelectionGroup().getSize() > 0))
4025 seqs = viewport.getAlignmentView(true);
4029 seqs = viewport.getAlignmentView(false);
4031 // limit sequences - JBPNote in future - could spawn multiple prediction
4033 // TODO: viewport.getAlignment().isAligned is a global state - the local
4034 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4035 if (!viewport.getAlignment().isAligned(false))
4037 seqs.setSequences(new SeqCigar[]
4038 { seqs.getSequences()[0] });
4039 // TODO: if seqs.getSequences().length>1 then should really have warned
4053 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4055 // Pick the tree file
4056 JalviewFileChooser chooser = new JalviewFileChooser(
4057 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4058 chooser.setFileView(new JalviewFileView());
4059 chooser.setDialogTitle(MessageManager.getString("label.select_newick_like_tree_file"));
\r
4060 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
\r
4062 int value = chooser.showOpenDialog(null);
4064 if (value == JalviewFileChooser.APPROVE_OPTION)
4066 String choice = chooser.getSelectedFile().getPath();
4067 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4068 jalview.io.NewickFile fin = null;
4071 fin = new jalview.io.NewickFile(choice, "File");
4072 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4073 } catch (Exception ex)
4075 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4076 MessageManager.getString("label.problem_reading_tree_file"), JOptionPane.WARNING_MESSAGE);
4077 ex.printStackTrace();
4079 if (fin != null && fin.hasWarningMessage())
4081 JOptionPane.showMessageDialog(Desktop.desktop,
4082 fin.getWarningMessage(), MessageManager.getString("label.possible_problem_with_tree_file"),
4083 JOptionPane.WARNING_MESSAGE);
4089 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4091 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4094 public TreePanel ShowNewickTree(NewickFile nf, String title)
4096 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4099 public TreePanel ShowNewickTree(NewickFile nf, String title,
4100 AlignmentView input)
4102 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4105 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4106 int h, int x, int y)
4108 return ShowNewickTree(nf, title, null, w, h, x, y);
4112 * Add a treeviewer for the tree extracted from a newick file object to the
4113 * current alignment view
4120 * Associated alignment input data (or null)
4129 * @return TreePanel handle
4131 public TreePanel ShowNewickTree(NewickFile nf, String title,
4132 AlignmentView input, int w, int h, int x, int y)
4134 TreePanel tp = null;
4140 if (nf.getTree() != null)
4142 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4148 tp.setLocation(x, y);
4151 Desktop.addInternalFrame(tp, title, w, h);
4153 } catch (Exception ex)
4155 ex.printStackTrace();
4161 private boolean buildingMenu = false;
4164 * Generates menu items and listener event actions for web service clients
4167 public void BuildWebServiceMenu()
4169 while (buildingMenu)
4173 System.err.println("Waiting for building menu to finish.");
4175 } catch (Exception e)
4180 final AlignFrame me = this;
4181 buildingMenu = true;
4182 new Thread(new Runnable()
4187 final List<JMenuItem> legacyItems=new ArrayList<JMenuItem>();
4190 System.err.println("Building ws menu again "
4191 + Thread.currentThread());
4192 // TODO: add support for context dependent disabling of services based
4194 // alignment and current selection
4195 // TODO: add additional serviceHandle parameter to specify abstract
4197 // class independently of AbstractName
4198 // TODO: add in rediscovery GUI function to restart discoverer
4199 // TODO: group services by location as well as function and/or
4201 // object broker mechanism.
4202 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4203 final IProgressIndicator af = me;
4204 final JMenu msawsmenu = new JMenu("Alignment");
4205 final JMenu secstrmenu = new JMenu(
4206 "Secondary Structure Prediction");
4207 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4208 final JMenu analymenu = new JMenu("Analysis");
4209 final JMenu dismenu = new JMenu("Protein Disorder");
4210 // JAL-940 - only show secondary structure prediction services from
4211 // the legacy server
4212 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4214 Discoverer.services != null && (Discoverer.services.size() > 0))
4216 // TODO: refactor to allow list of AbstractName/Handler bindings to
4218 // stored or retrieved from elsewhere
4219 // No MSAWS used any more:
4220 // Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4221 Vector secstrpr = (Vector) Discoverer.services
4223 if (secstrpr != null)
4225 // Add any secondary structure prediction services
4226 for (int i = 0, j = secstrpr.size(); i < j; i++)
4228 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4230 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4231 .getServiceClient(sh);
4232 int p=secstrmenu.getItemCount();
4233 impl.attachWSMenuEntry(secstrmenu, me);
4234 int q=secstrmenu.getItemCount();
4235 for (int litm=p;litm<q; litm++)
4237 legacyItems.add(secstrmenu.getItem(litm));
4243 // Add all submenus in the order they should appear on the web
4245 wsmenu.add(msawsmenu);
4246 wsmenu.add(secstrmenu);
4247 wsmenu.add(dismenu);
4248 wsmenu.add(analymenu);
4249 // No search services yet
4250 // wsmenu.add(seqsrchmenu);
4252 javax.swing.SwingUtilities.invokeLater(new Runnable()
4259 webService.removeAll();
4260 // first, add discovered services onto the webservices menu
4261 if (wsmenu.size() > 0)
4263 for (int i = 0, j = wsmenu.size(); i < j; i++)
4265 webService.add(wsmenu.get(i));
4270 webService.add(me.webServiceNoServices);
4272 // TODO: move into separate menu builder class.
4273 boolean new_sspred=false;
4274 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4276 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4277 if (jws2servs != null)
4279 if (jws2servs.hasServices())
4281 jws2servs.attachWSMenuEntry(webService, me);
4282 for (Jws2Instance sv:jws2servs.getServices()) {
4283 if (sv.description.toLowerCase().contains("jpred"))
4285 for (JMenuItem jmi:legacyItems)
4287 jmi.setVisible(false);
4293 if (jws2servs.isRunning())
4295 JMenuItem tm = new JMenuItem(
4296 "Still discovering JABA Services");
4297 tm.setEnabled(false);
4302 build_urlServiceMenu(me.webService);
4303 build_fetchdbmenu(webService);
4304 for (JMenu item : wsmenu)
4306 if (item.getItemCount() == 0)
4308 item.setEnabled(false);
4312 item.setEnabled(true);
4315 } catch (Exception e)
4318 .debug("Exception during web service menu building process.",
4324 } catch (Exception e)
4329 buildingMenu = false;
4336 * construct any groupURL type service menu entries.
4340 private void build_urlServiceMenu(JMenu webService)
4342 // TODO: remove this code when 2.7 is released
4343 // DEBUG - alignmentView
4345 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4346 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4348 * @Override public void actionPerformed(ActionEvent e) {
4349 * jalview.datamodel.AlignmentView
4350 * .testSelectionViews(af.viewport.getAlignment(),
4351 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4353 * }); webService.add(testAlView);
4355 // TODO: refactor to RestClient discoverer and merge menu entries for
4356 // rest-style services with other types of analysis/calculation service
4357 // SHmmr test client - still being implemented.
4358 // DEBUG - alignmentView
4360 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4363 client.attachWSMenuEntry(
4364 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4368 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4370 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4376 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4377 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4378 * getProperty("LAST_DIRECTORY"));
4380 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4381 * to Vamsas file"); chooser.setToolTipText("Export");
4383 * int value = chooser.showSaveDialog(this);
4385 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4386 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4387 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4388 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4391 * prototype of an automatically enabled/disabled analysis function
4394 protected void setShowProductsEnabled()
4396 SequenceI[] selection = viewport.getSequenceSelection();
4397 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4398 viewport.getAlignment().getDataset()))
4400 showProducts.setEnabled(true);
4405 showProducts.setEnabled(false);
4410 * search selection for sequence xRef products and build the show products
4415 * @return true if showProducts menu should be enabled.
4417 public boolean canShowProducts(SequenceI[] selection,
4418 boolean isRegionSelection, Alignment dataset)
4420 boolean showp = false;
4423 showProducts.removeAll();
4424 final boolean dna = viewport.getAlignment().isNucleotide();
4425 final Alignment ds = dataset;
4426 String[] ptypes = (selection == null || selection.length == 0) ? null
4427 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4429 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4430 // selection, dataset, true);
4431 final SequenceI[] sel = selection;
4432 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4435 final boolean isRegSel = isRegionSelection;
4436 final AlignFrame af = this;
4437 final String source = ptypes[t];
4438 JMenuItem xtype = new JMenuItem(ptypes[t]);
4439 xtype.addActionListener(new ActionListener()
4443 public void actionPerformed(ActionEvent e)
4445 // TODO: new thread for this call with vis-delay
4446 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4447 isRegSel, dna, source);
4451 showProducts.add(xtype);
4453 showProducts.setVisible(showp);
4454 showProducts.setEnabled(showp);
4455 } catch (Exception e)
4457 jalview.bin.Cache.log
4458 .warn("canTranslate threw an exception - please report to help@jalview.org",
4465 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4466 boolean isRegSel, boolean dna, String source)
4468 final boolean fisRegSel = isRegSel;
4469 final boolean fdna = dna;
4470 final String fsrc = source;
4471 final AlignFrame ths = this;
4472 final SequenceI[] fsel = sel;
4473 Runnable foo = new Runnable()
4479 final long sttime = System.currentTimeMillis();
4480 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4483 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4487 Alignment prods = CrossRef
4488 .findXrefSequences(fsel, fdna, fsrc, ds);
4491 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4492 for (int s = 0; s < sprods.length; s++)
4494 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4495 if (ds.getSequences() == null
4496 || !ds.getSequences().contains(
4497 sprods[s].getDatasetSequence()))
4498 ds.addSequence(sprods[s].getDatasetSequence());
4499 sprods[s].updatePDBIds();
4501 Alignment al = new Alignment(sprods);
4502 AlignedCodonFrame[] cf = prods.getCodonFrames();
4504 for (int s = 0; cf != null && s < cf.length; s++)
4506 al.addCodonFrame(cf[s]);
4509 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4511 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4512 + " for " + ((fisRegSel) ? "selected region of " : "")
4514 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4519 System.err.println("No Sequences generated for xRef type "
4522 } catch (Exception e)
4524 jalview.bin.Cache.log.error(
4525 "Exception when finding crossreferences", e);
4526 } catch (OutOfMemoryError e)
4528 new OOMWarning("whilst fetching crossreferences", e);
4531 jalview.bin.Cache.log.error("Error when finding crossreferences",
4534 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4539 Thread frunner = new Thread(foo);
4543 public boolean canShowTranslationProducts(SequenceI[] selection,
4544 AlignmentI alignment)
4549 return (jalview.analysis.Dna.canTranslate(selection,
4550 viewport.getViewAsVisibleContigs(true)));
4551 } catch (Exception e)
4553 jalview.bin.Cache.log
4554 .warn("canTranslate threw an exception - please report to help@jalview.org",
4561 public void showProducts_actionPerformed(ActionEvent e)
4563 // /////////////////////////////
4564 // Collect Data to be translated/transferred
4566 SequenceI[] selection = viewport.getSequenceSelection();
4567 AlignmentI al = null;
4570 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4571 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4572 viewport.getAlignment().getDataset());
4573 } catch (Exception ex)
4576 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4583 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4584 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4588 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4589 Desktop.addInternalFrame(af, MessageManager.formatMessage("label.translation_of_params", new String[]{this.getTitle()}),
\r
4590 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4595 public void showTranslation_actionPerformed(ActionEvent e)
4597 // /////////////////////////////
4598 // Collect Data to be translated/transferred
4600 SequenceI[] selection = viewport.getSequenceSelection();
4601 String[] seqstring = viewport.getViewAsString(true);
4602 AlignmentI al = null;
4605 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4606 viewport.getViewAsVisibleContigs(true), viewport
4607 .getGapCharacter(), viewport.getAlignment()
4608 .getAlignmentAnnotation(), viewport.getAlignment()
4609 .getWidth(), viewport.getAlignment().getDataset());
4610 } catch (Exception ex)
4613 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4617 MessageManager.getString("label.error_when_translating_sequences_submit_bug_report"),
4618 MessageManager.getString("label.implementation_error") + MessageManager.getString("translation_failed"), JOptionPane.ERROR_MESSAGE);
4626 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4627 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4631 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4632 Desktop.addInternalFrame(af, MessageManager.formatMessage("label.translation_of_params", new String[]{this.getTitle()}),
\r
4633 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4638 * Try to load a features file onto the alignment.
4641 * contents or path to retrieve file
4643 * access mode of file (see jalview.io.AlignFile)
4644 * @return true if features file was parsed corectly.
4646 public boolean parseFeaturesFile(String file, String type)
4648 boolean featuresFile = false;
4651 featuresFile = new FeaturesFile(file, type).parse(viewport
4652 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4653 .getFeatureRenderer().featureColours, false,
4654 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4655 } catch (Exception ex)
4657 ex.printStackTrace();
4662 viewport.showSequenceFeatures = true;
4663 showSeqFeatures.setSelected(true);
4664 if (alignPanel.seqPanel.seqCanvas.fr != null)
4666 // update the min/max ranges where necessary
4667 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4669 if (featureSettings != null)
4671 featureSettings.setTableData();
4673 alignPanel.paintAlignment(true);
4676 return featuresFile;
4680 public void dragEnter(DropTargetDragEvent evt)
4685 public void dragExit(DropTargetEvent evt)
4690 public void dragOver(DropTargetDragEvent evt)
4695 public void dropActionChanged(DropTargetDragEvent evt)
4700 public void drop(DropTargetDropEvent evt)
4702 Transferable t = evt.getTransferable();
4703 java.util.List files = null;
4707 DataFlavor uriListFlavor = new DataFlavor(
4708 "text/uri-list;class=java.lang.String");
4709 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4711 // Works on Windows and MacOSX
4712 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4713 files = (java.util.List) t
4714 .getTransferData(DataFlavor.javaFileListFlavor);
4716 else if (t.isDataFlavorSupported(uriListFlavor))
4718 // This is used by Unix drag system
4719 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4720 String data = (String) t.getTransferData(uriListFlavor);
4721 files = new java.util.ArrayList(1);
4722 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4723 data, "\r\n"); st.hasMoreTokens();)
4725 String s = st.nextToken();
4726 if (s.startsWith("#"))
4728 // the line is a comment (as per the RFC 2483)
4732 java.net.URI uri = new java.net.URI(s);
4733 // check to see if we can handle this kind of URI
4734 if (uri.getScheme().toLowerCase().startsWith("http"))
4736 files.add(uri.toString());
4740 // otherwise preserve old behaviour: catch all for file objects
4741 java.io.File file = new java.io.File(uri);
4742 files.add(file.toString());
4746 } catch (Exception e)
4748 e.printStackTrace();
4754 // check to see if any of these files have names matching sequences in
4756 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4757 .getAlignment().getSequencesArray());
4759 * Object[] { String,SequenceI}
4761 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4762 ArrayList<String> filesnotmatched = new ArrayList<String>();
4763 for (int i = 0; i < files.size(); i++)
4765 String file = files.get(i).toString();
4767 String protocol = FormatAdapter.checkProtocol(file);
4768 if (protocol == jalview.io.FormatAdapter.FILE)
4770 File fl = new File(file);
4771 pdbfn = fl.getName();
4773 else if (protocol == jalview.io.FormatAdapter.URL)
4775 URL url = new URL(file);
4776 pdbfn = url.getFile();
4778 if (pdbfn.length() > 0)
4780 // attempt to find a match in the alignment
4781 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4782 int l = 0, c = pdbfn.indexOf(".");
4783 while (mtch == null && c != -1)
4788 } while ((c = pdbfn.indexOf(".", l)) > l);
4791 pdbfn = pdbfn.substring(0, l);
4793 mtch = idm.findAllIdMatches(pdbfn);
4800 type = new IdentifyFile().Identify(file, protocol);
4801 } catch (Exception ex)
4807 if (type.equalsIgnoreCase("PDB"))
4809 filesmatched.add(new Object[]
4810 { file, protocol, mtch });
4815 // File wasn't named like one of the sequences or wasn't a PDB file.
4816 filesnotmatched.add(file);
4820 if (filesmatched.size() > 0)
4822 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4826 MessageManager.formatMessage("label.automatically_associate_pdb_files_with_sequences_same_name",
4827 new String[]{Integer.valueOf(filesmatched.size()).toString()}),
4828 MessageManager.getString("label.automatically_associate_pdb_files_by_name"),
4829 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4832 for (Object[] fm : filesmatched)
4834 // try and associate
4835 // TODO: may want to set a standard ID naming formalism for
4836 // associating PDB files which have no IDs.
4837 for (SequenceI toassoc : (SequenceI[]) fm[2])
4839 PDBEntry pe = new AssociatePdbFileWithSeq()
4840 .associatePdbWithSeq((String) fm[0],
4841 (String) fm[1], toassoc, false);
4844 System.err.println("Associated file : "
4845 + ((String) fm[0]) + " with "
4846 + toassoc.getDisplayId(true));
4850 alignPanel.paintAlignment(true);
4854 if (filesnotmatched.size() > 0)
4857 && (Cache.getDefault(
4858 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4861 MessageManager.formatMessage("label.ignore_unmatched_dropped_files_info", new String[]{Integer.valueOf(filesnotmatched.size()).toString()}),
4862 MessageManager.getString("label.ignore_unmatched_dropped_files"),
4863 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4867 for (String fn : filesnotmatched)
4869 loadJalviewDataFile(fn, null, null, null);
4873 } catch (Exception ex)
4875 ex.printStackTrace();
4881 * Attempt to load a "dropped" file or URL string: First by testing whether
4882 * it's and Annotation file, then a JNet file, and finally a features file. If
4883 * all are false then the user may have dropped an alignment file onto this
4887 * either a filename or a URL string.
4889 public void loadJalviewDataFile(String file, String protocol,
4890 String format, SequenceI assocSeq)
4894 if (protocol == null)
4896 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4898 // if the file isn't identified, or not positively identified as some
4899 // other filetype (PFAM is default unidentified alignment file type) then
4900 // try to parse as annotation.
4901 boolean isAnnotation = (format == null || format
4902 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4903 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4908 // first see if its a T-COFFEE score file
4909 TCoffeeScoreFile tcf = null;
4912 tcf = new TCoffeeScoreFile(file, protocol);
4915 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4917 tcoffeeColour.setEnabled(true);
4918 tcoffeeColour.setSelected(true);
4919 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4920 isAnnotation = true;
4921 statusBar.setText(MessageManager.getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
4925 // some problem - if no warning its probable that the ID matching
4926 // process didn't work
4930 tcf.getWarningMessage() == null ? MessageManager.getString("label.check_file_matches_sequence_ids_alignment")
4931 : tcf.getWarningMessage(),
4932 MessageManager.getString("label.problem_reading_tcoffee_score_file"),
4933 JOptionPane.WARNING_MESSAGE);
4940 } catch (Exception x)
4943 .debug("Exception when processing data source as T-COFFEE score file",
4949 // try to see if its a JNet 'concise' style annotation file *before*
4951 // try to parse it as a features file
4954 format = new IdentifyFile().Identify(file, protocol);
4956 if (format.equalsIgnoreCase("JnetFile"))
4958 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4960 new JnetAnnotationMaker().add_annotation(predictions,
4961 viewport.getAlignment(), 0, false);
4962 isAnnotation = true;
4967 * if (format.equalsIgnoreCase("PDB")) {
4969 * String pdbfn = ""; // try to match up filename with sequence id
4970 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4971 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4972 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4973 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4974 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4975 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4976 * // attempt to find a match in the alignment SequenceI mtch =
4977 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4978 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4979 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4980 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4981 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4982 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4983 * { System.err.println("Associated file : " + file + " with " +
4984 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4985 * TODO: maybe need to load as normal otherwise return; } }
4987 // try to parse it as a features file
4988 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4989 // if it wasn't a features file then we just treat it as a general
4990 // alignment file to load into the current view.
4993 new FileLoader().LoadFile(viewport, file, protocol, format);
4997 alignPanel.paintAlignment(true);
5005 alignPanel.adjustAnnotationHeight();
5006 viewport.updateSequenceIdColours();
5007 buildSortByAnnotationScoresMenu();
5008 alignPanel.paintAlignment(true);
5010 } catch (Exception ex)
5012 ex.printStackTrace();
5013 } catch (OutOfMemoryError oom)
5018 } catch (Exception x)
5024 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5025 : "using " + protocol + " from " + file)
5027 + (format != null ? "(parsing as '" + format
5028 + "' file)" : ""), oom, Desktop.desktop);
5033 public void tabSelectionChanged(int index)
5037 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5038 viewport = alignPanel.av;
5039 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5040 setMenusFromViewport(viewport);
5045 public void tabbedPane_mousePressed(MouseEvent e)
5047 if (SwingUtilities.isRightMouseButton(e))
5049 String reply = JOptionPane.showInternalInputDialog(this,
5050 MessageManager.getString("label.enter_view_name"), MessageManager.getString("label.enter_view_name"),
5051 JOptionPane.QUESTION_MESSAGE);
5055 viewport.viewName = reply;
5056 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5061 public AlignViewport getCurrentView()
5067 * Open the dialog for regex description parsing.
5070 protected void extractScores_actionPerformed(ActionEvent e)
5072 ParseProperties pp = new jalview.analysis.ParseProperties(
5073 viewport.getAlignment());
5074 // TODO: verify regex and introduce GUI dialog for version 2.5
5075 // if (pp.getScoresFromDescription("col", "score column ",
5076 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5078 if (pp.getScoresFromDescription("description column",
5079 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5081 buildSortByAnnotationScoresMenu();
5089 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5093 protected void showDbRefs_actionPerformed(ActionEvent e)
5095 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5101 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5105 protected void showNpFeats_actionPerformed(ActionEvent e)
5107 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5111 * find the viewport amongst the tabs in this alignment frame and close that
5116 public boolean closeView(AlignViewport av)
5120 this.closeMenuItem_actionPerformed(false);
5123 Component[] comp = tabbedPane.getComponents();
5124 for (int i = 0; comp != null && i < comp.length; i++)
5126 if (comp[i] instanceof AlignmentPanel)
5128 if (((AlignmentPanel) comp[i]).av == av)
5131 closeView((AlignmentPanel) comp[i]);
5139 protected void build_fetchdbmenu(JMenu webService)
5141 // Temporary hack - DBRef Fetcher always top level ws entry.
5142 // TODO We probably want to store a sequence database checklist in
5143 // preferences and have checkboxes.. rather than individual sources selected
5145 final JMenu rfetch = new JMenu(MessageManager.getString("action.fetch_db_references"));
\r
5146 rfetch.setToolTipText(MessageManager.getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
\r
5147 webService.add(rfetch);
5149 JMenuItem fetchr = new JMenuItem(MessageManager.getString("label.standard_databases"));
\r
5150 fetchr.setToolTipText(MessageManager.getString("label.fetch_embl_uniprot"));
\r
5151 fetchr.addActionListener(new ActionListener()
5155 public void actionPerformed(ActionEvent e)
5157 new Thread(new Runnable()
5163 new jalview.ws.DBRefFetcher(alignPanel.av
5164 .getSequenceSelection(), alignPanel.alignFrame)
5165 .fetchDBRefs(false);
5173 final AlignFrame me = this;
5174 new Thread(new Runnable()
5179 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5180 .getSequenceFetcherSingleton(me);
5181 javax.swing.SwingUtilities.invokeLater(new Runnable()
5186 String[] dbclasses = sf.getOrderedSupportedSources();
5187 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5188 // jalview.util.QuickSort.sort(otherdb, otherdb);
5189 List<DbSourceProxy> otherdb;
5190 JMenu dfetch = new JMenu();
5191 JMenu ifetch = new JMenu();
5192 JMenuItem fetchr = null;
5193 int comp = 0, icomp = 0, mcomp = 15;
5194 String mname = null;
5196 for (String dbclass : dbclasses)
5198 otherdb = sf.getSourceProxy(dbclass);
5199 // add a single entry for this class, or submenu allowing 'fetch
5201 if (otherdb == null || otherdb.size() < 1)
5205 // List<DbSourceProxy> dbs=otherdb;
5206 // otherdb=new ArrayList<DbSourceProxy>();
5207 // for (DbSourceProxy db:dbs)
5209 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5213 mname = "From " + dbclass;
5215 if (otherdb.size() == 1)
5217 final DbSourceProxy[] dassource = otherdb
5218 .toArray(new DbSourceProxy[0]);
5219 DbSourceProxy src = otherdb.get(0);
5220 fetchr = new JMenuItem(src.getDbSource());
5221 fetchr.addActionListener(new ActionListener()
5225 public void actionPerformed(ActionEvent e)
5227 new Thread(new Runnable()
5233 new jalview.ws.DBRefFetcher(alignPanel.av
5234 .getSequenceSelection(),
5235 alignPanel.alignFrame, dassource)
5236 .fetchDBRefs(false);
5242 fetchr.setToolTipText("<html>"
5243 + JvSwingUtils.wrapTooltip("Retrieve from "
5244 + src.getDbName()) + "<html>");
5250 final DbSourceProxy[] dassource = otherdb
5251 .toArray(new DbSourceProxy[0]);
5253 DbSourceProxy src = otherdb.get(0);
5254 fetchr = new JMenuItem(MessageManager.formatMessage("label.fetch_all_param", new String[]{src.getDbSource()}));
\r
5255 fetchr.addActionListener(new ActionListener()
5258 public void actionPerformed(ActionEvent e)
5260 new Thread(new Runnable()
5266 new jalview.ws.DBRefFetcher(alignPanel.av
5267 .getSequenceSelection(),
5268 alignPanel.alignFrame, dassource)
5269 .fetchDBRefs(false);
5275 fetchr.setToolTipText("<html>"
5276 + JvSwingUtils.wrapTooltip("Retrieve from all "
5277 + otherdb.size() + " sources in "
5278 + src.getDbSource() + "<br>First is :"
5279 + src.getDbName()) + "<html>");
5282 // and then build the rest of the individual menus
5283 ifetch = new JMenu("Sources from " + src.getDbSource());
5285 String imname = null;
5287 for (DbSourceProxy sproxy : otherdb)
5289 String dbname = sproxy.getDbName();
5290 String sname = dbname.length() > 5 ? dbname.substring(0,
5291 5) + "..." : dbname;
5292 String msname = dbname.length() > 10 ? dbname.substring(
5293 0, 10) + "..." : dbname;
5296 imname = "from '" + sname + "'";
5298 fetchr = new JMenuItem(msname);
5299 final DbSourceProxy[] dassrc =
5301 fetchr.addActionListener(new ActionListener()
5305 public void actionPerformed(ActionEvent e)
5307 new Thread(new Runnable()
5313 new jalview.ws.DBRefFetcher(alignPanel.av
5314 .getSequenceSelection(),
5315 alignPanel.alignFrame, dassrc)
5316 .fetchDBRefs(false);
5322 fetchr.setToolTipText("<html>"
5323 + JvSwingUtils.wrapTooltip("Retrieve from "
5324 + dbname) + "</html>");
5327 if (++icomp >= mcomp || i == (otherdb.size()))
5329 ifetch.setText(MessageManager.formatMessage("label.source_to_target",imname,sname));
5331 ifetch = new JMenu();
5339 if (comp >= mcomp || dbi >= (dbclasses.length))
5341 dfetch.setText(MessageManager.formatMessage("label.source_to_target",mname,dbclass));
5343 dfetch = new JMenu();
5356 * Left justify the whole alignment.
5359 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5361 AlignmentI al = viewport.getAlignment();
5363 viewport.firePropertyChange("alignment", null, al);
5367 * Right justify the whole alignment.
5370 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5372 AlignmentI al = viewport.getAlignment();
5374 viewport.firePropertyChange("alignment", null, al);
5377 public void setShowSeqFeatures(boolean b)
5379 showSeqFeatures.setSelected(true);
5380 viewport.setShowSequenceFeatures(true);
5387 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5388 * awt.event.ActionEvent)
5391 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5393 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5394 alignPanel.paintAlignment(true);
5401 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5405 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5407 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5408 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5416 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5417 * .event.ActionEvent)
5420 protected void showGroupConservation_actionPerformed(ActionEvent e)
5422 viewport.setShowGroupConservation(showGroupConservation.getState());
5423 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5430 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5431 * .event.ActionEvent)
5434 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5436 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5437 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5444 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5445 * .event.ActionEvent)
5448 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5450 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5451 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5455 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5457 showSequenceLogo.setState(true);
5458 viewport.setShowSequenceLogo(true);
5459 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5460 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5464 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5466 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5473 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5474 * .event.ActionEvent)
5477 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5479 if (avc.makeGroupsFromSelection()) {
5480 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5481 alignPanel.updateAnnotation();
5482 alignPanel.paintAlignment(true);
5487 protected void createGroup_actionPerformed(ActionEvent e)
5489 if (avc.createGroup())
5491 alignPanel.alignmentChanged();
5496 protected void unGroup_actionPerformed(ActionEvent e)
5500 alignPanel.alignmentChanged();
5505 * make the given alignmentPanel the currently selected tab
5507 * @param alignmentPanel
5509 public void setDisplayedView(AlignmentPanel alignmentPanel)
5511 if (!viewport.getSequenceSetId().equals(
5512 alignmentPanel.av.getSequenceSetId()))
5515 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5517 if (tabbedPane != null
5518 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5519 .getSelectedIndex())
5521 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5526 class PrintThread extends Thread
5530 public PrintThread(AlignmentPanel ap)
5535 static PageFormat pf;
5540 PrinterJob printJob = PrinterJob.getPrinterJob();
5544 printJob.setPrintable(ap, pf);
5548 printJob.setPrintable(ap);
5551 if (printJob.printDialog())
5556 } catch (Exception PrintException)
5558 PrintException.printStackTrace();