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.WSMenuEntryProviderI;
75 import jalview.ws.jws1.Discoverer;
76 import jalview.ws.jws2.Jws2Discoverer;
78 import java.awt.BorderLayout;
79 import java.awt.Color;
80 import java.awt.Component;
81 import java.awt.GridLayout;
82 import java.awt.Rectangle;
83 import java.awt.Toolkit;
84 import java.awt.datatransfer.Clipboard;
85 import java.awt.datatransfer.DataFlavor;
86 import java.awt.datatransfer.StringSelection;
87 import java.awt.datatransfer.Transferable;
88 import java.awt.dnd.DnDConstants;
89 import java.awt.dnd.DropTargetDragEvent;
90 import java.awt.dnd.DropTargetDropEvent;
91 import java.awt.dnd.DropTargetEvent;
92 import java.awt.dnd.DropTargetListener;
93 import java.awt.event.ActionEvent;
94 import java.awt.event.ActionListener;
95 import java.awt.event.KeyAdapter;
96 import java.awt.event.KeyEvent;
97 import java.awt.event.MouseAdapter;
98 import java.awt.event.MouseEvent;
99 import java.awt.print.PageFormat;
100 import java.awt.print.PrinterJob;
101 import java.beans.PropertyChangeEvent;
104 import java.util.ArrayList;
105 import java.util.Enumeration;
106 import java.util.Hashtable;
107 import java.util.Vector;
109 import javax.swing.JButton;
110 import javax.swing.JEditorPane;
111 import javax.swing.JInternalFrame;
112 import javax.swing.JLabel;
113 import javax.swing.JLayeredPane;
114 import javax.swing.JMenu;
115 import javax.swing.JMenuItem;
116 import javax.swing.JOptionPane;
117 import javax.swing.JPanel;
118 import javax.swing.JProgressBar;
119 import javax.swing.JRadioButtonMenuItem;
120 import javax.swing.JScrollPane;
121 import javax.swing.SwingUtilities;
127 * @version $Revision$
129 public class AlignFrame extends GAlignFrame implements DropTargetListener,
134 public static final int DEFAULT_WIDTH = 700;
137 public static final int DEFAULT_HEIGHT = 500;
139 public AlignmentPanel alignPanel;
141 AlignViewport viewport;
143 Vector alignPanels = new Vector();
146 * Last format used to load or save alignments in this window
148 String currentFileFormat = null;
151 * Current filename for this alignment
153 String fileName = null;
156 * Creates a new AlignFrame object with specific width and height.
162 public AlignFrame(AlignmentI al, int width, int height)
164 this(al, null, width, height);
168 * Creates a new AlignFrame object with specific width, height and
174 * @param sequenceSetId
176 public AlignFrame(AlignmentI al, int width, int height,
177 String sequenceSetId)
179 this(al, null, width, height, sequenceSetId);
183 * Creates a new AlignFrame object with specific width, height and
189 * @param sequenceSetId
192 public AlignFrame(AlignmentI al, int width, int height,
193 String sequenceSetId, String viewId)
195 this(al, null, width, height, sequenceSetId, viewId);
199 * new alignment window with hidden columns
203 * @param hiddenColumns
204 * ColumnSelection or null
206 * Width of alignment frame
210 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
211 int width, int height)
213 this(al, hiddenColumns, width, height, null);
217 * Create alignment frame for al with hiddenColumns, a specific width and
218 * height, and specific sequenceId
221 * @param hiddenColumns
224 * @param sequenceSetId
227 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
228 int width, int height, String sequenceSetId)
230 this(al, hiddenColumns, width, height, sequenceSetId, null);
234 * Create alignment frame for al with hiddenColumns, a specific width and
235 * height, and specific sequenceId
238 * @param hiddenColumns
241 * @param sequenceSetId
246 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
247 int width, int height, String sequenceSetId, String viewId)
249 setSize(width, height);
250 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
252 alignPanel = new AlignmentPanel(this, viewport);
254 if (al.getDataset() == null)
259 addAlignmentPanel(alignPanel, true);
264 * Make a new AlignFrame from exisiting alignmentPanels
271 public AlignFrame(AlignmentPanel ap)
275 addAlignmentPanel(ap, false);
280 * initalise the alignframe from the underlying viewport data and the
285 if (viewport.conservation == null)
287 BLOSUM62Colour.setEnabled(false);
288 conservationMenuItem.setEnabled(false);
289 modifyConservation.setEnabled(false);
290 // PIDColour.setEnabled(false);
291 // abovePIDThreshold.setEnabled(false);
292 // modifyPID.setEnabled(false);
295 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
298 if (sortby.equals("Id"))
300 sortIDMenuItem_actionPerformed(null);
302 else if (sortby.equals("Pairwise Identity"))
304 sortPairwiseMenuItem_actionPerformed(null);
307 if (Desktop.desktop != null)
309 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
310 addServiceListeners();
311 setGUINucleotide(viewport.alignment.isNucleotide());
314 setMenusFromViewport(viewport);
315 buildSortByAnnotationScoresMenu();
316 if (viewport.wrapAlignment)
318 wrapMenuItem_actionPerformed(null);
321 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
323 this.overviewMenuItem_actionPerformed(null);
331 * Change the filename and format for the alignment, and enable the 'reload'
332 * button functionality.
339 public void setFileName(String file, String format)
342 currentFileFormat = format;
343 reload.setEnabled(true);
346 void addKeyListener()
348 addKeyListener(new KeyAdapter()
350 public void keyPressed(KeyEvent evt)
352 if (viewport.cursorMode
353 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
354 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
355 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
356 && Character.isDigit(evt.getKeyChar()))
357 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
359 switch (evt.getKeyCode())
362 case 27: // escape key
363 deselectAllSequenceMenuItem_actionPerformed(null);
367 case KeyEvent.VK_DOWN:
368 if (evt.isAltDown() || !viewport.cursorMode)
369 moveSelectedSequences(false);
370 if (viewport.cursorMode)
371 alignPanel.seqPanel.moveCursor(0, 1);
375 if (evt.isAltDown() || !viewport.cursorMode)
376 moveSelectedSequences(true);
377 if (viewport.cursorMode)
378 alignPanel.seqPanel.moveCursor(0, -1);
382 case KeyEvent.VK_LEFT:
383 if (evt.isAltDown() || !viewport.cursorMode)
384 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
386 alignPanel.seqPanel.moveCursor(-1, 0);
390 case KeyEvent.VK_RIGHT:
391 if (evt.isAltDown() || !viewport.cursorMode)
392 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
394 alignPanel.seqPanel.moveCursor(1, 0);
397 case KeyEvent.VK_SPACE:
398 if (viewport.cursorMode)
400 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
401 || evt.isShiftDown() || evt.isAltDown());
405 case KeyEvent.VK_DELETE:
406 case KeyEvent.VK_BACK_SPACE:
407 if (!viewport.cursorMode)
409 cut_actionPerformed(null);
413 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
414 || evt.isShiftDown() || evt.isAltDown());
420 if (viewport.cursorMode)
422 alignPanel.seqPanel.setCursorRow();
426 if (viewport.cursorMode && !evt.isControlDown())
428 alignPanel.seqPanel.setCursorColumn();
432 if (viewport.cursorMode)
434 alignPanel.seqPanel.setCursorPosition();
438 case KeyEvent.VK_ENTER:
439 case KeyEvent.VK_COMMA:
440 if (viewport.cursorMode)
442 alignPanel.seqPanel.setCursorRowAndColumn();
447 if (viewport.cursorMode)
449 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
453 if (viewport.cursorMode)
455 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
460 viewport.cursorMode = !viewport.cursorMode;
461 statusBar.setText("Keyboard editing mode is "
462 + (viewport.cursorMode ? "on" : "off"));
463 if (viewport.cursorMode)
465 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
466 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
468 alignPanel.seqPanel.seqCanvas.repaint();
474 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
475 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
477 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
479 javax.help.HelpBroker hb = hs.createHelpBroker();
480 hb.setCurrentID("home");
481 hb.setDisplayed(true);
482 } catch (Exception ex)
484 ex.printStackTrace();
489 boolean toggleSeqs = !evt.isControlDown();
490 boolean toggleCols = !evt.isShiftDown();
491 toggleHiddenRegions(toggleSeqs, toggleCols);
494 case KeyEvent.VK_PAGE_UP:
495 if (viewport.wrapAlignment)
497 alignPanel.scrollUp(true);
501 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
502 - viewport.endSeq + viewport.startSeq);
505 case KeyEvent.VK_PAGE_DOWN:
506 if (viewport.wrapAlignment)
508 alignPanel.scrollUp(false);
512 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
513 + viewport.endSeq - viewport.startSeq);
519 public void keyReleased(KeyEvent evt)
521 switch (evt.getKeyCode())
523 case KeyEvent.VK_LEFT:
524 if (evt.isAltDown() || !viewport.cursorMode)
525 viewport.firePropertyChange("alignment", null, viewport
526 .getAlignment().getSequences());
529 case KeyEvent.VK_RIGHT:
530 if (evt.isAltDown() || !viewport.cursorMode)
531 viewport.firePropertyChange("alignment", null, viewport
532 .getAlignment().getSequences());
539 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
541 ap.alignFrame = this;
543 alignPanels.addElement(ap);
545 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
547 int aSize = alignPanels.size();
549 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
551 if (aSize == 1 && ap.av.viewName == null)
553 this.getContentPane().add(ap, BorderLayout.CENTER);
559 setInitialTabVisible();
562 expandViews.setEnabled(true);
563 gatherViews.setEnabled(true);
564 tabbedPane.addTab(ap.av.viewName, ap);
566 ap.setVisible(false);
573 ap.av.alignment.padGaps();
575 ap.av.updateConservation(ap);
576 ap.av.updateConsensus(ap);
580 public void setInitialTabVisible()
582 expandViews.setEnabled(true);
583 gatherViews.setEnabled(true);
584 tabbedPane.setVisible(true);
585 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
586 tabbedPane.addTab(first.av.viewName, first);
587 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
590 public AlignViewport getViewport()
595 /* Set up intrinsic listeners for dynamically generated GUI bits. */
596 private void addServiceListeners()
598 final java.beans.PropertyChangeListener thisListener;
599 Desktop.instance.addJalviewPropertyChangeListener("services",
600 thisListener = new java.beans.PropertyChangeListener()
602 public void propertyChange(PropertyChangeEvent evt)
604 // // System.out.println("Discoverer property change.");
605 // if (evt.getPropertyName().equals("services"))
607 SwingUtilities.invokeLater(new Runnable()
613 .println("Rebuild WS Menu for service change");
614 BuildWebServiceMenu();
621 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
623 public void internalFrameClosed(
624 javax.swing.event.InternalFrameEvent evt)
626 System.out.println("deregistering discoverer listener");
627 Desktop.instance.removeJalviewPropertyChangeListener("services",
629 closeMenuItem_actionPerformed(true);
632 // Finally, build the menu once to get current service state
633 new Thread(new Runnable()
637 BuildWebServiceMenu();
642 public void setGUINucleotide(boolean nucleotide)
644 showTranslation.setVisible(nucleotide);
645 conservationMenuItem.setEnabled(!nucleotide);
646 modifyConservation.setEnabled(!nucleotide);
647 showGroupConservation.setEnabled(!nucleotide);
648 // Remember AlignFrame always starts as protein
651 calculateMenu.remove(calculateMenu.getItemCount() - 2);
656 * set up menus for the currently viewport. This may be called after any
657 * operation that affects the data in the current view (selection changed,
658 * etc) to update the menus to reflect the new state.
660 public void setMenusForViewport()
662 setMenusFromViewport(viewport);
666 * Need to call this method when tabs are selected for multiple views, or when
667 * loading from Jalview2XML.java
672 void setMenusFromViewport(AlignViewport av)
674 padGapsMenuitem.setSelected(av.padGaps);
675 colourTextMenuItem.setSelected(av.showColourText);
676 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
677 conservationMenuItem.setSelected(av.getConservationSelected());
678 seqLimits.setSelected(av.getShowJVSuffix());
679 idRightAlign.setSelected(av.rightAlignIds);
680 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
681 renderGapsMenuItem.setSelected(av.renderGaps);
682 wrapMenuItem.setSelected(av.wrapAlignment);
683 scaleAbove.setVisible(av.wrapAlignment);
684 scaleLeft.setVisible(av.wrapAlignment);
685 scaleRight.setVisible(av.wrapAlignment);
686 annotationPanelMenuItem.setState(av.showAnnotation);
687 viewBoxesMenuItem.setSelected(av.showBoxes);
688 viewTextMenuItem.setSelected(av.showText);
689 showNonconservedMenuItem.setSelected(av.showUnconserved);
690 showGroupConsensus.setSelected(av.showGroupConsensus);
691 showGroupConservation.setSelected(av.showGroupConservation);
692 showConsensusHistogram.setSelected(av.showConsensusHistogram);
693 showSequenceLogo.setSelected(av.showSequenceLogo);
694 setColourSelected(ColourSchemeProperty.getColourName(av
695 .getGlobalColourScheme()));
697 showSeqFeatures.setSelected(av.showSequenceFeatures);
698 hiddenMarkers.setState(av.showHiddenMarkers);
699 applyToAllGroups.setState(av.colourAppliesToAllGroups);
700 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
701 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
702 autoCalculate.setSelected(av.autoCalculateConsensus);
703 sortByTree.setSelected(av.sortByTree);
705 setShowProductsEnabled();
710 Hashtable progressBars, progressBarHandlers;
715 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
717 public void setProgressBar(String message, long id)
719 if (progressBars == null)
721 progressBars = new Hashtable();
722 progressBarHandlers = new Hashtable();
725 JPanel progressPanel;
726 Long lId = new Long(id);
727 GridLayout layout = (GridLayout) statusPanel.getLayout();
728 if (progressBars.get(lId) != null)
730 progressPanel = (JPanel) progressBars.get(new Long(id));
731 statusPanel.remove(progressPanel);
732 progressBars.remove(lId);
733 progressPanel = null;
736 statusBar.setText(message);
738 if (progressBarHandlers.contains(lId))
740 progressBarHandlers.remove(lId);
742 layout.setRows(layout.getRows() - 1);
746 progressPanel = new JPanel(new BorderLayout(10, 5));
748 JProgressBar progressBar = new JProgressBar();
749 progressBar.setIndeterminate(true);
751 progressPanel.add(new JLabel(message), BorderLayout.WEST);
752 progressPanel.add(progressBar, BorderLayout.CENTER);
754 layout.setRows(layout.getRows() + 1);
755 statusPanel.add(progressPanel);
757 progressBars.put(lId, progressPanel);
760 // setMenusForViewport();
764 public void registerHandler(final long id,
765 final IProgressIndicatorHandler handler)
767 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
770 "call setProgressBar before registering the progress bar's handler.");
772 progressBarHandlers.put(new Long(id), handler);
773 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
774 if (handler.canCancel())
776 JButton cancel = new JButton("Cancel");
777 final IProgressIndicator us = this;
778 cancel.addActionListener(new ActionListener()
781 public void actionPerformed(ActionEvent e)
783 handler.cancelActivity(id);
786 + ((JLabel) progressPanel.getComponent(0))
790 progressPanel.add(cancel, BorderLayout.EAST);
796 * @return true if any progress bars are still active
798 public boolean operationInProgress()
800 if (progressBars != null && progressBars.size() > 0)
808 * Added so Castor Mapping file can obtain Jalview Version
810 public String getVersion()
812 return jalview.bin.Cache.getProperty("VERSION");
815 public FeatureRenderer getFeatureRenderer()
817 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
820 public void fetchSequence_actionPerformed(ActionEvent e)
822 new SequenceFetcher(this);
825 public void addFromFile_actionPerformed(ActionEvent e)
827 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
830 public void reload_actionPerformed(ActionEvent e)
832 if (fileName != null)
834 // TODO: work out how to recover feature settings for correct view(s) when
836 if (currentFileFormat.equals("Jalview"))
838 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
839 for (int i = 0; i < frames.length; i++)
841 if (frames[i] instanceof AlignFrame && frames[i] != this
842 && ((AlignFrame) frames[i]).fileName.equals(fileName))
846 frames[i].setSelected(true);
847 Desktop.instance.closeAssociatedWindows();
848 } catch (java.beans.PropertyVetoException ex)
854 Desktop.instance.closeAssociatedWindows();
856 FileLoader loader = new FileLoader();
857 String protocol = fileName.startsWith("http:") ? "URL" : "File";
858 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
862 Rectangle bounds = this.getBounds();
864 FileLoader loader = new FileLoader();
865 String protocol = fileName.startsWith("http:") ? "URL" : "File";
866 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
867 protocol, currentFileFormat);
869 newframe.setBounds(bounds);
870 if (featureSettings != null && featureSettings.isShowing())
872 final Rectangle fspos = featureSettings.frame.getBounds();
873 // TODO: need a 'show feature settings' function that takes bounds -
874 // need to refactor Desktop.addFrame
875 newframe.featureSettings_actionPerformed(null);
876 final FeatureSettings nfs = newframe.featureSettings;
877 SwingUtilities.invokeLater(new Runnable()
881 nfs.frame.setBounds(fspos);
884 this.featureSettings.close();
885 this.featureSettings = null;
887 this.closeMenuItem_actionPerformed(true);
892 public void addFromText_actionPerformed(ActionEvent e)
894 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
897 public void addFromURL_actionPerformed(ActionEvent e)
899 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
902 public void save_actionPerformed(ActionEvent e)
905 || (currentFileFormat == null || !jalview.io.FormatAdapter
906 .isValidIOFormat(currentFileFormat, true))
907 || fileName.startsWith("http"))
909 saveAs_actionPerformed(null);
913 saveAlignment(fileName, currentFileFormat);
923 public void saveAs_actionPerformed(ActionEvent e)
925 JalviewFileChooser chooser = new JalviewFileChooser(
926 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
927 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
928 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
929 currentFileFormat, false);
931 chooser.setFileView(new JalviewFileView());
932 chooser.setDialogTitle("Save Alignment to file");
933 chooser.setToolTipText("Save");
935 int value = chooser.showSaveDialog(this);
937 if (value == JalviewFileChooser.APPROVE_OPTION)
939 currentFileFormat = chooser.getSelectedFormat();
940 if (currentFileFormat == null)
942 JOptionPane.showInternalMessageDialog(Desktop.desktop,
943 "You must select a file format before saving!",
944 "File format not specified", JOptionPane.WARNING_MESSAGE);
945 value = chooser.showSaveDialog(this);
949 fileName = chooser.getSelectedFile().getPath();
951 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
954 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
955 if (currentFileFormat.indexOf(" ") > -1)
957 currentFileFormat = currentFileFormat.substring(0,
958 currentFileFormat.indexOf(" "));
960 saveAlignment(fileName, currentFileFormat);
964 public boolean saveAlignment(String file, String format)
966 boolean success = true;
968 if (format.equalsIgnoreCase("Jalview"))
970 String shortName = title;
972 if (shortName.indexOf(java.io.File.separatorChar) > -1)
974 shortName = shortName.substring(shortName
975 .lastIndexOf(java.io.File.separatorChar) + 1);
978 success = new Jalview2XML().SaveAlignment(this, file, shortName);
980 statusBar.setText("Successfully saved to file: " + fileName + " in "
981 + format + " format.");
986 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
988 warningMessage("Cannot save file " + fileName + " using format "
989 + format, "Alignment output format not supported");
990 saveAs_actionPerformed(null);
991 // JBPNote need to have a raise_gui flag here
995 String[] omitHidden = null;
997 if (viewport.hasHiddenColumns)
999 int reply = JOptionPane
1000 .showInternalConfirmDialog(
1002 "The Alignment contains hidden columns."
1003 + "\nDo you want to save only the visible alignment?",
1004 "Save / Omit Hidden Columns",
1005 JOptionPane.YES_NO_OPTION,
1006 JOptionPane.QUESTION_MESSAGE);
1008 if (reply == JOptionPane.YES_OPTION)
1010 omitHidden = viewport.getViewAsString(false);
1013 FormatAdapter f = new FormatAdapter();
1014 String output = f.formatSequences(format,
1015 (Alignment) viewport.alignment, // class cast exceptions will
1016 // occur in the distant future
1017 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
1027 java.io.PrintWriter out = new java.io.PrintWriter(
1028 new java.io.FileWriter(file));
1032 this.setTitle(file);
1033 statusBar.setText("Successfully saved to file: " + fileName
1034 + " in " + format + " format.");
1035 } catch (Exception ex)
1038 ex.printStackTrace();
1045 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
1046 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
1052 private void warningMessage(String warning, String title)
1054 if (new jalview.util.Platform().isHeadless())
1056 System.err.println("Warning: " + title + "\nWarning: " + warning);
1061 JOptionPane.showInternalMessageDialog(this, warning, title,
1062 JOptionPane.WARNING_MESSAGE);
1073 protected void outputText_actionPerformed(ActionEvent e)
1075 String[] omitHidden = null;
1077 if (viewport.hasHiddenColumns)
1079 int reply = JOptionPane
1080 .showInternalConfirmDialog(
1082 "The Alignment contains hidden columns."
1083 + "\nDo you want to output only the visible alignment?",
1084 "Save / Omit Hidden Columns",
1085 JOptionPane.YES_NO_OPTION,
1086 JOptionPane.QUESTION_MESSAGE);
1088 if (reply == JOptionPane.YES_OPTION)
1090 omitHidden = viewport.getViewAsString(false);
1094 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1095 cap.setForInput(null);
1099 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1100 viewport.alignment, omitHidden, viewport.colSel));
1101 Desktop.addInternalFrame(cap,
1102 "Alignment output - " + e.getActionCommand(), 600, 500);
1103 } catch (OutOfMemoryError oom)
1105 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1117 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1119 new HTMLOutput(alignPanel,
1120 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1121 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1124 public void createImageMap(File file, String image)
1126 alignPanel.makePNGImageMap(file, image);
1135 public void createPNG(File f)
1137 alignPanel.makePNG(f);
1146 public void createEPS(File f)
1148 alignPanel.makeEPS(f);
1151 public void pageSetup_actionPerformed(ActionEvent e)
1153 PrinterJob printJob = PrinterJob.getPrinterJob();
1154 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1163 public void printMenuItem_actionPerformed(ActionEvent e)
1165 // Putting in a thread avoids Swing painting problems
1166 PrintThread thread = new PrintThread(alignPanel);
1170 public void exportFeatures_actionPerformed(ActionEvent e)
1172 new AnnotationExporter().exportFeatures(alignPanel);
1175 public void exportAnnotations_actionPerformed(ActionEvent e)
1177 new AnnotationExporter().exportAnnotations(
1179 viewport.showAnnotation ? viewport.alignment
1180 .getAlignmentAnnotation() : null, viewport.alignment
1182 ((Alignment) viewport.alignment).alignmentProperties);
1185 public void associatedData_actionPerformed(ActionEvent e)
1187 // Pick the tree file
1188 JalviewFileChooser chooser = new JalviewFileChooser(
1189 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1190 chooser.setFileView(new JalviewFileView());
1191 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1192 chooser.setToolTipText("Load Jalview Annotations / Features file");
1194 int value = chooser.showOpenDialog(null);
1196 if (value == JalviewFileChooser.APPROVE_OPTION)
1198 String choice = chooser.getSelectedFile().getPath();
1199 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1200 loadJalviewDataFile(choice, null, null, null);
1206 * Close the current view or all views in the alignment frame. If the frame
1207 * only contains one view then the alignment will be removed from memory.
1209 * @param closeAllTabs
1211 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1213 if (alignPanels != null && alignPanels.size() < 2)
1215 closeAllTabs = true;
1220 if (alignPanels != null)
1224 if (this.isClosed())
1226 // really close all the windows - otherwise wait till
1227 // setClosed(true) is called
1228 for (int i = 0; i < alignPanels.size(); i++)
1230 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1237 closeView(alignPanel);
1243 this.setClosed(true);
1245 } catch (Exception ex)
1247 ex.printStackTrace();
1252 * close alignPanel2 and shuffle tabs appropriately.
1254 * @param alignPanel2
1256 public void closeView(AlignmentPanel alignPanel2)
1258 int index = tabbedPane.getSelectedIndex();
1259 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1260 alignPanels.removeElement(alignPanel2);
1262 // if (viewport == alignPanel2.av)
1266 alignPanel2.closePanel();
1269 tabbedPane.removeTabAt(closedindex);
1270 tabbedPane.validate();
1272 if (index > closedindex || index == tabbedPane.getTabCount())
1274 // modify currently selected tab index if necessary.
1278 this.tabSelectionChanged(index);
1284 void updateEditMenuBar()
1287 if (viewport.historyList.size() > 0)
1289 undoMenuItem.setEnabled(true);
1290 CommandI command = (CommandI) viewport.historyList.peek();
1291 undoMenuItem.setText("Undo " + command.getDescription());
1295 undoMenuItem.setEnabled(false);
1296 undoMenuItem.setText("Undo");
1299 if (viewport.redoList.size() > 0)
1301 redoMenuItem.setEnabled(true);
1303 CommandI command = (CommandI) viewport.redoList.peek();
1304 redoMenuItem.setText("Redo " + command.getDescription());
1308 redoMenuItem.setEnabled(false);
1309 redoMenuItem.setText("Redo");
1313 public void addHistoryItem(CommandI command)
1315 if (command.getSize() > 0)
1317 viewport.historyList.push(command);
1318 viewport.redoList.clear();
1319 updateEditMenuBar();
1320 viewport.hasHiddenColumns = (viewport.colSel != null
1321 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1322 .getHiddenColumns().size() > 0);
1328 * @return alignment objects for all views
1330 AlignmentI[] getViewAlignments()
1332 if (alignPanels != null)
1334 Enumeration e = alignPanels.elements();
1335 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1336 for (int i = 0; e.hasMoreElements(); i++)
1338 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1342 if (viewport != null)
1344 return new AlignmentI[]
1345 { viewport.alignment };
1356 protected void undoMenuItem_actionPerformed(ActionEvent e)
1358 if (viewport.historyList.empty())
1360 CommandI command = (CommandI) viewport.historyList.pop();
1361 viewport.redoList.push(command);
1362 command.undoCommand(getViewAlignments());
1364 AlignViewport originalSource = getOriginatingSource(command);
1365 updateEditMenuBar();
1367 if (originalSource != null)
1369 originalSource.hasHiddenColumns = (viewport.colSel != null
1370 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1371 .getHiddenColumns().size() > 0);
1372 originalSource.firePropertyChange("alignment", null,
1373 originalSource.alignment.getSequences());
1383 protected void redoMenuItem_actionPerformed(ActionEvent e)
1385 if (viewport.redoList.size() < 1)
1390 CommandI command = (CommandI) viewport.redoList.pop();
1391 viewport.historyList.push(command);
1392 command.doCommand(getViewAlignments());
1394 AlignViewport originalSource = getOriginatingSource(command);
1395 updateEditMenuBar();
1397 if (originalSource != null)
1399 originalSource.hasHiddenColumns = (viewport.colSel != null
1400 && viewport.colSel.getHiddenColumns() != null && viewport.colSel
1401 .getHiddenColumns().size() > 0);
1402 originalSource.firePropertyChange("alignment", null,
1403 originalSource.alignment.getSequences());
1407 AlignViewport getOriginatingSource(CommandI command)
1409 AlignViewport originalSource = null;
1410 // For sequence removal and addition, we need to fire
1411 // the property change event FROM the viewport where the
1412 // original alignment was altered
1413 AlignmentI al = null;
1414 if (command instanceof EditCommand)
1416 EditCommand editCommand = (EditCommand) command;
1417 al = editCommand.getAlignment();
1418 Vector comps = (Vector) PaintRefresher.components.get(viewport
1419 .getSequenceSetId());
1421 for (int i = 0; i < comps.size(); i++)
1423 if (comps.elementAt(i) instanceof AlignmentPanel)
1425 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1427 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1434 if (originalSource == null)
1436 // The original view is closed, we must validate
1437 // the current view against the closed view first
1440 PaintRefresher.validateSequences(al, viewport.alignment);
1443 originalSource = viewport;
1446 return originalSource;
1455 public void moveSelectedSequences(boolean up)
1457 SequenceGroup sg = viewport.getSelectionGroup();
1466 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1468 SequenceI seq = viewport.alignment.getSequenceAt(i);
1470 if (!sg.getSequences(null).contains(seq))
1475 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1477 if (sg.getSequences(null).contains(temp))
1482 viewport.alignment.getSequences().setElementAt(temp, i);
1483 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1488 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1490 SequenceI seq = viewport.alignment.getSequenceAt(i);
1492 if (!sg.getSequences(null).contains(seq))
1497 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1499 if (sg.getSequences(null).contains(temp))
1504 viewport.alignment.getSequences().setElementAt(temp, i);
1505 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1509 alignPanel.paintAlignment(true);
1512 synchronized void slideSequences(boolean right, int size)
1514 Vector sg = new Vector();
1515 if (viewport.cursorMode)
1517 sg.addElement(viewport.alignment
1518 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1520 else if (viewport.getSelectionGroup() != null
1521 && viewport.getSelectionGroup().getSize() != viewport.alignment
1524 sg = viewport.getSelectionGroup().getSequences(
1525 viewport.hiddenRepSequences);
1533 Vector invertGroup = new Vector();
1535 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1537 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1538 invertGroup.add(viewport.alignment.getSequenceAt(i));
1541 SequenceI[] seqs1 = new SequenceI[sg.size()];
1542 for (int i = 0; i < sg.size(); i++)
1543 seqs1[i] = (SequenceI) sg.elementAt(i);
1545 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1546 for (int i = 0; i < invertGroup.size(); i++)
1547 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1549 SlideSequencesCommand ssc;
1551 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1552 size, viewport.getGapCharacter());
1554 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1555 size, viewport.getGapCharacter());
1557 int groupAdjustment = 0;
1558 if (ssc.getGapsInsertedBegin() && right)
1560 if (viewport.cursorMode)
1561 alignPanel.seqPanel.moveCursor(size, 0);
1563 groupAdjustment = size;
1565 else if (!ssc.getGapsInsertedBegin() && !right)
1567 if (viewport.cursorMode)
1568 alignPanel.seqPanel.moveCursor(-size, 0);
1570 groupAdjustment = -size;
1573 if (groupAdjustment != 0)
1575 viewport.getSelectionGroup().setStartRes(
1576 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1577 viewport.getSelectionGroup().setEndRes(
1578 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1581 boolean appendHistoryItem = false;
1582 if (viewport.historyList != null && viewport.historyList.size() > 0
1583 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1585 appendHistoryItem = ssc
1586 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1590 if (!appendHistoryItem)
1591 addHistoryItem(ssc);
1602 protected void copy_actionPerformed(ActionEvent e)
1605 if (viewport.getSelectionGroup() == null)
1609 // TODO: preserve the ordering of displayed alignment annotation in any
1610 // internal paste (particularly sequence associated annotation)
1611 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1612 String[] omitHidden = null;
1614 if (viewport.hasHiddenColumns)
1616 omitHidden = viewport.getViewAsString(true);
1619 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1622 StringSelection ss = new StringSelection(output);
1626 jalview.gui.Desktop.internalCopy = true;
1627 // Its really worth setting the clipboard contents
1628 // to empty before setting the large StringSelection!!
1629 Toolkit.getDefaultToolkit().getSystemClipboard()
1630 .setContents(new StringSelection(""), null);
1632 Toolkit.getDefaultToolkit().getSystemClipboard()
1633 .setContents(ss, Desktop.instance);
1634 } catch (OutOfMemoryError er)
1636 new OOMWarning("copying region", er);
1640 Vector hiddenColumns = null;
1641 if (viewport.hasHiddenColumns)
1643 hiddenColumns = new Vector();
1644 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1645 .getSelectionGroup().getEndRes();
1646 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1649 int[] region = (int[]) viewport.getColumnSelection()
1650 .getHiddenColumns().elementAt(i);
1651 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1653 hiddenColumns.addElement(new int[]
1654 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1659 Desktop.jalviewClipboard = new Object[]
1660 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1661 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1670 protected void pasteNew_actionPerformed(ActionEvent e)
1681 protected void pasteThis_actionPerformed(ActionEvent e)
1687 * Paste contents of Jalview clipboard
1689 * @param newAlignment
1690 * true to paste to a new alignment, otherwise add to this.
1692 void paste(boolean newAlignment)
1694 boolean externalPaste = true;
1697 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1698 Transferable contents = c.getContents(this);
1700 if (contents == null)
1708 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1709 if (str.length() < 1)
1714 format = new IdentifyFile().Identify(str, "Paste");
1716 } catch (OutOfMemoryError er)
1718 new OOMWarning("Out of memory pasting sequences!!", er);
1722 SequenceI[] sequences;
1723 boolean annotationAdded = false;
1724 AlignmentI alignment = null;
1726 if (Desktop.jalviewClipboard != null)
1728 // The clipboard was filled from within Jalview, we must use the
1730 // And dataset from the copied alignment
1731 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1732 // be doubly sure that we create *new* sequence objects.
1733 sequences = new SequenceI[newseq.length];
1734 for (int i = 0; i < newseq.length; i++)
1736 sequences[i] = new Sequence(newseq[i]);
1738 alignment = new Alignment(sequences);
1739 externalPaste = false;
1743 // parse the clipboard as an alignment.
1744 alignment = new FormatAdapter().readFile(str, "Paste", format);
1745 sequences = alignment.getSequencesArray();
1753 if (Desktop.jalviewClipboard != null)
1755 // dataset is inherited
1756 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1760 // new dataset is constructed
1761 alignment.setDataset(null);
1763 alwidth = alignment.getWidth() + 1;
1767 AlignmentI pastedal = alignment; // preserve pasted alignment object
1768 // Add pasted sequences and dataset into existing alignment.
1769 alignment = viewport.getAlignment();
1770 alwidth = alignment.getWidth() + 1;
1771 // decide if we need to import sequences from an existing dataset
1772 boolean importDs = Desktop.jalviewClipboard != null
1773 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1774 // importDs==true instructs us to copy over new dataset sequences from
1775 // an existing alignment
1776 Vector newDs = (importDs) ? new Vector() : null; // used to create
1777 // minimum dataset set
1779 for (int i = 0; i < sequences.length; i++)
1783 newDs.addElement(null);
1785 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1787 if (importDs && ds != null)
1789 if (!newDs.contains(ds))
1791 newDs.setElementAt(ds, i);
1792 ds = new Sequence(ds);
1793 // update with new dataset sequence
1794 sequences[i].setDatasetSequence(ds);
1798 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1803 // copy and derive new dataset sequence
1804 sequences[i] = sequences[i].deriveSequence();
1805 alignment.getDataset().addSequence(
1806 sequences[i].getDatasetSequence());
1807 // TODO: avoid creation of duplicate dataset sequences with a
1808 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1810 alignment.addSequence(sequences[i]); // merges dataset
1814 newDs.clear(); // tidy up
1816 if (pastedal.getAlignmentAnnotation() != null)
1818 // Add any annotation attached to alignment.
1819 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1820 for (int i = 0; i < alann.length; i++)
1822 annotationAdded = true;
1823 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1825 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1826 newann.padAnnotation(alwidth);
1827 alignment.addAnnotation(newann);
1837 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1838 sequences, 0, alignment.getWidth(), alignment));
1840 // Add any annotations attached to sequences
1841 for (int i = 0; i < sequences.length; i++)
1843 if (sequences[i].getAnnotation() != null)
1845 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1847 annotationAdded = true;
1848 sequences[i].getAnnotation()[a].adjustForAlignment();
1849 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1850 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1855 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1862 // propagate alignment changed.
1863 viewport.setEndSeq(alignment.getHeight());
1864 if (annotationAdded)
1866 // Duplicate sequence annotation in all views.
1867 AlignmentI[] alview = this.getViewAlignments();
1868 for (int i = 0; i < sequences.length; i++)
1870 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1873 for (int avnum = 0; avnum < alview.length; avnum++)
1875 if (alview[avnum] != alignment)
1877 // duplicate in a view other than the one with input focus
1878 int avwidth = alview[avnum].getWidth() + 1;
1879 // this relies on sann being preserved after we
1880 // modify the sequence's annotation array for each duplication
1881 for (int a = 0; a < sann.length; a++)
1883 AlignmentAnnotation newann = new AlignmentAnnotation(
1885 sequences[i].addAlignmentAnnotation(newann);
1886 newann.padAnnotation(avwidth);
1887 alview[avnum].addAnnotation(newann); // annotation was
1888 // duplicated earlier
1889 alview[avnum].setAnnotationIndex(newann, a);
1894 buildSortByAnnotationScoresMenu();
1896 viewport.firePropertyChange("alignment", null,
1897 alignment.getSequences());
1902 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1904 String newtitle = new String("Copied sequences");
1906 if (Desktop.jalviewClipboard != null
1907 && Desktop.jalviewClipboard[2] != null)
1909 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1910 for (int i = 0; i < hc.size(); i++)
1912 int[] region = (int[]) hc.elementAt(i);
1913 af.viewport.hideColumns(region[0], region[1]);
1917 // >>>This is a fix for the moment, until a better solution is
1919 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1921 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1923 // TODO: maintain provenance of an alignment, rather than just make the
1924 // title a concatenation of operations.
1927 if (title.startsWith("Copied sequences"))
1933 newtitle = newtitle.concat("- from " + title);
1938 newtitle = new String("Pasted sequences");
1941 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1946 } catch (Exception ex)
1948 ex.printStackTrace();
1949 System.out.println("Exception whilst pasting: " + ex);
1950 // could be anything being pasted in here
1961 protected void cut_actionPerformed(ActionEvent e)
1963 copy_actionPerformed(null);
1964 delete_actionPerformed(null);
1973 protected void delete_actionPerformed(ActionEvent evt)
1976 SequenceGroup sg = viewport.getSelectionGroup();
1982 Vector seqs = new Vector();
1984 for (int i = 0; i < sg.getSize(); i++)
1986 seq = sg.getSequenceAt(i);
1987 seqs.addElement(seq);
1990 // If the cut affects all sequences, remove highlighted columns
1991 if (sg.getSize() == viewport.alignment.getHeight())
1993 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1994 sg.getEndRes() + 1);
1997 SequenceI[] cut = new SequenceI[seqs.size()];
1998 for (int i = 0; i < seqs.size(); i++)
2000 cut[i] = (SequenceI) seqs.elementAt(i);
2004 * //ADD HISTORY ITEM
2006 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2007 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2008 viewport.alignment));
2010 viewport.setSelectionGroup(null);
2011 viewport.sendSelection();
2012 viewport.alignment.deleteGroup(sg);
2014 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2016 if (viewport.getAlignment().getHeight() < 1)
2020 this.setClosed(true);
2021 } catch (Exception ex)
2033 protected void deleteGroups_actionPerformed(ActionEvent e)
2035 viewport.alignment.deleteAllGroups();
2036 viewport.sequenceColours = null;
2037 viewport.setSelectionGroup(null);
2038 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2039 alignPanel.updateAnnotation();
2040 alignPanel.paintAlignment(true);
2049 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2051 SequenceGroup sg = new SequenceGroup();
2053 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2055 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2058 sg.setEndRes(viewport.alignment.getWidth() - 1);
2059 viewport.setSelectionGroup(sg);
2060 viewport.sendSelection();
2061 alignPanel.paintAlignment(true);
2062 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2071 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2073 if (viewport.cursorMode)
2075 alignPanel.seqPanel.keyboardNo1 = null;
2076 alignPanel.seqPanel.keyboardNo2 = null;
2078 viewport.setSelectionGroup(null);
2079 viewport.getColumnSelection().clear();
2080 viewport.setSelectionGroup(null);
2081 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2082 alignPanel.idPanel.idCanvas.searchResults = null;
2083 alignPanel.paintAlignment(true);
2084 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2085 viewport.sendSelection();
2094 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2096 SequenceGroup sg = viewport.getSelectionGroup();
2100 selectAllSequenceMenuItem_actionPerformed(null);
2105 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2107 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2110 alignPanel.paintAlignment(true);
2111 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2112 viewport.sendSelection();
2115 public void invertColSel_actionPerformed(ActionEvent e)
2117 viewport.invertColumnSelection();
2118 alignPanel.paintAlignment(true);
2119 viewport.sendSelection();
2128 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2130 trimAlignment(true);
2139 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2141 trimAlignment(false);
2144 void trimAlignment(boolean trimLeft)
2146 ColumnSelection colSel = viewport.getColumnSelection();
2149 if (colSel.size() > 0)
2153 column = colSel.getMin();
2157 column = colSel.getMax();
2161 if (viewport.getSelectionGroup() != null)
2163 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2164 viewport.hiddenRepSequences);
2168 seqs = viewport.alignment.getSequencesArray();
2171 TrimRegionCommand trimRegion;
2174 trimRegion = new TrimRegionCommand("Remove Left",
2175 TrimRegionCommand.TRIM_LEFT, seqs, column,
2176 viewport.alignment, viewport.colSel,
2177 viewport.selectionGroup);
2178 viewport.setStartRes(0);
2182 trimRegion = new TrimRegionCommand("Remove Right",
2183 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2184 viewport.alignment, viewport.colSel,
2185 viewport.selectionGroup);
2188 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2190 addHistoryItem(trimRegion);
2192 Vector groups = viewport.alignment.getGroups();
2194 for (int i = 0; i < groups.size(); i++)
2196 SequenceGroup sg = (SequenceGroup) groups.get(i);
2198 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2199 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2201 viewport.alignment.deleteGroup(sg);
2205 viewport.firePropertyChange("alignment", null, viewport
2206 .getAlignment().getSequences());
2216 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2218 int start = 0, end = viewport.alignment.getWidth() - 1;
2221 if (viewport.getSelectionGroup() != null)
2223 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2224 viewport.hiddenRepSequences);
2225 start = viewport.getSelectionGroup().getStartRes();
2226 end = viewport.getSelectionGroup().getEndRes();
2230 seqs = viewport.alignment.getSequencesArray();
2233 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2234 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2236 addHistoryItem(removeGapCols);
2238 statusBar.setText("Removed " + removeGapCols.getSize()
2239 + " empty columns.");
2241 // This is to maintain viewport position on first residue
2242 // of first sequence
2243 SequenceI seq = viewport.alignment.getSequenceAt(0);
2244 int startRes = seq.findPosition(viewport.startRes);
2245 // ShiftList shifts;
2246 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2247 // edit.alColumnChanges=shifts.getInverse();
2248 // if (viewport.hasHiddenColumns)
2249 // viewport.getColumnSelection().compensateForEdits(shifts);
2250 viewport.setStartRes(seq.findIndex(startRes) - 1);
2251 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2262 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2264 int start = 0, end = viewport.alignment.getWidth() - 1;
2267 if (viewport.getSelectionGroup() != null)
2269 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2270 viewport.hiddenRepSequences);
2271 start = viewport.getSelectionGroup().getStartRes();
2272 end = viewport.getSelectionGroup().getEndRes();
2276 seqs = viewport.alignment.getSequencesArray();
2279 // This is to maintain viewport position on first residue
2280 // of first sequence
2281 SequenceI seq = viewport.alignment.getSequenceAt(0);
2282 int startRes = seq.findPosition(viewport.startRes);
2284 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2285 viewport.alignment));
2287 viewport.setStartRes(seq.findIndex(startRes) - 1);
2289 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2300 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2302 viewport.padGaps = padGapsMenuitem.isSelected();
2303 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2309 // if (justifySeqs>0)
2311 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2323 public void findMenuItem_actionPerformed(ActionEvent e)
2328 public void newView_actionPerformed(ActionEvent e)
2335 * @param copyAnnotation
2336 * if true then duplicate all annnotation, groups and settings
2337 * @return new alignment panel, already displayed.
2339 public AlignmentPanel newView(boolean copyAnnotation)
2341 return newView(null, copyAnnotation);
2347 * title of newly created view
2348 * @return new alignment panel, already displayed.
2350 public AlignmentPanel newView(String viewTitle)
2352 return newView(viewTitle, true);
2358 * title of newly created view
2359 * @param copyAnnotation
2360 * if true then duplicate all annnotation, groups and settings
2361 * @return new alignment panel, already displayed.
2363 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2365 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2367 if (!copyAnnotation)
2369 // just remove all the current annotation except for the automatic stuff
2370 newap.av.alignment.deleteAllGroups();
2371 for (AlignmentAnnotation alan : newap.av.alignment
2372 .getAlignmentAnnotation())
2374 if (!alan.autoCalculated)
2376 newap.av.alignment.deleteAnnotation(alan);
2382 newap.av.gatherViewsHere = false;
2384 if (viewport.viewName == null)
2386 viewport.viewName = "Original";
2389 newap.av.historyList = viewport.historyList;
2390 newap.av.redoList = viewport.redoList;
2392 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2393 // make sure the new view has a unique name - this is essential for Jalview
2395 boolean addFirstIndex = false;
2396 if (viewTitle == null || viewTitle.trim().length() == 0)
2399 addFirstIndex = true;
2403 index = 1;// we count from 1 if given a specific name
2405 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2406 Vector comps = (Vector) PaintRefresher.components.get(viewport
2407 .getSequenceSetId());
2408 Vector existingNames = new Vector();
2409 for (int i = 0; i < comps.size(); i++)
2411 if (comps.elementAt(i) instanceof AlignmentPanel)
2413 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2414 if (!existingNames.contains(ap.av.viewName))
2416 existingNames.addElement(ap.av.viewName);
2421 while (existingNames.contains(newViewName))
2423 newViewName = viewTitle + " " + (++index);
2426 newap.av.viewName = newViewName;
2428 addAlignmentPanel(newap, true);
2430 if (alignPanels.size() == 2)
2432 viewport.gatherViewsHere = true;
2434 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2438 public void expandViews_actionPerformed(ActionEvent e)
2440 Desktop.instance.explodeViews(this);
2443 public void gatherViews_actionPerformed(ActionEvent e)
2445 Desktop.instance.gatherViews(this);
2454 public void font_actionPerformed(ActionEvent e)
2456 new FontChooser(alignPanel);
2465 protected void seqLimit_actionPerformed(ActionEvent e)
2467 viewport.setShowJVSuffix(seqLimits.isSelected());
2469 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2470 .calculateIdWidth());
2471 alignPanel.paintAlignment(true);
2474 public void idRightAlign_actionPerformed(ActionEvent e)
2476 viewport.rightAlignIds = idRightAlign.isSelected();
2477 alignPanel.paintAlignment(true);
2480 public void centreColumnLabels_actionPerformed(ActionEvent e)
2482 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2483 alignPanel.paintAlignment(true);
2489 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2491 protected void followHighlight_actionPerformed()
2493 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2495 alignPanel.scrollToPosition(
2496 alignPanel.seqPanel.seqCanvas.searchResults, false);
2506 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2508 viewport.setColourText(colourTextMenuItem.isSelected());
2509 alignPanel.paintAlignment(true);
2518 public void wrapMenuItem_actionPerformed(ActionEvent e)
2520 scaleAbove.setVisible(wrapMenuItem.isSelected());
2521 scaleLeft.setVisible(wrapMenuItem.isSelected());
2522 scaleRight.setVisible(wrapMenuItem.isSelected());
2523 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2524 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2527 public void showAllSeqs_actionPerformed(ActionEvent e)
2529 viewport.showAllHiddenSeqs();
2532 public void showAllColumns_actionPerformed(ActionEvent e)
2534 viewport.showAllHiddenColumns();
2538 public void hideSelSequences_actionPerformed(ActionEvent e)
2540 viewport.hideAllSelectedSeqs();
2541 alignPanel.paintAlignment(true);
2545 * called by key handler and the hide all/show all menu items
2550 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2553 boolean hide = false;
2554 SequenceGroup sg = viewport.getSelectionGroup();
2555 if (!toggleSeqs && !toggleCols)
2557 // Hide everything by the current selection - this is a hack - we do the
2558 // invert and then hide
2559 // first check that there will be visible columns after the invert.
2560 if ((viewport.colSel != null && viewport.colSel.getSelected() != null && viewport.colSel
2561 .getSelected().size() > 0)
2562 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2565 // now invert the sequence set, if required - empty selection implies
2566 // that no hiding is required.
2569 invertSequenceMenuItem_actionPerformed(null);
2570 sg = viewport.getSelectionGroup();
2574 viewport.expandColSelection(sg, true);
2575 // finally invert the column selection and get the new sequence
2577 invertColSel_actionPerformed(null);
2584 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
2586 hideSelSequences_actionPerformed(null);
2589 else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))
2591 showAllSeqs_actionPerformed(null);
2597 if (viewport.colSel.getSelected().size() > 0)
2599 hideSelColumns_actionPerformed(null);
2602 viewport.selectionGroup = sg;
2607 showAllColumns_actionPerformed(null);
2616 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2617 * event.ActionEvent)
2619 public void hideAllButSelection_actionPerformed(ActionEvent e)
2621 toggleHiddenRegions(false, false);
2628 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2631 public void hideAllSelection_actionPerformed(ActionEvent e)
2633 SequenceGroup sg = viewport.getSelectionGroup();
2634 viewport.expandColSelection(sg, false);
2635 viewport.hideAllSelectedSeqs();
2636 viewport.hideSelectedColumns();
2637 alignPanel.paintAlignment(true);
2644 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2647 public void showAllhidden_actionPerformed(ActionEvent e)
2649 viewport.showAllHiddenColumns();
2650 viewport.showAllHiddenSeqs();
2651 alignPanel.paintAlignment(true);
2654 public void hideSelColumns_actionPerformed(ActionEvent e)
2656 viewport.hideSelectedColumns();
2657 alignPanel.paintAlignment(true);
2660 public void hiddenMarkers_actionPerformed(ActionEvent e)
2662 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2672 protected void scaleAbove_actionPerformed(ActionEvent e)
2674 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2675 alignPanel.paintAlignment(true);
2684 protected void scaleLeft_actionPerformed(ActionEvent e)
2686 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2687 alignPanel.paintAlignment(true);
2696 protected void scaleRight_actionPerformed(ActionEvent e)
2698 viewport.setScaleRightWrapped(scaleRight.isSelected());
2699 alignPanel.paintAlignment(true);
2708 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2710 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2711 alignPanel.paintAlignment(true);
2720 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2722 viewport.setShowText(viewTextMenuItem.isSelected());
2723 alignPanel.paintAlignment(true);
2732 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2734 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2735 alignPanel.paintAlignment(true);
2738 public FeatureSettings featureSettings;
2740 public void featureSettings_actionPerformed(ActionEvent e)
2742 if (featureSettings != null)
2744 featureSettings.close();
2745 featureSettings = null;
2747 if (!showSeqFeatures.isSelected())
2749 // make sure features are actually displayed
2750 showSeqFeatures.setSelected(true);
2751 showSeqFeatures_actionPerformed(null);
2753 featureSettings = new FeatureSettings(this);
2757 * Set or clear 'Show Sequence Features'
2762 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2764 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2765 alignPanel.paintAlignment(true);
2766 if (alignPanel.getOverviewPanel() != null)
2768 alignPanel.getOverviewPanel().updateOverviewImage();
2773 * Set or clear 'Show Sequence Features'
2778 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2780 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2782 if (viewport.getShowSequenceFeaturesHeight())
2784 // ensure we're actually displaying features
2785 viewport.setShowSequenceFeatures(true);
2786 showSeqFeatures.setSelected(true);
2788 alignPanel.paintAlignment(true);
2789 if (alignPanel.getOverviewPanel() != null)
2791 alignPanel.getOverviewPanel().updateOverviewImage();
2801 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2803 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2804 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2807 public void alignmentProperties()
2809 JEditorPane editPane = new JEditorPane("text/html", "");
2810 editPane.setEditable(false);
2811 StringBuffer contents = new AlignmentProperties(viewport.alignment)
2813 editPane.setText("<html>" + contents.toString() + "</html>");
2814 JInternalFrame frame = new JInternalFrame();
2815 frame.getContentPane().add(new JScrollPane(editPane));
2817 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2818 + getTitle(), 500, 400);
2827 public void overviewMenuItem_actionPerformed(ActionEvent e)
2829 if (alignPanel.overviewPanel != null)
2834 JInternalFrame frame = new JInternalFrame();
2835 OverviewPanel overview = new OverviewPanel(alignPanel);
2836 frame.setContentPane(overview);
2837 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2838 frame.getWidth(), frame.getHeight());
2840 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2841 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2843 public void internalFrameClosed(
2844 javax.swing.event.InternalFrameEvent evt)
2846 alignPanel.setOverviewPanel(null);
2850 alignPanel.setOverviewPanel(overview);
2853 public void textColour_actionPerformed(ActionEvent e)
2855 new TextColourChooser().chooseColour(alignPanel, null);
2864 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2875 public void clustalColour_actionPerformed(ActionEvent e)
2877 changeColour(new ClustalxColourScheme(
2878 viewport.alignment.getSequences(),
2879 viewport.alignment.getWidth()));
2888 public void zappoColour_actionPerformed(ActionEvent e)
2890 changeColour(new ZappoColourScheme());
2899 public void taylorColour_actionPerformed(ActionEvent e)
2901 changeColour(new TaylorColourScheme());
2910 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2912 changeColour(new HydrophobicColourScheme());
2921 public void helixColour_actionPerformed(ActionEvent e)
2923 changeColour(new HelixColourScheme());
2932 public void strandColour_actionPerformed(ActionEvent e)
2934 changeColour(new StrandColourScheme());
2943 public void turnColour_actionPerformed(ActionEvent e)
2945 changeColour(new TurnColourScheme());
2954 public void buriedColour_actionPerformed(ActionEvent e)
2956 changeColour(new BuriedColourScheme());
2965 public void nucleotideColour_actionPerformed(ActionEvent e)
2967 changeColour(new NucleotideColourScheme());
2970 public void annotationColour_actionPerformed(ActionEvent e)
2972 new AnnotationColourChooser(viewport, alignPanel);
2981 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2983 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2992 public void changeColour(ColourSchemeI cs)
2998 if (viewport.getAbovePIDThreshold())
3000 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3003 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3005 viewport.setGlobalColourScheme(cs);
3009 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3012 if (viewport.getConservationSelected())
3015 Alignment al = (Alignment) viewport.alignment;
3016 Conservation c = new Conservation("All",
3017 ResidueProperties.propHash, 3, al.getSequences(), 0,
3021 c.verdict(false, viewport.ConsPercGaps);
3023 cs.setConservation(c);
3025 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3030 cs.setConservation(null);
3033 cs.setConsensus(viewport.hconsensus);
3036 viewport.setGlobalColourScheme(cs);
3038 if (viewport.getColourAppliesToAllGroups())
3040 Vector groups = viewport.alignment.getGroups();
3042 for (int i = 0; i < groups.size(); i++)
3044 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
3052 if (cs instanceof ClustalxColourScheme)
3054 sg.cs = new ClustalxColourScheme(
3055 sg.getSequences(viewport.hiddenRepSequences),
3058 else if (cs instanceof UserColourScheme)
3060 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3066 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
3067 } catch (Exception ex)
3072 if (viewport.getAbovePIDThreshold()
3073 || cs instanceof PIDColourScheme
3074 || cs instanceof Blosum62ColourScheme)
3076 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3078 sg.cs.setConsensus(AAFrequency.calculate(
3079 sg.getSequences(viewport.hiddenRepSequences),
3080 sg.getStartRes(), sg.getEndRes() + 1));
3084 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3087 if (viewport.getConservationSelected())
3089 Conservation c = new Conservation("Group",
3090 ResidueProperties.propHash, 3,
3091 sg.getSequences(viewport.hiddenRepSequences),
3092 sg.getStartRes(), sg.getEndRes() + 1);
3094 c.verdict(false, viewport.ConsPercGaps);
3095 sg.cs.setConservation(c);
3099 sg.cs.setConservation(null);
3104 if (alignPanel.getOverviewPanel() != null)
3106 alignPanel.getOverviewPanel().updateOverviewImage();
3109 alignPanel.paintAlignment(true);
3118 protected void modifyPID_actionPerformed(ActionEvent e)
3120 if (viewport.getAbovePIDThreshold()
3121 && viewport.globalColourScheme != null)
3123 SliderPanel.setPIDSliderSource(alignPanel,
3124 viewport.getGlobalColourScheme(), "Background");
3125 SliderPanel.showPIDSlider();
3135 protected void modifyConservation_actionPerformed(ActionEvent e)
3137 if (viewport.getConservationSelected()
3138 && viewport.globalColourScheme != null)
3140 SliderPanel.setConservationSlider(alignPanel,
3141 viewport.globalColourScheme, "Background");
3142 SliderPanel.showConservationSlider();
3152 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3154 viewport.setConservationSelected(conservationMenuItem.isSelected());
3156 viewport.setAbovePIDThreshold(false);
3157 abovePIDThreshold.setSelected(false);
3159 changeColour(viewport.getGlobalColourScheme());
3161 modifyConservation_actionPerformed(null);
3170 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3172 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3174 conservationMenuItem.setSelected(false);
3175 viewport.setConservationSelected(false);
3177 changeColour(viewport.getGlobalColourScheme());
3179 modifyPID_actionPerformed(null);
3188 public void userDefinedColour_actionPerformed(ActionEvent e)
3190 if (e.getActionCommand().equals("User Defined..."))
3192 new UserDefinedColours(alignPanel, null);
3196 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3197 .getUserColourSchemes().get(e.getActionCommand());
3203 public void updateUserColourMenu()
3206 Component[] menuItems = colourMenu.getMenuComponents();
3207 int i, iSize = menuItems.length;
3208 for (i = 0; i < iSize; i++)
3210 if (menuItems[i].getName() != null
3211 && menuItems[i].getName().equals("USER_DEFINED"))
3213 colourMenu.remove(menuItems[i]);
3217 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3219 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3220 .getUserColourSchemes().keys();
3222 while (userColours.hasMoreElements())
3224 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3225 userColours.nextElement().toString());
3226 radioItem.setName("USER_DEFINED");
3227 radioItem.addMouseListener(new MouseAdapter()
3229 public void mousePressed(MouseEvent evt)
3231 if (evt.isControlDown()
3232 || SwingUtilities.isRightMouseButton(evt))
3234 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3236 int option = JOptionPane.showInternalConfirmDialog(
3237 jalview.gui.Desktop.desktop,
3238 "Remove from default list?",
3239 "Remove user defined colour",
3240 JOptionPane.YES_NO_OPTION);
3241 if (option == JOptionPane.YES_OPTION)
3243 jalview.gui.UserDefinedColours
3244 .removeColourFromDefaults(radioItem.getText());
3245 colourMenu.remove(radioItem);
3249 radioItem.addActionListener(new ActionListener()
3251 public void actionPerformed(ActionEvent evt)
3253 userDefinedColour_actionPerformed(evt);
3260 radioItem.addActionListener(new ActionListener()
3262 public void actionPerformed(ActionEvent evt)
3264 userDefinedColour_actionPerformed(evt);
3268 colourMenu.insert(radioItem, 15);
3269 colours.add(radioItem);
3280 public void PIDColour_actionPerformed(ActionEvent e)
3282 changeColour(new PIDColourScheme());
3291 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3293 changeColour(new Blosum62ColourScheme());
3302 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3304 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3305 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3306 .getAlignment().getSequenceAt(0), null);
3307 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3308 viewport.alignment));
3309 alignPanel.paintAlignment(true);
3318 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3320 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3321 AlignmentSorter.sortByID(viewport.getAlignment());
3322 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
3323 alignPanel.paintAlignment(true);
3332 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3334 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3335 AlignmentSorter.sortByLength(viewport.getAlignment());
3336 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3337 viewport.alignment));
3338 alignPanel.paintAlignment(true);
3347 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3349 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3350 AlignmentSorter.sortByGroup(viewport.getAlignment());
3351 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3352 viewport.alignment));
3354 alignPanel.paintAlignment(true);
3363 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3365 new RedundancyPanel(alignPanel, this);
3374 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3376 if ((viewport.getSelectionGroup() == null)
3377 || (viewport.getSelectionGroup().getSize() < 2))
3379 JOptionPane.showInternalMessageDialog(this,
3380 "You must select at least 2 sequences.", "Invalid Selection",
3381 JOptionPane.WARNING_MESSAGE);
3385 JInternalFrame frame = new JInternalFrame();
3386 frame.setContentPane(new PairwiseAlignPanel(viewport));
3387 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3397 public void PCAMenuItem_actionPerformed(ActionEvent e)
3399 if (((viewport.getSelectionGroup() != null)
3400 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3401 .getSelectionGroup().getSize() > 0))
3402 || (viewport.getAlignment().getHeight() < 4))
3404 JOptionPane.showInternalMessageDialog(this,
3405 "Principal component analysis must take\n"
3406 + "at least 4 input sequences.",
3407 "Sequence selection insufficient",
3408 JOptionPane.WARNING_MESSAGE);
3413 new PCAPanel(alignPanel);
3416 public void autoCalculate_actionPerformed(ActionEvent e)
3418 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3419 if (viewport.autoCalculateConsensus)
3421 viewport.firePropertyChange("alignment", null, viewport
3422 .getAlignment().getSequences());
3425 public void sortByTreeOption_actionPerformed(ActionEvent e)
3427 viewport.sortByTree = sortByTree.isSelected();
3436 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3438 NewTreePanel("AV", "PID", "Average distance tree using PID");
3447 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3449 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3458 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3460 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3469 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3471 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3484 void NewTreePanel(String type, String pwType, String title)
3488 if (viewport.getSelectionGroup() != null)
3490 if (viewport.getSelectionGroup().getSize() < 3)
3495 "You need to have more than two sequences selected to build a tree!",
3496 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3501 SequenceGroup sg = viewport.getSelectionGroup();
3503 /* Decide if the selection is a column region */
3504 while (s < sg.getSize())
3506 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3512 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3513 + "Try using the Pad function in the edit menu,\n"
3514 + "or one of the multiple sequence alignment web services.",
3515 "Sequences in selection are not aligned",
3516 JOptionPane.WARNING_MESSAGE);
3522 title = title + " on region";
3523 tp = new TreePanel(alignPanel, type, pwType);
3527 // are the visible sequences aligned?
3528 if (!viewport.alignment.isAligned(false))
3533 "The sequences must be aligned before creating a tree.\n"
3534 + "Try using the Pad function in the edit menu,\n"
3535 + "or one of the multiple sequence alignment web services.",
3536 "Sequences not aligned",
3537 JOptionPane.WARNING_MESSAGE);
3542 if (viewport.alignment.getHeight() < 2)
3547 tp = new TreePanel(alignPanel, type, pwType);
3552 if (viewport.viewName != null)
3554 title += viewport.viewName + " of ";
3557 title += this.title;
3559 Desktop.addInternalFrame(tp, title, 600, 500);
3570 public void addSortByOrderMenuItem(String title,
3571 final AlignmentOrder order)
3573 final JMenuItem item = new JMenuItem("by " + title);
3575 item.addActionListener(new java.awt.event.ActionListener()
3577 public void actionPerformed(ActionEvent e)
3579 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3581 // TODO: JBPNote - have to map order entries to curent SequenceI
3583 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3585 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3586 viewport.alignment));
3588 alignPanel.paintAlignment(true);
3594 * Add a new sort by annotation score menu item
3597 * the menu to add the option to
3599 * the label used to retrieve scores for each sequence on the
3602 public void addSortByAnnotScoreMenuItem(JMenu sort,
3603 final String scoreLabel)
3605 final JMenuItem item = new JMenuItem(scoreLabel);
3607 item.addActionListener(new java.awt.event.ActionListener()
3609 public void actionPerformed(ActionEvent e)
3611 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3612 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3613 viewport.getAlignment());// ,viewport.getSelectionGroup());
3614 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3615 viewport.alignment));
3616 alignPanel.paintAlignment(true);
3622 * last hash for alignment's annotation array - used to minimise cost of
3625 protected int _annotationScoreVectorHash;
3628 * search the alignment and rebuild the sort by annotation score submenu the
3629 * last alignment annotation vector hash is stored to minimize cost of
3630 * rebuilding in subsequence calls.
3633 public void buildSortByAnnotationScoresMenu()
3635 if (viewport.alignment.getAlignmentAnnotation() == null)
3640 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3642 sortByAnnotScore.removeAll();
3643 // almost certainly a quicker way to do this - but we keep it simple
3644 Hashtable scoreSorts = new Hashtable();
3645 AlignmentAnnotation aann[];
3646 Enumeration sq = viewport.alignment.getSequences().elements();
3647 while (sq.hasMoreElements())
3649 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3650 for (int i = 0; aann != null && i < aann.length; i++)
3652 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3654 scoreSorts.put(aann[i].label, aann[i].label);
3658 Enumeration labels = scoreSorts.keys();
3659 while (labels.hasMoreElements())
3661 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3662 (String) labels.nextElement());
3664 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3667 _annotationScoreVectorHash = viewport.alignment
3668 .getAlignmentAnnotation().hashCode();
3673 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3674 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3675 * call. Listeners are added to remove the menu item when the treePanel is
3676 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3680 * Displayed tree window.
3682 * SortBy menu item title.
3684 public void buildTreeMenu()
3686 sortByTreeMenu.removeAll();
3688 Vector comps = (Vector) PaintRefresher.components.get(viewport
3689 .getSequenceSetId());
3690 Vector treePanels = new Vector();
3691 int i, iSize = comps.size();
3692 for (i = 0; i < iSize; i++)
3694 if (comps.elementAt(i) instanceof TreePanel)
3696 treePanels.add(comps.elementAt(i));
3700 iSize = treePanels.size();
3704 sortByTreeMenu.setVisible(false);
3708 sortByTreeMenu.setVisible(true);
3710 for (i = 0; i < treePanels.size(); i++)
3712 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3713 final JMenuItem item = new JMenuItem(tp.getTitle());
3714 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3715 item.addActionListener(new java.awt.event.ActionListener()
3717 public void actionPerformed(ActionEvent e)
3719 tp.sortByTree_actionPerformed(null);
3720 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3725 sortByTreeMenu.add(item);
3729 public boolean sortBy(AlignmentOrder alorder, String undoname)
3731 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3732 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3733 if (undoname != null)
3735 addHistoryItem(new OrderCommand(undoname, oldOrder,
3736 viewport.alignment));
3738 alignPanel.paintAlignment(true);
3743 * Work out whether the whole set of sequences or just the selected set will
3744 * be submitted for multiple alignment.
3747 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3749 // Now, check we have enough sequences
3750 AlignmentView msa = null;
3752 if ((viewport.getSelectionGroup() != null)
3753 && (viewport.getSelectionGroup().getSize() > 1))
3755 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3756 // some common interface!
3758 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3759 * SequenceI[sz = seqs.getSize(false)];
3761 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3762 * seqs.getSequenceAt(i); }
3764 msa = viewport.getAlignmentView(true);
3769 * Vector seqs = viewport.getAlignment().getSequences();
3771 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3773 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3774 * seqs.elementAt(i); } }
3776 msa = viewport.getAlignmentView(false);
3782 * Decides what is submitted to a secondary structure prediction service: the
3783 * first sequence in the alignment, or in the current selection, or, if the
3784 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3785 * region or the whole alignment. (where the first sequence in the set is the
3786 * one that the prediction will be for).
3788 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3790 AlignmentView seqs = null;
3792 if ((viewport.getSelectionGroup() != null)
3793 && (viewport.getSelectionGroup().getSize() > 0))
3795 seqs = viewport.getAlignmentView(true);
3799 seqs = viewport.getAlignmentView(false);
3801 // limit sequences - JBPNote in future - could spawn multiple prediction
3803 // TODO: viewport.alignment.isAligned is a global state - the local
3804 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3805 if (!viewport.alignment.isAligned(false))
3807 seqs.setSequences(new SeqCigar[]
3808 { seqs.getSequences()[0] });
3809 // TODO: if seqs.getSequences().length>1 then should really have warned
3822 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3824 // Pick the tree file
3825 JalviewFileChooser chooser = new JalviewFileChooser(
3826 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
3827 chooser.setFileView(new JalviewFileView());
3828 chooser.setDialogTitle("Select a newick-like tree file");
3829 chooser.setToolTipText("Load a tree file");
3831 int value = chooser.showOpenDialog(null);
3833 if (value == JalviewFileChooser.APPROVE_OPTION)
3835 String choice = chooser.getSelectedFile().getPath();
3836 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3837 jalview.io.NewickFile fin = null;
3840 fin = new jalview.io.NewickFile(choice, "File");
3841 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3842 } catch (Exception ex)
3844 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3845 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3846 ex.printStackTrace();
3848 if (fin != null && fin.hasWarningMessage())
3850 JOptionPane.showMessageDialog(Desktop.desktop,
3851 fin.getWarningMessage(), "Possible problem with tree file",
3852 JOptionPane.WARNING_MESSAGE);
3857 public TreePanel ShowNewickTree(NewickFile nf, String title)
3859 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3862 public TreePanel ShowNewickTree(NewickFile nf, String title,
3863 AlignmentView input)
3865 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3868 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3869 int h, int x, int y)
3871 return ShowNewickTree(nf, title, null, w, h, x, y);
3875 * Add a treeviewer for the tree extracted from a newick file object to the
3876 * current alignment view
3883 * Associated alignment input data (or null)
3892 * @return TreePanel handle
3894 public TreePanel ShowNewickTree(NewickFile nf, String title,
3895 AlignmentView input, int w, int h, int x, int y)
3897 TreePanel tp = null;
3903 if (nf.getTree() != null)
3905 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3911 tp.setLocation(x, y);
3914 Desktop.addInternalFrame(tp, title, w, h);
3916 } catch (Exception ex)
3918 ex.printStackTrace();
3924 private boolean buildingMenu = false;
3927 * Generates menu items and listener event actions for web service clients
3930 public void BuildWebServiceMenu()
3932 while (buildingMenu)
3936 System.err.println("Waiting for building menu to finish.");
3938 } catch (Exception e)
3943 final AlignFrame me = this;
3944 buildingMenu = true;
3945 new Thread(new Runnable()
3951 System.err.println("Building ws menu again "
3952 + Thread.currentThread());
3953 // TODO: add support for context dependent disabling of services based
3955 // alignment and current selection
3956 // TODO: add additional serviceHandle parameter to specify abstract
3958 // class independently of AbstractName
3959 // TODO: add in rediscovery GUI function to restart discoverer
3960 // TODO: group services by location as well as function and/or
3962 // object broker mechanism.
3963 final Vector wsmenu = new Vector();
3964 final IProgressIndicator af = me;
3965 final JMenu msawsmenu = new JMenu("Alignment");
3966 final JMenu secstrmenu = new JMenu(
3967 "Secondary Structure Prediction");
3968 final JMenu seqsrchmenu = new JMenu(
3969 "Sequence Database Search");
3970 final JMenu analymenu = new JMenu(
3973 if (Cache.getDefault("SHOW_JWS1_SERVICES", true)
3974 && Discoverer.services != null
3975 && (Discoverer.services.size() > 0))
3977 // TODO: refactor to allow list of AbstractName/Handler bindings to
3979 // stored or retrieved from elsewhere
3980 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3981 Vector secstrpr = (Vector) Discoverer.services
3983 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3984 // TODO: move GUI generation code onto service implementation - so a
3985 // client instance attaches itself to the GUI with method call like
3986 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
3990 // Add any Multiple Sequence Alignment Services
3991 for (int i = 0, j = msaws.size(); i < j; i++)
3993 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
3995 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
3996 .getServiceClient(sh);
3997 impl.attachWSMenuEntry(msawsmenu, me);
4001 if (secstrpr != null)
4003 // Add any secondary structure prediction services
4004 for (int i = 0, j = secstrpr.size(); i < j; i++)
4006 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4008 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4009 .getServiceClient(sh);
4010 impl.attachWSMenuEntry(secstrmenu, me);
4013 if (seqsrch != null)
4015 // Add any sequence search services
4016 for (int i = 0, j = seqsrch.size(); i < j; i++)
4018 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
4020 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4021 .getServiceClient(sh);
4022 impl.attachWSMenuEntry(seqsrchmenu, me);
4027 // TODO: move into separate menu builder class.
4028 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4030 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4031 if (jws2servs != null)
4033 if (jws2servs.hasServices())
4035 jws2servs.attachWSMenuEntry(msawsmenu, me);
4039 // Add all submenus in the order they should appear on the web services menu
4040 wsmenu.add(msawsmenu);
4041 wsmenu.add(secstrmenu);
4042 wsmenu.add(analymenu);
4043 // No search services yet
4044 // wsmenu.add(seqsrchmenu);
4046 javax.swing.SwingUtilities.invokeLater(new Runnable()
4052 webService.removeAll();
4053 // first, add discovered services onto the webservices menu
4054 if (wsmenu.size() > 0)
4056 for (int i = 0, j = wsmenu.size(); i < j; i++)
4058 webService.add((JMenu) wsmenu.get(i));
4063 webService.add(me.webServiceNoServices);
4065 build_urlServiceMenu(me.webService);
4066 build_fetchdbmenu(webService);
4067 } catch (Exception e)
4073 } catch (Exception e)
4078 buildingMenu = false;
4086 * construct any groupURL type service menu entries.
4090 private void build_urlServiceMenu(JMenu webService)
4092 // TODO: remove this code when 2.7 is released
4093 // DEBUG - alignmentView
4095 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4096 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4098 * @Override public void actionPerformed(ActionEvent e) {
4099 * jalview.datamodel.AlignmentView.testSelectionViews(af.viewport.alignment,
4100 * af.viewport.colSel, af.viewport.selectionGroup); }
4102 * }); webService.add(testAlView);
4104 // TODO: refactor to RestClient discoverer and merge menu entries for
4105 // rest-style services with other types of analysis/calculation service
4106 // SHmmr test client - still being implemented.
4107 // DEBUG - alignmentView
4109 for (jalview.ws.rest.RestClient client: jalview.ws.rest.RestClient.getRestClients()) {
4110 client.attachWSMenuEntry(JvSwingUtils.findOrCreateMenu(webService, client.getAction()), this);
4113 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4115 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4121 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4122 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4123 * getProperty("LAST_DIRECTORY"));
4125 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4126 * to Vamsas file"); chooser.setToolTipText("Export");
4128 * int value = chooser.showSaveDialog(this);
4130 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4131 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4132 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4133 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4136 * prototype of an automatically enabled/disabled analysis function
4139 protected void setShowProductsEnabled()
4141 SequenceI[] selection = viewport.getSequenceSelection();
4142 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4143 viewport.getAlignment().getDataset()))
4145 showProducts.setEnabled(true);
4150 showProducts.setEnabled(false);
4155 * search selection for sequence xRef products and build the show products
4160 * @return true if showProducts menu should be enabled.
4162 public boolean canShowProducts(SequenceI[] selection,
4163 boolean isRegionSelection, Alignment dataset)
4165 boolean showp = false;
4168 showProducts.removeAll();
4169 final boolean dna = viewport.getAlignment().isNucleotide();
4170 final Alignment ds = dataset;
4171 String[] ptypes = (selection == null || selection.length == 0) ? null
4172 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4174 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4175 // selection, dataset, true);
4176 final SequenceI[] sel = selection;
4177 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4180 final boolean isRegSel = isRegionSelection;
4181 final AlignFrame af = this;
4182 final String source = ptypes[t];
4183 JMenuItem xtype = new JMenuItem(ptypes[t]);
4184 xtype.addActionListener(new ActionListener()
4187 public void actionPerformed(ActionEvent e)
4189 // TODO: new thread for this call with vis-delay
4190 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4191 isRegSel, dna, source);
4195 showProducts.add(xtype);
4197 showProducts.setVisible(showp);
4198 showProducts.setEnabled(showp);
4199 } catch (Exception e)
4201 jalview.bin.Cache.log
4202 .warn("canTranslate threw an exception - please report to help@jalview.org",
4209 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4210 boolean isRegSel, boolean dna, String source)
4212 final boolean fisRegSel = isRegSel;
4213 final boolean fdna = dna;
4214 final String fsrc = source;
4215 final AlignFrame ths = this;
4216 final SequenceI[] fsel = sel;
4217 Runnable foo = new Runnable()
4222 final long sttime = System.currentTimeMillis();
4223 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4226 Alignment ds = ths.getViewport().alignment.getDataset(); // update
4230 Alignment prods = CrossRef
4231 .findXrefSequences(fsel, fdna, fsrc, ds);
4234 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4235 for (int s = 0; s < sprods.length; s++)
4237 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4238 if (ds.getSequences() == null
4239 || !ds.getSequences().contains(
4240 sprods[s].getDatasetSequence()))
4241 ds.addSequence(sprods[s].getDatasetSequence());
4242 sprods[s].updatePDBIds();
4244 Alignment al = new Alignment(sprods);
4245 AlignedCodonFrame[] cf = prods.getCodonFrames();
4247 for (int s = 0; cf != null && s < cf.length; s++)
4249 al.addCodonFrame(cf[s]);
4252 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4254 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4255 + " for " + ((fisRegSel) ? "selected region of " : "")
4257 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4262 System.err.println("No Sequences generated for xRef type "
4265 } catch (Exception e)
4267 jalview.bin.Cache.log.error(
4268 "Exception when finding crossreferences", e);
4269 } catch (OutOfMemoryError e)
4271 new OOMWarning("whilst fetching crossreferences", e);
4274 jalview.bin.Cache.log.error("Error when finding crossreferences",
4277 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4282 Thread frunner = new Thread(foo);
4286 public boolean canShowTranslationProducts(SequenceI[] selection,
4287 AlignmentI alignment)
4292 return (jalview.analysis.Dna.canTranslate(selection,
4293 viewport.getViewAsVisibleContigs(true)));
4294 } catch (Exception e)
4296 jalview.bin.Cache.log
4297 .warn("canTranslate threw an exception - please report to help@jalview.org",
4303 public void showProducts_actionPerformed(ActionEvent e)
4305 // /////////////////////////////
4306 // Collect Data to be translated/transferred
4308 SequenceI[] selection = viewport.getSequenceSelection();
4309 AlignmentI al = null;
4312 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4313 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4314 viewport.getAlignment().getDataset());
4315 } catch (Exception ex)
4318 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4325 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4326 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4330 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4331 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4332 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4336 public void showTranslation_actionPerformed(ActionEvent e)
4338 // /////////////////////////////
4339 // Collect Data to be translated/transferred
4341 SequenceI[] selection = viewport.getSequenceSelection();
4342 String[] seqstring = viewport.getViewAsString(true);
4343 AlignmentI al = null;
4346 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4347 viewport.getViewAsVisibleContigs(true), viewport
4348 .getGapCharacter(), viewport.alignment
4349 .getAlignmentAnnotation(), viewport.alignment
4350 .getWidth(), viewport.getAlignment().getDataset());
4351 } catch (Exception ex)
4354 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4361 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
4362 "Translation Failed", JOptionPane.WARNING_MESSAGE);
4366 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4367 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4368 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4373 * Try to load a features file onto the alignment.
4376 * contents or path to retrieve file
4378 * access mode of file (see jalview.io.AlignFile)
4379 * @return true if features file was parsed corectly.
4381 public boolean parseFeaturesFile(String file, String type)
4383 boolean featuresFile = false;
4386 featuresFile = new FeaturesFile(file, type)
4387 .parse(viewport.alignment.getDataset(),
4388 alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
4389 false, jalview.bin.Cache.getDefault(
4390 "RELAXEDSEQIDMATCHING", false));
4391 } catch (Exception ex)
4393 ex.printStackTrace();
4398 viewport.showSequenceFeatures = true;
4399 showSeqFeatures.setSelected(true);
4400 if (alignPanel.seqPanel.seqCanvas.fr != null)
4402 // update the min/max ranges where necessary
4403 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4405 if (featureSettings != null)
4407 featureSettings.setTableData();
4409 alignPanel.paintAlignment(true);
4412 return featuresFile;
4415 public void dragEnter(DropTargetDragEvent evt)
4419 public void dragExit(DropTargetEvent evt)
4423 public void dragOver(DropTargetDragEvent evt)
4427 public void dropActionChanged(DropTargetDragEvent evt)
4431 public void drop(DropTargetDropEvent evt)
4433 Transferable t = evt.getTransferable();
4434 java.util.List files = null;
4438 DataFlavor uriListFlavor = new DataFlavor(
4439 "text/uri-list;class=java.lang.String");
4440 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4442 // Works on Windows and MacOSX
4443 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4444 files = (java.util.List) t
4445 .getTransferData(DataFlavor.javaFileListFlavor);
4447 else if (t.isDataFlavorSupported(uriListFlavor))
4449 // This is used by Unix drag system
4450 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4451 String data = (String) t.getTransferData(uriListFlavor);
4452 files = new java.util.ArrayList(1);
4453 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4454 data, "\r\n"); st.hasMoreTokens();)
4456 String s = st.nextToken();
4457 if (s.startsWith("#"))
4459 // the line is a comment (as per the RFC 2483)
4463 java.net.URI uri = new java.net.URI(s);
4464 // check to see if we can handle this kind of URI
4465 if (uri.getScheme().toLowerCase().startsWith("http"))
4467 files.add(uri.toString());
4471 // otherwise preserve old behaviour: catch all for file objects
4472 java.io.File file = new java.io.File(uri);
4473 files.add(file.toString());
4477 } catch (Exception e)
4479 e.printStackTrace();
4485 // check to see if any of these files have names matching sequences in
4487 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4488 .getAlignment().getSequencesArray());
4490 * Object[] { String,SequenceI}
4492 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4493 ArrayList<String> filesnotmatched = new ArrayList<String>();
4494 for (int i = 0; i < files.size(); i++)
4496 String file = files.get(i).toString();
4498 String protocol = FormatAdapter.checkProtocol(file);
4499 if (protocol == jalview.io.FormatAdapter.FILE)
4501 File fl = new File(file);
4502 pdbfn = fl.getName();
4504 else if (protocol == jalview.io.FormatAdapter.URL)
4506 URL url = new URL(file);
4507 pdbfn = url.getFile();
4509 if (pdbfn.length() > 0)
4511 // attempt to find a match in the alignment
4512 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4513 int l = 0, c = pdbfn.indexOf(".");
4514 while (mtch == null && c != -1)
4519 } while ((c = pdbfn.indexOf(".", l)) > l);
4522 pdbfn = pdbfn.substring(0, l);
4524 mtch = idm.findAllIdMatches(pdbfn);
4531 type = new IdentifyFile().Identify(file, protocol);
4532 } catch (Exception ex)
4538 if (type.equalsIgnoreCase("PDB"))
4540 filesmatched.add(new Object[]
4541 { file, protocol, mtch });
4546 // File wasn't named like one of the sequences or wasn't a PDB file.
4547 filesnotmatched.add(file);
4551 if (filesmatched.size() > 0)
4553 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4557 "Do you want to automatically associate the "
4558 + filesmatched.size()
4559 + " PDB files with sequences in the alignment that have the same name ?",
4560 "Automatically Associate PDB files by name",
4561 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4564 for (Object[] fm : filesmatched)
4566 // try and associate
4567 // TODO: may want to set a standard ID naming formalism for
4568 // associating PDB files which have no IDs.
4569 for (SequenceI toassoc: (SequenceI[])fm[2]) {
4570 PDBEntry pe = new AssociatePdbFileWithSeq()
4571 .associatePdbWithSeq((String) fm[0], (String) fm[1],
4576 .println("Associated file : " + ((String) fm[0])
4578 + toassoc.getDisplayId(true));
4582 alignPanel.paintAlignment(true);
4586 if (filesnotmatched.size() > 0)
4589 && (Cache.getDefault(
4590 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4593 "<html>Do you want to <em>ignore</em> the "
4594 + filesnotmatched.size()
4595 + " files whose names did not match any sequence IDs ?</html>",
4596 "Ignore unmatched dropped files ?",
4597 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4601 for (String fn : filesnotmatched)
4603 loadJalviewDataFile(fn, null, null, null);
4607 } catch (Exception ex)
4609 ex.printStackTrace();
4615 * Attempt to load a "dropped" file or URL string: First by testing whether
4616 * it's and Annotation file, then a JNet file, and finally a features file. If
4617 * all are false then the user may have dropped an alignment file onto this
4621 * either a filename or a URL string.
4623 public void loadJalviewDataFile(String file, String protocol,
4624 String format, SequenceI assocSeq)
4628 if (protocol == null)
4630 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4632 // if the file isn't identified, or not positively identified as some
4633 // other filetype (PFAM is default unidentified alignment file type) then
4634 // try to parse as annotation.
4635 boolean isAnnotation = (format == null || format
4636 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4637 .readAnnotationFile(viewport.alignment, file, protocol)
4642 // try to see if its a JNet 'concise' style annotation file *before* we
4643 // try to parse it as a features file
4646 format = new IdentifyFile().Identify(file, protocol);
4648 if (format.equalsIgnoreCase("JnetFile"))
4650 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4652 new JnetAnnotationMaker().add_annotation(predictions,
4653 viewport.getAlignment(), 0, false);
4654 isAnnotation = true;
4659 * if (format.equalsIgnoreCase("PDB")) {
4661 * String pdbfn = ""; // try to match up filename with sequence id try
4662 * { if (protocol == jalview.io.FormatAdapter.FILE) { File fl = new
4663 * File(file); pdbfn = fl.getName(); } else if (protocol ==
4664 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4665 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq == null)
4666 * { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4667 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) { //
4668 * attempt to find a match in the alignment SequenceI mtch =
4669 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4670 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) > l)
4671 * { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch =
4672 * idm.findIdMatch(pdbfn); } if (mtch != null) { // try and associate
4673 * // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4674 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null) {
4675 * System.err.println("Associated file : " + file + " with " +
4676 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4677 * TODO: maybe need to load as normal otherwise return; } }
4679 // try to parse it as a features file
4680 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4681 // if it wasn't a features file then we just treat it as a general
4682 // alignment file to load into the current view.
4685 new FileLoader().LoadFile(viewport, file, protocol, format);
4689 alignPanel.paintAlignment(true);
4696 alignPanel.adjustAnnotationHeight();
4697 viewport.updateSequenceIdColours();
4698 buildSortByAnnotationScoresMenu();
4699 alignPanel.paintAlignment(true);
4701 } catch (Exception ex)
4703 ex.printStackTrace();
4707 public void tabSelectionChanged(int index)
4711 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4712 viewport = alignPanel.av;
4713 setMenusFromViewport(viewport);
4717 public void tabbedPane_mousePressed(MouseEvent e)
4719 if (SwingUtilities.isRightMouseButton(e))
4721 String reply = JOptionPane.showInternalInputDialog(this,
4722 "Enter View Name", "Edit View Name",
4723 JOptionPane.QUESTION_MESSAGE);
4727 viewport.viewName = reply;
4728 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4733 public AlignViewport getCurrentView()
4739 * Open the dialog for regex description parsing.
4741 protected void extractScores_actionPerformed(ActionEvent e)
4743 ParseProperties pp = new jalview.analysis.ParseProperties(
4744 viewport.alignment);
4745 // TODO: verify regex and introduce GUI dialog for version 2.5
4746 // if (pp.getScoresFromDescription("col", "score column ",
4747 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4749 if (pp.getScoresFromDescription("description column",
4750 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4752 buildSortByAnnotationScoresMenu();
4760 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4763 protected void showDbRefs_actionPerformed(ActionEvent e)
4765 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4771 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4774 protected void showNpFeats_actionPerformed(ActionEvent e)
4776 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4780 * find the viewport amongst the tabs in this alignment frame and close that
4785 public boolean closeView(AlignViewport av)
4789 this.closeMenuItem_actionPerformed(false);
4792 Component[] comp = tabbedPane.getComponents();
4793 for (int i = 0; comp != null && i < comp.length; i++)
4795 if (comp[i] instanceof AlignmentPanel)
4797 if (((AlignmentPanel) comp[i]).av == av)
4800 closeView((AlignmentPanel) comp[i]);
4808 protected void build_fetchdbmenu(JMenu webService)
4810 // Temporary hack - DBRef Fetcher always top level ws entry.
4811 // TODO We probably want to store a sequence database checklist in
4812 // preferences and have checkboxes.. rather than individual sources selected
4814 final JMenu rfetch = new JMenu("Fetch DB References");
4815 rfetch.setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4816 webService.add(rfetch);
4818 JMenuItem fetchr = new JMenuItem("Standard Databases");
4819 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4820 fetchr.addActionListener(new ActionListener()
4823 public void actionPerformed(ActionEvent e)
4825 new Thread(new Runnable()
4830 new jalview.ws.DBRefFetcher(alignPanel.av
4831 .getSequenceSelection(), alignPanel.alignFrame)
4832 .fetchDBRefs(false);
4840 final AlignFrame me = this;
4841 new Thread(new Runnable()
4845 final jalview.ws.SequenceFetcher sf = SequenceFetcher
4846 .getSequenceFetcherSingleton(me);
4847 final String[] otherdb = sf.getOrderedSupportedSources();
4848 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4849 // jalview.util.QuickSort.sort(otherdb, otherdb);
4850 javax.swing.SwingUtilities.invokeLater(new Runnable()
4855 JMenu dfetch = new JMenu();
4858 int comp = 0, mcomp = 15;
4859 String mname = null;
4860 if (otherdb != null && otherdb.length > 0)
4862 for (int i = 0; i < otherdb.length; i++)
4864 String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
4867 mname = "from '" + dbname + "'";
4869 fetchr = new JMenuItem(otherdb[i]);
4870 final String[] dassource = new String[]
4872 fetchr.addActionListener(new ActionListener()
4875 public void actionPerformed(ActionEvent e)
4877 new Thread(new Runnable()
4882 new jalview.ws.DBRefFetcher(alignPanel.av
4883 .getSequenceSelection(),
4884 alignPanel.alignFrame, dassource)
4885 .fetchDBRefs(false);
4891 fetchr.setToolTipText("Retrieve from " + dbname);
4893 if (comp++ == mcomp || i == (otherdb.length - 1))
4895 dfetch.setText(mname + " to '" + dbname + "'");
4897 dfetch = new JMenu();
4911 * Left justify the whole alignment.
4913 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4915 AlignmentI al = viewport.getAlignment();
4917 viewport.firePropertyChange("alignment", null, al);
4921 * Right justify the whole alignment.
4923 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4925 AlignmentI al = viewport.getAlignment();
4927 viewport.firePropertyChange("alignment", null, al);
4930 public void setShowSeqFeatures(boolean b)
4932 showSeqFeatures.setSelected(true);
4933 viewport.setShowSequenceFeatures(true);
4940 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
4941 * awt.event.ActionEvent)
4943 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
4945 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
4946 alignPanel.paintAlignment(true);
4953 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
4956 protected void showGroupConsensus_actionPerformed(ActionEvent e)
4958 viewport.setShowGroupConsensus(showGroupConsensus.getState());
4959 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4967 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
4968 * .event.ActionEvent)
4970 protected void showGroupConservation_actionPerformed(ActionEvent e)
4972 viewport.setShowGroupConservation(showGroupConservation.getState());
4973 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4980 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
4981 * .event.ActionEvent)
4983 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
4985 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
4986 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
4993 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
4994 * .event.ActionEvent)
4996 protected void showSequenceLogo_actionPerformed(ActionEvent e)
4998 viewport.setShowSequenceLogo(showSequenceLogo.getState());
4999 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5002 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5004 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5011 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5012 * .event.ActionEvent)
5014 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5016 if (viewport.getSelectionGroup() != null)
5018 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
5019 viewport.getSequenceSelection(),
5020 viewport.getAlignmentView(true).getSequenceStrings(
5021 viewport.getGapCharacter()),
5022 viewport.alignment.getGroups());
5023 viewport.alignment.deleteAllGroups();
5024 viewport.sequenceColours = null;
5025 viewport.setSelectionGroup(null);
5026 // set view properties for each group
5027 for (int g = 0; g < gps.length; g++)
5029 gps[g].setShowNonconserved(viewport.getShowUnconserved());
5030 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
5031 viewport.alignment.addGroup(gps[g]);
5032 Color col = new Color((int) (Math.random() * 255),
5033 (int) (Math.random() * 255), (int) (Math.random() * 255));
5034 col = col.brighter();
5035 for (Enumeration sq = gps[g].getSequences(null).elements(); sq
5036 .hasMoreElements(); viewport.setSequenceColour(
5037 (SequenceI) sq.nextElement(), col))
5040 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5041 alignPanel.updateAnnotation();
5042 alignPanel.paintAlignment(true);
5047 * make the given alignmentPanel the currently selected tab
5049 * @param alignmentPanel
5051 public void setDisplayedView(AlignmentPanel alignmentPanel)
5053 if (!viewport.getSequenceSetId().equals(
5054 alignmentPanel.av.getSequenceSetId()))
5057 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5059 if (tabbedPane != null
5060 & alignPanels.indexOf(alignmentPanel) != tabbedPane.getSelectedIndex())
5062 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5067 class PrintThread extends Thread
5071 public PrintThread(AlignmentPanel ap)
5076 static PageFormat pf;
5080 PrinterJob printJob = PrinterJob.getPrinterJob();
5084 printJob.setPrintable(ap, pf);
5088 printJob.setPrintable(ap);
5091 if (printJob.printDialog())
5096 } catch (Exception PrintException)
5098 PrintException.printStackTrace();