2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.jbgui.GAlignFrame;
59 import jalview.schemes.Blosum62ColourScheme;
60 import jalview.schemes.BuriedColourScheme;
61 import jalview.schemes.ClustalxColourScheme;
62 import jalview.schemes.ColourSchemeI;
63 import jalview.schemes.ColourSchemeProperty;
64 import jalview.schemes.HelixColourScheme;
65 import jalview.schemes.HydrophobicColourScheme;
66 import jalview.schemes.NucleotideColourScheme;
67 import jalview.schemes.PIDColourScheme;
68 import jalview.schemes.PurinePyrimidineColourScheme;
69 import jalview.schemes.ResidueProperties;
70 import jalview.schemes.StrandColourScheme;
71 import jalview.schemes.TaylorColourScheme;
72 import jalview.schemes.TurnColourScheme;
73 import jalview.schemes.UserColourScheme;
74 import jalview.schemes.ZappoColourScheme;
75 import jalview.ws.jws1.Discoverer;
76 import jalview.ws.jws2.Jws2Discoverer;
78 import java.awt.BorderLayout;
79 import java.awt.Color;
80 import java.awt.Component;
81 import java.awt.GridLayout;
82 import java.awt.Rectangle;
83 import java.awt.Toolkit;
84 import java.awt.datatransfer.Clipboard;
85 import java.awt.datatransfer.DataFlavor;
86 import java.awt.datatransfer.StringSelection;
87 import java.awt.datatransfer.Transferable;
88 import java.awt.dnd.DnDConstants;
89 import java.awt.dnd.DropTargetDragEvent;
90 import java.awt.dnd.DropTargetDropEvent;
91 import java.awt.dnd.DropTargetEvent;
92 import java.awt.dnd.DropTargetListener;
93 import java.awt.event.ActionEvent;
94 import java.awt.event.ActionListener;
95 import java.awt.event.KeyAdapter;
96 import java.awt.event.KeyEvent;
97 import java.awt.event.MouseAdapter;
98 import java.awt.event.MouseEvent;
99 import java.awt.print.PageFormat;
100 import java.awt.print.PrinterJob;
101 import java.beans.PropertyChangeEvent;
104 import java.util.ArrayList;
105 import java.util.Enumeration;
106 import java.util.Hashtable;
107 import java.util.Vector;
109 import javax.swing.JButton;
110 import javax.swing.JEditorPane;
111 import javax.swing.JInternalFrame;
112 import javax.swing.JLabel;
113 import javax.swing.JLayeredPane;
114 import javax.swing.JMenu;
115 import javax.swing.JMenuItem;
116 import javax.swing.JOptionPane;
117 import javax.swing.JPanel;
118 import javax.swing.JProgressBar;
119 import javax.swing.JRadioButtonMenuItem;
120 import javax.swing.JScrollPane;
121 import javax.swing.SwingUtilities;
127 * @version $Revision$
129 public class AlignFrame extends GAlignFrame implements DropTargetListener,
134 public static final int DEFAULT_WIDTH = 700;
137 public static final int DEFAULT_HEIGHT = 500;
139 public AlignmentPanel alignPanel;
141 AlignViewport viewport;
143 Vector alignPanels = new Vector();
146 * Last format used to load or save alignments in this window
148 String currentFileFormat = null;
151 * Current filename for this alignment
153 String fileName = null;
156 * Creates a new AlignFrame object with specific width and height.
162 public AlignFrame(AlignmentI al, int width, int height)
164 this(al, null, width, height);
168 * Creates a new AlignFrame object with specific width, height and
174 * @param sequenceSetId
176 public AlignFrame(AlignmentI al, int width, int height,
177 String sequenceSetId)
179 this(al, null, width, height, sequenceSetId);
183 * Creates a new AlignFrame object with specific width, height and
189 * @param sequenceSetId
192 public AlignFrame(AlignmentI al, int width, int height,
193 String sequenceSetId, String viewId)
195 this(al, null, width, height, sequenceSetId, viewId);
199 * new alignment window with hidden columns
203 * @param hiddenColumns
204 * ColumnSelection or null
206 * Width of alignment frame
210 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
211 int width, int height)
213 this(al, hiddenColumns, width, height, null);
217 * Create alignment frame for al with hiddenColumns, a specific width and
218 * height, and specific sequenceId
221 * @param hiddenColumns
224 * @param sequenceSetId
227 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
228 int width, int height, String sequenceSetId)
230 this(al, hiddenColumns, width, height, sequenceSetId, null);
234 * Create alignment frame for al with hiddenColumns, a specific width and
235 * height, and specific sequenceId
238 * @param hiddenColumns
241 * @param sequenceSetId
246 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
247 int width, int height, String sequenceSetId, String viewId)
249 setSize(width, height);
250 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
252 alignPanel = new AlignmentPanel(this, viewport);
254 if (al.getDataset() == null)
259 addAlignmentPanel(alignPanel, true);
264 * Make a new AlignFrame from exisiting alignmentPanels
271 public AlignFrame(AlignmentPanel ap)
275 addAlignmentPanel(ap, false);
280 * initalise the alignframe from the underlying viewport data and the
285 if (viewport.conservation == null)
287 BLOSUM62Colour.setEnabled(false);
288 conservationMenuItem.setEnabled(false);
289 modifyConservation.setEnabled(false);
290 // PIDColour.setEnabled(false);
291 // abovePIDThreshold.setEnabled(false);
292 // modifyPID.setEnabled(false);
295 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
298 if (sortby.equals("Id"))
300 sortIDMenuItem_actionPerformed(null);
302 else if (sortby.equals("Pairwise Identity"))
304 sortPairwiseMenuItem_actionPerformed(null);
307 if (Desktop.desktop != null)
309 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
310 addServiceListeners();
311 setGUINucleotide(viewport.alignment.isNucleotide());
314 setMenusFromViewport(viewport);
315 buildSortByAnnotationScoresMenu();
316 if (viewport.wrapAlignment)
318 wrapMenuItem_actionPerformed(null);
321 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
323 this.overviewMenuItem_actionPerformed(null);
331 * Change the filename and format for the alignment, and enable the 'reload'
332 * button functionality.
339 public void setFileName(String file, String format)
342 currentFileFormat = format;
343 reload.setEnabled(true);
346 void addKeyListener()
348 addKeyListener(new KeyAdapter()
350 public void keyPressed(KeyEvent evt)
352 if (viewport.cursorMode
353 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
354 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
355 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
356 && Character.isDigit(evt.getKeyChar()))
357 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
359 switch (evt.getKeyCode())
362 case 27: // escape key
363 deselectAllSequenceMenuItem_actionPerformed(null);
367 case KeyEvent.VK_DOWN:
368 if (evt.isAltDown() || !viewport.cursorMode)
369 moveSelectedSequences(false);
370 if (viewport.cursorMode)
371 alignPanel.seqPanel.moveCursor(0, 1);
375 if (evt.isAltDown() || !viewport.cursorMode)
376 moveSelectedSequences(true);
377 if (viewport.cursorMode)
378 alignPanel.seqPanel.moveCursor(0, -1);
382 case KeyEvent.VK_LEFT:
383 if (evt.isAltDown() || !viewport.cursorMode)
384 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
386 alignPanel.seqPanel.moveCursor(-1, 0);
390 case KeyEvent.VK_RIGHT:
391 if (evt.isAltDown() || !viewport.cursorMode)
392 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
394 alignPanel.seqPanel.moveCursor(1, 0);
397 case KeyEvent.VK_SPACE:
398 if (viewport.cursorMode)
400 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
401 || evt.isShiftDown() || evt.isAltDown());
405 case KeyEvent.VK_DELETE:
406 case KeyEvent.VK_BACK_SPACE:
407 if (!viewport.cursorMode)
409 cut_actionPerformed(null);
413 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
414 || evt.isShiftDown() || evt.isAltDown());
420 if (viewport.cursorMode)
422 alignPanel.seqPanel.setCursorRow();
426 if (viewport.cursorMode && !evt.isControlDown())
428 alignPanel.seqPanel.setCursorColumn();
432 if (viewport.cursorMode)
434 alignPanel.seqPanel.setCursorPosition();
438 case KeyEvent.VK_ENTER:
439 case KeyEvent.VK_COMMA:
440 if (viewport.cursorMode)
442 alignPanel.seqPanel.setCursorRowAndColumn();
447 if (viewport.cursorMode)
449 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
453 if (viewport.cursorMode)
455 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
460 viewport.cursorMode = !viewport.cursorMode;
461 statusBar.setText("Keyboard editing mode is "
462 + (viewport.cursorMode ? "on" : "off"));
463 if (viewport.cursorMode)
465 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
466 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
468 alignPanel.seqPanel.seqCanvas.repaint();
474 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
475 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
477 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
479 javax.help.HelpBroker hb = hs.createHelpBroker();
480 hb.setCurrentID("home");
481 hb.setDisplayed(true);
482 } catch (Exception ex)
484 ex.printStackTrace();
489 boolean toggleSeqs = !evt.isControlDown();
490 boolean toggleCols = !evt.isShiftDown();
491 toggleHiddenRegions(toggleSeqs, toggleCols);
494 case KeyEvent.VK_PAGE_UP:
495 if (viewport.wrapAlignment)
497 alignPanel.scrollUp(true);
501 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
502 - viewport.endSeq + viewport.startSeq);
505 case KeyEvent.VK_PAGE_DOWN:
506 if (viewport.wrapAlignment)
508 alignPanel.scrollUp(false);
512 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
513 + viewport.endSeq - viewport.startSeq);
519 public void keyReleased(KeyEvent evt)
521 switch (evt.getKeyCode())
523 case KeyEvent.VK_LEFT:
524 if (evt.isAltDown() || !viewport.cursorMode)
525 viewport.firePropertyChange("alignment", null, viewport
526 .getAlignment().getSequences());
529 case KeyEvent.VK_RIGHT:
530 if (evt.isAltDown() || !viewport.cursorMode)
531 viewport.firePropertyChange("alignment", null, viewport
532 .getAlignment().getSequences());
539 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
541 ap.alignFrame = this;
543 alignPanels.addElement(ap);
545 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
547 int aSize = alignPanels.size();
549 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
551 if (aSize == 1 && ap.av.viewName == null)
553 this.getContentPane().add(ap, BorderLayout.CENTER);
559 setInitialTabVisible();
562 expandViews.setEnabled(true);
563 gatherViews.setEnabled(true);
564 tabbedPane.addTab(ap.av.viewName, ap);
566 ap.setVisible(false);
573 ap.av.alignment.padGaps();
575 ap.av.updateConservation(ap);
576 ap.av.updateConsensus(ap);
580 public void setInitialTabVisible()
582 expandViews.setEnabled(true);
583 gatherViews.setEnabled(true);
584 tabbedPane.setVisible(true);
585 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
586 tabbedPane.addTab(first.av.viewName, first);
587 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
590 public AlignViewport getViewport()
595 /* Set up intrinsic listeners for dynamically generated GUI bits. */
596 private void addServiceListeners()
598 final java.beans.PropertyChangeListener thisListener;
599 Desktop.instance.addJalviewPropertyChangeListener("services",
600 thisListener = new java.beans.PropertyChangeListener()
602 public void propertyChange(PropertyChangeEvent evt)
604 // // System.out.println("Discoverer property change.");
605 // if (evt.getPropertyName().equals("services"))
607 SwingUtilities.invokeLater(new Runnable()
613 .println("Rebuild WS Menu for service change");
614 BuildWebServiceMenu();
621 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
623 public void internalFrameClosed(
624 javax.swing.event.InternalFrameEvent evt)
626 System.out.println("deregistering discoverer listener");
627 Desktop.instance.removeJalviewPropertyChangeListener("services",
629 closeMenuItem_actionPerformed(true);
632 // Finally, build the menu once to get current service state
633 new Thread(new Runnable()
637 BuildWebServiceMenu();
642 public void setGUINucleotide(boolean nucleotide)
644 showTranslation.setVisible(nucleotide);
645 conservationMenuItem.setEnabled(!nucleotide);
646 modifyConservation.setEnabled(!nucleotide);
647 showGroupConservation.setEnabled(!nucleotide);
648 // Remember AlignFrame always starts as protein
651 calculateMenu.remove(calculateMenu.getItemCount() - 2);
656 * set up menus for the currently viewport. This may be called after any
657 * operation that affects the data in the current view (selection changed,
658 * etc) to update the menus to reflect the new state.
660 public void setMenusForViewport()
662 setMenusFromViewport(viewport);
666 * Need to call this method when tabs are selected for multiple views, or when
667 * loading from Jalview2XML.java
672 void setMenusFromViewport(AlignViewport av)
674 padGapsMenuitem.setSelected(av.padGaps);
675 colourTextMenuItem.setSelected(av.showColourText);
676 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
677 conservationMenuItem.setSelected(av.getConservationSelected());
678 seqLimits.setSelected(av.getShowJVSuffix());
679 idRightAlign.setSelected(av.rightAlignIds);
680 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
681 renderGapsMenuItem.setSelected(av.renderGaps);
682 wrapMenuItem.setSelected(av.wrapAlignment);
683 scaleAbove.setVisible(av.wrapAlignment);
684 scaleLeft.setVisible(av.wrapAlignment);
685 scaleRight.setVisible(av.wrapAlignment);
686 annotationPanelMenuItem.setState(av.showAnnotation);
687 viewBoxesMenuItem.setSelected(av.showBoxes);
688 viewTextMenuItem.setSelected(av.showText);
689 showNonconservedMenuItem.setSelected(av.showUnconserved);
690 showGroupConsensus.setSelected(av.showGroupConsensus);
691 showGroupConservation.setSelected(av.showGroupConservation);
692 showConsensusHistogram.setSelected(av.showConsensusHistogram);
693 showSequenceLogo.setSelected(av.showSequenceLogo);
694 setColourSelected(ColourSchemeProperty.getColourName(av
695 .getGlobalColourScheme()));
697 showSeqFeatures.setSelected(av.showSequenceFeatures);
698 hiddenMarkers.setState(av.showHiddenMarkers);
699 applyToAllGroups.setState(av.colourAppliesToAllGroups);
700 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
701 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
703 setShowProductsEnabled();
708 Hashtable progressBars, progressBarHandlers;
713 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
715 public void setProgressBar(String message, long id)
717 if (progressBars == null)
719 progressBars = new Hashtable();
720 progressBarHandlers = new Hashtable();
723 JPanel progressPanel;
724 Long lId = new Long(id);
725 GridLayout layout = (GridLayout) statusPanel.getLayout();
726 if (progressBars.get(lId) != null)
728 progressPanel = (JPanel) progressBars.get(new Long(id));
729 statusPanel.remove(progressPanel);
730 progressBars.remove(lId);
731 progressPanel = null;
734 statusBar.setText(message);
736 if (progressBarHandlers.contains(lId))
738 progressBarHandlers.remove(lId);
740 layout.setRows(layout.getRows() - 1);
744 progressPanel = new JPanel(new BorderLayout(10, 5));
746 JProgressBar progressBar = new JProgressBar();
747 progressBar.setIndeterminate(true);
749 progressPanel.add(new JLabel(message), BorderLayout.WEST);
750 progressPanel.add(progressBar, BorderLayout.CENTER);
752 layout.setRows(layout.getRows() + 1);
753 statusPanel.add(progressPanel);
755 progressBars.put(lId, progressPanel);
758 // setMenusForViewport();
762 public void registerHandler(final long id,
763 final IProgressIndicatorHandler handler)
765 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
768 "call setProgressBar before registering the progress bar's handler.");
770 progressBarHandlers.put(new Long(id), handler);
771 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
772 if (handler.canCancel())
774 JButton cancel = new JButton("Cancel");
775 final IProgressIndicator us = this;
776 cancel.addActionListener(new ActionListener()
779 public void actionPerformed(ActionEvent e)
781 handler.cancelActivity(id);
784 + ((JLabel) progressPanel.getComponent(0))
788 progressPanel.add(cancel, BorderLayout.EAST);
794 * @return true if any progress bars are still active
796 public boolean operationInProgress()
798 if (progressBars != null && progressBars.size() > 0)
806 * Added so Castor Mapping file can obtain Jalview Version
808 public String getVersion()
810 return jalview.bin.Cache.getProperty("VERSION");
813 public FeatureRenderer getFeatureRenderer()
815 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
818 public void fetchSequence_actionPerformed(ActionEvent e)
820 new SequenceFetcher(this);
823 public void addFromFile_actionPerformed(ActionEvent e)
825 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
828 public void reload_actionPerformed(ActionEvent e)
830 if (fileName != null)
832 // TODO: work out how to recover feature settings for correct view(s) when
834 if (currentFileFormat.equals("Jalview"))
836 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
837 for (int i = 0; i < frames.length; i++)
839 if (frames[i] instanceof AlignFrame && frames[i] != this
840 && ((AlignFrame) frames[i]).fileName.equals(fileName))
844 frames[i].setSelected(true);
845 Desktop.instance.closeAssociatedWindows();
846 } catch (java.beans.PropertyVetoException ex)
852 Desktop.instance.closeAssociatedWindows();
854 FileLoader loader = new FileLoader();
855 String protocol = fileName.startsWith("http:") ? "URL" : "File";
856 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
860 Rectangle bounds = this.getBounds();
862 FileLoader loader = new FileLoader();
863 String protocol = fileName.startsWith("http:") ? "URL" : "File";
864 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
865 protocol, currentFileFormat);
867 newframe.setBounds(bounds);
868 if (featureSettings != null && featureSettings.isShowing())
870 final Rectangle fspos = featureSettings.frame.getBounds();
871 // TODO: need a 'show feature settings' function that takes bounds -
872 // need to refactor Desktop.addFrame
873 newframe.featureSettings_actionPerformed(null);
874 final FeatureSettings nfs = newframe.featureSettings;
875 SwingUtilities.invokeLater(new Runnable()
879 nfs.frame.setBounds(fspos);
882 this.featureSettings.close();
883 this.featureSettings = null;
885 this.closeMenuItem_actionPerformed(true);
890 public void addFromText_actionPerformed(ActionEvent e)
892 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
895 public void addFromURL_actionPerformed(ActionEvent e)
897 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
900 public void save_actionPerformed(ActionEvent e)
903 || (currentFileFormat == null || !jalview.io.FormatAdapter
904 .isValidIOFormat(currentFileFormat, true))
905 || fileName.startsWith("http"))
907 saveAs_actionPerformed(null);
911 saveAlignment(fileName, currentFileFormat);
921 public void saveAs_actionPerformed(ActionEvent e)
923 JalviewFileChooser chooser = new JalviewFileChooser(
924 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
925 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
926 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
927 currentFileFormat, false);
929 chooser.setFileView(new JalviewFileView());
930 chooser.setDialogTitle("Save Alignment to file");
931 chooser.setToolTipText("Save");
933 int value = chooser.showSaveDialog(this);
935 if (value == JalviewFileChooser.APPROVE_OPTION)
937 currentFileFormat = chooser.getSelectedFormat();
938 if (currentFileFormat == null)
940 JOptionPane.showInternalMessageDialog(Desktop.desktop,
941 "You must select a file format before saving!",
942 "File format not specified", JOptionPane.WARNING_MESSAGE);
943 value = chooser.showSaveDialog(this);
947 fileName = chooser.getSelectedFile().getPath();
949 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
952 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
953 if (currentFileFormat.indexOf(" ") > -1)
955 currentFileFormat = currentFileFormat.substring(0,
956 currentFileFormat.indexOf(" "));
958 saveAlignment(fileName, currentFileFormat);
962 public boolean saveAlignment(String file, String format)
964 boolean success = true;
966 if (format.equalsIgnoreCase("Jalview"))
968 String shortName = title;
970 if (shortName.indexOf(java.io.File.separatorChar) > -1)
972 shortName = shortName.substring(shortName
973 .lastIndexOf(java.io.File.separatorChar) + 1);
976 success = new Jalview2XML().SaveAlignment(this, file, shortName);
978 statusBar.setText("Successfully saved to file: " + fileName + " in "
979 + format + " format.");
984 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
986 warningMessage("Cannot save file " + fileName + " using format "
987 + format, "Alignment output format not supported");
988 saveAs_actionPerformed(null);
989 // JBPNote need to have a raise_gui flag here
993 String[] omitHidden = null;
995 if (viewport.hasHiddenColumns)
997 int reply = JOptionPane
998 .showInternalConfirmDialog(
1000 "The Alignment contains hidden columns."
1001 + "\nDo you want to save only the visible alignment?",
1002 "Save / Omit Hidden Columns",
1003 JOptionPane.YES_NO_OPTION,
1004 JOptionPane.QUESTION_MESSAGE);
1006 if (reply == JOptionPane.YES_OPTION)
1008 omitHidden = viewport.getViewAsString(false);
1011 FormatAdapter f = new FormatAdapter();
1012 String output = f.formatSequences(format,
1013 (Alignment) viewport.alignment, // class cast exceptions will
1014 // occur in the distant future
1015 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
1025 java.io.PrintWriter out = new java.io.PrintWriter(
1026 new java.io.FileWriter(file));
1030 this.setTitle(file);
1031 statusBar.setText("Successfully saved to file: " + fileName
1032 + " in " + format + " format.");
1033 } catch (Exception ex)
1036 ex.printStackTrace();
1043 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1044 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1050 private void warningMessage(String warning, String title)
1052 if (new jalview.util.Platform().isHeadless())
1054 System.err.println("Warning: " + title + "\nWarning: " + warning);
1059 JOptionPane.showInternalMessageDialog(this, warning, title,
1060 JOptionPane.WARNING_MESSAGE);
1071 protected void outputText_actionPerformed(ActionEvent e)
1073 String[] omitHidden = null;
1075 if (viewport.hasHiddenColumns)
1077 int reply = JOptionPane
1078 .showInternalConfirmDialog(
1080 "The Alignment contains hidden columns."
1081 + "\nDo you want to output only the visible alignment?",
1082 "Save / Omit Hidden Columns",
1083 JOptionPane.YES_NO_OPTION,
1084 JOptionPane.QUESTION_MESSAGE);
1086 if (reply == JOptionPane.YES_OPTION)
1088 omitHidden = viewport.getViewAsString(false);
1092 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1093 cap.setForInput(null);
1097 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1098 viewport.alignment, omitHidden, viewport.colSel));
1099 Desktop.addInternalFrame(cap,
1100 "Alignment output - " + e.getActionCommand(), 600, 500);
1101 } catch (OutOfMemoryError oom)
1103 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1115 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1117 new HTMLOutput(alignPanel,
1118 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1119 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1122 public void createImageMap(File file, String image)
1124 alignPanel.makePNGImageMap(file, image);
1133 public void createPNG(File f)
1135 alignPanel.makePNG(f);
1144 public void createEPS(File f)
1146 alignPanel.makeEPS(f);
1149 public void pageSetup_actionPerformed(ActionEvent e)
1151 PrinterJob printJob = PrinterJob.getPrinterJob();
1152 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1161 public void printMenuItem_actionPerformed(ActionEvent e)
1163 // Putting in a thread avoids Swing painting problems
1164 PrintThread thread = new PrintThread(alignPanel);
1168 public void exportFeatures_actionPerformed(ActionEvent e)
1170 new AnnotationExporter().exportFeatures(alignPanel);
1173 public void exportAnnotations_actionPerformed(ActionEvent e)
1175 new AnnotationExporter().exportAnnotations(
1177 viewport.showAnnotation ? viewport.alignment
1178 .getAlignmentAnnotation() : null, viewport.alignment
1180 ((Alignment) viewport.alignment).alignmentProperties);
1183 public void associatedData_actionPerformed(ActionEvent e)
1185 // Pick the tree file
1186 JalviewFileChooser chooser = new JalviewFileChooser(
1187 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1188 chooser.setFileView(new JalviewFileView());
1189 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1190 chooser.setToolTipText("Load Jalview Annotations / Features file");
1192 int value = chooser.showOpenDialog(null);
1194 if (value == JalviewFileChooser.APPROVE_OPTION)
1196 String choice = chooser.getSelectedFile().getPath();
1197 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1198 loadJalviewDataFile(choice, null, null, null);
1204 * Close the current view or all views in the alignment frame. If the frame
1205 * only contains one view then the alignment will be removed from memory.
1207 * @param closeAllTabs
1209 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1211 if (alignPanels != null && alignPanels.size() < 2)
1213 closeAllTabs = true;
1218 if (alignPanels != null)
1222 if (this.isClosed())
1224 // really close all the windows - otherwise wait till
1225 // setClosed(true) is called
1226 for (int i = 0; i < alignPanels.size(); i++)
1228 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1235 closeView(alignPanel);
1241 this.setClosed(true);
1243 } catch (Exception ex)
1245 ex.printStackTrace();
1250 * close alignPanel2 and shuffle tabs appropriately.
1252 * @param alignPanel2
1254 public void closeView(AlignmentPanel alignPanel2)
1256 int index = tabbedPane.getSelectedIndex();
1257 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1258 alignPanels.removeElement(alignPanel2);
1260 // if (viewport == alignPanel2.av)
1264 alignPanel2.closePanel();
1267 tabbedPane.removeTabAt(closedindex);
1268 tabbedPane.validate();
1270 if (index > closedindex || index == tabbedPane.getTabCount())
1272 // modify currently selected tab index if necessary.
1276 this.tabSelectionChanged(index);
1282 void updateEditMenuBar()
1285 if (viewport.historyList.size() > 0)
1287 undoMenuItem.setEnabled(true);
1288 CommandI command = (CommandI) viewport.historyList.peek();
1289 undoMenuItem.setText("Undo " + command.getDescription());
1293 undoMenuItem.setEnabled(false);
1294 undoMenuItem.setText("Undo");
1297 if (viewport.redoList.size() > 0)
1299 redoMenuItem.setEnabled(true);
1301 CommandI command = (CommandI) viewport.redoList.peek();
1302 redoMenuItem.setText("Redo " + command.getDescription());
1306 redoMenuItem.setEnabled(false);
1307 redoMenuItem.setText("Redo");
1311 public void addHistoryItem(CommandI command)
1313 if (command.getSize() > 0)
1315 viewport.historyList.push(command);
1316 viewport.redoList.clear();
1317 updateEditMenuBar();
1318 viewport.hasHiddenColumns = (viewport.colSel != null
1319 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1320 .getHiddenColumns().size() > 0);
1326 * @return alignment objects for all views
1328 AlignmentI[] getViewAlignments()
1330 if (alignPanels != null)
1332 Enumeration e = alignPanels.elements();
1333 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1334 for (int i = 0; e.hasMoreElements(); i++)
1336 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1340 if (viewport != null)
1342 return new AlignmentI[]
1343 { viewport.alignment };
1354 protected void undoMenuItem_actionPerformed(ActionEvent e)
1356 if (viewport.historyList.empty())
1358 CommandI command = (CommandI) viewport.historyList.pop();
1359 viewport.redoList.push(command);
1360 command.undoCommand(getViewAlignments());
1362 AlignViewport originalSource = getOriginatingSource(command);
1363 updateEditMenuBar();
1365 if (originalSource != null)
1367 originalSource.hasHiddenColumns = (viewport.colSel != null
1368 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1369 .getHiddenColumns().size() > 0);
1370 originalSource.firePropertyChange("alignment", null,
1371 originalSource.alignment.getSequences());
1381 protected void redoMenuItem_actionPerformed(ActionEvent e)
1383 if (viewport.redoList.size() < 1)
1388 CommandI command = (CommandI) viewport.redoList.pop();
1389 viewport.historyList.push(command);
1390 command.doCommand(getViewAlignments());
1392 AlignViewport originalSource = getOriginatingSource(command);
1393 updateEditMenuBar();
1395 if (originalSource != null)
1397 originalSource.hasHiddenColumns = (viewport.colSel != null
1398 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1399 .getHiddenColumns().size() > 0);
1400 originalSource.firePropertyChange("alignment", null,
1401 originalSource.alignment.getSequences());
1405 AlignViewport getOriginatingSource(CommandI command)
1407 AlignViewport originalSource = null;
1408 // For sequence removal and addition, we need to fire
1409 // the property change event FROM the viewport where the
1410 // original alignment was altered
1411 AlignmentI al = null;
1412 if (command instanceof EditCommand)
1414 EditCommand editCommand = (EditCommand) command;
1415 al = editCommand.getAlignment();
1416 Vector comps = (Vector) PaintRefresher.components.get(viewport
1417 .getSequenceSetId());
1419 for (int i = 0; i < comps.size(); i++)
1421 if (comps.elementAt(i) instanceof AlignmentPanel)
1423 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1425 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1432 if (originalSource == null)
1434 // The original view is closed, we must validate
1435 // the current view against the closed view first
1438 PaintRefresher.validateSequences(al, viewport.alignment);
1441 originalSource = viewport;
1444 return originalSource;
1453 public void moveSelectedSequences(boolean up)
1455 SequenceGroup sg = viewport.getSelectionGroup();
1464 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1466 SequenceI seq = viewport.alignment.getSequenceAt(i);
1468 if (!sg.getSequences(null).contains(seq))
1473 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1475 if (sg.getSequences(null).contains(temp))
1480 viewport.alignment.getSequences().setElementAt(temp, i);
1481 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1486 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1488 SequenceI seq = viewport.alignment.getSequenceAt(i);
1490 if (!sg.getSequences(null).contains(seq))
1495 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1497 if (sg.getSequences(null).contains(temp))
1502 viewport.alignment.getSequences().setElementAt(temp, i);
1503 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1507 alignPanel.paintAlignment(true);
1510 synchronized void slideSequences(boolean right, int size)
1512 Vector sg = new Vector();
1513 if (viewport.cursorMode)
1515 sg.addElement(viewport.alignment
1516 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1518 else if (viewport.getSelectionGroup() != null
1519 && viewport.getSelectionGroup().getSize() != viewport.alignment
1522 sg = viewport.getSelectionGroup().getSequences(
1523 viewport.hiddenRepSequences);
1531 Vector invertGroup = new Vector();
1533 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1535 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1536 invertGroup.add(viewport.alignment.getSequenceAt(i));
1539 SequenceI[] seqs1 = new SequenceI[sg.size()];
1540 for (int i = 0; i < sg.size(); i++)
1541 seqs1[i] = (SequenceI) sg.elementAt(i);
1543 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1544 for (int i = 0; i < invertGroup.size(); i++)
1545 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1547 SlideSequencesCommand ssc;
1549 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1550 size, viewport.getGapCharacter());
1552 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1553 size, viewport.getGapCharacter());
1555 int groupAdjustment = 0;
1556 if (ssc.getGapsInsertedBegin() && right)
1558 if (viewport.cursorMode)
1559 alignPanel.seqPanel.moveCursor(size, 0);
1561 groupAdjustment = size;
1563 else if (!ssc.getGapsInsertedBegin() && !right)
1565 if (viewport.cursorMode)
1566 alignPanel.seqPanel.moveCursor(-size, 0);
1568 groupAdjustment = -size;
1571 if (groupAdjustment != 0)
1573 viewport.getSelectionGroup().setStartRes(
1574 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1575 viewport.getSelectionGroup().setEndRes(
1576 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1579 boolean appendHistoryItem = false;
1580 if (viewport.historyList != null && viewport.historyList.size() > 0
1581 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1583 appendHistoryItem = ssc
1584 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1588 if (!appendHistoryItem)
1589 addHistoryItem(ssc);
1600 protected void copy_actionPerformed(ActionEvent e)
1603 if (viewport.getSelectionGroup() == null)
1607 // TODO: preserve the ordering of displayed alignment annotation in any
1608 // internal paste (particularly sequence associated annotation)
1609 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1610 String[] omitHidden = null;
1612 if (viewport.hasHiddenColumns)
1614 omitHidden = viewport.getViewAsString(true);
1617 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1620 StringSelection ss = new StringSelection(output);
1624 jalview.gui.Desktop.internalCopy = true;
1625 // Its really worth setting the clipboard contents
1626 // to empty before setting the large StringSelection!!
1627 Toolkit.getDefaultToolkit().getSystemClipboard()
1628 .setContents(new StringSelection(""), null);
1630 Toolkit.getDefaultToolkit().getSystemClipboard()
1631 .setContents(ss, Desktop.instance);
1632 } catch (OutOfMemoryError er)
1634 new OOMWarning("copying region", er);
1638 Vector hiddenColumns = null;
1639 if (viewport.hasHiddenColumns)
1641 hiddenColumns = new Vector();
1642 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1643 .getSelectionGroup().getEndRes();
1644 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1647 int[] region = (int[]) viewport.getColumnSelection()
1648 .getHiddenColumns().elementAt(i);
1649 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1651 hiddenColumns.addElement(new int[]
1652 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1657 Desktop.jalviewClipboard = new Object[]
1658 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1659 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1668 protected void pasteNew_actionPerformed(ActionEvent e)
1679 protected void pasteThis_actionPerformed(ActionEvent e)
1685 * Paste contents of Jalview clipboard
1687 * @param newAlignment
1688 * true to paste to a new alignment, otherwise add to this.
1690 void paste(boolean newAlignment)
1692 boolean externalPaste = true;
1695 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1696 Transferable contents = c.getContents(this);
1698 if (contents == null)
1706 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1707 if (str.length() < 1)
1712 format = new IdentifyFile().Identify(str, "Paste");
1714 } catch (OutOfMemoryError er)
1716 new OOMWarning("Out of memory pasting sequences!!", er);
1720 SequenceI[] sequences;
1721 boolean annotationAdded = false;
1722 AlignmentI alignment = null;
1724 if (Desktop.jalviewClipboard != null)
1726 // The clipboard was filled from within Jalview, we must use the
1728 // And dataset from the copied alignment
1729 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1730 // be doubly sure that we create *new* sequence objects.
1731 sequences = new SequenceI[newseq.length];
1732 for (int i = 0; i < newseq.length; i++)
1734 sequences[i] = new Sequence(newseq[i]);
1736 alignment = new Alignment(sequences);
1737 externalPaste = false;
1741 // parse the clipboard as an alignment.
1742 alignment = new FormatAdapter().readFile(str, "Paste", format);
1743 sequences = alignment.getSequencesArray();
1751 if (Desktop.jalviewClipboard != null)
1753 // dataset is inherited
1754 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1758 // new dataset is constructed
1759 alignment.setDataset(null);
1761 alwidth = alignment.getWidth() + 1;
1765 AlignmentI pastedal = alignment; // preserve pasted alignment object
1766 // Add pasted sequences and dataset into existing alignment.
1767 alignment = viewport.getAlignment();
1768 alwidth = alignment.getWidth() + 1;
1769 // decide if we need to import sequences from an existing dataset
1770 boolean importDs = Desktop.jalviewClipboard != null
1771 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1772 // importDs==true instructs us to copy over new dataset sequences from
1773 // an existing alignment
1774 Vector newDs = (importDs) ? new Vector() : null; // used to create
1775 // minimum dataset set
1777 for (int i = 0; i < sequences.length; i++)
1781 newDs.addElement(null);
1783 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1785 if (importDs && ds != null)
1787 if (!newDs.contains(ds))
1789 newDs.setElementAt(ds, i);
1790 ds = new Sequence(ds);
1791 // update with new dataset sequence
1792 sequences[i].setDatasetSequence(ds);
1796 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1801 // copy and derive new dataset sequence
1802 sequences[i] = sequences[i].deriveSequence();
1803 alignment.getDataset().addSequence(
1804 sequences[i].getDatasetSequence());
1805 // TODO: avoid creation of duplicate dataset sequences with a
1806 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1808 alignment.addSequence(sequences[i]); // merges dataset
1812 newDs.clear(); // tidy up
1814 if (pastedal.getAlignmentAnnotation() != null)
1816 // Add any annotation attached to alignment.
1817 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1818 for (int i = 0; i < alann.length; i++)
1820 annotationAdded = true;
1821 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1823 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1824 newann.padAnnotation(alwidth);
1825 alignment.addAnnotation(newann);
1835 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1836 sequences, 0, alignment.getWidth(), alignment));
1838 // Add any annotations attached to sequences
1839 for (int i = 0; i < sequences.length; i++)
1841 if (sequences[i].getAnnotation() != null)
1843 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1845 annotationAdded = true;
1846 sequences[i].getAnnotation()[a].adjustForAlignment();
1847 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1848 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1853 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1860 // propagate alignment changed.
1861 viewport.setEndSeq(alignment.getHeight());
1862 if (annotationAdded)
1864 // Duplicate sequence annotation in all views.
1865 AlignmentI[] alview = this.getViewAlignments();
1866 for (int i = 0; i < sequences.length; i++)
1868 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1871 for (int avnum = 0; avnum < alview.length; avnum++)
1873 if (alview[avnum] != alignment)
1875 // duplicate in a view other than the one with input focus
1876 int avwidth = alview[avnum].getWidth() + 1;
1877 // this relies on sann being preserved after we
1878 // modify the sequence's annotation array for each duplication
1879 for (int a = 0; a < sann.length; a++)
1881 AlignmentAnnotation newann = new AlignmentAnnotation(
1883 sequences[i].addAlignmentAnnotation(newann);
1884 newann.padAnnotation(avwidth);
1885 alview[avnum].addAnnotation(newann); // annotation was
1886 // duplicated earlier
1887 alview[avnum].setAnnotationIndex(newann, a);
1892 buildSortByAnnotationScoresMenu();
1894 viewport.firePropertyChange("alignment", null,
1895 alignment.getSequences());
1900 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1902 String newtitle = new String("Copied sequences");
1904 if (Desktop.jalviewClipboard != null
1905 && Desktop.jalviewClipboard[2] != null)
1907 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1908 for (int i = 0; i < hc.size(); i++)
1910 int[] region = (int[]) hc.elementAt(i);
1911 af.viewport.hideColumns(region[0], region[1]);
1915 // >>>This is a fix for the moment, until a better solution is
1917 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1919 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1921 // TODO: maintain provenance of an alignment, rather than just make the
1922 // title a concatenation of operations.
1925 if (title.startsWith("Copied sequences"))
1931 newtitle = newtitle.concat("- from " + title);
1936 newtitle = new String("Pasted sequences");
1939 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1944 } catch (Exception ex)
1946 ex.printStackTrace();
1947 System.out.println("Exception whilst pasting: " + ex);
1948 // could be anything being pasted in here
1959 protected void cut_actionPerformed(ActionEvent e)
1961 copy_actionPerformed(null);
1962 delete_actionPerformed(null);
1971 protected void delete_actionPerformed(ActionEvent evt)
1974 SequenceGroup sg = viewport.getSelectionGroup();
1980 Vector seqs = new Vector();
1982 for (int i = 0; i < sg.getSize(); i++)
1984 seq = sg.getSequenceAt(i);
1985 seqs.addElement(seq);
1988 // If the cut affects all sequences, remove highlighted columns
1989 if (sg.getSize() == viewport.alignment.getHeight())
1991 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1992 sg.getEndRes() + 1);
1995 SequenceI[] cut = new SequenceI[seqs.size()];
1996 for (int i = 0; i < seqs.size(); i++)
1998 cut[i] = (SequenceI) seqs.elementAt(i);
2002 * //ADD HISTORY ITEM
2004 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2005 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2006 viewport.alignment));
2008 viewport.setSelectionGroup(null);
2009 viewport.sendSelection();
2010 viewport.alignment.deleteGroup(sg);
2012 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2014 if (viewport.getAlignment().getHeight() < 1)
2018 this.setClosed(true);
2019 } catch (Exception ex)
2031 protected void deleteGroups_actionPerformed(ActionEvent e)
2033 viewport.alignment.deleteAllGroups();
2034 viewport.sequenceColours = null;
2035 viewport.setSelectionGroup(null);
2036 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2037 alignPanel.updateAnnotation();
2038 alignPanel.paintAlignment(true);
2047 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2049 SequenceGroup sg = new SequenceGroup();
2051 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2053 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2056 sg.setEndRes(viewport.alignment.getWidth() - 1);
2057 viewport.setSelectionGroup(sg);
2058 viewport.sendSelection();
2059 alignPanel.paintAlignment(true);
2060 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2069 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2071 if (viewport.cursorMode)
2073 alignPanel.seqPanel.keyboardNo1 = null;
2074 alignPanel.seqPanel.keyboardNo2 = null;
2076 viewport.setSelectionGroup(null);
2077 viewport.getColumnSelection().clear();
2078 viewport.setSelectionGroup(null);
2079 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2080 alignPanel.idPanel.idCanvas.searchResults = null;
2081 alignPanel.paintAlignment(true);
2082 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2083 viewport.sendSelection();
2092 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2094 SequenceGroup sg = viewport.getSelectionGroup();
2098 selectAllSequenceMenuItem_actionPerformed(null);
2103 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2105 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2108 alignPanel.paintAlignment(true);
2109 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2110 viewport.sendSelection();
2113 public void invertColSel_actionPerformed(ActionEvent e)
2115 viewport.invertColumnSelection();
2116 alignPanel.paintAlignment(true);
2117 viewport.sendSelection();
2126 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2128 trimAlignment(true);
2137 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2139 trimAlignment(false);
2142 void trimAlignment(boolean trimLeft)
2144 ColumnSelection colSel = viewport.getColumnSelection();
2147 if (colSel.size() > 0)
2151 column = colSel.getMin();
2155 column = colSel.getMax();
2159 if (viewport.getSelectionGroup() != null)
2161 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2162 viewport.hiddenRepSequences);
2166 seqs = viewport.alignment.getSequencesArray();
2169 TrimRegionCommand trimRegion;
2172 trimRegion = new TrimRegionCommand("Remove Left",
2173 TrimRegionCommand.TRIM_LEFT, seqs, column,
2174 viewport.alignment, viewport.colSel,
2175 viewport.selectionGroup);
2176 viewport.setStartRes(0);
2180 trimRegion = new TrimRegionCommand("Remove Right",
2181 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2182 viewport.alignment, viewport.colSel,
2183 viewport.selectionGroup);
2186 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2188 addHistoryItem(trimRegion);
2190 Vector groups = viewport.alignment.getGroups();
2192 for (int i = 0; i < groups.size(); i++)
2194 SequenceGroup sg = (SequenceGroup) groups.get(i);
2196 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2197 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2199 viewport.alignment.deleteGroup(sg);
2203 viewport.firePropertyChange("alignment", null, viewport
2204 .getAlignment().getSequences());
2214 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2216 int start = 0, end = viewport.alignment.getWidth() - 1;
2219 if (viewport.getSelectionGroup() != null)
2221 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2222 viewport.hiddenRepSequences);
2223 start = viewport.getSelectionGroup().getStartRes();
2224 end = viewport.getSelectionGroup().getEndRes();
2228 seqs = viewport.alignment.getSequencesArray();
2231 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2232 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2234 addHistoryItem(removeGapCols);
2236 statusBar.setText("Removed " + removeGapCols.getSize()
2237 + " empty columns.");
2239 // This is to maintain viewport position on first residue
2240 // of first sequence
2241 SequenceI seq = viewport.alignment.getSequenceAt(0);
2242 int startRes = seq.findPosition(viewport.startRes);
2243 // ShiftList shifts;
2244 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2245 // edit.alColumnChanges=shifts.getInverse();
2246 // if (viewport.hasHiddenColumns)
2247 // viewport.getColumnSelection().compensateForEdits(shifts);
2248 viewport.setStartRes(seq.findIndex(startRes) - 1);
2249 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2260 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2262 int start = 0, end = viewport.alignment.getWidth() - 1;
2265 if (viewport.getSelectionGroup() != null)
2267 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2268 viewport.hiddenRepSequences);
2269 start = viewport.getSelectionGroup().getStartRes();
2270 end = viewport.getSelectionGroup().getEndRes();
2274 seqs = viewport.alignment.getSequencesArray();
2277 // This is to maintain viewport position on first residue
2278 // of first sequence
2279 SequenceI seq = viewport.alignment.getSequenceAt(0);
2280 int startRes = seq.findPosition(viewport.startRes);
2282 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2283 viewport.alignment));
2285 viewport.setStartRes(seq.findIndex(startRes) - 1);
2287 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2298 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2300 viewport.padGaps = padGapsMenuitem.isSelected();
2301 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2307 // if (justifySeqs>0)
2309 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2321 public void findMenuItem_actionPerformed(ActionEvent e)
2326 public void newView_actionPerformed(ActionEvent e)
2333 * @param copyAnnotation
2334 * if true then duplicate all annnotation, groups and settings
2335 * @return new alignment panel, already displayed.
2337 public AlignmentPanel newView(boolean copyAnnotation)
2339 return newView(null, copyAnnotation);
2345 * title of newly created view
2346 * @return new alignment panel, already displayed.
2348 public AlignmentPanel newView(String viewTitle)
2350 return newView(viewTitle, true);
2356 * title of newly created view
2357 * @param copyAnnotation
2358 * if true then duplicate all annnotation, groups and settings
2359 * @return new alignment panel, already displayed.
2361 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2363 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2365 if (!copyAnnotation)
2367 // just remove all the current annotation except for the automatic stuff
2368 newap.av.alignment.deleteAllGroups();
2369 for (AlignmentAnnotation alan : newap.av.alignment
2370 .getAlignmentAnnotation())
2372 if (!alan.autoCalculated)
2374 newap.av.alignment.deleteAnnotation(alan);
2380 newap.av.gatherViewsHere = false;
2382 if (viewport.viewName == null)
2384 viewport.viewName = "Original";
2387 newap.av.historyList = viewport.historyList;
2388 newap.av.redoList = viewport.redoList;
2390 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2391 // make sure the new view has a unique name - this is essential for Jalview
2393 boolean addFirstIndex = false;
2394 if (viewTitle == null || viewTitle.trim().length() == 0)
2397 addFirstIndex = true;
2401 index = 1;// we count from 1 if given a specific name
2403 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2404 Vector comps = (Vector) PaintRefresher.components.get(viewport
2405 .getSequenceSetId());
2406 Vector existingNames = new Vector();
2407 for (int i = 0; i < comps.size(); i++)
2409 if (comps.elementAt(i) instanceof AlignmentPanel)
2411 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2412 if (!existingNames.contains(ap.av.viewName))
2414 existingNames.addElement(ap.av.viewName);
2419 while (existingNames.contains(newViewName))
2421 newViewName = viewTitle + " " + (++index);
2424 newap.av.viewName = newViewName;
2426 addAlignmentPanel(newap, true);
2428 if (alignPanels.size() == 2)
2430 viewport.gatherViewsHere = true;
2432 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2436 public void expandViews_actionPerformed(ActionEvent e)
2438 Desktop.instance.explodeViews(this);
2441 public void gatherViews_actionPerformed(ActionEvent e)
2443 Desktop.instance.gatherViews(this);
2452 public void font_actionPerformed(ActionEvent e)
2454 new FontChooser(alignPanel);
2463 protected void seqLimit_actionPerformed(ActionEvent e)
2465 viewport.setShowJVSuffix(seqLimits.isSelected());
2467 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2468 .calculateIdWidth());
2469 alignPanel.paintAlignment(true);
2472 public void idRightAlign_actionPerformed(ActionEvent e)
2474 viewport.rightAlignIds = idRightAlign.isSelected();
2475 alignPanel.paintAlignment(true);
2478 public void centreColumnLabels_actionPerformed(ActionEvent e)
2480 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2481 alignPanel.paintAlignment(true);
2487 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2489 protected void followHighlight_actionPerformed()
2491 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2493 alignPanel.scrollToPosition(
2494 alignPanel.seqPanel.seqCanvas.searchResults, false);
2504 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2506 viewport.setColourText(colourTextMenuItem.isSelected());
2507 alignPanel.paintAlignment(true);
2516 public void wrapMenuItem_actionPerformed(ActionEvent e)
2518 scaleAbove.setVisible(wrapMenuItem.isSelected());
2519 scaleLeft.setVisible(wrapMenuItem.isSelected());
2520 scaleRight.setVisible(wrapMenuItem.isSelected());
2521 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2522 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2525 public void showAllSeqs_actionPerformed(ActionEvent e)
2527 viewport.showAllHiddenSeqs();
2530 public void showAllColumns_actionPerformed(ActionEvent e)
2532 viewport.showAllHiddenColumns();
2536 public void hideSelSequences_actionPerformed(ActionEvent e)
2538 viewport.hideAllSelectedSeqs();
2539 alignPanel.paintAlignment(true);
2543 * called by key handler and the hide all/show all menu items
2548 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2551 boolean hide = false;
2552 SequenceGroup sg = viewport.getSelectionGroup();
2553 if (!toggleSeqs && !toggleCols)
2555 // Hide everything by the current selection - this is a hack - we do the
2556 // invert and then hide
2557 // first check that there will be visible columns after the invert.
2558 if ((viewport.colSel != null && viewport.colSel.getSelected() != null && viewport.colSel
2559 .getSelected().size() > 0)
2560 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2563 // now invert the sequence set, if required - empty selection implies
2564 // that no hiding is required.
2567 invertSequenceMenuItem_actionPerformed(null);
2568 sg = viewport.getSelectionGroup();
2572 viewport.expandColSelection(sg, true);
2573 // finally invert the column selection and get the new sequence
2575 invertColSel_actionPerformed(null);
2582 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
2584 hideSelSequences_actionPerformed(null);
2587 else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))
2589 showAllSeqs_actionPerformed(null);
2595 if (viewport.colSel.getSelected().size() > 0)
2597 hideSelColumns_actionPerformed(null);
2600 viewport.selectionGroup = sg;
2605 showAllColumns_actionPerformed(null);
2614 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2615 * event.ActionEvent)
2617 public void hideAllButSelection_actionPerformed(ActionEvent e)
2619 toggleHiddenRegions(false, false);
2626 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2629 public void hideAllSelection_actionPerformed(ActionEvent e)
2631 SequenceGroup sg = viewport.getSelectionGroup();
2632 viewport.expandColSelection(sg, false);
2633 viewport.hideAllSelectedSeqs();
2634 viewport.hideSelectedColumns();
2635 alignPanel.paintAlignment(true);
2642 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2645 public void showAllhidden_actionPerformed(ActionEvent e)
2647 viewport.showAllHiddenColumns();
2648 viewport.showAllHiddenSeqs();
2649 alignPanel.paintAlignment(true);
2652 public void hideSelColumns_actionPerformed(ActionEvent e)
2654 viewport.hideSelectedColumns();
2655 alignPanel.paintAlignment(true);
2658 public void hiddenMarkers_actionPerformed(ActionEvent e)
2660 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2670 protected void scaleAbove_actionPerformed(ActionEvent e)
2672 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2673 alignPanel.paintAlignment(true);
2682 protected void scaleLeft_actionPerformed(ActionEvent e)
2684 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2685 alignPanel.paintAlignment(true);
2694 protected void scaleRight_actionPerformed(ActionEvent e)
2696 viewport.setScaleRightWrapped(scaleRight.isSelected());
2697 alignPanel.paintAlignment(true);
2706 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2708 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2709 alignPanel.paintAlignment(true);
2718 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2720 viewport.setShowText(viewTextMenuItem.isSelected());
2721 alignPanel.paintAlignment(true);
2730 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2732 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2733 alignPanel.paintAlignment(true);
2736 public FeatureSettings featureSettings;
2738 public void featureSettings_actionPerformed(ActionEvent e)
2740 if (featureSettings != null)
2742 featureSettings.close();
2743 featureSettings = null;
2745 if (!showSeqFeatures.isSelected())
2747 // make sure features are actually displayed
2748 showSeqFeatures.setSelected(true);
2749 showSeqFeatures_actionPerformed(null);
2751 featureSettings = new FeatureSettings(this);
2755 * Set or clear 'Show Sequence Features'
2760 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2762 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2763 alignPanel.paintAlignment(true);
2764 if (alignPanel.getOverviewPanel() != null)
2766 alignPanel.getOverviewPanel().updateOverviewImage();
2771 * Set or clear 'Show Sequence Features'
2776 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2778 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2780 if (viewport.getShowSequenceFeaturesHeight())
2782 // ensure we're actually displaying features
2783 viewport.setShowSequenceFeatures(true);
2784 showSeqFeatures.setSelected(true);
2786 alignPanel.paintAlignment(true);
2787 if (alignPanel.getOverviewPanel() != null)
2789 alignPanel.getOverviewPanel().updateOverviewImage();
2799 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2801 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2802 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2805 public void alignmentProperties()
2807 JEditorPane editPane = new JEditorPane("text/html", "");
2808 editPane.setEditable(false);
2809 StringBuffer contents = new AlignmentProperties(viewport.alignment)
2811 editPane.setText("<html>" + contents.toString() + "</html>");
2812 JInternalFrame frame = new JInternalFrame();
2813 frame.getContentPane().add(new JScrollPane(editPane));
2815 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2816 + getTitle(), 500, 400);
2825 public void overviewMenuItem_actionPerformed(ActionEvent e)
2827 if (alignPanel.overviewPanel != null)
2832 JInternalFrame frame = new JInternalFrame();
2833 OverviewPanel overview = new OverviewPanel(alignPanel);
2834 frame.setContentPane(overview);
2835 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2836 frame.getWidth(), frame.getHeight());
2838 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2839 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2841 public void internalFrameClosed(
2842 javax.swing.event.InternalFrameEvent evt)
2844 alignPanel.setOverviewPanel(null);
2848 alignPanel.setOverviewPanel(overview);
2851 public void textColour_actionPerformed(ActionEvent e)
2853 new TextColourChooser().chooseColour(alignPanel, null);
2862 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2873 public void clustalColour_actionPerformed(ActionEvent e)
2875 changeColour(new ClustalxColourScheme(
2876 viewport.alignment.getSequences(),
2877 viewport.alignment.getWidth()));
2886 public void zappoColour_actionPerformed(ActionEvent e)
2888 changeColour(new ZappoColourScheme());
2897 public void taylorColour_actionPerformed(ActionEvent e)
2899 changeColour(new TaylorColourScheme());
2908 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2910 changeColour(new HydrophobicColourScheme());
2919 public void helixColour_actionPerformed(ActionEvent e)
2921 changeColour(new HelixColourScheme());
2930 public void strandColour_actionPerformed(ActionEvent e)
2932 changeColour(new StrandColourScheme());
2941 public void turnColour_actionPerformed(ActionEvent e)
2943 changeColour(new TurnColourScheme());
2952 public void buriedColour_actionPerformed(ActionEvent e)
2954 changeColour(new BuriedColourScheme());
2963 public void nucleotideColour_actionPerformed(ActionEvent e)
2965 changeColour(new NucleotideColourScheme());
2968 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
2970 changeColour(new PurinePyrimidineColourScheme());
2973 public void covariationColour_actionPerformed(ActionEvent e)
2975 changeColour(new CovariationColourScheme(viewport.alignment.getAlignmentAnnotation()[0]));
2978 public void annotationColour_actionPerformed(ActionEvent e)
2980 new AnnotationColourChooser(viewport, alignPanel);
2983 public void rnahelicesColour_actionPerformed(ActionEvent e)
2985 new RNAHelicesColourChooser(viewport, alignPanel);
2994 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2996 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3005 public void changeColour(ColourSchemeI cs)
3011 if (viewport.getAbovePIDThreshold())
3013 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3016 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3018 viewport.setGlobalColourScheme(cs);
3022 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3025 if (viewport.getConservationSelected())
3028 Alignment al = (Alignment) viewport.alignment;
3029 Conservation c = new Conservation("All",
3030 ResidueProperties.propHash, 3, al.getSequences(), 0,
3034 c.verdict(false, viewport.ConsPercGaps);
3036 cs.setConservation(c);
3038 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3043 cs.setConservation(null);
3046 cs.setConsensus(viewport.hconsensus);
3049 viewport.setGlobalColourScheme(cs);
3051 if (viewport.getColourAppliesToAllGroups())
3053 Vector groups = viewport.alignment.getGroups();
3055 for (int i = 0; i < groups.size(); i++)
3057 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
3065 if (cs instanceof ClustalxColourScheme)
3067 sg.cs = new ClustalxColourScheme(
3068 sg.getSequences(viewport.hiddenRepSequences),
3071 else if (cs instanceof UserColourScheme)
3073 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3079 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
3080 } catch (Exception ex)
3085 if (viewport.getAbovePIDThreshold()
3086 || cs instanceof PIDColourScheme
3087 || cs instanceof Blosum62ColourScheme)
3089 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3091 sg.cs.setConsensus(AAFrequency.calculate(
3092 sg.getSequences(viewport.hiddenRepSequences),
3093 sg.getStartRes(), sg.getEndRes() + 1));
3097 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3100 if (viewport.getConservationSelected())
3102 Conservation c = new Conservation("Group",
3103 ResidueProperties.propHash, 3,
3104 sg.getSequences(viewport.hiddenRepSequences),
3105 sg.getStartRes(), sg.getEndRes() + 1);
3107 c.verdict(false, viewport.ConsPercGaps);
3108 sg.cs.setConservation(c);
3112 sg.cs.setConservation(null);
3117 if (alignPanel.getOverviewPanel() != null)
3119 alignPanel.getOverviewPanel().updateOverviewImage();
3122 alignPanel.paintAlignment(true);
3131 protected void modifyPID_actionPerformed(ActionEvent e)
3133 if (viewport.getAbovePIDThreshold()
3134 && viewport.globalColourScheme != null)
3136 SliderPanel.setPIDSliderSource(alignPanel,
3137 viewport.getGlobalColourScheme(), "Background");
3138 SliderPanel.showPIDSlider();
3148 protected void modifyConservation_actionPerformed(ActionEvent e)
3150 if (viewport.getConservationSelected()
3151 && viewport.globalColourScheme != null)
3153 SliderPanel.setConservationSlider(alignPanel,
3154 viewport.globalColourScheme, "Background");
3155 SliderPanel.showConservationSlider();
3165 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3167 viewport.setConservationSelected(conservationMenuItem.isSelected());
3169 viewport.setAbovePIDThreshold(false);
3170 abovePIDThreshold.setSelected(false);
3172 changeColour(viewport.getGlobalColourScheme());
3174 modifyConservation_actionPerformed(null);
3183 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3185 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3187 conservationMenuItem.setSelected(false);
3188 viewport.setConservationSelected(false);
3190 changeColour(viewport.getGlobalColourScheme());
3192 modifyPID_actionPerformed(null);
3201 public void userDefinedColour_actionPerformed(ActionEvent e)
3203 if (e.getActionCommand().equals("User Defined..."))
3205 new UserDefinedColours(alignPanel, null);
3209 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3210 .getUserColourSchemes().get(e.getActionCommand());
3216 public void updateUserColourMenu()
3219 Component[] menuItems = colourMenu.getMenuComponents();
3220 int i, iSize = menuItems.length;
3221 for (i = 0; i < iSize; i++)
3223 if (menuItems[i].getName() != null
3224 && menuItems[i].getName().equals("USER_DEFINED"))
3226 colourMenu.remove(menuItems[i]);
3230 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3232 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3233 .getUserColourSchemes().keys();
3235 while (userColours.hasMoreElements())
3237 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3238 userColours.nextElement().toString());
3239 radioItem.setName("USER_DEFINED");
3240 radioItem.addMouseListener(new MouseAdapter()
3242 public void mousePressed(MouseEvent evt)
3244 if (evt.isControlDown()
3245 || SwingUtilities.isRightMouseButton(evt))
3247 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3249 int option = JOptionPane.showInternalConfirmDialog(
3250 jalview.gui.Desktop.desktop,
3251 "Remove from default list?",
3252 "Remove user defined colour",
3253 JOptionPane.YES_NO_OPTION);
3254 if (option == JOptionPane.YES_OPTION)
3256 jalview.gui.UserDefinedColours
3257 .removeColourFromDefaults(radioItem.getText());
3258 colourMenu.remove(radioItem);
3262 radioItem.addActionListener(new ActionListener()
3264 public void actionPerformed(ActionEvent evt)
3266 userDefinedColour_actionPerformed(evt);
3273 radioItem.addActionListener(new ActionListener()
3275 public void actionPerformed(ActionEvent evt)
3277 userDefinedColour_actionPerformed(evt);
3281 colourMenu.insert(radioItem, 15);
3282 colours.add(radioItem);
3293 public void PIDColour_actionPerformed(ActionEvent e)
3295 changeColour(new PIDColourScheme());
3304 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3306 changeColour(new Blosum62ColourScheme());
3315 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3317 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3318 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3319 .getAlignment().getSequenceAt(0), null);
3320 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3321 viewport.alignment));
3322 alignPanel.paintAlignment(true);
3331 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3333 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3334 AlignmentSorter.sortByID(viewport.getAlignment());
3335 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
3336 alignPanel.paintAlignment(true);
3345 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3347 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3348 AlignmentSorter.sortByLength(viewport.getAlignment());
3349 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3350 viewport.alignment));
3351 alignPanel.paintAlignment(true);
3360 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3362 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3363 AlignmentSorter.sortByGroup(viewport.getAlignment());
3364 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3365 viewport.alignment));
3367 alignPanel.paintAlignment(true);
3376 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3378 new RedundancyPanel(alignPanel, this);
3387 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3389 if ((viewport.getSelectionGroup() == null)
3390 || (viewport.getSelectionGroup().getSize() < 2))
3392 JOptionPane.showInternalMessageDialog(this,
3393 "You must select at least 2 sequences.", "Invalid Selection",
3394 JOptionPane.WARNING_MESSAGE);
3398 JInternalFrame frame = new JInternalFrame();
3399 frame.setContentPane(new PairwiseAlignPanel(viewport));
3400 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3410 public void PCAMenuItem_actionPerformed(ActionEvent e)
3412 if (((viewport.getSelectionGroup() != null)
3413 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3414 .getSelectionGroup().getSize() > 0))
3415 || (viewport.getAlignment().getHeight() < 4))
3417 JOptionPane.showInternalMessageDialog(this,
3418 "Principal component analysis must take\n"
3419 + "at least 4 input sequences.",
3420 "Sequence selection insufficient",
3421 JOptionPane.WARNING_MESSAGE);
3426 new PCAPanel(alignPanel);
3429 public void autoCalculate_actionPerformed(ActionEvent e)
3431 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3432 if (viewport.autoCalculateConsensus)
3434 viewport.firePropertyChange("alignment", null, viewport
3435 .getAlignment().getSequences());
3445 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3447 NewTreePanel("AV", "PID", "Average distance tree using PID");
3456 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3458 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3467 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3469 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3478 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3480 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3493 void NewTreePanel(String type, String pwType, String title)
3497 if (viewport.getSelectionGroup() != null)
3499 if (viewport.getSelectionGroup().getSize() < 3)
3504 "You need to have more than two sequences selected to build a tree!",
3505 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3510 SequenceGroup sg = viewport.getSelectionGroup();
3512 /* Decide if the selection is a column region */
3513 while (s < sg.getSize())
3515 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3521 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3522 + "Try using the Pad function in the edit menu,\n"
3523 + "or one of the multiple sequence alignment web services.",
3524 "Sequences in selection are not aligned",
3525 JOptionPane.WARNING_MESSAGE);
3531 title = title + " on region";
3532 tp = new TreePanel(alignPanel, type, pwType);
3536 // are the visible sequences aligned?
3537 if (!viewport.alignment.isAligned(false))
3542 "The sequences must be aligned before creating a tree.\n"
3543 + "Try using the Pad function in the edit menu,\n"
3544 + "or one of the multiple sequence alignment web services.",
3545 "Sequences not aligned",
3546 JOptionPane.WARNING_MESSAGE);
3551 if (viewport.alignment.getHeight() < 2)
3556 tp = new TreePanel(alignPanel, type, pwType);
3561 if (viewport.viewName != null)
3563 title += viewport.viewName + " of ";
3566 title += this.title;
3568 Desktop.addInternalFrame(tp, title, 600, 500);
3579 public void addSortByOrderMenuItem(String title,
3580 final AlignmentOrder order)
3582 final JMenuItem item = new JMenuItem("by " + title);
3584 item.addActionListener(new java.awt.event.ActionListener()
3586 public void actionPerformed(ActionEvent e)
3588 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3590 // TODO: JBPNote - have to map order entries to curent SequenceI
3592 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3594 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3595 viewport.alignment));
3597 alignPanel.paintAlignment(true);
3603 * Add a new sort by annotation score menu item
3606 * the menu to add the option to
3608 * the label used to retrieve scores for each sequence on the
3611 public void addSortByAnnotScoreMenuItem(JMenu sort,
3612 final String scoreLabel)
3614 final JMenuItem item = new JMenuItem(scoreLabel);
3616 item.addActionListener(new java.awt.event.ActionListener()
3618 public void actionPerformed(ActionEvent e)
3620 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3621 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3622 viewport.getAlignment());// ,viewport.getSelectionGroup());
3623 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3624 viewport.alignment));
3625 alignPanel.paintAlignment(true);
3631 * last hash for alignment's annotation array - used to minimise cost of
3634 protected int _annotationScoreVectorHash;
3637 * search the alignment and rebuild the sort by annotation score submenu the
3638 * last alignment annotation vector hash is stored to minimize cost of
3639 * rebuilding in subsequence calls.
3642 public void buildSortByAnnotationScoresMenu()
3644 if (viewport.alignment.getAlignmentAnnotation() == null)
3649 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3651 sortByAnnotScore.removeAll();
3652 // almost certainly a quicker way to do this - but we keep it simple
3653 Hashtable scoreSorts = new Hashtable();
3654 AlignmentAnnotation aann[];
3655 Enumeration sq = viewport.alignment.getSequences().elements();
3656 while (sq.hasMoreElements())
3658 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3659 for (int i = 0; aann != null && i < aann.length; i++)
3661 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3663 scoreSorts.put(aann[i].label, aann[i].label);
3667 Enumeration labels = scoreSorts.keys();
3668 while (labels.hasMoreElements())
3670 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3671 (String) labels.nextElement());
3673 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3676 _annotationScoreVectorHash = viewport.alignment
3677 .getAlignmentAnnotation().hashCode();
3682 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3683 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3684 * call. Listeners are added to remove the menu item when the treePanel is
3685 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3689 * Displayed tree window.
3691 * SortBy menu item title.
3693 public void buildTreeMenu()
3695 sortByTreeMenu.removeAll();
3697 Vector comps = (Vector) PaintRefresher.components.get(viewport
3698 .getSequenceSetId());
3699 Vector treePanels = new Vector();
3700 int i, iSize = comps.size();
3701 for (i = 0; i < iSize; i++)
3703 if (comps.elementAt(i) instanceof TreePanel)
3705 treePanels.add(comps.elementAt(i));
3709 iSize = treePanels.size();
3713 sortByTreeMenu.setVisible(false);
3717 sortByTreeMenu.setVisible(true);
3719 for (i = 0; i < treePanels.size(); i++)
3721 TreePanel tp = (TreePanel) treePanels.elementAt(i);
3722 final JMenuItem item = new JMenuItem(tp.getTitle());
3723 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3724 item.addActionListener(new java.awt.event.ActionListener()
3726 public void actionPerformed(ActionEvent e)
3728 SequenceI[] oldOrder = viewport.getAlignment()
3729 .getSequencesArray();
3730 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3732 addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
3733 viewport.alignment));
3735 alignPanel.paintAlignment(true);
3739 sortByTreeMenu.add(item);
3743 public boolean sortBy(AlignmentOrder alorder, String undoname)
3745 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3746 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3747 if (undoname != null)
3749 addHistoryItem(new OrderCommand(undoname, oldOrder,
3750 viewport.alignment));
3752 alignPanel.paintAlignment(true);
3757 * Work out whether the whole set of sequences or just the selected set will
3758 * be submitted for multiple alignment.
3761 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3763 // Now, check we have enough sequences
3764 AlignmentView msa = null;
3766 if ((viewport.getSelectionGroup() != null)
3767 && (viewport.getSelectionGroup().getSize() > 1))
3769 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3770 // some common interface!
3772 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3773 * SequenceI[sz = seqs.getSize(false)];
3775 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3776 * seqs.getSequenceAt(i); }
3778 msa = viewport.getAlignmentView(true);
3783 * Vector seqs = viewport.getAlignment().getSequences();
3785 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3787 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3788 * seqs.elementAt(i); } }
3790 msa = viewport.getAlignmentView(false);
3796 * Decides what is submitted to a secondary structure prediction service: the
3797 * first sequence in the alignment, or in the current selection, or, if the
3798 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3799 * region or the whole alignment. (where the first sequence in the set is the
3800 * one that the prediction will be for).
3802 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3804 AlignmentView seqs = null;
3806 if ((viewport.getSelectionGroup() != null)
3807 && (viewport.getSelectionGroup().getSize() > 0))
3809 seqs = viewport.getAlignmentView(true);
3813 seqs = viewport.getAlignmentView(false);
3815 // limit sequences - JBPNote in future - could spawn multiple prediction
3817 // TODO: viewport.alignment.isAligned is a global state - the local
3818 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3819 if (!viewport.alignment.isAligned(false))
3821 seqs.setSequences(new SeqCigar[]
3822 { seqs.getSequences()[0] });
3823 // TODO: if seqs.getSequences().length>1 then should really have warned
3836 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3838 // Pick the tree file
3839 JalviewFileChooser chooser = new JalviewFileChooser(
3840 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3841 chooser.setFileView(new JalviewFileView());
3842 chooser.setDialogTitle("Select a newick-like tree file");
3843 chooser.setToolTipText("Load a tree file");
3845 int value = chooser.showOpenDialog(null);
3847 if (value == JalviewFileChooser.APPROVE_OPTION)
3849 String choice = chooser.getSelectedFile().getPath();
3850 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3851 jalview.io.NewickFile fin = null;
3854 fin = new jalview.io.NewickFile(choice, "File");
3855 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3856 } catch (Exception ex)
3858 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3859 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3860 ex.printStackTrace();
3862 if (fin != null && fin.hasWarningMessage())
3864 JOptionPane.showMessageDialog(Desktop.desktop,
3865 fin.getWarningMessage(), "Possible problem with tree file",
3866 JOptionPane.WARNING_MESSAGE);
3871 public TreePanel ShowNewickTree(NewickFile nf, String title)
3873 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3876 public TreePanel ShowNewickTree(NewickFile nf, String title,
3877 AlignmentView input)
3879 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3882 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3883 int h, int x, int y)
3885 return ShowNewickTree(nf, title, null, w, h, x, y);
3889 * Add a treeviewer for the tree extracted from a newick file object to the
3890 * current alignment view
3897 * Associated alignment input data (or null)
3906 * @return TreePanel handle
3908 public TreePanel ShowNewickTree(NewickFile nf, String title,
3909 AlignmentView input, int w, int h, int x, int y)
3911 TreePanel tp = null;
3917 if (nf.getTree() != null)
3919 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3925 tp.setLocation(x, y);
3928 Desktop.addInternalFrame(tp, title, w, h);
3930 } catch (Exception ex)
3932 ex.printStackTrace();
3938 private boolean buildingMenu = false;
3941 * Generates menu items and listener event actions for web service clients
3944 public void BuildWebServiceMenu()
3946 while (buildingMenu)
3950 System.err.println("Waiting for building menu to finish.");
3952 } catch (Exception e)
3957 final AlignFrame me = this;
3958 buildingMenu = true;
3959 new Thread(new Runnable()
3965 System.err.println("Building ws menu again "
3966 + Thread.currentThread());
3967 // TODO: add support for context dependent disabling of services based
3969 // alignment and current selection
3970 // TODO: add additional serviceHandle parameter to specify abstract
3972 // class independently of AbstractName
3973 // TODO: add in rediscovery GUI function to restart discoverer
3974 // TODO: group services by location as well as function and/or
3976 // object broker mechanism.
3977 final Vector wsmenu = new Vector();
3978 final IProgressIndicator af = me;
3979 if (Cache.getDefault("SHOW_JWS1_SERVICES", true)
3980 && Discoverer.services != null
3981 && (Discoverer.services.size() > 0))
3983 // TODO: refactor to allow list of AbstractName/Handler bindings to
3985 // stored or retrieved from elsewhere
3986 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3987 Vector secstrpr = (Vector) Discoverer.services
3989 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3990 // TODO: move GUI generation code onto service implementation - so a
3991 // client instance attaches itself to the GUI with method call like
3992 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
3996 // Add any Multiple Sequence Alignment Services
3997 final JMenu msawsmenu = new JMenu("Alignment");
3998 for (int i = 0, j = msaws.size(); i < j; i++)
4000 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4002 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4003 .getServiceClient(sh);
4004 impl.attachWSMenuEntry(msawsmenu, me);
4007 wsmenu.add(msawsmenu);
4009 if (secstrpr != null)
4011 // Add any secondary structure prediction services
4012 final JMenu secstrmenu = new JMenu(
4013 "Secondary Structure Prediction");
4014 for (int i = 0, j = secstrpr.size(); i < j; i++)
4016 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4018 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4019 .getServiceClient(sh);
4020 impl.attachWSMenuEntry(secstrmenu, me);
4022 wsmenu.add(secstrmenu);
4024 if (seqsrch != null)
4026 // Add any sequence search services
4027 final JMenu seqsrchmenu = new JMenu(
4028 "Sequence Database Search");
4029 for (int i = 0, j = seqsrch.size(); i < j; i++)
4031 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4033 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4034 .getServiceClient(sh);
4035 impl.attachWSMenuEntry(seqsrchmenu, me);
4037 wsmenu.add(seqsrchmenu);
4041 // TODO: move into separate menu builder class.
4042 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4044 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4045 if (jws2servs != null)
4047 if (jws2servs.hasServices())
4049 JMenu jws2men = new JMenu("Jaba Web Services");
4050 jws2servs.attachWSMenuEntry(jws2men, me);
4051 for (int i = 0, iSize = jws2men.getMenuComponentCount(); i < iSize; i++)
4053 wsmenu.add(jws2men.getMenuComponent(i));
4059 javax.swing.SwingUtilities.invokeLater(new Runnable()
4066 resetWebServiceMenu();
4067 // finally, add the whole shebang onto the webservices menu
4068 if (wsmenu.size() > 0)
4070 for (int i = 0, j = wsmenu.size(); i < j; i++)
4072 webService.add((JMenu) wsmenu.get(i));
4077 me.webService.add(me.webServiceNoServices);
4079 } catch (Exception e)
4085 } catch (Exception e)
4090 buildingMenu = false;
4097 * empty the web service menu and add any ad-hoc functions not dynamically
4101 private void resetWebServiceMenu()
4103 webService.removeAll();
4104 build_fetchdbmenu(webService);
4105 build_urlServiceMenu(webService);
4109 * construct any groupURL type service menu entries.
4113 private void build_urlServiceMenu(JMenu webService)
4115 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4117 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4120 // TODO: remove this code when 2.7 is released
4121 // DEBUG - alignmentView
4123 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4124 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4126 * @Override public void actionPerformed(ActionEvent e) {
4127 * jalview.datamodel.AlignmentView.testSelectionViews(af.viewport.alignment,
4128 * af.viewport.colSel, af.viewport.selectionGroup); }
4130 * }); webService.add(testAlView);
4132 // TODO: refactor to RestClient discoverer and merge menu entries for
4133 // rest-style services with other types of analysis/calculation service
4134 // SHmmr test client - still being implemented.
4135 jalview.ws.rest.RestClient.makeShmmrRestClient().attachWSMenuEntry(
4137 // DEBUG - alignmentView
4141 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4142 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4143 * getProperty("LAST_DIRECTORY"));
4145 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4146 * to Vamsas file"); chooser.setToolTipText("Export");
4148 * int value = chooser.showSaveDialog(this);
4150 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4151 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4152 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4153 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4156 * prototype of an automatically enabled/disabled analysis function
4159 protected void setShowProductsEnabled()
4161 SequenceI[] selection = viewport.getSequenceSelection();
4162 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4163 viewport.getAlignment().getDataset()))
4165 showProducts.setEnabled(true);
4170 showProducts.setEnabled(false);
4175 * search selection for sequence xRef products and build the show products
4180 * @return true if showProducts menu should be enabled.
4182 public boolean canShowProducts(SequenceI[] selection,
4183 boolean isRegionSelection, Alignment dataset)
4185 boolean showp = false;
4188 showProducts.removeAll();
4189 final boolean dna = viewport.getAlignment().isNucleotide();
4190 final Alignment ds = dataset;
4191 String[] ptypes = (selection == null || selection.length == 0) ? null
4192 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4194 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4195 // selection, dataset, true);
4196 final SequenceI[] sel = selection;
4197 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4200 final boolean isRegSel = isRegionSelection;
4201 final AlignFrame af = this;
4202 final String source = ptypes[t];
4203 JMenuItem xtype = new JMenuItem(ptypes[t]);
4204 xtype.addActionListener(new ActionListener()
4207 public void actionPerformed(ActionEvent e)
4209 // TODO: new thread for this call with vis-delay
4210 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4211 isRegSel, dna, source);
4215 showProducts.add(xtype);
4217 showProducts.setVisible(showp);
4218 showProducts.setEnabled(showp);
4219 } catch (Exception e)
4221 jalview.bin.Cache.log
4222 .warn("canTranslate threw an exception - please report to help@jalview.org",
4229 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4230 boolean isRegSel, boolean dna, String source)
4232 final boolean fisRegSel = isRegSel;
4233 final boolean fdna = dna;
4234 final String fsrc = source;
4235 final AlignFrame ths = this;
4236 final SequenceI[] fsel = sel;
4237 Runnable foo = new Runnable()
4242 final long sttime = System.currentTimeMillis();
4243 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4246 Alignment ds = ths.getViewport().alignment.getDataset(); // update
4250 Alignment prods = CrossRef
4251 .findXrefSequences(fsel, fdna, fsrc, ds);
4254 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4255 for (int s = 0; s < sprods.length; s++)
4257 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4258 if (ds.getSequences() == null
4259 || !ds.getSequences().contains(
4260 sprods[s].getDatasetSequence()))
4261 ds.addSequence(sprods[s].getDatasetSequence());
4262 sprods[s].updatePDBIds();
4264 Alignment al = new Alignment(sprods);
4265 AlignedCodonFrame[] cf = prods.getCodonFrames();
4267 for (int s = 0; cf != null && s < cf.length; s++)
4269 al.addCodonFrame(cf[s]);
4272 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4274 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4275 + " for " + ((fisRegSel) ? "selected region of " : "")
4277 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4282 System.err.println("No Sequences generated for xRef type "
4285 } catch (Exception e)
4287 jalview.bin.Cache.log.error(
4288 "Exception when finding crossreferences", e);
4289 } catch (OutOfMemoryError e)
4291 new OOMWarning("whilst fetching crossreferences", e);
4294 jalview.bin.Cache.log.error("Error when finding crossreferences",
4297 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4302 Thread frunner = new Thread(foo);
4306 public boolean canShowTranslationProducts(SequenceI[] selection,
4307 AlignmentI alignment)
4312 return (jalview.analysis.Dna.canTranslate(selection,
4313 viewport.getViewAsVisibleContigs(true)));
4314 } catch (Exception e)
4316 jalview.bin.Cache.log
4317 .warn("canTranslate threw an exception - please report to help@jalview.org",
4323 public void showProducts_actionPerformed(ActionEvent e)
4325 // /////////////////////////////
4326 // Collect Data to be translated/transferred
4328 SequenceI[] selection = viewport.getSequenceSelection();
4329 AlignmentI al = null;
4332 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4333 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4334 viewport.getAlignment().getDataset());
4335 } catch (Exception ex)
4338 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4345 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4346 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4350 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4351 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4352 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4356 public void showTranslation_actionPerformed(ActionEvent e)
4358 // /////////////////////////////
4359 // Collect Data to be translated/transferred
4361 SequenceI[] selection = viewport.getSequenceSelection();
4362 String[] seqstring = viewport.getViewAsString(true);
4363 AlignmentI al = null;
4366 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4367 viewport.getViewAsVisibleContigs(true), viewport
4368 .getGapCharacter(), viewport.alignment
4369 .getAlignmentAnnotation(), viewport.alignment
4370 .getWidth(), viewport.getAlignment().getDataset());
4371 } catch (Exception ex)
4374 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4381 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4382 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4386 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4387 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4388 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4393 * Try to load a features file onto the alignment.
4396 * contents or path to retrieve file
4398 * access mode of file (see jalview.io.AlignFile)
4399 * @return true if features file was parsed corectly.
4401 public boolean parseFeaturesFile(String file, String type)
4403 boolean featuresFile = false;
4406 featuresFile = new FeaturesFile(file, type)
4407 .parse(viewport.alignment.getDataset(),
4408 alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
4409 false, jalview.bin.Cache.getDefault(
4410 "RELAXEDSEQIDMATCHING", false));
4411 } catch (Exception ex)
4413 ex.printStackTrace();
4418 viewport.showSequenceFeatures = true;
4419 showSeqFeatures.setSelected(true);
4420 if (alignPanel.seqPanel.seqCanvas.fr != null)
4422 // update the min/max ranges where necessary
4423 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4425 if (featureSettings != null)
4427 featureSettings.setTableData();
4429 alignPanel.paintAlignment(true);
4432 return featuresFile;
4435 public void dragEnter(DropTargetDragEvent evt)
4439 public void dragExit(DropTargetEvent evt)
4443 public void dragOver(DropTargetDragEvent evt)
4447 public void dropActionChanged(DropTargetDragEvent evt)
4451 public void drop(DropTargetDropEvent evt)
4453 Transferable t = evt.getTransferable();
4454 java.util.List files = null;
4458 DataFlavor uriListFlavor = new DataFlavor(
4459 "text/uri-list;class=java.lang.String");
4460 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4462 // Works on Windows and MacOSX
4463 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4464 files = (java.util.List) t
4465 .getTransferData(DataFlavor.javaFileListFlavor);
4467 else if (t.isDataFlavorSupported(uriListFlavor))
4469 // This is used by Unix drag system
4470 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4471 String data = (String) t.getTransferData(uriListFlavor);
4472 files = new java.util.ArrayList(1);
4473 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4474 data, "\r\n"); st.hasMoreTokens();)
4476 String s = st.nextToken();
4477 if (s.startsWith("#"))
4479 // the line is a comment (as per the RFC 2483)
4483 java.net.URI uri = new java.net.URI(s);
4484 // check to see if we can handle this kind of URI
4485 if (uri.getScheme().toLowerCase().startsWith("http"))
4487 files.add(uri.toString());
4491 // otherwise preserve old behaviour: catch all for file objects
4492 java.io.File file = new java.io.File(uri);
4493 files.add(file.toString());
4497 } catch (Exception e)
4499 e.printStackTrace();
4505 // check to see if any of these files have names matching sequences in
4507 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4508 .getAlignment().getSequencesArray());
4510 * Object[] { String,SequenceI}
4512 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4513 ArrayList<String> filesnotmatched = new ArrayList<String>();
4514 for (int i = 0; i < files.size(); i++)
4516 String file = files.get(i).toString();
4518 String protocol = FormatAdapter.checkProtocol(file);
4519 if (protocol == jalview.io.FormatAdapter.FILE)
4521 File fl = new File(file);
4522 pdbfn = fl.getName();
4524 else if (protocol == jalview.io.FormatAdapter.URL)
4526 URL url = new URL(file);
4527 pdbfn = url.getFile();
4529 if (pdbfn.length() > 0)
4531 // attempt to find a match in the alignment
4532 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4533 int l = 0, c = pdbfn.indexOf(".");
4534 while (mtch == null && c != -1)
4539 } while ((c = pdbfn.indexOf(".", l)) > l);
4542 pdbfn = pdbfn.substring(0, l);
4544 mtch = idm.findAllIdMatches(pdbfn);
4551 type = new IdentifyFile().Identify(file, protocol);
4552 } catch (Exception ex)
4558 if (type.equalsIgnoreCase("PDB"))
4560 filesmatched.add(new Object[]
4561 { file, protocol, mtch });
4566 // File wasn't named like one of the sequences or wasn't a PDB file.
4567 filesnotmatched.add(file);
4571 if (filesmatched.size() > 0)
4573 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4577 "Do you want to automatically associate the "
4578 + filesmatched.size()
4579 + " PDB files with sequences in the alignment that have the same name ?",
4580 "Automatically Associate PDB files by name",
4581 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4584 for (Object[] fm : filesmatched)
4586 // try and associate
4587 // TODO: may want to set a standard ID naming formalism for
4588 // associating PDB files which have no IDs.
4589 for (SequenceI toassoc: (SequenceI[])fm[2]) {
4590 PDBEntry pe = new AssociatePdbFileWithSeq()
4591 .associatePdbWithSeq((String) fm[0], (String) fm[1],
4596 .println("Associated file : " + ((String) fm[0])
4598 + toassoc.getDisplayId(true));
4602 alignPanel.paintAlignment(true);
4606 if (filesnotmatched.size() > 0)
4609 && (Cache.getDefault(
4610 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4613 "<html>Do you want to <em>ignore</em> the "
4614 + filesnotmatched.size()
4615 + " files whose names did not match any sequence IDs ?</html>",
4616 "Ignore unmatched dropped files ?",
4617 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4621 for (String fn : filesnotmatched)
4623 loadJalviewDataFile(fn, null, null, null);
4627 } catch (Exception ex)
4629 ex.printStackTrace();
4635 * Attempt to load a "dropped" file or URL string: First by testing whether
4636 * it's and Annotation file, then a JNet file, and finally a features file. If
4637 * all are false then the user may have dropped an alignment file onto this
4641 * either a filename or a URL string.
4643 public void loadJalviewDataFile(String file, String protocol,
4644 String format, SequenceI assocSeq)
4648 if (protocol == null)
4650 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4652 // if the file isn't identified, or not positively identified as some
4653 // other filetype (PFAM is default unidentified alignment file type) then
4654 // try to parse as annotation.
4655 boolean isAnnotation = (format == null || format
4656 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4657 .readAnnotationFile(viewport.alignment, file, protocol)
4662 // try to see if its a JNet 'concise' style annotation file *before* we
4663 // try to parse it as a features file
4666 format = new IdentifyFile().Identify(file, protocol);
4668 if (format.equalsIgnoreCase("JnetFile"))
4670 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4672 new JnetAnnotationMaker().add_annotation(predictions,
4673 viewport.getAlignment(), 0, false);
4674 isAnnotation = true;
4679 * if (format.equalsIgnoreCase("PDB")) {
4681 * String pdbfn = ""; // try to match up filename with sequence id try
4682 * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new
4683 * File(file); pdbfn = fl.getName(); } else if (protocol ==
4684 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4685 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null)
4686 * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4687 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { //
4688 * attempt to find a match in the alignment SequenceI mtch =
4689 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4690 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l)
4691 * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch =
4692 * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate
4693 * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4694 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) {
4695 * System.err.println("Associated file : " + file + " with " +
4696 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4697 * TODO: maybe need to load as normal otherwise return; } }
4699 // try to parse it as a features file
4700 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4701 // if it wasn't a features file then we just treat it as a general
4702 // alignment file to load into the current view.
4705 new FileLoader().LoadFile(viewport, file, protocol, format);
4709 alignPanel.paintAlignment(true);
4716 alignPanel.adjustAnnotationHeight();
4717 viewport.updateSequenceIdColours();
4718 buildSortByAnnotationScoresMenu();
4719 alignPanel.paintAlignment(true);
4721 } catch (Exception ex)
4723 ex.printStackTrace();
4727 public void tabSelectionChanged(int index)
4731 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4732 viewport = alignPanel.av;
4733 setMenusFromViewport(viewport);
4737 public void tabbedPane_mousePressed(MouseEvent e)
4739 if (SwingUtilities.isRightMouseButton(e))
4741 String reply = JOptionPane.showInternalInputDialog(this,
4742 "Enter View Name", "Edit View Name",
4743 JOptionPane.QUESTION_MESSAGE);
4747 viewport.viewName = reply;
4748 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4753 public AlignViewport getCurrentView()
4759 * Open the dialog for regex description parsing.
4761 protected void extractScores_actionPerformed(ActionEvent e)
4763 ParseProperties pp = new jalview.analysis.ParseProperties(
4764 viewport.alignment);
4765 // TODO: verify regex and introduce GUI dialog for version 2.5
4766 // if (pp.getScoresFromDescription("col", "score column ",
4767 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4769 if (pp.getScoresFromDescription("description column",
4770 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4772 buildSortByAnnotationScoresMenu();
4780 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4783 protected void showDbRefs_actionPerformed(ActionEvent e)
4785 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4791 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4794 protected void showNpFeats_actionPerformed(ActionEvent e)
4796 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4800 * find the viewport amongst the tabs in this alignment frame and close that
4805 public boolean closeView(AlignViewport av)
4809 this.closeMenuItem_actionPerformed(false);
4812 Component[] comp = tabbedPane.getComponents();
4813 for (int i = 0; comp != null && i < comp.length; i++)
4815 if (comp[i] instanceof AlignmentPanel)
4817 if (((AlignmentPanel) comp[i]).av == av)
4820 closeView((AlignmentPanel) comp[i]);
4828 protected void build_fetchdbmenu(JMenu webService)
4830 // Temporary hack - DBRef Fetcher always top level ws entry.
4831 // TODO We probably want to store a sequence database checklist in
4832 // preferences and have checkboxes.. rather than individual sources selected
4834 final JMenu rfetch = new JMenu("Fetch DB References");
4835 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4836 webService.add(rfetch);
4838 JMenuItem fetchr = new JMenuItem("Standard Databases");
4839 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4840 fetchr.addActionListener(new ActionListener()
4843 public void actionPerformed(ActionEvent e)
4845 new Thread(new Runnable()
4850 new jalview.ws.DBRefFetcher(alignPanel.av
4851 .getSequenceSelection(), alignPanel.alignFrame)
4852 .fetchDBRefs(false);
4860 final AlignFrame me = this;
4861 new Thread(new Runnable()
4865 final jalview.ws.SequenceFetcher sf = SequenceFetcher
4866 .getSequenceFetcherSingleton(me);
4867 final String[] otherdb = sf.getOrderedSupportedSources();
4868 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4869 // jalview.util.QuickSort.sort(otherdb, otherdb);
4870 javax.swing.SwingUtilities.invokeLater(new Runnable()
4875 JMenu dfetch = new JMenu();
4878 int comp = 0, mcomp = 15;
4879 String mname = null;
4880 if (otherdb != null && otherdb.length > 0)
4882 for (int i = 0; i < otherdb.length; i++)
4884 String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
4887 mname = "from '" + dbname + "'";
4889 fetchr = new JMenuItem(otherdb[i]);
4890 final String[] dassource = new String[]
4892 fetchr.addActionListener(new ActionListener()
4895 public void actionPerformed(ActionEvent e)
4897 new Thread(new Runnable()
4902 new jalview.ws.DBRefFetcher(alignPanel.av
4903 .getSequenceSelection(),
4904 alignPanel.alignFrame, dassource)
4905 .fetchDBRefs(false);
4911 fetchr.setToolTipText("Retrieve from " + dbname);
4913 if (comp++ == mcomp || i == (otherdb.length - 1))
4915 dfetch.setText(mname + " to '" + dbname + "'");
4917 dfetch = new JMenu();
4931 * Left justify the whole alignment.
4933 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4935 AlignmentI al = viewport.getAlignment();
4937 viewport.firePropertyChange("alignment", null, al);
4941 * Right justify the whole alignment.
4943 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4945 AlignmentI al = viewport.getAlignment();
4947 viewport.firePropertyChange("alignment", null, al);
4950 public void setShowSeqFeatures(boolean b)
4952 showSeqFeatures.setSelected(true);
4953 viewport.setShowSequenceFeatures(true);
4960 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
4961 * awt.event.ActionEvent)
4963 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
4965 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
4966 alignPanel.paintAlignment(true);
4973 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
4976 protected void showGroupConsensus_actionPerformed(ActionEvent e)
4978 viewport.setShowGroupConsensus(showGroupConsensus.getState());
4979 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4987 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
4988 * .event.ActionEvent)
4990 protected void showGroupConservation_actionPerformed(ActionEvent e)
4992 viewport.setShowGroupConservation(showGroupConservation.getState());
4993 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5000 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5001 * .event.ActionEvent)
5003 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5005 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5006 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5013 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5014 * .event.ActionEvent)
5016 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5018 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5019 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5022 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5024 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5031 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5032 * .event.ActionEvent)
5034 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5036 if (viewport.getSelectionGroup() != null)
5038 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5039 viewport.getSequenceSelection(),
5040 viewport.getAlignmentView(true).getSequenceStrings(
5041 viewport.getGapCharacter()),
5042 viewport.alignment.getGroups());
5043 viewport.alignment.deleteAllGroups();
5044 viewport.sequenceColours = null;
5045 viewport.setSelectionGroup(null);
5046 // set view properties for each group
5047 for (int g = 0; g < gps.length; g++)
5049 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5050 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5051 viewport.alignment.addGroup(gps[g]);
5052 Color col = new Color((int) (Math.random() * 255),
5053 (int) (Math.random() * 255), (int) (Math.random() * 255));
5054 col = col.brighter();
5055 for (Enumeration sq = gps[g].getSequences(null).elements(); sq
5056 .hasMoreElements(); viewport.setSequenceColour(
5057 (SequenceI) sq.nextElement(), col))
5060 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5061 alignPanel.updateAnnotation();
5062 alignPanel.paintAlignment(true);
5067 * make the given alignmentPanel the currently selected tab
5069 * @param alignmentPanel
5071 public void setDisplayedView(AlignmentPanel alignmentPanel)
5073 if (!viewport.getSequenceSetId().equals(
5074 alignmentPanel.av.getSequenceSetId()))
5077 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5079 if (tabbedPane != null
5080 & alignPanels.indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5082 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5087 class PrintThread extends Thread
5091 public PrintThread(AlignmentPanel ap)
5096 static PageFormat pf;
5100 PrinterJob printJob = PrinterJob.getPrinterJob();
5104 printJob.setPrintable(ap, pf);
5108 printJob.setPrintable(ap);
5111 if (printJob.printDialog())
5116 } catch (Exception PrintException)
5118 PrintException.printStackTrace();