2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.analysis.AAFrequency;
22 import jalview.analysis.AlignmentSorter;
23 import jalview.analysis.Conservation;
24 import jalview.analysis.CrossRef;
25 import jalview.analysis.NJTree;
26 import jalview.analysis.ParseProperties;
27 import jalview.analysis.SequenceIdMatcher;
28 import jalview.bin.Cache;
29 import jalview.commands.CommandI;
30 import jalview.commands.EditCommand;
31 import jalview.commands.OrderCommand;
32 import jalview.commands.RemoveGapColCommand;
33 import jalview.commands.RemoveGapsCommand;
34 import jalview.commands.SlideSequencesCommand;
35 import jalview.commands.TrimRegionCommand;
36 import jalview.datamodel.AlignedCodonFrame;
37 import jalview.datamodel.Alignment;
38 import jalview.datamodel.AlignmentAnnotation;
39 import jalview.datamodel.AlignmentI;
40 import jalview.datamodel.AlignmentOrder;
41 import jalview.datamodel.AlignmentView;
42 import jalview.datamodel.ColumnSelection;
43 import jalview.datamodel.PDBEntry;
44 import jalview.datamodel.SeqCigar;
45 import jalview.datamodel.Sequence;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.io.AlignmentProperties;
49 import jalview.io.AnnotationFile;
50 import jalview.io.FeaturesFile;
51 import jalview.io.FileLoader;
52 import jalview.io.FormatAdapter;
53 import jalview.io.HTMLOutput;
54 import jalview.io.IdentifyFile;
55 import jalview.io.JalviewFileChooser;
56 import jalview.io.JalviewFileView;
57 import jalview.io.JnetAnnotationMaker;
58 import jalview.io.NewickFile;
59 import jalview.io.TCoffeeScoreFile;
60 import jalview.jbgui.GAlignFrame;
61 import jalview.schemes.Blosum62ColourScheme;
62 import jalview.schemes.BuriedColourScheme;
63 import jalview.schemes.ClustalxColourScheme;
64 import jalview.schemes.ColourSchemeI;
65 import jalview.schemes.ColourSchemeProperty;
66 import jalview.schemes.HelixColourScheme;
67 import jalview.schemes.HydrophobicColourScheme;
68 import jalview.schemes.NucleotideColourScheme;
69 import jalview.schemes.PIDColourScheme;
70 import jalview.schemes.PurinePyrimidineColourScheme;
71 import jalview.schemes.RNAHelicesColourChooser;
72 import jalview.schemes.ResidueProperties;
73 import jalview.schemes.StrandColourScheme;
74 import jalview.schemes.TCoffeeColourScheme;
75 import jalview.schemes.TaylorColourScheme;
76 import jalview.schemes.TurnColourScheme;
77 import jalview.schemes.UserColourScheme;
78 import jalview.schemes.ZappoColourScheme;
79 import jalview.ws.jws1.Discoverer;
80 import jalview.ws.jws2.Jws2Discoverer;
81 import jalview.ws.seqfetcher.DbSourceProxy;
83 import java.awt.BorderLayout;
84 import java.awt.Color;
85 import java.awt.Component;
86 import java.awt.GridLayout;
87 import java.awt.Rectangle;
88 import java.awt.Toolkit;
89 import java.awt.datatransfer.Clipboard;
90 import java.awt.datatransfer.DataFlavor;
91 import java.awt.datatransfer.StringSelection;
92 import java.awt.datatransfer.Transferable;
93 import java.awt.dnd.DnDConstants;
94 import java.awt.dnd.DropTargetDragEvent;
95 import java.awt.dnd.DropTargetDropEvent;
96 import java.awt.dnd.DropTargetEvent;
97 import java.awt.dnd.DropTargetListener;
98 import java.awt.event.ActionEvent;
99 import java.awt.event.ActionListener;
100 import java.awt.event.KeyAdapter;
101 import java.awt.event.KeyEvent;
102 import java.awt.event.MouseAdapter;
103 import java.awt.event.MouseEvent;
104 import java.awt.print.PageFormat;
105 import java.awt.print.PrinterJob;
106 import java.beans.PropertyChangeEvent;
109 import java.util.ArrayList;
110 import java.util.Enumeration;
111 import java.util.Hashtable;
112 import java.util.List;
113 import java.util.Vector;
115 import javax.swing.JButton;
116 import javax.swing.JEditorPane;
117 import javax.swing.JInternalFrame;
118 import javax.swing.JLabel;
119 import javax.swing.JLayeredPane;
120 import javax.swing.JMenu;
121 import javax.swing.JMenuItem;
122 import javax.swing.JOptionPane;
123 import javax.swing.JPanel;
124 import javax.swing.JProgressBar;
125 import javax.swing.JRadioButtonMenuItem;
126 import javax.swing.JScrollPane;
127 import javax.swing.SwingUtilities;
133 * @version $Revision$
135 public class AlignFrame extends GAlignFrame implements DropTargetListener,
140 public static final int DEFAULT_WIDTH = 700;
143 public static final int DEFAULT_HEIGHT = 500;
145 public AlignmentPanel alignPanel;
147 AlignViewport viewport;
149 Vector alignPanels = new Vector();
152 * Last format used to load or save alignments in this window
154 String currentFileFormat = null;
157 * Current filename for this alignment
159 String fileName = null;
162 * Creates a new AlignFrame object with specific width and height.
168 public AlignFrame(AlignmentI al, int width, int height)
170 this(al, null, width, height);
174 * Creates a new AlignFrame object with specific width, height and
180 * @param sequenceSetId
182 public AlignFrame(AlignmentI al, int width, int height,
183 String sequenceSetId)
185 this(al, null, width, height, sequenceSetId);
189 * Creates a new AlignFrame object with specific width, height and
195 * @param sequenceSetId
198 public AlignFrame(AlignmentI al, int width, int height,
199 String sequenceSetId, String viewId)
201 this(al, null, width, height, sequenceSetId, viewId);
205 * new alignment window with hidden columns
209 * @param hiddenColumns
210 * ColumnSelection or null
212 * Width of alignment frame
216 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
217 int width, int height)
219 this(al, hiddenColumns, width, height, null);
223 * Create alignment frame for al with hiddenColumns, a specific width and
224 * height, and specific sequenceId
227 * @param hiddenColumns
230 * @param sequenceSetId
233 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
234 int width, int height, String sequenceSetId)
236 this(al, hiddenColumns, width, height, sequenceSetId, null);
240 * Create alignment frame for al with hiddenColumns, a specific width and
241 * height, and specific sequenceId
244 * @param hiddenColumns
247 * @param sequenceSetId
252 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
253 int width, int height, String sequenceSetId, String viewId)
255 setSize(width, height);
256 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
258 alignPanel = new AlignmentPanel(this, viewport);
260 if (al.getDataset() == null)
265 addAlignmentPanel(alignPanel, true);
270 * Make a new AlignFrame from exisiting alignmentPanels
277 public AlignFrame(AlignmentPanel ap)
281 addAlignmentPanel(ap, false);
286 * initalise the alignframe from the underlying viewport data and the
291 if (viewport.getAlignmentConservationAnnotation() == null)
293 BLOSUM62Colour.setEnabled(false);
294 conservationMenuItem.setEnabled(false);
295 modifyConservation.setEnabled(false);
296 // PIDColour.setEnabled(false);
297 // abovePIDThreshold.setEnabled(false);
298 // modifyPID.setEnabled(false);
301 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
304 if (sortby.equals("Id"))
306 sortIDMenuItem_actionPerformed(null);
308 else if (sortby.equals("Pairwise Identity"))
310 sortPairwiseMenuItem_actionPerformed(null);
313 if (Desktop.desktop != null)
315 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
316 addServiceListeners();
317 setGUINucleotide(viewport.getAlignment().isNucleotide());
320 setMenusFromViewport(viewport);
321 buildSortByAnnotationScoresMenu();
322 if (viewport.wrapAlignment)
324 wrapMenuItem_actionPerformed(null);
327 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
329 this.overviewMenuItem_actionPerformed(null);
337 * Change the filename and format for the alignment, and enable the 'reload'
338 * button functionality.
345 public void setFileName(String file, String format)
348 currentFileFormat = format;
349 reload.setEnabled(true);
352 void addKeyListener()
354 addKeyListener(new KeyAdapter()
357 public void keyPressed(KeyEvent evt)
359 if (viewport.cursorMode
360 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
361 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
362 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
363 && Character.isDigit(evt.getKeyChar()))
364 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
366 switch (evt.getKeyCode())
369 case 27: // escape key
370 deselectAllSequenceMenuItem_actionPerformed(null);
374 case KeyEvent.VK_DOWN:
375 if (evt.isAltDown() || !viewport.cursorMode)
376 moveSelectedSequences(false);
377 if (viewport.cursorMode)
378 alignPanel.seqPanel.moveCursor(0, 1);
382 if (evt.isAltDown() || !viewport.cursorMode)
383 moveSelectedSequences(true);
384 if (viewport.cursorMode)
385 alignPanel.seqPanel.moveCursor(0, -1);
389 case KeyEvent.VK_LEFT:
390 if (evt.isAltDown() || !viewport.cursorMode)
391 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
393 alignPanel.seqPanel.moveCursor(-1, 0);
397 case KeyEvent.VK_RIGHT:
398 if (evt.isAltDown() || !viewport.cursorMode)
399 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
401 alignPanel.seqPanel.moveCursor(1, 0);
404 case KeyEvent.VK_SPACE:
405 if (viewport.cursorMode)
407 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
408 || evt.isShiftDown() || evt.isAltDown());
412 // case KeyEvent.VK_A:
413 // if (viewport.cursorMode)
415 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
416 // //System.out.println("A");
420 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
421 * System.out.println("closing bracket"); } break;
423 case KeyEvent.VK_DELETE:
424 case KeyEvent.VK_BACK_SPACE:
425 if (!viewport.cursorMode)
427 cut_actionPerformed(null);
431 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
432 || evt.isShiftDown() || evt.isAltDown());
438 if (viewport.cursorMode)
440 alignPanel.seqPanel.setCursorRow();
444 if (viewport.cursorMode && !evt.isControlDown())
446 alignPanel.seqPanel.setCursorColumn();
450 if (viewport.cursorMode)
452 alignPanel.seqPanel.setCursorPosition();
456 case KeyEvent.VK_ENTER:
457 case KeyEvent.VK_COMMA:
458 if (viewport.cursorMode)
460 alignPanel.seqPanel.setCursorRowAndColumn();
465 if (viewport.cursorMode)
467 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
471 if (viewport.cursorMode)
473 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
478 viewport.cursorMode = !viewport.cursorMode;
479 statusBar.setText("Keyboard editing mode is "
480 + (viewport.cursorMode ? "on" : "off"));
481 if (viewport.cursorMode)
483 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
484 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
486 alignPanel.seqPanel.seqCanvas.repaint();
492 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
493 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
495 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
497 javax.help.HelpBroker hb = hs.createHelpBroker();
498 hb.setCurrentID("home");
499 hb.setDisplayed(true);
500 } catch (Exception ex)
502 ex.printStackTrace();
507 boolean toggleSeqs = !evt.isControlDown();
508 boolean toggleCols = !evt.isShiftDown();
509 toggleHiddenRegions(toggleSeqs, toggleCols);
512 case KeyEvent.VK_PAGE_UP:
513 if (viewport.wrapAlignment)
515 alignPanel.scrollUp(true);
519 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
520 - viewport.endSeq + viewport.startSeq);
523 case KeyEvent.VK_PAGE_DOWN:
524 if (viewport.wrapAlignment)
526 alignPanel.scrollUp(false);
530 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
531 + viewport.endSeq - viewport.startSeq);
538 public void keyReleased(KeyEvent evt)
540 switch (evt.getKeyCode())
542 case KeyEvent.VK_LEFT:
543 if (evt.isAltDown() || !viewport.cursorMode)
544 viewport.firePropertyChange("alignment", null, viewport
545 .getAlignment().getSequences());
548 case KeyEvent.VK_RIGHT:
549 if (evt.isAltDown() || !viewport.cursorMode)
550 viewport.firePropertyChange("alignment", null, viewport
551 .getAlignment().getSequences());
558 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
560 ap.alignFrame = this;
562 alignPanels.addElement(ap);
564 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
566 int aSize = alignPanels.size();
568 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
570 if (aSize == 1 && ap.av.viewName == null)
572 this.getContentPane().add(ap, BorderLayout.CENTER);
578 setInitialTabVisible();
581 expandViews.setEnabled(true);
582 gatherViews.setEnabled(true);
583 tabbedPane.addTab(ap.av.viewName, ap);
585 ap.setVisible(false);
590 if (ap.av.isPadGaps())
592 ap.av.getAlignment().padGaps();
594 ap.av.updateConservation(ap);
595 ap.av.updateConsensus(ap);
596 ap.av.updateStrucConsensus(ap);
600 public void setInitialTabVisible()
602 expandViews.setEnabled(true);
603 gatherViews.setEnabled(true);
604 tabbedPane.setVisible(true);
605 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
606 tabbedPane.addTab(first.av.viewName, first);
607 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
610 public AlignViewport getViewport()
615 /* Set up intrinsic listeners for dynamically generated GUI bits. */
616 private void addServiceListeners()
618 final java.beans.PropertyChangeListener thisListener;
619 Desktop.instance.addJalviewPropertyChangeListener("services",
620 thisListener = new java.beans.PropertyChangeListener()
623 public void propertyChange(PropertyChangeEvent evt)
625 // // System.out.println("Discoverer property change.");
626 // if (evt.getPropertyName().equals("services"))
628 SwingUtilities.invokeLater(new Runnable()
635 .println("Rebuild WS Menu for service change");
636 BuildWebServiceMenu();
643 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
646 public void internalFrameClosed(
647 javax.swing.event.InternalFrameEvent evt)
649 System.out.println("deregistering discoverer listener");
650 Desktop.instance.removeJalviewPropertyChangeListener("services",
652 closeMenuItem_actionPerformed(true);
655 // Finally, build the menu once to get current service state
656 new Thread(new Runnable()
661 BuildWebServiceMenu();
666 public void setGUINucleotide(boolean nucleotide)
668 showTranslation.setVisible(nucleotide);
669 conservationMenuItem.setEnabled(!nucleotide);
670 modifyConservation.setEnabled(!nucleotide);
671 showGroupConservation.setEnabled(!nucleotide);
672 rnahelicesColour.setEnabled(nucleotide);
673 purinePyrimidineColour.setEnabled(nucleotide);
674 // Remember AlignFrame always starts as protein
678 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
683 * set up menus for the currently viewport. This may be called after any
684 * operation that affects the data in the current view (selection changed,
685 * etc) to update the menus to reflect the new state.
687 public void setMenusForViewport()
689 setMenusFromViewport(viewport);
693 * Need to call this method when tabs are selected for multiple views, or when
694 * loading from Jalview2XML.java
699 void setMenusFromViewport(AlignViewport av)
701 padGapsMenuitem.setSelected(av.isPadGaps());
702 colourTextMenuItem.setSelected(av.showColourText);
703 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
704 conservationMenuItem.setSelected(av.getConservationSelected());
705 seqLimits.setSelected(av.getShowJVSuffix());
706 idRightAlign.setSelected(av.rightAlignIds);
707 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
708 renderGapsMenuItem.setSelected(av.renderGaps);
709 wrapMenuItem.setSelected(av.wrapAlignment);
710 scaleAbove.setVisible(av.wrapAlignment);
711 scaleLeft.setVisible(av.wrapAlignment);
712 scaleRight.setVisible(av.wrapAlignment);
713 annotationPanelMenuItem.setState(av.showAnnotation);
714 viewBoxesMenuItem.setSelected(av.showBoxes);
715 viewTextMenuItem.setSelected(av.showText);
716 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
717 showGroupConsensus.setSelected(av.isShowGroupConsensus());
718 showGroupConservation.setSelected(av.isShowGroupConservation());
719 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
720 showSequenceLogo.setSelected(av.isShowSequenceLogo());
721 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
723 setColourSelected(ColourSchemeProperty.getColourName(av
724 .getGlobalColourScheme()));
726 showSeqFeatures.setSelected(av.showSequenceFeatures);
727 hiddenMarkers.setState(av.showHiddenMarkers);
728 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
729 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
730 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
731 autoCalculate.setSelected(av.autoCalculateConsensus);
732 sortByTree.setSelected(av.sortByTree);
733 listenToViewSelections.setSelected(av.followSelection);
734 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
736 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
737 setShowProductsEnabled();
742 // methods for implementing IProgressIndicator
743 // need to refactor to a reusable stub class
744 Hashtable progressBars, progressBarHandlers;
749 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
752 public void setProgressBar(String message, long id)
754 if (progressBars == null)
756 progressBars = new Hashtable();
757 progressBarHandlers = new Hashtable();
760 JPanel progressPanel;
761 Long lId = new Long(id);
762 GridLayout layout = (GridLayout) statusPanel.getLayout();
763 if (progressBars.get(lId) != null)
765 progressPanel = (JPanel) progressBars.get(new Long(id));
766 statusPanel.remove(progressPanel);
767 progressBars.remove(lId);
768 progressPanel = null;
771 statusBar.setText(message);
773 if (progressBarHandlers.contains(lId))
775 progressBarHandlers.remove(lId);
777 layout.setRows(layout.getRows() - 1);
781 progressPanel = new JPanel(new BorderLayout(10, 5));
783 JProgressBar progressBar = new JProgressBar();
784 progressBar.setIndeterminate(true);
786 progressPanel.add(new JLabel(message), BorderLayout.WEST);
787 progressPanel.add(progressBar, BorderLayout.CENTER);
789 layout.setRows(layout.getRows() + 1);
790 statusPanel.add(progressPanel);
792 progressBars.put(lId, progressPanel);
795 // setMenusForViewport();
800 public void registerHandler(final long id,
801 final IProgressIndicatorHandler handler)
803 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
806 "call setProgressBar before registering the progress bar's handler.");
808 progressBarHandlers.put(new Long(id), handler);
809 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
810 if (handler.canCancel())
812 JButton cancel = new JButton("Cancel");
813 final IProgressIndicator us = this;
814 cancel.addActionListener(new ActionListener()
818 public void actionPerformed(ActionEvent e)
820 handler.cancelActivity(id);
823 + ((JLabel) progressPanel.getComponent(0))
827 progressPanel.add(cancel, BorderLayout.EAST);
833 * @return true if any progress bars are still active
836 public boolean operationInProgress()
838 if (progressBars != null && progressBars.size() > 0)
846 * Added so Castor Mapping file can obtain Jalview Version
848 public String getVersion()
850 return jalview.bin.Cache.getProperty("VERSION");
853 public FeatureRenderer getFeatureRenderer()
855 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
859 public void fetchSequence_actionPerformed(ActionEvent e)
861 new SequenceFetcher(this);
865 public void addFromFile_actionPerformed(ActionEvent e)
867 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
871 public void reload_actionPerformed(ActionEvent e)
873 if (fileName != null)
875 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
876 // originating file's format
877 // TODO: work out how to recover feature settings for correct view(s) when
879 if (currentFileFormat.equals("Jalview"))
881 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
882 for (int i = 0; i < frames.length; i++)
884 if (frames[i] instanceof AlignFrame && frames[i] != this
885 && ((AlignFrame) frames[i]).fileName != null
886 && ((AlignFrame) frames[i]).fileName.equals(fileName))
890 frames[i].setSelected(true);
891 Desktop.instance.closeAssociatedWindows();
892 } catch (java.beans.PropertyVetoException ex)
898 Desktop.instance.closeAssociatedWindows();
900 FileLoader loader = new FileLoader();
901 String protocol = fileName.startsWith("http:") ? "URL" : "File";
902 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
906 Rectangle bounds = this.getBounds();
908 FileLoader loader = new FileLoader();
909 String protocol = fileName.startsWith("http:") ? "URL" : "File";
910 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
911 protocol, currentFileFormat);
913 newframe.setBounds(bounds);
914 if (featureSettings != null && featureSettings.isShowing())
916 final Rectangle fspos = featureSettings.frame.getBounds();
917 // TODO: need a 'show feature settings' function that takes bounds -
918 // need to refactor Desktop.addFrame
919 newframe.featureSettings_actionPerformed(null);
920 final FeatureSettings nfs = newframe.featureSettings;
921 SwingUtilities.invokeLater(new Runnable()
926 nfs.frame.setBounds(fspos);
929 this.featureSettings.close();
930 this.featureSettings = null;
932 this.closeMenuItem_actionPerformed(true);
938 public void addFromText_actionPerformed(ActionEvent e)
940 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
944 public void addFromURL_actionPerformed(ActionEvent e)
946 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
950 public void save_actionPerformed(ActionEvent e)
953 || (currentFileFormat == null || !jalview.io.FormatAdapter
954 .isValidIOFormat(currentFileFormat, true))
955 || fileName.startsWith("http"))
957 saveAs_actionPerformed(null);
961 saveAlignment(fileName, currentFileFormat);
972 public void saveAs_actionPerformed(ActionEvent e)
974 JalviewFileChooser chooser = new JalviewFileChooser(
975 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
976 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
977 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
978 currentFileFormat, false);
980 chooser.setFileView(new JalviewFileView());
981 chooser.setDialogTitle("Save Alignment to file");
982 chooser.setToolTipText("Save");
984 int value = chooser.showSaveDialog(this);
986 if (value == JalviewFileChooser.APPROVE_OPTION)
988 currentFileFormat = chooser.getSelectedFormat();
989 if (currentFileFormat == null)
991 JOptionPane.showInternalMessageDialog(Desktop.desktop,
992 "You must select a file format before saving!",
993 "File format not specified", JOptionPane.WARNING_MESSAGE);
994 value = chooser.showSaveDialog(this);
998 fileName = chooser.getSelectedFile().getPath();
1000 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1003 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1004 if (currentFileFormat.indexOf(" ") > -1)
1006 currentFileFormat = currentFileFormat.substring(0,
1007 currentFileFormat.indexOf(" "));
1009 saveAlignment(fileName, currentFileFormat);
1013 public boolean saveAlignment(String file, String format)
1015 boolean success = true;
1017 if (format.equalsIgnoreCase("Jalview"))
1019 String shortName = title;
1021 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1023 shortName = shortName.substring(shortName
1024 .lastIndexOf(java.io.File.separatorChar) + 1);
1027 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1029 statusBar.setText("Successfully saved to file: " + fileName + " in "
1030 + format + " format.");
1035 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1037 warningMessage("Cannot save file " + fileName + " using format "
1038 + format, "Alignment output format not supported");
1039 saveAs_actionPerformed(null);
1040 // JBPNote need to have a raise_gui flag here
1044 String[] omitHidden = null;
1046 if (viewport.hasHiddenColumns())
1048 int reply = JOptionPane
1049 .showInternalConfirmDialog(
1051 "The Alignment contains hidden columns."
1052 + "\nDo you want to save only the visible alignment?",
1053 "Save / Omit Hidden Columns",
1054 JOptionPane.YES_NO_OPTION,
1055 JOptionPane.QUESTION_MESSAGE);
1057 if (reply == JOptionPane.YES_OPTION)
1059 omitHidden = viewport.getViewAsString(false);
1062 FormatAdapter f = new FormatAdapter();
1063 String output = f.formatSequences(format,
1064 viewport.getAlignment(), // class cast exceptions will
1065 // occur in the distant future
1066 omitHidden, f.getCacheSuffixDefault(format),
1067 viewport.getColumnSelection());
1077 java.io.PrintWriter out = new java.io.PrintWriter(
1078 new java.io.FileWriter(file));
1082 this.setTitle(file);
1083 statusBar.setText("Successfully saved to file: " + fileName
1084 + " in " + format + " format.");
1085 } catch (Exception ex)
1088 ex.printStackTrace();
1095 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1096 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1102 private void warningMessage(String warning, String title)
1104 if (new jalview.util.Platform().isHeadless())
1106 System.err.println("Warning: " + title + "\nWarning: " + warning);
1111 JOptionPane.showInternalMessageDialog(this, warning, title,
1112 JOptionPane.WARNING_MESSAGE);
1124 protected void outputText_actionPerformed(ActionEvent e)
1126 String[] omitHidden = null;
1128 if (viewport.hasHiddenColumns())
1130 int reply = JOptionPane
1131 .showInternalConfirmDialog(
1133 "The Alignment contains hidden columns."
1134 + "\nDo you want to output only the visible alignment?",
1135 "Save / Omit Hidden Columns",
1136 JOptionPane.YES_NO_OPTION,
1137 JOptionPane.QUESTION_MESSAGE);
1139 if (reply == JOptionPane.YES_OPTION)
1141 omitHidden = viewport.getViewAsString(false);
1145 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1146 cap.setForInput(null);
1150 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1151 viewport.getAlignment(), omitHidden,
1152 viewport.getColumnSelection()));
1153 Desktop.addInternalFrame(cap,
1154 "Alignment output - " + e.getActionCommand(), 600, 500);
1155 } catch (OutOfMemoryError oom)
1157 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1170 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1172 new HTMLOutput(alignPanel,
1173 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1174 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1177 public void createImageMap(File file, String image)
1179 alignPanel.makePNGImageMap(file, image);
1189 public void createPNG(File f)
1191 alignPanel.makePNG(f);
1201 public void createEPS(File f)
1203 alignPanel.makeEPS(f);
1207 public void pageSetup_actionPerformed(ActionEvent e)
1209 PrinterJob printJob = PrinterJob.getPrinterJob();
1210 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1220 public void printMenuItem_actionPerformed(ActionEvent e)
1222 // Putting in a thread avoids Swing painting problems
1223 PrintThread thread = new PrintThread(alignPanel);
1228 public void exportFeatures_actionPerformed(ActionEvent e)
1230 new AnnotationExporter().exportFeatures(alignPanel);
1234 public void exportAnnotations_actionPerformed(ActionEvent e)
1236 new AnnotationExporter().exportAnnotations(alignPanel,
1237 viewport.showAnnotation ? viewport.getAlignment()
1238 .getAlignmentAnnotation() : null, viewport
1239 .getAlignment().getGroups(), ((Alignment) viewport
1240 .getAlignment()).alignmentProperties);
1244 public void associatedData_actionPerformed(ActionEvent e)
1246 // Pick the tree file
1247 JalviewFileChooser chooser = new JalviewFileChooser(
1248 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1249 chooser.setFileView(new JalviewFileView());
1250 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1251 chooser.setToolTipText("Load Jalview Annotations / Features file");
1253 int value = chooser.showOpenDialog(null);
1255 if (value == JalviewFileChooser.APPROVE_OPTION)
1257 String choice = chooser.getSelectedFile().getPath();
1258 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1259 loadJalviewDataFile(choice, null, null, null);
1265 * Close the current view or all views in the alignment frame. If the frame
1266 * only contains one view then the alignment will be removed from memory.
1268 * @param closeAllTabs
1271 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1273 if (alignPanels != null && alignPanels.size() < 2)
1275 closeAllTabs = true;
1280 if (alignPanels != null)
1284 if (this.isClosed())
1286 // really close all the windows - otherwise wait till
1287 // setClosed(true) is called
1288 for (int i = 0; i < alignPanels.size(); i++)
1290 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1297 closeView(alignPanel);
1303 this.setClosed(true);
1305 } catch (Exception ex)
1307 ex.printStackTrace();
1312 * close alignPanel2 and shuffle tabs appropriately.
1314 * @param alignPanel2
1316 public void closeView(AlignmentPanel alignPanel2)
1318 int index = tabbedPane.getSelectedIndex();
1319 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1320 alignPanels.removeElement(alignPanel2);
1322 // if (viewport == alignPanel2.av)
1326 alignPanel2.closePanel();
1329 tabbedPane.removeTabAt(closedindex);
1330 tabbedPane.validate();
1332 if (index > closedindex || index == tabbedPane.getTabCount())
1334 // modify currently selected tab index if necessary.
1338 this.tabSelectionChanged(index);
1344 void updateEditMenuBar()
1347 if (viewport.historyList.size() > 0)
1349 undoMenuItem.setEnabled(true);
1350 CommandI command = (CommandI) viewport.historyList.peek();
1351 undoMenuItem.setText("Undo " + command.getDescription());
1355 undoMenuItem.setEnabled(false);
1356 undoMenuItem.setText("Undo");
1359 if (viewport.redoList.size() > 0)
1361 redoMenuItem.setEnabled(true);
1363 CommandI command = (CommandI) viewport.redoList.peek();
1364 redoMenuItem.setText("Redo " + command.getDescription());
1368 redoMenuItem.setEnabled(false);
1369 redoMenuItem.setText("Redo");
1373 public void addHistoryItem(CommandI command)
1375 if (command.getSize() > 0)
1377 viewport.historyList.push(command);
1378 viewport.redoList.clear();
1379 updateEditMenuBar();
1380 viewport.updateHiddenColumns();
1381 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1382 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1383 // viewport.getColumnSelection()
1384 // .getHiddenColumns().size() > 0);
1390 * @return alignment objects for all views
1392 AlignmentI[] getViewAlignments()
1394 if (alignPanels != null)
1396 Enumeration e = alignPanels.elements();
1397 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1398 for (int i = 0; e.hasMoreElements(); i++)
1400 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1404 if (viewport != null)
1406 return new AlignmentI[]
1407 { viewport.getAlignment() };
1419 protected void undoMenuItem_actionPerformed(ActionEvent e)
1421 if (viewport.historyList.empty())
1423 CommandI command = (CommandI) viewport.historyList.pop();
1424 viewport.redoList.push(command);
1425 command.undoCommand(getViewAlignments());
1427 AlignViewport originalSource = getOriginatingSource(command);
1428 updateEditMenuBar();
1430 if (originalSource != null)
1432 if (originalSource != viewport)
1435 .warn("Implementation worry: mismatch of viewport origin for undo");
1437 originalSource.updateHiddenColumns();
1438 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1440 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1441 // viewport.getColumnSelection()
1442 // .getHiddenColumns().size() > 0);
1443 originalSource.firePropertyChange("alignment", null, originalSource
1444 .getAlignment().getSequences());
1455 protected void redoMenuItem_actionPerformed(ActionEvent e)
1457 if (viewport.redoList.size() < 1)
1462 CommandI command = (CommandI) viewport.redoList.pop();
1463 viewport.historyList.push(command);
1464 command.doCommand(getViewAlignments());
1466 AlignViewport originalSource = getOriginatingSource(command);
1467 updateEditMenuBar();
1469 if (originalSource != null)
1472 if (originalSource != viewport)
1475 .warn("Implementation worry: mismatch of viewport origin for redo");
1477 originalSource.updateHiddenColumns();
1478 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1480 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1481 // viewport.getColumnSelection()
1482 // .getHiddenColumns().size() > 0);
1483 originalSource.firePropertyChange("alignment", null, originalSource
1484 .getAlignment().getSequences());
1488 AlignViewport getOriginatingSource(CommandI command)
1490 AlignViewport originalSource = null;
1491 // For sequence removal and addition, we need to fire
1492 // the property change event FROM the viewport where the
1493 // original alignment was altered
1494 AlignmentI al = null;
1495 if (command instanceof EditCommand)
1497 EditCommand editCommand = (EditCommand) command;
1498 al = editCommand.getAlignment();
1499 Vector comps = (Vector) PaintRefresher.components.get(viewport
1500 .getSequenceSetId());
1502 for (int i = 0; i < comps.size(); i++)
1504 if (comps.elementAt(i) instanceof AlignmentPanel)
1506 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1508 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1515 if (originalSource == null)
1517 // The original view is closed, we must validate
1518 // the current view against the closed view first
1521 PaintRefresher.validateSequences(al, viewport.getAlignment());
1524 originalSource = viewport;
1527 return originalSource;
1536 public void moveSelectedSequences(boolean up)
1538 SequenceGroup sg = viewport.getSelectionGroup();
1544 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1545 viewport.getHiddenRepSequences(), up);
1546 alignPanel.paintAlignment(true);
1549 synchronized void slideSequences(boolean right, int size)
1551 List<SequenceI> sg = new Vector();
1552 if (viewport.cursorMode)
1554 sg.add(viewport.getAlignment().getSequenceAt(
1555 alignPanel.seqPanel.seqCanvas.cursorY));
1557 else if (viewport.getSelectionGroup() != null
1558 && viewport.getSelectionGroup().getSize() != viewport
1559 .getAlignment().getHeight())
1561 sg = viewport.getSelectionGroup().getSequences(
1562 viewport.getHiddenRepSequences());
1570 Vector invertGroup = new Vector();
1572 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1574 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1575 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1578 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1580 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1581 for (int i = 0; i < invertGroup.size(); i++)
1582 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1584 SlideSequencesCommand ssc;
1586 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1587 size, viewport.getGapCharacter());
1589 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1590 size, viewport.getGapCharacter());
1592 int groupAdjustment = 0;
1593 if (ssc.getGapsInsertedBegin() && right)
1595 if (viewport.cursorMode)
1596 alignPanel.seqPanel.moveCursor(size, 0);
1598 groupAdjustment = size;
1600 else if (!ssc.getGapsInsertedBegin() && !right)
1602 if (viewport.cursorMode)
1603 alignPanel.seqPanel.moveCursor(-size, 0);
1605 groupAdjustment = -size;
1608 if (groupAdjustment != 0)
1610 viewport.getSelectionGroup().setStartRes(
1611 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1612 viewport.getSelectionGroup().setEndRes(
1613 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1616 boolean appendHistoryItem = false;
1617 if (viewport.historyList != null && viewport.historyList.size() > 0
1618 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1620 appendHistoryItem = ssc
1621 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1625 if (!appendHistoryItem)
1626 addHistoryItem(ssc);
1638 protected void copy_actionPerformed(ActionEvent e)
1641 if (viewport.getSelectionGroup() == null)
1645 // TODO: preserve the ordering of displayed alignment annotation in any
1646 // internal paste (particularly sequence associated annotation)
1647 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1648 String[] omitHidden = null;
1650 if (viewport.hasHiddenColumns())
1652 omitHidden = viewport.getViewAsString(true);
1655 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1658 StringSelection ss = new StringSelection(output);
1662 jalview.gui.Desktop.internalCopy = true;
1663 // Its really worth setting the clipboard contents
1664 // to empty before setting the large StringSelection!!
1665 Toolkit.getDefaultToolkit().getSystemClipboard()
1666 .setContents(new StringSelection(""), null);
1668 Toolkit.getDefaultToolkit().getSystemClipboard()
1669 .setContents(ss, Desktop.instance);
1670 } catch (OutOfMemoryError er)
1672 new OOMWarning("copying region", er);
1676 Vector hiddenColumns = null;
1677 if (viewport.hasHiddenColumns())
1679 hiddenColumns = new Vector();
1680 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1681 .getSelectionGroup().getEndRes();
1682 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1685 int[] region = (int[]) viewport.getColumnSelection()
1686 .getHiddenColumns().elementAt(i);
1687 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1689 hiddenColumns.addElement(new int[]
1690 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1695 Desktop.jalviewClipboard = new Object[]
1696 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1697 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1707 protected void pasteNew_actionPerformed(ActionEvent e)
1719 protected void pasteThis_actionPerformed(ActionEvent e)
1725 * Paste contents of Jalview clipboard
1727 * @param newAlignment
1728 * true to paste to a new alignment, otherwise add to this.
1730 void paste(boolean newAlignment)
1732 boolean externalPaste = true;
1735 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1736 Transferable contents = c.getContents(this);
1738 if (contents == null)
1746 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1747 if (str.length() < 1)
1752 format = new IdentifyFile().Identify(str, "Paste");
1754 } catch (OutOfMemoryError er)
1756 new OOMWarning("Out of memory pasting sequences!!", er);
1760 SequenceI[] sequences;
1761 boolean annotationAdded = false;
1762 AlignmentI alignment = null;
1764 if (Desktop.jalviewClipboard != null)
1766 // The clipboard was filled from within Jalview, we must use the
1768 // And dataset from the copied alignment
1769 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1770 // be doubly sure that we create *new* sequence objects.
1771 sequences = new SequenceI[newseq.length];
1772 for (int i = 0; i < newseq.length; i++)
1774 sequences[i] = new Sequence(newseq[i]);
1776 alignment = new Alignment(sequences);
1777 externalPaste = false;
1781 // parse the clipboard as an alignment.
1782 alignment = new FormatAdapter().readFile(str, "Paste", format);
1783 sequences = alignment.getSequencesArray();
1787 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1793 if (Desktop.jalviewClipboard != null)
1795 // dataset is inherited
1796 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1800 // new dataset is constructed
1801 alignment.setDataset(null);
1803 alwidth = alignment.getWidth() + 1;
1807 AlignmentI pastedal = alignment; // preserve pasted alignment object
1808 // Add pasted sequences and dataset into existing alignment.
1809 alignment = viewport.getAlignment();
1810 alwidth = alignment.getWidth() + 1;
1811 // decide if we need to import sequences from an existing dataset
1812 boolean importDs = Desktop.jalviewClipboard != null
1813 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1814 // importDs==true instructs us to copy over new dataset sequences from
1815 // an existing alignment
1816 Vector newDs = (importDs) ? new Vector() : null; // used to create
1817 // minimum dataset set
1819 for (int i = 0; i < sequences.length; i++)
1823 newDs.addElement(null);
1825 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1827 if (importDs && ds != null)
1829 if (!newDs.contains(ds))
1831 newDs.setElementAt(ds, i);
1832 ds = new Sequence(ds);
1833 // update with new dataset sequence
1834 sequences[i].setDatasetSequence(ds);
1838 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1843 // copy and derive new dataset sequence
1844 sequences[i] = sequences[i].deriveSequence();
1845 alignment.getDataset().addSequence(
1846 sequences[i].getDatasetSequence());
1847 // TODO: avoid creation of duplicate dataset sequences with a
1848 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1850 alignment.addSequence(sequences[i]); // merges dataset
1854 newDs.clear(); // tidy up
1856 if (alignment.getAlignmentAnnotation() != null)
1858 for (AlignmentAnnotation alan : alignment
1859 .getAlignmentAnnotation())
1861 if (alan.graphGroup > fgroup)
1863 fgroup = alan.graphGroup;
1867 if (pastedal.getAlignmentAnnotation() != null)
1869 // Add any annotation attached to alignment.
1870 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1871 for (int i = 0; i < alann.length; i++)
1873 annotationAdded = true;
1874 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1876 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1877 if (newann.graphGroup > -1)
1879 if (newGraphGroups.size() <= newann.graphGroup
1880 || newGraphGroups.get(newann.graphGroup) == null)
1882 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1884 newGraphGroups.add(q, null);
1886 newGraphGroups.set(newann.graphGroup, new Integer(
1889 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1893 newann.padAnnotation(alwidth);
1894 alignment.addAnnotation(newann);
1904 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1905 sequences, 0, alignment.getWidth(), alignment));
1907 // Add any annotations attached to sequences
1908 for (int i = 0; i < sequences.length; i++)
1910 if (sequences[i].getAnnotation() != null)
1912 AlignmentAnnotation newann;
1913 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1915 annotationAdded = true;
1916 newann = sequences[i].getAnnotation()[a];
1917 newann.adjustForAlignment();
1918 newann.padAnnotation(alwidth);
1919 if (newann.graphGroup > -1)
1921 if (newann.graphGroup > -1)
1923 if (newGraphGroups.size() <= newann.graphGroup
1924 || newGraphGroups.get(newann.graphGroup) == null)
1926 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1928 newGraphGroups.add(q, null);
1930 newGraphGroups.set(newann.graphGroup, new Integer(
1933 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1937 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1942 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1949 // propagate alignment changed.
1950 viewport.setEndSeq(alignment.getHeight());
1951 if (annotationAdded)
1953 // Duplicate sequence annotation in all views.
1954 AlignmentI[] alview = this.getViewAlignments();
1955 for (int i = 0; i < sequences.length; i++)
1957 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1960 for (int avnum = 0; avnum < alview.length; avnum++)
1962 if (alview[avnum] != alignment)
1964 // duplicate in a view other than the one with input focus
1965 int avwidth = alview[avnum].getWidth() + 1;
1966 // this relies on sann being preserved after we
1967 // modify the sequence's annotation array for each duplication
1968 for (int a = 0; a < sann.length; a++)
1970 AlignmentAnnotation newann = new AlignmentAnnotation(
1972 sequences[i].addAlignmentAnnotation(newann);
1973 newann.padAnnotation(avwidth);
1974 alview[avnum].addAnnotation(newann); // annotation was
1975 // duplicated earlier
1976 // TODO JAL-1145 graphGroups are not updated for sequence
1977 // annotation added to several views. This may cause
1979 alview[avnum].setAnnotationIndex(newann, a);
1984 buildSortByAnnotationScoresMenu();
1986 viewport.firePropertyChange("alignment", null,
1987 alignment.getSequences());
1988 if (alignPanels != null)
1990 for (AlignmentPanel ap : ((Vector<AlignmentPanel>) alignPanels))
1992 ap.validateAnnotationDimensions(false);
1997 alignPanel.validateAnnotationDimensions(false);
2003 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2005 String newtitle = new String("Copied sequences");
2007 if (Desktop.jalviewClipboard != null
2008 && Desktop.jalviewClipboard[2] != null)
2010 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2011 for (int i = 0; i < hc.size(); i++)
2013 int[] region = (int[]) hc.elementAt(i);
2014 af.viewport.hideColumns(region[0], region[1]);
2018 // >>>This is a fix for the moment, until a better solution is
2020 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2022 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2024 // TODO: maintain provenance of an alignment, rather than just make the
2025 // title a concatenation of operations.
2028 if (title.startsWith("Copied sequences"))
2034 newtitle = newtitle.concat("- from " + title);
2039 newtitle = new String("Pasted sequences");
2042 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2047 } catch (Exception ex)
2049 ex.printStackTrace();
2050 System.out.println("Exception whilst pasting: " + ex);
2051 // could be anything being pasted in here
2063 protected void cut_actionPerformed(ActionEvent e)
2065 copy_actionPerformed(null);
2066 delete_actionPerformed(null);
2076 protected void delete_actionPerformed(ActionEvent evt)
2079 SequenceGroup sg = viewport.getSelectionGroup();
2085 Vector seqs = new Vector();
2087 for (int i = 0; i < sg.getSize(); i++)
2089 seq = sg.getSequenceAt(i);
2090 seqs.addElement(seq);
2093 // If the cut affects all sequences, remove highlighted columns
2094 if (sg.getSize() == viewport.getAlignment().getHeight())
2096 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2097 sg.getEndRes() + 1);
2100 SequenceI[] cut = new SequenceI[seqs.size()];
2101 for (int i = 0; i < seqs.size(); i++)
2103 cut[i] = (SequenceI) seqs.elementAt(i);
2107 * //ADD HISTORY ITEM
2109 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2110 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2111 viewport.getAlignment()));
2113 viewport.setSelectionGroup(null);
2114 viewport.sendSelection();
2115 viewport.getAlignment().deleteGroup(sg);
2117 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2119 if (viewport.getAlignment().getHeight() < 1)
2123 this.setClosed(true);
2124 } catch (Exception ex)
2137 protected void deleteGroups_actionPerformed(ActionEvent e)
2139 viewport.getAlignment().deleteAllGroups();
2140 viewport.sequenceColours = null;
2141 viewport.setSelectionGroup(null);
2142 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2143 alignPanel.updateAnnotation();
2144 alignPanel.paintAlignment(true);
2154 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2156 SequenceGroup sg = new SequenceGroup();
2158 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2160 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2163 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2164 viewport.setSelectionGroup(sg);
2165 viewport.sendSelection();
2166 alignPanel.paintAlignment(true);
2167 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2177 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2179 if (viewport.cursorMode)
2181 alignPanel.seqPanel.keyboardNo1 = null;
2182 alignPanel.seqPanel.keyboardNo2 = null;
2184 viewport.setSelectionGroup(null);
2185 viewport.getColumnSelection().clear();
2186 viewport.setSelectionGroup(null);
2187 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2188 alignPanel.idPanel.idCanvas.searchResults = null;
2189 alignPanel.paintAlignment(true);
2190 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2191 viewport.sendSelection();
2201 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2203 SequenceGroup sg = viewport.getSelectionGroup();
2207 selectAllSequenceMenuItem_actionPerformed(null);
2212 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2214 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2217 alignPanel.paintAlignment(true);
2218 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2219 viewport.sendSelection();
2223 public void invertColSel_actionPerformed(ActionEvent e)
2225 viewport.invertColumnSelection();
2226 alignPanel.paintAlignment(true);
2227 viewport.sendSelection();
2237 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2239 trimAlignment(true);
2249 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2251 trimAlignment(false);
2254 void trimAlignment(boolean trimLeft)
2256 ColumnSelection colSel = viewport.getColumnSelection();
2259 if (colSel.size() > 0)
2263 column = colSel.getMin();
2267 column = colSel.getMax();
2271 if (viewport.getSelectionGroup() != null)
2273 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2274 viewport.getHiddenRepSequences());
2278 seqs = viewport.getAlignment().getSequencesArray();
2281 TrimRegionCommand trimRegion;
2284 trimRegion = new TrimRegionCommand("Remove Left",
2285 TrimRegionCommand.TRIM_LEFT, seqs, column,
2286 viewport.getAlignment(), viewport.getColumnSelection(),
2287 viewport.getSelectionGroup());
2288 viewport.setStartRes(0);
2292 trimRegion = new TrimRegionCommand("Remove Right",
2293 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2294 viewport.getAlignment(), viewport.getColumnSelection(),
2295 viewport.getSelectionGroup());
2298 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2300 addHistoryItem(trimRegion);
2302 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2304 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2305 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2307 viewport.getAlignment().deleteGroup(sg);
2311 viewport.firePropertyChange("alignment", null, viewport
2312 .getAlignment().getSequences());
2323 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2325 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2328 if (viewport.getSelectionGroup() != null)
2330 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2331 viewport.getHiddenRepSequences());
2332 start = viewport.getSelectionGroup().getStartRes();
2333 end = viewport.getSelectionGroup().getEndRes();
2337 seqs = viewport.getAlignment().getSequencesArray();
2340 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2341 "Remove Gapped Columns", seqs, start, end,
2342 viewport.getAlignment());
2344 addHistoryItem(removeGapCols);
2346 statusBar.setText("Removed " + removeGapCols.getSize()
2347 + " empty columns.");
2349 // This is to maintain viewport position on first residue
2350 // of first sequence
2351 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2352 int startRes = seq.findPosition(viewport.startRes);
2353 // ShiftList shifts;
2354 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2355 // edit.alColumnChanges=shifts.getInverse();
2356 // if (viewport.hasHiddenColumns)
2357 // viewport.getColumnSelection().compensateForEdits(shifts);
2358 viewport.setStartRes(seq.findIndex(startRes) - 1);
2359 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2371 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2373 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2376 if (viewport.getSelectionGroup() != null)
2378 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2379 viewport.getHiddenRepSequences());
2380 start = viewport.getSelectionGroup().getStartRes();
2381 end = viewport.getSelectionGroup().getEndRes();
2385 seqs = viewport.getAlignment().getSequencesArray();
2388 // This is to maintain viewport position on first residue
2389 // of first sequence
2390 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2391 int startRes = seq.findPosition(viewport.startRes);
2393 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2394 viewport.getAlignment()));
2396 viewport.setStartRes(seq.findIndex(startRes) - 1);
2398 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2410 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2412 viewport.setPadGaps(padGapsMenuitem.isSelected());
2413 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2419 // if (justifySeqs>0)
2421 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2434 public void findMenuItem_actionPerformed(ActionEvent e)
2440 public void newView_actionPerformed(ActionEvent e)
2447 * @param copyAnnotation
2448 * if true then duplicate all annnotation, groups and settings
2449 * @return new alignment panel, already displayed.
2451 public AlignmentPanel newView(boolean copyAnnotation)
2453 return newView(null, copyAnnotation);
2459 * title of newly created view
2460 * @return new alignment panel, already displayed.
2462 public AlignmentPanel newView(String viewTitle)
2464 return newView(viewTitle, true);
2470 * title of newly created view
2471 * @param copyAnnotation
2472 * if true then duplicate all annnotation, groups and settings
2473 * @return new alignment panel, already displayed.
2475 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2477 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2479 if (!copyAnnotation)
2481 // just remove all the current annotation except for the automatic stuff
2482 newap.av.getAlignment().deleteAllGroups();
2483 for (AlignmentAnnotation alan : newap.av.getAlignment()
2484 .getAlignmentAnnotation())
2486 if (!alan.autoCalculated)
2488 newap.av.getAlignment().deleteAnnotation(alan);
2494 newap.av.gatherViewsHere = false;
2496 if (viewport.viewName == null)
2498 viewport.viewName = "Original";
2501 newap.av.historyList = viewport.historyList;
2502 newap.av.redoList = viewport.redoList;
2504 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2505 // make sure the new view has a unique name - this is essential for Jalview
2507 boolean addFirstIndex = false;
2508 if (viewTitle == null || viewTitle.trim().length() == 0)
2511 addFirstIndex = true;
2515 index = 1;// we count from 1 if given a specific name
2517 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2518 Vector comps = (Vector) PaintRefresher.components.get(viewport
2519 .getSequenceSetId());
2520 Vector existingNames = new Vector();
2521 for (int i = 0; i < comps.size(); i++)
2523 if (comps.elementAt(i) instanceof AlignmentPanel)
2525 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2526 if (!existingNames.contains(ap.av.viewName))
2528 existingNames.addElement(ap.av.viewName);
2533 while (existingNames.contains(newViewName))
2535 newViewName = viewTitle + " " + (++index);
2538 newap.av.viewName = newViewName;
2540 addAlignmentPanel(newap, true);
2542 if (alignPanels.size() == 2)
2544 viewport.gatherViewsHere = true;
2546 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2551 public void expandViews_actionPerformed(ActionEvent e)
2553 Desktop.instance.explodeViews(this);
2557 public void gatherViews_actionPerformed(ActionEvent e)
2559 Desktop.instance.gatherViews(this);
2569 public void font_actionPerformed(ActionEvent e)
2571 new FontChooser(alignPanel);
2581 protected void seqLimit_actionPerformed(ActionEvent e)
2583 viewport.setShowJVSuffix(seqLimits.isSelected());
2585 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2586 .calculateIdWidth());
2587 alignPanel.paintAlignment(true);
2591 public void idRightAlign_actionPerformed(ActionEvent e)
2593 viewport.rightAlignIds = idRightAlign.isSelected();
2594 alignPanel.paintAlignment(true);
2598 public void centreColumnLabels_actionPerformed(ActionEvent e)
2600 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2601 alignPanel.paintAlignment(true);
2607 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2610 protected void followHighlight_actionPerformed()
2612 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2614 alignPanel.scrollToPosition(
2615 alignPanel.seqPanel.seqCanvas.searchResults, false);
2626 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2628 viewport.setColourText(colourTextMenuItem.isSelected());
2629 alignPanel.paintAlignment(true);
2639 public void wrapMenuItem_actionPerformed(ActionEvent e)
2641 scaleAbove.setVisible(wrapMenuItem.isSelected());
2642 scaleLeft.setVisible(wrapMenuItem.isSelected());
2643 scaleRight.setVisible(wrapMenuItem.isSelected());
2644 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2645 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2649 public void showAllSeqs_actionPerformed(ActionEvent e)
2651 viewport.showAllHiddenSeqs();
2655 public void showAllColumns_actionPerformed(ActionEvent e)
2657 viewport.showAllHiddenColumns();
2662 public void hideSelSequences_actionPerformed(ActionEvent e)
2664 viewport.hideAllSelectedSeqs();
2665 alignPanel.paintAlignment(true);
2669 * called by key handler and the hide all/show all menu items
2674 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2677 boolean hide = false;
2678 SequenceGroup sg = viewport.getSelectionGroup();
2679 if (!toggleSeqs && !toggleCols)
2681 // Hide everything by the current selection - this is a hack - we do the
2682 // invert and then hide
2683 // first check that there will be visible columns after the invert.
2684 if ((viewport.getColumnSelection() != null
2685 && viewport.getColumnSelection().getSelected() != null && viewport
2686 .getColumnSelection().getSelected().size() > 0)
2687 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2690 // now invert the sequence set, if required - empty selection implies
2691 // that no hiding is required.
2694 invertSequenceMenuItem_actionPerformed(null);
2695 sg = viewport.getSelectionGroup();
2699 viewport.expandColSelection(sg, true);
2700 // finally invert the column selection and get the new sequence
2702 invertColSel_actionPerformed(null);
2709 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2711 hideSelSequences_actionPerformed(null);
2714 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2717 showAllSeqs_actionPerformed(null);
2723 if (viewport.getColumnSelection().getSelected().size() > 0)
2725 hideSelColumns_actionPerformed(null);
2728 viewport.setSelectionGroup(sg);
2733 showAllColumns_actionPerformed(null);
2742 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2743 * event.ActionEvent)
2746 public void hideAllButSelection_actionPerformed(ActionEvent e)
2748 toggleHiddenRegions(false, false);
2755 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2759 public void hideAllSelection_actionPerformed(ActionEvent e)
2761 SequenceGroup sg = viewport.getSelectionGroup();
2762 viewport.expandColSelection(sg, false);
2763 viewport.hideAllSelectedSeqs();
2764 viewport.hideSelectedColumns();
2765 alignPanel.paintAlignment(true);
2772 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2776 public void showAllhidden_actionPerformed(ActionEvent e)
2778 viewport.showAllHiddenColumns();
2779 viewport.showAllHiddenSeqs();
2780 alignPanel.paintAlignment(true);
2784 public void hideSelColumns_actionPerformed(ActionEvent e)
2786 viewport.hideSelectedColumns();
2787 alignPanel.paintAlignment(true);
2791 public void hiddenMarkers_actionPerformed(ActionEvent e)
2793 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2804 protected void scaleAbove_actionPerformed(ActionEvent e)
2806 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2807 alignPanel.paintAlignment(true);
2817 protected void scaleLeft_actionPerformed(ActionEvent e)
2819 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2820 alignPanel.paintAlignment(true);
2830 protected void scaleRight_actionPerformed(ActionEvent e)
2832 viewport.setScaleRightWrapped(scaleRight.isSelected());
2833 alignPanel.paintAlignment(true);
2843 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2845 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2846 alignPanel.paintAlignment(true);
2856 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2858 viewport.setShowText(viewTextMenuItem.isSelected());
2859 alignPanel.paintAlignment(true);
2869 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2871 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2872 alignPanel.paintAlignment(true);
2875 public FeatureSettings featureSettings;
2878 public void featureSettings_actionPerformed(ActionEvent e)
2880 if (featureSettings != null)
2882 featureSettings.close();
2883 featureSettings = null;
2885 if (!showSeqFeatures.isSelected())
2887 // make sure features are actually displayed
2888 showSeqFeatures.setSelected(true);
2889 showSeqFeatures_actionPerformed(null);
2891 featureSettings = new FeatureSettings(this);
2895 * Set or clear 'Show Sequence Features'
2901 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2903 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2904 alignPanel.paintAlignment(true);
2905 if (alignPanel.getOverviewPanel() != null)
2907 alignPanel.getOverviewPanel().updateOverviewImage();
2912 * Set or clear 'Show Sequence Features'
2918 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2920 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2922 if (viewport.getShowSequenceFeaturesHeight())
2924 // ensure we're actually displaying features
2925 viewport.setShowSequenceFeatures(true);
2926 showSeqFeatures.setSelected(true);
2928 alignPanel.paintAlignment(true);
2929 if (alignPanel.getOverviewPanel() != null)
2931 alignPanel.getOverviewPanel().updateOverviewImage();
2942 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2944 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2945 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2949 public void alignmentProperties()
2951 JEditorPane editPane = new JEditorPane("text/html", "");
2952 editPane.setEditable(false);
2953 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2955 editPane.setText("<html>" + contents.toString() + "</html>");
2956 JInternalFrame frame = new JInternalFrame();
2957 frame.getContentPane().add(new JScrollPane(editPane));
2959 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2960 + getTitle(), 500, 400);
2970 public void overviewMenuItem_actionPerformed(ActionEvent e)
2972 if (alignPanel.overviewPanel != null)
2977 JInternalFrame frame = new JInternalFrame();
2978 OverviewPanel overview = new OverviewPanel(alignPanel);
2979 frame.setContentPane(overview);
2980 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2981 frame.getWidth(), frame.getHeight());
2983 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2984 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2987 public void internalFrameClosed(
2988 javax.swing.event.InternalFrameEvent evt)
2990 alignPanel.setOverviewPanel(null);
2994 alignPanel.setOverviewPanel(overview);
2998 public void textColour_actionPerformed(ActionEvent e)
3000 new TextColourChooser().chooseColour(alignPanel, null);
3010 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3022 public void clustalColour_actionPerformed(ActionEvent e)
3024 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3025 viewport.getHiddenRepSequences()));
3035 public void zappoColour_actionPerformed(ActionEvent e)
3037 changeColour(new ZappoColourScheme());
3047 public void taylorColour_actionPerformed(ActionEvent e)
3049 changeColour(new TaylorColourScheme());
3059 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3061 changeColour(new HydrophobicColourScheme());
3071 public void helixColour_actionPerformed(ActionEvent e)
3073 changeColour(new HelixColourScheme());
3083 public void strandColour_actionPerformed(ActionEvent e)
3085 changeColour(new StrandColourScheme());
3095 public void turnColour_actionPerformed(ActionEvent e)
3097 changeColour(new TurnColourScheme());
3107 public void buriedColour_actionPerformed(ActionEvent e)
3109 changeColour(new BuriedColourScheme());
3119 public void nucleotideColour_actionPerformed(ActionEvent e)
3121 changeColour(new NucleotideColourScheme());
3125 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3127 changeColour(new PurinePyrimidineColourScheme());
3131 * public void covariationColour_actionPerformed(ActionEvent e) {
3133 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3137 public void annotationColour_actionPerformed(ActionEvent e)
3139 new AnnotationColourChooser(viewport, alignPanel);
3143 public void rnahelicesColour_actionPerformed(ActionEvent e)
3145 new RNAHelicesColourChooser(viewport, alignPanel);
3155 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3157 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3166 public void changeColour(ColourSchemeI cs)
3168 // TODO: compare with applet and pull up to model method
3173 if (viewport.getAbovePIDThreshold())
3175 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3178 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3180 viewport.setGlobalColourScheme(cs);
3184 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3187 if (viewport.getConservationSelected())
3190 Alignment al = (Alignment) viewport.getAlignment();
3191 Conservation c = new Conservation("All",
3192 ResidueProperties.propHash, 3, al.getSequences(), 0,
3196 c.verdict(false, viewport.getConsPercGaps());
3198 cs.setConservation(c);
3200 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3205 cs.setConservation(null);
3208 cs.setConsensus(viewport.getSequenceConsensusHash());
3211 viewport.setGlobalColourScheme(cs);
3213 if (viewport.getColourAppliesToAllGroups())
3216 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3224 if (cs instanceof ClustalxColourScheme)
3226 sg.cs = new ClustalxColourScheme(sg,
3227 viewport.getHiddenRepSequences());
3229 else if (cs instanceof UserColourScheme)
3231 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3237 sg.cs = cs.getClass().newInstance();
3238 } catch (Exception ex)
3243 if (viewport.getAbovePIDThreshold()
3244 || cs instanceof PIDColourScheme
3245 || cs instanceof Blosum62ColourScheme)
3247 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3249 sg.cs.setConsensus(AAFrequency.calculate(
3250 sg.getSequences(viewport.getHiddenRepSequences()),
3251 sg.getStartRes(), sg.getEndRes() + 1));
3255 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3258 if (viewport.getConservationSelected())
3260 Conservation c = new Conservation("Group",
3261 ResidueProperties.propHash, 3, sg.getSequences(viewport
3262 .getHiddenRepSequences()), sg.getStartRes(),
3263 sg.getEndRes() + 1);
3265 c.verdict(false, viewport.getConsPercGaps());
3266 sg.cs.setConservation(c);
3270 sg.cs.setConservation(null);
3275 if (alignPanel.getOverviewPanel() != null)
3277 alignPanel.getOverviewPanel().updateOverviewImage();
3280 alignPanel.paintAlignment(true);
3290 protected void modifyPID_actionPerformed(ActionEvent e)
3292 if (viewport.getAbovePIDThreshold()
3293 && viewport.getGlobalColourScheme() != null)
3295 SliderPanel.setPIDSliderSource(alignPanel,
3296 viewport.getGlobalColourScheme(), "Background");
3297 SliderPanel.showPIDSlider();
3308 protected void modifyConservation_actionPerformed(ActionEvent e)
3310 if (viewport.getConservationSelected()
3311 && viewport.getGlobalColourScheme() != null)
3313 SliderPanel.setConservationSlider(alignPanel,
3314 viewport.getGlobalColourScheme(), "Background");
3315 SliderPanel.showConservationSlider();
3326 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3328 viewport.setConservationSelected(conservationMenuItem.isSelected());
3330 viewport.setAbovePIDThreshold(false);
3331 abovePIDThreshold.setSelected(false);
3333 changeColour(viewport.getGlobalColourScheme());
3335 modifyConservation_actionPerformed(null);
3345 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3347 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3349 conservationMenuItem.setSelected(false);
3350 viewport.setConservationSelected(false);
3352 changeColour(viewport.getGlobalColourScheme());
3354 modifyPID_actionPerformed(null);
3364 public void userDefinedColour_actionPerformed(ActionEvent e)
3366 if (e.getActionCommand().equals("User Defined..."))
3368 new UserDefinedColours(alignPanel, null);
3372 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3373 .getUserColourSchemes().get(e.getActionCommand());
3379 public void updateUserColourMenu()
3382 Component[] menuItems = colourMenu.getMenuComponents();
3383 int i, iSize = menuItems.length;
3384 for (i = 0; i < iSize; i++)
3386 if (menuItems[i].getName() != null
3387 && menuItems[i].getName().equals("USER_DEFINED"))
3389 colourMenu.remove(menuItems[i]);
3393 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3395 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3396 .getUserColourSchemes().keys();
3398 while (userColours.hasMoreElements())
3400 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3401 userColours.nextElement().toString());
3402 radioItem.setName("USER_DEFINED");
3403 radioItem.addMouseListener(new MouseAdapter()
3406 public void mousePressed(MouseEvent evt)
3408 if (evt.isControlDown()
3409 || SwingUtilities.isRightMouseButton(evt))
3411 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3413 int option = JOptionPane.showInternalConfirmDialog(
3414 jalview.gui.Desktop.desktop,
3415 "Remove from default list?",
3416 "Remove user defined colour",
3417 JOptionPane.YES_NO_OPTION);
3418 if (option == JOptionPane.YES_OPTION)
3420 jalview.gui.UserDefinedColours
3421 .removeColourFromDefaults(radioItem.getText());
3422 colourMenu.remove(radioItem);
3426 radioItem.addActionListener(new ActionListener()
3429 public void actionPerformed(ActionEvent evt)
3431 userDefinedColour_actionPerformed(evt);
3438 radioItem.addActionListener(new ActionListener()
3441 public void actionPerformed(ActionEvent evt)
3443 userDefinedColour_actionPerformed(evt);
3447 colourMenu.insert(radioItem, 15);
3448 colours.add(radioItem);
3460 public void PIDColour_actionPerformed(ActionEvent e)
3462 changeColour(new PIDColourScheme());
3472 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3474 changeColour(new Blosum62ColourScheme());
3484 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3486 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3487 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3488 .getAlignment().getSequenceAt(0), null);
3489 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3490 viewport.getAlignment()));
3491 alignPanel.paintAlignment(true);
3501 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3503 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3504 AlignmentSorter.sortByID(viewport.getAlignment());
3505 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3506 viewport.getAlignment()));
3507 alignPanel.paintAlignment(true);
3517 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3519 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3520 AlignmentSorter.sortByLength(viewport.getAlignment());
3521 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3522 viewport.getAlignment()));
3523 alignPanel.paintAlignment(true);
3533 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3535 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3536 AlignmentSorter.sortByGroup(viewport.getAlignment());
3537 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3538 viewport.getAlignment()));
3540 alignPanel.paintAlignment(true);
3550 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3552 new RedundancyPanel(alignPanel, this);
3562 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3564 if ((viewport.getSelectionGroup() == null)
3565 || (viewport.getSelectionGroup().getSize() < 2))
3567 JOptionPane.showInternalMessageDialog(this,
3568 "You must select at least 2 sequences.", "Invalid Selection",
3569 JOptionPane.WARNING_MESSAGE);
3573 JInternalFrame frame = new JInternalFrame();
3574 frame.setContentPane(new PairwiseAlignPanel(viewport));
3575 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3586 public void PCAMenuItem_actionPerformed(ActionEvent e)
3588 if (((viewport.getSelectionGroup() != null)
3589 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3590 .getSelectionGroup().getSize() > 0))
3591 || (viewport.getAlignment().getHeight() < 4))
3593 JOptionPane.showInternalMessageDialog(this,
3594 "Principal component analysis must take\n"
3595 + "at least 4 input sequences.",
3596 "Sequence selection insufficient",
3597 JOptionPane.WARNING_MESSAGE);
3602 new PCAPanel(alignPanel);
3606 public void autoCalculate_actionPerformed(ActionEvent e)
3608 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3609 if (viewport.autoCalculateConsensus)
3611 viewport.firePropertyChange("alignment", null, viewport
3612 .getAlignment().getSequences());
3617 public void sortByTreeOption_actionPerformed(ActionEvent e)
3619 viewport.sortByTree = sortByTree.isSelected();
3623 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3625 viewport.followSelection = listenToViewSelections.isSelected();
3635 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3637 NewTreePanel("AV", "PID", "Average distance tree using PID");
3647 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3649 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3659 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3661 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3671 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3673 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3686 void NewTreePanel(String type, String pwType, String title)
3690 if (viewport.getSelectionGroup() != null
3691 && viewport.getSelectionGroup().getSize() > 0)
3693 if (viewport.getSelectionGroup().getSize() < 3)
3698 "You need to have more than two sequences selected to build a tree!",
3699 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3703 SequenceGroup sg = viewport.getSelectionGroup();
3705 /* Decide if the selection is a column region */
3706 for (SequenceI _s : sg.getSequences())
3708 if (_s.getLength() < sg.getEndRes())
3713 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3714 + "Try using the Pad function in the edit menu,\n"
3715 + "or one of the multiple sequence alignment web services.",
3716 "Sequences in selection are not aligned",
3717 JOptionPane.WARNING_MESSAGE);
3723 title = title + " on region";
3724 tp = new TreePanel(alignPanel, type, pwType);
3728 // are the visible sequences aligned?
3729 if (!viewport.getAlignment().isAligned(false))
3734 "The sequences must be aligned before creating a tree.\n"
3735 + "Try using the Pad function in the edit menu,\n"
3736 + "or one of the multiple sequence alignment web services.",
3737 "Sequences not aligned",
3738 JOptionPane.WARNING_MESSAGE);
3743 if (viewport.getAlignment().getHeight() < 2)
3748 tp = new TreePanel(alignPanel, type, pwType);
3753 if (viewport.viewName != null)
3755 title += viewport.viewName + " of ";
3758 title += this.title;
3760 Desktop.addInternalFrame(tp, title, 600, 500);
3771 public void addSortByOrderMenuItem(String title,
3772 final AlignmentOrder order)
3774 final JMenuItem item = new JMenuItem("by " + title);
3776 item.addActionListener(new java.awt.event.ActionListener()
3779 public void actionPerformed(ActionEvent e)
3781 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3783 // TODO: JBPNote - have to map order entries to curent SequenceI
3785 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3787 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3790 alignPanel.paintAlignment(true);
3796 * Add a new sort by annotation score menu item
3799 * the menu to add the option to
3801 * the label used to retrieve scores for each sequence on the
3804 public void addSortByAnnotScoreMenuItem(JMenu sort,
3805 final String scoreLabel)
3807 final JMenuItem item = new JMenuItem(scoreLabel);
3809 item.addActionListener(new java.awt.event.ActionListener()
3812 public void actionPerformed(ActionEvent e)
3814 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3815 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3816 viewport.getAlignment());// ,viewport.getSelectionGroup());
3817 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3818 viewport.getAlignment()));
3819 alignPanel.paintAlignment(true);
3825 * last hash for alignment's annotation array - used to minimise cost of
3828 protected int _annotationScoreVectorHash;
3831 * search the alignment and rebuild the sort by annotation score submenu the
3832 * last alignment annotation vector hash is stored to minimize cost of
3833 * rebuilding in subsequence calls.
3837 public void buildSortByAnnotationScoresMenu()
3839 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3844 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3846 sortByAnnotScore.removeAll();
3847 // almost certainly a quicker way to do this - but we keep it simple
3848 Hashtable scoreSorts = new Hashtable();
3849 AlignmentAnnotation aann[];
3850 for (SequenceI sqa : viewport.getAlignment().getSequences())
3852 aann = sqa.getAnnotation();
3853 for (int i = 0; aann != null && i < aann.length; i++)
3855 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3857 scoreSorts.put(aann[i].label, aann[i].label);
3861 Enumeration labels = scoreSorts.keys();
3862 while (labels.hasMoreElements())
3864 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3865 (String) labels.nextElement());
3867 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3870 _annotationScoreVectorHash = viewport.getAlignment()
3871 .getAlignmentAnnotation().hashCode();
3876 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3877 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3878 * call. Listeners are added to remove the menu item when the treePanel is
3879 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3883 * Displayed tree window.
3885 * SortBy menu item title.
3888 public void buildTreeMenu()
3890 sortByTreeMenu.removeAll();
3892 Vector comps = (Vector) PaintRefresher.components.get(viewport
3893 .getSequenceSetId());
3894 Vector treePanels = new Vector();
3895 int i, iSize = comps.size();
3896 for (i = 0; i < iSize; i++)
3898 if (comps.elementAt(i) instanceof TreePanel)
3900 treePanels.add(comps.elementAt(i));
3904 iSize = treePanels.size();
3908 sortByTreeMenu.setVisible(false);
3912 sortByTreeMenu.setVisible(true);
3914 for (i = 0; i < treePanels.size(); i++)
3916 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3917 final JMenuItem item = new JMenuItem(tp.getTitle());
3918 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3919 item.addActionListener(new java.awt.event.ActionListener()
3922 public void actionPerformed(ActionEvent e)
3924 tp.sortByTree_actionPerformed(null);
3925 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3930 sortByTreeMenu.add(item);
3934 public boolean sortBy(AlignmentOrder alorder, String undoname)
3936 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3937 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3938 if (undoname != null)
3940 addHistoryItem(new OrderCommand(undoname, oldOrder,
3941 viewport.getAlignment()));
3943 alignPanel.paintAlignment(true);
3948 * Work out whether the whole set of sequences or just the selected set will
3949 * be submitted for multiple alignment.
3952 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3954 // Now, check we have enough sequences
3955 AlignmentView msa = null;
3957 if ((viewport.getSelectionGroup() != null)
3958 && (viewport.getSelectionGroup().getSize() > 1))
3960 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3961 // some common interface!
3963 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3964 * SequenceI[sz = seqs.getSize(false)];
3966 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3967 * seqs.getSequenceAt(i); }
3969 msa = viewport.getAlignmentView(true);
3974 * Vector seqs = viewport.getAlignment().getSequences();
3976 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3978 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3979 * seqs.elementAt(i); } }
3981 msa = viewport.getAlignmentView(false);
3987 * Decides what is submitted to a secondary structure prediction service: the
3988 * first sequence in the alignment, or in the current selection, or, if the
3989 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3990 * region or the whole alignment. (where the first sequence in the set is the
3991 * one that the prediction will be for).
3993 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3995 AlignmentView seqs = null;
3997 if ((viewport.getSelectionGroup() != null)
3998 && (viewport.getSelectionGroup().getSize() > 0))
4000 seqs = viewport.getAlignmentView(true);
4004 seqs = viewport.getAlignmentView(false);
4006 // limit sequences - JBPNote in future - could spawn multiple prediction
4008 // TODO: viewport.getAlignment().isAligned is a global state - the local
4009 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4010 if (!viewport.getAlignment().isAligned(false))
4012 seqs.setSequences(new SeqCigar[]
4013 { seqs.getSequences()[0] });
4014 // TODO: if seqs.getSequences().length>1 then should really have warned
4028 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4030 // Pick the tree file
4031 JalviewFileChooser chooser = new JalviewFileChooser(
4032 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4033 chooser.setFileView(new JalviewFileView());
4034 chooser.setDialogTitle("Select a newick-like tree file");
4035 chooser.setToolTipText("Load a tree file");
4037 int value = chooser.showOpenDialog(null);
4039 if (value == JalviewFileChooser.APPROVE_OPTION)
4041 String choice = chooser.getSelectedFile().getPath();
4042 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4043 jalview.io.NewickFile fin = null;
4046 fin = new jalview.io.NewickFile(choice, "File");
4047 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4048 } catch (Exception ex)
4050 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4051 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
4052 ex.printStackTrace();
4054 if (fin != null && fin.hasWarningMessage())
4056 JOptionPane.showMessageDialog(Desktop.desktop,
4057 fin.getWarningMessage(), "Possible problem with tree file",
4058 JOptionPane.WARNING_MESSAGE);
4064 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4066 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4069 public TreePanel ShowNewickTree(NewickFile nf, String title)
4071 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4074 public TreePanel ShowNewickTree(NewickFile nf, String title,
4075 AlignmentView input)
4077 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4080 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4081 int h, int x, int y)
4083 return ShowNewickTree(nf, title, null, w, h, x, y);
4087 * Add a treeviewer for the tree extracted from a newick file object to the
4088 * current alignment view
4095 * Associated alignment input data (or null)
4104 * @return TreePanel handle
4106 public TreePanel ShowNewickTree(NewickFile nf, String title,
4107 AlignmentView input, int w, int h, int x, int y)
4109 TreePanel tp = null;
4115 if (nf.getTree() != null)
4117 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4123 tp.setLocation(x, y);
4126 Desktop.addInternalFrame(tp, title, w, h);
4128 } catch (Exception ex)
4130 ex.printStackTrace();
4136 private boolean buildingMenu = false;
4139 * Generates menu items and listener event actions for web service clients
4142 public void BuildWebServiceMenu()
4144 while (buildingMenu)
4148 System.err.println("Waiting for building menu to finish.");
4150 } catch (Exception e)
4155 final AlignFrame me = this;
4156 buildingMenu = true;
4157 new Thread(new Runnable()
4164 System.err.println("Building ws menu again "
4165 + Thread.currentThread());
4166 // TODO: add support for context dependent disabling of services based
4168 // alignment and current selection
4169 // TODO: add additional serviceHandle parameter to specify abstract
4171 // class independently of AbstractName
4172 // TODO: add in rediscovery GUI function to restart discoverer
4173 // TODO: group services by location as well as function and/or
4175 // object broker mechanism.
4176 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4177 final IProgressIndicator af = me;
4178 final JMenu msawsmenu = new JMenu("Alignment");
4179 final JMenu secstrmenu = new JMenu(
4180 "Secondary Structure Prediction");
4181 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4182 final JMenu analymenu = new JMenu("Analysis");
4183 final JMenu dismenu = new JMenu("Protein Disorder");
4184 // JAL-940 - only show secondary structure prediction services from
4185 // the legacy server
4186 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4188 Discoverer.services != null && (Discoverer.services.size() > 0))
4190 // TODO: refactor to allow list of AbstractName/Handler bindings to
4192 // stored or retrieved from elsewhere
4193 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4194 Vector secstrpr = (Vector) Discoverer.services
4196 Vector seqsrch = null; // (Vector)
4197 // Discoverer.services.get("SeqSearch");
4198 // TODO: move GUI generation code onto service implementation - so a
4199 // client instance attaches itself to the GUI with method call like
4200 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4204 // Add any Multiple Sequence Alignment Services
4205 for (int i = 0, j = msaws.size(); i < j; i++)
4207 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4209 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4210 .getServiceClient(sh);
4211 impl.attachWSMenuEntry(msawsmenu, me);
4215 if (secstrpr != null)
4217 // Add any secondary structure prediction services
4218 for (int i = 0, j = secstrpr.size(); i < j; i++)
4220 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4222 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4223 .getServiceClient(sh);
4224 impl.attachWSMenuEntry(secstrmenu, me);
4227 if (seqsrch != null)
4229 // Add any sequence search services
4230 for (int i = 0, j = seqsrch.size(); i < j; i++)
4232 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4234 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4235 .getServiceClient(sh);
4236 impl.attachWSMenuEntry(seqsrchmenu, me);
4241 // Add all submenus in the order they should appear on the web
4243 wsmenu.add(msawsmenu);
4244 wsmenu.add(secstrmenu);
4245 wsmenu.add(dismenu);
4246 wsmenu.add(analymenu);
4247 // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
4248 // submens.add(msawsmenu);
4249 // submens.add(secstrmenu);
4250 // submens.add(dismenu);
4251 // submens.add(analymenu);
4253 // No search services yet
4254 // wsmenu.add(seqsrchmenu);
4256 javax.swing.SwingUtilities.invokeLater(new Runnable()
4263 webService.removeAll();
4264 // first, add discovered services onto the webservices menu
4265 if (wsmenu.size() > 0)
4267 for (int i = 0, j = wsmenu.size(); i < j; i++)
4269 webService.add(wsmenu.get(i));
4274 webService.add(me.webServiceNoServices);
4276 // TODO: move into separate menu builder class.
4277 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4279 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4280 if (jws2servs != null)
4282 if (jws2servs.hasServices())
4284 jws2servs.attachWSMenuEntry(webService, me);
4286 if (jws2servs.isRunning())
4288 JMenuItem tm = new JMenuItem(
4289 "Still discovering JABA Services");
4290 tm.setEnabled(false);
4296 build_urlServiceMenu(me.webService);
4297 build_fetchdbmenu(webService);
4298 for (JMenu item : wsmenu)
4300 if (item.getItemCount() == 0)
4302 item.setEnabled(false);
4306 item.setEnabled(true);
4309 } catch (Exception e)
4312 .debug("Exception during web service menu building process.",
4318 } catch (Exception e)
4323 buildingMenu = false;
4330 * construct any groupURL type service menu entries.
4334 private void build_urlServiceMenu(JMenu webService)
4336 // TODO: remove this code when 2.7 is released
4337 // DEBUG - alignmentView
4339 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4340 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4342 * @Override public void actionPerformed(ActionEvent e) {
4343 * jalview.datamodel.AlignmentView
4344 * .testSelectionViews(af.viewport.getAlignment(),
4345 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4347 * }); webService.add(testAlView);
4349 // TODO: refactor to RestClient discoverer and merge menu entries for
4350 // rest-style services with other types of analysis/calculation service
4351 // SHmmr test client - still being implemented.
4352 // DEBUG - alignmentView
4354 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4357 client.attachWSMenuEntry(
4358 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4362 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4364 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4370 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4371 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4372 * getProperty("LAST_DIRECTORY"));
4374 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4375 * to Vamsas file"); chooser.setToolTipText("Export");
4377 * int value = chooser.showSaveDialog(this);
4379 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4380 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4381 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4382 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4385 * prototype of an automatically enabled/disabled analysis function
4388 protected void setShowProductsEnabled()
4390 SequenceI[] selection = viewport.getSequenceSelection();
4391 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4392 viewport.getAlignment().getDataset()))
4394 showProducts.setEnabled(true);
4399 showProducts.setEnabled(false);
4404 * search selection for sequence xRef products and build the show products
4409 * @return true if showProducts menu should be enabled.
4411 public boolean canShowProducts(SequenceI[] selection,
4412 boolean isRegionSelection, Alignment dataset)
4414 boolean showp = false;
4417 showProducts.removeAll();
4418 final boolean dna = viewport.getAlignment().isNucleotide();
4419 final Alignment ds = dataset;
4420 String[] ptypes = (selection == null || selection.length == 0) ? null
4421 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4423 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4424 // selection, dataset, true);
4425 final SequenceI[] sel = selection;
4426 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4429 final boolean isRegSel = isRegionSelection;
4430 final AlignFrame af = this;
4431 final String source = ptypes[t];
4432 JMenuItem xtype = new JMenuItem(ptypes[t]);
4433 xtype.addActionListener(new ActionListener()
4437 public void actionPerformed(ActionEvent e)
4439 // TODO: new thread for this call with vis-delay
4440 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4441 isRegSel, dna, source);
4445 showProducts.add(xtype);
4447 showProducts.setVisible(showp);
4448 showProducts.setEnabled(showp);
4449 } catch (Exception e)
4451 jalview.bin.Cache.log
4452 .warn("canTranslate threw an exception - please report to help@jalview.org",
4459 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4460 boolean isRegSel, boolean dna, String source)
4462 final boolean fisRegSel = isRegSel;
4463 final boolean fdna = dna;
4464 final String fsrc = source;
4465 final AlignFrame ths = this;
4466 final SequenceI[] fsel = sel;
4467 Runnable foo = new Runnable()
4473 final long sttime = System.currentTimeMillis();
4474 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4477 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4481 Alignment prods = CrossRef
4482 .findXrefSequences(fsel, fdna, fsrc, ds);
4485 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4486 for (int s = 0; s < sprods.length; s++)
4488 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4489 if (ds.getSequences() == null
4490 || !ds.getSequences().contains(
4491 sprods[s].getDatasetSequence()))
4492 ds.addSequence(sprods[s].getDatasetSequence());
4493 sprods[s].updatePDBIds();
4495 Alignment al = new Alignment(sprods);
4496 AlignedCodonFrame[] cf = prods.getCodonFrames();
4498 for (int s = 0; cf != null && s < cf.length; s++)
4500 al.addCodonFrame(cf[s]);
4503 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4505 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4506 + " for " + ((fisRegSel) ? "selected region of " : "")
4508 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4513 System.err.println("No Sequences generated for xRef type "
4516 } catch (Exception e)
4518 jalview.bin.Cache.log.error(
4519 "Exception when finding crossreferences", e);
4520 } catch (OutOfMemoryError e)
4522 new OOMWarning("whilst fetching crossreferences", e);
4525 jalview.bin.Cache.log.error("Error when finding crossreferences",
4528 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4533 Thread frunner = new Thread(foo);
4537 public boolean canShowTranslationProducts(SequenceI[] selection,
4538 AlignmentI alignment)
4543 return (jalview.analysis.Dna.canTranslate(selection,
4544 viewport.getViewAsVisibleContigs(true)));
4545 } catch (Exception e)
4547 jalview.bin.Cache.log
4548 .warn("canTranslate threw an exception - please report to help@jalview.org",
4555 public void showProducts_actionPerformed(ActionEvent e)
4557 // /////////////////////////////
4558 // Collect Data to be translated/transferred
4560 SequenceI[] selection = viewport.getSequenceSelection();
4561 AlignmentI al = null;
4564 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4565 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4566 viewport.getAlignment().getDataset());
4567 } catch (Exception ex)
4570 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4577 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4578 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4582 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4583 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4584 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4589 public void showTranslation_actionPerformed(ActionEvent e)
4591 // /////////////////////////////
4592 // Collect Data to be translated/transferred
4594 SequenceI[] selection = viewport.getSequenceSelection();
4595 String[] seqstring = viewport.getViewAsString(true);
4596 AlignmentI al = null;
4599 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4600 viewport.getViewAsVisibleContigs(true), viewport
4601 .getGapCharacter(), viewport.getAlignment()
4602 .getAlignmentAnnotation(), viewport.getAlignment()
4603 .getWidth(), viewport.getAlignment().getDataset());
4604 } catch (Exception ex)
4607 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4611 "Unfortunately, something went wrong when translating your sequences.\nPlease take a look in the Jalview java console\nand submit a bug report including the stacktrace.",
4612 "Implementation error: Translation Failed", JOptionPane.ERROR_MESSAGE);
4620 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4621 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4625 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4626 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4627 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4632 * Try to load a features file onto the alignment.
4635 * contents or path to retrieve file
4637 * access mode of file (see jalview.io.AlignFile)
4638 * @return true if features file was parsed corectly.
4640 public boolean parseFeaturesFile(String file, String type)
4642 boolean featuresFile = false;
4645 featuresFile = new FeaturesFile(file, type).parse(viewport
4646 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4647 .getFeatureRenderer().featureColours, false,
4648 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4649 } catch (Exception ex)
4651 ex.printStackTrace();
4656 viewport.showSequenceFeatures = true;
4657 showSeqFeatures.setSelected(true);
4658 if (alignPanel.seqPanel.seqCanvas.fr != null)
4660 // update the min/max ranges where necessary
4661 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4663 if (featureSettings != null)
4665 featureSettings.setTableData();
4667 alignPanel.paintAlignment(true);
4670 return featuresFile;
4674 public void dragEnter(DropTargetDragEvent evt)
4679 public void dragExit(DropTargetEvent evt)
4684 public void dragOver(DropTargetDragEvent evt)
4689 public void dropActionChanged(DropTargetDragEvent evt)
4694 public void drop(DropTargetDropEvent evt)
4696 Transferable t = evt.getTransferable();
4697 java.util.List files = null;
4701 DataFlavor uriListFlavor = new DataFlavor(
4702 "text/uri-list;class=java.lang.String");
4703 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4705 // Works on Windows and MacOSX
4706 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4707 files = (java.util.List) t
4708 .getTransferData(DataFlavor.javaFileListFlavor);
4710 else if (t.isDataFlavorSupported(uriListFlavor))
4712 // This is used by Unix drag system
4713 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4714 String data = (String) t.getTransferData(uriListFlavor);
4715 files = new java.util.ArrayList(1);
4716 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4717 data, "\r\n"); st.hasMoreTokens();)
4719 String s = st.nextToken();
4720 if (s.startsWith("#"))
4722 // the line is a comment (as per the RFC 2483)
4726 java.net.URI uri = new java.net.URI(s);
4727 // check to see if we can handle this kind of URI
4728 if (uri.getScheme().toLowerCase().startsWith("http"))
4730 files.add(uri.toString());
4734 // otherwise preserve old behaviour: catch all for file objects
4735 java.io.File file = new java.io.File(uri);
4736 files.add(file.toString());
4740 } catch (Exception e)
4742 e.printStackTrace();
4748 // check to see if any of these files have names matching sequences in
4750 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4751 .getAlignment().getSequencesArray());
4753 * Object[] { String,SequenceI}
4755 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4756 ArrayList<String> filesnotmatched = new ArrayList<String>();
4757 for (int i = 0; i < files.size(); i++)
4759 String file = files.get(i).toString();
4761 String protocol = FormatAdapter.checkProtocol(file);
4762 if (protocol == jalview.io.FormatAdapter.FILE)
4764 File fl = new File(file);
4765 pdbfn = fl.getName();
4767 else if (protocol == jalview.io.FormatAdapter.URL)
4769 URL url = new URL(file);
4770 pdbfn = url.getFile();
4772 if (pdbfn.length() > 0)
4774 // attempt to find a match in the alignment
4775 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4776 int l = 0, c = pdbfn.indexOf(".");
4777 while (mtch == null && c != -1)
4782 } while ((c = pdbfn.indexOf(".", l)) > l);
4785 pdbfn = pdbfn.substring(0, l);
4787 mtch = idm.findAllIdMatches(pdbfn);
4794 type = new IdentifyFile().Identify(file, protocol);
4795 } catch (Exception ex)
4801 if (type.equalsIgnoreCase("PDB"))
4803 filesmatched.add(new Object[]
4804 { file, protocol, mtch });
4809 // File wasn't named like one of the sequences or wasn't a PDB file.
4810 filesnotmatched.add(file);
4814 if (filesmatched.size() > 0)
4816 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4820 "Do you want to automatically associate the "
4821 + filesmatched.size()
4822 + " PDB files with sequences in the alignment that have the same name ?",
4823 "Automatically Associate PDB files by name",
4824 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4827 for (Object[] fm : filesmatched)
4829 // try and associate
4830 // TODO: may want to set a standard ID naming formalism for
4831 // associating PDB files which have no IDs.
4832 for (SequenceI toassoc : (SequenceI[]) fm[2])
4834 PDBEntry pe = new AssociatePdbFileWithSeq()
4835 .associatePdbWithSeq((String) fm[0],
4836 (String) fm[1], toassoc, false);
4839 System.err.println("Associated file : "
4840 + ((String) fm[0]) + " with "
4841 + toassoc.getDisplayId(true));
4845 alignPanel.paintAlignment(true);
4849 if (filesnotmatched.size() > 0)
4852 && (Cache.getDefault(
4853 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4856 "<html>Do you want to <em>ignore</em> the "
4857 + filesnotmatched.size()
4858 + " files whose names did not match any sequence IDs ?</html>",
4859 "Ignore unmatched dropped files ?",
4860 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4864 for (String fn : filesnotmatched)
4866 loadJalviewDataFile(fn, null, null, null);
4870 } catch (Exception ex)
4872 ex.printStackTrace();
4878 * Attempt to load a "dropped" file or URL string: First by testing whether
4879 * it's and Annotation file, then a JNet file, and finally a features file. If
4880 * all are false then the user may have dropped an alignment file onto this
4884 * either a filename or a URL string.
4886 public void loadJalviewDataFile(String file, String protocol,
4887 String format, SequenceI assocSeq)
4891 if (protocol == null)
4893 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4895 // if the file isn't identified, or not positively identified as some
4896 // other filetype (PFAM is default unidentified alignment file type) then
4897 // try to parse as annotation.
4898 boolean isAnnotation = (format == null || format
4899 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4900 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4905 // first see if its a T-COFFEE score file
4906 TCoffeeScoreFile tcf = null;
4909 tcf = new TCoffeeScoreFile(file, protocol);
4912 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4914 tcoffeeColour.setEnabled(true);
4915 tcoffeeColour.setSelected(true);
4916 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4917 isAnnotation = true;
4919 .setText("Successfully pasted T-Coffee scores to alignment.");
4923 // some problem - if no warning its probable that the ID matching
4924 // process didn't work
4928 tcf.getWarningMessage() == null ? "Check that the file matches sequence IDs in the alignment."
4929 : tcf.getWarningMessage(),
4930 "Problem reading T-COFFEE score file",
4931 JOptionPane.WARNING_MESSAGE);
4938 } catch (Exception x)
4941 .debug("Exception when processing data source as T-COFFEE score file",
4947 // try to see if its a JNet 'concise' style annotation file *before*
4949 // try to parse it as a features file
4952 format = new IdentifyFile().Identify(file, protocol);
4954 if (format.equalsIgnoreCase("JnetFile"))
4956 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4958 new JnetAnnotationMaker().add_annotation(predictions,
4959 viewport.getAlignment(), 0, false);
4960 isAnnotation = true;
4965 * if (format.equalsIgnoreCase("PDB")) {
4967 * String pdbfn = ""; // try to match up filename with sequence id
4968 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4969 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4970 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4971 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4972 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4973 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4974 * // attempt to find a match in the alignment SequenceI mtch =
4975 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4976 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4977 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4978 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4979 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4980 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4981 * { System.err.println("Associated file : " + file + " with " +
4982 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4983 * TODO: maybe need to load as normal otherwise return; } }
4985 // try to parse it as a features file
4986 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4987 // if it wasn't a features file then we just treat it as a general
4988 // alignment file to load into the current view.
4991 new FileLoader().LoadFile(viewport, file, protocol, format);
4995 alignPanel.paintAlignment(true);
5003 alignPanel.adjustAnnotationHeight();
5004 viewport.updateSequenceIdColours();
5005 buildSortByAnnotationScoresMenu();
5006 alignPanel.paintAlignment(true);
5008 } catch (Exception ex)
5010 ex.printStackTrace();
5011 } catch (OutOfMemoryError oom)
5016 } catch (Exception x)
5022 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5023 : "using " + protocol + " from " + file)
5025 + (format != null ? "(parsing as '" + format
5026 + "' file)" : ""), oom, Desktop.desktop);
5031 public void tabSelectionChanged(int index)
5035 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5036 viewport = alignPanel.av;
5037 setMenusFromViewport(viewport);
5042 public void tabbedPane_mousePressed(MouseEvent e)
5044 if (SwingUtilities.isRightMouseButton(e))
5046 String reply = JOptionPane.showInternalInputDialog(this,
5047 "Enter View Name", "Edit View Name",
5048 JOptionPane.QUESTION_MESSAGE);
5052 viewport.viewName = reply;
5053 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5058 public AlignViewport getCurrentView()
5064 * Open the dialog for regex description parsing.
5067 protected void extractScores_actionPerformed(ActionEvent e)
5069 ParseProperties pp = new jalview.analysis.ParseProperties(
5070 viewport.getAlignment());
5071 // TODO: verify regex and introduce GUI dialog for version 2.5
5072 // if (pp.getScoresFromDescription("col", "score column ",
5073 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5075 if (pp.getScoresFromDescription("description column",
5076 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5078 buildSortByAnnotationScoresMenu();
5086 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5090 protected void showDbRefs_actionPerformed(ActionEvent e)
5092 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5098 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5102 protected void showNpFeats_actionPerformed(ActionEvent e)
5104 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5108 * find the viewport amongst the tabs in this alignment frame and close that
5113 public boolean closeView(AlignViewport av)
5117 this.closeMenuItem_actionPerformed(false);
5120 Component[] comp = tabbedPane.getComponents();
5121 for (int i = 0; comp != null && i < comp.length; i++)
5123 if (comp[i] instanceof AlignmentPanel)
5125 if (((AlignmentPanel) comp[i]).av == av)
5128 closeView((AlignmentPanel) comp[i]);
5136 protected void build_fetchdbmenu(JMenu webService)
5138 // Temporary hack - DBRef Fetcher always top level ws entry.
5139 // TODO We probably want to store a sequence database checklist in
5140 // preferences and have checkboxes.. rather than individual sources selected
5142 final JMenu rfetch = new JMenu("Fetch DB References");
5143 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5144 webService.add(rfetch);
5146 JMenuItem fetchr = new JMenuItem("Standard Databases");
5147 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5148 fetchr.addActionListener(new ActionListener()
5152 public void actionPerformed(ActionEvent e)
5154 new Thread(new Runnable()
5160 new jalview.ws.DBRefFetcher(alignPanel.av
5161 .getSequenceSelection(), alignPanel.alignFrame)
5162 .fetchDBRefs(false);
5170 final AlignFrame me = this;
5171 new Thread(new Runnable()
5176 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5177 .getSequenceFetcherSingleton(me);
5178 javax.swing.SwingUtilities.invokeLater(new Runnable()
5183 String[] dbclasses = sf.getOrderedSupportedSources();
5184 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5185 // jalview.util.QuickSort.sort(otherdb, otherdb);
5186 List<DbSourceProxy> otherdb;
5187 JMenu dfetch = new JMenu();
5188 JMenu ifetch = new JMenu();
5189 JMenuItem fetchr = null;
5190 int comp = 0, icomp = 0, mcomp = 15;
5191 String mname = null;
5193 for (String dbclass : dbclasses)
5195 otherdb = sf.getSourceProxy(dbclass);
5196 // add a single entry for this class, or submenu allowing 'fetch
5198 if (otherdb == null || otherdb.size() < 1)
5202 // List<DbSourceProxy> dbs=otherdb;
5203 // otherdb=new ArrayList<DbSourceProxy>();
5204 // for (DbSourceProxy db:dbs)
5206 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5210 mname = "From " + dbclass;
5212 if (otherdb.size() == 1)
5214 final DbSourceProxy[] dassource = otherdb
5215 .toArray(new DbSourceProxy[0]);
5216 DbSourceProxy src = otherdb.get(0);
5217 fetchr = new JMenuItem(src.getDbSource());
5218 fetchr.addActionListener(new ActionListener()
5222 public void actionPerformed(ActionEvent e)
5224 new Thread(new Runnable()
5230 new jalview.ws.DBRefFetcher(alignPanel.av
5231 .getSequenceSelection(),
5232 alignPanel.alignFrame, dassource)
5233 .fetchDBRefs(false);
5239 fetchr.setToolTipText("<html>"
5240 + JvSwingUtils.wrapTooltip("Retrieve from "
5241 + src.getDbName()) + "<html>");
5247 final DbSourceProxy[] dassource = otherdb
5248 .toArray(new DbSourceProxy[0]);
5250 DbSourceProxy src = otherdb.get(0);
5251 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5253 fetchr.addActionListener(new ActionListener()
5256 public void actionPerformed(ActionEvent e)
5258 new Thread(new Runnable()
5264 new jalview.ws.DBRefFetcher(alignPanel.av
5265 .getSequenceSelection(),
5266 alignPanel.alignFrame, dassource)
5267 .fetchDBRefs(false);
5273 fetchr.setToolTipText("<html>"
5274 + JvSwingUtils.wrapTooltip("Retrieve from all "
5275 + otherdb.size() + " sources in "
5276 + src.getDbSource() + "<br>First is :"
5277 + src.getDbName()) + "<html>");
5280 // and then build the rest of the individual menus
5281 ifetch = new JMenu("Sources from " + src.getDbSource());
5283 String imname = null;
5285 for (DbSourceProxy sproxy : otherdb)
5287 String dbname = sproxy.getDbName();
5288 String sname = dbname.length() > 5 ? dbname.substring(0,
5289 5) + "..." : dbname;
5290 String msname = dbname.length() > 10 ? dbname.substring(
5291 0, 10) + "..." : dbname;
5294 imname = "from '" + sname + "'";
5296 fetchr = new JMenuItem(msname);
5297 final DbSourceProxy[] dassrc =
5299 fetchr.addActionListener(new ActionListener()
5303 public void actionPerformed(ActionEvent e)
5305 new Thread(new Runnable()
5311 new jalview.ws.DBRefFetcher(alignPanel.av
5312 .getSequenceSelection(),
5313 alignPanel.alignFrame, dassrc)
5314 .fetchDBRefs(false);
5320 fetchr.setToolTipText("<html>"
5321 + JvSwingUtils.wrapTooltip("Retrieve from "
5322 + dbname) + "</html>");
5325 if (++icomp >= mcomp || i == (otherdb.size()))
5327 ifetch.setText(imname + " to '" + sname + "'");
5329 ifetch = new JMenu();
5337 if (comp >= mcomp || dbi >= (dbclasses.length))
5339 dfetch.setText(mname + " to '" + dbclass + "'");
5341 dfetch = new JMenu();
5354 * Left justify the whole alignment.
5357 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5359 AlignmentI al = viewport.getAlignment();
5361 viewport.firePropertyChange("alignment", null, al);
5365 * Right justify the whole alignment.
5368 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5370 AlignmentI al = viewport.getAlignment();
5372 viewport.firePropertyChange("alignment", null, al);
5375 public void setShowSeqFeatures(boolean b)
5377 showSeqFeatures.setSelected(true);
5378 viewport.setShowSequenceFeatures(true);
5385 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5386 * awt.event.ActionEvent)
5389 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5391 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5392 alignPanel.paintAlignment(true);
5399 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5403 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5405 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5406 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5414 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5415 * .event.ActionEvent)
5418 protected void showGroupConservation_actionPerformed(ActionEvent e)
5420 viewport.setShowGroupConservation(showGroupConservation.getState());
5421 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5428 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5429 * .event.ActionEvent)
5432 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5434 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5435 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5442 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5443 * .event.ActionEvent)
5446 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5448 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5449 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5453 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5455 showSequenceLogo.setState(true);
5456 viewport.setShowSequenceLogo(true);
5457 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5458 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5462 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5464 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5471 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5472 * .event.ActionEvent)
5475 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5477 if (viewport.getSelectionGroup() != null)
5479 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5480 viewport.getSequenceSelection(),
5481 viewport.getAlignmentView(true).getSequenceStrings(
5482 viewport.getGapCharacter()), viewport.getAlignment()
5484 viewport.getAlignment().deleteAllGroups();
5485 viewport.sequenceColours = null;
5486 viewport.setSelectionGroup(null);
5487 // set view properties for each group
5488 for (int g = 0; g < gps.length; g++)
5490 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5491 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5492 viewport.getAlignment().addGroup(gps[g]);
5493 Color col = new Color((int) (Math.random() * 255),
5494 (int) (Math.random() * 255), (int) (Math.random() * 255));
5495 col = col.brighter();
5496 for (SequenceI s : gps[g].getSequences())
5497 viewport.setSequenceColour(s, col);
5499 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5500 alignPanel.updateAnnotation();
5501 alignPanel.paintAlignment(true);
5506 * make the given alignmentPanel the currently selected tab
5508 * @param alignmentPanel
5510 public void setDisplayedView(AlignmentPanel alignmentPanel)
5512 if (!viewport.getSequenceSetId().equals(
5513 alignmentPanel.av.getSequenceSetId()))
5516 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5518 if (tabbedPane != null
5519 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5520 .getSelectedIndex())
5522 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5527 class PrintThread extends Thread
5531 public PrintThread(AlignmentPanel ap)
5536 static PageFormat pf;
5541 PrinterJob printJob = PrinterJob.getPrinterJob();
5545 printJob.setPrintable(ap, pf);
5549 printJob.setPrintable(ap);
5552 if (printJob.printDialog())
5557 } catch (Exception PrintException)
5559 PrintException.printStackTrace();