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.jbgui.GAlignFrame;
59 import jalview.schemes.Blosum62ColourScheme;
60 import jalview.schemes.BuriedColourScheme;
61 import jalview.schemes.ClustalxColourScheme;
62 import jalview.schemes.ColourSchemeI;
63 import jalview.schemes.ColourSchemeProperty;
64 import jalview.schemes.HelixColourScheme;
65 import jalview.schemes.HydrophobicColourScheme;
66 import jalview.schemes.NucleotideColourScheme;
67 import jalview.schemes.PIDColourScheme;
68 import jalview.schemes.PurinePyrimidineColourScheme;
69 import jalview.schemes.RNAHelicesColourChooser;
70 import jalview.schemes.ResidueProperties;
71 import jalview.schemes.StrandColourScheme;
72 import jalview.schemes.TaylorColourScheme;
73 import jalview.schemes.TurnColourScheme;
74 import jalview.schemes.UserColourScheme;
75 import jalview.schemes.ZappoColourScheme;
76 import jalview.ws.WSMenuEntryProviderI;
77 import jalview.ws.jws1.Discoverer;
78 import jalview.ws.jws2.Jws2Discoverer;
80 import java.awt.BorderLayout;
81 import java.awt.Color;
82 import java.awt.Component;
83 import java.awt.GridLayout;
84 import java.awt.Rectangle;
85 import java.awt.Toolkit;
86 import java.awt.datatransfer.Clipboard;
87 import java.awt.datatransfer.DataFlavor;
88 import java.awt.datatransfer.StringSelection;
89 import java.awt.datatransfer.Transferable;
90 import java.awt.dnd.DnDConstants;
91 import java.awt.dnd.DropTargetDragEvent;
92 import java.awt.dnd.DropTargetDropEvent;
93 import java.awt.dnd.DropTargetEvent;
94 import java.awt.dnd.DropTargetListener;
95 import java.awt.event.ActionEvent;
96 import java.awt.event.ActionListener;
97 import java.awt.event.KeyAdapter;
98 import java.awt.event.KeyEvent;
99 import java.awt.event.MouseAdapter;
100 import java.awt.event.MouseEvent;
101 import java.awt.print.PageFormat;
102 import java.awt.print.PrinterJob;
103 import java.beans.PropertyChangeEvent;
106 import java.util.ArrayList;
107 import java.util.Enumeration;
108 import java.util.Hashtable;
109 import java.util.Vector;
111 import javax.swing.JButton;
112 import javax.swing.JEditorPane;
113 import javax.swing.JInternalFrame;
114 import javax.swing.JLabel;
115 import javax.swing.JLayeredPane;
116 import javax.swing.JMenu;
117 import javax.swing.JMenuItem;
118 import javax.swing.JOptionPane;
119 import javax.swing.JPanel;
120 import javax.swing.JProgressBar;
121 import javax.swing.JRadioButtonMenuItem;
122 import javax.swing.JScrollPane;
123 import javax.swing.SwingUtilities;
129 * @version $Revision$
131 public class AlignFrame extends GAlignFrame implements DropTargetListener,
136 public static final int DEFAULT_WIDTH = 700;
139 public static final int DEFAULT_HEIGHT = 500;
141 public AlignmentPanel alignPanel;
143 AlignViewport viewport;
145 Vector alignPanels = new Vector();
148 * Last format used to load or save alignments in this window
150 String currentFileFormat = null;
153 * Current filename for this alignment
155 String fileName = null;
158 * Creates a new AlignFrame object with specific width and height.
164 public AlignFrame(AlignmentI al, int width, int height)
166 this(al, null, width, height);
170 * Creates a new AlignFrame object with specific width, height and
176 * @param sequenceSetId
178 public AlignFrame(AlignmentI al, int width, int height,
179 String sequenceSetId)
181 this(al, null, width, height, sequenceSetId);
185 * Creates a new AlignFrame object with specific width, height and
191 * @param sequenceSetId
194 public AlignFrame(AlignmentI al, int width, int height,
195 String sequenceSetId, String viewId)
197 this(al, null, width, height, sequenceSetId, viewId);
201 * new alignment window with hidden columns
205 * @param hiddenColumns
206 * ColumnSelection or null
208 * Width of alignment frame
212 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
213 int width, int height)
215 this(al, hiddenColumns, width, height, null);
219 * Create alignment frame for al with hiddenColumns, a specific width and
220 * height, and specific sequenceId
223 * @param hiddenColumns
226 * @param sequenceSetId
229 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
230 int width, int height, String sequenceSetId)
232 this(al, hiddenColumns, width, height, sequenceSetId, null);
236 * Create alignment frame for al with hiddenColumns, a specific width and
237 * height, and specific sequenceId
240 * @param hiddenColumns
243 * @param sequenceSetId
248 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
249 int width, int height, String sequenceSetId, String viewId)
251 setSize(width, height);
252 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
254 alignPanel = new AlignmentPanel(this, viewport);
256 if (al.getDataset() == null)
261 addAlignmentPanel(alignPanel, true);
266 * Make a new AlignFrame from exisiting alignmentPanels
273 public AlignFrame(AlignmentPanel ap)
277 addAlignmentPanel(ap, false);
282 * initalise the alignframe from the underlying viewport data and the
287 if (viewport.getAlignmentConservationAnnotation() == null)
289 BLOSUM62Colour.setEnabled(false);
290 conservationMenuItem.setEnabled(false);
291 modifyConservation.setEnabled(false);
292 // PIDColour.setEnabled(false);
293 // abovePIDThreshold.setEnabled(false);
294 // modifyPID.setEnabled(false);
297 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
300 if (sortby.equals("Id"))
302 sortIDMenuItem_actionPerformed(null);
304 else if (sortby.equals("Pairwise Identity"))
306 sortPairwiseMenuItem_actionPerformed(null);
309 if (Desktop.desktop != null)
311 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
312 addServiceListeners();
313 setGUINucleotide(viewport.getAlignment().isNucleotide());
316 setMenusFromViewport(viewport);
317 buildSortByAnnotationScoresMenu();
318 if (viewport.wrapAlignment)
320 wrapMenuItem_actionPerformed(null);
323 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
325 this.overviewMenuItem_actionPerformed(null);
333 * Change the filename and format for the alignment, and enable the 'reload'
334 * button functionality.
341 public void setFileName(String file, String format)
344 currentFileFormat = format;
345 reload.setEnabled(true);
348 void addKeyListener()
350 addKeyListener(new KeyAdapter()
352 public void keyPressed(KeyEvent evt)
354 if (viewport.cursorMode
355 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
356 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
357 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
358 && Character.isDigit(evt.getKeyChar()))
359 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
361 switch (evt.getKeyCode())
364 case 27: // escape key
365 deselectAllSequenceMenuItem_actionPerformed(null);
369 case KeyEvent.VK_DOWN:
370 if (evt.isAltDown() || !viewport.cursorMode)
371 moveSelectedSequences(false);
372 if (viewport.cursorMode)
373 alignPanel.seqPanel.moveCursor(0, 1);
377 if (evt.isAltDown() || !viewport.cursorMode)
378 moveSelectedSequences(true);
379 if (viewport.cursorMode)
380 alignPanel.seqPanel.moveCursor(0, -1);
384 case KeyEvent.VK_LEFT:
385 if (evt.isAltDown() || !viewport.cursorMode)
386 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
388 alignPanel.seqPanel.moveCursor(-1, 0);
392 case KeyEvent.VK_RIGHT:
393 if (evt.isAltDown() || !viewport.cursorMode)
394 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
396 alignPanel.seqPanel.moveCursor(1, 0);
399 case KeyEvent.VK_SPACE:
400 if (viewport.cursorMode)
402 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
403 || evt.isShiftDown() || evt.isAltDown());
407 // case KeyEvent.VK_A:
408 // if (viewport.cursorMode)
410 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
411 // //System.out.println("A");
415 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
416 * System.out.println("closing bracket"); } break;
418 case KeyEvent.VK_DELETE:
419 case KeyEvent.VK_BACK_SPACE:
420 if (!viewport.cursorMode)
422 cut_actionPerformed(null);
426 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
427 || evt.isShiftDown() || evt.isAltDown());
433 if (viewport.cursorMode)
435 alignPanel.seqPanel.setCursorRow();
439 if (viewport.cursorMode && !evt.isControlDown())
441 alignPanel.seqPanel.setCursorColumn();
445 if (viewport.cursorMode)
447 alignPanel.seqPanel.setCursorPosition();
451 case KeyEvent.VK_ENTER:
452 case KeyEvent.VK_COMMA:
453 if (viewport.cursorMode)
455 alignPanel.seqPanel.setCursorRowAndColumn();
460 if (viewport.cursorMode)
462 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
466 if (viewport.cursorMode)
468 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
473 viewport.cursorMode = !viewport.cursorMode;
474 statusBar.setText("Keyboard editing mode is "
475 + (viewport.cursorMode ? "on" : "off"));
476 if (viewport.cursorMode)
478 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
479 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
481 alignPanel.seqPanel.seqCanvas.repaint();
487 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
488 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
490 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
492 javax.help.HelpBroker hb = hs.createHelpBroker();
493 hb.setCurrentID("home");
494 hb.setDisplayed(true);
495 } catch (Exception ex)
497 ex.printStackTrace();
502 boolean toggleSeqs = !evt.isControlDown();
503 boolean toggleCols = !evt.isShiftDown();
504 toggleHiddenRegions(toggleSeqs, toggleCols);
507 case KeyEvent.VK_PAGE_UP:
508 if (viewport.wrapAlignment)
510 alignPanel.scrollUp(true);
514 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
515 - viewport.endSeq + viewport.startSeq);
518 case KeyEvent.VK_PAGE_DOWN:
519 if (viewport.wrapAlignment)
521 alignPanel.scrollUp(false);
525 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
526 + viewport.endSeq - viewport.startSeq);
532 public void keyReleased(KeyEvent evt)
534 switch (evt.getKeyCode())
536 case KeyEvent.VK_LEFT:
537 if (evt.isAltDown() || !viewport.cursorMode)
538 viewport.firePropertyChange("alignment", null, viewport
539 .getAlignment().getSequences());
542 case KeyEvent.VK_RIGHT:
543 if (evt.isAltDown() || !viewport.cursorMode)
544 viewport.firePropertyChange("alignment", null, viewport
545 .getAlignment().getSequences());
552 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
554 ap.alignFrame = this;
556 alignPanels.addElement(ap);
558 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
560 int aSize = alignPanels.size();
562 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
564 if (aSize == 1 && ap.av.viewName == null)
566 this.getContentPane().add(ap, BorderLayout.CENTER);
572 setInitialTabVisible();
575 expandViews.setEnabled(true);
576 gatherViews.setEnabled(true);
577 tabbedPane.addTab(ap.av.viewName, ap);
579 ap.setVisible(false);
584 if (ap.av.isPadGaps())
586 ap.av.getAlignment().padGaps();
588 ap.av.updateConservation(ap);
589 ap.av.updateConsensus(ap);
590 ap.av.updateStrucConsensus(ap);
594 public void setInitialTabVisible()
596 expandViews.setEnabled(true);
597 gatherViews.setEnabled(true);
598 tabbedPane.setVisible(true);
599 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
600 tabbedPane.addTab(first.av.viewName, first);
601 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
604 public AlignViewport getViewport()
609 /* Set up intrinsic listeners for dynamically generated GUI bits. */
610 private void addServiceListeners()
612 final java.beans.PropertyChangeListener thisListener;
613 Desktop.instance.addJalviewPropertyChangeListener("services",
614 thisListener = new java.beans.PropertyChangeListener()
616 public void propertyChange(PropertyChangeEvent evt)
618 // // System.out.println("Discoverer property change.");
619 // if (evt.getPropertyName().equals("services"))
621 SwingUtilities.invokeLater(new Runnable()
627 .println("Rebuild WS Menu for service change");
628 BuildWebServiceMenu();
635 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
637 public void internalFrameClosed(
638 javax.swing.event.InternalFrameEvent evt)
640 System.out.println("deregistering discoverer listener");
641 Desktop.instance.removeJalviewPropertyChangeListener("services",
643 closeMenuItem_actionPerformed(true);
646 // Finally, build the menu once to get current service state
647 new Thread(new Runnable()
651 BuildWebServiceMenu();
656 public void setGUINucleotide(boolean nucleotide)
658 showTranslation.setVisible(nucleotide);
659 conservationMenuItem.setEnabled(!nucleotide);
660 modifyConservation.setEnabled(!nucleotide);
661 showGroupConservation.setEnabled(!nucleotide);
662 rnahelicesColour.setEnabled(nucleotide);
663 purinePyrimidineColour.setEnabled(nucleotide);
664 // Remember AlignFrame always starts as protein
668 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
673 * set up menus for the currently viewport. This may be called after any
674 * operation that affects the data in the current view (selection changed,
675 * etc) to update the menus to reflect the new state.
677 public void setMenusForViewport()
679 setMenusFromViewport(viewport);
683 * Need to call this method when tabs are selected for multiple views, or when
684 * loading from Jalview2XML.java
689 void setMenusFromViewport(AlignViewport av)
691 padGapsMenuitem.setSelected(av.isPadGaps());
692 colourTextMenuItem.setSelected(av.showColourText);
693 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
694 conservationMenuItem.setSelected(av.getConservationSelected());
695 seqLimits.setSelected(av.getShowJVSuffix());
696 idRightAlign.setSelected(av.rightAlignIds);
697 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
698 renderGapsMenuItem.setSelected(av.renderGaps);
699 wrapMenuItem.setSelected(av.wrapAlignment);
700 scaleAbove.setVisible(av.wrapAlignment);
701 scaleLeft.setVisible(av.wrapAlignment);
702 scaleRight.setVisible(av.wrapAlignment);
703 annotationPanelMenuItem.setState(av.showAnnotation);
704 viewBoxesMenuItem.setSelected(av.showBoxes);
705 viewTextMenuItem.setSelected(av.showText);
706 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
707 showGroupConsensus.setSelected(av.isShowGroupConsensus());
708 showGroupConservation.setSelected(av.isShowGroupConservation());
709 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
710 showSequenceLogo.setSelected(av.isShowSequenceLogo());
711 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
713 setColourSelected(ColourSchemeProperty.getColourName(av
714 .getGlobalColourScheme()));
716 showSeqFeatures.setSelected(av.showSequenceFeatures);
717 hiddenMarkers.setState(av.showHiddenMarkers);
718 applyToAllGroups.setState(av.colourAppliesToAllGroups);
719 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
720 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
721 autoCalculate.setSelected(av.autoCalculateConsensus);
722 sortByTree.setSelected(av.sortByTree);
723 listenToViewSelections.setSelected(av.followSelection);
724 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
726 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
727 setShowProductsEnabled();
732 Hashtable progressBars, progressBarHandlers;
737 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
739 public void setProgressBar(String message, long id)
741 if (progressBars == null)
743 progressBars = new Hashtable();
744 progressBarHandlers = new Hashtable();
747 JPanel progressPanel;
748 Long lId = new Long(id);
749 GridLayout layout = (GridLayout) statusPanel.getLayout();
750 if (progressBars.get(lId) != null)
752 progressPanel = (JPanel) progressBars.get(new Long(id));
753 statusPanel.remove(progressPanel);
754 progressBars.remove(lId);
755 progressPanel = null;
758 statusBar.setText(message);
760 if (progressBarHandlers.contains(lId))
762 progressBarHandlers.remove(lId);
764 layout.setRows(layout.getRows() - 1);
768 progressPanel = new JPanel(new BorderLayout(10, 5));
770 JProgressBar progressBar = new JProgressBar();
771 progressBar.setIndeterminate(true);
773 progressPanel.add(new JLabel(message), BorderLayout.WEST);
774 progressPanel.add(progressBar, BorderLayout.CENTER);
776 layout.setRows(layout.getRows() + 1);
777 statusPanel.add(progressPanel);
779 progressBars.put(lId, progressPanel);
782 // setMenusForViewport();
786 public void registerHandler(final long id,
787 final IProgressIndicatorHandler handler)
789 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
792 "call setProgressBar before registering the progress bar's handler.");
794 progressBarHandlers.put(new Long(id), handler);
795 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
796 if (handler.canCancel())
798 JButton cancel = new JButton("Cancel");
799 final IProgressIndicator us = this;
800 cancel.addActionListener(new ActionListener()
803 public void actionPerformed(ActionEvent e)
805 handler.cancelActivity(id);
808 + ((JLabel) progressPanel.getComponent(0))
812 progressPanel.add(cancel, BorderLayout.EAST);
818 * @return true if any progress bars are still active
820 public boolean operationInProgress()
822 if (progressBars != null && progressBars.size() > 0)
830 * Added so Castor Mapping file can obtain Jalview Version
832 public String getVersion()
834 return jalview.bin.Cache.getProperty("VERSION");
837 public FeatureRenderer getFeatureRenderer()
839 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
842 public void fetchSequence_actionPerformed(ActionEvent e)
844 new SequenceFetcher(this);
847 public void addFromFile_actionPerformed(ActionEvent e)
849 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
852 public void reload_actionPerformed(ActionEvent e)
854 if (fileName != null)
856 // TODO: work out how to recover feature settings for correct view(s) when
858 if (currentFileFormat.equals("Jalview"))
860 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
861 for (int i = 0; i < frames.length; i++)
863 if (frames[i] instanceof AlignFrame && frames[i] != this
864 && ((AlignFrame) frames[i]).fileName.equals(fileName))
868 frames[i].setSelected(true);
869 Desktop.instance.closeAssociatedWindows();
870 } catch (java.beans.PropertyVetoException ex)
876 Desktop.instance.closeAssociatedWindows();
878 FileLoader loader = new FileLoader();
879 String protocol = fileName.startsWith("http:") ? "URL" : "File";
880 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
884 Rectangle bounds = this.getBounds();
886 FileLoader loader = new FileLoader();
887 String protocol = fileName.startsWith("http:") ? "URL" : "File";
888 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
889 protocol, currentFileFormat);
891 newframe.setBounds(bounds);
892 if (featureSettings != null && featureSettings.isShowing())
894 final Rectangle fspos = featureSettings.frame.getBounds();
895 // TODO: need a 'show feature settings' function that takes bounds -
896 // need to refactor Desktop.addFrame
897 newframe.featureSettings_actionPerformed(null);
898 final FeatureSettings nfs = newframe.featureSettings;
899 SwingUtilities.invokeLater(new Runnable()
903 nfs.frame.setBounds(fspos);
906 this.featureSettings.close();
907 this.featureSettings = null;
909 this.closeMenuItem_actionPerformed(true);
914 public void addFromText_actionPerformed(ActionEvent e)
916 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
919 public void addFromURL_actionPerformed(ActionEvent e)
921 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
924 public void save_actionPerformed(ActionEvent e)
927 || (currentFileFormat == null || !jalview.io.FormatAdapter
928 .isValidIOFormat(currentFileFormat, true))
929 || fileName.startsWith("http"))
931 saveAs_actionPerformed(null);
935 saveAlignment(fileName, currentFileFormat);
945 public void saveAs_actionPerformed(ActionEvent e)
947 JalviewFileChooser chooser = new JalviewFileChooser(
948 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
949 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
950 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
951 currentFileFormat, false);
953 chooser.setFileView(new JalviewFileView());
954 chooser.setDialogTitle("Save Alignment to file");
955 chooser.setToolTipText("Save");
957 int value = chooser.showSaveDialog(this);
959 if (value == JalviewFileChooser.APPROVE_OPTION)
961 currentFileFormat = chooser.getSelectedFormat();
962 if (currentFileFormat == null)
964 JOptionPane.showInternalMessageDialog(Desktop.desktop,
965 "You must select a file format before saving!",
966 "File format not specified", JOptionPane.WARNING_MESSAGE);
967 value = chooser.showSaveDialog(this);
971 fileName = chooser.getSelectedFile().getPath();
973 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
976 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
977 if (currentFileFormat.indexOf(" ") > -1)
979 currentFileFormat = currentFileFormat.substring(0,
980 currentFileFormat.indexOf(" "));
982 saveAlignment(fileName, currentFileFormat);
986 public boolean saveAlignment(String file, String format)
988 boolean success = true;
990 if (format.equalsIgnoreCase("Jalview"))
992 String shortName = title;
994 if (shortName.indexOf(java.io.File.separatorChar) > -1)
996 shortName = shortName.substring(shortName
997 .lastIndexOf(java.io.File.separatorChar) + 1);
1000 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1002 statusBar.setText("Successfully saved to file: " + fileName + " in "
1003 + format + " format.");
1008 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1010 warningMessage("Cannot save file " + fileName + " using format "
1011 + format, "Alignment output format not supported");
1012 saveAs_actionPerformed(null);
1013 // JBPNote need to have a raise_gui flag here
1017 String[] omitHidden = null;
1019 if (viewport.hasHiddenColumns())
1021 int reply = JOptionPane
1022 .showInternalConfirmDialog(
1024 "The Alignment contains hidden columns."
1025 + "\nDo you want to save only the visible alignment?",
1026 "Save / Omit Hidden Columns",
1027 JOptionPane.YES_NO_OPTION,
1028 JOptionPane.QUESTION_MESSAGE);
1030 if (reply == JOptionPane.YES_OPTION)
1032 omitHidden = viewport.getViewAsString(false);
1035 FormatAdapter f = new FormatAdapter();
1036 String output = f.formatSequences(
1038 (Alignment) viewport.getAlignment(), // class cast exceptions will
1039 // occur in the distant future
1040 omitHidden, f.getCacheSuffixDefault(format),
1041 viewport.getColumnSelection());
1051 java.io.PrintWriter out = new java.io.PrintWriter(
1052 new java.io.FileWriter(file));
1056 this.setTitle(file);
1057 statusBar.setText("Successfully saved to file: " + fileName
1058 + " in " + format + " format.");
1059 } catch (Exception ex)
1062 ex.printStackTrace();
1069 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1070 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1076 private void warningMessage(String warning, String title)
1078 if (new jalview.util.Platform().isHeadless())
1080 System.err.println("Warning: " + title + "\nWarning: " + warning);
1085 JOptionPane.showInternalMessageDialog(this, warning, title,
1086 JOptionPane.WARNING_MESSAGE);
1097 protected void outputText_actionPerformed(ActionEvent e)
1099 String[] omitHidden = null;
1101 if (viewport.hasHiddenColumns())
1103 int reply = JOptionPane
1104 .showInternalConfirmDialog(
1106 "The Alignment contains hidden columns."
1107 + "\nDo you want to output only the visible alignment?",
1108 "Save / Omit Hidden Columns",
1109 JOptionPane.YES_NO_OPTION,
1110 JOptionPane.QUESTION_MESSAGE);
1112 if (reply == JOptionPane.YES_OPTION)
1114 omitHidden = viewport.getViewAsString(false);
1118 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1119 cap.setForInput(null);
1123 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1124 viewport.getAlignment(), omitHidden,
1125 viewport.getColumnSelection()));
1126 Desktop.addInternalFrame(cap,
1127 "Alignment output - " + e.getActionCommand(), 600, 500);
1128 } catch (OutOfMemoryError oom)
1130 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1142 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1144 new HTMLOutput(alignPanel,
1145 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1146 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1149 public void createImageMap(File file, String image)
1151 alignPanel.makePNGImageMap(file, image);
1160 public void createPNG(File f)
1162 alignPanel.makePNG(f);
1171 public void createEPS(File f)
1173 alignPanel.makeEPS(f);
1176 public void pageSetup_actionPerformed(ActionEvent e)
1178 PrinterJob printJob = PrinterJob.getPrinterJob();
1179 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1188 public void printMenuItem_actionPerformed(ActionEvent e)
1190 // Putting in a thread avoids Swing painting problems
1191 PrintThread thread = new PrintThread(alignPanel);
1195 public void exportFeatures_actionPerformed(ActionEvent e)
1197 new AnnotationExporter().exportFeatures(alignPanel);
1200 public void exportAnnotations_actionPerformed(ActionEvent e)
1202 new AnnotationExporter().exportAnnotations(alignPanel,
1203 viewport.showAnnotation ? viewport.getAlignment()
1204 .getAlignmentAnnotation() : null, viewport
1205 .getAlignment().getGroups(), ((Alignment) viewport
1206 .getAlignment()).alignmentProperties);
1209 public void associatedData_actionPerformed(ActionEvent e)
1211 // Pick the tree file
1212 JalviewFileChooser chooser = new JalviewFileChooser(
1213 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1214 chooser.setFileView(new JalviewFileView());
1215 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1216 chooser.setToolTipText("Load Jalview Annotations / Features file");
1218 int value = chooser.showOpenDialog(null);
1220 if (value == JalviewFileChooser.APPROVE_OPTION)
1222 String choice = chooser.getSelectedFile().getPath();
1223 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1224 loadJalviewDataFile(choice, null, null, null);
1230 * Close the current view or all views in the alignment frame. If the frame
1231 * only contains one view then the alignment will be removed from memory.
1233 * @param closeAllTabs
1235 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1237 if (alignPanels != null && alignPanels.size() < 2)
1239 closeAllTabs = true;
1244 if (alignPanels != null)
1248 if (this.isClosed())
1250 // really close all the windows - otherwise wait till
1251 // setClosed(true) is called
1252 for (int i = 0; i < alignPanels.size(); i++)
1254 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1261 closeView(alignPanel);
1267 this.setClosed(true);
1269 } catch (Exception ex)
1271 ex.printStackTrace();
1276 * close alignPanel2 and shuffle tabs appropriately.
1278 * @param alignPanel2
1280 public void closeView(AlignmentPanel alignPanel2)
1282 int index = tabbedPane.getSelectedIndex();
1283 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1284 alignPanels.removeElement(alignPanel2);
1286 // if (viewport == alignPanel2.av)
1290 alignPanel2.closePanel();
1293 tabbedPane.removeTabAt(closedindex);
1294 tabbedPane.validate();
1296 if (index > closedindex || index == tabbedPane.getTabCount())
1298 // modify currently selected tab index if necessary.
1302 this.tabSelectionChanged(index);
1308 void updateEditMenuBar()
1311 if (viewport.historyList.size() > 0)
1313 undoMenuItem.setEnabled(true);
1314 CommandI command = (CommandI) viewport.historyList.peek();
1315 undoMenuItem.setText("Undo " + command.getDescription());
1319 undoMenuItem.setEnabled(false);
1320 undoMenuItem.setText("Undo");
1323 if (viewport.redoList.size() > 0)
1325 redoMenuItem.setEnabled(true);
1327 CommandI command = (CommandI) viewport.redoList.peek();
1328 redoMenuItem.setText("Redo " + command.getDescription());
1332 redoMenuItem.setEnabled(false);
1333 redoMenuItem.setText("Redo");
1337 public void addHistoryItem(CommandI command)
1339 if (command.getSize() > 0)
1341 viewport.historyList.push(command);
1342 viewport.redoList.clear();
1343 updateEditMenuBar();
1344 viewport.updateHiddenColumns();
1345 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1346 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1347 // viewport.getColumnSelection()
1348 // .getHiddenColumns().size() > 0);
1354 * @return alignment objects for all views
1356 AlignmentI[] getViewAlignments()
1358 if (alignPanels != null)
1360 Enumeration e = alignPanels.elements();
1361 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1362 for (int i = 0; e.hasMoreElements(); i++)
1364 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1368 if (viewport != null)
1370 return new AlignmentI[]
1371 { viewport.getAlignment() };
1382 protected void undoMenuItem_actionPerformed(ActionEvent e)
1384 if (viewport.historyList.empty())
1386 CommandI command = (CommandI) viewport.historyList.pop();
1387 viewport.redoList.push(command);
1388 command.undoCommand(getViewAlignments());
1390 AlignViewport originalSource = getOriginatingSource(command);
1391 updateEditMenuBar();
1393 if (originalSource != null)
1395 if (originalSource != viewport)
1398 .warn("Implementation worry: mismatch of viewport origin for undo");
1400 originalSource.updateHiddenColumns();
1401 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1403 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1404 // viewport.getColumnSelection()
1405 // .getHiddenColumns().size() > 0);
1406 originalSource.firePropertyChange("alignment", null, originalSource
1407 .getAlignment().getSequences());
1417 protected void redoMenuItem_actionPerformed(ActionEvent e)
1419 if (viewport.redoList.size() < 1)
1424 CommandI command = (CommandI) viewport.redoList.pop();
1425 viewport.historyList.push(command);
1426 command.doCommand(getViewAlignments());
1428 AlignViewport originalSource = getOriginatingSource(command);
1429 updateEditMenuBar();
1431 if (originalSource != null)
1434 if (originalSource != viewport)
1437 .warn("Implementation worry: mismatch of viewport origin for redo");
1439 originalSource.updateHiddenColumns();
1440 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1442 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1443 // viewport.getColumnSelection()
1444 // .getHiddenColumns().size() > 0);
1445 originalSource.firePropertyChange("alignment", null, originalSource
1446 .getAlignment().getSequences());
1450 AlignViewport getOriginatingSource(CommandI command)
1452 AlignViewport originalSource = null;
1453 // For sequence removal and addition, we need to fire
1454 // the property change event FROM the viewport where the
1455 // original alignment was altered
1456 AlignmentI al = null;
1457 if (command instanceof EditCommand)
1459 EditCommand editCommand = (EditCommand) command;
1460 al = editCommand.getAlignment();
1461 Vector comps = (Vector) PaintRefresher.components.get(viewport
1462 .getSequenceSetId());
1464 for (int i = 0; i < comps.size(); i++)
1466 if (comps.elementAt(i) instanceof AlignmentPanel)
1468 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1470 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1477 if (originalSource == null)
1479 // The original view is closed, we must validate
1480 // the current view against the closed view first
1483 PaintRefresher.validateSequences(al, viewport.getAlignment());
1486 originalSource = viewport;
1489 return originalSource;
1498 public void moveSelectedSequences(boolean up)
1500 SequenceGroup sg = viewport.getSelectionGroup();
1509 for (int i = 1; i < viewport.getAlignment().getHeight(); i++)
1511 SequenceI seq = viewport.getAlignment().getSequenceAt(i);
1513 if (!sg.getSequences(null).contains(seq))
1518 SequenceI temp = viewport.getAlignment().getSequenceAt(i - 1);
1520 if (sg.getSequences(null).contains(temp))
1525 viewport.getAlignment().getSequences().setElementAt(temp, i);
1526 viewport.getAlignment().getSequences().setElementAt(seq, i - 1);
1531 for (int i = viewport.getAlignment().getHeight() - 2; i > -1; i--)
1533 SequenceI seq = viewport.getAlignment().getSequenceAt(i);
1535 if (!sg.getSequences(null).contains(seq))
1540 SequenceI temp = viewport.getAlignment().getSequenceAt(i + 1);
1542 if (sg.getSequences(null).contains(temp))
1547 viewport.getAlignment().getSequences().setElementAt(temp, i);
1548 viewport.getAlignment().getSequences().setElementAt(seq, i + 1);
1552 alignPanel.paintAlignment(true);
1555 synchronized void slideSequences(boolean right, int size)
1557 Vector sg = new Vector();
1558 if (viewport.cursorMode)
1560 sg.addElement(viewport.getAlignment().getSequenceAt(
1561 alignPanel.seqPanel.seqCanvas.cursorY));
1563 else if (viewport.getSelectionGroup() != null
1564 && viewport.getSelectionGroup().getSize() != viewport
1565 .getAlignment().getHeight())
1567 sg = viewport.getSelectionGroup().getSequences(
1568 viewport.getHiddenRepSequences());
1576 Vector invertGroup = new Vector();
1578 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1580 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1581 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1584 SequenceI[] seqs1 = new SequenceI[sg.size()];
1585 for (int i = 0; i < sg.size(); i++)
1586 seqs1[i] = (SequenceI) sg.elementAt(i);
1588 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1589 for (int i = 0; i < invertGroup.size(); i++)
1590 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1592 SlideSequencesCommand ssc;
1594 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1595 size, viewport.getGapCharacter());
1597 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1598 size, viewport.getGapCharacter());
1600 int groupAdjustment = 0;
1601 if (ssc.getGapsInsertedBegin() && right)
1603 if (viewport.cursorMode)
1604 alignPanel.seqPanel.moveCursor(size, 0);
1606 groupAdjustment = size;
1608 else if (!ssc.getGapsInsertedBegin() && !right)
1610 if (viewport.cursorMode)
1611 alignPanel.seqPanel.moveCursor(-size, 0);
1613 groupAdjustment = -size;
1616 if (groupAdjustment != 0)
1618 viewport.getSelectionGroup().setStartRes(
1619 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1620 viewport.getSelectionGroup().setEndRes(
1621 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1624 boolean appendHistoryItem = false;
1625 if (viewport.historyList != null && viewport.historyList.size() > 0
1626 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1628 appendHistoryItem = ssc
1629 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1633 if (!appendHistoryItem)
1634 addHistoryItem(ssc);
1645 protected void copy_actionPerformed(ActionEvent e)
1648 if (viewport.getSelectionGroup() == null)
1652 // TODO: preserve the ordering of displayed alignment annotation in any
1653 // internal paste (particularly sequence associated annotation)
1654 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1655 String[] omitHidden = null;
1657 if (viewport.hasHiddenColumns())
1659 omitHidden = viewport.getViewAsString(true);
1662 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1665 StringSelection ss = new StringSelection(output);
1669 jalview.gui.Desktop.internalCopy = true;
1670 // Its really worth setting the clipboard contents
1671 // to empty before setting the large StringSelection!!
1672 Toolkit.getDefaultToolkit().getSystemClipboard()
1673 .setContents(new StringSelection(""), null);
1675 Toolkit.getDefaultToolkit().getSystemClipboard()
1676 .setContents(ss, Desktop.instance);
1677 } catch (OutOfMemoryError er)
1679 new OOMWarning("copying region", er);
1683 Vector hiddenColumns = null;
1684 if (viewport.hasHiddenColumns())
1686 hiddenColumns = new Vector();
1687 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1688 .getSelectionGroup().getEndRes();
1689 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1692 int[] region = (int[]) viewport.getColumnSelection()
1693 .getHiddenColumns().elementAt(i);
1694 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1696 hiddenColumns.addElement(new int[]
1697 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1702 Desktop.jalviewClipboard = new Object[]
1703 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1704 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1713 protected void pasteNew_actionPerformed(ActionEvent e)
1724 protected void pasteThis_actionPerformed(ActionEvent e)
1730 * Paste contents of Jalview clipboard
1732 * @param newAlignment
1733 * true to paste to a new alignment, otherwise add to this.
1735 void paste(boolean newAlignment)
1737 boolean externalPaste = true;
1740 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1741 Transferable contents = c.getContents(this);
1743 if (contents == null)
1751 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1752 if (str.length() < 1)
1757 format = new IdentifyFile().Identify(str, "Paste");
1759 } catch (OutOfMemoryError er)
1761 new OOMWarning("Out of memory pasting sequences!!", er);
1765 SequenceI[] sequences;
1766 boolean annotationAdded = false;
1767 AlignmentI alignment = null;
1769 if (Desktop.jalviewClipboard != null)
1771 // The clipboard was filled from within Jalview, we must use the
1773 // And dataset from the copied alignment
1774 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1775 // be doubly sure that we create *new* sequence objects.
1776 sequences = new SequenceI[newseq.length];
1777 for (int i = 0; i < newseq.length; i++)
1779 sequences[i] = new Sequence(newseq[i]);
1781 alignment = new Alignment(sequences);
1782 externalPaste = false;
1786 // parse the clipboard as an alignment.
1787 alignment = new FormatAdapter().readFile(str, "Paste", format);
1788 sequences = alignment.getSequencesArray();
1796 if (Desktop.jalviewClipboard != null)
1798 // dataset is inherited
1799 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1803 // new dataset is constructed
1804 alignment.setDataset(null);
1806 alwidth = alignment.getWidth() + 1;
1810 AlignmentI pastedal = alignment; // preserve pasted alignment object
1811 // Add pasted sequences and dataset into existing alignment.
1812 alignment = viewport.getAlignment();
1813 alwidth = alignment.getWidth() + 1;
1814 // decide if we need to import sequences from an existing dataset
1815 boolean importDs = Desktop.jalviewClipboard != null
1816 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1817 // importDs==true instructs us to copy over new dataset sequences from
1818 // an existing alignment
1819 Vector newDs = (importDs) ? new Vector() : null; // used to create
1820 // minimum dataset set
1822 for (int i = 0; i < sequences.length; i++)
1826 newDs.addElement(null);
1828 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1830 if (importDs && ds != null)
1832 if (!newDs.contains(ds))
1834 newDs.setElementAt(ds, i);
1835 ds = new Sequence(ds);
1836 // update with new dataset sequence
1837 sequences[i].setDatasetSequence(ds);
1841 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1846 // copy and derive new dataset sequence
1847 sequences[i] = sequences[i].deriveSequence();
1848 alignment.getDataset().addSequence(
1849 sequences[i].getDatasetSequence());
1850 // TODO: avoid creation of duplicate dataset sequences with a
1851 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1853 alignment.addSequence(sequences[i]); // merges dataset
1857 newDs.clear(); // tidy up
1859 if (pastedal.getAlignmentAnnotation() != null)
1861 // Add any annotation attached to alignment.
1862 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1863 for (int i = 0; i < alann.length; i++)
1865 annotationAdded = true;
1866 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1868 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1869 newann.padAnnotation(alwidth);
1870 alignment.addAnnotation(newann);
1880 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1881 sequences, 0, alignment.getWidth(), alignment));
1883 // Add any annotations attached to sequences
1884 for (int i = 0; i < sequences.length; i++)
1886 if (sequences[i].getAnnotation() != null)
1888 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1890 annotationAdded = true;
1891 sequences[i].getAnnotation()[a].adjustForAlignment();
1892 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1893 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1898 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1905 // propagate alignment changed.
1906 viewport.setEndSeq(alignment.getHeight());
1907 if (annotationAdded)
1909 // Duplicate sequence annotation in all views.
1910 AlignmentI[] alview = this.getViewAlignments();
1911 for (int i = 0; i < sequences.length; i++)
1913 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1916 for (int avnum = 0; avnum < alview.length; avnum++)
1918 if (alview[avnum] != alignment)
1920 // duplicate in a view other than the one with input focus
1921 int avwidth = alview[avnum].getWidth() + 1;
1922 // this relies on sann being preserved after we
1923 // modify the sequence's annotation array for each duplication
1924 for (int a = 0; a < sann.length; a++)
1926 AlignmentAnnotation newann = new AlignmentAnnotation(
1928 sequences[i].addAlignmentAnnotation(newann);
1929 newann.padAnnotation(avwidth);
1930 alview[avnum].addAnnotation(newann); // annotation was
1931 // duplicated earlier
1932 alview[avnum].setAnnotationIndex(newann, a);
1937 buildSortByAnnotationScoresMenu();
1939 viewport.firePropertyChange("alignment", null,
1940 alignment.getSequences());
1945 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1947 String newtitle = new String("Copied sequences");
1949 if (Desktop.jalviewClipboard != null
1950 && Desktop.jalviewClipboard[2] != null)
1952 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1953 for (int i = 0; i < hc.size(); i++)
1955 int[] region = (int[]) hc.elementAt(i);
1956 af.viewport.hideColumns(region[0], region[1]);
1960 // >>>This is a fix for the moment, until a better solution is
1962 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1964 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1966 // TODO: maintain provenance of an alignment, rather than just make the
1967 // title a concatenation of operations.
1970 if (title.startsWith("Copied sequences"))
1976 newtitle = newtitle.concat("- from " + title);
1981 newtitle = new String("Pasted sequences");
1984 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1989 } catch (Exception ex)
1991 ex.printStackTrace();
1992 System.out.println("Exception whilst pasting: " + ex);
1993 // could be anything being pasted in here
2004 protected void cut_actionPerformed(ActionEvent e)
2006 copy_actionPerformed(null);
2007 delete_actionPerformed(null);
2016 protected void delete_actionPerformed(ActionEvent evt)
2019 SequenceGroup sg = viewport.getSelectionGroup();
2025 Vector seqs = new Vector();
2027 for (int i = 0; i < sg.getSize(); i++)
2029 seq = sg.getSequenceAt(i);
2030 seqs.addElement(seq);
2033 // If the cut affects all sequences, remove highlighted columns
2034 if (sg.getSize() == viewport.getAlignment().getHeight())
2036 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2037 sg.getEndRes() + 1);
2040 SequenceI[] cut = new SequenceI[seqs.size()];
2041 for (int i = 0; i < seqs.size(); i++)
2043 cut[i] = (SequenceI) seqs.elementAt(i);
2047 * //ADD HISTORY ITEM
2049 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2050 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2051 viewport.getAlignment()));
2053 viewport.setSelectionGroup(null);
2054 viewport.sendSelection();
2055 viewport.getAlignment().deleteGroup(sg);
2057 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2059 if (viewport.getAlignment().getHeight() < 1)
2063 this.setClosed(true);
2064 } catch (Exception ex)
2076 protected void deleteGroups_actionPerformed(ActionEvent e)
2078 viewport.getAlignment().deleteAllGroups();
2079 viewport.sequenceColours = null;
2080 viewport.setSelectionGroup(null);
2081 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2082 alignPanel.updateAnnotation();
2083 alignPanel.paintAlignment(true);
2092 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2094 SequenceGroup sg = new SequenceGroup();
2096 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2098 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2101 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2102 viewport.setSelectionGroup(sg);
2103 viewport.sendSelection();
2104 alignPanel.paintAlignment(true);
2105 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2114 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2116 if (viewport.cursorMode)
2118 alignPanel.seqPanel.keyboardNo1 = null;
2119 alignPanel.seqPanel.keyboardNo2 = null;
2121 viewport.setSelectionGroup(null);
2122 viewport.getColumnSelection().clear();
2123 viewport.setSelectionGroup(null);
2124 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2125 alignPanel.idPanel.idCanvas.searchResults = null;
2126 alignPanel.paintAlignment(true);
2127 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2128 viewport.sendSelection();
2137 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2139 SequenceGroup sg = viewport.getSelectionGroup();
2143 selectAllSequenceMenuItem_actionPerformed(null);
2148 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2150 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2153 alignPanel.paintAlignment(true);
2154 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2155 viewport.sendSelection();
2158 public void invertColSel_actionPerformed(ActionEvent e)
2160 viewport.invertColumnSelection();
2161 alignPanel.paintAlignment(true);
2162 viewport.sendSelection();
2171 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2173 trimAlignment(true);
2182 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2184 trimAlignment(false);
2187 void trimAlignment(boolean trimLeft)
2189 ColumnSelection colSel = viewport.getColumnSelection();
2192 if (colSel.size() > 0)
2196 column = colSel.getMin();
2200 column = colSel.getMax();
2204 if (viewport.getSelectionGroup() != null)
2206 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2207 viewport.getHiddenRepSequences());
2211 seqs = viewport.getAlignment().getSequencesArray();
2214 TrimRegionCommand trimRegion;
2217 trimRegion = new TrimRegionCommand("Remove Left",
2218 TrimRegionCommand.TRIM_LEFT, seqs, column,
2219 viewport.getAlignment(), viewport.getColumnSelection(),
2220 viewport.getSelectionGroup());
2221 viewport.setStartRes(0);
2225 trimRegion = new TrimRegionCommand("Remove Right",
2226 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2227 viewport.getAlignment(), viewport.getColumnSelection(),
2228 viewport.getSelectionGroup());
2231 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2233 addHistoryItem(trimRegion);
2235 Vector groups = viewport.getAlignment().getGroups();
2237 for (int i = 0; i < groups.size(); i++)
2239 SequenceGroup sg = (SequenceGroup) groups.get(i);
2241 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2242 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2244 viewport.getAlignment().deleteGroup(sg);
2248 viewport.firePropertyChange("alignment", null, viewport
2249 .getAlignment().getSequences());
2259 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2261 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2264 if (viewport.getSelectionGroup() != null)
2266 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2267 viewport.getHiddenRepSequences());
2268 start = viewport.getSelectionGroup().getStartRes();
2269 end = viewport.getSelectionGroup().getEndRes();
2273 seqs = viewport.getAlignment().getSequencesArray();
2276 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2277 "Remove Gapped Columns", seqs, start, end,
2278 viewport.getAlignment());
2280 addHistoryItem(removeGapCols);
2282 statusBar.setText("Removed " + removeGapCols.getSize()
2283 + " empty columns.");
2285 // This is to maintain viewport position on first residue
2286 // of first sequence
2287 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2288 int startRes = seq.findPosition(viewport.startRes);
2289 // ShiftList shifts;
2290 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2291 // edit.alColumnChanges=shifts.getInverse();
2292 // if (viewport.hasHiddenColumns)
2293 // viewport.getColumnSelection().compensateForEdits(shifts);
2294 viewport.setStartRes(seq.findIndex(startRes) - 1);
2295 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2306 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2308 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2311 if (viewport.getSelectionGroup() != null)
2313 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2314 viewport.getHiddenRepSequences());
2315 start = viewport.getSelectionGroup().getStartRes();
2316 end = viewport.getSelectionGroup().getEndRes();
2320 seqs = viewport.getAlignment().getSequencesArray();
2323 // This is to maintain viewport position on first residue
2324 // of first sequence
2325 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2326 int startRes = seq.findPosition(viewport.startRes);
2328 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2329 viewport.getAlignment()));
2331 viewport.setStartRes(seq.findIndex(startRes) - 1);
2333 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2344 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2346 viewport.setPadGaps(padGapsMenuitem.isSelected());
2347 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2353 // if (justifySeqs>0)
2355 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2367 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);
2482 public void expandViews_actionPerformed(ActionEvent e)
2484 Desktop.instance.explodeViews(this);
2487 public void gatherViews_actionPerformed(ActionEvent e)
2489 Desktop.instance.gatherViews(this);
2498 public void font_actionPerformed(ActionEvent e)
2500 new FontChooser(alignPanel);
2509 protected void seqLimit_actionPerformed(ActionEvent e)
2511 viewport.setShowJVSuffix(seqLimits.isSelected());
2513 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2514 .calculateIdWidth());
2515 alignPanel.paintAlignment(true);
2518 public void idRightAlign_actionPerformed(ActionEvent e)
2520 viewport.rightAlignIds = idRightAlign.isSelected();
2521 alignPanel.paintAlignment(true);
2524 public void centreColumnLabels_actionPerformed(ActionEvent e)
2526 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2527 alignPanel.paintAlignment(true);
2533 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2535 protected void followHighlight_actionPerformed()
2537 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2539 alignPanel.scrollToPosition(
2540 alignPanel.seqPanel.seqCanvas.searchResults, false);
2550 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2552 viewport.setColourText(colourTextMenuItem.isSelected());
2553 alignPanel.paintAlignment(true);
2562 public void wrapMenuItem_actionPerformed(ActionEvent e)
2564 scaleAbove.setVisible(wrapMenuItem.isSelected());
2565 scaleLeft.setVisible(wrapMenuItem.isSelected());
2566 scaleRight.setVisible(wrapMenuItem.isSelected());
2567 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2568 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2571 public void showAllSeqs_actionPerformed(ActionEvent e)
2573 viewport.showAllHiddenSeqs();
2576 public void showAllColumns_actionPerformed(ActionEvent e)
2578 viewport.showAllHiddenColumns();
2582 public void hideSelSequences_actionPerformed(ActionEvent e)
2584 viewport.hideAllSelectedSeqs();
2585 alignPanel.paintAlignment(true);
2589 * called by key handler and the hide all/show all menu items
2594 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2597 boolean hide = false;
2598 SequenceGroup sg = viewport.getSelectionGroup();
2599 if (!toggleSeqs && !toggleCols)
2601 // Hide everything by the current selection - this is a hack - we do the
2602 // invert and then hide
2603 // first check that there will be visible columns after the invert.
2604 if ((viewport.getColumnSelection() != null
2605 && viewport.getColumnSelection().getSelected() != null && viewport
2606 .getColumnSelection().getSelected().size() > 0)
2607 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2610 // now invert the sequence set, if required - empty selection implies
2611 // that no hiding is required.
2614 invertSequenceMenuItem_actionPerformed(null);
2615 sg = viewport.getSelectionGroup();
2619 viewport.expandColSelection(sg, true);
2620 // finally invert the column selection and get the new sequence
2622 invertColSel_actionPerformed(null);
2629 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2631 hideSelSequences_actionPerformed(null);
2634 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2637 showAllSeqs_actionPerformed(null);
2643 if (viewport.getColumnSelection().getSelected().size() > 0)
2645 hideSelColumns_actionPerformed(null);
2648 viewport.setSelectionGroup(sg);
2653 showAllColumns_actionPerformed(null);
2662 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2663 * event.ActionEvent)
2665 public void hideAllButSelection_actionPerformed(ActionEvent e)
2667 toggleHiddenRegions(false, false);
2674 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2677 public void hideAllSelection_actionPerformed(ActionEvent e)
2679 SequenceGroup sg = viewport.getSelectionGroup();
2680 viewport.expandColSelection(sg, false);
2681 viewport.hideAllSelectedSeqs();
2682 viewport.hideSelectedColumns();
2683 alignPanel.paintAlignment(true);
2690 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2693 public void showAllhidden_actionPerformed(ActionEvent e)
2695 viewport.showAllHiddenColumns();
2696 viewport.showAllHiddenSeqs();
2697 alignPanel.paintAlignment(true);
2700 public void hideSelColumns_actionPerformed(ActionEvent e)
2702 viewport.hideSelectedColumns();
2703 alignPanel.paintAlignment(true);
2706 public void hiddenMarkers_actionPerformed(ActionEvent e)
2708 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2718 protected void scaleAbove_actionPerformed(ActionEvent e)
2720 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2721 alignPanel.paintAlignment(true);
2730 protected void scaleLeft_actionPerformed(ActionEvent e)
2732 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2733 alignPanel.paintAlignment(true);
2742 protected void scaleRight_actionPerformed(ActionEvent e)
2744 viewport.setScaleRightWrapped(scaleRight.isSelected());
2745 alignPanel.paintAlignment(true);
2754 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2756 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2757 alignPanel.paintAlignment(true);
2766 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2768 viewport.setShowText(viewTextMenuItem.isSelected());
2769 alignPanel.paintAlignment(true);
2778 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2780 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2781 alignPanel.paintAlignment(true);
2784 public FeatureSettings featureSettings;
2786 public void featureSettings_actionPerformed(ActionEvent e)
2788 if (featureSettings != null)
2790 featureSettings.close();
2791 featureSettings = null;
2793 if (!showSeqFeatures.isSelected())
2795 // make sure features are actually displayed
2796 showSeqFeatures.setSelected(true);
2797 showSeqFeatures_actionPerformed(null);
2799 featureSettings = new FeatureSettings(this);
2803 * Set or clear 'Show Sequence Features'
2808 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2810 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2811 alignPanel.paintAlignment(true);
2812 if (alignPanel.getOverviewPanel() != null)
2814 alignPanel.getOverviewPanel().updateOverviewImage();
2819 * Set or clear 'Show Sequence Features'
2824 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2826 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2828 if (viewport.getShowSequenceFeaturesHeight())
2830 // ensure we're actually displaying features
2831 viewport.setShowSequenceFeatures(true);
2832 showSeqFeatures.setSelected(true);
2834 alignPanel.paintAlignment(true);
2835 if (alignPanel.getOverviewPanel() != null)
2837 alignPanel.getOverviewPanel().updateOverviewImage();
2847 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2849 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2850 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2853 public void alignmentProperties()
2855 JEditorPane editPane = new JEditorPane("text/html", "");
2856 editPane.setEditable(false);
2857 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2859 editPane.setText("<html>" + contents.toString() + "</html>");
2860 JInternalFrame frame = new JInternalFrame();
2861 frame.getContentPane().add(new JScrollPane(editPane));
2863 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2864 + getTitle(), 500, 400);
2873 public void overviewMenuItem_actionPerformed(ActionEvent e)
2875 if (alignPanel.overviewPanel != null)
2880 JInternalFrame frame = new JInternalFrame();
2881 OverviewPanel overview = new OverviewPanel(alignPanel);
2882 frame.setContentPane(overview);
2883 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2884 frame.getWidth(), frame.getHeight());
2886 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2887 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2889 public void internalFrameClosed(
2890 javax.swing.event.InternalFrameEvent evt)
2892 alignPanel.setOverviewPanel(null);
2896 alignPanel.setOverviewPanel(overview);
2899 public void textColour_actionPerformed(ActionEvent e)
2901 new TextColourChooser().chooseColour(alignPanel, null);
2910 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2921 public void clustalColour_actionPerformed(ActionEvent e)
2923 changeColour(new ClustalxColourScheme(viewport.getAlignment()
2924 .getSequences(), viewport.getAlignment().getWidth()));
2933 public void zappoColour_actionPerformed(ActionEvent e)
2935 changeColour(new ZappoColourScheme());
2944 public void taylorColour_actionPerformed(ActionEvent e)
2946 changeColour(new TaylorColourScheme());
2955 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2957 changeColour(new HydrophobicColourScheme());
2966 public void helixColour_actionPerformed(ActionEvent e)
2968 changeColour(new HelixColourScheme());
2977 public void strandColour_actionPerformed(ActionEvent e)
2979 changeColour(new StrandColourScheme());
2988 public void turnColour_actionPerformed(ActionEvent e)
2990 changeColour(new TurnColourScheme());
2999 public void buriedColour_actionPerformed(ActionEvent e)
3001 changeColour(new BuriedColourScheme());
3010 public void nucleotideColour_actionPerformed(ActionEvent e)
3012 changeColour(new NucleotideColourScheme());
3015 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3017 changeColour(new PurinePyrimidineColourScheme());
3021 * public void covariationColour_actionPerformed(ActionEvent e) {
3023 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3026 public void annotationColour_actionPerformed(ActionEvent e)
3028 new AnnotationColourChooser(viewport, alignPanel);
3031 public void rnahelicesColour_actionPerformed(ActionEvent e)
3033 new RNAHelicesColourChooser(viewport, alignPanel);
3042 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3044 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3053 public void changeColour(ColourSchemeI cs)
3059 if (viewport.getAbovePIDThreshold())
3061 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3064 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3066 viewport.setGlobalColourScheme(cs);
3070 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3073 if (viewport.getConservationSelected())
3076 Alignment al = (Alignment) viewport.getAlignment();
3077 Conservation c = new Conservation("All",
3078 ResidueProperties.propHash, 3, al.getSequences(), 0,
3082 c.verdict(false, viewport.getConsPercGaps());
3084 cs.setConservation(c);
3086 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3091 cs.setConservation(null);
3094 cs.setConsensus(viewport.getSequenceConsensusHash());
3097 viewport.setGlobalColourScheme(cs);
3099 if (viewport.getColourAppliesToAllGroups())
3101 Vector groups = viewport.getAlignment().getGroups();
3103 for (int i = 0; i < groups.size(); i++)
3105 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
3113 if (cs instanceof ClustalxColourScheme)
3115 sg.cs = new ClustalxColourScheme(sg.getSequences(viewport
3116 .getHiddenRepSequences()), sg.getWidth());
3118 else if (cs instanceof UserColourScheme)
3120 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3126 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
3127 } catch (Exception ex)
3132 if (viewport.getAbovePIDThreshold()
3133 || cs instanceof PIDColourScheme
3134 || cs instanceof Blosum62ColourScheme)
3136 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3138 sg.cs.setConsensus(AAFrequency.calculate(
3139 sg.getSequences(viewport.getHiddenRepSequences()),
3140 sg.getStartRes(), sg.getEndRes() + 1));
3144 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3147 if (viewport.getConservationSelected())
3149 Conservation c = new Conservation("Group",
3150 ResidueProperties.propHash, 3, sg.getSequences(viewport
3151 .getHiddenRepSequences()), sg.getStartRes(),
3152 sg.getEndRes() + 1);
3154 c.verdict(false, viewport.getConsPercGaps());
3155 sg.cs.setConservation(c);
3159 sg.cs.setConservation(null);
3164 if (alignPanel.getOverviewPanel() != null)
3166 alignPanel.getOverviewPanel().updateOverviewImage();
3169 alignPanel.paintAlignment(true);
3178 protected void modifyPID_actionPerformed(ActionEvent e)
3180 if (viewport.getAbovePIDThreshold()
3181 && viewport.getGlobalColourScheme() != null)
3183 SliderPanel.setPIDSliderSource(alignPanel,
3184 viewport.getGlobalColourScheme(), "Background");
3185 SliderPanel.showPIDSlider();
3195 protected void modifyConservation_actionPerformed(ActionEvent e)
3197 if (viewport.getConservationSelected()
3198 && viewport.getGlobalColourScheme() != null)
3200 SliderPanel.setConservationSlider(alignPanel,
3201 viewport.getGlobalColourScheme(), "Background");
3202 SliderPanel.showConservationSlider();
3212 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3214 viewport.setConservationSelected(conservationMenuItem.isSelected());
3216 viewport.setAbovePIDThreshold(false);
3217 abovePIDThreshold.setSelected(false);
3219 changeColour(viewport.getGlobalColourScheme());
3221 modifyConservation_actionPerformed(null);
3230 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3232 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3234 conservationMenuItem.setSelected(false);
3235 viewport.setConservationSelected(false);
3237 changeColour(viewport.getGlobalColourScheme());
3239 modifyPID_actionPerformed(null);
3248 public void userDefinedColour_actionPerformed(ActionEvent e)
3250 if (e.getActionCommand().equals("User Defined..."))
3252 new UserDefinedColours(alignPanel, null);
3256 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3257 .getUserColourSchemes().get(e.getActionCommand());
3263 public void updateUserColourMenu()
3266 Component[] menuItems = colourMenu.getMenuComponents();
3267 int i, iSize = menuItems.length;
3268 for (i = 0; i < iSize; i++)
3270 if (menuItems[i].getName() != null
3271 && menuItems[i].getName().equals("USER_DEFINED"))
3273 colourMenu.remove(menuItems[i]);
3277 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3279 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3280 .getUserColourSchemes().keys();
3282 while (userColours.hasMoreElements())
3284 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3285 userColours.nextElement().toString());
3286 radioItem.setName("USER_DEFINED");
3287 radioItem.addMouseListener(new MouseAdapter()
3289 public void mousePressed(MouseEvent evt)
3291 if (evt.isControlDown()
3292 || SwingUtilities.isRightMouseButton(evt))
3294 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3296 int option = JOptionPane.showInternalConfirmDialog(
3297 jalview.gui.Desktop.desktop,
3298 "Remove from default list?",
3299 "Remove user defined colour",
3300 JOptionPane.YES_NO_OPTION);
3301 if (option == JOptionPane.YES_OPTION)
3303 jalview.gui.UserDefinedColours
3304 .removeColourFromDefaults(radioItem.getText());
3305 colourMenu.remove(radioItem);
3309 radioItem.addActionListener(new ActionListener()
3311 public void actionPerformed(ActionEvent evt)
3313 userDefinedColour_actionPerformed(evt);
3320 radioItem.addActionListener(new ActionListener()
3322 public void actionPerformed(ActionEvent evt)
3324 userDefinedColour_actionPerformed(evt);
3328 colourMenu.insert(radioItem, 15);
3329 colours.add(radioItem);
3340 public void PIDColour_actionPerformed(ActionEvent e)
3342 changeColour(new PIDColourScheme());
3351 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3353 changeColour(new Blosum62ColourScheme());
3362 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3364 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3365 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3366 .getAlignment().getSequenceAt(0), null);
3367 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3368 viewport.getAlignment()));
3369 alignPanel.paintAlignment(true);
3378 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3380 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3381 AlignmentSorter.sortByID(viewport.getAlignment());
3382 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3383 viewport.getAlignment()));
3384 alignPanel.paintAlignment(true);
3393 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3395 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3396 AlignmentSorter.sortByLength(viewport.getAlignment());
3397 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3398 viewport.getAlignment()));
3399 alignPanel.paintAlignment(true);
3408 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3410 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3411 AlignmentSorter.sortByGroup(viewport.getAlignment());
3412 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3413 viewport.getAlignment()));
3415 alignPanel.paintAlignment(true);
3424 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3426 new RedundancyPanel(alignPanel, this);
3435 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3437 if ((viewport.getSelectionGroup() == null)
3438 || (viewport.getSelectionGroup().getSize() < 2))
3440 JOptionPane.showInternalMessageDialog(this,
3441 "You must select at least 2 sequences.", "Invalid Selection",
3442 JOptionPane.WARNING_MESSAGE);
3446 JInternalFrame frame = new JInternalFrame();
3447 frame.setContentPane(new PairwiseAlignPanel(viewport));
3448 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3458 public void PCAMenuItem_actionPerformed(ActionEvent e)
3460 if (((viewport.getSelectionGroup() != null)
3461 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3462 .getSelectionGroup().getSize() > 0))
3463 || (viewport.getAlignment().getHeight() < 4))
3465 JOptionPane.showInternalMessageDialog(this,
3466 "Principal component analysis must take\n"
3467 + "at least 4 input sequences.",
3468 "Sequence selection insufficient",
3469 JOptionPane.WARNING_MESSAGE);
3474 new PCAPanel(alignPanel);
3477 public void autoCalculate_actionPerformed(ActionEvent e)
3479 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3480 if (viewport.autoCalculateConsensus)
3482 viewport.firePropertyChange("alignment", null, viewport
3483 .getAlignment().getSequences());
3487 public void sortByTreeOption_actionPerformed(ActionEvent e)
3489 viewport.sortByTree = sortByTree.isSelected();
3493 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3495 viewport.followSelection = listenToViewSelections.isSelected();
3504 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3506 NewTreePanel("AV", "PID", "Average distance tree using PID");
3515 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3517 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3526 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3528 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3537 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3539 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3552 void NewTreePanel(String type, String pwType, String title)
3556 if (viewport.getSelectionGroup() != null)
3558 if (viewport.getSelectionGroup().getSize() < 3)
3563 "You need to have more than two sequences selected to build a tree!",
3564 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3569 SequenceGroup sg = viewport.getSelectionGroup();
3571 /* Decide if the selection is a column region */
3572 while (s < sg.getSize())
3574 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3580 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3581 + "Try using the Pad function in the edit menu,\n"
3582 + "or one of the multiple sequence alignment web services.",
3583 "Sequences in selection are not aligned",
3584 JOptionPane.WARNING_MESSAGE);
3590 title = title + " on region";
3591 tp = new TreePanel(alignPanel, type, pwType);
3595 // are the visible sequences aligned?
3596 if (!viewport.getAlignment().isAligned(false))
3601 "The sequences must be aligned before creating a tree.\n"
3602 + "Try using the Pad function in the edit menu,\n"
3603 + "or one of the multiple sequence alignment web services.",
3604 "Sequences not aligned",
3605 JOptionPane.WARNING_MESSAGE);
3610 if (viewport.getAlignment().getHeight() < 2)
3615 tp = new TreePanel(alignPanel, type, pwType);
3620 if (viewport.viewName != null)
3622 title += viewport.viewName + " of ";
3625 title += this.title;
3627 Desktop.addInternalFrame(tp, title, 600, 500);
3638 public void addSortByOrderMenuItem(String title,
3639 final AlignmentOrder order)
3641 final JMenuItem item = new JMenuItem("by " + title);
3643 item.addActionListener(new java.awt.event.ActionListener()
3645 public void actionPerformed(ActionEvent e)
3647 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3649 // TODO: JBPNote - have to map order entries to curent SequenceI
3651 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3653 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3656 alignPanel.paintAlignment(true);
3662 * Add a new sort by annotation score menu item
3665 * the menu to add the option to
3667 * the label used to retrieve scores for each sequence on the
3670 public void addSortByAnnotScoreMenuItem(JMenu sort,
3671 final String scoreLabel)
3673 final JMenuItem item = new JMenuItem(scoreLabel);
3675 item.addActionListener(new java.awt.event.ActionListener()
3677 public void actionPerformed(ActionEvent e)
3679 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3680 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3681 viewport.getAlignment());// ,viewport.getSelectionGroup());
3682 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3683 viewport.getAlignment()));
3684 alignPanel.paintAlignment(true);
3690 * last hash for alignment's annotation array - used to minimise cost of
3693 protected int _annotationScoreVectorHash;
3696 * search the alignment and rebuild the sort by annotation score submenu the
3697 * last alignment annotation vector hash is stored to minimize cost of
3698 * rebuilding in subsequence calls.
3701 public void buildSortByAnnotationScoresMenu()
3703 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3708 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3710 sortByAnnotScore.removeAll();
3711 // almost certainly a quicker way to do this - but we keep it simple
3712 Hashtable scoreSorts = new Hashtable();
3713 AlignmentAnnotation aann[];
3714 Enumeration sq = viewport.getAlignment().getSequences().elements();
3715 while (sq.hasMoreElements())
3717 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3718 for (int i = 0; aann != null && i < aann.length; i++)
3720 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3722 scoreSorts.put(aann[i].label, aann[i].label);
3726 Enumeration labels = scoreSorts.keys();
3727 while (labels.hasMoreElements())
3729 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3730 (String) labels.nextElement());
3732 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3735 _annotationScoreVectorHash = viewport.getAlignment()
3736 .getAlignmentAnnotation().hashCode();
3741 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3742 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3743 * call. Listeners are added to remove the menu item when the treePanel is
3744 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3748 * Displayed tree window.
3750 * SortBy menu item title.
3752 public void buildTreeMenu()
3754 sortByTreeMenu.removeAll();
3756 Vector comps = (Vector) PaintRefresher.components.get(viewport
3757 .getSequenceSetId());
3758 Vector treePanels = new Vector();
3759 int i, iSize = comps.size();
3760 for (i = 0; i < iSize; i++)
3762 if (comps.elementAt(i) instanceof TreePanel)
3764 treePanels.add(comps.elementAt(i));
3768 iSize = treePanels.size();
3772 sortByTreeMenu.setVisible(false);
3776 sortByTreeMenu.setVisible(true);
3778 for (i = 0; i < treePanels.size(); i++)
3780 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3781 final JMenuItem item = new JMenuItem(tp.getTitle());
3782 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3783 item.addActionListener(new java.awt.event.ActionListener()
3785 public void actionPerformed(ActionEvent e)
3787 tp.sortByTree_actionPerformed(null);
3788 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3793 sortByTreeMenu.add(item);
3797 public boolean sortBy(AlignmentOrder alorder, String undoname)
3799 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3800 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3801 if (undoname != null)
3803 addHistoryItem(new OrderCommand(undoname, oldOrder,
3804 viewport.getAlignment()));
3806 alignPanel.paintAlignment(true);
3811 * Work out whether the whole set of sequences or just the selected set will
3812 * be submitted for multiple alignment.
3815 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3817 // Now, check we have enough sequences
3818 AlignmentView msa = null;
3820 if ((viewport.getSelectionGroup() != null)
3821 && (viewport.getSelectionGroup().getSize() > 1))
3823 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3824 // some common interface!
3826 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3827 * SequenceI[sz = seqs.getSize(false)];
3829 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3830 * seqs.getSequenceAt(i); }
3832 msa = viewport.getAlignmentView(true);
3837 * Vector seqs = viewport.getAlignment().getSequences();
3839 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3841 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3842 * seqs.elementAt(i); } }
3844 msa = viewport.getAlignmentView(false);
3850 * Decides what is submitted to a secondary structure prediction service: the
3851 * first sequence in the alignment, or in the current selection, or, if the
3852 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3853 * region or the whole alignment. (where the first sequence in the set is the
3854 * one that the prediction will be for).
3856 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3858 AlignmentView seqs = null;
3860 if ((viewport.getSelectionGroup() != null)
3861 && (viewport.getSelectionGroup().getSize() > 0))
3863 seqs = viewport.getAlignmentView(true);
3867 seqs = viewport.getAlignmentView(false);
3869 // limit sequences - JBPNote in future - could spawn multiple prediction
3871 // TODO: viewport.getAlignment().isAligned is a global state - the local
3872 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3873 if (!viewport.getAlignment().isAligned(false))
3875 seqs.setSequences(new SeqCigar[]
3876 { seqs.getSequences()[0] });
3877 // TODO: if seqs.getSequences().length>1 then should really have warned
3890 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3892 // Pick the tree file
3893 JalviewFileChooser chooser = new JalviewFileChooser(
3894 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3895 chooser.setFileView(new JalviewFileView());
3896 chooser.setDialogTitle("Select a newick-like tree file");
3897 chooser.setToolTipText("Load a tree file");
3899 int value = chooser.showOpenDialog(null);
3901 if (value == JalviewFileChooser.APPROVE_OPTION)
3903 String choice = chooser.getSelectedFile().getPath();
3904 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3905 jalview.io.NewickFile fin = null;
3908 fin = new jalview.io.NewickFile(choice, "File");
3909 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3910 } catch (Exception ex)
3912 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3913 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3914 ex.printStackTrace();
3916 if (fin != null && fin.hasWarningMessage())
3918 JOptionPane.showMessageDialog(Desktop.desktop,
3919 fin.getWarningMessage(), "Possible problem with tree file",
3920 JOptionPane.WARNING_MESSAGE);
3925 public TreePanel ShowNewickTree(NewickFile nf, String title)
3927 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3930 public TreePanel ShowNewickTree(NewickFile nf, String title,
3931 AlignmentView input)
3933 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3936 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3937 int h, int x, int y)
3939 return ShowNewickTree(nf, title, null, w, h, x, y);
3943 * Add a treeviewer for the tree extracted from a newick file object to the
3944 * current alignment view
3951 * Associated alignment input data (or null)
3960 * @return TreePanel handle
3962 public TreePanel ShowNewickTree(NewickFile nf, String title,
3963 AlignmentView input, int w, int h, int x, int y)
3965 TreePanel tp = null;
3971 if (nf.getTree() != null)
3973 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3979 tp.setLocation(x, y);
3982 Desktop.addInternalFrame(tp, title, w, h);
3984 } catch (Exception ex)
3986 ex.printStackTrace();
3992 private boolean buildingMenu = false;
3995 * Generates menu items and listener event actions for web service clients
3998 public void BuildWebServiceMenu()
4000 while (buildingMenu)
4004 System.err.println("Waiting for building menu to finish.");
4006 } catch (Exception e)
4011 final AlignFrame me = this;
4012 buildingMenu = true;
4013 new Thread(new Runnable()
4019 System.err.println("Building ws menu again "
4020 + Thread.currentThread());
4021 // TODO: add support for context dependent disabling of services based
4023 // alignment and current selection
4024 // TODO: add additional serviceHandle parameter to specify abstract
4026 // class independently of AbstractName
4027 // TODO: add in rediscovery GUI function to restart discoverer
4028 // TODO: group services by location as well as function and/or
4030 // object broker mechanism.
4031 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4032 final IProgressIndicator af = me;
4033 final JMenu msawsmenu = new JMenu("Alignment");
4034 final JMenu secstrmenu = new JMenu(
4035 "Secondary Structure Prediction");
4036 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4037 final JMenu analymenu = new JMenu("Analysis");
4038 final JMenu dismenu = new JMenu("Disorder");
4039 // JAL-940 - only show secondary structure prediction services from
4040 // the legacy server
4041 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4043 Discoverer.services != null && (Discoverer.services.size() > 0))
4045 // TODO: refactor to allow list of AbstractName/Handler bindings to
4047 // stored or retrieved from elsewhere
4048 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4049 Vector secstrpr = (Vector) Discoverer.services
4051 Vector seqsrch = null; // (Vector)
4052 // Discoverer.services.get("SeqSearch");
4053 // TODO: move GUI generation code onto service implementation - so a
4054 // client instance attaches itself to the GUI with method call like
4055 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4059 // Add any Multiple Sequence Alignment Services
4060 for (int i = 0, j = msaws.size(); i < j; i++)
4062 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4064 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4065 .getServiceClient(sh);
4066 impl.attachWSMenuEntry(msawsmenu, me);
4070 if (secstrpr != null)
4072 // Add any secondary structure prediction services
4073 for (int i = 0, j = secstrpr.size(); i < j; i++)
4075 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4077 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4078 .getServiceClient(sh);
4079 impl.attachWSMenuEntry(secstrmenu, me);
4082 if (seqsrch != null)
4084 // Add any sequence search services
4085 for (int i = 0, j = seqsrch.size(); i < j; i++)
4087 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4089 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4090 .getServiceClient(sh);
4091 impl.attachWSMenuEntry(seqsrchmenu, me);
4096 // Add all submenus in the order they should appear on the web
4098 wsmenu.add(msawsmenu);
4099 wsmenu.add(secstrmenu);
4100 wsmenu.add(dismenu);
4101 wsmenu.add(analymenu);
4102 // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
4103 // submens.add(msawsmenu);
4104 // submens.add(secstrmenu);
4105 // submens.add(dismenu);
4106 // submens.add(analymenu);
4108 // No search services yet
4109 // wsmenu.add(seqsrchmenu);
4111 javax.swing.SwingUtilities.invokeLater(new Runnable()
4117 webService.removeAll();
4118 // first, add discovered services onto the webservices menu
4119 if (wsmenu.size() > 0)
4121 for (int i = 0, j = wsmenu.size(); i < j; i++)
4123 webService.add((JMenu) wsmenu.get(i));
4128 webService.add(me.webServiceNoServices);
4130 // TODO: move into separate menu builder class.
4131 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4133 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4134 if (jws2servs != null)
4136 if (jws2servs.hasServices())
4138 jws2servs.attachWSMenuEntry(webService, me);
4140 if (jws2servs.isRunning())
4142 JMenuItem tm = new JMenuItem(
4143 "Still discovering JABA Services");
4144 tm.setEnabled(false);
4150 build_urlServiceMenu(me.webService);
4151 build_fetchdbmenu(webService);
4152 for (JMenu item : wsmenu)
4154 if (item.getItemCount() == 0)
4156 item.setEnabled(false);
4160 item.setEnabled(true);
4163 } catch (Exception e)
4169 } catch (Exception e)
4174 buildingMenu = false;
4181 * construct any groupURL type service menu entries.
4185 private void build_urlServiceMenu(JMenu webService)
4187 // TODO: remove this code when 2.7 is released
4188 // DEBUG - alignmentView
4190 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4191 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4193 * @Override public void actionPerformed(ActionEvent e) {
4194 * jalview.datamodel.AlignmentView
4195 * .testSelectionViews(af.viewport.getAlignment(),
4196 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4198 * }); webService.add(testAlView);
4200 // TODO: refactor to RestClient discoverer and merge menu entries for
4201 // rest-style services with other types of analysis/calculation service
4202 // SHmmr test client - still being implemented.
4203 // DEBUG - alignmentView
4205 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4208 client.attachWSMenuEntry(
4209 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4213 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4215 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4221 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4222 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4223 * getProperty("LAST_DIRECTORY"));
4225 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4226 * to Vamsas file"); chooser.setToolTipText("Export");
4228 * int value = chooser.showSaveDialog(this);
4230 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4231 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4232 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4233 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4236 * prototype of an automatically enabled/disabled analysis function
4239 protected void setShowProductsEnabled()
4241 SequenceI[] selection = viewport.getSequenceSelection();
4242 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4243 viewport.getAlignment().getDataset()))
4245 showProducts.setEnabled(true);
4250 showProducts.setEnabled(false);
4255 * search selection for sequence xRef products and build the show products
4260 * @return true if showProducts menu should be enabled.
4262 public boolean canShowProducts(SequenceI[] selection,
4263 boolean isRegionSelection, Alignment dataset)
4265 boolean showp = false;
4268 showProducts.removeAll();
4269 final boolean dna = viewport.getAlignment().isNucleotide();
4270 final Alignment ds = dataset;
4271 String[] ptypes = (selection == null || selection.length == 0) ? null
4272 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4274 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4275 // selection, dataset, true);
4276 final SequenceI[] sel = selection;
4277 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4280 final boolean isRegSel = isRegionSelection;
4281 final AlignFrame af = this;
4282 final String source = ptypes[t];
4283 JMenuItem xtype = new JMenuItem(ptypes[t]);
4284 xtype.addActionListener(new ActionListener()
4287 public void actionPerformed(ActionEvent e)
4289 // TODO: new thread for this call with vis-delay
4290 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4291 isRegSel, dna, source);
4295 showProducts.add(xtype);
4297 showProducts.setVisible(showp);
4298 showProducts.setEnabled(showp);
4299 } catch (Exception e)
4301 jalview.bin.Cache.log
4302 .warn("canTranslate threw an exception - please report to help@jalview.org",
4309 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4310 boolean isRegSel, boolean dna, String source)
4312 final boolean fisRegSel = isRegSel;
4313 final boolean fdna = dna;
4314 final String fsrc = source;
4315 final AlignFrame ths = this;
4316 final SequenceI[] fsel = sel;
4317 Runnable foo = new Runnable()
4322 final long sttime = System.currentTimeMillis();
4323 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4326 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4330 Alignment prods = CrossRef
4331 .findXrefSequences(fsel, fdna, fsrc, ds);
4334 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4335 for (int s = 0; s < sprods.length; s++)
4337 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4338 if (ds.getSequences() == null
4339 || !ds.getSequences().contains(
4340 sprods[s].getDatasetSequence()))
4341 ds.addSequence(sprods[s].getDatasetSequence());
4342 sprods[s].updatePDBIds();
4344 Alignment al = new Alignment(sprods);
4345 AlignedCodonFrame[] cf = prods.getCodonFrames();
4347 for (int s = 0; cf != null && s < cf.length; s++)
4349 al.addCodonFrame(cf[s]);
4352 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4354 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4355 + " for " + ((fisRegSel) ? "selected region of " : "")
4357 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4362 System.err.println("No Sequences generated for xRef type "
4365 } catch (Exception e)
4367 jalview.bin.Cache.log.error(
4368 "Exception when finding crossreferences", e);
4369 } catch (OutOfMemoryError e)
4371 new OOMWarning("whilst fetching crossreferences", e);
4374 jalview.bin.Cache.log.error("Error when finding crossreferences",
4377 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4382 Thread frunner = new Thread(foo);
4386 public boolean canShowTranslationProducts(SequenceI[] selection,
4387 AlignmentI alignment)
4392 return (jalview.analysis.Dna.canTranslate(selection,
4393 viewport.getViewAsVisibleContigs(true)));
4394 } catch (Exception e)
4396 jalview.bin.Cache.log
4397 .warn("canTranslate threw an exception - please report to help@jalview.org",
4403 public void showProducts_actionPerformed(ActionEvent e)
4405 // /////////////////////////////
4406 // Collect Data to be translated/transferred
4408 SequenceI[] selection = viewport.getSequenceSelection();
4409 AlignmentI al = null;
4412 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4413 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4414 viewport.getAlignment().getDataset());
4415 } catch (Exception ex)
4418 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4425 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4426 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4430 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4431 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4432 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4436 public void showTranslation_actionPerformed(ActionEvent e)
4438 // /////////////////////////////
4439 // Collect Data to be translated/transferred
4441 SequenceI[] selection = viewport.getSequenceSelection();
4442 String[] seqstring = viewport.getViewAsString(true);
4443 AlignmentI al = null;
4446 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4447 viewport.getViewAsVisibleContigs(true), viewport
4448 .getGapCharacter(), viewport.getAlignment()
4449 .getAlignmentAnnotation(), viewport.getAlignment()
4450 .getWidth(), viewport.getAlignment().getDataset());
4451 } catch (Exception ex)
4454 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4461 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4462 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4466 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4467 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4468 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4473 * Try to load a features file onto the alignment.
4476 * contents or path to retrieve file
4478 * access mode of file (see jalview.io.AlignFile)
4479 * @return true if features file was parsed corectly.
4481 public boolean parseFeaturesFile(String file, String type)
4483 boolean featuresFile = false;
4486 featuresFile = new FeaturesFile(file, type).parse(viewport
4487 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4488 .getFeatureRenderer().featureColours, false,
4489 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4490 } catch (Exception ex)
4492 ex.printStackTrace();
4497 viewport.showSequenceFeatures = true;
4498 showSeqFeatures.setSelected(true);
4499 if (alignPanel.seqPanel.seqCanvas.fr != null)
4501 // update the min/max ranges where necessary
4502 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4504 if (featureSettings != null)
4506 featureSettings.setTableData();
4508 alignPanel.paintAlignment(true);
4511 return featuresFile;
4514 public void dragEnter(DropTargetDragEvent evt)
4518 public void dragExit(DropTargetEvent evt)
4522 public void dragOver(DropTargetDragEvent evt)
4526 public void dropActionChanged(DropTargetDragEvent evt)
4530 public void drop(DropTargetDropEvent evt)
4532 Transferable t = evt.getTransferable();
4533 java.util.List files = null;
4537 DataFlavor uriListFlavor = new DataFlavor(
4538 "text/uri-list;class=java.lang.String");
4539 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4541 // Works on Windows and MacOSX
4542 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4543 files = (java.util.List) t
4544 .getTransferData(DataFlavor.javaFileListFlavor);
4546 else if (t.isDataFlavorSupported(uriListFlavor))
4548 // This is used by Unix drag system
4549 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4550 String data = (String) t.getTransferData(uriListFlavor);
4551 files = new java.util.ArrayList(1);
4552 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4553 data, "\r\n"); st.hasMoreTokens();)
4555 String s = st.nextToken();
4556 if (s.startsWith("#"))
4558 // the line is a comment (as per the RFC 2483)
4562 java.net.URI uri = new java.net.URI(s);
4563 // check to see if we can handle this kind of URI
4564 if (uri.getScheme().toLowerCase().startsWith("http"))
4566 files.add(uri.toString());
4570 // otherwise preserve old behaviour: catch all for file objects
4571 java.io.File file = new java.io.File(uri);
4572 files.add(file.toString());
4576 } catch (Exception e)
4578 e.printStackTrace();
4584 // check to see if any of these files have names matching sequences in
4586 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4587 .getAlignment().getSequencesArray());
4589 * Object[] { String,SequenceI}
4591 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4592 ArrayList<String> filesnotmatched = new ArrayList<String>();
4593 for (int i = 0; i < files.size(); i++)
4595 String file = files.get(i).toString();
4597 String protocol = FormatAdapter.checkProtocol(file);
4598 if (protocol == jalview.io.FormatAdapter.FILE)
4600 File fl = new File(file);
4601 pdbfn = fl.getName();
4603 else if (protocol == jalview.io.FormatAdapter.URL)
4605 URL url = new URL(file);
4606 pdbfn = url.getFile();
4608 if (pdbfn.length() > 0)
4610 // attempt to find a match in the alignment
4611 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4612 int l = 0, c = pdbfn.indexOf(".");
4613 while (mtch == null && c != -1)
4618 } while ((c = pdbfn.indexOf(".", l)) > l);
4621 pdbfn = pdbfn.substring(0, l);
4623 mtch = idm.findAllIdMatches(pdbfn);
4630 type = new IdentifyFile().Identify(file, protocol);
4631 } catch (Exception ex)
4637 if (type.equalsIgnoreCase("PDB"))
4639 filesmatched.add(new Object[]
4640 { file, protocol, mtch });
4645 // File wasn't named like one of the sequences or wasn't a PDB file.
4646 filesnotmatched.add(file);
4650 if (filesmatched.size() > 0)
4652 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4656 "Do you want to automatically associate the "
4657 + filesmatched.size()
4658 + " PDB files with sequences in the alignment that have the same name ?",
4659 "Automatically Associate PDB files by name",
4660 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4663 for (Object[] fm : filesmatched)
4665 // try and associate
4666 // TODO: may want to set a standard ID naming formalism for
4667 // associating PDB files which have no IDs.
4668 for (SequenceI toassoc : (SequenceI[]) fm[2])
4670 PDBEntry pe = new AssociatePdbFileWithSeq()
4671 .associatePdbWithSeq((String) fm[0],
4672 (String) fm[1], toassoc, false);
4675 System.err.println("Associated file : "
4676 + ((String) fm[0]) + " with "
4677 + toassoc.getDisplayId(true));
4681 alignPanel.paintAlignment(true);
4685 if (filesnotmatched.size() > 0)
4688 && (Cache.getDefault(
4689 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4692 "<html>Do you want to <em>ignore</em> the "
4693 + filesnotmatched.size()
4694 + " files whose names did not match any sequence IDs ?</html>",
4695 "Ignore unmatched dropped files ?",
4696 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4700 for (String fn : filesnotmatched)
4702 loadJalviewDataFile(fn, null, null, null);
4706 } catch (Exception ex)
4708 ex.printStackTrace();
4714 * Attempt to load a "dropped" file or URL string: First by testing whether
4715 * it's and Annotation file, then a JNet file, and finally a features file. If
4716 * all are false then the user may have dropped an alignment file onto this
4720 * either a filename or a URL string.
4722 public void loadJalviewDataFile(String file, String protocol,
4723 String format, SequenceI assocSeq)
4727 if (protocol == null)
4729 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4731 // if the file isn't identified, or not positively identified as some
4732 // other filetype (PFAM is default unidentified alignment file type) then
4733 // try to parse as annotation.
4734 boolean isAnnotation = (format == null || format
4735 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4736 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4741 // try to see if its a JNet 'concise' style annotation file *before* we
4742 // try to parse it as a features file
4745 format = new IdentifyFile().Identify(file, protocol);
4747 if (format.equalsIgnoreCase("JnetFile"))
4749 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4751 new JnetAnnotationMaker().add_annotation(predictions,
4752 viewport.getAlignment(), 0, false);
4753 isAnnotation = true;
4758 * if (format.equalsIgnoreCase("PDB")) {
4760 * String pdbfn = ""; // try to match up filename with sequence id try
4761 * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new
4762 * File(file); pdbfn = fl.getName(); } else if (protocol ==
4763 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4764 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null)
4765 * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4766 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { //
4767 * attempt to find a match in the alignment SequenceI mtch =
4768 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4769 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l)
4770 * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch =
4771 * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate
4772 * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4773 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) {
4774 * System.err.println("Associated file : " + file + " with " +
4775 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4776 * TODO: maybe need to load as normal otherwise return; } }
4778 // try to parse it as a features file
4779 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4780 // if it wasn't a features file then we just treat it as a general
4781 // alignment file to load into the current view.
4784 new FileLoader().LoadFile(viewport, file, protocol, format);
4788 alignPanel.paintAlignment(true);
4795 alignPanel.adjustAnnotationHeight();
4796 viewport.updateSequenceIdColours();
4797 buildSortByAnnotationScoresMenu();
4798 alignPanel.paintAlignment(true);
4800 } catch (Exception ex)
4802 ex.printStackTrace();
4806 public void tabSelectionChanged(int index)
4810 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4811 viewport = alignPanel.av;
4812 setMenusFromViewport(viewport);
4816 public void tabbedPane_mousePressed(MouseEvent e)
4818 if (SwingUtilities.isRightMouseButton(e))
4820 String reply = JOptionPane.showInternalInputDialog(this,
4821 "Enter View Name", "Edit View Name",
4822 JOptionPane.QUESTION_MESSAGE);
4826 viewport.viewName = reply;
4827 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4832 public AlignViewport getCurrentView()
4838 * Open the dialog for regex description parsing.
4840 protected void extractScores_actionPerformed(ActionEvent e)
4842 ParseProperties pp = new jalview.analysis.ParseProperties(
4843 viewport.getAlignment());
4844 // TODO: verify regex and introduce GUI dialog for version 2.5
4845 // if (pp.getScoresFromDescription("col", "score column ",
4846 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4848 if (pp.getScoresFromDescription("description column",
4849 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4851 buildSortByAnnotationScoresMenu();
4859 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4862 protected void showDbRefs_actionPerformed(ActionEvent e)
4864 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4870 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4873 protected void showNpFeats_actionPerformed(ActionEvent e)
4875 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4879 * find the viewport amongst the tabs in this alignment frame and close that
4884 public boolean closeView(AlignViewport av)
4888 this.closeMenuItem_actionPerformed(false);
4891 Component[] comp = tabbedPane.getComponents();
4892 for (int i = 0; comp != null && i < comp.length; i++)
4894 if (comp[i] instanceof AlignmentPanel)
4896 if (((AlignmentPanel) comp[i]).av == av)
4899 closeView((AlignmentPanel) comp[i]);
4907 protected void build_fetchdbmenu(JMenu webService)
4909 // Temporary hack - DBRef Fetcher always top level ws entry.
4910 // TODO We probably want to store a sequence database checklist in
4911 // preferences and have checkboxes.. rather than individual sources selected
4913 final JMenu rfetch = new JMenu("Fetch DB References");
4914 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4915 webService.add(rfetch);
4917 JMenuItem fetchr = new JMenuItem("Standard Databases");
4918 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4919 fetchr.addActionListener(new ActionListener()
4922 public void actionPerformed(ActionEvent e)
4924 new Thread(new Runnable()
4929 new jalview.ws.DBRefFetcher(alignPanel.av
4930 .getSequenceSelection(), alignPanel.alignFrame)
4931 .fetchDBRefs(false);
4939 final AlignFrame me = this;
4940 new Thread(new Runnable()
4944 final jalview.ws.SequenceFetcher sf = SequenceFetcher
4945 .getSequenceFetcherSingleton(me);
4946 final String[] otherdb = sf.getOrderedSupportedSources();
4947 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4948 // jalview.util.QuickSort.sort(otherdb, otherdb);
4949 javax.swing.SwingUtilities.invokeLater(new Runnable()
4954 JMenu dfetch = new JMenu();
4957 int comp = 0, mcomp = 15;
4958 String mname = null;
4959 if (otherdb != null && otherdb.length > 0)
4961 for (int i = 0; i < otherdb.length; i++)
4963 String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
4966 mname = "from '" + dbname + "'";
4968 fetchr = new JMenuItem(otherdb[i]);
4969 final String[] dassource = new String[]
4971 fetchr.addActionListener(new ActionListener()
4974 public void actionPerformed(ActionEvent e)
4976 new Thread(new Runnable()
4981 new jalview.ws.DBRefFetcher(alignPanel.av
4982 .getSequenceSelection(),
4983 alignPanel.alignFrame, dassource)
4984 .fetchDBRefs(false);
4990 fetchr.setToolTipText("Retrieve from " + dbname);
4992 if (comp++ == mcomp || i == (otherdb.length - 1))
4994 dfetch.setText(mname + " to '" + dbname + "'");
4996 dfetch = new JMenu();
5010 * Left justify the whole alignment.
5012 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5014 AlignmentI al = viewport.getAlignment();
5016 viewport.firePropertyChange("alignment", null, al);
5020 * Right justify the whole alignment.
5022 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5024 AlignmentI al = viewport.getAlignment();
5026 viewport.firePropertyChange("alignment", null, al);
5029 public void setShowSeqFeatures(boolean b)
5031 showSeqFeatures.setSelected(true);
5032 viewport.setShowSequenceFeatures(true);
5039 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5040 * awt.event.ActionEvent)
5042 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5044 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5045 alignPanel.paintAlignment(true);
5052 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5055 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5057 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5058 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5066 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5067 * .event.ActionEvent)
5069 protected void showGroupConservation_actionPerformed(ActionEvent e)
5071 viewport.setShowGroupConservation(showGroupConservation.getState());
5072 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5079 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5080 * .event.ActionEvent)
5082 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5084 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5085 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5092 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5093 * .event.ActionEvent)
5095 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5097 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5098 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5101 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5103 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5104 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5107 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5109 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5116 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5117 * .event.ActionEvent)
5119 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5121 if (viewport.getSelectionGroup() != null)
5123 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5124 viewport.getSequenceSelection(),
5125 viewport.getAlignmentView(true).getSequenceStrings(
5126 viewport.getGapCharacter()), viewport.getAlignment()
5128 viewport.getAlignment().deleteAllGroups();
5129 viewport.sequenceColours = null;
5130 viewport.setSelectionGroup(null);
5131 // set view properties for each group
5132 for (int g = 0; g < gps.length; g++)
5134 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5135 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5136 viewport.getAlignment().addGroup(gps[g]);
5137 Color col = new Color((int) (Math.random() * 255),
5138 (int) (Math.random() * 255), (int) (Math.random() * 255));
5139 col = col.brighter();
5140 for (Enumeration sq = gps[g].getSequences(null).elements(); sq
5141 .hasMoreElements(); viewport.setSequenceColour(
5142 (SequenceI) sq.nextElement(), col))
5145 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5146 alignPanel.updateAnnotation();
5147 alignPanel.paintAlignment(true);
5152 * make the given alignmentPanel the currently selected tab
5154 * @param alignmentPanel
5156 public void setDisplayedView(AlignmentPanel alignmentPanel)
5158 if (!viewport.getSequenceSetId().equals(
5159 alignmentPanel.av.getSequenceSetId()))
5162 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5164 if (tabbedPane != null
5165 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5166 .getSelectedIndex())
5168 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5173 class PrintThread extends Thread
5177 public PrintThread(AlignmentPanel ap)
5182 static PageFormat pf;
5186 PrinterJob printJob = PrinterJob.getPrinterJob();
5190 printJob.setPrintable(ap, pf);
5194 printJob.setPrintable(ap);
5197 if (printJob.printDialog())
5202 } catch (Exception PrintException)
5204 PrintException.printStackTrace();