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.api.AlignViewControllerI;
28 import jalview.bin.Cache;
29 import jalview.commands.CommandI;
30 import jalview.commands.EditCommand;
31 import jalview.commands.OrderCommand;
32 import jalview.commands.RemoveGapColCommand;
33 import jalview.commands.RemoveGapsCommand;
34 import jalview.commands.SlideSequencesCommand;
35 import jalview.commands.TrimRegionCommand;
36 import jalview.datamodel.AlignedCodonFrame;
37 import jalview.datamodel.Alignment;
38 import jalview.datamodel.AlignmentAnnotation;
39 import jalview.datamodel.AlignmentI;
40 import jalview.datamodel.AlignmentOrder;
41 import jalview.datamodel.AlignmentView;
42 import jalview.datamodel.ColumnSelection;
43 import jalview.datamodel.PDBEntry;
44 import jalview.datamodel.SeqCigar;
45 import jalview.datamodel.Sequence;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.io.AlignmentProperties;
49 import jalview.io.AnnotationFile;
50 import jalview.io.FeaturesFile;
51 import jalview.io.FileLoader;
52 import jalview.io.FormatAdapter;
53 import jalview.io.HTMLOutput;
54 import jalview.io.IdentifyFile;
55 import jalview.io.JalviewFileChooser;
56 import jalview.io.JalviewFileView;
57 import jalview.io.JnetAnnotationMaker;
58 import jalview.io.NewickFile;
59 import jalview.io.TCoffeeScoreFile;
60 import jalview.jbgui.GAlignFrame;
61 import jalview.schemes.Blosum62ColourScheme;
62 import jalview.schemes.BuriedColourScheme;
63 import jalview.schemes.ClustalxColourScheme;
64 import jalview.schemes.ColourSchemeI;
65 import jalview.schemes.ColourSchemeProperty;
66 import jalview.schemes.HelixColourScheme;
67 import jalview.schemes.HydrophobicColourScheme;
68 import jalview.schemes.NucleotideColourScheme;
69 import jalview.schemes.PIDColourScheme;
70 import jalview.schemes.PurinePyrimidineColourScheme;
71 import jalview.schemes.RNAHelicesColourChooser;
72 import jalview.schemes.ResidueProperties;
73 import jalview.schemes.StrandColourScheme;
74 import jalview.schemes.TCoffeeColourScheme;
75 import jalview.schemes.TaylorColourScheme;
76 import jalview.schemes.TurnColourScheme;
77 import jalview.schemes.UserColourScheme;
78 import jalview.schemes.ZappoColourScheme;
79 import jalview.ws.jws1.Discoverer;
80 import jalview.ws.jws2.Jws2Discoverer;
81 import jalview.ws.jws2.jabaws2.Jws2Instance;
82 import jalview.ws.seqfetcher.DbSourceProxy;
84 import java.awt.BorderLayout;
85 import java.awt.Color;
86 import java.awt.Component;
87 import java.awt.GridLayout;
88 import java.awt.Rectangle;
89 import java.awt.Toolkit;
90 import java.awt.datatransfer.Clipboard;
91 import java.awt.datatransfer.DataFlavor;
92 import java.awt.datatransfer.StringSelection;
93 import java.awt.datatransfer.Transferable;
94 import java.awt.dnd.DnDConstants;
95 import java.awt.dnd.DropTargetDragEvent;
96 import java.awt.dnd.DropTargetDropEvent;
97 import java.awt.dnd.DropTargetEvent;
98 import java.awt.dnd.DropTargetListener;
99 import java.awt.event.ActionEvent;
100 import java.awt.event.ActionListener;
101 import java.awt.event.KeyAdapter;
102 import java.awt.event.KeyEvent;
103 import java.awt.event.MouseAdapter;
104 import java.awt.event.MouseEvent;
105 import java.awt.print.PageFormat;
106 import java.awt.print.PrinterJob;
107 import java.beans.PropertyChangeEvent;
110 import java.util.ArrayList;
111 import java.util.Enumeration;
112 import java.util.Hashtable;
113 import java.util.List;
114 import java.util.Vector;
116 import javax.swing.JButton;
117 import javax.swing.JEditorPane;
118 import javax.swing.JInternalFrame;
119 import javax.swing.JLabel;
120 import javax.swing.JLayeredPane;
121 import javax.swing.JMenu;
122 import javax.swing.JMenuItem;
123 import javax.swing.JOptionPane;
124 import javax.swing.JPanel;
125 import javax.swing.JProgressBar;
126 import javax.swing.JRadioButtonMenuItem;
127 import javax.swing.JScrollPane;
128 import javax.swing.SwingUtilities;
134 * @version $Revision$
136 public class AlignFrame extends GAlignFrame implements DropTargetListener,
141 public static final int DEFAULT_WIDTH = 700;
144 public static final int DEFAULT_HEIGHT = 500;
146 public AlignmentPanel alignPanel;
148 AlignViewport viewport;
150 public AlignViewControllerI avc;
153 Vector alignPanels = new Vector();
156 * Last format used to load or save alignments in this window
158 String currentFileFormat = null;
161 * Current filename for this alignment
163 String fileName = null;
166 * Creates a new AlignFrame object with specific width and height.
172 public AlignFrame(AlignmentI al, int width, int height)
174 this(al, null, width, height);
178 * Creates a new AlignFrame object with specific width, height and
184 * @param sequenceSetId
186 public AlignFrame(AlignmentI al, int width, int height,
187 String sequenceSetId)
189 this(al, null, width, height, sequenceSetId);
193 * Creates a new AlignFrame object with specific width, height and
199 * @param sequenceSetId
202 public AlignFrame(AlignmentI al, int width, int height,
203 String sequenceSetId, String viewId)
205 this(al, null, width, height, sequenceSetId, viewId);
209 * new alignment window with hidden columns
213 * @param hiddenColumns
214 * ColumnSelection or null
216 * Width of alignment frame
220 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
221 int width, int height)
223 this(al, hiddenColumns, width, height, null);
227 * Create alignment frame for al with hiddenColumns, a specific width and
228 * height, and specific sequenceId
231 * @param hiddenColumns
234 * @param sequenceSetId
237 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
238 int width, int height, String sequenceSetId)
240 this(al, hiddenColumns, width, height, sequenceSetId, null);
244 * Create alignment frame for al with hiddenColumns, a specific width and
245 * height, and specific sequenceId
248 * @param hiddenColumns
251 * @param sequenceSetId
256 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
257 int width, int height, String sequenceSetId, String viewId)
259 setSize(width, height);
260 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
262 alignPanel = new AlignmentPanel(this, viewport);
264 if (al.getDataset() == null)
269 addAlignmentPanel(alignPanel, true);
274 * Make a new AlignFrame from exisiting alignmentPanels
281 public AlignFrame(AlignmentPanel ap)
285 addAlignmentPanel(ap, false);
290 * initalise the alignframe from the underlying viewport data and the
295 avc = new jalview.controller.AlignViewController(viewport, alignPanel);
296 if (viewport.getAlignmentConservationAnnotation() == null)
298 BLOSUM62Colour.setEnabled(false);
299 conservationMenuItem.setEnabled(false);
300 modifyConservation.setEnabled(false);
301 // PIDColour.setEnabled(false);
302 // abovePIDThreshold.setEnabled(false);
303 // modifyPID.setEnabled(false);
306 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
309 if (sortby.equals("Id"))
311 sortIDMenuItem_actionPerformed(null);
313 else if (sortby.equals("Pairwise Identity"))
315 sortPairwiseMenuItem_actionPerformed(null);
318 if (Desktop.desktop != null)
320 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
321 addServiceListeners();
322 setGUINucleotide(viewport.getAlignment().isNucleotide());
325 setMenusFromViewport(viewport);
326 buildSortByAnnotationScoresMenu();
327 if (viewport.wrapAlignment)
329 wrapMenuItem_actionPerformed(null);
332 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
334 this.overviewMenuItem_actionPerformed(null);
342 * Change the filename and format for the alignment, and enable the 'reload'
343 * button functionality.
350 public void setFileName(String file, String format)
353 currentFileFormat = format;
354 reload.setEnabled(true);
357 void addKeyListener()
359 addKeyListener(new KeyAdapter()
362 public void keyPressed(KeyEvent evt)
364 if (viewport.cursorMode
365 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
366 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
367 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
368 && Character.isDigit(evt.getKeyChar()))
369 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
371 switch (evt.getKeyCode())
374 case 27: // escape key
375 deselectAllSequenceMenuItem_actionPerformed(null);
379 case KeyEvent.VK_DOWN:
380 if (evt.isAltDown() || !viewport.cursorMode)
381 moveSelectedSequences(false);
382 if (viewport.cursorMode)
383 alignPanel.seqPanel.moveCursor(0, 1);
387 if (evt.isAltDown() || !viewport.cursorMode)
388 moveSelectedSequences(true);
389 if (viewport.cursorMode)
390 alignPanel.seqPanel.moveCursor(0, -1);
394 case KeyEvent.VK_LEFT:
395 if (evt.isAltDown() || !viewport.cursorMode)
396 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
398 alignPanel.seqPanel.moveCursor(-1, 0);
402 case KeyEvent.VK_RIGHT:
403 if (evt.isAltDown() || !viewport.cursorMode)
404 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
406 alignPanel.seqPanel.moveCursor(1, 0);
409 case KeyEvent.VK_SPACE:
410 if (viewport.cursorMode)
412 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
413 || evt.isShiftDown() || evt.isAltDown());
417 // case KeyEvent.VK_A:
418 // if (viewport.cursorMode)
420 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
421 // //System.out.println("A");
425 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
426 * System.out.println("closing bracket"); } break;
428 case KeyEvent.VK_DELETE:
429 case KeyEvent.VK_BACK_SPACE:
430 if (!viewport.cursorMode)
432 cut_actionPerformed(null);
436 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
437 || evt.isShiftDown() || evt.isAltDown());
443 if (viewport.cursorMode)
445 alignPanel.seqPanel.setCursorRow();
449 if (viewport.cursorMode && !evt.isControlDown())
451 alignPanel.seqPanel.setCursorColumn();
455 if (viewport.cursorMode)
457 alignPanel.seqPanel.setCursorPosition();
461 case KeyEvent.VK_ENTER:
462 case KeyEvent.VK_COMMA:
463 if (viewport.cursorMode)
465 alignPanel.seqPanel.setCursorRowAndColumn();
470 if (viewport.cursorMode)
472 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
476 if (viewport.cursorMode)
478 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
483 viewport.cursorMode = !viewport.cursorMode;
484 statusBar.setText("Keyboard editing mode is "
485 + (viewport.cursorMode ? "on" : "off"));
486 if (viewport.cursorMode)
488 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
489 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
491 alignPanel.seqPanel.seqCanvas.repaint();
497 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
498 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
500 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
502 javax.help.HelpBroker hb = hs.createHelpBroker();
503 hb.setCurrentID("home");
504 hb.setDisplayed(true);
505 } catch (Exception ex)
507 ex.printStackTrace();
512 boolean toggleSeqs = !evt.isControlDown();
513 boolean toggleCols = !evt.isShiftDown();
514 toggleHiddenRegions(toggleSeqs, toggleCols);
517 case KeyEvent.VK_PAGE_UP:
518 if (viewport.wrapAlignment)
520 alignPanel.scrollUp(true);
524 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
525 - viewport.endSeq + viewport.startSeq);
528 case KeyEvent.VK_PAGE_DOWN:
529 if (viewport.wrapAlignment)
531 alignPanel.scrollUp(false);
535 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
536 + viewport.endSeq - viewport.startSeq);
543 public void keyReleased(KeyEvent evt)
545 switch (evt.getKeyCode())
547 case KeyEvent.VK_LEFT:
548 if (evt.isAltDown() || !viewport.cursorMode)
549 viewport.firePropertyChange("alignment", null, viewport
550 .getAlignment().getSequences());
553 case KeyEvent.VK_RIGHT:
554 if (evt.isAltDown() || !viewport.cursorMode)
555 viewport.firePropertyChange("alignment", null, viewport
556 .getAlignment().getSequences());
563 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
565 ap.alignFrame = this;
566 avc = new jalview.controller.AlignViewController(viewport, alignPanel);
568 alignPanels.addElement(ap);
570 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
572 int aSize = alignPanels.size();
574 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
576 if (aSize == 1 && ap.av.viewName == null)
578 this.getContentPane().add(ap, BorderLayout.CENTER);
584 setInitialTabVisible();
587 expandViews.setEnabled(true);
588 gatherViews.setEnabled(true);
589 tabbedPane.addTab(ap.av.viewName, ap);
591 ap.setVisible(false);
596 if (ap.av.isPadGaps())
598 ap.av.getAlignment().padGaps();
600 ap.av.updateConservation(ap);
601 ap.av.updateConsensus(ap);
602 ap.av.updateStrucConsensus(ap);
606 public void setInitialTabVisible()
608 expandViews.setEnabled(true);
609 gatherViews.setEnabled(true);
610 tabbedPane.setVisible(true);
611 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
612 tabbedPane.addTab(first.av.viewName, first);
613 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
616 public AlignViewport getViewport()
621 /* Set up intrinsic listeners for dynamically generated GUI bits. */
622 private void addServiceListeners()
624 final java.beans.PropertyChangeListener thisListener;
625 Desktop.instance.addJalviewPropertyChangeListener("services",
626 thisListener = new java.beans.PropertyChangeListener()
629 public void propertyChange(PropertyChangeEvent evt)
631 // // System.out.println("Discoverer property change.");
632 // if (evt.getPropertyName().equals("services"))
634 SwingUtilities.invokeLater(new Runnable()
641 .println("Rebuild WS Menu for service change");
642 BuildWebServiceMenu();
649 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
652 public void internalFrameClosed(
653 javax.swing.event.InternalFrameEvent evt)
655 System.out.println("deregistering discoverer listener");
656 Desktop.instance.removeJalviewPropertyChangeListener("services",
658 closeMenuItem_actionPerformed(true);
661 // Finally, build the menu once to get current service state
662 new Thread(new Runnable()
667 BuildWebServiceMenu();
672 public void setGUINucleotide(boolean nucleotide)
674 showTranslation.setVisible(nucleotide);
675 conservationMenuItem.setEnabled(!nucleotide);
676 modifyConservation.setEnabled(!nucleotide);
677 showGroupConservation.setEnabled(!nucleotide);
678 rnahelicesColour.setEnabled(nucleotide);
679 purinePyrimidineColour.setEnabled(nucleotide);
680 // Remember AlignFrame always starts as protein
684 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
689 * set up menus for the currently viewport. This may be called after any
690 * operation that affects the data in the current view (selection changed,
691 * etc) to update the menus to reflect the new state.
693 public void setMenusForViewport()
695 setMenusFromViewport(viewport);
699 * Need to call this method when tabs are selected for multiple views, or when
700 * loading from Jalview2XML.java
705 void setMenusFromViewport(AlignViewport av)
707 padGapsMenuitem.setSelected(av.isPadGaps());
708 colourTextMenuItem.setSelected(av.showColourText);
709 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
710 conservationMenuItem.setSelected(av.getConservationSelected());
711 seqLimits.setSelected(av.getShowJVSuffix());
712 idRightAlign.setSelected(av.rightAlignIds);
713 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
714 renderGapsMenuItem.setSelected(av.renderGaps);
715 wrapMenuItem.setSelected(av.wrapAlignment);
716 scaleAbove.setVisible(av.wrapAlignment);
717 scaleLeft.setVisible(av.wrapAlignment);
718 scaleRight.setVisible(av.wrapAlignment);
719 annotationPanelMenuItem.setState(av.showAnnotation);
720 viewBoxesMenuItem.setSelected(av.showBoxes);
721 viewTextMenuItem.setSelected(av.showText);
722 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
723 showGroupConsensus.setSelected(av.isShowGroupConsensus());
724 showGroupConservation.setSelected(av.isShowGroupConservation());
725 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
726 showSequenceLogo.setSelected(av.isShowSequenceLogo());
727 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
729 setColourSelected(ColourSchemeProperty.getColourName(av
730 .getGlobalColourScheme()));
732 showSeqFeatures.setSelected(av.showSequenceFeatures);
733 hiddenMarkers.setState(av.showHiddenMarkers);
734 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
735 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
736 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
737 autoCalculate.setSelected(av.autoCalculateConsensus);
738 sortByTree.setSelected(av.sortByTree);
739 listenToViewSelections.setSelected(av.followSelection);
740 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
742 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
743 setShowProductsEnabled();
747 // methods for implementing IProgressIndicator
748 // need to refactor to a reusable stub class
749 Hashtable progressBars, progressBarHandlers;
754 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
757 public void setProgressBar(String message, long id)
759 if (progressBars == null)
761 progressBars = new Hashtable();
762 progressBarHandlers = new Hashtable();
765 JPanel progressPanel;
766 Long lId = new Long(id);
767 GridLayout layout = (GridLayout) statusPanel.getLayout();
768 if (progressBars.get(lId) != null)
770 progressPanel = (JPanel) progressBars.get(new Long(id));
771 statusPanel.remove(progressPanel);
772 progressBars.remove(lId);
773 progressPanel = null;
776 statusBar.setText(message);
778 if (progressBarHandlers.contains(lId))
780 progressBarHandlers.remove(lId);
782 layout.setRows(layout.getRows() - 1);
786 progressPanel = new JPanel(new BorderLayout(10, 5));
788 JProgressBar progressBar = new JProgressBar();
789 progressBar.setIndeterminate(true);
791 progressPanel.add(new JLabel(message), BorderLayout.WEST);
792 progressPanel.add(progressBar, BorderLayout.CENTER);
794 layout.setRows(layout.getRows() + 1);
795 statusPanel.add(progressPanel);
797 progressBars.put(lId, progressPanel);
800 // setMenusForViewport();
805 public void registerHandler(final long id,
806 final IProgressIndicatorHandler handler)
808 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
811 "call setProgressBar before registering the progress bar's handler.");
813 progressBarHandlers.put(new Long(id), handler);
814 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
815 if (handler.canCancel())
817 JButton cancel = new JButton("Cancel");
818 final IProgressIndicator us = this;
819 cancel.addActionListener(new ActionListener()
823 public void actionPerformed(ActionEvent e)
825 handler.cancelActivity(id);
828 + ((JLabel) progressPanel.getComponent(0))
832 progressPanel.add(cancel, BorderLayout.EAST);
838 * @return true if any progress bars are still active
841 public boolean operationInProgress()
843 if (progressBars != null && progressBars.size() > 0)
851 * Added so Castor Mapping file can obtain Jalview Version
853 public String getVersion()
855 return jalview.bin.Cache.getProperty("VERSION");
858 public FeatureRenderer getFeatureRenderer()
860 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
864 public void fetchSequence_actionPerformed(ActionEvent e)
866 new SequenceFetcher(this);
870 public void addFromFile_actionPerformed(ActionEvent e)
872 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
876 public void reload_actionPerformed(ActionEvent e)
878 if (fileName != null)
880 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
881 // originating file's format
882 // TODO: work out how to recover feature settings for correct view(s) when
884 if (currentFileFormat.equals("Jalview"))
886 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
887 for (int i = 0; i < frames.length; i++)
889 if (frames[i] instanceof AlignFrame && frames[i] != this
890 && ((AlignFrame) frames[i]).fileName != null
891 && ((AlignFrame) frames[i]).fileName.equals(fileName))
895 frames[i].setSelected(true);
896 Desktop.instance.closeAssociatedWindows();
897 } catch (java.beans.PropertyVetoException ex)
903 Desktop.instance.closeAssociatedWindows();
905 FileLoader loader = new FileLoader();
906 String protocol = fileName.startsWith("http:") ? "URL" : "File";
907 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
911 Rectangle bounds = this.getBounds();
913 FileLoader loader = new FileLoader();
914 String protocol = fileName.startsWith("http:") ? "URL" : "File";
915 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
916 protocol, currentFileFormat);
918 newframe.setBounds(bounds);
919 if (featureSettings != null && featureSettings.isShowing())
921 final Rectangle fspos = featureSettings.frame.getBounds();
922 // TODO: need a 'show feature settings' function that takes bounds -
923 // need to refactor Desktop.addFrame
924 newframe.featureSettings_actionPerformed(null);
925 final FeatureSettings nfs = newframe.featureSettings;
926 SwingUtilities.invokeLater(new Runnable()
931 nfs.frame.setBounds(fspos);
934 this.featureSettings.close();
935 this.featureSettings = null;
937 this.closeMenuItem_actionPerformed(true);
943 public void addFromText_actionPerformed(ActionEvent e)
945 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
949 public void addFromURL_actionPerformed(ActionEvent e)
951 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
955 public void save_actionPerformed(ActionEvent e)
958 || (currentFileFormat == null || !jalview.io.FormatAdapter
959 .isValidIOFormat(currentFileFormat, true))
960 || fileName.startsWith("http"))
962 saveAs_actionPerformed(null);
966 saveAlignment(fileName, currentFileFormat);
977 public void saveAs_actionPerformed(ActionEvent e)
979 JalviewFileChooser chooser = new JalviewFileChooser(
980 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
981 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
982 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
983 currentFileFormat, false);
985 chooser.setFileView(new JalviewFileView());
986 chooser.setDialogTitle("Save Alignment to file");
987 chooser.setToolTipText("Save");
989 int value = chooser.showSaveDialog(this);
991 if (value == JalviewFileChooser.APPROVE_OPTION)
993 currentFileFormat = chooser.getSelectedFormat();
994 if (currentFileFormat == null)
996 JOptionPane.showInternalMessageDialog(Desktop.desktop,
997 "You must select a file format before saving!",
998 "File format not specified", JOptionPane.WARNING_MESSAGE);
999 value = chooser.showSaveDialog(this);
1003 fileName = chooser.getSelectedFile().getPath();
1005 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1008 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1009 if (currentFileFormat.indexOf(" ") > -1)
1011 currentFileFormat = currentFileFormat.substring(0,
1012 currentFileFormat.indexOf(" "));
1014 saveAlignment(fileName, currentFileFormat);
1018 public boolean saveAlignment(String file, String format)
1020 boolean success = true;
1022 if (format.equalsIgnoreCase("Jalview"))
1024 String shortName = title;
1026 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1028 shortName = shortName.substring(shortName
1029 .lastIndexOf(java.io.File.separatorChar) + 1);
1032 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1034 statusBar.setText("Successfully saved to file: " + fileName + " in "
1035 + format + " format.");
1040 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1042 warningMessage("Cannot save file " + fileName + " using format "
1043 + format, "Alignment output format not supported");
1044 saveAs_actionPerformed(null);
1045 // JBPNote need to have a raise_gui flag here
1049 String[] omitHidden = null;
1051 if (viewport.hasHiddenColumns())
1053 int reply = JOptionPane
1054 .showInternalConfirmDialog(
1056 "The Alignment contains hidden columns."
1057 + "\nDo you want to save only the visible alignment?",
1058 "Save / Omit Hidden Columns",
1059 JOptionPane.YES_NO_OPTION,
1060 JOptionPane.QUESTION_MESSAGE);
1062 if (reply == JOptionPane.YES_OPTION)
1064 omitHidden = viewport.getViewAsString(false);
1067 FormatAdapter f = new FormatAdapter();
1068 String output = f.formatSequences(format,
1069 viewport.getAlignment(), // class cast exceptions will
1070 // occur in the distant future
1071 omitHidden, f.getCacheSuffixDefault(format),
1072 viewport.getColumnSelection());
1082 java.io.PrintWriter out = new java.io.PrintWriter(
1083 new java.io.FileWriter(file));
1087 this.setTitle(file);
1088 statusBar.setText("Successfully saved to file: " + fileName
1089 + " in " + format + " format.");
1090 } catch (Exception ex)
1093 ex.printStackTrace();
1100 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1101 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1107 private void warningMessage(String warning, String title)
1109 if (new jalview.util.Platform().isHeadless())
1111 System.err.println("Warning: " + title + "\nWarning: " + warning);
1116 JOptionPane.showInternalMessageDialog(this, warning, title,
1117 JOptionPane.WARNING_MESSAGE);
1129 protected void outputText_actionPerformed(ActionEvent e)
1131 String[] omitHidden = null;
1133 if (viewport.hasHiddenColumns())
1135 int reply = JOptionPane
1136 .showInternalConfirmDialog(
1138 "The Alignment contains hidden columns."
1139 + "\nDo you want to output only the visible alignment?",
1140 "Save / Omit Hidden Columns",
1141 JOptionPane.YES_NO_OPTION,
1142 JOptionPane.QUESTION_MESSAGE);
1144 if (reply == JOptionPane.YES_OPTION)
1146 omitHidden = viewport.getViewAsString(false);
1150 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1151 cap.setForInput(null);
1155 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1156 viewport.getAlignment(), omitHidden,
1157 viewport.getColumnSelection()));
1158 Desktop.addInternalFrame(cap,
1159 "Alignment output - " + e.getActionCommand(), 600, 500);
1160 } catch (OutOfMemoryError oom)
1162 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1175 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1177 new HTMLOutput(alignPanel,
1178 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1179 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1182 public void createImageMap(File file, String image)
1184 alignPanel.makePNGImageMap(file, image);
1194 public void createPNG(File f)
1196 alignPanel.makePNG(f);
1206 public void createEPS(File f)
1208 alignPanel.makeEPS(f);
1212 public void pageSetup_actionPerformed(ActionEvent e)
1214 PrinterJob printJob = PrinterJob.getPrinterJob();
1215 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1225 public void printMenuItem_actionPerformed(ActionEvent e)
1227 // Putting in a thread avoids Swing painting problems
1228 PrintThread thread = new PrintThread(alignPanel);
1233 public void exportFeatures_actionPerformed(ActionEvent e)
1235 new AnnotationExporter().exportFeatures(alignPanel);
1239 public void exportAnnotations_actionPerformed(ActionEvent e)
1241 new AnnotationExporter().exportAnnotations(alignPanel,
1242 viewport.showAnnotation ? viewport.getAlignment()
1243 .getAlignmentAnnotation() : null, viewport
1244 .getAlignment().getGroups(), ((Alignment) viewport
1245 .getAlignment()).alignmentProperties);
1249 public void associatedData_actionPerformed(ActionEvent e)
1251 // Pick the tree file
1252 JalviewFileChooser chooser = new JalviewFileChooser(
1253 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1254 chooser.setFileView(new JalviewFileView());
1255 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1256 chooser.setToolTipText("Load Jalview Annotations / Features file");
1258 int value = chooser.showOpenDialog(null);
1260 if (value == JalviewFileChooser.APPROVE_OPTION)
1262 String choice = chooser.getSelectedFile().getPath();
1263 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1264 loadJalviewDataFile(choice, null, null, null);
1270 * Close the current view or all views in the alignment frame. If the frame
1271 * only contains one view then the alignment will be removed from memory.
1273 * @param closeAllTabs
1276 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1278 if (alignPanels != null && alignPanels.size() < 2)
1280 closeAllTabs = true;
1285 if (alignPanels != null)
1289 if (this.isClosed())
1291 // really close all the windows - otherwise wait till
1292 // setClosed(true) is called
1293 for (int i = 0; i < alignPanels.size(); i++)
1295 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1302 closeView(alignPanel);
1308 this.setClosed(true);
1310 } catch (Exception ex)
1312 ex.printStackTrace();
1317 * close alignPanel2 and shuffle tabs appropriately.
1319 * @param alignPanel2
1321 public void closeView(AlignmentPanel alignPanel2)
1323 int index = tabbedPane.getSelectedIndex();
1324 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1325 alignPanels.removeElement(alignPanel2);
1327 // if (viewport == alignPanel2.av)
1331 alignPanel2.closePanel();
1334 tabbedPane.removeTabAt(closedindex);
1335 tabbedPane.validate();
1337 if (index > closedindex || index == tabbedPane.getTabCount())
1339 // modify currently selected tab index if necessary.
1343 this.tabSelectionChanged(index);
1349 void updateEditMenuBar()
1352 if (viewport.historyList.size() > 0)
1354 undoMenuItem.setEnabled(true);
1355 CommandI command = (CommandI) viewport.historyList.peek();
1356 undoMenuItem.setText("Undo " + command.getDescription());
1360 undoMenuItem.setEnabled(false);
1361 undoMenuItem.setText("Undo");
1364 if (viewport.redoList.size() > 0)
1366 redoMenuItem.setEnabled(true);
1368 CommandI command = (CommandI) viewport.redoList.peek();
1369 redoMenuItem.setText("Redo " + command.getDescription());
1373 redoMenuItem.setEnabled(false);
1374 redoMenuItem.setText("Redo");
1378 public void addHistoryItem(CommandI command)
1380 if (command.getSize() > 0)
1382 viewport.historyList.push(command);
1383 viewport.redoList.clear();
1384 updateEditMenuBar();
1385 viewport.updateHiddenColumns();
1386 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1387 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1388 // viewport.getColumnSelection()
1389 // .getHiddenColumns().size() > 0);
1395 * @return alignment objects for all views
1397 AlignmentI[] getViewAlignments()
1399 if (alignPanels != null)
1401 Enumeration e = alignPanels.elements();
1402 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1403 for (int i = 0; e.hasMoreElements(); i++)
1405 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1409 if (viewport != null)
1411 return new AlignmentI[]
1412 { viewport.getAlignment() };
1424 protected void undoMenuItem_actionPerformed(ActionEvent e)
1426 if (viewport.historyList.empty())
1428 CommandI command = (CommandI) viewport.historyList.pop();
1429 viewport.redoList.push(command);
1430 command.undoCommand(getViewAlignments());
1432 AlignViewport originalSource = getOriginatingSource(command);
1433 updateEditMenuBar();
1435 if (originalSource != null)
1437 if (originalSource != viewport)
1440 .warn("Implementation worry: mismatch of viewport origin for undo");
1442 originalSource.updateHiddenColumns();
1443 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1445 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1446 // viewport.getColumnSelection()
1447 // .getHiddenColumns().size() > 0);
1448 originalSource.firePropertyChange("alignment", null, originalSource
1449 .getAlignment().getSequences());
1460 protected void redoMenuItem_actionPerformed(ActionEvent e)
1462 if (viewport.redoList.size() < 1)
1467 CommandI command = (CommandI) viewport.redoList.pop();
1468 viewport.historyList.push(command);
1469 command.doCommand(getViewAlignments());
1471 AlignViewport originalSource = getOriginatingSource(command);
1472 updateEditMenuBar();
1474 if (originalSource != null)
1477 if (originalSource != viewport)
1480 .warn("Implementation worry: mismatch of viewport origin for redo");
1482 originalSource.updateHiddenColumns();
1483 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1485 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1486 // viewport.getColumnSelection()
1487 // .getHiddenColumns().size() > 0);
1488 originalSource.firePropertyChange("alignment", null, originalSource
1489 .getAlignment().getSequences());
1493 AlignViewport getOriginatingSource(CommandI command)
1495 AlignViewport originalSource = null;
1496 // For sequence removal and addition, we need to fire
1497 // the property change event FROM the viewport where the
1498 // original alignment was altered
1499 AlignmentI al = null;
1500 if (command instanceof EditCommand)
1502 EditCommand editCommand = (EditCommand) command;
1503 al = editCommand.getAlignment();
1504 Vector comps = (Vector) PaintRefresher.components.get(viewport
1505 .getSequenceSetId());
1507 for (int i = 0; i < comps.size(); i++)
1509 if (comps.elementAt(i) instanceof AlignmentPanel)
1511 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1513 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1520 if (originalSource == null)
1522 // The original view is closed, we must validate
1523 // the current view against the closed view first
1526 PaintRefresher.validateSequences(al, viewport.getAlignment());
1529 originalSource = viewport;
1532 return originalSource;
1541 public void moveSelectedSequences(boolean up)
1543 SequenceGroup sg = viewport.getSelectionGroup();
1549 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1550 viewport.getHiddenRepSequences(), up);
1551 alignPanel.paintAlignment(true);
1554 synchronized void slideSequences(boolean right, int size)
1556 List<SequenceI> sg = new Vector();
1557 if (viewport.cursorMode)
1559 sg.add(viewport.getAlignment().getSequenceAt(
1560 alignPanel.seqPanel.seqCanvas.cursorY));
1562 else if (viewport.getSelectionGroup() != null
1563 && viewport.getSelectionGroup().getSize() != viewport
1564 .getAlignment().getHeight())
1566 sg = viewport.getSelectionGroup().getSequences(
1567 viewport.getHiddenRepSequences());
1575 Vector invertGroup = new Vector();
1577 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1579 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1580 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1583 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1585 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1586 for (int i = 0; i < invertGroup.size(); i++)
1587 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1589 SlideSequencesCommand ssc;
1591 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1592 size, viewport.getGapCharacter());
1594 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1595 size, viewport.getGapCharacter());
1597 int groupAdjustment = 0;
1598 if (ssc.getGapsInsertedBegin() && right)
1600 if (viewport.cursorMode)
1601 alignPanel.seqPanel.moveCursor(size, 0);
1603 groupAdjustment = size;
1605 else if (!ssc.getGapsInsertedBegin() && !right)
1607 if (viewport.cursorMode)
1608 alignPanel.seqPanel.moveCursor(-size, 0);
1610 groupAdjustment = -size;
1613 if (groupAdjustment != 0)
1615 viewport.getSelectionGroup().setStartRes(
1616 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1617 viewport.getSelectionGroup().setEndRes(
1618 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1621 boolean appendHistoryItem = false;
1622 if (viewport.historyList != null && viewport.historyList.size() > 0
1623 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1625 appendHistoryItem = ssc
1626 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1630 if (!appendHistoryItem)
1631 addHistoryItem(ssc);
1643 protected void copy_actionPerformed(ActionEvent e)
1646 if (viewport.getSelectionGroup() == null)
1650 // TODO: preserve the ordering of displayed alignment annotation in any
1651 // internal paste (particularly sequence associated annotation)
1652 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1653 String[] omitHidden = null;
1655 if (viewport.hasHiddenColumns())
1657 omitHidden = viewport.getViewAsString(true);
1660 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1663 StringSelection ss = new StringSelection(output);
1667 jalview.gui.Desktop.internalCopy = true;
1668 // Its really worth setting the clipboard contents
1669 // to empty before setting the large StringSelection!!
1670 Toolkit.getDefaultToolkit().getSystemClipboard()
1671 .setContents(new StringSelection(""), null);
1673 Toolkit.getDefaultToolkit().getSystemClipboard()
1674 .setContents(ss, Desktop.instance);
1675 } catch (OutOfMemoryError er)
1677 new OOMWarning("copying region", er);
1681 Vector hiddenColumns = null;
1682 if (viewport.hasHiddenColumns())
1684 hiddenColumns = new Vector();
1685 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1686 .getSelectionGroup().getEndRes();
1687 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1690 int[] region = (int[]) viewport.getColumnSelection()
1691 .getHiddenColumns().elementAt(i);
1692 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1694 hiddenColumns.addElement(new int[]
1695 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1700 Desktop.jalviewClipboard = new Object[]
1701 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1702 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1712 protected void pasteNew_actionPerformed(ActionEvent e)
1724 protected void pasteThis_actionPerformed(ActionEvent e)
1730 * Paste contents of Jalview clipboard
1732 * @param newAlignment
1733 * true to paste to a new alignment, otherwise add to this.
1735 void paste(boolean newAlignment)
1737 boolean externalPaste = true;
1740 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1741 Transferable contents = c.getContents(this);
1743 if (contents == null)
1751 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1752 if (str.length() < 1)
1757 format = new IdentifyFile().Identify(str, "Paste");
1759 } catch (OutOfMemoryError er)
1761 new OOMWarning("Out of memory pasting sequences!!", er);
1765 SequenceI[] sequences;
1766 boolean annotationAdded = false;
1767 AlignmentI alignment = null;
1769 if (Desktop.jalviewClipboard != null)
1771 // The clipboard was filled from within Jalview, we must use the
1773 // And dataset from the copied alignment
1774 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1775 // be doubly sure that we create *new* sequence objects.
1776 sequences = new SequenceI[newseq.length];
1777 for (int i = 0; i < newseq.length; i++)
1779 sequences[i] = new Sequence(newseq[i]);
1781 alignment = new Alignment(sequences);
1782 externalPaste = false;
1786 // parse the clipboard as an alignment.
1787 alignment = new FormatAdapter().readFile(str, "Paste", format);
1788 sequences = alignment.getSequencesArray();
1792 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1798 if (Desktop.jalviewClipboard != null)
1800 // dataset is inherited
1801 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1805 // new dataset is constructed
1806 alignment.setDataset(null);
1808 alwidth = alignment.getWidth() + 1;
1812 AlignmentI pastedal = alignment; // preserve pasted alignment object
1813 // Add pasted sequences and dataset into existing alignment.
1814 alignment = viewport.getAlignment();
1815 alwidth = alignment.getWidth() + 1;
1816 // decide if we need to import sequences from an existing dataset
1817 boolean importDs = Desktop.jalviewClipboard != null
1818 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1819 // importDs==true instructs us to copy over new dataset sequences from
1820 // an existing alignment
1821 Vector newDs = (importDs) ? new Vector() : null; // used to create
1822 // minimum dataset set
1824 for (int i = 0; i < sequences.length; i++)
1828 newDs.addElement(null);
1830 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1832 if (importDs && ds != null)
1834 if (!newDs.contains(ds))
1836 newDs.setElementAt(ds, i);
1837 ds = new Sequence(ds);
1838 // update with new dataset sequence
1839 sequences[i].setDatasetSequence(ds);
1843 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1848 // copy and derive new dataset sequence
1849 sequences[i] = sequences[i].deriveSequence();
1850 alignment.getDataset().addSequence(
1851 sequences[i].getDatasetSequence());
1852 // TODO: avoid creation of duplicate dataset sequences with a
1853 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1855 alignment.addSequence(sequences[i]); // merges dataset
1859 newDs.clear(); // tidy up
1861 if (alignment.getAlignmentAnnotation() != null)
1863 for (AlignmentAnnotation alan : alignment
1864 .getAlignmentAnnotation())
1866 if (alan.graphGroup > fgroup)
1868 fgroup = alan.graphGroup;
1872 if (pastedal.getAlignmentAnnotation() != null)
1874 // Add any annotation attached to alignment.
1875 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1876 for (int i = 0; i < alann.length; i++)
1878 annotationAdded = true;
1879 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1881 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1882 if (newann.graphGroup > -1)
1884 if (newGraphGroups.size() <= newann.graphGroup
1885 || newGraphGroups.get(newann.graphGroup) == null)
1887 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1889 newGraphGroups.add(q, null);
1891 newGraphGroups.set(newann.graphGroup, new Integer(
1894 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1898 newann.padAnnotation(alwidth);
1899 alignment.addAnnotation(newann);
1909 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1910 sequences, 0, alignment.getWidth(), alignment));
1912 // Add any annotations attached to sequences
1913 for (int i = 0; i < sequences.length; i++)
1915 if (sequences[i].getAnnotation() != null)
1917 AlignmentAnnotation newann;
1918 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1920 annotationAdded = true;
1921 newann = sequences[i].getAnnotation()[a];
1922 newann.adjustForAlignment();
1923 newann.padAnnotation(alwidth);
1924 if (newann.graphGroup > -1)
1926 if (newann.graphGroup > -1)
1928 if (newGraphGroups.size() <= newann.graphGroup
1929 || newGraphGroups.get(newann.graphGroup) == null)
1931 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1933 newGraphGroups.add(q, null);
1935 newGraphGroups.set(newann.graphGroup, new Integer(
1938 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1942 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1947 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1954 // propagate alignment changed.
1955 viewport.setEndSeq(alignment.getHeight());
1956 if (annotationAdded)
1958 // Duplicate sequence annotation in all views.
1959 AlignmentI[] alview = this.getViewAlignments();
1960 for (int i = 0; i < sequences.length; i++)
1962 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1965 for (int avnum = 0; avnum < alview.length; avnum++)
1967 if (alview[avnum] != alignment)
1969 // duplicate in a view other than the one with input focus
1970 int avwidth = alview[avnum].getWidth() + 1;
1971 // this relies on sann being preserved after we
1972 // modify the sequence's annotation array for each duplication
1973 for (int a = 0; a < sann.length; a++)
1975 AlignmentAnnotation newann = new AlignmentAnnotation(
1977 sequences[i].addAlignmentAnnotation(newann);
1978 newann.padAnnotation(avwidth);
1979 alview[avnum].addAnnotation(newann); // annotation was
1980 // duplicated earlier
1981 // TODO JAL-1145 graphGroups are not updated for sequence
1982 // annotation added to several views. This may cause
1984 alview[avnum].setAnnotationIndex(newann, a);
1989 buildSortByAnnotationScoresMenu();
1991 viewport.firePropertyChange("alignment", null,
1992 alignment.getSequences());
1993 if (alignPanels != null)
1995 for (AlignmentPanel ap : ((Vector<AlignmentPanel>) alignPanels))
1997 ap.validateAnnotationDimensions(false);
2002 alignPanel.validateAnnotationDimensions(false);
2008 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2010 String newtitle = new String("Copied sequences");
2012 if (Desktop.jalviewClipboard != null
2013 && Desktop.jalviewClipboard[2] != null)
2015 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2016 for (int i = 0; i < hc.size(); i++)
2018 int[] region = (int[]) hc.elementAt(i);
2019 af.viewport.hideColumns(region[0], region[1]);
2023 // >>>This is a fix for the moment, until a better solution is
2025 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2027 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2029 // TODO: maintain provenance of an alignment, rather than just make the
2030 // title a concatenation of operations.
2033 if (title.startsWith("Copied sequences"))
2039 newtitle = newtitle.concat("- from " + title);
2044 newtitle = new String("Pasted sequences");
2047 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2052 } catch (Exception ex)
2054 ex.printStackTrace();
2055 System.out.println("Exception whilst pasting: " + ex);
2056 // could be anything being pasted in here
2068 protected void cut_actionPerformed(ActionEvent e)
2070 copy_actionPerformed(null);
2071 delete_actionPerformed(null);
2081 protected void delete_actionPerformed(ActionEvent evt)
2084 SequenceGroup sg = viewport.getSelectionGroup();
2090 Vector seqs = new Vector();
2092 for (int i = 0; i < sg.getSize(); i++)
2094 seq = sg.getSequenceAt(i);
2095 seqs.addElement(seq);
2098 // If the cut affects all sequences, remove highlighted columns
2099 if (sg.getSize() == viewport.getAlignment().getHeight())
2101 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2102 sg.getEndRes() + 1);
2105 SequenceI[] cut = new SequenceI[seqs.size()];
2106 for (int i = 0; i < seqs.size(); i++)
2108 cut[i] = (SequenceI) seqs.elementAt(i);
2112 * //ADD HISTORY ITEM
2114 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2115 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2116 viewport.getAlignment()));
2118 viewport.setSelectionGroup(null);
2119 viewport.sendSelection();
2120 viewport.getAlignment().deleteGroup(sg);
2122 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2124 if (viewport.getAlignment().getHeight() < 1)
2128 this.setClosed(true);
2129 } catch (Exception ex)
2142 protected void deleteGroups_actionPerformed(ActionEvent e)
2144 if (avc.deleteGroups()) {
2145 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2146 alignPanel.updateAnnotation();
2147 alignPanel.paintAlignment(true);
2158 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2160 SequenceGroup sg = new SequenceGroup();
2162 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2164 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2167 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2168 viewport.setSelectionGroup(sg);
2169 viewport.sendSelection();
2170 alignPanel.paintAlignment(true);
2171 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2181 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2183 if (viewport.cursorMode)
2185 alignPanel.seqPanel.keyboardNo1 = null;
2186 alignPanel.seqPanel.keyboardNo2 = null;
2188 viewport.setSelectionGroup(null);
2189 viewport.getColumnSelection().clear();
2190 viewport.setSelectionGroup(null);
2191 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2192 alignPanel.idPanel.idCanvas.searchResults = null;
2193 alignPanel.paintAlignment(true);
2194 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2195 viewport.sendSelection();
2205 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2207 SequenceGroup sg = viewport.getSelectionGroup();
2211 selectAllSequenceMenuItem_actionPerformed(null);
2216 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2218 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2221 alignPanel.paintAlignment(true);
2222 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2223 viewport.sendSelection();
2227 public void invertColSel_actionPerformed(ActionEvent e)
2229 viewport.invertColumnSelection();
2230 alignPanel.paintAlignment(true);
2231 viewport.sendSelection();
2241 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2243 trimAlignment(true);
2253 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2255 trimAlignment(false);
2258 void trimAlignment(boolean trimLeft)
2260 ColumnSelection colSel = viewport.getColumnSelection();
2263 if (colSel.size() > 0)
2267 column = colSel.getMin();
2271 column = colSel.getMax();
2275 if (viewport.getSelectionGroup() != null)
2277 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2278 viewport.getHiddenRepSequences());
2282 seqs = viewport.getAlignment().getSequencesArray();
2285 TrimRegionCommand trimRegion;
2288 trimRegion = new TrimRegionCommand("Remove Left",
2289 TrimRegionCommand.TRIM_LEFT, seqs, column,
2290 viewport.getAlignment(), viewport.getColumnSelection(),
2291 viewport.getSelectionGroup());
2292 viewport.setStartRes(0);
2296 trimRegion = new TrimRegionCommand("Remove Right",
2297 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2298 viewport.getAlignment(), viewport.getColumnSelection(),
2299 viewport.getSelectionGroup());
2302 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2304 addHistoryItem(trimRegion);
2306 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2308 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2309 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2311 viewport.getAlignment().deleteGroup(sg);
2315 viewport.firePropertyChange("alignment", null, viewport
2316 .getAlignment().getSequences());
2327 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2329 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2332 if (viewport.getSelectionGroup() != null)
2334 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2335 viewport.getHiddenRepSequences());
2336 start = viewport.getSelectionGroup().getStartRes();
2337 end = viewport.getSelectionGroup().getEndRes();
2341 seqs = viewport.getAlignment().getSequencesArray();
2344 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2345 "Remove Gapped Columns", seqs, start, end,
2346 viewport.getAlignment());
2348 addHistoryItem(removeGapCols);
2350 statusBar.setText("Removed " + removeGapCols.getSize()
2351 + " empty columns.");
2353 // This is to maintain viewport position on first residue
2354 // of first sequence
2355 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2356 int startRes = seq.findPosition(viewport.startRes);
2357 // ShiftList shifts;
2358 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2359 // edit.alColumnChanges=shifts.getInverse();
2360 // if (viewport.hasHiddenColumns)
2361 // viewport.getColumnSelection().compensateForEdits(shifts);
2362 viewport.setStartRes(seq.findIndex(startRes) - 1);
2363 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2375 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2377 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2380 if (viewport.getSelectionGroup() != null)
2382 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2383 viewport.getHiddenRepSequences());
2384 start = viewport.getSelectionGroup().getStartRes();
2385 end = viewport.getSelectionGroup().getEndRes();
2389 seqs = viewport.getAlignment().getSequencesArray();
2392 // This is to maintain viewport position on first residue
2393 // of first sequence
2394 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2395 int startRes = seq.findPosition(viewport.startRes);
2397 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2398 viewport.getAlignment()));
2400 viewport.setStartRes(seq.findIndex(startRes) - 1);
2402 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2414 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2416 viewport.setPadGaps(padGapsMenuitem.isSelected());
2417 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2423 // if (justifySeqs>0)
2425 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2438 public void findMenuItem_actionPerformed(ActionEvent e)
2444 public void newView_actionPerformed(ActionEvent e)
2451 * @param copyAnnotation
2452 * if true then duplicate all annnotation, groups and settings
2453 * @return new alignment panel, already displayed.
2455 public AlignmentPanel newView(boolean copyAnnotation)
2457 return newView(null, copyAnnotation);
2463 * title of newly created view
2464 * @return new alignment panel, already displayed.
2466 public AlignmentPanel newView(String viewTitle)
2468 return newView(viewTitle, true);
2474 * title of newly created view
2475 * @param copyAnnotation
2476 * if true then duplicate all annnotation, groups and settings
2477 * @return new alignment panel, already displayed.
2479 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2481 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2483 if (!copyAnnotation)
2485 // just remove all the current annotation except for the automatic stuff
2486 newap.av.getAlignment().deleteAllGroups();
2487 for (AlignmentAnnotation alan : newap.av.getAlignment()
2488 .getAlignmentAnnotation())
2490 if (!alan.autoCalculated)
2492 newap.av.getAlignment().deleteAnnotation(alan);
2498 newap.av.gatherViewsHere = false;
2500 if (viewport.viewName == null)
2502 viewport.viewName = "Original";
2505 newap.av.historyList = viewport.historyList;
2506 newap.av.redoList = viewport.redoList;
2508 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2509 // make sure the new view has a unique name - this is essential for Jalview
2511 boolean addFirstIndex = false;
2512 if (viewTitle == null || viewTitle.trim().length() == 0)
2515 addFirstIndex = true;
2519 index = 1;// we count from 1 if given a specific name
2521 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2522 Vector comps = (Vector) PaintRefresher.components.get(viewport
2523 .getSequenceSetId());
2524 Vector existingNames = new Vector();
2525 for (int i = 0; i < comps.size(); i++)
2527 if (comps.elementAt(i) instanceof AlignmentPanel)
2529 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2530 if (!existingNames.contains(ap.av.viewName))
2532 existingNames.addElement(ap.av.viewName);
2537 while (existingNames.contains(newViewName))
2539 newViewName = viewTitle + " " + (++index);
2542 newap.av.viewName = newViewName;
2544 addAlignmentPanel(newap, true);
2546 if (alignPanels.size() == 2)
2548 viewport.gatherViewsHere = true;
2550 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2555 public void expandViews_actionPerformed(ActionEvent e)
2557 Desktop.instance.explodeViews(this);
2561 public void gatherViews_actionPerformed(ActionEvent e)
2563 Desktop.instance.gatherViews(this);
2573 public void font_actionPerformed(ActionEvent e)
2575 new FontChooser(alignPanel);
2585 protected void seqLimit_actionPerformed(ActionEvent e)
2587 viewport.setShowJVSuffix(seqLimits.isSelected());
2589 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2590 .calculateIdWidth());
2591 alignPanel.paintAlignment(true);
2595 public void idRightAlign_actionPerformed(ActionEvent e)
2597 viewport.rightAlignIds = idRightAlign.isSelected();
2598 alignPanel.paintAlignment(true);
2602 public void centreColumnLabels_actionPerformed(ActionEvent e)
2604 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2605 alignPanel.paintAlignment(true);
2611 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2614 protected void followHighlight_actionPerformed()
2616 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2618 alignPanel.scrollToPosition(
2619 alignPanel.seqPanel.seqCanvas.searchResults, false);
2630 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2632 viewport.setColourText(colourTextMenuItem.isSelected());
2633 alignPanel.paintAlignment(true);
2643 public void wrapMenuItem_actionPerformed(ActionEvent e)
2645 scaleAbove.setVisible(wrapMenuItem.isSelected());
2646 scaleLeft.setVisible(wrapMenuItem.isSelected());
2647 scaleRight.setVisible(wrapMenuItem.isSelected());
2648 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2649 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2653 public void showAllSeqs_actionPerformed(ActionEvent e)
2655 viewport.showAllHiddenSeqs();
2659 public void showAllColumns_actionPerformed(ActionEvent e)
2661 viewport.showAllHiddenColumns();
2666 public void hideSelSequences_actionPerformed(ActionEvent e)
2668 viewport.hideAllSelectedSeqs();
2669 alignPanel.paintAlignment(true);
2673 * called by key handler and the hide all/show all menu items
2678 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2681 boolean hide = false;
2682 SequenceGroup sg = viewport.getSelectionGroup();
2683 if (!toggleSeqs && !toggleCols)
2685 // Hide everything by the current selection - this is a hack - we do the
2686 // invert and then hide
2687 // first check that there will be visible columns after the invert.
2688 if ((viewport.getColumnSelection() != null
2689 && viewport.getColumnSelection().getSelected() != null && viewport
2690 .getColumnSelection().getSelected().size() > 0)
2691 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2694 // now invert the sequence set, if required - empty selection implies
2695 // that no hiding is required.
2698 invertSequenceMenuItem_actionPerformed(null);
2699 sg = viewport.getSelectionGroup();
2703 viewport.expandColSelection(sg, true);
2704 // finally invert the column selection and get the new sequence
2706 invertColSel_actionPerformed(null);
2713 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2715 hideSelSequences_actionPerformed(null);
2718 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2721 showAllSeqs_actionPerformed(null);
2727 if (viewport.getColumnSelection().getSelected().size() > 0)
2729 hideSelColumns_actionPerformed(null);
2732 viewport.setSelectionGroup(sg);
2737 showAllColumns_actionPerformed(null);
2746 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2747 * event.ActionEvent)
2750 public void hideAllButSelection_actionPerformed(ActionEvent e)
2752 toggleHiddenRegions(false, false);
2759 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2763 public void hideAllSelection_actionPerformed(ActionEvent e)
2765 SequenceGroup sg = viewport.getSelectionGroup();
2766 viewport.expandColSelection(sg, false);
2767 viewport.hideAllSelectedSeqs();
2768 viewport.hideSelectedColumns();
2769 alignPanel.paintAlignment(true);
2776 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2780 public void showAllhidden_actionPerformed(ActionEvent e)
2782 viewport.showAllHiddenColumns();
2783 viewport.showAllHiddenSeqs();
2784 alignPanel.paintAlignment(true);
2788 public void hideSelColumns_actionPerformed(ActionEvent e)
2790 viewport.hideSelectedColumns();
2791 alignPanel.paintAlignment(true);
2795 public void hiddenMarkers_actionPerformed(ActionEvent e)
2797 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2808 protected void scaleAbove_actionPerformed(ActionEvent e)
2810 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2811 alignPanel.paintAlignment(true);
2821 protected void scaleLeft_actionPerformed(ActionEvent e)
2823 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2824 alignPanel.paintAlignment(true);
2834 protected void scaleRight_actionPerformed(ActionEvent e)
2836 viewport.setScaleRightWrapped(scaleRight.isSelected());
2837 alignPanel.paintAlignment(true);
2847 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2849 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2850 alignPanel.paintAlignment(true);
2860 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2862 viewport.setShowText(viewTextMenuItem.isSelected());
2863 alignPanel.paintAlignment(true);
2873 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2875 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2876 alignPanel.paintAlignment(true);
2879 public FeatureSettings featureSettings;
2882 public void featureSettings_actionPerformed(ActionEvent e)
2884 if (featureSettings != null)
2886 featureSettings.close();
2887 featureSettings = null;
2889 if (!showSeqFeatures.isSelected())
2891 // make sure features are actually displayed
2892 showSeqFeatures.setSelected(true);
2893 showSeqFeatures_actionPerformed(null);
2895 featureSettings = new FeatureSettings(this);
2899 * Set or clear 'Show Sequence Features'
2905 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2907 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2908 alignPanel.paintAlignment(true);
2909 if (alignPanel.getOverviewPanel() != null)
2911 alignPanel.getOverviewPanel().updateOverviewImage();
2916 * Set or clear 'Show Sequence Features'
2922 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2924 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2926 if (viewport.getShowSequenceFeaturesHeight())
2928 // ensure we're actually displaying features
2929 viewport.setShowSequenceFeatures(true);
2930 showSeqFeatures.setSelected(true);
2932 alignPanel.paintAlignment(true);
2933 if (alignPanel.getOverviewPanel() != null)
2935 alignPanel.getOverviewPanel().updateOverviewImage();
2946 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2948 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2949 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2953 public void alignmentProperties()
2955 JEditorPane editPane = new JEditorPane("text/html", "");
2956 editPane.setEditable(false);
2957 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2959 editPane.setText("<html>" + contents.toString() + "</html>");
2960 JInternalFrame frame = new JInternalFrame();
2961 frame.getContentPane().add(new JScrollPane(editPane));
2963 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2964 + getTitle(), 500, 400);
2974 public void overviewMenuItem_actionPerformed(ActionEvent e)
2976 if (alignPanel.overviewPanel != null)
2981 JInternalFrame frame = new JInternalFrame();
2982 OverviewPanel overview = new OverviewPanel(alignPanel);
2983 frame.setContentPane(overview);
2984 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2985 frame.getWidth(), frame.getHeight());
2987 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2988 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2991 public void internalFrameClosed(
2992 javax.swing.event.InternalFrameEvent evt)
2994 alignPanel.setOverviewPanel(null);
2998 alignPanel.setOverviewPanel(overview);
3002 public void textColour_actionPerformed(ActionEvent e)
3004 new TextColourChooser().chooseColour(alignPanel, null);
3014 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3026 public void clustalColour_actionPerformed(ActionEvent e)
3028 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3029 viewport.getHiddenRepSequences()));
3039 public void zappoColour_actionPerformed(ActionEvent e)
3041 changeColour(new ZappoColourScheme());
3051 public void taylorColour_actionPerformed(ActionEvent e)
3053 changeColour(new TaylorColourScheme());
3063 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3065 changeColour(new HydrophobicColourScheme());
3075 public void helixColour_actionPerformed(ActionEvent e)
3077 changeColour(new HelixColourScheme());
3087 public void strandColour_actionPerformed(ActionEvent e)
3089 changeColour(new StrandColourScheme());
3099 public void turnColour_actionPerformed(ActionEvent e)
3101 changeColour(new TurnColourScheme());
3111 public void buriedColour_actionPerformed(ActionEvent e)
3113 changeColour(new BuriedColourScheme());
3123 public void nucleotideColour_actionPerformed(ActionEvent e)
3125 changeColour(new NucleotideColourScheme());
3129 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3131 changeColour(new PurinePyrimidineColourScheme());
3135 * public void covariationColour_actionPerformed(ActionEvent e) {
3137 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3141 public void annotationColour_actionPerformed(ActionEvent e)
3143 new AnnotationColourChooser(viewport, alignPanel);
3147 public void rnahelicesColour_actionPerformed(ActionEvent e)
3149 new RNAHelicesColourChooser(viewport, alignPanel);
3159 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3161 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3170 public void changeColour(ColourSchemeI cs)
3172 // TODO: compare with applet and pull up to model method
3177 if (viewport.getAbovePIDThreshold())
3179 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3182 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3184 viewport.setGlobalColourScheme(cs);
3188 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3191 if (viewport.getConservationSelected())
3194 Alignment al = (Alignment) viewport.getAlignment();
3195 Conservation c = new Conservation("All",
3196 ResidueProperties.propHash, 3, al.getSequences(), 0,
3200 c.verdict(false, viewport.getConsPercGaps());
3202 cs.setConservation(c);
3204 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3209 cs.setConservation(null);
3212 cs.setConsensus(viewport.getSequenceConsensusHash());
3215 viewport.setGlobalColourScheme(cs);
3217 if (viewport.getColourAppliesToAllGroups())
3220 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3228 if (cs instanceof ClustalxColourScheme)
3230 sg.cs = new ClustalxColourScheme(sg,
3231 viewport.getHiddenRepSequences());
3233 else if (cs instanceof UserColourScheme)
3235 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3241 sg.cs = cs.getClass().newInstance();
3242 } catch (Exception ex)
3247 if (viewport.getAbovePIDThreshold()
3248 || cs instanceof PIDColourScheme
3249 || cs instanceof Blosum62ColourScheme)
3251 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3253 sg.cs.setConsensus(AAFrequency.calculate(
3254 sg.getSequences(viewport.getHiddenRepSequences()),
3255 sg.getStartRes(), sg.getEndRes() + 1));
3259 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3262 if (viewport.getConservationSelected())
3264 Conservation c = new Conservation("Group",
3265 ResidueProperties.propHash, 3, sg.getSequences(viewport
3266 .getHiddenRepSequences()), sg.getStartRes(),
3267 sg.getEndRes() + 1);
3269 c.verdict(false, viewport.getConsPercGaps());
3270 sg.cs.setConservation(c);
3274 sg.cs.setConservation(null);
3279 if (alignPanel.getOverviewPanel() != null)
3281 alignPanel.getOverviewPanel().updateOverviewImage();
3284 alignPanel.paintAlignment(true);
3294 protected void modifyPID_actionPerformed(ActionEvent e)
3296 if (viewport.getAbovePIDThreshold()
3297 && viewport.getGlobalColourScheme() != null)
3299 SliderPanel.setPIDSliderSource(alignPanel,
3300 viewport.getGlobalColourScheme(), "Background");
3301 SliderPanel.showPIDSlider();
3312 protected void modifyConservation_actionPerformed(ActionEvent e)
3314 if (viewport.getConservationSelected()
3315 && viewport.getGlobalColourScheme() != null)
3317 SliderPanel.setConservationSlider(alignPanel,
3318 viewport.getGlobalColourScheme(), "Background");
3319 SliderPanel.showConservationSlider();
3330 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3332 viewport.setConservationSelected(conservationMenuItem.isSelected());
3334 viewport.setAbovePIDThreshold(false);
3335 abovePIDThreshold.setSelected(false);
3337 changeColour(viewport.getGlobalColourScheme());
3339 modifyConservation_actionPerformed(null);
3349 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3351 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3353 conservationMenuItem.setSelected(false);
3354 viewport.setConservationSelected(false);
3356 changeColour(viewport.getGlobalColourScheme());
3358 modifyPID_actionPerformed(null);
3368 public void userDefinedColour_actionPerformed(ActionEvent e)
3370 if (e.getActionCommand().equals("User Defined..."))
3372 new UserDefinedColours(alignPanel, null);
3376 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3377 .getUserColourSchemes().get(e.getActionCommand());
3383 public void updateUserColourMenu()
3386 Component[] menuItems = colourMenu.getMenuComponents();
3387 int i, iSize = menuItems.length;
3388 for (i = 0; i < iSize; i++)
3390 if (menuItems[i].getName() != null
3391 && menuItems[i].getName().equals("USER_DEFINED"))
3393 colourMenu.remove(menuItems[i]);
3397 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3399 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3400 .getUserColourSchemes().keys();
3402 while (userColours.hasMoreElements())
3404 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3405 userColours.nextElement().toString());
3406 radioItem.setName("USER_DEFINED");
3407 radioItem.addMouseListener(new MouseAdapter()
3410 public void mousePressed(MouseEvent evt)
3412 if (evt.isControlDown()
3413 || SwingUtilities.isRightMouseButton(evt))
3415 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3417 int option = JOptionPane.showInternalConfirmDialog(
3418 jalview.gui.Desktop.desktop,
3419 "Remove from default list?",
3420 "Remove user defined colour",
3421 JOptionPane.YES_NO_OPTION);
3422 if (option == JOptionPane.YES_OPTION)
3424 jalview.gui.UserDefinedColours
3425 .removeColourFromDefaults(radioItem.getText());
3426 colourMenu.remove(radioItem);
3430 radioItem.addActionListener(new ActionListener()
3433 public void actionPerformed(ActionEvent evt)
3435 userDefinedColour_actionPerformed(evt);
3442 radioItem.addActionListener(new ActionListener()
3445 public void actionPerformed(ActionEvent evt)
3447 userDefinedColour_actionPerformed(evt);
3451 colourMenu.insert(radioItem, 15);
3452 colours.add(radioItem);
3464 public void PIDColour_actionPerformed(ActionEvent e)
3466 changeColour(new PIDColourScheme());
3476 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3478 changeColour(new Blosum62ColourScheme());
3488 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3490 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3491 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3492 .getAlignment().getSequenceAt(0), null);
3493 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3494 viewport.getAlignment()));
3495 alignPanel.paintAlignment(true);
3505 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3507 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3508 AlignmentSorter.sortByID(viewport.getAlignment());
3509 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3510 viewport.getAlignment()));
3511 alignPanel.paintAlignment(true);
3521 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3523 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3524 AlignmentSorter.sortByLength(viewport.getAlignment());
3525 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3526 viewport.getAlignment()));
3527 alignPanel.paintAlignment(true);
3537 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3539 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3540 AlignmentSorter.sortByGroup(viewport.getAlignment());
3541 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3542 viewport.getAlignment()));
3544 alignPanel.paintAlignment(true);
3554 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3556 new RedundancyPanel(alignPanel, this);
3566 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3568 if ((viewport.getSelectionGroup() == null)
3569 || (viewport.getSelectionGroup().getSize() < 2))
3571 JOptionPane.showInternalMessageDialog(this,
3572 "You must select at least 2 sequences.", "Invalid Selection",
3573 JOptionPane.WARNING_MESSAGE);
3577 JInternalFrame frame = new JInternalFrame();
3578 frame.setContentPane(new PairwiseAlignPanel(viewport));
3579 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3590 public void PCAMenuItem_actionPerformed(ActionEvent e)
3592 if (((viewport.getSelectionGroup() != null)
3593 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3594 .getSelectionGroup().getSize() > 0))
3595 || (viewport.getAlignment().getHeight() < 4))
3597 JOptionPane.showInternalMessageDialog(this,
3598 "Principal component analysis must take\n"
3599 + "at least 4 input sequences.",
3600 "Sequence selection insufficient",
3601 JOptionPane.WARNING_MESSAGE);
3606 new PCAPanel(alignPanel);
3610 public void autoCalculate_actionPerformed(ActionEvent e)
3612 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3613 if (viewport.autoCalculateConsensus)
3615 viewport.firePropertyChange("alignment", null, viewport
3616 .getAlignment().getSequences());
3621 public void sortByTreeOption_actionPerformed(ActionEvent e)
3623 viewport.sortByTree = sortByTree.isSelected();
3627 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3629 viewport.followSelection = listenToViewSelections.isSelected();
3639 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3641 NewTreePanel("AV", "PID", "Average distance tree using PID");
3651 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3653 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3663 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3665 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3675 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3677 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3690 void NewTreePanel(String type, String pwType, String title)
3694 if (viewport.getSelectionGroup() != null
3695 && viewport.getSelectionGroup().getSize() > 0)
3697 if (viewport.getSelectionGroup().getSize() < 3)
3702 "You need to have more than two sequences selected to build a tree!",
3703 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3707 SequenceGroup sg = viewport.getSelectionGroup();
3709 /* Decide if the selection is a column region */
3710 for (SequenceI _s : sg.getSequences())
3712 if (_s.getLength() < sg.getEndRes())
3717 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3718 + "Try using the Pad function in the edit menu,\n"
3719 + "or one of the multiple sequence alignment web services.",
3720 "Sequences in selection are not aligned",
3721 JOptionPane.WARNING_MESSAGE);
3727 title = title + " on region";
3728 tp = new TreePanel(alignPanel, type, pwType);
3732 // are the visible sequences aligned?
3733 if (!viewport.getAlignment().isAligned(false))
3738 "The sequences must be aligned before creating a tree.\n"
3739 + "Try using the Pad function in the edit menu,\n"
3740 + "or one of the multiple sequence alignment web services.",
3741 "Sequences not aligned",
3742 JOptionPane.WARNING_MESSAGE);
3747 if (viewport.getAlignment().getHeight() < 2)
3752 tp = new TreePanel(alignPanel, type, pwType);
3757 if (viewport.viewName != null)
3759 title += viewport.viewName + " of ";
3762 title += this.title;
3764 Desktop.addInternalFrame(tp, title, 600, 500);
3775 public void addSortByOrderMenuItem(String title,
3776 final AlignmentOrder order)
3778 final JMenuItem item = new JMenuItem("by " + title);
3780 item.addActionListener(new java.awt.event.ActionListener()
3783 public void actionPerformed(ActionEvent e)
3785 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3787 // TODO: JBPNote - have to map order entries to curent SequenceI
3789 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3791 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3794 alignPanel.paintAlignment(true);
3800 * Add a new sort by annotation score menu item
3803 * the menu to add the option to
3805 * the label used to retrieve scores for each sequence on the
3808 public void addSortByAnnotScoreMenuItem(JMenu sort,
3809 final String scoreLabel)
3811 final JMenuItem item = new JMenuItem(scoreLabel);
3813 item.addActionListener(new java.awt.event.ActionListener()
3816 public void actionPerformed(ActionEvent e)
3818 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3819 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3820 viewport.getAlignment());// ,viewport.getSelectionGroup());
3821 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3822 viewport.getAlignment()));
3823 alignPanel.paintAlignment(true);
3829 * last hash for alignment's annotation array - used to minimise cost of
3832 protected int _annotationScoreVectorHash;
3835 * search the alignment and rebuild the sort by annotation score submenu the
3836 * last alignment annotation vector hash is stored to minimize cost of
3837 * rebuilding in subsequence calls.
3841 public void buildSortByAnnotationScoresMenu()
3843 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3848 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3850 sortByAnnotScore.removeAll();
3851 // almost certainly a quicker way to do this - but we keep it simple
3852 Hashtable scoreSorts = new Hashtable();
3853 AlignmentAnnotation aann[];
3854 for (SequenceI sqa : viewport.getAlignment().getSequences())
3856 aann = sqa.getAnnotation();
3857 for (int i = 0; aann != null && i < aann.length; i++)
3859 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3861 scoreSorts.put(aann[i].label, aann[i].label);
3865 Enumeration labels = scoreSorts.keys();
3866 while (labels.hasMoreElements())
3868 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3869 (String) labels.nextElement());
3871 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3874 _annotationScoreVectorHash = viewport.getAlignment()
3875 .getAlignmentAnnotation().hashCode();
3880 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3881 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3882 * call. Listeners are added to remove the menu item when the treePanel is
3883 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3887 * Displayed tree window.
3889 * SortBy menu item title.
3892 public void buildTreeMenu()
3894 sortByTreeMenu.removeAll();
3896 Vector comps = (Vector) PaintRefresher.components.get(viewport
3897 .getSequenceSetId());
3898 Vector treePanels = new Vector();
3899 int i, iSize = comps.size();
3900 for (i = 0; i < iSize; i++)
3902 if (comps.elementAt(i) instanceof TreePanel)
3904 treePanels.add(comps.elementAt(i));
3908 iSize = treePanels.size();
3912 sortByTreeMenu.setVisible(false);
3916 sortByTreeMenu.setVisible(true);
3918 for (i = 0; i < treePanels.size(); i++)
3920 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3921 final JMenuItem item = new JMenuItem(tp.getTitle());
3922 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3923 item.addActionListener(new java.awt.event.ActionListener()
3926 public void actionPerformed(ActionEvent e)
3928 tp.sortByTree_actionPerformed(null);
3929 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3934 sortByTreeMenu.add(item);
3938 public boolean sortBy(AlignmentOrder alorder, String undoname)
3940 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3941 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3942 if (undoname != null)
3944 addHistoryItem(new OrderCommand(undoname, oldOrder,
3945 viewport.getAlignment()));
3947 alignPanel.paintAlignment(true);
3952 * Work out whether the whole set of sequences or just the selected set will
3953 * be submitted for multiple alignment.
3956 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3958 // Now, check we have enough sequences
3959 AlignmentView msa = null;
3961 if ((viewport.getSelectionGroup() != null)
3962 && (viewport.getSelectionGroup().getSize() > 1))
3964 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3965 // some common interface!
3967 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3968 * SequenceI[sz = seqs.getSize(false)];
3970 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3971 * seqs.getSequenceAt(i); }
3973 msa = viewport.getAlignmentView(true);
3978 * Vector seqs = viewport.getAlignment().getSequences();
3980 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3982 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3983 * seqs.elementAt(i); } }
3985 msa = viewport.getAlignmentView(false);
3991 * Decides what is submitted to a secondary structure prediction service: the
3992 * first sequence in the alignment, or in the current selection, or, if the
3993 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3994 * region or the whole alignment. (where the first sequence in the set is the
3995 * one that the prediction will be for).
3997 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3999 AlignmentView seqs = null;
4001 if ((viewport.getSelectionGroup() != null)
4002 && (viewport.getSelectionGroup().getSize() > 0))
4004 seqs = viewport.getAlignmentView(true);
4008 seqs = viewport.getAlignmentView(false);
4010 // limit sequences - JBPNote in future - could spawn multiple prediction
4012 // TODO: viewport.getAlignment().isAligned is a global state - the local
4013 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4014 if (!viewport.getAlignment().isAligned(false))
4016 seqs.setSequences(new SeqCigar[]
4017 { seqs.getSequences()[0] });
4018 // TODO: if seqs.getSequences().length>1 then should really have warned
4032 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4034 // Pick the tree file
4035 JalviewFileChooser chooser = new JalviewFileChooser(
4036 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4037 chooser.setFileView(new JalviewFileView());
4038 chooser.setDialogTitle("Select a newick-like tree file");
4039 chooser.setToolTipText("Load a tree file");
4041 int value = chooser.showOpenDialog(null);
4043 if (value == JalviewFileChooser.APPROVE_OPTION)
4045 String choice = chooser.getSelectedFile().getPath();
4046 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4047 jalview.io.NewickFile fin = null;
4050 fin = new jalview.io.NewickFile(choice, "File");
4051 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4052 } catch (Exception ex)
4054 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4055 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
4056 ex.printStackTrace();
4058 if (fin != null && fin.hasWarningMessage())
4060 JOptionPane.showMessageDialog(Desktop.desktop,
4061 fin.getWarningMessage(), "Possible problem with tree file",
4062 JOptionPane.WARNING_MESSAGE);
4068 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4070 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4073 public TreePanel ShowNewickTree(NewickFile nf, String title)
4075 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4078 public TreePanel ShowNewickTree(NewickFile nf, String title,
4079 AlignmentView input)
4081 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4084 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4085 int h, int x, int y)
4087 return ShowNewickTree(nf, title, null, w, h, x, y);
4091 * Add a treeviewer for the tree extracted from a newick file object to the
4092 * current alignment view
4099 * Associated alignment input data (or null)
4108 * @return TreePanel handle
4110 public TreePanel ShowNewickTree(NewickFile nf, String title,
4111 AlignmentView input, int w, int h, int x, int y)
4113 TreePanel tp = null;
4119 if (nf.getTree() != null)
4121 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4127 tp.setLocation(x, y);
4130 Desktop.addInternalFrame(tp, title, w, h);
4132 } catch (Exception ex)
4134 ex.printStackTrace();
4140 private boolean buildingMenu = false;
4143 * Generates menu items and listener event actions for web service clients
4146 public void BuildWebServiceMenu()
4148 while (buildingMenu)
4152 System.err.println("Waiting for building menu to finish.");
4154 } catch (Exception e)
4159 final AlignFrame me = this;
4160 buildingMenu = true;
4161 new Thread(new Runnable()
4166 final List<JMenuItem> legacyItems=new ArrayList<JMenuItem>();
4169 System.err.println("Building ws menu again "
4170 + Thread.currentThread());
4171 // TODO: add support for context dependent disabling of services based
4173 // alignment and current selection
4174 // TODO: add additional serviceHandle parameter to specify abstract
4176 // class independently of AbstractName
4177 // TODO: add in rediscovery GUI function to restart discoverer
4178 // TODO: group services by location as well as function and/or
4180 // object broker mechanism.
4181 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4182 final IProgressIndicator af = me;
4183 final JMenu msawsmenu = new JMenu("Alignment");
4184 final JMenu secstrmenu = new JMenu(
4185 "Secondary Structure Prediction");
4186 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4187 final JMenu analymenu = new JMenu("Analysis");
4188 final JMenu dismenu = new JMenu("Protein Disorder");
4189 // JAL-940 - only show secondary structure prediction services from
4190 // the legacy server
4191 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4193 Discoverer.services != null && (Discoverer.services.size() > 0))
4195 // TODO: refactor to allow list of AbstractName/Handler bindings to
4197 // stored or retrieved from elsewhere
4198 // No MSAWS used any more:
4199 // Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4200 Vector secstrpr = (Vector) Discoverer.services
4202 if (secstrpr != null)
4204 // Add any secondary structure prediction services
4205 for (int i = 0, j = secstrpr.size(); i < j; i++)
4207 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4209 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4210 .getServiceClient(sh);
4211 int p=secstrmenu.getItemCount();
4212 impl.attachWSMenuEntry(secstrmenu, me);
4213 int q=secstrmenu.getItemCount();
4214 for (int litm=p;litm<q; litm++)
4216 legacyItems.add(secstrmenu.getItem(litm));
4222 // Add all submenus in the order they should appear on the web
4224 wsmenu.add(msawsmenu);
4225 wsmenu.add(secstrmenu);
4226 wsmenu.add(dismenu);
4227 wsmenu.add(analymenu);
4228 // No search services yet
4229 // wsmenu.add(seqsrchmenu);
4231 javax.swing.SwingUtilities.invokeLater(new Runnable()
4238 webService.removeAll();
4239 // first, add discovered services onto the webservices menu
4240 if (wsmenu.size() > 0)
4242 for (int i = 0, j = wsmenu.size(); i < j; i++)
4244 webService.add(wsmenu.get(i));
4249 webService.add(me.webServiceNoServices);
4251 // TODO: move into separate menu builder class.
4252 boolean new_sspred=false;
4253 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4255 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4256 if (jws2servs != null)
4258 if (jws2servs.hasServices())
4260 jws2servs.attachWSMenuEntry(webService, me);
4261 for (Jws2Instance sv:jws2servs.getServices()) {
4262 if (sv.description.toLowerCase().contains("jpred"))
4264 for (JMenuItem jmi:legacyItems)
4266 jmi.setVisible(false);
4272 if (jws2servs.isRunning())
4274 JMenuItem tm = new JMenuItem(
4275 "Still discovering JABA Services");
4276 tm.setEnabled(false);
4281 build_urlServiceMenu(me.webService);
4282 build_fetchdbmenu(webService);
4283 for (JMenu item : wsmenu)
4285 if (item.getItemCount() == 0)
4287 item.setEnabled(false);
4291 item.setEnabled(true);
4294 } catch (Exception e)
4297 .debug("Exception during web service menu building process.",
4303 } catch (Exception e)
4308 buildingMenu = false;
4315 * construct any groupURL type service menu entries.
4319 private void build_urlServiceMenu(JMenu webService)
4321 // TODO: remove this code when 2.7 is released
4322 // DEBUG - alignmentView
4324 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4325 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4327 * @Override public void actionPerformed(ActionEvent e) {
4328 * jalview.datamodel.AlignmentView
4329 * .testSelectionViews(af.viewport.getAlignment(),
4330 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4332 * }); webService.add(testAlView);
4334 // TODO: refactor to RestClient discoverer and merge menu entries for
4335 // rest-style services with other types of analysis/calculation service
4336 // SHmmr test client - still being implemented.
4337 // DEBUG - alignmentView
4339 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4342 client.attachWSMenuEntry(
4343 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4347 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4349 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4355 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4356 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4357 * getProperty("LAST_DIRECTORY"));
4359 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4360 * to Vamsas file"); chooser.setToolTipText("Export");
4362 * int value = chooser.showSaveDialog(this);
4364 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4365 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4366 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4367 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4370 * prototype of an automatically enabled/disabled analysis function
4373 protected void setShowProductsEnabled()
4375 SequenceI[] selection = viewport.getSequenceSelection();
4376 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4377 viewport.getAlignment().getDataset()))
4379 showProducts.setEnabled(true);
4384 showProducts.setEnabled(false);
4389 * search selection for sequence xRef products and build the show products
4394 * @return true if showProducts menu should be enabled.
4396 public boolean canShowProducts(SequenceI[] selection,
4397 boolean isRegionSelection, Alignment dataset)
4399 boolean showp = false;
4402 showProducts.removeAll();
4403 final boolean dna = viewport.getAlignment().isNucleotide();
4404 final Alignment ds = dataset;
4405 String[] ptypes = (selection == null || selection.length == 0) ? null
4406 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4408 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4409 // selection, dataset, true);
4410 final SequenceI[] sel = selection;
4411 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4414 final boolean isRegSel = isRegionSelection;
4415 final AlignFrame af = this;
4416 final String source = ptypes[t];
4417 JMenuItem xtype = new JMenuItem(ptypes[t]);
4418 xtype.addActionListener(new ActionListener()
4422 public void actionPerformed(ActionEvent e)
4424 // TODO: new thread for this call with vis-delay
4425 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4426 isRegSel, dna, source);
4430 showProducts.add(xtype);
4432 showProducts.setVisible(showp);
4433 showProducts.setEnabled(showp);
4434 } catch (Exception e)
4436 jalview.bin.Cache.log
4437 .warn("canTranslate threw an exception - please report to help@jalview.org",
4444 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4445 boolean isRegSel, boolean dna, String source)
4447 final boolean fisRegSel = isRegSel;
4448 final boolean fdna = dna;
4449 final String fsrc = source;
4450 final AlignFrame ths = this;
4451 final SequenceI[] fsel = sel;
4452 Runnable foo = new Runnable()
4458 final long sttime = System.currentTimeMillis();
4459 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4462 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4466 Alignment prods = CrossRef
4467 .findXrefSequences(fsel, fdna, fsrc, ds);
4470 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4471 for (int s = 0; s < sprods.length; s++)
4473 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4474 if (ds.getSequences() == null
4475 || !ds.getSequences().contains(
4476 sprods[s].getDatasetSequence()))
4477 ds.addSequence(sprods[s].getDatasetSequence());
4478 sprods[s].updatePDBIds();
4480 Alignment al = new Alignment(sprods);
4481 AlignedCodonFrame[] cf = prods.getCodonFrames();
4483 for (int s = 0; cf != null && s < cf.length; s++)
4485 al.addCodonFrame(cf[s]);
4488 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4490 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4491 + " for " + ((fisRegSel) ? "selected region of " : "")
4493 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4498 System.err.println("No Sequences generated for xRef type "
4501 } catch (Exception e)
4503 jalview.bin.Cache.log.error(
4504 "Exception when finding crossreferences", e);
4505 } catch (OutOfMemoryError e)
4507 new OOMWarning("whilst fetching crossreferences", e);
4510 jalview.bin.Cache.log.error("Error when finding crossreferences",
4513 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4518 Thread frunner = new Thread(foo);
4522 public boolean canShowTranslationProducts(SequenceI[] selection,
4523 AlignmentI alignment)
4528 return (jalview.analysis.Dna.canTranslate(selection,
4529 viewport.getViewAsVisibleContigs(true)));
4530 } catch (Exception e)
4532 jalview.bin.Cache.log
4533 .warn("canTranslate threw an exception - please report to help@jalview.org",
4540 public void showProducts_actionPerformed(ActionEvent e)
4542 // /////////////////////////////
4543 // Collect Data to be translated/transferred
4545 SequenceI[] selection = viewport.getSequenceSelection();
4546 AlignmentI al = null;
4549 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4550 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4551 viewport.getAlignment().getDataset());
4552 } catch (Exception ex)
4555 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4562 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4563 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4567 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4568 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4569 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4574 public void showTranslation_actionPerformed(ActionEvent e)
4576 // /////////////////////////////
4577 // Collect Data to be translated/transferred
4579 SequenceI[] selection = viewport.getSequenceSelection();
4580 String[] seqstring = viewport.getViewAsString(true);
4581 AlignmentI al = null;
4584 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4585 viewport.getViewAsVisibleContigs(true), viewport
4586 .getGapCharacter(), viewport.getAlignment()
4587 .getAlignmentAnnotation(), viewport.getAlignment()
4588 .getWidth(), viewport.getAlignment().getDataset());
4589 } catch (Exception ex)
4592 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4596 "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.",
4597 "Implementation error: Translation Failed", JOptionPane.ERROR_MESSAGE);
4605 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4606 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4610 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4611 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4612 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4617 * Try to load a features file onto the alignment.
4620 * contents or path to retrieve file
4622 * access mode of file (see jalview.io.AlignFile)
4623 * @return true if features file was parsed corectly.
4625 public boolean parseFeaturesFile(String file, String type)
4627 boolean featuresFile = false;
4630 featuresFile = new FeaturesFile(file, type).parse(viewport
4631 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4632 .getFeatureRenderer().featureColours, false,
4633 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4634 } catch (Exception ex)
4636 ex.printStackTrace();
4641 viewport.showSequenceFeatures = true;
4642 showSeqFeatures.setSelected(true);
4643 if (alignPanel.seqPanel.seqCanvas.fr != null)
4645 // update the min/max ranges where necessary
4646 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4648 if (featureSettings != null)
4650 featureSettings.setTableData();
4652 alignPanel.paintAlignment(true);
4655 return featuresFile;
4659 public void dragEnter(DropTargetDragEvent evt)
4664 public void dragExit(DropTargetEvent evt)
4669 public void dragOver(DropTargetDragEvent evt)
4674 public void dropActionChanged(DropTargetDragEvent evt)
4679 public void drop(DropTargetDropEvent evt)
4681 Transferable t = evt.getTransferable();
4682 java.util.List files = null;
4686 DataFlavor uriListFlavor = new DataFlavor(
4687 "text/uri-list;class=java.lang.String");
4688 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4690 // Works on Windows and MacOSX
4691 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4692 files = (java.util.List) t
4693 .getTransferData(DataFlavor.javaFileListFlavor);
4695 else if (t.isDataFlavorSupported(uriListFlavor))
4697 // This is used by Unix drag system
4698 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4699 String data = (String) t.getTransferData(uriListFlavor);
4700 files = new java.util.ArrayList(1);
4701 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4702 data, "\r\n"); st.hasMoreTokens();)
4704 String s = st.nextToken();
4705 if (s.startsWith("#"))
4707 // the line is a comment (as per the RFC 2483)
4711 java.net.URI uri = new java.net.URI(s);
4712 // check to see if we can handle this kind of URI
4713 if (uri.getScheme().toLowerCase().startsWith("http"))
4715 files.add(uri.toString());
4719 // otherwise preserve old behaviour: catch all for file objects
4720 java.io.File file = new java.io.File(uri);
4721 files.add(file.toString());
4725 } catch (Exception e)
4727 e.printStackTrace();
4733 // check to see if any of these files have names matching sequences in
4735 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4736 .getAlignment().getSequencesArray());
4738 * Object[] { String,SequenceI}
4740 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4741 ArrayList<String> filesnotmatched = new ArrayList<String>();
4742 for (int i = 0; i < files.size(); i++)
4744 String file = files.get(i).toString();
4746 String protocol = FormatAdapter.checkProtocol(file);
4747 if (protocol == jalview.io.FormatAdapter.FILE)
4749 File fl = new File(file);
4750 pdbfn = fl.getName();
4752 else if (protocol == jalview.io.FormatAdapter.URL)
4754 URL url = new URL(file);
4755 pdbfn = url.getFile();
4757 if (pdbfn.length() > 0)
4759 // attempt to find a match in the alignment
4760 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4761 int l = 0, c = pdbfn.indexOf(".");
4762 while (mtch == null && c != -1)
4767 } while ((c = pdbfn.indexOf(".", l)) > l);
4770 pdbfn = pdbfn.substring(0, l);
4772 mtch = idm.findAllIdMatches(pdbfn);
4779 type = new IdentifyFile().Identify(file, protocol);
4780 } catch (Exception ex)
4786 if (type.equalsIgnoreCase("PDB"))
4788 filesmatched.add(new Object[]
4789 { file, protocol, mtch });
4794 // File wasn't named like one of the sequences or wasn't a PDB file.
4795 filesnotmatched.add(file);
4799 if (filesmatched.size() > 0)
4801 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4805 "Do you want to automatically associate the "
4806 + filesmatched.size()
4807 + " PDB files with sequences in the alignment that have the same name ?",
4808 "Automatically Associate PDB files by name",
4809 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4812 for (Object[] fm : filesmatched)
4814 // try and associate
4815 // TODO: may want to set a standard ID naming formalism for
4816 // associating PDB files which have no IDs.
4817 for (SequenceI toassoc : (SequenceI[]) fm[2])
4819 PDBEntry pe = new AssociatePdbFileWithSeq()
4820 .associatePdbWithSeq((String) fm[0],
4821 (String) fm[1], toassoc, false);
4824 System.err.println("Associated file : "
4825 + ((String) fm[0]) + " with "
4826 + toassoc.getDisplayId(true));
4830 alignPanel.paintAlignment(true);
4834 if (filesnotmatched.size() > 0)
4837 && (Cache.getDefault(
4838 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4841 "<html>Do you want to <em>ignore</em> the "
4842 + filesnotmatched.size()
4843 + " files whose names did not match any sequence IDs ?</html>",
4844 "Ignore unmatched dropped files ?",
4845 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4849 for (String fn : filesnotmatched)
4851 loadJalviewDataFile(fn, null, null, null);
4855 } catch (Exception ex)
4857 ex.printStackTrace();
4863 * Attempt to load a "dropped" file or URL string: First by testing whether
4864 * it's and Annotation file, then a JNet file, and finally a features file. If
4865 * all are false then the user may have dropped an alignment file onto this
4869 * either a filename or a URL string.
4871 public void loadJalviewDataFile(String file, String protocol,
4872 String format, SequenceI assocSeq)
4876 if (protocol == null)
4878 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4880 // if the file isn't identified, or not positively identified as some
4881 // other filetype (PFAM is default unidentified alignment file type) then
4882 // try to parse as annotation.
4883 boolean isAnnotation = (format == null || format
4884 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4885 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4890 // first see if its a T-COFFEE score file
4891 TCoffeeScoreFile tcf = null;
4894 tcf = new TCoffeeScoreFile(file, protocol);
4897 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4899 tcoffeeColour.setEnabled(true);
4900 tcoffeeColour.setSelected(true);
4901 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4902 isAnnotation = true;
4904 .setText("Successfully pasted T-Coffee scores to alignment.");
4908 // some problem - if no warning its probable that the ID matching
4909 // process didn't work
4913 tcf.getWarningMessage() == null ? "Check that the file matches sequence IDs in the alignment."
4914 : tcf.getWarningMessage(),
4915 "Problem reading T-COFFEE score file",
4916 JOptionPane.WARNING_MESSAGE);
4923 } catch (Exception x)
4926 .debug("Exception when processing data source as T-COFFEE score file",
4932 // try to see if its a JNet 'concise' style annotation file *before*
4934 // try to parse it as a features file
4937 format = new IdentifyFile().Identify(file, protocol);
4939 if (format.equalsIgnoreCase("JnetFile"))
4941 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4943 new JnetAnnotationMaker().add_annotation(predictions,
4944 viewport.getAlignment(), 0, false);
4945 isAnnotation = true;
4950 * if (format.equalsIgnoreCase("PDB")) {
4952 * String pdbfn = ""; // try to match up filename with sequence id
4953 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4954 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4955 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4956 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4957 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4958 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4959 * // attempt to find a match in the alignment SequenceI mtch =
4960 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4961 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4962 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4963 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4964 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4965 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4966 * { System.err.println("Associated file : " + file + " with " +
4967 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4968 * TODO: maybe need to load as normal otherwise return; } }
4970 // try to parse it as a features file
4971 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4972 // if it wasn't a features file then we just treat it as a general
4973 // alignment file to load into the current view.
4976 new FileLoader().LoadFile(viewport, file, protocol, format);
4980 alignPanel.paintAlignment(true);
4988 alignPanel.adjustAnnotationHeight();
4989 viewport.updateSequenceIdColours();
4990 buildSortByAnnotationScoresMenu();
4991 alignPanel.paintAlignment(true);
4993 } catch (Exception ex)
4995 ex.printStackTrace();
4996 } catch (OutOfMemoryError oom)
5001 } catch (Exception x)
5007 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5008 : "using " + protocol + " from " + file)
5010 + (format != null ? "(parsing as '" + format
5011 + "' file)" : ""), oom, Desktop.desktop);
5016 public void tabSelectionChanged(int index)
5020 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5021 viewport = alignPanel.av;
5022 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5023 setMenusFromViewport(viewport);
5028 public void tabbedPane_mousePressed(MouseEvent e)
5030 if (SwingUtilities.isRightMouseButton(e))
5032 String reply = JOptionPane.showInternalInputDialog(this,
5033 "Enter View Name", "Edit View Name",
5034 JOptionPane.QUESTION_MESSAGE);
5038 viewport.viewName = reply;
5039 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5044 public AlignViewport getCurrentView()
5050 * Open the dialog for regex description parsing.
5053 protected void extractScores_actionPerformed(ActionEvent e)
5055 ParseProperties pp = new jalview.analysis.ParseProperties(
5056 viewport.getAlignment());
5057 // TODO: verify regex and introduce GUI dialog for version 2.5
5058 // if (pp.getScoresFromDescription("col", "score column ",
5059 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5061 if (pp.getScoresFromDescription("description column",
5062 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5064 buildSortByAnnotationScoresMenu();
5072 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5076 protected void showDbRefs_actionPerformed(ActionEvent e)
5078 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5084 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5088 protected void showNpFeats_actionPerformed(ActionEvent e)
5090 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5094 * find the viewport amongst the tabs in this alignment frame and close that
5099 public boolean closeView(AlignViewport av)
5103 this.closeMenuItem_actionPerformed(false);
5106 Component[] comp = tabbedPane.getComponents();
5107 for (int i = 0; comp != null && i < comp.length; i++)
5109 if (comp[i] instanceof AlignmentPanel)
5111 if (((AlignmentPanel) comp[i]).av == av)
5114 closeView((AlignmentPanel) comp[i]);
5122 protected void build_fetchdbmenu(JMenu webService)
5124 // Temporary hack - DBRef Fetcher always top level ws entry.
5125 // TODO We probably want to store a sequence database checklist in
5126 // preferences and have checkboxes.. rather than individual sources selected
5128 final JMenu rfetch = new JMenu("Fetch DB References");
5129 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5130 webService.add(rfetch);
5132 JMenuItem fetchr = new JMenuItem("Standard Databases");
5133 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5134 fetchr.addActionListener(new ActionListener()
5138 public void actionPerformed(ActionEvent e)
5140 new Thread(new Runnable()
5146 new jalview.ws.DBRefFetcher(alignPanel.av
5147 .getSequenceSelection(), alignPanel.alignFrame)
5148 .fetchDBRefs(false);
5156 final AlignFrame me = this;
5157 new Thread(new Runnable()
5162 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5163 .getSequenceFetcherSingleton(me);
5164 javax.swing.SwingUtilities.invokeLater(new Runnable()
5169 String[] dbclasses = sf.getOrderedSupportedSources();
5170 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5171 // jalview.util.QuickSort.sort(otherdb, otherdb);
5172 List<DbSourceProxy> otherdb;
5173 JMenu dfetch = new JMenu();
5174 JMenu ifetch = new JMenu();
5175 JMenuItem fetchr = null;
5176 int comp = 0, icomp = 0, mcomp = 15;
5177 String mname = null;
5179 for (String dbclass : dbclasses)
5181 otherdb = sf.getSourceProxy(dbclass);
5182 // add a single entry for this class, or submenu allowing 'fetch
5184 if (otherdb == null || otherdb.size() < 1)
5188 // List<DbSourceProxy> dbs=otherdb;
5189 // otherdb=new ArrayList<DbSourceProxy>();
5190 // for (DbSourceProxy db:dbs)
5192 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5196 mname = "From " + dbclass;
5198 if (otherdb.size() == 1)
5200 final DbSourceProxy[] dassource = otherdb
5201 .toArray(new DbSourceProxy[0]);
5202 DbSourceProxy src = otherdb.get(0);
5203 fetchr = new JMenuItem(src.getDbSource());
5204 fetchr.addActionListener(new ActionListener()
5208 public void actionPerformed(ActionEvent e)
5210 new Thread(new Runnable()
5216 new jalview.ws.DBRefFetcher(alignPanel.av
5217 .getSequenceSelection(),
5218 alignPanel.alignFrame, dassource)
5219 .fetchDBRefs(false);
5225 fetchr.setToolTipText("<html>"
5226 + JvSwingUtils.wrapTooltip("Retrieve from "
5227 + src.getDbName()) + "<html>");
5233 final DbSourceProxy[] dassource = otherdb
5234 .toArray(new DbSourceProxy[0]);
5236 DbSourceProxy src = otherdb.get(0);
5237 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5239 fetchr.addActionListener(new ActionListener()
5242 public void actionPerformed(ActionEvent e)
5244 new Thread(new Runnable()
5250 new jalview.ws.DBRefFetcher(alignPanel.av
5251 .getSequenceSelection(),
5252 alignPanel.alignFrame, dassource)
5253 .fetchDBRefs(false);
5259 fetchr.setToolTipText("<html>"
5260 + JvSwingUtils.wrapTooltip("Retrieve from all "
5261 + otherdb.size() + " sources in "
5262 + src.getDbSource() + "<br>First is :"
5263 + src.getDbName()) + "<html>");
5266 // and then build the rest of the individual menus
5267 ifetch = new JMenu("Sources from " + src.getDbSource());
5269 String imname = null;
5271 for (DbSourceProxy sproxy : otherdb)
5273 String dbname = sproxy.getDbName();
5274 String sname = dbname.length() > 5 ? dbname.substring(0,
5275 5) + "..." : dbname;
5276 String msname = dbname.length() > 10 ? dbname.substring(
5277 0, 10) + "..." : dbname;
5280 imname = "from '" + sname + "'";
5282 fetchr = new JMenuItem(msname);
5283 final DbSourceProxy[] dassrc =
5285 fetchr.addActionListener(new ActionListener()
5289 public void actionPerformed(ActionEvent e)
5291 new Thread(new Runnable()
5297 new jalview.ws.DBRefFetcher(alignPanel.av
5298 .getSequenceSelection(),
5299 alignPanel.alignFrame, dassrc)
5300 .fetchDBRefs(false);
5306 fetchr.setToolTipText("<html>"
5307 + JvSwingUtils.wrapTooltip("Retrieve from "
5308 + dbname) + "</html>");
5311 if (++icomp >= mcomp || i == (otherdb.size()))
5313 ifetch.setText(imname + " to '" + sname + "'");
5315 ifetch = new JMenu();
5323 if (comp >= mcomp || dbi >= (dbclasses.length))
5325 dfetch.setText(mname + " to '" + dbclass + "'");
5327 dfetch = new JMenu();
5340 * Left justify the whole alignment.
5343 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5345 AlignmentI al = viewport.getAlignment();
5347 viewport.firePropertyChange("alignment", null, al);
5351 * Right justify the whole alignment.
5354 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5356 AlignmentI al = viewport.getAlignment();
5358 viewport.firePropertyChange("alignment", null, al);
5361 public void setShowSeqFeatures(boolean b)
5363 showSeqFeatures.setSelected(true);
5364 viewport.setShowSequenceFeatures(true);
5371 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5372 * awt.event.ActionEvent)
5375 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5377 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5378 alignPanel.paintAlignment(true);
5385 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5389 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5391 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5392 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5400 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5401 * .event.ActionEvent)
5404 protected void showGroupConservation_actionPerformed(ActionEvent e)
5406 viewport.setShowGroupConservation(showGroupConservation.getState());
5407 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5414 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5415 * .event.ActionEvent)
5418 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5420 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5421 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5428 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5429 * .event.ActionEvent)
5432 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5434 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5435 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5439 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5441 showSequenceLogo.setState(true);
5442 viewport.setShowSequenceLogo(true);
5443 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5444 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5448 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5450 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5457 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5458 * .event.ActionEvent)
5461 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5463 if (avc.makeGroupsFromSelection()) {
5464 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5465 alignPanel.updateAnnotation();
5466 alignPanel.paintAlignment(true);
5471 * make the given alignmentPanel the currently selected tab
5473 * @param alignmentPanel
5475 public void setDisplayedView(AlignmentPanel alignmentPanel)
5477 if (!viewport.getSequenceSetId().equals(
5478 alignmentPanel.av.getSequenceSetId()))
5481 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5483 if (tabbedPane != null
5484 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5485 .getSelectedIndex())
5487 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5492 class PrintThread extends Thread
5496 public PrintThread(AlignmentPanel ap)
5501 static PageFormat pf;
5506 PrinterJob printJob = PrinterJob.getPrinterJob();
5510 printJob.setPrintable(ap, pf);
5514 printJob.setPrintable(ap);
5517 if (printJob.printDialog())
5522 } catch (Exception PrintException)
5524 PrintException.printStackTrace();