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(MessageManager.getString("action.save"));
\r
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 MessageManager.formatMessage("label.alignment_output_command", new String[]{e.getActionCommand()}), 600, 500);
\r
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(MessageManager.getString("label.load_jalview_annotations"));
\r
1254 chooser.setToolTipText(MessageManager.getString("label.load_jalview_annotations"));
\r
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, MessageManager.formatMessage("label.alignment_properties", new String[]{getTitle()}), 500, 400);
\r
2971 public void overviewMenuItem_actionPerformed(ActionEvent e)
2973 if (alignPanel.overviewPanel != null)
2978 JInternalFrame frame = new JInternalFrame();
2979 OverviewPanel overview = new OverviewPanel(alignPanel);
2980 frame.setContentPane(overview);
2981 Desktop.addInternalFrame(frame, MessageManager.formatMessage("label.overview_params", new String[]{this.getTitle()}),
\r
2982 frame.getWidth(), frame.getHeight());
2984 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2985 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2988 public void internalFrameClosed(
2989 javax.swing.event.InternalFrameEvent evt)
2991 alignPanel.setOverviewPanel(null);
2995 alignPanel.setOverviewPanel(overview);
2999 public void textColour_actionPerformed(ActionEvent e)
3001 new TextColourChooser().chooseColour(alignPanel, null);
3011 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3023 public void clustalColour_actionPerformed(ActionEvent e)
3025 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3026 viewport.getHiddenRepSequences()));
3036 public void zappoColour_actionPerformed(ActionEvent e)
3038 changeColour(new ZappoColourScheme());
3048 public void taylorColour_actionPerformed(ActionEvent e)
3050 changeColour(new TaylorColourScheme());
3060 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3062 changeColour(new HydrophobicColourScheme());
3072 public void helixColour_actionPerformed(ActionEvent e)
3074 changeColour(new HelixColourScheme());
3084 public void strandColour_actionPerformed(ActionEvent e)
3086 changeColour(new StrandColourScheme());
3096 public void turnColour_actionPerformed(ActionEvent e)
3098 changeColour(new TurnColourScheme());
3108 public void buriedColour_actionPerformed(ActionEvent e)
3110 changeColour(new BuriedColourScheme());
3120 public void nucleotideColour_actionPerformed(ActionEvent e)
3122 changeColour(new NucleotideColourScheme());
3126 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3128 changeColour(new PurinePyrimidineColourScheme());
3132 * public void covariationColour_actionPerformed(ActionEvent e) {
3134 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3138 public void annotationColour_actionPerformed(ActionEvent e)
3140 new AnnotationColourChooser(viewport, alignPanel);
3144 public void rnahelicesColour_actionPerformed(ActionEvent e)
3146 new RNAHelicesColourChooser(viewport, alignPanel);
3156 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3158 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3167 public void changeColour(ColourSchemeI cs)
3169 // TODO: compare with applet and pull up to model method
3174 if (viewport.getAbovePIDThreshold())
3176 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3179 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3181 viewport.setGlobalColourScheme(cs);
3185 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3188 if (viewport.getConservationSelected())
3191 Alignment al = (Alignment) viewport.getAlignment();
3192 Conservation c = new Conservation("All",
3193 ResidueProperties.propHash, 3, al.getSequences(), 0,
3197 c.verdict(false, viewport.getConsPercGaps());
3199 cs.setConservation(c);
3201 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3206 cs.setConservation(null);
3209 cs.setConsensus(viewport.getSequenceConsensusHash());
3212 viewport.setGlobalColourScheme(cs);
3214 if (viewport.getColourAppliesToAllGroups())
3217 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3225 if (cs instanceof ClustalxColourScheme)
3227 sg.cs = new ClustalxColourScheme(sg,
3228 viewport.getHiddenRepSequences());
3230 else if (cs instanceof UserColourScheme)
3232 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3238 sg.cs = cs.getClass().newInstance();
3239 } catch (Exception ex)
3244 if (viewport.getAbovePIDThreshold()
3245 || cs instanceof PIDColourScheme
3246 || cs instanceof Blosum62ColourScheme)
3248 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3250 sg.cs.setConsensus(AAFrequency.calculate(
3251 sg.getSequences(viewport.getHiddenRepSequences()),
3252 sg.getStartRes(), sg.getEndRes() + 1));
3256 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3259 if (viewport.getConservationSelected())
3261 Conservation c = new Conservation("Group",
3262 ResidueProperties.propHash, 3, sg.getSequences(viewport
3263 .getHiddenRepSequences()), sg.getStartRes(),
3264 sg.getEndRes() + 1);
3266 c.verdict(false, viewport.getConsPercGaps());
3267 sg.cs.setConservation(c);
3271 sg.cs.setConservation(null);
3276 if (alignPanel.getOverviewPanel() != null)
3278 alignPanel.getOverviewPanel().updateOverviewImage();
3281 alignPanel.paintAlignment(true);
3291 protected void modifyPID_actionPerformed(ActionEvent e)
3293 if (viewport.getAbovePIDThreshold()
3294 && viewport.getGlobalColourScheme() != null)
3296 SliderPanel.setPIDSliderSource(alignPanel,
3297 viewport.getGlobalColourScheme(), "Background");
3298 SliderPanel.showPIDSlider();
3309 protected void modifyConservation_actionPerformed(ActionEvent e)
3311 if (viewport.getConservationSelected()
3312 && viewport.getGlobalColourScheme() != null)
3314 SliderPanel.setConservationSlider(alignPanel,
3315 viewport.getGlobalColourScheme(), "Background");
3316 SliderPanel.showConservationSlider();
3327 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3329 viewport.setConservationSelected(conservationMenuItem.isSelected());
3331 viewport.setAbovePIDThreshold(false);
3332 abovePIDThreshold.setSelected(false);
3334 changeColour(viewport.getGlobalColourScheme());
3336 modifyConservation_actionPerformed(null);
3346 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3348 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3350 conservationMenuItem.setSelected(false);
3351 viewport.setConservationSelected(false);
3353 changeColour(viewport.getGlobalColourScheme());
3355 modifyPID_actionPerformed(null);
3365 public void userDefinedColour_actionPerformed(ActionEvent e)
3367 if (e.getActionCommand().equals(MessageManager.getString("action.user_defined")))
\r
3369 new UserDefinedColours(alignPanel, null);
3373 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3374 .getUserColourSchemes().get(e.getActionCommand());
3380 public void updateUserColourMenu()
3383 Component[] menuItems = colourMenu.getMenuComponents();
3384 int i, iSize = menuItems.length;
3385 for (i = 0; i < iSize; i++)
3387 if (menuItems[i].getName() != null
3388 && menuItems[i].getName().equals("USER_DEFINED"))
3390 colourMenu.remove(menuItems[i]);
3394 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3396 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3397 .getUserColourSchemes().keys();
3399 while (userColours.hasMoreElements())
3401 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3402 userColours.nextElement().toString());
3403 radioItem.setName("USER_DEFINED");
3404 radioItem.addMouseListener(new MouseAdapter()
3407 public void mousePressed(MouseEvent evt)
3409 if (evt.isControlDown()
3410 || SwingUtilities.isRightMouseButton(evt))
3412 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3414 int option = JOptionPane.showInternalConfirmDialog(
3415 jalview.gui.Desktop.desktop,
3416 MessageManager.getString("label.remove_from_default_list"),
3417 MessageManager.getString("label.remove_user_defined_colour"),
3418 JOptionPane.YES_NO_OPTION);
3419 if (option == JOptionPane.YES_OPTION)
3421 jalview.gui.UserDefinedColours
3422 .removeColourFromDefaults(radioItem.getText());
3423 colourMenu.remove(radioItem);
3427 radioItem.addActionListener(new ActionListener()
3430 public void actionPerformed(ActionEvent evt)
3432 userDefinedColour_actionPerformed(evt);
3439 radioItem.addActionListener(new ActionListener()
3442 public void actionPerformed(ActionEvent evt)
3444 userDefinedColour_actionPerformed(evt);
3448 colourMenu.insert(radioItem, 15);
3449 colours.add(radioItem);
3461 public void PIDColour_actionPerformed(ActionEvent e)
3463 changeColour(new PIDColourScheme());
3473 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3475 changeColour(new Blosum62ColourScheme());
3485 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3487 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3488 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3489 .getAlignment().getSequenceAt(0), null);
3490 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3491 viewport.getAlignment()));
3492 alignPanel.paintAlignment(true);
3502 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3504 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3505 AlignmentSorter.sortByID(viewport.getAlignment());
3506 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3507 viewport.getAlignment()));
3508 alignPanel.paintAlignment(true);
3518 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3520 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3521 AlignmentSorter.sortByLength(viewport.getAlignment());
3522 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3523 viewport.getAlignment()));
3524 alignPanel.paintAlignment(true);
3534 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3536 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3537 AlignmentSorter.sortByGroup(viewport.getAlignment());
3538 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3539 viewport.getAlignment()));
3541 alignPanel.paintAlignment(true);
3551 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3553 new RedundancyPanel(alignPanel, this);
3563 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3565 if ((viewport.getSelectionGroup() == null)
3566 || (viewport.getSelectionGroup().getSize() < 2))
3568 JOptionPane.showInternalMessageDialog(this,
3569 MessageManager.getString("label.you_must_select_least_two_sequences"), MessageManager.getString("label.invalid_selection"),
3570 JOptionPane.WARNING_MESSAGE);
3574 JInternalFrame frame = new JInternalFrame();
3575 frame.setContentPane(new PairwiseAlignPanel(viewport));
3576 Desktop.addInternalFrame(frame, MessageManager.getString("action.pairwise_alignment"), 600, 500);
\r
3587 public void PCAMenuItem_actionPerformed(ActionEvent e)
3589 if (((viewport.getSelectionGroup() != null)
3590 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3591 .getSelectionGroup().getSize() > 0))
3592 || (viewport.getAlignment().getHeight() < 4))
3594 JOptionPane.showInternalMessageDialog(this,
3595 MessageManager.getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3596 MessageManager.getString("label.sequence_selection_insufficient"),
3597 JOptionPane.WARNING_MESSAGE);
3602 new PCAPanel(alignPanel);
3606 public void autoCalculate_actionPerformed(ActionEvent e)
3608 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3609 if (viewport.autoCalculateConsensus)
3611 viewport.firePropertyChange("alignment", null, viewport
3612 .getAlignment().getSequences());
3617 public void sortByTreeOption_actionPerformed(ActionEvent e)
3619 viewport.sortByTree = sortByTree.isSelected();
3623 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3625 viewport.followSelection = listenToViewSelections.isSelected();
3635 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3637 NewTreePanel("AV", "PID", "Average distance tree using PID");
3647 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3649 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3659 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3661 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3671 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3673 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3686 void NewTreePanel(String type, String pwType, String title)
3690 if (viewport.getSelectionGroup() != null
3691 && viewport.getSelectionGroup().getSize() > 0)
3693 if (viewport.getSelectionGroup().getSize() < 3)
3698 MessageManager.getString("label.you_need_more_two_sequences_selected_build_tree"),
3699 MessageManager.getString("label.not_enough_sequences"), JOptionPane.WARNING_MESSAGE);
3703 SequenceGroup sg = viewport.getSelectionGroup();
3705 /* Decide if the selection is a column region */
3706 for (SequenceI _s : sg.getSequences())
3708 if (_s.getLength() < sg.getEndRes())
3713 MessageManager.getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3714 MessageManager.getString("label.sequences_selection_not_aligned"),
3715 JOptionPane.WARNING_MESSAGE);
3721 title = title + " on region";
3722 tp = new TreePanel(alignPanel, type, pwType);
3726 // are the visible sequences aligned?
3727 if (!viewport.getAlignment().isAligned(false))
3732 MessageManager.getString("label.sequences_must_be_aligned_before_creating_tree"),
3733 MessageManager.getString("label.sequences_not_aligned"),
3734 JOptionPane.WARNING_MESSAGE);
3739 if (viewport.getAlignment().getHeight() < 2)
3744 tp = new TreePanel(alignPanel, type, pwType);
3749 if (viewport.viewName != null)
3751 title += viewport.viewName + " of ";
3754 title += this.title;
3756 Desktop.addInternalFrame(tp, title, 600, 500);
3767 public void addSortByOrderMenuItem(String title,
3768 final AlignmentOrder order)
3770 final JMenuItem item = new JMenuItem("by " + title);
3772 item.addActionListener(new java.awt.event.ActionListener()
3775 public void actionPerformed(ActionEvent e)
3777 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3779 // TODO: JBPNote - have to map order entries to curent SequenceI
3781 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3783 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3786 alignPanel.paintAlignment(true);
3792 * Add a new sort by annotation score menu item
3795 * the menu to add the option to
3797 * the label used to retrieve scores for each sequence on the
3800 public void addSortByAnnotScoreMenuItem(JMenu sort,
3801 final String scoreLabel)
3803 final JMenuItem item = new JMenuItem(scoreLabel);
3805 item.addActionListener(new java.awt.event.ActionListener()
3808 public void actionPerformed(ActionEvent e)
3810 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3811 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3812 viewport.getAlignment());// ,viewport.getSelectionGroup());
3813 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3814 viewport.getAlignment()));
3815 alignPanel.paintAlignment(true);
3821 * last hash for alignment's annotation array - used to minimise cost of
3824 protected int _annotationScoreVectorHash;
3827 * search the alignment and rebuild the sort by annotation score submenu the
3828 * last alignment annotation vector hash is stored to minimize cost of
3829 * rebuilding in subsequence calls.
3833 public void buildSortByAnnotationScoresMenu()
3835 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3840 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3842 sortByAnnotScore.removeAll();
3843 // almost certainly a quicker way to do this - but we keep it simple
3844 Hashtable scoreSorts = new Hashtable();
3845 AlignmentAnnotation aann[];
3846 for (SequenceI sqa : viewport.getAlignment().getSequences())
3848 aann = sqa.getAnnotation();
3849 for (int i = 0; aann != null && i < aann.length; i++)
3851 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3853 scoreSorts.put(aann[i].label, aann[i].label);
3857 Enumeration labels = scoreSorts.keys();
3858 while (labels.hasMoreElements())
3860 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3861 (String) labels.nextElement());
3863 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3866 _annotationScoreVectorHash = viewport.getAlignment()
3867 .getAlignmentAnnotation().hashCode();
3872 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3873 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3874 * call. Listeners are added to remove the menu item when the treePanel is
3875 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3879 * Displayed tree window.
3881 * SortBy menu item title.
3884 public void buildTreeMenu()
3886 sortByTreeMenu.removeAll();
3888 Vector comps = (Vector) PaintRefresher.components.get(viewport
3889 .getSequenceSetId());
3890 Vector treePanels = new Vector();
3891 int i, iSize = comps.size();
3892 for (i = 0; i < iSize; i++)
3894 if (comps.elementAt(i) instanceof TreePanel)
3896 treePanels.add(comps.elementAt(i));
3900 iSize = treePanels.size();
3904 sortByTreeMenu.setVisible(false);
3908 sortByTreeMenu.setVisible(true);
3910 for (i = 0; i < treePanels.size(); i++)
3912 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3913 final JMenuItem item = new JMenuItem(tp.getTitle());
3914 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3915 item.addActionListener(new java.awt.event.ActionListener()
3918 public void actionPerformed(ActionEvent e)
3920 tp.sortByTree_actionPerformed(null);
3921 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3926 sortByTreeMenu.add(item);
3930 public boolean sortBy(AlignmentOrder alorder, String undoname)
3932 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3933 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3934 if (undoname != null)
3936 addHistoryItem(new OrderCommand(undoname, oldOrder,
3937 viewport.getAlignment()));
3939 alignPanel.paintAlignment(true);
3944 * Work out whether the whole set of sequences or just the selected set will
3945 * be submitted for multiple alignment.
3948 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3950 // Now, check we have enough sequences
3951 AlignmentView msa = null;
3953 if ((viewport.getSelectionGroup() != null)
3954 && (viewport.getSelectionGroup().getSize() > 1))
3956 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3957 // some common interface!
3959 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3960 * SequenceI[sz = seqs.getSize(false)];
3962 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3963 * seqs.getSequenceAt(i); }
3965 msa = viewport.getAlignmentView(true);
3970 * Vector seqs = viewport.getAlignment().getSequences();
3972 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3974 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3975 * seqs.elementAt(i); } }
3977 msa = viewport.getAlignmentView(false);
3983 * Decides what is submitted to a secondary structure prediction service: the
3984 * first sequence in the alignment, or in the current selection, or, if the
3985 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3986 * region or the whole alignment. (where the first sequence in the set is the
3987 * one that the prediction will be for).
3989 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3991 AlignmentView seqs = null;
3993 if ((viewport.getSelectionGroup() != null)
3994 && (viewport.getSelectionGroup().getSize() > 0))
3996 seqs = viewport.getAlignmentView(true);
4000 seqs = viewport.getAlignmentView(false);
4002 // limit sequences - JBPNote in future - could spawn multiple prediction
4004 // TODO: viewport.getAlignment().isAligned is a global state - the local
4005 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4006 if (!viewport.getAlignment().isAligned(false))
4008 seqs.setSequences(new SeqCigar[]
4009 { seqs.getSequences()[0] });
4010 // TODO: if seqs.getSequences().length>1 then should really have warned
4024 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4026 // Pick the tree file
4027 JalviewFileChooser chooser = new JalviewFileChooser(
4028 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4029 chooser.setFileView(new JalviewFileView());
4030 chooser.setDialogTitle(MessageManager.getString("label.select_newick_like_tree_file"));
\r
4031 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
\r
4033 int value = chooser.showOpenDialog(null);
4035 if (value == JalviewFileChooser.APPROVE_OPTION)
4037 String choice = chooser.getSelectedFile().getPath();
4038 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4039 jalview.io.NewickFile fin = null;
4042 fin = new jalview.io.NewickFile(choice, "File");
4043 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4044 } catch (Exception ex)
4046 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4047 MessageManager.getString("label.problem_reading_tree_file"), JOptionPane.WARNING_MESSAGE);
4048 ex.printStackTrace();
4050 if (fin != null && fin.hasWarningMessage())
4052 JOptionPane.showMessageDialog(Desktop.desktop,
4053 fin.getWarningMessage(), MessageManager.getString("label.possible_problem_with_tree_file"),
4054 JOptionPane.WARNING_MESSAGE);
4060 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4062 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4065 public TreePanel ShowNewickTree(NewickFile nf, String title)
4067 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4070 public TreePanel ShowNewickTree(NewickFile nf, String title,
4071 AlignmentView input)
4073 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4076 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4077 int h, int x, int y)
4079 return ShowNewickTree(nf, title, null, w, h, x, y);
4083 * Add a treeviewer for the tree extracted from a newick file object to the
4084 * current alignment view
4091 * Associated alignment input data (or null)
4100 * @return TreePanel handle
4102 public TreePanel ShowNewickTree(NewickFile nf, String title,
4103 AlignmentView input, int w, int h, int x, int y)
4105 TreePanel tp = null;
4111 if (nf.getTree() != null)
4113 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4119 tp.setLocation(x, y);
4122 Desktop.addInternalFrame(tp, title, w, h);
4124 } catch (Exception ex)
4126 ex.printStackTrace();
4132 private boolean buildingMenu = false;
4135 * Generates menu items and listener event actions for web service clients
4138 public void BuildWebServiceMenu()
4140 while (buildingMenu)
4144 System.err.println("Waiting for building menu to finish.");
4146 } catch (Exception e)
4151 final AlignFrame me = this;
4152 buildingMenu = true;
4153 new Thread(new Runnable()
4158 final List<JMenuItem> legacyItems=new ArrayList<JMenuItem>();
4161 System.err.println("Building ws menu again "
4162 + Thread.currentThread());
4163 // TODO: add support for context dependent disabling of services based
4165 // alignment and current selection
4166 // TODO: add additional serviceHandle parameter to specify abstract
4168 // class independently of AbstractName
4169 // TODO: add in rediscovery GUI function to restart discoverer
4170 // TODO: group services by location as well as function and/or
4172 // object broker mechanism.
4173 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4174 final IProgressIndicator af = me;
4175 final JMenu msawsmenu = new JMenu("Alignment");
4176 final JMenu secstrmenu = new JMenu(
4177 "Secondary Structure Prediction");
4178 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4179 final JMenu analymenu = new JMenu("Analysis");
4180 final JMenu dismenu = new JMenu("Protein Disorder");
4181 // JAL-940 - only show secondary structure prediction services from
4182 // the legacy server
4183 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4185 Discoverer.services != null && (Discoverer.services.size() > 0))
4187 // TODO: refactor to allow list of AbstractName/Handler bindings to
4189 // stored or retrieved from elsewhere
4190 // No MSAWS used any more:
4191 // Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4192 Vector secstrpr = (Vector) Discoverer.services
4194 if (secstrpr != null)
4196 // Add any secondary structure prediction services
4197 for (int i = 0, j = secstrpr.size(); i < j; i++)
4199 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4201 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4202 .getServiceClient(sh);
4203 int p=secstrmenu.getItemCount();
4204 impl.attachWSMenuEntry(secstrmenu, me);
4205 int q=secstrmenu.getItemCount();
4206 for (int litm=p;litm<q; litm++)
4208 legacyItems.add(secstrmenu.getItem(litm));
4214 // Add all submenus in the order they should appear on the web
4216 wsmenu.add(msawsmenu);
4217 wsmenu.add(secstrmenu);
4218 wsmenu.add(dismenu);
4219 wsmenu.add(analymenu);
4220 // No search services yet
4221 // wsmenu.add(seqsrchmenu);
4223 javax.swing.SwingUtilities.invokeLater(new Runnable()
4230 webService.removeAll();
4231 // first, add discovered services onto the webservices menu
4232 if (wsmenu.size() > 0)
4234 for (int i = 0, j = wsmenu.size(); i < j; i++)
4236 webService.add(wsmenu.get(i));
4241 webService.add(me.webServiceNoServices);
4243 // TODO: move into separate menu builder class.
4244 boolean new_sspred=false;
4245 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4247 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4248 if (jws2servs != null)
4250 if (jws2servs.hasServices())
4252 jws2servs.attachWSMenuEntry(webService, me);
4253 for (Jws2Instance sv:jws2servs.getServices()) {
4254 if (sv.description.toLowerCase().contains("jpred"))
4256 for (JMenuItem jmi:legacyItems)
4258 jmi.setVisible(false);
4264 if (jws2servs.isRunning())
4266 JMenuItem tm = new JMenuItem(
4267 "Still discovering JABA Services");
4268 tm.setEnabled(false);
4273 build_urlServiceMenu(me.webService);
4274 build_fetchdbmenu(webService);
4275 for (JMenu item : wsmenu)
4277 if (item.getItemCount() == 0)
4279 item.setEnabled(false);
4283 item.setEnabled(true);
4286 } catch (Exception e)
4289 .debug("Exception during web service menu building process.",
4295 } catch (Exception e)
4300 buildingMenu = false;
4307 * construct any groupURL type service menu entries.
4311 private void build_urlServiceMenu(JMenu webService)
4313 // TODO: remove this code when 2.7 is released
4314 // DEBUG - alignmentView
4316 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4317 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4319 * @Override public void actionPerformed(ActionEvent e) {
4320 * jalview.datamodel.AlignmentView
4321 * .testSelectionViews(af.viewport.getAlignment(),
4322 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4324 * }); webService.add(testAlView);
4326 // TODO: refactor to RestClient discoverer and merge menu entries for
4327 // rest-style services with other types of analysis/calculation service
4328 // SHmmr test client - still being implemented.
4329 // DEBUG - alignmentView
4331 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4334 client.attachWSMenuEntry(
4335 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4339 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4341 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4347 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4348 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4349 * getProperty("LAST_DIRECTORY"));
4351 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4352 * to Vamsas file"); chooser.setToolTipText("Export");
4354 * int value = chooser.showSaveDialog(this);
4356 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4357 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4358 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4359 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4362 * prototype of an automatically enabled/disabled analysis function
4365 protected void setShowProductsEnabled()
4367 SequenceI[] selection = viewport.getSequenceSelection();
4368 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4369 viewport.getAlignment().getDataset()))
4371 showProducts.setEnabled(true);
4376 showProducts.setEnabled(false);
4381 * search selection for sequence xRef products and build the show products
4386 * @return true if showProducts menu should be enabled.
4388 public boolean canShowProducts(SequenceI[] selection,
4389 boolean isRegionSelection, Alignment dataset)
4391 boolean showp = false;
4394 showProducts.removeAll();
4395 final boolean dna = viewport.getAlignment().isNucleotide();
4396 final Alignment ds = dataset;
4397 String[] ptypes = (selection == null || selection.length == 0) ? null
4398 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4400 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4401 // selection, dataset, true);
4402 final SequenceI[] sel = selection;
4403 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4406 final boolean isRegSel = isRegionSelection;
4407 final AlignFrame af = this;
4408 final String source = ptypes[t];
4409 JMenuItem xtype = new JMenuItem(ptypes[t]);
4410 xtype.addActionListener(new ActionListener()
4414 public void actionPerformed(ActionEvent e)
4416 // TODO: new thread for this call with vis-delay
4417 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4418 isRegSel, dna, source);
4422 showProducts.add(xtype);
4424 showProducts.setVisible(showp);
4425 showProducts.setEnabled(showp);
4426 } catch (Exception e)
4428 jalview.bin.Cache.log
4429 .warn("canTranslate threw an exception - please report to help@jalview.org",
4436 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4437 boolean isRegSel, boolean dna, String source)
4439 final boolean fisRegSel = isRegSel;
4440 final boolean fdna = dna;
4441 final String fsrc = source;
4442 final AlignFrame ths = this;
4443 final SequenceI[] fsel = sel;
4444 Runnable foo = new Runnable()
4450 final long sttime = System.currentTimeMillis();
4451 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4454 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4458 Alignment prods = CrossRef
4459 .findXrefSequences(fsel, fdna, fsrc, ds);
4462 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4463 for (int s = 0; s < sprods.length; s++)
4465 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4466 if (ds.getSequences() == null
4467 || !ds.getSequences().contains(
4468 sprods[s].getDatasetSequence()))
4469 ds.addSequence(sprods[s].getDatasetSequence());
4470 sprods[s].updatePDBIds();
4472 Alignment al = new Alignment(sprods);
4473 AlignedCodonFrame[] cf = prods.getCodonFrames();
4475 for (int s = 0; cf != null && s < cf.length; s++)
4477 al.addCodonFrame(cf[s]);
4480 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4482 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4483 + " for " + ((fisRegSel) ? "selected region of " : "")
4485 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4490 System.err.println("No Sequences generated for xRef type "
4493 } catch (Exception e)
4495 jalview.bin.Cache.log.error(
4496 "Exception when finding crossreferences", e);
4497 } catch (OutOfMemoryError e)
4499 new OOMWarning("whilst fetching crossreferences", e);
4502 jalview.bin.Cache.log.error("Error when finding crossreferences",
4505 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4510 Thread frunner = new Thread(foo);
4514 public boolean canShowTranslationProducts(SequenceI[] selection,
4515 AlignmentI alignment)
4520 return (jalview.analysis.Dna.canTranslate(selection,
4521 viewport.getViewAsVisibleContigs(true)));
4522 } catch (Exception e)
4524 jalview.bin.Cache.log
4525 .warn("canTranslate threw an exception - please report to help@jalview.org",
4532 public void showProducts_actionPerformed(ActionEvent e)
4534 // /////////////////////////////
4535 // Collect Data to be translated/transferred
4537 SequenceI[] selection = viewport.getSequenceSelection();
4538 AlignmentI al = null;
4541 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4542 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4543 viewport.getAlignment().getDataset());
4544 } catch (Exception ex)
4547 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4554 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4555 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4559 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4560 Desktop.addInternalFrame(af, MessageManager.formatMessage("label.translation_of_params", new String[]{this.getTitle()}),
\r
4561 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4566 public void showTranslation_actionPerformed(ActionEvent e)
4568 // /////////////////////////////
4569 // Collect Data to be translated/transferred
4571 SequenceI[] selection = viewport.getSequenceSelection();
4572 String[] seqstring = viewport.getViewAsString(true);
4573 AlignmentI al = null;
4576 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4577 viewport.getViewAsVisibleContigs(true), viewport
4578 .getGapCharacter(), viewport.getAlignment()
4579 .getAlignmentAnnotation(), viewport.getAlignment()
4580 .getWidth(), viewport.getAlignment().getDataset());
4581 } catch (Exception ex)
4584 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4588 MessageManager.getString("label.error_when_translating_sequences_submit_bug_report"),
4589 MessageManager.getString("label.implementation_error") + MessageManager.getString("translation_failed"), JOptionPane.ERROR_MESSAGE);
4597 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4598 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4602 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4603 Desktop.addInternalFrame(af, MessageManager.formatMessage("label.translation_of_params", new String[]{this.getTitle()}),
\r
4604 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4609 * Try to load a features file onto the alignment.
4612 * contents or path to retrieve file
4614 * access mode of file (see jalview.io.AlignFile)
4615 * @return true if features file was parsed corectly.
4617 public boolean parseFeaturesFile(String file, String type)
4619 boolean featuresFile = false;
4622 featuresFile = new FeaturesFile(file, type).parse(viewport
4623 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4624 .getFeatureRenderer().featureColours, false,
4625 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4626 } catch (Exception ex)
4628 ex.printStackTrace();
4633 viewport.showSequenceFeatures = true;
4634 showSeqFeatures.setSelected(true);
4635 if (alignPanel.seqPanel.seqCanvas.fr != null)
4637 // update the min/max ranges where necessary
4638 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4640 if (featureSettings != null)
4642 featureSettings.setTableData();
4644 alignPanel.paintAlignment(true);
4647 return featuresFile;
4651 public void dragEnter(DropTargetDragEvent evt)
4656 public void dragExit(DropTargetEvent evt)
4661 public void dragOver(DropTargetDragEvent evt)
4666 public void dropActionChanged(DropTargetDragEvent evt)
4671 public void drop(DropTargetDropEvent evt)
4673 Transferable t = evt.getTransferable();
4674 java.util.List files = null;
4678 DataFlavor uriListFlavor = new DataFlavor(
4679 "text/uri-list;class=java.lang.String");
4680 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4682 // Works on Windows and MacOSX
4683 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4684 files = (java.util.List) t
4685 .getTransferData(DataFlavor.javaFileListFlavor);
4687 else if (t.isDataFlavorSupported(uriListFlavor))
4689 // This is used by Unix drag system
4690 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4691 String data = (String) t.getTransferData(uriListFlavor);
4692 files = new java.util.ArrayList(1);
4693 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4694 data, "\r\n"); st.hasMoreTokens();)
4696 String s = st.nextToken();
4697 if (s.startsWith("#"))
4699 // the line is a comment (as per the RFC 2483)
4703 java.net.URI uri = new java.net.URI(s);
4704 // check to see if we can handle this kind of URI
4705 if (uri.getScheme().toLowerCase().startsWith("http"))
4707 files.add(uri.toString());
4711 // otherwise preserve old behaviour: catch all for file objects
4712 java.io.File file = new java.io.File(uri);
4713 files.add(file.toString());
4717 } catch (Exception e)
4719 e.printStackTrace();
4725 // check to see if any of these files have names matching sequences in
4727 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4728 .getAlignment().getSequencesArray());
4730 * Object[] { String,SequenceI}
4732 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4733 ArrayList<String> filesnotmatched = new ArrayList<String>();
4734 for (int i = 0; i < files.size(); i++)
4736 String file = files.get(i).toString();
4738 String protocol = FormatAdapter.checkProtocol(file);
4739 if (protocol == jalview.io.FormatAdapter.FILE)
4741 File fl = new File(file);
4742 pdbfn = fl.getName();
4744 else if (protocol == jalview.io.FormatAdapter.URL)
4746 URL url = new URL(file);
4747 pdbfn = url.getFile();
4749 if (pdbfn.length() > 0)
4751 // attempt to find a match in the alignment
4752 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4753 int l = 0, c = pdbfn.indexOf(".");
4754 while (mtch == null && c != -1)
4759 } while ((c = pdbfn.indexOf(".", l)) > l);
4762 pdbfn = pdbfn.substring(0, l);
4764 mtch = idm.findAllIdMatches(pdbfn);
4771 type = new IdentifyFile().Identify(file, protocol);
4772 } catch (Exception ex)
4778 if (type.equalsIgnoreCase("PDB"))
4780 filesmatched.add(new Object[]
4781 { file, protocol, mtch });
4786 // File wasn't named like one of the sequences or wasn't a PDB file.
4787 filesnotmatched.add(file);
4791 if (filesmatched.size() > 0)
4793 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4797 MessageManager.formatMessage("label.automatically_associate_pdb_files_with_sequences_same_name",
4798 new String[]{Integer.valueOf(filesmatched.size()).toString()}),
4799 MessageManager.getString("label.automatically_associate_pdb_files_by_name"),
4800 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4803 for (Object[] fm : filesmatched)
4805 // try and associate
4806 // TODO: may want to set a standard ID naming formalism for
4807 // associating PDB files which have no IDs.
4808 for (SequenceI toassoc : (SequenceI[]) fm[2])
4810 PDBEntry pe = new AssociatePdbFileWithSeq()
4811 .associatePdbWithSeq((String) fm[0],
4812 (String) fm[1], toassoc, false);
4815 System.err.println("Associated file : "
4816 + ((String) fm[0]) + " with "
4817 + toassoc.getDisplayId(true));
4821 alignPanel.paintAlignment(true);
4825 if (filesnotmatched.size() > 0)
4828 && (Cache.getDefault(
4829 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4832 MessageManager.formatMessage("label.ignore_unmatched_dropped_files_info", new String[]{Integer.valueOf(filesnotmatched.size()).toString()}),
4833 MessageManager.getString("label.ignore_unmatched_dropped_files"),
4834 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4838 for (String fn : filesnotmatched)
4840 loadJalviewDataFile(fn, null, null, null);
4844 } catch (Exception ex)
4846 ex.printStackTrace();
4852 * Attempt to load a "dropped" file or URL string: First by testing whether
4853 * it's and Annotation file, then a JNet file, and finally a features file. If
4854 * all are false then the user may have dropped an alignment file onto this
4858 * either a filename or a URL string.
4860 public void loadJalviewDataFile(String file, String protocol,
4861 String format, SequenceI assocSeq)
4865 if (protocol == null)
4867 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4869 // if the file isn't identified, or not positively identified as some
4870 // other filetype (PFAM is default unidentified alignment file type) then
4871 // try to parse as annotation.
4872 boolean isAnnotation = (format == null || format
4873 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4874 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4879 // first see if its a T-COFFEE score file
4880 TCoffeeScoreFile tcf = null;
4883 tcf = new TCoffeeScoreFile(file, protocol);
4886 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4888 tcoffeeColour.setEnabled(true);
4889 tcoffeeColour.setSelected(true);
4890 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4891 isAnnotation = true;
4892 statusBar.setText(MessageManager.getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
4896 // some problem - if no warning its probable that the ID matching
4897 // process didn't work
4901 tcf.getWarningMessage() == null ? MessageManager.getString("label.check_file_matches_sequence_ids_alignment")
4902 : tcf.getWarningMessage(),
4903 MessageManager.getString("label.problem_reading_tcoffee_score_file"),
4904 JOptionPane.WARNING_MESSAGE);
4911 } catch (Exception x)
4914 .debug("Exception when processing data source as T-COFFEE score file",
4920 // try to see if its a JNet 'concise' style annotation file *before*
4922 // try to parse it as a features file
4925 format = new IdentifyFile().Identify(file, protocol);
4927 if (format.equalsIgnoreCase("JnetFile"))
4929 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4931 new JnetAnnotationMaker().add_annotation(predictions,
4932 viewport.getAlignment(), 0, false);
4933 isAnnotation = true;
4938 * if (format.equalsIgnoreCase("PDB")) {
4940 * String pdbfn = ""; // try to match up filename with sequence id
4941 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4942 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4943 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4944 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4945 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4946 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4947 * // attempt to find a match in the alignment SequenceI mtch =
4948 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4949 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4950 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4951 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4952 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4953 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4954 * { System.err.println("Associated file : " + file + " with " +
4955 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4956 * TODO: maybe need to load as normal otherwise return; } }
4958 // try to parse it as a features file
4959 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4960 // if it wasn't a features file then we just treat it as a general
4961 // alignment file to load into the current view.
4964 new FileLoader().LoadFile(viewport, file, protocol, format);
4968 alignPanel.paintAlignment(true);
4976 alignPanel.adjustAnnotationHeight();
4977 viewport.updateSequenceIdColours();
4978 buildSortByAnnotationScoresMenu();
4979 alignPanel.paintAlignment(true);
4981 } catch (Exception ex)
4983 ex.printStackTrace();
4984 } catch (OutOfMemoryError oom)
4989 } catch (Exception x)
4995 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
4996 : "using " + protocol + " from " + file)
4998 + (format != null ? "(parsing as '" + format
4999 + "' file)" : ""), oom, Desktop.desktop);
5004 public void tabSelectionChanged(int index)
5008 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5009 viewport = alignPanel.av;
5010 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5011 setMenusFromViewport(viewport);
5016 public void tabbedPane_mousePressed(MouseEvent e)
5018 if (SwingUtilities.isRightMouseButton(e))
5020 String reply = JOptionPane.showInternalInputDialog(this,
5021 MessageManager.getString("label.enter_view_name"), MessageManager.getString("label.enter_view_name"),
5022 JOptionPane.QUESTION_MESSAGE);
5026 viewport.viewName = reply;
5027 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5032 public AlignViewport getCurrentView()
5038 * Open the dialog for regex description parsing.
5041 protected void extractScores_actionPerformed(ActionEvent e)
5043 ParseProperties pp = new jalview.analysis.ParseProperties(
5044 viewport.getAlignment());
5045 // TODO: verify regex and introduce GUI dialog for version 2.5
5046 // if (pp.getScoresFromDescription("col", "score column ",
5047 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5049 if (pp.getScoresFromDescription("description column",
5050 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5052 buildSortByAnnotationScoresMenu();
5060 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5064 protected void showDbRefs_actionPerformed(ActionEvent e)
5066 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5072 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5076 protected void showNpFeats_actionPerformed(ActionEvent e)
5078 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5082 * find the viewport amongst the tabs in this alignment frame and close that
5087 public boolean closeView(AlignViewport av)
5091 this.closeMenuItem_actionPerformed(false);
5094 Component[] comp = tabbedPane.getComponents();
5095 for (int i = 0; comp != null && i < comp.length; i++)
5097 if (comp[i] instanceof AlignmentPanel)
5099 if (((AlignmentPanel) comp[i]).av == av)
5102 closeView((AlignmentPanel) comp[i]);
5110 protected void build_fetchdbmenu(JMenu webService)
5112 // Temporary hack - DBRef Fetcher always top level ws entry.
5113 // TODO We probably want to store a sequence database checklist in
5114 // preferences and have checkboxes.. rather than individual sources selected
5116 final JMenu rfetch = new JMenu(MessageManager.getString("action.fetch_db_references"));
\r
5117 rfetch.setToolTipText(MessageManager.getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
\r
5118 webService.add(rfetch);
5120 JMenuItem fetchr = new JMenuItem(MessageManager.getString("label.standard_databases"));
\r
5121 fetchr.setToolTipText(MessageManager.getString("label.fetch_embl_uniprot"));
\r
5122 fetchr.addActionListener(new ActionListener()
5126 public void actionPerformed(ActionEvent e)
5128 new Thread(new Runnable()
5134 new jalview.ws.DBRefFetcher(alignPanel.av
5135 .getSequenceSelection(), alignPanel.alignFrame)
5136 .fetchDBRefs(false);
5144 final AlignFrame me = this;
5145 new Thread(new Runnable()
5150 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5151 .getSequenceFetcherSingleton(me);
5152 javax.swing.SwingUtilities.invokeLater(new Runnable()
5157 String[] dbclasses = sf.getOrderedSupportedSources();
5158 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5159 // jalview.util.QuickSort.sort(otherdb, otherdb);
5160 List<DbSourceProxy> otherdb;
5161 JMenu dfetch = new JMenu();
5162 JMenu ifetch = new JMenu();
5163 JMenuItem fetchr = null;
5164 int comp = 0, icomp = 0, mcomp = 15;
5165 String mname = null;
5167 for (String dbclass : dbclasses)
5169 otherdb = sf.getSourceProxy(dbclass);
5170 // add a single entry for this class, or submenu allowing 'fetch
5172 if (otherdb == null || otherdb.size() < 1)
5176 // List<DbSourceProxy> dbs=otherdb;
5177 // otherdb=new ArrayList<DbSourceProxy>();
5178 // for (DbSourceProxy db:dbs)
5180 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5184 mname = "From " + dbclass;
5186 if (otherdb.size() == 1)
5188 final DbSourceProxy[] dassource = otherdb
5189 .toArray(new DbSourceProxy[0]);
5190 DbSourceProxy src = otherdb.get(0);
5191 fetchr = new JMenuItem(src.getDbSource());
5192 fetchr.addActionListener(new ActionListener()
5196 public void actionPerformed(ActionEvent e)
5198 new Thread(new Runnable()
5204 new jalview.ws.DBRefFetcher(alignPanel.av
5205 .getSequenceSelection(),
5206 alignPanel.alignFrame, dassource)
5207 .fetchDBRefs(false);
5213 fetchr.setToolTipText("<html>"
5214 + JvSwingUtils.wrapTooltip("Retrieve from "
5215 + src.getDbName()) + "<html>");
5221 final DbSourceProxy[] dassource = otherdb
5222 .toArray(new DbSourceProxy[0]);
5224 DbSourceProxy src = otherdb.get(0);
5225 fetchr = new JMenuItem(MessageManager.formatMessage("label.fetch_all_param", new String[]{src.getDbSource()}));
\r
5226 fetchr.addActionListener(new ActionListener()
5229 public void actionPerformed(ActionEvent e)
5231 new Thread(new Runnable()
5237 new jalview.ws.DBRefFetcher(alignPanel.av
5238 .getSequenceSelection(),
5239 alignPanel.alignFrame, dassource)
5240 .fetchDBRefs(false);
5246 fetchr.setToolTipText("<html>"
5247 + JvSwingUtils.wrapTooltip("Retrieve from all "
5248 + otherdb.size() + " sources in "
5249 + src.getDbSource() + "<br>First is :"
5250 + src.getDbName()) + "<html>");
5253 // and then build the rest of the individual menus
5254 ifetch = new JMenu("Sources from " + src.getDbSource());
5256 String imname = null;
5258 for (DbSourceProxy sproxy : otherdb)
5260 String dbname = sproxy.getDbName();
5261 String sname = dbname.length() > 5 ? dbname.substring(0,
5262 5) + "..." : dbname;
5263 String msname = dbname.length() > 10 ? dbname.substring(
5264 0, 10) + "..." : dbname;
5267 imname = "from '" + sname + "'";
5269 fetchr = new JMenuItem(msname);
5270 final DbSourceProxy[] dassrc =
5272 fetchr.addActionListener(new ActionListener()
5276 public void actionPerformed(ActionEvent e)
5278 new Thread(new Runnable()
5284 new jalview.ws.DBRefFetcher(alignPanel.av
5285 .getSequenceSelection(),
5286 alignPanel.alignFrame, dassrc)
5287 .fetchDBRefs(false);
5293 fetchr.setToolTipText("<html>"
5294 + JvSwingUtils.wrapTooltip("Retrieve from "
5295 + dbname) + "</html>");
5298 if (++icomp >= mcomp || i == (otherdb.size()))
5300 ifetch.setText(MessageManager.formatMessage("label.source_to_target",new String[]{imname,sname}));
5302 ifetch = new JMenu();
5310 if (comp >= mcomp || dbi >= (dbclasses.length))
5312 dfetch.setText(MessageManager.formatMessage("label.source_to_target",new String[]{mname,dbclass}));
5314 dfetch = new JMenu();
5327 * Left justify the whole alignment.
5330 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5332 AlignmentI al = viewport.getAlignment();
5334 viewport.firePropertyChange("alignment", null, al);
5338 * Right justify the whole alignment.
5341 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5343 AlignmentI al = viewport.getAlignment();
5345 viewport.firePropertyChange("alignment", null, al);
5348 public void setShowSeqFeatures(boolean b)
5350 showSeqFeatures.setSelected(true);
5351 viewport.setShowSequenceFeatures(true);
5358 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5359 * awt.event.ActionEvent)
5362 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5364 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5365 alignPanel.paintAlignment(true);
5372 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5376 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5378 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5379 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5387 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5388 * .event.ActionEvent)
5391 protected void showGroupConservation_actionPerformed(ActionEvent e)
5393 viewport.setShowGroupConservation(showGroupConservation.getState());
5394 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5401 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5402 * .event.ActionEvent)
5405 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5407 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5408 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5415 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5416 * .event.ActionEvent)
5419 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5421 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5422 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5426 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5428 showSequenceLogo.setState(true);
5429 viewport.setShowSequenceLogo(true);
5430 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5431 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5435 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5437 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5444 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5445 * .event.ActionEvent)
5448 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5450 if (avc.makeGroupsFromSelection()) {
5451 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5452 alignPanel.updateAnnotation();
5453 alignPanel.paintAlignment(true);
5458 protected void createGroup_actionPerformed(ActionEvent e)
5460 if (avc.createGroup())
5462 alignPanel.alignmentChanged();
5467 protected void unGroup_actionPerformed(ActionEvent e)
5471 alignPanel.alignmentChanged();
5476 * make the given alignmentPanel the currently selected tab
5478 * @param alignmentPanel
5480 public void setDisplayedView(AlignmentPanel alignmentPanel)
5482 if (!viewport.getSequenceSetId().equals(
5483 alignmentPanel.av.getSequenceSetId()))
5486 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5488 if (tabbedPane != null
5489 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5490 .getSelectedIndex())
5492 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5497 class PrintThread extends Thread
5501 public PrintThread(AlignmentPanel ap)
5506 static PageFormat pf;
5511 PrinterJob printJob = PrinterJob.getPrinterJob();
5515 printJob.setPrintable(ap, pf);
5519 printJob.setPrintable(ap);
5522 if (printJob.printDialog())
5527 } catch (Exception PrintException)
5529 PrintException.printStackTrace();