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());
406 if (viewport.cursorMode)
408 alignPanel.seqPanel.insertNucAtCursor(false,"A");
409 //System.out.println("A");
413 case KeyEvent.VK_CLOSE_BRACKET:
414 if (viewport.cursorMode)
416 System.out.println("closing bracket");
420 case KeyEvent.VK_DELETE:
421 case KeyEvent.VK_BACK_SPACE:
422 if (!viewport.cursorMode)
424 cut_actionPerformed(null);
428 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
429 || evt.isShiftDown() || evt.isAltDown());
435 if (viewport.cursorMode)
437 alignPanel.seqPanel.setCursorRow();
441 if (viewport.cursorMode && !evt.isControlDown())
443 alignPanel.seqPanel.setCursorColumn();
447 if (viewport.cursorMode)
449 alignPanel.seqPanel.setCursorPosition();
453 case KeyEvent.VK_ENTER:
454 case KeyEvent.VK_COMMA:
455 if (viewport.cursorMode)
457 alignPanel.seqPanel.setCursorRowAndColumn();
462 if (viewport.cursorMode)
464 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
468 if (viewport.cursorMode)
470 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
475 viewport.cursorMode = !viewport.cursorMode;
476 statusBar.setText("Keyboard editing mode is "
477 + (viewport.cursorMode ? "on" : "off"));
478 if (viewport.cursorMode)
480 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
481 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
483 alignPanel.seqPanel.seqCanvas.repaint();
489 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
490 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
492 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
494 javax.help.HelpBroker hb = hs.createHelpBroker();
495 hb.setCurrentID("home");
496 hb.setDisplayed(true);
497 } catch (Exception ex)
499 ex.printStackTrace();
504 boolean toggleSeqs = !evt.isControlDown();
505 boolean toggleCols = !evt.isShiftDown();
506 toggleHiddenRegions(toggleSeqs, toggleCols);
509 case KeyEvent.VK_PAGE_UP:
510 if (viewport.wrapAlignment)
512 alignPanel.scrollUp(true);
516 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
517 - viewport.endSeq + viewport.startSeq);
520 case KeyEvent.VK_PAGE_DOWN:
521 if (viewport.wrapAlignment)
523 alignPanel.scrollUp(false);
527 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
528 + viewport.endSeq - viewport.startSeq);
534 public void keyReleased(KeyEvent evt)
536 switch (evt.getKeyCode())
538 case KeyEvent.VK_LEFT:
539 if (evt.isAltDown() || !viewport.cursorMode)
540 viewport.firePropertyChange("alignment", null, viewport
541 .getAlignment().getSequences());
544 case KeyEvent.VK_RIGHT:
545 if (evt.isAltDown() || !viewport.cursorMode)
546 viewport.firePropertyChange("alignment", null, viewport
547 .getAlignment().getSequences());
554 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
556 ap.alignFrame = this;
558 alignPanels.addElement(ap);
560 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
562 int aSize = alignPanels.size();
564 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
566 if (aSize == 1 && ap.av.viewName == null)
568 this.getContentPane().add(ap, BorderLayout.CENTER);
574 setInitialTabVisible();
577 expandViews.setEnabled(true);
578 gatherViews.setEnabled(true);
579 tabbedPane.addTab(ap.av.viewName, ap);
581 ap.setVisible(false);
588 ap.av.alignment.padGaps();
590 ap.av.updateConservation(ap);
591 ap.av.updateConsensus(ap);
595 public void setInitialTabVisible()
597 expandViews.setEnabled(true);
598 gatherViews.setEnabled(true);
599 tabbedPane.setVisible(true);
600 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
601 tabbedPane.addTab(first.av.viewName, first);
602 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
605 public AlignViewport getViewport()
610 /* Set up intrinsic listeners for dynamically generated GUI bits. */
611 private void addServiceListeners()
613 final java.beans.PropertyChangeListener thisListener;
614 Desktop.instance.addJalviewPropertyChangeListener("services",
615 thisListener = new java.beans.PropertyChangeListener()
617 public void propertyChange(PropertyChangeEvent evt)
619 // // System.out.println("Discoverer property change.");
620 // if (evt.getPropertyName().equals("services"))
622 SwingUtilities.invokeLater(new Runnable()
628 .println("Rebuild WS Menu for service change");
629 BuildWebServiceMenu();
636 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
638 public void internalFrameClosed(
639 javax.swing.event.InternalFrameEvent evt)
641 System.out.println("deregistering discoverer listener");
642 Desktop.instance.removeJalviewPropertyChangeListener("services",
644 closeMenuItem_actionPerformed(true);
647 // Finally, build the menu once to get current service state
648 new Thread(new Runnable()
652 BuildWebServiceMenu();
657 public void setGUINucleotide(boolean nucleotide)
659 showTranslation.setVisible(nucleotide);
660 conservationMenuItem.setEnabled(!nucleotide);
661 modifyConservation.setEnabled(!nucleotide);
662 showGroupConservation.setEnabled(!nucleotide);
663 // Remember AlignFrame always starts as protein
666 calculateMenu.remove(calculateMenu.getItemCount() - 2);
671 * set up menus for the currently viewport. This may be called after any
672 * operation that affects the data in the current view (selection changed,
673 * etc) to update the menus to reflect the new state.
675 public void setMenusForViewport()
677 setMenusFromViewport(viewport);
681 * Need to call this method when tabs are selected for multiple views, or when
682 * loading from Jalview2XML.java
687 void setMenusFromViewport(AlignViewport av)
689 padGapsMenuitem.setSelected(av.padGaps);
690 colourTextMenuItem.setSelected(av.showColourText);
691 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
692 conservationMenuItem.setSelected(av.getConservationSelected());
693 seqLimits.setSelected(av.getShowJVSuffix());
694 idRightAlign.setSelected(av.rightAlignIds);
695 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
696 renderGapsMenuItem.setSelected(av.renderGaps);
697 wrapMenuItem.setSelected(av.wrapAlignment);
698 scaleAbove.setVisible(av.wrapAlignment);
699 scaleLeft.setVisible(av.wrapAlignment);
700 scaleRight.setVisible(av.wrapAlignment);
701 annotationPanelMenuItem.setState(av.showAnnotation);
702 viewBoxesMenuItem.setSelected(av.showBoxes);
703 viewTextMenuItem.setSelected(av.showText);
704 showNonconservedMenuItem.setSelected(av.showUnconserved);
705 showGroupConsensus.setSelected(av.showGroupConsensus);
706 showGroupConservation.setSelected(av.showGroupConservation);
707 showConsensusHistogram.setSelected(av.showConsensusHistogram);
708 showSequenceLogo.setSelected(av.showSequenceLogo);
709 setColourSelected(ColourSchemeProperty.getColourName(av
710 .getGlobalColourScheme()));
712 showSeqFeatures.setSelected(av.showSequenceFeatures);
713 hiddenMarkers.setState(av.showHiddenMarkers);
714 applyToAllGroups.setState(av.colourAppliesToAllGroups);
715 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
716 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
718 setShowProductsEnabled();
723 Hashtable progressBars, progressBarHandlers;
728 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
730 public void setProgressBar(String message, long id)
732 if (progressBars == null)
734 progressBars = new Hashtable();
735 progressBarHandlers = new Hashtable();
738 JPanel progressPanel;
739 Long lId = new Long(id);
740 GridLayout layout = (GridLayout) statusPanel.getLayout();
741 if (progressBars.get(lId) != null)
743 progressPanel = (JPanel) progressBars.get(new Long(id));
744 statusPanel.remove(progressPanel);
745 progressBars.remove(lId);
746 progressPanel = null;
749 statusBar.setText(message);
751 if (progressBarHandlers.contains(lId))
753 progressBarHandlers.remove(lId);
755 layout.setRows(layout.getRows() - 1);
759 progressPanel = new JPanel(new BorderLayout(10, 5));
761 JProgressBar progressBar = new JProgressBar();
762 progressBar.setIndeterminate(true);
764 progressPanel.add(new JLabel(message), BorderLayout.WEST);
765 progressPanel.add(progressBar, BorderLayout.CENTER);
767 layout.setRows(layout.getRows() + 1);
768 statusPanel.add(progressPanel);
770 progressBars.put(lId, progressPanel);
773 // setMenusForViewport();
777 public void registerHandler(final long id,
778 final IProgressIndicatorHandler handler)
780 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
783 "call setProgressBar before registering the progress bar's handler.");
785 progressBarHandlers.put(new Long(id), handler);
786 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
787 if (handler.canCancel())
789 JButton cancel = new JButton("Cancel");
790 final IProgressIndicator us = this;
791 cancel.addActionListener(new ActionListener()
794 public void actionPerformed(ActionEvent e)
796 handler.cancelActivity(id);
799 + ((JLabel) progressPanel.getComponent(0))
803 progressPanel.add(cancel, BorderLayout.EAST);
809 * @return true if any progress bars are still active
811 public boolean operationInProgress()
813 if (progressBars != null && progressBars.size() > 0)
821 * Added so Castor Mapping file can obtain Jalview Version
823 public String getVersion()
825 return jalview.bin.Cache.getProperty("VERSION");
828 public FeatureRenderer getFeatureRenderer()
830 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
833 public void fetchSequence_actionPerformed(ActionEvent e)
835 new SequenceFetcher(this);
838 public void addFromFile_actionPerformed(ActionEvent e)
840 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
843 public void reload_actionPerformed(ActionEvent e)
845 if (fileName != null)
847 // TODO: work out how to recover feature settings for correct view(s) when
849 if (currentFileFormat.equals("Jalview"))
851 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
852 for (int i = 0; i < frames.length; i++)
854 if (frames[i] instanceof AlignFrame && frames[i] != this
855 && ((AlignFrame) frames[i]).fileName.equals(fileName))
859 frames[i].setSelected(true);
860 Desktop.instance.closeAssociatedWindows();
861 } catch (java.beans.PropertyVetoException ex)
867 Desktop.instance.closeAssociatedWindows();
869 FileLoader loader = new FileLoader();
870 String protocol = fileName.startsWith("http:") ? "URL" : "File";
871 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
875 Rectangle bounds = this.getBounds();
877 FileLoader loader = new FileLoader();
878 String protocol = fileName.startsWith("http:") ? "URL" : "File";
879 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
880 protocol, currentFileFormat);
882 newframe.setBounds(bounds);
883 if (featureSettings != null && featureSettings.isShowing())
885 final Rectangle fspos = featureSettings.frame.getBounds();
886 // TODO: need a 'show feature settings' function that takes bounds -
887 // need to refactor Desktop.addFrame
888 newframe.featureSettings_actionPerformed(null);
889 final FeatureSettings nfs = newframe.featureSettings;
890 SwingUtilities.invokeLater(new Runnable()
894 nfs.frame.setBounds(fspos);
897 this.featureSettings.close();
898 this.featureSettings = null;
900 this.closeMenuItem_actionPerformed(true);
905 public void addFromText_actionPerformed(ActionEvent e)
907 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
910 public void addFromURL_actionPerformed(ActionEvent e)
912 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
915 public void save_actionPerformed(ActionEvent e)
918 || (currentFileFormat == null || !jalview.io.FormatAdapter
919 .isValidIOFormat(currentFileFormat, true))
920 || fileName.startsWith("http"))
922 saveAs_actionPerformed(null);
926 saveAlignment(fileName, currentFileFormat);
936 public void saveAs_actionPerformed(ActionEvent e)
938 JalviewFileChooser chooser = new JalviewFileChooser(
939 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
940 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
941 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
942 currentFileFormat, false);
944 chooser.setFileView(new JalviewFileView());
945 chooser.setDialogTitle("Save Alignment to file");
946 chooser.setToolTipText("Save");
948 int value = chooser.showSaveDialog(this);
950 if (value == JalviewFileChooser.APPROVE_OPTION)
952 currentFileFormat = chooser.getSelectedFormat();
953 if (currentFileFormat == null)
955 JOptionPane.showInternalMessageDialog(Desktop.desktop,
956 "You must select a file format before saving!",
957 "File format not specified", JOptionPane.WARNING_MESSAGE);
958 value = chooser.showSaveDialog(this);
962 fileName = chooser.getSelectedFile().getPath();
964 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
967 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
968 if (currentFileFormat.indexOf(" ") > -1)
970 currentFileFormat = currentFileFormat.substring(0,
971 currentFileFormat.indexOf(" "));
973 saveAlignment(fileName, currentFileFormat);
977 public boolean saveAlignment(String file, String format)
979 boolean success = true;
981 if (format.equalsIgnoreCase("Jalview"))
983 String shortName = title;
985 if (shortName.indexOf(java.io.File.separatorChar) > -1)
987 shortName = shortName.substring(shortName
988 .lastIndexOf(java.io.File.separatorChar) + 1);
991 success = new Jalview2XML().SaveAlignment(this, file, shortName);
993 statusBar.setText("Successfully saved to file: " + fileName + " in "
994 + format + " format.");
999 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1001 warningMessage("Cannot save file " + fileName + " using format "
1002 + format, "Alignment output format not supported");
1003 saveAs_actionPerformed(null);
1004 // JBPNote need to have a raise_gui flag here
1008 String[] omitHidden = null;
1010 if (viewport.hasHiddenColumns)
1012 int reply = JOptionPane
1013 .showInternalConfirmDialog(
1015 "The Alignment contains hidden columns."
1016 + "\nDo you want to save only the visible alignment?",
1017 "Save / Omit Hidden Columns",
1018 JOptionPane.YES_NO_OPTION,
1019 JOptionPane.QUESTION_MESSAGE);
1021 if (reply == JOptionPane.YES_OPTION)
1023 omitHidden = viewport.getViewAsString(false);
1026 FormatAdapter f = new FormatAdapter();
1027 String output = f.formatSequences(format,
1028 (Alignment) viewport.alignment, // class cast exceptions will
1029 // occur in the distant future
1030 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
1040 java.io.PrintWriter out = new java.io.PrintWriter(
1041 new java.io.FileWriter(file));
1045 this.setTitle(file);
1046 statusBar.setText("Successfully saved to file: " + fileName
1047 + " in " + format + " format.");
1048 } catch (Exception ex)
1051 ex.printStackTrace();
1058 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1059 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1065 private void warningMessage(String warning, String title)
1067 if (new jalview.util.Platform().isHeadless())
1069 System.err.println("Warning: " + title + "\nWarning: " + warning);
1074 JOptionPane.showInternalMessageDialog(this, warning, title,
1075 JOptionPane.WARNING_MESSAGE);
1086 protected void outputText_actionPerformed(ActionEvent e)
1088 String[] omitHidden = null;
1090 if (viewport.hasHiddenColumns)
1092 int reply = JOptionPane
1093 .showInternalConfirmDialog(
1095 "The Alignment contains hidden columns."
1096 + "\nDo you want to output only the visible alignment?",
1097 "Save / Omit Hidden Columns",
1098 JOptionPane.YES_NO_OPTION,
1099 JOptionPane.QUESTION_MESSAGE);
1101 if (reply == JOptionPane.YES_OPTION)
1103 omitHidden = viewport.getViewAsString(false);
1107 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1108 cap.setForInput(null);
1112 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1113 viewport.alignment, omitHidden, viewport.colSel));
1114 Desktop.addInternalFrame(cap,
1115 "Alignment output - " + e.getActionCommand(), 600, 500);
1116 } catch (OutOfMemoryError oom)
1118 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1130 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1132 new HTMLOutput(alignPanel,
1133 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1134 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1137 public void createImageMap(File file, String image)
1139 alignPanel.makePNGImageMap(file, image);
1148 public void createPNG(File f)
1150 alignPanel.makePNG(f);
1159 public void createEPS(File f)
1161 alignPanel.makeEPS(f);
1164 public void pageSetup_actionPerformed(ActionEvent e)
1166 PrinterJob printJob = PrinterJob.getPrinterJob();
1167 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1176 public void printMenuItem_actionPerformed(ActionEvent e)
1178 // Putting in a thread avoids Swing painting problems
1179 PrintThread thread = new PrintThread(alignPanel);
1183 public void exportFeatures_actionPerformed(ActionEvent e)
1185 new AnnotationExporter().exportFeatures(alignPanel);
1188 public void exportAnnotations_actionPerformed(ActionEvent e)
1190 new AnnotationExporter().exportAnnotations(
1192 viewport.showAnnotation ? viewport.alignment
1193 .getAlignmentAnnotation() : null, viewport.alignment
1195 ((Alignment) viewport.alignment).alignmentProperties);
1198 public void associatedData_actionPerformed(ActionEvent e)
1200 // Pick the tree file
1201 JalviewFileChooser chooser = new JalviewFileChooser(
1202 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1203 chooser.setFileView(new JalviewFileView());
1204 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1205 chooser.setToolTipText("Load Jalview Annotations / Features file");
1207 int value = chooser.showOpenDialog(null);
1209 if (value == JalviewFileChooser.APPROVE_OPTION)
1211 String choice = chooser.getSelectedFile().getPath();
1212 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1213 loadJalviewDataFile(choice, null, null, null);
1219 * Close the current view or all views in the alignment frame. If the frame
1220 * only contains one view then the alignment will be removed from memory.
1222 * @param closeAllTabs
1224 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1226 if (alignPanels != null && alignPanels.size() < 2)
1228 closeAllTabs = true;
1233 if (alignPanels != null)
1237 if (this.isClosed())
1239 // really close all the windows - otherwise wait till
1240 // setClosed(true) is called
1241 for (int i = 0; i < alignPanels.size(); i++)
1243 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1250 closeView(alignPanel);
1256 this.setClosed(true);
1258 } catch (Exception ex)
1260 ex.printStackTrace();
1265 * close alignPanel2 and shuffle tabs appropriately.
1267 * @param alignPanel2
1269 public void closeView(AlignmentPanel alignPanel2)
1271 int index = tabbedPane.getSelectedIndex();
1272 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1273 alignPanels.removeElement(alignPanel2);
1275 // if (viewport == alignPanel2.av)
1279 alignPanel2.closePanel();
1282 tabbedPane.removeTabAt(closedindex);
1283 tabbedPane.validate();
1285 if (index > closedindex || index == tabbedPane.getTabCount())
1287 // modify currently selected tab index if necessary.
1291 this.tabSelectionChanged(index);
1297 void updateEditMenuBar()
1300 if (viewport.historyList.size() > 0)
1302 undoMenuItem.setEnabled(true);
1303 CommandI command = (CommandI) viewport.historyList.peek();
1304 undoMenuItem.setText("Undo " + command.getDescription());
1308 undoMenuItem.setEnabled(false);
1309 undoMenuItem.setText("Undo");
1312 if (viewport.redoList.size() > 0)
1314 redoMenuItem.setEnabled(true);
1316 CommandI command = (CommandI) viewport.redoList.peek();
1317 redoMenuItem.setText("Redo " + command.getDescription());
1321 redoMenuItem.setEnabled(false);
1322 redoMenuItem.setText("Redo");
1326 public void addHistoryItem(CommandI command)
1328 if (command.getSize() > 0)
1330 viewport.historyList.push(command);
1331 viewport.redoList.clear();
1332 updateEditMenuBar();
1333 viewport.hasHiddenColumns = (viewport.colSel != null
1334 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1335 .getHiddenColumns().size() > 0);
1341 * @return alignment objects for all views
1343 AlignmentI[] getViewAlignments()
1345 if (alignPanels != null)
1347 Enumeration e = alignPanels.elements();
1348 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1349 for (int i = 0; e.hasMoreElements(); i++)
1351 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1355 if (viewport != null)
1357 return new AlignmentI[]
1358 { viewport.alignment };
1369 protected void undoMenuItem_actionPerformed(ActionEvent e)
1371 if (viewport.historyList.empty())
1373 CommandI command = (CommandI) viewport.historyList.pop();
1374 viewport.redoList.push(command);
1375 command.undoCommand(getViewAlignments());
1377 AlignViewport originalSource = getOriginatingSource(command);
1378 updateEditMenuBar();
1380 if (originalSource != null)
1382 originalSource.hasHiddenColumns = (viewport.colSel != null
1383 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1384 .getHiddenColumns().size() > 0);
1385 originalSource.firePropertyChange("alignment", null,
1386 originalSource.alignment.getSequences());
1396 protected void redoMenuItem_actionPerformed(ActionEvent e)
1398 if (viewport.redoList.size() < 1)
1403 CommandI command = (CommandI) viewport.redoList.pop();
1404 viewport.historyList.push(command);
1405 command.doCommand(getViewAlignments());
1407 AlignViewport originalSource = getOriginatingSource(command);
1408 updateEditMenuBar();
1410 if (originalSource != null)
1412 originalSource.hasHiddenColumns = (viewport.colSel != null
1413 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1414 .getHiddenColumns().size() > 0);
1415 originalSource.firePropertyChange("alignment", null,
1416 originalSource.alignment.getSequences());
1420 AlignViewport getOriginatingSource(CommandI command)
1422 AlignViewport originalSource = null;
1423 // For sequence removal and addition, we need to fire
1424 // the property change event FROM the viewport where the
1425 // original alignment was altered
1426 AlignmentI al = null;
1427 if (command instanceof EditCommand)
1429 EditCommand editCommand = (EditCommand) command;
1430 al = editCommand.getAlignment();
1431 Vector comps = (Vector) PaintRefresher.components.get(viewport
1432 .getSequenceSetId());
1434 for (int i = 0; i < comps.size(); i++)
1436 if (comps.elementAt(i) instanceof AlignmentPanel)
1438 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1440 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1447 if (originalSource == null)
1449 // The original view is closed, we must validate
1450 // the current view against the closed view first
1453 PaintRefresher.validateSequences(al, viewport.alignment);
1456 originalSource = viewport;
1459 return originalSource;
1468 public void moveSelectedSequences(boolean up)
1470 SequenceGroup sg = viewport.getSelectionGroup();
1479 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1481 SequenceI seq = viewport.alignment.getSequenceAt(i);
1483 if (!sg.getSequences(null).contains(seq))
1488 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1490 if (sg.getSequences(null).contains(temp))
1495 viewport.alignment.getSequences().setElementAt(temp, i);
1496 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1501 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1503 SequenceI seq = viewport.alignment.getSequenceAt(i);
1505 if (!sg.getSequences(null).contains(seq))
1510 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1512 if (sg.getSequences(null).contains(temp))
1517 viewport.alignment.getSequences().setElementAt(temp, i);
1518 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1522 alignPanel.paintAlignment(true);
1525 synchronized void slideSequences(boolean right, int size)
1527 Vector sg = new Vector();
1528 if (viewport.cursorMode)
1530 sg.addElement(viewport.alignment
1531 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1533 else if (viewport.getSelectionGroup() != null
1534 && viewport.getSelectionGroup().getSize() != viewport.alignment
1537 sg = viewport.getSelectionGroup().getSequences(
1538 viewport.hiddenRepSequences);
1546 Vector invertGroup = new Vector();
1548 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1550 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1551 invertGroup.add(viewport.alignment.getSequenceAt(i));
1554 SequenceI[] seqs1 = new SequenceI[sg.size()];
1555 for (int i = 0; i < sg.size(); i++)
1556 seqs1[i] = (SequenceI) sg.elementAt(i);
1558 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1559 for (int i = 0; i < invertGroup.size(); i++)
1560 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1562 SlideSequencesCommand ssc;
1564 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1565 size, viewport.getGapCharacter());
1567 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1568 size, viewport.getGapCharacter());
1570 int groupAdjustment = 0;
1571 if (ssc.getGapsInsertedBegin() && right)
1573 if (viewport.cursorMode)
1574 alignPanel.seqPanel.moveCursor(size, 0);
1576 groupAdjustment = size;
1578 else if (!ssc.getGapsInsertedBegin() && !right)
1580 if (viewport.cursorMode)
1581 alignPanel.seqPanel.moveCursor(-size, 0);
1583 groupAdjustment = -size;
1586 if (groupAdjustment != 0)
1588 viewport.getSelectionGroup().setStartRes(
1589 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1590 viewport.getSelectionGroup().setEndRes(
1591 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1594 boolean appendHistoryItem = false;
1595 if (viewport.historyList != null && viewport.historyList.size() > 0
1596 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1598 appendHistoryItem = ssc
1599 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1603 if (!appendHistoryItem)
1604 addHistoryItem(ssc);
1615 protected void copy_actionPerformed(ActionEvent e)
1618 if (viewport.getSelectionGroup() == null)
1622 // TODO: preserve the ordering of displayed alignment annotation in any
1623 // internal paste (particularly sequence associated annotation)
1624 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1625 String[] omitHidden = null;
1627 if (viewport.hasHiddenColumns)
1629 omitHidden = viewport.getViewAsString(true);
1632 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1635 StringSelection ss = new StringSelection(output);
1639 jalview.gui.Desktop.internalCopy = true;
1640 // Its really worth setting the clipboard contents
1641 // to empty before setting the large StringSelection!!
1642 Toolkit.getDefaultToolkit().getSystemClipboard()
1643 .setContents(new StringSelection(""), null);
1645 Toolkit.getDefaultToolkit().getSystemClipboard()
1646 .setContents(ss, Desktop.instance);
1647 } catch (OutOfMemoryError er)
1649 new OOMWarning("copying region", er);
1653 Vector hiddenColumns = null;
1654 if (viewport.hasHiddenColumns)
1656 hiddenColumns = new Vector();
1657 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1658 .getSelectionGroup().getEndRes();
1659 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1662 int[] region = (int[]) viewport.getColumnSelection()
1663 .getHiddenColumns().elementAt(i);
1664 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1666 hiddenColumns.addElement(new int[]
1667 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1672 Desktop.jalviewClipboard = new Object[]
1673 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1674 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1683 protected void pasteNew_actionPerformed(ActionEvent e)
1694 protected void pasteThis_actionPerformed(ActionEvent e)
1700 * Paste contents of Jalview clipboard
1702 * @param newAlignment
1703 * true to paste to a new alignment, otherwise add to this.
1705 void paste(boolean newAlignment)
1707 boolean externalPaste = true;
1710 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1711 Transferable contents = c.getContents(this);
1713 if (contents == null)
1721 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1722 if (str.length() < 1)
1727 format = new IdentifyFile().Identify(str, "Paste");
1729 } catch (OutOfMemoryError er)
1731 new OOMWarning("Out of memory pasting sequences!!", er);
1735 SequenceI[] sequences;
1736 boolean annotationAdded = false;
1737 AlignmentI alignment = null;
1739 if (Desktop.jalviewClipboard != null)
1741 // The clipboard was filled from within Jalview, we must use the
1743 // And dataset from the copied alignment
1744 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1745 // be doubly sure that we create *new* sequence objects.
1746 sequences = new SequenceI[newseq.length];
1747 for (int i = 0; i < newseq.length; i++)
1749 sequences[i] = new Sequence(newseq[i]);
1751 alignment = new Alignment(sequences);
1752 externalPaste = false;
1756 // parse the clipboard as an alignment.
1757 alignment = new FormatAdapter().readFile(str, "Paste", format);
1758 sequences = alignment.getSequencesArray();
1766 if (Desktop.jalviewClipboard != null)
1768 // dataset is inherited
1769 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1773 // new dataset is constructed
1774 alignment.setDataset(null);
1776 alwidth = alignment.getWidth() + 1;
1780 AlignmentI pastedal = alignment; // preserve pasted alignment object
1781 // Add pasted sequences and dataset into existing alignment.
1782 alignment = viewport.getAlignment();
1783 alwidth = alignment.getWidth() + 1;
1784 // decide if we need to import sequences from an existing dataset
1785 boolean importDs = Desktop.jalviewClipboard != null
1786 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1787 // importDs==true instructs us to copy over new dataset sequences from
1788 // an existing alignment
1789 Vector newDs = (importDs) ? new Vector() : null; // used to create
1790 // minimum dataset set
1792 for (int i = 0; i < sequences.length; i++)
1796 newDs.addElement(null);
1798 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1800 if (importDs && ds != null)
1802 if (!newDs.contains(ds))
1804 newDs.setElementAt(ds, i);
1805 ds = new Sequence(ds);
1806 // update with new dataset sequence
1807 sequences[i].setDatasetSequence(ds);
1811 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1816 // copy and derive new dataset sequence
1817 sequences[i] = sequences[i].deriveSequence();
1818 alignment.getDataset().addSequence(
1819 sequences[i].getDatasetSequence());
1820 // TODO: avoid creation of duplicate dataset sequences with a
1821 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1823 alignment.addSequence(sequences[i]); // merges dataset
1827 newDs.clear(); // tidy up
1829 if (pastedal.getAlignmentAnnotation() != null)
1831 // Add any annotation attached to alignment.
1832 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1833 for (int i = 0; i < alann.length; i++)
1835 annotationAdded = true;
1836 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1838 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1839 newann.padAnnotation(alwidth);
1840 alignment.addAnnotation(newann);
1850 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1851 sequences, 0, alignment.getWidth(), alignment));
1853 // Add any annotations attached to sequences
1854 for (int i = 0; i < sequences.length; i++)
1856 if (sequences[i].getAnnotation() != null)
1858 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1860 annotationAdded = true;
1861 sequences[i].getAnnotation()[a].adjustForAlignment();
1862 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1863 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1868 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1875 // propagate alignment changed.
1876 viewport.setEndSeq(alignment.getHeight());
1877 if (annotationAdded)
1879 // Duplicate sequence annotation in all views.
1880 AlignmentI[] alview = this.getViewAlignments();
1881 for (int i = 0; i < sequences.length; i++)
1883 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1886 for (int avnum = 0; avnum < alview.length; avnum++)
1888 if (alview[avnum] != alignment)
1890 // duplicate in a view other than the one with input focus
1891 int avwidth = alview[avnum].getWidth() + 1;
1892 // this relies on sann being preserved after we
1893 // modify the sequence's annotation array for each duplication
1894 for (int a = 0; a < sann.length; a++)
1896 AlignmentAnnotation newann = new AlignmentAnnotation(
1898 sequences[i].addAlignmentAnnotation(newann);
1899 newann.padAnnotation(avwidth);
1900 alview[avnum].addAnnotation(newann); // annotation was
1901 // duplicated earlier
1902 alview[avnum].setAnnotationIndex(newann, a);
1907 buildSortByAnnotationScoresMenu();
1909 viewport.firePropertyChange("alignment", null,
1910 alignment.getSequences());
1915 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1917 String newtitle = new String("Copied sequences");
1919 if (Desktop.jalviewClipboard != null
1920 && Desktop.jalviewClipboard[2] != null)
1922 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1923 for (int i = 0; i < hc.size(); i++)
1925 int[] region = (int[]) hc.elementAt(i);
1926 af.viewport.hideColumns(region[0], region[1]);
1930 // >>>This is a fix for the moment, until a better solution is
1932 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1934 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1936 // TODO: maintain provenance of an alignment, rather than just make the
1937 // title a concatenation of operations.
1940 if (title.startsWith("Copied sequences"))
1946 newtitle = newtitle.concat("- from " + title);
1951 newtitle = new String("Pasted sequences");
1954 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1959 } catch (Exception ex)
1961 ex.printStackTrace();
1962 System.out.println("Exception whilst pasting: " + ex);
1963 // could be anything being pasted in here
1974 protected void cut_actionPerformed(ActionEvent e)
1976 copy_actionPerformed(null);
1977 delete_actionPerformed(null);
1986 protected void delete_actionPerformed(ActionEvent evt)
1989 SequenceGroup sg = viewport.getSelectionGroup();
1995 Vector seqs = new Vector();
1997 for (int i = 0; i < sg.getSize(); i++)
1999 seq = sg.getSequenceAt(i);
2000 seqs.addElement(seq);
2003 // If the cut affects all sequences, remove highlighted columns
2004 if (sg.getSize() == viewport.alignment.getHeight())
2006 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2007 sg.getEndRes() + 1);
2010 SequenceI[] cut = new SequenceI[seqs.size()];
2011 for (int i = 0; i < seqs.size(); i++)
2013 cut[i] = (SequenceI) seqs.elementAt(i);
2017 * //ADD HISTORY ITEM
2019 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2020 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2021 viewport.alignment));
2023 viewport.setSelectionGroup(null);
2024 viewport.sendSelection();
2025 viewport.alignment.deleteGroup(sg);
2027 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2029 if (viewport.getAlignment().getHeight() < 1)
2033 this.setClosed(true);
2034 } catch (Exception ex)
2046 protected void deleteGroups_actionPerformed(ActionEvent e)
2048 viewport.alignment.deleteAllGroups();
2049 viewport.sequenceColours = null;
2050 viewport.setSelectionGroup(null);
2051 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2052 alignPanel.updateAnnotation();
2053 alignPanel.paintAlignment(true);
2062 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2064 SequenceGroup sg = new SequenceGroup();
2066 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2068 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2071 sg.setEndRes(viewport.alignment.getWidth() - 1);
2072 viewport.setSelectionGroup(sg);
2073 viewport.sendSelection();
2074 alignPanel.paintAlignment(true);
2075 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2084 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2086 if (viewport.cursorMode)
2088 alignPanel.seqPanel.keyboardNo1 = null;
2089 alignPanel.seqPanel.keyboardNo2 = null;
2091 viewport.setSelectionGroup(null);
2092 viewport.getColumnSelection().clear();
2093 viewport.setSelectionGroup(null);
2094 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2095 alignPanel.idPanel.idCanvas.searchResults = null;
2096 alignPanel.paintAlignment(true);
2097 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2098 viewport.sendSelection();
2107 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2109 SequenceGroup sg = viewport.getSelectionGroup();
2113 selectAllSequenceMenuItem_actionPerformed(null);
2118 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2120 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2123 alignPanel.paintAlignment(true);
2124 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2125 viewport.sendSelection();
2128 public void invertColSel_actionPerformed(ActionEvent e)
2130 viewport.invertColumnSelection();
2131 alignPanel.paintAlignment(true);
2132 viewport.sendSelection();
2141 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2143 trimAlignment(true);
2152 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2154 trimAlignment(false);
2157 void trimAlignment(boolean trimLeft)
2159 ColumnSelection colSel = viewport.getColumnSelection();
2162 if (colSel.size() > 0)
2166 column = colSel.getMin();
2170 column = colSel.getMax();
2174 if (viewport.getSelectionGroup() != null)
2176 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2177 viewport.hiddenRepSequences);
2181 seqs = viewport.alignment.getSequencesArray();
2184 TrimRegionCommand trimRegion;
2187 trimRegion = new TrimRegionCommand("Remove Left",
2188 TrimRegionCommand.TRIM_LEFT, seqs, column,
2189 viewport.alignment, viewport.colSel,
2190 viewport.selectionGroup);
2191 viewport.setStartRes(0);
2195 trimRegion = new TrimRegionCommand("Remove Right",
2196 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2197 viewport.alignment, viewport.colSel,
2198 viewport.selectionGroup);
2201 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2203 addHistoryItem(trimRegion);
2205 Vector groups = viewport.alignment.getGroups();
2207 for (int i = 0; i < groups.size(); i++)
2209 SequenceGroup sg = (SequenceGroup) groups.get(i);
2211 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2212 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2214 viewport.alignment.deleteGroup(sg);
2218 viewport.firePropertyChange("alignment", null, viewport
2219 .getAlignment().getSequences());
2229 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2231 int start = 0, end = viewport.alignment.getWidth() - 1;
2234 if (viewport.getSelectionGroup() != null)
2236 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2237 viewport.hiddenRepSequences);
2238 start = viewport.getSelectionGroup().getStartRes();
2239 end = viewport.getSelectionGroup().getEndRes();
2243 seqs = viewport.alignment.getSequencesArray();
2246 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2247 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2249 addHistoryItem(removeGapCols);
2251 statusBar.setText("Removed " + removeGapCols.getSize()
2252 + " empty columns.");
2254 // This is to maintain viewport position on first residue
2255 // of first sequence
2256 SequenceI seq = viewport.alignment.getSequenceAt(0);
2257 int startRes = seq.findPosition(viewport.startRes);
2258 // ShiftList shifts;
2259 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2260 // edit.alColumnChanges=shifts.getInverse();
2261 // if (viewport.hasHiddenColumns)
2262 // viewport.getColumnSelection().compensateForEdits(shifts);
2263 viewport.setStartRes(seq.findIndex(startRes) - 1);
2264 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2275 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2277 int start = 0, end = viewport.alignment.getWidth() - 1;
2280 if (viewport.getSelectionGroup() != null)
2282 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2283 viewport.hiddenRepSequences);
2284 start = viewport.getSelectionGroup().getStartRes();
2285 end = viewport.getSelectionGroup().getEndRes();
2289 seqs = viewport.alignment.getSequencesArray();
2292 // This is to maintain viewport position on first residue
2293 // of first sequence
2294 SequenceI seq = viewport.alignment.getSequenceAt(0);
2295 int startRes = seq.findPosition(viewport.startRes);
2297 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2298 viewport.alignment));
2300 viewport.setStartRes(seq.findIndex(startRes) - 1);
2302 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2313 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2315 viewport.padGaps = padGapsMenuitem.isSelected();
2316 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2322 // if (justifySeqs>0)
2324 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2336 public void findMenuItem_actionPerformed(ActionEvent e)
2341 public void newView_actionPerformed(ActionEvent e)
2348 * @param copyAnnotation
2349 * if true then duplicate all annnotation, groups and settings
2350 * @return new alignment panel, already displayed.
2352 public AlignmentPanel newView(boolean copyAnnotation)
2354 return newView(null, copyAnnotation);
2360 * title of newly created view
2361 * @return new alignment panel, already displayed.
2363 public AlignmentPanel newView(String viewTitle)
2365 return newView(viewTitle, true);
2371 * title of newly created view
2372 * @param copyAnnotation
2373 * if true then duplicate all annnotation, groups and settings
2374 * @return new alignment panel, already displayed.
2376 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2378 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2380 if (!copyAnnotation)
2382 // just remove all the current annotation except for the automatic stuff
2383 newap.av.alignment.deleteAllGroups();
2384 for (AlignmentAnnotation alan : newap.av.alignment
2385 .getAlignmentAnnotation())
2387 if (!alan.autoCalculated)
2389 newap.av.alignment.deleteAnnotation(alan);
2395 newap.av.gatherViewsHere = false;
2397 if (viewport.viewName == null)
2399 viewport.viewName = "Original";
2402 newap.av.historyList = viewport.historyList;
2403 newap.av.redoList = viewport.redoList;
2405 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2406 // make sure the new view has a unique name - this is essential for Jalview
2408 boolean addFirstIndex = false;
2409 if (viewTitle == null || viewTitle.trim().length() == 0)
2412 addFirstIndex = true;
2416 index = 1;// we count from 1 if given a specific name
2418 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2419 Vector comps = (Vector) PaintRefresher.components.get(viewport
2420 .getSequenceSetId());
2421 Vector existingNames = new Vector();
2422 for (int i = 0; i < comps.size(); i++)
2424 if (comps.elementAt(i) instanceof AlignmentPanel)
2426 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2427 if (!existingNames.contains(ap.av.viewName))
2429 existingNames.addElement(ap.av.viewName);
2434 while (existingNames.contains(newViewName))
2436 newViewName = viewTitle + " " + (++index);
2439 newap.av.viewName = newViewName;
2441 addAlignmentPanel(newap, true);
2443 if (alignPanels.size() == 2)
2445 viewport.gatherViewsHere = true;
2447 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2451 public void expandViews_actionPerformed(ActionEvent e)
2453 Desktop.instance.explodeViews(this);
2456 public void gatherViews_actionPerformed(ActionEvent e)
2458 Desktop.instance.gatherViews(this);
2467 public void font_actionPerformed(ActionEvent e)
2469 new FontChooser(alignPanel);
2478 protected void seqLimit_actionPerformed(ActionEvent e)
2480 viewport.setShowJVSuffix(seqLimits.isSelected());
2482 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2483 .calculateIdWidth());
2484 alignPanel.paintAlignment(true);
2487 public void idRightAlign_actionPerformed(ActionEvent e)
2489 viewport.rightAlignIds = idRightAlign.isSelected();
2490 alignPanel.paintAlignment(true);
2493 public void centreColumnLabels_actionPerformed(ActionEvent e)
2495 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2496 alignPanel.paintAlignment(true);
2502 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2504 protected void followHighlight_actionPerformed()
2506 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2508 alignPanel.scrollToPosition(
2509 alignPanel.seqPanel.seqCanvas.searchResults, false);
2519 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2521 viewport.setColourText(colourTextMenuItem.isSelected());
2522 alignPanel.paintAlignment(true);
2531 public void wrapMenuItem_actionPerformed(ActionEvent e)
2533 scaleAbove.setVisible(wrapMenuItem.isSelected());
2534 scaleLeft.setVisible(wrapMenuItem.isSelected());
2535 scaleRight.setVisible(wrapMenuItem.isSelected());
2536 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2537 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2540 public void showAllSeqs_actionPerformed(ActionEvent e)
2542 viewport.showAllHiddenSeqs();
2545 public void showAllColumns_actionPerformed(ActionEvent e)
2547 viewport.showAllHiddenColumns();
2551 public void hideSelSequences_actionPerformed(ActionEvent e)
2553 viewport.hideAllSelectedSeqs();
2554 alignPanel.paintAlignment(true);
2558 * called by key handler and the hide all/show all menu items
2563 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2566 boolean hide = false;
2567 SequenceGroup sg = viewport.getSelectionGroup();
2568 if (!toggleSeqs && !toggleCols)
2570 // Hide everything by the current selection - this is a hack - we do the
2571 // invert and then hide
2572 // first check that there will be visible columns after the invert.
2573 if ((viewport.colSel != null && viewport.colSel.getSelected() != null && viewport.colSel
2574 .getSelected().size() > 0)
2575 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2578 // now invert the sequence set, if required - empty selection implies
2579 // that no hiding is required.
2582 invertSequenceMenuItem_actionPerformed(null);
2583 sg = viewport.getSelectionGroup();
2587 viewport.expandColSelection(sg, true);
2588 // finally invert the column selection and get the new sequence
2590 invertColSel_actionPerformed(null);
2597 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
2599 hideSelSequences_actionPerformed(null);
2602 else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))
2604 showAllSeqs_actionPerformed(null);
2610 if (viewport.colSel.getSelected().size() > 0)
2612 hideSelColumns_actionPerformed(null);
2615 viewport.selectionGroup = sg;
2620 showAllColumns_actionPerformed(null);
2629 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2630 * event.ActionEvent)
2632 public void hideAllButSelection_actionPerformed(ActionEvent e)
2634 toggleHiddenRegions(false, false);
2641 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2644 public void hideAllSelection_actionPerformed(ActionEvent e)
2646 SequenceGroup sg = viewport.getSelectionGroup();
2647 viewport.expandColSelection(sg, false);
2648 viewport.hideAllSelectedSeqs();
2649 viewport.hideSelectedColumns();
2650 alignPanel.paintAlignment(true);
2657 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2660 public void showAllhidden_actionPerformed(ActionEvent e)
2662 viewport.showAllHiddenColumns();
2663 viewport.showAllHiddenSeqs();
2664 alignPanel.paintAlignment(true);
2667 public void hideSelColumns_actionPerformed(ActionEvent e)
2669 viewport.hideSelectedColumns();
2670 alignPanel.paintAlignment(true);
2673 public void hiddenMarkers_actionPerformed(ActionEvent e)
2675 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2685 protected void scaleAbove_actionPerformed(ActionEvent e)
2687 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2688 alignPanel.paintAlignment(true);
2697 protected void scaleLeft_actionPerformed(ActionEvent e)
2699 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2700 alignPanel.paintAlignment(true);
2709 protected void scaleRight_actionPerformed(ActionEvent e)
2711 viewport.setScaleRightWrapped(scaleRight.isSelected());
2712 alignPanel.paintAlignment(true);
2721 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2723 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2724 alignPanel.paintAlignment(true);
2733 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2735 viewport.setShowText(viewTextMenuItem.isSelected());
2736 alignPanel.paintAlignment(true);
2745 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2747 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2748 alignPanel.paintAlignment(true);
2751 public FeatureSettings featureSettings;
2753 public void featureSettings_actionPerformed(ActionEvent e)
2755 if (featureSettings != null)
2757 featureSettings.close();
2758 featureSettings = null;
2760 if (!showSeqFeatures.isSelected())
2762 // make sure features are actually displayed
2763 showSeqFeatures.setSelected(true);
2764 showSeqFeatures_actionPerformed(null);
2766 featureSettings = new FeatureSettings(this);
2770 * Set or clear 'Show Sequence Features'
2775 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2777 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2778 alignPanel.paintAlignment(true);
2779 if (alignPanel.getOverviewPanel() != null)
2781 alignPanel.getOverviewPanel().updateOverviewImage();
2786 * Set or clear 'Show Sequence Features'
2791 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2793 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2795 if (viewport.getShowSequenceFeaturesHeight())
2797 // ensure we're actually displaying features
2798 viewport.setShowSequenceFeatures(true);
2799 showSeqFeatures.setSelected(true);
2801 alignPanel.paintAlignment(true);
2802 if (alignPanel.getOverviewPanel() != null)
2804 alignPanel.getOverviewPanel().updateOverviewImage();
2814 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2816 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2817 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2820 public void alignmentProperties()
2822 JEditorPane editPane = new JEditorPane("text/html", "");
2823 editPane.setEditable(false);
2824 StringBuffer contents = new AlignmentProperties(viewport.alignment)
2826 editPane.setText("<html>" + contents.toString() + "</html>");
2827 JInternalFrame frame = new JInternalFrame();
2828 frame.getContentPane().add(new JScrollPane(editPane));
2830 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2831 + getTitle(), 500, 400);
2840 public void overviewMenuItem_actionPerformed(ActionEvent e)
2842 if (alignPanel.overviewPanel != null)
2847 JInternalFrame frame = new JInternalFrame();
2848 OverviewPanel overview = new OverviewPanel(alignPanel);
2849 frame.setContentPane(overview);
2850 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2851 frame.getWidth(), frame.getHeight());
2853 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2854 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2856 public void internalFrameClosed(
2857 javax.swing.event.InternalFrameEvent evt)
2859 alignPanel.setOverviewPanel(null);
2863 alignPanel.setOverviewPanel(overview);
2866 public void textColour_actionPerformed(ActionEvent e)
2868 new TextColourChooser().chooseColour(alignPanel, null);
2877 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2888 public void clustalColour_actionPerformed(ActionEvent e)
2890 changeColour(new ClustalxColourScheme(
2891 viewport.alignment.getSequences(),
2892 viewport.alignment.getWidth()));
2901 public void zappoColour_actionPerformed(ActionEvent e)
2903 changeColour(new ZappoColourScheme());
2912 public void taylorColour_actionPerformed(ActionEvent e)
2914 changeColour(new TaylorColourScheme());
2923 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2925 changeColour(new HydrophobicColourScheme());
2934 public void helixColour_actionPerformed(ActionEvent e)
2936 changeColour(new HelixColourScheme());
2945 public void strandColour_actionPerformed(ActionEvent e)
2947 changeColour(new StrandColourScheme());
2956 public void turnColour_actionPerformed(ActionEvent e)
2958 changeColour(new TurnColourScheme());
2967 public void buriedColour_actionPerformed(ActionEvent e)
2969 changeColour(new BuriedColourScheme());
2978 public void nucleotideColour_actionPerformed(ActionEvent e)
2980 changeColour(new NucleotideColourScheme());
2983 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
2985 changeColour(new PurinePyrimidineColourScheme());
2988 public void covariationColour_actionPerformed(ActionEvent e)
2990 changeColour(new CovariationColourScheme(viewport.alignment.getAlignmentAnnotation()[0]));
2993 public void annotationColour_actionPerformed(ActionEvent e)
2995 new AnnotationColourChooser(viewport, alignPanel);
2998 public void rnahelicesColour_actionPerformed(ActionEvent e)
3000 new RNAHelicesColourChooser(viewport, alignPanel);
3009 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3011 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3020 public void changeColour(ColourSchemeI cs)
3026 if (viewport.getAbovePIDThreshold())
3028 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3031 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3033 viewport.setGlobalColourScheme(cs);
3037 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3040 if (viewport.getConservationSelected())
3043 Alignment al = (Alignment) viewport.alignment;
3044 Conservation c = new Conservation("All",
3045 ResidueProperties.propHash, 3, al.getSequences(), 0,
3049 c.verdict(false, viewport.ConsPercGaps);
3051 cs.setConservation(c);
3053 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3058 cs.setConservation(null);
3061 cs.setConsensus(viewport.hconsensus);
3064 viewport.setGlobalColourScheme(cs);
3066 if (viewport.getColourAppliesToAllGroups())
3068 Vector groups = viewport.alignment.getGroups();
3070 for (int i = 0; i < groups.size(); i++)
3072 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
3080 if (cs instanceof ClustalxColourScheme)
3082 sg.cs = new ClustalxColourScheme(
3083 sg.getSequences(viewport.hiddenRepSequences),
3086 else if (cs instanceof UserColourScheme)
3088 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3094 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
3095 } catch (Exception ex)
3100 if (viewport.getAbovePIDThreshold()
3101 || cs instanceof PIDColourScheme
3102 || cs instanceof Blosum62ColourScheme)
3104 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3106 sg.cs.setConsensus(AAFrequency.calculate(
3107 sg.getSequences(viewport.hiddenRepSequences),
3108 sg.getStartRes(), sg.getEndRes() + 1));
3112 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3115 if (viewport.getConservationSelected())
3117 Conservation c = new Conservation("Group",
3118 ResidueProperties.propHash, 3,
3119 sg.getSequences(viewport.hiddenRepSequences),
3120 sg.getStartRes(), sg.getEndRes() + 1);
3122 c.verdict(false, viewport.ConsPercGaps);
3123 sg.cs.setConservation(c);
3127 sg.cs.setConservation(null);
3132 if (alignPanel.getOverviewPanel() != null)
3134 alignPanel.getOverviewPanel().updateOverviewImage();
3137 alignPanel.paintAlignment(true);
3146 protected void modifyPID_actionPerformed(ActionEvent e)
3148 if (viewport.getAbovePIDThreshold()
3149 && viewport.globalColourScheme != null)
3151 SliderPanel.setPIDSliderSource(alignPanel,
3152 viewport.getGlobalColourScheme(), "Background");
3153 SliderPanel.showPIDSlider();
3163 protected void modifyConservation_actionPerformed(ActionEvent e)
3165 if (viewport.getConservationSelected()
3166 && viewport.globalColourScheme != null)
3168 SliderPanel.setConservationSlider(alignPanel,
3169 viewport.globalColourScheme, "Background");
3170 SliderPanel.showConservationSlider();
3180 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3182 viewport.setConservationSelected(conservationMenuItem.isSelected());
3184 viewport.setAbovePIDThreshold(false);
3185 abovePIDThreshold.setSelected(false);
3187 changeColour(viewport.getGlobalColourScheme());
3189 modifyConservation_actionPerformed(null);
3198 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3200 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3202 conservationMenuItem.setSelected(false);
3203 viewport.setConservationSelected(false);
3205 changeColour(viewport.getGlobalColourScheme());
3207 modifyPID_actionPerformed(null);
3216 public void userDefinedColour_actionPerformed(ActionEvent e)
3218 if (e.getActionCommand().equals("User Defined..."))
3220 new UserDefinedColours(alignPanel, null);
3224 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3225 .getUserColourSchemes().get(e.getActionCommand());
3231 public void updateUserColourMenu()
3234 Component[] menuItems = colourMenu.getMenuComponents();
3235 int i, iSize = menuItems.length;
3236 for (i = 0; i < iSize; i++)
3238 if (menuItems[i].getName() != null
3239 && menuItems[i].getName().equals("USER_DEFINED"))
3241 colourMenu.remove(menuItems[i]);
3245 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3247 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3248 .getUserColourSchemes().keys();
3250 while (userColours.hasMoreElements())
3252 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3253 userColours.nextElement().toString());
3254 radioItem.setName("USER_DEFINED");
3255 radioItem.addMouseListener(new MouseAdapter()
3257 public void mousePressed(MouseEvent evt)
3259 if (evt.isControlDown()
3260 || SwingUtilities.isRightMouseButton(evt))
3262 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3264 int option = JOptionPane.showInternalConfirmDialog(
3265 jalview.gui.Desktop.desktop,
3266 "Remove from default list?",
3267 "Remove user defined colour",
3268 JOptionPane.YES_NO_OPTION);
3269 if (option == JOptionPane.YES_OPTION)
3271 jalview.gui.UserDefinedColours
3272 .removeColourFromDefaults(radioItem.getText());
3273 colourMenu.remove(radioItem);
3277 radioItem.addActionListener(new ActionListener()
3279 public void actionPerformed(ActionEvent evt)
3281 userDefinedColour_actionPerformed(evt);
3288 radioItem.addActionListener(new ActionListener()
3290 public void actionPerformed(ActionEvent evt)
3292 userDefinedColour_actionPerformed(evt);
3296 colourMenu.insert(radioItem, 15);
3297 colours.add(radioItem);
3308 public void PIDColour_actionPerformed(ActionEvent e)
3310 changeColour(new PIDColourScheme());
3319 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3321 changeColour(new Blosum62ColourScheme());
3330 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3332 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3333 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3334 .getAlignment().getSequenceAt(0), null);
3335 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3336 viewport.alignment));
3337 alignPanel.paintAlignment(true);
3346 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3348 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3349 AlignmentSorter.sortByID(viewport.getAlignment());
3350 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
3351 alignPanel.paintAlignment(true);
3360 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3362 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3363 AlignmentSorter.sortByLength(viewport.getAlignment());
3364 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3365 viewport.alignment));
3366 alignPanel.paintAlignment(true);
3375 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3377 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3378 AlignmentSorter.sortByGroup(viewport.getAlignment());
3379 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3380 viewport.alignment));
3382 alignPanel.paintAlignment(true);
3391 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3393 new RedundancyPanel(alignPanel, this);
3402 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3404 if ((viewport.getSelectionGroup() == null)
3405 || (viewport.getSelectionGroup().getSize() < 2))
3407 JOptionPane.showInternalMessageDialog(this,
3408 "You must select at least 2 sequences.", "Invalid Selection",
3409 JOptionPane.WARNING_MESSAGE);
3413 JInternalFrame frame = new JInternalFrame();
3414 frame.setContentPane(new PairwiseAlignPanel(viewport));
3415 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3425 public void PCAMenuItem_actionPerformed(ActionEvent e)
3427 if (((viewport.getSelectionGroup() != null)
3428 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3429 .getSelectionGroup().getSize() > 0))
3430 || (viewport.getAlignment().getHeight() < 4))
3432 JOptionPane.showInternalMessageDialog(this,
3433 "Principal component analysis must take\n"
3434 + "at least 4 input sequences.",
3435 "Sequence selection insufficient",
3436 JOptionPane.WARNING_MESSAGE);
3441 new PCAPanel(alignPanel);
3444 public void autoCalculate_actionPerformed(ActionEvent e)
3446 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3447 if (viewport.autoCalculateConsensus)
3449 viewport.firePropertyChange("alignment", null, viewport
3450 .getAlignment().getSequences());
3460 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3462 NewTreePanel("AV", "PID", "Average distance tree using PID");
3471 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3473 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3482 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3484 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3493 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3495 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3508 void NewTreePanel(String type, String pwType, String title)
3512 if (viewport.getSelectionGroup() != null)
3514 if (viewport.getSelectionGroup().getSize() < 3)
3519 "You need to have more than two sequences selected to build a tree!",
3520 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3525 SequenceGroup sg = viewport.getSelectionGroup();
3527 /* Decide if the selection is a column region */
3528 while (s < sg.getSize())
3530 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3536 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3537 + "Try using the Pad function in the edit menu,\n"
3538 + "or one of the multiple sequence alignment web services.",
3539 "Sequences in selection are not aligned",
3540 JOptionPane.WARNING_MESSAGE);
3546 title = title + " on region";
3547 tp = new TreePanel(alignPanel, type, pwType);
3551 // are the visible sequences aligned?
3552 if (!viewport.alignment.isAligned(false))
3557 "The sequences must be aligned before creating a tree.\n"
3558 + "Try using the Pad function in the edit menu,\n"
3559 + "or one of the multiple sequence alignment web services.",
3560 "Sequences not aligned",
3561 JOptionPane.WARNING_MESSAGE);
3566 if (viewport.alignment.getHeight() < 2)
3571 tp = new TreePanel(alignPanel, type, pwType);
3576 if (viewport.viewName != null)
3578 title += viewport.viewName + " of ";
3581 title += this.title;
3583 Desktop.addInternalFrame(tp, title, 600, 500);
3594 public void addSortByOrderMenuItem(String title,
3595 final AlignmentOrder order)
3597 final JMenuItem item = new JMenuItem("by " + title);
3599 item.addActionListener(new java.awt.event.ActionListener()
3601 public void actionPerformed(ActionEvent e)
3603 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3605 // TODO: JBPNote - have to map order entries to curent SequenceI
3607 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3609 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3610 viewport.alignment));
3612 alignPanel.paintAlignment(true);
3618 * Add a new sort by annotation score menu item
3621 * the menu to add the option to
3623 * the label used to retrieve scores for each sequence on the
3626 public void addSortByAnnotScoreMenuItem(JMenu sort,
3627 final String scoreLabel)
3629 final JMenuItem item = new JMenuItem(scoreLabel);
3631 item.addActionListener(new java.awt.event.ActionListener()
3633 public void actionPerformed(ActionEvent e)
3635 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3636 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3637 viewport.getAlignment());// ,viewport.getSelectionGroup());
3638 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3639 viewport.alignment));
3640 alignPanel.paintAlignment(true);
3646 * last hash for alignment's annotation array - used to minimise cost of
3649 protected int _annotationScoreVectorHash;
3652 * search the alignment and rebuild the sort by annotation score submenu the
3653 * last alignment annotation vector hash is stored to minimize cost of
3654 * rebuilding in subsequence calls.
3657 public void buildSortByAnnotationScoresMenu()
3659 if (viewport.alignment.getAlignmentAnnotation() == null)
3664 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3666 sortByAnnotScore.removeAll();
3667 // almost certainly a quicker way to do this - but we keep it simple
3668 Hashtable scoreSorts = new Hashtable();
3669 AlignmentAnnotation aann[];
3670 Enumeration sq = viewport.alignment.getSequences().elements();
3671 while (sq.hasMoreElements())
3673 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3674 for (int i = 0; aann != null && i < aann.length; i++)
3676 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3678 scoreSorts.put(aann[i].label, aann[i].label);
3682 Enumeration labels = scoreSorts.keys();
3683 while (labels.hasMoreElements())
3685 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3686 (String) labels.nextElement());
3688 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3691 _annotationScoreVectorHash = viewport.alignment
3692 .getAlignmentAnnotation().hashCode();
3697 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3698 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3699 * call. Listeners are added to remove the menu item when the treePanel is
3700 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3704 * Displayed tree window.
3706 * SortBy menu item title.
3708 public void buildTreeMenu()
3710 sortByTreeMenu.removeAll();
3712 Vector comps = (Vector) PaintRefresher.components.get(viewport
3713 .getSequenceSetId());
3714 Vector treePanels = new Vector();
3715 int i, iSize = comps.size();
3716 for (i = 0; i < iSize; i++)
3718 if (comps.elementAt(i) instanceof TreePanel)
3720 treePanels.add(comps.elementAt(i));
3724 iSize = treePanels.size();
3728 sortByTreeMenu.setVisible(false);
3732 sortByTreeMenu.setVisible(true);
3734 for (i = 0; i < treePanels.size(); i++)
3736 TreePanel tp = (TreePanel) treePanels.elementAt(i);
3737 final JMenuItem item = new JMenuItem(tp.getTitle());
3738 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3739 item.addActionListener(new java.awt.event.ActionListener()
3741 public void actionPerformed(ActionEvent e)
3743 SequenceI[] oldOrder = viewport.getAlignment()
3744 .getSequencesArray();
3745 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3747 addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
3748 viewport.alignment));
3750 alignPanel.paintAlignment(true);
3754 sortByTreeMenu.add(item);
3758 public boolean sortBy(AlignmentOrder alorder, String undoname)
3760 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3761 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3762 if (undoname != null)
3764 addHistoryItem(new OrderCommand(undoname, oldOrder,
3765 viewport.alignment));
3767 alignPanel.paintAlignment(true);
3772 * Work out whether the whole set of sequences or just the selected set will
3773 * be submitted for multiple alignment.
3776 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3778 // Now, check we have enough sequences
3779 AlignmentView msa = null;
3781 if ((viewport.getSelectionGroup() != null)
3782 && (viewport.getSelectionGroup().getSize() > 1))
3784 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3785 // some common interface!
3787 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3788 * SequenceI[sz = seqs.getSize(false)];
3790 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3791 * seqs.getSequenceAt(i); }
3793 msa = viewport.getAlignmentView(true);
3798 * Vector seqs = viewport.getAlignment().getSequences();
3800 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3802 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3803 * seqs.elementAt(i); } }
3805 msa = viewport.getAlignmentView(false);
3811 * Decides what is submitted to a secondary structure prediction service: the
3812 * first sequence in the alignment, or in the current selection, or, if the
3813 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3814 * region or the whole alignment. (where the first sequence in the set is the
3815 * one that the prediction will be for).
3817 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3819 AlignmentView seqs = null;
3821 if ((viewport.getSelectionGroup() != null)
3822 && (viewport.getSelectionGroup().getSize() > 0))
3824 seqs = viewport.getAlignmentView(true);
3828 seqs = viewport.getAlignmentView(false);
3830 // limit sequences - JBPNote in future - could spawn multiple prediction
3832 // TODO: viewport.alignment.isAligned is a global state - the local
3833 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3834 if (!viewport.alignment.isAligned(false))
3836 seqs.setSequences(new SeqCigar[]
3837 { seqs.getSequences()[0] });
3838 // TODO: if seqs.getSequences().length>1 then should really have warned
3851 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3853 // Pick the tree file
3854 JalviewFileChooser chooser = new JalviewFileChooser(
3855 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3856 chooser.setFileView(new JalviewFileView());
3857 chooser.setDialogTitle("Select a newick-like tree file");
3858 chooser.setToolTipText("Load a tree file");
3860 int value = chooser.showOpenDialog(null);
3862 if (value == JalviewFileChooser.APPROVE_OPTION)
3864 String choice = chooser.getSelectedFile().getPath();
3865 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3866 jalview.io.NewickFile fin = null;
3869 fin = new jalview.io.NewickFile(choice, "File");
3870 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3871 } catch (Exception ex)
3873 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3874 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3875 ex.printStackTrace();
3877 if (fin != null && fin.hasWarningMessage())
3879 JOptionPane.showMessageDialog(Desktop.desktop,
3880 fin.getWarningMessage(), "Possible problem with tree file",
3881 JOptionPane.WARNING_MESSAGE);
3886 public TreePanel ShowNewickTree(NewickFile nf, String title)
3888 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3891 public TreePanel ShowNewickTree(NewickFile nf, String title,
3892 AlignmentView input)
3894 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3897 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3898 int h, int x, int y)
3900 return ShowNewickTree(nf, title, null, w, h, x, y);
3904 * Add a treeviewer for the tree extracted from a newick file object to the
3905 * current alignment view
3912 * Associated alignment input data (or null)
3921 * @return TreePanel handle
3923 public TreePanel ShowNewickTree(NewickFile nf, String title,
3924 AlignmentView input, int w, int h, int x, int y)
3926 TreePanel tp = null;
3932 if (nf.getTree() != null)
3934 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3940 tp.setLocation(x, y);
3943 Desktop.addInternalFrame(tp, title, w, h);
3945 } catch (Exception ex)
3947 ex.printStackTrace();
3953 private boolean buildingMenu = false;
3956 * Generates menu items and listener event actions for web service clients
3959 public void BuildWebServiceMenu()
3961 while (buildingMenu)
3965 System.err.println("Waiting for building menu to finish.");
3967 } catch (Exception e)
3972 final AlignFrame me = this;
3973 buildingMenu = true;
3974 new Thread(new Runnable()
3980 System.err.println("Building ws menu again "
3981 + Thread.currentThread());
3982 // TODO: add support for context dependent disabling of services based
3984 // alignment and current selection
3985 // TODO: add additional serviceHandle parameter to specify abstract
3987 // class independently of AbstractName
3988 // TODO: add in rediscovery GUI function to restart discoverer
3989 // TODO: group services by location as well as function and/or
3991 // object broker mechanism.
3992 final Vector wsmenu = new Vector();
3993 final IProgressIndicator af = me;
3994 if (Cache.getDefault("SHOW_JWS1_SERVICES", true)
3995 && Discoverer.services != null
3996 && (Discoverer.services.size() > 0))
3998 // TODO: refactor to allow list of AbstractName/Handler bindings to
4000 // stored or retrieved from elsewhere
4001 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
4002 Vector secstrpr = (Vector) Discoverer.services
4004 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
4005 // TODO: move GUI generation code onto service implementation - so a
4006 // client instance attaches itself to the GUI with method call like
4007 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4011 // Add any Multiple Sequence Alignment Services
4012 final JMenu msawsmenu = new JMenu("Alignment");
4013 for (int i = 0, j = msaws.size(); i < j; i++)
4015 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4017 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4018 .getServiceClient(sh);
4019 impl.attachWSMenuEntry(msawsmenu, me);
4022 wsmenu.add(msawsmenu);
4024 if (secstrpr != null)
4026 // Add any secondary structure prediction services
4027 final JMenu secstrmenu = new JMenu(
4028 "Secondary Structure Prediction");
4029 for (int i = 0, j = secstrpr.size(); i < j; i++)
4031 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4033 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4034 .getServiceClient(sh);
4035 impl.attachWSMenuEntry(secstrmenu, me);
4037 wsmenu.add(secstrmenu);
4039 if (seqsrch != null)
4041 // Add any sequence search services
4042 final JMenu seqsrchmenu = new JMenu(
4043 "Sequence Database Search");
4044 for (int i = 0, j = seqsrch.size(); i < j; i++)
4046 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4048 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4049 .getServiceClient(sh);
4050 impl.attachWSMenuEntry(seqsrchmenu, me);
4052 wsmenu.add(seqsrchmenu);
4056 // TODO: move into separate menu builder class.
4057 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4059 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4060 if (jws2servs != null)
4062 if (jws2servs.hasServices())
4064 JMenu jws2men = new JMenu("Jaba Web Services");
4065 jws2servs.attachWSMenuEntry(jws2men, me);
4066 for (int i = 0, iSize = jws2men.getMenuComponentCount(); i < iSize; i++)
4068 wsmenu.add(jws2men.getMenuComponent(i));
4074 javax.swing.SwingUtilities.invokeLater(new Runnable()
4081 resetWebServiceMenu();
4082 // finally, add the whole shebang onto the webservices menu
4083 if (wsmenu.size() > 0)
4085 for (int i = 0, j = wsmenu.size(); i < j; i++)
4087 webService.add((JMenu) wsmenu.get(i));
4092 me.webService.add(me.webServiceNoServices);
4094 } catch (Exception e)
4100 } catch (Exception e)
4105 buildingMenu = false;
4112 * empty the web service menu and add any ad-hoc functions not dynamically
4116 private void resetWebServiceMenu()
4118 webService.removeAll();
4119 build_fetchdbmenu(webService);
4120 build_urlServiceMenu(webService);
4124 * construct any groupURL type service menu entries.
4128 private void build_urlServiceMenu(JMenu webService)
4130 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4132 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4135 // TODO: remove this code when 2.7 is released
4136 // DEBUG - alignmentView
4138 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4139 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4141 * @Override public void actionPerformed(ActionEvent e) {
4142 * jalview.datamodel.AlignmentView.testSelectionViews(af.viewport.alignment,
4143 * af.viewport.colSel, af.viewport.selectionGroup); }
4145 * }); webService.add(testAlView);
4147 // TODO: refactor to RestClient discoverer and merge menu entries for
4148 // rest-style services with other types of analysis/calculation service
4149 // SHmmr test client - still being implemented.
4150 jalview.ws.rest.RestClient.makeShmmrRestClient().attachWSMenuEntry(
4152 // DEBUG - alignmentView
4156 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4157 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4158 * getProperty("LAST_DIRECTORY"));
4160 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4161 * to Vamsas file"); chooser.setToolTipText("Export");
4163 * int value = chooser.showSaveDialog(this);
4165 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4166 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4167 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4168 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4171 * prototype of an automatically enabled/disabled analysis function
4174 protected void setShowProductsEnabled()
4176 SequenceI[] selection = viewport.getSequenceSelection();
4177 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4178 viewport.getAlignment().getDataset()))
4180 showProducts.setEnabled(true);
4185 showProducts.setEnabled(false);
4190 * search selection for sequence xRef products and build the show products
4195 * @return true if showProducts menu should be enabled.
4197 public boolean canShowProducts(SequenceI[] selection,
4198 boolean isRegionSelection, Alignment dataset)
4200 boolean showp = false;
4203 showProducts.removeAll();
4204 final boolean dna = viewport.getAlignment().isNucleotide();
4205 final Alignment ds = dataset;
4206 String[] ptypes = (selection == null || selection.length == 0) ? null
4207 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4209 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4210 // selection, dataset, true);
4211 final SequenceI[] sel = selection;
4212 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4215 final boolean isRegSel = isRegionSelection;
4216 final AlignFrame af = this;
4217 final String source = ptypes[t];
4218 JMenuItem xtype = new JMenuItem(ptypes[t]);
4219 xtype.addActionListener(new ActionListener()
4222 public void actionPerformed(ActionEvent e)
4224 // TODO: new thread for this call with vis-delay
4225 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4226 isRegSel, dna, source);
4230 showProducts.add(xtype);
4232 showProducts.setVisible(showp);
4233 showProducts.setEnabled(showp);
4234 } catch (Exception e)
4236 jalview.bin.Cache.log
4237 .warn("canTranslate threw an exception - please report to help@jalview.org",
4244 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4245 boolean isRegSel, boolean dna, String source)
4247 final boolean fisRegSel = isRegSel;
4248 final boolean fdna = dna;
4249 final String fsrc = source;
4250 final AlignFrame ths = this;
4251 final SequenceI[] fsel = sel;
4252 Runnable foo = new Runnable()
4257 final long sttime = System.currentTimeMillis();
4258 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4261 Alignment ds = ths.getViewport().alignment.getDataset(); // update
4265 Alignment prods = CrossRef
4266 .findXrefSequences(fsel, fdna, fsrc, ds);
4269 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4270 for (int s = 0; s < sprods.length; s++)
4272 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4273 if (ds.getSequences() == null
4274 || !ds.getSequences().contains(
4275 sprods[s].getDatasetSequence()))
4276 ds.addSequence(sprods[s].getDatasetSequence());
4277 sprods[s].updatePDBIds();
4279 Alignment al = new Alignment(sprods);
4280 AlignedCodonFrame[] cf = prods.getCodonFrames();
4282 for (int s = 0; cf != null && s < cf.length; s++)
4284 al.addCodonFrame(cf[s]);
4287 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4289 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4290 + " for " + ((fisRegSel) ? "selected region of " : "")
4292 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4297 System.err.println("No Sequences generated for xRef type "
4300 } catch (Exception e)
4302 jalview.bin.Cache.log.error(
4303 "Exception when finding crossreferences", e);
4304 } catch (OutOfMemoryError e)
4306 new OOMWarning("whilst fetching crossreferences", e);
4309 jalview.bin.Cache.log.error("Error when finding crossreferences",
4312 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4317 Thread frunner = new Thread(foo);
4321 public boolean canShowTranslationProducts(SequenceI[] selection,
4322 AlignmentI alignment)
4327 return (jalview.analysis.Dna.canTranslate(selection,
4328 viewport.getViewAsVisibleContigs(true)));
4329 } catch (Exception e)
4331 jalview.bin.Cache.log
4332 .warn("canTranslate threw an exception - please report to help@jalview.org",
4338 public void showProducts_actionPerformed(ActionEvent e)
4340 // /////////////////////////////
4341 // Collect Data to be translated/transferred
4343 SequenceI[] selection = viewport.getSequenceSelection();
4344 AlignmentI al = null;
4347 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4348 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4349 viewport.getAlignment().getDataset());
4350 } catch (Exception ex)
4353 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4360 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4361 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4365 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4366 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4367 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4371 public void showTranslation_actionPerformed(ActionEvent e)
4373 // /////////////////////////////
4374 // Collect Data to be translated/transferred
4376 SequenceI[] selection = viewport.getSequenceSelection();
4377 String[] seqstring = viewport.getViewAsString(true);
4378 AlignmentI al = null;
4381 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4382 viewport.getViewAsVisibleContigs(true), viewport
4383 .getGapCharacter(), viewport.alignment
4384 .getAlignmentAnnotation(), viewport.alignment
4385 .getWidth(), viewport.getAlignment().getDataset());
4386 } catch (Exception ex)
4389 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4396 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4397 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4401 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4402 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4403 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4408 * Try to load a features file onto the alignment.
4411 * contents or path to retrieve file
4413 * access mode of file (see jalview.io.AlignFile)
4414 * @return true if features file was parsed corectly.
4416 public boolean parseFeaturesFile(String file, String type)
4418 boolean featuresFile = false;
4421 featuresFile = new FeaturesFile(file, type)
4422 .parse(viewport.alignment.getDataset(),
4423 alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
4424 false, jalview.bin.Cache.getDefault(
4425 "RELAXEDSEQIDMATCHING", false));
4426 } catch (Exception ex)
4428 ex.printStackTrace();
4433 viewport.showSequenceFeatures = true;
4434 showSeqFeatures.setSelected(true);
4435 if (alignPanel.seqPanel.seqCanvas.fr != null)
4437 // update the min/max ranges where necessary
4438 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4440 if (featureSettings != null)
4442 featureSettings.setTableData();
4444 alignPanel.paintAlignment(true);
4447 return featuresFile;
4450 public void dragEnter(DropTargetDragEvent evt)
4454 public void dragExit(DropTargetEvent evt)
4458 public void dragOver(DropTargetDragEvent evt)
4462 public void dropActionChanged(DropTargetDragEvent evt)
4466 public void drop(DropTargetDropEvent evt)
4468 Transferable t = evt.getTransferable();
4469 java.util.List files = null;
4473 DataFlavor uriListFlavor = new DataFlavor(
4474 "text/uri-list;class=java.lang.String");
4475 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4477 // Works on Windows and MacOSX
4478 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4479 files = (java.util.List) t
4480 .getTransferData(DataFlavor.javaFileListFlavor);
4482 else if (t.isDataFlavorSupported(uriListFlavor))
4484 // This is used by Unix drag system
4485 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4486 String data = (String) t.getTransferData(uriListFlavor);
4487 files = new java.util.ArrayList(1);
4488 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4489 data, "\r\n"); st.hasMoreTokens();)
4491 String s = st.nextToken();
4492 if (s.startsWith("#"))
4494 // the line is a comment (as per the RFC 2483)
4498 java.net.URI uri = new java.net.URI(s);
4499 // check to see if we can handle this kind of URI
4500 if (uri.getScheme().toLowerCase().startsWith("http"))
4502 files.add(uri.toString());
4506 // otherwise preserve old behaviour: catch all for file objects
4507 java.io.File file = new java.io.File(uri);
4508 files.add(file.toString());
4512 } catch (Exception e)
4514 e.printStackTrace();
4520 // check to see if any of these files have names matching sequences in
4522 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4523 .getAlignment().getSequencesArray());
4525 * Object[] { String,SequenceI}
4527 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4528 ArrayList<String> filesnotmatched = new ArrayList<String>();
4529 for (int i = 0; i < files.size(); i++)
4531 String file = files.get(i).toString();
4533 String protocol = FormatAdapter.checkProtocol(file);
4534 if (protocol == jalview.io.FormatAdapter.FILE)
4536 File fl = new File(file);
4537 pdbfn = fl.getName();
4539 else if (protocol == jalview.io.FormatAdapter.URL)
4541 URL url = new URL(file);
4542 pdbfn = url.getFile();
4544 if (pdbfn.length() > 0)
4546 // attempt to find a match in the alignment
4547 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4548 int l = 0, c = pdbfn.indexOf(".");
4549 while (mtch == null && c != -1)
4554 } while ((c = pdbfn.indexOf(".", l)) > l);
4557 pdbfn = pdbfn.substring(0, l);
4559 mtch = idm.findAllIdMatches(pdbfn);
4566 type = new IdentifyFile().Identify(file, protocol);
4567 } catch (Exception ex)
4573 if (type.equalsIgnoreCase("PDB"))
4575 filesmatched.add(new Object[]
4576 { file, protocol, mtch });
4581 // File wasn't named like one of the sequences or wasn't a PDB file.
4582 filesnotmatched.add(file);
4586 if (filesmatched.size() > 0)
4588 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4592 "Do you want to automatically associate the "
4593 + filesmatched.size()
4594 + " PDB files with sequences in the alignment that have the same name ?",
4595 "Automatically Associate PDB files by name",
4596 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4599 for (Object[] fm : filesmatched)
4601 // try and associate
4602 // TODO: may want to set a standard ID naming formalism for
4603 // associating PDB files which have no IDs.
4604 for (SequenceI toassoc: (SequenceI[])fm[2]) {
4605 PDBEntry pe = new AssociatePdbFileWithSeq()
4606 .associatePdbWithSeq((String) fm[0], (String) fm[1],
4611 .println("Associated file : " + ((String) fm[0])
4613 + toassoc.getDisplayId(true));
4617 alignPanel.paintAlignment(true);
4621 if (filesnotmatched.size() > 0)
4624 && (Cache.getDefault(
4625 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4628 "<html>Do you want to <em>ignore</em> the "
4629 + filesnotmatched.size()
4630 + " files whose names did not match any sequence IDs ?</html>",
4631 "Ignore unmatched dropped files ?",
4632 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4636 for (String fn : filesnotmatched)
4638 loadJalviewDataFile(fn, null, null, null);
4642 } catch (Exception ex)
4644 ex.printStackTrace();
4650 * Attempt to load a "dropped" file or URL string: First by testing whether
4651 * it's and Annotation file, then a JNet file, and finally a features file. If
4652 * all are false then the user may have dropped an alignment file onto this
4656 * either a filename or a URL string.
4658 public void loadJalviewDataFile(String file, String protocol,
4659 String format, SequenceI assocSeq)
4663 if (protocol == null)
4665 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4667 // if the file isn't identified, or not positively identified as some
4668 // other filetype (PFAM is default unidentified alignment file type) then
4669 // try to parse as annotation.
4670 boolean isAnnotation = (format == null || format
4671 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4672 .readAnnotationFile(viewport.alignment, file, protocol)
4677 // try to see if its a JNet 'concise' style annotation file *before* we
4678 // try to parse it as a features file
4681 format = new IdentifyFile().Identify(file, protocol);
4683 if (format.equalsIgnoreCase("JnetFile"))
4685 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4687 new JnetAnnotationMaker().add_annotation(predictions,
4688 viewport.getAlignment(), 0, false);
4689 isAnnotation = true;
4694 * if (format.equalsIgnoreCase("PDB")) {
4696 * String pdbfn = ""; // try to match up filename with sequence id try
4697 * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new
4698 * File(file); pdbfn = fl.getName(); } else if (protocol ==
4699 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4700 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null)
4701 * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4702 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { //
4703 * attempt to find a match in the alignment SequenceI mtch =
4704 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4705 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l)
4706 * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch =
4707 * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate
4708 * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4709 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) {
4710 * System.err.println("Associated file : " + file + " with " +
4711 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4712 * TODO: maybe need to load as normal otherwise return; } }
4714 // try to parse it as a features file
4715 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4716 // if it wasn't a features file then we just treat it as a general
4717 // alignment file to load into the current view.
4720 new FileLoader().LoadFile(viewport, file, protocol, format);
4724 alignPanel.paintAlignment(true);
4731 alignPanel.adjustAnnotationHeight();
4732 viewport.updateSequenceIdColours();
4733 buildSortByAnnotationScoresMenu();
4734 alignPanel.paintAlignment(true);
4735 System.out.println("Hallo");
4737 } catch (Exception ex)
4739 ex.printStackTrace();
4743 public void tabSelectionChanged(int index)
4747 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4748 viewport = alignPanel.av;
4749 setMenusFromViewport(viewport);
4753 public void tabbedPane_mousePressed(MouseEvent e)
4755 if (SwingUtilities.isRightMouseButton(e))
4757 String reply = JOptionPane.showInternalInputDialog(this,
4758 "Enter View Name", "Edit View Name",
4759 JOptionPane.QUESTION_MESSAGE);
4763 viewport.viewName = reply;
4764 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4769 public AlignViewport getCurrentView()
4775 * Open the dialog for regex description parsing.
4777 protected void extractScores_actionPerformed(ActionEvent e)
4779 ParseProperties pp = new jalview.analysis.ParseProperties(
4780 viewport.alignment);
4781 // TODO: verify regex and introduce GUI dialog for version 2.5
4782 // if (pp.getScoresFromDescription("col", "score column ",
4783 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4785 if (pp.getScoresFromDescription("description column",
4786 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4788 buildSortByAnnotationScoresMenu();
4796 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4799 protected void showDbRefs_actionPerformed(ActionEvent e)
4801 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4807 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4810 protected void showNpFeats_actionPerformed(ActionEvent e)
4812 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4816 * find the viewport amongst the tabs in this alignment frame and close that
4821 public boolean closeView(AlignViewport av)
4825 this.closeMenuItem_actionPerformed(false);
4828 Component[] comp = tabbedPane.getComponents();
4829 for (int i = 0; comp != null && i < comp.length; i++)
4831 if (comp[i] instanceof AlignmentPanel)
4833 if (((AlignmentPanel) comp[i]).av == av)
4836 closeView((AlignmentPanel) comp[i]);
4844 protected void build_fetchdbmenu(JMenu webService)
4846 // Temporary hack - DBRef Fetcher always top level ws entry.
4847 // TODO We probably want to store a sequence database checklist in
4848 // preferences and have checkboxes.. rather than individual sources selected
4850 final JMenu rfetch = new JMenu("Fetch DB References");
4851 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4852 webService.add(rfetch);
4854 JMenuItem fetchr = new JMenuItem("Standard Databases");
4855 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4856 fetchr.addActionListener(new ActionListener()
4859 public void actionPerformed(ActionEvent e)
4861 new Thread(new Runnable()
4866 new jalview.ws.DBRefFetcher(alignPanel.av
4867 .getSequenceSelection(), alignPanel.alignFrame)
4868 .fetchDBRefs(false);
4876 final AlignFrame me = this;
4877 new Thread(new Runnable()
4881 final jalview.ws.SequenceFetcher sf = SequenceFetcher
4882 .getSequenceFetcherSingleton(me);
4883 final String[] otherdb = sf.getOrderedSupportedSources();
4884 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4885 // jalview.util.QuickSort.sort(otherdb, otherdb);
4886 javax.swing.SwingUtilities.invokeLater(new Runnable()
4891 JMenu dfetch = new JMenu();
4894 int comp = 0, mcomp = 15;
4895 String mname = null;
4896 if (otherdb != null && otherdb.length > 0)
4898 for (int i = 0; i < otherdb.length; i++)
4900 String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
4903 mname = "from '" + dbname + "'";
4905 fetchr = new JMenuItem(otherdb[i]);
4906 final String[] dassource = new String[]
4908 fetchr.addActionListener(new ActionListener()
4911 public void actionPerformed(ActionEvent e)
4913 new Thread(new Runnable()
4918 new jalview.ws.DBRefFetcher(alignPanel.av
4919 .getSequenceSelection(),
4920 alignPanel.alignFrame, dassource)
4921 .fetchDBRefs(false);
4927 fetchr.setToolTipText("Retrieve from " + dbname);
4929 if (comp++ == mcomp || i == (otherdb.length - 1))
4931 dfetch.setText(mname + " to '" + dbname + "'");
4933 dfetch = new JMenu();
4947 * Left justify the whole alignment.
4949 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4951 AlignmentI al = viewport.getAlignment();
4953 viewport.firePropertyChange("alignment", null, al);
4957 * Right justify the whole alignment.
4959 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4961 AlignmentI al = viewport.getAlignment();
4963 viewport.firePropertyChange("alignment", null, al);
4966 public void setShowSeqFeatures(boolean b)
4968 showSeqFeatures.setSelected(true);
4969 viewport.setShowSequenceFeatures(true);
4976 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
4977 * awt.event.ActionEvent)
4979 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
4981 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
4982 alignPanel.paintAlignment(true);
4989 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
4992 protected void showGroupConsensus_actionPerformed(ActionEvent e)
4994 viewport.setShowGroupConsensus(showGroupConsensus.getState());
4995 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5003 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5004 * .event.ActionEvent)
5006 protected void showGroupConservation_actionPerformed(ActionEvent e)
5008 viewport.setShowGroupConservation(showGroupConservation.getState());
5009 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5016 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5017 * .event.ActionEvent)
5019 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5021 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5022 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5029 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5030 * .event.ActionEvent)
5032 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5034 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5035 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5038 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5040 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5047 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5048 * .event.ActionEvent)
5050 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5052 if (viewport.getSelectionGroup() != null)
5054 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5055 viewport.getSequenceSelection(),
5056 viewport.getAlignmentView(true).getSequenceStrings(
5057 viewport.getGapCharacter()),
5058 viewport.alignment.getGroups());
5059 viewport.alignment.deleteAllGroups();
5060 viewport.sequenceColours = null;
5061 viewport.setSelectionGroup(null);
5062 // set view properties for each group
5063 for (int g = 0; g < gps.length; g++)
5065 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5066 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5067 viewport.alignment.addGroup(gps[g]);
5068 Color col = new Color((int) (Math.random() * 255),
5069 (int) (Math.random() * 255), (int) (Math.random() * 255));
5070 col = col.brighter();
5071 for (Enumeration sq = gps[g].getSequences(null).elements(); sq
5072 .hasMoreElements(); viewport.setSequenceColour(
5073 (SequenceI) sq.nextElement(), col))
5076 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5077 alignPanel.updateAnnotation();
5078 alignPanel.paintAlignment(true);
5083 * make the given alignmentPanel the currently selected tab
5085 * @param alignmentPanel
5087 public void setDisplayedView(AlignmentPanel alignmentPanel)
5089 if (!viewport.getSequenceSetId().equals(
5090 alignmentPanel.av.getSequenceSetId()))
5093 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5095 if (tabbedPane != null
5096 & alignPanels.indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5098 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5103 class PrintThread extends Thread
5107 public PrintThread(AlignmentPanel ap)
5112 static PageFormat pf;
5116 PrinterJob printJob = PrinterJob.getPrinterJob();
5120 printJob.setPrintable(ap, pf);
5124 printJob.setPrintable(ap);
5127 if (printJob.printDialog())
5132 } catch (Exception PrintException)
5134 PrintException.printStackTrace();