2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.analysis.AAFrequency;
21 import jalview.analysis.AlignmentSorter;
22 import jalview.analysis.Conservation;
23 import jalview.analysis.CrossRef;
24 import jalview.analysis.NJTree;
25 import jalview.analysis.ParseProperties;
26 import jalview.analysis.SequenceIdMatcher;
27 import jalview.bin.Cache;
28 import jalview.commands.CommandI;
29 import jalview.commands.EditCommand;
30 import jalview.commands.OrderCommand;
31 import jalview.commands.RemoveGapColCommand;
32 import jalview.commands.RemoveGapsCommand;
33 import jalview.commands.SlideSequencesCommand;
34 import jalview.commands.TrimRegionCommand;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.Alignment;
37 import jalview.datamodel.AlignmentAnnotation;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentOrder;
40 import jalview.datamodel.AlignmentView;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.PDBEntry;
43 import jalview.datamodel.SeqCigar;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.datamodel.SequenceI;
47 import jalview.io.AlignmentProperties;
48 import jalview.io.AnnotationFile;
49 import jalview.io.FeaturesFile;
50 import jalview.io.FileLoader;
51 import jalview.io.FormatAdapter;
52 import jalview.io.HTMLOutput;
53 import jalview.io.IdentifyFile;
54 import jalview.io.JalviewFileChooser;
55 import jalview.io.JalviewFileView;
56 import jalview.io.JnetAnnotationMaker;
57 import jalview.io.NewickFile;
58 import jalview.jbgui.GAlignFrame;
59 import jalview.schemes.Blosum62ColourScheme;
60 import jalview.schemes.BuriedColourScheme;
61 import jalview.schemes.ClustalxColourScheme;
62 import jalview.schemes.ColourSchemeI;
63 import jalview.schemes.ColourSchemeProperty;
64 import jalview.schemes.HelixColourScheme;
65 import jalview.schemes.HydrophobicColourScheme;
66 import jalview.schemes.NucleotideColourScheme;
67 import jalview.schemes.PIDColourScheme;
68 import jalview.schemes.ResidueProperties;
69 import jalview.schemes.StrandColourScheme;
70 import jalview.schemes.TaylorColourScheme;
71 import jalview.schemes.TurnColourScheme;
72 import jalview.schemes.UserColourScheme;
73 import jalview.schemes.ZappoColourScheme;
74 import jalview.ws.jws1.Discoverer;
75 import jalview.ws.jws2.Jws2Discoverer;
77 import java.awt.BorderLayout;
78 import java.awt.Color;
79 import java.awt.Component;
80 import java.awt.GridLayout;
81 import java.awt.Rectangle;
82 import java.awt.Toolkit;
83 import java.awt.datatransfer.Clipboard;
84 import java.awt.datatransfer.DataFlavor;
85 import java.awt.datatransfer.StringSelection;
86 import java.awt.datatransfer.Transferable;
87 import java.awt.dnd.DnDConstants;
88 import java.awt.dnd.DropTargetDragEvent;
89 import java.awt.dnd.DropTargetDropEvent;
90 import java.awt.dnd.DropTargetEvent;
91 import java.awt.dnd.DropTargetListener;
92 import java.awt.event.ActionEvent;
93 import java.awt.event.ActionListener;
94 import java.awt.event.KeyAdapter;
95 import java.awt.event.KeyEvent;
96 import java.awt.event.MouseAdapter;
97 import java.awt.event.MouseEvent;
98 import java.awt.print.PageFormat;
99 import java.awt.print.PrinterJob;
100 import java.beans.PropertyChangeEvent;
103 import java.util.ArrayList;
104 import java.util.Enumeration;
105 import java.util.Hashtable;
106 import java.util.Vector;
108 import javax.swing.JButton;
109 import javax.swing.JEditorPane;
110 import javax.swing.JInternalFrame;
111 import javax.swing.JLabel;
112 import javax.swing.JLayeredPane;
113 import javax.swing.JMenu;
114 import javax.swing.JMenuItem;
115 import javax.swing.JOptionPane;
116 import javax.swing.JPanel;
117 import javax.swing.JProgressBar;
118 import javax.swing.JRadioButtonMenuItem;
119 import javax.swing.JScrollPane;
120 import javax.swing.SwingUtilities;
126 * @version $Revision$
128 public class AlignFrame extends GAlignFrame implements DropTargetListener,
133 public static final int DEFAULT_WIDTH = 700;
136 public static final int DEFAULT_HEIGHT = 500;
138 public AlignmentPanel alignPanel;
140 AlignViewport viewport;
142 Vector alignPanels = new Vector();
145 * Last format used to load or save alignments in this window
147 String currentFileFormat = null;
150 * Current filename for this alignment
152 String fileName = null;
155 * Creates a new AlignFrame object with specific width and height.
161 public AlignFrame(AlignmentI al, int width, int height)
163 this(al, null, width, height);
167 * Creates a new AlignFrame object with specific width, height and
173 * @param sequenceSetId
175 public AlignFrame(AlignmentI al, int width, int height,
176 String sequenceSetId)
178 this(al, null, width, height, sequenceSetId);
182 * Creates a new AlignFrame object with specific width, height and
188 * @param sequenceSetId
191 public AlignFrame(AlignmentI al, int width, int height,
192 String sequenceSetId, String viewId)
194 this(al, null, width, height, sequenceSetId, viewId);
198 * new alignment window with hidden columns
202 * @param hiddenColumns
203 * ColumnSelection or null
205 * Width of alignment frame
209 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
210 int width, int height)
212 this(al, hiddenColumns, width, height, null);
216 * Create alignment frame for al with hiddenColumns, a specific width and
217 * height, and specific sequenceId
220 * @param hiddenColumns
223 * @param sequenceSetId
226 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
227 int width, int height, String sequenceSetId)
229 this(al, hiddenColumns, width, height, sequenceSetId, null);
233 * Create alignment frame for al with hiddenColumns, a specific width and
234 * height, and specific sequenceId
237 * @param hiddenColumns
240 * @param sequenceSetId
245 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
246 int width, int height, String sequenceSetId, String viewId)
248 setSize(width, height);
249 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
251 alignPanel = new AlignmentPanel(this, viewport);
253 if (al.getDataset() == null)
258 addAlignmentPanel(alignPanel, true);
263 * Make a new AlignFrame from exisiting alignmentPanels
270 public AlignFrame(AlignmentPanel ap)
274 addAlignmentPanel(ap, false);
279 * initalise the alignframe from the underlying viewport data and the
284 if (viewport.conservation == null)
286 BLOSUM62Colour.setEnabled(false);
287 conservationMenuItem.setEnabled(false);
288 modifyConservation.setEnabled(false);
289 // PIDColour.setEnabled(false);
290 // abovePIDThreshold.setEnabled(false);
291 // modifyPID.setEnabled(false);
294 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
297 if (sortby.equals("Id"))
299 sortIDMenuItem_actionPerformed(null);
301 else if (sortby.equals("Pairwise Identity"))
303 sortPairwiseMenuItem_actionPerformed(null);
306 if (Desktop.desktop != null)
308 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
309 addServiceListeners();
310 setGUINucleotide(viewport.alignment.isNucleotide());
313 setMenusFromViewport(viewport);
314 buildSortByAnnotationScoresMenu();
315 if (viewport.wrapAlignment)
317 wrapMenuItem_actionPerformed(null);
320 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
322 this.overviewMenuItem_actionPerformed(null);
330 * Change the filename and format for the alignment, and enable the 'reload'
331 * button functionality.
338 public void setFileName(String file, String format)
341 currentFileFormat = format;
342 reload.setEnabled(true);
345 void addKeyListener()
347 addKeyListener(new KeyAdapter()
349 public void keyPressed(KeyEvent evt)
351 if (viewport.cursorMode
352 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
353 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
354 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
355 && Character.isDigit(evt.getKeyChar()))
356 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
358 switch (evt.getKeyCode())
361 case 27: // escape key
362 deselectAllSequenceMenuItem_actionPerformed(null);
366 case KeyEvent.VK_DOWN:
367 if (evt.isAltDown() || !viewport.cursorMode)
368 moveSelectedSequences(false);
369 if (viewport.cursorMode)
370 alignPanel.seqPanel.moveCursor(0, 1);
374 if (evt.isAltDown() || !viewport.cursorMode)
375 moveSelectedSequences(true);
376 if (viewport.cursorMode)
377 alignPanel.seqPanel.moveCursor(0, -1);
381 case KeyEvent.VK_LEFT:
382 if (evt.isAltDown() || !viewport.cursorMode)
383 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
385 alignPanel.seqPanel.moveCursor(-1, 0);
389 case KeyEvent.VK_RIGHT:
390 if (evt.isAltDown() || !viewport.cursorMode)
391 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
393 alignPanel.seqPanel.moveCursor(1, 0);
396 case KeyEvent.VK_SPACE:
397 if (viewport.cursorMode)
399 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
400 || evt.isShiftDown() || evt.isAltDown());
404 case KeyEvent.VK_DELETE:
405 case KeyEvent.VK_BACK_SPACE:
406 if (!viewport.cursorMode)
408 cut_actionPerformed(null);
412 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
413 || evt.isShiftDown() || evt.isAltDown());
419 if (viewport.cursorMode)
421 alignPanel.seqPanel.setCursorRow();
425 if (viewport.cursorMode && !evt.isControlDown())
427 alignPanel.seqPanel.setCursorColumn();
431 if (viewport.cursorMode)
433 alignPanel.seqPanel.setCursorPosition();
437 case KeyEvent.VK_ENTER:
438 case KeyEvent.VK_COMMA:
439 if (viewport.cursorMode)
441 alignPanel.seqPanel.setCursorRowAndColumn();
446 if (viewport.cursorMode)
448 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
452 if (viewport.cursorMode)
454 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
459 viewport.cursorMode = !viewport.cursorMode;
460 statusBar.setText("Keyboard editing mode is "
461 + (viewport.cursorMode ? "on" : "off"));
462 if (viewport.cursorMode)
464 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
465 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
467 alignPanel.seqPanel.seqCanvas.repaint();
473 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
474 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
476 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
478 javax.help.HelpBroker hb = hs.createHelpBroker();
479 hb.setCurrentID("home");
480 hb.setDisplayed(true);
481 } catch (Exception ex)
483 ex.printStackTrace();
488 boolean toggleSeqs = !evt.isControlDown();
489 boolean toggleCols = !evt.isShiftDown();
490 toggleHiddenRegions(toggleSeqs, toggleCols);
493 case KeyEvent.VK_PAGE_UP:
494 if (viewport.wrapAlignment)
496 alignPanel.scrollUp(true);
500 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
501 - viewport.endSeq + viewport.startSeq);
504 case KeyEvent.VK_PAGE_DOWN:
505 if (viewport.wrapAlignment)
507 alignPanel.scrollUp(false);
511 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
512 + viewport.endSeq - viewport.startSeq);
518 public void keyReleased(KeyEvent evt)
520 switch (evt.getKeyCode())
522 case KeyEvent.VK_LEFT:
523 if (evt.isAltDown() || !viewport.cursorMode)
524 viewport.firePropertyChange("alignment", null, viewport
525 .getAlignment().getSequences());
528 case KeyEvent.VK_RIGHT:
529 if (evt.isAltDown() || !viewport.cursorMode)
530 viewport.firePropertyChange("alignment", null, viewport
531 .getAlignment().getSequences());
538 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
540 ap.alignFrame = this;
542 alignPanels.addElement(ap);
544 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
546 int aSize = alignPanels.size();
548 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
550 if (aSize == 1 && ap.av.viewName == null)
552 this.getContentPane().add(ap, BorderLayout.CENTER);
558 setInitialTabVisible();
561 expandViews.setEnabled(true);
562 gatherViews.setEnabled(true);
563 tabbedPane.addTab(ap.av.viewName, ap);
565 ap.setVisible(false);
572 ap.av.alignment.padGaps();
574 ap.av.updateConservation(ap);
575 ap.av.updateConsensus(ap);
579 public void setInitialTabVisible()
581 expandViews.setEnabled(true);
582 gatherViews.setEnabled(true);
583 tabbedPane.setVisible(true);
584 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
585 tabbedPane.addTab(first.av.viewName, first);
586 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
589 public AlignViewport getViewport()
594 /* Set up intrinsic listeners for dynamically generated GUI bits. */
595 private void addServiceListeners()
597 final java.beans.PropertyChangeListener thisListener;
598 Desktop.instance.addJalviewPropertyChangeListener("services",
599 thisListener = new java.beans.PropertyChangeListener()
601 public void propertyChange(PropertyChangeEvent evt)
603 // // System.out.println("Discoverer property change.");
604 // if (evt.getPropertyName().equals("services"))
606 SwingUtilities.invokeLater(new Runnable()
612 .println("Rebuild WS Menu for service change");
613 BuildWebServiceMenu();
620 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
622 public void internalFrameClosed(
623 javax.swing.event.InternalFrameEvent evt)
625 System.out.println("deregistering discoverer listener");
626 Desktop.instance.removeJalviewPropertyChangeListener("services",
628 closeMenuItem_actionPerformed(true);
631 // Finally, build the menu once to get current service state
632 new Thread(new Runnable()
636 BuildWebServiceMenu();
641 public void setGUINucleotide(boolean nucleotide)
643 showTranslation.setVisible(nucleotide);
644 conservationMenuItem.setEnabled(!nucleotide);
645 modifyConservation.setEnabled(!nucleotide);
646 showGroupConservation.setEnabled(!nucleotide);
647 // Remember AlignFrame always starts as protein
650 calculateMenu.remove(calculateMenu.getItemCount() - 2);
655 * set up menus for the currently viewport. This may be called after any
656 * operation that affects the data in the current view (selection changed,
657 * etc) to update the menus to reflect the new state.
659 public void setMenusForViewport()
661 setMenusFromViewport(viewport);
665 * Need to call this method when tabs are selected for multiple views, or when
666 * loading from Jalview2XML.java
671 void setMenusFromViewport(AlignViewport av)
673 padGapsMenuitem.setSelected(av.padGaps);
674 colourTextMenuItem.setSelected(av.showColourText);
675 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
676 conservationMenuItem.setSelected(av.getConservationSelected());
677 seqLimits.setSelected(av.getShowJVSuffix());
678 idRightAlign.setSelected(av.rightAlignIds);
679 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
680 renderGapsMenuItem.setSelected(av.renderGaps);
681 wrapMenuItem.setSelected(av.wrapAlignment);
682 scaleAbove.setVisible(av.wrapAlignment);
683 scaleLeft.setVisible(av.wrapAlignment);
684 scaleRight.setVisible(av.wrapAlignment);
685 annotationPanelMenuItem.setState(av.showAnnotation);
686 viewBoxesMenuItem.setSelected(av.showBoxes);
687 viewTextMenuItem.setSelected(av.showText);
688 showNonconservedMenuItem.setSelected(av.showUnconserved);
689 showGroupConsensus.setSelected(av.showGroupConsensus);
690 showGroupConservation.setSelected(av.showGroupConservation);
691 showConsensusHistogram.setSelected(av.showConsensusHistogram);
692 showSequenceLogo.setSelected(av.showSequenceLogo);
693 setColourSelected(ColourSchemeProperty.getColourName(av
694 .getGlobalColourScheme()));
696 showSeqFeatures.setSelected(av.showSequenceFeatures);
697 hiddenMarkers.setState(av.showHiddenMarkers);
698 applyToAllGroups.setState(av.colourAppliesToAllGroups);
699 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
700 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
702 setShowProductsEnabled();
707 Hashtable progressBars, progressBarHandlers;
712 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
714 public void setProgressBar(String message, long id)
716 if (progressBars == null)
718 progressBars = new Hashtable();
719 progressBarHandlers = new Hashtable();
722 JPanel progressPanel;
723 Long lId = new Long(id);
724 GridLayout layout = (GridLayout) statusPanel.getLayout();
725 if (progressBars.get(lId) != null)
727 progressPanel = (JPanel) progressBars.get(new Long(id));
728 statusPanel.remove(progressPanel);
729 progressBars.remove(lId);
730 progressPanel = null;
733 statusBar.setText(message);
735 if (progressBarHandlers.contains(lId))
737 progressBarHandlers.remove(lId);
739 layout.setRows(layout.getRows() - 1);
743 progressPanel = new JPanel(new BorderLayout(10, 5));
745 JProgressBar progressBar = new JProgressBar();
746 progressBar.setIndeterminate(true);
748 progressPanel.add(new JLabel(message), BorderLayout.WEST);
749 progressPanel.add(progressBar, BorderLayout.CENTER);
751 layout.setRows(layout.getRows() + 1);
752 statusPanel.add(progressPanel);
754 progressBars.put(lId, progressPanel);
757 setMenusForViewport();
761 public void registerHandler(final long id,
762 final IProgressIndicatorHandler handler)
764 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
767 "call setProgressBar before registering the progress bar's handler.");
769 progressBarHandlers.put(new Long(id), handler);
770 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
771 if (handler.canCancel())
773 JButton cancel = new JButton("Cancel");
774 final IProgressIndicator us = this;
775 cancel.addActionListener(new ActionListener()
778 public void actionPerformed(ActionEvent e)
780 handler.cancelActivity(id);
783 + ((JLabel) progressPanel.getComponent(0))
787 progressPanel.add(cancel, BorderLayout.EAST);
793 * @return true if any progress bars are still active
795 public boolean operationInProgress()
797 if (progressBars != null && progressBars.size() > 0)
805 * Added so Castor Mapping file can obtain Jalview Version
807 public String getVersion()
809 return jalview.bin.Cache.getProperty("VERSION");
812 public FeatureRenderer getFeatureRenderer()
814 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
817 public void fetchSequence_actionPerformed(ActionEvent e)
819 new SequenceFetcher(this);
822 public void addFromFile_actionPerformed(ActionEvent e)
824 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
827 public void reload_actionPerformed(ActionEvent e)
829 if (fileName != null)
831 // TODO: work out how to recover feature settings for correct view(s) when
833 if (currentFileFormat.equals("Jalview"))
835 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
836 for (int i = 0; i < frames.length; i++)
838 if (frames[i] instanceof AlignFrame && frames[i] != this
839 && ((AlignFrame) frames[i]).fileName.equals(fileName))
843 frames[i].setSelected(true);
844 Desktop.instance.closeAssociatedWindows();
845 } catch (java.beans.PropertyVetoException ex)
851 Desktop.instance.closeAssociatedWindows();
853 FileLoader loader = new FileLoader();
854 String protocol = fileName.startsWith("http:") ? "URL" : "File";
855 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
859 Rectangle bounds = this.getBounds();
861 FileLoader loader = new FileLoader();
862 String protocol = fileName.startsWith("http:") ? "URL" : "File";
863 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
864 protocol, currentFileFormat);
866 newframe.setBounds(bounds);
867 if (featureSettings != null && featureSettings.isShowing())
869 final Rectangle fspos = featureSettings.frame.getBounds();
870 // TODO: need a 'show feature settings' function that takes bounds -
871 // need to refactor Desktop.addFrame
872 newframe.featureSettings_actionPerformed(null);
873 final FeatureSettings nfs = newframe.featureSettings;
874 SwingUtilities.invokeLater(new Runnable()
878 nfs.frame.setBounds(fspos);
881 this.featureSettings.close();
882 this.featureSettings = null;
884 this.closeMenuItem_actionPerformed(true);
889 public void addFromText_actionPerformed(ActionEvent e)
891 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
894 public void addFromURL_actionPerformed(ActionEvent e)
896 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
899 public void save_actionPerformed(ActionEvent e)
902 || (currentFileFormat == null || !jalview.io.FormatAdapter
903 .isValidIOFormat(currentFileFormat, true))
904 || fileName.startsWith("http"))
906 saveAs_actionPerformed(null);
910 saveAlignment(fileName, currentFileFormat);
920 public void saveAs_actionPerformed(ActionEvent e)
922 JalviewFileChooser chooser = new JalviewFileChooser(
923 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
924 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
925 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
926 currentFileFormat, false);
928 chooser.setFileView(new JalviewFileView());
929 chooser.setDialogTitle("Save Alignment to file");
930 chooser.setToolTipText("Save");
932 int value = chooser.showSaveDialog(this);
934 if (value == JalviewFileChooser.APPROVE_OPTION)
936 currentFileFormat = chooser.getSelectedFormat();
937 if (currentFileFormat == null)
939 JOptionPane.showInternalMessageDialog(Desktop.desktop,
940 "You must select a file format before saving!",
941 "File format not specified", JOptionPane.WARNING_MESSAGE);
942 value = chooser.showSaveDialog(this);
946 fileName = chooser.getSelectedFile().getPath();
948 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
951 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
952 if (currentFileFormat.indexOf(" ") > -1)
954 currentFileFormat = currentFileFormat.substring(0,
955 currentFileFormat.indexOf(" "));
957 saveAlignment(fileName, currentFileFormat);
961 public boolean saveAlignment(String file, String format)
963 boolean success = true;
965 if (format.equalsIgnoreCase("Jalview"))
967 String shortName = title;
969 if (shortName.indexOf(java.io.File.separatorChar) > -1)
971 shortName = shortName.substring(shortName
972 .lastIndexOf(java.io.File.separatorChar) + 1);
975 success = new Jalview2XML().SaveAlignment(this, file, shortName);
977 statusBar.setText("Successfully saved to file: " + fileName + " in "
978 + format + " format.");
983 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
985 warningMessage("Cannot save file " + fileName + " using format "
986 + format, "Alignment output format not supported");
987 saveAs_actionPerformed(null);
988 // JBPNote need to have a raise_gui flag here
992 String[] omitHidden = null;
994 if (viewport.hasHiddenColumns)
996 int reply = JOptionPane
997 .showInternalConfirmDialog(
999 "The Alignment contains hidden columns."
1000 + "\nDo you want to save only the visible alignment?",
1001 "Save / Omit Hidden Columns",
1002 JOptionPane.YES_NO_OPTION,
1003 JOptionPane.QUESTION_MESSAGE);
1005 if (reply == JOptionPane.YES_OPTION)
1007 omitHidden = viewport.getViewAsString(false);
1010 FormatAdapter f = new FormatAdapter();
1011 String output = f.formatSequences(format,
1012 (Alignment) viewport.alignment, // class cast exceptions will
1013 // occur in the distant future
1014 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
1024 java.io.PrintWriter out = new java.io.PrintWriter(
1025 new java.io.FileWriter(file));
1029 this.setTitle(file);
1030 statusBar.setText("Successfully saved to file: " + fileName
1031 + " in " + format + " format.");
1032 } catch (Exception ex)
1035 ex.printStackTrace();
1042 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1043 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1049 private void warningMessage(String warning, String title)
1051 if (new jalview.util.Platform().isHeadless())
1053 System.err.println("Warning: " + title + "\nWarning: " + warning);
1058 JOptionPane.showInternalMessageDialog(this, warning, title,
1059 JOptionPane.WARNING_MESSAGE);
1070 protected void outputText_actionPerformed(ActionEvent e)
1072 String[] omitHidden = null;
1074 if (viewport.hasHiddenColumns)
1076 int reply = JOptionPane
1077 .showInternalConfirmDialog(
1079 "The Alignment contains hidden columns."
1080 + "\nDo you want to output only the visible alignment?",
1081 "Save / Omit Hidden Columns",
1082 JOptionPane.YES_NO_OPTION,
1083 JOptionPane.QUESTION_MESSAGE);
1085 if (reply == JOptionPane.YES_OPTION)
1087 omitHidden = viewport.getViewAsString(false);
1091 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1092 cap.setForInput(null);
1096 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1097 viewport.alignment, omitHidden, viewport.colSel));
1098 Desktop.addInternalFrame(cap,
1099 "Alignment output - " + e.getActionCommand(), 600, 500);
1100 } catch (OutOfMemoryError oom)
1102 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1114 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1116 new HTMLOutput(alignPanel,
1117 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1118 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1121 public void createImageMap(File file, String image)
1123 alignPanel.makePNGImageMap(file, image);
1132 public void createPNG(File f)
1134 alignPanel.makePNG(f);
1143 public void createEPS(File f)
1145 alignPanel.makeEPS(f);
1148 public void pageSetup_actionPerformed(ActionEvent e)
1150 PrinterJob printJob = PrinterJob.getPrinterJob();
1151 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1160 public void printMenuItem_actionPerformed(ActionEvent e)
1162 // Putting in a thread avoids Swing painting problems
1163 PrintThread thread = new PrintThread(alignPanel);
1167 public void exportFeatures_actionPerformed(ActionEvent e)
1169 new AnnotationExporter().exportFeatures(alignPanel);
1172 public void exportAnnotations_actionPerformed(ActionEvent e)
1174 new AnnotationExporter().exportAnnotations(
1176 viewport.showAnnotation ? viewport.alignment
1177 .getAlignmentAnnotation() : null, viewport.alignment
1179 ((Alignment) viewport.alignment).alignmentProperties);
1182 public void associatedData_actionPerformed(ActionEvent e)
1184 // Pick the tree file
1185 JalviewFileChooser chooser = new JalviewFileChooser(
1186 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1187 chooser.setFileView(new JalviewFileView());
1188 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1189 chooser.setToolTipText("Load Jalview Annotations / Features file");
1191 int value = chooser.showOpenDialog(null);
1193 if (value == JalviewFileChooser.APPROVE_OPTION)
1195 String choice = chooser.getSelectedFile().getPath();
1196 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1197 loadJalviewDataFile(choice, null, null, null);
1203 * Close the current view or all views in the alignment frame. If the frame
1204 * only contains one view then the alignment will be removed from memory.
1206 * @param closeAllTabs
1208 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1210 if (alignPanels != null && alignPanels.size() < 2)
1212 closeAllTabs = true;
1217 if (alignPanels != null)
1221 if (this.isClosed())
1223 // really close all the windows - otherwise wait till
1224 // setClosed(true) is called
1225 for (int i = 0; i < alignPanels.size(); i++)
1227 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1234 closeView(alignPanel);
1240 this.setClosed(true);
1242 } catch (Exception ex)
1244 ex.printStackTrace();
1249 * close alignPanel2 and shuffle tabs appropriately.
1251 * @param alignPanel2
1253 public void closeView(AlignmentPanel alignPanel2)
1255 int index = tabbedPane.getSelectedIndex();
1256 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1257 alignPanels.removeElement(alignPanel2);
1259 // if (viewport == alignPanel2.av)
1263 alignPanel2.closePanel();
1266 tabbedPane.removeTabAt(closedindex);
1267 tabbedPane.validate();
1269 if (index > closedindex || index == tabbedPane.getTabCount())
1271 // modify currently selected tab index if necessary.
1275 this.tabSelectionChanged(index);
1281 void updateEditMenuBar()
1284 if (viewport.historyList.size() > 0)
1286 undoMenuItem.setEnabled(true);
1287 CommandI command = (CommandI) viewport.historyList.peek();
1288 undoMenuItem.setText("Undo " + command.getDescription());
1292 undoMenuItem.setEnabled(false);
1293 undoMenuItem.setText("Undo");
1296 if (viewport.redoList.size() > 0)
1298 redoMenuItem.setEnabled(true);
1300 CommandI command = (CommandI) viewport.redoList.peek();
1301 redoMenuItem.setText("Redo " + command.getDescription());
1305 redoMenuItem.setEnabled(false);
1306 redoMenuItem.setText("Redo");
1310 public void addHistoryItem(CommandI command)
1312 if (command.getSize() > 0)
1314 viewport.historyList.push(command);
1315 viewport.redoList.clear();
1316 updateEditMenuBar();
1317 viewport.hasHiddenColumns = (viewport.colSel != null
1318 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1319 .getHiddenColumns().size() > 0);
1325 * @return alignment objects for all views
1327 AlignmentI[] getViewAlignments()
1329 if (alignPanels != null)
1331 Enumeration e = alignPanels.elements();
1332 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1333 for (int i = 0; e.hasMoreElements(); i++)
1335 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1339 if (viewport != null)
1341 return new AlignmentI[]
1342 { viewport.alignment };
1353 protected void undoMenuItem_actionPerformed(ActionEvent e)
1355 if (viewport.historyList.empty())
1357 CommandI command = (CommandI) viewport.historyList.pop();
1358 viewport.redoList.push(command);
1359 command.undoCommand(getViewAlignments());
1361 AlignViewport originalSource = getOriginatingSource(command);
1362 updateEditMenuBar();
1364 if (originalSource != null)
1366 originalSource.hasHiddenColumns = (viewport.colSel != null
1367 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1368 .getHiddenColumns().size() > 0);
1369 originalSource.firePropertyChange("alignment", null,
1370 originalSource.alignment.getSequences());
1380 protected void redoMenuItem_actionPerformed(ActionEvent e)
1382 if (viewport.redoList.size() < 1)
1387 CommandI command = (CommandI) viewport.redoList.pop();
1388 viewport.historyList.push(command);
1389 command.doCommand(getViewAlignments());
1391 AlignViewport originalSource = getOriginatingSource(command);
1392 updateEditMenuBar();
1394 if (originalSource != null)
1396 originalSource.hasHiddenColumns = (viewport.colSel != null
1397 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1398 .getHiddenColumns().size() > 0);
1399 originalSource.firePropertyChange("alignment", null,
1400 originalSource.alignment.getSequences());
1404 AlignViewport getOriginatingSource(CommandI command)
1406 AlignViewport originalSource = null;
1407 // For sequence removal and addition, we need to fire
1408 // the property change event FROM the viewport where the
1409 // original alignment was altered
1410 AlignmentI al = null;
1411 if (command instanceof EditCommand)
1413 EditCommand editCommand = (EditCommand) command;
1414 al = editCommand.getAlignment();
1415 Vector comps = (Vector) PaintRefresher.components.get(viewport
1416 .getSequenceSetId());
1418 for (int i = 0; i < comps.size(); i++)
1420 if (comps.elementAt(i) instanceof AlignmentPanel)
1422 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1424 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1431 if (originalSource == null)
1433 // The original view is closed, we must validate
1434 // the current view against the closed view first
1437 PaintRefresher.validateSequences(al, viewport.alignment);
1440 originalSource = viewport;
1443 return originalSource;
1452 public void moveSelectedSequences(boolean up)
1454 SequenceGroup sg = viewport.getSelectionGroup();
1463 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1465 SequenceI seq = viewport.alignment.getSequenceAt(i);
1467 if (!sg.getSequences(null).contains(seq))
1472 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1474 if (sg.getSequences(null).contains(temp))
1479 viewport.alignment.getSequences().setElementAt(temp, i);
1480 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1485 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1487 SequenceI seq = viewport.alignment.getSequenceAt(i);
1489 if (!sg.getSequences(null).contains(seq))
1494 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1496 if (sg.getSequences(null).contains(temp))
1501 viewport.alignment.getSequences().setElementAt(temp, i);
1502 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1506 alignPanel.paintAlignment(true);
1509 synchronized void slideSequences(boolean right, int size)
1511 Vector sg = new Vector();
1512 if (viewport.cursorMode)
1514 sg.addElement(viewport.alignment
1515 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1517 else if (viewport.getSelectionGroup() != null
1518 && viewport.getSelectionGroup().getSize() != viewport.alignment
1521 sg = viewport.getSelectionGroup().getSequences(
1522 viewport.hiddenRepSequences);
1530 Vector invertGroup = new Vector();
1532 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1534 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1535 invertGroup.add(viewport.alignment.getSequenceAt(i));
1538 SequenceI[] seqs1 = new SequenceI[sg.size()];
1539 for (int i = 0; i < sg.size(); i++)
1540 seqs1[i] = (SequenceI) sg.elementAt(i);
1542 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1543 for (int i = 0; i < invertGroup.size(); i++)
1544 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1546 SlideSequencesCommand ssc;
1548 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1549 size, viewport.getGapCharacter());
1551 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1552 size, viewport.getGapCharacter());
1554 int groupAdjustment = 0;
1555 if (ssc.getGapsInsertedBegin() && right)
1557 if (viewport.cursorMode)
1558 alignPanel.seqPanel.moveCursor(size, 0);
1560 groupAdjustment = size;
1562 else if (!ssc.getGapsInsertedBegin() && !right)
1564 if (viewport.cursorMode)
1565 alignPanel.seqPanel.moveCursor(-size, 0);
1567 groupAdjustment = -size;
1570 if (groupAdjustment != 0)
1572 viewport.getSelectionGroup().setStartRes(
1573 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1574 viewport.getSelectionGroup().setEndRes(
1575 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1578 boolean appendHistoryItem = false;
1579 if (viewport.historyList != null && viewport.historyList.size() > 0
1580 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1582 appendHistoryItem = ssc
1583 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1587 if (!appendHistoryItem)
1588 addHistoryItem(ssc);
1599 protected void copy_actionPerformed(ActionEvent e)
1602 if (viewport.getSelectionGroup() == null)
1606 // TODO: preserve the ordering of displayed alignment annotation in any
1607 // internal paste (particularly sequence associated annotation)
1608 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1609 String[] omitHidden = null;
1611 if (viewport.hasHiddenColumns)
1613 omitHidden = viewport.getViewAsString(true);
1616 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1619 StringSelection ss = new StringSelection(output);
1623 jalview.gui.Desktop.internalCopy = true;
1624 // Its really worth setting the clipboard contents
1625 // to empty before setting the large StringSelection!!
1626 Toolkit.getDefaultToolkit().getSystemClipboard()
1627 .setContents(new StringSelection(""), null);
1629 Toolkit.getDefaultToolkit().getSystemClipboard()
1630 .setContents(ss, Desktop.instance);
1631 } catch (OutOfMemoryError er)
1633 new OOMWarning("copying region", er);
1637 Vector hiddenColumns = null;
1638 if (viewport.hasHiddenColumns)
1640 hiddenColumns = new Vector();
1641 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1642 .getSelectionGroup().getEndRes();
1643 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1646 int[] region = (int[]) viewport.getColumnSelection()
1647 .getHiddenColumns().elementAt(i);
1648 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1650 hiddenColumns.addElement(new int[]
1651 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1656 Desktop.jalviewClipboard = new Object[]
1657 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1658 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1667 protected void pasteNew_actionPerformed(ActionEvent e)
1678 protected void pasteThis_actionPerformed(ActionEvent e)
1684 * Paste contents of Jalview clipboard
1686 * @param newAlignment
1687 * true to paste to a new alignment, otherwise add to this.
1689 void paste(boolean newAlignment)
1691 boolean externalPaste = true;
1694 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1695 Transferable contents = c.getContents(this);
1697 if (contents == null)
1705 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1706 if (str.length() < 1)
1711 format = new IdentifyFile().Identify(str, "Paste");
1713 } catch (OutOfMemoryError er)
1715 new OOMWarning("Out of memory pasting sequences!!", er);
1719 SequenceI[] sequences;
1720 boolean annotationAdded = false;
1721 AlignmentI alignment = null;
1723 if (Desktop.jalviewClipboard != null)
1725 // The clipboard was filled from within Jalview, we must use the
1727 // And dataset from the copied alignment
1728 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1729 // be doubly sure that we create *new* sequence objects.
1730 sequences = new SequenceI[newseq.length];
1731 for (int i = 0; i < newseq.length; i++)
1733 sequences[i] = new Sequence(newseq[i]);
1735 alignment = new Alignment(sequences);
1736 externalPaste = false;
1740 // parse the clipboard as an alignment.
1741 alignment = new FormatAdapter().readFile(str, "Paste", format);
1742 sequences = alignment.getSequencesArray();
1750 if (Desktop.jalviewClipboard != null)
1752 // dataset is inherited
1753 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1757 // new dataset is constructed
1758 alignment.setDataset(null);
1760 alwidth = alignment.getWidth() + 1;
1764 AlignmentI pastedal = alignment; // preserve pasted alignment object
1765 // Add pasted sequences and dataset into existing alignment.
1766 alignment = viewport.getAlignment();
1767 alwidth = alignment.getWidth() + 1;
1768 // decide if we need to import sequences from an existing dataset
1769 boolean importDs = Desktop.jalviewClipboard != null
1770 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1771 // importDs==true instructs us to copy over new dataset sequences from
1772 // an existing alignment
1773 Vector newDs = (importDs) ? new Vector() : null; // used to create
1774 // minimum dataset set
1776 for (int i = 0; i < sequences.length; i++)
1780 newDs.addElement(null);
1782 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1784 if (importDs && ds != null)
1786 if (!newDs.contains(ds))
1788 newDs.setElementAt(ds, i);
1789 ds = new Sequence(ds);
1790 // update with new dataset sequence
1791 sequences[i].setDatasetSequence(ds);
1795 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1800 // copy and derive new dataset sequence
1801 sequences[i] = sequences[i].deriveSequence();
1802 alignment.getDataset().addSequence(
1803 sequences[i].getDatasetSequence());
1804 // TODO: avoid creation of duplicate dataset sequences with a
1805 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1807 alignment.addSequence(sequences[i]); // merges dataset
1811 newDs.clear(); // tidy up
1813 if (pastedal.getAlignmentAnnotation() != null)
1815 // Add any annotation attached to alignment.
1816 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1817 for (int i = 0; i < alann.length; i++)
1819 annotationAdded = true;
1820 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1822 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1823 newann.padAnnotation(alwidth);
1824 alignment.addAnnotation(newann);
1834 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1835 sequences, 0, alignment.getWidth(), alignment));
1837 // Add any annotations attached to sequences
1838 for (int i = 0; i < sequences.length; i++)
1840 if (sequences[i].getAnnotation() != null)
1842 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1844 annotationAdded = true;
1845 sequences[i].getAnnotation()[a].adjustForAlignment();
1846 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1847 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1852 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1859 // propagate alignment changed.
1860 viewport.setEndSeq(alignment.getHeight());
1861 if (annotationAdded)
1863 // Duplicate sequence annotation in all views.
1864 AlignmentI[] alview = this.getViewAlignments();
1865 for (int i = 0; i < sequences.length; i++)
1867 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1870 for (int avnum = 0; avnum < alview.length; avnum++)
1872 if (alview[avnum] != alignment)
1874 // duplicate in a view other than the one with input focus
1875 int avwidth = alview[avnum].getWidth() + 1;
1876 // this relies on sann being preserved after we
1877 // modify the sequence's annotation array for each duplication
1878 for (int a = 0; a < sann.length; a++)
1880 AlignmentAnnotation newann = new AlignmentAnnotation(
1882 sequences[i].addAlignmentAnnotation(newann);
1883 newann.padAnnotation(avwidth);
1884 alview[avnum].addAnnotation(newann); // annotation was
1885 // duplicated earlier
1886 alview[avnum].setAnnotationIndex(newann, a);
1891 buildSortByAnnotationScoresMenu();
1893 viewport.firePropertyChange("alignment", null,
1894 alignment.getSequences());
1899 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1901 String newtitle = new String("Copied sequences");
1903 if (Desktop.jalviewClipboard != null
1904 && Desktop.jalviewClipboard[2] != null)
1906 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1907 for (int i = 0; i < hc.size(); i++)
1909 int[] region = (int[]) hc.elementAt(i);
1910 af.viewport.hideColumns(region[0], region[1]);
1914 // >>>This is a fix for the moment, until a better solution is
1916 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1918 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1920 // TODO: maintain provenance of an alignment, rather than just make the
1921 // title a concatenation of operations.
1924 if (title.startsWith("Copied sequences"))
1930 newtitle = newtitle.concat("- from " + title);
1935 newtitle = new String("Pasted sequences");
1938 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1943 } catch (Exception ex)
1945 ex.printStackTrace();
1946 System.out.println("Exception whilst pasting: " + ex);
1947 // could be anything being pasted in here
1958 protected void cut_actionPerformed(ActionEvent e)
1960 copy_actionPerformed(null);
1961 delete_actionPerformed(null);
1970 protected void delete_actionPerformed(ActionEvent evt)
1973 SequenceGroup sg = viewport.getSelectionGroup();
1979 Vector seqs = new Vector();
1981 for (int i = 0; i < sg.getSize(); i++)
1983 seq = sg.getSequenceAt(i);
1984 seqs.addElement(seq);
1987 // If the cut affects all sequences, remove highlighted columns
1988 if (sg.getSize() == viewport.alignment.getHeight())
1990 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1991 sg.getEndRes() + 1);
1994 SequenceI[] cut = new SequenceI[seqs.size()];
1995 for (int i = 0; i < seqs.size(); i++)
1997 cut[i] = (SequenceI) seqs.elementAt(i);
2001 * //ADD HISTORY ITEM
2003 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2004 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2005 viewport.alignment));
2007 viewport.setSelectionGroup(null);
2008 viewport.sendSelection();
2009 viewport.alignment.deleteGroup(sg);
2011 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2013 if (viewport.getAlignment().getHeight() < 1)
2017 this.setClosed(true);
2018 } catch (Exception ex)
2030 protected void deleteGroups_actionPerformed(ActionEvent e)
2032 viewport.alignment.deleteAllGroups();
2033 viewport.sequenceColours = null;
2034 viewport.setSelectionGroup(null);
2035 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2036 alignPanel.updateAnnotation();
2037 alignPanel.paintAlignment(true);
2046 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2048 SequenceGroup sg = new SequenceGroup();
2050 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2052 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2055 sg.setEndRes(viewport.alignment.getWidth() - 1);
2056 viewport.setSelectionGroup(sg);
2057 viewport.sendSelection();
2058 alignPanel.paintAlignment(true);
2059 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2068 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2070 if (viewport.cursorMode)
2072 alignPanel.seqPanel.keyboardNo1 = null;
2073 alignPanel.seqPanel.keyboardNo2 = null;
2075 viewport.setSelectionGroup(null);
2076 viewport.getColumnSelection().clear();
2077 viewport.setSelectionGroup(null);
2078 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2079 alignPanel.idPanel.idCanvas.searchResults = null;
2080 alignPanel.paintAlignment(true);
2081 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2090 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2092 SequenceGroup sg = viewport.getSelectionGroup();
2096 selectAllSequenceMenuItem_actionPerformed(null);
2101 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2103 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2106 alignPanel.paintAlignment(true);
2107 viewport.sendSelection();
2108 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2111 public void invertColSel_actionPerformed(ActionEvent e)
2113 viewport.invertColumnSelection();
2114 alignPanel.paintAlignment(true);
2123 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2125 trimAlignment(true);
2134 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2136 trimAlignment(false);
2139 void trimAlignment(boolean trimLeft)
2141 ColumnSelection colSel = viewport.getColumnSelection();
2144 if (colSel.size() > 0)
2148 column = colSel.getMin();
2152 column = colSel.getMax();
2156 if (viewport.getSelectionGroup() != null)
2158 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2159 viewport.hiddenRepSequences);
2163 seqs = viewport.alignment.getSequencesArray();
2166 TrimRegionCommand trimRegion;
2169 trimRegion = new TrimRegionCommand("Remove Left",
2170 TrimRegionCommand.TRIM_LEFT, seqs, column,
2171 viewport.alignment, viewport.colSel,
2172 viewport.selectionGroup);
2173 viewport.setStartRes(0);
2177 trimRegion = new TrimRegionCommand("Remove Right",
2178 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2179 viewport.alignment, viewport.colSel,
2180 viewport.selectionGroup);
2183 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2185 addHistoryItem(trimRegion);
2187 Vector groups = viewport.alignment.getGroups();
2189 for (int i = 0; i < groups.size(); i++)
2191 SequenceGroup sg = (SequenceGroup) groups.get(i);
2193 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2194 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2196 viewport.alignment.deleteGroup(sg);
2200 viewport.firePropertyChange("alignment", null, viewport
2201 .getAlignment().getSequences());
2211 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2213 int start = 0, end = viewport.alignment.getWidth() - 1;
2216 if (viewport.getSelectionGroup() != null)
2218 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2219 viewport.hiddenRepSequences);
2220 start = viewport.getSelectionGroup().getStartRes();
2221 end = viewport.getSelectionGroup().getEndRes();
2225 seqs = viewport.alignment.getSequencesArray();
2228 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2229 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2231 addHistoryItem(removeGapCols);
2233 statusBar.setText("Removed " + removeGapCols.getSize()
2234 + " empty columns.");
2236 // This is to maintain viewport position on first residue
2237 // of first sequence
2238 SequenceI seq = viewport.alignment.getSequenceAt(0);
2239 int startRes = seq.findPosition(viewport.startRes);
2240 // ShiftList shifts;
2241 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2242 // edit.alColumnChanges=shifts.getInverse();
2243 // if (viewport.hasHiddenColumns)
2244 // viewport.getColumnSelection().compensateForEdits(shifts);
2245 viewport.setStartRes(seq.findIndex(startRes) - 1);
2246 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2257 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2259 int start = 0, end = viewport.alignment.getWidth() - 1;
2262 if (viewport.getSelectionGroup() != null)
2264 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2265 viewport.hiddenRepSequences);
2266 start = viewport.getSelectionGroup().getStartRes();
2267 end = viewport.getSelectionGroup().getEndRes();
2271 seqs = viewport.alignment.getSequencesArray();
2274 // This is to maintain viewport position on first residue
2275 // of first sequence
2276 SequenceI seq = viewport.alignment.getSequenceAt(0);
2277 int startRes = seq.findPosition(viewport.startRes);
2279 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2280 viewport.alignment));
2282 viewport.setStartRes(seq.findIndex(startRes) - 1);
2284 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2295 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2297 viewport.padGaps = padGapsMenuitem.isSelected();
2298 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2304 // if (justifySeqs>0)
2306 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2318 public void findMenuItem_actionPerformed(ActionEvent e)
2323 public void newView_actionPerformed(ActionEvent e)
2330 * @param copyAnnotation
2331 * if true then duplicate all annnotation, groups and settings
2332 * @return new alignment panel, already displayed.
2334 public AlignmentPanel newView(boolean copyAnnotation)
2336 return newView(null, copyAnnotation);
2342 * title of newly created view
2343 * @return new alignment panel, already displayed.
2345 public AlignmentPanel newView(String viewTitle)
2347 return newView(viewTitle, true);
2353 * title of newly created view
2354 * @param copyAnnotation
2355 * if true then duplicate all annnotation, groups and settings
2356 * @return new alignment panel, already displayed.
2358 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2360 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2362 if (!copyAnnotation)
2364 // just remove all the current annotation except for the automatic stuff
2365 newap.av.alignment.deleteAllGroups();
2366 for (AlignmentAnnotation alan : newap.av.alignment
2367 .getAlignmentAnnotation())
2369 if (!alan.autoCalculated)
2371 newap.av.alignment.deleteAnnotation(alan);
2377 newap.av.gatherViewsHere = false;
2379 if (viewport.viewName == null)
2381 viewport.viewName = "Original";
2384 newap.av.historyList = viewport.historyList;
2385 newap.av.redoList = viewport.redoList;
2387 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2388 // make sure the new view has a unique name - this is essential for Jalview
2390 boolean addFirstIndex = false;
2391 if (viewTitle == null || viewTitle.trim().length() == 0)
2394 addFirstIndex = true;
2398 index = 1;// we count from 1 if given a specific name
2400 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2401 Vector comps = (Vector) PaintRefresher.components.get(viewport
2402 .getSequenceSetId());
2403 Vector existingNames = new Vector();
2404 for (int i = 0; i < comps.size(); i++)
2406 if (comps.elementAt(i) instanceof AlignmentPanel)
2408 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2409 if (!existingNames.contains(ap.av.viewName))
2411 existingNames.addElement(ap.av.viewName);
2416 while (existingNames.contains(newViewName))
2418 newViewName = viewTitle + " " + (++index);
2421 newap.av.viewName = newViewName;
2423 addAlignmentPanel(newap, true);
2425 if (alignPanels.size() == 2)
2427 viewport.gatherViewsHere = true;
2429 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2433 public void expandViews_actionPerformed(ActionEvent e)
2435 Desktop.instance.explodeViews(this);
2438 public void gatherViews_actionPerformed(ActionEvent e)
2440 Desktop.instance.gatherViews(this);
2449 public void font_actionPerformed(ActionEvent e)
2451 new FontChooser(alignPanel);
2460 protected void seqLimit_actionPerformed(ActionEvent e)
2462 viewport.setShowJVSuffix(seqLimits.isSelected());
2464 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2465 .calculateIdWidth());
2466 alignPanel.paintAlignment(true);
2469 public void idRightAlign_actionPerformed(ActionEvent e)
2471 viewport.rightAlignIds = idRightAlign.isSelected();
2472 alignPanel.paintAlignment(true);
2475 public void centreColumnLabels_actionPerformed(ActionEvent e)
2477 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2478 alignPanel.paintAlignment(true);
2484 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2486 protected void followHighlight_actionPerformed()
2488 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2490 alignPanel.scrollToPosition(
2491 alignPanel.seqPanel.seqCanvas.searchResults, false);
2501 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2503 viewport.setColourText(colourTextMenuItem.isSelected());
2504 alignPanel.paintAlignment(true);
2513 public void wrapMenuItem_actionPerformed(ActionEvent e)
2515 scaleAbove.setVisible(wrapMenuItem.isSelected());
2516 scaleLeft.setVisible(wrapMenuItem.isSelected());
2517 scaleRight.setVisible(wrapMenuItem.isSelected());
2518 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2519 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2522 public void showAllSeqs_actionPerformed(ActionEvent e)
2524 viewport.showAllHiddenSeqs();
2527 public void showAllColumns_actionPerformed(ActionEvent e)
2529 viewport.showAllHiddenColumns();
2533 public void hideSelSequences_actionPerformed(ActionEvent e)
2535 viewport.hideAllSelectedSeqs();
2536 alignPanel.paintAlignment(true);
2540 * called by key handler and the hide all/show all menu items
2545 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2548 boolean hide = false;
2549 SequenceGroup sg = viewport.getSelectionGroup();
2550 if (!toggleSeqs && !toggleCols)
2552 // Hide everything by the current selection - this is a hack - we do the
2553 // invert and then hide
2554 // first check that there will be visible columns after the invert.
2555 if ((viewport.colSel != null && viewport.colSel.getSelected() != null && viewport.colSel
2556 .getSelected().size() > 0)
2557 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2560 // now invert the sequence set, if required - empty selection implies
2561 // that no hiding is required.
2564 invertSequenceMenuItem_actionPerformed(null);
2565 sg = viewport.getSelectionGroup();
2569 viewport.expandColSelection(sg, true);
2570 // finally invert the column selection and get the new sequence
2572 invertColSel_actionPerformed(null);
2579 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
2581 hideSelSequences_actionPerformed(null);
2584 else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))
2586 showAllSeqs_actionPerformed(null);
2592 if (viewport.colSel.getSelected().size() > 0)
2594 hideSelColumns_actionPerformed(null);
2597 viewport.selectionGroup = sg;
2602 showAllColumns_actionPerformed(null);
2611 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2612 * event.ActionEvent)
2614 public void hideAllButSelection_actionPerformed(ActionEvent e)
2616 toggleHiddenRegions(false, false);
2623 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2626 public void hideAllSelection_actionPerformed(ActionEvent e)
2628 SequenceGroup sg = viewport.getSelectionGroup();
2629 viewport.expandColSelection(sg, false);
2630 viewport.hideAllSelectedSeqs();
2631 viewport.hideSelectedColumns();
2632 alignPanel.paintAlignment(true);
2639 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2642 public void showAllhidden_actionPerformed(ActionEvent e)
2644 viewport.showAllHiddenColumns();
2645 viewport.showAllHiddenSeqs();
2646 alignPanel.paintAlignment(true);
2649 public void hideSelColumns_actionPerformed(ActionEvent e)
2651 viewport.hideSelectedColumns();
2652 alignPanel.paintAlignment(true);
2655 public void hiddenMarkers_actionPerformed(ActionEvent e)
2657 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2667 protected void scaleAbove_actionPerformed(ActionEvent e)
2669 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2670 alignPanel.paintAlignment(true);
2679 protected void scaleLeft_actionPerformed(ActionEvent e)
2681 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2682 alignPanel.paintAlignment(true);
2691 protected void scaleRight_actionPerformed(ActionEvent e)
2693 viewport.setScaleRightWrapped(scaleRight.isSelected());
2694 alignPanel.paintAlignment(true);
2703 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2705 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2706 alignPanel.paintAlignment(true);
2715 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2717 viewport.setShowText(viewTextMenuItem.isSelected());
2718 alignPanel.paintAlignment(true);
2727 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2729 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2730 alignPanel.paintAlignment(true);
2733 public FeatureSettings featureSettings;
2735 public void featureSettings_actionPerformed(ActionEvent e)
2737 if (featureSettings != null)
2739 featureSettings.close();
2740 featureSettings = null;
2742 if (!showSeqFeatures.isSelected())
2744 // make sure features are actually displayed
2745 showSeqFeatures.setSelected(true);
2746 showSeqFeatures_actionPerformed(null);
2748 featureSettings = new FeatureSettings(this);
2752 * Set or clear 'Show Sequence Features'
2757 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2759 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2760 alignPanel.paintAlignment(true);
2761 if (alignPanel.getOverviewPanel() != null)
2763 alignPanel.getOverviewPanel().updateOverviewImage();
2768 * Set or clear 'Show Sequence Features'
2773 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2775 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2777 if (viewport.getShowSequenceFeaturesHeight())
2779 // ensure we're actually displaying features
2780 viewport.setShowSequenceFeatures(true);
2781 showSeqFeatures.setSelected(true);
2783 alignPanel.paintAlignment(true);
2784 if (alignPanel.getOverviewPanel() != null)
2786 alignPanel.getOverviewPanel().updateOverviewImage();
2796 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2798 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2799 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2802 public void alignmentProperties()
2804 JEditorPane editPane = new JEditorPane("text/html", "");
2805 editPane.setEditable(false);
2806 StringBuffer contents = new AlignmentProperties(viewport.alignment)
2808 editPane.setText("<html>" + contents.toString() + "</html>");
2809 JInternalFrame frame = new JInternalFrame();
2810 frame.getContentPane().add(new JScrollPane(editPane));
2812 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2813 + getTitle(), 500, 400);
2822 public void overviewMenuItem_actionPerformed(ActionEvent e)
2824 if (alignPanel.overviewPanel != null)
2829 JInternalFrame frame = new JInternalFrame();
2830 OverviewPanel overview = new OverviewPanel(alignPanel);
2831 frame.setContentPane(overview);
2832 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2833 frame.getWidth(), frame.getHeight());
2835 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2836 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2838 public void internalFrameClosed(
2839 javax.swing.event.InternalFrameEvent evt)
2841 alignPanel.setOverviewPanel(null);
2845 alignPanel.setOverviewPanel(overview);
2848 public void textColour_actionPerformed(ActionEvent e)
2850 new TextColourChooser().chooseColour(alignPanel, null);
2859 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2870 public void clustalColour_actionPerformed(ActionEvent e)
2872 changeColour(new ClustalxColourScheme(
2873 viewport.alignment.getSequences(),
2874 viewport.alignment.getWidth()));
2883 public void zappoColour_actionPerformed(ActionEvent e)
2885 changeColour(new ZappoColourScheme());
2894 public void taylorColour_actionPerformed(ActionEvent e)
2896 changeColour(new TaylorColourScheme());
2905 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2907 changeColour(new HydrophobicColourScheme());
2916 public void helixColour_actionPerformed(ActionEvent e)
2918 changeColour(new HelixColourScheme());
2927 public void strandColour_actionPerformed(ActionEvent e)
2929 changeColour(new StrandColourScheme());
2938 public void turnColour_actionPerformed(ActionEvent e)
2940 changeColour(new TurnColourScheme());
2949 public void buriedColour_actionPerformed(ActionEvent e)
2951 changeColour(new BuriedColourScheme());
2960 public void nucleotideColour_actionPerformed(ActionEvent e)
2962 changeColour(new NucleotideColourScheme());
2965 public void annotationColour_actionPerformed(ActionEvent e)
2967 new AnnotationColourChooser(viewport, alignPanel);
2976 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2978 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2987 public void changeColour(ColourSchemeI cs)
2993 if (viewport.getAbovePIDThreshold())
2995 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2998 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3000 viewport.setGlobalColourScheme(cs);
3004 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3007 if (viewport.getConservationSelected())
3010 Alignment al = (Alignment) viewport.alignment;
3011 Conservation c = new Conservation("All",
3012 ResidueProperties.propHash, 3, al.getSequences(), 0,
3016 c.verdict(false, viewport.ConsPercGaps);
3018 cs.setConservation(c);
3020 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3025 cs.setConservation(null);
3028 cs.setConsensus(viewport.hconsensus);
3031 viewport.setGlobalColourScheme(cs);
3033 if (viewport.getColourAppliesToAllGroups())
3035 Vector groups = viewport.alignment.getGroups();
3037 for (int i = 0; i < groups.size(); i++)
3039 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
3047 if (cs instanceof ClustalxColourScheme)
3049 sg.cs = new ClustalxColourScheme(
3050 sg.getSequences(viewport.hiddenRepSequences),
3053 else if (cs instanceof UserColourScheme)
3055 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3061 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
3062 } catch (Exception ex)
3067 if (viewport.getAbovePIDThreshold()
3068 || cs instanceof PIDColourScheme
3069 || cs instanceof Blosum62ColourScheme)
3071 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3073 sg.cs.setConsensus(AAFrequency.calculate(
3074 sg.getSequences(viewport.hiddenRepSequences),
3075 sg.getStartRes(), sg.getEndRes() + 1));
3079 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3082 if (viewport.getConservationSelected())
3084 Conservation c = new Conservation("Group",
3085 ResidueProperties.propHash, 3,
3086 sg.getSequences(viewport.hiddenRepSequences),
3087 sg.getStartRes(), sg.getEndRes() + 1);
3089 c.verdict(false, viewport.ConsPercGaps);
3090 sg.cs.setConservation(c);
3094 sg.cs.setConservation(null);
3099 if (alignPanel.getOverviewPanel() != null)
3101 alignPanel.getOverviewPanel().updateOverviewImage();
3104 alignPanel.paintAlignment(true);
3113 protected void modifyPID_actionPerformed(ActionEvent e)
3115 if (viewport.getAbovePIDThreshold()
3116 && viewport.globalColourScheme != null)
3118 SliderPanel.setPIDSliderSource(alignPanel,
3119 viewport.getGlobalColourScheme(), "Background");
3120 SliderPanel.showPIDSlider();
3130 protected void modifyConservation_actionPerformed(ActionEvent e)
3132 if (viewport.getConservationSelected()
3133 && viewport.globalColourScheme != null)
3135 SliderPanel.setConservationSlider(alignPanel,
3136 viewport.globalColourScheme, "Background");
3137 SliderPanel.showConservationSlider();
3147 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3149 viewport.setConservationSelected(conservationMenuItem.isSelected());
3151 viewport.setAbovePIDThreshold(false);
3152 abovePIDThreshold.setSelected(false);
3154 changeColour(viewport.getGlobalColourScheme());
3156 modifyConservation_actionPerformed(null);
3165 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3167 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3169 conservationMenuItem.setSelected(false);
3170 viewport.setConservationSelected(false);
3172 changeColour(viewport.getGlobalColourScheme());
3174 modifyPID_actionPerformed(null);
3183 public void userDefinedColour_actionPerformed(ActionEvent e)
3185 if (e.getActionCommand().equals("User Defined..."))
3187 new UserDefinedColours(alignPanel, null);
3191 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3192 .getUserColourSchemes().get(e.getActionCommand());
3198 public void updateUserColourMenu()
3201 Component[] menuItems = colourMenu.getMenuComponents();
3202 int i, iSize = menuItems.length;
3203 for (i = 0; i < iSize; i++)
3205 if (menuItems[i].getName() != null
3206 && menuItems[i].getName().equals("USER_DEFINED"))
3208 colourMenu.remove(menuItems[i]);
3212 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3214 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3215 .getUserColourSchemes().keys();
3217 while (userColours.hasMoreElements())
3219 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3220 userColours.nextElement().toString());
3221 radioItem.setName("USER_DEFINED");
3222 radioItem.addMouseListener(new MouseAdapter()
3224 public void mousePressed(MouseEvent evt)
3226 if (evt.isControlDown()
3227 || SwingUtilities.isRightMouseButton(evt))
3229 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3231 int option = JOptionPane.showInternalConfirmDialog(
3232 jalview.gui.Desktop.desktop,
3233 "Remove from default list?",
3234 "Remove user defined colour",
3235 JOptionPane.YES_NO_OPTION);
3236 if (option == JOptionPane.YES_OPTION)
3238 jalview.gui.UserDefinedColours
3239 .removeColourFromDefaults(radioItem.getText());
3240 colourMenu.remove(radioItem);
3244 radioItem.addActionListener(new ActionListener()
3246 public void actionPerformed(ActionEvent evt)
3248 userDefinedColour_actionPerformed(evt);
3255 radioItem.addActionListener(new ActionListener()
3257 public void actionPerformed(ActionEvent evt)
3259 userDefinedColour_actionPerformed(evt);
3263 colourMenu.insert(radioItem, 15);
3264 colours.add(radioItem);
3275 public void PIDColour_actionPerformed(ActionEvent e)
3277 changeColour(new PIDColourScheme());
3286 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3288 changeColour(new Blosum62ColourScheme());
3297 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3299 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3300 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3301 .getAlignment().getSequenceAt(0), null);
3302 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3303 viewport.alignment));
3304 alignPanel.paintAlignment(true);
3313 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3315 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3316 AlignmentSorter.sortByID(viewport.getAlignment());
3317 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
3318 alignPanel.paintAlignment(true);
3327 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3329 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3330 AlignmentSorter.sortByLength(viewport.getAlignment());
3331 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3332 viewport.alignment));
3333 alignPanel.paintAlignment(true);
3342 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3344 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3345 AlignmentSorter.sortByGroup(viewport.getAlignment());
3346 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3347 viewport.alignment));
3349 alignPanel.paintAlignment(true);
3358 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3360 new RedundancyPanel(alignPanel, this);
3369 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3371 if ((viewport.getSelectionGroup() == null)
3372 || (viewport.getSelectionGroup().getSize() < 2))
3374 JOptionPane.showInternalMessageDialog(this,
3375 "You must select at least 2 sequences.", "Invalid Selection",
3376 JOptionPane.WARNING_MESSAGE);
3380 JInternalFrame frame = new JInternalFrame();
3381 frame.setContentPane(new PairwiseAlignPanel(viewport));
3382 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3392 public void PCAMenuItem_actionPerformed(ActionEvent e)
3394 if (((viewport.getSelectionGroup() != null)
3395 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3396 .getSelectionGroup().getSize() > 0))
3397 || (viewport.getAlignment().getHeight() < 4))
3399 JOptionPane.showInternalMessageDialog(this,
3400 "Principal component analysis must take\n"
3401 + "at least 4 input sequences.",
3402 "Sequence selection insufficient",
3403 JOptionPane.WARNING_MESSAGE);
3408 new PCAPanel(alignPanel);
3411 public void autoCalculate_actionPerformed(ActionEvent e)
3413 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3414 if (viewport.autoCalculateConsensus)
3416 viewport.firePropertyChange("alignment", null, viewport
3417 .getAlignment().getSequences());
3427 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3429 NewTreePanel("AV", "PID", "Average distance tree using PID");
3438 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3440 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3449 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3451 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3460 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3462 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3475 void NewTreePanel(String type, String pwType, String title)
3479 if (viewport.getSelectionGroup() != null)
3481 if (viewport.getSelectionGroup().getSize() < 3)
3486 "You need to have more than two sequences selected to build a tree!",
3487 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3492 SequenceGroup sg = viewport.getSelectionGroup();
3494 /* Decide if the selection is a column region */
3495 while (s < sg.getSize())
3497 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3503 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3504 + "Try using the Pad function in the edit menu,\n"
3505 + "or one of the multiple sequence alignment web services.",
3506 "Sequences in selection are not aligned",
3507 JOptionPane.WARNING_MESSAGE);
3513 title = title + " on region";
3514 tp = new TreePanel(alignPanel, type, pwType);
3518 // are the visible sequences aligned?
3519 if (!viewport.alignment.isAligned(false))
3524 "The sequences must be aligned before creating a tree.\n"
3525 + "Try using the Pad function in the edit menu,\n"
3526 + "or one of the multiple sequence alignment web services.",
3527 "Sequences not aligned",
3528 JOptionPane.WARNING_MESSAGE);
3533 if (viewport.alignment.getHeight() < 2)
3538 tp = new TreePanel(alignPanel, type, pwType);
3543 if (viewport.viewName != null)
3545 title += viewport.viewName + " of ";
3548 title += this.title;
3550 Desktop.addInternalFrame(tp, title, 600, 500);
3561 public void addSortByOrderMenuItem(String title,
3562 final AlignmentOrder order)
3564 final JMenuItem item = new JMenuItem("by " + title);
3566 item.addActionListener(new java.awt.event.ActionListener()
3568 public void actionPerformed(ActionEvent e)
3570 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3572 // TODO: JBPNote - have to map order entries to curent SequenceI
3574 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3576 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3577 viewport.alignment));
3579 alignPanel.paintAlignment(true);
3585 * Add a new sort by annotation score menu item
3588 * the menu to add the option to
3590 * the label used to retrieve scores for each sequence on the
3593 public void addSortByAnnotScoreMenuItem(JMenu sort,
3594 final String scoreLabel)
3596 final JMenuItem item = new JMenuItem(scoreLabel);
3598 item.addActionListener(new java.awt.event.ActionListener()
3600 public void actionPerformed(ActionEvent e)
3602 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3603 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3604 viewport.getAlignment());// ,viewport.getSelectionGroup());
3605 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3606 viewport.alignment));
3607 alignPanel.paintAlignment(true);
3613 * last hash for alignment's annotation array - used to minimise cost of
3616 protected int _annotationScoreVectorHash;
3619 * search the alignment and rebuild the sort by annotation score submenu the
3620 * last alignment annotation vector hash is stored to minimize cost of
3621 * rebuilding in subsequence calls.
3624 public void buildSortByAnnotationScoresMenu()
3626 if (viewport.alignment.getAlignmentAnnotation() == null)
3631 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3633 sortByAnnotScore.removeAll();
3634 // almost certainly a quicker way to do this - but we keep it simple
3635 Hashtable scoreSorts = new Hashtable();
3636 AlignmentAnnotation aann[];
3637 Enumeration sq = viewport.alignment.getSequences().elements();
3638 while (sq.hasMoreElements())
3640 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3641 for (int i = 0; aann != null && i < aann.length; i++)
3643 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3645 scoreSorts.put(aann[i].label, aann[i].label);
3649 Enumeration labels = scoreSorts.keys();
3650 while (labels.hasMoreElements())
3652 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3653 (String) labels.nextElement());
3655 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3658 _annotationScoreVectorHash = viewport.alignment
3659 .getAlignmentAnnotation().hashCode();
3664 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3665 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3666 * call. Listeners are added to remove the menu item when the treePanel is
3667 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3671 * Displayed tree window.
3673 * SortBy menu item title.
3675 public void buildTreeMenu()
3677 sortByTreeMenu.removeAll();
3679 Vector comps = (Vector) PaintRefresher.components.get(viewport
3680 .getSequenceSetId());
3681 Vector treePanels = new Vector();
3682 int i, iSize = comps.size();
3683 for (i = 0; i < iSize; i++)
3685 if (comps.elementAt(i) instanceof TreePanel)
3687 treePanels.add(comps.elementAt(i));
3691 iSize = treePanels.size();
3695 sortByTreeMenu.setVisible(false);
3699 sortByTreeMenu.setVisible(true);
3701 for (i = 0; i < treePanels.size(); i++)
3703 TreePanel tp = (TreePanel) treePanels.elementAt(i);
3704 final JMenuItem item = new JMenuItem(tp.getTitle());
3705 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3706 item.addActionListener(new java.awt.event.ActionListener()
3708 public void actionPerformed(ActionEvent e)
3710 SequenceI[] oldOrder = viewport.getAlignment()
3711 .getSequencesArray();
3712 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3714 addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
3715 viewport.alignment));
3717 alignPanel.paintAlignment(true);
3721 sortByTreeMenu.add(item);
3726 * Work out whether the whole set of sequences or just the selected set will
3727 * be submitted for multiple alignment.
3730 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3732 // Now, check we have enough sequences
3733 AlignmentView msa = null;
3735 if ((viewport.getSelectionGroup() != null)
3736 && (viewport.getSelectionGroup().getSize() > 1))
3738 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3739 // some common interface!
3741 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3742 * SequenceI[sz = seqs.getSize(false)];
3744 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3745 * seqs.getSequenceAt(i); }
3747 msa = viewport.getAlignmentView(true);
3752 * Vector seqs = viewport.getAlignment().getSequences();
3754 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3756 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3757 * seqs.elementAt(i); } }
3759 msa = viewport.getAlignmentView(false);
3765 * Decides what is submitted to a secondary structure prediction service: the
3766 * first sequence in the alignment, or in the current selection, or, if the
3767 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3768 * region or the whole alignment. (where the first sequence in the set is the
3769 * one that the prediction will be for).
3771 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3773 AlignmentView seqs = null;
3775 if ((viewport.getSelectionGroup() != null)
3776 && (viewport.getSelectionGroup().getSize() > 0))
3778 seqs = viewport.getAlignmentView(true);
3782 seqs = viewport.getAlignmentView(false);
3784 // limit sequences - JBPNote in future - could spawn multiple prediction
3786 // TODO: viewport.alignment.isAligned is a global state - the local
3787 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3788 if (!viewport.alignment.isAligned(false))
3790 seqs.setSequences(new SeqCigar[]
3791 { seqs.getSequences()[0] });
3792 // TODO: if seqs.getSequences().length>1 then should really have warned
3805 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3807 // Pick the tree file
3808 JalviewFileChooser chooser = new JalviewFileChooser(
3809 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3810 chooser.setFileView(new JalviewFileView());
3811 chooser.setDialogTitle("Select a newick-like tree file");
3812 chooser.setToolTipText("Load a tree file");
3814 int value = chooser.showOpenDialog(null);
3816 if (value == JalviewFileChooser.APPROVE_OPTION)
3818 String choice = chooser.getSelectedFile().getPath();
3819 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3820 jalview.io.NewickFile fin = null;
3823 fin = new jalview.io.NewickFile(choice, "File");
3824 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3825 } catch (Exception ex)
3827 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3828 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3829 ex.printStackTrace();
3831 if (fin != null && fin.hasWarningMessage())
3833 JOptionPane.showMessageDialog(Desktop.desktop,
3834 fin.getWarningMessage(), "Possible problem with tree file",
3835 JOptionPane.WARNING_MESSAGE);
3840 public TreePanel ShowNewickTree(NewickFile nf, String title)
3842 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3845 public TreePanel ShowNewickTree(NewickFile nf, String title,
3846 AlignmentView input)
3848 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3851 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3852 int h, int x, int y)
3854 return ShowNewickTree(nf, title, null, w, h, x, y);
3858 * Add a treeviewer for the tree extracted from a newick file object to the
3859 * current alignment view
3866 * Associated alignment input data (or null)
3875 * @return TreePanel handle
3877 public TreePanel ShowNewickTree(NewickFile nf, String title,
3878 AlignmentView input, int w, int h, int x, int y)
3880 TreePanel tp = null;
3886 if (nf.getTree() != null)
3888 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3894 tp.setLocation(x, y);
3897 Desktop.addInternalFrame(tp, title, w, h);
3899 } catch (Exception ex)
3901 ex.printStackTrace();
3907 private boolean buildingMenu = false;
3910 * Generates menu items and listener event actions for web service clients
3913 public void BuildWebServiceMenu()
3915 while (buildingMenu)
3919 System.err.println("Waiting for building menu to finish.");
3921 } catch (Exception e)
3926 final AlignFrame me = this;
3927 buildingMenu = true;
3928 new Thread(new Runnable()
3934 System.err.println("Building ws menu again "
3935 + Thread.currentThread());
3936 // TODO: add support for context dependent disabling of services based
3938 // alignment and current selection
3939 // TODO: add additional serviceHandle parameter to specify abstract
3941 // class independently of AbstractName
3942 // TODO: add in rediscovery GUI function to restart discoverer
3943 // TODO: group services by location as well as function and/or
3945 // object broker mechanism.
3946 final Vector wsmenu = new Vector();
3947 final IProgressIndicator af = me;
3948 if (Cache.getDefault("SHOW_JWS1_SERVICES", true)
3949 && Discoverer.services != null
3950 && (Discoverer.services.size() > 0))
3952 // TODO: refactor to allow list of AbstractName/Handler bindings to
3954 // stored or retrieved from elsewhere
3955 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3956 Vector secstrpr = (Vector) Discoverer.services
3958 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3959 // TODO: move GUI generation code onto service implementation - so a
3960 // client instance attaches itself to the GUI with method call like
3961 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
3965 // Add any Multiple Sequence Alignment Services
3966 final JMenu msawsmenu = new JMenu("Alignment");
3967 for (int i = 0, j = msaws.size(); i < j; i++)
3969 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
3971 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
3972 .getServiceClient(sh);
3973 impl.attachWSMenuEntry(msawsmenu, me);
3976 wsmenu.add(msawsmenu);
3978 if (secstrpr != null)
3980 // Add any secondary structure prediction services
3981 final JMenu secstrmenu = new JMenu(
3982 "Secondary Structure Prediction");
3983 for (int i = 0, j = secstrpr.size(); i < j; i++)
3985 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
3987 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
3988 .getServiceClient(sh);
3989 impl.attachWSMenuEntry(secstrmenu, me);
3991 wsmenu.add(secstrmenu);
3993 if (seqsrch != null)
3995 // Add any sequence search services
3996 final JMenu seqsrchmenu = new JMenu(
3997 "Sequence Database Search");
3998 for (int i = 0, j = seqsrch.size(); i < j; i++)
4000 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4002 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4003 .getServiceClient(sh);
4004 impl.attachWSMenuEntry(seqsrchmenu, me);
4006 wsmenu.add(seqsrchmenu);
4010 // TODO: move into separate menu builder class.
4011 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4013 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4014 if (jws2servs != null)
4016 if (jws2servs.hasServices())
4018 JMenu jws2men = new JMenu("Jaba Web Services");
4019 jws2servs.attachWSMenuEntry(jws2men, me);
4020 for (int i = 0, iSize = jws2men.getMenuComponentCount(); i < iSize; i++)
4022 wsmenu.add(jws2men.getMenuComponent(i));
4028 javax.swing.SwingUtilities.invokeLater(new Runnable()
4035 resetWebServiceMenu();
4036 // finally, add the whole shebang onto the webservices menu
4037 if (wsmenu.size() > 0)
4039 for (int i = 0, j = wsmenu.size(); i < j; i++)
4041 webService.add((JMenu) wsmenu.get(i));
4046 me.webService.add(me.webServiceNoServices);
4048 } catch (Exception e)
4054 } catch (Exception e)
4059 buildingMenu = false;
4066 * empty the web service menu and add any ad-hoc functions not dynamically
4070 private void resetWebServiceMenu()
4072 webService.removeAll();
4073 build_fetchdbmenu(webService);
4074 build_urlServiceMenu(webService);
4078 * construct any groupURL type service menu entries.
4082 private void build_urlServiceMenu(JMenu webService)
4084 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4086 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4089 // TODO: remove this code when 2.7 is released
4090 // DEBUG - alignmentView
4092 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4093 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4095 * @Override public void actionPerformed(ActionEvent e) {
4096 * jalview.datamodel.AlignmentView.testSelectionViews(af.viewport.alignment,
4097 * af.viewport.colSel, af.viewport.selectionGroup); }
4099 * }); webService.add(testAlView);
4101 // TODO: refactor to RestClient discoverer and merge menu entries for
4102 // rest-style services with other types of analysis/calculation service
4103 // SHmmr test client - still being implemented.
4104 jalview.ws.rest.RestClient.makeShmmrRestClient().attachWSMenuEntry(
4106 // DEBUG - alignmentView
4110 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4111 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4112 * getProperty("LAST_DIRECTORY"));
4114 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4115 * to Vamsas file"); chooser.setToolTipText("Export");
4117 * int value = chooser.showSaveDialog(this);
4119 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4120 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4121 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4122 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4125 * prototype of an automatically enabled/disabled analysis function
4128 protected void setShowProductsEnabled()
4130 SequenceI[] selection = viewport.getSequenceSelection();
4131 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4132 viewport.getAlignment().getDataset()))
4134 showProducts.setEnabled(true);
4139 showProducts.setEnabled(false);
4144 * search selection for sequence xRef products and build the show products
4149 * @return true if showProducts menu should be enabled.
4151 public boolean canShowProducts(SequenceI[] selection,
4152 boolean isRegionSelection, Alignment dataset)
4154 boolean showp = false;
4157 showProducts.removeAll();
4158 final boolean dna = viewport.getAlignment().isNucleotide();
4159 final Alignment ds = dataset;
4160 String[] ptypes = (selection == null || selection.length == 0) ? null
4161 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4163 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4164 // selection, dataset, true);
4165 final SequenceI[] sel = selection;
4166 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4169 final boolean isRegSel = isRegionSelection;
4170 final AlignFrame af = this;
4171 final String source = ptypes[t];
4172 JMenuItem xtype = new JMenuItem(ptypes[t]);
4173 xtype.addActionListener(new ActionListener()
4176 public void actionPerformed(ActionEvent e)
4178 // TODO: new thread for this call with vis-delay
4179 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4180 isRegSel, dna, source);
4184 showProducts.add(xtype);
4186 showProducts.setVisible(showp);
4187 showProducts.setEnabled(showp);
4188 } catch (Exception e)
4190 jalview.bin.Cache.log
4191 .warn("canTranslate threw an exception - please report to help@jalview.org",
4198 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4199 boolean isRegSel, boolean dna, String source)
4201 final boolean fisRegSel = isRegSel;
4202 final boolean fdna = dna;
4203 final String fsrc = source;
4204 final AlignFrame ths = this;
4205 final SequenceI[] fsel = sel;
4206 Runnable foo = new Runnable()
4211 final long sttime = System.currentTimeMillis();
4212 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4215 Alignment ds = ths.getViewport().alignment.getDataset(); // update
4219 Alignment prods = CrossRef
4220 .findXrefSequences(fsel, fdna, fsrc, ds);
4223 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4224 for (int s = 0; s < sprods.length; s++)
4226 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4227 if (ds.getSequences() == null
4228 || !ds.getSequences().contains(
4229 sprods[s].getDatasetSequence()))
4230 ds.addSequence(sprods[s].getDatasetSequence());
4231 sprods[s].updatePDBIds();
4233 Alignment al = new Alignment(sprods);
4234 AlignedCodonFrame[] cf = prods.getCodonFrames();
4236 for (int s = 0; cf != null && s < cf.length; s++)
4238 al.addCodonFrame(cf[s]);
4241 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4243 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4244 + " for " + ((fisRegSel) ? "selected region of " : "")
4246 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4251 System.err.println("No Sequences generated for xRef type "
4254 } catch (Exception e)
4256 jalview.bin.Cache.log.error(
4257 "Exception when finding crossreferences", e);
4258 } catch (OutOfMemoryError e)
4260 new OOMWarning("whilst fetching crossreferences", e);
4263 jalview.bin.Cache.log.error("Error when finding crossreferences",
4266 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4271 Thread frunner = new Thread(foo);
4275 public boolean canShowTranslationProducts(SequenceI[] selection,
4276 AlignmentI alignment)
4281 return (jalview.analysis.Dna.canTranslate(selection,
4282 viewport.getViewAsVisibleContigs(true)));
4283 } catch (Exception e)
4285 jalview.bin.Cache.log
4286 .warn("canTranslate threw an exception - please report to help@jalview.org",
4292 public void showProducts_actionPerformed(ActionEvent e)
4294 // /////////////////////////////
4295 // Collect Data to be translated/transferred
4297 SequenceI[] selection = viewport.getSequenceSelection();
4298 AlignmentI al = null;
4301 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4302 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4303 viewport.getAlignment().getDataset());
4304 } catch (Exception ex)
4307 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4314 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4315 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4319 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4320 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4321 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4325 public void showTranslation_actionPerformed(ActionEvent e)
4327 // /////////////////////////////
4328 // Collect Data to be translated/transferred
4330 SequenceI[] selection = viewport.getSequenceSelection();
4331 String[] seqstring = viewport.getViewAsString(true);
4332 AlignmentI al = null;
4335 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4336 viewport.getViewAsVisibleContigs(true), viewport
4337 .getGapCharacter(), viewport.alignment
4338 .getAlignmentAnnotation(), viewport.alignment
4339 .getWidth(), viewport.getAlignment().getDataset());
4340 } catch (Exception ex)
4343 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4350 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4351 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4355 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4356 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4357 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4362 * Try to load a features file onto the alignment.
4365 * contents or path to retrieve file
4367 * access mode of file (see jalview.io.AlignFile)
4368 * @return true if features file was parsed corectly.
4370 public boolean parseFeaturesFile(String file, String type)
4372 boolean featuresFile = false;
4375 featuresFile = new FeaturesFile(file, type)
4376 .parse(viewport.alignment.getDataset(),
4377 alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
4379 } catch (Exception ex)
4381 ex.printStackTrace();
4386 viewport.showSequenceFeatures = true;
4387 showSeqFeatures.setSelected(true);
4388 if (alignPanel.seqPanel.seqCanvas.fr != null)
4390 // update the min/max ranges where necessary
4391 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4393 if (featureSettings != null)
4395 featureSettings.setTableData();
4397 alignPanel.paintAlignment(true);
4400 return featuresFile;
4403 public void dragEnter(DropTargetDragEvent evt)
4407 public void dragExit(DropTargetEvent evt)
4411 public void dragOver(DropTargetDragEvent evt)
4415 public void dropActionChanged(DropTargetDragEvent evt)
4419 public void drop(DropTargetDropEvent evt)
4421 Transferable t = evt.getTransferable();
4422 java.util.List files = null;
4426 DataFlavor uriListFlavor = new DataFlavor(
4427 "text/uri-list;class=java.lang.String");
4428 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4430 // Works on Windows and MacOSX
4431 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4432 files = (java.util.List) t
4433 .getTransferData(DataFlavor.javaFileListFlavor);
4435 else if (t.isDataFlavorSupported(uriListFlavor))
4437 // This is used by Unix drag system
4438 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4439 String data = (String) t.getTransferData(uriListFlavor);
4440 files = new java.util.ArrayList(1);
4441 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4442 data, "\r\n"); st.hasMoreTokens();)
4444 String s = st.nextToken();
4445 if (s.startsWith("#"))
4447 // the line is a comment (as per the RFC 2483)
4451 java.net.URI uri = new java.net.URI(s);
4452 // check to see if we can handle this kind of URI
4453 if (uri.getScheme().toLowerCase().startsWith("http"))
4455 files.add(uri.toString());
4459 // otherwise preserve old behaviour: catch all for file objects
4460 java.io.File file = new java.io.File(uri);
4461 files.add(file.toString());
4465 } catch (Exception e)
4467 e.printStackTrace();
4473 // check to see if any of these files have names matching sequences in
4475 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4476 .getAlignment().getSequencesArray());
4478 * Object[] { String,SequenceI}
4480 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4481 ArrayList<String> filesnotmatched = new ArrayList<String>();
4482 for (int i = 0; i < files.size(); i++)
4484 String file = files.get(i).toString();
4486 String protocol = FormatAdapter.checkProtocol(file);
4487 if (protocol == jalview.io.FormatAdapter.FILE)
4489 File fl = new File(file);
4490 pdbfn = fl.getName();
4492 else if (protocol == jalview.io.FormatAdapter.URL)
4494 URL url = new URL(file);
4495 pdbfn = url.getFile();
4497 if (pdbfn.length() > 0)
4499 // attempt to find a match in the alignment
4500 SequenceI mtch = idm.findIdMatch(pdbfn);
4501 int l = 0, c = pdbfn.indexOf(".");
4502 while (mtch == null && c != -1)
4504 while ((c = pdbfn.indexOf(".", l)) > l)
4510 pdbfn = pdbfn.substring(0, l);
4512 mtch = idm.findIdMatch(pdbfn);
4519 type = new IdentifyFile().Identify(file, protocol);
4520 } catch (Exception ex)
4526 if (type.equalsIgnoreCase("PDB"))
4528 filesmatched.add(new Object[]
4529 { file, protocol, mtch });
4534 // File wasn't named like one of the sequences or wasn't a PDB file.
4535 filesnotmatched.add(file);
4539 if (filesmatched.size() > 0)
4541 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4545 "Do you want to automatically associate the "
4546 + filesmatched.size()
4547 + " PDB files with sequences in the alignment that have the same name ?",
4548 "Automatically Associate PDB files by name",
4549 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4552 for (Object[] fm : filesmatched)
4554 // try and associate
4555 // TODO: may want to set a standard ID naming formalism for
4556 // associating PDB files which have no IDs.
4557 PDBEntry pe = new AssociatePdbFileWithSeq()
4558 .associatePdbWithSeq((String) fm[0], (String) fm[1],
4559 (SequenceI) fm[2], false);
4563 .println("Associated file : " + ((String) fm[0])
4565 + ((SequenceI) fm[2]).getDisplayId(true));
4568 alignPanel.paintAlignment(true);
4572 if (filesnotmatched.size() > 0)
4575 && (Cache.getDefault(
4576 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4579 "<html>Do you want to <em>ignore</em> the "
4580 + filesnotmatched.size()
4581 + " files whose names did not match any sequence IDs ?</html>",
4582 "Ignore unmatched dropped files ?",
4583 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4587 for (String fn : filesnotmatched)
4589 loadJalviewDataFile(fn, null, null, null);
4593 } catch (Exception ex)
4595 ex.printStackTrace();
4601 * Attempt to load a "dropped" file or URL string: First by testing whether
4602 * it's and Annotation file, then a JNet file, and finally a features file. If
4603 * all are false then the user may have dropped an alignment file onto this
4607 * either a filename or a URL string.
4609 public void loadJalviewDataFile(String file, String protocol,
4610 String format, SequenceI assocSeq)
4614 if (protocol == null)
4616 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4618 // if the file isn't identified, or not positively identified as some
4619 // other filetype (PFAM is default unidentified alignment file type) then
4620 // try to parse as annotation.
4621 boolean isAnnotation = (format == null || format
4622 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4623 .readAnnotationFile(viewport.alignment, file, protocol)
4628 // try to see if its a JNet 'concise' style annotation file *before* we
4629 // try to parse it as a features file
4632 format = new IdentifyFile().Identify(file, protocol);
4634 if (format.equalsIgnoreCase("JnetFile"))
4636 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4638 new JnetAnnotationMaker().add_annotation(predictions,
4639 viewport.getAlignment(), 0, false);
4640 isAnnotation = true;
4645 * if (format.equalsIgnoreCase("PDB")) {
4647 * String pdbfn = ""; // try to match up filename with sequence id try
4648 * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new
4649 * File(file); pdbfn = fl.getName(); } else if (protocol ==
4650 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4651 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null)
4652 * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4653 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { //
4654 * attempt to find a match in the alignment SequenceI mtch =
4655 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4656 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l)
4657 * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch =
4658 * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate
4659 * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4660 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) {
4661 * System.err.println("Associated file : " + file + " with " +
4662 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4663 * TODO: maybe need to load as normal otherwise return; } }
4665 // try to parse it as a features file
4666 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4667 // if it wasn't a features file then we just treat it as a general
4668 // alignment file to load into the current view.
4671 new FileLoader().LoadFile(viewport, file, protocol, format);
4675 alignPanel.paintAlignment(true);
4682 alignPanel.adjustAnnotationHeight();
4683 viewport.updateSequenceIdColours();
4684 buildSortByAnnotationScoresMenu();
4685 alignPanel.paintAlignment(true);
4687 } catch (Exception ex)
4689 ex.printStackTrace();
4693 public void tabSelectionChanged(int index)
4697 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4698 viewport = alignPanel.av;
4699 setMenusFromViewport(viewport);
4703 public void tabbedPane_mousePressed(MouseEvent e)
4705 if (SwingUtilities.isRightMouseButton(e))
4707 String reply = JOptionPane.showInternalInputDialog(this,
4708 "Enter View Name", "Edit View Name",
4709 JOptionPane.QUESTION_MESSAGE);
4713 viewport.viewName = reply;
4714 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4719 public AlignViewport getCurrentView()
4725 * Open the dialog for regex description parsing.
4727 protected void extractScores_actionPerformed(ActionEvent e)
4729 ParseProperties pp = new jalview.analysis.ParseProperties(
4730 viewport.alignment);
4731 // TODO: verify regex and introduce GUI dialog for version 2.5
4732 // if (pp.getScoresFromDescription("col", "score column ",
4733 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4735 if (pp.getScoresFromDescription("description column",
4736 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4738 buildSortByAnnotationScoresMenu();
4746 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4749 protected void showDbRefs_actionPerformed(ActionEvent e)
4751 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4757 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4760 protected void showNpFeats_actionPerformed(ActionEvent e)
4762 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4766 * find the viewport amongst the tabs in this alignment frame and close that
4771 public boolean closeView(AlignViewport av)
4775 this.closeMenuItem_actionPerformed(false);
4778 Component[] comp = tabbedPane.getComponents();
4779 for (int i = 0; comp != null && i < comp.length; i++)
4781 if (comp[i] instanceof AlignmentPanel)
4783 if (((AlignmentPanel) comp[i]).av == av)
4786 closeView((AlignmentPanel) comp[i]);
4794 protected void build_fetchdbmenu(JMenu webService)
4796 // Temporary hack - DBRef Fetcher always top level ws entry.
4797 // TODO We probably want to store a sequence database checklist in
4798 // preferences and have checkboxes.. rather than individual sources selected
4800 final JMenu rfetch = new JMenu("Fetch DB References");
4801 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4802 webService.add(rfetch);
4804 JMenuItem fetchr = new JMenuItem("Standard Databases");
4805 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4806 fetchr.addActionListener(new ActionListener()
4809 public void actionPerformed(ActionEvent e)
4811 new Thread(new Runnable()
4816 new jalview.ws.DBRefFetcher(alignPanel.av
4817 .getSequenceSelection(), alignPanel.alignFrame)
4818 .fetchDBRefs(false);
4826 final AlignFrame me = this;
4827 new Thread(new Runnable()
4831 final jalview.ws.SequenceFetcher sf = SequenceFetcher
4832 .getSequenceFetcherSingleton(me);
4833 final String[] otherdb = sf.getOrderedSupportedSources();
4834 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4835 // jalview.util.QuickSort.sort(otherdb, otherdb);
4836 javax.swing.SwingUtilities.invokeLater(new Runnable()
4841 JMenu dfetch = new JMenu();
4844 int comp = 0, mcomp = 15;
4845 String mname = null;
4846 if (otherdb != null && otherdb.length > 0)
4848 for (int i = 0; i < otherdb.length; i++)
4850 String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
4853 mname = "from '" + dbname + "'";
4855 fetchr = new JMenuItem(otherdb[i]);
4856 final String[] dassource = new String[]
4858 fetchr.addActionListener(new ActionListener()
4861 public void actionPerformed(ActionEvent e)
4863 new Thread(new Runnable()
4868 new jalview.ws.DBRefFetcher(alignPanel.av
4869 .getSequenceSelection(),
4870 alignPanel.alignFrame, dassource)
4871 .fetchDBRefs(false);
4877 fetchr.setToolTipText("Retrieve from " + dbname);
4879 if (comp++ == mcomp || i == (otherdb.length - 1))
4881 dfetch.setText(mname + " to '" + dbname + "'");
4883 dfetch = new JMenu();
4897 * Left justify the whole alignment.
4899 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4901 AlignmentI al = viewport.getAlignment();
4903 viewport.firePropertyChange("alignment", null, al);
4907 * Right justify the whole alignment.
4909 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4911 AlignmentI al = viewport.getAlignment();
4913 viewport.firePropertyChange("alignment", null, al);
4916 public void setShowSeqFeatures(boolean b)
4918 showSeqFeatures.setSelected(true);
4919 viewport.setShowSequenceFeatures(true);
4926 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
4927 * awt.event.ActionEvent)
4929 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
4931 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
4932 alignPanel.paintAlignment(true);
4939 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
4942 protected void showGroupConsensus_actionPerformed(ActionEvent e)
4944 viewport.setShowGroupConsensus(showGroupConsensus.getState());
4945 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4953 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
4954 * .event.ActionEvent)
4956 protected void showGroupConservation_actionPerformed(ActionEvent e)
4958 viewport.setShowGroupConservation(showGroupConservation.getState());
4959 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4966 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
4967 * .event.ActionEvent)
4969 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
4971 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
4972 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4979 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
4980 * .event.ActionEvent)
4982 protected void showSequenceLogo_actionPerformed(ActionEvent e)
4984 viewport.setShowSequenceLogo(showSequenceLogo.getState());
4985 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4988 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
4990 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4997 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
4998 * .event.ActionEvent)
5000 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5002 if (viewport.getSelectionGroup() != null)
5004 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5005 viewport.getSequenceSelection(),
5006 viewport.getAlignmentView(true).getSequenceStrings(
5007 viewport.getGapCharacter()),
5008 viewport.alignment.getGroups());
5009 viewport.alignment.deleteAllGroups();
5010 viewport.sequenceColours = null;
5011 viewport.setSelectionGroup(null);
5012 // set view properties for each group
5013 for (int g = 0; g < gps.length; g++)
5015 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5016 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5017 viewport.alignment.addGroup(gps[g]);
5018 Color col = new Color((int) (Math.random() * 255),
5019 (int) (Math.random() * 255), (int) (Math.random() * 255));
5020 col = col.brighter();
5021 for (Enumeration sq = gps[g].getSequences(null).elements(); sq
5022 .hasMoreElements(); viewport.setSequenceColour(
5023 (SequenceI) sq.nextElement(), col))
5026 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5027 alignPanel.updateAnnotation();
5028 alignPanel.paintAlignment(true);
5033 class PrintThread extends Thread
5037 public PrintThread(AlignmentPanel ap)
5042 static PageFormat pf;
5046 PrinterJob printJob = PrinterJob.getPrinterJob();
5050 printJob.setPrintable(ap, pf);
5054 printJob.setPrintable(ap);
5057 if (printJob.printDialog())
5062 } catch (Exception PrintException)
5064 PrintException.printStackTrace();