2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.analysis.AAFrequency;
22 import jalview.analysis.AlignmentSorter;
23 import jalview.analysis.Conservation;
24 import jalview.analysis.CrossRef;
25 import jalview.analysis.NJTree;
26 import jalview.analysis.ParseProperties;
27 import jalview.analysis.SequenceIdMatcher;
28 import jalview.api.AlignViewControllerI;
29 import jalview.bin.Cache;
30 import jalview.commands.CommandI;
31 import jalview.commands.EditCommand;
32 import jalview.commands.OrderCommand;
33 import jalview.commands.RemoveGapColCommand;
34 import jalview.commands.RemoveGapsCommand;
35 import jalview.commands.SlideSequencesCommand;
36 import jalview.commands.TrimRegionCommand;
37 import jalview.datamodel.AlignedCodonFrame;
38 import jalview.datamodel.Alignment;
39 import jalview.datamodel.AlignmentAnnotation;
40 import jalview.datamodel.AlignmentI;
41 import jalview.datamodel.AlignmentOrder;
42 import jalview.datamodel.AlignmentView;
43 import jalview.datamodel.ColumnSelection;
44 import jalview.datamodel.PDBEntry;
45 import jalview.datamodel.SeqCigar;
46 import jalview.datamodel.Sequence;
47 import jalview.datamodel.SequenceGroup;
48 import jalview.datamodel.SequenceI;
49 import jalview.io.AlignmentProperties;
50 import jalview.io.AnnotationFile;
51 import jalview.io.FeaturesFile;
52 import jalview.io.FileLoader;
53 import jalview.io.FormatAdapter;
54 import jalview.io.HTMLOutput;
55 import jalview.io.IdentifyFile;
56 import jalview.io.JalviewFileChooser;
57 import jalview.io.JalviewFileView;
58 import jalview.io.JnetAnnotationMaker;
59 import jalview.io.NewickFile;
60 import jalview.io.TCoffeeScoreFile;
61 import jalview.jbgui.GAlignFrame;
62 import jalview.schemes.Blosum62ColourScheme;
63 import jalview.schemes.BuriedColourScheme;
64 import jalview.schemes.ClustalxColourScheme;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.ColourSchemeProperty;
67 import jalview.schemes.HelixColourScheme;
68 import jalview.schemes.HydrophobicColourScheme;
69 import jalview.schemes.NucleotideColourScheme;
70 import jalview.schemes.PIDColourScheme;
71 import jalview.schemes.PurinePyrimidineColourScheme;
72 import jalview.schemes.RNAHelicesColourChooser;
73 import jalview.schemes.ResidueProperties;
74 import jalview.schemes.StrandColourScheme;
75 import jalview.schemes.TCoffeeColourScheme;
76 import jalview.schemes.TaylorColourScheme;
77 import jalview.schemes.TurnColourScheme;
78 import jalview.schemes.UserColourScheme;
79 import jalview.schemes.ZappoColourScheme;
80 import jalview.util.MessageManager;
81 import jalview.ws.jws1.Discoverer;
82 import jalview.ws.jws2.Jws2Discoverer;
83 import jalview.ws.jws2.jabaws2.Jws2Instance;
84 import jalview.ws.seqfetcher.DbSourceProxy;
86 import java.awt.BorderLayout;
87 import java.awt.Color;
88 import java.awt.Component;
89 import java.awt.GridLayout;
90 import java.awt.Rectangle;
91 import java.awt.Toolkit;
92 import java.awt.datatransfer.Clipboard;
93 import java.awt.datatransfer.DataFlavor;
94 import java.awt.datatransfer.StringSelection;
95 import java.awt.datatransfer.Transferable;
96 import java.awt.dnd.DnDConstants;
97 import java.awt.dnd.DropTargetDragEvent;
98 import java.awt.dnd.DropTargetDropEvent;
99 import java.awt.dnd.DropTargetEvent;
100 import java.awt.dnd.DropTargetListener;
101 import java.awt.event.ActionEvent;
102 import java.awt.event.ActionListener;
103 import java.awt.event.KeyAdapter;
104 import java.awt.event.KeyEvent;
105 import java.awt.event.MouseAdapter;
106 import java.awt.event.MouseEvent;
107 import java.awt.print.PageFormat;
108 import java.awt.print.PrinterJob;
109 import java.beans.PropertyChangeEvent;
112 import java.util.ArrayList;
113 import java.util.Enumeration;
114 import java.util.Hashtable;
115 import java.util.List;
116 import java.util.Vector;
118 import javax.swing.JButton;
119 import javax.swing.JEditorPane;
120 import javax.swing.JInternalFrame;
121 import javax.swing.JLabel;
122 import javax.swing.JLayeredPane;
123 import javax.swing.JMenu;
124 import javax.swing.JMenuItem;
125 import javax.swing.JOptionPane;
126 import javax.swing.JPanel;
127 import javax.swing.JProgressBar;
128 import javax.swing.JRadioButtonMenuItem;
129 import javax.swing.JScrollPane;
130 import javax.swing.SwingUtilities;
136 * @version $Revision$
138 public class AlignFrame extends GAlignFrame implements DropTargetListener,
143 public static final int DEFAULT_WIDTH = 700;
146 public static final int DEFAULT_HEIGHT = 500;
148 public AlignmentPanel alignPanel;
150 AlignViewport viewport;
152 public AlignViewControllerI avc;
155 Vector alignPanels = new Vector();
158 * Last format used to load or save alignments in this window
160 String currentFileFormat = null;
163 * Current filename for this alignment
165 String fileName = null;
168 * Creates a new AlignFrame object with specific width and height.
174 public AlignFrame(AlignmentI al, int width, int height)
176 this(al, null, width, height);
180 * Creates a new AlignFrame object with specific width, height and
186 * @param sequenceSetId
188 public AlignFrame(AlignmentI al, int width, int height,
189 String sequenceSetId)
191 this(al, null, width, height, sequenceSetId);
195 * Creates a new AlignFrame object with specific width, height and
201 * @param sequenceSetId
204 public AlignFrame(AlignmentI al, int width, int height,
205 String sequenceSetId, String viewId)
207 this(al, null, width, height, sequenceSetId, viewId);
211 * new alignment window with hidden columns
215 * @param hiddenColumns
216 * ColumnSelection or null
218 * Width of alignment frame
222 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
223 int width, int height)
225 this(al, hiddenColumns, width, height, null);
229 * Create alignment frame for al with hiddenColumns, a specific width and
230 * height, and specific sequenceId
233 * @param hiddenColumns
236 * @param sequenceSetId
239 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
240 int width, int height, String sequenceSetId)
242 this(al, hiddenColumns, width, height, sequenceSetId, null);
246 * Create alignment frame for al with hiddenColumns, a specific width and
247 * height, and specific sequenceId
250 * @param hiddenColumns
253 * @param sequenceSetId
258 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
259 int width, int height, String sequenceSetId, String viewId)
261 setSize(width, height);
262 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
264 alignPanel = new AlignmentPanel(this, viewport);
266 if (al.getDataset() == null)
271 addAlignmentPanel(alignPanel, true);
276 * Make a new AlignFrame from exisiting alignmentPanels
283 public AlignFrame(AlignmentPanel ap)
287 addAlignmentPanel(ap, false);
292 * initalise the alignframe from the underlying viewport data and the
297 avc = new jalview.controller.AlignViewController(viewport, alignPanel);
298 if (viewport.getAlignmentConservationAnnotation() == null)
300 BLOSUM62Colour.setEnabled(false);
301 conservationMenuItem.setEnabled(false);
302 modifyConservation.setEnabled(false);
303 // PIDColour.setEnabled(false);
304 // abovePIDThreshold.setEnabled(false);
305 // modifyPID.setEnabled(false);
308 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
311 if (sortby.equals("Id"))
313 sortIDMenuItem_actionPerformed(null);
315 else if (sortby.equals("Pairwise Identity"))
317 sortPairwiseMenuItem_actionPerformed(null);
320 if (Desktop.desktop != null)
322 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
323 addServiceListeners();
324 setGUINucleotide(viewport.getAlignment().isNucleotide());
327 setMenusFromViewport(viewport);
328 buildSortByAnnotationScoresMenu();
329 if (viewport.wrapAlignment)
331 wrapMenuItem_actionPerformed(null);
334 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
336 this.overviewMenuItem_actionPerformed(null);
344 * Change the filename and format for the alignment, and enable the 'reload'
345 * button functionality.
352 public void setFileName(String file, String format)
355 currentFileFormat = format;
356 reload.setEnabled(true);
359 void addKeyListener()
361 addKeyListener(new KeyAdapter()
364 public void keyPressed(KeyEvent evt)
366 if (viewport.cursorMode
367 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
368 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
369 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
370 && Character.isDigit(evt.getKeyChar()))
371 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
373 switch (evt.getKeyCode())
376 case 27: // escape key
377 deselectAllSequenceMenuItem_actionPerformed(null);
381 case KeyEvent.VK_DOWN:
382 if (evt.isAltDown() || !viewport.cursorMode)
383 moveSelectedSequences(false);
384 if (viewport.cursorMode)
385 alignPanel.seqPanel.moveCursor(0, 1);
389 if (evt.isAltDown() || !viewport.cursorMode)
390 moveSelectedSequences(true);
391 if (viewport.cursorMode)
392 alignPanel.seqPanel.moveCursor(0, -1);
396 case KeyEvent.VK_LEFT:
397 if (evt.isAltDown() || !viewport.cursorMode)
398 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
400 alignPanel.seqPanel.moveCursor(-1, 0);
404 case KeyEvent.VK_RIGHT:
405 if (evt.isAltDown() || !viewport.cursorMode)
406 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
408 alignPanel.seqPanel.moveCursor(1, 0);
411 case KeyEvent.VK_SPACE:
412 if (viewport.cursorMode)
414 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
415 || evt.isShiftDown() || evt.isAltDown());
419 // case KeyEvent.VK_A:
420 // if (viewport.cursorMode)
422 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
423 // //System.out.println("A");
427 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
428 * System.out.println("closing bracket"); } break;
430 case KeyEvent.VK_DELETE:
431 case KeyEvent.VK_BACK_SPACE:
432 if (!viewport.cursorMode)
434 cut_actionPerformed(null);
438 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
439 || evt.isShiftDown() || evt.isAltDown());
445 if (viewport.cursorMode)
447 alignPanel.seqPanel.setCursorRow();
451 if (viewport.cursorMode && !evt.isControlDown())
453 alignPanel.seqPanel.setCursorColumn();
457 if (viewport.cursorMode)
459 alignPanel.seqPanel.setCursorPosition();
463 case KeyEvent.VK_ENTER:
464 case KeyEvent.VK_COMMA:
465 if (viewport.cursorMode)
467 alignPanel.seqPanel.setCursorRowAndColumn();
472 if (viewport.cursorMode)
474 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
478 if (viewport.cursorMode)
480 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
485 viewport.cursorMode = !viewport.cursorMode;
486 statusBar.setText(MessageManager.formatMessage("label.keyboard_editing_mode", new String[]{(viewport.cursorMode ? "on" : "off")}));
487 if (viewport.cursorMode)
489 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
490 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
492 alignPanel.seqPanel.seqCanvas.repaint();
498 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
499 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
501 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
503 javax.help.HelpBroker hb = hs.createHelpBroker();
504 hb.setCurrentID("home");
505 hb.setDisplayed(true);
506 } catch (Exception ex)
508 ex.printStackTrace();
513 boolean toggleSeqs = !evt.isControlDown();
514 boolean toggleCols = !evt.isShiftDown();
515 toggleHiddenRegions(toggleSeqs, toggleCols);
518 case KeyEvent.VK_PAGE_UP:
519 if (viewport.wrapAlignment)
521 alignPanel.scrollUp(true);
525 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
526 - viewport.endSeq + viewport.startSeq);
529 case KeyEvent.VK_PAGE_DOWN:
530 if (viewport.wrapAlignment)
532 alignPanel.scrollUp(false);
536 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
537 + viewport.endSeq - viewport.startSeq);
544 public void keyReleased(KeyEvent evt)
546 switch (evt.getKeyCode())
548 case KeyEvent.VK_LEFT:
549 if (evt.isAltDown() || !viewport.cursorMode)
550 viewport.firePropertyChange("alignment", null, viewport
551 .getAlignment().getSequences());
554 case KeyEvent.VK_RIGHT:
555 if (evt.isAltDown() || !viewport.cursorMode)
556 viewport.firePropertyChange("alignment", null, viewport
557 .getAlignment().getSequences());
564 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
566 ap.alignFrame = this;
567 avc = new jalview.controller.AlignViewController(viewport, alignPanel);
569 alignPanels.addElement(ap);
571 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
573 int aSize = alignPanels.size();
575 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
577 if (aSize == 1 && ap.av.viewName == null)
579 this.getContentPane().add(ap, BorderLayout.CENTER);
585 setInitialTabVisible();
588 expandViews.setEnabled(true);
589 gatherViews.setEnabled(true);
590 tabbedPane.addTab(ap.av.viewName, ap);
592 ap.setVisible(false);
597 if (ap.av.isPadGaps())
599 ap.av.getAlignment().padGaps();
601 ap.av.updateConservation(ap);
602 ap.av.updateConsensus(ap);
603 ap.av.updateStrucConsensus(ap);
607 public void setInitialTabVisible()
609 expandViews.setEnabled(true);
610 gatherViews.setEnabled(true);
611 tabbedPane.setVisible(true);
612 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
613 tabbedPane.addTab(first.av.viewName, first);
614 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
617 public AlignViewport getViewport()
622 /* Set up intrinsic listeners for dynamically generated GUI bits. */
623 private void addServiceListeners()
625 final java.beans.PropertyChangeListener thisListener;
626 Desktop.instance.addJalviewPropertyChangeListener("services",
627 thisListener = new java.beans.PropertyChangeListener()
630 public void propertyChange(PropertyChangeEvent evt)
632 // // System.out.println("Discoverer property change.");
633 // if (evt.getPropertyName().equals("services"))
635 SwingUtilities.invokeLater(new Runnable()
642 .println("Rebuild WS Menu for service change");
643 BuildWebServiceMenu();
650 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
653 public void internalFrameClosed(
654 javax.swing.event.InternalFrameEvent evt)
656 System.out.println("deregistering discoverer listener");
657 Desktop.instance.removeJalviewPropertyChangeListener("services",
659 closeMenuItem_actionPerformed(true);
662 // Finally, build the menu once to get current service state
663 new Thread(new Runnable()
668 BuildWebServiceMenu();
673 public void setGUINucleotide(boolean nucleotide)
675 showTranslation.setVisible(nucleotide);
676 conservationMenuItem.setEnabled(!nucleotide);
677 modifyConservation.setEnabled(!nucleotide);
678 showGroupConservation.setEnabled(!nucleotide);
679 rnahelicesColour.setEnabled(nucleotide);
680 purinePyrimidineColour.setEnabled(nucleotide);
681 // Remember AlignFrame always starts as protein
685 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
690 * set up menus for the currently viewport. This may be called after any
691 * operation that affects the data in the current view (selection changed,
692 * etc) to update the menus to reflect the new state.
694 public void setMenusForViewport()
696 setMenusFromViewport(viewport);
700 * Need to call this method when tabs are selected for multiple views, or when
701 * loading from Jalview2XML.java
706 void setMenusFromViewport(AlignViewport av)
708 padGapsMenuitem.setSelected(av.isPadGaps());
709 colourTextMenuItem.setSelected(av.showColourText);
710 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
711 conservationMenuItem.setSelected(av.getConservationSelected());
712 seqLimits.setSelected(av.getShowJVSuffix());
713 idRightAlign.setSelected(av.rightAlignIds);
714 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
715 renderGapsMenuItem.setSelected(av.renderGaps);
716 wrapMenuItem.setSelected(av.wrapAlignment);
717 scaleAbove.setVisible(av.wrapAlignment);
718 scaleLeft.setVisible(av.wrapAlignment);
719 scaleRight.setVisible(av.wrapAlignment);
720 annotationPanelMenuItem.setState(av.showAnnotation);
721 viewBoxesMenuItem.setSelected(av.showBoxes);
722 viewTextMenuItem.setSelected(av.showText);
723 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
724 showGroupConsensus.setSelected(av.isShowGroupConsensus());
725 showGroupConservation.setSelected(av.isShowGroupConservation());
726 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
727 showSequenceLogo.setSelected(av.isShowSequenceLogo());
728 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
730 setColourSelected(ColourSchemeProperty.getColourName(av
731 .getGlobalColourScheme()));
733 showSeqFeatures.setSelected(av.showSequenceFeatures);
734 hiddenMarkers.setState(av.showHiddenMarkers);
735 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
736 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
737 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
738 autoCalculate.setSelected(av.autoCalculateConsensus);
739 sortByTree.setSelected(av.sortByTree);
740 listenToViewSelections.setSelected(av.followSelection);
741 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
743 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
744 setShowProductsEnabled();
748 // methods for implementing IProgressIndicator
749 // need to refactor to a reusable stub class
750 Hashtable progressBars, progressBarHandlers;
755 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
758 public void setProgressBar(String message, long id)
760 if (progressBars == null)
762 progressBars = new Hashtable();
763 progressBarHandlers = new Hashtable();
766 JPanel progressPanel;
767 Long lId = new Long(id);
768 GridLayout layout = (GridLayout) statusPanel.getLayout();
769 if (progressBars.get(lId) != null)
771 progressPanel = (JPanel) progressBars.get(new Long(id));
772 statusPanel.remove(progressPanel);
773 progressBars.remove(lId);
774 progressPanel = null;
777 statusBar.setText(message);
779 if (progressBarHandlers.contains(lId))
781 progressBarHandlers.remove(lId);
783 layout.setRows(layout.getRows() - 1);
787 progressPanel = new JPanel(new BorderLayout(10, 5));
789 JProgressBar progressBar = new JProgressBar();
790 progressBar.setIndeterminate(true);
792 progressPanel.add(new JLabel(message), BorderLayout.WEST);
793 progressPanel.add(progressBar, BorderLayout.CENTER);
795 layout.setRows(layout.getRows() + 1);
796 statusPanel.add(progressPanel);
798 progressBars.put(lId, progressPanel);
801 // setMenusForViewport();
806 public void registerHandler(final long id,
807 final IProgressIndicatorHandler handler)
809 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
812 "call setProgressBar before registering the progress bar's handler.");
814 progressBarHandlers.put(new Long(id), handler);
815 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
816 if (handler.canCancel())
818 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
819 final IProgressIndicator us = this;
820 cancel.addActionListener(new ActionListener()
824 public void actionPerformed(ActionEvent e)
826 handler.cancelActivity(id);
829 + ((JLabel) progressPanel.getComponent(0))
833 progressPanel.add(cancel, BorderLayout.EAST);
839 * @return true if any progress bars are still active
842 public boolean operationInProgress()
844 if (progressBars != null && progressBars.size() > 0)
852 * Added so Castor Mapping file can obtain Jalview Version
854 public String getVersion()
856 return jalview.bin.Cache.getProperty("VERSION");
859 public FeatureRenderer getFeatureRenderer()
861 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
865 public void fetchSequence_actionPerformed(ActionEvent e)
867 new SequenceFetcher(this);
871 public void addFromFile_actionPerformed(ActionEvent e)
873 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
877 public void reload_actionPerformed(ActionEvent e)
879 if (fileName != null)
881 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
882 // originating file's format
883 // TODO: work out how to recover feature settings for correct view(s) when
885 if (currentFileFormat.equals("Jalview"))
887 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
888 for (int i = 0; i < frames.length; i++)
890 if (frames[i] instanceof AlignFrame && frames[i] != this
891 && ((AlignFrame) frames[i]).fileName != null
892 && ((AlignFrame) frames[i]).fileName.equals(fileName))
896 frames[i].setSelected(true);
897 Desktop.instance.closeAssociatedWindows();
898 } catch (java.beans.PropertyVetoException ex)
904 Desktop.instance.closeAssociatedWindows();
906 FileLoader loader = new FileLoader();
907 String protocol = fileName.startsWith("http:") ? "URL" : "File";
908 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
912 Rectangle bounds = this.getBounds();
914 FileLoader loader = new FileLoader();
915 String protocol = fileName.startsWith("http:") ? "URL" : "File";
916 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
917 protocol, currentFileFormat);
919 newframe.setBounds(bounds);
920 if (featureSettings != null && featureSettings.isShowing())
922 final Rectangle fspos = featureSettings.frame.getBounds();
923 // TODO: need a 'show feature settings' function that takes bounds -
924 // need to refactor Desktop.addFrame
925 newframe.featureSettings_actionPerformed(null);
926 final FeatureSettings nfs = newframe.featureSettings;
927 SwingUtilities.invokeLater(new Runnable()
932 nfs.frame.setBounds(fspos);
935 this.featureSettings.close();
936 this.featureSettings = null;
938 this.closeMenuItem_actionPerformed(true);
944 public void addFromText_actionPerformed(ActionEvent e)
946 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
950 public void addFromURL_actionPerformed(ActionEvent e)
952 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
956 public void save_actionPerformed(ActionEvent e)
959 || (currentFileFormat == null || !jalview.io.FormatAdapter
960 .isValidIOFormat(currentFileFormat, true))
961 || fileName.startsWith("http"))
963 saveAs_actionPerformed(null);
967 saveAlignment(fileName, currentFileFormat);
978 public void saveAs_actionPerformed(ActionEvent e)
980 JalviewFileChooser chooser = new JalviewFileChooser(
981 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
982 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
983 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
984 currentFileFormat, false);
986 chooser.setFileView(new JalviewFileView());
987 chooser.setDialogTitle("Save Alignment to file");
988 chooser.setToolTipText("Save");
990 int value = chooser.showSaveDialog(this);
992 if (value == JalviewFileChooser.APPROVE_OPTION)
994 currentFileFormat = chooser.getSelectedFormat();
995 if (currentFileFormat == null)
997 JOptionPane.showInternalMessageDialog(Desktop.desktop,
998 MessageManager.getString("label.select_file_format_before_saving"),
999 MessageManager.getString("label.file_format_not_specified"), JOptionPane.WARNING_MESSAGE);
1000 value = chooser.showSaveDialog(this);
1004 fileName = chooser.getSelectedFile().getPath();
1006 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1009 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1010 if (currentFileFormat.indexOf(" ") > -1)
1012 currentFileFormat = currentFileFormat.substring(0,
1013 currentFileFormat.indexOf(" "));
1015 saveAlignment(fileName, currentFileFormat);
1019 public boolean saveAlignment(String file, String format)
1021 boolean success = true;
1023 if (format.equalsIgnoreCase("Jalview"))
1025 String shortName = title;
1027 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1029 shortName = shortName.substring(shortName
1030 .lastIndexOf(java.io.File.separatorChar) + 1);
1033 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1035 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1041 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1043 warningMessage("Cannot save file " + fileName + " using format "
1044 + format, "Alignment output format not supported");
1045 saveAs_actionPerformed(null);
1046 // JBPNote need to have a raise_gui flag here
1050 String[] omitHidden = null;
1052 if (viewport.hasHiddenColumns())
1054 int reply = JOptionPane
1055 .showInternalConfirmDialog(
1057 MessageManager.getString("label.alignment_contains_hidden_columns"),
1058 MessageManager.getString("action.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(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1089 } catch (Exception ex)
1092 ex.printStackTrace();
1099 JOptionPane.showInternalMessageDialog(this, MessageManager.formatMessage("label.couldnt_save_file", new String[]{fileName}),
1100 MessageManager.getString("label.error_saving_file"), JOptionPane.WARNING_MESSAGE);
1106 private void warningMessage(String warning, String title)
1108 if (new jalview.util.Platform().isHeadless())
1110 System.err.println("Warning: " + title + "\nWarning: " + warning);
1115 JOptionPane.showInternalMessageDialog(this, warning, title,
1116 JOptionPane.WARNING_MESSAGE);
1128 protected void outputText_actionPerformed(ActionEvent e)
1130 String[] omitHidden = null;
1132 if (viewport.hasHiddenColumns())
1134 int reply = JOptionPane
1135 .showInternalConfirmDialog(
1137 MessageManager.getString("label.alignment_contains_hidden_columns"),
1138 MessageManager.getString("action.save_omit_hidden_columns"),
1139 JOptionPane.YES_NO_OPTION,
1140 JOptionPane.QUESTION_MESSAGE);
1142 if (reply == JOptionPane.YES_OPTION)
1144 omitHidden = viewport.getViewAsString(false);
1148 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1149 cap.setForInput(null);
1153 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1154 viewport.getAlignment(), omitHidden,
1155 viewport.getColumnSelection()));
1156 Desktop.addInternalFrame(cap,
1157 "Alignment output - " + e.getActionCommand(), 600, 500);
1158 } catch (OutOfMemoryError oom)
1160 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1173 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1175 new HTMLOutput(alignPanel,
1176 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1177 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1180 public void createImageMap(File file, String image)
1182 alignPanel.makePNGImageMap(file, image);
1192 public void createPNG(File f)
1194 alignPanel.makePNG(f);
1204 public void createEPS(File f)
1206 alignPanel.makeEPS(f);
1210 public void pageSetup_actionPerformed(ActionEvent e)
1212 PrinterJob printJob = PrinterJob.getPrinterJob();
1213 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1223 public void printMenuItem_actionPerformed(ActionEvent e)
1225 // Putting in a thread avoids Swing painting problems
1226 PrintThread thread = new PrintThread(alignPanel);
1231 public void exportFeatures_actionPerformed(ActionEvent e)
1233 new AnnotationExporter().exportFeatures(alignPanel);
1237 public void exportAnnotations_actionPerformed(ActionEvent e)
1239 new AnnotationExporter().exportAnnotations(alignPanel,
1240 viewport.showAnnotation ? viewport.getAlignment()
1241 .getAlignmentAnnotation() : null, viewport
1242 .getAlignment().getGroups(), ((Alignment) viewport
1243 .getAlignment()).alignmentProperties);
1247 public void associatedData_actionPerformed(ActionEvent e)
1249 // Pick the tree file
1250 JalviewFileChooser chooser = new JalviewFileChooser(
1251 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1252 chooser.setFileView(new JalviewFileView());
1253 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1254 chooser.setToolTipText("Load Jalview Annotations / Features file");
1256 int value = chooser.showOpenDialog(null);
1258 if (value == JalviewFileChooser.APPROVE_OPTION)
1260 String choice = chooser.getSelectedFile().getPath();
1261 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1262 loadJalviewDataFile(choice, null, null, null);
1268 * Close the current view or all views in the alignment frame. If the frame
1269 * only contains one view then the alignment will be removed from memory.
1271 * @param closeAllTabs
1274 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1276 if (alignPanels != null && alignPanels.size() < 2)
1278 closeAllTabs = true;
1283 if (alignPanels != null)
1287 if (this.isClosed())
1289 // really close all the windows - otherwise wait till
1290 // setClosed(true) is called
1291 for (int i = 0; i < alignPanels.size(); i++)
1293 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1300 closeView(alignPanel);
1306 this.setClosed(true);
1308 } catch (Exception ex)
1310 ex.printStackTrace();
1315 * close alignPanel2 and shuffle tabs appropriately.
1317 * @param alignPanel2
1319 public void closeView(AlignmentPanel alignPanel2)
1321 int index = tabbedPane.getSelectedIndex();
1322 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1323 alignPanels.removeElement(alignPanel2);
1325 // if (viewport == alignPanel2.av)
1329 alignPanel2.closePanel();
1332 tabbedPane.removeTabAt(closedindex);
1333 tabbedPane.validate();
1335 if (index > closedindex || index == tabbedPane.getTabCount())
1337 // modify currently selected tab index if necessary.
1341 this.tabSelectionChanged(index);
1347 void updateEditMenuBar()
1350 if (viewport.historyList.size() > 0)
1352 undoMenuItem.setEnabled(true);
1353 CommandI command = (CommandI) viewport.historyList.peek();
1354 undoMenuItem.setText(MessageManager.formatMessage("label.undo_command", new String[]{command.getDescription()}));
1358 undoMenuItem.setEnabled(false);
1359 undoMenuItem.setText(MessageManager.getString("action.undo"));
1362 if (viewport.redoList.size() > 0)
1364 redoMenuItem.setEnabled(true);
1366 CommandI command = (CommandI) viewport.redoList.peek();
1367 redoMenuItem.setText(MessageManager.formatMessage("label.redo_command", new String[]{command.getDescription()}));
1371 redoMenuItem.setEnabled(false);
1372 redoMenuItem.setText(MessageManager.getString("action.redo"));
1376 public void addHistoryItem(CommandI command)
1378 if (command.getSize() > 0)
1380 viewport.historyList.push(command);
1381 viewport.redoList.clear();
1382 updateEditMenuBar();
1383 viewport.updateHiddenColumns();
1384 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1385 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1386 // viewport.getColumnSelection()
1387 // .getHiddenColumns().size() > 0);
1393 * @return alignment objects for all views
1395 AlignmentI[] getViewAlignments()
1397 if (alignPanels != null)
1399 Enumeration e = alignPanels.elements();
1400 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1401 for (int i = 0; e.hasMoreElements(); i++)
1403 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1407 if (viewport != null)
1409 return new AlignmentI[]
1410 { viewport.getAlignment() };
1422 protected void undoMenuItem_actionPerformed(ActionEvent e)
1424 if (viewport.historyList.empty())
1426 CommandI command = (CommandI) viewport.historyList.pop();
1427 viewport.redoList.push(command);
1428 command.undoCommand(getViewAlignments());
1430 AlignViewport originalSource = getOriginatingSource(command);
1431 updateEditMenuBar();
1433 if (originalSource != null)
1435 if (originalSource != viewport)
1438 .warn("Implementation worry: mismatch of viewport origin for undo");
1440 originalSource.updateHiddenColumns();
1441 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1443 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1444 // viewport.getColumnSelection()
1445 // .getHiddenColumns().size() > 0);
1446 originalSource.firePropertyChange("alignment", null, originalSource
1447 .getAlignment().getSequences());
1458 protected void redoMenuItem_actionPerformed(ActionEvent e)
1460 if (viewport.redoList.size() < 1)
1465 CommandI command = (CommandI) viewport.redoList.pop();
1466 viewport.historyList.push(command);
1467 command.doCommand(getViewAlignments());
1469 AlignViewport originalSource = getOriginatingSource(command);
1470 updateEditMenuBar();
1472 if (originalSource != null)
1475 if (originalSource != viewport)
1478 .warn("Implementation worry: mismatch of viewport origin for redo");
1480 originalSource.updateHiddenColumns();
1481 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1483 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1484 // viewport.getColumnSelection()
1485 // .getHiddenColumns().size() > 0);
1486 originalSource.firePropertyChange("alignment", null, originalSource
1487 .getAlignment().getSequences());
1491 AlignViewport getOriginatingSource(CommandI command)
1493 AlignViewport originalSource = null;
1494 // For sequence removal and addition, we need to fire
1495 // the property change event FROM the viewport where the
1496 // original alignment was altered
1497 AlignmentI al = null;
1498 if (command instanceof EditCommand)
1500 EditCommand editCommand = (EditCommand) command;
1501 al = editCommand.getAlignment();
1502 Vector comps = (Vector) PaintRefresher.components.get(viewport
1503 .getSequenceSetId());
1505 for (int i = 0; i < comps.size(); i++)
1507 if (comps.elementAt(i) instanceof AlignmentPanel)
1509 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1511 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1518 if (originalSource == null)
1520 // The original view is closed, we must validate
1521 // the current view against the closed view first
1524 PaintRefresher.validateSequences(al, viewport.getAlignment());
1527 originalSource = viewport;
1530 return originalSource;
1539 public void moveSelectedSequences(boolean up)
1541 SequenceGroup sg = viewport.getSelectionGroup();
1547 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1548 viewport.getHiddenRepSequences(), up);
1549 alignPanel.paintAlignment(true);
1552 synchronized void slideSequences(boolean right, int size)
1554 List<SequenceI> sg = new Vector();
1555 if (viewport.cursorMode)
1557 sg.add(viewport.getAlignment().getSequenceAt(
1558 alignPanel.seqPanel.seqCanvas.cursorY));
1560 else if (viewport.getSelectionGroup() != null
1561 && viewport.getSelectionGroup().getSize() != viewport
1562 .getAlignment().getHeight())
1564 sg = viewport.getSelectionGroup().getSequences(
1565 viewport.getHiddenRepSequences());
1573 Vector invertGroup = new Vector();
1575 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1577 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1578 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1581 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1583 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1584 for (int i = 0; i < invertGroup.size(); i++)
1585 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1587 SlideSequencesCommand ssc;
1589 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1590 size, viewport.getGapCharacter());
1592 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1593 size, viewport.getGapCharacter());
1595 int groupAdjustment = 0;
1596 if (ssc.getGapsInsertedBegin() && right)
1598 if (viewport.cursorMode)
1599 alignPanel.seqPanel.moveCursor(size, 0);
1601 groupAdjustment = size;
1603 else if (!ssc.getGapsInsertedBegin() && !right)
1605 if (viewport.cursorMode)
1606 alignPanel.seqPanel.moveCursor(-size, 0);
1608 groupAdjustment = -size;
1611 if (groupAdjustment != 0)
1613 viewport.getSelectionGroup().setStartRes(
1614 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1615 viewport.getSelectionGroup().setEndRes(
1616 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1619 boolean appendHistoryItem = false;
1620 if (viewport.historyList != null && viewport.historyList.size() > 0
1621 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1623 appendHistoryItem = ssc
1624 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1628 if (!appendHistoryItem)
1629 addHistoryItem(ssc);
1641 protected void copy_actionPerformed(ActionEvent e)
1644 if (viewport.getSelectionGroup() == null)
1648 // TODO: preserve the ordering of displayed alignment annotation in any
1649 // internal paste (particularly sequence associated annotation)
1650 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1651 String[] omitHidden = null;
1653 if (viewport.hasHiddenColumns())
1655 omitHidden = viewport.getViewAsString(true);
1658 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1661 StringSelection ss = new StringSelection(output);
1665 jalview.gui.Desktop.internalCopy = true;
1666 // Its really worth setting the clipboard contents
1667 // to empty before setting the large StringSelection!!
1668 Toolkit.getDefaultToolkit().getSystemClipboard()
1669 .setContents(new StringSelection(""), null);
1671 Toolkit.getDefaultToolkit().getSystemClipboard()
1672 .setContents(ss, Desktop.instance);
1673 } catch (OutOfMemoryError er)
1675 new OOMWarning("copying region", er);
1679 Vector hiddenColumns = null;
1680 if (viewport.hasHiddenColumns())
1682 hiddenColumns = new Vector();
1683 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1684 .getSelectionGroup().getEndRes();
1685 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1688 int[] region = (int[]) viewport.getColumnSelection()
1689 .getHiddenColumns().elementAt(i);
1690 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1692 hiddenColumns.addElement(new int[]
1693 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1698 Desktop.jalviewClipboard = new Object[]
1699 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1700 statusBar.setText(MessageManager.formatMessage("label.copied_sequences_to_clipboard", new String[]{Integer.valueOf(seqs.length).toString()}));
1710 protected void pasteNew_actionPerformed(ActionEvent e)
1722 protected void pasteThis_actionPerformed(ActionEvent e)
1728 * Paste contents of Jalview clipboard
1730 * @param newAlignment
1731 * true to paste to a new alignment, otherwise add to this.
1733 void paste(boolean newAlignment)
1735 boolean externalPaste = true;
1738 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1739 Transferable contents = c.getContents(this);
1741 if (contents == null)
1749 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1750 if (str.length() < 1)
1755 format = new IdentifyFile().Identify(str, "Paste");
1757 } catch (OutOfMemoryError er)
1759 new OOMWarning("Out of memory pasting sequences!!", er);
1763 SequenceI[] sequences;
1764 boolean annotationAdded = false;
1765 AlignmentI alignment = null;
1767 if (Desktop.jalviewClipboard != null)
1769 // The clipboard was filled from within Jalview, we must use the
1771 // And dataset from the copied alignment
1772 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1773 // be doubly sure that we create *new* sequence objects.
1774 sequences = new SequenceI[newseq.length];
1775 for (int i = 0; i < newseq.length; i++)
1777 sequences[i] = new Sequence(newseq[i]);
1779 alignment = new Alignment(sequences);
1780 externalPaste = false;
1784 // parse the clipboard as an alignment.
1785 alignment = new FormatAdapter().readFile(str, "Paste", format);
1786 sequences = alignment.getSequencesArray();
1790 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1796 if (Desktop.jalviewClipboard != null)
1798 // dataset is inherited
1799 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1803 // new dataset is constructed
1804 alignment.setDataset(null);
1806 alwidth = alignment.getWidth() + 1;
1810 AlignmentI pastedal = alignment; // preserve pasted alignment object
1811 // Add pasted sequences and dataset into existing alignment.
1812 alignment = viewport.getAlignment();
1813 alwidth = alignment.getWidth() + 1;
1814 // decide if we need to import sequences from an existing dataset
1815 boolean importDs = Desktop.jalviewClipboard != null
1816 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1817 // importDs==true instructs us to copy over new dataset sequences from
1818 // an existing alignment
1819 Vector newDs = (importDs) ? new Vector() : null; // used to create
1820 // minimum dataset set
1822 for (int i = 0; i < sequences.length; i++)
1826 newDs.addElement(null);
1828 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1830 if (importDs && ds != null)
1832 if (!newDs.contains(ds))
1834 newDs.setElementAt(ds, i);
1835 ds = new Sequence(ds);
1836 // update with new dataset sequence
1837 sequences[i].setDatasetSequence(ds);
1841 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1846 // copy and derive new dataset sequence
1847 sequences[i] = sequences[i].deriveSequence();
1848 alignment.getDataset().addSequence(
1849 sequences[i].getDatasetSequence());
1850 // TODO: avoid creation of duplicate dataset sequences with a
1851 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1853 alignment.addSequence(sequences[i]); // merges dataset
1857 newDs.clear(); // tidy up
1859 if (alignment.getAlignmentAnnotation() != null)
1861 for (AlignmentAnnotation alan : alignment
1862 .getAlignmentAnnotation())
1864 if (alan.graphGroup > fgroup)
1866 fgroup = alan.graphGroup;
1870 if (pastedal.getAlignmentAnnotation() != null)
1872 // Add any annotation attached to alignment.
1873 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1874 for (int i = 0; i < alann.length; i++)
1876 annotationAdded = true;
1877 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1879 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1880 if (newann.graphGroup > -1)
1882 if (newGraphGroups.size() <= newann.graphGroup
1883 || newGraphGroups.get(newann.graphGroup) == null)
1885 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1887 newGraphGroups.add(q, null);
1889 newGraphGroups.set(newann.graphGroup, new Integer(
1892 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1896 newann.padAnnotation(alwidth);
1897 alignment.addAnnotation(newann);
1907 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1908 sequences, 0, alignment.getWidth(), alignment));
1910 // Add any annotations attached to sequences
1911 for (int i = 0; i < sequences.length; i++)
1913 if (sequences[i].getAnnotation() != null)
1915 AlignmentAnnotation newann;
1916 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1918 annotationAdded = true;
1919 newann = sequences[i].getAnnotation()[a];
1920 newann.adjustForAlignment();
1921 newann.padAnnotation(alwidth);
1922 if (newann.graphGroup > -1)
1924 if (newann.graphGroup > -1)
1926 if (newGraphGroups.size() <= newann.graphGroup
1927 || newGraphGroups.get(newann.graphGroup) == null)
1929 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1931 newGraphGroups.add(q, null);
1933 newGraphGroups.set(newann.graphGroup, new Integer(
1936 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1940 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1945 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1952 // propagate alignment changed.
1953 viewport.setEndSeq(alignment.getHeight());
1954 if (annotationAdded)
1956 // Duplicate sequence annotation in all views.
1957 AlignmentI[] alview = this.getViewAlignments();
1958 for (int i = 0; i < sequences.length; i++)
1960 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1963 for (int avnum = 0; avnum < alview.length; avnum++)
1965 if (alview[avnum] != alignment)
1967 // duplicate in a view other than the one with input focus
1968 int avwidth = alview[avnum].getWidth() + 1;
1969 // this relies on sann being preserved after we
1970 // modify the sequence's annotation array for each duplication
1971 for (int a = 0; a < sann.length; a++)
1973 AlignmentAnnotation newann = new AlignmentAnnotation(
1975 sequences[i].addAlignmentAnnotation(newann);
1976 newann.padAnnotation(avwidth);
1977 alview[avnum].addAnnotation(newann); // annotation was
1978 // duplicated earlier
1979 // TODO JAL-1145 graphGroups are not updated for sequence
1980 // annotation added to several views. This may cause
1982 alview[avnum].setAnnotationIndex(newann, a);
1987 buildSortByAnnotationScoresMenu();
1989 viewport.firePropertyChange("alignment", null,
1990 alignment.getSequences());
1991 if (alignPanels != null)
1993 for (AlignmentPanel ap : ((Vector<AlignmentPanel>) alignPanels))
1995 ap.validateAnnotationDimensions(false);
2000 alignPanel.validateAnnotationDimensions(false);
2006 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2008 String newtitle = new String("Copied sequences");
2010 if (Desktop.jalviewClipboard != null
2011 && Desktop.jalviewClipboard[2] != null)
2013 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2014 for (int i = 0; i < hc.size(); i++)
2016 int[] region = (int[]) hc.elementAt(i);
2017 af.viewport.hideColumns(region[0], region[1]);
2021 // >>>This is a fix for the moment, until a better solution is
2023 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2025 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2027 // TODO: maintain provenance of an alignment, rather than just make the
2028 // title a concatenation of operations.
2031 if (title.startsWith("Copied sequences"))
2037 newtitle = newtitle.concat("- from " + title);
2042 newtitle = new String("Pasted sequences");
2045 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2050 } catch (Exception ex)
2052 ex.printStackTrace();
2053 System.out.println("Exception whilst pasting: " + ex);
2054 // could be anything being pasted in here
2066 protected void cut_actionPerformed(ActionEvent e)
2068 copy_actionPerformed(null);
2069 delete_actionPerformed(null);
2079 protected void delete_actionPerformed(ActionEvent evt)
2082 SequenceGroup sg = viewport.getSelectionGroup();
2088 Vector seqs = new Vector();
2090 for (int i = 0; i < sg.getSize(); i++)
2092 seq = sg.getSequenceAt(i);
2093 seqs.addElement(seq);
2096 // If the cut affects all sequences, remove highlighted columns
2097 if (sg.getSize() == viewport.getAlignment().getHeight())
2099 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2100 sg.getEndRes() + 1);
2103 SequenceI[] cut = new SequenceI[seqs.size()];
2104 for (int i = 0; i < seqs.size(); i++)
2106 cut[i] = (SequenceI) seqs.elementAt(i);
2110 * //ADD HISTORY ITEM
2112 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2113 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2114 viewport.getAlignment()));
2116 viewport.setSelectionGroup(null);
2117 viewport.sendSelection();
2118 viewport.getAlignment().deleteGroup(sg);
2120 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2122 if (viewport.getAlignment().getHeight() < 1)
2126 this.setClosed(true);
2127 } catch (Exception ex)
2140 protected void deleteGroups_actionPerformed(ActionEvent e)
2142 if (avc.deleteGroups()) {
2143 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2144 alignPanel.updateAnnotation();
2145 alignPanel.paintAlignment(true);
2156 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2158 SequenceGroup sg = new SequenceGroup();
2160 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2162 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2165 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2166 viewport.setSelectionGroup(sg);
2167 viewport.sendSelection();
2168 alignPanel.paintAlignment(true);
2169 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2179 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2181 if (viewport.cursorMode)
2183 alignPanel.seqPanel.keyboardNo1 = null;
2184 alignPanel.seqPanel.keyboardNo2 = null;
2186 viewport.setSelectionGroup(null);
2187 viewport.getColumnSelection().clear();
2188 viewport.setSelectionGroup(null);
2189 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2190 alignPanel.idPanel.idCanvas.searchResults = null;
2191 alignPanel.paintAlignment(true);
2192 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2193 viewport.sendSelection();
2203 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2205 SequenceGroup sg = viewport.getSelectionGroup();
2209 selectAllSequenceMenuItem_actionPerformed(null);
2214 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2216 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2219 alignPanel.paintAlignment(true);
2220 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2221 viewport.sendSelection();
2225 public void invertColSel_actionPerformed(ActionEvent e)
2227 viewport.invertColumnSelection();
2228 alignPanel.paintAlignment(true);
2229 viewport.sendSelection();
2239 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2241 trimAlignment(true);
2251 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2253 trimAlignment(false);
2256 void trimAlignment(boolean trimLeft)
2258 ColumnSelection colSel = viewport.getColumnSelection();
2261 if (colSel.size() > 0)
2265 column = colSel.getMin();
2269 column = colSel.getMax();
2273 if (viewport.getSelectionGroup() != null)
2275 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2276 viewport.getHiddenRepSequences());
2280 seqs = viewport.getAlignment().getSequencesArray();
2283 TrimRegionCommand trimRegion;
2286 trimRegion = new TrimRegionCommand("Remove Left",
2287 TrimRegionCommand.TRIM_LEFT, seqs, column,
2288 viewport.getAlignment(), viewport.getColumnSelection(),
2289 viewport.getSelectionGroup());
2290 viewport.setStartRes(0);
2294 trimRegion = new TrimRegionCommand("Remove Right",
2295 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2296 viewport.getAlignment(), viewport.getColumnSelection(),
2297 viewport.getSelectionGroup());
2300 statusBar.setText(MessageManager.formatMessage("label.removed_columns", new String[]{Integer.valueOf(trimRegion.getSize()).toString()}));
2302 addHistoryItem(trimRegion);
2304 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2306 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2307 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2309 viewport.getAlignment().deleteGroup(sg);
2313 viewport.firePropertyChange("alignment", null, viewport
2314 .getAlignment().getSequences());
2325 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2327 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2330 if (viewport.getSelectionGroup() != null)
2332 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2333 viewport.getHiddenRepSequences());
2334 start = viewport.getSelectionGroup().getStartRes();
2335 end = viewport.getSelectionGroup().getEndRes();
2339 seqs = viewport.getAlignment().getSequencesArray();
2342 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2343 "Remove Gapped Columns", seqs, start, end,
2344 viewport.getAlignment());
2346 addHistoryItem(removeGapCols);
2348 statusBar.setText(MessageManager.formatMessage("label.removed_empty_columns", new String[]{Integer.valueOf(removeGapCols.getSize()).toString()}));
2350 // This is to maintain viewport position on first residue
2351 // of first sequence
2352 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2353 int startRes = seq.findPosition(viewport.startRes);
2354 // ShiftList shifts;
2355 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2356 // edit.alColumnChanges=shifts.getInverse();
2357 // if (viewport.hasHiddenColumns)
2358 // viewport.getColumnSelection().compensateForEdits(shifts);
2359 viewport.setStartRes(seq.findIndex(startRes) - 1);
2360 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2372 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2374 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2377 if (viewport.getSelectionGroup() != null)
2379 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2380 viewport.getHiddenRepSequences());
2381 start = viewport.getSelectionGroup().getStartRes();
2382 end = viewport.getSelectionGroup().getEndRes();
2386 seqs = viewport.getAlignment().getSequencesArray();
2389 // This is to maintain viewport position on first residue
2390 // of first sequence
2391 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2392 int startRes = seq.findPosition(viewport.startRes);
2394 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2395 viewport.getAlignment()));
2397 viewport.setStartRes(seq.findIndex(startRes) - 1);
2399 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2411 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2413 viewport.setPadGaps(padGapsMenuitem.isSelected());
2414 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2420 // if (justifySeqs>0)
2422 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2435 public void findMenuItem_actionPerformed(ActionEvent e)
2441 public void newView_actionPerformed(ActionEvent e)
2448 * @param copyAnnotation
2449 * if true then duplicate all annnotation, groups and settings
2450 * @return new alignment panel, already displayed.
2452 public AlignmentPanel newView(boolean copyAnnotation)
2454 return newView(null, copyAnnotation);
2460 * title of newly created view
2461 * @return new alignment panel, already displayed.
2463 public AlignmentPanel newView(String viewTitle)
2465 return newView(viewTitle, true);
2471 * title of newly created view
2472 * @param copyAnnotation
2473 * if true then duplicate all annnotation, groups and settings
2474 * @return new alignment panel, already displayed.
2476 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2478 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2480 if (!copyAnnotation)
2482 // just remove all the current annotation except for the automatic stuff
2483 newap.av.getAlignment().deleteAllGroups();
2484 for (AlignmentAnnotation alan : newap.av.getAlignment()
2485 .getAlignmentAnnotation())
2487 if (!alan.autoCalculated)
2489 newap.av.getAlignment().deleteAnnotation(alan);
2495 newap.av.gatherViewsHere = false;
2497 if (viewport.viewName == null)
2499 viewport.viewName = "Original";
2502 newap.av.historyList = viewport.historyList;
2503 newap.av.redoList = viewport.redoList;
2505 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2506 // make sure the new view has a unique name - this is essential for Jalview
2508 boolean addFirstIndex = false;
2509 if (viewTitle == null || viewTitle.trim().length() == 0)
2512 addFirstIndex = true;
2516 index = 1;// we count from 1 if given a specific name
2518 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2519 Vector comps = (Vector) PaintRefresher.components.get(viewport
2520 .getSequenceSetId());
2521 Vector existingNames = new Vector();
2522 for (int i = 0; i < comps.size(); i++)
2524 if (comps.elementAt(i) instanceof AlignmentPanel)
2526 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2527 if (!existingNames.contains(ap.av.viewName))
2529 existingNames.addElement(ap.av.viewName);
2534 while (existingNames.contains(newViewName))
2536 newViewName = viewTitle + " " + (++index);
2539 newap.av.viewName = newViewName;
2541 addAlignmentPanel(newap, true);
2542 newap.alignmentChanged();
2544 if (alignPanels.size() == 2)
2546 viewport.gatherViewsHere = true;
2548 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2553 public void expandViews_actionPerformed(ActionEvent e)
2555 Desktop.instance.explodeViews(this);
2559 public void gatherViews_actionPerformed(ActionEvent e)
2561 Desktop.instance.gatherViews(this);
2571 public void font_actionPerformed(ActionEvent e)
2573 new FontChooser(alignPanel);
2583 protected void seqLimit_actionPerformed(ActionEvent e)
2585 viewport.setShowJVSuffix(seqLimits.isSelected());
2587 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2588 .calculateIdWidth());
2589 alignPanel.paintAlignment(true);
2593 public void idRightAlign_actionPerformed(ActionEvent e)
2595 viewport.rightAlignIds = idRightAlign.isSelected();
2596 alignPanel.paintAlignment(true);
2600 public void centreColumnLabels_actionPerformed(ActionEvent e)
2602 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2603 alignPanel.paintAlignment(true);
2609 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2612 protected void followHighlight_actionPerformed()
2614 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2616 alignPanel.scrollToPosition(
2617 alignPanel.seqPanel.seqCanvas.searchResults, false);
2628 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2630 viewport.setColourText(colourTextMenuItem.isSelected());
2631 alignPanel.paintAlignment(true);
2641 public void wrapMenuItem_actionPerformed(ActionEvent e)
2643 scaleAbove.setVisible(wrapMenuItem.isSelected());
2644 scaleLeft.setVisible(wrapMenuItem.isSelected());
2645 scaleRight.setVisible(wrapMenuItem.isSelected());
2646 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2647 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2651 public void showAllSeqs_actionPerformed(ActionEvent e)
2653 viewport.showAllHiddenSeqs();
2657 public void showAllColumns_actionPerformed(ActionEvent e)
2659 viewport.showAllHiddenColumns();
2664 public void hideSelSequences_actionPerformed(ActionEvent e)
2666 viewport.hideAllSelectedSeqs();
2667 alignPanel.paintAlignment(true);
2671 * called by key handler and the hide all/show all menu items
2676 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2679 boolean hide = false;
2680 SequenceGroup sg = viewport.getSelectionGroup();
2681 if (!toggleSeqs && !toggleCols)
2683 // Hide everything by the current selection - this is a hack - we do the
2684 // invert and then hide
2685 // first check that there will be visible columns after the invert.
2686 if ((viewport.getColumnSelection() != null
2687 && viewport.getColumnSelection().getSelected() != null && viewport
2688 .getColumnSelection().getSelected().size() > 0)
2689 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2692 // now invert the sequence set, if required - empty selection implies
2693 // that no hiding is required.
2696 invertSequenceMenuItem_actionPerformed(null);
2697 sg = viewport.getSelectionGroup();
2701 viewport.expandColSelection(sg, true);
2702 // finally invert the column selection and get the new sequence
2704 invertColSel_actionPerformed(null);
2711 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2713 hideSelSequences_actionPerformed(null);
2716 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2719 showAllSeqs_actionPerformed(null);
2725 if (viewport.getColumnSelection().getSelected().size() > 0)
2727 hideSelColumns_actionPerformed(null);
2730 viewport.setSelectionGroup(sg);
2735 showAllColumns_actionPerformed(null);
2744 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2745 * event.ActionEvent)
2748 public void hideAllButSelection_actionPerformed(ActionEvent e)
2750 toggleHiddenRegions(false, false);
2757 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2761 public void hideAllSelection_actionPerformed(ActionEvent e)
2763 SequenceGroup sg = viewport.getSelectionGroup();
2764 viewport.expandColSelection(sg, false);
2765 viewport.hideAllSelectedSeqs();
2766 viewport.hideSelectedColumns();
2767 alignPanel.paintAlignment(true);
2774 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2778 public void showAllhidden_actionPerformed(ActionEvent e)
2780 viewport.showAllHiddenColumns();
2781 viewport.showAllHiddenSeqs();
2782 alignPanel.paintAlignment(true);
2786 public void hideSelColumns_actionPerformed(ActionEvent e)
2788 viewport.hideSelectedColumns();
2789 alignPanel.paintAlignment(true);
2793 public void hiddenMarkers_actionPerformed(ActionEvent e)
2795 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2806 protected void scaleAbove_actionPerformed(ActionEvent e)
2808 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2809 alignPanel.paintAlignment(true);
2819 protected void scaleLeft_actionPerformed(ActionEvent e)
2821 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2822 alignPanel.paintAlignment(true);
2832 protected void scaleRight_actionPerformed(ActionEvent e)
2834 viewport.setScaleRightWrapped(scaleRight.isSelected());
2835 alignPanel.paintAlignment(true);
2845 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2847 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2848 alignPanel.paintAlignment(true);
2858 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2860 viewport.setShowText(viewTextMenuItem.isSelected());
2861 alignPanel.paintAlignment(true);
2871 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2873 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2874 alignPanel.paintAlignment(true);
2877 public FeatureSettings featureSettings;
2880 public void featureSettings_actionPerformed(ActionEvent e)
2882 if (featureSettings != null)
2884 featureSettings.close();
2885 featureSettings = null;
2887 if (!showSeqFeatures.isSelected())
2889 // make sure features are actually displayed
2890 showSeqFeatures.setSelected(true);
2891 showSeqFeatures_actionPerformed(null);
2893 featureSettings = new FeatureSettings(this);
2897 * Set or clear 'Show Sequence Features'
2903 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2905 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2906 alignPanel.paintAlignment(true);
2907 if (alignPanel.getOverviewPanel() != null)
2909 alignPanel.getOverviewPanel().updateOverviewImage();
2914 * Set or clear 'Show Sequence Features'
2920 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2922 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2924 if (viewport.getShowSequenceFeaturesHeight())
2926 // ensure we're actually displaying features
2927 viewport.setShowSequenceFeatures(true);
2928 showSeqFeatures.setSelected(true);
2930 alignPanel.paintAlignment(true);
2931 if (alignPanel.getOverviewPanel() != null)
2933 alignPanel.getOverviewPanel().updateOverviewImage();
2944 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2946 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2947 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2951 public void alignmentProperties()
2953 JEditorPane editPane = new JEditorPane("text/html", "");
2954 editPane.setEditable(false);
2955 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2957 editPane.setText(MessageManager.formatMessage("label.html_content", new String[]{contents.toString()}));
2958 JInternalFrame frame = new JInternalFrame();
2959 frame.getContentPane().add(new JScrollPane(editPane));
2961 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2962 + getTitle(), 500, 400);
2972 public void overviewMenuItem_actionPerformed(ActionEvent e)
2974 if (alignPanel.overviewPanel != null)
2979 JInternalFrame frame = new JInternalFrame();
2980 OverviewPanel overview = new OverviewPanel(alignPanel);
2981 frame.setContentPane(overview);
2982 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2983 frame.getWidth(), frame.getHeight());
2985 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2986 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2989 public void internalFrameClosed(
2990 javax.swing.event.InternalFrameEvent evt)
2992 alignPanel.setOverviewPanel(null);
2996 alignPanel.setOverviewPanel(overview);
3000 public void textColour_actionPerformed(ActionEvent e)
3002 new TextColourChooser().chooseColour(alignPanel, null);
3012 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3024 public void clustalColour_actionPerformed(ActionEvent e)
3026 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3027 viewport.getHiddenRepSequences()));
3037 public void zappoColour_actionPerformed(ActionEvent e)
3039 changeColour(new ZappoColourScheme());
3049 public void taylorColour_actionPerformed(ActionEvent e)
3051 changeColour(new TaylorColourScheme());
3061 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3063 changeColour(new HydrophobicColourScheme());
3073 public void helixColour_actionPerformed(ActionEvent e)
3075 changeColour(new HelixColourScheme());
3085 public void strandColour_actionPerformed(ActionEvent e)
3087 changeColour(new StrandColourScheme());
3097 public void turnColour_actionPerformed(ActionEvent e)
3099 changeColour(new TurnColourScheme());
3109 public void buriedColour_actionPerformed(ActionEvent e)
3111 changeColour(new BuriedColourScheme());
3121 public void nucleotideColour_actionPerformed(ActionEvent e)
3123 changeColour(new NucleotideColourScheme());
3127 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3129 changeColour(new PurinePyrimidineColourScheme());
3133 * public void covariationColour_actionPerformed(ActionEvent e) {
3135 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3139 public void annotationColour_actionPerformed(ActionEvent e)
3141 new AnnotationColourChooser(viewport, alignPanel);
3145 public void rnahelicesColour_actionPerformed(ActionEvent e)
3147 new RNAHelicesColourChooser(viewport, alignPanel);
3157 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3159 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3168 public void changeColour(ColourSchemeI cs)
3170 // TODO: compare with applet and pull up to model method
3175 if (viewport.getAbovePIDThreshold())
3177 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3180 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3182 viewport.setGlobalColourScheme(cs);
3186 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3189 if (viewport.getConservationSelected())
3192 Alignment al = (Alignment) viewport.getAlignment();
3193 Conservation c = new Conservation("All",
3194 ResidueProperties.propHash, 3, al.getSequences(), 0,
3198 c.verdict(false, viewport.getConsPercGaps());
3200 cs.setConservation(c);
3202 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3207 cs.setConservation(null);
3210 cs.setConsensus(viewport.getSequenceConsensusHash());
3213 viewport.setGlobalColourScheme(cs);
3215 if (viewport.getColourAppliesToAllGroups())
3218 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3226 if (cs instanceof ClustalxColourScheme)
3228 sg.cs = new ClustalxColourScheme(sg,
3229 viewport.getHiddenRepSequences());
3231 else if (cs instanceof UserColourScheme)
3233 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3239 sg.cs = cs.getClass().newInstance();
3240 } catch (Exception ex)
3245 if (viewport.getAbovePIDThreshold()
3246 || cs instanceof PIDColourScheme
3247 || cs instanceof Blosum62ColourScheme)
3249 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3251 sg.cs.setConsensus(AAFrequency.calculate(
3252 sg.getSequences(viewport.getHiddenRepSequences()),
3253 sg.getStartRes(), sg.getEndRes() + 1));
3257 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3260 if (viewport.getConservationSelected())
3262 Conservation c = new Conservation("Group",
3263 ResidueProperties.propHash, 3, sg.getSequences(viewport
3264 .getHiddenRepSequences()), sg.getStartRes(),
3265 sg.getEndRes() + 1);
3267 c.verdict(false, viewport.getConsPercGaps());
3268 sg.cs.setConservation(c);
3272 sg.cs.setConservation(null);
3277 if (alignPanel.getOverviewPanel() != null)
3279 alignPanel.getOverviewPanel().updateOverviewImage();
3282 alignPanel.paintAlignment(true);
3292 protected void modifyPID_actionPerformed(ActionEvent e)
3294 if (viewport.getAbovePIDThreshold()
3295 && viewport.getGlobalColourScheme() != null)
3297 SliderPanel.setPIDSliderSource(alignPanel,
3298 viewport.getGlobalColourScheme(), "Background");
3299 SliderPanel.showPIDSlider();
3310 protected void modifyConservation_actionPerformed(ActionEvent e)
3312 if (viewport.getConservationSelected()
3313 && viewport.getGlobalColourScheme() != null)
3315 SliderPanel.setConservationSlider(alignPanel,
3316 viewport.getGlobalColourScheme(), "Background");
3317 SliderPanel.showConservationSlider();
3328 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3330 viewport.setConservationSelected(conservationMenuItem.isSelected());
3332 viewport.setAbovePIDThreshold(false);
3333 abovePIDThreshold.setSelected(false);
3335 changeColour(viewport.getGlobalColourScheme());
3337 modifyConservation_actionPerformed(null);
3347 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3349 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3351 conservationMenuItem.setSelected(false);
3352 viewport.setConservationSelected(false);
3354 changeColour(viewport.getGlobalColourScheme());
3356 modifyPID_actionPerformed(null);
3366 public void userDefinedColour_actionPerformed(ActionEvent e)
3368 if (e.getActionCommand().equals("User Defined..."))
3370 new UserDefinedColours(alignPanel, null);
3374 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3375 .getUserColourSchemes().get(e.getActionCommand());
3381 public void updateUserColourMenu()
3384 Component[] menuItems = colourMenu.getMenuComponents();
3385 int i, iSize = menuItems.length;
3386 for (i = 0; i < iSize; i++)
3388 if (menuItems[i].getName() != null
3389 && menuItems[i].getName().equals("USER_DEFINED"))
3391 colourMenu.remove(menuItems[i]);
3395 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3397 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3398 .getUserColourSchemes().keys();
3400 while (userColours.hasMoreElements())
3402 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3403 userColours.nextElement().toString());
3404 radioItem.setName("USER_DEFINED");
3405 radioItem.addMouseListener(new MouseAdapter()
3408 public void mousePressed(MouseEvent evt)
3410 if (evt.isControlDown()
3411 || SwingUtilities.isRightMouseButton(evt))
3413 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3415 int option = JOptionPane.showInternalConfirmDialog(
3416 jalview.gui.Desktop.desktop,
3417 MessageManager.getString("label.remove_from_default_list"),
3418 MessageManager.getString("label.remove_user_defined_colour"),
3419 JOptionPane.YES_NO_OPTION);
3420 if (option == JOptionPane.YES_OPTION)
3422 jalview.gui.UserDefinedColours
3423 .removeColourFromDefaults(radioItem.getText());
3424 colourMenu.remove(radioItem);
3428 radioItem.addActionListener(new ActionListener()
3431 public void actionPerformed(ActionEvent evt)
3433 userDefinedColour_actionPerformed(evt);
3440 radioItem.addActionListener(new ActionListener()
3443 public void actionPerformed(ActionEvent evt)
3445 userDefinedColour_actionPerformed(evt);
3449 colourMenu.insert(radioItem, 15);
3450 colours.add(radioItem);
3462 public void PIDColour_actionPerformed(ActionEvent e)
3464 changeColour(new PIDColourScheme());
3474 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3476 changeColour(new Blosum62ColourScheme());
3486 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3488 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3489 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3490 .getAlignment().getSequenceAt(0), null);
3491 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3492 viewport.getAlignment()));
3493 alignPanel.paintAlignment(true);
3503 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3505 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3506 AlignmentSorter.sortByID(viewport.getAlignment());
3507 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3508 viewport.getAlignment()));
3509 alignPanel.paintAlignment(true);
3519 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3521 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3522 AlignmentSorter.sortByLength(viewport.getAlignment());
3523 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3524 viewport.getAlignment()));
3525 alignPanel.paintAlignment(true);
3535 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3537 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3538 AlignmentSorter.sortByGroup(viewport.getAlignment());
3539 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3540 viewport.getAlignment()));
3542 alignPanel.paintAlignment(true);
3552 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3554 new RedundancyPanel(alignPanel, this);
3564 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3566 if ((viewport.getSelectionGroup() == null)
3567 || (viewport.getSelectionGroup().getSize() < 2))
3569 JOptionPane.showInternalMessageDialog(this,
3570 MessageManager.getString("label.you_must_select_least_two_sequences"), MessageManager.getString("label.invalid_selection"),
3571 JOptionPane.WARNING_MESSAGE);
3575 JInternalFrame frame = new JInternalFrame();
3576 frame.setContentPane(new PairwiseAlignPanel(viewport));
3577 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3588 public void PCAMenuItem_actionPerformed(ActionEvent e)
3590 if (((viewport.getSelectionGroup() != null)
3591 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3592 .getSelectionGroup().getSize() > 0))
3593 || (viewport.getAlignment().getHeight() < 4))
3595 JOptionPane.showInternalMessageDialog(this,
3596 MessageManager.getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3597 MessageManager.getString("label.sequence_selection_insufficient"),
3598 JOptionPane.WARNING_MESSAGE);
3603 new PCAPanel(alignPanel);
3607 public void autoCalculate_actionPerformed(ActionEvent e)
3609 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3610 if (viewport.autoCalculateConsensus)
3612 viewport.firePropertyChange("alignment", null, viewport
3613 .getAlignment().getSequences());
3618 public void sortByTreeOption_actionPerformed(ActionEvent e)
3620 viewport.sortByTree = sortByTree.isSelected();
3624 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3626 viewport.followSelection = listenToViewSelections.isSelected();
3636 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3638 NewTreePanel("AV", "PID", "Average distance tree using PID");
3648 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3650 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3660 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3662 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3672 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3674 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3687 void NewTreePanel(String type, String pwType, String title)
3691 if (viewport.getSelectionGroup() != null
3692 && viewport.getSelectionGroup().getSize() > 0)
3694 if (viewport.getSelectionGroup().getSize() < 3)
3699 MessageManager.getString("label.you_need_more_two_sequences_selected_build_tree"),
3700 MessageManager.getString("label.not_enough_sequences"), JOptionPane.WARNING_MESSAGE);
3704 SequenceGroup sg = viewport.getSelectionGroup();
3706 /* Decide if the selection is a column region */
3707 for (SequenceI _s : sg.getSequences())
3709 if (_s.getLength() < sg.getEndRes())
3714 MessageManager.getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3715 MessageManager.getString("label.sequences_selection_not_aligned"),
3716 JOptionPane.WARNING_MESSAGE);
3722 title = title + " on region";
3723 tp = new TreePanel(alignPanel, type, pwType);
3727 // are the visible sequences aligned?
3728 if (!viewport.getAlignment().isAligned(false))
3733 MessageManager.getString("label.sequences_must_be_aligned_before_creating_tree"),
3734 MessageManager.getString("label.sequences_not_aligned"),
3735 JOptionPane.WARNING_MESSAGE);
3740 if (viewport.getAlignment().getHeight() < 2)
3745 tp = new TreePanel(alignPanel, type, pwType);
3750 if (viewport.viewName != null)
3752 title += viewport.viewName + " of ";
3755 title += this.title;
3757 Desktop.addInternalFrame(tp, title, 600, 500);
3768 public void addSortByOrderMenuItem(String title,
3769 final AlignmentOrder order)
3771 final JMenuItem item = new JMenuItem("by " + title);
3773 item.addActionListener(new java.awt.event.ActionListener()
3776 public void actionPerformed(ActionEvent e)
3778 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3780 // TODO: JBPNote - have to map order entries to curent SequenceI
3782 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3784 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3787 alignPanel.paintAlignment(true);
3793 * Add a new sort by annotation score menu item
3796 * the menu to add the option to
3798 * the label used to retrieve scores for each sequence on the
3801 public void addSortByAnnotScoreMenuItem(JMenu sort,
3802 final String scoreLabel)
3804 final JMenuItem item = new JMenuItem(scoreLabel);
3806 item.addActionListener(new java.awt.event.ActionListener()
3809 public void actionPerformed(ActionEvent e)
3811 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3812 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3813 viewport.getAlignment());// ,viewport.getSelectionGroup());
3814 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3815 viewport.getAlignment()));
3816 alignPanel.paintAlignment(true);
3822 * last hash for alignment's annotation array - used to minimise cost of
3825 protected int _annotationScoreVectorHash;
3828 * search the alignment and rebuild the sort by annotation score submenu the
3829 * last alignment annotation vector hash is stored to minimize cost of
3830 * rebuilding in subsequence calls.
3834 public void buildSortByAnnotationScoresMenu()
3836 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3841 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3843 sortByAnnotScore.removeAll();
3844 // almost certainly a quicker way to do this - but we keep it simple
3845 Hashtable scoreSorts = new Hashtable();
3846 AlignmentAnnotation aann[];
3847 for (SequenceI sqa : viewport.getAlignment().getSequences())
3849 aann = sqa.getAnnotation();
3850 for (int i = 0; aann != null && i < aann.length; i++)
3852 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3854 scoreSorts.put(aann[i].label, aann[i].label);
3858 Enumeration labels = scoreSorts.keys();
3859 while (labels.hasMoreElements())
3861 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3862 (String) labels.nextElement());
3864 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3867 _annotationScoreVectorHash = viewport.getAlignment()
3868 .getAlignmentAnnotation().hashCode();
3873 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3874 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3875 * call. Listeners are added to remove the menu item when the treePanel is
3876 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3880 * Displayed tree window.
3882 * SortBy menu item title.
3885 public void buildTreeMenu()
3887 sortByTreeMenu.removeAll();
3889 Vector comps = (Vector) PaintRefresher.components.get(viewport
3890 .getSequenceSetId());
3891 Vector treePanels = new Vector();
3892 int i, iSize = comps.size();
3893 for (i = 0; i < iSize; i++)
3895 if (comps.elementAt(i) instanceof TreePanel)
3897 treePanels.add(comps.elementAt(i));
3901 iSize = treePanels.size();
3905 sortByTreeMenu.setVisible(false);
3909 sortByTreeMenu.setVisible(true);
3911 for (i = 0; i < treePanels.size(); i++)
3913 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3914 final JMenuItem item = new JMenuItem(tp.getTitle());
3915 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3916 item.addActionListener(new java.awt.event.ActionListener()
3919 public void actionPerformed(ActionEvent e)
3921 tp.sortByTree_actionPerformed(null);
3922 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3927 sortByTreeMenu.add(item);
3931 public boolean sortBy(AlignmentOrder alorder, String undoname)
3933 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3934 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3935 if (undoname != null)
3937 addHistoryItem(new OrderCommand(undoname, oldOrder,
3938 viewport.getAlignment()));
3940 alignPanel.paintAlignment(true);
3945 * Work out whether the whole set of sequences or just the selected set will
3946 * be submitted for multiple alignment.
3949 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3951 // Now, check we have enough sequences
3952 AlignmentView msa = null;
3954 if ((viewport.getSelectionGroup() != null)
3955 && (viewport.getSelectionGroup().getSize() > 1))
3957 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3958 // some common interface!
3960 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3961 * SequenceI[sz = seqs.getSize(false)];
3963 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3964 * seqs.getSequenceAt(i); }
3966 msa = viewport.getAlignmentView(true);
3971 * Vector seqs = viewport.getAlignment().getSequences();
3973 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3975 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3976 * seqs.elementAt(i); } }
3978 msa = viewport.getAlignmentView(false);
3984 * Decides what is submitted to a secondary structure prediction service: the
3985 * first sequence in the alignment, or in the current selection, or, if the
3986 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3987 * region or the whole alignment. (where the first sequence in the set is the
3988 * one that the prediction will be for).
3990 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3992 AlignmentView seqs = null;
3994 if ((viewport.getSelectionGroup() != null)
3995 && (viewport.getSelectionGroup().getSize() > 0))
3997 seqs = viewport.getAlignmentView(true);
4001 seqs = viewport.getAlignmentView(false);
4003 // limit sequences - JBPNote in future - could spawn multiple prediction
4005 // TODO: viewport.getAlignment().isAligned is a global state - the local
4006 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4007 if (!viewport.getAlignment().isAligned(false))
4009 seqs.setSequences(new SeqCigar[]
4010 { seqs.getSequences()[0] });
4011 // TODO: if seqs.getSequences().length>1 then should really have warned
4025 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4027 // Pick the tree file
4028 JalviewFileChooser chooser = new JalviewFileChooser(
4029 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4030 chooser.setFileView(new JalviewFileView());
4031 chooser.setDialogTitle("Select a newick-like tree file");
4032 chooser.setToolTipText("Load a tree file");
4034 int value = chooser.showOpenDialog(null);
4036 if (value == JalviewFileChooser.APPROVE_OPTION)
4038 String choice = chooser.getSelectedFile().getPath();
4039 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4040 jalview.io.NewickFile fin = null;
4043 fin = new jalview.io.NewickFile(choice, "File");
4044 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4045 } catch (Exception ex)
4047 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4048 MessageManager.getString("label.problem_reading_tree_file"), JOptionPane.WARNING_MESSAGE);
4049 ex.printStackTrace();
4051 if (fin != null && fin.hasWarningMessage())
4053 JOptionPane.showMessageDialog(Desktop.desktop,
4054 fin.getWarningMessage(), MessageManager.getString("label.possible_problem_with_tree_file"),
4055 JOptionPane.WARNING_MESSAGE);
4061 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4063 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4066 public TreePanel ShowNewickTree(NewickFile nf, String title)
4068 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4071 public TreePanel ShowNewickTree(NewickFile nf, String title,
4072 AlignmentView input)
4074 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4077 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4078 int h, int x, int y)
4080 return ShowNewickTree(nf, title, null, w, h, x, y);
4084 * Add a treeviewer for the tree extracted from a newick file object to the
4085 * current alignment view
4092 * Associated alignment input data (or null)
4101 * @return TreePanel handle
4103 public TreePanel ShowNewickTree(NewickFile nf, String title,
4104 AlignmentView input, int w, int h, int x, int y)
4106 TreePanel tp = null;
4112 if (nf.getTree() != null)
4114 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4120 tp.setLocation(x, y);
4123 Desktop.addInternalFrame(tp, title, w, h);
4125 } catch (Exception ex)
4127 ex.printStackTrace();
4133 private boolean buildingMenu = false;
4136 * Generates menu items and listener event actions for web service clients
4139 public void BuildWebServiceMenu()
4141 while (buildingMenu)
4145 System.err.println("Waiting for building menu to finish.");
4147 } catch (Exception e)
4152 final AlignFrame me = this;
4153 buildingMenu = true;
4154 new Thread(new Runnable()
4159 final List<JMenuItem> legacyItems=new ArrayList<JMenuItem>();
4162 System.err.println("Building ws menu again "
4163 + Thread.currentThread());
4164 // TODO: add support for context dependent disabling of services based
4166 // alignment and current selection
4167 // TODO: add additional serviceHandle parameter to specify abstract
4169 // class independently of AbstractName
4170 // TODO: add in rediscovery GUI function to restart discoverer
4171 // TODO: group services by location as well as function and/or
4173 // object broker mechanism.
4174 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4175 final IProgressIndicator af = me;
4176 final JMenu msawsmenu = new JMenu("Alignment");
4177 final JMenu secstrmenu = new JMenu(
4178 "Secondary Structure Prediction");
4179 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4180 final JMenu analymenu = new JMenu("Analysis");
4181 final JMenu dismenu = new JMenu("Protein Disorder");
4182 // JAL-940 - only show secondary structure prediction services from
4183 // the legacy server
4184 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4186 Discoverer.services != null && (Discoverer.services.size() > 0))
4188 // TODO: refactor to allow list of AbstractName/Handler bindings to
4190 // stored or retrieved from elsewhere
4191 // No MSAWS used any more:
4192 // Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4193 Vector secstrpr = (Vector) Discoverer.services
4195 if (secstrpr != null)
4197 // Add any secondary structure prediction services
4198 for (int i = 0, j = secstrpr.size(); i < j; i++)
4200 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4202 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4203 .getServiceClient(sh);
4204 int p=secstrmenu.getItemCount();
4205 impl.attachWSMenuEntry(secstrmenu, me);
4206 int q=secstrmenu.getItemCount();
4207 for (int litm=p;litm<q; litm++)
4209 legacyItems.add(secstrmenu.getItem(litm));
4215 // Add all submenus in the order they should appear on the web
4217 wsmenu.add(msawsmenu);
4218 wsmenu.add(secstrmenu);
4219 wsmenu.add(dismenu);
4220 wsmenu.add(analymenu);
4221 // No search services yet
4222 // wsmenu.add(seqsrchmenu);
4224 javax.swing.SwingUtilities.invokeLater(new Runnable()
4231 webService.removeAll();
4232 // first, add discovered services onto the webservices menu
4233 if (wsmenu.size() > 0)
4235 for (int i = 0, j = wsmenu.size(); i < j; i++)
4237 webService.add(wsmenu.get(i));
4242 webService.add(me.webServiceNoServices);
4244 // TODO: move into separate menu builder class.
4245 boolean new_sspred=false;
4246 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4248 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4249 if (jws2servs != null)
4251 if (jws2servs.hasServices())
4253 jws2servs.attachWSMenuEntry(webService, me);
4254 for (Jws2Instance sv:jws2servs.getServices()) {
4255 if (sv.description.toLowerCase().contains("jpred"))
4257 for (JMenuItem jmi:legacyItems)
4259 jmi.setVisible(false);
4265 if (jws2servs.isRunning())
4267 JMenuItem tm = new JMenuItem(
4268 "Still discovering JABA Services");
4269 tm.setEnabled(false);
4274 build_urlServiceMenu(me.webService);
4275 build_fetchdbmenu(webService);
4276 for (JMenu item : wsmenu)
4278 if (item.getItemCount() == 0)
4280 item.setEnabled(false);
4284 item.setEnabled(true);
4287 } catch (Exception e)
4290 .debug("Exception during web service menu building process.",
4296 } catch (Exception e)
4301 buildingMenu = false;
4308 * construct any groupURL type service menu entries.
4312 private void build_urlServiceMenu(JMenu webService)
4314 // TODO: remove this code when 2.7 is released
4315 // DEBUG - alignmentView
4317 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4318 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4320 * @Override public void actionPerformed(ActionEvent e) {
4321 * jalview.datamodel.AlignmentView
4322 * .testSelectionViews(af.viewport.getAlignment(),
4323 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4325 * }); webService.add(testAlView);
4327 // TODO: refactor to RestClient discoverer and merge menu entries for
4328 // rest-style services with other types of analysis/calculation service
4329 // SHmmr test client - still being implemented.
4330 // DEBUG - alignmentView
4332 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4335 client.attachWSMenuEntry(
4336 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4340 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4342 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4348 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4349 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4350 * getProperty("LAST_DIRECTORY"));
4352 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4353 * to Vamsas file"); chooser.setToolTipText("Export");
4355 * int value = chooser.showSaveDialog(this);
4357 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4358 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4359 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4360 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4363 * prototype of an automatically enabled/disabled analysis function
4366 protected void setShowProductsEnabled()
4368 SequenceI[] selection = viewport.getSequenceSelection();
4369 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4370 viewport.getAlignment().getDataset()))
4372 showProducts.setEnabled(true);
4377 showProducts.setEnabled(false);
4382 * search selection for sequence xRef products and build the show products
4387 * @return true if showProducts menu should be enabled.
4389 public boolean canShowProducts(SequenceI[] selection,
4390 boolean isRegionSelection, Alignment dataset)
4392 boolean showp = false;
4395 showProducts.removeAll();
4396 final boolean dna = viewport.getAlignment().isNucleotide();
4397 final Alignment ds = dataset;
4398 String[] ptypes = (selection == null || selection.length == 0) ? null
4399 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4401 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4402 // selection, dataset, true);
4403 final SequenceI[] sel = selection;
4404 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4407 final boolean isRegSel = isRegionSelection;
4408 final AlignFrame af = this;
4409 final String source = ptypes[t];
4410 JMenuItem xtype = new JMenuItem(ptypes[t]);
4411 xtype.addActionListener(new ActionListener()
4415 public void actionPerformed(ActionEvent e)
4417 // TODO: new thread for this call with vis-delay
4418 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4419 isRegSel, dna, source);
4423 showProducts.add(xtype);
4425 showProducts.setVisible(showp);
4426 showProducts.setEnabled(showp);
4427 } catch (Exception e)
4429 jalview.bin.Cache.log
4430 .warn("canTranslate threw an exception - please report to help@jalview.org",
4437 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4438 boolean isRegSel, boolean dna, String source)
4440 final boolean fisRegSel = isRegSel;
4441 final boolean fdna = dna;
4442 final String fsrc = source;
4443 final AlignFrame ths = this;
4444 final SequenceI[] fsel = sel;
4445 Runnable foo = new Runnable()
4451 final long sttime = System.currentTimeMillis();
4452 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4455 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4459 Alignment prods = CrossRef
4460 .findXrefSequences(fsel, fdna, fsrc, ds);
4463 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4464 for (int s = 0; s < sprods.length; s++)
4466 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4467 if (ds.getSequences() == null
4468 || !ds.getSequences().contains(
4469 sprods[s].getDatasetSequence()))
4470 ds.addSequence(sprods[s].getDatasetSequence());
4471 sprods[s].updatePDBIds();
4473 Alignment al = new Alignment(sprods);
4474 AlignedCodonFrame[] cf = prods.getCodonFrames();
4476 for (int s = 0; cf != null && s < cf.length; s++)
4478 al.addCodonFrame(cf[s]);
4481 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4483 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4484 + " for " + ((fisRegSel) ? "selected region of " : "")
4486 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4491 System.err.println("No Sequences generated for xRef type "
4494 } catch (Exception e)
4496 jalview.bin.Cache.log.error(
4497 "Exception when finding crossreferences", e);
4498 } catch (OutOfMemoryError e)
4500 new OOMWarning("whilst fetching crossreferences", e);
4503 jalview.bin.Cache.log.error("Error when finding crossreferences",
4506 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4511 Thread frunner = new Thread(foo);
4515 public boolean canShowTranslationProducts(SequenceI[] selection,
4516 AlignmentI alignment)
4521 return (jalview.analysis.Dna.canTranslate(selection,
4522 viewport.getViewAsVisibleContigs(true)));
4523 } catch (Exception e)
4525 jalview.bin.Cache.log
4526 .warn("canTranslate threw an exception - please report to help@jalview.org",
4533 public void showProducts_actionPerformed(ActionEvent e)
4535 // /////////////////////////////
4536 // Collect Data to be translated/transferred
4538 SequenceI[] selection = viewport.getSequenceSelection();
4539 AlignmentI al = null;
4542 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4543 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4544 viewport.getAlignment().getDataset());
4545 } catch (Exception ex)
4548 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4555 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4556 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4560 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4561 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4562 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4567 public void showTranslation_actionPerformed(ActionEvent e)
4569 // /////////////////////////////
4570 // Collect Data to be translated/transferred
4572 SequenceI[] selection = viewport.getSequenceSelection();
4573 String[] seqstring = viewport.getViewAsString(true);
4574 AlignmentI al = null;
4577 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4578 viewport.getViewAsVisibleContigs(true), viewport
4579 .getGapCharacter(), viewport.getAlignment()
4580 .getAlignmentAnnotation(), viewport.getAlignment()
4581 .getWidth(), viewport.getAlignment().getDataset());
4582 } catch (Exception ex)
4585 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4589 MessageManager.getString("label.error_when_translating_sequences_submit_bug_report"),
4590 MessageManager.getString("label.implementation_error") + MessageManager.getString("translation_failed"), JOptionPane.ERROR_MESSAGE);
4598 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4599 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4603 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4604 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4605 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4610 * Try to load a features file onto the alignment.
4613 * contents or path to retrieve file
4615 * access mode of file (see jalview.io.AlignFile)
4616 * @return true if features file was parsed corectly.
4618 public boolean parseFeaturesFile(String file, String type)
4620 boolean featuresFile = false;
4623 featuresFile = new FeaturesFile(file, type).parse(viewport
4624 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4625 .getFeatureRenderer().featureColours, false,
4626 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4627 } catch (Exception ex)
4629 ex.printStackTrace();
4634 viewport.showSequenceFeatures = true;
4635 showSeqFeatures.setSelected(true);
4636 if (alignPanel.seqPanel.seqCanvas.fr != null)
4638 // update the min/max ranges where necessary
4639 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4641 if (featureSettings != null)
4643 featureSettings.setTableData();
4645 alignPanel.paintAlignment(true);
4648 return featuresFile;
4652 public void dragEnter(DropTargetDragEvent evt)
4657 public void dragExit(DropTargetEvent evt)
4662 public void dragOver(DropTargetDragEvent evt)
4667 public void dropActionChanged(DropTargetDragEvent evt)
4672 public void drop(DropTargetDropEvent evt)
4674 Transferable t = evt.getTransferable();
4675 java.util.List files = null;
4679 DataFlavor uriListFlavor = new DataFlavor(
4680 "text/uri-list;class=java.lang.String");
4681 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4683 // Works on Windows and MacOSX
4684 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4685 files = (java.util.List) t
4686 .getTransferData(DataFlavor.javaFileListFlavor);
4688 else if (t.isDataFlavorSupported(uriListFlavor))
4690 // This is used by Unix drag system
4691 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4692 String data = (String) t.getTransferData(uriListFlavor);
4693 files = new java.util.ArrayList(1);
4694 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4695 data, "\r\n"); st.hasMoreTokens();)
4697 String s = st.nextToken();
4698 if (s.startsWith("#"))
4700 // the line is a comment (as per the RFC 2483)
4704 java.net.URI uri = new java.net.URI(s);
4705 // check to see if we can handle this kind of URI
4706 if (uri.getScheme().toLowerCase().startsWith("http"))
4708 files.add(uri.toString());
4712 // otherwise preserve old behaviour: catch all for file objects
4713 java.io.File file = new java.io.File(uri);
4714 files.add(file.toString());
4718 } catch (Exception e)
4720 e.printStackTrace();
4726 // check to see if any of these files have names matching sequences in
4728 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4729 .getAlignment().getSequencesArray());
4731 * Object[] { String,SequenceI}
4733 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4734 ArrayList<String> filesnotmatched = new ArrayList<String>();
4735 for (int i = 0; i < files.size(); i++)
4737 String file = files.get(i).toString();
4739 String protocol = FormatAdapter.checkProtocol(file);
4740 if (protocol == jalview.io.FormatAdapter.FILE)
4742 File fl = new File(file);
4743 pdbfn = fl.getName();
4745 else if (protocol == jalview.io.FormatAdapter.URL)
4747 URL url = new URL(file);
4748 pdbfn = url.getFile();
4750 if (pdbfn.length() > 0)
4752 // attempt to find a match in the alignment
4753 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4754 int l = 0, c = pdbfn.indexOf(".");
4755 while (mtch == null && c != -1)
4760 } while ((c = pdbfn.indexOf(".", l)) > l);
4763 pdbfn = pdbfn.substring(0, l);
4765 mtch = idm.findAllIdMatches(pdbfn);
4772 type = new IdentifyFile().Identify(file, protocol);
4773 } catch (Exception ex)
4779 if (type.equalsIgnoreCase("PDB"))
4781 filesmatched.add(new Object[]
4782 { file, protocol, mtch });
4787 // File wasn't named like one of the sequences or wasn't a PDB file.
4788 filesnotmatched.add(file);
4792 if (filesmatched.size() > 0)
4794 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4798 MessageManager.formatMessage("label.automatically_associate_pdb_files_with_sequences_same_name",
4799 new String[]{Integer.valueOf(filesmatched.size()).toString()}),
4800 MessageManager.getString("label.automatically_associate_pdb_files_by_name"),
4801 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4804 for (Object[] fm : filesmatched)
4806 // try and associate
4807 // TODO: may want to set a standard ID naming formalism for
4808 // associating PDB files which have no IDs.
4809 for (SequenceI toassoc : (SequenceI[]) fm[2])
4811 PDBEntry pe = new AssociatePdbFileWithSeq()
4812 .associatePdbWithSeq((String) fm[0],
4813 (String) fm[1], toassoc, false);
4816 System.err.println("Associated file : "
4817 + ((String) fm[0]) + " with "
4818 + toassoc.getDisplayId(true));
4822 alignPanel.paintAlignment(true);
4826 if (filesnotmatched.size() > 0)
4829 && (Cache.getDefault(
4830 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4833 MessageManager.formatMessage("label.ignore_unmatched_dropped_files_info", new String[]{Integer.valueOf(filesnotmatched.size()).toString()}),
4834 MessageManager.getString("label.ignore_unmatched_dropped_files"),
4835 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4839 for (String fn : filesnotmatched)
4841 loadJalviewDataFile(fn, null, null, null);
4845 } catch (Exception ex)
4847 ex.printStackTrace();
4853 * Attempt to load a "dropped" file or URL string: First by testing whether
4854 * it's and Annotation file, then a JNet file, and finally a features file. If
4855 * all are false then the user may have dropped an alignment file onto this
4859 * either a filename or a URL string.
4861 public void loadJalviewDataFile(String file, String protocol,
4862 String format, SequenceI assocSeq)
4866 if (protocol == null)
4868 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4870 // if the file isn't identified, or not positively identified as some
4871 // other filetype (PFAM is default unidentified alignment file type) then
4872 // try to parse as annotation.
4873 boolean isAnnotation = (format == null || format
4874 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4875 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4880 // first see if its a T-COFFEE score file
4881 TCoffeeScoreFile tcf = null;
4884 tcf = new TCoffeeScoreFile(file, protocol);
4887 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4889 tcoffeeColour.setEnabled(true);
4890 tcoffeeColour.setSelected(true);
4891 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4892 isAnnotation = true;
4893 statusBar.setText(MessageManager.getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
4897 // some problem - if no warning its probable that the ID matching
4898 // process didn't work
4902 tcf.getWarningMessage() == null ? MessageManager.getString("label.check_file_matches_sequence_ids_alignment")
4903 : tcf.getWarningMessage(),
4904 MessageManager.getString("label.problem_reading_tcoffee_score_file"),
4905 JOptionPane.WARNING_MESSAGE);
4912 } catch (Exception x)
4915 .debug("Exception when processing data source as T-COFFEE score file",
4921 // try to see if its a JNet 'concise' style annotation file *before*
4923 // try to parse it as a features file
4926 format = new IdentifyFile().Identify(file, protocol);
4928 if (format.equalsIgnoreCase("JnetFile"))
4930 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4932 new JnetAnnotationMaker().add_annotation(predictions,
4933 viewport.getAlignment(), 0, false);
4934 isAnnotation = true;
4939 * if (format.equalsIgnoreCase("PDB")) {
4941 * String pdbfn = ""; // try to match up filename with sequence id
4942 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4943 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4944 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4945 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4946 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4947 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4948 * // attempt to find a match in the alignment SequenceI mtch =
4949 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4950 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4951 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4952 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4953 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4954 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4955 * { System.err.println("Associated file : " + file + " with " +
4956 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4957 * TODO: maybe need to load as normal otherwise return; } }
4959 // try to parse it as a features file
4960 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4961 // if it wasn't a features file then we just treat it as a general
4962 // alignment file to load into the current view.
4965 new FileLoader().LoadFile(viewport, file, protocol, format);
4969 alignPanel.paintAlignment(true);
4977 alignPanel.adjustAnnotationHeight();
4978 viewport.updateSequenceIdColours();
4979 buildSortByAnnotationScoresMenu();
4980 alignPanel.paintAlignment(true);
4982 } catch (Exception ex)
4984 ex.printStackTrace();
4985 } catch (OutOfMemoryError oom)
4990 } catch (Exception x)
4996 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
4997 : "using " + protocol + " from " + file)
4999 + (format != null ? "(parsing as '" + format
5000 + "' file)" : ""), oom, Desktop.desktop);
5005 public void tabSelectionChanged(int index)
5009 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5010 viewport = alignPanel.av;
5011 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5012 setMenusFromViewport(viewport);
5017 public void tabbedPane_mousePressed(MouseEvent e)
5019 if (SwingUtilities.isRightMouseButton(e))
5021 String reply = JOptionPane.showInternalInputDialog(this,
5022 MessageManager.getString("label.enter_view_name"), MessageManager.getString("label.enter_view_name"),
5023 JOptionPane.QUESTION_MESSAGE);
5027 viewport.viewName = reply;
5028 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5033 public AlignViewport getCurrentView()
5039 * Open the dialog for regex description parsing.
5042 protected void extractScores_actionPerformed(ActionEvent e)
5044 ParseProperties pp = new jalview.analysis.ParseProperties(
5045 viewport.getAlignment());
5046 // TODO: verify regex and introduce GUI dialog for version 2.5
5047 // if (pp.getScoresFromDescription("col", "score column ",
5048 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5050 if (pp.getScoresFromDescription("description column",
5051 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5053 buildSortByAnnotationScoresMenu();
5061 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5065 protected void showDbRefs_actionPerformed(ActionEvent e)
5067 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5073 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5077 protected void showNpFeats_actionPerformed(ActionEvent e)
5079 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5083 * find the viewport amongst the tabs in this alignment frame and close that
5088 public boolean closeView(AlignViewport av)
5092 this.closeMenuItem_actionPerformed(false);
5095 Component[] comp = tabbedPane.getComponents();
5096 for (int i = 0; comp != null && i < comp.length; i++)
5098 if (comp[i] instanceof AlignmentPanel)
5100 if (((AlignmentPanel) comp[i]).av == av)
5103 closeView((AlignmentPanel) comp[i]);
5111 protected void build_fetchdbmenu(JMenu webService)
5113 // Temporary hack - DBRef Fetcher always top level ws entry.
5114 // TODO We probably want to store a sequence database checklist in
5115 // preferences and have checkboxes.. rather than individual sources selected
5117 final JMenu rfetch = new JMenu("Fetch DB References");
5118 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5119 webService.add(rfetch);
5121 JMenuItem fetchr = new JMenuItem("Standard Databases");
5122 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5123 fetchr.addActionListener(new ActionListener()
5127 public void actionPerformed(ActionEvent e)
5129 new Thread(new Runnable()
5135 new jalview.ws.DBRefFetcher(alignPanel.av
5136 .getSequenceSelection(), alignPanel.alignFrame)
5137 .fetchDBRefs(false);
5145 final AlignFrame me = this;
5146 new Thread(new Runnable()
5151 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5152 .getSequenceFetcherSingleton(me);
5153 javax.swing.SwingUtilities.invokeLater(new Runnable()
5158 String[] dbclasses = sf.getOrderedSupportedSources();
5159 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5160 // jalview.util.QuickSort.sort(otherdb, otherdb);
5161 List<DbSourceProxy> otherdb;
5162 JMenu dfetch = new JMenu();
5163 JMenu ifetch = new JMenu();
5164 JMenuItem fetchr = null;
5165 int comp = 0, icomp = 0, mcomp = 15;
5166 String mname = null;
5168 for (String dbclass : dbclasses)
5170 otherdb = sf.getSourceProxy(dbclass);
5171 // add a single entry for this class, or submenu allowing 'fetch
5173 if (otherdb == null || otherdb.size() < 1)
5177 // List<DbSourceProxy> dbs=otherdb;
5178 // otherdb=new ArrayList<DbSourceProxy>();
5179 // for (DbSourceProxy db:dbs)
5181 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5185 mname = "From " + dbclass;
5187 if (otherdb.size() == 1)
5189 final DbSourceProxy[] dassource = otherdb
5190 .toArray(new DbSourceProxy[0]);
5191 DbSourceProxy src = otherdb.get(0);
5192 fetchr = new JMenuItem(src.getDbSource());
5193 fetchr.addActionListener(new ActionListener()
5197 public void actionPerformed(ActionEvent e)
5199 new Thread(new Runnable()
5205 new jalview.ws.DBRefFetcher(alignPanel.av
5206 .getSequenceSelection(),
5207 alignPanel.alignFrame, dassource)
5208 .fetchDBRefs(false);
5214 fetchr.setToolTipText("<html>"
5215 + JvSwingUtils.wrapTooltip("Retrieve from "
5216 + src.getDbName()) + "<html>");
5222 final DbSourceProxy[] dassource = otherdb
5223 .toArray(new DbSourceProxy[0]);
5225 DbSourceProxy src = otherdb.get(0);
5226 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5228 fetchr.addActionListener(new ActionListener()
5231 public void actionPerformed(ActionEvent e)
5233 new Thread(new Runnable()
5239 new jalview.ws.DBRefFetcher(alignPanel.av
5240 .getSequenceSelection(),
5241 alignPanel.alignFrame, dassource)
5242 .fetchDBRefs(false);
5248 fetchr.setToolTipText("<html>"
5249 + JvSwingUtils.wrapTooltip("Retrieve from all "
5250 + otherdb.size() + " sources in "
5251 + src.getDbSource() + "<br>First is :"
5252 + src.getDbName()) + "<html>");
5255 // and then build the rest of the individual menus
5256 ifetch = new JMenu("Sources from " + src.getDbSource());
5258 String imname = null;
5260 for (DbSourceProxy sproxy : otherdb)
5262 String dbname = sproxy.getDbName();
5263 String sname = dbname.length() > 5 ? dbname.substring(0,
5264 5) + "..." : dbname;
5265 String msname = dbname.length() > 10 ? dbname.substring(
5266 0, 10) + "..." : dbname;
5269 imname = "from '" + sname + "'";
5271 fetchr = new JMenuItem(msname);
5272 final DbSourceProxy[] dassrc =
5274 fetchr.addActionListener(new ActionListener()
5278 public void actionPerformed(ActionEvent e)
5280 new Thread(new Runnable()
5286 new jalview.ws.DBRefFetcher(alignPanel.av
5287 .getSequenceSelection(),
5288 alignPanel.alignFrame, dassrc)
5289 .fetchDBRefs(false);
5295 fetchr.setToolTipText("<html>"
5296 + JvSwingUtils.wrapTooltip("Retrieve from "
5297 + dbname) + "</html>");
5300 if (++icomp >= mcomp || i == (otherdb.size()))
5302 ifetch.setText(MessageManager.formatMessage("label.source_to_target",new String[]{imname,sname}));
5304 ifetch = new JMenu();
5312 if (comp >= mcomp || dbi >= (dbclasses.length))
5314 dfetch.setText(MessageManager.formatMessage("label.source_to_target",new String[]{mname,dbclass}));
5316 dfetch = new JMenu();
5329 * Left justify the whole alignment.
5332 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5334 AlignmentI al = viewport.getAlignment();
5336 viewport.firePropertyChange("alignment", null, al);
5340 * Right justify the whole alignment.
5343 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5345 AlignmentI al = viewport.getAlignment();
5347 viewport.firePropertyChange("alignment", null, al);
5350 public void setShowSeqFeatures(boolean b)
5352 showSeqFeatures.setSelected(true);
5353 viewport.setShowSequenceFeatures(true);
5360 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5361 * awt.event.ActionEvent)
5364 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5366 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5367 alignPanel.paintAlignment(true);
5374 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5378 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5380 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5381 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5389 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5390 * .event.ActionEvent)
5393 protected void showGroupConservation_actionPerformed(ActionEvent e)
5395 viewport.setShowGroupConservation(showGroupConservation.getState());
5396 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5403 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5404 * .event.ActionEvent)
5407 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5409 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5410 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5417 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5418 * .event.ActionEvent)
5421 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5423 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5424 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5428 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5430 showSequenceLogo.setState(true);
5431 viewport.setShowSequenceLogo(true);
5432 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5433 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5437 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5439 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5446 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5447 * .event.ActionEvent)
5450 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5452 if (avc.makeGroupsFromSelection()) {
5453 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5454 alignPanel.updateAnnotation();
5455 alignPanel.paintAlignment(true);
5460 protected void createGroup_actionPerformed(ActionEvent e)
5462 if (avc.createGroup())
5464 alignPanel.alignmentChanged();
5469 protected void unGroup_actionPerformed(ActionEvent e)
5473 alignPanel.alignmentChanged();
5478 * make the given alignmentPanel the currently selected tab
5480 * @param alignmentPanel
5482 public void setDisplayedView(AlignmentPanel alignmentPanel)
5484 if (!viewport.getSequenceSetId().equals(
5485 alignmentPanel.av.getSequenceSetId()))
5488 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5490 if (tabbedPane != null
5491 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5492 .getSelectedIndex())
5494 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5499 class PrintThread extends Thread
5503 public PrintThread(AlignmentPanel ap)
5508 static PageFormat pf;
5513 PrinterJob printJob = PrinterJob.getPrinterJob();
5517 printJob.setPrintable(ap, pf);
5521 printJob.setPrintable(ap);
5524 if (printJob.printDialog())
5529 } catch (Exception PrintException)
5531 PrintException.printStackTrace();