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);
592 ap.av.updateStrucConsensus(ap);
596 public void setInitialTabVisible()
598 expandViews.setEnabled(true);
599 gatherViews.setEnabled(true);
600 tabbedPane.setVisible(true);
601 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
602 tabbedPane.addTab(first.av.viewName, first);
603 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
606 public AlignViewport getViewport()
611 /* Set up intrinsic listeners for dynamically generated GUI bits. */
612 private void addServiceListeners()
614 final java.beans.PropertyChangeListener thisListener;
615 Desktop.instance.addJalviewPropertyChangeListener("services",
616 thisListener = new java.beans.PropertyChangeListener()
618 public void propertyChange(PropertyChangeEvent evt)
620 // // System.out.println("Discoverer property change.");
621 // if (evt.getPropertyName().equals("services"))
623 SwingUtilities.invokeLater(new Runnable()
629 .println("Rebuild WS Menu for service change");
630 BuildWebServiceMenu();
637 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
639 public void internalFrameClosed(
640 javax.swing.event.InternalFrameEvent evt)
642 System.out.println("deregistering discoverer listener");
643 Desktop.instance.removeJalviewPropertyChangeListener("services",
645 closeMenuItem_actionPerformed(true);
648 // Finally, build the menu once to get current service state
649 new Thread(new Runnable()
653 BuildWebServiceMenu();
658 public void setGUINucleotide(boolean nucleotide)
660 showTranslation.setVisible(nucleotide);
661 conservationMenuItem.setEnabled(!nucleotide);
662 modifyConservation.setEnabled(!nucleotide);
663 showGroupConservation.setEnabled(!nucleotide);
664 // Remember AlignFrame always starts as protein
667 calculateMenu.remove(calculateMenu.getItemCount() - 2);
672 * set up menus for the currently viewport. This may be called after any
673 * operation that affects the data in the current view (selection changed,
674 * etc) to update the menus to reflect the new state.
676 public void setMenusForViewport()
678 setMenusFromViewport(viewport);
682 * Need to call this method when tabs are selected for multiple views, or when
683 * loading from Jalview2XML.java
688 void setMenusFromViewport(AlignViewport av)
690 padGapsMenuitem.setSelected(av.padGaps);
691 colourTextMenuItem.setSelected(av.showColourText);
692 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
693 conservationMenuItem.setSelected(av.getConservationSelected());
694 seqLimits.setSelected(av.getShowJVSuffix());
695 idRightAlign.setSelected(av.rightAlignIds);
696 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
697 renderGapsMenuItem.setSelected(av.renderGaps);
698 wrapMenuItem.setSelected(av.wrapAlignment);
699 scaleAbove.setVisible(av.wrapAlignment);
700 scaleLeft.setVisible(av.wrapAlignment);
701 scaleRight.setVisible(av.wrapAlignment);
702 annotationPanelMenuItem.setState(av.showAnnotation);
703 viewBoxesMenuItem.setSelected(av.showBoxes);
704 viewTextMenuItem.setSelected(av.showText);
705 showNonconservedMenuItem.setSelected(av.showUnconserved);
706 showGroupConsensus.setSelected(av.showGroupConsensus);
707 showGroupConservation.setSelected(av.showGroupConservation);
708 showConsensusHistogram.setSelected(av.showConsensusHistogram);
709 showSequenceLogo.setSelected(av.showSequenceLogo);
710 setColourSelected(ColourSchemeProperty.getColourName(av
711 .getGlobalColourScheme()));
713 showSeqFeatures.setSelected(av.showSequenceFeatures);
714 hiddenMarkers.setState(av.showHiddenMarkers);
715 applyToAllGroups.setState(av.colourAppliesToAllGroups);
716 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
717 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
719 setShowProductsEnabled();
724 Hashtable progressBars, progressBarHandlers;
729 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
731 public void setProgressBar(String message, long id)
733 if (progressBars == null)
735 progressBars = new Hashtable();
736 progressBarHandlers = new Hashtable();
739 JPanel progressPanel;
740 Long lId = new Long(id);
741 GridLayout layout = (GridLayout) statusPanel.getLayout();
742 if (progressBars.get(lId) != null)
744 progressPanel = (JPanel) progressBars.get(new Long(id));
745 statusPanel.remove(progressPanel);
746 progressBars.remove(lId);
747 progressPanel = null;
750 statusBar.setText(message);
752 if (progressBarHandlers.contains(lId))
754 progressBarHandlers.remove(lId);
756 layout.setRows(layout.getRows() - 1);
760 progressPanel = new JPanel(new BorderLayout(10, 5));
762 JProgressBar progressBar = new JProgressBar();
763 progressBar.setIndeterminate(true);
765 progressPanel.add(new JLabel(message), BorderLayout.WEST);
766 progressPanel.add(progressBar, BorderLayout.CENTER);
768 layout.setRows(layout.getRows() + 1);
769 statusPanel.add(progressPanel);
771 progressBars.put(lId, progressPanel);
774 // setMenusForViewport();
778 public void registerHandler(final long id,
779 final IProgressIndicatorHandler handler)
781 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
784 "call setProgressBar before registering the progress bar's handler.");
786 progressBarHandlers.put(new Long(id), handler);
787 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
788 if (handler.canCancel())
790 JButton cancel = new JButton("Cancel");
791 final IProgressIndicator us = this;
792 cancel.addActionListener(new ActionListener()
795 public void actionPerformed(ActionEvent e)
797 handler.cancelActivity(id);
800 + ((JLabel) progressPanel.getComponent(0))
804 progressPanel.add(cancel, BorderLayout.EAST);
810 * @return true if any progress bars are still active
812 public boolean operationInProgress()
814 if (progressBars != null && progressBars.size() > 0)
822 * Added so Castor Mapping file can obtain Jalview Version
824 public String getVersion()
826 return jalview.bin.Cache.getProperty("VERSION");
829 public FeatureRenderer getFeatureRenderer()
831 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
834 public void fetchSequence_actionPerformed(ActionEvent e)
836 new SequenceFetcher(this);
839 public void addFromFile_actionPerformed(ActionEvent e)
841 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
844 public void reload_actionPerformed(ActionEvent e)
846 if (fileName != null)
848 // TODO: work out how to recover feature settings for correct view(s) when
850 if (currentFileFormat.equals("Jalview"))
852 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
853 for (int i = 0; i < frames.length; i++)
855 if (frames[i] instanceof AlignFrame && frames[i] != this
856 && ((AlignFrame) frames[i]).fileName.equals(fileName))
860 frames[i].setSelected(true);
861 Desktop.instance.closeAssociatedWindows();
862 } catch (java.beans.PropertyVetoException ex)
868 Desktop.instance.closeAssociatedWindows();
870 FileLoader loader = new FileLoader();
871 String protocol = fileName.startsWith("http:") ? "URL" : "File";
872 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
876 Rectangle bounds = this.getBounds();
878 FileLoader loader = new FileLoader();
879 String protocol = fileName.startsWith("http:") ? "URL" : "File";
880 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
881 protocol, currentFileFormat);
883 newframe.setBounds(bounds);
884 if (featureSettings != null && featureSettings.isShowing())
886 final Rectangle fspos = featureSettings.frame.getBounds();
887 // TODO: need a 'show feature settings' function that takes bounds -
888 // need to refactor Desktop.addFrame
889 newframe.featureSettings_actionPerformed(null);
890 final FeatureSettings nfs = newframe.featureSettings;
891 SwingUtilities.invokeLater(new Runnable()
895 nfs.frame.setBounds(fspos);
898 this.featureSettings.close();
899 this.featureSettings = null;
901 this.closeMenuItem_actionPerformed(true);
906 public void addFromText_actionPerformed(ActionEvent e)
908 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
911 public void addFromURL_actionPerformed(ActionEvent e)
913 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
916 public void save_actionPerformed(ActionEvent e)
919 || (currentFileFormat == null || !jalview.io.FormatAdapter
920 .isValidIOFormat(currentFileFormat, true))
921 || fileName.startsWith("http"))
923 saveAs_actionPerformed(null);
927 saveAlignment(fileName, currentFileFormat);
937 public void saveAs_actionPerformed(ActionEvent e)
939 JalviewFileChooser chooser = new JalviewFileChooser(
940 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
941 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
942 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
943 currentFileFormat, false);
945 chooser.setFileView(new JalviewFileView());
946 chooser.setDialogTitle("Save Alignment to file");
947 chooser.setToolTipText("Save");
949 int value = chooser.showSaveDialog(this);
951 if (value == JalviewFileChooser.APPROVE_OPTION)
953 currentFileFormat = chooser.getSelectedFormat();
954 if (currentFileFormat == null)
956 JOptionPane.showInternalMessageDialog(Desktop.desktop,
957 "You must select a file format before saving!",
958 "File format not specified", JOptionPane.WARNING_MESSAGE);
959 value = chooser.showSaveDialog(this);
963 fileName = chooser.getSelectedFile().getPath();
965 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
968 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
969 if (currentFileFormat.indexOf(" ") > -1)
971 currentFileFormat = currentFileFormat.substring(0,
972 currentFileFormat.indexOf(" "));
974 saveAlignment(fileName, currentFileFormat);
978 public boolean saveAlignment(String file, String format)
980 boolean success = true;
982 if (format.equalsIgnoreCase("Jalview"))
984 String shortName = title;
986 if (shortName.indexOf(java.io.File.separatorChar) > -1)
988 shortName = shortName.substring(shortName
989 .lastIndexOf(java.io.File.separatorChar) + 1);
992 success = new Jalview2XML().SaveAlignment(this, file, shortName);
994 statusBar.setText("Successfully saved to file: " + fileName + " in "
995 + format + " format.");
1000 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1002 warningMessage("Cannot save file " + fileName + " using format "
1003 + format, "Alignment output format not supported");
1004 saveAs_actionPerformed(null);
1005 // JBPNote need to have a raise_gui flag here
1009 String[] omitHidden = null;
1011 if (viewport.hasHiddenColumns)
1013 int reply = JOptionPane
1014 .showInternalConfirmDialog(
1016 "The Alignment contains hidden columns."
1017 + "\nDo you want to save only the visible alignment?",
1018 "Save / Omit Hidden Columns",
1019 JOptionPane.YES_NO_OPTION,
1020 JOptionPane.QUESTION_MESSAGE);
1022 if (reply == JOptionPane.YES_OPTION)
1024 omitHidden = viewport.getViewAsString(false);
1027 FormatAdapter f = new FormatAdapter();
1028 String output = f.formatSequences(format,
1029 (Alignment) viewport.alignment, // class cast exceptions will
1030 // occur in the distant future
1031 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
1041 java.io.PrintWriter out = new java.io.PrintWriter(
1042 new java.io.FileWriter(file));
1046 this.setTitle(file);
1047 statusBar.setText("Successfully saved to file: " + fileName
1048 + " in " + format + " format.");
1049 } catch (Exception ex)
1052 ex.printStackTrace();
1059 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1060 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1066 private void warningMessage(String warning, String title)
1068 if (new jalview.util.Platform().isHeadless())
1070 System.err.println("Warning: " + title + "\nWarning: " + warning);
1075 JOptionPane.showInternalMessageDialog(this, warning, title,
1076 JOptionPane.WARNING_MESSAGE);
1087 protected void outputText_actionPerformed(ActionEvent e)
1089 String[] omitHidden = null;
1091 if (viewport.hasHiddenColumns)
1093 int reply = JOptionPane
1094 .showInternalConfirmDialog(
1096 "The Alignment contains hidden columns."
1097 + "\nDo you want to output only the visible alignment?",
1098 "Save / Omit Hidden Columns",
1099 JOptionPane.YES_NO_OPTION,
1100 JOptionPane.QUESTION_MESSAGE);
1102 if (reply == JOptionPane.YES_OPTION)
1104 omitHidden = viewport.getViewAsString(false);
1108 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1109 cap.setForInput(null);
1113 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1114 viewport.alignment, omitHidden, viewport.colSel));
1115 Desktop.addInternalFrame(cap,
1116 "Alignment output - " + e.getActionCommand(), 600, 500);
1117 } catch (OutOfMemoryError oom)
1119 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1131 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1133 new HTMLOutput(alignPanel,
1134 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1135 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1138 public void createImageMap(File file, String image)
1140 alignPanel.makePNGImageMap(file, image);
1149 public void createPNG(File f)
1151 alignPanel.makePNG(f);
1160 public void createEPS(File f)
1162 alignPanel.makeEPS(f);
1165 public void pageSetup_actionPerformed(ActionEvent e)
1167 PrinterJob printJob = PrinterJob.getPrinterJob();
1168 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1177 public void printMenuItem_actionPerformed(ActionEvent e)
1179 // Putting in a thread avoids Swing painting problems
1180 PrintThread thread = new PrintThread(alignPanel);
1184 public void exportFeatures_actionPerformed(ActionEvent e)
1186 new AnnotationExporter().exportFeatures(alignPanel);
1189 public void exportAnnotations_actionPerformed(ActionEvent e)
1191 new AnnotationExporter().exportAnnotations(
1193 viewport.showAnnotation ? viewport.alignment
1194 .getAlignmentAnnotation() : null, viewport.alignment
1196 ((Alignment) viewport.alignment).alignmentProperties);
1199 public void associatedData_actionPerformed(ActionEvent e)
1201 // Pick the tree file
1202 JalviewFileChooser chooser = new JalviewFileChooser(
1203 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1204 chooser.setFileView(new JalviewFileView());
1205 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1206 chooser.setToolTipText("Load Jalview Annotations / Features file");
1208 int value = chooser.showOpenDialog(null);
1210 if (value == JalviewFileChooser.APPROVE_OPTION)
1212 String choice = chooser.getSelectedFile().getPath();
1213 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1214 loadJalviewDataFile(choice, null, null, null);
1220 * Close the current view or all views in the alignment frame. If the frame
1221 * only contains one view then the alignment will be removed from memory.
1223 * @param closeAllTabs
1225 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1227 if (alignPanels != null && alignPanels.size() < 2)
1229 closeAllTabs = true;
1234 if (alignPanels != null)
1238 if (this.isClosed())
1240 // really close all the windows - otherwise wait till
1241 // setClosed(true) is called
1242 for (int i = 0; i < alignPanels.size(); i++)
1244 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1251 closeView(alignPanel);
1257 this.setClosed(true);
1259 } catch (Exception ex)
1261 ex.printStackTrace();
1266 * close alignPanel2 and shuffle tabs appropriately.
1268 * @param alignPanel2
1270 public void closeView(AlignmentPanel alignPanel2)
1272 int index = tabbedPane.getSelectedIndex();
1273 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1274 alignPanels.removeElement(alignPanel2);
1276 // if (viewport == alignPanel2.av)
1280 alignPanel2.closePanel();
1283 tabbedPane.removeTabAt(closedindex);
1284 tabbedPane.validate();
1286 if (index > closedindex || index == tabbedPane.getTabCount())
1288 // modify currently selected tab index if necessary.
1292 this.tabSelectionChanged(index);
1298 void updateEditMenuBar()
1301 if (viewport.historyList.size() > 0)
1303 undoMenuItem.setEnabled(true);
1304 CommandI command = (CommandI) viewport.historyList.peek();
1305 undoMenuItem.setText("Undo " + command.getDescription());
1309 undoMenuItem.setEnabled(false);
1310 undoMenuItem.setText("Undo");
1313 if (viewport.redoList.size() > 0)
1315 redoMenuItem.setEnabled(true);
1317 CommandI command = (CommandI) viewport.redoList.peek();
1318 redoMenuItem.setText("Redo " + command.getDescription());
1322 redoMenuItem.setEnabled(false);
1323 redoMenuItem.setText("Redo");
1327 public void addHistoryItem(CommandI command)
1329 if (command.getSize() > 0)
1331 viewport.historyList.push(command);
1332 viewport.redoList.clear();
1333 updateEditMenuBar();
1334 viewport.hasHiddenColumns = (viewport.colSel != null
1335 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1336 .getHiddenColumns().size() > 0);
1342 * @return alignment objects for all views
1344 AlignmentI[] getViewAlignments()
1346 if (alignPanels != null)
1348 Enumeration e = alignPanels.elements();
1349 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1350 for (int i = 0; e.hasMoreElements(); i++)
1352 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1356 if (viewport != null)
1358 return new AlignmentI[]
1359 { viewport.alignment };
1370 protected void undoMenuItem_actionPerformed(ActionEvent e)
1372 if (viewport.historyList.empty())
1374 CommandI command = (CommandI) viewport.historyList.pop();
1375 viewport.redoList.push(command);
1376 command.undoCommand(getViewAlignments());
1378 AlignViewport originalSource = getOriginatingSource(command);
1379 updateEditMenuBar();
1381 if (originalSource != null)
1383 originalSource.hasHiddenColumns = (viewport.colSel != null
1384 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1385 .getHiddenColumns().size() > 0);
1386 originalSource.firePropertyChange("alignment", null,
1387 originalSource.alignment.getSequences());
1397 protected void redoMenuItem_actionPerformed(ActionEvent e)
1399 if (viewport.redoList.size() < 1)
1404 CommandI command = (CommandI) viewport.redoList.pop();
1405 viewport.historyList.push(command);
1406 command.doCommand(getViewAlignments());
1408 AlignViewport originalSource = getOriginatingSource(command);
1409 updateEditMenuBar();
1411 if (originalSource != null)
1413 originalSource.hasHiddenColumns = (viewport.colSel != null
1414 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1415 .getHiddenColumns().size() > 0);
1416 originalSource.firePropertyChange("alignment", null,
1417 originalSource.alignment.getSequences());
1421 AlignViewport getOriginatingSource(CommandI command)
1423 AlignViewport originalSource = null;
1424 // For sequence removal and addition, we need to fire
1425 // the property change event FROM the viewport where the
1426 // original alignment was altered
1427 AlignmentI al = null;
1428 if (command instanceof EditCommand)
1430 EditCommand editCommand = (EditCommand) command;
1431 al = editCommand.getAlignment();
1432 Vector comps = (Vector) PaintRefresher.components.get(viewport
1433 .getSequenceSetId());
1435 for (int i = 0; i < comps.size(); i++)
1437 if (comps.elementAt(i) instanceof AlignmentPanel)
1439 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1441 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1448 if (originalSource == null)
1450 // The original view is closed, we must validate
1451 // the current view against the closed view first
1454 PaintRefresher.validateSequences(al, viewport.alignment);
1457 originalSource = viewport;
1460 return originalSource;
1469 public void moveSelectedSequences(boolean up)
1471 SequenceGroup sg = viewport.getSelectionGroup();
1480 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1482 SequenceI seq = viewport.alignment.getSequenceAt(i);
1484 if (!sg.getSequences(null).contains(seq))
1489 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1491 if (sg.getSequences(null).contains(temp))
1496 viewport.alignment.getSequences().setElementAt(temp, i);
1497 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1502 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1504 SequenceI seq = viewport.alignment.getSequenceAt(i);
1506 if (!sg.getSequences(null).contains(seq))
1511 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1513 if (sg.getSequences(null).contains(temp))
1518 viewport.alignment.getSequences().setElementAt(temp, i);
1519 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1523 alignPanel.paintAlignment(true);
1526 synchronized void slideSequences(boolean right, int size)
1528 Vector sg = new Vector();
1529 if (viewport.cursorMode)
1531 sg.addElement(viewport.alignment
1532 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1534 else if (viewport.getSelectionGroup() != null
1535 && viewport.getSelectionGroup().getSize() != viewport.alignment
1538 sg = viewport.getSelectionGroup().getSequences(
1539 viewport.hiddenRepSequences);
1547 Vector invertGroup = new Vector();
1549 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1551 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1552 invertGroup.add(viewport.alignment.getSequenceAt(i));
1555 SequenceI[] seqs1 = new SequenceI[sg.size()];
1556 for (int i = 0; i < sg.size(); i++)
1557 seqs1[i] = (SequenceI) sg.elementAt(i);
1559 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1560 for (int i = 0; i < invertGroup.size(); i++)
1561 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1563 SlideSequencesCommand ssc;
1565 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1566 size, viewport.getGapCharacter());
1568 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1569 size, viewport.getGapCharacter());
1571 int groupAdjustment = 0;
1572 if (ssc.getGapsInsertedBegin() && right)
1574 if (viewport.cursorMode)
1575 alignPanel.seqPanel.moveCursor(size, 0);
1577 groupAdjustment = size;
1579 else if (!ssc.getGapsInsertedBegin() && !right)
1581 if (viewport.cursorMode)
1582 alignPanel.seqPanel.moveCursor(-size, 0);
1584 groupAdjustment = -size;
1587 if (groupAdjustment != 0)
1589 viewport.getSelectionGroup().setStartRes(
1590 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1591 viewport.getSelectionGroup().setEndRes(
1592 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1595 boolean appendHistoryItem = false;
1596 if (viewport.historyList != null && viewport.historyList.size() > 0
1597 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1599 appendHistoryItem = ssc
1600 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1604 if (!appendHistoryItem)
1605 addHistoryItem(ssc);
1616 protected void copy_actionPerformed(ActionEvent e)
1619 if (viewport.getSelectionGroup() == null)
1623 // TODO: preserve the ordering of displayed alignment annotation in any
1624 // internal paste (particularly sequence associated annotation)
1625 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1626 String[] omitHidden = null;
1628 if (viewport.hasHiddenColumns)
1630 omitHidden = viewport.getViewAsString(true);
1633 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1636 StringSelection ss = new StringSelection(output);
1640 jalview.gui.Desktop.internalCopy = true;
1641 // Its really worth setting the clipboard contents
1642 // to empty before setting the large StringSelection!!
1643 Toolkit.getDefaultToolkit().getSystemClipboard()
1644 .setContents(new StringSelection(""), null);
1646 Toolkit.getDefaultToolkit().getSystemClipboard()
1647 .setContents(ss, Desktop.instance);
1648 } catch (OutOfMemoryError er)
1650 new OOMWarning("copying region", er);
1654 Vector hiddenColumns = null;
1655 if (viewport.hasHiddenColumns)
1657 hiddenColumns = new Vector();
1658 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1659 .getSelectionGroup().getEndRes();
1660 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1663 int[] region = (int[]) viewport.getColumnSelection()
1664 .getHiddenColumns().elementAt(i);
1665 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1667 hiddenColumns.addElement(new int[]
1668 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1673 Desktop.jalviewClipboard = new Object[]
1674 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1675 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1684 protected void pasteNew_actionPerformed(ActionEvent e)
1695 protected void pasteThis_actionPerformed(ActionEvent e)
1701 * Paste contents of Jalview clipboard
1703 * @param newAlignment
1704 * true to paste to a new alignment, otherwise add to this.
1706 void paste(boolean newAlignment)
1708 boolean externalPaste = true;
1711 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1712 Transferable contents = c.getContents(this);
1714 if (contents == null)
1722 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1723 if (str.length() < 1)
1728 format = new IdentifyFile().Identify(str, "Paste");
1730 } catch (OutOfMemoryError er)
1732 new OOMWarning("Out of memory pasting sequences!!", er);
1736 SequenceI[] sequences;
1737 boolean annotationAdded = false;
1738 AlignmentI alignment = null;
1740 if (Desktop.jalviewClipboard != null)
1742 // The clipboard was filled from within Jalview, we must use the
1744 // And dataset from the copied alignment
1745 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1746 // be doubly sure that we create *new* sequence objects.
1747 sequences = new SequenceI[newseq.length];
1748 for (int i = 0; i < newseq.length; i++)
1750 sequences[i] = new Sequence(newseq[i]);
1752 alignment = new Alignment(sequences);
1753 externalPaste = false;
1757 // parse the clipboard as an alignment.
1758 alignment = new FormatAdapter().readFile(str, "Paste", format);
1759 sequences = alignment.getSequencesArray();
1767 if (Desktop.jalviewClipboard != null)
1769 // dataset is inherited
1770 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1774 // new dataset is constructed
1775 alignment.setDataset(null);
1777 alwidth = alignment.getWidth() + 1;
1781 AlignmentI pastedal = alignment; // preserve pasted alignment object
1782 // Add pasted sequences and dataset into existing alignment.
1783 alignment = viewport.getAlignment();
1784 alwidth = alignment.getWidth() + 1;
1785 // decide if we need to import sequences from an existing dataset
1786 boolean importDs = Desktop.jalviewClipboard != null
1787 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1788 // importDs==true instructs us to copy over new dataset sequences from
1789 // an existing alignment
1790 Vector newDs = (importDs) ? new Vector() : null; // used to create
1791 // minimum dataset set
1793 for (int i = 0; i < sequences.length; i++)
1797 newDs.addElement(null);
1799 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1801 if (importDs && ds != null)
1803 if (!newDs.contains(ds))
1805 newDs.setElementAt(ds, i);
1806 ds = new Sequence(ds);
1807 // update with new dataset sequence
1808 sequences[i].setDatasetSequence(ds);
1812 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1817 // copy and derive new dataset sequence
1818 sequences[i] = sequences[i].deriveSequence();
1819 alignment.getDataset().addSequence(
1820 sequences[i].getDatasetSequence());
1821 // TODO: avoid creation of duplicate dataset sequences with a
1822 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1824 alignment.addSequence(sequences[i]); // merges dataset
1828 newDs.clear(); // tidy up
1830 if (pastedal.getAlignmentAnnotation() != null)
1832 // Add any annotation attached to alignment.
1833 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1834 for (int i = 0; i < alann.length; i++)
1836 annotationAdded = true;
1837 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1839 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1840 newann.padAnnotation(alwidth);
1841 alignment.addAnnotation(newann);
1851 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1852 sequences, 0, alignment.getWidth(), alignment));
1854 // Add any annotations attached to sequences
1855 for (int i = 0; i < sequences.length; i++)
1857 if (sequences[i].getAnnotation() != null)
1859 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1861 annotationAdded = true;
1862 sequences[i].getAnnotation()[a].adjustForAlignment();
1863 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1864 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1869 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1876 // propagate alignment changed.
1877 viewport.setEndSeq(alignment.getHeight());
1878 if (annotationAdded)
1880 // Duplicate sequence annotation in all views.
1881 AlignmentI[] alview = this.getViewAlignments();
1882 for (int i = 0; i < sequences.length; i++)
1884 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1887 for (int avnum = 0; avnum < alview.length; avnum++)
1889 if (alview[avnum] != alignment)
1891 // duplicate in a view other than the one with input focus
1892 int avwidth = alview[avnum].getWidth() + 1;
1893 // this relies on sann being preserved after we
1894 // modify the sequence's annotation array for each duplication
1895 for (int a = 0; a < sann.length; a++)
1897 AlignmentAnnotation newann = new AlignmentAnnotation(
1899 sequences[i].addAlignmentAnnotation(newann);
1900 newann.padAnnotation(avwidth);
1901 alview[avnum].addAnnotation(newann); // annotation was
1902 // duplicated earlier
1903 alview[avnum].setAnnotationIndex(newann, a);
1908 buildSortByAnnotationScoresMenu();
1910 viewport.firePropertyChange("alignment", null,
1911 alignment.getSequences());
1916 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1918 String newtitle = new String("Copied sequences");
1920 if (Desktop.jalviewClipboard != null
1921 && Desktop.jalviewClipboard[2] != null)
1923 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1924 for (int i = 0; i < hc.size(); i++)
1926 int[] region = (int[]) hc.elementAt(i);
1927 af.viewport.hideColumns(region[0], region[1]);
1931 // >>>This is a fix for the moment, until a better solution is
1933 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1935 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1937 // TODO: maintain provenance of an alignment, rather than just make the
1938 // title a concatenation of operations.
1941 if (title.startsWith("Copied sequences"))
1947 newtitle = newtitle.concat("- from " + title);
1952 newtitle = new String("Pasted sequences");
1955 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1960 } catch (Exception ex)
1962 ex.printStackTrace();
1963 System.out.println("Exception whilst pasting: " + ex);
1964 // could be anything being pasted in here
1975 protected void cut_actionPerformed(ActionEvent e)
1977 copy_actionPerformed(null);
1978 delete_actionPerformed(null);
1987 protected void delete_actionPerformed(ActionEvent evt)
1990 SequenceGroup sg = viewport.getSelectionGroup();
1996 Vector seqs = new Vector();
1998 for (int i = 0; i < sg.getSize(); i++)
2000 seq = sg.getSequenceAt(i);
2001 seqs.addElement(seq);
2004 // If the cut affects all sequences, remove highlighted columns
2005 if (sg.getSize() == viewport.alignment.getHeight())
2007 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2008 sg.getEndRes() + 1);
2011 SequenceI[] cut = new SequenceI[seqs.size()];
2012 for (int i = 0; i < seqs.size(); i++)
2014 cut[i] = (SequenceI) seqs.elementAt(i);
2018 * //ADD HISTORY ITEM
2020 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2021 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2022 viewport.alignment));
2024 viewport.setSelectionGroup(null);
2025 viewport.sendSelection();
2026 viewport.alignment.deleteGroup(sg);
2028 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2030 if (viewport.getAlignment().getHeight() < 1)
2034 this.setClosed(true);
2035 } catch (Exception ex)
2047 protected void deleteGroups_actionPerformed(ActionEvent e)
2049 viewport.alignment.deleteAllGroups();
2050 viewport.sequenceColours = null;
2051 viewport.setSelectionGroup(null);
2052 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2053 alignPanel.updateAnnotation();
2054 alignPanel.paintAlignment(true);
2063 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2065 SequenceGroup sg = new SequenceGroup();
2067 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2069 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2072 sg.setEndRes(viewport.alignment.getWidth() - 1);
2073 viewport.setSelectionGroup(sg);
2074 viewport.sendSelection();
2075 alignPanel.paintAlignment(true);
2076 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2085 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2087 if (viewport.cursorMode)
2089 alignPanel.seqPanel.keyboardNo1 = null;
2090 alignPanel.seqPanel.keyboardNo2 = null;
2092 viewport.setSelectionGroup(null);
2093 viewport.getColumnSelection().clear();
2094 viewport.setSelectionGroup(null);
2095 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2096 alignPanel.idPanel.idCanvas.searchResults = null;
2097 alignPanel.paintAlignment(true);
2098 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2099 viewport.sendSelection();
2108 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2110 SequenceGroup sg = viewport.getSelectionGroup();
2114 selectAllSequenceMenuItem_actionPerformed(null);
2119 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2121 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2124 alignPanel.paintAlignment(true);
2125 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2126 viewport.sendSelection();
2129 public void invertColSel_actionPerformed(ActionEvent e)
2131 viewport.invertColumnSelection();
2132 alignPanel.paintAlignment(true);
2133 viewport.sendSelection();
2142 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2144 trimAlignment(true);
2153 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2155 trimAlignment(false);
2158 void trimAlignment(boolean trimLeft)
2160 ColumnSelection colSel = viewport.getColumnSelection();
2163 if (colSel.size() > 0)
2167 column = colSel.getMin();
2171 column = colSel.getMax();
2175 if (viewport.getSelectionGroup() != null)
2177 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2178 viewport.hiddenRepSequences);
2182 seqs = viewport.alignment.getSequencesArray();
2185 TrimRegionCommand trimRegion;
2188 trimRegion = new TrimRegionCommand("Remove Left",
2189 TrimRegionCommand.TRIM_LEFT, seqs, column,
2190 viewport.alignment, viewport.colSel,
2191 viewport.selectionGroup);
2192 viewport.setStartRes(0);
2196 trimRegion = new TrimRegionCommand("Remove Right",
2197 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2198 viewport.alignment, viewport.colSel,
2199 viewport.selectionGroup);
2202 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2204 addHistoryItem(trimRegion);
2206 Vector groups = viewport.alignment.getGroups();
2208 for (int i = 0; i < groups.size(); i++)
2210 SequenceGroup sg = (SequenceGroup) groups.get(i);
2212 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2213 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2215 viewport.alignment.deleteGroup(sg);
2219 viewport.firePropertyChange("alignment", null, viewport
2220 .getAlignment().getSequences());
2230 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2232 int start = 0, end = viewport.alignment.getWidth() - 1;
2235 if (viewport.getSelectionGroup() != null)
2237 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2238 viewport.hiddenRepSequences);
2239 start = viewport.getSelectionGroup().getStartRes();
2240 end = viewport.getSelectionGroup().getEndRes();
2244 seqs = viewport.alignment.getSequencesArray();
2247 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2248 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2250 addHistoryItem(removeGapCols);
2252 statusBar.setText("Removed " + removeGapCols.getSize()
2253 + " empty columns.");
2255 // This is to maintain viewport position on first residue
2256 // of first sequence
2257 SequenceI seq = viewport.alignment.getSequenceAt(0);
2258 int startRes = seq.findPosition(viewport.startRes);
2259 // ShiftList shifts;
2260 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2261 // edit.alColumnChanges=shifts.getInverse();
2262 // if (viewport.hasHiddenColumns)
2263 // viewport.getColumnSelection().compensateForEdits(shifts);
2264 viewport.setStartRes(seq.findIndex(startRes) - 1);
2265 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2276 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2278 int start = 0, end = viewport.alignment.getWidth() - 1;
2281 if (viewport.getSelectionGroup() != null)
2283 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2284 viewport.hiddenRepSequences);
2285 start = viewport.getSelectionGroup().getStartRes();
2286 end = viewport.getSelectionGroup().getEndRes();
2290 seqs = viewport.alignment.getSequencesArray();
2293 // This is to maintain viewport position on first residue
2294 // of first sequence
2295 SequenceI seq = viewport.alignment.getSequenceAt(0);
2296 int startRes = seq.findPosition(viewport.startRes);
2298 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2299 viewport.alignment));
2301 viewport.setStartRes(seq.findIndex(startRes) - 1);
2303 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2314 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2316 viewport.padGaps = padGapsMenuitem.isSelected();
2317 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2323 // if (justifySeqs>0)
2325 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2337 public void findMenuItem_actionPerformed(ActionEvent e)
2342 public void newView_actionPerformed(ActionEvent e)
2349 * @param copyAnnotation
2350 * if true then duplicate all annnotation, groups and settings
2351 * @return new alignment panel, already displayed.
2353 public AlignmentPanel newView(boolean copyAnnotation)
2355 return newView(null, copyAnnotation);
2361 * title of newly created view
2362 * @return new alignment panel, already displayed.
2364 public AlignmentPanel newView(String viewTitle)
2366 return newView(viewTitle, true);
2372 * title of newly created view
2373 * @param copyAnnotation
2374 * if true then duplicate all annnotation, groups and settings
2375 * @return new alignment panel, already displayed.
2377 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2379 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2381 if (!copyAnnotation)
2383 // just remove all the current annotation except for the automatic stuff
2384 newap.av.alignment.deleteAllGroups();
2385 for (AlignmentAnnotation alan : newap.av.alignment
2386 .getAlignmentAnnotation())
2388 if (!alan.autoCalculated)
2390 newap.av.alignment.deleteAnnotation(alan);
2396 newap.av.gatherViewsHere = false;
2398 if (viewport.viewName == null)
2400 viewport.viewName = "Original";
2403 newap.av.historyList = viewport.historyList;
2404 newap.av.redoList = viewport.redoList;
2406 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2407 // make sure the new view has a unique name - this is essential for Jalview
2409 boolean addFirstIndex = false;
2410 if (viewTitle == null || viewTitle.trim().length() == 0)
2413 addFirstIndex = true;
2417 index = 1;// we count from 1 if given a specific name
2419 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2420 Vector comps = (Vector) PaintRefresher.components.get(viewport
2421 .getSequenceSetId());
2422 Vector existingNames = new Vector();
2423 for (int i = 0; i < comps.size(); i++)
2425 if (comps.elementAt(i) instanceof AlignmentPanel)
2427 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2428 if (!existingNames.contains(ap.av.viewName))
2430 existingNames.addElement(ap.av.viewName);
2435 while (existingNames.contains(newViewName))
2437 newViewName = viewTitle + " " + (++index);
2440 newap.av.viewName = newViewName;
2442 addAlignmentPanel(newap, true);
2444 if (alignPanels.size() == 2)
2446 viewport.gatherViewsHere = true;
2448 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2452 public void expandViews_actionPerformed(ActionEvent e)
2454 Desktop.instance.explodeViews(this);
2457 public void gatherViews_actionPerformed(ActionEvent e)
2459 Desktop.instance.gatherViews(this);
2468 public void font_actionPerformed(ActionEvent e)
2470 new FontChooser(alignPanel);
2479 protected void seqLimit_actionPerformed(ActionEvent e)
2481 viewport.setShowJVSuffix(seqLimits.isSelected());
2483 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2484 .calculateIdWidth());
2485 alignPanel.paintAlignment(true);
2488 public void idRightAlign_actionPerformed(ActionEvent e)
2490 viewport.rightAlignIds = idRightAlign.isSelected();
2491 alignPanel.paintAlignment(true);
2494 public void centreColumnLabels_actionPerformed(ActionEvent e)
2496 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2497 alignPanel.paintAlignment(true);
2503 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2505 protected void followHighlight_actionPerformed()
2507 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2509 alignPanel.scrollToPosition(
2510 alignPanel.seqPanel.seqCanvas.searchResults, false);
2520 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2522 viewport.setColourText(colourTextMenuItem.isSelected());
2523 alignPanel.paintAlignment(true);
2532 public void wrapMenuItem_actionPerformed(ActionEvent e)
2534 scaleAbove.setVisible(wrapMenuItem.isSelected());
2535 scaleLeft.setVisible(wrapMenuItem.isSelected());
2536 scaleRight.setVisible(wrapMenuItem.isSelected());
2537 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2538 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2541 public void showAllSeqs_actionPerformed(ActionEvent e)
2543 viewport.showAllHiddenSeqs();
2546 public void showAllColumns_actionPerformed(ActionEvent e)
2548 viewport.showAllHiddenColumns();
2552 public void hideSelSequences_actionPerformed(ActionEvent e)
2554 viewport.hideAllSelectedSeqs();
2555 alignPanel.paintAlignment(true);
2559 * called by key handler and the hide all/show all menu items
2564 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2567 boolean hide = false;
2568 SequenceGroup sg = viewport.getSelectionGroup();
2569 if (!toggleSeqs && !toggleCols)
2571 // Hide everything by the current selection - this is a hack - we do the
2572 // invert and then hide
2573 // first check that there will be visible columns after the invert.
2574 if ((viewport.colSel != null && viewport.colSel.getSelected() != null && viewport.colSel
2575 .getSelected().size() > 0)
2576 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2579 // now invert the sequence set, if required - empty selection implies
2580 // that no hiding is required.
2583 invertSequenceMenuItem_actionPerformed(null);
2584 sg = viewport.getSelectionGroup();
2588 viewport.expandColSelection(sg, true);
2589 // finally invert the column selection and get the new sequence
2591 invertColSel_actionPerformed(null);
2598 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
2600 hideSelSequences_actionPerformed(null);
2603 else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))
2605 showAllSeqs_actionPerformed(null);
2611 if (viewport.colSel.getSelected().size() > 0)
2613 hideSelColumns_actionPerformed(null);
2616 viewport.selectionGroup = sg;
2621 showAllColumns_actionPerformed(null);
2630 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2631 * event.ActionEvent)
2633 public void hideAllButSelection_actionPerformed(ActionEvent e)
2635 toggleHiddenRegions(false, false);
2642 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2645 public void hideAllSelection_actionPerformed(ActionEvent e)
2647 SequenceGroup sg = viewport.getSelectionGroup();
2648 viewport.expandColSelection(sg, false);
2649 viewport.hideAllSelectedSeqs();
2650 viewport.hideSelectedColumns();
2651 alignPanel.paintAlignment(true);
2658 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2661 public void showAllhidden_actionPerformed(ActionEvent e)
2663 viewport.showAllHiddenColumns();
2664 viewport.showAllHiddenSeqs();
2665 alignPanel.paintAlignment(true);
2668 public void hideSelColumns_actionPerformed(ActionEvent e)
2670 viewport.hideSelectedColumns();
2671 alignPanel.paintAlignment(true);
2674 public void hiddenMarkers_actionPerformed(ActionEvent e)
2676 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2686 protected void scaleAbove_actionPerformed(ActionEvent e)
2688 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2689 alignPanel.paintAlignment(true);
2698 protected void scaleLeft_actionPerformed(ActionEvent e)
2700 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2701 alignPanel.paintAlignment(true);
2710 protected void scaleRight_actionPerformed(ActionEvent e)
2712 viewport.setScaleRightWrapped(scaleRight.isSelected());
2713 alignPanel.paintAlignment(true);
2722 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2724 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2725 alignPanel.paintAlignment(true);
2734 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2736 viewport.setShowText(viewTextMenuItem.isSelected());
2737 alignPanel.paintAlignment(true);
2746 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2748 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2749 alignPanel.paintAlignment(true);
2752 public FeatureSettings featureSettings;
2754 public void featureSettings_actionPerformed(ActionEvent e)
2756 if (featureSettings != null)
2758 featureSettings.close();
2759 featureSettings = null;
2761 if (!showSeqFeatures.isSelected())
2763 // make sure features are actually displayed
2764 showSeqFeatures.setSelected(true);
2765 showSeqFeatures_actionPerformed(null);
2767 featureSettings = new FeatureSettings(this);
2771 * Set or clear 'Show Sequence Features'
2776 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2778 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2779 alignPanel.paintAlignment(true);
2780 if (alignPanel.getOverviewPanel() != null)
2782 alignPanel.getOverviewPanel().updateOverviewImage();
2787 * Set or clear 'Show Sequence Features'
2792 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2794 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2796 if (viewport.getShowSequenceFeaturesHeight())
2798 // ensure we're actually displaying features
2799 viewport.setShowSequenceFeatures(true);
2800 showSeqFeatures.setSelected(true);
2802 alignPanel.paintAlignment(true);
2803 if (alignPanel.getOverviewPanel() != null)
2805 alignPanel.getOverviewPanel().updateOverviewImage();
2815 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2817 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2818 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2821 public void alignmentProperties()
2823 JEditorPane editPane = new JEditorPane("text/html", "");
2824 editPane.setEditable(false);
2825 StringBuffer contents = new AlignmentProperties(viewport.alignment)
2827 editPane.setText("<html>" + contents.toString() + "</html>");
2828 JInternalFrame frame = new JInternalFrame();
2829 frame.getContentPane().add(new JScrollPane(editPane));
2831 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2832 + getTitle(), 500, 400);
2841 public void overviewMenuItem_actionPerformed(ActionEvent e)
2843 if (alignPanel.overviewPanel != null)
2848 JInternalFrame frame = new JInternalFrame();
2849 OverviewPanel overview = new OverviewPanel(alignPanel);
2850 frame.setContentPane(overview);
2851 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2852 frame.getWidth(), frame.getHeight());
2854 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2855 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2857 public void internalFrameClosed(
2858 javax.swing.event.InternalFrameEvent evt)
2860 alignPanel.setOverviewPanel(null);
2864 alignPanel.setOverviewPanel(overview);
2867 public void textColour_actionPerformed(ActionEvent e)
2869 new TextColourChooser().chooseColour(alignPanel, null);
2878 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2889 public void clustalColour_actionPerformed(ActionEvent e)
2891 changeColour(new ClustalxColourScheme(
2892 viewport.alignment.getSequences(),
2893 viewport.alignment.getWidth()));
2902 public void zappoColour_actionPerformed(ActionEvent e)
2904 changeColour(new ZappoColourScheme());
2913 public void taylorColour_actionPerformed(ActionEvent e)
2915 changeColour(new TaylorColourScheme());
2924 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2926 changeColour(new HydrophobicColourScheme());
2935 public void helixColour_actionPerformed(ActionEvent e)
2937 changeColour(new HelixColourScheme());
2946 public void strandColour_actionPerformed(ActionEvent e)
2948 changeColour(new StrandColourScheme());
2957 public void turnColour_actionPerformed(ActionEvent e)
2959 changeColour(new TurnColourScheme());
2968 public void buriedColour_actionPerformed(ActionEvent e)
2970 changeColour(new BuriedColourScheme());
2979 public void nucleotideColour_actionPerformed(ActionEvent e)
2981 changeColour(new NucleotideColourScheme());
2984 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
2986 changeColour(new PurinePyrimidineColourScheme());
2989 public void covariationColour_actionPerformed(ActionEvent e)
2991 changeColour(new CovariationColourScheme(viewport.alignment.getAlignmentAnnotation()[0]));
2994 public void annotationColour_actionPerformed(ActionEvent e)
2996 new AnnotationColourChooser(viewport, alignPanel);
2999 public void rnahelicesColour_actionPerformed(ActionEvent e)
3001 new RNAHelicesColourChooser(viewport, alignPanel);
3010 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3012 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3021 public void changeColour(ColourSchemeI cs)
3027 if (viewport.getAbovePIDThreshold())
3029 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3032 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3034 viewport.setGlobalColourScheme(cs);
3038 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3041 if (viewport.getConservationSelected())
3044 Alignment al = (Alignment) viewport.alignment;
3045 Conservation c = new Conservation("All",
3046 ResidueProperties.propHash, 3, al.getSequences(), 0,
3050 c.verdict(false, viewport.ConsPercGaps);
3052 cs.setConservation(c);
3054 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3059 cs.setConservation(null);
3062 cs.setConsensus(viewport.hconsensus);
3065 viewport.setGlobalColourScheme(cs);
3067 if (viewport.getColourAppliesToAllGroups())
3069 Vector groups = viewport.alignment.getGroups();
3071 for (int i = 0; i < groups.size(); i++)
3073 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
3081 if (cs instanceof ClustalxColourScheme)
3083 sg.cs = new ClustalxColourScheme(
3084 sg.getSequences(viewport.hiddenRepSequences),
3087 else if (cs instanceof UserColourScheme)
3089 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3095 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
3096 } catch (Exception ex)
3101 if (viewport.getAbovePIDThreshold()
3102 || cs instanceof PIDColourScheme
3103 || cs instanceof Blosum62ColourScheme)
3105 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3107 sg.cs.setConsensus(AAFrequency.calculate(
3108 sg.getSequences(viewport.hiddenRepSequences),
3109 sg.getStartRes(), sg.getEndRes() + 1));
3113 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3116 if (viewport.getConservationSelected())
3118 Conservation c = new Conservation("Group",
3119 ResidueProperties.propHash, 3,
3120 sg.getSequences(viewport.hiddenRepSequences),
3121 sg.getStartRes(), sg.getEndRes() + 1);
3123 c.verdict(false, viewport.ConsPercGaps);
3124 sg.cs.setConservation(c);
3128 sg.cs.setConservation(null);
3133 if (alignPanel.getOverviewPanel() != null)
3135 alignPanel.getOverviewPanel().updateOverviewImage();
3138 alignPanel.paintAlignment(true);
3147 protected void modifyPID_actionPerformed(ActionEvent e)
3149 if (viewport.getAbovePIDThreshold()
3150 && viewport.globalColourScheme != null)
3152 SliderPanel.setPIDSliderSource(alignPanel,
3153 viewport.getGlobalColourScheme(), "Background");
3154 SliderPanel.showPIDSlider();
3164 protected void modifyConservation_actionPerformed(ActionEvent e)
3166 if (viewport.getConservationSelected()
3167 && viewport.globalColourScheme != null)
3169 SliderPanel.setConservationSlider(alignPanel,
3170 viewport.globalColourScheme, "Background");
3171 SliderPanel.showConservationSlider();
3181 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3183 viewport.setConservationSelected(conservationMenuItem.isSelected());
3185 viewport.setAbovePIDThreshold(false);
3186 abovePIDThreshold.setSelected(false);
3188 changeColour(viewport.getGlobalColourScheme());
3190 modifyConservation_actionPerformed(null);
3199 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3201 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3203 conservationMenuItem.setSelected(false);
3204 viewport.setConservationSelected(false);
3206 changeColour(viewport.getGlobalColourScheme());
3208 modifyPID_actionPerformed(null);
3217 public void userDefinedColour_actionPerformed(ActionEvent e)
3219 if (e.getActionCommand().equals("User Defined..."))
3221 new UserDefinedColours(alignPanel, null);
3225 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3226 .getUserColourSchemes().get(e.getActionCommand());
3232 public void updateUserColourMenu()
3235 Component[] menuItems = colourMenu.getMenuComponents();
3236 int i, iSize = menuItems.length;
3237 for (i = 0; i < iSize; i++)
3239 if (menuItems[i].getName() != null
3240 && menuItems[i].getName().equals("USER_DEFINED"))
3242 colourMenu.remove(menuItems[i]);
3246 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3248 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3249 .getUserColourSchemes().keys();
3251 while (userColours.hasMoreElements())
3253 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3254 userColours.nextElement().toString());
3255 radioItem.setName("USER_DEFINED");
3256 radioItem.addMouseListener(new MouseAdapter()
3258 public void mousePressed(MouseEvent evt)
3260 if (evt.isControlDown()
3261 || SwingUtilities.isRightMouseButton(evt))
3263 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3265 int option = JOptionPane.showInternalConfirmDialog(
3266 jalview.gui.Desktop.desktop,
3267 "Remove from default list?",
3268 "Remove user defined colour",
3269 JOptionPane.YES_NO_OPTION);
3270 if (option == JOptionPane.YES_OPTION)
3272 jalview.gui.UserDefinedColours
3273 .removeColourFromDefaults(radioItem.getText());
3274 colourMenu.remove(radioItem);
3278 radioItem.addActionListener(new ActionListener()
3280 public void actionPerformed(ActionEvent evt)
3282 userDefinedColour_actionPerformed(evt);
3289 radioItem.addActionListener(new ActionListener()
3291 public void actionPerformed(ActionEvent evt)
3293 userDefinedColour_actionPerformed(evt);
3297 colourMenu.insert(radioItem, 15);
3298 colours.add(radioItem);
3309 public void PIDColour_actionPerformed(ActionEvent e)
3311 changeColour(new PIDColourScheme());
3320 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3322 changeColour(new Blosum62ColourScheme());
3331 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3333 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3334 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3335 .getAlignment().getSequenceAt(0), null);
3336 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3337 viewport.alignment));
3338 alignPanel.paintAlignment(true);
3347 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3349 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3350 AlignmentSorter.sortByID(viewport.getAlignment());
3351 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
3352 alignPanel.paintAlignment(true);
3361 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3363 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3364 AlignmentSorter.sortByLength(viewport.getAlignment());
3365 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3366 viewport.alignment));
3367 alignPanel.paintAlignment(true);
3376 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3378 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3379 AlignmentSorter.sortByGroup(viewport.getAlignment());
3380 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3381 viewport.alignment));
3383 alignPanel.paintAlignment(true);
3392 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3394 new RedundancyPanel(alignPanel, this);
3403 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3405 if ((viewport.getSelectionGroup() == null)
3406 || (viewport.getSelectionGroup().getSize() < 2))
3408 JOptionPane.showInternalMessageDialog(this,
3409 "You must select at least 2 sequences.", "Invalid Selection",
3410 JOptionPane.WARNING_MESSAGE);
3414 JInternalFrame frame = new JInternalFrame();
3415 frame.setContentPane(new PairwiseAlignPanel(viewport));
3416 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3426 public void PCAMenuItem_actionPerformed(ActionEvent e)
3428 if (((viewport.getSelectionGroup() != null)
3429 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3430 .getSelectionGroup().getSize() > 0))
3431 || (viewport.getAlignment().getHeight() < 4))
3433 JOptionPane.showInternalMessageDialog(this,
3434 "Principal component analysis must take\n"
3435 + "at least 4 input sequences.",
3436 "Sequence selection insufficient",
3437 JOptionPane.WARNING_MESSAGE);
3442 new PCAPanel(alignPanel);
3445 public void autoCalculate_actionPerformed(ActionEvent e)
3447 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3448 if (viewport.autoCalculateConsensus)
3450 viewport.firePropertyChange("alignment", null, viewport
3451 .getAlignment().getSequences());
3461 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3463 NewTreePanel("AV", "PID", "Average distance tree using PID");
3472 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3474 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3483 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3485 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3494 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3496 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3509 void NewTreePanel(String type, String pwType, String title)
3513 if (viewport.getSelectionGroup() != null)
3515 if (viewport.getSelectionGroup().getSize() < 3)
3520 "You need to have more than two sequences selected to build a tree!",
3521 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3526 SequenceGroup sg = viewport.getSelectionGroup();
3528 /* Decide if the selection is a column region */
3529 while (s < sg.getSize())
3531 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3537 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3538 + "Try using the Pad function in the edit menu,\n"
3539 + "or one of the multiple sequence alignment web services.",
3540 "Sequences in selection are not aligned",
3541 JOptionPane.WARNING_MESSAGE);
3547 title = title + " on region";
3548 tp = new TreePanel(alignPanel, type, pwType);
3552 // are the visible sequences aligned?
3553 if (!viewport.alignment.isAligned(false))
3558 "The sequences must be aligned before creating a tree.\n"
3559 + "Try using the Pad function in the edit menu,\n"
3560 + "or one of the multiple sequence alignment web services.",
3561 "Sequences not aligned",
3562 JOptionPane.WARNING_MESSAGE);
3567 if (viewport.alignment.getHeight() < 2)
3572 tp = new TreePanel(alignPanel, type, pwType);
3577 if (viewport.viewName != null)
3579 title += viewport.viewName + " of ";
3582 title += this.title;
3584 Desktop.addInternalFrame(tp, title, 600, 500);
3595 public void addSortByOrderMenuItem(String title,
3596 final AlignmentOrder order)
3598 final JMenuItem item = new JMenuItem("by " + title);
3600 item.addActionListener(new java.awt.event.ActionListener()
3602 public void actionPerformed(ActionEvent e)
3604 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3606 // TODO: JBPNote - have to map order entries to curent SequenceI
3608 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3610 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3611 viewport.alignment));
3613 alignPanel.paintAlignment(true);
3619 * Add a new sort by annotation score menu item
3622 * the menu to add the option to
3624 * the label used to retrieve scores for each sequence on the
3627 public void addSortByAnnotScoreMenuItem(JMenu sort,
3628 final String scoreLabel)
3630 final JMenuItem item = new JMenuItem(scoreLabel);
3632 item.addActionListener(new java.awt.event.ActionListener()
3634 public void actionPerformed(ActionEvent e)
3636 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3637 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3638 viewport.getAlignment());// ,viewport.getSelectionGroup());
3639 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3640 viewport.alignment));
3641 alignPanel.paintAlignment(true);
3647 * last hash for alignment's annotation array - used to minimise cost of
3650 protected int _annotationScoreVectorHash;
3653 * search the alignment and rebuild the sort by annotation score submenu the
3654 * last alignment annotation vector hash is stored to minimize cost of
3655 * rebuilding in subsequence calls.
3658 public void buildSortByAnnotationScoresMenu()
3660 if (viewport.alignment.getAlignmentAnnotation() == null)
3665 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3667 sortByAnnotScore.removeAll();
3668 // almost certainly a quicker way to do this - but we keep it simple
3669 Hashtable scoreSorts = new Hashtable();
3670 AlignmentAnnotation aann[];
3671 Enumeration sq = viewport.alignment.getSequences().elements();
3672 while (sq.hasMoreElements())
3674 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3675 for (int i = 0; aann != null && i < aann.length; i++)
3677 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3679 scoreSorts.put(aann[i].label, aann[i].label);
3683 Enumeration labels = scoreSorts.keys();
3684 while (labels.hasMoreElements())
3686 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3687 (String) labels.nextElement());
3689 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3692 _annotationScoreVectorHash = viewport.alignment
3693 .getAlignmentAnnotation().hashCode();
3698 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3699 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3700 * call. Listeners are added to remove the menu item when the treePanel is
3701 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3705 * Displayed tree window.
3707 * SortBy menu item title.
3709 public void buildTreeMenu()
3711 sortByTreeMenu.removeAll();
3713 Vector comps = (Vector) PaintRefresher.components.get(viewport
3714 .getSequenceSetId());
3715 Vector treePanels = new Vector();
3716 int i, iSize = comps.size();
3717 for (i = 0; i < iSize; i++)
3719 if (comps.elementAt(i) instanceof TreePanel)
3721 treePanels.add(comps.elementAt(i));
3725 iSize = treePanels.size();
3729 sortByTreeMenu.setVisible(false);
3733 sortByTreeMenu.setVisible(true);
3735 for (i = 0; i < treePanels.size(); i++)
3737 TreePanel tp = (TreePanel) treePanels.elementAt(i);
3738 final JMenuItem item = new JMenuItem(tp.getTitle());
3739 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3740 item.addActionListener(new java.awt.event.ActionListener()
3742 public void actionPerformed(ActionEvent e)
3744 SequenceI[] oldOrder = viewport.getAlignment()
3745 .getSequencesArray();
3746 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3748 addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
3749 viewport.alignment));
3751 alignPanel.paintAlignment(true);
3755 sortByTreeMenu.add(item);
3759 public boolean sortBy(AlignmentOrder alorder, String undoname)
3761 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3762 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3763 if (undoname != null)
3765 addHistoryItem(new OrderCommand(undoname, oldOrder,
3766 viewport.alignment));
3768 alignPanel.paintAlignment(true);
3773 * Work out whether the whole set of sequences or just the selected set will
3774 * be submitted for multiple alignment.
3777 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3779 // Now, check we have enough sequences
3780 AlignmentView msa = null;
3782 if ((viewport.getSelectionGroup() != null)
3783 && (viewport.getSelectionGroup().getSize() > 1))
3785 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3786 // some common interface!
3788 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3789 * SequenceI[sz = seqs.getSize(false)];
3791 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3792 * seqs.getSequenceAt(i); }
3794 msa = viewport.getAlignmentView(true);
3799 * Vector seqs = viewport.getAlignment().getSequences();
3801 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3803 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3804 * seqs.elementAt(i); } }
3806 msa = viewport.getAlignmentView(false);
3812 * Decides what is submitted to a secondary structure prediction service: the
3813 * first sequence in the alignment, or in the current selection, or, if the
3814 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3815 * region or the whole alignment. (where the first sequence in the set is the
3816 * one that the prediction will be for).
3818 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3820 AlignmentView seqs = null;
3822 if ((viewport.getSelectionGroup() != null)
3823 && (viewport.getSelectionGroup().getSize() > 0))
3825 seqs = viewport.getAlignmentView(true);
3829 seqs = viewport.getAlignmentView(false);
3831 // limit sequences - JBPNote in future - could spawn multiple prediction
3833 // TODO: viewport.alignment.isAligned is a global state - the local
3834 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3835 if (!viewport.alignment.isAligned(false))
3837 seqs.setSequences(new SeqCigar[]
3838 { seqs.getSequences()[0] });
3839 // TODO: if seqs.getSequences().length>1 then should really have warned
3852 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3854 // Pick the tree file
3855 JalviewFileChooser chooser = new JalviewFileChooser(
3856 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3857 chooser.setFileView(new JalviewFileView());
3858 chooser.setDialogTitle("Select a newick-like tree file");
3859 chooser.setToolTipText("Load a tree file");
3861 int value = chooser.showOpenDialog(null);
3863 if (value == JalviewFileChooser.APPROVE_OPTION)
3865 String choice = chooser.getSelectedFile().getPath();
3866 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3867 jalview.io.NewickFile fin = null;
3870 fin = new jalview.io.NewickFile(choice, "File");
3871 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3872 } catch (Exception ex)
3874 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3875 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3876 ex.printStackTrace();
3878 if (fin != null && fin.hasWarningMessage())
3880 JOptionPane.showMessageDialog(Desktop.desktop,
3881 fin.getWarningMessage(), "Possible problem with tree file",
3882 JOptionPane.WARNING_MESSAGE);
3887 public TreePanel ShowNewickTree(NewickFile nf, String title)
3889 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3892 public TreePanel ShowNewickTree(NewickFile nf, String title,
3893 AlignmentView input)
3895 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3898 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3899 int h, int x, int y)
3901 return ShowNewickTree(nf, title, null, w, h, x, y);
3905 * Add a treeviewer for the tree extracted from a newick file object to the
3906 * current alignment view
3913 * Associated alignment input data (or null)
3922 * @return TreePanel handle
3924 public TreePanel ShowNewickTree(NewickFile nf, String title,
3925 AlignmentView input, int w, int h, int x, int y)
3927 TreePanel tp = null;
3933 if (nf.getTree() != null)
3935 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3941 tp.setLocation(x, y);
3944 Desktop.addInternalFrame(tp, title, w, h);
3946 } catch (Exception ex)
3948 ex.printStackTrace();
3954 private boolean buildingMenu = false;
3957 * Generates menu items and listener event actions for web service clients
3960 public void BuildWebServiceMenu()
3962 while (buildingMenu)
3966 System.err.println("Waiting for building menu to finish.");
3968 } catch (Exception e)
3973 final AlignFrame me = this;
3974 buildingMenu = true;
3975 new Thread(new Runnable()
3981 System.err.println("Building ws menu again "
3982 + Thread.currentThread());
3983 // TODO: add support for context dependent disabling of services based
3985 // alignment and current selection
3986 // TODO: add additional serviceHandle parameter to specify abstract
3988 // class independently of AbstractName
3989 // TODO: add in rediscovery GUI function to restart discoverer
3990 // TODO: group services by location as well as function and/or
3992 // object broker mechanism.
3993 final Vector wsmenu = new Vector();
3994 final IProgressIndicator af = me;
3995 if (Cache.getDefault("SHOW_JWS1_SERVICES", true)
3996 && Discoverer.services != null
3997 && (Discoverer.services.size() > 0))
3999 // TODO: refactor to allow list of AbstractName/Handler bindings to
4001 // stored or retrieved from elsewhere
4002 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
4003 Vector secstrpr = (Vector) Discoverer.services
4005 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
4006 // TODO: move GUI generation code onto service implementation - so a
4007 // client instance attaches itself to the GUI with method call like
4008 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4012 // Add any Multiple Sequence Alignment Services
4013 final JMenu msawsmenu = new JMenu("Alignment");
4014 for (int i = 0, j = msaws.size(); i < j; i++)
4016 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4018 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4019 .getServiceClient(sh);
4020 impl.attachWSMenuEntry(msawsmenu, me);
4023 wsmenu.add(msawsmenu);
4025 if (secstrpr != null)
4027 // Add any secondary structure prediction services
4028 final JMenu secstrmenu = new JMenu(
4029 "Secondary Structure Prediction");
4030 for (int i = 0, j = secstrpr.size(); i < j; i++)
4032 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4034 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4035 .getServiceClient(sh);
4036 impl.attachWSMenuEntry(secstrmenu, me);
4038 wsmenu.add(secstrmenu);
4040 if (seqsrch != null)
4042 // Add any sequence search services
4043 final JMenu seqsrchmenu = new JMenu(
4044 "Sequence Database Search");
4045 for (int i = 0, j = seqsrch.size(); i < j; i++)
4047 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4049 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4050 .getServiceClient(sh);
4051 impl.attachWSMenuEntry(seqsrchmenu, me);
4053 wsmenu.add(seqsrchmenu);
4057 // TODO: move into separate menu builder class.
4058 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4060 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4061 if (jws2servs != null)
4063 if (jws2servs.hasServices())
4065 JMenu jws2men = new JMenu("Jaba Web Services");
4066 jws2servs.attachWSMenuEntry(jws2men, me);
4067 for (int i = 0, iSize = jws2men.getMenuComponentCount(); i < iSize; i++)
4069 wsmenu.add(jws2men.getMenuComponent(i));
4075 javax.swing.SwingUtilities.invokeLater(new Runnable()
4082 resetWebServiceMenu();
4083 // finally, add the whole shebang onto the webservices menu
4084 if (wsmenu.size() > 0)
4086 for (int i = 0, j = wsmenu.size(); i < j; i++)
4088 webService.add((JMenu) wsmenu.get(i));
4093 me.webService.add(me.webServiceNoServices);
4095 } catch (Exception e)
4101 } catch (Exception e)
4106 buildingMenu = false;
4113 * empty the web service menu and add any ad-hoc functions not dynamically
4117 private void resetWebServiceMenu()
4119 webService.removeAll();
4120 build_fetchdbmenu(webService);
4121 build_urlServiceMenu(webService);
4125 * construct any groupURL type service menu entries.
4129 private void build_urlServiceMenu(JMenu webService)
4131 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4133 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4136 // TODO: remove this code when 2.7 is released
4137 // DEBUG - alignmentView
4139 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4140 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4142 * @Override public void actionPerformed(ActionEvent e) {
4143 * jalview.datamodel.AlignmentView.testSelectionViews(af.viewport.alignment,
4144 * af.viewport.colSel, af.viewport.selectionGroup); }
4146 * }); webService.add(testAlView);
4148 // TODO: refactor to RestClient discoverer and merge menu entries for
4149 // rest-style services with other types of analysis/calculation service
4150 // SHmmr test client - still being implemented.
4151 jalview.ws.rest.RestClient.makeShmmrRestClient().attachWSMenuEntry(
4153 // DEBUG - alignmentView
4157 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4158 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4159 * getProperty("LAST_DIRECTORY"));
4161 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4162 * to Vamsas file"); chooser.setToolTipText("Export");
4164 * int value = chooser.showSaveDialog(this);
4166 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4167 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4168 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4169 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4172 * prototype of an automatically enabled/disabled analysis function
4175 protected void setShowProductsEnabled()
4177 SequenceI[] selection = viewport.getSequenceSelection();
4178 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4179 viewport.getAlignment().getDataset()))
4181 showProducts.setEnabled(true);
4186 showProducts.setEnabled(false);
4191 * search selection for sequence xRef products and build the show products
4196 * @return true if showProducts menu should be enabled.
4198 public boolean canShowProducts(SequenceI[] selection,
4199 boolean isRegionSelection, Alignment dataset)
4201 boolean showp = false;
4204 showProducts.removeAll();
4205 final boolean dna = viewport.getAlignment().isNucleotide();
4206 final Alignment ds = dataset;
4207 String[] ptypes = (selection == null || selection.length == 0) ? null
4208 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4210 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4211 // selection, dataset, true);
4212 final SequenceI[] sel = selection;
4213 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4216 final boolean isRegSel = isRegionSelection;
4217 final AlignFrame af = this;
4218 final String source = ptypes[t];
4219 JMenuItem xtype = new JMenuItem(ptypes[t]);
4220 xtype.addActionListener(new ActionListener()
4223 public void actionPerformed(ActionEvent e)
4225 // TODO: new thread for this call with vis-delay
4226 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4227 isRegSel, dna, source);
4231 showProducts.add(xtype);
4233 showProducts.setVisible(showp);
4234 showProducts.setEnabled(showp);
4235 } catch (Exception e)
4237 jalview.bin.Cache.log
4238 .warn("canTranslate threw an exception - please report to help@jalview.org",
4245 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4246 boolean isRegSel, boolean dna, String source)
4248 final boolean fisRegSel = isRegSel;
4249 final boolean fdna = dna;
4250 final String fsrc = source;
4251 final AlignFrame ths = this;
4252 final SequenceI[] fsel = sel;
4253 Runnable foo = new Runnable()
4258 final long sttime = System.currentTimeMillis();
4259 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4262 Alignment ds = ths.getViewport().alignment.getDataset(); // update
4266 Alignment prods = CrossRef
4267 .findXrefSequences(fsel, fdna, fsrc, ds);
4270 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4271 for (int s = 0; s < sprods.length; s++)
4273 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4274 if (ds.getSequences() == null
4275 || !ds.getSequences().contains(
4276 sprods[s].getDatasetSequence()))
4277 ds.addSequence(sprods[s].getDatasetSequence());
4278 sprods[s].updatePDBIds();
4280 Alignment al = new Alignment(sprods);
4281 AlignedCodonFrame[] cf = prods.getCodonFrames();
4283 for (int s = 0; cf != null && s < cf.length; s++)
4285 al.addCodonFrame(cf[s]);
4288 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4290 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4291 + " for " + ((fisRegSel) ? "selected region of " : "")
4293 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4298 System.err.println("No Sequences generated for xRef type "
4301 } catch (Exception e)
4303 jalview.bin.Cache.log.error(
4304 "Exception when finding crossreferences", e);
4305 } catch (OutOfMemoryError e)
4307 new OOMWarning("whilst fetching crossreferences", e);
4310 jalview.bin.Cache.log.error("Error when finding crossreferences",
4313 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4318 Thread frunner = new Thread(foo);
4322 public boolean canShowTranslationProducts(SequenceI[] selection,
4323 AlignmentI alignment)
4328 return (jalview.analysis.Dna.canTranslate(selection,
4329 viewport.getViewAsVisibleContigs(true)));
4330 } catch (Exception e)
4332 jalview.bin.Cache.log
4333 .warn("canTranslate threw an exception - please report to help@jalview.org",
4339 public void showProducts_actionPerformed(ActionEvent e)
4341 // /////////////////////////////
4342 // Collect Data to be translated/transferred
4344 SequenceI[] selection = viewport.getSequenceSelection();
4345 AlignmentI al = null;
4348 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4349 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4350 viewport.getAlignment().getDataset());
4351 } catch (Exception ex)
4354 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4361 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4362 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4366 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4367 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4368 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4372 public void showTranslation_actionPerformed(ActionEvent e)
4374 // /////////////////////////////
4375 // Collect Data to be translated/transferred
4377 SequenceI[] selection = viewport.getSequenceSelection();
4378 String[] seqstring = viewport.getViewAsString(true);
4379 AlignmentI al = null;
4382 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4383 viewport.getViewAsVisibleContigs(true), viewport
4384 .getGapCharacter(), viewport.alignment
4385 .getAlignmentAnnotation(), viewport.alignment
4386 .getWidth(), viewport.getAlignment().getDataset());
4387 } catch (Exception ex)
4390 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4397 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4398 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4402 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4403 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4404 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4409 * Try to load a features file onto the alignment.
4412 * contents or path to retrieve file
4414 * access mode of file (see jalview.io.AlignFile)
4415 * @return true if features file was parsed corectly.
4417 public boolean parseFeaturesFile(String file, String type)
4419 boolean featuresFile = false;
4422 featuresFile = new FeaturesFile(file, type)
4423 .parse(viewport.alignment.getDataset(),
4424 alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
4425 false, jalview.bin.Cache.getDefault(
4426 "RELAXEDSEQIDMATCHING", false));
4427 } catch (Exception ex)
4429 ex.printStackTrace();
4434 viewport.showSequenceFeatures = true;
4435 showSeqFeatures.setSelected(true);
4436 if (alignPanel.seqPanel.seqCanvas.fr != null)
4438 // update the min/max ranges where necessary
4439 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4441 if (featureSettings != null)
4443 featureSettings.setTableData();
4445 alignPanel.paintAlignment(true);
4448 return featuresFile;
4451 public void dragEnter(DropTargetDragEvent evt)
4455 public void dragExit(DropTargetEvent evt)
4459 public void dragOver(DropTargetDragEvent evt)
4463 public void dropActionChanged(DropTargetDragEvent evt)
4467 public void drop(DropTargetDropEvent evt)
4469 Transferable t = evt.getTransferable();
4470 java.util.List files = null;
4474 DataFlavor uriListFlavor = new DataFlavor(
4475 "text/uri-list;class=java.lang.String");
4476 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4478 // Works on Windows and MacOSX
4479 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4480 files = (java.util.List) t
4481 .getTransferData(DataFlavor.javaFileListFlavor);
4483 else if (t.isDataFlavorSupported(uriListFlavor))
4485 // This is used by Unix drag system
4486 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4487 String data = (String) t.getTransferData(uriListFlavor);
4488 files = new java.util.ArrayList(1);
4489 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4490 data, "\r\n"); st.hasMoreTokens();)
4492 String s = st.nextToken();
4493 if (s.startsWith("#"))
4495 // the line is a comment (as per the RFC 2483)
4499 java.net.URI uri = new java.net.URI(s);
4500 // check to see if we can handle this kind of URI
4501 if (uri.getScheme().toLowerCase().startsWith("http"))
4503 files.add(uri.toString());
4507 // otherwise preserve old behaviour: catch all for file objects
4508 java.io.File file = new java.io.File(uri);
4509 files.add(file.toString());
4513 } catch (Exception e)
4515 e.printStackTrace();
4521 // check to see if any of these files have names matching sequences in
4523 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4524 .getAlignment().getSequencesArray());
4526 * Object[] { String,SequenceI}
4528 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4529 ArrayList<String> filesnotmatched = new ArrayList<String>();
4530 for (int i = 0; i < files.size(); i++)
4532 String file = files.get(i).toString();
4534 String protocol = FormatAdapter.checkProtocol(file);
4535 if (protocol == jalview.io.FormatAdapter.FILE)
4537 File fl = new File(file);
4538 pdbfn = fl.getName();
4540 else if (protocol == jalview.io.FormatAdapter.URL)
4542 URL url = new URL(file);
4543 pdbfn = url.getFile();
4545 if (pdbfn.length() > 0)
4547 // attempt to find a match in the alignment
4548 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4549 int l = 0, c = pdbfn.indexOf(".");
4550 while (mtch == null && c != -1)
4555 } while ((c = pdbfn.indexOf(".", l)) > l);
4558 pdbfn = pdbfn.substring(0, l);
4560 mtch = idm.findAllIdMatches(pdbfn);
4567 type = new IdentifyFile().Identify(file, protocol);
4568 } catch (Exception ex)
4574 if (type.equalsIgnoreCase("PDB"))
4576 filesmatched.add(new Object[]
4577 { file, protocol, mtch });
4582 // File wasn't named like one of the sequences or wasn't a PDB file.
4583 filesnotmatched.add(file);
4587 if (filesmatched.size() > 0)
4589 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4593 "Do you want to automatically associate the "
4594 + filesmatched.size()
4595 + " PDB files with sequences in the alignment that have the same name ?",
4596 "Automatically Associate PDB files by name",
4597 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4600 for (Object[] fm : filesmatched)
4602 // try and associate
4603 // TODO: may want to set a standard ID naming formalism for
4604 // associating PDB files which have no IDs.
4605 for (SequenceI toassoc: (SequenceI[])fm[2]) {
4606 PDBEntry pe = new AssociatePdbFileWithSeq()
4607 .associatePdbWithSeq((String) fm[0], (String) fm[1],
4612 .println("Associated file : " + ((String) fm[0])
4614 + toassoc.getDisplayId(true));
4618 alignPanel.paintAlignment(true);
4622 if (filesnotmatched.size() > 0)
4625 && (Cache.getDefault(
4626 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4629 "<html>Do you want to <em>ignore</em> the "
4630 + filesnotmatched.size()
4631 + " files whose names did not match any sequence IDs ?</html>",
4632 "Ignore unmatched dropped files ?",
4633 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4637 for (String fn : filesnotmatched)
4639 loadJalviewDataFile(fn, null, null, null);
4643 } catch (Exception ex)
4645 ex.printStackTrace();
4651 * Attempt to load a "dropped" file or URL string: First by testing whether
4652 * it's and Annotation file, then a JNet file, and finally a features file. If
4653 * all are false then the user may have dropped an alignment file onto this
4657 * either a filename or a URL string.
4659 public void loadJalviewDataFile(String file, String protocol,
4660 String format, SequenceI assocSeq)
4664 if (protocol == null)
4666 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4668 // if the file isn't identified, or not positively identified as some
4669 // other filetype (PFAM is default unidentified alignment file type) then
4670 // try to parse as annotation.
4671 boolean isAnnotation = (format == null || format
4672 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4673 .readAnnotationFile(viewport.alignment, file, protocol)
4678 // try to see if its a JNet 'concise' style annotation file *before* we
4679 // try to parse it as a features file
4682 format = new IdentifyFile().Identify(file, protocol);
4684 if (format.equalsIgnoreCase("JnetFile"))
4686 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4688 new JnetAnnotationMaker().add_annotation(predictions,
4689 viewport.getAlignment(), 0, false);
4690 isAnnotation = true;
4695 * if (format.equalsIgnoreCase("PDB")) {
4697 * String pdbfn = ""; // try to match up filename with sequence id try
4698 * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new
4699 * File(file); pdbfn = fl.getName(); } else if (protocol ==
4700 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4701 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null)
4702 * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4703 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { //
4704 * attempt to find a match in the alignment SequenceI mtch =
4705 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4706 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l)
4707 * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch =
4708 * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate
4709 * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4710 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) {
4711 * System.err.println("Associated file : " + file + " with " +
4712 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4713 * TODO: maybe need to load as normal otherwise return; } }
4715 // try to parse it as a features file
4716 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4717 // if it wasn't a features file then we just treat it as a general
4718 // alignment file to load into the current view.
4721 new FileLoader().LoadFile(viewport, file, protocol, format);
4725 alignPanel.paintAlignment(true);
4732 alignPanel.adjustAnnotationHeight();
4733 viewport.updateSequenceIdColours();
4734 buildSortByAnnotationScoresMenu();
4735 alignPanel.paintAlignment(true);
4736 System.out.println("Hallo");
4738 } catch (Exception ex)
4740 ex.printStackTrace();
4744 public void tabSelectionChanged(int index)
4748 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4749 viewport = alignPanel.av;
4750 setMenusFromViewport(viewport);
4754 public void tabbedPane_mousePressed(MouseEvent e)
4756 if (SwingUtilities.isRightMouseButton(e))
4758 String reply = JOptionPane.showInternalInputDialog(this,
4759 "Enter View Name", "Edit View Name",
4760 JOptionPane.QUESTION_MESSAGE);
4764 viewport.viewName = reply;
4765 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4770 public AlignViewport getCurrentView()
4776 * Open the dialog for regex description parsing.
4778 protected void extractScores_actionPerformed(ActionEvent e)
4780 ParseProperties pp = new jalview.analysis.ParseProperties(
4781 viewport.alignment);
4782 // TODO: verify regex and introduce GUI dialog for version 2.5
4783 // if (pp.getScoresFromDescription("col", "score column ",
4784 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4786 if (pp.getScoresFromDescription("description column",
4787 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4789 buildSortByAnnotationScoresMenu();
4797 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4800 protected void showDbRefs_actionPerformed(ActionEvent e)
4802 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4808 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4811 protected void showNpFeats_actionPerformed(ActionEvent e)
4813 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4817 * find the viewport amongst the tabs in this alignment frame and close that
4822 public boolean closeView(AlignViewport av)
4826 this.closeMenuItem_actionPerformed(false);
4829 Component[] comp = tabbedPane.getComponents();
4830 for (int i = 0; comp != null && i < comp.length; i++)
4832 if (comp[i] instanceof AlignmentPanel)
4834 if (((AlignmentPanel) comp[i]).av == av)
4837 closeView((AlignmentPanel) comp[i]);
4845 protected void build_fetchdbmenu(JMenu webService)
4847 // Temporary hack - DBRef Fetcher always top level ws entry.
4848 // TODO We probably want to store a sequence database checklist in
4849 // preferences and have checkboxes.. rather than individual sources selected
4851 final JMenu rfetch = new JMenu("Fetch DB References");
4852 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4853 webService.add(rfetch);
4855 JMenuItem fetchr = new JMenuItem("Standard Databases");
4856 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4857 fetchr.addActionListener(new ActionListener()
4860 public void actionPerformed(ActionEvent e)
4862 new Thread(new Runnable()
4867 new jalview.ws.DBRefFetcher(alignPanel.av
4868 .getSequenceSelection(), alignPanel.alignFrame)
4869 .fetchDBRefs(false);
4877 final AlignFrame me = this;
4878 new Thread(new Runnable()
4882 final jalview.ws.SequenceFetcher sf = SequenceFetcher
4883 .getSequenceFetcherSingleton(me);
4884 final String[] otherdb = sf.getOrderedSupportedSources();
4885 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4886 // jalview.util.QuickSort.sort(otherdb, otherdb);
4887 javax.swing.SwingUtilities.invokeLater(new Runnable()
4892 JMenu dfetch = new JMenu();
4895 int comp = 0, mcomp = 15;
4896 String mname = null;
4897 if (otherdb != null && otherdb.length > 0)
4899 for (int i = 0; i < otherdb.length; i++)
4901 String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
4904 mname = "from '" + dbname + "'";
4906 fetchr = new JMenuItem(otherdb[i]);
4907 final String[] dassource = new String[]
4909 fetchr.addActionListener(new ActionListener()
4912 public void actionPerformed(ActionEvent e)
4914 new Thread(new Runnable()
4919 new jalview.ws.DBRefFetcher(alignPanel.av
4920 .getSequenceSelection(),
4921 alignPanel.alignFrame, dassource)
4922 .fetchDBRefs(false);
4928 fetchr.setToolTipText("Retrieve from " + dbname);
4930 if (comp++ == mcomp || i == (otherdb.length - 1))
4932 dfetch.setText(mname + " to '" + dbname + "'");
4934 dfetch = new JMenu();
4948 * Left justify the whole alignment.
4950 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4952 AlignmentI al = viewport.getAlignment();
4954 viewport.firePropertyChange("alignment", null, al);
4958 * Right justify the whole alignment.
4960 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4962 AlignmentI al = viewport.getAlignment();
4964 viewport.firePropertyChange("alignment", null, al);
4967 public void setShowSeqFeatures(boolean b)
4969 showSeqFeatures.setSelected(true);
4970 viewport.setShowSequenceFeatures(true);
4977 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
4978 * awt.event.ActionEvent)
4980 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
4982 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
4983 alignPanel.paintAlignment(true);
4990 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
4993 protected void showGroupConsensus_actionPerformed(ActionEvent e)
4995 viewport.setShowGroupConsensus(showGroupConsensus.getState());
4996 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5004 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5005 * .event.ActionEvent)
5007 protected void showGroupConservation_actionPerformed(ActionEvent e)
5009 viewport.setShowGroupConservation(showGroupConservation.getState());
5010 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5017 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5018 * .event.ActionEvent)
5020 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5022 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5023 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5030 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5031 * .event.ActionEvent)
5033 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5035 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5036 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5039 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5041 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5048 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5049 * .event.ActionEvent)
5051 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5053 if (viewport.getSelectionGroup() != null)
5055 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5056 viewport.getSequenceSelection(),
5057 viewport.getAlignmentView(true).getSequenceStrings(
5058 viewport.getGapCharacter()),
5059 viewport.alignment.getGroups());
5060 viewport.alignment.deleteAllGroups();
5061 viewport.sequenceColours = null;
5062 viewport.setSelectionGroup(null);
5063 // set view properties for each group
5064 for (int g = 0; g < gps.length; g++)
5066 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5067 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5068 viewport.alignment.addGroup(gps[g]);
5069 Color col = new Color((int) (Math.random() * 255),
5070 (int) (Math.random() * 255), (int) (Math.random() * 255));
5071 col = col.brighter();
5072 for (Enumeration sq = gps[g].getSequences(null).elements(); sq
5073 .hasMoreElements(); viewport.setSequenceColour(
5074 (SequenceI) sq.nextElement(), col))
5077 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5078 alignPanel.updateAnnotation();
5079 alignPanel.paintAlignment(true);
5084 * make the given alignmentPanel the currently selected tab
5086 * @param alignmentPanel
5088 public void setDisplayedView(AlignmentPanel alignmentPanel)
5090 if (!viewport.getSequenceSetId().equals(
5091 alignmentPanel.av.getSequenceSetId()))
5094 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5096 if (tabbedPane != null
5097 & alignPanels.indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5099 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5104 class PrintThread extends Thread
5108 public PrintThread(AlignmentPanel ap)
5113 static PageFormat pf;
5117 PrinterJob printJob = PrinterJob.getPrinterJob();
5121 printJob.setPrintable(ap, pf);
5125 printJob.setPrintable(ap);
5128 if (printJob.printDialog())
5133 } catch (Exception PrintException)
5135 PrintException.printStackTrace();