2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.RNAHelicesColourChooser;
70 import jalview.schemes.ResidueProperties;
71 import jalview.schemes.StrandColourScheme;
72 import jalview.schemes.TaylorColourScheme;
73 import jalview.schemes.TurnColourScheme;
74 import jalview.schemes.UserColourScheme;
75 import jalview.schemes.ZappoColourScheme;
76 import jalview.ws.WSMenuEntryProviderI;
77 import jalview.ws.jws1.Discoverer;
78 import jalview.ws.jws2.Jws2Discoverer;
80 import java.awt.BorderLayout;
81 import java.awt.Color;
82 import java.awt.Component;
83 import java.awt.GridLayout;
84 import java.awt.Rectangle;
85 import java.awt.Toolkit;
86 import java.awt.datatransfer.Clipboard;
87 import java.awt.datatransfer.DataFlavor;
88 import java.awt.datatransfer.StringSelection;
89 import java.awt.datatransfer.Transferable;
90 import java.awt.dnd.DnDConstants;
91 import java.awt.dnd.DropTargetDragEvent;
92 import java.awt.dnd.DropTargetDropEvent;
93 import java.awt.dnd.DropTargetEvent;
94 import java.awt.dnd.DropTargetListener;
95 import java.awt.event.ActionEvent;
96 import java.awt.event.ActionListener;
97 import java.awt.event.KeyAdapter;
98 import java.awt.event.KeyEvent;
99 import java.awt.event.MouseAdapter;
100 import java.awt.event.MouseEvent;
101 import java.awt.print.PageFormat;
102 import java.awt.print.PrinterJob;
103 import java.beans.PropertyChangeEvent;
106 import java.util.ArrayList;
107 import java.util.Enumeration;
108 import java.util.Hashtable;
109 import java.util.Vector;
111 import javax.swing.JButton;
112 import javax.swing.JEditorPane;
113 import javax.swing.JInternalFrame;
114 import javax.swing.JLabel;
115 import javax.swing.JLayeredPane;
116 import javax.swing.JMenu;
117 import javax.swing.JMenuItem;
118 import javax.swing.JOptionPane;
119 import javax.swing.JPanel;
120 import javax.swing.JProgressBar;
121 import javax.swing.JRadioButtonMenuItem;
122 import javax.swing.JScrollPane;
123 import javax.swing.SwingUtilities;
129 * @version $Revision$
131 public class AlignFrame extends GAlignFrame implements DropTargetListener,
136 public static final int DEFAULT_WIDTH = 700;
139 public static final int DEFAULT_HEIGHT = 500;
141 public AlignmentPanel alignPanel;
143 AlignViewport viewport;
145 Vector alignPanels = new Vector();
148 * Last format used to load or save alignments in this window
150 String currentFileFormat = null;
153 * Current filename for this alignment
155 String fileName = null;
158 * Creates a new AlignFrame object with specific width and height.
164 public AlignFrame(AlignmentI al, int width, int height)
166 this(al, null, width, height);
170 * Creates a new AlignFrame object with specific width, height and
176 * @param sequenceSetId
178 public AlignFrame(AlignmentI al, int width, int height,
179 String sequenceSetId)
181 this(al, null, width, height, sequenceSetId);
185 * Creates a new AlignFrame object with specific width, height and
191 * @param sequenceSetId
194 public AlignFrame(AlignmentI al, int width, int height,
195 String sequenceSetId, String viewId)
197 this(al, null, width, height, sequenceSetId, viewId);
201 * new alignment window with hidden columns
205 * @param hiddenColumns
206 * ColumnSelection or null
208 * Width of alignment frame
212 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
213 int width, int height)
215 this(al, hiddenColumns, width, height, null);
219 * Create alignment frame for al with hiddenColumns, a specific width and
220 * height, and specific sequenceId
223 * @param hiddenColumns
226 * @param sequenceSetId
229 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
230 int width, int height, String sequenceSetId)
232 this(al, hiddenColumns, width, height, sequenceSetId, null);
236 * Create alignment frame for al with hiddenColumns, a specific width and
237 * height, and specific sequenceId
240 * @param hiddenColumns
243 * @param sequenceSetId
248 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
249 int width, int height, String sequenceSetId, String viewId)
251 setSize(width, height);
252 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
254 alignPanel = new AlignmentPanel(this, viewport);
256 if (al.getDataset() == null)
261 addAlignmentPanel(alignPanel, true);
266 * Make a new AlignFrame from exisiting alignmentPanels
273 public AlignFrame(AlignmentPanel ap)
277 addAlignmentPanel(ap, false);
282 * initalise the alignframe from the underlying viewport data and the
287 if (viewport.getAlignmentConservationAnnotation()== null)
289 BLOSUM62Colour.setEnabled(false);
290 conservationMenuItem.setEnabled(false);
291 modifyConservation.setEnabled(false);
292 // PIDColour.setEnabled(false);
293 // abovePIDThreshold.setEnabled(false);
294 // modifyPID.setEnabled(false);
297 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
300 if (sortby.equals("Id"))
302 sortIDMenuItem_actionPerformed(null);
304 else if (sortby.equals("Pairwise Identity"))
306 sortPairwiseMenuItem_actionPerformed(null);
309 if (Desktop.desktop != null)
311 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
312 addServiceListeners();
313 setGUINucleotide(viewport.getAlignment().isNucleotide());
316 setMenusFromViewport(viewport);
317 buildSortByAnnotationScoresMenu();
318 if (viewport.wrapAlignment)
320 wrapMenuItem_actionPerformed(null);
323 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
325 this.overviewMenuItem_actionPerformed(null);
333 * Change the filename and format for the alignment, and enable the 'reload'
334 * button functionality.
341 public void setFileName(String file, String format)
344 currentFileFormat = format;
345 reload.setEnabled(true);
348 void addKeyListener()
350 addKeyListener(new KeyAdapter()
352 public void keyPressed(KeyEvent evt)
354 if (viewport.cursorMode
355 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
356 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
357 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
358 && Character.isDigit(evt.getKeyChar()))
359 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
361 switch (evt.getKeyCode())
364 case 27: // escape key
365 deselectAllSequenceMenuItem_actionPerformed(null);
369 case KeyEvent.VK_DOWN:
370 if (evt.isAltDown() || !viewport.cursorMode)
371 moveSelectedSequences(false);
372 if (viewport.cursorMode)
373 alignPanel.seqPanel.moveCursor(0, 1);
377 if (evt.isAltDown() || !viewport.cursorMode)
378 moveSelectedSequences(true);
379 if (viewport.cursorMode)
380 alignPanel.seqPanel.moveCursor(0, -1);
384 case KeyEvent.VK_LEFT:
385 if (evt.isAltDown() || !viewport.cursorMode)
386 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
388 alignPanel.seqPanel.moveCursor(-1, 0);
392 case KeyEvent.VK_RIGHT:
393 if (evt.isAltDown() || !viewport.cursorMode)
394 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
396 alignPanel.seqPanel.moveCursor(1, 0);
399 case KeyEvent.VK_SPACE:
400 if (viewport.cursorMode)
402 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
403 || evt.isShiftDown() || evt.isAltDown());
407 //case KeyEvent.VK_A:
408 // if (viewport.cursorMode)
410 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
411 // //System.out.println("A");
415 case KeyEvent.VK_CLOSE_BRACKET:
416 if (viewport.cursorMode)
418 System.out.println("closing bracket");
422 case KeyEvent.VK_DELETE:
423 case KeyEvent.VK_BACK_SPACE:
424 if (!viewport.cursorMode)
426 cut_actionPerformed(null);
430 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
431 || evt.isShiftDown() || evt.isAltDown());
437 if (viewport.cursorMode)
439 alignPanel.seqPanel.setCursorRow();
443 if (viewport.cursorMode && !evt.isControlDown())
445 alignPanel.seqPanel.setCursorColumn();
449 if (viewport.cursorMode)
451 alignPanel.seqPanel.setCursorPosition();
455 case KeyEvent.VK_ENTER:
456 case KeyEvent.VK_COMMA:
457 if (viewport.cursorMode)
459 alignPanel.seqPanel.setCursorRowAndColumn();
464 if (viewport.cursorMode)
466 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
470 if (viewport.cursorMode)
472 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
477 viewport.cursorMode = !viewport.cursorMode;
478 statusBar.setText("Keyboard editing mode is "
479 + (viewport.cursorMode ? "on" : "off"));
480 if (viewport.cursorMode)
482 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
483 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
485 alignPanel.seqPanel.seqCanvas.repaint();
491 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
492 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
494 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
496 javax.help.HelpBroker hb = hs.createHelpBroker();
497 hb.setCurrentID("home");
498 hb.setDisplayed(true);
499 } catch (Exception ex)
501 ex.printStackTrace();
506 boolean toggleSeqs = !evt.isControlDown();
507 boolean toggleCols = !evt.isShiftDown();
508 toggleHiddenRegions(toggleSeqs, toggleCols);
511 case KeyEvent.VK_PAGE_UP:
512 if (viewport.wrapAlignment)
514 alignPanel.scrollUp(true);
518 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
519 - viewport.endSeq + viewport.startSeq);
522 case KeyEvent.VK_PAGE_DOWN:
523 if (viewport.wrapAlignment)
525 alignPanel.scrollUp(false);
529 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
530 + viewport.endSeq - viewport.startSeq);
536 public void keyReleased(KeyEvent evt)
538 switch (evt.getKeyCode())
540 case KeyEvent.VK_LEFT:
541 if (evt.isAltDown() || !viewport.cursorMode)
542 viewport.firePropertyChange("alignment", null, viewport
543 .getAlignment().getSequences());
546 case KeyEvent.VK_RIGHT:
547 if (evt.isAltDown() || !viewport.cursorMode)
548 viewport.firePropertyChange("alignment", null, viewport
549 .getAlignment().getSequences());
556 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
558 ap.alignFrame = this;
560 alignPanels.addElement(ap);
562 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
564 int aSize = alignPanels.size();
566 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
568 if (aSize == 1 && ap.av.viewName == null)
570 this.getContentPane().add(ap, BorderLayout.CENTER);
576 setInitialTabVisible();
579 expandViews.setEnabled(true);
580 gatherViews.setEnabled(true);
581 tabbedPane.addTab(ap.av.viewName, ap);
583 ap.setVisible(false);
588 if (ap.av.isPadGaps())
590 ap.av.getAlignment().padGaps();
592 ap.av.updateConservation(ap);
593 ap.av.updateConsensus(ap);
594 ap.av.updateStrucConsensus(ap);
598 public void setInitialTabVisible()
600 expandViews.setEnabled(true);
601 gatherViews.setEnabled(true);
602 tabbedPane.setVisible(true);
603 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
604 tabbedPane.addTab(first.av.viewName, first);
605 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
608 public AlignViewport getViewport()
613 /* Set up intrinsic listeners for dynamically generated GUI bits. */
614 private void addServiceListeners()
616 final java.beans.PropertyChangeListener thisListener;
617 Desktop.instance.addJalviewPropertyChangeListener("services",
618 thisListener = new java.beans.PropertyChangeListener()
620 public void propertyChange(PropertyChangeEvent evt)
622 // // System.out.println("Discoverer property change.");
623 // if (evt.getPropertyName().equals("services"))
625 SwingUtilities.invokeLater(new Runnable()
631 .println("Rebuild WS Menu for service change");
632 BuildWebServiceMenu();
639 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
641 public void internalFrameClosed(
642 javax.swing.event.InternalFrameEvent evt)
644 System.out.println("deregistering discoverer listener");
645 Desktop.instance.removeJalviewPropertyChangeListener("services",
647 closeMenuItem_actionPerformed(true);
650 // Finally, build the menu once to get current service state
651 new Thread(new Runnable()
655 BuildWebServiceMenu();
660 public void setGUINucleotide(boolean nucleotide)
662 showTranslation.setVisible(nucleotide);
663 conservationMenuItem.setEnabled(!nucleotide);
664 modifyConservation.setEnabled(!nucleotide);
665 showGroupConservation.setEnabled(!nucleotide);
666 rnahelicesColour.setEnabled(nucleotide);
667 purinePyrimidineColour.setEnabled(nucleotide);
668 // Remember AlignFrame always starts as protein
672 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
677 * set up menus for the currently viewport. This may be called after any
678 * operation that affects the data in the current view (selection changed,
679 * etc) to update the menus to reflect the new state.
681 public void setMenusForViewport()
683 setMenusFromViewport(viewport);
687 * Need to call this method when tabs are selected for multiple views, or when
688 * loading from Jalview2XML.java
693 void setMenusFromViewport(AlignViewport av)
695 padGapsMenuitem.setSelected(av.isPadGaps());
696 colourTextMenuItem.setSelected(av.showColourText);
697 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
698 conservationMenuItem.setSelected(av.getConservationSelected());
699 seqLimits.setSelected(av.getShowJVSuffix());
700 idRightAlign.setSelected(av.rightAlignIds);
701 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
702 renderGapsMenuItem.setSelected(av.renderGaps);
703 wrapMenuItem.setSelected(av.wrapAlignment);
704 scaleAbove.setVisible(av.wrapAlignment);
705 scaleLeft.setVisible(av.wrapAlignment);
706 scaleRight.setVisible(av.wrapAlignment);
707 annotationPanelMenuItem.setState(av.showAnnotation);
708 viewBoxesMenuItem.setSelected(av.showBoxes);
709 viewTextMenuItem.setSelected(av.showText);
710 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
711 showGroupConsensus.setSelected(av.isShowGroupConsensus());
712 showGroupConservation.setSelected(av.isShowGroupConservation());
713 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
714 showSequenceLogo.setSelected(av.isShowSequenceLogo());
715 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
717 setColourSelected(ColourSchemeProperty.getColourName(av
718 .getGlobalColourScheme()));
720 showSeqFeatures.setSelected(av.showSequenceFeatures);
721 hiddenMarkers.setState(av.showHiddenMarkers);
722 applyToAllGroups.setState(av.colourAppliesToAllGroups);
723 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
724 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
725 autoCalculate.setSelected(av.autoCalculateConsensus);
726 sortByTree.setSelected(av.sortByTree);
727 listenToViewSelections.setSelected(av.followSelection);
728 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
729 rnahelicesColour.setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
730 setShowProductsEnabled();
735 Hashtable progressBars, progressBarHandlers;
740 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
742 public void setProgressBar(String message, long id)
744 if (progressBars == null)
746 progressBars = new Hashtable();
747 progressBarHandlers = new Hashtable();
750 JPanel progressPanel;
751 Long lId = new Long(id);
752 GridLayout layout = (GridLayout) statusPanel.getLayout();
753 if (progressBars.get(lId) != null)
755 progressPanel = (JPanel) progressBars.get(new Long(id));
756 statusPanel.remove(progressPanel);
757 progressBars.remove(lId);
758 progressPanel = null;
761 statusBar.setText(message);
763 if (progressBarHandlers.contains(lId))
765 progressBarHandlers.remove(lId);
767 layout.setRows(layout.getRows() - 1);
771 progressPanel = new JPanel(new BorderLayout(10, 5));
773 JProgressBar progressBar = new JProgressBar();
774 progressBar.setIndeterminate(true);
776 progressPanel.add(new JLabel(message), BorderLayout.WEST);
777 progressPanel.add(progressBar, BorderLayout.CENTER);
779 layout.setRows(layout.getRows() + 1);
780 statusPanel.add(progressPanel);
782 progressBars.put(lId, progressPanel);
785 // setMenusForViewport();
789 public void registerHandler(final long id,
790 final IProgressIndicatorHandler handler)
792 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
795 "call setProgressBar before registering the progress bar's handler.");
797 progressBarHandlers.put(new Long(id), handler);
798 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
799 if (handler.canCancel())
801 JButton cancel = new JButton("Cancel");
802 final IProgressIndicator us = this;
803 cancel.addActionListener(new ActionListener()
806 public void actionPerformed(ActionEvent e)
808 handler.cancelActivity(id);
811 + ((JLabel) progressPanel.getComponent(0))
815 progressPanel.add(cancel, BorderLayout.EAST);
821 * @return true if any progress bars are still active
823 public boolean operationInProgress()
825 if (progressBars != null && progressBars.size() > 0)
833 * Added so Castor Mapping file can obtain Jalview Version
835 public String getVersion()
837 return jalview.bin.Cache.getProperty("VERSION");
840 public FeatureRenderer getFeatureRenderer()
842 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
845 public void fetchSequence_actionPerformed(ActionEvent e)
847 new SequenceFetcher(this);
850 public void addFromFile_actionPerformed(ActionEvent e)
852 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
855 public void reload_actionPerformed(ActionEvent e)
857 if (fileName != null)
859 // TODO: work out how to recover feature settings for correct view(s) when
861 if (currentFileFormat.equals("Jalview"))
863 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
864 for (int i = 0; i < frames.length; i++)
866 if (frames[i] instanceof AlignFrame && frames[i] != this
867 && ((AlignFrame) frames[i]).fileName.equals(fileName))
871 frames[i].setSelected(true);
872 Desktop.instance.closeAssociatedWindows();
873 } catch (java.beans.PropertyVetoException ex)
879 Desktop.instance.closeAssociatedWindows();
881 FileLoader loader = new FileLoader();
882 String protocol = fileName.startsWith("http:") ? "URL" : "File";
883 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
887 Rectangle bounds = this.getBounds();
889 FileLoader loader = new FileLoader();
890 String protocol = fileName.startsWith("http:") ? "URL" : "File";
891 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
892 protocol, currentFileFormat);
894 newframe.setBounds(bounds);
895 if (featureSettings != null && featureSettings.isShowing())
897 final Rectangle fspos = featureSettings.frame.getBounds();
898 // TODO: need a 'show feature settings' function that takes bounds -
899 // need to refactor Desktop.addFrame
900 newframe.featureSettings_actionPerformed(null);
901 final FeatureSettings nfs = newframe.featureSettings;
902 SwingUtilities.invokeLater(new Runnable()
906 nfs.frame.setBounds(fspos);
909 this.featureSettings.close();
910 this.featureSettings = null;
912 this.closeMenuItem_actionPerformed(true);
917 public void addFromText_actionPerformed(ActionEvent e)
919 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
922 public void addFromURL_actionPerformed(ActionEvent e)
924 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
927 public void save_actionPerformed(ActionEvent e)
930 || (currentFileFormat == null || !jalview.io.FormatAdapter
931 .isValidIOFormat(currentFileFormat, true))
932 || fileName.startsWith("http"))
934 saveAs_actionPerformed(null);
938 saveAlignment(fileName, currentFileFormat);
948 public void saveAs_actionPerformed(ActionEvent e)
950 JalviewFileChooser chooser = new JalviewFileChooser(
951 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
952 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
953 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
954 currentFileFormat, false);
956 chooser.setFileView(new JalviewFileView());
957 chooser.setDialogTitle("Save Alignment to file");
958 chooser.setToolTipText("Save");
960 int value = chooser.showSaveDialog(this);
962 if (value == JalviewFileChooser.APPROVE_OPTION)
964 currentFileFormat = chooser.getSelectedFormat();
965 if (currentFileFormat == null)
967 JOptionPane.showInternalMessageDialog(Desktop.desktop,
968 "You must select a file format before saving!",
969 "File format not specified", JOptionPane.WARNING_MESSAGE);
970 value = chooser.showSaveDialog(this);
974 fileName = chooser.getSelectedFile().getPath();
976 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
979 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
980 if (currentFileFormat.indexOf(" ") > -1)
982 currentFileFormat = currentFileFormat.substring(0,
983 currentFileFormat.indexOf(" "));
985 saveAlignment(fileName, currentFileFormat);
989 public boolean saveAlignment(String file, String format)
991 boolean success = true;
993 if (format.equalsIgnoreCase("Jalview"))
995 String shortName = title;
997 if (shortName.indexOf(java.io.File.separatorChar) > -1)
999 shortName = shortName.substring(shortName
1000 .lastIndexOf(java.io.File.separatorChar) + 1);
1003 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1005 statusBar.setText("Successfully saved to file: " + fileName + " in "
1006 + format + " format.");
1011 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1013 warningMessage("Cannot save file " + fileName + " using format "
1014 + format, "Alignment output format not supported");
1015 saveAs_actionPerformed(null);
1016 // JBPNote need to have a raise_gui flag here
1020 String[] omitHidden = null;
1022 if (viewport.hasHiddenColumns())
1024 int reply = JOptionPane
1025 .showInternalConfirmDialog(
1027 "The Alignment contains hidden columns."
1028 + "\nDo you want to save only the visible alignment?",
1029 "Save / Omit Hidden Columns",
1030 JOptionPane.YES_NO_OPTION,
1031 JOptionPane.QUESTION_MESSAGE);
1033 if (reply == JOptionPane.YES_OPTION)
1035 omitHidden = viewport.getViewAsString(false);
1038 FormatAdapter f = new FormatAdapter();
1039 String output = f.formatSequences(format,
1040 (Alignment) viewport.getAlignment(), // class cast exceptions will
1041 // occur in the distant future
1042 omitHidden, f.getCacheSuffixDefault(format), viewport.getColumnSelection());
1052 java.io.PrintWriter out = new java.io.PrintWriter(
1053 new java.io.FileWriter(file));
1057 this.setTitle(file);
1058 statusBar.setText("Successfully saved to file: " + fileName
1059 + " in " + format + " format.");
1060 } catch (Exception ex)
1063 ex.printStackTrace();
1070 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1071 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1077 private void warningMessage(String warning, String title)
1079 if (new jalview.util.Platform().isHeadless())
1081 System.err.println("Warning: " + title + "\nWarning: " + warning);
1086 JOptionPane.showInternalMessageDialog(this, warning, title,
1087 JOptionPane.WARNING_MESSAGE);
1098 protected void outputText_actionPerformed(ActionEvent e)
1100 String[] omitHidden = null;
1102 if (viewport.hasHiddenColumns())
1104 int reply = JOptionPane
1105 .showInternalConfirmDialog(
1107 "The Alignment contains hidden columns."
1108 + "\nDo you want to output only the visible alignment?",
1109 "Save / Omit Hidden Columns",
1110 JOptionPane.YES_NO_OPTION,
1111 JOptionPane.QUESTION_MESSAGE);
1113 if (reply == JOptionPane.YES_OPTION)
1115 omitHidden = viewport.getViewAsString(false);
1119 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1120 cap.setForInput(null);
1124 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1125 viewport.getAlignment(), omitHidden, viewport.getColumnSelection()));
1126 Desktop.addInternalFrame(cap,
1127 "Alignment output - " + e.getActionCommand(), 600, 500);
1128 } catch (OutOfMemoryError oom)
1130 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1142 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1144 new HTMLOutput(alignPanel,
1145 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1146 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1149 public void createImageMap(File file, String image)
1151 alignPanel.makePNGImageMap(file, image);
1160 public void createPNG(File f)
1162 alignPanel.makePNG(f);
1171 public void createEPS(File f)
1173 alignPanel.makeEPS(f);
1176 public void pageSetup_actionPerformed(ActionEvent e)
1178 PrinterJob printJob = PrinterJob.getPrinterJob();
1179 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1188 public void printMenuItem_actionPerformed(ActionEvent e)
1190 // Putting in a thread avoids Swing painting problems
1191 PrintThread thread = new PrintThread(alignPanel);
1195 public void exportFeatures_actionPerformed(ActionEvent e)
1197 new AnnotationExporter().exportFeatures(alignPanel);
1200 public void exportAnnotations_actionPerformed(ActionEvent e)
1202 new AnnotationExporter().exportAnnotations(
1204 viewport.showAnnotation ? viewport.getAlignment()
1205 .getAlignmentAnnotation() : null, viewport.getAlignment()
1207 ((Alignment) viewport.getAlignment()).alignmentProperties);
1210 public void associatedData_actionPerformed(ActionEvent e)
1212 // Pick the tree file
1213 JalviewFileChooser chooser = new JalviewFileChooser(
1214 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1215 chooser.setFileView(new JalviewFileView());
1216 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1217 chooser.setToolTipText("Load Jalview Annotations / Features file");
1219 int value = chooser.showOpenDialog(null);
1221 if (value == JalviewFileChooser.APPROVE_OPTION)
1223 String choice = chooser.getSelectedFile().getPath();
1224 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1225 loadJalviewDataFile(choice, null, null, null);
1231 * Close the current view or all views in the alignment frame. If the frame
1232 * only contains one view then the alignment will be removed from memory.
1234 * @param closeAllTabs
1236 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1238 if (alignPanels != null && alignPanels.size() < 2)
1240 closeAllTabs = true;
1245 if (alignPanels != null)
1249 if (this.isClosed())
1251 // really close all the windows - otherwise wait till
1252 // setClosed(true) is called
1253 for (int i = 0; i < alignPanels.size(); i++)
1255 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1262 closeView(alignPanel);
1268 this.setClosed(true);
1270 } catch (Exception ex)
1272 ex.printStackTrace();
1277 * close alignPanel2 and shuffle tabs appropriately.
1279 * @param alignPanel2
1281 public void closeView(AlignmentPanel alignPanel2)
1283 int index = tabbedPane.getSelectedIndex();
1284 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1285 alignPanels.removeElement(alignPanel2);
1287 // if (viewport == alignPanel2.av)
1291 alignPanel2.closePanel();
1294 tabbedPane.removeTabAt(closedindex);
1295 tabbedPane.validate();
1297 if (index > closedindex || index == tabbedPane.getTabCount())
1299 // modify currently selected tab index if necessary.
1303 this.tabSelectionChanged(index);
1309 void updateEditMenuBar()
1312 if (viewport.historyList.size() > 0)
1314 undoMenuItem.setEnabled(true);
1315 CommandI command = (CommandI) viewport.historyList.peek();
1316 undoMenuItem.setText("Undo " + command.getDescription());
1320 undoMenuItem.setEnabled(false);
1321 undoMenuItem.setText("Undo");
1324 if (viewport.redoList.size() > 0)
1326 redoMenuItem.setEnabled(true);
1328 CommandI command = (CommandI) viewport.redoList.peek();
1329 redoMenuItem.setText("Redo " + command.getDescription());
1333 redoMenuItem.setEnabled(false);
1334 redoMenuItem.setText("Redo");
1338 public void addHistoryItem(CommandI command)
1340 if (command.getSize() > 0)
1342 viewport.historyList.push(command);
1343 viewport.redoList.clear();
1344 updateEditMenuBar();
1345 viewport.updateHiddenColumns();
1346 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1347 // && viewport.getColumnSelection().getHiddenColumns() != null && viewport.getColumnSelection()
1348 // .getHiddenColumns().size() > 0);
1354 * @return alignment objects for all views
1356 AlignmentI[] getViewAlignments()
1358 if (alignPanels != null)
1360 Enumeration e = alignPanels.elements();
1361 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1362 for (int i = 0; e.hasMoreElements(); i++)
1364 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1368 if (viewport != null)
1370 return new AlignmentI[]
1371 { viewport.getAlignment() };
1382 protected void undoMenuItem_actionPerformed(ActionEvent e)
1384 if (viewport.historyList.empty())
1386 CommandI command = (CommandI) viewport.historyList.pop();
1387 viewport.redoList.push(command);
1388 command.undoCommand(getViewAlignments());
1390 AlignViewport originalSource = getOriginatingSource(command);
1391 updateEditMenuBar();
1393 if (originalSource != null)
1395 if (originalSource!=viewport)
1397 Cache.log.warn("Implementation worry: mismatch of viewport origin for undo");
1399 originalSource.updateHiddenColumns();
1400 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() != null
1401 // && viewport.getColumnSelection().getHiddenColumns() != null && viewport.getColumnSelection()
1402 // .getHiddenColumns().size() > 0);
1403 originalSource.firePropertyChange("alignment", null,
1404 originalSource.getAlignment().getSequences());
1414 protected void redoMenuItem_actionPerformed(ActionEvent e)
1416 if (viewport.redoList.size() < 1)
1421 CommandI command = (CommandI) viewport.redoList.pop();
1422 viewport.historyList.push(command);
1423 command.doCommand(getViewAlignments());
1425 AlignViewport originalSource = getOriginatingSource(command);
1426 updateEditMenuBar();
1428 if (originalSource != null)
1431 if (originalSource!=viewport)
1433 Cache.log.warn("Implementation worry: mismatch of viewport origin for redo");
1435 originalSource.updateHiddenColumns();
1436 //originalSource.hasHiddenColumns = (viewport.getColumnSelection() != null
1437 // && viewport.getColumnSelection().getHiddenColumns() != null && viewport.getColumnSelection()
1438 // .getHiddenColumns().size() > 0);
1439 originalSource.firePropertyChange("alignment", null,
1440 originalSource.getAlignment().getSequences());
1444 AlignViewport getOriginatingSource(CommandI command)
1446 AlignViewport originalSource = null;
1447 // For sequence removal and addition, we need to fire
1448 // the property change event FROM the viewport where the
1449 // original alignment was altered
1450 AlignmentI al = null;
1451 if (command instanceof EditCommand)
1453 EditCommand editCommand = (EditCommand) command;
1454 al = editCommand.getAlignment();
1455 Vector comps = (Vector) PaintRefresher.components.get(viewport
1456 .getSequenceSetId());
1458 for (int i = 0; i < comps.size(); i++)
1460 if (comps.elementAt(i) instanceof AlignmentPanel)
1462 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1464 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1471 if (originalSource == null)
1473 // The original view is closed, we must validate
1474 // the current view against the closed view first
1477 PaintRefresher.validateSequences(al, viewport.getAlignment());
1480 originalSource = viewport;
1483 return originalSource;
1492 public void moveSelectedSequences(boolean up)
1494 SequenceGroup sg = viewport.getSelectionGroup();
1503 for (int i = 1; i < viewport.getAlignment().getHeight(); i++)
1505 SequenceI seq = viewport.getAlignment().getSequenceAt(i);
1507 if (!sg.getSequences(null).contains(seq))
1512 SequenceI temp = viewport.getAlignment().getSequenceAt(i - 1);
1514 if (sg.getSequences(null).contains(temp))
1519 viewport.getAlignment().getSequences().setElementAt(temp, i);
1520 viewport.getAlignment().getSequences().setElementAt(seq, i - 1);
1525 for (int i = viewport.getAlignment().getHeight() - 2; i > -1; i--)
1527 SequenceI seq = viewport.getAlignment().getSequenceAt(i);
1529 if (!sg.getSequences(null).contains(seq))
1534 SequenceI temp = viewport.getAlignment().getSequenceAt(i + 1);
1536 if (sg.getSequences(null).contains(temp))
1541 viewport.getAlignment().getSequences().setElementAt(temp, i);
1542 viewport.getAlignment().getSequences().setElementAt(seq, i + 1);
1546 alignPanel.paintAlignment(true);
1549 synchronized void slideSequences(boolean right, int size)
1551 Vector sg = new Vector();
1552 if (viewport.cursorMode)
1554 sg.addElement(viewport.getAlignment()
1555 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1557 else if (viewport.getSelectionGroup() != null
1558 && viewport.getSelectionGroup().getSize() != viewport.getAlignment()
1561 sg = viewport.getSelectionGroup().getSequences(
1562 viewport.getHiddenRepSequences());
1570 Vector invertGroup = new Vector();
1572 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1574 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1575 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1578 SequenceI[] seqs1 = new SequenceI[sg.size()];
1579 for (int i = 0; i < sg.size(); i++)
1580 seqs1[i] = (SequenceI) sg.elementAt(i);
1582 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1583 for (int i = 0; i < invertGroup.size(); i++)
1584 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1586 SlideSequencesCommand ssc;
1588 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1589 size, viewport.getGapCharacter());
1591 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1592 size, viewport.getGapCharacter());
1594 int groupAdjustment = 0;
1595 if (ssc.getGapsInsertedBegin() && right)
1597 if (viewport.cursorMode)
1598 alignPanel.seqPanel.moveCursor(size, 0);
1600 groupAdjustment = size;
1602 else if (!ssc.getGapsInsertedBegin() && !right)
1604 if (viewport.cursorMode)
1605 alignPanel.seqPanel.moveCursor(-size, 0);
1607 groupAdjustment = -size;
1610 if (groupAdjustment != 0)
1612 viewport.getSelectionGroup().setStartRes(
1613 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1614 viewport.getSelectionGroup().setEndRes(
1615 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1618 boolean appendHistoryItem = false;
1619 if (viewport.historyList != null && viewport.historyList.size() > 0
1620 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1622 appendHistoryItem = ssc
1623 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1627 if (!appendHistoryItem)
1628 addHistoryItem(ssc);
1639 protected void copy_actionPerformed(ActionEvent e)
1642 if (viewport.getSelectionGroup() == null)
1646 // TODO: preserve the ordering of displayed alignment annotation in any
1647 // internal paste (particularly sequence associated annotation)
1648 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1649 String[] omitHidden = null;
1651 if (viewport.hasHiddenColumns())
1653 omitHidden = viewport.getViewAsString(true);
1656 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1659 StringSelection ss = new StringSelection(output);
1663 jalview.gui.Desktop.internalCopy = true;
1664 // Its really worth setting the clipboard contents
1665 // to empty before setting the large StringSelection!!
1666 Toolkit.getDefaultToolkit().getSystemClipboard()
1667 .setContents(new StringSelection(""), null);
1669 Toolkit.getDefaultToolkit().getSystemClipboard()
1670 .setContents(ss, Desktop.instance);
1671 } catch (OutOfMemoryError er)
1673 new OOMWarning("copying region", er);
1677 Vector hiddenColumns = null;
1678 if (viewport.hasHiddenColumns())
1680 hiddenColumns = new Vector();
1681 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1682 .getSelectionGroup().getEndRes();
1683 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1686 int[] region = (int[]) viewport.getColumnSelection()
1687 .getHiddenColumns().elementAt(i);
1688 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1690 hiddenColumns.addElement(new int[]
1691 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1696 Desktop.jalviewClipboard = new Object[]
1697 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1698 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1707 protected void pasteNew_actionPerformed(ActionEvent e)
1718 protected void pasteThis_actionPerformed(ActionEvent e)
1724 * Paste contents of Jalview clipboard
1726 * @param newAlignment
1727 * true to paste to a new alignment, otherwise add to this.
1729 void paste(boolean newAlignment)
1731 boolean externalPaste = true;
1734 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1735 Transferable contents = c.getContents(this);
1737 if (contents == null)
1745 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1746 if (str.length() < 1)
1751 format = new IdentifyFile().Identify(str, "Paste");
1753 } catch (OutOfMemoryError er)
1755 new OOMWarning("Out of memory pasting sequences!!", er);
1759 SequenceI[] sequences;
1760 boolean annotationAdded = false;
1761 AlignmentI alignment = null;
1763 if (Desktop.jalviewClipboard != null)
1765 // The clipboard was filled from within Jalview, we must use the
1767 // And dataset from the copied alignment
1768 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1769 // be doubly sure that we create *new* sequence objects.
1770 sequences = new SequenceI[newseq.length];
1771 for (int i = 0; i < newseq.length; i++)
1773 sequences[i] = new Sequence(newseq[i]);
1775 alignment = new Alignment(sequences);
1776 externalPaste = false;
1780 // parse the clipboard as an alignment.
1781 alignment = new FormatAdapter().readFile(str, "Paste", format);
1782 sequences = alignment.getSequencesArray();
1790 if (Desktop.jalviewClipboard != null)
1792 // dataset is inherited
1793 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1797 // new dataset is constructed
1798 alignment.setDataset(null);
1800 alwidth = alignment.getWidth() + 1;
1804 AlignmentI pastedal = alignment; // preserve pasted alignment object
1805 // Add pasted sequences and dataset into existing alignment.
1806 alignment = viewport.getAlignment();
1807 alwidth = alignment.getWidth() + 1;
1808 // decide if we need to import sequences from an existing dataset
1809 boolean importDs = Desktop.jalviewClipboard != null
1810 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1811 // importDs==true instructs us to copy over new dataset sequences from
1812 // an existing alignment
1813 Vector newDs = (importDs) ? new Vector() : null; // used to create
1814 // minimum dataset set
1816 for (int i = 0; i < sequences.length; i++)
1820 newDs.addElement(null);
1822 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1824 if (importDs && ds != null)
1826 if (!newDs.contains(ds))
1828 newDs.setElementAt(ds, i);
1829 ds = new Sequence(ds);
1830 // update with new dataset sequence
1831 sequences[i].setDatasetSequence(ds);
1835 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1840 // copy and derive new dataset sequence
1841 sequences[i] = sequences[i].deriveSequence();
1842 alignment.getDataset().addSequence(
1843 sequences[i].getDatasetSequence());
1844 // TODO: avoid creation of duplicate dataset sequences with a
1845 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1847 alignment.addSequence(sequences[i]); // merges dataset
1851 newDs.clear(); // tidy up
1853 if (pastedal.getAlignmentAnnotation() != null)
1855 // Add any annotation attached to alignment.
1856 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1857 for (int i = 0; i < alann.length; i++)
1859 annotationAdded = true;
1860 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1862 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1863 newann.padAnnotation(alwidth);
1864 alignment.addAnnotation(newann);
1874 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1875 sequences, 0, alignment.getWidth(), alignment));
1877 // Add any annotations attached to sequences
1878 for (int i = 0; i < sequences.length; i++)
1880 if (sequences[i].getAnnotation() != null)
1882 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1884 annotationAdded = true;
1885 sequences[i].getAnnotation()[a].adjustForAlignment();
1886 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1887 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1892 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1899 // propagate alignment changed.
1900 viewport.setEndSeq(alignment.getHeight());
1901 if (annotationAdded)
1903 // Duplicate sequence annotation in all views.
1904 AlignmentI[] alview = this.getViewAlignments();
1905 for (int i = 0; i < sequences.length; i++)
1907 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1910 for (int avnum = 0; avnum < alview.length; avnum++)
1912 if (alview[avnum] != alignment)
1914 // duplicate in a view other than the one with input focus
1915 int avwidth = alview[avnum].getWidth() + 1;
1916 // this relies on sann being preserved after we
1917 // modify the sequence's annotation array for each duplication
1918 for (int a = 0; a < sann.length; a++)
1920 AlignmentAnnotation newann = new AlignmentAnnotation(
1922 sequences[i].addAlignmentAnnotation(newann);
1923 newann.padAnnotation(avwidth);
1924 alview[avnum].addAnnotation(newann); // annotation was
1925 // duplicated earlier
1926 alview[avnum].setAnnotationIndex(newann, a);
1931 buildSortByAnnotationScoresMenu();
1933 viewport.firePropertyChange("alignment", null,
1934 alignment.getSequences());
1939 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1941 String newtitle = new String("Copied sequences");
1943 if (Desktop.jalviewClipboard != null
1944 && Desktop.jalviewClipboard[2] != null)
1946 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1947 for (int i = 0; i < hc.size(); i++)
1949 int[] region = (int[]) hc.elementAt(i);
1950 af.viewport.hideColumns(region[0], region[1]);
1954 // >>>This is a fix for the moment, until a better solution is
1956 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1958 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1960 // TODO: maintain provenance of an alignment, rather than just make the
1961 // title a concatenation of operations.
1964 if (title.startsWith("Copied sequences"))
1970 newtitle = newtitle.concat("- from " + title);
1975 newtitle = new String("Pasted sequences");
1978 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1983 } catch (Exception ex)
1985 ex.printStackTrace();
1986 System.out.println("Exception whilst pasting: " + ex);
1987 // could be anything being pasted in here
1998 protected void cut_actionPerformed(ActionEvent e)
2000 copy_actionPerformed(null);
2001 delete_actionPerformed(null);
2010 protected void delete_actionPerformed(ActionEvent evt)
2013 SequenceGroup sg = viewport.getSelectionGroup();
2019 Vector seqs = new Vector();
2021 for (int i = 0; i < sg.getSize(); i++)
2023 seq = sg.getSequenceAt(i);
2024 seqs.addElement(seq);
2027 // If the cut affects all sequences, remove highlighted columns
2028 if (sg.getSize() == viewport.getAlignment().getHeight())
2030 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2031 sg.getEndRes() + 1);
2034 SequenceI[] cut = new SequenceI[seqs.size()];
2035 for (int i = 0; i < seqs.size(); i++)
2037 cut[i] = (SequenceI) seqs.elementAt(i);
2041 * //ADD HISTORY ITEM
2043 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2044 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2045 viewport.getAlignment()));
2047 viewport.setSelectionGroup(null);
2048 viewport.sendSelection();
2049 viewport.getAlignment().deleteGroup(sg);
2051 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2053 if (viewport.getAlignment().getHeight() < 1)
2057 this.setClosed(true);
2058 } catch (Exception ex)
2070 protected void deleteGroups_actionPerformed(ActionEvent e)
2072 viewport.getAlignment().deleteAllGroups();
2073 viewport.sequenceColours = null;
2074 viewport.setSelectionGroup(null);
2075 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2076 alignPanel.updateAnnotation();
2077 alignPanel.paintAlignment(true);
2086 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2088 SequenceGroup sg = new SequenceGroup();
2090 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2092 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2095 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2096 viewport.setSelectionGroup(sg);
2097 viewport.sendSelection();
2098 alignPanel.paintAlignment(true);
2099 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2108 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2110 if (viewport.cursorMode)
2112 alignPanel.seqPanel.keyboardNo1 = null;
2113 alignPanel.seqPanel.keyboardNo2 = null;
2115 viewport.setSelectionGroup(null);
2116 viewport.getColumnSelection().clear();
2117 viewport.setSelectionGroup(null);
2118 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2119 alignPanel.idPanel.idCanvas.searchResults = null;
2120 alignPanel.paintAlignment(true);
2121 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2122 viewport.sendSelection();
2131 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2133 SequenceGroup sg = viewport.getSelectionGroup();
2137 selectAllSequenceMenuItem_actionPerformed(null);
2142 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2144 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2147 alignPanel.paintAlignment(true);
2148 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2149 viewport.sendSelection();
2152 public void invertColSel_actionPerformed(ActionEvent e)
2154 viewport.invertColumnSelection();
2155 alignPanel.paintAlignment(true);
2156 viewport.sendSelection();
2165 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2167 trimAlignment(true);
2176 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2178 trimAlignment(false);
2181 void trimAlignment(boolean trimLeft)
2183 ColumnSelection colSel = viewport.getColumnSelection();
2186 if (colSel.size() > 0)
2190 column = colSel.getMin();
2194 column = colSel.getMax();
2198 if (viewport.getSelectionGroup() != null)
2200 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2201 viewport.getHiddenRepSequences());
2205 seqs = viewport.getAlignment().getSequencesArray();
2208 TrimRegionCommand trimRegion;
2211 trimRegion = new TrimRegionCommand("Remove Left",
2212 TrimRegionCommand.TRIM_LEFT, seqs, column,
2213 viewport.getAlignment(), viewport.getColumnSelection(),
2214 viewport.getSelectionGroup());
2215 viewport.setStartRes(0);
2219 trimRegion = new TrimRegionCommand("Remove Right",
2220 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2221 viewport.getAlignment(), viewport.getColumnSelection(),
2222 viewport.getSelectionGroup());
2225 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2227 addHistoryItem(trimRegion);
2229 Vector groups = viewport.getAlignment().getGroups();
2231 for (int i = 0; i < groups.size(); i++)
2233 SequenceGroup sg = (SequenceGroup) groups.get(i);
2235 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2236 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2238 viewport.getAlignment().deleteGroup(sg);
2242 viewport.firePropertyChange("alignment", null, viewport
2243 .getAlignment().getSequences());
2253 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2255 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2258 if (viewport.getSelectionGroup() != null)
2260 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2261 viewport.getHiddenRepSequences());
2262 start = viewport.getSelectionGroup().getStartRes();
2263 end = viewport.getSelectionGroup().getEndRes();
2267 seqs = viewport.getAlignment().getSequencesArray();
2270 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2271 "Remove Gapped Columns", seqs, start, end, viewport.getAlignment());
2273 addHistoryItem(removeGapCols);
2275 statusBar.setText("Removed " + removeGapCols.getSize()
2276 + " empty columns.");
2278 // This is to maintain viewport position on first residue
2279 // of first sequence
2280 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2281 int startRes = seq.findPosition(viewport.startRes);
2282 // ShiftList shifts;
2283 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2284 // edit.alColumnChanges=shifts.getInverse();
2285 // if (viewport.hasHiddenColumns)
2286 // viewport.getColumnSelection().compensateForEdits(shifts);
2287 viewport.setStartRes(seq.findIndex(startRes) - 1);
2288 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2299 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2301 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2304 if (viewport.getSelectionGroup() != null)
2306 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2307 viewport.getHiddenRepSequences());
2308 start = viewport.getSelectionGroup().getStartRes();
2309 end = viewport.getSelectionGroup().getEndRes();
2313 seqs = viewport.getAlignment().getSequencesArray();
2316 // This is to maintain viewport position on first residue
2317 // of first sequence
2318 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2319 int startRes = seq.findPosition(viewport.startRes);
2321 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2322 viewport.getAlignment()));
2324 viewport.setStartRes(seq.findIndex(startRes) - 1);
2326 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2337 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2339 viewport.setPadGaps(padGapsMenuitem.isSelected());
2340 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2346 // if (justifySeqs>0)
2348 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2360 public void findMenuItem_actionPerformed(ActionEvent e)
2365 public void newView_actionPerformed(ActionEvent e)
2372 * @param copyAnnotation
2373 * if true then duplicate all annnotation, groups and settings
2374 * @return new alignment panel, already displayed.
2376 public AlignmentPanel newView(boolean copyAnnotation)
2378 return newView(null, copyAnnotation);
2384 * title of newly created view
2385 * @return new alignment panel, already displayed.
2387 public AlignmentPanel newView(String viewTitle)
2389 return newView(viewTitle, true);
2395 * title of newly created view
2396 * @param copyAnnotation
2397 * if true then duplicate all annnotation, groups and settings
2398 * @return new alignment panel, already displayed.
2400 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2402 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2404 if (!copyAnnotation)
2406 // just remove all the current annotation except for the automatic stuff
2407 newap.av.getAlignment().deleteAllGroups();
2408 for (AlignmentAnnotation alan : newap.av.getAlignment()
2409 .getAlignmentAnnotation())
2411 if (!alan.autoCalculated)
2413 newap.av.getAlignment().deleteAnnotation(alan);
2419 newap.av.gatherViewsHere = false;
2421 if (viewport.viewName == null)
2423 viewport.viewName = "Original";
2426 newap.av.historyList = viewport.historyList;
2427 newap.av.redoList = viewport.redoList;
2429 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2430 // make sure the new view has a unique name - this is essential for Jalview
2432 boolean addFirstIndex = false;
2433 if (viewTitle == null || viewTitle.trim().length() == 0)
2436 addFirstIndex = true;
2440 index = 1;// we count from 1 if given a specific name
2442 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2443 Vector comps = (Vector) PaintRefresher.components.get(viewport
2444 .getSequenceSetId());
2445 Vector existingNames = new Vector();
2446 for (int i = 0; i < comps.size(); i++)
2448 if (comps.elementAt(i) instanceof AlignmentPanel)
2450 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2451 if (!existingNames.contains(ap.av.viewName))
2453 existingNames.addElement(ap.av.viewName);
2458 while (existingNames.contains(newViewName))
2460 newViewName = viewTitle + " " + (++index);
2463 newap.av.viewName = newViewName;
2465 addAlignmentPanel(newap, true);
2467 if (alignPanels.size() == 2)
2469 viewport.gatherViewsHere = true;
2471 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2475 public void expandViews_actionPerformed(ActionEvent e)
2477 Desktop.instance.explodeViews(this);
2480 public void gatherViews_actionPerformed(ActionEvent e)
2482 Desktop.instance.gatherViews(this);
2491 public void font_actionPerformed(ActionEvent e)
2493 new FontChooser(alignPanel);
2502 protected void seqLimit_actionPerformed(ActionEvent e)
2504 viewport.setShowJVSuffix(seqLimits.isSelected());
2506 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2507 .calculateIdWidth());
2508 alignPanel.paintAlignment(true);
2511 public void idRightAlign_actionPerformed(ActionEvent e)
2513 viewport.rightAlignIds = idRightAlign.isSelected();
2514 alignPanel.paintAlignment(true);
2517 public void centreColumnLabels_actionPerformed(ActionEvent e)
2519 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2520 alignPanel.paintAlignment(true);
2526 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2528 protected void followHighlight_actionPerformed()
2530 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2532 alignPanel.scrollToPosition(
2533 alignPanel.seqPanel.seqCanvas.searchResults, false);
2543 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2545 viewport.setColourText(colourTextMenuItem.isSelected());
2546 alignPanel.paintAlignment(true);
2555 public void wrapMenuItem_actionPerformed(ActionEvent e)
2557 scaleAbove.setVisible(wrapMenuItem.isSelected());
2558 scaleLeft.setVisible(wrapMenuItem.isSelected());
2559 scaleRight.setVisible(wrapMenuItem.isSelected());
2560 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2561 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2564 public void showAllSeqs_actionPerformed(ActionEvent e)
2566 viewport.showAllHiddenSeqs();
2569 public void showAllColumns_actionPerformed(ActionEvent e)
2571 viewport.showAllHiddenColumns();
2575 public void hideSelSequences_actionPerformed(ActionEvent e)
2577 viewport.hideAllSelectedSeqs();
2578 alignPanel.paintAlignment(true);
2582 * called by key handler and the hide all/show all menu items
2587 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2590 boolean hide = false;
2591 SequenceGroup sg = viewport.getSelectionGroup();
2592 if (!toggleSeqs && !toggleCols)
2594 // Hide everything by the current selection - this is a hack - we do the
2595 // invert and then hide
2596 // first check that there will be visible columns after the invert.
2597 if ((viewport.getColumnSelection() != null && viewport.getColumnSelection().getSelected() != null && viewport.getColumnSelection()
2598 .getSelected().size() > 0)
2599 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2602 // now invert the sequence set, if required - empty selection implies
2603 // that no hiding is required.
2606 invertSequenceMenuItem_actionPerformed(null);
2607 sg = viewport.getSelectionGroup();
2611 viewport.expandColSelection(sg, true);
2612 // finally invert the column selection and get the new sequence
2614 invertColSel_actionPerformed(null);
2621 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2623 hideSelSequences_actionPerformed(null);
2626 else if (!(toggleCols && viewport.getColumnSelection().getSelected().size() > 0))
2628 showAllSeqs_actionPerformed(null);
2634 if (viewport.getColumnSelection().getSelected().size() > 0)
2636 hideSelColumns_actionPerformed(null);
2639 viewport.setSelectionGroup(sg);
2644 showAllColumns_actionPerformed(null);
2653 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2654 * event.ActionEvent)
2656 public void hideAllButSelection_actionPerformed(ActionEvent e)
2658 toggleHiddenRegions(false, false);
2665 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2668 public void hideAllSelection_actionPerformed(ActionEvent e)
2670 SequenceGroup sg = viewport.getSelectionGroup();
2671 viewport.expandColSelection(sg, false);
2672 viewport.hideAllSelectedSeqs();
2673 viewport.hideSelectedColumns();
2674 alignPanel.paintAlignment(true);
2681 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2684 public void showAllhidden_actionPerformed(ActionEvent e)
2686 viewport.showAllHiddenColumns();
2687 viewport.showAllHiddenSeqs();
2688 alignPanel.paintAlignment(true);
2691 public void hideSelColumns_actionPerformed(ActionEvent e)
2693 viewport.hideSelectedColumns();
2694 alignPanel.paintAlignment(true);
2697 public void hiddenMarkers_actionPerformed(ActionEvent e)
2699 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2709 protected void scaleAbove_actionPerformed(ActionEvent e)
2711 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2712 alignPanel.paintAlignment(true);
2721 protected void scaleLeft_actionPerformed(ActionEvent e)
2723 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2724 alignPanel.paintAlignment(true);
2733 protected void scaleRight_actionPerformed(ActionEvent e)
2735 viewport.setScaleRightWrapped(scaleRight.isSelected());
2736 alignPanel.paintAlignment(true);
2745 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2747 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2748 alignPanel.paintAlignment(true);
2757 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2759 viewport.setShowText(viewTextMenuItem.isSelected());
2760 alignPanel.paintAlignment(true);
2769 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2771 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2772 alignPanel.paintAlignment(true);
2775 public FeatureSettings featureSettings;
2777 public void featureSettings_actionPerformed(ActionEvent e)
2779 if (featureSettings != null)
2781 featureSettings.close();
2782 featureSettings = null;
2784 if (!showSeqFeatures.isSelected())
2786 // make sure features are actually displayed
2787 showSeqFeatures.setSelected(true);
2788 showSeqFeatures_actionPerformed(null);
2790 featureSettings = new FeatureSettings(this);
2794 * Set or clear 'Show Sequence Features'
2799 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2801 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2802 alignPanel.paintAlignment(true);
2803 if (alignPanel.getOverviewPanel() != null)
2805 alignPanel.getOverviewPanel().updateOverviewImage();
2810 * Set or clear 'Show Sequence Features'
2815 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2817 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2819 if (viewport.getShowSequenceFeaturesHeight())
2821 // ensure we're actually displaying features
2822 viewport.setShowSequenceFeatures(true);
2823 showSeqFeatures.setSelected(true);
2825 alignPanel.paintAlignment(true);
2826 if (alignPanel.getOverviewPanel() != null)
2828 alignPanel.getOverviewPanel().updateOverviewImage();
2838 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2840 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2841 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2844 public void alignmentProperties()
2846 JEditorPane editPane = new JEditorPane("text/html", "");
2847 editPane.setEditable(false);
2848 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2850 editPane.setText("<html>" + contents.toString() + "</html>");
2851 JInternalFrame frame = new JInternalFrame();
2852 frame.getContentPane().add(new JScrollPane(editPane));
2854 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2855 + getTitle(), 500, 400);
2864 public void overviewMenuItem_actionPerformed(ActionEvent e)
2866 if (alignPanel.overviewPanel != null)
2871 JInternalFrame frame = new JInternalFrame();
2872 OverviewPanel overview = new OverviewPanel(alignPanel);
2873 frame.setContentPane(overview);
2874 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2875 frame.getWidth(), frame.getHeight());
2877 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2878 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2880 public void internalFrameClosed(
2881 javax.swing.event.InternalFrameEvent evt)
2883 alignPanel.setOverviewPanel(null);
2887 alignPanel.setOverviewPanel(overview);
2890 public void textColour_actionPerformed(ActionEvent e)
2892 new TextColourChooser().chooseColour(alignPanel, null);
2901 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2912 public void clustalColour_actionPerformed(ActionEvent e)
2914 changeColour(new ClustalxColourScheme(
2915 viewport.getAlignment().getSequences(),
2916 viewport.getAlignment().getWidth()));
2925 public void zappoColour_actionPerformed(ActionEvent e)
2927 changeColour(new ZappoColourScheme());
2936 public void taylorColour_actionPerformed(ActionEvent e)
2938 changeColour(new TaylorColourScheme());
2947 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2949 changeColour(new HydrophobicColourScheme());
2958 public void helixColour_actionPerformed(ActionEvent e)
2960 changeColour(new HelixColourScheme());
2969 public void strandColour_actionPerformed(ActionEvent e)
2971 changeColour(new StrandColourScheme());
2980 public void turnColour_actionPerformed(ActionEvent e)
2982 changeColour(new TurnColourScheme());
2991 public void buriedColour_actionPerformed(ActionEvent e)
2993 changeColour(new BuriedColourScheme());
3002 public void nucleotideColour_actionPerformed(ActionEvent e)
3004 changeColour(new NucleotideColourScheme());
3007 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3009 changeColour(new PurinePyrimidineColourScheme());
3012 public void covariationColour_actionPerformed(ActionEvent e)
3014 changeColour(new CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation()[0]));
3017 public void annotationColour_actionPerformed(ActionEvent e)
3019 new AnnotationColourChooser(viewport, alignPanel);
3022 public void rnahelicesColour_actionPerformed(ActionEvent e)
3024 new RNAHelicesColourChooser(viewport, alignPanel);
3033 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3035 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3044 public void changeColour(ColourSchemeI cs)
3050 if (viewport.getAbovePIDThreshold())
3052 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3055 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3057 viewport.setGlobalColourScheme(cs);
3061 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3064 if (viewport.getConservationSelected())
3067 Alignment al = (Alignment) viewport.getAlignment();
3068 Conservation c = new Conservation("All",
3069 ResidueProperties.propHash, 3, al.getSequences(), 0,
3073 c.verdict(false, viewport.getConsPercGaps());
3075 cs.setConservation(c);
3077 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3082 cs.setConservation(null);
3085 cs.setConsensus(viewport.getSequenceConsensusHash());
3088 viewport.setGlobalColourScheme(cs);
3090 if (viewport.getColourAppliesToAllGroups())
3092 Vector groups = viewport.getAlignment().getGroups();
3094 for (int i = 0; i < groups.size(); i++)
3096 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
3104 if (cs instanceof ClustalxColourScheme)
3106 sg.cs = new ClustalxColourScheme(
3107 sg.getSequences(viewport.getHiddenRepSequences()),
3110 else if (cs instanceof UserColourScheme)
3112 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3118 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
3119 } catch (Exception ex)
3124 if (viewport.getAbovePIDThreshold()
3125 || cs instanceof PIDColourScheme
3126 || cs instanceof Blosum62ColourScheme)
3128 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3130 sg.cs.setConsensus(AAFrequency.calculate(
3131 sg.getSequences(viewport.getHiddenRepSequences()),
3132 sg.getStartRes(), sg.getEndRes() + 1));
3136 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3139 if (viewport.getConservationSelected())
3141 Conservation c = new Conservation("Group",
3142 ResidueProperties.propHash, 3,
3143 sg.getSequences(viewport.getHiddenRepSequences()),
3144 sg.getStartRes(), sg.getEndRes() + 1);
3146 c.verdict(false, viewport.getConsPercGaps());
3147 sg.cs.setConservation(c);
3151 sg.cs.setConservation(null);
3156 if (alignPanel.getOverviewPanel() != null)
3158 alignPanel.getOverviewPanel().updateOverviewImage();
3161 alignPanel.paintAlignment(true);
3170 protected void modifyPID_actionPerformed(ActionEvent e)
3172 if (viewport.getAbovePIDThreshold()
3173 && viewport.getGlobalColourScheme() != null)
3175 SliderPanel.setPIDSliderSource(alignPanel,
3176 viewport.getGlobalColourScheme(), "Background");
3177 SliderPanel.showPIDSlider();
3187 protected void modifyConservation_actionPerformed(ActionEvent e)
3189 if (viewport.getConservationSelected()
3190 && viewport.getGlobalColourScheme()!= null)
3192 SliderPanel.setConservationSlider(alignPanel,
3193 viewport.getGlobalColourScheme(), "Background");
3194 SliderPanel.showConservationSlider();
3204 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3206 viewport.setConservationSelected(conservationMenuItem.isSelected());
3208 viewport.setAbovePIDThreshold(false);
3209 abovePIDThreshold.setSelected(false);
3211 changeColour(viewport.getGlobalColourScheme());
3213 modifyConservation_actionPerformed(null);
3222 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3224 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3226 conservationMenuItem.setSelected(false);
3227 viewport.setConservationSelected(false);
3229 changeColour(viewport.getGlobalColourScheme());
3231 modifyPID_actionPerformed(null);
3240 public void userDefinedColour_actionPerformed(ActionEvent e)
3242 if (e.getActionCommand().equals("User Defined..."))
3244 new UserDefinedColours(alignPanel, null);
3248 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3249 .getUserColourSchemes().get(e.getActionCommand());
3255 public void updateUserColourMenu()
3258 Component[] menuItems = colourMenu.getMenuComponents();
3259 int i, iSize = menuItems.length;
3260 for (i = 0; i < iSize; i++)
3262 if (menuItems[i].getName() != null
3263 && menuItems[i].getName().equals("USER_DEFINED"))
3265 colourMenu.remove(menuItems[i]);
3269 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3271 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3272 .getUserColourSchemes().keys();
3274 while (userColours.hasMoreElements())
3276 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3277 userColours.nextElement().toString());
3278 radioItem.setName("USER_DEFINED");
3279 radioItem.addMouseListener(new MouseAdapter()
3281 public void mousePressed(MouseEvent evt)
3283 if (evt.isControlDown()
3284 || SwingUtilities.isRightMouseButton(evt))
3286 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3288 int option = JOptionPane.showInternalConfirmDialog(
3289 jalview.gui.Desktop.desktop,
3290 "Remove from default list?",
3291 "Remove user defined colour",
3292 JOptionPane.YES_NO_OPTION);
3293 if (option == JOptionPane.YES_OPTION)
3295 jalview.gui.UserDefinedColours
3296 .removeColourFromDefaults(radioItem.getText());
3297 colourMenu.remove(radioItem);
3301 radioItem.addActionListener(new ActionListener()
3303 public void actionPerformed(ActionEvent evt)
3305 userDefinedColour_actionPerformed(evt);
3312 radioItem.addActionListener(new ActionListener()
3314 public void actionPerformed(ActionEvent evt)
3316 userDefinedColour_actionPerformed(evt);
3320 colourMenu.insert(radioItem, 15);
3321 colours.add(radioItem);
3332 public void PIDColour_actionPerformed(ActionEvent e)
3334 changeColour(new PIDColourScheme());
3343 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3345 changeColour(new Blosum62ColourScheme());
3354 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3356 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3357 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3358 .getAlignment().getSequenceAt(0), null);
3359 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3360 viewport.getAlignment()));
3361 alignPanel.paintAlignment(true);
3370 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3372 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3373 AlignmentSorter.sortByID(viewport.getAlignment());
3374 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.getAlignment()));
3375 alignPanel.paintAlignment(true);
3384 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3386 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3387 AlignmentSorter.sortByLength(viewport.getAlignment());
3388 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3389 viewport.getAlignment()));
3390 alignPanel.paintAlignment(true);
3399 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3401 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3402 AlignmentSorter.sortByGroup(viewport.getAlignment());
3403 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3404 viewport.getAlignment()));
3406 alignPanel.paintAlignment(true);
3415 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3417 new RedundancyPanel(alignPanel, this);
3426 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3428 if ((viewport.getSelectionGroup() == null)
3429 || (viewport.getSelectionGroup().getSize() < 2))
3431 JOptionPane.showInternalMessageDialog(this,
3432 "You must select at least 2 sequences.", "Invalid Selection",
3433 JOptionPane.WARNING_MESSAGE);
3437 JInternalFrame frame = new JInternalFrame();
3438 frame.setContentPane(new PairwiseAlignPanel(viewport));
3439 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3449 public void PCAMenuItem_actionPerformed(ActionEvent e)
3451 if (((viewport.getSelectionGroup() != null)
3452 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3453 .getSelectionGroup().getSize() > 0))
3454 || (viewport.getAlignment().getHeight() < 4))
3456 JOptionPane.showInternalMessageDialog(this,
3457 "Principal component analysis must take\n"
3458 + "at least 4 input sequences.",
3459 "Sequence selection insufficient",
3460 JOptionPane.WARNING_MESSAGE);
3465 new PCAPanel(alignPanel);
3468 public void autoCalculate_actionPerformed(ActionEvent e)
3470 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3471 if (viewport.autoCalculateConsensus)
3473 viewport.firePropertyChange("alignment", null, viewport
3474 .getAlignment().getSequences());
3477 public void sortByTreeOption_actionPerformed(ActionEvent e)
3479 viewport.sortByTree = sortByTree.isSelected();
3483 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3485 viewport.followSelection = listenToViewSelections.isSelected();
3493 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3495 NewTreePanel("AV", "PID", "Average distance tree using PID");
3504 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3506 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3515 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3517 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3526 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3528 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3541 void NewTreePanel(String type, String pwType, String title)
3545 if (viewport.getSelectionGroup() != null)
3547 if (viewport.getSelectionGroup().getSize() < 3)
3552 "You need to have more than two sequences selected to build a tree!",
3553 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3558 SequenceGroup sg = viewport.getSelectionGroup();
3560 /* Decide if the selection is a column region */
3561 while (s < sg.getSize())
3563 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3569 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3570 + "Try using the Pad function in the edit menu,\n"
3571 + "or one of the multiple sequence alignment web services.",
3572 "Sequences in selection are not aligned",
3573 JOptionPane.WARNING_MESSAGE);
3579 title = title + " on region";
3580 tp = new TreePanel(alignPanel, type, pwType);
3584 // are the visible sequences aligned?
3585 if (!viewport.getAlignment().isAligned(false))
3590 "The sequences must be aligned before creating a tree.\n"
3591 + "Try using the Pad function in the edit menu,\n"
3592 + "or one of the multiple sequence alignment web services.",
3593 "Sequences not aligned",
3594 JOptionPane.WARNING_MESSAGE);
3599 if (viewport.getAlignment().getHeight() < 2)
3604 tp = new TreePanel(alignPanel, type, pwType);
3609 if (viewport.viewName != null)
3611 title += viewport.viewName + " of ";
3614 title += this.title;
3616 Desktop.addInternalFrame(tp, title, 600, 500);
3627 public void addSortByOrderMenuItem(String title,
3628 final AlignmentOrder order)
3630 final JMenuItem item = new JMenuItem("by " + title);
3632 item.addActionListener(new java.awt.event.ActionListener()
3634 public void actionPerformed(ActionEvent e)
3636 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3638 // TODO: JBPNote - have to map order entries to curent SequenceI
3640 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3642 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3643 viewport.getAlignment()));
3645 alignPanel.paintAlignment(true);
3651 * Add a new sort by annotation score menu item
3654 * the menu to add the option to
3656 * the label used to retrieve scores for each sequence on the
3659 public void addSortByAnnotScoreMenuItem(JMenu sort,
3660 final String scoreLabel)
3662 final JMenuItem item = new JMenuItem(scoreLabel);
3664 item.addActionListener(new java.awt.event.ActionListener()
3666 public void actionPerformed(ActionEvent e)
3668 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3669 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3670 viewport.getAlignment());// ,viewport.getSelectionGroup());
3671 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3672 viewport.getAlignment()));
3673 alignPanel.paintAlignment(true);
3679 * last hash for alignment's annotation array - used to minimise cost of
3682 protected int _annotationScoreVectorHash;
3685 * search the alignment and rebuild the sort by annotation score submenu the
3686 * last alignment annotation vector hash is stored to minimize cost of
3687 * rebuilding in subsequence calls.
3690 public void buildSortByAnnotationScoresMenu()
3692 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3697 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3699 sortByAnnotScore.removeAll();
3700 // almost certainly a quicker way to do this - but we keep it simple
3701 Hashtable scoreSorts = new Hashtable();
3702 AlignmentAnnotation aann[];
3703 Enumeration sq = viewport.getAlignment().getSequences().elements();
3704 while (sq.hasMoreElements())
3706 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3707 for (int i = 0; aann != null && i < aann.length; i++)
3709 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3711 scoreSorts.put(aann[i].label, aann[i].label);
3715 Enumeration labels = scoreSorts.keys();
3716 while (labels.hasMoreElements())
3718 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3719 (String) labels.nextElement());
3721 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3724 _annotationScoreVectorHash = viewport.getAlignment()
3725 .getAlignmentAnnotation().hashCode();
3730 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3731 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3732 * call. Listeners are added to remove the menu item when the treePanel is
3733 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3737 * Displayed tree window.
3739 * SortBy menu item title.
3741 public void buildTreeMenu()
3743 sortByTreeMenu.removeAll();
3745 Vector comps = (Vector) PaintRefresher.components.get(viewport
3746 .getSequenceSetId());
3747 Vector treePanels = new Vector();
3748 int i, iSize = comps.size();
3749 for (i = 0; i < iSize; i++)
3751 if (comps.elementAt(i) instanceof TreePanel)
3753 treePanels.add(comps.elementAt(i));
3757 iSize = treePanels.size();
3761 sortByTreeMenu.setVisible(false);
3765 sortByTreeMenu.setVisible(true);
3767 for (i = 0; i < treePanels.size(); i++)
3769 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3770 final JMenuItem item = new JMenuItem(tp.getTitle());
3771 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3772 item.addActionListener(new java.awt.event.ActionListener()
3774 public void actionPerformed(ActionEvent e)
3776 tp.sortByTree_actionPerformed(null);
3777 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3782 sortByTreeMenu.add(item);
3786 public boolean sortBy(AlignmentOrder alorder, String undoname)
3788 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3789 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3790 if (undoname != null)
3792 addHistoryItem(new OrderCommand(undoname, oldOrder,
3793 viewport.getAlignment()));
3795 alignPanel.paintAlignment(true);
3800 * Work out whether the whole set of sequences or just the selected set will
3801 * be submitted for multiple alignment.
3804 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3806 // Now, check we have enough sequences
3807 AlignmentView msa = null;
3809 if ((viewport.getSelectionGroup() != null)
3810 && (viewport.getSelectionGroup().getSize() > 1))
3812 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3813 // some common interface!
3815 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3816 * SequenceI[sz = seqs.getSize(false)];
3818 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3819 * seqs.getSequenceAt(i); }
3821 msa = viewport.getAlignmentView(true);
3826 * Vector seqs = viewport.getAlignment().getSequences();
3828 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3830 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3831 * seqs.elementAt(i); } }
3833 msa = viewport.getAlignmentView(false);
3839 * Decides what is submitted to a secondary structure prediction service: the
3840 * first sequence in the alignment, or in the current selection, or, if the
3841 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3842 * region or the whole alignment. (where the first sequence in the set is the
3843 * one that the prediction will be for).
3845 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3847 AlignmentView seqs = null;
3849 if ((viewport.getSelectionGroup() != null)
3850 && (viewport.getSelectionGroup().getSize() > 0))
3852 seqs = viewport.getAlignmentView(true);
3856 seqs = viewport.getAlignmentView(false);
3858 // limit sequences - JBPNote in future - could spawn multiple prediction
3860 // TODO: viewport.getAlignment().isAligned is a global state - the local
3861 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3862 if (!viewport.getAlignment().isAligned(false))
3864 seqs.setSequences(new SeqCigar[]
3865 { seqs.getSequences()[0] });
3866 // TODO: if seqs.getSequences().length>1 then should really have warned
3879 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3881 // Pick the tree file
3882 JalviewFileChooser chooser = new JalviewFileChooser(
3883 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3884 chooser.setFileView(new JalviewFileView());
3885 chooser.setDialogTitle("Select a newick-like tree file");
3886 chooser.setToolTipText("Load a tree file");
3888 int value = chooser.showOpenDialog(null);
3890 if (value == JalviewFileChooser.APPROVE_OPTION)
3892 String choice = chooser.getSelectedFile().getPath();
3893 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3894 jalview.io.NewickFile fin = null;
3897 fin = new jalview.io.NewickFile(choice, "File");
3898 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3899 } catch (Exception ex)
3901 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3902 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3903 ex.printStackTrace();
3905 if (fin != null && fin.hasWarningMessage())
3907 JOptionPane.showMessageDialog(Desktop.desktop,
3908 fin.getWarningMessage(), "Possible problem with tree file",
3909 JOptionPane.WARNING_MESSAGE);
3914 public TreePanel ShowNewickTree(NewickFile nf, String title)
3916 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3919 public TreePanel ShowNewickTree(NewickFile nf, String title,
3920 AlignmentView input)
3922 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3925 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3926 int h, int x, int y)
3928 return ShowNewickTree(nf, title, null, w, h, x, y);
3932 * Add a treeviewer for the tree extracted from a newick file object to the
3933 * current alignment view
3940 * Associated alignment input data (or null)
3949 * @return TreePanel handle
3951 public TreePanel ShowNewickTree(NewickFile nf, String title,
3952 AlignmentView input, int w, int h, int x, int y)
3954 TreePanel tp = null;
3960 if (nf.getTree() != null)
3962 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3968 tp.setLocation(x, y);
3971 Desktop.addInternalFrame(tp, title, w, h);
3973 } catch (Exception ex)
3975 ex.printStackTrace();
3981 private boolean buildingMenu = false;
3984 * Generates menu items and listener event actions for web service clients
3987 public void BuildWebServiceMenu()
3989 while (buildingMenu)
3993 System.err.println("Waiting for building menu to finish.");
3995 } catch (Exception e)
4000 final AlignFrame me = this;
4001 buildingMenu = true;
4002 new Thread(new Runnable()
4008 System.err.println("Building ws menu again "
4009 + Thread.currentThread());
4010 // TODO: add support for context dependent disabling of services based
4012 // alignment and current selection
4013 // TODO: add additional serviceHandle parameter to specify abstract
4015 // class independently of AbstractName
4016 // TODO: add in rediscovery GUI function to restart discoverer
4017 // TODO: group services by location as well as function and/or
4019 // object broker mechanism.
4020 final Vector wsmenu = new Vector();
4021 final IProgressIndicator af = me;
4022 final JMenu msawsmenu = new JMenu("Alignment");
4023 final JMenu secstrmenu = new JMenu(
4024 "Secondary Structure Prediction");
4025 final JMenu seqsrchmenu = new JMenu(
4026 "Sequence Database Search");
4027 final JMenu analymenu = new JMenu(
4029 // JAL-940 - only show secondary structure prediction services from the legacy server
4030 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4032 Discoverer.services != null
4033 && (Discoverer.services.size() > 0))
4035 // TODO: refactor to allow list of AbstractName/Handler bindings to
4037 // stored or retrieved from elsewhere
4038 Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4039 Vector secstrpr = (Vector) Discoverer.services
4041 Vector seqsrch = null; // (Vector) Discoverer.services.get("SeqSearch");
4042 // TODO: move GUI generation code onto service implementation - so a
4043 // client instance attaches itself to the GUI with method call like
4044 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
4048 // Add any Multiple Sequence Alignment Services
4049 for (int i = 0, j = msaws.size(); i < j; i++)
4051 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
4053 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4054 .getServiceClient(sh);
4055 impl.attachWSMenuEntry(msawsmenu, me);
4059 if (secstrpr != null)
4061 // Add any secondary structure prediction services
4062 for (int i = 0, j = secstrpr.size(); i < j; i++)
4064 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4066 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4067 .getServiceClient(sh);
4068 impl.attachWSMenuEntry(secstrmenu, me);
4071 if (seqsrch != null)
4073 // Add any sequence search services
4074 for (int i = 0, j = seqsrch.size(); i < j; i++)
4076 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4078 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4079 .getServiceClient(sh);
4080 impl.attachWSMenuEntry(seqsrchmenu, me);
4085 // TODO: move into separate menu builder class.
4086 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4088 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4089 if (jws2servs != null)
4091 if (jws2servs.hasServices())
4093 jws2servs.attachWSMenuEntry(msawsmenu, me);
4097 // Add all submenus in the order they should appear on the web services menu
4098 wsmenu.add(msawsmenu);
4099 wsmenu.add(secstrmenu);
4100 wsmenu.add(analymenu);
4101 // No search services yet
4102 // wsmenu.add(seqsrchmenu);
4104 javax.swing.SwingUtilities.invokeLater(new Runnable()
4110 webService.removeAll();
4111 // first, add discovered services onto the webservices menu
4112 if (wsmenu.size() > 0)
4114 for (int i = 0, j = wsmenu.size(); i < j; i++)
4116 webService.add((JMenu) wsmenu.get(i));
4121 webService.add(me.webServiceNoServices);
4123 build_urlServiceMenu(me.webService);
4124 build_fetchdbmenu(webService);
4125 } catch (Exception e)
4131 } catch (Exception e)
4136 buildingMenu = false;
4144 * construct any groupURL type service menu entries.
4148 private void build_urlServiceMenu(JMenu webService)
4150 // TODO: remove this code when 2.7 is released
4151 // DEBUG - alignmentView
4153 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4154 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4156 * @Override public void actionPerformed(ActionEvent e) {
4157 * jalview.datamodel.AlignmentView.testSelectionViews(af.viewport.getAlignment(),
4158 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4160 * }); webService.add(testAlView);
4162 // TODO: refactor to RestClient discoverer and merge menu entries for
4163 // rest-style services with other types of analysis/calculation service
4164 // SHmmr test client - still being implemented.
4165 // DEBUG - alignmentView
4167 for (jalview.ws.rest.RestClient client: jalview.ws.rest.RestClient.getRestClients()) {
4168 client.attachWSMenuEntry(JvSwingUtils.findOrCreateMenu(webService, client.getAction()), this);
4171 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4173 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4179 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4180 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4181 * getProperty("LAST_DIRECTORY"));
4183 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4184 * to Vamsas file"); chooser.setToolTipText("Export");
4186 * int value = chooser.showSaveDialog(this);
4188 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4189 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4190 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4191 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4194 * prototype of an automatically enabled/disabled analysis function
4197 protected void setShowProductsEnabled()
4199 SequenceI[] selection = viewport.getSequenceSelection();
4200 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4201 viewport.getAlignment().getDataset()))
4203 showProducts.setEnabled(true);
4208 showProducts.setEnabled(false);
4213 * search selection for sequence xRef products and build the show products
4218 * @return true if showProducts menu should be enabled.
4220 public boolean canShowProducts(SequenceI[] selection,
4221 boolean isRegionSelection, Alignment dataset)
4223 boolean showp = false;
4226 showProducts.removeAll();
4227 final boolean dna = viewport.getAlignment().isNucleotide();
4228 final Alignment ds = dataset;
4229 String[] ptypes = (selection == null || selection.length == 0) ? null
4230 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4232 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4233 // selection, dataset, true);
4234 final SequenceI[] sel = selection;
4235 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4238 final boolean isRegSel = isRegionSelection;
4239 final AlignFrame af = this;
4240 final String source = ptypes[t];
4241 JMenuItem xtype = new JMenuItem(ptypes[t]);
4242 xtype.addActionListener(new ActionListener()
4245 public void actionPerformed(ActionEvent e)
4247 // TODO: new thread for this call with vis-delay
4248 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4249 isRegSel, dna, source);
4253 showProducts.add(xtype);
4255 showProducts.setVisible(showp);
4256 showProducts.setEnabled(showp);
4257 } catch (Exception e)
4259 jalview.bin.Cache.log
4260 .warn("canTranslate threw an exception - please report to help@jalview.org",
4267 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4268 boolean isRegSel, boolean dna, String source)
4270 final boolean fisRegSel = isRegSel;
4271 final boolean fdna = dna;
4272 final String fsrc = source;
4273 final AlignFrame ths = this;
4274 final SequenceI[] fsel = sel;
4275 Runnable foo = new Runnable()
4280 final long sttime = System.currentTimeMillis();
4281 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4284 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4288 Alignment prods = CrossRef
4289 .findXrefSequences(fsel, fdna, fsrc, ds);
4292 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4293 for (int s = 0; s < sprods.length; s++)
4295 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4296 if (ds.getSequences() == null
4297 || !ds.getSequences().contains(
4298 sprods[s].getDatasetSequence()))
4299 ds.addSequence(sprods[s].getDatasetSequence());
4300 sprods[s].updatePDBIds();
4302 Alignment al = new Alignment(sprods);
4303 AlignedCodonFrame[] cf = prods.getCodonFrames();
4305 for (int s = 0; cf != null && s < cf.length; s++)
4307 al.addCodonFrame(cf[s]);
4310 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4312 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4313 + " for " + ((fisRegSel) ? "selected region of " : "")
4315 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4320 System.err.println("No Sequences generated for xRef type "
4323 } catch (Exception e)
4325 jalview.bin.Cache.log.error(
4326 "Exception when finding crossreferences", e);
4327 } catch (OutOfMemoryError e)
4329 new OOMWarning("whilst fetching crossreferences", e);
4332 jalview.bin.Cache.log.error("Error when finding crossreferences",
4335 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4340 Thread frunner = new Thread(foo);
4344 public boolean canShowTranslationProducts(SequenceI[] selection,
4345 AlignmentI alignment)
4350 return (jalview.analysis.Dna.canTranslate(selection,
4351 viewport.getViewAsVisibleContigs(true)));
4352 } catch (Exception e)
4354 jalview.bin.Cache.log
4355 .warn("canTranslate threw an exception - please report to help@jalview.org",
4361 public void showProducts_actionPerformed(ActionEvent e)
4363 // /////////////////////////////
4364 // Collect Data to be translated/transferred
4366 SequenceI[] selection = viewport.getSequenceSelection();
4367 AlignmentI al = null;
4370 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4371 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4372 viewport.getAlignment().getDataset());
4373 } catch (Exception ex)
4376 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4383 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4384 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4388 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4389 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4390 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4394 public void showTranslation_actionPerformed(ActionEvent e)
4396 // /////////////////////////////
4397 // Collect Data to be translated/transferred
4399 SequenceI[] selection = viewport.getSequenceSelection();
4400 String[] seqstring = viewport.getViewAsString(true);
4401 AlignmentI al = null;
4404 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4405 viewport.getViewAsVisibleContigs(true), viewport
4406 .getGapCharacter(), viewport.getAlignment()
4407 .getAlignmentAnnotation(), viewport.getAlignment()
4408 .getWidth(), viewport.getAlignment().getDataset());
4409 } catch (Exception ex)
4412 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4419 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4420 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4424 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4425 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4426 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4431 * Try to load a features file onto the alignment.
4434 * contents or path to retrieve file
4436 * access mode of file (see jalview.io.AlignFile)
4437 * @return true if features file was parsed corectly.
4439 public boolean parseFeaturesFile(String file, String type)
4441 boolean featuresFile = false;
4444 featuresFile = new FeaturesFile(file, type)
4445 .parse(viewport.getAlignment().getDataset(),
4446 alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
4447 false, jalview.bin.Cache.getDefault(
4448 "RELAXEDSEQIDMATCHING", false));
4449 } catch (Exception ex)
4451 ex.printStackTrace();
4456 viewport.showSequenceFeatures = true;
4457 showSeqFeatures.setSelected(true);
4458 if (alignPanel.seqPanel.seqCanvas.fr != null)
4460 // update the min/max ranges where necessary
4461 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4463 if (featureSettings != null)
4465 featureSettings.setTableData();
4467 alignPanel.paintAlignment(true);
4470 return featuresFile;
4473 public void dragEnter(DropTargetDragEvent evt)
4477 public void dragExit(DropTargetEvent evt)
4481 public void dragOver(DropTargetDragEvent evt)
4485 public void dropActionChanged(DropTargetDragEvent evt)
4489 public void drop(DropTargetDropEvent evt)
4491 Transferable t = evt.getTransferable();
4492 java.util.List files = null;
4496 DataFlavor uriListFlavor = new DataFlavor(
4497 "text/uri-list;class=java.lang.String");
4498 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4500 // Works on Windows and MacOSX
4501 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4502 files = (java.util.List) t
4503 .getTransferData(DataFlavor.javaFileListFlavor);
4505 else if (t.isDataFlavorSupported(uriListFlavor))
4507 // This is used by Unix drag system
4508 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4509 String data = (String) t.getTransferData(uriListFlavor);
4510 files = new java.util.ArrayList(1);
4511 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4512 data, "\r\n"); st.hasMoreTokens();)
4514 String s = st.nextToken();
4515 if (s.startsWith("#"))
4517 // the line is a comment (as per the RFC 2483)
4521 java.net.URI uri = new java.net.URI(s);
4522 // check to see if we can handle this kind of URI
4523 if (uri.getScheme().toLowerCase().startsWith("http"))
4525 files.add(uri.toString());
4529 // otherwise preserve old behaviour: catch all for file objects
4530 java.io.File file = new java.io.File(uri);
4531 files.add(file.toString());
4535 } catch (Exception e)
4537 e.printStackTrace();
4543 // check to see if any of these files have names matching sequences in
4545 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4546 .getAlignment().getSequencesArray());
4548 * Object[] { String,SequenceI}
4550 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4551 ArrayList<String> filesnotmatched = new ArrayList<String>();
4552 for (int i = 0; i < files.size(); i++)
4554 String file = files.get(i).toString();
4556 String protocol = FormatAdapter.checkProtocol(file);
4557 if (protocol == jalview.io.FormatAdapter.FILE)
4559 File fl = new File(file);
4560 pdbfn = fl.getName();
4562 else if (protocol == jalview.io.FormatAdapter.URL)
4564 URL url = new URL(file);
4565 pdbfn = url.getFile();
4567 if (pdbfn.length() > 0)
4569 // attempt to find a match in the alignment
4570 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4571 int l = 0, c = pdbfn.indexOf(".");
4572 while (mtch == null && c != -1)
4577 } while ((c = pdbfn.indexOf(".", l)) > l);
4580 pdbfn = pdbfn.substring(0, l);
4582 mtch = idm.findAllIdMatches(pdbfn);
4589 type = new IdentifyFile().Identify(file, protocol);
4590 } catch (Exception ex)
4596 if (type.equalsIgnoreCase("PDB"))
4598 filesmatched.add(new Object[]
4599 { file, protocol, mtch });
4604 // File wasn't named like one of the sequences or wasn't a PDB file.
4605 filesnotmatched.add(file);
4609 if (filesmatched.size() > 0)
4611 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4615 "Do you want to automatically associate the "
4616 + filesmatched.size()
4617 + " PDB files with sequences in the alignment that have the same name ?",
4618 "Automatically Associate PDB files by name",
4619 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4622 for (Object[] fm : filesmatched)
4624 // try and associate
4625 // TODO: may want to set a standard ID naming formalism for
4626 // associating PDB files which have no IDs.
4627 for (SequenceI toassoc: (SequenceI[])fm[2]) {
4628 PDBEntry pe = new AssociatePdbFileWithSeq()
4629 .associatePdbWithSeq((String) fm[0], (String) fm[1],
4634 .println("Associated file : " + ((String) fm[0])
4636 + toassoc.getDisplayId(true));
4640 alignPanel.paintAlignment(true);
4644 if (filesnotmatched.size() > 0)
4647 && (Cache.getDefault(
4648 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4651 "<html>Do you want to <em>ignore</em> the "
4652 + filesnotmatched.size()
4653 + " files whose names did not match any sequence IDs ?</html>",
4654 "Ignore unmatched dropped files ?",
4655 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4659 for (String fn : filesnotmatched)
4661 loadJalviewDataFile(fn, null, null, null);
4665 } catch (Exception ex)
4667 ex.printStackTrace();
4673 * Attempt to load a "dropped" file or URL string: First by testing whether
4674 * it's and Annotation file, then a JNet file, and finally a features file. If
4675 * all are false then the user may have dropped an alignment file onto this
4679 * either a filename or a URL string.
4681 public void loadJalviewDataFile(String file, String protocol,
4682 String format, SequenceI assocSeq)
4686 if (protocol == null)
4688 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4690 // if the file isn't identified, or not positively identified as some
4691 // other filetype (PFAM is default unidentified alignment file type) then
4692 // try to parse as annotation.
4693 boolean isAnnotation = (format == null || format
4694 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4695 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4700 // try to see if its a JNet 'concise' style annotation file *before* we
4701 // try to parse it as a features file
4704 format = new IdentifyFile().Identify(file, protocol);
4706 if (format.equalsIgnoreCase("JnetFile"))
4708 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4710 new JnetAnnotationMaker().add_annotation(predictions,
4711 viewport.getAlignment(), 0, false);
4712 isAnnotation = true;
4717 * if (format.equalsIgnoreCase("PDB")) {
4719 * String pdbfn = ""; // try to match up filename with sequence id try
4720 * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new
4721 * File(file); pdbfn = fl.getName(); } else if (protocol ==
4722 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4723 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null)
4724 * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4725 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { //
4726 * attempt to find a match in the alignment SequenceI mtch =
4727 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4728 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l)
4729 * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch =
4730 * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate
4731 * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4732 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) {
4733 * System.err.println("Associated file : " + file + " with " +
4734 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4735 * TODO: maybe need to load as normal otherwise return; } }
4737 // try to parse it as a features file
4738 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4739 // if it wasn't a features file then we just treat it as a general
4740 // alignment file to load into the current view.
4743 new FileLoader().LoadFile(viewport, file, protocol, format);
4747 alignPanel.paintAlignment(true);
4754 alignPanel.adjustAnnotationHeight();
4755 viewport.updateSequenceIdColours();
4756 buildSortByAnnotationScoresMenu();
4757 alignPanel.paintAlignment(true);
4759 } catch (Exception ex)
4761 ex.printStackTrace();
4765 public void tabSelectionChanged(int index)
4769 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4770 viewport = alignPanel.av;
4771 setMenusFromViewport(viewport);
4775 public void tabbedPane_mousePressed(MouseEvent e)
4777 if (SwingUtilities.isRightMouseButton(e))
4779 String reply = JOptionPane.showInternalInputDialog(this,
4780 "Enter View Name", "Edit View Name",
4781 JOptionPane.QUESTION_MESSAGE);
4785 viewport.viewName = reply;
4786 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4791 public AlignViewport getCurrentView()
4797 * Open the dialog for regex description parsing.
4799 protected void extractScores_actionPerformed(ActionEvent e)
4801 ParseProperties pp = new jalview.analysis.ParseProperties(
4802 viewport.getAlignment());
4803 // TODO: verify regex and introduce GUI dialog for version 2.5
4804 // if (pp.getScoresFromDescription("col", "score column ",
4805 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4807 if (pp.getScoresFromDescription("description column",
4808 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4810 buildSortByAnnotationScoresMenu();
4818 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4821 protected void showDbRefs_actionPerformed(ActionEvent e)
4823 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4829 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4832 protected void showNpFeats_actionPerformed(ActionEvent e)
4834 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4838 * find the viewport amongst the tabs in this alignment frame and close that
4843 public boolean closeView(AlignViewport av)
4847 this.closeMenuItem_actionPerformed(false);
4850 Component[] comp = tabbedPane.getComponents();
4851 for (int i = 0; comp != null && i < comp.length; i++)
4853 if (comp[i] instanceof AlignmentPanel)
4855 if (((AlignmentPanel) comp[i]).av == av)
4858 closeView((AlignmentPanel) comp[i]);
4866 protected void build_fetchdbmenu(JMenu webService)
4868 // Temporary hack - DBRef Fetcher always top level ws entry.
4869 // TODO We probably want to store a sequence database checklist in
4870 // preferences and have checkboxes.. rather than individual sources selected
4872 final JMenu rfetch = new JMenu("Fetch DB References");
4873 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4874 webService.add(rfetch);
4876 JMenuItem fetchr = new JMenuItem("Standard Databases");
4877 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4878 fetchr.addActionListener(new ActionListener()
4881 public void actionPerformed(ActionEvent e)
4883 new Thread(new Runnable()
4888 new jalview.ws.DBRefFetcher(alignPanel.av
4889 .getSequenceSelection(), alignPanel.alignFrame)
4890 .fetchDBRefs(false);
4898 final AlignFrame me = this;
4899 new Thread(new Runnable()
4903 final jalview.ws.SequenceFetcher sf = SequenceFetcher
4904 .getSequenceFetcherSingleton(me);
4905 final String[] otherdb = sf.getOrderedSupportedSources();
4906 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4907 // jalview.util.QuickSort.sort(otherdb, otherdb);
4908 javax.swing.SwingUtilities.invokeLater(new Runnable()
4913 JMenu dfetch = new JMenu();
4916 int comp = 0, mcomp = 15;
4917 String mname = null;
4918 if (otherdb != null && otherdb.length > 0)
4920 for (int i = 0; i < otherdb.length; i++)
4922 String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
4925 mname = "from '" + dbname + "'";
4927 fetchr = new JMenuItem(otherdb[i]);
4928 final String[] dassource = new String[]
4930 fetchr.addActionListener(new ActionListener()
4933 public void actionPerformed(ActionEvent e)
4935 new Thread(new Runnable()
4940 new jalview.ws.DBRefFetcher(alignPanel.av
4941 .getSequenceSelection(),
4942 alignPanel.alignFrame, dassource)
4943 .fetchDBRefs(false);
4949 fetchr.setToolTipText("Retrieve from " + dbname);
4951 if (comp++ == mcomp || i == (otherdb.length - 1))
4953 dfetch.setText(mname + " to '" + dbname + "'");
4955 dfetch = new JMenu();
4969 * Left justify the whole alignment.
4971 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4973 AlignmentI al = viewport.getAlignment();
4975 viewport.firePropertyChange("alignment", null, al);
4979 * Right justify the whole alignment.
4981 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4983 AlignmentI al = viewport.getAlignment();
4985 viewport.firePropertyChange("alignment", null, al);
4988 public void setShowSeqFeatures(boolean b)
4990 showSeqFeatures.setSelected(true);
4991 viewport.setShowSequenceFeatures(true);
4998 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
4999 * awt.event.ActionEvent)
5001 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5003 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5004 alignPanel.paintAlignment(true);
5011 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5014 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5016 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5017 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5025 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5026 * .event.ActionEvent)
5028 protected void showGroupConservation_actionPerformed(ActionEvent e)
5030 viewport.setShowGroupConservation(showGroupConservation.getState());
5031 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5038 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5039 * .event.ActionEvent)
5041 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5043 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5044 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5051 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5052 * .event.ActionEvent)
5054 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5056 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5057 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5059 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5061 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5062 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5064 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5066 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5073 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5074 * .event.ActionEvent)
5076 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5078 if (viewport.getSelectionGroup() != null)
5080 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5081 viewport.getSequenceSelection(),
5082 viewport.getAlignmentView(true).getSequenceStrings(
5083 viewport.getGapCharacter()),
5084 viewport.getAlignment().getGroups());
5085 viewport.getAlignment().deleteAllGroups();
5086 viewport.sequenceColours = null;
5087 viewport.setSelectionGroup(null);
5088 // set view properties for each group
5089 for (int g = 0; g < gps.length; g++)
5091 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5092 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5093 viewport.getAlignment().addGroup(gps[g]);
5094 Color col = new Color((int) (Math.random() * 255),
5095 (int) (Math.random() * 255), (int) (Math.random() * 255));
5096 col = col.brighter();
5097 for (Enumeration sq = gps[g].getSequences(null).elements(); sq
5098 .hasMoreElements(); viewport.setSequenceColour(
5099 (SequenceI) sq.nextElement(), col))
5102 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5103 alignPanel.updateAnnotation();
5104 alignPanel.paintAlignment(true);
5109 * make the given alignmentPanel the currently selected tab
5111 * @param alignmentPanel
5113 public void setDisplayedView(AlignmentPanel alignmentPanel)
5115 if (!viewport.getSequenceSetId().equals(
5116 alignmentPanel.av.getSequenceSetId()))
5119 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5121 if (tabbedPane != null
5122 & alignPanels.indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5124 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5129 class PrintThread extends Thread
5133 public PrintThread(AlignmentPanel ap)
5138 static PageFormat pf;
5142 PrinterJob printJob = PrinterJob.getPrinterJob();
5146 printJob.setPrintable(ap, pf);
5150 printJob.setPrintable(ap);
5153 if (printJob.printDialog())
5158 } catch (Exception PrintException)
5160 PrintException.printStackTrace();