2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.AlignmentSorter;
22 import jalview.analysis.Conservation;
23 import jalview.analysis.CrossRef;
24 import jalview.analysis.NJTree;
25 import jalview.analysis.ParseProperties;
26 import jalview.analysis.SequenceIdMatcher;
27 import jalview.bin.Cache;
28 import jalview.commands.CommandI;
29 import jalview.commands.EditCommand;
30 import jalview.commands.OrderCommand;
31 import jalview.commands.RemoveGapColCommand;
32 import jalview.commands.RemoveGapsCommand;
33 import jalview.commands.SlideSequencesCommand;
34 import jalview.commands.TrimRegionCommand;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.Alignment;
37 import jalview.datamodel.AlignmentAnnotation;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentOrder;
40 import jalview.datamodel.AlignmentView;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.PDBEntry;
43 import jalview.datamodel.SeqCigar;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.io.AlignmentProperties;
48 import jalview.io.AnnotationFile;
49 import jalview.io.FeaturesFile;
50 import jalview.io.FileLoader;
51 import jalview.io.FormatAdapter;
52 import jalview.io.HTMLOutput;
53 import jalview.io.IdentifyFile;
54 import jalview.io.JalviewFileChooser;
55 import jalview.io.JalviewFileView;
56 import jalview.io.JnetAnnotationMaker;
57 import jalview.io.NewickFile;
58 import jalview.io.TCoffeeScoreFile;
59 import jalview.jbgui.GAlignFrame;
60 import jalview.schemes.Blosum62ColourScheme;
61 import jalview.schemes.BuriedColourScheme;
62 import jalview.schemes.ClustalxColourScheme;
63 import jalview.schemes.ColourSchemeI;
64 import jalview.schemes.ColourSchemeProperty;
65 import jalview.schemes.HelixColourScheme;
66 import jalview.schemes.HydrophobicColourScheme;
67 import jalview.schemes.NucleotideColourScheme;
68 import jalview.schemes.PIDColourScheme;
69 import jalview.schemes.PurinePyrimidineColourScheme;
70 import jalview.schemes.RNAHelicesColourChooser;
71 import jalview.schemes.ResidueProperties;
72 import jalview.schemes.StrandColourScheme;
73 import jalview.schemes.TCoffeeColourScheme;
74 import jalview.schemes.TaylorColourScheme;
75 import jalview.schemes.TurnColourScheme;
76 import jalview.schemes.UserColourScheme;
77 import jalview.schemes.ZappoColourScheme;
78 import jalview.util.MessageManager;
79 import jalview.ws.jws1.Discoverer;
80 import jalview.ws.jws2.Jws2Discoverer;
81 import jalview.ws.seqfetcher.DbSourceProxy;
83 import java.awt.BorderLayout;
84 import java.awt.Color;
85 import java.awt.Component;
86 import java.awt.GridLayout;
87 import java.awt.Rectangle;
88 import java.awt.Toolkit;
89 import java.awt.datatransfer.Clipboard;
90 import java.awt.datatransfer.DataFlavor;
91 import java.awt.datatransfer.StringSelection;
92 import java.awt.datatransfer.Transferable;
93 import java.awt.dnd.DnDConstants;
94 import java.awt.dnd.DropTargetDragEvent;
95 import java.awt.dnd.DropTargetDropEvent;
96 import java.awt.dnd.DropTargetEvent;
97 import java.awt.dnd.DropTargetListener;
98 import java.awt.event.ActionEvent;
99 import java.awt.event.ActionListener;
100 import java.awt.event.KeyAdapter;
101 import java.awt.event.KeyEvent;
102 import java.awt.event.MouseAdapter;
103 import java.awt.event.MouseEvent;
104 import java.awt.print.PageFormat;
105 import java.awt.print.PrinterJob;
106 import java.beans.PropertyChangeEvent;
109 import java.util.ArrayList;
110 import java.util.Enumeration;
111 import java.util.Hashtable;
112 import java.util.List;
113 import java.util.Vector;
115 import javax.swing.JButton;
116 import javax.swing.JEditorPane;
117 import javax.swing.JInternalFrame;
118 import javax.swing.JLabel;
119 import javax.swing.JLayeredPane;
120 import javax.swing.JMenu;
121 import javax.swing.JMenuItem;
122 import javax.swing.JOptionPane;
123 import javax.swing.JPanel;
124 import javax.swing.JProgressBar;
125 import javax.swing.JRadioButtonMenuItem;
126 import javax.swing.JScrollPane;
127 import javax.swing.SwingUtilities;
133 * @version $Revision$
135 public class AlignFrame extends GAlignFrame implements DropTargetListener,
140 public static final int DEFAULT_WIDTH = 700;
143 public static final int DEFAULT_HEIGHT = 500;
145 public AlignmentPanel alignPanel;
147 AlignViewport viewport;
149 Vector alignPanels = new Vector();
152 * Last format used to load or save alignments in this window
154 String currentFileFormat = null;
157 * Current filename for this alignment
159 String fileName = null;
162 * Creates a new AlignFrame object with specific width and height.
168 public AlignFrame(AlignmentI al, int width, int height)
170 this(al, null, width, height);
174 * Creates a new AlignFrame object with specific width, height and
180 * @param sequenceSetId
182 public AlignFrame(AlignmentI al, int width, int height,
183 String sequenceSetId)
185 this(al, null, width, height, sequenceSetId);
189 * Creates a new AlignFrame object with specific width, height and
195 * @param sequenceSetId
198 public AlignFrame(AlignmentI al, int width, int height,
199 String sequenceSetId, String viewId)
201 this(al, null, width, height, sequenceSetId, viewId);
205 * new alignment window with hidden columns
209 * @param hiddenColumns
210 * ColumnSelection or null
212 * Width of alignment frame
216 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
217 int width, int height)
219 this(al, hiddenColumns, width, height, null);
223 * Create alignment frame for al with hiddenColumns, a specific width and
224 * height, and specific sequenceId
227 * @param hiddenColumns
230 * @param sequenceSetId
233 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
234 int width, int height, String sequenceSetId)
236 this(al, hiddenColumns, width, height, sequenceSetId, null);
240 * Create alignment frame for al with hiddenColumns, a specific width and
241 * height, and specific sequenceId
244 * @param hiddenColumns
247 * @param sequenceSetId
252 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
253 int width, int height, String sequenceSetId, String viewId)
255 setSize(width, height);
256 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
258 alignPanel = new AlignmentPanel(this, viewport);
260 if (al.getDataset() == null)
265 addAlignmentPanel(alignPanel, true);
270 * Make a new AlignFrame from exisiting alignmentPanels
277 public AlignFrame(AlignmentPanel ap)
281 addAlignmentPanel(ap, false);
286 * initalise the alignframe from the underlying viewport data and the
291 if (viewport.getAlignmentConservationAnnotation() == null)
293 BLOSUM62Colour.setEnabled(false);
294 conservationMenuItem.setEnabled(false);
295 modifyConservation.setEnabled(false);
296 // PIDColour.setEnabled(false);
297 // abovePIDThreshold.setEnabled(false);
298 // modifyPID.setEnabled(false);
301 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
304 if (sortby.equals("Id"))
306 sortIDMenuItem_actionPerformed(null);
308 else if (sortby.equals("Pairwise Identity"))
310 sortPairwiseMenuItem_actionPerformed(null);
313 if (Desktop.desktop != null)
315 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
316 addServiceListeners();
317 setGUINucleotide(viewport.getAlignment().isNucleotide());
320 setMenusFromViewport(viewport);
321 buildSortByAnnotationScoresMenu();
322 if (viewport.wrapAlignment)
324 wrapMenuItem_actionPerformed(null);
327 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
329 this.overviewMenuItem_actionPerformed(null);
337 * Change the filename and format for the alignment, and enable the 'reload'
338 * button functionality.
345 public void setFileName(String file, String format)
348 currentFileFormat = format;
349 reload.setEnabled(true);
352 void addKeyListener()
354 addKeyListener(new KeyAdapter()
357 public void keyPressed(KeyEvent evt)
359 if (viewport.cursorMode
360 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
361 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
362 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
363 && Character.isDigit(evt.getKeyChar()))
364 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
366 switch (evt.getKeyCode())
369 case 27: // escape key
370 deselectAllSequenceMenuItem_actionPerformed(null);
374 case KeyEvent.VK_DOWN:
375 if (evt.isAltDown() || !viewport.cursorMode)
376 moveSelectedSequences(false);
377 if (viewport.cursorMode)
378 alignPanel.seqPanel.moveCursor(0, 1);
382 if (evt.isAltDown() || !viewport.cursorMode)
383 moveSelectedSequences(true);
384 if (viewport.cursorMode)
385 alignPanel.seqPanel.moveCursor(0, -1);
389 case KeyEvent.VK_LEFT:
390 if (evt.isAltDown() || !viewport.cursorMode)
391 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
393 alignPanel.seqPanel.moveCursor(-1, 0);
397 case KeyEvent.VK_RIGHT:
398 if (evt.isAltDown() || !viewport.cursorMode)
399 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
401 alignPanel.seqPanel.moveCursor(1, 0);
404 case KeyEvent.VK_SPACE:
405 if (viewport.cursorMode)
407 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
408 || evt.isShiftDown() || evt.isAltDown());
412 // case KeyEvent.VK_A:
413 // if (viewport.cursorMode)
415 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
416 // //System.out.println("A");
420 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
421 * System.out.println("closing bracket"); } break;
423 case KeyEvent.VK_DELETE:
424 case KeyEvent.VK_BACK_SPACE:
425 if (!viewport.cursorMode)
427 cut_actionPerformed(null);
431 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
432 || evt.isShiftDown() || evt.isAltDown());
438 if (viewport.cursorMode)
440 alignPanel.seqPanel.setCursorRow();
444 if (viewport.cursorMode && !evt.isControlDown())
446 alignPanel.seqPanel.setCursorColumn();
450 if (viewport.cursorMode)
452 alignPanel.seqPanel.setCursorPosition();
456 case KeyEvent.VK_ENTER:
457 case KeyEvent.VK_COMMA:
458 if (viewport.cursorMode)
460 alignPanel.seqPanel.setCursorRowAndColumn();
465 if (viewport.cursorMode)
467 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
471 if (viewport.cursorMode)
473 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
478 viewport.cursorMode = !viewport.cursorMode;
479 statusBar.setText(MessageManager.formatMessage("label.keyboard_editing_mode", new String[]{(viewport.cursorMode ? "on" : "off")}));
480 if (viewport.cursorMode)
482 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
483 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
485 alignPanel.seqPanel.seqCanvas.repaint();
491 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
492 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
494 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
496 javax.help.HelpBroker hb = hs.createHelpBroker();
497 hb.setCurrentID("home");
498 hb.setDisplayed(true);
499 } catch (Exception ex)
501 ex.printStackTrace();
506 boolean toggleSeqs = !evt.isControlDown();
507 boolean toggleCols = !evt.isShiftDown();
508 toggleHiddenRegions(toggleSeqs, toggleCols);
511 case KeyEvent.VK_PAGE_UP:
512 if (viewport.wrapAlignment)
514 alignPanel.scrollUp(true);
518 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
519 - viewport.endSeq + viewport.startSeq);
522 case KeyEvent.VK_PAGE_DOWN:
523 if (viewport.wrapAlignment)
525 alignPanel.scrollUp(false);
529 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
530 + viewport.endSeq - viewport.startSeq);
537 public void keyReleased(KeyEvent evt)
539 switch (evt.getKeyCode())
541 case KeyEvent.VK_LEFT:
542 if (evt.isAltDown() || !viewport.cursorMode)
543 viewport.firePropertyChange("alignment", null, viewport
544 .getAlignment().getSequences());
547 case KeyEvent.VK_RIGHT:
548 if (evt.isAltDown() || !viewport.cursorMode)
549 viewport.firePropertyChange("alignment", null, viewport
550 .getAlignment().getSequences());
557 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
559 ap.alignFrame = this;
561 alignPanels.addElement(ap);
563 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
565 int aSize = alignPanels.size();
567 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
569 if (aSize == 1 && ap.av.viewName == null)
571 this.getContentPane().add(ap, BorderLayout.CENTER);
577 setInitialTabVisible();
580 expandViews.setEnabled(true);
581 gatherViews.setEnabled(true);
582 tabbedPane.addTab(ap.av.viewName, ap);
584 ap.setVisible(false);
589 if (ap.av.isPadGaps())
591 ap.av.getAlignment().padGaps();
593 ap.av.updateConservation(ap);
594 ap.av.updateConsensus(ap);
595 ap.av.updateStrucConsensus(ap);
599 public void setInitialTabVisible()
601 expandViews.setEnabled(true);
602 gatherViews.setEnabled(true);
603 tabbedPane.setVisible(true);
604 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
605 tabbedPane.addTab(first.av.viewName, first);
606 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
609 public AlignViewport getViewport()
614 /* Set up intrinsic listeners for dynamically generated GUI bits. */
615 private void addServiceListeners()
617 final java.beans.PropertyChangeListener thisListener;
618 Desktop.instance.addJalviewPropertyChangeListener("services",
619 thisListener = new java.beans.PropertyChangeListener()
622 public void propertyChange(PropertyChangeEvent evt)
624 // // System.out.println("Discoverer property change.");
625 // if (evt.getPropertyName().equals("services"))
627 SwingUtilities.invokeLater(new Runnable()
634 .println("Rebuild WS Menu for service change");
635 BuildWebServiceMenu();
642 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
645 public void internalFrameClosed(
646 javax.swing.event.InternalFrameEvent evt)
648 System.out.println("deregistering discoverer listener");
649 Desktop.instance.removeJalviewPropertyChangeListener("services",
651 closeMenuItem_actionPerformed(true);
654 // Finally, build the menu once to get current service state
655 new Thread(new Runnable()
660 BuildWebServiceMenu();
665 public void setGUINucleotide(boolean nucleotide)
667 showTranslation.setVisible(nucleotide);
668 conservationMenuItem.setEnabled(!nucleotide);
669 modifyConservation.setEnabled(!nucleotide);
670 showGroupConservation.setEnabled(!nucleotide);
671 rnahelicesColour.setEnabled(nucleotide);
672 purinePyrimidineColour.setEnabled(nucleotide);
673 // Remember AlignFrame always starts as protein
677 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
682 * set up menus for the currently viewport. This may be called after any
683 * operation that affects the data in the current view (selection changed,
684 * etc) to update the menus to reflect the new state.
686 public void setMenusForViewport()
688 setMenusFromViewport(viewport);
692 * Need to call this method when tabs are selected for multiple views, or when
693 * loading from Jalview2XML.java
698 void setMenusFromViewport(AlignViewport av)
700 padGapsMenuitem.setSelected(av.isPadGaps());
701 colourTextMenuItem.setSelected(av.showColourText);
702 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
703 conservationMenuItem.setSelected(av.getConservationSelected());
704 seqLimits.setSelected(av.getShowJVSuffix());
705 idRightAlign.setSelected(av.rightAlignIds);
706 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
707 renderGapsMenuItem.setSelected(av.renderGaps);
708 wrapMenuItem.setSelected(av.wrapAlignment);
709 scaleAbove.setVisible(av.wrapAlignment);
710 scaleLeft.setVisible(av.wrapAlignment);
711 scaleRight.setVisible(av.wrapAlignment);
712 annotationPanelMenuItem.setState(av.showAnnotation);
713 viewBoxesMenuItem.setSelected(av.showBoxes);
714 viewTextMenuItem.setSelected(av.showText);
715 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
716 showGroupConsensus.setSelected(av.isShowGroupConsensus());
717 showGroupConservation.setSelected(av.isShowGroupConservation());
718 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
719 showSequenceLogo.setSelected(av.isShowSequenceLogo());
720 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
722 setColourSelected(ColourSchemeProperty.getColourName(av
723 .getGlobalColourScheme()));
725 showSeqFeatures.setSelected(av.showSequenceFeatures);
726 hiddenMarkers.setState(av.showHiddenMarkers);
727 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
728 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
729 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
730 autoCalculate.setSelected(av.autoCalculateConsensus);
731 sortByTree.setSelected(av.sortByTree);
732 listenToViewSelections.setSelected(av.followSelection);
733 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
735 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
736 setShowProductsEnabled();
741 // methods for implementing IProgressIndicator
742 // need to refactor to a reusable stub class
743 Hashtable progressBars, progressBarHandlers;
748 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
751 public void setProgressBar(String message, long id)
753 if (progressBars == null)
755 progressBars = new Hashtable();
756 progressBarHandlers = new Hashtable();
759 JPanel progressPanel;
760 Long lId = new Long(id);
761 GridLayout layout = (GridLayout) statusPanel.getLayout();
762 if (progressBars.get(lId) != null)
764 progressPanel = (JPanel) progressBars.get(new Long(id));
765 statusPanel.remove(progressPanel);
766 progressBars.remove(lId);
767 progressPanel = null;
770 statusBar.setText(message);
772 if (progressBarHandlers.contains(lId))
774 progressBarHandlers.remove(lId);
776 layout.setRows(layout.getRows() - 1);
780 progressPanel = new JPanel(new BorderLayout(10, 5));
782 JProgressBar progressBar = new JProgressBar();
783 progressBar.setIndeterminate(true);
785 progressPanel.add(new JLabel(message), BorderLayout.WEST);
786 progressPanel.add(progressBar, BorderLayout.CENTER);
788 layout.setRows(layout.getRows() + 1);
789 statusPanel.add(progressPanel);
791 progressBars.put(lId, progressPanel);
794 // setMenusForViewport();
799 public void registerHandler(final long id,
800 final IProgressIndicatorHandler handler)
802 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
805 "call setProgressBar before registering the progress bar's handler.");
807 progressBarHandlers.put(new Long(id), handler);
808 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
809 if (handler.canCancel())
811 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
812 final IProgressIndicator us = this;
813 cancel.addActionListener(new ActionListener()
817 public void actionPerformed(ActionEvent e)
819 handler.cancelActivity(id);
822 + ((JLabel) progressPanel.getComponent(0))
826 progressPanel.add(cancel, BorderLayout.EAST);
832 * @return true if any progress bars are still active
835 public boolean operationInProgress()
837 if (progressBars != null && progressBars.size() > 0)
845 * Added so Castor Mapping file can obtain Jalview Version
847 public String getVersion()
849 return jalview.bin.Cache.getProperty("VERSION");
852 public FeatureRenderer getFeatureRenderer()
854 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
858 public void fetchSequence_actionPerformed(ActionEvent e)
860 new SequenceFetcher(this);
864 public void addFromFile_actionPerformed(ActionEvent e)
866 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
870 public void reload_actionPerformed(ActionEvent e)
872 if (fileName != null)
874 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
875 // originating file's format
876 // TODO: work out how to recover feature settings for correct view(s) when
878 if (currentFileFormat.equals("Jalview"))
880 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
881 for (int i = 0; i < frames.length; i++)
883 if (frames[i] instanceof AlignFrame && frames[i] != this
884 && ((AlignFrame) frames[i]).fileName != null
885 && ((AlignFrame) frames[i]).fileName.equals(fileName))
889 frames[i].setSelected(true);
890 Desktop.instance.closeAssociatedWindows();
891 } catch (java.beans.PropertyVetoException ex)
897 Desktop.instance.closeAssociatedWindows();
899 FileLoader loader = new FileLoader();
900 String protocol = fileName.startsWith("http:") ? "URL" : "File";
901 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
905 Rectangle bounds = this.getBounds();
907 FileLoader loader = new FileLoader();
908 String protocol = fileName.startsWith("http:") ? "URL" : "File";
909 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
910 protocol, currentFileFormat);
912 newframe.setBounds(bounds);
913 if (featureSettings != null && featureSettings.isShowing())
915 final Rectangle fspos = featureSettings.frame.getBounds();
916 // TODO: need a 'show feature settings' function that takes bounds -
917 // need to refactor Desktop.addFrame
918 newframe.featureSettings_actionPerformed(null);
919 final FeatureSettings nfs = newframe.featureSettings;
920 SwingUtilities.invokeLater(new Runnable()
925 nfs.frame.setBounds(fspos);
928 this.featureSettings.close();
929 this.featureSettings = null;
931 this.closeMenuItem_actionPerformed(true);
937 public void addFromText_actionPerformed(ActionEvent e)
939 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
943 public void addFromURL_actionPerformed(ActionEvent e)
945 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
949 public void save_actionPerformed(ActionEvent e)
952 || (currentFileFormat == null || !jalview.io.FormatAdapter
953 .isValidIOFormat(currentFileFormat, true))
954 || fileName.startsWith("http"))
956 saveAs_actionPerformed(null);
960 saveAlignment(fileName, currentFileFormat);
971 public void saveAs_actionPerformed(ActionEvent e)
973 JalviewFileChooser chooser = new JalviewFileChooser(
974 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
975 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
976 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
977 currentFileFormat, false);
979 chooser.setFileView(new JalviewFileView());
980 chooser.setDialogTitle("Save Alignment to file");
981 chooser.setToolTipText("Save");
983 int value = chooser.showSaveDialog(this);
985 if (value == JalviewFileChooser.APPROVE_OPTION)
987 currentFileFormat = chooser.getSelectedFormat();
988 if (currentFileFormat == null)
990 JOptionPane.showInternalMessageDialog(Desktop.desktop,
991 MessageManager.getString("label.select_file_format_before_saving"),
992 MessageManager.getString("label.file_format_not_specified"), JOptionPane.WARNING_MESSAGE);
993 value = chooser.showSaveDialog(this);
997 fileName = chooser.getSelectedFile().getPath();
999 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1002 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1003 if (currentFileFormat.indexOf(" ") > -1)
1005 currentFileFormat = currentFileFormat.substring(0,
1006 currentFileFormat.indexOf(" "));
1008 saveAlignment(fileName, currentFileFormat);
1012 public boolean saveAlignment(String file, String format)
1014 boolean success = true;
1016 if (format.equalsIgnoreCase("Jalview"))
1018 String shortName = title;
1020 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1022 shortName = shortName.substring(shortName
1023 .lastIndexOf(java.io.File.separatorChar) + 1);
1026 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1028 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1034 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1036 warningMessage("Cannot save file " + fileName + " using format "
1037 + format, "Alignment output format not supported");
1038 saveAs_actionPerformed(null);
1039 // JBPNote need to have a raise_gui flag here
1043 String[] omitHidden = null;
1045 if (viewport.hasHiddenColumns())
1047 int reply = JOptionPane
1048 .showInternalConfirmDialog(
1050 MessageManager.getString("label.alignment_contains_hidden_columns"),
1051 MessageManager.getString("action.save_omit_hidden_columns"),
1052 JOptionPane.YES_NO_OPTION,
1053 JOptionPane.QUESTION_MESSAGE);
1055 if (reply == JOptionPane.YES_OPTION)
1057 omitHidden = viewport.getViewAsString(false);
1060 FormatAdapter f = new FormatAdapter();
1061 String output = f.formatSequences(format,
1062 viewport.getAlignment(), // class cast exceptions will
1063 // occur in the distant future
1064 omitHidden, f.getCacheSuffixDefault(format),
1065 viewport.getColumnSelection());
1075 java.io.PrintWriter out = new java.io.PrintWriter(
1076 new java.io.FileWriter(file));
1080 this.setTitle(file);
1081 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1082 } catch (Exception ex)
1085 ex.printStackTrace();
1092 JOptionPane.showInternalMessageDialog(this, MessageManager.formatMessage("label.couldnt_save_file", new String[]{fileName}),
1093 MessageManager.getString("label.error_saving_file"), JOptionPane.WARNING_MESSAGE);
1099 private void warningMessage(String warning, String title)
1101 if (new jalview.util.Platform().isHeadless())
1103 System.err.println("Warning: " + title + "\nWarning: " + warning);
1108 JOptionPane.showInternalMessageDialog(this, warning, title,
1109 JOptionPane.WARNING_MESSAGE);
1121 protected void outputText_actionPerformed(ActionEvent e)
1123 String[] omitHidden = null;
1125 if (viewport.hasHiddenColumns())
1127 int reply = JOptionPane
1128 .showInternalConfirmDialog(
1130 MessageManager.getString("label.alignment_contains_hidden_columns"),
1131 MessageManager.getString("action.save_omit_hidden_columns"),
1132 JOptionPane.YES_NO_OPTION,
1133 JOptionPane.QUESTION_MESSAGE);
1135 if (reply == JOptionPane.YES_OPTION)
1137 omitHidden = viewport.getViewAsString(false);
1141 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1142 cap.setForInput(null);
1146 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1147 viewport.getAlignment(), omitHidden,
1148 viewport.getColumnSelection()));
1149 Desktop.addInternalFrame(cap,
1150 "Alignment output - " + e.getActionCommand(), 600, 500);
1151 } catch (OutOfMemoryError oom)
1153 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1166 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1168 new HTMLOutput(alignPanel,
1169 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1170 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1173 public void createImageMap(File file, String image)
1175 alignPanel.makePNGImageMap(file, image);
1185 public void createPNG(File f)
1187 alignPanel.makePNG(f);
1197 public void createEPS(File f)
1199 alignPanel.makeEPS(f);
1203 public void pageSetup_actionPerformed(ActionEvent e)
1205 PrinterJob printJob = PrinterJob.getPrinterJob();
1206 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1216 public void printMenuItem_actionPerformed(ActionEvent e)
1218 // Putting in a thread avoids Swing painting problems
1219 PrintThread thread = new PrintThread(alignPanel);
1224 public void exportFeatures_actionPerformed(ActionEvent e)
1226 new AnnotationExporter().exportFeatures(alignPanel);
1230 public void exportAnnotations_actionPerformed(ActionEvent e)
1232 new AnnotationExporter().exportAnnotations(alignPanel,
1233 viewport.showAnnotation ? viewport.getAlignment()
1234 .getAlignmentAnnotation() : null, viewport
1235 .getAlignment().getGroups(), ((Alignment) viewport
1236 .getAlignment()).alignmentProperties);
1240 public void associatedData_actionPerformed(ActionEvent e)
1242 // Pick the tree file
1243 JalviewFileChooser chooser = new JalviewFileChooser(
1244 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1245 chooser.setFileView(new JalviewFileView());
1246 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1247 chooser.setToolTipText("Load Jalview Annotations / Features file");
1249 int value = chooser.showOpenDialog(null);
1251 if (value == JalviewFileChooser.APPROVE_OPTION)
1253 String choice = chooser.getSelectedFile().getPath();
1254 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1255 loadJalviewDataFile(choice, null, null, null);
1261 * Close the current view or all views in the alignment frame. If the frame
1262 * only contains one view then the alignment will be removed from memory.
1264 * @param closeAllTabs
1267 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1269 if (alignPanels != null && alignPanels.size() < 2)
1271 closeAllTabs = true;
1276 if (alignPanels != null)
1280 if (this.isClosed())
1282 // really close all the windows - otherwise wait till
1283 // setClosed(true) is called
1284 for (int i = 0; i < alignPanels.size(); i++)
1286 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1293 closeView(alignPanel);
1299 this.setClosed(true);
1301 } catch (Exception ex)
1303 ex.printStackTrace();
1308 * close alignPanel2 and shuffle tabs appropriately.
1310 * @param alignPanel2
1312 public void closeView(AlignmentPanel alignPanel2)
1314 int index = tabbedPane.getSelectedIndex();
1315 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1316 alignPanels.removeElement(alignPanel2);
1318 // if (viewport == alignPanel2.av)
1322 alignPanel2.closePanel();
1325 tabbedPane.removeTabAt(closedindex);
1326 tabbedPane.validate();
1328 if (index > closedindex || index == tabbedPane.getTabCount())
1330 // modify currently selected tab index if necessary.
1334 this.tabSelectionChanged(index);
1340 void updateEditMenuBar()
1343 if (viewport.historyList.size() > 0)
1345 undoMenuItem.setEnabled(true);
1346 CommandI command = (CommandI) viewport.historyList.peek();
1347 undoMenuItem.setText(MessageManager.formatMessage("label.undo_command", new String[]{command.getDescription()}));
1351 undoMenuItem.setEnabled(false);
1352 undoMenuItem.setText(MessageManager.getString("action.undo"));
1355 if (viewport.redoList.size() > 0)
1357 redoMenuItem.setEnabled(true);
1359 CommandI command = (CommandI) viewport.redoList.peek();
1360 redoMenuItem.setText(MessageManager.formatMessage("label.redo_command", new String[]{command.getDescription()}));
1364 redoMenuItem.setEnabled(false);
1365 redoMenuItem.setText(MessageManager.getString("action.redo"));
1369 public void addHistoryItem(CommandI command)
1371 if (command.getSize() > 0)
1373 viewport.historyList.push(command);
1374 viewport.redoList.clear();
1375 updateEditMenuBar();
1376 viewport.updateHiddenColumns();
1377 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1378 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1379 // viewport.getColumnSelection()
1380 // .getHiddenColumns().size() > 0);
1386 * @return alignment objects for all views
1388 AlignmentI[] getViewAlignments()
1390 if (alignPanels != null)
1392 Enumeration e = alignPanels.elements();
1393 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1394 for (int i = 0; e.hasMoreElements(); i++)
1396 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1400 if (viewport != null)
1402 return new AlignmentI[]
1403 { viewport.getAlignment() };
1415 protected void undoMenuItem_actionPerformed(ActionEvent e)
1417 if (viewport.historyList.empty())
1419 CommandI command = (CommandI) viewport.historyList.pop();
1420 viewport.redoList.push(command);
1421 command.undoCommand(getViewAlignments());
1423 AlignViewport originalSource = getOriginatingSource(command);
1424 updateEditMenuBar();
1426 if (originalSource != null)
1428 if (originalSource != viewport)
1431 .warn("Implementation worry: mismatch of viewport origin for undo");
1433 originalSource.updateHiddenColumns();
1434 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1436 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1437 // viewport.getColumnSelection()
1438 // .getHiddenColumns().size() > 0);
1439 originalSource.firePropertyChange("alignment", null, originalSource
1440 .getAlignment().getSequences());
1451 protected void redoMenuItem_actionPerformed(ActionEvent e)
1453 if (viewport.redoList.size() < 1)
1458 CommandI command = (CommandI) viewport.redoList.pop();
1459 viewport.historyList.push(command);
1460 command.doCommand(getViewAlignments());
1462 AlignViewport originalSource = getOriginatingSource(command);
1463 updateEditMenuBar();
1465 if (originalSource != null)
1468 if (originalSource != viewport)
1471 .warn("Implementation worry: mismatch of viewport origin for redo");
1473 originalSource.updateHiddenColumns();
1474 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1476 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1477 // viewport.getColumnSelection()
1478 // .getHiddenColumns().size() > 0);
1479 originalSource.firePropertyChange("alignment", null, originalSource
1480 .getAlignment().getSequences());
1484 AlignViewport getOriginatingSource(CommandI command)
1486 AlignViewport originalSource = null;
1487 // For sequence removal and addition, we need to fire
1488 // the property change event FROM the viewport where the
1489 // original alignment was altered
1490 AlignmentI al = null;
1491 if (command instanceof EditCommand)
1493 EditCommand editCommand = (EditCommand) command;
1494 al = editCommand.getAlignment();
1495 Vector comps = (Vector) PaintRefresher.components.get(viewport
1496 .getSequenceSetId());
1498 for (int i = 0; i < comps.size(); i++)
1500 if (comps.elementAt(i) instanceof AlignmentPanel)
1502 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1504 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1511 if (originalSource == null)
1513 // The original view is closed, we must validate
1514 // the current view against the closed view first
1517 PaintRefresher.validateSequences(al, viewport.getAlignment());
1520 originalSource = viewport;
1523 return originalSource;
1532 public void moveSelectedSequences(boolean up)
1534 SequenceGroup sg = viewport.getSelectionGroup();
1540 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1541 viewport.getHiddenRepSequences(), up);
1542 alignPanel.paintAlignment(true);
1545 synchronized void slideSequences(boolean right, int size)
1547 List<SequenceI> sg = new Vector();
1548 if (viewport.cursorMode)
1550 sg.add(viewport.getAlignment().getSequenceAt(
1551 alignPanel.seqPanel.seqCanvas.cursorY));
1553 else if (viewport.getSelectionGroup() != null
1554 && viewport.getSelectionGroup().getSize() != viewport
1555 .getAlignment().getHeight())
1557 sg = viewport.getSelectionGroup().getSequences(
1558 viewport.getHiddenRepSequences());
1566 Vector invertGroup = new Vector();
1568 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1570 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1571 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1574 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1576 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1577 for (int i = 0; i < invertGroup.size(); i++)
1578 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1580 SlideSequencesCommand ssc;
1582 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1583 size, viewport.getGapCharacter());
1585 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1586 size, viewport.getGapCharacter());
1588 int groupAdjustment = 0;
1589 if (ssc.getGapsInsertedBegin() && right)
1591 if (viewport.cursorMode)
1592 alignPanel.seqPanel.moveCursor(size, 0);
1594 groupAdjustment = size;
1596 else if (!ssc.getGapsInsertedBegin() && !right)
1598 if (viewport.cursorMode)
1599 alignPanel.seqPanel.moveCursor(-size, 0);
1601 groupAdjustment = -size;
1604 if (groupAdjustment != 0)
1606 viewport.getSelectionGroup().setStartRes(
1607 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1608 viewport.getSelectionGroup().setEndRes(
1609 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1612 boolean appendHistoryItem = false;
1613 if (viewport.historyList != null && viewport.historyList.size() > 0
1614 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1616 appendHistoryItem = ssc
1617 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1621 if (!appendHistoryItem)
1622 addHistoryItem(ssc);
1634 protected void copy_actionPerformed(ActionEvent e)
1637 if (viewport.getSelectionGroup() == null)
1641 // TODO: preserve the ordering of displayed alignment annotation in any
1642 // internal paste (particularly sequence associated annotation)
1643 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1644 String[] omitHidden = null;
1646 if (viewport.hasHiddenColumns())
1648 omitHidden = viewport.getViewAsString(true);
1651 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1654 StringSelection ss = new StringSelection(output);
1658 jalview.gui.Desktop.internalCopy = true;
1659 // Its really worth setting the clipboard contents
1660 // to empty before setting the large StringSelection!!
1661 Toolkit.getDefaultToolkit().getSystemClipboard()
1662 .setContents(new StringSelection(""), null);
1664 Toolkit.getDefaultToolkit().getSystemClipboard()
1665 .setContents(ss, Desktop.instance);
1666 } catch (OutOfMemoryError er)
1668 new OOMWarning("copying region", er);
1672 Vector hiddenColumns = null;
1673 if (viewport.hasHiddenColumns())
1675 hiddenColumns = new Vector();
1676 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1677 .getSelectionGroup().getEndRes();
1678 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1681 int[] region = (int[]) viewport.getColumnSelection()
1682 .getHiddenColumns().elementAt(i);
1683 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1685 hiddenColumns.addElement(new int[]
1686 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1691 Desktop.jalviewClipboard = new Object[]
1692 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1693 statusBar.setText(MessageManager.formatMessage("label.copied_sequences_to_clipboard", new String[]{Integer.valueOf(seqs.length).toString()}));
1703 protected void pasteNew_actionPerformed(ActionEvent e)
1715 protected void pasteThis_actionPerformed(ActionEvent e)
1721 * Paste contents of Jalview clipboard
1723 * @param newAlignment
1724 * true to paste to a new alignment, otherwise add to this.
1726 void paste(boolean newAlignment)
1728 boolean externalPaste = true;
1731 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1732 Transferable contents = c.getContents(this);
1734 if (contents == null)
1742 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1743 if (str.length() < 1)
1748 format = new IdentifyFile().Identify(str, "Paste");
1750 } catch (OutOfMemoryError er)
1752 new OOMWarning("Out of memory pasting sequences!!", er);
1756 SequenceI[] sequences;
1757 boolean annotationAdded = false;
1758 AlignmentI alignment = null;
1760 if (Desktop.jalviewClipboard != null)
1762 // The clipboard was filled from within Jalview, we must use the
1764 // And dataset from the copied alignment
1765 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1766 // be doubly sure that we create *new* sequence objects.
1767 sequences = new SequenceI[newseq.length];
1768 for (int i = 0; i < newseq.length; i++)
1770 sequences[i] = new Sequence(newseq[i]);
1772 alignment = new Alignment(sequences);
1773 externalPaste = false;
1777 // parse the clipboard as an alignment.
1778 alignment = new FormatAdapter().readFile(str, "Paste", format);
1779 sequences = alignment.getSequencesArray();
1783 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1789 if (Desktop.jalviewClipboard != null)
1791 // dataset is inherited
1792 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1796 // new dataset is constructed
1797 alignment.setDataset(null);
1799 alwidth = alignment.getWidth() + 1;
1803 AlignmentI pastedal = alignment; // preserve pasted alignment object
1804 // Add pasted sequences and dataset into existing alignment.
1805 alignment = viewport.getAlignment();
1806 alwidth = alignment.getWidth() + 1;
1807 // decide if we need to import sequences from an existing dataset
1808 boolean importDs = Desktop.jalviewClipboard != null
1809 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1810 // importDs==true instructs us to copy over new dataset sequences from
1811 // an existing alignment
1812 Vector newDs = (importDs) ? new Vector() : null; // used to create
1813 // minimum dataset set
1815 for (int i = 0; i < sequences.length; i++)
1819 newDs.addElement(null);
1821 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1823 if (importDs && ds != null)
1825 if (!newDs.contains(ds))
1827 newDs.setElementAt(ds, i);
1828 ds = new Sequence(ds);
1829 // update with new dataset sequence
1830 sequences[i].setDatasetSequence(ds);
1834 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1839 // copy and derive new dataset sequence
1840 sequences[i] = sequences[i].deriveSequence();
1841 alignment.getDataset().addSequence(
1842 sequences[i].getDatasetSequence());
1843 // TODO: avoid creation of duplicate dataset sequences with a
1844 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1846 alignment.addSequence(sequences[i]); // merges dataset
1850 newDs.clear(); // tidy up
1852 if (alignment.getAlignmentAnnotation() != null)
1854 for (AlignmentAnnotation alan : alignment
1855 .getAlignmentAnnotation())
1857 if (alan.graphGroup > fgroup)
1859 fgroup = alan.graphGroup;
1863 if (pastedal.getAlignmentAnnotation() != null)
1865 // Add any annotation attached to alignment.
1866 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1867 for (int i = 0; i < alann.length; i++)
1869 annotationAdded = true;
1870 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1872 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1873 if (newann.graphGroup > -1)
1875 if (newGraphGroups.size() <= newann.graphGroup
1876 || newGraphGroups.get(newann.graphGroup) == null)
1878 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1880 newGraphGroups.add(q, null);
1882 newGraphGroups.set(newann.graphGroup, new Integer(
1885 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1889 newann.padAnnotation(alwidth);
1890 alignment.addAnnotation(newann);
1900 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1901 sequences, 0, alignment.getWidth(), alignment));
1903 // Add any annotations attached to sequences
1904 for (int i = 0; i < sequences.length; i++)
1906 if (sequences[i].getAnnotation() != null)
1908 AlignmentAnnotation newann;
1909 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1911 annotationAdded = true;
1912 newann = sequences[i].getAnnotation()[a];
1913 newann.adjustForAlignment();
1914 newann.padAnnotation(alwidth);
1915 if (newann.graphGroup > -1)
1917 if (newann.graphGroup > -1)
1919 if (newGraphGroups.size() <= newann.graphGroup
1920 || newGraphGroups.get(newann.graphGroup) == null)
1922 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1924 newGraphGroups.add(q, null);
1926 newGraphGroups.set(newann.graphGroup, new Integer(
1929 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1933 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1938 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1945 // propagate alignment changed.
1946 viewport.setEndSeq(alignment.getHeight());
1947 if (annotationAdded)
1949 // Duplicate sequence annotation in all views.
1950 AlignmentI[] alview = this.getViewAlignments();
1951 for (int i = 0; i < sequences.length; i++)
1953 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1956 for (int avnum = 0; avnum < alview.length; avnum++)
1958 if (alview[avnum] != alignment)
1960 // duplicate in a view other than the one with input focus
1961 int avwidth = alview[avnum].getWidth() + 1;
1962 // this relies on sann being preserved after we
1963 // modify the sequence's annotation array for each duplication
1964 for (int a = 0; a < sann.length; a++)
1966 AlignmentAnnotation newann = new AlignmentAnnotation(
1968 sequences[i].addAlignmentAnnotation(newann);
1969 newann.padAnnotation(avwidth);
1970 alview[avnum].addAnnotation(newann); // annotation was
1971 // duplicated earlier
1972 // TODO JAL-1145 graphGroups are not updated for sequence
1973 // annotation added to several views. This may cause
1975 alview[avnum].setAnnotationIndex(newann, a);
1980 buildSortByAnnotationScoresMenu();
1982 viewport.firePropertyChange("alignment", null,
1983 alignment.getSequences());
1984 if (alignPanels != null)
1986 for (AlignmentPanel ap : ((Vector<AlignmentPanel>) alignPanels))
1988 ap.validateAnnotationDimensions(false);
1993 alignPanel.validateAnnotationDimensions(false);
1999 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2001 String newtitle = new String("Copied sequences");
2003 if (Desktop.jalviewClipboard != null
2004 && Desktop.jalviewClipboard[2] != null)
2006 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2007 for (int i = 0; i < hc.size(); i++)
2009 int[] region = (int[]) hc.elementAt(i);
2010 af.viewport.hideColumns(region[0], region[1]);
2014 // >>>This is a fix for the moment, until a better solution is
2016 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2018 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2020 // TODO: maintain provenance of an alignment, rather than just make the
2021 // title a concatenation of operations.
2024 if (title.startsWith("Copied sequences"))
2030 newtitle = newtitle.concat("- from " + title);
2035 newtitle = new String("Pasted sequences");
2038 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2043 } catch (Exception ex)
2045 ex.printStackTrace();
2046 System.out.println("Exception whilst pasting: " + ex);
2047 // could be anything being pasted in here
2059 protected void cut_actionPerformed(ActionEvent e)
2061 copy_actionPerformed(null);
2062 delete_actionPerformed(null);
2072 protected void delete_actionPerformed(ActionEvent evt)
2075 SequenceGroup sg = viewport.getSelectionGroup();
2081 Vector seqs = new Vector();
2083 for (int i = 0; i < sg.getSize(); i++)
2085 seq = sg.getSequenceAt(i);
2086 seqs.addElement(seq);
2089 // If the cut affects all sequences, remove highlighted columns
2090 if (sg.getSize() == viewport.getAlignment().getHeight())
2092 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2093 sg.getEndRes() + 1);
2096 SequenceI[] cut = new SequenceI[seqs.size()];
2097 for (int i = 0; i < seqs.size(); i++)
2099 cut[i] = (SequenceI) seqs.elementAt(i);
2103 * //ADD HISTORY ITEM
2105 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2106 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2107 viewport.getAlignment()));
2109 viewport.setSelectionGroup(null);
2110 viewport.sendSelection();
2111 viewport.getAlignment().deleteGroup(sg);
2113 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2115 if (viewport.getAlignment().getHeight() < 1)
2119 this.setClosed(true);
2120 } catch (Exception ex)
2133 protected void deleteGroups_actionPerformed(ActionEvent e)
2135 viewport.getAlignment().deleteAllGroups();
2136 viewport.sequenceColours = null;
2137 viewport.setSelectionGroup(null);
2138 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2139 alignPanel.updateAnnotation();
2140 alignPanel.paintAlignment(true);
2150 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2152 SequenceGroup sg = new SequenceGroup();
2154 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2156 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2159 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2160 viewport.setSelectionGroup(sg);
2161 viewport.sendSelection();
2162 alignPanel.paintAlignment(true);
2163 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2173 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2175 if (viewport.cursorMode)
2177 alignPanel.seqPanel.keyboardNo1 = null;
2178 alignPanel.seqPanel.keyboardNo2 = null;
2180 viewport.setSelectionGroup(null);
2181 viewport.getColumnSelection().clear();
2182 viewport.setSelectionGroup(null);
2183 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2184 alignPanel.idPanel.idCanvas.searchResults = null;
2185 alignPanel.paintAlignment(true);
2186 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2187 viewport.sendSelection();
2197 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2199 SequenceGroup sg = viewport.getSelectionGroup();
2203 selectAllSequenceMenuItem_actionPerformed(null);
2208 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2210 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2213 alignPanel.paintAlignment(true);
2214 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2215 viewport.sendSelection();
2219 public void invertColSel_actionPerformed(ActionEvent e)
2221 viewport.invertColumnSelection();
2222 alignPanel.paintAlignment(true);
2223 viewport.sendSelection();
2233 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2235 trimAlignment(true);
2245 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2247 trimAlignment(false);
2250 void trimAlignment(boolean trimLeft)
2252 ColumnSelection colSel = viewport.getColumnSelection();
2255 if (colSel.size() > 0)
2259 column = colSel.getMin();
2263 column = colSel.getMax();
2267 if (viewport.getSelectionGroup() != null)
2269 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2270 viewport.getHiddenRepSequences());
2274 seqs = viewport.getAlignment().getSequencesArray();
2277 TrimRegionCommand trimRegion;
2280 trimRegion = new TrimRegionCommand("Remove Left",
2281 TrimRegionCommand.TRIM_LEFT, seqs, column,
2282 viewport.getAlignment(), viewport.getColumnSelection(),
2283 viewport.getSelectionGroup());
2284 viewport.setStartRes(0);
2288 trimRegion = new TrimRegionCommand("Remove Right",
2289 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2290 viewport.getAlignment(), viewport.getColumnSelection(),
2291 viewport.getSelectionGroup());
2294 statusBar.setText(MessageManager.formatMessage("label.removed_columns", new String[]{Integer.valueOf(trimRegion.getSize()).toString()}));
2296 addHistoryItem(trimRegion);
2298 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2300 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2301 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2303 viewport.getAlignment().deleteGroup(sg);
2307 viewport.firePropertyChange("alignment", null, viewport
2308 .getAlignment().getSequences());
2319 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2321 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2324 if (viewport.getSelectionGroup() != null)
2326 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2327 viewport.getHiddenRepSequences());
2328 start = viewport.getSelectionGroup().getStartRes();
2329 end = viewport.getSelectionGroup().getEndRes();
2333 seqs = viewport.getAlignment().getSequencesArray();
2336 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2337 "Remove Gapped Columns", seqs, start, end,
2338 viewport.getAlignment());
2340 addHistoryItem(removeGapCols);
2342 statusBar.setText(MessageManager.formatMessage("label.removed_empty_columns", new String[]{Integer.valueOf(removeGapCols.getSize()).toString()}));
2344 // This is to maintain viewport position on first residue
2345 // of first sequence
2346 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2347 int startRes = seq.findPosition(viewport.startRes);
2348 // ShiftList shifts;
2349 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2350 // edit.alColumnChanges=shifts.getInverse();
2351 // if (viewport.hasHiddenColumns)
2352 // viewport.getColumnSelection().compensateForEdits(shifts);
2353 viewport.setStartRes(seq.findIndex(startRes) - 1);
2354 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2366 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2368 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2371 if (viewport.getSelectionGroup() != null)
2373 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2374 viewport.getHiddenRepSequences());
2375 start = viewport.getSelectionGroup().getStartRes();
2376 end = viewport.getSelectionGroup().getEndRes();
2380 seqs = viewport.getAlignment().getSequencesArray();
2383 // This is to maintain viewport position on first residue
2384 // of first sequence
2385 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2386 int startRes = seq.findPosition(viewport.startRes);
2388 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2389 viewport.getAlignment()));
2391 viewport.setStartRes(seq.findIndex(startRes) - 1);
2393 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2405 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2407 viewport.setPadGaps(padGapsMenuitem.isSelected());
2408 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2414 // if (justifySeqs>0)
2416 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2429 public void findMenuItem_actionPerformed(ActionEvent e)
2435 public void newView_actionPerformed(ActionEvent e)
2442 * @param copyAnnotation
2443 * if true then duplicate all annnotation, groups and settings
2444 * @return new alignment panel, already displayed.
2446 public AlignmentPanel newView(boolean copyAnnotation)
2448 return newView(null, copyAnnotation);
2454 * title of newly created view
2455 * @return new alignment panel, already displayed.
2457 public AlignmentPanel newView(String viewTitle)
2459 return newView(viewTitle, true);
2465 * title of newly created view
2466 * @param copyAnnotation
2467 * if true then duplicate all annnotation, groups and settings
2468 * @return new alignment panel, already displayed.
2470 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2472 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2474 if (!copyAnnotation)
2476 // just remove all the current annotation except for the automatic stuff
2477 newap.av.getAlignment().deleteAllGroups();
2478 for (AlignmentAnnotation alan : newap.av.getAlignment()
2479 .getAlignmentAnnotation())
2481 if (!alan.autoCalculated)
2483 newap.av.getAlignment().deleteAnnotation(alan);
2489 newap.av.gatherViewsHere = false;
2491 if (viewport.viewName == null)
2493 viewport.viewName = "Original";
2496 newap.av.historyList = viewport.historyList;
2497 newap.av.redoList = viewport.redoList;
2499 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2500 // make sure the new view has a unique name - this is essential for Jalview
2502 boolean addFirstIndex = false;
2503 if (viewTitle == null || viewTitle.trim().length() == 0)
2506 addFirstIndex = true;
2510 index = 1;// we count from 1 if given a specific name
2512 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2513 Vector comps = (Vector) PaintRefresher.components.get(viewport
2514 .getSequenceSetId());
2515 Vector existingNames = new Vector();
2516 for (int i = 0; i < comps.size(); i++)
2518 if (comps.elementAt(i) instanceof AlignmentPanel)
2520 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2521 if (!existingNames.contains(ap.av.viewName))
2523 existingNames.addElement(ap.av.viewName);
2528 while (existingNames.contains(newViewName))
2530 newViewName = viewTitle + " " + (++index);
2533 newap.av.viewName = newViewName;
2535 addAlignmentPanel(newap, true);
2537 if (alignPanels.size() == 2)
2539 viewport.gatherViewsHere = true;
2541 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2546 public void expandViews_actionPerformed(ActionEvent e)
2548 Desktop.instance.explodeViews(this);
2552 public void gatherViews_actionPerformed(ActionEvent e)
2554 Desktop.instance.gatherViews(this);
2564 public void font_actionPerformed(ActionEvent e)
2566 new FontChooser(alignPanel);
2576 protected void seqLimit_actionPerformed(ActionEvent e)
2578 viewport.setShowJVSuffix(seqLimits.isSelected());
2580 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2581 .calculateIdWidth());
2582 alignPanel.paintAlignment(true);
2586 public void idRightAlign_actionPerformed(ActionEvent e)
2588 viewport.rightAlignIds = idRightAlign.isSelected();
2589 alignPanel.paintAlignment(true);
2593 public void centreColumnLabels_actionPerformed(ActionEvent e)
2595 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2596 alignPanel.paintAlignment(true);
2602 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2605 protected void followHighlight_actionPerformed()
2607 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2609 alignPanel.scrollToPosition(
2610 alignPanel.seqPanel.seqCanvas.searchResults, false);
2621 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2623 viewport.setColourText(colourTextMenuItem.isSelected());
2624 alignPanel.paintAlignment(true);
2634 public void wrapMenuItem_actionPerformed(ActionEvent e)
2636 scaleAbove.setVisible(wrapMenuItem.isSelected());
2637 scaleLeft.setVisible(wrapMenuItem.isSelected());
2638 scaleRight.setVisible(wrapMenuItem.isSelected());
2639 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2640 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2644 public void showAllSeqs_actionPerformed(ActionEvent e)
2646 viewport.showAllHiddenSeqs();
2650 public void showAllColumns_actionPerformed(ActionEvent e)
2652 viewport.showAllHiddenColumns();
2657 public void hideSelSequences_actionPerformed(ActionEvent e)
2659 viewport.hideAllSelectedSeqs();
2660 alignPanel.paintAlignment(true);
2664 * called by key handler and the hide all/show all menu items
2669 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2672 boolean hide = false;
2673 SequenceGroup sg = viewport.getSelectionGroup();
2674 if (!toggleSeqs && !toggleCols)
2676 // Hide everything by the current selection - this is a hack - we do the
2677 // invert and then hide
2678 // first check that there will be visible columns after the invert.
2679 if ((viewport.getColumnSelection() != null
2680 && viewport.getColumnSelection().getSelected() != null && viewport
2681 .getColumnSelection().getSelected().size() > 0)
2682 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2685 // now invert the sequence set, if required - empty selection implies
2686 // that no hiding is required.
2689 invertSequenceMenuItem_actionPerformed(null);
2690 sg = viewport.getSelectionGroup();
2694 viewport.expandColSelection(sg, true);
2695 // finally invert the column selection and get the new sequence
2697 invertColSel_actionPerformed(null);
2704 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2706 hideSelSequences_actionPerformed(null);
2709 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2712 showAllSeqs_actionPerformed(null);
2718 if (viewport.getColumnSelection().getSelected().size() > 0)
2720 hideSelColumns_actionPerformed(null);
2723 viewport.setSelectionGroup(sg);
2728 showAllColumns_actionPerformed(null);
2737 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2738 * event.ActionEvent)
2741 public void hideAllButSelection_actionPerformed(ActionEvent e)
2743 toggleHiddenRegions(false, false);
2750 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2754 public void hideAllSelection_actionPerformed(ActionEvent e)
2756 SequenceGroup sg = viewport.getSelectionGroup();
2757 viewport.expandColSelection(sg, false);
2758 viewport.hideAllSelectedSeqs();
2759 viewport.hideSelectedColumns();
2760 alignPanel.paintAlignment(true);
2767 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2771 public void showAllhidden_actionPerformed(ActionEvent e)
2773 viewport.showAllHiddenColumns();
2774 viewport.showAllHiddenSeqs();
2775 alignPanel.paintAlignment(true);
2779 public void hideSelColumns_actionPerformed(ActionEvent e)
2781 viewport.hideSelectedColumns();
2782 alignPanel.paintAlignment(true);
2786 public void hiddenMarkers_actionPerformed(ActionEvent e)
2788 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2799 protected void scaleAbove_actionPerformed(ActionEvent e)
2801 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2802 alignPanel.paintAlignment(true);
2812 protected void scaleLeft_actionPerformed(ActionEvent e)
2814 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2815 alignPanel.paintAlignment(true);
2825 protected void scaleRight_actionPerformed(ActionEvent e)
2827 viewport.setScaleRightWrapped(scaleRight.isSelected());
2828 alignPanel.paintAlignment(true);
2838 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2840 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2841 alignPanel.paintAlignment(true);
2851 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2853 viewport.setShowText(viewTextMenuItem.isSelected());
2854 alignPanel.paintAlignment(true);
2864 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2866 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2867 alignPanel.paintAlignment(true);
2870 public FeatureSettings featureSettings;
2873 public void featureSettings_actionPerformed(ActionEvent e)
2875 if (featureSettings != null)
2877 featureSettings.close();
2878 featureSettings = null;
2880 if (!showSeqFeatures.isSelected())
2882 // make sure features are actually displayed
2883 showSeqFeatures.setSelected(true);
2884 showSeqFeatures_actionPerformed(null);
2886 featureSettings = new FeatureSettings(this);
2890 * Set or clear 'Show Sequence Features'
2896 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2898 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2899 alignPanel.paintAlignment(true);
2900 if (alignPanel.getOverviewPanel() != null)
2902 alignPanel.getOverviewPanel().updateOverviewImage();
2907 * Set or clear 'Show Sequence Features'
2913 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2915 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2917 if (viewport.getShowSequenceFeaturesHeight())
2919 // ensure we're actually displaying features
2920 viewport.setShowSequenceFeatures(true);
2921 showSeqFeatures.setSelected(true);
2923 alignPanel.paintAlignment(true);
2924 if (alignPanel.getOverviewPanel() != null)
2926 alignPanel.getOverviewPanel().updateOverviewImage();
2937 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2939 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2940 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2944 public void alignmentProperties()
2946 JEditorPane editPane = new JEditorPane("text/html", "");
2947 editPane.setEditable(false);
2948 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2950 editPane.setText(MessageManager.formatMessage("label.html_content", new String[]{contents.toString()}));
2951 JInternalFrame frame = new JInternalFrame();
2952 frame.getContentPane().add(new JScrollPane(editPane));
2954 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2955 + getTitle(), 500, 400);
2965 public void overviewMenuItem_actionPerformed(ActionEvent e)
2967 if (alignPanel.overviewPanel != null)
2972 JInternalFrame frame = new JInternalFrame();
2973 OverviewPanel overview = new OverviewPanel(alignPanel);
2974 frame.setContentPane(overview);
2975 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2976 frame.getWidth(), frame.getHeight());
2978 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2979 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2982 public void internalFrameClosed(
2983 javax.swing.event.InternalFrameEvent evt)
2985 alignPanel.setOverviewPanel(null);
2989 alignPanel.setOverviewPanel(overview);
2993 public void textColour_actionPerformed(ActionEvent e)
2995 new TextColourChooser().chooseColour(alignPanel, null);
3005 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3017 public void clustalColour_actionPerformed(ActionEvent e)
3019 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3020 viewport.getHiddenRepSequences()));
3030 public void zappoColour_actionPerformed(ActionEvent e)
3032 changeColour(new ZappoColourScheme());
3042 public void taylorColour_actionPerformed(ActionEvent e)
3044 changeColour(new TaylorColourScheme());
3054 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3056 changeColour(new HydrophobicColourScheme());
3066 public void helixColour_actionPerformed(ActionEvent e)
3068 changeColour(new HelixColourScheme());
3078 public void strandColour_actionPerformed(ActionEvent e)
3080 changeColour(new StrandColourScheme());
3090 public void turnColour_actionPerformed(ActionEvent e)
3092 changeColour(new TurnColourScheme());
3102 public void buriedColour_actionPerformed(ActionEvent e)
3104 changeColour(new BuriedColourScheme());
3114 public void nucleotideColour_actionPerformed(ActionEvent e)
3116 changeColour(new NucleotideColourScheme());
3120 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3122 changeColour(new PurinePyrimidineColourScheme());
3126 * public void covariationColour_actionPerformed(ActionEvent e) {
3128 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3132 public void annotationColour_actionPerformed(ActionEvent e)
3134 new AnnotationColourChooser(viewport, alignPanel);
3138 public void rnahelicesColour_actionPerformed(ActionEvent e)
3140 new RNAHelicesColourChooser(viewport, alignPanel);
3150 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3152 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3161 public void changeColour(ColourSchemeI cs)
3163 // TODO: compare with applet and pull up to model method
3168 if (viewport.getAbovePIDThreshold())
3170 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3173 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3175 viewport.setGlobalColourScheme(cs);
3179 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3182 if (viewport.getConservationSelected())
3185 Alignment al = (Alignment) viewport.getAlignment();
3186 Conservation c = new Conservation("All",
3187 ResidueProperties.propHash, 3, al.getSequences(), 0,
3191 c.verdict(false, viewport.getConsPercGaps());
3193 cs.setConservation(c);
3195 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3200 cs.setConservation(null);
3203 cs.setConsensus(viewport.getSequenceConsensusHash());
3206 viewport.setGlobalColourScheme(cs);
3208 if (viewport.getColourAppliesToAllGroups())
3211 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3219 if (cs instanceof ClustalxColourScheme)
3221 sg.cs = new ClustalxColourScheme(sg,
3222 viewport.getHiddenRepSequences());
3224 else if (cs instanceof UserColourScheme)
3226 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3232 sg.cs = cs.getClass().newInstance();
3233 } catch (Exception ex)
3238 if (viewport.getAbovePIDThreshold()
3239 || cs instanceof PIDColourScheme
3240 || cs instanceof Blosum62ColourScheme)
3242 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3244 sg.cs.setConsensus(AAFrequency.calculate(
3245 sg.getSequences(viewport.getHiddenRepSequences()),
3246 sg.getStartRes(), sg.getEndRes() + 1));
3250 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3253 if (viewport.getConservationSelected())
3255 Conservation c = new Conservation("Group",
3256 ResidueProperties.propHash, 3, sg.getSequences(viewport
3257 .getHiddenRepSequences()), sg.getStartRes(),
3258 sg.getEndRes() + 1);
3260 c.verdict(false, viewport.getConsPercGaps());
3261 sg.cs.setConservation(c);
3265 sg.cs.setConservation(null);
3270 if (alignPanel.getOverviewPanel() != null)
3272 alignPanel.getOverviewPanel().updateOverviewImage();
3275 alignPanel.paintAlignment(true);
3285 protected void modifyPID_actionPerformed(ActionEvent e)
3287 if (viewport.getAbovePIDThreshold()
3288 && viewport.getGlobalColourScheme() != null)
3290 SliderPanel.setPIDSliderSource(alignPanel,
3291 viewport.getGlobalColourScheme(), "Background");
3292 SliderPanel.showPIDSlider();
3303 protected void modifyConservation_actionPerformed(ActionEvent e)
3305 if (viewport.getConservationSelected()
3306 && viewport.getGlobalColourScheme() != null)
3308 SliderPanel.setConservationSlider(alignPanel,
3309 viewport.getGlobalColourScheme(), "Background");
3310 SliderPanel.showConservationSlider();
3321 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3323 viewport.setConservationSelected(conservationMenuItem.isSelected());
3325 viewport.setAbovePIDThreshold(false);
3326 abovePIDThreshold.setSelected(false);
3328 changeColour(viewport.getGlobalColourScheme());
3330 modifyConservation_actionPerformed(null);
3340 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3342 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3344 conservationMenuItem.setSelected(false);
3345 viewport.setConservationSelected(false);
3347 changeColour(viewport.getGlobalColourScheme());
3349 modifyPID_actionPerformed(null);
3359 public void userDefinedColour_actionPerformed(ActionEvent e)
3361 if (e.getActionCommand().equals("User Defined..."))
3363 new UserDefinedColours(alignPanel, null);
3367 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3368 .getUserColourSchemes().get(e.getActionCommand());
3374 public void updateUserColourMenu()
3377 Component[] menuItems = colourMenu.getMenuComponents();
3378 int i, iSize = menuItems.length;
3379 for (i = 0; i < iSize; i++)
3381 if (menuItems[i].getName() != null
3382 && menuItems[i].getName().equals("USER_DEFINED"))
3384 colourMenu.remove(menuItems[i]);
3388 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3390 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3391 .getUserColourSchemes().keys();
3393 while (userColours.hasMoreElements())
3395 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3396 userColours.nextElement().toString());
3397 radioItem.setName("USER_DEFINED");
3398 radioItem.addMouseListener(new MouseAdapter()
3401 public void mousePressed(MouseEvent evt)
3403 if (evt.isControlDown()
3404 || SwingUtilities.isRightMouseButton(evt))
3406 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3408 int option = JOptionPane.showInternalConfirmDialog(
3409 jalview.gui.Desktop.desktop,
3410 MessageManager.getString("label.remove_from_default_list"),
3411 MessageManager.getString("label.remove_user_defined_colour"),
3412 JOptionPane.YES_NO_OPTION);
3413 if (option == JOptionPane.YES_OPTION)
3415 jalview.gui.UserDefinedColours
3416 .removeColourFromDefaults(radioItem.getText());
3417 colourMenu.remove(radioItem);
3421 radioItem.addActionListener(new ActionListener()
3424 public void actionPerformed(ActionEvent evt)
3426 userDefinedColour_actionPerformed(evt);
3433 radioItem.addActionListener(new ActionListener()
3436 public void actionPerformed(ActionEvent evt)
3438 userDefinedColour_actionPerformed(evt);
3442 colourMenu.insert(radioItem, 15);
3443 colours.add(radioItem);
3455 public void PIDColour_actionPerformed(ActionEvent e)
3457 changeColour(new PIDColourScheme());
3467 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3469 changeColour(new Blosum62ColourScheme());
3479 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3481 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3482 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3483 .getAlignment().getSequenceAt(0), null);
3484 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3485 viewport.getAlignment()));
3486 alignPanel.paintAlignment(true);
3496 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3498 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3499 AlignmentSorter.sortByID(viewport.getAlignment());
3500 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3501 viewport.getAlignment()));
3502 alignPanel.paintAlignment(true);
3512 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3514 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3515 AlignmentSorter.sortByLength(viewport.getAlignment());
3516 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3517 viewport.getAlignment()));
3518 alignPanel.paintAlignment(true);
3528 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3530 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3531 AlignmentSorter.sortByGroup(viewport.getAlignment());
3532 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3533 viewport.getAlignment()));
3535 alignPanel.paintAlignment(true);
3545 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3547 new RedundancyPanel(alignPanel, this);
3557 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3559 if ((viewport.getSelectionGroup() == null)
3560 || (viewport.getSelectionGroup().getSize() < 2))
3562 JOptionPane.showInternalMessageDialog(this,
3563 MessageManager.getString("label.you_must_select_least_two_sequences"), MessageManager.getString("label.invalid_selection"),
3564 JOptionPane.WARNING_MESSAGE);
3568 JInternalFrame frame = new JInternalFrame();
3569 frame.setContentPane(new PairwiseAlignPanel(viewport));
3570 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3581 public void PCAMenuItem_actionPerformed(ActionEvent e)
3583 if (((viewport.getSelectionGroup() != null)
3584 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3585 .getSelectionGroup().getSize() > 0))
3586 || (viewport.getAlignment().getHeight() < 4))
3588 JOptionPane.showInternalMessageDialog(this,
3589 MessageManager.getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3590 MessageManager.getString("label.sequence_selection_insufficient"),
3591 JOptionPane.WARNING_MESSAGE);
3596 new PCAPanel(alignPanel);
3600 public void autoCalculate_actionPerformed(ActionEvent e)
3602 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3603 if (viewport.autoCalculateConsensus)
3605 viewport.firePropertyChange("alignment", null, viewport
3606 .getAlignment().getSequences());
3611 public void sortByTreeOption_actionPerformed(ActionEvent e)
3613 viewport.sortByTree = sortByTree.isSelected();
3617 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3619 viewport.followSelection = listenToViewSelections.isSelected();
3629 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3631 NewTreePanel("AV", "PID", "Average distance tree using PID");
3641 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3643 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3653 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3655 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3665 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3667 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3680 void NewTreePanel(String type, String pwType, String title)
3684 if (viewport.getSelectionGroup() != null
3685 && viewport.getSelectionGroup().getSize() > 0)
3687 if (viewport.getSelectionGroup().getSize() < 3)
3692 MessageManager.getString("label.you_need_more_two_sequences_selected_build_tree"),
3693 MessageManager.getString("label.not_enough_sequences"), JOptionPane.WARNING_MESSAGE);
3697 SequenceGroup sg = viewport.getSelectionGroup();
3699 /* Decide if the selection is a column region */
3700 for (SequenceI _s : sg.getSequences())
3702 if (_s.getLength() < sg.getEndRes())
3707 MessageManager.getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3708 MessageManager.getString("label.sequences_selection_not_aligned"),
3709 JOptionPane.WARNING_MESSAGE);
3715 title = title + " on region";
3716 tp = new TreePanel(alignPanel, type, pwType);
3720 // are the visible sequences aligned?
3721 if (!viewport.getAlignment().isAligned(false))
3726 MessageManager.getString("label.sequences_must_be_aligned_before_creating_tree"),
3727 MessageManager.getString("label.sequences_not_aligned"),
3728 JOptionPane.WARNING_MESSAGE);
3733 if (viewport.getAlignment().getHeight() < 2)
3738 tp = new TreePanel(alignPanel, type, pwType);
3743 if (viewport.viewName != null)
3745 title += viewport.viewName + " of ";
3748 title += this.title;
3750 Desktop.addInternalFrame(tp, title, 600, 500);
3761 public void addSortByOrderMenuItem(String title,
3762 final AlignmentOrder order)
3764 final JMenuItem item = new JMenuItem("by " + title);
3766 item.addActionListener(new java.awt.event.ActionListener()
3769 public void actionPerformed(ActionEvent e)
3771 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3773 // TODO: JBPNote - have to map order entries to curent SequenceI
3775 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3777 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3780 alignPanel.paintAlignment(true);
3786 * Add a new sort by annotation score menu item
3789 * the menu to add the option to
3791 * the label used to retrieve scores for each sequence on the
3794 public void addSortByAnnotScoreMenuItem(JMenu sort,
3795 final String scoreLabel)
3797 final JMenuItem item = new JMenuItem(scoreLabel);
3799 item.addActionListener(new java.awt.event.ActionListener()
3802 public void actionPerformed(ActionEvent e)
3804 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3805 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3806 viewport.getAlignment());// ,viewport.getSelectionGroup());
3807 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3808 viewport.getAlignment()));
3809 alignPanel.paintAlignment(true);
3815 * last hash for alignment's annotation array - used to minimise cost of
3818 protected int _annotationScoreVectorHash;
3821 * search the alignment and rebuild the sort by annotation score submenu the
3822 * last alignment annotation vector hash is stored to minimize cost of
3823 * rebuilding in subsequence calls.
3827 public void buildSortByAnnotationScoresMenu()
3829 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3834 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3836 sortByAnnotScore.removeAll();
3837 // almost certainly a quicker way to do this - but we keep it simple
3838 Hashtable scoreSorts = new Hashtable();
3839 AlignmentAnnotation aann[];
3840 for (SequenceI sqa : viewport.getAlignment().getSequences())
3842 aann = sqa.getAnnotation();
3843 for (int i = 0; aann != null && i < aann.length; i++)
3845 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3847 scoreSorts.put(aann[i].label, aann[i].label);
3851 Enumeration labels = scoreSorts.keys();
3852 while (labels.hasMoreElements())
3854 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3855 (String) labels.nextElement());
3857 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3860 _annotationScoreVectorHash = viewport.getAlignment()
3861 .getAlignmentAnnotation().hashCode();
3866 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3867 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3868 * call. Listeners are added to remove the menu item when the treePanel is
3869 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3873 * Displayed tree window.
3875 * SortBy menu item title.
3878 public void buildTreeMenu()
3880 sortByTreeMenu.removeAll();
3882 Vector comps = (Vector) PaintRefresher.components.get(viewport
3883 .getSequenceSetId());
3884 Vector treePanels = new Vector();
3885 int i, iSize = comps.size();
3886 for (i = 0; i < iSize; i++)
3888 if (comps.elementAt(i) instanceof TreePanel)
3890 treePanels.add(comps.elementAt(i));
3894 iSize = treePanels.size();
3898 sortByTreeMenu.setVisible(false);
3902 sortByTreeMenu.setVisible(true);
3904 for (i = 0; i < treePanels.size(); i++)
3906 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3907 final JMenuItem item = new JMenuItem(tp.getTitle());
3908 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3909 item.addActionListener(new java.awt.event.ActionListener()
3912 public void actionPerformed(ActionEvent e)
3914 tp.sortByTree_actionPerformed(null);
3915 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3920 sortByTreeMenu.add(item);
3924 public boolean sortBy(AlignmentOrder alorder, String undoname)
3926 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3927 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3928 if (undoname != null)
3930 addHistoryItem(new OrderCommand(undoname, oldOrder,
3931 viewport.getAlignment()));
3933 alignPanel.paintAlignment(true);
3938 * Work out whether the whole set of sequences or just the selected set will
3939 * be submitted for multiple alignment.
3942 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3944 // Now, check we have enough sequences
3945 AlignmentView msa = null;
3947 if ((viewport.getSelectionGroup() != null)
3948 && (viewport.getSelectionGroup().getSize() > 1))
3950 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3951 // some common interface!
3953 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3954 * SequenceI[sz = seqs.getSize(false)];
3956 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3957 * seqs.getSequenceAt(i); }
3959 msa = viewport.getAlignmentView(true);
3964 * Vector seqs = viewport.getAlignment().getSequences();
3966 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3968 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3969 * seqs.elementAt(i); } }
3971 msa = viewport.getAlignmentView(false);
3977 * Decides what is submitted to a secondary structure prediction service: the
3978 * first sequence in the alignment, or in the current selection, or, if the
3979 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3980 * region or the whole alignment. (where the first sequence in the set is the
3981 * one that the prediction will be for).
3983 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3985 AlignmentView seqs = null;
3987 if ((viewport.getSelectionGroup() != null)
3988 && (viewport.getSelectionGroup().getSize() > 0))
3990 seqs = viewport.getAlignmentView(true);
3994 seqs = viewport.getAlignmentView(false);
3996 // limit sequences - JBPNote in future - could spawn multiple prediction
3998 // TODO: viewport.getAlignment().isAligned is a global state - the local
3999 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4000 if (!viewport.getAlignment().isAligned(false))
4002 seqs.setSequences(new SeqCigar[]
4003 { seqs.getSequences()[0] });
4004 // TODO: if seqs.getSequences().length>1 then should really have warned
4018 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4020 // Pick the tree file
4021 JalviewFileChooser chooser = new JalviewFileChooser(
4022 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4023 chooser.setFileView(new JalviewFileView());
4024 chooser.setDialogTitle("Select a newick-like tree file");
4025 chooser.setToolTipText("Load a tree file");
4027 int value = chooser.showOpenDialog(null);
4029 if (value == JalviewFileChooser.APPROVE_OPTION)
4031 String choice = chooser.getSelectedFile().getPath();
4032 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4033 jalview.io.NewickFile fin = null;
4036 fin = new jalview.io.NewickFile(choice, "File");
4037 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4038 } catch (Exception ex)
4040 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4041 MessageManager.getString("label.problem_reading_tree_file"), JOptionPane.WARNING_MESSAGE);
4042 ex.printStackTrace();
4044 if (fin != null && fin.hasWarningMessage())
4046 JOptionPane.showMessageDialog(Desktop.desktop,
4047 fin.getWarningMessage(), MessageManager.getString("label.possible_problem_with_tree_file"),
4048 JOptionPane.WARNING_MESSAGE);
4054 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4056 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4059 public TreePanel ShowNewickTree(NewickFile nf, String title)
4061 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4064 public TreePanel ShowNewickTree(NewickFile nf, String title,
4065 AlignmentView input)
4067 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4070 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4071 int h, int x, int y)
4073 return ShowNewickTree(nf, title, null, w, h, x, y);
4077 * Add a treeviewer for the tree extracted from a newick file object to the
4078 * current alignment view
4085 * Associated alignment input data (or null)
4094 * @return TreePanel handle
4096 public TreePanel ShowNewickTree(NewickFile nf, String title,
4097 AlignmentView input, int w, int h, int x, int y)
4099 TreePanel tp = null;
4105 if (nf.getTree() != null)
4107 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4113 tp.setLocation(x, y);
4116 Desktop.addInternalFrame(tp, title, w, h);
4118 } catch (Exception ex)
4120 ex.printStackTrace();
4126 private boolean buildingMenu = false;
4129 * Generates menu items and listener event actions for web service clients
4132 public void BuildWebServiceMenu()
4134 while (buildingMenu)
4138 System.err.println("Waiting for building menu to finish.");
4140 } catch (Exception e)
4145 final AlignFrame me = this;
4146 buildingMenu = true;
4147 new Thread(new Runnable()
4154 System.err.println("Building ws menu again "
4155 + Thread.currentThread());
4156 // TODO: add support for context dependent disabling of services based
4158 // alignment and current selection
4159 // TODO: add additional serviceHandle parameter to specify abstract
4161 // class independently of AbstractName
4162 // TODO: add in rediscovery GUI function to restart discoverer
4163 // TODO: group services by location as well as function and/or
4165 // object broker mechanism.
4166 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4167 final IProgressIndicator af = me;
4168 final JMenu msawsmenu = new JMenu("Alignment");
4169 final JMenu secstrmenu = new JMenu(
4170 "Secondary Structure Prediction");
4171 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4172 final JMenu analymenu = new JMenu("Analysis");
4173 final JMenu dismenu = new JMenu("Protein Disorder");
4174 // JAL-940 - only show secondary structure prediction services from
4175 // the legacy server
4176 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4178 Discoverer.services != null && (Discoverer.services.size() > 0))
4180 // TODO: refactor to allow list of AbstractName/Handler bindings to
4182 // stored or retrieved from elsewhere
4183 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4184 Vector secstrpr = (Vector) Discoverer.services
4186 Vector seqsrch = null; // (Vector)
4187 // Discoverer.services.get("SeqSearch");
4188 // TODO: move GUI generation code onto service implementation - so a
4189 // client instance attaches itself to the GUI with method call like
4190 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4194 // Add any Multiple Sequence Alignment Services
4195 for (int i = 0, j = msaws.size(); i < j; i++)
4197 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4199 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4200 .getServiceClient(sh);
4201 impl.attachWSMenuEntry(msawsmenu, me);
4205 if (secstrpr != null)
4207 // Add any secondary structure prediction services
4208 for (int i = 0, j = secstrpr.size(); i < j; i++)
4210 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4212 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4213 .getServiceClient(sh);
4214 impl.attachWSMenuEntry(secstrmenu, me);
4217 if (seqsrch != null)
4219 // Add any sequence search services
4220 for (int i = 0, j = seqsrch.size(); i < j; i++)
4222 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4224 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4225 .getServiceClient(sh);
4226 impl.attachWSMenuEntry(seqsrchmenu, me);
4231 // Add all submenus in the order they should appear on the web
4233 wsmenu.add(msawsmenu);
4234 wsmenu.add(secstrmenu);
4235 wsmenu.add(dismenu);
4236 wsmenu.add(analymenu);
4237 // final ArrayList<JMenu> submens=new ArrayList<JMenu>();
4238 // submens.add(msawsmenu);
4239 // submens.add(secstrmenu);
4240 // submens.add(dismenu);
4241 // submens.add(analymenu);
4243 // No search services yet
4244 // wsmenu.add(seqsrchmenu);
4246 javax.swing.SwingUtilities.invokeLater(new Runnable()
4253 webService.removeAll();
4254 // first, add discovered services onto the webservices menu
4255 if (wsmenu.size() > 0)
4257 for (int i = 0, j = wsmenu.size(); i < j; i++)
4259 webService.add(wsmenu.get(i));
4264 webService.add(me.webServiceNoServices);
4266 // TODO: move into separate menu builder class.
4267 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4269 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4270 if (jws2servs != null)
4272 if (jws2servs.hasServices())
4274 jws2servs.attachWSMenuEntry(webService, me);
4276 if (jws2servs.isRunning())
4278 JMenuItem tm = new JMenuItem(
4279 "Still discovering JABA Services");
4280 tm.setEnabled(false);
4286 build_urlServiceMenu(me.webService);
4287 build_fetchdbmenu(webService);
4288 for (JMenu item : wsmenu)
4290 if (item.getItemCount() == 0)
4292 item.setEnabled(false);
4296 item.setEnabled(true);
4299 } catch (Exception e)
4302 .debug("Exception during web service menu building process.",
4308 } catch (Exception e)
4313 buildingMenu = false;
4320 * construct any groupURL type service menu entries.
4324 private void build_urlServiceMenu(JMenu webService)
4326 // TODO: remove this code when 2.7 is released
4327 // DEBUG - alignmentView
4329 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4330 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4332 * @Override public void actionPerformed(ActionEvent e) {
4333 * jalview.datamodel.AlignmentView
4334 * .testSelectionViews(af.viewport.getAlignment(),
4335 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4337 * }); webService.add(testAlView);
4339 // TODO: refactor to RestClient discoverer and merge menu entries for
4340 // rest-style services with other types of analysis/calculation service
4341 // SHmmr test client - still being implemented.
4342 // DEBUG - alignmentView
4344 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4347 client.attachWSMenuEntry(
4348 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4352 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4354 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4360 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4361 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4362 * getProperty("LAST_DIRECTORY"));
4364 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4365 * to Vamsas file"); chooser.setToolTipText("Export");
4367 * int value = chooser.showSaveDialog(this);
4369 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4370 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4371 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4372 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4375 * prototype of an automatically enabled/disabled analysis function
4378 protected void setShowProductsEnabled()
4380 SequenceI[] selection = viewport.getSequenceSelection();
4381 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4382 viewport.getAlignment().getDataset()))
4384 showProducts.setEnabled(true);
4389 showProducts.setEnabled(false);
4394 * search selection for sequence xRef products and build the show products
4399 * @return true if showProducts menu should be enabled.
4401 public boolean canShowProducts(SequenceI[] selection,
4402 boolean isRegionSelection, Alignment dataset)
4404 boolean showp = false;
4407 showProducts.removeAll();
4408 final boolean dna = viewport.getAlignment().isNucleotide();
4409 final Alignment ds = dataset;
4410 String[] ptypes = (selection == null || selection.length == 0) ? null
4411 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4413 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4414 // selection, dataset, true);
4415 final SequenceI[] sel = selection;
4416 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4419 final boolean isRegSel = isRegionSelection;
4420 final AlignFrame af = this;
4421 final String source = ptypes[t];
4422 JMenuItem xtype = new JMenuItem(ptypes[t]);
4423 xtype.addActionListener(new ActionListener()
4427 public void actionPerformed(ActionEvent e)
4429 // TODO: new thread for this call with vis-delay
4430 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4431 isRegSel, dna, source);
4435 showProducts.add(xtype);
4437 showProducts.setVisible(showp);
4438 showProducts.setEnabled(showp);
4439 } catch (Exception e)
4441 jalview.bin.Cache.log
4442 .warn("canTranslate threw an exception - please report to help@jalview.org",
4449 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4450 boolean isRegSel, boolean dna, String source)
4452 final boolean fisRegSel = isRegSel;
4453 final boolean fdna = dna;
4454 final String fsrc = source;
4455 final AlignFrame ths = this;
4456 final SequenceI[] fsel = sel;
4457 Runnable foo = new Runnable()
4463 final long sttime = System.currentTimeMillis();
4464 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4467 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4471 Alignment prods = CrossRef
4472 .findXrefSequences(fsel, fdna, fsrc, ds);
4475 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4476 for (int s = 0; s < sprods.length; s++)
4478 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4479 if (ds.getSequences() == null
4480 || !ds.getSequences().contains(
4481 sprods[s].getDatasetSequence()))
4482 ds.addSequence(sprods[s].getDatasetSequence());
4483 sprods[s].updatePDBIds();
4485 Alignment al = new Alignment(sprods);
4486 AlignedCodonFrame[] cf = prods.getCodonFrames();
4488 for (int s = 0; cf != null && s < cf.length; s++)
4490 al.addCodonFrame(cf[s]);
4493 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4495 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4496 + " for " + ((fisRegSel) ? "selected region of " : "")
4498 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4503 System.err.println("No Sequences generated for xRef type "
4506 } catch (Exception e)
4508 jalview.bin.Cache.log.error(
4509 "Exception when finding crossreferences", e);
4510 } catch (OutOfMemoryError e)
4512 new OOMWarning("whilst fetching crossreferences", e);
4515 jalview.bin.Cache.log.error("Error when finding crossreferences",
4518 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4523 Thread frunner = new Thread(foo);
4527 public boolean canShowTranslationProducts(SequenceI[] selection,
4528 AlignmentI alignment)
4533 return (jalview.analysis.Dna.canTranslate(selection,
4534 viewport.getViewAsVisibleContigs(true)));
4535 } catch (Exception e)
4537 jalview.bin.Cache.log
4538 .warn("canTranslate threw an exception - please report to help@jalview.org",
4545 public void showProducts_actionPerformed(ActionEvent e)
4547 // /////////////////////////////
4548 // Collect Data to be translated/transferred
4550 SequenceI[] selection = viewport.getSequenceSelection();
4551 AlignmentI al = null;
4554 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4555 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4556 viewport.getAlignment().getDataset());
4557 } catch (Exception ex)
4560 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4567 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4568 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4572 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4573 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4574 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4579 public void showTranslation_actionPerformed(ActionEvent e)
4581 // /////////////////////////////
4582 // Collect Data to be translated/transferred
4584 SequenceI[] selection = viewport.getSequenceSelection();
4585 String[] seqstring = viewport.getViewAsString(true);
4586 AlignmentI al = null;
4589 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4590 viewport.getViewAsVisibleContigs(true), viewport
4591 .getGapCharacter(), viewport.getAlignment()
4592 .getAlignmentAnnotation(), viewport.getAlignment()
4593 .getWidth(), viewport.getAlignment().getDataset());
4594 } catch (Exception ex)
4597 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4601 MessageManager.getString("label.error_when_translating_sequences_submit_bug_report"),
4602 MessageManager.getString("label.implementation_error") + MessageManager.getString("translation_failed"), JOptionPane.ERROR_MESSAGE);
4610 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4611 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4615 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4616 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4617 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4622 * Try to load a features file onto the alignment.
4625 * contents or path to retrieve file
4627 * access mode of file (see jalview.io.AlignFile)
4628 * @return true if features file was parsed corectly.
4630 public boolean parseFeaturesFile(String file, String type)
4632 boolean featuresFile = false;
4635 featuresFile = new FeaturesFile(file, type).parse(viewport
4636 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4637 .getFeatureRenderer().featureColours, false,
4638 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4639 } catch (Exception ex)
4641 ex.printStackTrace();
4646 viewport.showSequenceFeatures = true;
4647 showSeqFeatures.setSelected(true);
4648 if (alignPanel.seqPanel.seqCanvas.fr != null)
4650 // update the min/max ranges where necessary
4651 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4653 if (featureSettings != null)
4655 featureSettings.setTableData();
4657 alignPanel.paintAlignment(true);
4660 return featuresFile;
4664 public void dragEnter(DropTargetDragEvent evt)
4669 public void dragExit(DropTargetEvent evt)
4674 public void dragOver(DropTargetDragEvent evt)
4679 public void dropActionChanged(DropTargetDragEvent evt)
4684 public void drop(DropTargetDropEvent evt)
4686 Transferable t = evt.getTransferable();
4687 java.util.List files = null;
4691 DataFlavor uriListFlavor = new DataFlavor(
4692 "text/uri-list;class=java.lang.String");
4693 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4695 // Works on Windows and MacOSX
4696 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4697 files = (java.util.List) t
4698 .getTransferData(DataFlavor.javaFileListFlavor);
4700 else if (t.isDataFlavorSupported(uriListFlavor))
4702 // This is used by Unix drag system
4703 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4704 String data = (String) t.getTransferData(uriListFlavor);
4705 files = new java.util.ArrayList(1);
4706 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4707 data, "\r\n"); st.hasMoreTokens();)
4709 String s = st.nextToken();
4710 if (s.startsWith("#"))
4712 // the line is a comment (as per the RFC 2483)
4716 java.net.URI uri = new java.net.URI(s);
4717 // check to see if we can handle this kind of URI
4718 if (uri.getScheme().toLowerCase().startsWith("http"))
4720 files.add(uri.toString());
4724 // otherwise preserve old behaviour: catch all for file objects
4725 java.io.File file = new java.io.File(uri);
4726 files.add(file.toString());
4730 } catch (Exception e)
4732 e.printStackTrace();
4738 // check to see if any of these files have names matching sequences in
4740 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4741 .getAlignment().getSequencesArray());
4743 * Object[] { String,SequenceI}
4745 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4746 ArrayList<String> filesnotmatched = new ArrayList<String>();
4747 for (int i = 0; i < files.size(); i++)
4749 String file = files.get(i).toString();
4751 String protocol = FormatAdapter.checkProtocol(file);
4752 if (protocol == jalview.io.FormatAdapter.FILE)
4754 File fl = new File(file);
4755 pdbfn = fl.getName();
4757 else if (protocol == jalview.io.FormatAdapter.URL)
4759 URL url = new URL(file);
4760 pdbfn = url.getFile();
4762 if (pdbfn.length() > 0)
4764 // attempt to find a match in the alignment
4765 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4766 int l = 0, c = pdbfn.indexOf(".");
4767 while (mtch == null && c != -1)
4772 } while ((c = pdbfn.indexOf(".", l)) > l);
4775 pdbfn = pdbfn.substring(0, l);
4777 mtch = idm.findAllIdMatches(pdbfn);
4784 type = new IdentifyFile().Identify(file, protocol);
4785 } catch (Exception ex)
4791 if (type.equalsIgnoreCase("PDB"))
4793 filesmatched.add(new Object[]
4794 { file, protocol, mtch });
4799 // File wasn't named like one of the sequences or wasn't a PDB file.
4800 filesnotmatched.add(file);
4804 if (filesmatched.size() > 0)
4806 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4810 MessageManager.formatMessage("label.automatically_associate_pdb_files_with_sequences_same_name",
4811 new String[]{Integer.valueOf(filesmatched.size()).toString()}),
4812 MessageManager.getString("label.automatically_associate_pdb_files_by_name"),
4813 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4816 for (Object[] fm : filesmatched)
4818 // try and associate
4819 // TODO: may want to set a standard ID naming formalism for
4820 // associating PDB files which have no IDs.
4821 for (SequenceI toassoc : (SequenceI[]) fm[2])
4823 PDBEntry pe = new AssociatePdbFileWithSeq()
4824 .associatePdbWithSeq((String) fm[0],
4825 (String) fm[1], toassoc, false);
4828 System.err.println("Associated file : "
4829 + ((String) fm[0]) + " with "
4830 + toassoc.getDisplayId(true));
4834 alignPanel.paintAlignment(true);
4838 if (filesnotmatched.size() > 0)
4841 && (Cache.getDefault(
4842 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4845 MessageManager.formatMessage("label.ignore_unmatched_dropped_files_info", new String[]{Integer.valueOf(filesnotmatched.size()).toString()}),
4846 MessageManager.getString("label.ignore_unmatched_dropped_files"),
4847 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4851 for (String fn : filesnotmatched)
4853 loadJalviewDataFile(fn, null, null, null);
4857 } catch (Exception ex)
4859 ex.printStackTrace();
4865 * Attempt to load a "dropped" file or URL string: First by testing whether
4866 * it's and Annotation file, then a JNet file, and finally a features file. If
4867 * all are false then the user may have dropped an alignment file onto this
4871 * either a filename or a URL string.
4873 public void loadJalviewDataFile(String file, String protocol,
4874 String format, SequenceI assocSeq)
4878 if (protocol == null)
4880 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4882 // if the file isn't identified, or not positively identified as some
4883 // other filetype (PFAM is default unidentified alignment file type) then
4884 // try to parse as annotation.
4885 boolean isAnnotation = (format == null || format
4886 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4887 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4892 // first see if its a T-COFFEE score file
4893 TCoffeeScoreFile tcf = null;
4896 tcf = new TCoffeeScoreFile(file, protocol);
4899 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4901 tcoffeeColour.setEnabled(true);
4902 tcoffeeColour.setSelected(true);
4903 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4904 isAnnotation = true;
4905 statusBar.setText(MessageManager.getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
4909 // some problem - if no warning its probable that the ID matching
4910 // process didn't work
4914 tcf.getWarningMessage() == null ? MessageManager.getString("label.check_file_matches_sequence_ids_alignment")
4915 : tcf.getWarningMessage(),
4916 MessageManager.getString("label.problem_reading_tcoffee_score_file"),
4917 JOptionPane.WARNING_MESSAGE);
4924 } catch (Exception x)
4927 .debug("Exception when processing data source as T-COFFEE score file",
4933 // try to see if its a JNet 'concise' style annotation file *before*
4935 // try to parse it as a features file
4938 format = new IdentifyFile().Identify(file, protocol);
4940 if (format.equalsIgnoreCase("JnetFile"))
4942 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4944 new JnetAnnotationMaker().add_annotation(predictions,
4945 viewport.getAlignment(), 0, false);
4946 isAnnotation = true;
4951 * if (format.equalsIgnoreCase("PDB")) {
4953 * String pdbfn = ""; // try to match up filename with sequence id
4954 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4955 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4956 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4957 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4958 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4959 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4960 * // attempt to find a match in the alignment SequenceI mtch =
4961 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4962 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4963 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4964 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4965 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4966 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4967 * { System.err.println("Associated file : " + file + " with " +
4968 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4969 * TODO: maybe need to load as normal otherwise return; } }
4971 // try to parse it as a features file
4972 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4973 // if it wasn't a features file then we just treat it as a general
4974 // alignment file to load into the current view.
4977 new FileLoader().LoadFile(viewport, file, protocol, format);
4981 alignPanel.paintAlignment(true);
4989 alignPanel.adjustAnnotationHeight();
4990 viewport.updateSequenceIdColours();
4991 buildSortByAnnotationScoresMenu();
4992 alignPanel.paintAlignment(true);
4994 } catch (Exception ex)
4996 ex.printStackTrace();
4997 } catch (OutOfMemoryError oom)
5002 } catch (Exception x)
5008 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5009 : "using " + protocol + " from " + file)
5011 + (format != null ? "(parsing as '" + format
5012 + "' file)" : ""), oom, Desktop.desktop);
5017 public void tabSelectionChanged(int index)
5021 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5022 viewport = alignPanel.av;
5023 setMenusFromViewport(viewport);
5028 public void tabbedPane_mousePressed(MouseEvent e)
5030 if (SwingUtilities.isRightMouseButton(e))
5032 String reply = JOptionPane.showInternalInputDialog(this,
5033 MessageManager.getString("label.enter_view_name"), MessageManager.getString("label.enter_view_name,
5034 JOptionPane.QUESTION_MESSAGE);
5038 viewport.viewName = reply;
5039 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5044 public AlignViewport getCurrentView()
5050 * Open the dialog for regex description parsing.
5053 protected void extractScores_actionPerformed(ActionEvent e)
5055 ParseProperties pp = new jalview.analysis.ParseProperties(
5056 viewport.getAlignment());
5057 // TODO: verify regex and introduce GUI dialog for version 2.5
5058 // if (pp.getScoresFromDescription("col", "score column ",
5059 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5061 if (pp.getScoresFromDescription("description column",
5062 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5064 buildSortByAnnotationScoresMenu();
5072 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5076 protected void showDbRefs_actionPerformed(ActionEvent e)
5078 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5084 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5088 protected void showNpFeats_actionPerformed(ActionEvent e)
5090 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5094 * find the viewport amongst the tabs in this alignment frame and close that
5099 public boolean closeView(AlignViewport av)
5103 this.closeMenuItem_actionPerformed(false);
5106 Component[] comp = tabbedPane.getComponents();
5107 for (int i = 0; comp != null && i < comp.length; i++)
5109 if (comp[i] instanceof AlignmentPanel)
5111 if (((AlignmentPanel) comp[i]).av == av)
5114 closeView((AlignmentPanel) comp[i]);
5122 protected void build_fetchdbmenu(JMenu webService)
5124 // Temporary hack - DBRef Fetcher always top level ws entry.
5125 // TODO We probably want to store a sequence database checklist in
5126 // preferences and have checkboxes.. rather than individual sources selected
5128 final JMenu rfetch = new JMenu("Fetch DB References");
5129 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
5130 webService.add(rfetch);
5132 JMenuItem fetchr = new JMenuItem("Standard Databases");
5133 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
5134 fetchr.addActionListener(new ActionListener()
5138 public void actionPerformed(ActionEvent e)
5140 new Thread(new Runnable()
5146 new jalview.ws.DBRefFetcher(alignPanel.av
5147 .getSequenceSelection(), alignPanel.alignFrame)
5148 .fetchDBRefs(false);
5156 final AlignFrame me = this;
5157 new Thread(new Runnable()
5162 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5163 .getSequenceFetcherSingleton(me);
5164 javax.swing.SwingUtilities.invokeLater(new Runnable()
5169 String[] dbclasses = sf.getOrderedSupportedSources();
5170 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5171 // jalview.util.QuickSort.sort(otherdb, otherdb);
5172 List<DbSourceProxy> otherdb;
5173 JMenu dfetch = new JMenu();
5174 JMenu ifetch = new JMenu();
5175 JMenuItem fetchr = null;
5176 int comp = 0, icomp = 0, mcomp = 15;
5177 String mname = null;
5179 for (String dbclass : dbclasses)
5181 otherdb = sf.getSourceProxy(dbclass);
5182 // add a single entry for this class, or submenu allowing 'fetch
5184 if (otherdb == null || otherdb.size() < 1)
5188 // List<DbSourceProxy> dbs=otherdb;
5189 // otherdb=new ArrayList<DbSourceProxy>();
5190 // for (DbSourceProxy db:dbs)
5192 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5196 mname = "From " + dbclass;
5198 if (otherdb.size() == 1)
5200 final DbSourceProxy[] dassource = otherdb
5201 .toArray(new DbSourceProxy[0]);
5202 DbSourceProxy src = otherdb.get(0);
5203 fetchr = new JMenuItem(src.getDbSource());
5204 fetchr.addActionListener(new ActionListener()
5208 public void actionPerformed(ActionEvent e)
5210 new Thread(new Runnable()
5216 new jalview.ws.DBRefFetcher(alignPanel.av
5217 .getSequenceSelection(),
5218 alignPanel.alignFrame, dassource)
5219 .fetchDBRefs(false);
5225 fetchr.setToolTipText("<html>"
5226 + JvSwingUtils.wrapTooltip("Retrieve from "
5227 + src.getDbName()) + "<html>");
5233 final DbSourceProxy[] dassource = otherdb
5234 .toArray(new DbSourceProxy[0]);
5236 DbSourceProxy src = otherdb.get(0);
5237 fetchr = new JMenuItem("Fetch All '" + src.getDbSource()
5239 fetchr.addActionListener(new ActionListener()
5242 public void actionPerformed(ActionEvent e)
5244 new Thread(new Runnable()
5250 new jalview.ws.DBRefFetcher(alignPanel.av
5251 .getSequenceSelection(),
5252 alignPanel.alignFrame, dassource)
5253 .fetchDBRefs(false);
5259 fetchr.setToolTipText("<html>"
5260 + JvSwingUtils.wrapTooltip("Retrieve from all "
5261 + otherdb.size() + " sources in "
5262 + src.getDbSource() + "<br>First is :"
5263 + src.getDbName()) + "<html>");
5266 // and then build the rest of the individual menus
5267 ifetch = new JMenu("Sources from " + src.getDbSource());
5269 String imname = null;
5271 for (DbSourceProxy sproxy : otherdb)
5273 String dbname = sproxy.getDbName();
5274 String sname = dbname.length() > 5 ? dbname.substring(0,
5275 5) + "..." : dbname;
5276 String msname = dbname.length() > 10 ? dbname.substring(
5277 0, 10) + "..." : dbname;
5280 imname = "from '" + sname + "'";
5282 fetchr = new JMenuItem(msname);
5283 final DbSourceProxy[] dassrc =
5285 fetchr.addActionListener(new ActionListener()
5289 public void actionPerformed(ActionEvent e)
5291 new Thread(new Runnable()
5297 new jalview.ws.DBRefFetcher(alignPanel.av
5298 .getSequenceSelection(),
5299 alignPanel.alignFrame, dassrc)
5300 .fetchDBRefs(false);
5306 fetchr.setToolTipText("<html>"
5307 + JvSwingUtils.wrapTooltip("Retrieve from "
5308 + dbname) + "</html>");
5311 if (++icomp >= mcomp || i == (otherdb.size()))
5313 ifetch.setText(MessageManager.formatMessage("label.source_to_target",new String[]{imname,sname}));
5315 ifetch = new JMenu();
5323 if (comp >= mcomp || dbi >= (dbclasses.length))
5325 dfetch.setText(MessageManager.formatMessage("label.source_to_target",new String[]{mname,dbclass}));
5327 dfetch = new JMenu();
5340 * Left justify the whole alignment.
5343 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5345 AlignmentI al = viewport.getAlignment();
5347 viewport.firePropertyChange("alignment", null, al);
5351 * Right justify the whole alignment.
5354 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5356 AlignmentI al = viewport.getAlignment();
5358 viewport.firePropertyChange("alignment", null, al);
5361 public void setShowSeqFeatures(boolean b)
5363 showSeqFeatures.setSelected(true);
5364 viewport.setShowSequenceFeatures(true);
5371 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5372 * awt.event.ActionEvent)
5375 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5377 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5378 alignPanel.paintAlignment(true);
5385 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5389 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5391 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5392 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5400 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5401 * .event.ActionEvent)
5404 protected void showGroupConservation_actionPerformed(ActionEvent e)
5406 viewport.setShowGroupConservation(showGroupConservation.getState());
5407 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5414 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5415 * .event.ActionEvent)
5418 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5420 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5421 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5428 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5429 * .event.ActionEvent)
5432 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5434 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5435 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5439 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5441 showSequenceLogo.setState(true);
5442 viewport.setShowSequenceLogo(true);
5443 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5444 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5448 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5450 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5457 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5458 * .event.ActionEvent)
5461 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5463 if (viewport.getSelectionGroup() != null)
5465 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5466 viewport.getSequenceSelection(),
5467 viewport.getAlignmentView(true).getSequenceStrings(
5468 viewport.getGapCharacter()), viewport.getAlignment()
5470 viewport.getAlignment().deleteAllGroups();
5471 viewport.sequenceColours = null;
5472 viewport.setSelectionGroup(null);
5473 // set view properties for each group
5474 for (int g = 0; g < gps.length; g++)
5476 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5477 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5478 viewport.getAlignment().addGroup(gps[g]);
5479 Color col = new Color((int) (Math.random() * 255),
5480 (int) (Math.random() * 255), (int) (Math.random() * 255));
5481 col = col.brighter();
5482 for (SequenceI s : gps[g].getSequences())
5483 viewport.setSequenceColour(s, col);
5485 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5486 alignPanel.updateAnnotation();
5487 alignPanel.paintAlignment(true);
5492 * make the given alignmentPanel the currently selected tab
5494 * @param alignmentPanel
5496 public void setDisplayedView(AlignmentPanel alignmentPanel)
5498 if (!viewport.getSequenceSetId().equals(
5499 alignmentPanel.av.getSequenceSetId()))
5502 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5504 if (tabbedPane != null
5505 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5506 .getSelectedIndex())
5508 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5513 class PrintThread extends Thread
5517 public PrintThread(AlignmentPanel ap)
5522 static PageFormat pf;
5527 PrinterJob printJob = PrinterJob.getPrinterJob();
5531 printJob.setPrintable(ap, pf);
5535 printJob.setPrintable(ap);
5538 if (printJob.printDialog())
5543 } catch (Exception PrintException)
5545 PrintException.printStackTrace();