2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.AlignmentSorter;
22 import jalview.analysis.Conservation;
23 import jalview.analysis.CrossRef;
24 import jalview.analysis.NJTree;
25 import jalview.analysis.ParseProperties;
26 import jalview.analysis.SequenceIdMatcher;
27 import jalview.bin.Cache;
28 import jalview.commands.CommandI;
29 import jalview.commands.EditCommand;
30 import jalview.commands.OrderCommand;
31 import jalview.commands.RemoveGapColCommand;
32 import jalview.commands.RemoveGapsCommand;
33 import jalview.commands.SlideSequencesCommand;
34 import jalview.commands.TrimRegionCommand;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.Alignment;
37 import jalview.datamodel.AlignmentAnnotation;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentOrder;
40 import jalview.datamodel.AlignmentView;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.PDBEntry;
43 import jalview.datamodel.SeqCigar;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.io.AlignmentProperties;
48 import jalview.io.AnnotationFile;
49 import jalview.io.FeaturesFile;
50 import jalview.io.FileLoader;
51 import jalview.io.FormatAdapter;
52 import jalview.io.HTMLOutput;
53 import jalview.io.IdentifyFile;
54 import jalview.io.JalviewFileChooser;
55 import jalview.io.JalviewFileView;
56 import jalview.io.JnetAnnotationMaker;
57 import jalview.io.NewickFile;
58 import jalview.io.TCoffeeScoreFile;
59 import jalview.jbgui.GAlignFrame;
60 import jalview.schemes.Blosum62ColourScheme;
61 import jalview.schemes.BuriedColourScheme;
62 import jalview.schemes.ClustalxColourScheme;
63 import jalview.schemes.ColourSchemeI;
64 import jalview.schemes.ColourSchemeProperty;
65 import jalview.schemes.HelixColourScheme;
66 import jalview.schemes.HydrophobicColourScheme;
67 import jalview.schemes.NucleotideColourScheme;
68 import jalview.schemes.PIDColourScheme;
69 import jalview.schemes.PurinePyrimidineColourScheme;
70 import jalview.schemes.RNAHelicesColourChooser;
71 import jalview.schemes.ResidueProperties;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.UserColourScheme;
77 import jalview.schemes.ZappoColourScheme;
78 import jalview.ws.jws1.Discoverer;
79 import jalview.ws.jws2.Jws2Discoverer;
80 import jalview.ws.seqfetcher.DbSourceProxy;
82 import java.awt.BorderLayout;
83 import java.awt.Color;
84 import java.awt.Component;
85 import java.awt.GridLayout;
86 import java.awt.Rectangle;
87 import java.awt.Toolkit;
88 import java.awt.datatransfer.Clipboard;
89 import java.awt.datatransfer.DataFlavor;
90 import java.awt.datatransfer.StringSelection;
91 import java.awt.datatransfer.Transferable;
92 import java.awt.dnd.DnDConstants;
93 import java.awt.dnd.DropTargetDragEvent;
94 import java.awt.dnd.DropTargetDropEvent;
95 import java.awt.dnd.DropTargetEvent;
96 import java.awt.dnd.DropTargetListener;
97 import java.awt.event.ActionEvent;
98 import java.awt.event.ActionListener;
99 import java.awt.event.KeyAdapter;
100 import java.awt.event.KeyEvent;
101 import java.awt.event.MouseAdapter;
102 import java.awt.event.MouseEvent;
103 import java.awt.print.PageFormat;
104 import java.awt.print.PrinterJob;
105 import java.beans.PropertyChangeEvent;
108 import java.util.ArrayList;
109 import java.util.Enumeration;
110 import java.util.Hashtable;
111 import java.util.List;
112 import java.util.Vector;
114 import javax.swing.JButton;
115 import javax.swing.JEditorPane;
116 import javax.swing.JInternalFrame;
117 import javax.swing.JLabel;
118 import javax.swing.JLayeredPane;
119 import javax.swing.JMenu;
120 import javax.swing.JMenuItem;
121 import javax.swing.JOptionPane;
122 import javax.swing.JPanel;
123 import javax.swing.JProgressBar;
124 import javax.swing.JRadioButtonMenuItem;
125 import javax.swing.JScrollPane;
126 import javax.swing.SwingUtilities;
132 * @version $Revision$
134 public class AlignFrame extends GAlignFrame implements DropTargetListener,
139 public static final int DEFAULT_WIDTH = 700;
142 public static final int DEFAULT_HEIGHT = 500;
144 public AlignmentPanel alignPanel;
146 AlignViewport viewport;
148 Vector alignPanels = new Vector();
151 * Last format used to load or save alignments in this window
153 String currentFileFormat = null;
156 * Current filename for this alignment
158 String fileName = null;
161 * Creates a new AlignFrame object with specific width and height.
167 public AlignFrame(AlignmentI al, int width, int height)
169 this(al, null, width, height);
173 * Creates a new AlignFrame object with specific width, height and
179 * @param sequenceSetId
181 public AlignFrame(AlignmentI al, int width, int height,
182 String sequenceSetId)
184 this(al, null, width, height, sequenceSetId);
188 * Creates a new AlignFrame object with specific width, height and
194 * @param sequenceSetId
197 public AlignFrame(AlignmentI al, int width, int height,
198 String sequenceSetId, String viewId)
200 this(al, null, width, height, sequenceSetId, viewId);
204 * new alignment window with hidden columns
208 * @param hiddenColumns
209 * ColumnSelection or null
211 * Width of alignment frame
215 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
216 int width, int height)
218 this(al, hiddenColumns, width, height, null);
222 * Create alignment frame for al with hiddenColumns, a specific width and
223 * height, and specific sequenceId
226 * @param hiddenColumns
229 * @param sequenceSetId
232 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
233 int width, int height, String sequenceSetId)
235 this(al, hiddenColumns, width, height, sequenceSetId, null);
239 * Create alignment frame for al with hiddenColumns, a specific width and
240 * height, and specific sequenceId
243 * @param hiddenColumns
246 * @param sequenceSetId
251 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
252 int width, int height, String sequenceSetId, String viewId)
254 setSize(width, height);
255 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
257 alignPanel = new AlignmentPanel(this, viewport);
259 if (al.getDataset() == null)
264 addAlignmentPanel(alignPanel, true);
269 * Make a new AlignFrame from exisiting alignmentPanels
276 public AlignFrame(AlignmentPanel ap)
280 addAlignmentPanel(ap, false);
285 * initalise the alignframe from the underlying viewport data and the
290 if (viewport.getAlignmentConservationAnnotation() == null)
292 BLOSUM62Colour.setEnabled(false);
293 conservationMenuItem.setEnabled(false);
294 modifyConservation.setEnabled(false);
295 // PIDColour.setEnabled(false);
296 // abovePIDThreshold.setEnabled(false);
297 // modifyPID.setEnabled(false);
300 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
303 if (sortby.equals("Id"))
305 sortIDMenuItem_actionPerformed(null);
307 else if (sortby.equals("Pairwise Identity"))
309 sortPairwiseMenuItem_actionPerformed(null);
312 if (Desktop.desktop != null)
314 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
315 addServiceListeners();
316 setGUINucleotide(viewport.getAlignment().isNucleotide());
319 setMenusFromViewport(viewport);
320 buildSortByAnnotationScoresMenu();
321 if (viewport.wrapAlignment)
323 wrapMenuItem_actionPerformed(null);
326 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
328 this.overviewMenuItem_actionPerformed(null);
336 * Change the filename and format for the alignment, and enable the 'reload'
337 * button functionality.
344 public void setFileName(String file, String format)
347 currentFileFormat = format;
348 reload.setEnabled(true);
351 void addKeyListener()
353 addKeyListener(new KeyAdapter()
356 public void keyPressed(KeyEvent evt)
358 if (viewport.cursorMode
359 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
360 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
361 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
362 && Character.isDigit(evt.getKeyChar()))
363 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
365 switch (evt.getKeyCode())
368 case 27: // escape key
369 deselectAllSequenceMenuItem_actionPerformed(null);
373 case KeyEvent.VK_DOWN:
374 if (evt.isAltDown() || !viewport.cursorMode)
375 moveSelectedSequences(false);
376 if (viewport.cursorMode)
377 alignPanel.seqPanel.moveCursor(0, 1);
381 if (evt.isAltDown() || !viewport.cursorMode)
382 moveSelectedSequences(true);
383 if (viewport.cursorMode)
384 alignPanel.seqPanel.moveCursor(0, -1);
388 case KeyEvent.VK_LEFT:
389 if (evt.isAltDown() || !viewport.cursorMode)
390 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
392 alignPanel.seqPanel.moveCursor(-1, 0);
396 case KeyEvent.VK_RIGHT:
397 if (evt.isAltDown() || !viewport.cursorMode)
398 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
400 alignPanel.seqPanel.moveCursor(1, 0);
403 case KeyEvent.VK_SPACE:
404 if (viewport.cursorMode)
406 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
407 || evt.isShiftDown() || evt.isAltDown());
411 // case KeyEvent.VK_A:
412 // if (viewport.cursorMode)
414 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
415 // //System.out.println("A");
419 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
420 * System.out.println("closing bracket"); } break;
422 case KeyEvent.VK_DELETE:
423 case KeyEvent.VK_BACK_SPACE:
424 if (!viewport.cursorMode)
426 cut_actionPerformed(null);
430 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
431 || evt.isShiftDown() || evt.isAltDown());
437 if (viewport.cursorMode)
439 alignPanel.seqPanel.setCursorRow();
443 if (viewport.cursorMode && !evt.isControlDown())
445 alignPanel.seqPanel.setCursorColumn();
449 if (viewport.cursorMode)
451 alignPanel.seqPanel.setCursorPosition();
455 case KeyEvent.VK_ENTER:
456 case KeyEvent.VK_COMMA:
457 if (viewport.cursorMode)
459 alignPanel.seqPanel.setCursorRowAndColumn();
464 if (viewport.cursorMode)
466 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
470 if (viewport.cursorMode)
472 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
477 viewport.cursorMode = !viewport.cursorMode;
478 statusBar.setText("Keyboard editing mode is "
479 + (viewport.cursorMode ? "on" : "off"));
480 if (viewport.cursorMode)
482 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
483 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
485 alignPanel.seqPanel.seqCanvas.repaint();
491 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
492 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
494 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
496 javax.help.HelpBroker hb = hs.createHelpBroker();
497 hb.setCurrentID("home");
498 hb.setDisplayed(true);
499 } catch (Exception ex)
501 ex.printStackTrace();
506 boolean toggleSeqs = !evt.isControlDown();
507 boolean toggleCols = !evt.isShiftDown();
508 toggleHiddenRegions(toggleSeqs, toggleCols);
511 case KeyEvent.VK_PAGE_UP:
512 if (viewport.wrapAlignment)
514 alignPanel.scrollUp(true);
518 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
519 - viewport.endSeq + viewport.startSeq);
522 case KeyEvent.VK_PAGE_DOWN:
523 if (viewport.wrapAlignment)
525 alignPanel.scrollUp(false);
529 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
530 + viewport.endSeq - viewport.startSeq);
537 public void keyReleased(KeyEvent evt)
539 switch (evt.getKeyCode())
541 case KeyEvent.VK_LEFT:
542 if (evt.isAltDown() || !viewport.cursorMode)
543 viewport.firePropertyChange("alignment", null, viewport
544 .getAlignment().getSequences());
547 case KeyEvent.VK_RIGHT:
548 if (evt.isAltDown() || !viewport.cursorMode)
549 viewport.firePropertyChange("alignment", null, viewport
550 .getAlignment().getSequences());
557 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
559 ap.alignFrame = this;
561 alignPanels.addElement(ap);
563 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
565 int aSize = alignPanels.size();
567 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
569 if (aSize == 1 && ap.av.viewName == null)
571 this.getContentPane().add(ap, BorderLayout.CENTER);
577 setInitialTabVisible();
580 expandViews.setEnabled(true);
581 gatherViews.setEnabled(true);
582 tabbedPane.addTab(ap.av.viewName, ap);
584 ap.setVisible(false);
589 if (ap.av.isPadGaps())
591 ap.av.getAlignment().padGaps();
593 ap.av.updateConservation(ap);
594 ap.av.updateConsensus(ap);
595 ap.av.updateStrucConsensus(ap);
599 public void setInitialTabVisible()
601 expandViews.setEnabled(true);
602 gatherViews.setEnabled(true);
603 tabbedPane.setVisible(true);
604 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
605 tabbedPane.addTab(first.av.viewName, first);
606 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
609 public AlignViewport getViewport()
614 /* Set up intrinsic listeners for dynamically generated GUI bits. */
615 private void addServiceListeners()
617 final java.beans.PropertyChangeListener thisListener;
618 Desktop.instance.addJalviewPropertyChangeListener("services",
619 thisListener = new java.beans.PropertyChangeListener()
622 public void propertyChange(PropertyChangeEvent evt)
624 // // System.out.println("Discoverer property change.");
625 // if (evt.getPropertyName().equals("services"))
627 SwingUtilities.invokeLater(new Runnable()
634 .println("Rebuild WS Menu for service change");
635 BuildWebServiceMenu();
642 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
645 public void internalFrameClosed(
646 javax.swing.event.InternalFrameEvent evt)
648 System.out.println("deregistering discoverer listener");
649 Desktop.instance.removeJalviewPropertyChangeListener("services",
651 closeMenuItem_actionPerformed(true);
654 // Finally, build the menu once to get current service state
655 new Thread(new Runnable()
660 BuildWebServiceMenu();
665 public void setGUINucleotide(boolean nucleotide)
667 showTranslation.setVisible(nucleotide);
668 conservationMenuItem.setEnabled(!nucleotide);
669 modifyConservation.setEnabled(!nucleotide);
670 showGroupConservation.setEnabled(!nucleotide);
671 rnahelicesColour.setEnabled(nucleotide);
672 purinePyrimidineColour.setEnabled(nucleotide);
673 // Remember AlignFrame always starts as protein
677 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
682 * set up menus for the currently viewport. This may be called after any
683 * operation that affects the data in the current view (selection changed,
684 * etc) to update the menus to reflect the new state.
686 public void setMenusForViewport()
688 setMenusFromViewport(viewport);
692 * Need to call this method when tabs are selected for multiple views, or when
693 * loading from Jalview2XML.java
698 void setMenusFromViewport(AlignViewport av)
700 padGapsMenuitem.setSelected(av.isPadGaps());
701 colourTextMenuItem.setSelected(av.showColourText);
702 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
703 conservationMenuItem.setSelected(av.getConservationSelected());
704 seqLimits.setSelected(av.getShowJVSuffix());
705 idRightAlign.setSelected(av.rightAlignIds);
706 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
707 renderGapsMenuItem.setSelected(av.renderGaps);
708 wrapMenuItem.setSelected(av.wrapAlignment);
709 scaleAbove.setVisible(av.wrapAlignment);
710 scaleLeft.setVisible(av.wrapAlignment);
711 scaleRight.setVisible(av.wrapAlignment);
712 annotationPanelMenuItem.setState(av.showAnnotation);
713 viewBoxesMenuItem.setSelected(av.showBoxes);
714 viewTextMenuItem.setSelected(av.showText);
715 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
716 showGroupConsensus.setSelected(av.isShowGroupConsensus());
717 showGroupConservation.setSelected(av.isShowGroupConservation());
718 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
719 showSequenceLogo.setSelected(av.isShowSequenceLogo());
720 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
722 setColourSelected(ColourSchemeProperty.getColourName(av
723 .getGlobalColourScheme()));
725 showSeqFeatures.setSelected(av.showSequenceFeatures);
726 hiddenMarkers.setState(av.showHiddenMarkers);
727 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
728 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
729 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
730 autoCalculate.setSelected(av.autoCalculateConsensus);
731 sortByTree.setSelected(av.sortByTree);
732 listenToViewSelections.setSelected(av.followSelection);
733 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
735 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
736 setShowProductsEnabled();
741 Hashtable progressBars, progressBarHandlers;
746 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
749 public void setProgressBar(String message, long id)
751 if (progressBars == null)
753 progressBars = new Hashtable();
754 progressBarHandlers = new Hashtable();
757 JPanel progressPanel;
758 Long lId = new Long(id);
759 GridLayout layout = (GridLayout) statusPanel.getLayout();
760 if (progressBars.get(lId) != null)
762 progressPanel = (JPanel) progressBars.get(new Long(id));
763 statusPanel.remove(progressPanel);
764 progressBars.remove(lId);
765 progressPanel = null;
768 statusBar.setText(message);
770 if (progressBarHandlers.contains(lId))
772 progressBarHandlers.remove(lId);
774 layout.setRows(layout.getRows() - 1);
778 progressPanel = new JPanel(new BorderLayout(10, 5));
780 JProgressBar progressBar = new JProgressBar();
781 progressBar.setIndeterminate(true);
783 progressPanel.add(new JLabel(message), BorderLayout.WEST);
784 progressPanel.add(progressBar, BorderLayout.CENTER);
786 layout.setRows(layout.getRows() + 1);
787 statusPanel.add(progressPanel);
789 progressBars.put(lId, progressPanel);
792 // setMenusForViewport();
797 public void registerHandler(final long id,
798 final IProgressIndicatorHandler handler)
800 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
803 "call setProgressBar before registering the progress bar's handler.");
805 progressBarHandlers.put(new Long(id), handler);
806 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
807 if (handler.canCancel())
809 JButton cancel = new JButton("Cancel");
810 final IProgressIndicator us = this;
811 cancel.addActionListener(new ActionListener()
815 public void actionPerformed(ActionEvent e)
817 handler.cancelActivity(id);
820 + ((JLabel) progressPanel.getComponent(0))
824 progressPanel.add(cancel, BorderLayout.EAST);
830 * @return true if any progress bars are still active
832 public boolean operationInProgress()
834 if (progressBars != null && progressBars.size() > 0)
842 * Added so Castor Mapping file can obtain Jalview Version
844 public String getVersion()
846 return jalview.bin.Cache.getProperty("VERSION");
849 public FeatureRenderer getFeatureRenderer()
851 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
855 public void fetchSequence_actionPerformed(ActionEvent e)
857 new SequenceFetcher(this);
861 public void addFromFile_actionPerformed(ActionEvent e)
863 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
867 public void reload_actionPerformed(ActionEvent e)
869 if (fileName != null)
871 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
872 // originating file's format
873 // TODO: work out how to recover feature settings for correct view(s) when
875 if (currentFileFormat.equals("Jalview"))
877 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
878 for (int i = 0; i < frames.length; i++)
880 if (frames[i] instanceof AlignFrame && frames[i] != this
881 && ((AlignFrame) frames[i]).fileName.equals(fileName))
885 frames[i].setSelected(true);
886 Desktop.instance.closeAssociatedWindows();
887 } catch (java.beans.PropertyVetoException ex)
893 Desktop.instance.closeAssociatedWindows();
895 FileLoader loader = new FileLoader();
896 String protocol = fileName.startsWith("http:") ? "URL" : "File";
897 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
901 Rectangle bounds = this.getBounds();
903 FileLoader loader = new FileLoader();
904 String protocol = fileName.startsWith("http:") ? "URL" : "File";
905 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
906 protocol, currentFileFormat);
908 newframe.setBounds(bounds);
909 if (featureSettings != null && featureSettings.isShowing())
911 final Rectangle fspos = featureSettings.frame.getBounds();
912 // TODO: need a 'show feature settings' function that takes bounds -
913 // need to refactor Desktop.addFrame
914 newframe.featureSettings_actionPerformed(null);
915 final FeatureSettings nfs = newframe.featureSettings;
916 SwingUtilities.invokeLater(new Runnable()
921 nfs.frame.setBounds(fspos);
924 this.featureSettings.close();
925 this.featureSettings = null;
927 this.closeMenuItem_actionPerformed(true);
933 public void addFromText_actionPerformed(ActionEvent e)
935 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
939 public void addFromURL_actionPerformed(ActionEvent e)
941 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
945 public void save_actionPerformed(ActionEvent e)
948 || (currentFileFormat == null || !jalview.io.FormatAdapter
949 .isValidIOFormat(currentFileFormat, true))
950 || fileName.startsWith("http"))
952 saveAs_actionPerformed(null);
956 saveAlignment(fileName, currentFileFormat);
967 public void saveAs_actionPerformed(ActionEvent e)
969 JalviewFileChooser chooser = new JalviewFileChooser(
970 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
971 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
972 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
973 currentFileFormat, false);
975 chooser.setFileView(new JalviewFileView());
976 chooser.setDialogTitle("Save Alignment to file");
977 chooser.setToolTipText("Save");
979 int value = chooser.showSaveDialog(this);
981 if (value == JalviewFileChooser.APPROVE_OPTION)
983 currentFileFormat = chooser.getSelectedFormat();
984 if (currentFileFormat == null)
986 JOptionPane.showInternalMessageDialog(Desktop.desktop,
987 "You must select a file format before saving!",
988 "File format not specified", JOptionPane.WARNING_MESSAGE);
989 value = chooser.showSaveDialog(this);
993 fileName = chooser.getSelectedFile().getPath();
995 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
998 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
999 if (currentFileFormat.indexOf(" ") > -1)
1001 currentFileFormat = currentFileFormat.substring(0,
1002 currentFileFormat.indexOf(" "));
1004 saveAlignment(fileName, currentFileFormat);
1008 public boolean saveAlignment(String file, String format)
1010 boolean success = true;
1012 if (format.equalsIgnoreCase("Jalview"))
1014 String shortName = title;
1016 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1018 shortName = shortName.substring(shortName
1019 .lastIndexOf(java.io.File.separatorChar) + 1);
1022 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1024 statusBar.setText("Successfully saved to file: " + fileName + " in "
1025 + format + " format.");
1030 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1032 warningMessage("Cannot save file " + fileName + " using format "
1033 + format, "Alignment output format not supported");
1034 saveAs_actionPerformed(null);
1035 // JBPNote need to have a raise_gui flag here
1039 String[] omitHidden = null;
1041 if (viewport.hasHiddenColumns())
1043 int reply = JOptionPane
1044 .showInternalConfirmDialog(
1046 "The Alignment contains hidden columns."
1047 + "\nDo you want to save only the visible alignment?",
1048 "Save / Omit Hidden Columns",
1049 JOptionPane.YES_NO_OPTION,
1050 JOptionPane.QUESTION_MESSAGE);
1052 if (reply == JOptionPane.YES_OPTION)
1054 omitHidden = viewport.getViewAsString(false);
1057 FormatAdapter f = new FormatAdapter();
1058 String output = f.formatSequences(
1060 viewport.getAlignment(), // class cast exceptions will
1061 // occur in the distant future
1062 omitHidden, f.getCacheSuffixDefault(format),
1063 viewport.getColumnSelection());
1073 java.io.PrintWriter out = new java.io.PrintWriter(
1074 new java.io.FileWriter(file));
1078 this.setTitle(file);
1079 statusBar.setText("Successfully saved to file: " + fileName
1080 + " in " + format + " format.");
1081 } catch (Exception ex)
1084 ex.printStackTrace();
1091 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1092 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1098 private void warningMessage(String warning, String title)
1100 if (new jalview.util.Platform().isHeadless())
1102 System.err.println("Warning: " + title + "\nWarning: " + warning);
1107 JOptionPane.showInternalMessageDialog(this, warning, title,
1108 JOptionPane.WARNING_MESSAGE);
1120 protected void outputText_actionPerformed(ActionEvent e)
1122 String[] omitHidden = null;
1124 if (viewport.hasHiddenColumns())
1126 int reply = JOptionPane
1127 .showInternalConfirmDialog(
1129 "The Alignment contains hidden columns."
1130 + "\nDo you want to output only the visible alignment?",
1131 "Save / Omit Hidden Columns",
1132 JOptionPane.YES_NO_OPTION,
1133 JOptionPane.QUESTION_MESSAGE);
1135 if (reply == JOptionPane.YES_OPTION)
1137 omitHidden = viewport.getViewAsString(false);
1141 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1142 cap.setForInput(null);
1146 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1147 viewport.getAlignment(), omitHidden,
1148 viewport.getColumnSelection()));
1149 Desktop.addInternalFrame(cap,
1150 "Alignment output - " + e.getActionCommand(), 600, 500);
1151 } catch (OutOfMemoryError oom)
1153 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1166 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1168 new HTMLOutput(alignPanel,
1169 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1170 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1173 public void createImageMap(File file, String image)
1175 alignPanel.makePNGImageMap(file, image);
1185 public void createPNG(File f)
1187 alignPanel.makePNG(f);
1197 public void createEPS(File f)
1199 alignPanel.makeEPS(f);
1203 public void pageSetup_actionPerformed(ActionEvent e)
1205 PrinterJob printJob = PrinterJob.getPrinterJob();
1206 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1216 public void printMenuItem_actionPerformed(ActionEvent e)
1218 // Putting in a thread avoids Swing painting problems
1219 PrintThread thread = new PrintThread(alignPanel);
1224 public void exportFeatures_actionPerformed(ActionEvent e)
1226 new AnnotationExporter().exportFeatures(alignPanel);
1230 public void exportAnnotations_actionPerformed(ActionEvent e)
1232 new AnnotationExporter().exportAnnotations(alignPanel,
1233 viewport.showAnnotation ? viewport.getAlignment()
1234 .getAlignmentAnnotation() : null, viewport
1235 .getAlignment().getGroups(), ((Alignment) viewport
1236 .getAlignment()).alignmentProperties);
1240 public void associatedData_actionPerformed(ActionEvent e)
1242 // Pick the tree file
1243 JalviewFileChooser chooser = new JalviewFileChooser(
1244 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1245 chooser.setFileView(new JalviewFileView());
1246 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1247 chooser.setToolTipText("Load Jalview Annotations / Features file");
1249 int value = chooser.showOpenDialog(null);
1251 if (value == JalviewFileChooser.APPROVE_OPTION)
1253 String choice = chooser.getSelectedFile().getPath();
1254 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1255 loadJalviewDataFile(choice, null, null, null);
1261 * Close the current view or all views in the alignment frame. If the frame
1262 * only contains one view then the alignment will be removed from memory.
1264 * @param closeAllTabs
1267 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1269 if (alignPanels != null && alignPanels.size() < 2)
1271 closeAllTabs = true;
1276 if (alignPanels != null)
1280 if (this.isClosed())
1282 // really close all the windows - otherwise wait till
1283 // setClosed(true) is called
1284 for (int i = 0; i < alignPanels.size(); i++)
1286 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1293 closeView(alignPanel);
1299 this.setClosed(true);
1301 } catch (Exception ex)
1303 ex.printStackTrace();
1308 * close alignPanel2 and shuffle tabs appropriately.
1310 * @param alignPanel2
1312 public void closeView(AlignmentPanel alignPanel2)
1314 int index = tabbedPane.getSelectedIndex();
1315 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1316 alignPanels.removeElement(alignPanel2);
1318 // if (viewport == alignPanel2.av)
1322 alignPanel2.closePanel();
1325 tabbedPane.removeTabAt(closedindex);
1326 tabbedPane.validate();
1328 if (index > closedindex || index == tabbedPane.getTabCount())
1330 // modify currently selected tab index if necessary.
1334 this.tabSelectionChanged(index);
1340 void updateEditMenuBar()
1343 if (viewport.historyList.size() > 0)
1345 undoMenuItem.setEnabled(true);
1346 CommandI command = (CommandI) viewport.historyList.peek();
1347 undoMenuItem.setText("Undo " + command.getDescription());
1351 undoMenuItem.setEnabled(false);
1352 undoMenuItem.setText("Undo");
1355 if (viewport.redoList.size() > 0)
1357 redoMenuItem.setEnabled(true);
1359 CommandI command = (CommandI) viewport.redoList.peek();
1360 redoMenuItem.setText("Redo " + command.getDescription());
1364 redoMenuItem.setEnabled(false);
1365 redoMenuItem.setText("Redo");
1369 public void addHistoryItem(CommandI command)
1371 if (command.getSize() > 0)
1373 viewport.historyList.push(command);
1374 viewport.redoList.clear();
1375 updateEditMenuBar();
1376 viewport.updateHiddenColumns();
1377 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1378 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1379 // viewport.getColumnSelection()
1380 // .getHiddenColumns().size() > 0);
1386 * @return alignment objects for all views
1388 AlignmentI[] getViewAlignments()
1390 if (alignPanels != null)
1392 Enumeration e = alignPanels.elements();
1393 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1394 for (int i = 0; e.hasMoreElements(); i++)
1396 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1400 if (viewport != null)
1402 return new AlignmentI[]
1403 { viewport.getAlignment() };
1415 protected void undoMenuItem_actionPerformed(ActionEvent e)
1417 if (viewport.historyList.empty())
1419 CommandI command = (CommandI) viewport.historyList.pop();
1420 viewport.redoList.push(command);
1421 command.undoCommand(getViewAlignments());
1423 AlignViewport originalSource = getOriginatingSource(command);
1424 updateEditMenuBar();
1426 if (originalSource != null)
1428 if (originalSource != viewport)
1431 .warn("Implementation worry: mismatch of viewport origin for undo");
1433 originalSource.updateHiddenColumns();
1434 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1436 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1437 // viewport.getColumnSelection()
1438 // .getHiddenColumns().size() > 0);
1439 originalSource.firePropertyChange("alignment", null, originalSource
1440 .getAlignment().getSequences());
1451 protected void redoMenuItem_actionPerformed(ActionEvent e)
1453 if (viewport.redoList.size() < 1)
1458 CommandI command = (CommandI) viewport.redoList.pop();
1459 viewport.historyList.push(command);
1460 command.doCommand(getViewAlignments());
1462 AlignViewport originalSource = getOriginatingSource(command);
1463 updateEditMenuBar();
1465 if (originalSource != null)
1468 if (originalSource != viewport)
1471 .warn("Implementation worry: mismatch of viewport origin for redo");
1473 originalSource.updateHiddenColumns();
1474 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1476 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1477 // viewport.getColumnSelection()
1478 // .getHiddenColumns().size() > 0);
1479 originalSource.firePropertyChange("alignment", null, originalSource
1480 .getAlignment().getSequences());
1484 AlignViewport getOriginatingSource(CommandI command)
1486 AlignViewport originalSource = null;
1487 // For sequence removal and addition, we need to fire
1488 // the property change event FROM the viewport where the
1489 // original alignment was altered
1490 AlignmentI al = null;
1491 if (command instanceof EditCommand)
1493 EditCommand editCommand = (EditCommand) command;
1494 al = editCommand.getAlignment();
1495 Vector comps = (Vector) PaintRefresher.components.get(viewport
1496 .getSequenceSetId());
1498 for (int i = 0; i < comps.size(); i++)
1500 if (comps.elementAt(i) instanceof AlignmentPanel)
1502 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1504 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1511 if (originalSource == null)
1513 // The original view is closed, we must validate
1514 // the current view against the closed view first
1517 PaintRefresher.validateSequences(al, viewport.getAlignment());
1520 originalSource = viewport;
1523 return originalSource;
1532 public void moveSelectedSequences(boolean up)
1534 SequenceGroup sg = viewport.getSelectionGroup();
1540 viewport.getAlignment().moveSelectedSequencesByOne(sg, viewport.getHiddenRepSequences(), up);
1541 alignPanel.paintAlignment(true);
1544 synchronized void slideSequences(boolean right, int size)
1546 List<SequenceI> sg = new Vector();
1547 if (viewport.cursorMode)
1549 sg.add(viewport.getAlignment().getSequenceAt(
1550 alignPanel.seqPanel.seqCanvas.cursorY));
1552 else if (viewport.getSelectionGroup() != null
1553 && viewport.getSelectionGroup().getSize() != viewport
1554 .getAlignment().getHeight())
1556 sg = viewport.getSelectionGroup().getSequences(
1557 viewport.getHiddenRepSequences());
1565 Vector invertGroup = new Vector();
1567 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1569 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1570 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1573 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1575 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1576 for (int i = 0; i < invertGroup.size(); i++)
1577 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1579 SlideSequencesCommand ssc;
1581 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1582 size, viewport.getGapCharacter());
1584 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1585 size, viewport.getGapCharacter());
1587 int groupAdjustment = 0;
1588 if (ssc.getGapsInsertedBegin() && right)
1590 if (viewport.cursorMode)
1591 alignPanel.seqPanel.moveCursor(size, 0);
1593 groupAdjustment = size;
1595 else if (!ssc.getGapsInsertedBegin() && !right)
1597 if (viewport.cursorMode)
1598 alignPanel.seqPanel.moveCursor(-size, 0);
1600 groupAdjustment = -size;
1603 if (groupAdjustment != 0)
1605 viewport.getSelectionGroup().setStartRes(
1606 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1607 viewport.getSelectionGroup().setEndRes(
1608 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1611 boolean appendHistoryItem = false;
1612 if (viewport.historyList != null && viewport.historyList.size() > 0
1613 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1615 appendHistoryItem = ssc
1616 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1620 if (!appendHistoryItem)
1621 addHistoryItem(ssc);
1633 protected void copy_actionPerformed(ActionEvent e)
1636 if (viewport.getSelectionGroup() == null)
1640 // TODO: preserve the ordering of displayed alignment annotation in any
1641 // internal paste (particularly sequence associated annotation)
1642 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1643 String[] omitHidden = null;
1645 if (viewport.hasHiddenColumns())
1647 omitHidden = viewport.getViewAsString(true);
1650 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1653 StringSelection ss = new StringSelection(output);
1657 jalview.gui.Desktop.internalCopy = true;
1658 // Its really worth setting the clipboard contents
1659 // to empty before setting the large StringSelection!!
1660 Toolkit.getDefaultToolkit().getSystemClipboard()
1661 .setContents(new StringSelection(""), null);
1663 Toolkit.getDefaultToolkit().getSystemClipboard()
1664 .setContents(ss, Desktop.instance);
1665 } catch (OutOfMemoryError er)
1667 new OOMWarning("copying region", er);
1671 Vector hiddenColumns = null;
1672 if (viewport.hasHiddenColumns())
1674 hiddenColumns = new Vector();
1675 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1676 .getSelectionGroup().getEndRes();
1677 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1680 int[] region = (int[]) viewport.getColumnSelection()
1681 .getHiddenColumns().elementAt(i);
1682 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1684 hiddenColumns.addElement(new int[]
1685 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1690 Desktop.jalviewClipboard = new Object[]
1691 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1692 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1702 protected void pasteNew_actionPerformed(ActionEvent e)
1714 protected void pasteThis_actionPerformed(ActionEvent e)
1720 * Paste contents of Jalview clipboard
1722 * @param newAlignment
1723 * true to paste to a new alignment, otherwise add to this.
1725 void paste(boolean newAlignment)
1727 boolean externalPaste = true;
1730 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1731 Transferable contents = c.getContents(this);
1733 if (contents == null)
1741 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1742 if (str.length() < 1)
1747 format = new IdentifyFile().Identify(str, "Paste");
1749 } catch (OutOfMemoryError er)
1751 new OOMWarning("Out of memory pasting sequences!!", er);
1755 SequenceI[] sequences;
1756 boolean annotationAdded = false;
1757 AlignmentI alignment = null;
1759 if (Desktop.jalviewClipboard != null)
1761 // The clipboard was filled from within Jalview, we must use the
1763 // And dataset from the copied alignment
1764 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1765 // be doubly sure that we create *new* sequence objects.
1766 sequences = new SequenceI[newseq.length];
1767 for (int i = 0; i < newseq.length; i++)
1769 sequences[i] = new Sequence(newseq[i]);
1771 alignment = new Alignment(sequences);
1772 externalPaste = false;
1776 // parse the clipboard as an alignment.
1777 alignment = new FormatAdapter().readFile(str, "Paste", format);
1778 sequences = alignment.getSequencesArray();
1786 if (Desktop.jalviewClipboard != null)
1788 // dataset is inherited
1789 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1793 // new dataset is constructed
1794 alignment.setDataset(null);
1796 alwidth = alignment.getWidth() + 1;
1800 AlignmentI pastedal = alignment; // preserve pasted alignment object
1801 // Add pasted sequences and dataset into existing alignment.
1802 alignment = viewport.getAlignment();
1803 alwidth = alignment.getWidth() + 1;
1804 // decide if we need to import sequences from an existing dataset
1805 boolean importDs = Desktop.jalviewClipboard != null
1806 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1807 // importDs==true instructs us to copy over new dataset sequences from
1808 // an existing alignment
1809 Vector newDs = (importDs) ? new Vector() : null; // used to create
1810 // minimum dataset set
1812 for (int i = 0; i < sequences.length; i++)
1816 newDs.addElement(null);
1818 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1820 if (importDs && ds != null)
1822 if (!newDs.contains(ds))
1824 newDs.setElementAt(ds, i);
1825 ds = new Sequence(ds);
1826 // update with new dataset sequence
1827 sequences[i].setDatasetSequence(ds);
1831 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1836 // copy and derive new dataset sequence
1837 sequences[i] = sequences[i].deriveSequence();
1838 alignment.getDataset().addSequence(
1839 sequences[i].getDatasetSequence());
1840 // TODO: avoid creation of duplicate dataset sequences with a
1841 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1843 alignment.addSequence(sequences[i]); // merges dataset
1847 newDs.clear(); // tidy up
1849 if (pastedal.getAlignmentAnnotation() != null)
1851 // Add any annotation attached to alignment.
1852 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1853 for (int i = 0; i < alann.length; i++)
1855 annotationAdded = true;
1856 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1858 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1859 newann.padAnnotation(alwidth);
1860 alignment.addAnnotation(newann);
1870 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1871 sequences, 0, alignment.getWidth(), alignment));
1873 // Add any annotations attached to sequences
1874 for (int i = 0; i < sequences.length; i++)
1876 if (sequences[i].getAnnotation() != null)
1878 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1880 annotationAdded = true;
1881 sequences[i].getAnnotation()[a].adjustForAlignment();
1882 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1883 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1888 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1895 // propagate alignment changed.
1896 viewport.setEndSeq(alignment.getHeight());
1897 if (annotationAdded)
1899 // Duplicate sequence annotation in all views.
1900 AlignmentI[] alview = this.getViewAlignments();
1901 for (int i = 0; i < sequences.length; i++)
1903 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1906 for (int avnum = 0; avnum < alview.length; avnum++)
1908 if (alview[avnum] != alignment)
1910 // duplicate in a view other than the one with input focus
1911 int avwidth = alview[avnum].getWidth() + 1;
1912 // this relies on sann being preserved after we
1913 // modify the sequence's annotation array for each duplication
1914 for (int a = 0; a < sann.length; a++)
1916 AlignmentAnnotation newann = new AlignmentAnnotation(
1918 sequences[i].addAlignmentAnnotation(newann);
1919 newann.padAnnotation(avwidth);
1920 alview[avnum].addAnnotation(newann); // annotation was
1921 // duplicated earlier
1922 alview[avnum].setAnnotationIndex(newann, a);
1927 buildSortByAnnotationScoresMenu();
1929 viewport.firePropertyChange("alignment", null,
1930 alignment.getSequences());
1935 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1937 String newtitle = new String("Copied sequences");
1939 if (Desktop.jalviewClipboard != null
1940 && Desktop.jalviewClipboard[2] != null)
1942 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1943 for (int i = 0; i < hc.size(); i++)
1945 int[] region = (int[]) hc.elementAt(i);
1946 af.viewport.hideColumns(region[0], region[1]);
1950 // >>>This is a fix for the moment, until a better solution is
1952 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1954 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1956 // TODO: maintain provenance of an alignment, rather than just make the
1957 // title a concatenation of operations.
1960 if (title.startsWith("Copied sequences"))
1966 newtitle = newtitle.concat("- from " + title);
1971 newtitle = new String("Pasted sequences");
1974 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1979 } catch (Exception ex)
1981 ex.printStackTrace();
1982 System.out.println("Exception whilst pasting: " + ex);
1983 // could be anything being pasted in here
1995 protected void cut_actionPerformed(ActionEvent e)
1997 copy_actionPerformed(null);
1998 delete_actionPerformed(null);
2008 protected void delete_actionPerformed(ActionEvent evt)
2011 SequenceGroup sg = viewport.getSelectionGroup();
2017 Vector seqs = new Vector();
2019 for (int i = 0; i < sg.getSize(); i++)
2021 seq = sg.getSequenceAt(i);
2022 seqs.addElement(seq);
2025 // If the cut affects all sequences, remove highlighted columns
2026 if (sg.getSize() == viewport.getAlignment().getHeight())
2028 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2029 sg.getEndRes() + 1);
2032 SequenceI[] cut = new SequenceI[seqs.size()];
2033 for (int i = 0; i < seqs.size(); i++)
2035 cut[i] = (SequenceI) seqs.elementAt(i);
2039 * //ADD HISTORY ITEM
2041 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2042 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2043 viewport.getAlignment()));
2045 viewport.setSelectionGroup(null);
2046 viewport.sendSelection();
2047 viewport.getAlignment().deleteGroup(sg);
2049 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2051 if (viewport.getAlignment().getHeight() < 1)
2055 this.setClosed(true);
2056 } catch (Exception ex)
2069 protected void deleteGroups_actionPerformed(ActionEvent e)
2071 viewport.getAlignment().deleteAllGroups();
2072 viewport.sequenceColours = null;
2073 viewport.setSelectionGroup(null);
2074 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2075 alignPanel.updateAnnotation();
2076 alignPanel.paintAlignment(true);
2086 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2088 SequenceGroup sg = new SequenceGroup();
2090 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2092 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2095 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2096 viewport.setSelectionGroup(sg);
2097 viewport.sendSelection();
2098 alignPanel.paintAlignment(true);
2099 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2109 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2111 if (viewport.cursorMode)
2113 alignPanel.seqPanel.keyboardNo1 = null;
2114 alignPanel.seqPanel.keyboardNo2 = null;
2116 viewport.setSelectionGroup(null);
2117 viewport.getColumnSelection().clear();
2118 viewport.setSelectionGroup(null);
2119 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2120 alignPanel.idPanel.idCanvas.searchResults = null;
2121 alignPanel.paintAlignment(true);
2122 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2123 viewport.sendSelection();
2133 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2135 SequenceGroup sg = viewport.getSelectionGroup();
2139 selectAllSequenceMenuItem_actionPerformed(null);
2144 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2146 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2149 alignPanel.paintAlignment(true);
2150 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2151 viewport.sendSelection();
2155 public void invertColSel_actionPerformed(ActionEvent e)
2157 viewport.invertColumnSelection();
2158 alignPanel.paintAlignment(true);
2159 viewport.sendSelection();
2169 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2171 trimAlignment(true);
2181 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2183 trimAlignment(false);
2186 void trimAlignment(boolean trimLeft)
2188 ColumnSelection colSel = viewport.getColumnSelection();
2191 if (colSel.size() > 0)
2195 column = colSel.getMin();
2199 column = colSel.getMax();
2203 if (viewport.getSelectionGroup() != null)
2205 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2206 viewport.getHiddenRepSequences());
2210 seqs = viewport.getAlignment().getSequencesArray();
2213 TrimRegionCommand trimRegion;
2216 trimRegion = new TrimRegionCommand("Remove Left",
2217 TrimRegionCommand.TRIM_LEFT, seqs, column,
2218 viewport.getAlignment(), viewport.getColumnSelection(),
2219 viewport.getSelectionGroup());
2220 viewport.setStartRes(0);
2224 trimRegion = new TrimRegionCommand("Remove Right",
2225 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2226 viewport.getAlignment(), viewport.getColumnSelection(),
2227 viewport.getSelectionGroup());
2230 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2232 addHistoryItem(trimRegion);
2234 for (SequenceGroup sg :viewport.getAlignment().getGroups())
2236 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2237 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2239 viewport.getAlignment().deleteGroup(sg);
2243 viewport.firePropertyChange("alignment", null, viewport
2244 .getAlignment().getSequences());
2255 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2257 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2260 if (viewport.getSelectionGroup() != null)
2262 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2263 viewport.getHiddenRepSequences());
2264 start = viewport.getSelectionGroup().getStartRes();
2265 end = viewport.getSelectionGroup().getEndRes();
2269 seqs = viewport.getAlignment().getSequencesArray();
2272 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2273 "Remove Gapped Columns", seqs, start, end,
2274 viewport.getAlignment());
2276 addHistoryItem(removeGapCols);
2278 statusBar.setText("Removed " + removeGapCols.getSize()
2279 + " empty columns.");
2281 // This is to maintain viewport position on first residue
2282 // of first sequence
2283 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2284 int startRes = seq.findPosition(viewport.startRes);
2285 // ShiftList shifts;
2286 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2287 // edit.alColumnChanges=shifts.getInverse();
2288 // if (viewport.hasHiddenColumns)
2289 // viewport.getColumnSelection().compensateForEdits(shifts);
2290 viewport.setStartRes(seq.findIndex(startRes) - 1);
2291 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2303 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2305 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2308 if (viewport.getSelectionGroup() != null)
2310 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2311 viewport.getHiddenRepSequences());
2312 start = viewport.getSelectionGroup().getStartRes();
2313 end = viewport.getSelectionGroup().getEndRes();
2317 seqs = viewport.getAlignment().getSequencesArray();
2320 // This is to maintain viewport position on first residue
2321 // of first sequence
2322 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2323 int startRes = seq.findPosition(viewport.startRes);
2325 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2326 viewport.getAlignment()));
2328 viewport.setStartRes(seq.findIndex(startRes) - 1);
2330 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2342 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2344 viewport.setPadGaps(padGapsMenuitem.isSelected());
2345 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2351 // if (justifySeqs>0)
2353 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2366 public void findMenuItem_actionPerformed(ActionEvent e)
2372 public void newView_actionPerformed(ActionEvent e)
2379 * @param copyAnnotation
2380 * if true then duplicate all annnotation, groups and settings
2381 * @return new alignment panel, already displayed.
2383 public AlignmentPanel newView(boolean copyAnnotation)
2385 return newView(null, copyAnnotation);
2391 * title of newly created view
2392 * @return new alignment panel, already displayed.
2394 public AlignmentPanel newView(String viewTitle)
2396 return newView(viewTitle, true);
2402 * title of newly created view
2403 * @param copyAnnotation
2404 * if true then duplicate all annnotation, groups and settings
2405 * @return new alignment panel, already displayed.
2407 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2409 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2411 if (!copyAnnotation)
2413 // just remove all the current annotation except for the automatic stuff
2414 newap.av.getAlignment().deleteAllGroups();
2415 for (AlignmentAnnotation alan : newap.av.getAlignment()
2416 .getAlignmentAnnotation())
2418 if (!alan.autoCalculated)
2420 newap.av.getAlignment().deleteAnnotation(alan);
2426 newap.av.gatherViewsHere = false;
2428 if (viewport.viewName == null)
2430 viewport.viewName = "Original";
2433 newap.av.historyList = viewport.historyList;
2434 newap.av.redoList = viewport.redoList;
2436 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2437 // make sure the new view has a unique name - this is essential for Jalview
2439 boolean addFirstIndex = false;
2440 if (viewTitle == null || viewTitle.trim().length() == 0)
2443 addFirstIndex = true;
2447 index = 1;// we count from 1 if given a specific name
2449 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2450 Vector comps = (Vector) PaintRefresher.components.get(viewport
2451 .getSequenceSetId());
2452 Vector existingNames = new Vector();
2453 for (int i = 0; i < comps.size(); i++)
2455 if (comps.elementAt(i) instanceof AlignmentPanel)
2457 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2458 if (!existingNames.contains(ap.av.viewName))
2460 existingNames.addElement(ap.av.viewName);
2465 while (existingNames.contains(newViewName))
2467 newViewName = viewTitle + " " + (++index);
2470 newap.av.viewName = newViewName;
2472 addAlignmentPanel(newap, true);
2474 if (alignPanels.size() == 2)
2476 viewport.gatherViewsHere = true;
2478 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2483 public void expandViews_actionPerformed(ActionEvent e)
2485 Desktop.instance.explodeViews(this);
2489 public void gatherViews_actionPerformed(ActionEvent e)
2491 Desktop.instance.gatherViews(this);
2501 public void font_actionPerformed(ActionEvent e)
2503 new FontChooser(alignPanel);
2513 protected void seqLimit_actionPerformed(ActionEvent e)
2515 viewport.setShowJVSuffix(seqLimits.isSelected());
2517 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2518 .calculateIdWidth());
2519 alignPanel.paintAlignment(true);
2523 public void idRightAlign_actionPerformed(ActionEvent e)
2525 viewport.rightAlignIds = idRightAlign.isSelected();
2526 alignPanel.paintAlignment(true);
2530 public void centreColumnLabels_actionPerformed(ActionEvent e)
2532 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2533 alignPanel.paintAlignment(true);
2539 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2542 protected void followHighlight_actionPerformed()
2544 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2546 alignPanel.scrollToPosition(
2547 alignPanel.seqPanel.seqCanvas.searchResults, false);
2558 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2560 viewport.setColourText(colourTextMenuItem.isSelected());
2561 alignPanel.paintAlignment(true);
2571 public void wrapMenuItem_actionPerformed(ActionEvent e)
2573 scaleAbove.setVisible(wrapMenuItem.isSelected());
2574 scaleLeft.setVisible(wrapMenuItem.isSelected());
2575 scaleRight.setVisible(wrapMenuItem.isSelected());
2576 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2577 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2581 public void showAllSeqs_actionPerformed(ActionEvent e)
2583 viewport.showAllHiddenSeqs();
2587 public void showAllColumns_actionPerformed(ActionEvent e)
2589 viewport.showAllHiddenColumns();
2594 public void hideSelSequences_actionPerformed(ActionEvent e)
2596 viewport.hideAllSelectedSeqs();
2597 alignPanel.paintAlignment(true);
2601 * called by key handler and the hide all/show all menu items
2606 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2609 boolean hide = false;
2610 SequenceGroup sg = viewport.getSelectionGroup();
2611 if (!toggleSeqs && !toggleCols)
2613 // Hide everything by the current selection - this is a hack - we do the
2614 // invert and then hide
2615 // first check that there will be visible columns after the invert.
2616 if ((viewport.getColumnSelection() != null
2617 && viewport.getColumnSelection().getSelected() != null && viewport
2618 .getColumnSelection().getSelected().size() > 0)
2619 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2622 // now invert the sequence set, if required - empty selection implies
2623 // that no hiding is required.
2626 invertSequenceMenuItem_actionPerformed(null);
2627 sg = viewport.getSelectionGroup();
2631 viewport.expandColSelection(sg, true);
2632 // finally invert the column selection and get the new sequence
2634 invertColSel_actionPerformed(null);
2641 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2643 hideSelSequences_actionPerformed(null);
2646 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2649 showAllSeqs_actionPerformed(null);
2655 if (viewport.getColumnSelection().getSelected().size() > 0)
2657 hideSelColumns_actionPerformed(null);
2660 viewport.setSelectionGroup(sg);
2665 showAllColumns_actionPerformed(null);
2674 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2675 * event.ActionEvent)
2678 public void hideAllButSelection_actionPerformed(ActionEvent e)
2680 toggleHiddenRegions(false, false);
2687 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2691 public void hideAllSelection_actionPerformed(ActionEvent e)
2693 SequenceGroup sg = viewport.getSelectionGroup();
2694 viewport.expandColSelection(sg, false);
2695 viewport.hideAllSelectedSeqs();
2696 viewport.hideSelectedColumns();
2697 alignPanel.paintAlignment(true);
2704 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2708 public void showAllhidden_actionPerformed(ActionEvent e)
2710 viewport.showAllHiddenColumns();
2711 viewport.showAllHiddenSeqs();
2712 alignPanel.paintAlignment(true);
2716 public void hideSelColumns_actionPerformed(ActionEvent e)
2718 viewport.hideSelectedColumns();
2719 alignPanel.paintAlignment(true);
2723 public void hiddenMarkers_actionPerformed(ActionEvent e)
2725 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2736 protected void scaleAbove_actionPerformed(ActionEvent e)
2738 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2739 alignPanel.paintAlignment(true);
2749 protected void scaleLeft_actionPerformed(ActionEvent e)
2751 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2752 alignPanel.paintAlignment(true);
2762 protected void scaleRight_actionPerformed(ActionEvent e)
2764 viewport.setScaleRightWrapped(scaleRight.isSelected());
2765 alignPanel.paintAlignment(true);
2775 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2777 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2778 alignPanel.paintAlignment(true);
2788 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2790 viewport.setShowText(viewTextMenuItem.isSelected());
2791 alignPanel.paintAlignment(true);
2801 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2803 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2804 alignPanel.paintAlignment(true);
2807 public FeatureSettings featureSettings;
2810 public void featureSettings_actionPerformed(ActionEvent e)
2812 if (featureSettings != null)
2814 featureSettings.close();
2815 featureSettings = null;
2817 if (!showSeqFeatures.isSelected())
2819 // make sure features are actually displayed
2820 showSeqFeatures.setSelected(true);
2821 showSeqFeatures_actionPerformed(null);
2823 featureSettings = new FeatureSettings(this);
2827 * Set or clear 'Show Sequence Features'
2833 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2835 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2836 alignPanel.paintAlignment(true);
2837 if (alignPanel.getOverviewPanel() != null)
2839 alignPanel.getOverviewPanel().updateOverviewImage();
2844 * Set or clear 'Show Sequence Features'
2850 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2852 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2854 if (viewport.getShowSequenceFeaturesHeight())
2856 // ensure we're actually displaying features
2857 viewport.setShowSequenceFeatures(true);
2858 showSeqFeatures.setSelected(true);
2860 alignPanel.paintAlignment(true);
2861 if (alignPanel.getOverviewPanel() != null)
2863 alignPanel.getOverviewPanel().updateOverviewImage();
2874 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2876 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2877 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2881 public void alignmentProperties()
2883 JEditorPane editPane = new JEditorPane("text/html", "");
2884 editPane.setEditable(false);
2885 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2887 editPane.setText("<html>" + contents.toString() + "</html>");
2888 JInternalFrame frame = new JInternalFrame();
2889 frame.getContentPane().add(new JScrollPane(editPane));
2891 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2892 + getTitle(), 500, 400);
2902 public void overviewMenuItem_actionPerformed(ActionEvent e)
2904 if (alignPanel.overviewPanel != null)
2909 JInternalFrame frame = new JInternalFrame();
2910 OverviewPanel overview = new OverviewPanel(alignPanel);
2911 frame.setContentPane(overview);
2912 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2913 frame.getWidth(), frame.getHeight());
2915 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2916 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2919 public void internalFrameClosed(
2920 javax.swing.event.InternalFrameEvent evt)
2922 alignPanel.setOverviewPanel(null);
2926 alignPanel.setOverviewPanel(overview);
2930 public void textColour_actionPerformed(ActionEvent e)
2932 new TextColourChooser().chooseColour(alignPanel, null);
2942 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2954 public void clustalColour_actionPerformed(ActionEvent e)
2956 changeColour(new ClustalxColourScheme(viewport.getAlignment(), viewport.getHiddenRepSequences()));
2966 public void zappoColour_actionPerformed(ActionEvent e)
2968 changeColour(new ZappoColourScheme());
2978 public void taylorColour_actionPerformed(ActionEvent e)
2980 changeColour(new TaylorColourScheme());
2990 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2992 changeColour(new HydrophobicColourScheme());
3002 public void helixColour_actionPerformed(ActionEvent e)
3004 changeColour(new HelixColourScheme());
3014 public void strandColour_actionPerformed(ActionEvent e)
3016 changeColour(new StrandColourScheme());
3026 public void turnColour_actionPerformed(ActionEvent e)
3028 changeColour(new TurnColourScheme());
3038 public void buriedColour_actionPerformed(ActionEvent e)
3040 changeColour(new BuriedColourScheme());
3050 public void nucleotideColour_actionPerformed(ActionEvent e)
3052 changeColour(new NucleotideColourScheme());
3056 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3058 changeColour(new PurinePyrimidineColourScheme());
3062 * public void covariationColour_actionPerformed(ActionEvent e) {
3064 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3068 public void annotationColour_actionPerformed(ActionEvent e)
3070 new AnnotationColourChooser(viewport, alignPanel);
3074 public void rnahelicesColour_actionPerformed(ActionEvent e)
3076 new RNAHelicesColourChooser(viewport, alignPanel);
3086 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3088 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3097 public void changeColour(ColourSchemeI cs)
3099 // TODO: compare with applet and pull up to model method
3104 if (viewport.getAbovePIDThreshold())
3106 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3109 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3111 viewport.setGlobalColourScheme(cs);
3115 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3118 if (viewport.getConservationSelected())
3121 Alignment al = (Alignment) viewport.getAlignment();
3122 Conservation c = new Conservation("All",
3123 ResidueProperties.propHash, 3, al.getSequences(), 0,
3127 c.verdict(false, viewport.getConsPercGaps());
3129 cs.setConservation(c);
3131 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3136 cs.setConservation(null);
3139 cs.setConsensus(viewport.getSequenceConsensusHash());
3142 viewport.setGlobalColourScheme(cs);
3144 if (viewport.getColourAppliesToAllGroups())
3148 for (SequenceGroup sg:viewport.getAlignment().getGroups())
3156 if (cs instanceof ClustalxColourScheme)
3158 sg.cs = new ClustalxColourScheme(sg, viewport
3159 .getHiddenRepSequences());
3161 else if (cs instanceof UserColourScheme)
3163 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3169 sg.cs = cs.getClass().newInstance();
3170 } catch (Exception ex)
3175 if (viewport.getAbovePIDThreshold()
3176 || cs instanceof PIDColourScheme
3177 || cs instanceof Blosum62ColourScheme)
3179 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3181 sg.cs.setConsensus(AAFrequency.calculate(
3182 sg.getSequences(viewport.getHiddenRepSequences()),
3183 sg.getStartRes(), sg.getEndRes() + 1));
3187 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3190 if (viewport.getConservationSelected())
3192 Conservation c = new Conservation("Group",
3193 ResidueProperties.propHash, 3, sg.getSequences(viewport
3194 .getHiddenRepSequences()), sg.getStartRes(),
3195 sg.getEndRes() + 1);
3197 c.verdict(false, viewport.getConsPercGaps());
3198 sg.cs.setConservation(c);
3202 sg.cs.setConservation(null);
3207 if (alignPanel.getOverviewPanel() != null)
3209 alignPanel.getOverviewPanel().updateOverviewImage();
3212 alignPanel.paintAlignment(true);
3222 protected void modifyPID_actionPerformed(ActionEvent e)
3224 if (viewport.getAbovePIDThreshold()
3225 && viewport.getGlobalColourScheme() != null)
3227 SliderPanel.setPIDSliderSource(alignPanel,
3228 viewport.getGlobalColourScheme(), "Background");
3229 SliderPanel.showPIDSlider();
3240 protected void modifyConservation_actionPerformed(ActionEvent e)
3242 if (viewport.getConservationSelected()
3243 && viewport.getGlobalColourScheme() != null)
3245 SliderPanel.setConservationSlider(alignPanel,
3246 viewport.getGlobalColourScheme(), "Background");
3247 SliderPanel.showConservationSlider();
3258 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3260 viewport.setConservationSelected(conservationMenuItem.isSelected());
3262 viewport.setAbovePIDThreshold(false);
3263 abovePIDThreshold.setSelected(false);
3265 changeColour(viewport.getGlobalColourScheme());
3267 modifyConservation_actionPerformed(null);
3277 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3279 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3281 conservationMenuItem.setSelected(false);
3282 viewport.setConservationSelected(false);
3284 changeColour(viewport.getGlobalColourScheme());
3286 modifyPID_actionPerformed(null);
3296 public void userDefinedColour_actionPerformed(ActionEvent e)
3298 if (e.getActionCommand().equals("User Defined..."))
3300 new UserDefinedColours(alignPanel, null);
3304 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3305 .getUserColourSchemes().get(e.getActionCommand());
3311 public void updateUserColourMenu()
3314 Component[] menuItems = colourMenu.getMenuComponents();
3315 int i, iSize = menuItems.length;
3316 for (i = 0; i < iSize; i++)
3318 if (menuItems[i].getName() != null
3319 && menuItems[i].getName().equals("USER_DEFINED"))
3321 colourMenu.remove(menuItems[i]);
3325 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3327 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3328 .getUserColourSchemes().keys();
3330 while (userColours.hasMoreElements())
3332 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3333 userColours.nextElement().toString());
3334 radioItem.setName("USER_DEFINED");
3335 radioItem.addMouseListener(new MouseAdapter()
3338 public void mousePressed(MouseEvent evt)
3340 if (evt.isControlDown()
3341 || SwingUtilities.isRightMouseButton(evt))
3343 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3345 int option = JOptionPane.showInternalConfirmDialog(
3346 jalview.gui.Desktop.desktop,
3347 "Remove from default list?",
3348 "Remove user defined colour",
3349 JOptionPane.YES_NO_OPTION);
3350 if (option == JOptionPane.YES_OPTION)
3352 jalview.gui.UserDefinedColours
3353 .removeColourFromDefaults(radioItem.getText());
3354 colourMenu.remove(radioItem);
3358 radioItem.addActionListener(new ActionListener()
3361 public void actionPerformed(ActionEvent evt)
3363 userDefinedColour_actionPerformed(evt);
3370 radioItem.addActionListener(new ActionListener()
3373 public void actionPerformed(ActionEvent evt)
3375 userDefinedColour_actionPerformed(evt);
3379 colourMenu.insert(radioItem, 15);
3380 colours.add(radioItem);
3392 public void PIDColour_actionPerformed(ActionEvent e)
3394 changeColour(new PIDColourScheme());
3404 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3406 changeColour(new Blosum62ColourScheme());
3416 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3418 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3419 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3420 .getAlignment().getSequenceAt(0), null);
3421 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3422 viewport.getAlignment()));
3423 alignPanel.paintAlignment(true);
3433 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3435 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3436 AlignmentSorter.sortByID(viewport.getAlignment());
3437 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3438 viewport.getAlignment()));
3439 alignPanel.paintAlignment(true);
3449 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3451 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3452 AlignmentSorter.sortByLength(viewport.getAlignment());
3453 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3454 viewport.getAlignment()));
3455 alignPanel.paintAlignment(true);
3465 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3467 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3468 AlignmentSorter.sortByGroup(viewport.getAlignment());
3469 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3470 viewport.getAlignment()));
3472 alignPanel.paintAlignment(true);
3482 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3484 new RedundancyPanel(alignPanel, this);
3494 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3496 if ((viewport.getSelectionGroup() == null)
3497 || (viewport.getSelectionGroup().getSize() < 2))
3499 JOptionPane.showInternalMessageDialog(this,
3500 "You must select at least 2 sequences.", "Invalid Selection",
3501 JOptionPane.WARNING_MESSAGE);
3505 JInternalFrame frame = new JInternalFrame();
3506 frame.setContentPane(new PairwiseAlignPanel(viewport));
3507 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3518 public void PCAMenuItem_actionPerformed(ActionEvent e)
3520 if (((viewport.getSelectionGroup() != null)
3521 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3522 .getSelectionGroup().getSize() > 0))
3523 || (viewport.getAlignment().getHeight() < 4))
3525 JOptionPane.showInternalMessageDialog(this,
3526 "Principal component analysis must take\n"
3527 + "at least 4 input sequences.",
3528 "Sequence selection insufficient",
3529 JOptionPane.WARNING_MESSAGE);
3534 new PCAPanel(alignPanel);
3538 public void autoCalculate_actionPerformed(ActionEvent e)
3540 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3541 if (viewport.autoCalculateConsensus)
3543 viewport.firePropertyChange("alignment", null, viewport
3544 .getAlignment().getSequences());
3549 public void sortByTreeOption_actionPerformed(ActionEvent e)
3551 viewport.sortByTree = sortByTree.isSelected();
3555 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3557 viewport.followSelection = listenToViewSelections.isSelected();
3567 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3569 NewTreePanel("AV", "PID", "Average distance tree using PID");
3579 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3581 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3591 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3593 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3603 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3605 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3618 void NewTreePanel(String type, String pwType, String title)
3622 if (viewport.getSelectionGroup() != null)
3624 if (viewport.getSelectionGroup().getSize() < 3)
3629 "You need to have more than two sequences selected to build a tree!",
3630 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3634 SequenceGroup sg = viewport.getSelectionGroup();
3636 /* Decide if the selection is a column region */
3637 for (SequenceI _s:sg.getSequences())
3639 if (_s.getLength() < sg
3645 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3646 + "Try using the Pad function in the edit menu,\n"
3647 + "or one of the multiple sequence alignment web services.",
3648 "Sequences in selection are not aligned",
3649 JOptionPane.WARNING_MESSAGE);
3655 title = title + " on region";
3656 tp = new TreePanel(alignPanel, type, pwType);
3660 // are the visible sequences aligned?
3661 if (!viewport.getAlignment().isAligned(false))
3666 "The sequences must be aligned before creating a tree.\n"
3667 + "Try using the Pad function in the edit menu,\n"
3668 + "or one of the multiple sequence alignment web services.",
3669 "Sequences not aligned",
3670 JOptionPane.WARNING_MESSAGE);
3675 if (viewport.getAlignment().getHeight() < 2)
3680 tp = new TreePanel(alignPanel, type, pwType);
3685 if (viewport.viewName != null)
3687 title += viewport.viewName + " of ";
3690 title += this.title;
3692 Desktop.addInternalFrame(tp, title, 600, 500);
3703 public void addSortByOrderMenuItem(String title,
3704 final AlignmentOrder order)
3706 final JMenuItem item = new JMenuItem("by " + title);
3708 item.addActionListener(new java.awt.event.ActionListener()
3711 public void actionPerformed(ActionEvent e)
3713 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3715 // TODO: JBPNote - have to map order entries to curent SequenceI
3717 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3719 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3722 alignPanel.paintAlignment(true);
3728 * Add a new sort by annotation score menu item
3731 * the menu to add the option to
3733 * the label used to retrieve scores for each sequence on the
3736 public void addSortByAnnotScoreMenuItem(JMenu sort,
3737 final String scoreLabel)
3739 final JMenuItem item = new JMenuItem(scoreLabel);
3741 item.addActionListener(new java.awt.event.ActionListener()
3744 public void actionPerformed(ActionEvent e)
3746 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3747 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3748 viewport.getAlignment());// ,viewport.getSelectionGroup());
3749 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3750 viewport.getAlignment()));
3751 alignPanel.paintAlignment(true);
3757 * last hash for alignment's annotation array - used to minimise cost of
3760 protected int _annotationScoreVectorHash;
3763 * search the alignment and rebuild the sort by annotation score submenu the
3764 * last alignment annotation vector hash is stored to minimize cost of
3765 * rebuilding in subsequence calls.
3769 public void buildSortByAnnotationScoresMenu()
3771 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3776 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3778 sortByAnnotScore.removeAll();
3779 // almost certainly a quicker way to do this - but we keep it simple
3780 Hashtable scoreSorts = new Hashtable();
3781 AlignmentAnnotation aann[];
3782 for (SequenceI sqa:viewport.getAlignment().getSequences())
3784 aann = sqa.getAnnotation();
3785 for (int i = 0; aann != null && i < aann.length; i++)
3787 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3789 scoreSorts.put(aann[i].label, aann[i].label);
3793 Enumeration labels = scoreSorts.keys();
3794 while (labels.hasMoreElements())
3796 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3797 (String) labels.nextElement());
3799 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3802 _annotationScoreVectorHash = viewport.getAlignment()
3803 .getAlignmentAnnotation().hashCode();
3808 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3809 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3810 * call. Listeners are added to remove the menu item when the treePanel is
3811 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3815 * Displayed tree window.
3817 * SortBy menu item title.
3820 public void buildTreeMenu()
3822 sortByTreeMenu.removeAll();
3824 Vector comps = (Vector) PaintRefresher.components.get(viewport
3825 .getSequenceSetId());
3826 Vector treePanels = new Vector();
3827 int i, iSize = comps.size();
3828 for (i = 0; i < iSize; i++)
3830 if (comps.elementAt(i) instanceof TreePanel)
3832 treePanels.add(comps.elementAt(i));
3836 iSize = treePanels.size();
3840 sortByTreeMenu.setVisible(false);
3844 sortByTreeMenu.setVisible(true);
3846 for (i = 0; i < treePanels.size(); i++)
3848 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3849 final JMenuItem item = new JMenuItem(tp.getTitle());
3850 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3851 item.addActionListener(new java.awt.event.ActionListener()
3854 public void actionPerformed(ActionEvent e)
3856 tp.sortByTree_actionPerformed(null);
3857 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3862 sortByTreeMenu.add(item);
3866 public boolean sortBy(AlignmentOrder alorder, String undoname)
3868 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3869 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3870 if (undoname != null)
3872 addHistoryItem(new OrderCommand(undoname, oldOrder,
3873 viewport.getAlignment()));
3875 alignPanel.paintAlignment(true);
3880 * Work out whether the whole set of sequences or just the selected set will
3881 * be submitted for multiple alignment.
3884 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3886 // Now, check we have enough sequences
3887 AlignmentView msa = null;
3889 if ((viewport.getSelectionGroup() != null)
3890 && (viewport.getSelectionGroup().getSize() > 1))
3892 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3893 // some common interface!
3895 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3896 * SequenceI[sz = seqs.getSize(false)];
3898 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3899 * seqs.getSequenceAt(i); }
3901 msa = viewport.getAlignmentView(true);
3906 * Vector seqs = viewport.getAlignment().getSequences();
3908 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3910 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3911 * seqs.elementAt(i); } }
3913 msa = viewport.getAlignmentView(false);
3919 * Decides what is submitted to a secondary structure prediction service: the
3920 * first sequence in the alignment, or in the current selection, or, if the
3921 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3922 * region or the whole alignment. (where the first sequence in the set is the
3923 * one that the prediction will be for).
3925 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3927 AlignmentView seqs = null;
3929 if ((viewport.getSelectionGroup() != null)
3930 && (viewport.getSelectionGroup().getSize() > 0))
3932 seqs = viewport.getAlignmentView(true);
3936 seqs = viewport.getAlignmentView(false);
3938 // limit sequences - JBPNote in future - could spawn multiple prediction
3940 // TODO: viewport.getAlignment().isAligned is a global state - the local
3941 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3942 if (!viewport.getAlignment().isAligned(false))
3944 seqs.setSequences(new SeqCigar[]
3945 { seqs.getSequences()[0] });
3946 // TODO: if seqs.getSequences().length>1 then should really have warned
3960 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3962 // Pick the tree file
3963 JalviewFileChooser chooser = new JalviewFileChooser(
3964 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3965 chooser.setFileView(new JalviewFileView());
3966 chooser.setDialogTitle("Select a newick-like tree file");
3967 chooser.setToolTipText("Load a tree file");
3969 int value = chooser.showOpenDialog(null);
3971 if (value == JalviewFileChooser.APPROVE_OPTION)
3973 String choice = chooser.getSelectedFile().getPath();
3974 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3975 jalview.io.NewickFile fin = null;
3978 fin = new jalview.io.NewickFile(choice, "File");
3979 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3980 } catch (Exception ex)
3982 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3983 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3984 ex.printStackTrace();
3986 if (fin != null && fin.hasWarningMessage())
3988 JOptionPane.showMessageDialog(Desktop.desktop,
3989 fin.getWarningMessage(), "Possible problem with tree file",
3990 JOptionPane.WARNING_MESSAGE);
3996 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
3998 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4001 public TreePanel ShowNewickTree(NewickFile nf, String title)
4003 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4006 public TreePanel ShowNewickTree(NewickFile nf, String title,
4007 AlignmentView input)
4009 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4012 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4013 int h, int x, int y)
4015 return ShowNewickTree(nf, title, null, w, h, x, y);
4019 * Add a treeviewer for the tree extracted from a newick file object to the
4020 * current alignment view
4027 * Associated alignment input data (or null)
4036 * @return TreePanel handle
4038 public TreePanel ShowNewickTree(NewickFile nf, String title,
4039 AlignmentView input, int w, int h, int x, int y)
4041 TreePanel tp = null;
4047 if (nf.getTree() != null)
4049 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4055 tp.setLocation(x, y);
4058 Desktop.addInternalFrame(tp, title, w, h);
4060 } catch (Exception ex)
4062 ex.printStackTrace();
4068 private boolean buildingMenu = false;
4071 * Generates menu items and listener event actions for web service clients
4074 public void BuildWebServiceMenu()
4076 while (buildingMenu)
4080 System.err.println("Waiting for building menu to finish.");
4082 } catch (Exception e)
4087 final AlignFrame me = this;
4088 buildingMenu = true;
4089 new Thread(new Runnable()
4096 System.err.println("Building ws menu again "
4097 + Thread.currentThread());
4098 // TODO: add support for context dependent disabling of services based
4100 // alignment and current selection
4101 // TODO: add additional serviceHandle parameter to specify abstract
4103 // class independently of AbstractName
4104 // TODO: add in rediscovery GUI function to restart discoverer
4105 // TODO: group services by location as well as function and/or
4107 // object broker mechanism.
4108 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4109 final IProgressIndicator af = me;
4110 final JMenu msawsmenu = new JMenu("Alignment");
4111 final JMenu secstrmenu = new JMenu(
4112 "Secondary Structure Prediction");
4113 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4114 final JMenu analymenu = new JMenu("Analysis");
4115 final JMenu dismenu = new JMenu("Disorder");
4116 // JAL-940 - only show secondary structure prediction services from
4117 // the legacy server
4118 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4120 Discoverer.services != null && (Discoverer.services.size() > 0))
4122 // TODO: refactor to allow list of AbstractName/Handler bindings to
4124 // stored or retrieved from elsewhere
4125 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4126 Vector secstrpr = (Vector) Discoverer.services
4128 Vector seqsrch = null; // (Vector)
4129 // Discoverer.services.get("SeqSearch");
4130 // TODO: move GUI generation code onto service implementation - so a
4131 // client instance attaches itself to the GUI with method call like
4132 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4136 // Add any Multiple Sequence Alignment Services
4137 for (int i = 0, j = msaws.size(); i < j; i++)
4139 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4141 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4142 .getServiceClient(sh);
4143 impl.attachWSMenuEntry(msawsmenu, me);
4147 if (secstrpr != null)
4149 // Add any secondary structure prediction services
4150 for (int i = 0, j = secstrpr.size(); i < j; i++)
4152 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4154 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4155 .getServiceClient(sh);
4156 impl.attachWSMenuEntry(secstrmenu, me);
4159 if (seqsrch != null)
4161 // Add any sequence search services
4162 for (int i = 0, j = seqsrch.size(); i < j; i++)
4164 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4166 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4167 .getServiceClient(sh);
4168 impl.attachWSMenuEntry(seqsrchmenu, me);
4173 // Add all submenus in the order they should appear on the web
4175 wsmenu.add(msawsmenu);
4176 wsmenu.add(secstrmenu);
4177 wsmenu.add(dismenu);
4178 wsmenu.add(analymenu);
4179 // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
4180 // submens.add(msawsmenu);
4181 // submens.add(secstrmenu);
4182 // submens.add(dismenu);
4183 // submens.add(analymenu);
4185 // No search services yet
4186 // wsmenu.add(seqsrchmenu);
4188 javax.swing.SwingUtilities.invokeLater(new Runnable()
4195 webService.removeAll();
4196 // first, add discovered services onto the webservices menu
4197 if (wsmenu.size() > 0)
4199 for (int i = 0, j = wsmenu.size(); i < j; i++)
4201 webService.add(wsmenu.get(i));
4206 webService.add(me.webServiceNoServices);
4208 // TODO: move into separate menu builder class.
4209 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4211 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4212 if (jws2servs != null)
4214 if (jws2servs.hasServices())
4216 jws2servs.attachWSMenuEntry(webService, me);
4218 if (jws2servs.isRunning())
4220 JMenuItem tm = new JMenuItem(
4221 "Still discovering JABA Services");
4222 tm.setEnabled(false);
4228 build_urlServiceMenu(me.webService);
4229 build_fetchdbmenu(webService);
4230 for (JMenu item : wsmenu)
4232 if (item.getItemCount() == 0)
4234 item.setEnabled(false);
4238 item.setEnabled(true);
4241 } catch (Exception e)
4247 } catch (Exception e)
4252 buildingMenu = false;
4259 * construct any groupURL type service menu entries.
4263 private void build_urlServiceMenu(JMenu webService)
4265 // TODO: remove this code when 2.7 is released
4266 // DEBUG - alignmentView
4268 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4269 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4271 * @Override public void actionPerformed(ActionEvent e) {
4272 * jalview.datamodel.AlignmentView
4273 * .testSelectionViews(af.viewport.getAlignment(),
4274 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4276 * }); webService.add(testAlView);
4278 // TODO: refactor to RestClient discoverer and merge menu entries for
4279 // rest-style services with other types of analysis/calculation service
4280 // SHmmr test client - still being implemented.
4281 // DEBUG - alignmentView
4283 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4286 client.attachWSMenuEntry(
4287 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4291 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4293 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4299 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4300 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4301 * getProperty("LAST_DIRECTORY"));
4303 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4304 * to Vamsas file"); chooser.setToolTipText("Export");
4306 * int value = chooser.showSaveDialog(this);
4308 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4309 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4310 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4311 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4314 * prototype of an automatically enabled/disabled analysis function
4317 protected void setShowProductsEnabled()
4319 SequenceI[] selection = viewport.getSequenceSelection();
4320 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4321 viewport.getAlignment().getDataset()))
4323 showProducts.setEnabled(true);
4328 showProducts.setEnabled(false);
4333 * search selection for sequence xRef products and build the show products
4338 * @return true if showProducts menu should be enabled.
4340 public boolean canShowProducts(SequenceI[] selection,
4341 boolean isRegionSelection, Alignment dataset)
4343 boolean showp = false;
4346 showProducts.removeAll();
4347 final boolean dna = viewport.getAlignment().isNucleotide();
4348 final Alignment ds = dataset;
4349 String[] ptypes = (selection == null || selection.length == 0) ? null
4350 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4352 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4353 // selection, dataset, true);
4354 final SequenceI[] sel = selection;
4355 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4358 final boolean isRegSel = isRegionSelection;
4359 final AlignFrame af = this;
4360 final String source = ptypes[t];
4361 JMenuItem xtype = new JMenuItem(ptypes[t]);
4362 xtype.addActionListener(new ActionListener()
4366 public void actionPerformed(ActionEvent e)
4368 // TODO: new thread for this call with vis-delay
4369 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4370 isRegSel, dna, source);
4374 showProducts.add(xtype);
4376 showProducts.setVisible(showp);
4377 showProducts.setEnabled(showp);
4378 } catch (Exception e)
4380 jalview.bin.Cache.log
4381 .warn("canTranslate threw an exception - please report to help@jalview.org",
4388 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4389 boolean isRegSel, boolean dna, String source)
4391 final boolean fisRegSel = isRegSel;
4392 final boolean fdna = dna;
4393 final String fsrc = source;
4394 final AlignFrame ths = this;
4395 final SequenceI[] fsel = sel;
4396 Runnable foo = new Runnable()
4402 final long sttime = System.currentTimeMillis();
4403 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4406 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4410 Alignment prods = CrossRef
4411 .findXrefSequences(fsel, fdna, fsrc, ds);
4414 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4415 for (int s = 0; s < sprods.length; s++)
4417 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4418 if (ds.getSequences() == null
4419 || !ds.getSequences().contains(
4420 sprods[s].getDatasetSequence()))
4421 ds.addSequence(sprods[s].getDatasetSequence());
4422 sprods[s].updatePDBIds();
4424 Alignment al = new Alignment(sprods);
4425 AlignedCodonFrame[] cf = prods.getCodonFrames();
4427 for (int s = 0; cf != null && s < cf.length; s++)
4429 al.addCodonFrame(cf[s]);
4432 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4434 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4435 + " for " + ((fisRegSel) ? "selected region of " : "")
4437 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4442 System.err.println("No Sequences generated for xRef type "
4445 } catch (Exception e)
4447 jalview.bin.Cache.log.error(
4448 "Exception when finding crossreferences", e);
4449 } catch (OutOfMemoryError e)
4451 new OOMWarning("whilst fetching crossreferences", e);
4454 jalview.bin.Cache.log.error("Error when finding crossreferences",
4457 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4462 Thread frunner = new Thread(foo);
4466 public boolean canShowTranslationProducts(SequenceI[] selection,
4467 AlignmentI alignment)
4472 return (jalview.analysis.Dna.canTranslate(selection,
4473 viewport.getViewAsVisibleContigs(true)));
4474 } catch (Exception e)
4476 jalview.bin.Cache.log
4477 .warn("canTranslate threw an exception - please report to help@jalview.org",
4484 public void showProducts_actionPerformed(ActionEvent e)
4486 // /////////////////////////////
4487 // Collect Data to be translated/transferred
4489 SequenceI[] selection = viewport.getSequenceSelection();
4490 AlignmentI al = null;
4493 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4494 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4495 viewport.getAlignment().getDataset());
4496 } catch (Exception ex)
4499 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4506 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4507 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4511 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4512 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4513 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4518 public void showTranslation_actionPerformed(ActionEvent e)
4520 // /////////////////////////////
4521 // Collect Data to be translated/transferred
4523 SequenceI[] selection = viewport.getSequenceSelection();
4524 String[] seqstring = viewport.getViewAsString(true);
4525 AlignmentI al = null;
4528 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4529 viewport.getViewAsVisibleContigs(true), viewport
4530 .getGapCharacter(), viewport.getAlignment()
4531 .getAlignmentAnnotation(), viewport.getAlignment()
4532 .getWidth(), viewport.getAlignment().getDataset());
4533 } catch (Exception ex)
4536 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4543 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4544 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4548 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4549 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4550 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4555 * Try to load a features file onto the alignment.
4558 * contents or path to retrieve file
4560 * access mode of file (see jalview.io.AlignFile)
4561 * @return true if features file was parsed corectly.
4563 public boolean parseFeaturesFile(String file, String type)
4565 boolean featuresFile = false;
4568 featuresFile = new FeaturesFile(file, type).parse(viewport
4569 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4570 .getFeatureRenderer().featureColours, false,
4571 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4572 } catch (Exception ex)
4574 ex.printStackTrace();
4579 viewport.showSequenceFeatures = true;
4580 showSeqFeatures.setSelected(true);
4581 if (alignPanel.seqPanel.seqCanvas.fr != null)
4583 // update the min/max ranges where necessary
4584 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4586 if (featureSettings != null)
4588 featureSettings.setTableData();
4590 alignPanel.paintAlignment(true);
4593 return featuresFile;
4597 public void dragEnter(DropTargetDragEvent evt)
4602 public void dragExit(DropTargetEvent evt)
4607 public void dragOver(DropTargetDragEvent evt)
4612 public void dropActionChanged(DropTargetDragEvent evt)
4617 public void drop(DropTargetDropEvent evt)
4619 Transferable t = evt.getTransferable();
4620 java.util.List files = null;
4624 DataFlavor uriListFlavor = new DataFlavor(
4625 "text/uri-list;class=java.lang.String");
4626 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4628 // Works on Windows and MacOSX
4629 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4630 files = (java.util.List) t
4631 .getTransferData(DataFlavor.javaFileListFlavor);
4633 else if (t.isDataFlavorSupported(uriListFlavor))
4635 // This is used by Unix drag system
4636 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4637 String data = (String) t.getTransferData(uriListFlavor);
4638 files = new java.util.ArrayList(1);
4639 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4640 data, "\r\n"); st.hasMoreTokens();)
4642 String s = st.nextToken();
4643 if (s.startsWith("#"))
4645 // the line is a comment (as per the RFC 2483)
4649 java.net.URI uri = new java.net.URI(s);
4650 // check to see if we can handle this kind of URI
4651 if (uri.getScheme().toLowerCase().startsWith("http"))
4653 files.add(uri.toString());
4657 // otherwise preserve old behaviour: catch all for file objects
4658 java.io.File file = new java.io.File(uri);
4659 files.add(file.toString());
4663 } catch (Exception e)
4665 e.printStackTrace();
4671 // check to see if any of these files have names matching sequences in
4673 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4674 .getAlignment().getSequencesArray());
4676 * Object[] { String,SequenceI}
4678 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4679 ArrayList<String> filesnotmatched = new ArrayList<String>();
4680 for (int i = 0; i < files.size(); i++)
4682 String file = files.get(i).toString();
4684 String protocol = FormatAdapter.checkProtocol(file);
4685 if (protocol == jalview.io.FormatAdapter.FILE)
4687 File fl = new File(file);
4688 pdbfn = fl.getName();
4690 else if (protocol == jalview.io.FormatAdapter.URL)
4692 URL url = new URL(file);
4693 pdbfn = url.getFile();
4695 if (pdbfn.length() > 0)
4697 // attempt to find a match in the alignment
4698 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4699 int l = 0, c = pdbfn.indexOf(".");
4700 while (mtch == null && c != -1)
4705 } while ((c = pdbfn.indexOf(".", l)) > l);
4708 pdbfn = pdbfn.substring(0, l);
4710 mtch = idm.findAllIdMatches(pdbfn);
4717 type = new IdentifyFile().Identify(file, protocol);
4718 } catch (Exception ex)
4724 if (type.equalsIgnoreCase("PDB"))
4726 filesmatched.add(new Object[]
4727 { file, protocol, mtch });
4732 // File wasn't named like one of the sequences or wasn't a PDB file.
4733 filesnotmatched.add(file);
4737 if (filesmatched.size() > 0)
4739 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4743 "Do you want to automatically associate the "
4744 + filesmatched.size()
4745 + " PDB files with sequences in the alignment that have the same name ?",
4746 "Automatically Associate PDB files by name",
4747 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4750 for (Object[] fm : filesmatched)
4752 // try and associate
4753 // TODO: may want to set a standard ID naming formalism for
4754 // associating PDB files which have no IDs.
4755 for (SequenceI toassoc : (SequenceI[]) fm[2])
4757 PDBEntry pe = new AssociatePdbFileWithSeq()
4758 .associatePdbWithSeq((String) fm[0],
4759 (String) fm[1], toassoc, false);
4762 System.err.println("Associated file : "
4763 + ((String) fm[0]) + " with "
4764 + toassoc.getDisplayId(true));
4768 alignPanel.paintAlignment(true);
4772 if (filesnotmatched.size() > 0)
4775 && (Cache.getDefault(
4776 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4779 "<html>Do you want to <em>ignore</em> the "
4780 + filesnotmatched.size()
4781 + " files whose names did not match any sequence IDs ?</html>",
4782 "Ignore unmatched dropped files ?",
4783 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4787 for (String fn : filesnotmatched)
4789 loadJalviewDataFile(fn, null, null, null);
4793 } catch (Exception ex)
4795 ex.printStackTrace();
4801 * Attempt to load a "dropped" file or URL string: First by testing whether
4802 * it's and Annotation file, then a JNet file, and finally a features file. If
4803 * all are false then the user may have dropped an alignment file onto this
4807 * either a filename or a URL string.
4809 public void loadJalviewDataFile(String file, String protocol,
4810 String format, SequenceI assocSeq)
4814 if (protocol == null)
4816 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4818 // if the file isn't identified, or not positively identified as some
4819 // other filetype (PFAM is default unidentified alignment file type) then
4820 // try to parse as annotation.
4821 boolean isAnnotation = (format == null || format
4822 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4823 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4828 // first see if its a T-COFFEE score file
4829 TCoffeeScoreFile tcf = null;
4832 tcf = new TCoffeeScoreFile(file, protocol);
4835 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4837 tcoffeeColour.setEnabled(true);
4838 tcoffeeColour.setSelected(true);
4839 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4840 isAnnotation = true;
4842 .setText("Successfully pasted T-Coffee scores to alignment.");
4846 // some problem - if no warning its probable that the ID matching process didn't work
4847 JOptionPane.showMessageDialog(Desktop.desktop,
4848 tcf.getWarningMessage()==null ? "Check that the file matches sequence IDs in the alignment." : tcf.getWarningMessage(),
4849 "Problem reading T-COFFEE score file",
4850 JOptionPane.WARNING_MESSAGE);
4857 } catch (Exception x)
4859 Cache.log.debug("Exception when processing data source as T-COFFEE score file",x);
4864 // try to see if its a JNet 'concise' style annotation file *before*
4866 // try to parse it as a features file
4869 format = new IdentifyFile().Identify(file, protocol);
4871 if (format.equalsIgnoreCase("JnetFile"))
4873 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4875 new JnetAnnotationMaker().add_annotation(predictions,
4876 viewport.getAlignment(), 0, false);
4877 isAnnotation = true;
4882 * if (format.equalsIgnoreCase("PDB")) {
4884 * String pdbfn = ""; // try to match up filename with sequence id
4885 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4886 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4887 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4888 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4889 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4890 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4891 * // attempt to find a match in the alignment SequenceI mtch =
4892 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4893 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4894 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4895 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4896 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4897 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4898 * { System.err.println("Associated file : " + file + " with " +
4899 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4900 * TODO: maybe need to load as normal otherwise return; } }
4902 // try to parse it as a features file
4903 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4904 // if it wasn't a features file then we just treat it as a general
4905 // alignment file to load into the current view.
4908 new FileLoader().LoadFile(viewport, file, protocol, format);
4912 alignPanel.paintAlignment(true);
4920 alignPanel.adjustAnnotationHeight();
4921 viewport.updateSequenceIdColours();
4922 buildSortByAnnotationScoresMenu();
4923 alignPanel.paintAlignment(true);
4925 } catch (Exception ex)
4927 ex.printStackTrace();
4932 public void tabSelectionChanged(int index)
4936 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4937 viewport = alignPanel.av;
4938 setMenusFromViewport(viewport);
4943 public void tabbedPane_mousePressed(MouseEvent e)
4945 if (SwingUtilities.isRightMouseButton(e))
4947 String reply = JOptionPane.showInternalInputDialog(this,
4948 "Enter View Name", "Edit View Name",
4949 JOptionPane.QUESTION_MESSAGE);
4953 viewport.viewName = reply;
4954 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4959 public AlignViewport getCurrentView()
4965 * Open the dialog for regex description parsing.
4968 protected void extractScores_actionPerformed(ActionEvent e)
4970 ParseProperties pp = new jalview.analysis.ParseProperties(
4971 viewport.getAlignment());
4972 // TODO: verify regex and introduce GUI dialog for version 2.5
4973 // if (pp.getScoresFromDescription("col", "score column ",
4974 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4976 if (pp.getScoresFromDescription("description column",
4977 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4979 buildSortByAnnotationScoresMenu();
4987 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4991 protected void showDbRefs_actionPerformed(ActionEvent e)
4993 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4999 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5003 protected void showNpFeats_actionPerformed(ActionEvent e)
5005 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5009 * find the viewport amongst the tabs in this alignment frame and close that
5014 public boolean closeView(AlignViewport av)
5018 this.closeMenuItem_actionPerformed(false);
5021 Component[] comp = tabbedPane.getComponents();
5022 for (int i = 0; comp != null && i < comp.length; i++)
5024 if (comp[i] instanceof AlignmentPanel)
5026 if (((AlignmentPanel) comp[i]).av == av)
5029 closeView((AlignmentPanel) comp[i]);
5037 protected void build_fetchdbmenu(JMenu webService)
5039 // Temporary hack - DBRef Fetcher always top level ws entry.
5040 // TODO We probably want to store a sequence database checklist in
5041 // preferences and have checkboxes.. rather than individual sources selected
5043 final JMenu rfetch = new JMenu("Fetch DB References");
5044 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5045 webService.add(rfetch);
5047 JMenuItem fetchr = new JMenuItem("Standard Databases");
5048 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5049 fetchr.addActionListener(new ActionListener()
5053 public void actionPerformed(ActionEvent e)
5055 new Thread(new Runnable()
5061 new jalview.ws.DBRefFetcher(alignPanel.av
5062 .getSequenceSelection(), alignPanel.alignFrame)
5063 .fetchDBRefs(false);
5071 final AlignFrame me = this;
5072 new Thread(new Runnable()
5077 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5078 .getSequenceFetcherSingleton(me);
5079 javax.swing.SwingUtilities.invokeLater(new Runnable()
5084 String[] dbclasses = sf.getOrderedSupportedSources();
5085 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5086 // jalview.util.QuickSort.sort(otherdb, otherdb);
5087 List<DbSourceProxy> otherdb;
5088 JMenu dfetch = new JMenu();
5089 JMenu ifetch = new JMenu();
5090 JMenuItem fetchr = null;
5091 int comp = 0, icomp = 0, mcomp = 15;
5092 String mname = null;
5094 for (String dbclass : dbclasses)
5096 otherdb = sf.getSourceProxy(dbclass);
5097 // add a single entry for this class, or submenu allowing 'fetch
5099 if (otherdb == null || otherdb.size() < 1)
5103 // List<DbSourceProxy> dbs=otherdb;
5104 // otherdb=new ArrayList<DbSourceProxy>();
5105 // for (DbSourceProxy db:dbs)
5107 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5111 mname = "From " + dbclass;
5113 if (otherdb.size() == 1)
5115 final DbSourceProxy[] dassource = otherdb
5116 .toArray(new DbSourceProxy[0]);
5117 DbSourceProxy src = otherdb.get(0);
5118 fetchr = new JMenuItem(src.getDbSource());
5119 fetchr.addActionListener(new ActionListener()
5123 public void actionPerformed(ActionEvent e)
5125 new Thread(new Runnable()
5131 new jalview.ws.DBRefFetcher(alignPanel.av
5132 .getSequenceSelection(),
5133 alignPanel.alignFrame, dassource)
5134 .fetchDBRefs(false);
5140 fetchr.setToolTipText("<html>"
5141 + JvSwingUtils.wrapTooltip("Retrieve from "
5142 + src.getDbName()) + "<html>");
5148 final DbSourceProxy[] dassource = otherdb
5149 .toArray(new DbSourceProxy[0]);
5151 DbSourceProxy src = otherdb.get(0);
5152 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5154 fetchr.addActionListener(new ActionListener()
5157 public void actionPerformed(ActionEvent e)
5159 new Thread(new Runnable()
5165 new jalview.ws.DBRefFetcher(alignPanel.av
5166 .getSequenceSelection(),
5167 alignPanel.alignFrame, dassource)
5168 .fetchDBRefs(false);
5174 fetchr.setToolTipText("<html>"
5175 + JvSwingUtils.wrapTooltip("Retrieve from all "
5176 + otherdb.size() + " sources in "
5177 + src.getDbSource() + "<br>First is :"
5178 + src.getDbName()) + "<html>");
5181 // and then build the rest of the individual menus
5182 ifetch = new JMenu("Sources from " + src.getDbSource());
5184 String imname = null;
5186 for (DbSourceProxy sproxy : otherdb)
5188 String dbname = sproxy.getDbName();
5189 String sname = dbname.length() > 5 ? dbname.substring(0,
5190 5) + "..." : dbname;
5191 String msname = dbname.length() > 10 ? dbname.substring(
5192 0, 10) + "..." : dbname;
5195 imname = "from '" + sname + "'";
5197 fetchr = new JMenuItem(msname);
5198 final DbSourceProxy[] dassrc =
5200 fetchr.addActionListener(new ActionListener()
5204 public void actionPerformed(ActionEvent e)
5206 new Thread(new Runnable()
5212 new jalview.ws.DBRefFetcher(alignPanel.av
5213 .getSequenceSelection(),
5214 alignPanel.alignFrame, dassrc)
5215 .fetchDBRefs(false);
5221 fetchr.setToolTipText("<html>"
5222 + JvSwingUtils.wrapTooltip("Retrieve from "
5223 + dbname) + "</html>");
5226 if (++icomp >= mcomp || i == (otherdb.size()))
5228 ifetch.setText(imname + " to '" + sname + "'");
5230 ifetch = new JMenu();
5238 if (comp >= mcomp || dbi >= (dbclasses.length))
5240 dfetch.setText(mname + " to '" + dbclass + "'");
5242 dfetch = new JMenu();
5255 * Left justify the whole alignment.
5258 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5260 AlignmentI al = viewport.getAlignment();
5262 viewport.firePropertyChange("alignment", null, al);
5266 * Right justify the whole alignment.
5269 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5271 AlignmentI al = viewport.getAlignment();
5273 viewport.firePropertyChange("alignment", null, al);
5276 public void setShowSeqFeatures(boolean b)
5278 showSeqFeatures.setSelected(true);
5279 viewport.setShowSequenceFeatures(true);
5286 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5287 * awt.event.ActionEvent)
5290 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5292 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5293 alignPanel.paintAlignment(true);
5300 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5304 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5306 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5307 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5315 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5316 * .event.ActionEvent)
5319 protected void showGroupConservation_actionPerformed(ActionEvent e)
5321 viewport.setShowGroupConservation(showGroupConservation.getState());
5322 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5329 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5330 * .event.ActionEvent)
5333 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5335 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5336 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5343 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5344 * .event.ActionEvent)
5347 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5349 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5350 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5354 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5356 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5357 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5361 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5363 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5370 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5371 * .event.ActionEvent)
5374 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5376 if (viewport.getSelectionGroup() != null)
5378 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5379 viewport.getSequenceSelection(),
5380 viewport.getAlignmentView(true).getSequenceStrings(
5381 viewport.getGapCharacter()), viewport.getAlignment()
5383 viewport.getAlignment().deleteAllGroups();
5384 viewport.sequenceColours = null;
5385 viewport.setSelectionGroup(null);
5386 // set view properties for each group
5387 for (int g = 0; g < gps.length; g++)
5389 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5390 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5391 viewport.getAlignment().addGroup(gps[g]);
5392 Color col = new Color((int) (Math.random() * 255),
5393 (int) (Math.random() * 255), (int) (Math.random() * 255));
5394 col = col.brighter();
5395 for (SequenceI s:gps[g].getSequences())
5396 viewport.setSequenceColour(
5400 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5401 alignPanel.updateAnnotation();
5402 alignPanel.paintAlignment(true);
5407 * make the given alignmentPanel the currently selected tab
5409 * @param alignmentPanel
5411 public void setDisplayedView(AlignmentPanel alignmentPanel)
5413 if (!viewport.getSequenceSetId().equals(
5414 alignmentPanel.av.getSequenceSetId()))
5417 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5419 if (tabbedPane != null
5420 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5421 .getSelectedIndex())
5423 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5428 class PrintThread extends Thread
5432 public PrintThread(AlignmentPanel ap)
5437 static PageFormat pf;
5442 PrinterJob printJob = PrinterJob.getPrinterJob();
5446 printJob.setPrintable(ap, pf);
5450 printJob.setPrintable(ap);
5453 if (printJob.printDialog())
5458 } catch (Exception PrintException)
5460 PrintException.printStackTrace();