2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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/>.
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.AlignmentSorter;
22 import jalview.analysis.Conservation;
23 import jalview.analysis.CrossRef;
24 import jalview.analysis.NJTree;
25 import jalview.analysis.ParseProperties;
26 import jalview.analysis.SequenceIdMatcher;
27 import jalview.bin.Cache;
28 import jalview.commands.CommandI;
29 import jalview.commands.EditCommand;
30 import jalview.commands.OrderCommand;
31 import jalview.commands.RemoveGapColCommand;
32 import jalview.commands.RemoveGapsCommand;
33 import jalview.commands.SlideSequencesCommand;
34 import jalview.commands.TrimRegionCommand;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.Alignment;
37 import jalview.datamodel.AlignmentAnnotation;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentOrder;
40 import jalview.datamodel.AlignmentView;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.PDBEntry;
43 import jalview.datamodel.SeqCigar;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.io.AlignmentProperties;
48 import jalview.io.AnnotationFile;
49 import jalview.io.FeaturesFile;
50 import jalview.io.FileLoader;
51 import jalview.io.FormatAdapter;
52 import jalview.io.HTMLOutput;
53 import jalview.io.IdentifyFile;
54 import jalview.io.JalviewFileChooser;
55 import jalview.io.JalviewFileView;
56 import jalview.io.JnetAnnotationMaker;
57 import jalview.io.NewickFile;
58 import jalview.io.TCoffeeScoreFile;
59 import jalview.jbgui.GAlignFrame;
60 import jalview.schemes.Blosum62ColourScheme;
61 import jalview.schemes.BuriedColourScheme;
62 import jalview.schemes.ClustalxColourScheme;
63 import jalview.schemes.ColourSchemeI;
64 import jalview.schemes.ColourSchemeProperty;
65 import jalview.schemes.HelixColourScheme;
66 import jalview.schemes.HydrophobicColourScheme;
67 import jalview.schemes.NucleotideColourScheme;
68 import jalview.schemes.PIDColourScheme;
69 import jalview.schemes.PurinePyrimidineColourScheme;
70 import jalview.schemes.RNAHelicesColourChooser;
71 import jalview.schemes.ResidueProperties;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.UserColourScheme;
77 import jalview.schemes.ZappoColourScheme;
78 import jalview.ws.jws1.Discoverer;
79 import jalview.ws.jws2.Jws2Discoverer;
80 import jalview.ws.seqfetcher.DbSourceProxy;
82 import java.awt.BorderLayout;
83 import java.awt.Color;
84 import java.awt.Component;
85 import java.awt.GridLayout;
86 import java.awt.Rectangle;
87 import java.awt.Toolkit;
88 import java.awt.datatransfer.Clipboard;
89 import java.awt.datatransfer.DataFlavor;
90 import java.awt.datatransfer.StringSelection;
91 import java.awt.datatransfer.Transferable;
92 import java.awt.dnd.DnDConstants;
93 import java.awt.dnd.DropTargetDragEvent;
94 import java.awt.dnd.DropTargetDropEvent;
95 import java.awt.dnd.DropTargetEvent;
96 import java.awt.dnd.DropTargetListener;
97 import java.awt.event.ActionEvent;
98 import java.awt.event.ActionListener;
99 import java.awt.event.KeyAdapter;
100 import java.awt.event.KeyEvent;
101 import java.awt.event.MouseAdapter;
102 import java.awt.event.MouseEvent;
103 import java.awt.print.PageFormat;
104 import java.awt.print.PrinterJob;
105 import java.beans.PropertyChangeEvent;
108 import java.util.ArrayList;
109 import java.util.Enumeration;
110 import java.util.Hashtable;
111 import java.util.List;
112 import java.util.Vector;
114 import javax.swing.JButton;
115 import javax.swing.JEditorPane;
116 import javax.swing.JInternalFrame;
117 import javax.swing.JLabel;
118 import javax.swing.JLayeredPane;
119 import javax.swing.JMenu;
120 import javax.swing.JMenuItem;
121 import javax.swing.JOptionPane;
122 import javax.swing.JPanel;
123 import javax.swing.JProgressBar;
124 import javax.swing.JRadioButtonMenuItem;
125 import javax.swing.JScrollPane;
126 import javax.swing.SwingUtilities;
132 * @version $Revision$
134 public class AlignFrame extends GAlignFrame implements DropTargetListener,
139 public static final int DEFAULT_WIDTH = 700;
142 public static final int DEFAULT_HEIGHT = 500;
144 public AlignmentPanel alignPanel;
146 AlignViewport viewport;
148 Vector alignPanels = new Vector();
151 * Last format used to load or save alignments in this window
153 String currentFileFormat = null;
156 * Current filename for this alignment
158 String fileName = null;
161 * Creates a new AlignFrame object with specific width and height.
167 public AlignFrame(AlignmentI al, int width, int height)
169 this(al, null, width, height);
173 * Creates a new AlignFrame object with specific width, height and
179 * @param sequenceSetId
181 public AlignFrame(AlignmentI al, int width, int height,
182 String sequenceSetId)
184 this(al, null, width, height, sequenceSetId);
188 * Creates a new AlignFrame object with specific width, height and
194 * @param sequenceSetId
197 public AlignFrame(AlignmentI al, int width, int height,
198 String sequenceSetId, String viewId)
200 this(al, null, width, height, sequenceSetId, viewId);
204 * new alignment window with hidden columns
208 * @param hiddenColumns
209 * ColumnSelection or null
211 * Width of alignment frame
215 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
216 int width, int height)
218 this(al, hiddenColumns, width, height, null);
222 * Create alignment frame for al with hiddenColumns, a specific width and
223 * height, and specific sequenceId
226 * @param hiddenColumns
229 * @param sequenceSetId
232 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
233 int width, int height, String sequenceSetId)
235 this(al, hiddenColumns, width, height, sequenceSetId, null);
239 * Create alignment frame for al with hiddenColumns, a specific width and
240 * height, and specific sequenceId
243 * @param hiddenColumns
246 * @param sequenceSetId
251 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
252 int width, int height, String sequenceSetId, String viewId)
254 setSize(width, height);
255 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
257 alignPanel = new AlignmentPanel(this, viewport);
259 if (al.getDataset() == null)
264 addAlignmentPanel(alignPanel, true);
269 * Make a new AlignFrame from exisiting alignmentPanels
276 public AlignFrame(AlignmentPanel ap)
280 addAlignmentPanel(ap, false);
285 * initalise the alignframe from the underlying viewport data and the
290 if (viewport.getAlignmentConservationAnnotation() == null)
292 BLOSUM62Colour.setEnabled(false);
293 conservationMenuItem.setEnabled(false);
294 modifyConservation.setEnabled(false);
295 // PIDColour.setEnabled(false);
296 // abovePIDThreshold.setEnabled(false);
297 // modifyPID.setEnabled(false);
300 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
303 if (sortby.equals("Id"))
305 sortIDMenuItem_actionPerformed(null);
307 else if (sortby.equals("Pairwise Identity"))
309 sortPairwiseMenuItem_actionPerformed(null);
312 if (Desktop.desktop != null)
314 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
315 addServiceListeners();
316 setGUINucleotide(viewport.getAlignment().isNucleotide());
319 setMenusFromViewport(viewport);
320 buildSortByAnnotationScoresMenu();
321 if (viewport.wrapAlignment)
323 wrapMenuItem_actionPerformed(null);
326 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
328 this.overviewMenuItem_actionPerformed(null);
336 * Change the filename and format for the alignment, and enable the 'reload'
337 * button functionality.
344 public void setFileName(String file, String format)
347 currentFileFormat = format;
348 reload.setEnabled(true);
351 void addKeyListener()
353 addKeyListener(new KeyAdapter()
356 public void keyPressed(KeyEvent evt)
358 if (viewport.cursorMode
359 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
360 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
361 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
362 && Character.isDigit(evt.getKeyChar()))
363 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
365 switch (evt.getKeyCode())
368 case 27: // escape key
369 deselectAllSequenceMenuItem_actionPerformed(null);
373 case KeyEvent.VK_DOWN:
374 if (evt.isAltDown() || !viewport.cursorMode)
375 moveSelectedSequences(false);
376 if (viewport.cursorMode)
377 alignPanel.seqPanel.moveCursor(0, 1);
381 if (evt.isAltDown() || !viewport.cursorMode)
382 moveSelectedSequences(true);
383 if (viewport.cursorMode)
384 alignPanel.seqPanel.moveCursor(0, -1);
388 case KeyEvent.VK_LEFT:
389 if (evt.isAltDown() || !viewport.cursorMode)
390 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
392 alignPanel.seqPanel.moveCursor(-1, 0);
396 case KeyEvent.VK_RIGHT:
397 if (evt.isAltDown() || !viewport.cursorMode)
398 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
400 alignPanel.seqPanel.moveCursor(1, 0);
403 case KeyEvent.VK_SPACE:
404 if (viewport.cursorMode)
406 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
407 || evt.isShiftDown() || evt.isAltDown());
411 // case KeyEvent.VK_A:
412 // if (viewport.cursorMode)
414 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
415 // //System.out.println("A");
419 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
420 * System.out.println("closing bracket"); } break;
422 case KeyEvent.VK_DELETE:
423 case KeyEvent.VK_BACK_SPACE:
424 if (!viewport.cursorMode)
426 cut_actionPerformed(null);
430 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
431 || evt.isShiftDown() || evt.isAltDown());
437 if (viewport.cursorMode)
439 alignPanel.seqPanel.setCursorRow();
443 if (viewport.cursorMode && !evt.isControlDown())
445 alignPanel.seqPanel.setCursorColumn();
449 if (viewport.cursorMode)
451 alignPanel.seqPanel.setCursorPosition();
455 case KeyEvent.VK_ENTER:
456 case KeyEvent.VK_COMMA:
457 if (viewport.cursorMode)
459 alignPanel.seqPanel.setCursorRowAndColumn();
464 if (viewport.cursorMode)
466 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
470 if (viewport.cursorMode)
472 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
477 viewport.cursorMode = !viewport.cursorMode;
478 statusBar.setText("Keyboard editing mode is "
479 + (viewport.cursorMode ? "on" : "off"));
480 if (viewport.cursorMode)
482 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
483 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
485 alignPanel.seqPanel.seqCanvas.repaint();
491 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
492 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
494 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
496 javax.help.HelpBroker hb = hs.createHelpBroker();
497 hb.setCurrentID("home");
498 hb.setDisplayed(true);
499 } catch (Exception ex)
501 ex.printStackTrace();
506 boolean toggleSeqs = !evt.isControlDown();
507 boolean toggleCols = !evt.isShiftDown();
508 toggleHiddenRegions(toggleSeqs, toggleCols);
511 case KeyEvent.VK_PAGE_UP:
512 if (viewport.wrapAlignment)
514 alignPanel.scrollUp(true);
518 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
519 - viewport.endSeq + viewport.startSeq);
522 case KeyEvent.VK_PAGE_DOWN:
523 if (viewport.wrapAlignment)
525 alignPanel.scrollUp(false);
529 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
530 + viewport.endSeq - viewport.startSeq);
537 public void keyReleased(KeyEvent evt)
539 switch (evt.getKeyCode())
541 case KeyEvent.VK_LEFT:
542 if (evt.isAltDown() || !viewport.cursorMode)
543 viewport.firePropertyChange("alignment", null, viewport
544 .getAlignment().getSequences());
547 case KeyEvent.VK_RIGHT:
548 if (evt.isAltDown() || !viewport.cursorMode)
549 viewport.firePropertyChange("alignment", null, viewport
550 .getAlignment().getSequences());
557 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
559 ap.alignFrame = this;
561 alignPanels.addElement(ap);
563 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
565 int aSize = alignPanels.size();
567 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
569 if (aSize == 1 && ap.av.viewName == null)
571 this.getContentPane().add(ap, BorderLayout.CENTER);
577 setInitialTabVisible();
580 expandViews.setEnabled(true);
581 gatherViews.setEnabled(true);
582 tabbedPane.addTab(ap.av.viewName, ap);
584 ap.setVisible(false);
589 if (ap.av.isPadGaps())
591 ap.av.getAlignment().padGaps();
593 ap.av.updateConservation(ap);
594 ap.av.updateConsensus(ap);
595 ap.av.updateStrucConsensus(ap);
599 public void setInitialTabVisible()
601 expandViews.setEnabled(true);
602 gatherViews.setEnabled(true);
603 tabbedPane.setVisible(true);
604 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
605 tabbedPane.addTab(first.av.viewName, first);
606 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
609 public AlignViewport getViewport()
614 /* Set up intrinsic listeners for dynamically generated GUI bits. */
615 private void addServiceListeners()
617 final java.beans.PropertyChangeListener thisListener;
618 Desktop.instance.addJalviewPropertyChangeListener("services",
619 thisListener = new java.beans.PropertyChangeListener()
622 public void propertyChange(PropertyChangeEvent evt)
624 // // System.out.println("Discoverer property change.");
625 // if (evt.getPropertyName().equals("services"))
627 SwingUtilities.invokeLater(new Runnable()
634 .println("Rebuild WS Menu for service change");
635 BuildWebServiceMenu();
642 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
645 public void internalFrameClosed(
646 javax.swing.event.InternalFrameEvent evt)
648 System.out.println("deregistering discoverer listener");
649 Desktop.instance.removeJalviewPropertyChangeListener("services",
651 closeMenuItem_actionPerformed(true);
654 // Finally, build the menu once to get current service state
655 new Thread(new Runnable()
660 BuildWebServiceMenu();
665 public void setGUINucleotide(boolean nucleotide)
667 showTranslation.setVisible(nucleotide);
668 conservationMenuItem.setEnabled(!nucleotide);
669 modifyConservation.setEnabled(!nucleotide);
670 showGroupConservation.setEnabled(!nucleotide);
671 rnahelicesColour.setEnabled(nucleotide);
672 purinePyrimidineColour.setEnabled(nucleotide);
673 // Remember AlignFrame always starts as protein
677 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
682 * set up menus for the currently viewport. This may be called after any
683 * operation that affects the data in the current view (selection changed,
684 * etc) to update the menus to reflect the new state.
686 public void setMenusForViewport()
688 setMenusFromViewport(viewport);
692 * Need to call this method when tabs are selected for multiple views, or when
693 * loading from Jalview2XML.java
698 void setMenusFromViewport(AlignViewport av)
700 padGapsMenuitem.setSelected(av.isPadGaps());
701 colourTextMenuItem.setSelected(av.showColourText);
702 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
703 conservationMenuItem.setSelected(av.getConservationSelected());
704 seqLimits.setSelected(av.getShowJVSuffix());
705 idRightAlign.setSelected(av.rightAlignIds);
706 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
707 renderGapsMenuItem.setSelected(av.renderGaps);
708 wrapMenuItem.setSelected(av.wrapAlignment);
709 scaleAbove.setVisible(av.wrapAlignment);
710 scaleLeft.setVisible(av.wrapAlignment);
711 scaleRight.setVisible(av.wrapAlignment);
712 annotationPanelMenuItem.setState(av.showAnnotation);
713 viewBoxesMenuItem.setSelected(av.showBoxes);
714 viewTextMenuItem.setSelected(av.showText);
715 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
716 showGroupConsensus.setSelected(av.isShowGroupConsensus());
717 showGroupConservation.setSelected(av.isShowGroupConservation());
718 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
719 showSequenceLogo.setSelected(av.isShowSequenceLogo());
720 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
722 setColourSelected(ColourSchemeProperty.getColourName(av
723 .getGlobalColourScheme()));
725 showSeqFeatures.setSelected(av.showSequenceFeatures);
726 hiddenMarkers.setState(av.showHiddenMarkers);
727 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
728 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
729 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
730 autoCalculate.setSelected(av.autoCalculateConsensus);
731 sortByTree.setSelected(av.sortByTree);
732 listenToViewSelections.setSelected(av.followSelection);
733 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
735 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
736 setShowProductsEnabled();
741 Hashtable progressBars, progressBarHandlers;
746 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
749 public void setProgressBar(String message, long id)
751 if (progressBars == null)
753 progressBars = new Hashtable();
754 progressBarHandlers = new Hashtable();
757 JPanel progressPanel;
758 Long lId = new Long(id);
759 GridLayout layout = (GridLayout) statusPanel.getLayout();
760 if (progressBars.get(lId) != null)
762 progressPanel = (JPanel) progressBars.get(new Long(id));
763 statusPanel.remove(progressPanel);
764 progressBars.remove(lId);
765 progressPanel = null;
768 statusBar.setText(message);
770 if (progressBarHandlers.contains(lId))
772 progressBarHandlers.remove(lId);
774 layout.setRows(layout.getRows() - 1);
778 progressPanel = new JPanel(new BorderLayout(10, 5));
780 JProgressBar progressBar = new JProgressBar();
781 progressBar.setIndeterminate(true);
783 progressPanel.add(new JLabel(message), BorderLayout.WEST);
784 progressPanel.add(progressBar, BorderLayout.CENTER);
786 layout.setRows(layout.getRows() + 1);
787 statusPanel.add(progressPanel);
789 progressBars.put(lId, progressPanel);
792 // setMenusForViewport();
797 public void registerHandler(final long id,
798 final IProgressIndicatorHandler handler)
800 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
803 "call setProgressBar before registering the progress bar's handler.");
805 progressBarHandlers.put(new Long(id), handler);
806 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
807 if (handler.canCancel())
809 JButton cancel = new JButton("Cancel");
810 final IProgressIndicator us = this;
811 cancel.addActionListener(new ActionListener()
815 public void actionPerformed(ActionEvent e)
817 handler.cancelActivity(id);
820 + ((JLabel) progressPanel.getComponent(0))
824 progressPanel.add(cancel, BorderLayout.EAST);
830 * @return true if any progress bars are still active
833 public boolean operationInProgress()
835 if (progressBars != null && progressBars.size() > 0)
843 * Added so Castor Mapping file can obtain Jalview Version
845 public String getVersion()
847 return jalview.bin.Cache.getProperty("VERSION");
850 public FeatureRenderer getFeatureRenderer()
852 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
856 public void fetchSequence_actionPerformed(ActionEvent e)
858 new SequenceFetcher(this);
862 public void addFromFile_actionPerformed(ActionEvent e)
864 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
868 public void reload_actionPerformed(ActionEvent e)
870 if (fileName != null)
872 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
873 // originating file's format
874 // TODO: work out how to recover feature settings for correct view(s) when
876 if (currentFileFormat.equals("Jalview"))
878 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
879 for (int i = 0; i < frames.length; i++)
881 if (frames[i] instanceof AlignFrame && frames[i] != this
882 && ((AlignFrame) frames[i]).fileName.equals(fileName))
886 frames[i].setSelected(true);
887 Desktop.instance.closeAssociatedWindows();
888 } catch (java.beans.PropertyVetoException ex)
894 Desktop.instance.closeAssociatedWindows();
896 FileLoader loader = new FileLoader();
897 String protocol = fileName.startsWith("http:") ? "URL" : "File";
898 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
902 Rectangle bounds = this.getBounds();
904 FileLoader loader = new FileLoader();
905 String protocol = fileName.startsWith("http:") ? "URL" : "File";
906 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
907 protocol, currentFileFormat);
909 newframe.setBounds(bounds);
910 if (featureSettings != null && featureSettings.isShowing())
912 final Rectangle fspos = featureSettings.frame.getBounds();
913 // TODO: need a 'show feature settings' function that takes bounds -
914 // need to refactor Desktop.addFrame
915 newframe.featureSettings_actionPerformed(null);
916 final FeatureSettings nfs = newframe.featureSettings;
917 SwingUtilities.invokeLater(new Runnable()
922 nfs.frame.setBounds(fspos);
925 this.featureSettings.close();
926 this.featureSettings = null;
928 this.closeMenuItem_actionPerformed(true);
934 public void addFromText_actionPerformed(ActionEvent e)
936 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
940 public void addFromURL_actionPerformed(ActionEvent e)
942 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
946 public void save_actionPerformed(ActionEvent e)
949 || (currentFileFormat == null || !jalview.io.FormatAdapter
950 .isValidIOFormat(currentFileFormat, true))
951 || fileName.startsWith("http"))
953 saveAs_actionPerformed(null);
957 saveAlignment(fileName, currentFileFormat);
968 public void saveAs_actionPerformed(ActionEvent e)
970 JalviewFileChooser chooser = new JalviewFileChooser(
971 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
972 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
973 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
974 currentFileFormat, false);
976 chooser.setFileView(new JalviewFileView());
977 chooser.setDialogTitle("Save Alignment to file");
978 chooser.setToolTipText("Save");
980 int value = chooser.showSaveDialog(this);
982 if (value == JalviewFileChooser.APPROVE_OPTION)
984 currentFileFormat = chooser.getSelectedFormat();
985 if (currentFileFormat == null)
987 JOptionPane.showInternalMessageDialog(Desktop.desktop,
988 "You must select a file format before saving!",
989 "File format not specified", JOptionPane.WARNING_MESSAGE);
990 value = chooser.showSaveDialog(this);
994 fileName = chooser.getSelectedFile().getPath();
996 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
999 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1000 if (currentFileFormat.indexOf(" ") > -1)
1002 currentFileFormat = currentFileFormat.substring(0,
1003 currentFileFormat.indexOf(" "));
1005 saveAlignment(fileName, currentFileFormat);
1009 public boolean saveAlignment(String file, String format)
1011 boolean success = true;
1013 if (format.equalsIgnoreCase("Jalview"))
1015 String shortName = title;
1017 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1019 shortName = shortName.substring(shortName
1020 .lastIndexOf(java.io.File.separatorChar) + 1);
1023 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1025 statusBar.setText("Successfully saved to file: " + fileName + " in "
1026 + format + " format.");
1031 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1033 warningMessage("Cannot save file " + fileName + " using format "
1034 + format, "Alignment output format not supported");
1035 saveAs_actionPerformed(null);
1036 // JBPNote need to have a raise_gui flag here
1040 String[] omitHidden = null;
1042 if (viewport.hasHiddenColumns())
1044 int reply = JOptionPane
1045 .showInternalConfirmDialog(
1047 "The Alignment contains hidden columns."
1048 + "\nDo you want to save only the visible alignment?",
1049 "Save / Omit Hidden Columns",
1050 JOptionPane.YES_NO_OPTION,
1051 JOptionPane.QUESTION_MESSAGE);
1053 if (reply == JOptionPane.YES_OPTION)
1055 omitHidden = viewport.getViewAsString(false);
1058 FormatAdapter f = new FormatAdapter();
1059 String output = f.formatSequences(
1061 viewport.getAlignment(), // class cast exceptions will
1062 // occur in the distant future
1063 omitHidden, f.getCacheSuffixDefault(format),
1064 viewport.getColumnSelection());
1074 java.io.PrintWriter out = new java.io.PrintWriter(
1075 new java.io.FileWriter(file));
1079 this.setTitle(file);
1080 statusBar.setText("Successfully saved to file: " + fileName
1081 + " in " + format + " format.");
1082 } catch (Exception ex)
1085 ex.printStackTrace();
1092 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1093 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1099 private void warningMessage(String warning, String title)
1101 if (new jalview.util.Platform().isHeadless())
1103 System.err.println("Warning: " + title + "\nWarning: " + warning);
1108 JOptionPane.showInternalMessageDialog(this, warning, title,
1109 JOptionPane.WARNING_MESSAGE);
1121 protected void outputText_actionPerformed(ActionEvent e)
1123 String[] omitHidden = null;
1125 if (viewport.hasHiddenColumns())
1127 int reply = JOptionPane
1128 .showInternalConfirmDialog(
1130 "The Alignment contains hidden columns."
1131 + "\nDo you want to output only the visible alignment?",
1132 "Save / Omit Hidden Columns",
1133 JOptionPane.YES_NO_OPTION,
1134 JOptionPane.QUESTION_MESSAGE);
1136 if (reply == JOptionPane.YES_OPTION)
1138 omitHidden = viewport.getViewAsString(false);
1142 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1143 cap.setForInput(null);
1147 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1148 viewport.getAlignment(), omitHidden,
1149 viewport.getColumnSelection()));
1150 Desktop.addInternalFrame(cap,
1151 "Alignment output - " + e.getActionCommand(), 600, 500);
1152 } catch (OutOfMemoryError oom)
1154 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1167 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1169 new HTMLOutput(alignPanel,
1170 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1171 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1174 public void createImageMap(File file, String image)
1176 alignPanel.makePNGImageMap(file, image);
1186 public void createPNG(File f)
1188 alignPanel.makePNG(f);
1198 public void createEPS(File f)
1200 alignPanel.makeEPS(f);
1204 public void pageSetup_actionPerformed(ActionEvent e)
1206 PrinterJob printJob = PrinterJob.getPrinterJob();
1207 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1217 public void printMenuItem_actionPerformed(ActionEvent e)
1219 // Putting in a thread avoids Swing painting problems
1220 PrintThread thread = new PrintThread(alignPanel);
1225 public void exportFeatures_actionPerformed(ActionEvent e)
1227 new AnnotationExporter().exportFeatures(alignPanel);
1231 public void exportAnnotations_actionPerformed(ActionEvent e)
1233 new AnnotationExporter().exportAnnotations(alignPanel,
1234 viewport.showAnnotation ? viewport.getAlignment()
1235 .getAlignmentAnnotation() : null, viewport
1236 .getAlignment().getGroups(), ((Alignment) viewport
1237 .getAlignment()).alignmentProperties);
1241 public void associatedData_actionPerformed(ActionEvent e)
1243 // Pick the tree file
1244 JalviewFileChooser chooser = new JalviewFileChooser(
1245 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1246 chooser.setFileView(new JalviewFileView());
1247 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1248 chooser.setToolTipText("Load Jalview Annotations / Features file");
1250 int value = chooser.showOpenDialog(null);
1252 if (value == JalviewFileChooser.APPROVE_OPTION)
1254 String choice = chooser.getSelectedFile().getPath();
1255 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1256 loadJalviewDataFile(choice, null, null, null);
1262 * Close the current view or all views in the alignment frame. If the frame
1263 * only contains one view then the alignment will be removed from memory.
1265 * @param closeAllTabs
1268 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1270 if (alignPanels != null && alignPanels.size() < 2)
1272 closeAllTabs = true;
1277 if (alignPanels != null)
1281 if (this.isClosed())
1283 // really close all the windows - otherwise wait till
1284 // setClosed(true) is called
1285 for (int i = 0; i < alignPanels.size(); i++)
1287 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1294 closeView(alignPanel);
1300 this.setClosed(true);
1302 } catch (Exception ex)
1304 ex.printStackTrace();
1309 * close alignPanel2 and shuffle tabs appropriately.
1311 * @param alignPanel2
1313 public void closeView(AlignmentPanel alignPanel2)
1315 int index = tabbedPane.getSelectedIndex();
1316 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1317 alignPanels.removeElement(alignPanel2);
1319 // if (viewport == alignPanel2.av)
1323 alignPanel2.closePanel();
1326 tabbedPane.removeTabAt(closedindex);
1327 tabbedPane.validate();
1329 if (index > closedindex || index == tabbedPane.getTabCount())
1331 // modify currently selected tab index if necessary.
1335 this.tabSelectionChanged(index);
1341 void updateEditMenuBar()
1344 if (viewport.historyList.size() > 0)
1346 undoMenuItem.setEnabled(true);
1347 CommandI command = (CommandI) viewport.historyList.peek();
1348 undoMenuItem.setText("Undo " + command.getDescription());
1352 undoMenuItem.setEnabled(false);
1353 undoMenuItem.setText("Undo");
1356 if (viewport.redoList.size() > 0)
1358 redoMenuItem.setEnabled(true);
1360 CommandI command = (CommandI) viewport.redoList.peek();
1361 redoMenuItem.setText("Redo " + command.getDescription());
1365 redoMenuItem.setEnabled(false);
1366 redoMenuItem.setText("Redo");
1370 public void addHistoryItem(CommandI command)
1372 if (command.getSize() > 0)
1374 viewport.historyList.push(command);
1375 viewport.redoList.clear();
1376 updateEditMenuBar();
1377 viewport.updateHiddenColumns();
1378 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1379 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1380 // viewport.getColumnSelection()
1381 // .getHiddenColumns().size() > 0);
1387 * @return alignment objects for all views
1389 AlignmentI[] getViewAlignments()
1391 if (alignPanels != null)
1393 Enumeration e = alignPanels.elements();
1394 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1395 for (int i = 0; e.hasMoreElements(); i++)
1397 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1401 if (viewport != null)
1403 return new AlignmentI[]
1404 { viewport.getAlignment() };
1416 protected void undoMenuItem_actionPerformed(ActionEvent e)
1418 if (viewport.historyList.empty())
1420 CommandI command = (CommandI) viewport.historyList.pop();
1421 viewport.redoList.push(command);
1422 command.undoCommand(getViewAlignments());
1424 AlignViewport originalSource = getOriginatingSource(command);
1425 updateEditMenuBar();
1427 if (originalSource != null)
1429 if (originalSource != viewport)
1432 .warn("Implementation worry: mismatch of viewport origin for undo");
1434 originalSource.updateHiddenColumns();
1435 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1437 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1438 // viewport.getColumnSelection()
1439 // .getHiddenColumns().size() > 0);
1440 originalSource.firePropertyChange("alignment", null, originalSource
1441 .getAlignment().getSequences());
1452 protected void redoMenuItem_actionPerformed(ActionEvent e)
1454 if (viewport.redoList.size() < 1)
1459 CommandI command = (CommandI) viewport.redoList.pop();
1460 viewport.historyList.push(command);
1461 command.doCommand(getViewAlignments());
1463 AlignViewport originalSource = getOriginatingSource(command);
1464 updateEditMenuBar();
1466 if (originalSource != null)
1469 if (originalSource != viewport)
1472 .warn("Implementation worry: mismatch of viewport origin for redo");
1474 originalSource.updateHiddenColumns();
1475 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1477 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1478 // viewport.getColumnSelection()
1479 // .getHiddenColumns().size() > 0);
1480 originalSource.firePropertyChange("alignment", null, originalSource
1481 .getAlignment().getSequences());
1485 AlignViewport getOriginatingSource(CommandI command)
1487 AlignViewport originalSource = null;
1488 // For sequence removal and addition, we need to fire
1489 // the property change event FROM the viewport where the
1490 // original alignment was altered
1491 AlignmentI al = null;
1492 if (command instanceof EditCommand)
1494 EditCommand editCommand = (EditCommand) command;
1495 al = editCommand.getAlignment();
1496 Vector comps = (Vector) PaintRefresher.components.get(viewport
1497 .getSequenceSetId());
1499 for (int i = 0; i < comps.size(); i++)
1501 if (comps.elementAt(i) instanceof AlignmentPanel)
1503 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1505 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1512 if (originalSource == null)
1514 // The original view is closed, we must validate
1515 // the current view against the closed view first
1518 PaintRefresher.validateSequences(al, viewport.getAlignment());
1521 originalSource = viewport;
1524 return originalSource;
1533 public void moveSelectedSequences(boolean up)
1535 SequenceGroup sg = viewport.getSelectionGroup();
1541 viewport.getAlignment().moveSelectedSequencesByOne(sg, viewport.getHiddenRepSequences(), up);
1542 alignPanel.paintAlignment(true);
1545 synchronized void slideSequences(boolean right, int size)
1547 List<SequenceI> sg = new Vector();
1548 if (viewport.cursorMode)
1550 sg.add(viewport.getAlignment().getSequenceAt(
1551 alignPanel.seqPanel.seqCanvas.cursorY));
1553 else if (viewport.getSelectionGroup() != null
1554 && viewport.getSelectionGroup().getSize() != viewport
1555 .getAlignment().getHeight())
1557 sg = viewport.getSelectionGroup().getSequences(
1558 viewport.getHiddenRepSequences());
1566 Vector invertGroup = new Vector();
1568 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1570 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1571 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1574 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1576 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1577 for (int i = 0; i < invertGroup.size(); i++)
1578 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1580 SlideSequencesCommand ssc;
1582 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1583 size, viewport.getGapCharacter());
1585 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1586 size, viewport.getGapCharacter());
1588 int groupAdjustment = 0;
1589 if (ssc.getGapsInsertedBegin() && right)
1591 if (viewport.cursorMode)
1592 alignPanel.seqPanel.moveCursor(size, 0);
1594 groupAdjustment = size;
1596 else if (!ssc.getGapsInsertedBegin() && !right)
1598 if (viewport.cursorMode)
1599 alignPanel.seqPanel.moveCursor(-size, 0);
1601 groupAdjustment = -size;
1604 if (groupAdjustment != 0)
1606 viewport.getSelectionGroup().setStartRes(
1607 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1608 viewport.getSelectionGroup().setEndRes(
1609 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1612 boolean appendHistoryItem = false;
1613 if (viewport.historyList != null && viewport.historyList.size() > 0
1614 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1616 appendHistoryItem = ssc
1617 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1621 if (!appendHistoryItem)
1622 addHistoryItem(ssc);
1634 protected void copy_actionPerformed(ActionEvent e)
1637 if (viewport.getSelectionGroup() == null)
1641 // TODO: preserve the ordering of displayed alignment annotation in any
1642 // internal paste (particularly sequence associated annotation)
1643 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1644 String[] omitHidden = null;
1646 if (viewport.hasHiddenColumns())
1648 omitHidden = viewport.getViewAsString(true);
1651 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1654 StringSelection ss = new StringSelection(output);
1658 jalview.gui.Desktop.internalCopy = true;
1659 // Its really worth setting the clipboard contents
1660 // to empty before setting the large StringSelection!!
1661 Toolkit.getDefaultToolkit().getSystemClipboard()
1662 .setContents(new StringSelection(""), null);
1664 Toolkit.getDefaultToolkit().getSystemClipboard()
1665 .setContents(ss, Desktop.instance);
1666 } catch (OutOfMemoryError er)
1668 new OOMWarning("copying region", er);
1672 Vector hiddenColumns = null;
1673 if (viewport.hasHiddenColumns())
1675 hiddenColumns = new Vector();
1676 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1677 .getSelectionGroup().getEndRes();
1678 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1681 int[] region = (int[]) viewport.getColumnSelection()
1682 .getHiddenColumns().elementAt(i);
1683 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1685 hiddenColumns.addElement(new int[]
1686 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1691 Desktop.jalviewClipboard = new Object[]
1692 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1693 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1703 protected void pasteNew_actionPerformed(ActionEvent e)
1715 protected void pasteThis_actionPerformed(ActionEvent e)
1721 * Paste contents of Jalview clipboard
1723 * @param newAlignment
1724 * true to paste to a new alignment, otherwise add to this.
1726 void paste(boolean newAlignment)
1728 boolean externalPaste = true;
1731 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1732 Transferable contents = c.getContents(this);
1734 if (contents == null)
1742 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1743 if (str.length() < 1)
1748 format = new IdentifyFile().Identify(str, "Paste");
1750 } catch (OutOfMemoryError er)
1752 new OOMWarning("Out of memory pasting sequences!!", er);
1756 SequenceI[] sequences;
1757 boolean annotationAdded = false;
1758 AlignmentI alignment = null;
1760 if (Desktop.jalviewClipboard != null)
1762 // The clipboard was filled from within Jalview, we must use the
1764 // And dataset from the copied alignment
1765 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1766 // be doubly sure that we create *new* sequence objects.
1767 sequences = new SequenceI[newseq.length];
1768 for (int i = 0; i < newseq.length; i++)
1770 sequences[i] = new Sequence(newseq[i]);
1772 alignment = new Alignment(sequences);
1773 externalPaste = false;
1777 // parse the clipboard as an alignment.
1778 alignment = new FormatAdapter().readFile(str, "Paste", format);
1779 sequences = alignment.getSequencesArray();
1787 if (Desktop.jalviewClipboard != null)
1789 // dataset is inherited
1790 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1794 // new dataset is constructed
1795 alignment.setDataset(null);
1797 alwidth = alignment.getWidth() + 1;
1801 AlignmentI pastedal = alignment; // preserve pasted alignment object
1802 // Add pasted sequences and dataset into existing alignment.
1803 alignment = viewport.getAlignment();
1804 alwidth = alignment.getWidth() + 1;
1805 // decide if we need to import sequences from an existing dataset
1806 boolean importDs = Desktop.jalviewClipboard != null
1807 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1808 // importDs==true instructs us to copy over new dataset sequences from
1809 // an existing alignment
1810 Vector newDs = (importDs) ? new Vector() : null; // used to create
1811 // minimum dataset set
1813 for (int i = 0; i < sequences.length; i++)
1817 newDs.addElement(null);
1819 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1821 if (importDs && ds != null)
1823 if (!newDs.contains(ds))
1825 newDs.setElementAt(ds, i);
1826 ds = new Sequence(ds);
1827 // update with new dataset sequence
1828 sequences[i].setDatasetSequence(ds);
1832 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1837 // copy and derive new dataset sequence
1838 sequences[i] = sequences[i].deriveSequence();
1839 alignment.getDataset().addSequence(
1840 sequences[i].getDatasetSequence());
1841 // TODO: avoid creation of duplicate dataset sequences with a
1842 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1844 alignment.addSequence(sequences[i]); // merges dataset
1848 newDs.clear(); // tidy up
1850 if (pastedal.getAlignmentAnnotation() != null)
1852 // Add any annotation attached to alignment.
1853 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1854 for (int i = 0; i < alann.length; i++)
1856 annotationAdded = true;
1857 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1859 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1860 newann.padAnnotation(alwidth);
1861 alignment.addAnnotation(newann);
1871 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1872 sequences, 0, alignment.getWidth(), alignment));
1874 // Add any annotations attached to sequences
1875 for (int i = 0; i < sequences.length; i++)
1877 if (sequences[i].getAnnotation() != null)
1879 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1881 annotationAdded = true;
1882 sequences[i].getAnnotation()[a].adjustForAlignment();
1883 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1884 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1889 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1896 // propagate alignment changed.
1897 viewport.setEndSeq(alignment.getHeight());
1898 if (annotationAdded)
1900 // Duplicate sequence annotation in all views.
1901 AlignmentI[] alview = this.getViewAlignments();
1902 for (int i = 0; i < sequences.length; i++)
1904 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1907 for (int avnum = 0; avnum < alview.length; avnum++)
1909 if (alview[avnum] != alignment)
1911 // duplicate in a view other than the one with input focus
1912 int avwidth = alview[avnum].getWidth() + 1;
1913 // this relies on sann being preserved after we
1914 // modify the sequence's annotation array for each duplication
1915 for (int a = 0; a < sann.length; a++)
1917 AlignmentAnnotation newann = new AlignmentAnnotation(
1919 sequences[i].addAlignmentAnnotation(newann);
1920 newann.padAnnotation(avwidth);
1921 alview[avnum].addAnnotation(newann); // annotation was
1922 // duplicated earlier
1923 alview[avnum].setAnnotationIndex(newann, a);
1928 buildSortByAnnotationScoresMenu();
1930 viewport.firePropertyChange("alignment", null,
1931 alignment.getSequences());
1936 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1938 String newtitle = new String("Copied sequences");
1940 if (Desktop.jalviewClipboard != null
1941 && Desktop.jalviewClipboard[2] != null)
1943 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1944 for (int i = 0; i < hc.size(); i++)
1946 int[] region = (int[]) hc.elementAt(i);
1947 af.viewport.hideColumns(region[0], region[1]);
1951 // >>>This is a fix for the moment, until a better solution is
1953 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1955 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1957 // TODO: maintain provenance of an alignment, rather than just make the
1958 // title a concatenation of operations.
1961 if (title.startsWith("Copied sequences"))
1967 newtitle = newtitle.concat("- from " + title);
1972 newtitle = new String("Pasted sequences");
1975 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1980 } catch (Exception ex)
1982 ex.printStackTrace();
1983 System.out.println("Exception whilst pasting: " + ex);
1984 // could be anything being pasted in here
1996 protected void cut_actionPerformed(ActionEvent e)
1998 copy_actionPerformed(null);
1999 delete_actionPerformed(null);
2009 protected void delete_actionPerformed(ActionEvent evt)
2012 SequenceGroup sg = viewport.getSelectionGroup();
2018 Vector seqs = new Vector();
2020 for (int i = 0; i < sg.getSize(); i++)
2022 seq = sg.getSequenceAt(i);
2023 seqs.addElement(seq);
2026 // If the cut affects all sequences, remove highlighted columns
2027 if (sg.getSize() == viewport.getAlignment().getHeight())
2029 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2030 sg.getEndRes() + 1);
2033 SequenceI[] cut = new SequenceI[seqs.size()];
2034 for (int i = 0; i < seqs.size(); i++)
2036 cut[i] = (SequenceI) seqs.elementAt(i);
2040 * //ADD HISTORY ITEM
2042 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2043 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2044 viewport.getAlignment()));
2046 viewport.setSelectionGroup(null);
2047 viewport.sendSelection();
2048 viewport.getAlignment().deleteGroup(sg);
2050 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2052 if (viewport.getAlignment().getHeight() < 1)
2056 this.setClosed(true);
2057 } catch (Exception ex)
2070 protected void deleteGroups_actionPerformed(ActionEvent e)
2072 viewport.getAlignment().deleteAllGroups();
2073 viewport.sequenceColours = null;
2074 viewport.setSelectionGroup(null);
2075 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2076 alignPanel.updateAnnotation();
2077 alignPanel.paintAlignment(true);
2087 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2089 SequenceGroup sg = new SequenceGroup();
2091 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2093 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2096 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2097 viewport.setSelectionGroup(sg);
2098 viewport.sendSelection();
2099 alignPanel.paintAlignment(true);
2100 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2110 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2112 if (viewport.cursorMode)
2114 alignPanel.seqPanel.keyboardNo1 = null;
2115 alignPanel.seqPanel.keyboardNo2 = null;
2117 viewport.setSelectionGroup(null);
2118 viewport.getColumnSelection().clear();
2119 viewport.setSelectionGroup(null);
2120 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2121 alignPanel.idPanel.idCanvas.searchResults = null;
2122 alignPanel.paintAlignment(true);
2123 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2124 viewport.sendSelection();
2134 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2136 SequenceGroup sg = viewport.getSelectionGroup();
2140 selectAllSequenceMenuItem_actionPerformed(null);
2145 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2147 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2150 alignPanel.paintAlignment(true);
2151 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2152 viewport.sendSelection();
2156 public void invertColSel_actionPerformed(ActionEvent e)
2158 viewport.invertColumnSelection();
2159 alignPanel.paintAlignment(true);
2160 viewport.sendSelection();
2170 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2172 trimAlignment(true);
2182 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2184 trimAlignment(false);
2187 void trimAlignment(boolean trimLeft)
2189 ColumnSelection colSel = viewport.getColumnSelection();
2192 if (colSel.size() > 0)
2196 column = colSel.getMin();
2200 column = colSel.getMax();
2204 if (viewport.getSelectionGroup() != null)
2206 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2207 viewport.getHiddenRepSequences());
2211 seqs = viewport.getAlignment().getSequencesArray();
2214 TrimRegionCommand trimRegion;
2217 trimRegion = new TrimRegionCommand("Remove Left",
2218 TrimRegionCommand.TRIM_LEFT, seqs, column,
2219 viewport.getAlignment(), viewport.getColumnSelection(),
2220 viewport.getSelectionGroup());
2221 viewport.setStartRes(0);
2225 trimRegion = new TrimRegionCommand("Remove Right",
2226 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2227 viewport.getAlignment(), viewport.getColumnSelection(),
2228 viewport.getSelectionGroup());
2231 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2233 addHistoryItem(trimRegion);
2235 for (SequenceGroup sg :viewport.getAlignment().getGroups())
2237 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2238 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2240 viewport.getAlignment().deleteGroup(sg);
2244 viewport.firePropertyChange("alignment", null, viewport
2245 .getAlignment().getSequences());
2256 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2258 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2261 if (viewport.getSelectionGroup() != null)
2263 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2264 viewport.getHiddenRepSequences());
2265 start = viewport.getSelectionGroup().getStartRes();
2266 end = viewport.getSelectionGroup().getEndRes();
2270 seqs = viewport.getAlignment().getSequencesArray();
2273 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2274 "Remove Gapped Columns", seqs, start, end,
2275 viewport.getAlignment());
2277 addHistoryItem(removeGapCols);
2279 statusBar.setText("Removed " + removeGapCols.getSize()
2280 + " empty columns.");
2282 // This is to maintain viewport position on first residue
2283 // of first sequence
2284 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2285 int startRes = seq.findPosition(viewport.startRes);
2286 // ShiftList shifts;
2287 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2288 // edit.alColumnChanges=shifts.getInverse();
2289 // if (viewport.hasHiddenColumns)
2290 // viewport.getColumnSelection().compensateForEdits(shifts);
2291 viewport.setStartRes(seq.findIndex(startRes) - 1);
2292 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2304 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2306 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2309 if (viewport.getSelectionGroup() != null)
2311 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2312 viewport.getHiddenRepSequences());
2313 start = viewport.getSelectionGroup().getStartRes();
2314 end = viewport.getSelectionGroup().getEndRes();
2318 seqs = viewport.getAlignment().getSequencesArray();
2321 // This is to maintain viewport position on first residue
2322 // of first sequence
2323 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2324 int startRes = seq.findPosition(viewport.startRes);
2326 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2327 viewport.getAlignment()));
2329 viewport.setStartRes(seq.findIndex(startRes) - 1);
2331 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2343 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2345 viewport.setPadGaps(padGapsMenuitem.isSelected());
2346 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2352 // if (justifySeqs>0)
2354 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2367 public void findMenuItem_actionPerformed(ActionEvent e)
2373 public void newView_actionPerformed(ActionEvent e)
2380 * @param copyAnnotation
2381 * if true then duplicate all annnotation, groups and settings
2382 * @return new alignment panel, already displayed.
2384 public AlignmentPanel newView(boolean copyAnnotation)
2386 return newView(null, copyAnnotation);
2392 * title of newly created view
2393 * @return new alignment panel, already displayed.
2395 public AlignmentPanel newView(String viewTitle)
2397 return newView(viewTitle, true);
2403 * title of newly created view
2404 * @param copyAnnotation
2405 * if true then duplicate all annnotation, groups and settings
2406 * @return new alignment panel, already displayed.
2408 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2410 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2412 if (!copyAnnotation)
2414 // just remove all the current annotation except for the automatic stuff
2415 newap.av.getAlignment().deleteAllGroups();
2416 for (AlignmentAnnotation alan : newap.av.getAlignment()
2417 .getAlignmentAnnotation())
2419 if (!alan.autoCalculated)
2421 newap.av.getAlignment().deleteAnnotation(alan);
2427 newap.av.gatherViewsHere = false;
2429 if (viewport.viewName == null)
2431 viewport.viewName = "Original";
2434 newap.av.historyList = viewport.historyList;
2435 newap.av.redoList = viewport.redoList;
2437 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2438 // make sure the new view has a unique name - this is essential for Jalview
2440 boolean addFirstIndex = false;
2441 if (viewTitle == null || viewTitle.trim().length() == 0)
2444 addFirstIndex = true;
2448 index = 1;// we count from 1 if given a specific name
2450 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2451 Vector comps = (Vector) PaintRefresher.components.get(viewport
2452 .getSequenceSetId());
2453 Vector existingNames = new Vector();
2454 for (int i = 0; i < comps.size(); i++)
2456 if (comps.elementAt(i) instanceof AlignmentPanel)
2458 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2459 if (!existingNames.contains(ap.av.viewName))
2461 existingNames.addElement(ap.av.viewName);
2466 while (existingNames.contains(newViewName))
2468 newViewName = viewTitle + " " + (++index);
2471 newap.av.viewName = newViewName;
2473 addAlignmentPanel(newap, true);
2475 if (alignPanels.size() == 2)
2477 viewport.gatherViewsHere = true;
2479 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2484 public void expandViews_actionPerformed(ActionEvent e)
2486 Desktop.instance.explodeViews(this);
2490 public void gatherViews_actionPerformed(ActionEvent e)
2492 Desktop.instance.gatherViews(this);
2502 public void font_actionPerformed(ActionEvent e)
2504 new FontChooser(alignPanel);
2514 protected void seqLimit_actionPerformed(ActionEvent e)
2516 viewport.setShowJVSuffix(seqLimits.isSelected());
2518 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2519 .calculateIdWidth());
2520 alignPanel.paintAlignment(true);
2524 public void idRightAlign_actionPerformed(ActionEvent e)
2526 viewport.rightAlignIds = idRightAlign.isSelected();
2527 alignPanel.paintAlignment(true);
2531 public void centreColumnLabels_actionPerformed(ActionEvent e)
2533 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2534 alignPanel.paintAlignment(true);
2540 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2543 protected void followHighlight_actionPerformed()
2545 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2547 alignPanel.scrollToPosition(
2548 alignPanel.seqPanel.seqCanvas.searchResults, false);
2559 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2561 viewport.setColourText(colourTextMenuItem.isSelected());
2562 alignPanel.paintAlignment(true);
2572 public void wrapMenuItem_actionPerformed(ActionEvent e)
2574 scaleAbove.setVisible(wrapMenuItem.isSelected());
2575 scaleLeft.setVisible(wrapMenuItem.isSelected());
2576 scaleRight.setVisible(wrapMenuItem.isSelected());
2577 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2578 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2582 public void showAllSeqs_actionPerformed(ActionEvent e)
2584 viewport.showAllHiddenSeqs();
2588 public void showAllColumns_actionPerformed(ActionEvent e)
2590 viewport.showAllHiddenColumns();
2595 public void hideSelSequences_actionPerformed(ActionEvent e)
2597 viewport.hideAllSelectedSeqs();
2598 alignPanel.paintAlignment(true);
2602 * called by key handler and the hide all/show all menu items
2607 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2610 boolean hide = false;
2611 SequenceGroup sg = viewport.getSelectionGroup();
2612 if (!toggleSeqs && !toggleCols)
2614 // Hide everything by the current selection - this is a hack - we do the
2615 // invert and then hide
2616 // first check that there will be visible columns after the invert.
2617 if ((viewport.getColumnSelection() != null
2618 && viewport.getColumnSelection().getSelected() != null && viewport
2619 .getColumnSelection().getSelected().size() > 0)
2620 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2623 // now invert the sequence set, if required - empty selection implies
2624 // that no hiding is required.
2627 invertSequenceMenuItem_actionPerformed(null);
2628 sg = viewport.getSelectionGroup();
2632 viewport.expandColSelection(sg, true);
2633 // finally invert the column selection and get the new sequence
2635 invertColSel_actionPerformed(null);
2642 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2644 hideSelSequences_actionPerformed(null);
2647 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2650 showAllSeqs_actionPerformed(null);
2656 if (viewport.getColumnSelection().getSelected().size() > 0)
2658 hideSelColumns_actionPerformed(null);
2661 viewport.setSelectionGroup(sg);
2666 showAllColumns_actionPerformed(null);
2675 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2676 * event.ActionEvent)
2679 public void hideAllButSelection_actionPerformed(ActionEvent e)
2681 toggleHiddenRegions(false, false);
2688 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2692 public void hideAllSelection_actionPerformed(ActionEvent e)
2694 SequenceGroup sg = viewport.getSelectionGroup();
2695 viewport.expandColSelection(sg, false);
2696 viewport.hideAllSelectedSeqs();
2697 viewport.hideSelectedColumns();
2698 alignPanel.paintAlignment(true);
2705 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2709 public void showAllhidden_actionPerformed(ActionEvent e)
2711 viewport.showAllHiddenColumns();
2712 viewport.showAllHiddenSeqs();
2713 alignPanel.paintAlignment(true);
2717 public void hideSelColumns_actionPerformed(ActionEvent e)
2719 viewport.hideSelectedColumns();
2720 alignPanel.paintAlignment(true);
2724 public void hiddenMarkers_actionPerformed(ActionEvent e)
2726 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2737 protected void scaleAbove_actionPerformed(ActionEvent e)
2739 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2740 alignPanel.paintAlignment(true);
2750 protected void scaleLeft_actionPerformed(ActionEvent e)
2752 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2753 alignPanel.paintAlignment(true);
2763 protected void scaleRight_actionPerformed(ActionEvent e)
2765 viewport.setScaleRightWrapped(scaleRight.isSelected());
2766 alignPanel.paintAlignment(true);
2776 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2778 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2779 alignPanel.paintAlignment(true);
2789 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2791 viewport.setShowText(viewTextMenuItem.isSelected());
2792 alignPanel.paintAlignment(true);
2802 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2804 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2805 alignPanel.paintAlignment(true);
2808 public FeatureSettings featureSettings;
2811 public void featureSettings_actionPerformed(ActionEvent e)
2813 if (featureSettings != null)
2815 featureSettings.close();
2816 featureSettings = null;
2818 if (!showSeqFeatures.isSelected())
2820 // make sure features are actually displayed
2821 showSeqFeatures.setSelected(true);
2822 showSeqFeatures_actionPerformed(null);
2824 featureSettings = new FeatureSettings(this);
2828 * Set or clear 'Show Sequence Features'
2834 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2836 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2837 alignPanel.paintAlignment(true);
2838 if (alignPanel.getOverviewPanel() != null)
2840 alignPanel.getOverviewPanel().updateOverviewImage();
2845 * Set or clear 'Show Sequence Features'
2851 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2853 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2855 if (viewport.getShowSequenceFeaturesHeight())
2857 // ensure we're actually displaying features
2858 viewport.setShowSequenceFeatures(true);
2859 showSeqFeatures.setSelected(true);
2861 alignPanel.paintAlignment(true);
2862 if (alignPanel.getOverviewPanel() != null)
2864 alignPanel.getOverviewPanel().updateOverviewImage();
2875 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2877 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2878 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2882 public void alignmentProperties()
2884 JEditorPane editPane = new JEditorPane("text/html", "");
2885 editPane.setEditable(false);
2886 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2888 editPane.setText("<html>" + contents.toString() + "</html>");
2889 JInternalFrame frame = new JInternalFrame();
2890 frame.getContentPane().add(new JScrollPane(editPane));
2892 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2893 + getTitle(), 500, 400);
2903 public void overviewMenuItem_actionPerformed(ActionEvent e)
2905 if (alignPanel.overviewPanel != null)
2910 JInternalFrame frame = new JInternalFrame();
2911 OverviewPanel overview = new OverviewPanel(alignPanel);
2912 frame.setContentPane(overview);
2913 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2914 frame.getWidth(), frame.getHeight());
2916 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2917 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2920 public void internalFrameClosed(
2921 javax.swing.event.InternalFrameEvent evt)
2923 alignPanel.setOverviewPanel(null);
2927 alignPanel.setOverviewPanel(overview);
2931 public void textColour_actionPerformed(ActionEvent e)
2933 new TextColourChooser().chooseColour(alignPanel, null);
2943 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2955 public void clustalColour_actionPerformed(ActionEvent e)
2957 changeColour(new ClustalxColourScheme(viewport.getAlignment(), viewport.getHiddenRepSequences()));
2967 public void zappoColour_actionPerformed(ActionEvent e)
2969 changeColour(new ZappoColourScheme());
2979 public void taylorColour_actionPerformed(ActionEvent e)
2981 changeColour(new TaylorColourScheme());
2991 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2993 changeColour(new HydrophobicColourScheme());
3003 public void helixColour_actionPerformed(ActionEvent e)
3005 changeColour(new HelixColourScheme());
3015 public void strandColour_actionPerformed(ActionEvent e)
3017 changeColour(new StrandColourScheme());
3027 public void turnColour_actionPerformed(ActionEvent e)
3029 changeColour(new TurnColourScheme());
3039 public void buriedColour_actionPerformed(ActionEvent e)
3041 changeColour(new BuriedColourScheme());
3051 public void nucleotideColour_actionPerformed(ActionEvent e)
3053 changeColour(new NucleotideColourScheme());
3057 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3059 changeColour(new PurinePyrimidineColourScheme());
3063 * public void covariationColour_actionPerformed(ActionEvent e) {
3065 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3069 public void annotationColour_actionPerformed(ActionEvent e)
3071 new AnnotationColourChooser(viewport, alignPanel);
3075 public void rnahelicesColour_actionPerformed(ActionEvent e)
3077 new RNAHelicesColourChooser(viewport, alignPanel);
3087 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3089 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3098 public void changeColour(ColourSchemeI cs)
3100 // TODO: compare with applet and pull up to model method
3105 if (viewport.getAbovePIDThreshold())
3107 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3110 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3112 viewport.setGlobalColourScheme(cs);
3116 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3119 if (viewport.getConservationSelected())
3122 Alignment al = (Alignment) viewport.getAlignment();
3123 Conservation c = new Conservation("All",
3124 ResidueProperties.propHash, 3, al.getSequences(), 0,
3128 c.verdict(false, viewport.getConsPercGaps());
3130 cs.setConservation(c);
3132 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3137 cs.setConservation(null);
3140 cs.setConsensus(viewport.getSequenceConsensusHash());
3143 viewport.setGlobalColourScheme(cs);
3145 if (viewport.getColourAppliesToAllGroups())
3149 for (SequenceGroup sg:viewport.getAlignment().getGroups())
3157 if (cs instanceof ClustalxColourScheme)
3159 sg.cs = new ClustalxColourScheme(sg, viewport
3160 .getHiddenRepSequences());
3162 else if (cs instanceof UserColourScheme)
3164 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3170 sg.cs = cs.getClass().newInstance();
3171 } catch (Exception ex)
3176 if (viewport.getAbovePIDThreshold()
3177 || cs instanceof PIDColourScheme
3178 || cs instanceof Blosum62ColourScheme)
3180 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3182 sg.cs.setConsensus(AAFrequency.calculate(
3183 sg.getSequences(viewport.getHiddenRepSequences()),
3184 sg.getStartRes(), sg.getEndRes() + 1));
3188 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3191 if (viewport.getConservationSelected())
3193 Conservation c = new Conservation("Group",
3194 ResidueProperties.propHash, 3, sg.getSequences(viewport
3195 .getHiddenRepSequences()), sg.getStartRes(),
3196 sg.getEndRes() + 1);
3198 c.verdict(false, viewport.getConsPercGaps());
3199 sg.cs.setConservation(c);
3203 sg.cs.setConservation(null);
3208 if (alignPanel.getOverviewPanel() != null)
3210 alignPanel.getOverviewPanel().updateOverviewImage();
3213 alignPanel.paintAlignment(true);
3223 protected void modifyPID_actionPerformed(ActionEvent e)
3225 if (viewport.getAbovePIDThreshold()
3226 && viewport.getGlobalColourScheme() != null)
3228 SliderPanel.setPIDSliderSource(alignPanel,
3229 viewport.getGlobalColourScheme(), "Background");
3230 SliderPanel.showPIDSlider();
3241 protected void modifyConservation_actionPerformed(ActionEvent e)
3243 if (viewport.getConservationSelected()
3244 && viewport.getGlobalColourScheme() != null)
3246 SliderPanel.setConservationSlider(alignPanel,
3247 viewport.getGlobalColourScheme(), "Background");
3248 SliderPanel.showConservationSlider();
3259 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3261 viewport.setConservationSelected(conservationMenuItem.isSelected());
3263 viewport.setAbovePIDThreshold(false);
3264 abovePIDThreshold.setSelected(false);
3266 changeColour(viewport.getGlobalColourScheme());
3268 modifyConservation_actionPerformed(null);
3278 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3280 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3282 conservationMenuItem.setSelected(false);
3283 viewport.setConservationSelected(false);
3285 changeColour(viewport.getGlobalColourScheme());
3287 modifyPID_actionPerformed(null);
3297 public void userDefinedColour_actionPerformed(ActionEvent e)
3299 if (e.getActionCommand().equals("User Defined..."))
3301 new UserDefinedColours(alignPanel, null);
3305 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3306 .getUserColourSchemes().get(e.getActionCommand());
3312 public void updateUserColourMenu()
3315 Component[] menuItems = colourMenu.getMenuComponents();
3316 int i, iSize = menuItems.length;
3317 for (i = 0; i < iSize; i++)
3319 if (menuItems[i].getName() != null
3320 && menuItems[i].getName().equals("USER_DEFINED"))
3322 colourMenu.remove(menuItems[i]);
3326 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3328 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3329 .getUserColourSchemes().keys();
3331 while (userColours.hasMoreElements())
3333 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3334 userColours.nextElement().toString());
3335 radioItem.setName("USER_DEFINED");
3336 radioItem.addMouseListener(new MouseAdapter()
3339 public void mousePressed(MouseEvent evt)
3341 if (evt.isControlDown()
3342 || SwingUtilities.isRightMouseButton(evt))
3344 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3346 int option = JOptionPane.showInternalConfirmDialog(
3347 jalview.gui.Desktop.desktop,
3348 "Remove from default list?",
3349 "Remove user defined colour",
3350 JOptionPane.YES_NO_OPTION);
3351 if (option == JOptionPane.YES_OPTION)
3353 jalview.gui.UserDefinedColours
3354 .removeColourFromDefaults(radioItem.getText());
3355 colourMenu.remove(radioItem);
3359 radioItem.addActionListener(new ActionListener()
3362 public void actionPerformed(ActionEvent evt)
3364 userDefinedColour_actionPerformed(evt);
3371 radioItem.addActionListener(new ActionListener()
3374 public void actionPerformed(ActionEvent evt)
3376 userDefinedColour_actionPerformed(evt);
3380 colourMenu.insert(radioItem, 15);
3381 colours.add(radioItem);
3393 public void PIDColour_actionPerformed(ActionEvent e)
3395 changeColour(new PIDColourScheme());
3405 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3407 changeColour(new Blosum62ColourScheme());
3417 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3419 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3420 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3421 .getAlignment().getSequenceAt(0), null);
3422 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3423 viewport.getAlignment()));
3424 alignPanel.paintAlignment(true);
3434 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3436 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3437 AlignmentSorter.sortByID(viewport.getAlignment());
3438 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3439 viewport.getAlignment()));
3440 alignPanel.paintAlignment(true);
3450 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3452 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3453 AlignmentSorter.sortByLength(viewport.getAlignment());
3454 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3455 viewport.getAlignment()));
3456 alignPanel.paintAlignment(true);
3466 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3468 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3469 AlignmentSorter.sortByGroup(viewport.getAlignment());
3470 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3471 viewport.getAlignment()));
3473 alignPanel.paintAlignment(true);
3483 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3485 new RedundancyPanel(alignPanel, this);
3495 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3497 if ((viewport.getSelectionGroup() == null)
3498 || (viewport.getSelectionGroup().getSize() < 2))
3500 JOptionPane.showInternalMessageDialog(this,
3501 "You must select at least 2 sequences.", "Invalid Selection",
3502 JOptionPane.WARNING_MESSAGE);
3506 JInternalFrame frame = new JInternalFrame();
3507 frame.setContentPane(new PairwiseAlignPanel(viewport));
3508 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3519 public void PCAMenuItem_actionPerformed(ActionEvent e)
3521 if (((viewport.getSelectionGroup() != null)
3522 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3523 .getSelectionGroup().getSize() > 0))
3524 || (viewport.getAlignment().getHeight() < 4))
3526 JOptionPane.showInternalMessageDialog(this,
3527 "Principal component analysis must take\n"
3528 + "at least 4 input sequences.",
3529 "Sequence selection insufficient",
3530 JOptionPane.WARNING_MESSAGE);
3535 new PCAPanel(alignPanel);
3539 public void autoCalculate_actionPerformed(ActionEvent e)
3541 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3542 if (viewport.autoCalculateConsensus)
3544 viewport.firePropertyChange("alignment", null, viewport
3545 .getAlignment().getSequences());
3550 public void sortByTreeOption_actionPerformed(ActionEvent e)
3552 viewport.sortByTree = sortByTree.isSelected();
3556 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3558 viewport.followSelection = listenToViewSelections.isSelected();
3568 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3570 NewTreePanel("AV", "PID", "Average distance tree using PID");
3580 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3582 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3592 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3594 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3604 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3606 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3619 void NewTreePanel(String type, String pwType, String title)
3623 if (viewport.getSelectionGroup() != null)
3625 if (viewport.getSelectionGroup().getSize() < 3)
3630 "You need to have more than two sequences selected to build a tree!",
3631 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3635 SequenceGroup sg = viewport.getSelectionGroup();
3637 /* Decide if the selection is a column region */
3638 for (SequenceI _s:sg.getSequences())
3640 if (_s.getLength() < sg
3646 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3647 + "Try using the Pad function in the edit menu,\n"
3648 + "or one of the multiple sequence alignment web services.",
3649 "Sequences in selection are not aligned",
3650 JOptionPane.WARNING_MESSAGE);
3656 title = title + " on region";
3657 tp = new TreePanel(alignPanel, type, pwType);
3661 // are the visible sequences aligned?
3662 if (!viewport.getAlignment().isAligned(false))
3667 "The sequences must be aligned before creating a tree.\n"
3668 + "Try using the Pad function in the edit menu,\n"
3669 + "or one of the multiple sequence alignment web services.",
3670 "Sequences not aligned",
3671 JOptionPane.WARNING_MESSAGE);
3676 if (viewport.getAlignment().getHeight() < 2)
3681 tp = new TreePanel(alignPanel, type, pwType);
3686 if (viewport.viewName != null)
3688 title += viewport.viewName + " of ";
3691 title += this.title;
3693 Desktop.addInternalFrame(tp, title, 600, 500);
3704 public void addSortByOrderMenuItem(String title,
3705 final AlignmentOrder order)
3707 final JMenuItem item = new JMenuItem("by " + title);
3709 item.addActionListener(new java.awt.event.ActionListener()
3712 public void actionPerformed(ActionEvent e)
3714 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3716 // TODO: JBPNote - have to map order entries to curent SequenceI
3718 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3720 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3723 alignPanel.paintAlignment(true);
3729 * Add a new sort by annotation score menu item
3732 * the menu to add the option to
3734 * the label used to retrieve scores for each sequence on the
3737 public void addSortByAnnotScoreMenuItem(JMenu sort,
3738 final String scoreLabel)
3740 final JMenuItem item = new JMenuItem(scoreLabel);
3742 item.addActionListener(new java.awt.event.ActionListener()
3745 public void actionPerformed(ActionEvent e)
3747 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3748 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3749 viewport.getAlignment());// ,viewport.getSelectionGroup());
3750 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3751 viewport.getAlignment()));
3752 alignPanel.paintAlignment(true);
3758 * last hash for alignment's annotation array - used to minimise cost of
3761 protected int _annotationScoreVectorHash;
3764 * search the alignment and rebuild the sort by annotation score submenu the
3765 * last alignment annotation vector hash is stored to minimize cost of
3766 * rebuilding in subsequence calls.
3770 public void buildSortByAnnotationScoresMenu()
3772 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3777 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3779 sortByAnnotScore.removeAll();
3780 // almost certainly a quicker way to do this - but we keep it simple
3781 Hashtable scoreSorts = new Hashtable();
3782 AlignmentAnnotation aann[];
3783 for (SequenceI sqa:viewport.getAlignment().getSequences())
3785 aann = sqa.getAnnotation();
3786 for (int i = 0; aann != null && i < aann.length; i++)
3788 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3790 scoreSorts.put(aann[i].label, aann[i].label);
3794 Enumeration labels = scoreSorts.keys();
3795 while (labels.hasMoreElements())
3797 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3798 (String) labels.nextElement());
3800 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3803 _annotationScoreVectorHash = viewport.getAlignment()
3804 .getAlignmentAnnotation().hashCode();
3809 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3810 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3811 * call. Listeners are added to remove the menu item when the treePanel is
3812 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3816 * Displayed tree window.
3818 * SortBy menu item title.
3821 public void buildTreeMenu()
3823 sortByTreeMenu.removeAll();
3825 Vector comps = (Vector) PaintRefresher.components.get(viewport
3826 .getSequenceSetId());
3827 Vector treePanels = new Vector();
3828 int i, iSize = comps.size();
3829 for (i = 0; i < iSize; i++)
3831 if (comps.elementAt(i) instanceof TreePanel)
3833 treePanels.add(comps.elementAt(i));
3837 iSize = treePanels.size();
3841 sortByTreeMenu.setVisible(false);
3845 sortByTreeMenu.setVisible(true);
3847 for (i = 0; i < treePanels.size(); i++)
3849 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3850 final JMenuItem item = new JMenuItem(tp.getTitle());
3851 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3852 item.addActionListener(new java.awt.event.ActionListener()
3855 public void actionPerformed(ActionEvent e)
3857 tp.sortByTree_actionPerformed(null);
3858 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3863 sortByTreeMenu.add(item);
3867 public boolean sortBy(AlignmentOrder alorder, String undoname)
3869 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3870 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3871 if (undoname != null)
3873 addHistoryItem(new OrderCommand(undoname, oldOrder,
3874 viewport.getAlignment()));
3876 alignPanel.paintAlignment(true);
3881 * Work out whether the whole set of sequences or just the selected set will
3882 * be submitted for multiple alignment.
3885 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3887 // Now, check we have enough sequences
3888 AlignmentView msa = null;
3890 if ((viewport.getSelectionGroup() != null)
3891 && (viewport.getSelectionGroup().getSize() > 1))
3893 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3894 // some common interface!
3896 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3897 * SequenceI[sz = seqs.getSize(false)];
3899 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3900 * seqs.getSequenceAt(i); }
3902 msa = viewport.getAlignmentView(true);
3907 * Vector seqs = viewport.getAlignment().getSequences();
3909 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3911 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3912 * seqs.elementAt(i); } }
3914 msa = viewport.getAlignmentView(false);
3920 * Decides what is submitted to a secondary structure prediction service: the
3921 * first sequence in the alignment, or in the current selection, or, if the
3922 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3923 * region or the whole alignment. (where the first sequence in the set is the
3924 * one that the prediction will be for).
3926 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3928 AlignmentView seqs = null;
3930 if ((viewport.getSelectionGroup() != null)
3931 && (viewport.getSelectionGroup().getSize() > 0))
3933 seqs = viewport.getAlignmentView(true);
3937 seqs = viewport.getAlignmentView(false);
3939 // limit sequences - JBPNote in future - could spawn multiple prediction
3941 // TODO: viewport.getAlignment().isAligned is a global state - the local
3942 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3943 if (!viewport.getAlignment().isAligned(false))
3945 seqs.setSequences(new SeqCigar[]
3946 { seqs.getSequences()[0] });
3947 // TODO: if seqs.getSequences().length>1 then should really have warned
3961 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3963 // Pick the tree file
3964 JalviewFileChooser chooser = new JalviewFileChooser(
3965 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3966 chooser.setFileView(new JalviewFileView());
3967 chooser.setDialogTitle("Select a newick-like tree file");
3968 chooser.setToolTipText("Load a tree file");
3970 int value = chooser.showOpenDialog(null);
3972 if (value == JalviewFileChooser.APPROVE_OPTION)
3974 String choice = chooser.getSelectedFile().getPath();
3975 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3976 jalview.io.NewickFile fin = null;
3979 fin = new jalview.io.NewickFile(choice, "File");
3980 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3981 } catch (Exception ex)
3983 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3984 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3985 ex.printStackTrace();
3987 if (fin != null && fin.hasWarningMessage())
3989 JOptionPane.showMessageDialog(Desktop.desktop,
3990 fin.getWarningMessage(), "Possible problem with tree file",
3991 JOptionPane.WARNING_MESSAGE);
3997 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
3999 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4002 public TreePanel ShowNewickTree(NewickFile nf, String title)
4004 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4007 public TreePanel ShowNewickTree(NewickFile nf, String title,
4008 AlignmentView input)
4010 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4013 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4014 int h, int x, int y)
4016 return ShowNewickTree(nf, title, null, w, h, x, y);
4020 * Add a treeviewer for the tree extracted from a newick file object to the
4021 * current alignment view
4028 * Associated alignment input data (or null)
4037 * @return TreePanel handle
4039 public TreePanel ShowNewickTree(NewickFile nf, String title,
4040 AlignmentView input, int w, int h, int x, int y)
4042 TreePanel tp = null;
4048 if (nf.getTree() != null)
4050 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4056 tp.setLocation(x, y);
4059 Desktop.addInternalFrame(tp, title, w, h);
4061 } catch (Exception ex)
4063 ex.printStackTrace();
4069 private boolean buildingMenu = false;
4072 * Generates menu items and listener event actions for web service clients
4075 public void BuildWebServiceMenu()
4077 while (buildingMenu)
4081 System.err.println("Waiting for building menu to finish.");
4083 } catch (Exception e)
4088 final AlignFrame me = this;
4089 buildingMenu = true;
4090 new Thread(new Runnable()
4097 System.err.println("Building ws menu again "
4098 + Thread.currentThread());
4099 // TODO: add support for context dependent disabling of services based
4101 // alignment and current selection
4102 // TODO: add additional serviceHandle parameter to specify abstract
4104 // class independently of AbstractName
4105 // TODO: add in rediscovery GUI function to restart discoverer
4106 // TODO: group services by location as well as function and/or
4108 // object broker mechanism.
4109 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4110 final IProgressIndicator af = me;
4111 final JMenu msawsmenu = new JMenu("Alignment");
4112 final JMenu secstrmenu = new JMenu(
4113 "Secondary Structure Prediction");
4114 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4115 final JMenu analymenu = new JMenu("Analysis");
4116 final JMenu dismenu = new JMenu("Disorder");
4117 // JAL-940 - only show secondary structure prediction services from
4118 // the legacy server
4119 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4121 Discoverer.services != null && (Discoverer.services.size() > 0))
4123 // TODO: refactor to allow list of AbstractName/Handler bindings to
4125 // stored or retrieved from elsewhere
4126 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4127 Vector secstrpr = (Vector) Discoverer.services
4129 Vector seqsrch = null; // (Vector)
4130 // Discoverer.services.get("SeqSearch");
4131 // TODO: move GUI generation code onto service implementation - so a
4132 // client instance attaches itself to the GUI with method call like
4133 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4137 // Add any Multiple Sequence Alignment Services
4138 for (int i = 0, j = msaws.size(); i < j; i++)
4140 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4142 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4143 .getServiceClient(sh);
4144 impl.attachWSMenuEntry(msawsmenu, me);
4148 if (secstrpr != null)
4150 // Add any secondary structure prediction services
4151 for (int i = 0, j = secstrpr.size(); i < j; i++)
4153 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4155 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4156 .getServiceClient(sh);
4157 impl.attachWSMenuEntry(secstrmenu, me);
4160 if (seqsrch != null)
4162 // Add any sequence search services
4163 for (int i = 0, j = seqsrch.size(); i < j; i++)
4165 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4167 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4168 .getServiceClient(sh);
4169 impl.attachWSMenuEntry(seqsrchmenu, me);
4174 // Add all submenus in the order they should appear on the web
4176 wsmenu.add(msawsmenu);
4177 wsmenu.add(secstrmenu);
4178 wsmenu.add(dismenu);
4179 wsmenu.add(analymenu);
4180 // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
4181 // submens.add(msawsmenu);
4182 // submens.add(secstrmenu);
4183 // submens.add(dismenu);
4184 // submens.add(analymenu);
4186 // No search services yet
4187 // wsmenu.add(seqsrchmenu);
4189 javax.swing.SwingUtilities.invokeLater(new Runnable()
4196 webService.removeAll();
4197 // first, add discovered services onto the webservices menu
4198 if (wsmenu.size() > 0)
4200 for (int i = 0, j = wsmenu.size(); i < j; i++)
4202 webService.add(wsmenu.get(i));
4207 webService.add(me.webServiceNoServices);
4209 // TODO: move into separate menu builder class.
4210 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4212 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4213 if (jws2servs != null)
4215 if (jws2servs.hasServices())
4217 jws2servs.attachWSMenuEntry(webService, me);
4219 if (jws2servs.isRunning())
4221 JMenuItem tm = new JMenuItem(
4222 "Still discovering JABA Services");
4223 tm.setEnabled(false);
4229 build_urlServiceMenu(me.webService);
4230 build_fetchdbmenu(webService);
4231 for (JMenu item : wsmenu)
4233 if (item.getItemCount() == 0)
4235 item.setEnabled(false);
4239 item.setEnabled(true);
4242 } catch (Exception e)
4248 } catch (Exception e)
4253 buildingMenu = false;
4260 * construct any groupURL type service menu entries.
4264 private void build_urlServiceMenu(JMenu webService)
4266 // TODO: remove this code when 2.7 is released
4267 // DEBUG - alignmentView
4269 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4270 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4272 * @Override public void actionPerformed(ActionEvent e) {
4273 * jalview.datamodel.AlignmentView
4274 * .testSelectionViews(af.viewport.getAlignment(),
4275 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4277 * }); webService.add(testAlView);
4279 // TODO: refactor to RestClient discoverer and merge menu entries for
4280 // rest-style services with other types of analysis/calculation service
4281 // SHmmr test client - still being implemented.
4282 // DEBUG - alignmentView
4284 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4287 client.attachWSMenuEntry(
4288 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4292 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4294 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4300 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4301 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4302 * getProperty("LAST_DIRECTORY"));
4304 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4305 * to Vamsas file"); chooser.setToolTipText("Export");
4307 * int value = chooser.showSaveDialog(this);
4309 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4310 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4311 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4312 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4315 * prototype of an automatically enabled/disabled analysis function
4318 protected void setShowProductsEnabled()
4320 SequenceI[] selection = viewport.getSequenceSelection();
4321 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4322 viewport.getAlignment().getDataset()))
4324 showProducts.setEnabled(true);
4329 showProducts.setEnabled(false);
4334 * search selection for sequence xRef products and build the show products
4339 * @return true if showProducts menu should be enabled.
4341 public boolean canShowProducts(SequenceI[] selection,
4342 boolean isRegionSelection, Alignment dataset)
4344 boolean showp = false;
4347 showProducts.removeAll();
4348 final boolean dna = viewport.getAlignment().isNucleotide();
4349 final Alignment ds = dataset;
4350 String[] ptypes = (selection == null || selection.length == 0) ? null
4351 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4353 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4354 // selection, dataset, true);
4355 final SequenceI[] sel = selection;
4356 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4359 final boolean isRegSel = isRegionSelection;
4360 final AlignFrame af = this;
4361 final String source = ptypes[t];
4362 JMenuItem xtype = new JMenuItem(ptypes[t]);
4363 xtype.addActionListener(new ActionListener()
4367 public void actionPerformed(ActionEvent e)
4369 // TODO: new thread for this call with vis-delay
4370 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4371 isRegSel, dna, source);
4375 showProducts.add(xtype);
4377 showProducts.setVisible(showp);
4378 showProducts.setEnabled(showp);
4379 } catch (Exception e)
4381 jalview.bin.Cache.log
4382 .warn("canTranslate threw an exception - please report to help@jalview.org",
4389 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4390 boolean isRegSel, boolean dna, String source)
4392 final boolean fisRegSel = isRegSel;
4393 final boolean fdna = dna;
4394 final String fsrc = source;
4395 final AlignFrame ths = this;
4396 final SequenceI[] fsel = sel;
4397 Runnable foo = new Runnable()
4403 final long sttime = System.currentTimeMillis();
4404 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4407 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4411 Alignment prods = CrossRef
4412 .findXrefSequences(fsel, fdna, fsrc, ds);
4415 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4416 for (int s = 0; s < sprods.length; s++)
4418 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4419 if (ds.getSequences() == null
4420 || !ds.getSequences().contains(
4421 sprods[s].getDatasetSequence()))
4422 ds.addSequence(sprods[s].getDatasetSequence());
4423 sprods[s].updatePDBIds();
4425 Alignment al = new Alignment(sprods);
4426 AlignedCodonFrame[] cf = prods.getCodonFrames();
4428 for (int s = 0; cf != null && s < cf.length; s++)
4430 al.addCodonFrame(cf[s]);
4433 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4435 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4436 + " for " + ((fisRegSel) ? "selected region of " : "")
4438 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4443 System.err.println("No Sequences generated for xRef type "
4446 } catch (Exception e)
4448 jalview.bin.Cache.log.error(
4449 "Exception when finding crossreferences", e);
4450 } catch (OutOfMemoryError e)
4452 new OOMWarning("whilst fetching crossreferences", e);
4455 jalview.bin.Cache.log.error("Error when finding crossreferences",
4458 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4463 Thread frunner = new Thread(foo);
4467 public boolean canShowTranslationProducts(SequenceI[] selection,
4468 AlignmentI alignment)
4473 return (jalview.analysis.Dna.canTranslate(selection,
4474 viewport.getViewAsVisibleContigs(true)));
4475 } catch (Exception e)
4477 jalview.bin.Cache.log
4478 .warn("canTranslate threw an exception - please report to help@jalview.org",
4485 public void showProducts_actionPerformed(ActionEvent e)
4487 // /////////////////////////////
4488 // Collect Data to be translated/transferred
4490 SequenceI[] selection = viewport.getSequenceSelection();
4491 AlignmentI al = null;
4494 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4495 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4496 viewport.getAlignment().getDataset());
4497 } catch (Exception ex)
4500 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4507 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4508 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4512 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4513 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4514 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4519 public void showTranslation_actionPerformed(ActionEvent e)
4521 // /////////////////////////////
4522 // Collect Data to be translated/transferred
4524 SequenceI[] selection = viewport.getSequenceSelection();
4525 String[] seqstring = viewport.getViewAsString(true);
4526 AlignmentI al = null;
4529 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4530 viewport.getViewAsVisibleContigs(true), viewport
4531 .getGapCharacter(), viewport.getAlignment()
4532 .getAlignmentAnnotation(), viewport.getAlignment()
4533 .getWidth(), viewport.getAlignment().getDataset());
4534 } catch (Exception ex)
4537 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4544 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4545 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4549 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4550 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4551 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4556 * Try to load a features file onto the alignment.
4559 * contents or path to retrieve file
4561 * access mode of file (see jalview.io.AlignFile)
4562 * @return true if features file was parsed corectly.
4564 public boolean parseFeaturesFile(String file, String type)
4566 boolean featuresFile = false;
4569 featuresFile = new FeaturesFile(file, type).parse(viewport
4570 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4571 .getFeatureRenderer().featureColours, false,
4572 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4573 } catch (Exception ex)
4575 ex.printStackTrace();
4580 viewport.showSequenceFeatures = true;
4581 showSeqFeatures.setSelected(true);
4582 if (alignPanel.seqPanel.seqCanvas.fr != null)
4584 // update the min/max ranges where necessary
4585 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4587 if (featureSettings != null)
4589 featureSettings.setTableData();
4591 alignPanel.paintAlignment(true);
4594 return featuresFile;
4598 public void dragEnter(DropTargetDragEvent evt)
4603 public void dragExit(DropTargetEvent evt)
4608 public void dragOver(DropTargetDragEvent evt)
4613 public void dropActionChanged(DropTargetDragEvent evt)
4618 public void drop(DropTargetDropEvent evt)
4620 Transferable t = evt.getTransferable();
4621 java.util.List files = null;
4625 DataFlavor uriListFlavor = new DataFlavor(
4626 "text/uri-list;class=java.lang.String");
4627 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4629 // Works on Windows and MacOSX
4630 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4631 files = (java.util.List) t
4632 .getTransferData(DataFlavor.javaFileListFlavor);
4634 else if (t.isDataFlavorSupported(uriListFlavor))
4636 // This is used by Unix drag system
4637 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4638 String data = (String) t.getTransferData(uriListFlavor);
4639 files = new java.util.ArrayList(1);
4640 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4641 data, "\r\n"); st.hasMoreTokens();)
4643 String s = st.nextToken();
4644 if (s.startsWith("#"))
4646 // the line is a comment (as per the RFC 2483)
4650 java.net.URI uri = new java.net.URI(s);
4651 // check to see if we can handle this kind of URI
4652 if (uri.getScheme().toLowerCase().startsWith("http"))
4654 files.add(uri.toString());
4658 // otherwise preserve old behaviour: catch all for file objects
4659 java.io.File file = new java.io.File(uri);
4660 files.add(file.toString());
4664 } catch (Exception e)
4666 e.printStackTrace();
4672 // check to see if any of these files have names matching sequences in
4674 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4675 .getAlignment().getSequencesArray());
4677 * Object[] { String,SequenceI}
4679 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4680 ArrayList<String> filesnotmatched = new ArrayList<String>();
4681 for (int i = 0; i < files.size(); i++)
4683 String file = files.get(i).toString();
4685 String protocol = FormatAdapter.checkProtocol(file);
4686 if (protocol == jalview.io.FormatAdapter.FILE)
4688 File fl = new File(file);
4689 pdbfn = fl.getName();
4691 else if (protocol == jalview.io.FormatAdapter.URL)
4693 URL url = new URL(file);
4694 pdbfn = url.getFile();
4696 if (pdbfn.length() > 0)
4698 // attempt to find a match in the alignment
4699 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4700 int l = 0, c = pdbfn.indexOf(".");
4701 while (mtch == null && c != -1)
4706 } while ((c = pdbfn.indexOf(".", l)) > l);
4709 pdbfn = pdbfn.substring(0, l);
4711 mtch = idm.findAllIdMatches(pdbfn);
4718 type = new IdentifyFile().Identify(file, protocol);
4719 } catch (Exception ex)
4725 if (type.equalsIgnoreCase("PDB"))
4727 filesmatched.add(new Object[]
4728 { file, protocol, mtch });
4733 // File wasn't named like one of the sequences or wasn't a PDB file.
4734 filesnotmatched.add(file);
4738 if (filesmatched.size() > 0)
4740 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4744 "Do you want to automatically associate the "
4745 + filesmatched.size()
4746 + " PDB files with sequences in the alignment that have the same name ?",
4747 "Automatically Associate PDB files by name",
4748 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4751 for (Object[] fm : filesmatched)
4753 // try and associate
4754 // TODO: may want to set a standard ID naming formalism for
4755 // associating PDB files which have no IDs.
4756 for (SequenceI toassoc : (SequenceI[]) fm[2])
4758 PDBEntry pe = new AssociatePdbFileWithSeq()
4759 .associatePdbWithSeq((String) fm[0],
4760 (String) fm[1], toassoc, false);
4763 System.err.println("Associated file : "
4764 + ((String) fm[0]) + " with "
4765 + toassoc.getDisplayId(true));
4769 alignPanel.paintAlignment(true);
4773 if (filesnotmatched.size() > 0)
4776 && (Cache.getDefault(
4777 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4780 "<html>Do you want to <em>ignore</em> the "
4781 + filesnotmatched.size()
4782 + " files whose names did not match any sequence IDs ?</html>",
4783 "Ignore unmatched dropped files ?",
4784 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4788 for (String fn : filesnotmatched)
4790 loadJalviewDataFile(fn, null, null, null);
4794 } catch (Exception ex)
4796 ex.printStackTrace();
4802 * Attempt to load a "dropped" file or URL string: First by testing whether
4803 * it's and Annotation file, then a JNet file, and finally a features file. If
4804 * all are false then the user may have dropped an alignment file onto this
4808 * either a filename or a URL string.
4810 public void loadJalviewDataFile(String file, String protocol,
4811 String format, SequenceI assocSeq)
4815 if (protocol == null)
4817 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4819 // if the file isn't identified, or not positively identified as some
4820 // other filetype (PFAM is default unidentified alignment file type) then
4821 // try to parse as annotation.
4822 boolean isAnnotation = (format == null || format
4823 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4824 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4829 // first see if its a T-COFFEE score file
4830 TCoffeeScoreFile tcf = null;
4833 tcf = new TCoffeeScoreFile(file, protocol);
4836 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4838 tcoffeeColour.setEnabled(true);
4839 tcoffeeColour.setSelected(true);
4840 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4841 isAnnotation = true;
4843 .setText("Successfully pasted T-Coffee scores to alignment.");
4847 // some problem - if no warning its probable that the ID matching process didn't work
4848 JOptionPane.showMessageDialog(Desktop.desktop,
4849 tcf.getWarningMessage()==null ? "Check that the file matches sequence IDs in the alignment." : tcf.getWarningMessage(),
4850 "Problem reading T-COFFEE score file",
4851 JOptionPane.WARNING_MESSAGE);
4858 } catch (Exception x)
4860 Cache.log.debug("Exception when processing data source as T-COFFEE score file",x);
4865 // try to see if its a JNet 'concise' style annotation file *before*
4867 // try to parse it as a features file
4870 format = new IdentifyFile().Identify(file, protocol);
4872 if (format.equalsIgnoreCase("JnetFile"))
4874 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4876 new JnetAnnotationMaker().add_annotation(predictions,
4877 viewport.getAlignment(), 0, false);
4878 isAnnotation = true;
4883 * if (format.equalsIgnoreCase("PDB")) {
4885 * String pdbfn = ""; // try to match up filename with sequence id
4886 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4887 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4888 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4889 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4890 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4891 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4892 * // attempt to find a match in the alignment SequenceI mtch =
4893 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4894 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4895 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4896 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4897 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4898 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4899 * { System.err.println("Associated file : " + file + " with " +
4900 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4901 * TODO: maybe need to load as normal otherwise return; } }
4903 // try to parse it as a features file
4904 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4905 // if it wasn't a features file then we just treat it as a general
4906 // alignment file to load into the current view.
4909 new FileLoader().LoadFile(viewport, file, protocol, format);
4913 alignPanel.paintAlignment(true);
4921 alignPanel.adjustAnnotationHeight();
4922 viewport.updateSequenceIdColours();
4923 buildSortByAnnotationScoresMenu();
4924 alignPanel.paintAlignment(true);
4926 } catch (Exception ex)
4928 ex.printStackTrace();
4933 public void tabSelectionChanged(int index)
4937 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4938 viewport = alignPanel.av;
4939 setMenusFromViewport(viewport);
4944 public void tabbedPane_mousePressed(MouseEvent e)
4946 if (SwingUtilities.isRightMouseButton(e))
4948 String reply = JOptionPane.showInternalInputDialog(this,
4949 "Enter View Name", "Edit View Name",
4950 JOptionPane.QUESTION_MESSAGE);
4954 viewport.viewName = reply;
4955 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4960 public AlignViewport getCurrentView()
4966 * Open the dialog for regex description parsing.
4969 protected void extractScores_actionPerformed(ActionEvent e)
4971 ParseProperties pp = new jalview.analysis.ParseProperties(
4972 viewport.getAlignment());
4973 // TODO: verify regex and introduce GUI dialog for version 2.5
4974 // if (pp.getScoresFromDescription("col", "score column ",
4975 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4977 if (pp.getScoresFromDescription("description column",
4978 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4980 buildSortByAnnotationScoresMenu();
4988 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4992 protected void showDbRefs_actionPerformed(ActionEvent e)
4994 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5000 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5004 protected void showNpFeats_actionPerformed(ActionEvent e)
5006 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5010 * find the viewport amongst the tabs in this alignment frame and close that
5015 public boolean closeView(AlignViewport av)
5019 this.closeMenuItem_actionPerformed(false);
5022 Component[] comp = tabbedPane.getComponents();
5023 for (int i = 0; comp != null && i < comp.length; i++)
5025 if (comp[i] instanceof AlignmentPanel)
5027 if (((AlignmentPanel) comp[i]).av == av)
5030 closeView((AlignmentPanel) comp[i]);
5038 protected void build_fetchdbmenu(JMenu webService)
5040 // Temporary hack - DBRef Fetcher always top level ws entry.
5041 // TODO We probably want to store a sequence database checklist in
5042 // preferences and have checkboxes.. rather than individual sources selected
5044 final JMenu rfetch = new JMenu("Fetch DB References");
5045 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5046 webService.add(rfetch);
5048 JMenuItem fetchr = new JMenuItem("Standard Databases");
5049 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5050 fetchr.addActionListener(new ActionListener()
5054 public void actionPerformed(ActionEvent e)
5056 new Thread(new Runnable()
5062 new jalview.ws.DBRefFetcher(alignPanel.av
5063 .getSequenceSelection(), alignPanel.alignFrame)
5064 .fetchDBRefs(false);
5072 final AlignFrame me = this;
5073 new Thread(new Runnable()
5078 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5079 .getSequenceFetcherSingleton(me);
5080 javax.swing.SwingUtilities.invokeLater(new Runnable()
5085 String[] dbclasses = sf.getOrderedSupportedSources();
5086 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5087 // jalview.util.QuickSort.sort(otherdb, otherdb);
5088 List<DbSourceProxy> otherdb;
5089 JMenu dfetch = new JMenu();
5090 JMenu ifetch = new JMenu();
5091 JMenuItem fetchr = null;
5092 int comp = 0, icomp = 0, mcomp = 15;
5093 String mname = null;
5095 for (String dbclass : dbclasses)
5097 otherdb = sf.getSourceProxy(dbclass);
5098 // add a single entry for this class, or submenu allowing 'fetch
5100 if (otherdb == null || otherdb.size() < 1)
5104 // List<DbSourceProxy> dbs=otherdb;
5105 // otherdb=new ArrayList<DbSourceProxy>();
5106 // for (DbSourceProxy db:dbs)
5108 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5112 mname = "From " + dbclass;
5114 if (otherdb.size() == 1)
5116 final DbSourceProxy[] dassource = otherdb
5117 .toArray(new DbSourceProxy[0]);
5118 DbSourceProxy src = otherdb.get(0);
5119 fetchr = new JMenuItem(src.getDbSource());
5120 fetchr.addActionListener(new ActionListener()
5124 public void actionPerformed(ActionEvent e)
5126 new Thread(new Runnable()
5132 new jalview.ws.DBRefFetcher(alignPanel.av
5133 .getSequenceSelection(),
5134 alignPanel.alignFrame, dassource)
5135 .fetchDBRefs(false);
5141 fetchr.setToolTipText("<html>"
5142 + JvSwingUtils.wrapTooltip("Retrieve from "
5143 + src.getDbName()) + "<html>");
5149 final DbSourceProxy[] dassource = otherdb
5150 .toArray(new DbSourceProxy[0]);
5152 DbSourceProxy src = otherdb.get(0);
5153 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5155 fetchr.addActionListener(new ActionListener()
5158 public void actionPerformed(ActionEvent e)
5160 new Thread(new Runnable()
5166 new jalview.ws.DBRefFetcher(alignPanel.av
5167 .getSequenceSelection(),
5168 alignPanel.alignFrame, dassource)
5169 .fetchDBRefs(false);
5175 fetchr.setToolTipText("<html>"
5176 + JvSwingUtils.wrapTooltip("Retrieve from all "
5177 + otherdb.size() + " sources in "
5178 + src.getDbSource() + "<br>First is :"
5179 + src.getDbName()) + "<html>");
5182 // and then build the rest of the individual menus
5183 ifetch = new JMenu("Sources from " + src.getDbSource());
5185 String imname = null;
5187 for (DbSourceProxy sproxy : otherdb)
5189 String dbname = sproxy.getDbName();
5190 String sname = dbname.length() > 5 ? dbname.substring(0,
5191 5) + "..." : dbname;
5192 String msname = dbname.length() > 10 ? dbname.substring(
5193 0, 10) + "..." : dbname;
5196 imname = "from '" + sname + "'";
5198 fetchr = new JMenuItem(msname);
5199 final DbSourceProxy[] dassrc =
5201 fetchr.addActionListener(new ActionListener()
5205 public void actionPerformed(ActionEvent e)
5207 new Thread(new Runnable()
5213 new jalview.ws.DBRefFetcher(alignPanel.av
5214 .getSequenceSelection(),
5215 alignPanel.alignFrame, dassrc)
5216 .fetchDBRefs(false);
5222 fetchr.setToolTipText("<html>"
5223 + JvSwingUtils.wrapTooltip("Retrieve from "
5224 + dbname) + "</html>");
5227 if (++icomp >= mcomp || i == (otherdb.size()))
5229 ifetch.setText(imname + " to '" + sname + "'");
5231 ifetch = new JMenu();
5239 if (comp >= mcomp || dbi >= (dbclasses.length))
5241 dfetch.setText(mname + " to '" + dbclass + "'");
5243 dfetch = new JMenu();
5256 * Left justify the whole alignment.
5259 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5261 AlignmentI al = viewport.getAlignment();
5263 viewport.firePropertyChange("alignment", null, al);
5267 * Right justify the whole alignment.
5270 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5272 AlignmentI al = viewport.getAlignment();
5274 viewport.firePropertyChange("alignment", null, al);
5277 public void setShowSeqFeatures(boolean b)
5279 showSeqFeatures.setSelected(true);
5280 viewport.setShowSequenceFeatures(true);
5287 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5288 * awt.event.ActionEvent)
5291 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5293 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5294 alignPanel.paintAlignment(true);
5301 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5305 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5307 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5308 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5316 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5317 * .event.ActionEvent)
5320 protected void showGroupConservation_actionPerformed(ActionEvent e)
5322 viewport.setShowGroupConservation(showGroupConservation.getState());
5323 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5330 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5331 * .event.ActionEvent)
5334 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5336 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5337 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5344 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5345 * .event.ActionEvent)
5348 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5350 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5351 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5355 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5357 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5358 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5362 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5364 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5371 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5372 * .event.ActionEvent)
5375 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5377 if (viewport.getSelectionGroup() != null)
5379 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5380 viewport.getSequenceSelection(),
5381 viewport.getAlignmentView(true).getSequenceStrings(
5382 viewport.getGapCharacter()), viewport.getAlignment()
5384 viewport.getAlignment().deleteAllGroups();
5385 viewport.sequenceColours = null;
5386 viewport.setSelectionGroup(null);
5387 // set view properties for each group
5388 for (int g = 0; g < gps.length; g++)
5390 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5391 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5392 viewport.getAlignment().addGroup(gps[g]);
5393 Color col = new Color((int) (Math.random() * 255),
5394 (int) (Math.random() * 255), (int) (Math.random() * 255));
5395 col = col.brighter();
5396 for (SequenceI s:gps[g].getSequences())
5397 viewport.setSequenceColour(
5401 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5402 alignPanel.updateAnnotation();
5403 alignPanel.paintAlignment(true);
5408 * make the given alignmentPanel the currently selected tab
5410 * @param alignmentPanel
5412 public void setDisplayedView(AlignmentPanel alignmentPanel)
5414 if (!viewport.getSequenceSetId().equals(
5415 alignmentPanel.av.getSequenceSetId()))
5418 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5420 if (tabbedPane != null
5421 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5422 .getSelectedIndex())
5424 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5429 class PrintThread extends Thread
5433 public PrintThread(AlignmentPanel ap)
5438 static PageFormat pf;
5443 PrinterJob printJob = PrinterJob.getPrinterJob();
5447 printJob.setPrintable(ap, pf);
5451 printJob.setPrintable(ap);
5454 if (printJob.printDialog())
5459 } catch (Exception PrintException)
5461 PrintException.printStackTrace();