2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.AlignmentSorter;
22 import jalview.analysis.Conservation;
23 import jalview.analysis.CrossRef;
24 import jalview.analysis.NJTree;
25 import jalview.analysis.ParseProperties;
26 import jalview.analysis.SequenceIdMatcher;
27 import jalview.bin.Cache;
28 import jalview.commands.CommandI;
29 import jalview.commands.EditCommand;
30 import jalview.commands.OrderCommand;
31 import jalview.commands.RemoveGapColCommand;
32 import jalview.commands.RemoveGapsCommand;
33 import jalview.commands.SlideSequencesCommand;
34 import jalview.commands.TrimRegionCommand;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.Alignment;
37 import jalview.datamodel.AlignmentAnnotation;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentOrder;
40 import jalview.datamodel.AlignmentView;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.PDBEntry;
43 import jalview.datamodel.SeqCigar;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.io.AlignmentProperties;
48 import jalview.io.AnnotationFile;
49 import jalview.io.FeaturesFile;
50 import jalview.io.FileLoader;
51 import jalview.io.FormatAdapter;
52 import jalview.io.HTMLOutput;
53 import jalview.io.IdentifyFile;
54 import jalview.io.JalviewFileChooser;
55 import jalview.io.JalviewFileView;
56 import jalview.io.JnetAnnotationMaker;
57 import jalview.io.NewickFile;
58 import jalview.io.TCoffeeScoreFile;
59 import jalview.jbgui.GAlignFrame;
60 import jalview.schemes.Blosum62ColourScheme;
61 import jalview.schemes.BuriedColourScheme;
62 import jalview.schemes.ClustalxColourScheme;
63 import jalview.schemes.ColourSchemeI;
64 import jalview.schemes.ColourSchemeProperty;
65 import jalview.schemes.HelixColourScheme;
66 import jalview.schemes.HydrophobicColourScheme;
67 import jalview.schemes.NucleotideColourScheme;
68 import jalview.schemes.PIDColourScheme;
69 import jalview.schemes.PurinePyrimidineColourScheme;
70 import jalview.schemes.RNAHelicesColourChooser;
71 import jalview.schemes.ResidueProperties;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.UserColourScheme;
77 import jalview.schemes.ZappoColourScheme;
78 import jalview.ws.jws1.Discoverer;
79 import jalview.ws.jws2.Jws2Discoverer;
80 import jalview.ws.jws2.jabaws2.Jws2Instance;
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()
4162 final List<JMenuItem> legacyItems=new ArrayList<JMenuItem>();
4165 System.err.println("Building ws menu again "
4166 + Thread.currentThread());
4167 // TODO: add support for context dependent disabling of services based
4169 // alignment and current selection
4170 // TODO: add additional serviceHandle parameter to specify abstract
4172 // class independently of AbstractName
4173 // TODO: add in rediscovery GUI function to restart discoverer
4174 // TODO: group services by location as well as function and/or
4176 // object broker mechanism.
4177 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4178 final IProgressIndicator af = me;
4179 final JMenu msawsmenu = new JMenu("Alignment");
4180 final JMenu secstrmenu = new JMenu(
4181 "Secondary Structure Prediction");
4182 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4183 final JMenu analymenu = new JMenu("Analysis");
4184 final JMenu dismenu = new JMenu("Protein Disorder");
4185 // JAL-940 - only show secondary structure prediction services from
4186 // the legacy server
4187 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4189 Discoverer.services != null && (Discoverer.services.size() > 0))
4191 // TODO: refactor to allow list of AbstractName/Handler bindings to
4193 // stored or retrieved from elsewhere
4194 // No MSAWS used any more:
4195 // Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4196 Vector secstrpr = (Vector) Discoverer.services
4198 if (secstrpr != null)
4200 // Add any secondary structure prediction services
4201 for (int i = 0, j = secstrpr.size(); i < j; i++)
4203 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4205 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4206 .getServiceClient(sh);
4207 int p=secstrmenu.getItemCount();
4208 impl.attachWSMenuEntry(secstrmenu, me);
4209 int q=secstrmenu.getItemCount();
4210 for (int litm=p;litm<q; litm++)
4212 legacyItems.add(secstrmenu.getItem(litm));
4218 // Add all submenus in the order they should appear on the web
4220 wsmenu.add(msawsmenu);
4221 wsmenu.add(secstrmenu);
4222 wsmenu.add(dismenu);
4223 wsmenu.add(analymenu);
4224 // No search services yet
4225 // wsmenu.add(seqsrchmenu);
4227 javax.swing.SwingUtilities.invokeLater(new Runnable()
4234 webService.removeAll();
4235 // first, add discovered services onto the webservices menu
4236 if (wsmenu.size() > 0)
4238 for (int i = 0, j = wsmenu.size(); i < j; i++)
4240 webService.add(wsmenu.get(i));
4245 webService.add(me.webServiceNoServices);
4247 // TODO: move into separate menu builder class.
4248 boolean new_sspred=false;
4249 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4251 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4252 if (jws2servs != null)
4254 if (jws2servs.hasServices())
4256 jws2servs.attachWSMenuEntry(webService, me);
4257 for (Jws2Instance sv:jws2servs.getServices()) {
4258 if (sv.description.toLowerCase().contains("jpred"))
4260 for (JMenuItem jmi:legacyItems)
4262 jmi.setVisible(false);
4268 if (jws2servs.isRunning())
4270 JMenuItem tm = new JMenuItem(
4271 "Still discovering JABA Services");
4272 tm.setEnabled(false);
4277 build_urlServiceMenu(me.webService);
4278 build_fetchdbmenu(webService);
4279 for (JMenu item : wsmenu)
4281 if (item.getItemCount() == 0)
4283 item.setEnabled(false);
4287 item.setEnabled(true);
4290 } catch (Exception e)
4293 .debug("Exception during web service menu building process.",
4299 } catch (Exception e)
4304 buildingMenu = false;
4311 * construct any groupURL type service menu entries.
4315 private void build_urlServiceMenu(JMenu webService)
4317 // TODO: remove this code when 2.7 is released
4318 // DEBUG - alignmentView
4320 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4321 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4323 * @Override public void actionPerformed(ActionEvent e) {
4324 * jalview.datamodel.AlignmentView
4325 * .testSelectionViews(af.viewport.getAlignment(),
4326 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4328 * }); webService.add(testAlView);
4330 // TODO: refactor to RestClient discoverer and merge menu entries for
4331 // rest-style services with other types of analysis/calculation service
4332 // SHmmr test client - still being implemented.
4333 // DEBUG - alignmentView
4335 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4338 client.attachWSMenuEntry(
4339 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4343 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4345 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4351 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4352 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4353 * getProperty("LAST_DIRECTORY"));
4355 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4356 * to Vamsas file"); chooser.setToolTipText("Export");
4358 * int value = chooser.showSaveDialog(this);
4360 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4361 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4362 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4363 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4366 * prototype of an automatically enabled/disabled analysis function
4369 protected void setShowProductsEnabled()
4371 SequenceI[] selection = viewport.getSequenceSelection();
4372 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4373 viewport.getAlignment().getDataset()))
4375 showProducts.setEnabled(true);
4380 showProducts.setEnabled(false);
4385 * search selection for sequence xRef products and build the show products
4390 * @return true if showProducts menu should be enabled.
4392 public boolean canShowProducts(SequenceI[] selection,
4393 boolean isRegionSelection, Alignment dataset)
4395 boolean showp = false;
4398 showProducts.removeAll();
4399 final boolean dna = viewport.getAlignment().isNucleotide();
4400 final Alignment ds = dataset;
4401 String[] ptypes = (selection == null || selection.length == 0) ? null
4402 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4404 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4405 // selection, dataset, true);
4406 final SequenceI[] sel = selection;
4407 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4410 final boolean isRegSel = isRegionSelection;
4411 final AlignFrame af = this;
4412 final String source = ptypes[t];
4413 JMenuItem xtype = new JMenuItem(ptypes[t]);
4414 xtype.addActionListener(new ActionListener()
4418 public void actionPerformed(ActionEvent e)
4420 // TODO: new thread for this call with vis-delay
4421 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4422 isRegSel, dna, source);
4426 showProducts.add(xtype);
4428 showProducts.setVisible(showp);
4429 showProducts.setEnabled(showp);
4430 } catch (Exception e)
4432 jalview.bin.Cache.log
4433 .warn("canTranslate threw an exception - please report to help@jalview.org",
4440 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4441 boolean isRegSel, boolean dna, String source)
4443 final boolean fisRegSel = isRegSel;
4444 final boolean fdna = dna;
4445 final String fsrc = source;
4446 final AlignFrame ths = this;
4447 final SequenceI[] fsel = sel;
4448 Runnable foo = new Runnable()
4454 final long sttime = System.currentTimeMillis();
4455 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4458 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4462 Alignment prods = CrossRef
4463 .findXrefSequences(fsel, fdna, fsrc, ds);
4466 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4467 for (int s = 0; s < sprods.length; s++)
4469 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4470 if (ds.getSequences() == null
4471 || !ds.getSequences().contains(
4472 sprods[s].getDatasetSequence()))
4473 ds.addSequence(sprods[s].getDatasetSequence());
4474 sprods[s].updatePDBIds();
4476 Alignment al = new Alignment(sprods);
4477 AlignedCodonFrame[] cf = prods.getCodonFrames();
4479 for (int s = 0; cf != null && s < cf.length; s++)
4481 al.addCodonFrame(cf[s]);
4484 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4486 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4487 + " for " + ((fisRegSel) ? "selected region of " : "")
4489 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4494 System.err.println("No Sequences generated for xRef type "
4497 } catch (Exception e)
4499 jalview.bin.Cache.log.error(
4500 "Exception when finding crossreferences", e);
4501 } catch (OutOfMemoryError e)
4503 new OOMWarning("whilst fetching crossreferences", e);
4506 jalview.bin.Cache.log.error("Error when finding crossreferences",
4509 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4514 Thread frunner = new Thread(foo);
4518 public boolean canShowTranslationProducts(SequenceI[] selection,
4519 AlignmentI alignment)
4524 return (jalview.analysis.Dna.canTranslate(selection,
4525 viewport.getViewAsVisibleContigs(true)));
4526 } catch (Exception e)
4528 jalview.bin.Cache.log
4529 .warn("canTranslate threw an exception - please report to help@jalview.org",
4536 public void showProducts_actionPerformed(ActionEvent e)
4538 // /////////////////////////////
4539 // Collect Data to be translated/transferred
4541 SequenceI[] selection = viewport.getSequenceSelection();
4542 AlignmentI al = null;
4545 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4546 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4547 viewport.getAlignment().getDataset());
4548 } catch (Exception ex)
4551 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4558 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4559 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4563 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4564 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4565 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4570 public void showTranslation_actionPerformed(ActionEvent e)
4572 // /////////////////////////////
4573 // Collect Data to be translated/transferred
4575 SequenceI[] selection = viewport.getSequenceSelection();
4576 String[] seqstring = viewport.getViewAsString(true);
4577 AlignmentI al = null;
4580 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4581 viewport.getViewAsVisibleContigs(true), viewport
4582 .getGapCharacter(), viewport.getAlignment()
4583 .getAlignmentAnnotation(), viewport.getAlignment()
4584 .getWidth(), viewport.getAlignment().getDataset());
4585 } catch (Exception ex)
4588 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4592 "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.",
4593 "Implementation error: Translation Failed", JOptionPane.ERROR_MESSAGE);
4601 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4602 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4606 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4607 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4608 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4613 * Try to load a features file onto the alignment.
4616 * contents or path to retrieve file
4618 * access mode of file (see jalview.io.AlignFile)
4619 * @return true if features file was parsed corectly.
4621 public boolean parseFeaturesFile(String file, String type)
4623 boolean featuresFile = false;
4626 featuresFile = new FeaturesFile(file, type).parse(viewport
4627 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4628 .getFeatureRenderer().featureColours, false,
4629 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4630 } catch (Exception ex)
4632 ex.printStackTrace();
4637 viewport.showSequenceFeatures = true;
4638 showSeqFeatures.setSelected(true);
4639 if (alignPanel.seqPanel.seqCanvas.fr != null)
4641 // update the min/max ranges where necessary
4642 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4644 if (featureSettings != null)
4646 featureSettings.setTableData();
4648 alignPanel.paintAlignment(true);
4651 return featuresFile;
4655 public void dragEnter(DropTargetDragEvent evt)
4660 public void dragExit(DropTargetEvent evt)
4665 public void dragOver(DropTargetDragEvent evt)
4670 public void dropActionChanged(DropTargetDragEvent evt)
4675 public void drop(DropTargetDropEvent evt)
4677 Transferable t = evt.getTransferable();
4678 java.util.List files = null;
4682 DataFlavor uriListFlavor = new DataFlavor(
4683 "text/uri-list;class=java.lang.String");
4684 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4686 // Works on Windows and MacOSX
4687 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4688 files = (java.util.List) t
4689 .getTransferData(DataFlavor.javaFileListFlavor);
4691 else if (t.isDataFlavorSupported(uriListFlavor))
4693 // This is used by Unix drag system
4694 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4695 String data = (String) t.getTransferData(uriListFlavor);
4696 files = new java.util.ArrayList(1);
4697 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4698 data, "\r\n"); st.hasMoreTokens();)
4700 String s = st.nextToken();
4701 if (s.startsWith("#"))
4703 // the line is a comment (as per the RFC 2483)
4707 java.net.URI uri = new java.net.URI(s);
4708 // check to see if we can handle this kind of URI
4709 if (uri.getScheme().toLowerCase().startsWith("http"))
4711 files.add(uri.toString());
4715 // otherwise preserve old behaviour: catch all for file objects
4716 java.io.File file = new java.io.File(uri);
4717 files.add(file.toString());
4721 } catch (Exception e)
4723 e.printStackTrace();
4729 // check to see if any of these files have names matching sequences in
4731 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4732 .getAlignment().getSequencesArray());
4734 * Object[] { String,SequenceI}
4736 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4737 ArrayList<String> filesnotmatched = new ArrayList<String>();
4738 for (int i = 0; i < files.size(); i++)
4740 String file = files.get(i).toString();
4742 String protocol = FormatAdapter.checkProtocol(file);
4743 if (protocol == jalview.io.FormatAdapter.FILE)
4745 File fl = new File(file);
4746 pdbfn = fl.getName();
4748 else if (protocol == jalview.io.FormatAdapter.URL)
4750 URL url = new URL(file);
4751 pdbfn = url.getFile();
4753 if (pdbfn.length() > 0)
4755 // attempt to find a match in the alignment
4756 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4757 int l = 0, c = pdbfn.indexOf(".");
4758 while (mtch == null && c != -1)
4763 } while ((c = pdbfn.indexOf(".", l)) > l);
4766 pdbfn = pdbfn.substring(0, l);
4768 mtch = idm.findAllIdMatches(pdbfn);
4775 type = new IdentifyFile().Identify(file, protocol);
4776 } catch (Exception ex)
4782 if (type.equalsIgnoreCase("PDB"))
4784 filesmatched.add(new Object[]
4785 { file, protocol, mtch });
4790 // File wasn't named like one of the sequences or wasn't a PDB file.
4791 filesnotmatched.add(file);
4795 if (filesmatched.size() > 0)
4797 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4801 "Do you want to automatically associate the "
4802 + filesmatched.size()
4803 + " PDB files with sequences in the alignment that have the same name ?",
4804 "Automatically Associate PDB files by name",
4805 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4808 for (Object[] fm : filesmatched)
4810 // try and associate
4811 // TODO: may want to set a standard ID naming formalism for
4812 // associating PDB files which have no IDs.
4813 for (SequenceI toassoc : (SequenceI[]) fm[2])
4815 PDBEntry pe = new AssociatePdbFileWithSeq()
4816 .associatePdbWithSeq((String) fm[0],
4817 (String) fm[1], toassoc, false);
4820 System.err.println("Associated file : "
4821 + ((String) fm[0]) + " with "
4822 + toassoc.getDisplayId(true));
4826 alignPanel.paintAlignment(true);
4830 if (filesnotmatched.size() > 0)
4833 && (Cache.getDefault(
4834 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4837 "<html>Do you want to <em>ignore</em> the "
4838 + filesnotmatched.size()
4839 + " files whose names did not match any sequence IDs ?</html>",
4840 "Ignore unmatched dropped files ?",
4841 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4845 for (String fn : filesnotmatched)
4847 loadJalviewDataFile(fn, null, null, null);
4851 } catch (Exception ex)
4853 ex.printStackTrace();
4859 * Attempt to load a "dropped" file or URL string: First by testing whether
4860 * it's and Annotation file, then a JNet file, and finally a features file. If
4861 * all are false then the user may have dropped an alignment file onto this
4865 * either a filename or a URL string.
4867 public void loadJalviewDataFile(String file, String protocol,
4868 String format, SequenceI assocSeq)
4872 if (protocol == null)
4874 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4876 // if the file isn't identified, or not positively identified as some
4877 // other filetype (PFAM is default unidentified alignment file type) then
4878 // try to parse as annotation.
4879 boolean isAnnotation = (format == null || format
4880 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4881 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4886 // first see if its a T-COFFEE score file
4887 TCoffeeScoreFile tcf = null;
4890 tcf = new TCoffeeScoreFile(file, protocol);
4893 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4895 tcoffeeColour.setEnabled(true);
4896 tcoffeeColour.setSelected(true);
4897 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4898 isAnnotation = true;
4900 .setText("Successfully pasted T-Coffee scores to alignment.");
4904 // some problem - if no warning its probable that the ID matching
4905 // process didn't work
4909 tcf.getWarningMessage() == null ? "Check that the file matches sequence IDs in the alignment."
4910 : tcf.getWarningMessage(),
4911 "Problem reading T-COFFEE score file",
4912 JOptionPane.WARNING_MESSAGE);
4919 } catch (Exception x)
4922 .debug("Exception when processing data source as T-COFFEE score file",
4928 // try to see if its a JNet 'concise' style annotation file *before*
4930 // try to parse it as a features file
4933 format = new IdentifyFile().Identify(file, protocol);
4935 if (format.equalsIgnoreCase("JnetFile"))
4937 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4939 new JnetAnnotationMaker().add_annotation(predictions,
4940 viewport.getAlignment(), 0, false);
4941 isAnnotation = true;
4946 * if (format.equalsIgnoreCase("PDB")) {
4948 * String pdbfn = ""; // try to match up filename with sequence id
4949 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4950 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4951 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4952 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4953 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4954 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4955 * // attempt to find a match in the alignment SequenceI mtch =
4956 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4957 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4958 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4959 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4960 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4961 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4962 * { System.err.println("Associated file : " + file + " with " +
4963 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4964 * TODO: maybe need to load as normal otherwise return; } }
4966 // try to parse it as a features file
4967 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4968 // if it wasn't a features file then we just treat it as a general
4969 // alignment file to load into the current view.
4972 new FileLoader().LoadFile(viewport, file, protocol, format);
4976 alignPanel.paintAlignment(true);
4984 alignPanel.adjustAnnotationHeight();
4985 viewport.updateSequenceIdColours();
4986 buildSortByAnnotationScoresMenu();
4987 alignPanel.paintAlignment(true);
4989 } catch (Exception ex)
4991 ex.printStackTrace();
4992 } catch (OutOfMemoryError oom)
4997 } catch (Exception x)
5003 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5004 : "using " + protocol + " from " + file)
5006 + (format != null ? "(parsing as '" + format
5007 + "' file)" : ""), oom, Desktop.desktop);
5012 public void tabSelectionChanged(int index)
5016 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5017 viewport = alignPanel.av;
5018 setMenusFromViewport(viewport);
5023 public void tabbedPane_mousePressed(MouseEvent e)
5025 if (SwingUtilities.isRightMouseButton(e))
5027 String reply = JOptionPane.showInternalInputDialog(this,
5028 "Enter View Name", "Edit View Name",
5029 JOptionPane.QUESTION_MESSAGE);
5033 viewport.viewName = reply;
5034 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5039 public AlignViewport getCurrentView()
5045 * Open the dialog for regex description parsing.
5048 protected void extractScores_actionPerformed(ActionEvent e)
5050 ParseProperties pp = new jalview.analysis.ParseProperties(
5051 viewport.getAlignment());
5052 // TODO: verify regex and introduce GUI dialog for version 2.5
5053 // if (pp.getScoresFromDescription("col", "score column ",
5054 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5056 if (pp.getScoresFromDescription("description column",
5057 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5059 buildSortByAnnotationScoresMenu();
5067 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5071 protected void showDbRefs_actionPerformed(ActionEvent e)
5073 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5079 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5083 protected void showNpFeats_actionPerformed(ActionEvent e)
5085 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5089 * find the viewport amongst the tabs in this alignment frame and close that
5094 public boolean closeView(AlignViewport av)
5098 this.closeMenuItem_actionPerformed(false);
5101 Component[] comp = tabbedPane.getComponents();
5102 for (int i = 0; comp != null && i < comp.length; i++)
5104 if (comp[i] instanceof AlignmentPanel)
5106 if (((AlignmentPanel) comp[i]).av == av)
5109 closeView((AlignmentPanel) comp[i]);
5117 protected void build_fetchdbmenu(JMenu webService)
5119 // Temporary hack - DBRef Fetcher always top level ws entry.
5120 // TODO We probably want to store a sequence database checklist in
5121 // preferences and have checkboxes.. rather than individual sources selected
5123 final JMenu rfetch = new JMenu("Fetch DB References");
5124 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5125 webService.add(rfetch);
5127 JMenuItem fetchr = new JMenuItem("Standard Databases");
5128 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5129 fetchr.addActionListener(new ActionListener()
5133 public void actionPerformed(ActionEvent e)
5135 new Thread(new Runnable()
5141 new jalview.ws.DBRefFetcher(alignPanel.av
5142 .getSequenceSelection(), alignPanel.alignFrame)
5143 .fetchDBRefs(false);
5151 final AlignFrame me = this;
5152 new Thread(new Runnable()
5157 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5158 .getSequenceFetcherSingleton(me);
5159 javax.swing.SwingUtilities.invokeLater(new Runnable()
5164 String[] dbclasses = sf.getOrderedSupportedSources();
5165 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5166 // jalview.util.QuickSort.sort(otherdb, otherdb);
5167 List<DbSourceProxy> otherdb;
5168 JMenu dfetch = new JMenu();
5169 JMenu ifetch = new JMenu();
5170 JMenuItem fetchr = null;
5171 int comp = 0, icomp = 0, mcomp = 15;
5172 String mname = null;
5174 for (String dbclass : dbclasses)
5176 otherdb = sf.getSourceProxy(dbclass);
5177 // add a single entry for this class, or submenu allowing 'fetch
5179 if (otherdb == null || otherdb.size() < 1)
5183 // List<DbSourceProxy> dbs=otherdb;
5184 // otherdb=new ArrayList<DbSourceProxy>();
5185 // for (DbSourceProxy db:dbs)
5187 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5191 mname = "From " + dbclass;
5193 if (otherdb.size() == 1)
5195 final DbSourceProxy[] dassource = otherdb
5196 .toArray(new DbSourceProxy[0]);
5197 DbSourceProxy src = otherdb.get(0);
5198 fetchr = new JMenuItem(src.getDbSource());
5199 fetchr.addActionListener(new ActionListener()
5203 public void actionPerformed(ActionEvent e)
5205 new Thread(new Runnable()
5211 new jalview.ws.DBRefFetcher(alignPanel.av
5212 .getSequenceSelection(),
5213 alignPanel.alignFrame, dassource)
5214 .fetchDBRefs(false);
5220 fetchr.setToolTipText("<html>"
5221 + JvSwingUtils.wrapTooltip("Retrieve from "
5222 + src.getDbName()) + "<html>");
5228 final DbSourceProxy[] dassource = otherdb
5229 .toArray(new DbSourceProxy[0]);
5231 DbSourceProxy src = otherdb.get(0);
5232 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5234 fetchr.addActionListener(new ActionListener()
5237 public void actionPerformed(ActionEvent e)
5239 new Thread(new Runnable()
5245 new jalview.ws.DBRefFetcher(alignPanel.av
5246 .getSequenceSelection(),
5247 alignPanel.alignFrame, dassource)
5248 .fetchDBRefs(false);
5254 fetchr.setToolTipText("<html>"
5255 + JvSwingUtils.wrapTooltip("Retrieve from all "
5256 + otherdb.size() + " sources in "
5257 + src.getDbSource() + "<br>First is :"
5258 + src.getDbName()) + "<html>");
5261 // and then build the rest of the individual menus
5262 ifetch = new JMenu("Sources from " + src.getDbSource());
5264 String imname = null;
5266 for (DbSourceProxy sproxy : otherdb)
5268 String dbname = sproxy.getDbName();
5269 String sname = dbname.length() > 5 ? dbname.substring(0,
5270 5) + "..." : dbname;
5271 String msname = dbname.length() > 10 ? dbname.substring(
5272 0, 10) + "..." : dbname;
5275 imname = "from '" + sname + "'";
5277 fetchr = new JMenuItem(msname);
5278 final DbSourceProxy[] dassrc =
5280 fetchr.addActionListener(new ActionListener()
5284 public void actionPerformed(ActionEvent e)
5286 new Thread(new Runnable()
5292 new jalview.ws.DBRefFetcher(alignPanel.av
5293 .getSequenceSelection(),
5294 alignPanel.alignFrame, dassrc)
5295 .fetchDBRefs(false);
5301 fetchr.setToolTipText("<html>"
5302 + JvSwingUtils.wrapTooltip("Retrieve from "
5303 + dbname) + "</html>");
5306 if (++icomp >= mcomp || i == (otherdb.size()))
5308 ifetch.setText(imname + " to '" + sname + "'");
5310 ifetch = new JMenu();
5318 if (comp >= mcomp || dbi >= (dbclasses.length))
5320 dfetch.setText(mname + " to '" + dbclass + "'");
5322 dfetch = new JMenu();
5335 * Left justify the whole alignment.
5338 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5340 AlignmentI al = viewport.getAlignment();
5342 viewport.firePropertyChange("alignment", null, al);
5346 * Right justify the whole alignment.
5349 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5351 AlignmentI al = viewport.getAlignment();
5353 viewport.firePropertyChange("alignment", null, al);
5356 public void setShowSeqFeatures(boolean b)
5358 showSeqFeatures.setSelected(true);
5359 viewport.setShowSequenceFeatures(true);
5366 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5367 * awt.event.ActionEvent)
5370 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5372 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5373 alignPanel.paintAlignment(true);
5380 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5384 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5386 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5387 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5395 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5396 * .event.ActionEvent)
5399 protected void showGroupConservation_actionPerformed(ActionEvent e)
5401 viewport.setShowGroupConservation(showGroupConservation.getState());
5402 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5409 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5410 * .event.ActionEvent)
5413 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5415 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5416 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5423 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5424 * .event.ActionEvent)
5427 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5429 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5430 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5434 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5436 showSequenceLogo.setState(true);
5437 viewport.setShowSequenceLogo(true);
5438 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5439 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5443 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5445 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5452 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5453 * .event.ActionEvent)
5456 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5458 if (viewport.getSelectionGroup() != null)
5460 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5461 viewport.getSequenceSelection(),
5462 viewport.getAlignmentView(true).getSequenceStrings(
5463 viewport.getGapCharacter()), viewport.getAlignment()
5465 viewport.getAlignment().deleteAllGroups();
5466 viewport.sequenceColours = null;
5467 viewport.setSelectionGroup(null);
5468 // set view properties for each group
5469 for (int g = 0; g < gps.length; g++)
5471 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5472 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5473 viewport.getAlignment().addGroup(gps[g]);
5474 Color col = new Color((int) (Math.random() * 255),
5475 (int) (Math.random() * 255), (int) (Math.random() * 255));
5476 col = col.brighter();
5477 for (SequenceI s : gps[g].getSequences())
5478 viewport.setSequenceColour(s, col);
5480 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5481 alignPanel.updateAnnotation();
5482 alignPanel.paintAlignment(true);
5487 * make the given alignmentPanel the currently selected tab
5489 * @param alignmentPanel
5491 public void setDisplayedView(AlignmentPanel alignmentPanel)
5493 if (!viewport.getSequenceSetId().equals(
5494 alignmentPanel.av.getSequenceSetId()))
5497 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5499 if (tabbedPane != null
5500 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5501 .getSelectedIndex())
5503 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5508 class PrintThread extends Thread
5512 public PrintThread(AlignmentPanel ap)
5517 static PageFormat pf;
5522 PrinterJob printJob = PrinterJob.getPrinterJob();
5526 printJob.setPrintable(ap, pf);
5530 printJob.setPrintable(ap);
5533 if (printJob.printDialog())
5538 } catch (Exception PrintException)
5540 PrintException.printStackTrace();