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();
740 // methods for implementing IProgressIndicator
741 // need to refactor to a reusable stub class
742 Hashtable progressBars, progressBarHandlers;
747 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
750 public void setProgressBar(String message, long id)
752 if (progressBars == null)
754 progressBars = new Hashtable();
755 progressBarHandlers = new Hashtable();
758 JPanel progressPanel;
759 Long lId = new Long(id);
760 GridLayout layout = (GridLayout) statusPanel.getLayout();
761 if (progressBars.get(lId) != null)
763 progressPanel = (JPanel) progressBars.get(new Long(id));
764 statusPanel.remove(progressPanel);
765 progressBars.remove(lId);
766 progressPanel = null;
769 statusBar.setText(message);
771 if (progressBarHandlers.contains(lId))
773 progressBarHandlers.remove(lId);
775 layout.setRows(layout.getRows() - 1);
779 progressPanel = new JPanel(new BorderLayout(10, 5));
781 JProgressBar progressBar = new JProgressBar();
782 progressBar.setIndeterminate(true);
784 progressPanel.add(new JLabel(message), BorderLayout.WEST);
785 progressPanel.add(progressBar, BorderLayout.CENTER);
787 layout.setRows(layout.getRows() + 1);
788 statusPanel.add(progressPanel);
790 progressBars.put(lId, progressPanel);
793 // setMenusForViewport();
798 public void registerHandler(final long id,
799 final IProgressIndicatorHandler handler)
801 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
804 "call setProgressBar before registering the progress bar's handler.");
806 progressBarHandlers.put(new Long(id), handler);
807 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
808 if (handler.canCancel())
810 JButton cancel = new JButton("Cancel");
811 final IProgressIndicator us = this;
812 cancel.addActionListener(new ActionListener()
816 public void actionPerformed(ActionEvent e)
818 handler.cancelActivity(id);
821 + ((JLabel) progressPanel.getComponent(0))
825 progressPanel.add(cancel, BorderLayout.EAST);
831 * @return true if any progress bars are still active
834 public boolean operationInProgress()
836 if (progressBars != null && progressBars.size() > 0)
844 * Added so Castor Mapping file can obtain Jalview Version
846 public String getVersion()
848 return jalview.bin.Cache.getProperty("VERSION");
851 public FeatureRenderer getFeatureRenderer()
853 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
857 public void fetchSequence_actionPerformed(ActionEvent e)
859 new SequenceFetcher(this);
863 public void addFromFile_actionPerformed(ActionEvent e)
865 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
869 public void reload_actionPerformed(ActionEvent e)
871 if (fileName != null)
873 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
874 // originating file's format
875 // TODO: work out how to recover feature settings for correct view(s) when
877 if (currentFileFormat.equals("Jalview"))
879 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
880 for (int i = 0; i < frames.length; i++)
882 if (frames[i] instanceof AlignFrame && frames[i] != this
883 && ((AlignFrame) frames[i]).fileName.equals(fileName))
887 frames[i].setSelected(true);
888 Desktop.instance.closeAssociatedWindows();
889 } catch (java.beans.PropertyVetoException ex)
895 Desktop.instance.closeAssociatedWindows();
897 FileLoader loader = new FileLoader();
898 String protocol = fileName.startsWith("http:") ? "URL" : "File";
899 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
903 Rectangle bounds = this.getBounds();
905 FileLoader loader = new FileLoader();
906 String protocol = fileName.startsWith("http:") ? "URL" : "File";
907 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
908 protocol, currentFileFormat);
910 newframe.setBounds(bounds);
911 if (featureSettings != null && featureSettings.isShowing())
913 final Rectangle fspos = featureSettings.frame.getBounds();
914 // TODO: need a 'show feature settings' function that takes bounds -
915 // need to refactor Desktop.addFrame
916 newframe.featureSettings_actionPerformed(null);
917 final FeatureSettings nfs = newframe.featureSettings;
918 SwingUtilities.invokeLater(new Runnable()
923 nfs.frame.setBounds(fspos);
926 this.featureSettings.close();
927 this.featureSettings = null;
929 this.closeMenuItem_actionPerformed(true);
935 public void addFromText_actionPerformed(ActionEvent e)
937 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
941 public void addFromURL_actionPerformed(ActionEvent e)
943 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
947 public void save_actionPerformed(ActionEvent e)
950 || (currentFileFormat == null || !jalview.io.FormatAdapter
951 .isValidIOFormat(currentFileFormat, true))
952 || fileName.startsWith("http"))
954 saveAs_actionPerformed(null);
958 saveAlignment(fileName, currentFileFormat);
969 public void saveAs_actionPerformed(ActionEvent e)
971 JalviewFileChooser chooser = new JalviewFileChooser(
972 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
973 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
974 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
975 currentFileFormat, false);
977 chooser.setFileView(new JalviewFileView());
978 chooser.setDialogTitle("Save Alignment to file");
979 chooser.setToolTipText("Save");
981 int value = chooser.showSaveDialog(this);
983 if (value == JalviewFileChooser.APPROVE_OPTION)
985 currentFileFormat = chooser.getSelectedFormat();
986 if (currentFileFormat == null)
988 JOptionPane.showInternalMessageDialog(Desktop.desktop,
989 "You must select a file format before saving!",
990 "File format not specified", JOptionPane.WARNING_MESSAGE);
991 value = chooser.showSaveDialog(this);
995 fileName = chooser.getSelectedFile().getPath();
997 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1000 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1001 if (currentFileFormat.indexOf(" ") > -1)
1003 currentFileFormat = currentFileFormat.substring(0,
1004 currentFileFormat.indexOf(" "));
1006 saveAlignment(fileName, currentFileFormat);
1010 public boolean saveAlignment(String file, String format)
1012 boolean success = true;
1014 if (format.equalsIgnoreCase("Jalview"))
1016 String shortName = title;
1018 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1020 shortName = shortName.substring(shortName
1021 .lastIndexOf(java.io.File.separatorChar) + 1);
1024 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1026 statusBar.setText("Successfully saved to file: " + fileName + " in "
1027 + format + " format.");
1032 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1034 warningMessage("Cannot save file " + fileName + " using format "
1035 + format, "Alignment output format not supported");
1036 saveAs_actionPerformed(null);
1037 // JBPNote need to have a raise_gui flag here
1041 String[] omitHidden = null;
1043 if (viewport.hasHiddenColumns())
1045 int reply = JOptionPane
1046 .showInternalConfirmDialog(
1048 "The Alignment contains hidden columns."
1049 + "\nDo you want to save only the visible alignment?",
1050 "Save / Omit Hidden Columns",
1051 JOptionPane.YES_NO_OPTION,
1052 JOptionPane.QUESTION_MESSAGE);
1054 if (reply == JOptionPane.YES_OPTION)
1056 omitHidden = viewport.getViewAsString(false);
1059 FormatAdapter f = new FormatAdapter();
1060 String output = f.formatSequences(
1062 viewport.getAlignment(), // class cast exceptions will
1063 // occur in the distant future
1064 omitHidden, f.getCacheSuffixDefault(format),
1065 viewport.getColumnSelection());
1075 java.io.PrintWriter out = new java.io.PrintWriter(
1076 new java.io.FileWriter(file));
1080 this.setTitle(file);
1081 statusBar.setText("Successfully saved to file: " + fileName
1082 + " in " + format + " format.");
1083 } catch (Exception ex)
1086 ex.printStackTrace();
1093 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1094 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1100 private void warningMessage(String warning, String title)
1102 if (new jalview.util.Platform().isHeadless())
1104 System.err.println("Warning: " + title + "\nWarning: " + warning);
1109 JOptionPane.showInternalMessageDialog(this, warning, title,
1110 JOptionPane.WARNING_MESSAGE);
1122 protected void outputText_actionPerformed(ActionEvent e)
1124 String[] omitHidden = null;
1126 if (viewport.hasHiddenColumns())
1128 int reply = JOptionPane
1129 .showInternalConfirmDialog(
1131 "The Alignment contains hidden columns."
1132 + "\nDo you want to output only the visible alignment?",
1133 "Save / Omit Hidden Columns",
1134 JOptionPane.YES_NO_OPTION,
1135 JOptionPane.QUESTION_MESSAGE);
1137 if (reply == JOptionPane.YES_OPTION)
1139 omitHidden = viewport.getViewAsString(false);
1143 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1144 cap.setForInput(null);
1148 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1149 viewport.getAlignment(), omitHidden,
1150 viewport.getColumnSelection()));
1151 Desktop.addInternalFrame(cap,
1152 "Alignment output - " + e.getActionCommand(), 600, 500);
1153 } catch (OutOfMemoryError oom)
1155 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1168 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1170 new HTMLOutput(alignPanel,
1171 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1172 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1175 public void createImageMap(File file, String image)
1177 alignPanel.makePNGImageMap(file, image);
1187 public void createPNG(File f)
1189 alignPanel.makePNG(f);
1199 public void createEPS(File f)
1201 alignPanel.makeEPS(f);
1205 public void pageSetup_actionPerformed(ActionEvent e)
1207 PrinterJob printJob = PrinterJob.getPrinterJob();
1208 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1218 public void printMenuItem_actionPerformed(ActionEvent e)
1220 // Putting in a thread avoids Swing painting problems
1221 PrintThread thread = new PrintThread(alignPanel);
1226 public void exportFeatures_actionPerformed(ActionEvent e)
1228 new AnnotationExporter().exportFeatures(alignPanel);
1232 public void exportAnnotations_actionPerformed(ActionEvent e)
1234 new AnnotationExporter().exportAnnotations(alignPanel,
1235 viewport.showAnnotation ? viewport.getAlignment()
1236 .getAlignmentAnnotation() : null, viewport
1237 .getAlignment().getGroups(), ((Alignment) viewport
1238 .getAlignment()).alignmentProperties);
1242 public void associatedData_actionPerformed(ActionEvent e)
1244 // Pick the tree file
1245 JalviewFileChooser chooser = new JalviewFileChooser(
1246 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1247 chooser.setFileView(new JalviewFileView());
1248 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1249 chooser.setToolTipText("Load Jalview Annotations / Features file");
1251 int value = chooser.showOpenDialog(null);
1253 if (value == JalviewFileChooser.APPROVE_OPTION)
1255 String choice = chooser.getSelectedFile().getPath();
1256 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1257 loadJalviewDataFile(choice, null, null, null);
1263 * Close the current view or all views in the alignment frame. If the frame
1264 * only contains one view then the alignment will be removed from memory.
1266 * @param closeAllTabs
1269 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1271 if (alignPanels != null && alignPanels.size() < 2)
1273 closeAllTabs = true;
1278 if (alignPanels != null)
1282 if (this.isClosed())
1284 // really close all the windows - otherwise wait till
1285 // setClosed(true) is called
1286 for (int i = 0; i < alignPanels.size(); i++)
1288 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1295 closeView(alignPanel);
1301 this.setClosed(true);
1303 } catch (Exception ex)
1305 ex.printStackTrace();
1310 * close alignPanel2 and shuffle tabs appropriately.
1312 * @param alignPanel2
1314 public void closeView(AlignmentPanel alignPanel2)
1316 int index = tabbedPane.getSelectedIndex();
1317 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1318 alignPanels.removeElement(alignPanel2);
1320 // if (viewport == alignPanel2.av)
1324 alignPanel2.closePanel();
1327 tabbedPane.removeTabAt(closedindex);
1328 tabbedPane.validate();
1330 if (index > closedindex || index == tabbedPane.getTabCount())
1332 // modify currently selected tab index if necessary.
1336 this.tabSelectionChanged(index);
1342 void updateEditMenuBar()
1345 if (viewport.historyList.size() > 0)
1347 undoMenuItem.setEnabled(true);
1348 CommandI command = (CommandI) viewport.historyList.peek();
1349 undoMenuItem.setText("Undo " + command.getDescription());
1353 undoMenuItem.setEnabled(false);
1354 undoMenuItem.setText("Undo");
1357 if (viewport.redoList.size() > 0)
1359 redoMenuItem.setEnabled(true);
1361 CommandI command = (CommandI) viewport.redoList.peek();
1362 redoMenuItem.setText("Redo " + command.getDescription());
1366 redoMenuItem.setEnabled(false);
1367 redoMenuItem.setText("Redo");
1371 public void addHistoryItem(CommandI command)
1373 if (command.getSize() > 0)
1375 viewport.historyList.push(command);
1376 viewport.redoList.clear();
1377 updateEditMenuBar();
1378 viewport.updateHiddenColumns();
1379 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1380 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1381 // viewport.getColumnSelection()
1382 // .getHiddenColumns().size() > 0);
1388 * @return alignment objects for all views
1390 AlignmentI[] getViewAlignments()
1392 if (alignPanels != null)
1394 Enumeration e = alignPanels.elements();
1395 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1396 for (int i = 0; e.hasMoreElements(); i++)
1398 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1402 if (viewport != null)
1404 return new AlignmentI[]
1405 { viewport.getAlignment() };
1417 protected void undoMenuItem_actionPerformed(ActionEvent e)
1419 if (viewport.historyList.empty())
1421 CommandI command = (CommandI) viewport.historyList.pop();
1422 viewport.redoList.push(command);
1423 command.undoCommand(getViewAlignments());
1425 AlignViewport originalSource = getOriginatingSource(command);
1426 updateEditMenuBar();
1428 if (originalSource != null)
1430 if (originalSource != viewport)
1433 .warn("Implementation worry: mismatch of viewport origin for undo");
1435 originalSource.updateHiddenColumns();
1436 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1438 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1439 // viewport.getColumnSelection()
1440 // .getHiddenColumns().size() > 0);
1441 originalSource.firePropertyChange("alignment", null, originalSource
1442 .getAlignment().getSequences());
1453 protected void redoMenuItem_actionPerformed(ActionEvent e)
1455 if (viewport.redoList.size() < 1)
1460 CommandI command = (CommandI) viewport.redoList.pop();
1461 viewport.historyList.push(command);
1462 command.doCommand(getViewAlignments());
1464 AlignViewport originalSource = getOriginatingSource(command);
1465 updateEditMenuBar();
1467 if (originalSource != null)
1470 if (originalSource != viewport)
1473 .warn("Implementation worry: mismatch of viewport origin for redo");
1475 originalSource.updateHiddenColumns();
1476 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1478 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1479 // viewport.getColumnSelection()
1480 // .getHiddenColumns().size() > 0);
1481 originalSource.firePropertyChange("alignment", null, originalSource
1482 .getAlignment().getSequences());
1486 AlignViewport getOriginatingSource(CommandI command)
1488 AlignViewport originalSource = null;
1489 // For sequence removal and addition, we need to fire
1490 // the property change event FROM the viewport where the
1491 // original alignment was altered
1492 AlignmentI al = null;
1493 if (command instanceof EditCommand)
1495 EditCommand editCommand = (EditCommand) command;
1496 al = editCommand.getAlignment();
1497 Vector comps = (Vector) PaintRefresher.components.get(viewport
1498 .getSequenceSetId());
1500 for (int i = 0; i < comps.size(); i++)
1502 if (comps.elementAt(i) instanceof AlignmentPanel)
1504 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1506 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1513 if (originalSource == null)
1515 // The original view is closed, we must validate
1516 // the current view against the closed view first
1519 PaintRefresher.validateSequences(al, viewport.getAlignment());
1522 originalSource = viewport;
1525 return originalSource;
1534 public void moveSelectedSequences(boolean up)
1536 SequenceGroup sg = viewport.getSelectionGroup();
1542 viewport.getAlignment().moveSelectedSequencesByOne(sg, viewport.getHiddenRepSequences(), up);
1543 alignPanel.paintAlignment(true);
1546 synchronized void slideSequences(boolean right, int size)
1548 List<SequenceI> sg = new Vector();
1549 if (viewport.cursorMode)
1551 sg.add(viewport.getAlignment().getSequenceAt(
1552 alignPanel.seqPanel.seqCanvas.cursorY));
1554 else if (viewport.getSelectionGroup() != null
1555 && viewport.getSelectionGroup().getSize() != viewport
1556 .getAlignment().getHeight())
1558 sg = viewport.getSelectionGroup().getSequences(
1559 viewport.getHiddenRepSequences());
1567 Vector invertGroup = new Vector();
1569 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1571 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1572 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1575 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1577 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1578 for (int i = 0; i < invertGroup.size(); i++)
1579 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1581 SlideSequencesCommand ssc;
1583 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1584 size, viewport.getGapCharacter());
1586 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1587 size, viewport.getGapCharacter());
1589 int groupAdjustment = 0;
1590 if (ssc.getGapsInsertedBegin() && right)
1592 if (viewport.cursorMode)
1593 alignPanel.seqPanel.moveCursor(size, 0);
1595 groupAdjustment = size;
1597 else if (!ssc.getGapsInsertedBegin() && !right)
1599 if (viewport.cursorMode)
1600 alignPanel.seqPanel.moveCursor(-size, 0);
1602 groupAdjustment = -size;
1605 if (groupAdjustment != 0)
1607 viewport.getSelectionGroup().setStartRes(
1608 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1609 viewport.getSelectionGroup().setEndRes(
1610 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1613 boolean appendHistoryItem = false;
1614 if (viewport.historyList != null && viewport.historyList.size() > 0
1615 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1617 appendHistoryItem = ssc
1618 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1622 if (!appendHistoryItem)
1623 addHistoryItem(ssc);
1635 protected void copy_actionPerformed(ActionEvent e)
1638 if (viewport.getSelectionGroup() == null)
1642 // TODO: preserve the ordering of displayed alignment annotation in any
1643 // internal paste (particularly sequence associated annotation)
1644 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1645 String[] omitHidden = null;
1647 if (viewport.hasHiddenColumns())
1649 omitHidden = viewport.getViewAsString(true);
1652 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1655 StringSelection ss = new StringSelection(output);
1659 jalview.gui.Desktop.internalCopy = true;
1660 // Its really worth setting the clipboard contents
1661 // to empty before setting the large StringSelection!!
1662 Toolkit.getDefaultToolkit().getSystemClipboard()
1663 .setContents(new StringSelection(""), null);
1665 Toolkit.getDefaultToolkit().getSystemClipboard()
1666 .setContents(ss, Desktop.instance);
1667 } catch (OutOfMemoryError er)
1669 new OOMWarning("copying region", er);
1673 Vector hiddenColumns = null;
1674 if (viewport.hasHiddenColumns())
1676 hiddenColumns = new Vector();
1677 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1678 .getSelectionGroup().getEndRes();
1679 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1682 int[] region = (int[]) viewport.getColumnSelection()
1683 .getHiddenColumns().elementAt(i);
1684 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1686 hiddenColumns.addElement(new int[]
1687 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1692 Desktop.jalviewClipboard = new Object[]
1693 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1694 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1704 protected void pasteNew_actionPerformed(ActionEvent e)
1716 protected void pasteThis_actionPerformed(ActionEvent e)
1722 * Paste contents of Jalview clipboard
1724 * @param newAlignment
1725 * true to paste to a new alignment, otherwise add to this.
1727 void paste(boolean newAlignment)
1729 boolean externalPaste = true;
1732 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1733 Transferable contents = c.getContents(this);
1735 if (contents == null)
1743 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1744 if (str.length() < 1)
1749 format = new IdentifyFile().Identify(str, "Paste");
1751 } catch (OutOfMemoryError er)
1753 new OOMWarning("Out of memory pasting sequences!!", er);
1757 SequenceI[] sequences;
1758 boolean annotationAdded = false;
1759 AlignmentI alignment = null;
1761 if (Desktop.jalviewClipboard != null)
1763 // The clipboard was filled from within Jalview, we must use the
1765 // And dataset from the copied alignment
1766 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1767 // be doubly sure that we create *new* sequence objects.
1768 sequences = new SequenceI[newseq.length];
1769 for (int i = 0; i < newseq.length; i++)
1771 sequences[i] = new Sequence(newseq[i]);
1773 alignment = new Alignment(sequences);
1774 externalPaste = false;
1778 // parse the clipboard as an alignment.
1779 alignment = new FormatAdapter().readFile(str, "Paste", format);
1780 sequences = alignment.getSequencesArray();
1788 if (Desktop.jalviewClipboard != null)
1790 // dataset is inherited
1791 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1795 // new dataset is constructed
1796 alignment.setDataset(null);
1798 alwidth = alignment.getWidth() + 1;
1802 AlignmentI pastedal = alignment; // preserve pasted alignment object
1803 // Add pasted sequences and dataset into existing alignment.
1804 alignment = viewport.getAlignment();
1805 alwidth = alignment.getWidth() + 1;
1806 // decide if we need to import sequences from an existing dataset
1807 boolean importDs = Desktop.jalviewClipboard != null
1808 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1809 // importDs==true instructs us to copy over new dataset sequences from
1810 // an existing alignment
1811 Vector newDs = (importDs) ? new Vector() : null; // used to create
1812 // minimum dataset set
1814 for (int i = 0; i < sequences.length; i++)
1818 newDs.addElement(null);
1820 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1822 if (importDs && ds != null)
1824 if (!newDs.contains(ds))
1826 newDs.setElementAt(ds, i);
1827 ds = new Sequence(ds);
1828 // update with new dataset sequence
1829 sequences[i].setDatasetSequence(ds);
1833 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1838 // copy and derive new dataset sequence
1839 sequences[i] = sequences[i].deriveSequence();
1840 alignment.getDataset().addSequence(
1841 sequences[i].getDatasetSequence());
1842 // TODO: avoid creation of duplicate dataset sequences with a
1843 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1845 alignment.addSequence(sequences[i]); // merges dataset
1849 newDs.clear(); // tidy up
1851 if (pastedal.getAlignmentAnnotation() != null)
1853 // Add any annotation attached to alignment.
1854 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1855 for (int i = 0; i < alann.length; i++)
1857 annotationAdded = true;
1858 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1860 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1861 newann.padAnnotation(alwidth);
1862 alignment.addAnnotation(newann);
1872 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1873 sequences, 0, alignment.getWidth(), alignment));
1875 // Add any annotations attached to sequences
1876 for (int i = 0; i < sequences.length; i++)
1878 if (sequences[i].getAnnotation() != null)
1880 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1882 annotationAdded = true;
1883 sequences[i].getAnnotation()[a].adjustForAlignment();
1884 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1885 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1890 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1897 // propagate alignment changed.
1898 viewport.setEndSeq(alignment.getHeight());
1899 if (annotationAdded)
1901 // Duplicate sequence annotation in all views.
1902 AlignmentI[] alview = this.getViewAlignments();
1903 for (int i = 0; i < sequences.length; i++)
1905 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1908 for (int avnum = 0; avnum < alview.length; avnum++)
1910 if (alview[avnum] != alignment)
1912 // duplicate in a view other than the one with input focus
1913 int avwidth = alview[avnum].getWidth() + 1;
1914 // this relies on sann being preserved after we
1915 // modify the sequence's annotation array for each duplication
1916 for (int a = 0; a < sann.length; a++)
1918 AlignmentAnnotation newann = new AlignmentAnnotation(
1920 sequences[i].addAlignmentAnnotation(newann);
1921 newann.padAnnotation(avwidth);
1922 alview[avnum].addAnnotation(newann); // annotation was
1923 // duplicated earlier
1924 alview[avnum].setAnnotationIndex(newann, a);
1929 buildSortByAnnotationScoresMenu();
1931 viewport.firePropertyChange("alignment", null,
1932 alignment.getSequences());
1937 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1939 String newtitle = new String("Copied sequences");
1941 if (Desktop.jalviewClipboard != null
1942 && Desktop.jalviewClipboard[2] != null)
1944 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1945 for (int i = 0; i < hc.size(); i++)
1947 int[] region = (int[]) hc.elementAt(i);
1948 af.viewport.hideColumns(region[0], region[1]);
1952 // >>>This is a fix for the moment, until a better solution is
1954 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1956 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1958 // TODO: maintain provenance of an alignment, rather than just make the
1959 // title a concatenation of operations.
1962 if (title.startsWith("Copied sequences"))
1968 newtitle = newtitle.concat("- from " + title);
1973 newtitle = new String("Pasted sequences");
1976 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1981 } catch (Exception ex)
1983 ex.printStackTrace();
1984 System.out.println("Exception whilst pasting: " + ex);
1985 // could be anything being pasted in here
1997 protected void cut_actionPerformed(ActionEvent e)
1999 copy_actionPerformed(null);
2000 delete_actionPerformed(null);
2010 protected void delete_actionPerformed(ActionEvent evt)
2013 SequenceGroup sg = viewport.getSelectionGroup();
2019 Vector seqs = new Vector();
2021 for (int i = 0; i < sg.getSize(); i++)
2023 seq = sg.getSequenceAt(i);
2024 seqs.addElement(seq);
2027 // If the cut affects all sequences, remove highlighted columns
2028 if (sg.getSize() == viewport.getAlignment().getHeight())
2030 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2031 sg.getEndRes() + 1);
2034 SequenceI[] cut = new SequenceI[seqs.size()];
2035 for (int i = 0; i < seqs.size(); i++)
2037 cut[i] = (SequenceI) seqs.elementAt(i);
2041 * //ADD HISTORY ITEM
2043 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2044 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2045 viewport.getAlignment()));
2047 viewport.setSelectionGroup(null);
2048 viewport.sendSelection();
2049 viewport.getAlignment().deleteGroup(sg);
2051 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2053 if (viewport.getAlignment().getHeight() < 1)
2057 this.setClosed(true);
2058 } catch (Exception ex)
2071 protected void deleteGroups_actionPerformed(ActionEvent e)
2073 viewport.getAlignment().deleteAllGroups();
2074 viewport.sequenceColours = null;
2075 viewport.setSelectionGroup(null);
2076 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2077 alignPanel.updateAnnotation();
2078 alignPanel.paintAlignment(true);
2088 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2090 SequenceGroup sg = new SequenceGroup();
2092 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2094 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2097 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2098 viewport.setSelectionGroup(sg);
2099 viewport.sendSelection();
2100 alignPanel.paintAlignment(true);
2101 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2111 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2113 if (viewport.cursorMode)
2115 alignPanel.seqPanel.keyboardNo1 = null;
2116 alignPanel.seqPanel.keyboardNo2 = null;
2118 viewport.setSelectionGroup(null);
2119 viewport.getColumnSelection().clear();
2120 viewport.setSelectionGroup(null);
2121 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2122 alignPanel.idPanel.idCanvas.searchResults = null;
2123 alignPanel.paintAlignment(true);
2124 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2125 viewport.sendSelection();
2135 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2137 SequenceGroup sg = viewport.getSelectionGroup();
2141 selectAllSequenceMenuItem_actionPerformed(null);
2146 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2148 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2151 alignPanel.paintAlignment(true);
2152 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2153 viewport.sendSelection();
2157 public void invertColSel_actionPerformed(ActionEvent e)
2159 viewport.invertColumnSelection();
2160 alignPanel.paintAlignment(true);
2161 viewport.sendSelection();
2171 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2173 trimAlignment(true);
2183 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2185 trimAlignment(false);
2188 void trimAlignment(boolean trimLeft)
2190 ColumnSelection colSel = viewport.getColumnSelection();
2193 if (colSel.size() > 0)
2197 column = colSel.getMin();
2201 column = colSel.getMax();
2205 if (viewport.getSelectionGroup() != null)
2207 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2208 viewport.getHiddenRepSequences());
2212 seqs = viewport.getAlignment().getSequencesArray();
2215 TrimRegionCommand trimRegion;
2218 trimRegion = new TrimRegionCommand("Remove Left",
2219 TrimRegionCommand.TRIM_LEFT, seqs, column,
2220 viewport.getAlignment(), viewport.getColumnSelection(),
2221 viewport.getSelectionGroup());
2222 viewport.setStartRes(0);
2226 trimRegion = new TrimRegionCommand("Remove Right",
2227 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2228 viewport.getAlignment(), viewport.getColumnSelection(),
2229 viewport.getSelectionGroup());
2232 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2234 addHistoryItem(trimRegion);
2236 for (SequenceGroup sg :viewport.getAlignment().getGroups())
2238 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2239 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2241 viewport.getAlignment().deleteGroup(sg);
2245 viewport.firePropertyChange("alignment", null, viewport
2246 .getAlignment().getSequences());
2257 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2259 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2262 if (viewport.getSelectionGroup() != null)
2264 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2265 viewport.getHiddenRepSequences());
2266 start = viewport.getSelectionGroup().getStartRes();
2267 end = viewport.getSelectionGroup().getEndRes();
2271 seqs = viewport.getAlignment().getSequencesArray();
2274 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2275 "Remove Gapped Columns", seqs, start, end,
2276 viewport.getAlignment());
2278 addHistoryItem(removeGapCols);
2280 statusBar.setText("Removed " + removeGapCols.getSize()
2281 + " empty columns.");
2283 // This is to maintain viewport position on first residue
2284 // of first sequence
2285 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2286 int startRes = seq.findPosition(viewport.startRes);
2287 // ShiftList shifts;
2288 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2289 // edit.alColumnChanges=shifts.getInverse();
2290 // if (viewport.hasHiddenColumns)
2291 // viewport.getColumnSelection().compensateForEdits(shifts);
2292 viewport.setStartRes(seq.findIndex(startRes) - 1);
2293 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2305 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2307 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2310 if (viewport.getSelectionGroup() != null)
2312 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2313 viewport.getHiddenRepSequences());
2314 start = viewport.getSelectionGroup().getStartRes();
2315 end = viewport.getSelectionGroup().getEndRes();
2319 seqs = viewport.getAlignment().getSequencesArray();
2322 // This is to maintain viewport position on first residue
2323 // of first sequence
2324 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2325 int startRes = seq.findPosition(viewport.startRes);
2327 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2328 viewport.getAlignment()));
2330 viewport.setStartRes(seq.findIndex(startRes) - 1);
2332 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2344 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2346 viewport.setPadGaps(padGapsMenuitem.isSelected());
2347 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2353 // if (justifySeqs>0)
2355 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2368 public void findMenuItem_actionPerformed(ActionEvent e)
2374 public void newView_actionPerformed(ActionEvent e)
2381 * @param copyAnnotation
2382 * if true then duplicate all annnotation, groups and settings
2383 * @return new alignment panel, already displayed.
2385 public AlignmentPanel newView(boolean copyAnnotation)
2387 return newView(null, copyAnnotation);
2393 * title of newly created view
2394 * @return new alignment panel, already displayed.
2396 public AlignmentPanel newView(String viewTitle)
2398 return newView(viewTitle, true);
2404 * title of newly created view
2405 * @param copyAnnotation
2406 * if true then duplicate all annnotation, groups and settings
2407 * @return new alignment panel, already displayed.
2409 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2411 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2413 if (!copyAnnotation)
2415 // just remove all the current annotation except for the automatic stuff
2416 newap.av.getAlignment().deleteAllGroups();
2417 for (AlignmentAnnotation alan : newap.av.getAlignment()
2418 .getAlignmentAnnotation())
2420 if (!alan.autoCalculated)
2422 newap.av.getAlignment().deleteAnnotation(alan);
2428 newap.av.gatherViewsHere = false;
2430 if (viewport.viewName == null)
2432 viewport.viewName = "Original";
2435 newap.av.historyList = viewport.historyList;
2436 newap.av.redoList = viewport.redoList;
2438 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2439 // make sure the new view has a unique name - this is essential for Jalview
2441 boolean addFirstIndex = false;
2442 if (viewTitle == null || viewTitle.trim().length() == 0)
2445 addFirstIndex = true;
2449 index = 1;// we count from 1 if given a specific name
2451 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2452 Vector comps = (Vector) PaintRefresher.components.get(viewport
2453 .getSequenceSetId());
2454 Vector existingNames = new Vector();
2455 for (int i = 0; i < comps.size(); i++)
2457 if (comps.elementAt(i) instanceof AlignmentPanel)
2459 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2460 if (!existingNames.contains(ap.av.viewName))
2462 existingNames.addElement(ap.av.viewName);
2467 while (existingNames.contains(newViewName))
2469 newViewName = viewTitle + " " + (++index);
2472 newap.av.viewName = newViewName;
2474 addAlignmentPanel(newap, true);
2476 if (alignPanels.size() == 2)
2478 viewport.gatherViewsHere = true;
2480 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2485 public void expandViews_actionPerformed(ActionEvent e)
2487 Desktop.instance.explodeViews(this);
2491 public void gatherViews_actionPerformed(ActionEvent e)
2493 Desktop.instance.gatherViews(this);
2503 public void font_actionPerformed(ActionEvent e)
2505 new FontChooser(alignPanel);
2515 protected void seqLimit_actionPerformed(ActionEvent e)
2517 viewport.setShowJVSuffix(seqLimits.isSelected());
2519 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2520 .calculateIdWidth());
2521 alignPanel.paintAlignment(true);
2525 public void idRightAlign_actionPerformed(ActionEvent e)
2527 viewport.rightAlignIds = idRightAlign.isSelected();
2528 alignPanel.paintAlignment(true);
2532 public void centreColumnLabels_actionPerformed(ActionEvent e)
2534 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2535 alignPanel.paintAlignment(true);
2541 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2544 protected void followHighlight_actionPerformed()
2546 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2548 alignPanel.scrollToPosition(
2549 alignPanel.seqPanel.seqCanvas.searchResults, false);
2560 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2562 viewport.setColourText(colourTextMenuItem.isSelected());
2563 alignPanel.paintAlignment(true);
2573 public void wrapMenuItem_actionPerformed(ActionEvent e)
2575 scaleAbove.setVisible(wrapMenuItem.isSelected());
2576 scaleLeft.setVisible(wrapMenuItem.isSelected());
2577 scaleRight.setVisible(wrapMenuItem.isSelected());
2578 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2579 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2583 public void showAllSeqs_actionPerformed(ActionEvent e)
2585 viewport.showAllHiddenSeqs();
2589 public void showAllColumns_actionPerformed(ActionEvent e)
2591 viewport.showAllHiddenColumns();
2596 public void hideSelSequences_actionPerformed(ActionEvent e)
2598 viewport.hideAllSelectedSeqs();
2599 alignPanel.paintAlignment(true);
2603 * called by key handler and the hide all/show all menu items
2608 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2611 boolean hide = false;
2612 SequenceGroup sg = viewport.getSelectionGroup();
2613 if (!toggleSeqs && !toggleCols)
2615 // Hide everything by the current selection - this is a hack - we do the
2616 // invert and then hide
2617 // first check that there will be visible columns after the invert.
2618 if ((viewport.getColumnSelection() != null
2619 && viewport.getColumnSelection().getSelected() != null && viewport
2620 .getColumnSelection().getSelected().size() > 0)
2621 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2624 // now invert the sequence set, if required - empty selection implies
2625 // that no hiding is required.
2628 invertSequenceMenuItem_actionPerformed(null);
2629 sg = viewport.getSelectionGroup();
2633 viewport.expandColSelection(sg, true);
2634 // finally invert the column selection and get the new sequence
2636 invertColSel_actionPerformed(null);
2643 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2645 hideSelSequences_actionPerformed(null);
2648 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2651 showAllSeqs_actionPerformed(null);
2657 if (viewport.getColumnSelection().getSelected().size() > 0)
2659 hideSelColumns_actionPerformed(null);
2662 viewport.setSelectionGroup(sg);
2667 showAllColumns_actionPerformed(null);
2676 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2677 * event.ActionEvent)
2680 public void hideAllButSelection_actionPerformed(ActionEvent e)
2682 toggleHiddenRegions(false, false);
2689 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2693 public void hideAllSelection_actionPerformed(ActionEvent e)
2695 SequenceGroup sg = viewport.getSelectionGroup();
2696 viewport.expandColSelection(sg, false);
2697 viewport.hideAllSelectedSeqs();
2698 viewport.hideSelectedColumns();
2699 alignPanel.paintAlignment(true);
2706 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2710 public void showAllhidden_actionPerformed(ActionEvent e)
2712 viewport.showAllHiddenColumns();
2713 viewport.showAllHiddenSeqs();
2714 alignPanel.paintAlignment(true);
2718 public void hideSelColumns_actionPerformed(ActionEvent e)
2720 viewport.hideSelectedColumns();
2721 alignPanel.paintAlignment(true);
2725 public void hiddenMarkers_actionPerformed(ActionEvent e)
2727 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2738 protected void scaleAbove_actionPerformed(ActionEvent e)
2740 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2741 alignPanel.paintAlignment(true);
2751 protected void scaleLeft_actionPerformed(ActionEvent e)
2753 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2754 alignPanel.paintAlignment(true);
2764 protected void scaleRight_actionPerformed(ActionEvent e)
2766 viewport.setScaleRightWrapped(scaleRight.isSelected());
2767 alignPanel.paintAlignment(true);
2777 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2779 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2780 alignPanel.paintAlignment(true);
2790 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2792 viewport.setShowText(viewTextMenuItem.isSelected());
2793 alignPanel.paintAlignment(true);
2803 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2805 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2806 alignPanel.paintAlignment(true);
2809 public FeatureSettings featureSettings;
2812 public void featureSettings_actionPerformed(ActionEvent e)
2814 if (featureSettings != null)
2816 featureSettings.close();
2817 featureSettings = null;
2819 if (!showSeqFeatures.isSelected())
2821 // make sure features are actually displayed
2822 showSeqFeatures.setSelected(true);
2823 showSeqFeatures_actionPerformed(null);
2825 featureSettings = new FeatureSettings(this);
2829 * Set or clear 'Show Sequence Features'
2835 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2837 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2838 alignPanel.paintAlignment(true);
2839 if (alignPanel.getOverviewPanel() != null)
2841 alignPanel.getOverviewPanel().updateOverviewImage();
2846 * Set or clear 'Show Sequence Features'
2852 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2854 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2856 if (viewport.getShowSequenceFeaturesHeight())
2858 // ensure we're actually displaying features
2859 viewport.setShowSequenceFeatures(true);
2860 showSeqFeatures.setSelected(true);
2862 alignPanel.paintAlignment(true);
2863 if (alignPanel.getOverviewPanel() != null)
2865 alignPanel.getOverviewPanel().updateOverviewImage();
2876 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2878 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2879 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2883 public void alignmentProperties()
2885 JEditorPane editPane = new JEditorPane("text/html", "");
2886 editPane.setEditable(false);
2887 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2889 editPane.setText("<html>" + contents.toString() + "</html>");
2890 JInternalFrame frame = new JInternalFrame();
2891 frame.getContentPane().add(new JScrollPane(editPane));
2893 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2894 + getTitle(), 500, 400);
2904 public void overviewMenuItem_actionPerformed(ActionEvent e)
2906 if (alignPanel.overviewPanel != null)
2911 JInternalFrame frame = new JInternalFrame();
2912 OverviewPanel overview = new OverviewPanel(alignPanel);
2913 frame.setContentPane(overview);
2914 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2915 frame.getWidth(), frame.getHeight());
2917 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2918 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2921 public void internalFrameClosed(
2922 javax.swing.event.InternalFrameEvent evt)
2924 alignPanel.setOverviewPanel(null);
2928 alignPanel.setOverviewPanel(overview);
2932 public void textColour_actionPerformed(ActionEvent e)
2934 new TextColourChooser().chooseColour(alignPanel, null);
2944 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2956 public void clustalColour_actionPerformed(ActionEvent e)
2958 changeColour(new ClustalxColourScheme(viewport.getAlignment(), viewport.getHiddenRepSequences()));
2968 public void zappoColour_actionPerformed(ActionEvent e)
2970 changeColour(new ZappoColourScheme());
2980 public void taylorColour_actionPerformed(ActionEvent e)
2982 changeColour(new TaylorColourScheme());
2992 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2994 changeColour(new HydrophobicColourScheme());
3004 public void helixColour_actionPerformed(ActionEvent e)
3006 changeColour(new HelixColourScheme());
3016 public void strandColour_actionPerformed(ActionEvent e)
3018 changeColour(new StrandColourScheme());
3028 public void turnColour_actionPerformed(ActionEvent e)
3030 changeColour(new TurnColourScheme());
3040 public void buriedColour_actionPerformed(ActionEvent e)
3042 changeColour(new BuriedColourScheme());
3052 public void nucleotideColour_actionPerformed(ActionEvent e)
3054 changeColour(new NucleotideColourScheme());
3058 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3060 changeColour(new PurinePyrimidineColourScheme());
3064 * public void covariationColour_actionPerformed(ActionEvent e) {
3066 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3070 public void annotationColour_actionPerformed(ActionEvent e)
3072 new AnnotationColourChooser(viewport, alignPanel);
3076 public void rnahelicesColour_actionPerformed(ActionEvent e)
3078 new RNAHelicesColourChooser(viewport, alignPanel);
3088 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3090 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3099 public void changeColour(ColourSchemeI cs)
3101 // TODO: compare with applet and pull up to model method
3106 if (viewport.getAbovePIDThreshold())
3108 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3111 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3113 viewport.setGlobalColourScheme(cs);
3117 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3120 if (viewport.getConservationSelected())
3123 Alignment al = (Alignment) viewport.getAlignment();
3124 Conservation c = new Conservation("All",
3125 ResidueProperties.propHash, 3, al.getSequences(), 0,
3129 c.verdict(false, viewport.getConsPercGaps());
3131 cs.setConservation(c);
3133 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3138 cs.setConservation(null);
3141 cs.setConsensus(viewport.getSequenceConsensusHash());
3144 viewport.setGlobalColourScheme(cs);
3146 if (viewport.getColourAppliesToAllGroups())
3150 for (SequenceGroup sg:viewport.getAlignment().getGroups())
3158 if (cs instanceof ClustalxColourScheme)
3160 sg.cs = new ClustalxColourScheme(sg, viewport
3161 .getHiddenRepSequences());
3163 else if (cs instanceof UserColourScheme)
3165 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3171 sg.cs = cs.getClass().newInstance();
3172 } catch (Exception ex)
3177 if (viewport.getAbovePIDThreshold()
3178 || cs instanceof PIDColourScheme
3179 || cs instanceof Blosum62ColourScheme)
3181 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3183 sg.cs.setConsensus(AAFrequency.calculate(
3184 sg.getSequences(viewport.getHiddenRepSequences()),
3185 sg.getStartRes(), sg.getEndRes() + 1));
3189 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3192 if (viewport.getConservationSelected())
3194 Conservation c = new Conservation("Group",
3195 ResidueProperties.propHash, 3, sg.getSequences(viewport
3196 .getHiddenRepSequences()), sg.getStartRes(),
3197 sg.getEndRes() + 1);
3199 c.verdict(false, viewport.getConsPercGaps());
3200 sg.cs.setConservation(c);
3204 sg.cs.setConservation(null);
3209 if (alignPanel.getOverviewPanel() != null)
3211 alignPanel.getOverviewPanel().updateOverviewImage();
3214 alignPanel.paintAlignment(true);
3224 protected void modifyPID_actionPerformed(ActionEvent e)
3226 if (viewport.getAbovePIDThreshold()
3227 && viewport.getGlobalColourScheme() != null)
3229 SliderPanel.setPIDSliderSource(alignPanel,
3230 viewport.getGlobalColourScheme(), "Background");
3231 SliderPanel.showPIDSlider();
3242 protected void modifyConservation_actionPerformed(ActionEvent e)
3244 if (viewport.getConservationSelected()
3245 && viewport.getGlobalColourScheme() != null)
3247 SliderPanel.setConservationSlider(alignPanel,
3248 viewport.getGlobalColourScheme(), "Background");
3249 SliderPanel.showConservationSlider();
3260 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3262 viewport.setConservationSelected(conservationMenuItem.isSelected());
3264 viewport.setAbovePIDThreshold(false);
3265 abovePIDThreshold.setSelected(false);
3267 changeColour(viewport.getGlobalColourScheme());
3269 modifyConservation_actionPerformed(null);
3279 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3281 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3283 conservationMenuItem.setSelected(false);
3284 viewport.setConservationSelected(false);
3286 changeColour(viewport.getGlobalColourScheme());
3288 modifyPID_actionPerformed(null);
3298 public void userDefinedColour_actionPerformed(ActionEvent e)
3300 if (e.getActionCommand().equals("User Defined..."))
3302 new UserDefinedColours(alignPanel, null);
3306 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3307 .getUserColourSchemes().get(e.getActionCommand());
3313 public void updateUserColourMenu()
3316 Component[] menuItems = colourMenu.getMenuComponents();
3317 int i, iSize = menuItems.length;
3318 for (i = 0; i < iSize; i++)
3320 if (menuItems[i].getName() != null
3321 && menuItems[i].getName().equals("USER_DEFINED"))
3323 colourMenu.remove(menuItems[i]);
3327 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3329 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3330 .getUserColourSchemes().keys();
3332 while (userColours.hasMoreElements())
3334 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3335 userColours.nextElement().toString());
3336 radioItem.setName("USER_DEFINED");
3337 radioItem.addMouseListener(new MouseAdapter()
3340 public void mousePressed(MouseEvent evt)
3342 if (evt.isControlDown()
3343 || SwingUtilities.isRightMouseButton(evt))
3345 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3347 int option = JOptionPane.showInternalConfirmDialog(
3348 jalview.gui.Desktop.desktop,
3349 "Remove from default list?",
3350 "Remove user defined colour",
3351 JOptionPane.YES_NO_OPTION);
3352 if (option == JOptionPane.YES_OPTION)
3354 jalview.gui.UserDefinedColours
3355 .removeColourFromDefaults(radioItem.getText());
3356 colourMenu.remove(radioItem);
3360 radioItem.addActionListener(new ActionListener()
3363 public void actionPerformed(ActionEvent evt)
3365 userDefinedColour_actionPerformed(evt);
3372 radioItem.addActionListener(new ActionListener()
3375 public void actionPerformed(ActionEvent evt)
3377 userDefinedColour_actionPerformed(evt);
3381 colourMenu.insert(radioItem, 15);
3382 colours.add(radioItem);
3394 public void PIDColour_actionPerformed(ActionEvent e)
3396 changeColour(new PIDColourScheme());
3406 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3408 changeColour(new Blosum62ColourScheme());
3418 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3420 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3421 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3422 .getAlignment().getSequenceAt(0), null);
3423 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3424 viewport.getAlignment()));
3425 alignPanel.paintAlignment(true);
3435 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3437 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3438 AlignmentSorter.sortByID(viewport.getAlignment());
3439 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3440 viewport.getAlignment()));
3441 alignPanel.paintAlignment(true);
3451 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3453 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3454 AlignmentSorter.sortByLength(viewport.getAlignment());
3455 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3456 viewport.getAlignment()));
3457 alignPanel.paintAlignment(true);
3467 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3469 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3470 AlignmentSorter.sortByGroup(viewport.getAlignment());
3471 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3472 viewport.getAlignment()));
3474 alignPanel.paintAlignment(true);
3484 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3486 new RedundancyPanel(alignPanel, this);
3496 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3498 if ((viewport.getSelectionGroup() == null)
3499 || (viewport.getSelectionGroup().getSize() < 2))
3501 JOptionPane.showInternalMessageDialog(this,
3502 "You must select at least 2 sequences.", "Invalid Selection",
3503 JOptionPane.WARNING_MESSAGE);
3507 JInternalFrame frame = new JInternalFrame();
3508 frame.setContentPane(new PairwiseAlignPanel(viewport));
3509 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3520 public void PCAMenuItem_actionPerformed(ActionEvent e)
3522 if (((viewport.getSelectionGroup() != null)
3523 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3524 .getSelectionGroup().getSize() > 0))
3525 || (viewport.getAlignment().getHeight() < 4))
3527 JOptionPane.showInternalMessageDialog(this,
3528 "Principal component analysis must take\n"
3529 + "at least 4 input sequences.",
3530 "Sequence selection insufficient",
3531 JOptionPane.WARNING_MESSAGE);
3536 new PCAPanel(alignPanel);
3540 public void autoCalculate_actionPerformed(ActionEvent e)
3542 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3543 if (viewport.autoCalculateConsensus)
3545 viewport.firePropertyChange("alignment", null, viewport
3546 .getAlignment().getSequences());
3551 public void sortByTreeOption_actionPerformed(ActionEvent e)
3553 viewport.sortByTree = sortByTree.isSelected();
3557 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3559 viewport.followSelection = listenToViewSelections.isSelected();
3569 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3571 NewTreePanel("AV", "PID", "Average distance tree using PID");
3581 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3583 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3593 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3595 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3605 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3607 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3620 void NewTreePanel(String type, String pwType, String title)
3624 if (viewport.getSelectionGroup() != null)
3626 if (viewport.getSelectionGroup().getSize() < 3)
3631 "You need to have more than two sequences selected to build a tree!",
3632 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3636 SequenceGroup sg = viewport.getSelectionGroup();
3638 /* Decide if the selection is a column region */
3639 for (SequenceI _s:sg.getSequences())
3641 if (_s.getLength() < sg
3647 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3648 + "Try using the Pad function in the edit menu,\n"
3649 + "or one of the multiple sequence alignment web services.",
3650 "Sequences in selection are not aligned",
3651 JOptionPane.WARNING_MESSAGE);
3657 title = title + " on region";
3658 tp = new TreePanel(alignPanel, type, pwType);
3662 // are the visible sequences aligned?
3663 if (!viewport.getAlignment().isAligned(false))
3668 "The sequences must be aligned before creating a tree.\n"
3669 + "Try using the Pad function in the edit menu,\n"
3670 + "or one of the multiple sequence alignment web services.",
3671 "Sequences not aligned",
3672 JOptionPane.WARNING_MESSAGE);
3677 if (viewport.getAlignment().getHeight() < 2)
3682 tp = new TreePanel(alignPanel, type, pwType);
3687 if (viewport.viewName != null)
3689 title += viewport.viewName + " of ";
3692 title += this.title;
3694 Desktop.addInternalFrame(tp, title, 600, 500);
3705 public void addSortByOrderMenuItem(String title,
3706 final AlignmentOrder order)
3708 final JMenuItem item = new JMenuItem("by " + title);
3710 item.addActionListener(new java.awt.event.ActionListener()
3713 public void actionPerformed(ActionEvent e)
3715 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3717 // TODO: JBPNote - have to map order entries to curent SequenceI
3719 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3721 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3724 alignPanel.paintAlignment(true);
3730 * Add a new sort by annotation score menu item
3733 * the menu to add the option to
3735 * the label used to retrieve scores for each sequence on the
3738 public void addSortByAnnotScoreMenuItem(JMenu sort,
3739 final String scoreLabel)
3741 final JMenuItem item = new JMenuItem(scoreLabel);
3743 item.addActionListener(new java.awt.event.ActionListener()
3746 public void actionPerformed(ActionEvent e)
3748 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3749 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3750 viewport.getAlignment());// ,viewport.getSelectionGroup());
3751 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3752 viewport.getAlignment()));
3753 alignPanel.paintAlignment(true);
3759 * last hash for alignment's annotation array - used to minimise cost of
3762 protected int _annotationScoreVectorHash;
3765 * search the alignment and rebuild the sort by annotation score submenu the
3766 * last alignment annotation vector hash is stored to minimize cost of
3767 * rebuilding in subsequence calls.
3771 public void buildSortByAnnotationScoresMenu()
3773 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3778 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3780 sortByAnnotScore.removeAll();
3781 // almost certainly a quicker way to do this - but we keep it simple
3782 Hashtable scoreSorts = new Hashtable();
3783 AlignmentAnnotation aann[];
3784 for (SequenceI sqa:viewport.getAlignment().getSequences())
3786 aann = sqa.getAnnotation();
3787 for (int i = 0; aann != null && i < aann.length; i++)
3789 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3791 scoreSorts.put(aann[i].label, aann[i].label);
3795 Enumeration labels = scoreSorts.keys();
3796 while (labels.hasMoreElements())
3798 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3799 (String) labels.nextElement());
3801 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3804 _annotationScoreVectorHash = viewport.getAlignment()
3805 .getAlignmentAnnotation().hashCode();
3810 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3811 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3812 * call. Listeners are added to remove the menu item when the treePanel is
3813 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3817 * Displayed tree window.
3819 * SortBy menu item title.
3822 public void buildTreeMenu()
3824 sortByTreeMenu.removeAll();
3826 Vector comps = (Vector) PaintRefresher.components.get(viewport
3827 .getSequenceSetId());
3828 Vector treePanels = new Vector();
3829 int i, iSize = comps.size();
3830 for (i = 0; i < iSize; i++)
3832 if (comps.elementAt(i) instanceof TreePanel)
3834 treePanels.add(comps.elementAt(i));
3838 iSize = treePanels.size();
3842 sortByTreeMenu.setVisible(false);
3846 sortByTreeMenu.setVisible(true);
3848 for (i = 0; i < treePanels.size(); i++)
3850 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3851 final JMenuItem item = new JMenuItem(tp.getTitle());
3852 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3853 item.addActionListener(new java.awt.event.ActionListener()
3856 public void actionPerformed(ActionEvent e)
3858 tp.sortByTree_actionPerformed(null);
3859 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3864 sortByTreeMenu.add(item);
3868 public boolean sortBy(AlignmentOrder alorder, String undoname)
3870 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3871 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3872 if (undoname != null)
3874 addHistoryItem(new OrderCommand(undoname, oldOrder,
3875 viewport.getAlignment()));
3877 alignPanel.paintAlignment(true);
3882 * Work out whether the whole set of sequences or just the selected set will
3883 * be submitted for multiple alignment.
3886 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3888 // Now, check we have enough sequences
3889 AlignmentView msa = null;
3891 if ((viewport.getSelectionGroup() != null)
3892 && (viewport.getSelectionGroup().getSize() > 1))
3894 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3895 // some common interface!
3897 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3898 * SequenceI[sz = seqs.getSize(false)];
3900 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3901 * seqs.getSequenceAt(i); }
3903 msa = viewport.getAlignmentView(true);
3908 * Vector seqs = viewport.getAlignment().getSequences();
3910 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3912 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3913 * seqs.elementAt(i); } }
3915 msa = viewport.getAlignmentView(false);
3921 * Decides what is submitted to a secondary structure prediction service: the
3922 * first sequence in the alignment, or in the current selection, or, if the
3923 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3924 * region or the whole alignment. (where the first sequence in the set is the
3925 * one that the prediction will be for).
3927 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3929 AlignmentView seqs = null;
3931 if ((viewport.getSelectionGroup() != null)
3932 && (viewport.getSelectionGroup().getSize() > 0))
3934 seqs = viewport.getAlignmentView(true);
3938 seqs = viewport.getAlignmentView(false);
3940 // limit sequences - JBPNote in future - could spawn multiple prediction
3942 // TODO: viewport.getAlignment().isAligned is a global state - the local
3943 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3944 if (!viewport.getAlignment().isAligned(false))
3946 seqs.setSequences(new SeqCigar[]
3947 { seqs.getSequences()[0] });
3948 // TODO: if seqs.getSequences().length>1 then should really have warned
3962 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3964 // Pick the tree file
3965 JalviewFileChooser chooser = new JalviewFileChooser(
3966 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3967 chooser.setFileView(new JalviewFileView());
3968 chooser.setDialogTitle("Select a newick-like tree file");
3969 chooser.setToolTipText("Load a tree file");
3971 int value = chooser.showOpenDialog(null);
3973 if (value == JalviewFileChooser.APPROVE_OPTION)
3975 String choice = chooser.getSelectedFile().getPath();
3976 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3977 jalview.io.NewickFile fin = null;
3980 fin = new jalview.io.NewickFile(choice, "File");
3981 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3982 } catch (Exception ex)
3984 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3985 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3986 ex.printStackTrace();
3988 if (fin != null && fin.hasWarningMessage())
3990 JOptionPane.showMessageDialog(Desktop.desktop,
3991 fin.getWarningMessage(), "Possible problem with tree file",
3992 JOptionPane.WARNING_MESSAGE);
3998 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4000 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4003 public TreePanel ShowNewickTree(NewickFile nf, String title)
4005 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4008 public TreePanel ShowNewickTree(NewickFile nf, String title,
4009 AlignmentView input)
4011 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4014 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4015 int h, int x, int y)
4017 return ShowNewickTree(nf, title, null, w, h, x, y);
4021 * Add a treeviewer for the tree extracted from a newick file object to the
4022 * current alignment view
4029 * Associated alignment input data (or null)
4038 * @return TreePanel handle
4040 public TreePanel ShowNewickTree(NewickFile nf, String title,
4041 AlignmentView input, int w, int h, int x, int y)
4043 TreePanel tp = null;
4049 if (nf.getTree() != null)
4051 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4057 tp.setLocation(x, y);
4060 Desktop.addInternalFrame(tp, title, w, h);
4062 } catch (Exception ex)
4064 ex.printStackTrace();
4070 private boolean buildingMenu = false;
4073 * Generates menu items and listener event actions for web service clients
4076 public void BuildWebServiceMenu()
4078 while (buildingMenu)
4082 System.err.println("Waiting for building menu to finish.");
4084 } catch (Exception e)
4089 final AlignFrame me = this;
4090 buildingMenu = true;
4091 new Thread(new Runnable()
4098 System.err.println("Building ws menu again "
4099 + Thread.currentThread());
4100 // TODO: add support for context dependent disabling of services based
4102 // alignment and current selection
4103 // TODO: add additional serviceHandle parameter to specify abstract
4105 // class independently of AbstractName
4106 // TODO: add in rediscovery GUI function to restart discoverer
4107 // TODO: group services by location as well as function and/or
4109 // object broker mechanism.
4110 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4111 final IProgressIndicator af = me;
4112 final JMenu msawsmenu = new JMenu("Alignment");
4113 final JMenu secstrmenu = new JMenu(
4114 "Secondary Structure Prediction");
4115 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4116 final JMenu analymenu = new JMenu("Analysis");
4117 final JMenu dismenu = new JMenu("Protein Disorder");
4118 // JAL-940 - only show secondary structure prediction services from
4119 // the legacy server
4120 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4122 Discoverer.services != null && (Discoverer.services.size() > 0))
4124 // TODO: refactor to allow list of AbstractName/Handler bindings to
4126 // stored or retrieved from elsewhere
4127 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4128 Vector secstrpr = (Vector) Discoverer.services
4130 Vector seqsrch = null; // (Vector)
4131 // Discoverer.services.get("SeqSearch");
4132 // TODO: move GUI generation code onto service implementation - so a
4133 // client instance attaches itself to the GUI with method call like
4134 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4138 // Add any Multiple Sequence Alignment Services
4139 for (int i = 0, j = msaws.size(); i < j; i++)
4141 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4143 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4144 .getServiceClient(sh);
4145 impl.attachWSMenuEntry(msawsmenu, me);
4149 if (secstrpr != null)
4151 // Add any secondary structure prediction services
4152 for (int i = 0, j = secstrpr.size(); i < j; i++)
4154 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4156 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4157 .getServiceClient(sh);
4158 impl.attachWSMenuEntry(secstrmenu, me);
4161 if (seqsrch != null)
4163 // Add any sequence search services
4164 for (int i = 0, j = seqsrch.size(); i < j; i++)
4166 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4168 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4169 .getServiceClient(sh);
4170 impl.attachWSMenuEntry(seqsrchmenu, me);
4175 // Add all submenus in the order they should appear on the web
4177 wsmenu.add(msawsmenu);
4178 wsmenu.add(secstrmenu);
4179 wsmenu.add(dismenu);
4180 wsmenu.add(analymenu);
4181 // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
4182 // submens.add(msawsmenu);
4183 // submens.add(secstrmenu);
4184 // submens.add(dismenu);
4185 // submens.add(analymenu);
4187 // No search services yet
4188 // wsmenu.add(seqsrchmenu);
4190 javax.swing.SwingUtilities.invokeLater(new Runnable()
4197 webService.removeAll();
4198 // first, add discovered services onto the webservices menu
4199 if (wsmenu.size() > 0)
4201 for (int i = 0, j = wsmenu.size(); i < j; i++)
4203 webService.add(wsmenu.get(i));
4208 webService.add(me.webServiceNoServices);
4210 // TODO: move into separate menu builder class.
4211 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4213 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4214 if (jws2servs != null)
4216 if (jws2servs.hasServices())
4218 jws2servs.attachWSMenuEntry(webService, me);
4220 if (jws2servs.isRunning())
4222 JMenuItem tm = new JMenuItem(
4223 "Still discovering JABA Services");
4224 tm.setEnabled(false);
4230 build_urlServiceMenu(me.webService);
4231 build_fetchdbmenu(webService);
4232 for (JMenu item : wsmenu)
4234 if (item.getItemCount() == 0)
4236 item.setEnabled(false);
4240 item.setEnabled(true);
4243 } catch (Exception e)
4249 } catch (Exception e)
4254 buildingMenu = false;
4261 * construct any groupURL type service menu entries.
4265 private void build_urlServiceMenu(JMenu webService)
4267 // TODO: remove this code when 2.7 is released
4268 // DEBUG - alignmentView
4270 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4271 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4273 * @Override public void actionPerformed(ActionEvent e) {
4274 * jalview.datamodel.AlignmentView
4275 * .testSelectionViews(af.viewport.getAlignment(),
4276 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4278 * }); webService.add(testAlView);
4280 // TODO: refactor to RestClient discoverer and merge menu entries for
4281 // rest-style services with other types of analysis/calculation service
4282 // SHmmr test client - still being implemented.
4283 // DEBUG - alignmentView
4285 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4288 client.attachWSMenuEntry(
4289 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4293 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4295 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4301 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4302 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4303 * getProperty("LAST_DIRECTORY"));
4305 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4306 * to Vamsas file"); chooser.setToolTipText("Export");
4308 * int value = chooser.showSaveDialog(this);
4310 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4311 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4312 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4313 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4316 * prototype of an automatically enabled/disabled analysis function
4319 protected void setShowProductsEnabled()
4321 SequenceI[] selection = viewport.getSequenceSelection();
4322 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4323 viewport.getAlignment().getDataset()))
4325 showProducts.setEnabled(true);
4330 showProducts.setEnabled(false);
4335 * search selection for sequence xRef products and build the show products
4340 * @return true if showProducts menu should be enabled.
4342 public boolean canShowProducts(SequenceI[] selection,
4343 boolean isRegionSelection, Alignment dataset)
4345 boolean showp = false;
4348 showProducts.removeAll();
4349 final boolean dna = viewport.getAlignment().isNucleotide();
4350 final Alignment ds = dataset;
4351 String[] ptypes = (selection == null || selection.length == 0) ? null
4352 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4354 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4355 // selection, dataset, true);
4356 final SequenceI[] sel = selection;
4357 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4360 final boolean isRegSel = isRegionSelection;
4361 final AlignFrame af = this;
4362 final String source = ptypes[t];
4363 JMenuItem xtype = new JMenuItem(ptypes[t]);
4364 xtype.addActionListener(new ActionListener()
4368 public void actionPerformed(ActionEvent e)
4370 // TODO: new thread for this call with vis-delay
4371 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4372 isRegSel, dna, source);
4376 showProducts.add(xtype);
4378 showProducts.setVisible(showp);
4379 showProducts.setEnabled(showp);
4380 } catch (Exception e)
4382 jalview.bin.Cache.log
4383 .warn("canTranslate threw an exception - please report to help@jalview.org",
4390 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4391 boolean isRegSel, boolean dna, String source)
4393 final boolean fisRegSel = isRegSel;
4394 final boolean fdna = dna;
4395 final String fsrc = source;
4396 final AlignFrame ths = this;
4397 final SequenceI[] fsel = sel;
4398 Runnable foo = new Runnable()
4404 final long sttime = System.currentTimeMillis();
4405 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4408 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4412 Alignment prods = CrossRef
4413 .findXrefSequences(fsel, fdna, fsrc, ds);
4416 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4417 for (int s = 0; s < sprods.length; s++)
4419 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4420 if (ds.getSequences() == null
4421 || !ds.getSequences().contains(
4422 sprods[s].getDatasetSequence()))
4423 ds.addSequence(sprods[s].getDatasetSequence());
4424 sprods[s].updatePDBIds();
4426 Alignment al = new Alignment(sprods);
4427 AlignedCodonFrame[] cf = prods.getCodonFrames();
4429 for (int s = 0; cf != null && s < cf.length; s++)
4431 al.addCodonFrame(cf[s]);
4434 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4436 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4437 + " for " + ((fisRegSel) ? "selected region of " : "")
4439 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4444 System.err.println("No Sequences generated for xRef type "
4447 } catch (Exception e)
4449 jalview.bin.Cache.log.error(
4450 "Exception when finding crossreferences", e);
4451 } catch (OutOfMemoryError e)
4453 new OOMWarning("whilst fetching crossreferences", e);
4456 jalview.bin.Cache.log.error("Error when finding crossreferences",
4459 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4464 Thread frunner = new Thread(foo);
4468 public boolean canShowTranslationProducts(SequenceI[] selection,
4469 AlignmentI alignment)
4474 return (jalview.analysis.Dna.canTranslate(selection,
4475 viewport.getViewAsVisibleContigs(true)));
4476 } catch (Exception e)
4478 jalview.bin.Cache.log
4479 .warn("canTranslate threw an exception - please report to help@jalview.org",
4486 public void showProducts_actionPerformed(ActionEvent e)
4488 // /////////////////////////////
4489 // Collect Data to be translated/transferred
4491 SequenceI[] selection = viewport.getSequenceSelection();
4492 AlignmentI al = null;
4495 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4496 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4497 viewport.getAlignment().getDataset());
4498 } catch (Exception ex)
4501 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4508 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4509 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4513 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4514 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4515 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4520 public void showTranslation_actionPerformed(ActionEvent e)
4522 // /////////////////////////////
4523 // Collect Data to be translated/transferred
4525 SequenceI[] selection = viewport.getSequenceSelection();
4526 String[] seqstring = viewport.getViewAsString(true);
4527 AlignmentI al = null;
4530 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4531 viewport.getViewAsVisibleContigs(true), viewport
4532 .getGapCharacter(), viewport.getAlignment()
4533 .getAlignmentAnnotation(), viewport.getAlignment()
4534 .getWidth(), viewport.getAlignment().getDataset());
4535 } catch (Exception ex)
4538 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4545 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4546 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4550 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4551 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4552 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4557 * Try to load a features file onto the alignment.
4560 * contents or path to retrieve file
4562 * access mode of file (see jalview.io.AlignFile)
4563 * @return true if features file was parsed corectly.
4565 public boolean parseFeaturesFile(String file, String type)
4567 boolean featuresFile = false;
4570 featuresFile = new FeaturesFile(file, type).parse(viewport
4571 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4572 .getFeatureRenderer().featureColours, false,
4573 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4574 } catch (Exception ex)
4576 ex.printStackTrace();
4581 viewport.showSequenceFeatures = true;
4582 showSeqFeatures.setSelected(true);
4583 if (alignPanel.seqPanel.seqCanvas.fr != null)
4585 // update the min/max ranges where necessary
4586 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4588 if (featureSettings != null)
4590 featureSettings.setTableData();
4592 alignPanel.paintAlignment(true);
4595 return featuresFile;
4599 public void dragEnter(DropTargetDragEvent evt)
4604 public void dragExit(DropTargetEvent evt)
4609 public void dragOver(DropTargetDragEvent evt)
4614 public void dropActionChanged(DropTargetDragEvent evt)
4619 public void drop(DropTargetDropEvent evt)
4621 Transferable t = evt.getTransferable();
4622 java.util.List files = null;
4626 DataFlavor uriListFlavor = new DataFlavor(
4627 "text/uri-list;class=java.lang.String");
4628 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4630 // Works on Windows and MacOSX
4631 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4632 files = (java.util.List) t
4633 .getTransferData(DataFlavor.javaFileListFlavor);
4635 else if (t.isDataFlavorSupported(uriListFlavor))
4637 // This is used by Unix drag system
4638 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4639 String data = (String) t.getTransferData(uriListFlavor);
4640 files = new java.util.ArrayList(1);
4641 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4642 data, "\r\n"); st.hasMoreTokens();)
4644 String s = st.nextToken();
4645 if (s.startsWith("#"))
4647 // the line is a comment (as per the RFC 2483)
4651 java.net.URI uri = new java.net.URI(s);
4652 // check to see if we can handle this kind of URI
4653 if (uri.getScheme().toLowerCase().startsWith("http"))
4655 files.add(uri.toString());
4659 // otherwise preserve old behaviour: catch all for file objects
4660 java.io.File file = new java.io.File(uri);
4661 files.add(file.toString());
4665 } catch (Exception e)
4667 e.printStackTrace();
4673 // check to see if any of these files have names matching sequences in
4675 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4676 .getAlignment().getSequencesArray());
4678 * Object[] { String,SequenceI}
4680 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4681 ArrayList<String> filesnotmatched = new ArrayList<String>();
4682 for (int i = 0; i < files.size(); i++)
4684 String file = files.get(i).toString();
4686 String protocol = FormatAdapter.checkProtocol(file);
4687 if (protocol == jalview.io.FormatAdapter.FILE)
4689 File fl = new File(file);
4690 pdbfn = fl.getName();
4692 else if (protocol == jalview.io.FormatAdapter.URL)
4694 URL url = new URL(file);
4695 pdbfn = url.getFile();
4697 if (pdbfn.length() > 0)
4699 // attempt to find a match in the alignment
4700 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4701 int l = 0, c = pdbfn.indexOf(".");
4702 while (mtch == null && c != -1)
4707 } while ((c = pdbfn.indexOf(".", l)) > l);
4710 pdbfn = pdbfn.substring(0, l);
4712 mtch = idm.findAllIdMatches(pdbfn);
4719 type = new IdentifyFile().Identify(file, protocol);
4720 } catch (Exception ex)
4726 if (type.equalsIgnoreCase("PDB"))
4728 filesmatched.add(new Object[]
4729 { file, protocol, mtch });
4734 // File wasn't named like one of the sequences or wasn't a PDB file.
4735 filesnotmatched.add(file);
4739 if (filesmatched.size() > 0)
4741 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4745 "Do you want to automatically associate the "
4746 + filesmatched.size()
4747 + " PDB files with sequences in the alignment that have the same name ?",
4748 "Automatically Associate PDB files by name",
4749 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4752 for (Object[] fm : filesmatched)
4754 // try and associate
4755 // TODO: may want to set a standard ID naming formalism for
4756 // associating PDB files which have no IDs.
4757 for (SequenceI toassoc : (SequenceI[]) fm[2])
4759 PDBEntry pe = new AssociatePdbFileWithSeq()
4760 .associatePdbWithSeq((String) fm[0],
4761 (String) fm[1], toassoc, false);
4764 System.err.println("Associated file : "
4765 + ((String) fm[0]) + " with "
4766 + toassoc.getDisplayId(true));
4770 alignPanel.paintAlignment(true);
4774 if (filesnotmatched.size() > 0)
4777 && (Cache.getDefault(
4778 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4781 "<html>Do you want to <em>ignore</em> the "
4782 + filesnotmatched.size()
4783 + " files whose names did not match any sequence IDs ?</html>",
4784 "Ignore unmatched dropped files ?",
4785 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4789 for (String fn : filesnotmatched)
4791 loadJalviewDataFile(fn, null, null, null);
4795 } catch (Exception ex)
4797 ex.printStackTrace();
4803 * Attempt to load a "dropped" file or URL string: First by testing whether
4804 * it's and Annotation file, then a JNet file, and finally a features file. If
4805 * all are false then the user may have dropped an alignment file onto this
4809 * either a filename or a URL string.
4811 public void loadJalviewDataFile(String file, String protocol,
4812 String format, SequenceI assocSeq)
4816 if (protocol == null)
4818 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4820 // if the file isn't identified, or not positively identified as some
4821 // other filetype (PFAM is default unidentified alignment file type) then
4822 // try to parse as annotation.
4823 boolean isAnnotation = (format == null || format
4824 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4825 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4830 // first see if its a T-COFFEE score file
4831 TCoffeeScoreFile tcf = null;
4834 tcf = new TCoffeeScoreFile(file, protocol);
4837 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4839 tcoffeeColour.setEnabled(true);
4840 tcoffeeColour.setSelected(true);
4841 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4842 isAnnotation = true;
4844 .setText("Successfully pasted T-Coffee scores to alignment.");
4848 // some problem - if no warning its probable that the ID matching process didn't work
4849 JOptionPane.showMessageDialog(Desktop.desktop,
4850 tcf.getWarningMessage()==null ? "Check that the file matches sequence IDs in the alignment." : tcf.getWarningMessage(),
4851 "Problem reading T-COFFEE score file",
4852 JOptionPane.WARNING_MESSAGE);
4859 } catch (Exception x)
4861 Cache.log.debug("Exception when processing data source as T-COFFEE score file",x);
4866 // try to see if its a JNet 'concise' style annotation file *before*
4868 // try to parse it as a features file
4871 format = new IdentifyFile().Identify(file, protocol);
4873 if (format.equalsIgnoreCase("JnetFile"))
4875 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4877 new JnetAnnotationMaker().add_annotation(predictions,
4878 viewport.getAlignment(), 0, false);
4879 isAnnotation = true;
4884 * if (format.equalsIgnoreCase("PDB")) {
4886 * String pdbfn = ""; // try to match up filename with sequence id
4887 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4888 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4889 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4890 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4891 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4892 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4893 * // attempt to find a match in the alignment SequenceI mtch =
4894 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4895 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4896 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4897 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4898 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4899 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4900 * { System.err.println("Associated file : " + file + " with " +
4901 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4902 * TODO: maybe need to load as normal otherwise return; } }
4904 // try to parse it as a features file
4905 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4906 // if it wasn't a features file then we just treat it as a general
4907 // alignment file to load into the current view.
4910 new FileLoader().LoadFile(viewport, file, protocol, format);
4914 alignPanel.paintAlignment(true);
4922 alignPanel.adjustAnnotationHeight();
4923 viewport.updateSequenceIdColours();
4924 buildSortByAnnotationScoresMenu();
4925 alignPanel.paintAlignment(true);
4927 } catch (Exception ex)
4929 ex.printStackTrace();
4934 public void tabSelectionChanged(int index)
4938 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4939 viewport = alignPanel.av;
4940 setMenusFromViewport(viewport);
4945 public void tabbedPane_mousePressed(MouseEvent e)
4947 if (SwingUtilities.isRightMouseButton(e))
4949 String reply = JOptionPane.showInternalInputDialog(this,
4950 "Enter View Name", "Edit View Name",
4951 JOptionPane.QUESTION_MESSAGE);
4955 viewport.viewName = reply;
4956 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4961 public AlignViewport getCurrentView()
4967 * Open the dialog for regex description parsing.
4970 protected void extractScores_actionPerformed(ActionEvent e)
4972 ParseProperties pp = new jalview.analysis.ParseProperties(
4973 viewport.getAlignment());
4974 // TODO: verify regex and introduce GUI dialog for version 2.5
4975 // if (pp.getScoresFromDescription("col", "score column ",
4976 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4978 if (pp.getScoresFromDescription("description column",
4979 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4981 buildSortByAnnotationScoresMenu();
4989 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4993 protected void showDbRefs_actionPerformed(ActionEvent e)
4995 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5001 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5005 protected void showNpFeats_actionPerformed(ActionEvent e)
5007 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5011 * find the viewport amongst the tabs in this alignment frame and close that
5016 public boolean closeView(AlignViewport av)
5020 this.closeMenuItem_actionPerformed(false);
5023 Component[] comp = tabbedPane.getComponents();
5024 for (int i = 0; comp != null && i < comp.length; i++)
5026 if (comp[i] instanceof AlignmentPanel)
5028 if (((AlignmentPanel) comp[i]).av == av)
5031 closeView((AlignmentPanel) comp[i]);
5039 protected void build_fetchdbmenu(JMenu webService)
5041 // Temporary hack - DBRef Fetcher always top level ws entry.
5042 // TODO We probably want to store a sequence database checklist in
5043 // preferences and have checkboxes.. rather than individual sources selected
5045 final JMenu rfetch = new JMenu("Fetch DB References");
5046 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5047 webService.add(rfetch);
5049 JMenuItem fetchr = new JMenuItem("Standard Databases");
5050 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5051 fetchr.addActionListener(new ActionListener()
5055 public void actionPerformed(ActionEvent e)
5057 new Thread(new Runnable()
5063 new jalview.ws.DBRefFetcher(alignPanel.av
5064 .getSequenceSelection(), alignPanel.alignFrame)
5065 .fetchDBRefs(false);
5073 final AlignFrame me = this;
5074 new Thread(new Runnable()
5079 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5080 .getSequenceFetcherSingleton(me);
5081 javax.swing.SwingUtilities.invokeLater(new Runnable()
5086 String[] dbclasses = sf.getOrderedSupportedSources();
5087 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5088 // jalview.util.QuickSort.sort(otherdb, otherdb);
5089 List<DbSourceProxy> otherdb;
5090 JMenu dfetch = new JMenu();
5091 JMenu ifetch = new JMenu();
5092 JMenuItem fetchr = null;
5093 int comp = 0, icomp = 0, mcomp = 15;
5094 String mname = null;
5096 for (String dbclass : dbclasses)
5098 otherdb = sf.getSourceProxy(dbclass);
5099 // add a single entry for this class, or submenu allowing 'fetch
5101 if (otherdb == null || otherdb.size() < 1)
5105 // List<DbSourceProxy> dbs=otherdb;
5106 // otherdb=new ArrayList<DbSourceProxy>();
5107 // for (DbSourceProxy db:dbs)
5109 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5113 mname = "From " + dbclass;
5115 if (otherdb.size() == 1)
5117 final DbSourceProxy[] dassource = otherdb
5118 .toArray(new DbSourceProxy[0]);
5119 DbSourceProxy src = otherdb.get(0);
5120 fetchr = new JMenuItem(src.getDbSource());
5121 fetchr.addActionListener(new ActionListener()
5125 public void actionPerformed(ActionEvent e)
5127 new Thread(new Runnable()
5133 new jalview.ws.DBRefFetcher(alignPanel.av
5134 .getSequenceSelection(),
5135 alignPanel.alignFrame, dassource)
5136 .fetchDBRefs(false);
5142 fetchr.setToolTipText("<html>"
5143 + JvSwingUtils.wrapTooltip("Retrieve from "
5144 + src.getDbName()) + "<html>");
5150 final DbSourceProxy[] dassource = otherdb
5151 .toArray(new DbSourceProxy[0]);
5153 DbSourceProxy src = otherdb.get(0);
5154 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5156 fetchr.addActionListener(new ActionListener()
5159 public void actionPerformed(ActionEvent e)
5161 new Thread(new Runnable()
5167 new jalview.ws.DBRefFetcher(alignPanel.av
5168 .getSequenceSelection(),
5169 alignPanel.alignFrame, dassource)
5170 .fetchDBRefs(false);
5176 fetchr.setToolTipText("<html>"
5177 + JvSwingUtils.wrapTooltip("Retrieve from all "
5178 + otherdb.size() + " sources in "
5179 + src.getDbSource() + "<br>First is :"
5180 + src.getDbName()) + "<html>");
5183 // and then build the rest of the individual menus
5184 ifetch = new JMenu("Sources from " + src.getDbSource());
5186 String imname = null;
5188 for (DbSourceProxy sproxy : otherdb)
5190 String dbname = sproxy.getDbName();
5191 String sname = dbname.length() > 5 ? dbname.substring(0,
5192 5) + "..." : dbname;
5193 String msname = dbname.length() > 10 ? dbname.substring(
5194 0, 10) + "..." : dbname;
5197 imname = "from '" + sname + "'";
5199 fetchr = new JMenuItem(msname);
5200 final DbSourceProxy[] dassrc =
5202 fetchr.addActionListener(new ActionListener()
5206 public void actionPerformed(ActionEvent e)
5208 new Thread(new Runnable()
5214 new jalview.ws.DBRefFetcher(alignPanel.av
5215 .getSequenceSelection(),
5216 alignPanel.alignFrame, dassrc)
5217 .fetchDBRefs(false);
5223 fetchr.setToolTipText("<html>"
5224 + JvSwingUtils.wrapTooltip("Retrieve from "
5225 + dbname) + "</html>");
5228 if (++icomp >= mcomp || i == (otherdb.size()))
5230 ifetch.setText(imname + " to '" + sname + "'");
5232 ifetch = new JMenu();
5240 if (comp >= mcomp || dbi >= (dbclasses.length))
5242 dfetch.setText(mname + " to '" + dbclass + "'");
5244 dfetch = new JMenu();
5257 * Left justify the whole alignment.
5260 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5262 AlignmentI al = viewport.getAlignment();
5264 viewport.firePropertyChange("alignment", null, al);
5268 * Right justify the whole alignment.
5271 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5273 AlignmentI al = viewport.getAlignment();
5275 viewport.firePropertyChange("alignment", null, al);
5278 public void setShowSeqFeatures(boolean b)
5280 showSeqFeatures.setSelected(true);
5281 viewport.setShowSequenceFeatures(true);
5288 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5289 * awt.event.ActionEvent)
5292 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5294 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5295 alignPanel.paintAlignment(true);
5302 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5306 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5308 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5309 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5317 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5318 * .event.ActionEvent)
5321 protected void showGroupConservation_actionPerformed(ActionEvent e)
5323 viewport.setShowGroupConservation(showGroupConservation.getState());
5324 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5331 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5332 * .event.ActionEvent)
5335 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5337 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5338 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5345 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5346 * .event.ActionEvent)
5349 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5351 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5352 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5356 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5358 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5359 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5363 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5365 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5372 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5373 * .event.ActionEvent)
5376 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5378 if (viewport.getSelectionGroup() != null)
5380 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5381 viewport.getSequenceSelection(),
5382 viewport.getAlignmentView(true).getSequenceStrings(
5383 viewport.getGapCharacter()), viewport.getAlignment()
5385 viewport.getAlignment().deleteAllGroups();
5386 viewport.sequenceColours = null;
5387 viewport.setSelectionGroup(null);
5388 // set view properties for each group
5389 for (int g = 0; g < gps.length; g++)
5391 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5392 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5393 viewport.getAlignment().addGroup(gps[g]);
5394 Color col = new Color((int) (Math.random() * 255),
5395 (int) (Math.random() * 255), (int) (Math.random() * 255));
5396 col = col.brighter();
5397 for (SequenceI s:gps[g].getSequences())
5398 viewport.setSequenceColour(
5402 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5403 alignPanel.updateAnnotation();
5404 alignPanel.paintAlignment(true);
5409 * make the given alignmentPanel the currently selected tab
5411 * @param alignmentPanel
5413 public void setDisplayedView(AlignmentPanel alignmentPanel)
5415 if (!viewport.getSequenceSetId().equals(
5416 alignmentPanel.av.getSequenceSetId()))
5419 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5421 if (tabbedPane != null
5422 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5423 .getSelectedIndex())
5425 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5430 class PrintThread extends Thread
5434 public PrintThread(AlignmentPanel ap)
5439 static PageFormat pf;
5444 PrinterJob printJob = PrinterJob.getPrinterJob();
5448 printJob.setPrintable(ap, pf);
5452 printJob.setPrintable(ap);
5455 if (printJob.printDialog())
5460 } catch (Exception PrintException)
5462 PrintException.printStackTrace();