2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.analysis.AAFrequency;
22 import jalview.analysis.AlignmentSorter;
23 import jalview.analysis.Conservation;
24 import jalview.analysis.CrossRef;
25 import jalview.analysis.NJTree;
26 import jalview.analysis.ParseProperties;
27 import jalview.analysis.SequenceIdMatcher;
28 import jalview.api.AlignViewControllerGuiI;
29 import jalview.api.AlignViewControllerI;
30 import jalview.api.analysis.ScoreModelI;
31 import jalview.bin.Cache;
32 import jalview.commands.CommandI;
33 import jalview.commands.EditCommand;
34 import jalview.commands.OrderCommand;
35 import jalview.commands.RemoveGapColCommand;
36 import jalview.commands.RemoveGapsCommand;
37 import jalview.commands.SlideSequencesCommand;
38 import jalview.commands.TrimRegionCommand;
39 import jalview.datamodel.AlignedCodonFrame;
40 import jalview.datamodel.Alignment;
41 import jalview.datamodel.AlignmentAnnotation;
42 import jalview.datamodel.AlignmentI;
43 import jalview.datamodel.AlignmentOrder;
44 import jalview.datamodel.AlignmentView;
45 import jalview.datamodel.ColumnSelection;
46 import jalview.datamodel.PDBEntry;
47 import jalview.datamodel.SeqCigar;
48 import jalview.datamodel.Sequence;
49 import jalview.datamodel.SequenceGroup;
50 import jalview.datamodel.SequenceI;
51 import jalview.io.AlignmentProperties;
52 import jalview.io.AnnotationFile;
53 import jalview.io.FeaturesFile;
54 import jalview.io.FileLoader;
55 import jalview.io.FormatAdapter;
56 import jalview.io.HTMLOutput;
57 import jalview.io.IdentifyFile;
58 import jalview.io.JalviewFileChooser;
59 import jalview.io.JalviewFileView;
60 import jalview.io.JnetAnnotationMaker;
61 import jalview.io.NewickFile;
62 import jalview.io.TCoffeeScoreFile;
63 import jalview.jbgui.GAlignFrame;
64 import jalview.schemes.Blosum62ColourScheme;
65 import jalview.schemes.BuriedColourScheme;
66 import jalview.schemes.ClustalxColourScheme;
67 import jalview.schemes.ColourSchemeI;
68 import jalview.schemes.ColourSchemeProperty;
69 import jalview.schemes.HelixColourScheme;
70 import jalview.schemes.HydrophobicColourScheme;
71 import jalview.schemes.NucleotideColourScheme;
72 import jalview.schemes.PIDColourScheme;
73 import jalview.schemes.PurinePyrimidineColourScheme;
74 import jalview.schemes.RNAHelicesColourChooser;
75 import jalview.schemes.ResidueProperties;
76 import jalview.schemes.StrandColourScheme;
77 import jalview.schemes.TCoffeeColourScheme;
78 import jalview.schemes.TaylorColourScheme;
79 import jalview.schemes.TurnColourScheme;
80 import jalview.schemes.UserColourScheme;
81 import jalview.schemes.ZappoColourScheme;
82 import jalview.util.MessageManager;
83 import jalview.ws.jws1.Discoverer;
84 import jalview.ws.jws2.Jws2Discoverer;
85 import jalview.ws.jws2.jabaws2.Jws2Instance;
86 import jalview.ws.seqfetcher.DbSourceProxy;
88 import java.awt.BorderLayout;
89 import java.awt.Component;
90 import java.awt.GridLayout;
91 import java.awt.Rectangle;
92 import java.awt.Toolkit;
93 import java.awt.datatransfer.Clipboard;
94 import java.awt.datatransfer.DataFlavor;
95 import java.awt.datatransfer.StringSelection;
96 import java.awt.datatransfer.Transferable;
97 import java.awt.dnd.DnDConstants;
98 import java.awt.dnd.DropTargetDragEvent;
99 import java.awt.dnd.DropTargetDropEvent;
100 import java.awt.dnd.DropTargetEvent;
101 import java.awt.dnd.DropTargetListener;
102 import java.awt.event.ActionEvent;
103 import java.awt.event.ActionListener;
104 import java.awt.event.KeyAdapter;
105 import java.awt.event.KeyEvent;
106 import java.awt.event.MouseAdapter;
107 import java.awt.event.MouseEvent;
108 import java.awt.print.PageFormat;
109 import java.awt.print.PrinterJob;
110 import java.beans.PropertyChangeEvent;
113 import java.util.ArrayList;
114 import java.util.Enumeration;
115 import java.util.Hashtable;
116 import java.util.List;
117 import java.util.Vector;
119 import javax.swing.JButton;
120 import javax.swing.JEditorPane;
121 import javax.swing.JInternalFrame;
122 import javax.swing.JLabel;
123 import javax.swing.JLayeredPane;
124 import javax.swing.JMenu;
125 import javax.swing.JMenuItem;
126 import javax.swing.JOptionPane;
127 import javax.swing.JPanel;
128 import javax.swing.JProgressBar;
129 import javax.swing.JRadioButtonMenuItem;
130 import javax.swing.JScrollPane;
131 import javax.swing.SwingUtilities;
137 * @version $Revision$
139 public class AlignFrame extends GAlignFrame implements DropTargetListener,
140 IProgressIndicator, AlignViewControllerGuiI
144 public static final int DEFAULT_WIDTH = 700;
147 public static final int DEFAULT_HEIGHT = 500;
149 public AlignmentPanel alignPanel;
151 AlignViewport viewport;
153 public AlignViewControllerI avc;
156 Vector alignPanels = new Vector();
159 * Last format used to load or save alignments in this window
161 String currentFileFormat = null;
164 * Current filename for this alignment
166 String fileName = null;
169 * Creates a new AlignFrame object with specific width and height.
175 public AlignFrame(AlignmentI al, int width, int height)
177 this(al, null, width, height);
181 * Creates a new AlignFrame object with specific width, height and
187 * @param sequenceSetId
189 public AlignFrame(AlignmentI al, int width, int height,
190 String sequenceSetId)
192 this(al, null, width, height, sequenceSetId);
196 * Creates a new AlignFrame object with specific width, height and
202 * @param sequenceSetId
205 public AlignFrame(AlignmentI al, int width, int height,
206 String sequenceSetId, String viewId)
208 this(al, null, width, height, sequenceSetId, viewId);
212 * new alignment window with hidden columns
216 * @param hiddenColumns
217 * ColumnSelection or null
219 * Width of alignment frame
223 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
224 int width, int height)
226 this(al, hiddenColumns, width, height, null);
230 * Create alignment frame for al with hiddenColumns, a specific width and
231 * height, and specific sequenceId
234 * @param hiddenColumns
237 * @param sequenceSetId
240 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
241 int width, int height, String sequenceSetId)
243 this(al, hiddenColumns, width, height, sequenceSetId, null);
247 * Create alignment frame for al with hiddenColumns, a specific width and
248 * height, and specific sequenceId
251 * @param hiddenColumns
254 * @param sequenceSetId
259 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
260 int width, int height, String sequenceSetId, String viewId)
262 setSize(width, height);
263 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
265 alignPanel = new AlignmentPanel(this, viewport);
267 if (al.getDataset() == null)
272 addAlignmentPanel(alignPanel, true);
277 * Make a new AlignFrame from exisiting alignmentPanels
284 public AlignFrame(AlignmentPanel ap)
288 addAlignmentPanel(ap, false);
293 * initalise the alignframe from the underlying viewport data and the
298 avc = new jalview.controller.AlignViewController(this, viewport, alignPanel);
299 if (viewport.getAlignmentConservationAnnotation() == null)
301 BLOSUM62Colour.setEnabled(false);
302 conservationMenuItem.setEnabled(false);
303 modifyConservation.setEnabled(false);
304 // PIDColour.setEnabled(false);
305 // abovePIDThreshold.setEnabled(false);
306 // modifyPID.setEnabled(false);
309 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
312 if (sortby.equals("Id"))
314 sortIDMenuItem_actionPerformed(null);
316 else if (sortby.equals("Pairwise Identity"))
318 sortPairwiseMenuItem_actionPerformed(null);
321 if (Desktop.desktop != null)
323 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
324 addServiceListeners();
325 setGUINucleotide(viewport.getAlignment().isNucleotide());
328 setMenusFromViewport(viewport);
329 buildSortByAnnotationScoresMenu();
331 if (viewport.wrapAlignment)
333 wrapMenuItem_actionPerformed(null);
336 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
338 this.overviewMenuItem_actionPerformed(null);
346 * Change the filename and format for the alignment, and enable the 'reload'
347 * button functionality.
354 public void setFileName(String file, String format)
357 currentFileFormat = format;
358 reload.setEnabled(true);
361 void addKeyListener()
363 addKeyListener(new KeyAdapter()
366 public void keyPressed(KeyEvent evt)
368 if (viewport.cursorMode
369 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
370 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
371 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
372 && Character.isDigit(evt.getKeyChar()))
373 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
375 switch (evt.getKeyCode())
378 case 27: // escape key
379 deselectAllSequenceMenuItem_actionPerformed(null);
383 case KeyEvent.VK_DOWN:
384 if (evt.isAltDown() || !viewport.cursorMode)
385 moveSelectedSequences(false);
386 if (viewport.cursorMode)
387 alignPanel.seqPanel.moveCursor(0, 1);
391 if (evt.isAltDown() || !viewport.cursorMode)
392 moveSelectedSequences(true);
393 if (viewport.cursorMode)
394 alignPanel.seqPanel.moveCursor(0, -1);
398 case KeyEvent.VK_LEFT:
399 if (evt.isAltDown() || !viewport.cursorMode)
400 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
402 alignPanel.seqPanel.moveCursor(-1, 0);
406 case KeyEvent.VK_RIGHT:
407 if (evt.isAltDown() || !viewport.cursorMode)
408 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
410 alignPanel.seqPanel.moveCursor(1, 0);
413 case KeyEvent.VK_SPACE:
414 if (viewport.cursorMode)
416 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
417 || evt.isShiftDown() || evt.isAltDown());
421 // case KeyEvent.VK_A:
422 // if (viewport.cursorMode)
424 // alignPanel.seqPanel.insertNucAtCursor(false,"A");
425 // //System.out.println("A");
429 * case KeyEvent.VK_CLOSE_BRACKET: if (viewport.cursorMode) {
430 * System.out.println("closing bracket"); } break;
432 case KeyEvent.VK_DELETE:
433 case KeyEvent.VK_BACK_SPACE:
434 if (!viewport.cursorMode)
436 cut_actionPerformed(null);
440 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
441 || evt.isShiftDown() || evt.isAltDown());
447 if (viewport.cursorMode)
449 alignPanel.seqPanel.setCursorRow();
453 if (viewport.cursorMode && !evt.isControlDown())
455 alignPanel.seqPanel.setCursorColumn();
459 if (viewport.cursorMode)
461 alignPanel.seqPanel.setCursorPosition();
465 case KeyEvent.VK_ENTER:
466 case KeyEvent.VK_COMMA:
467 if (viewport.cursorMode)
469 alignPanel.seqPanel.setCursorRowAndColumn();
474 if (viewport.cursorMode)
476 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
480 if (viewport.cursorMode)
482 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
487 viewport.cursorMode = !viewport.cursorMode;
488 statusBar.setText(MessageManager.formatMessage("label.keyboard_editing_mode", new String[]{(viewport.cursorMode ? "on" : "off")}));
489 if (viewport.cursorMode)
491 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
492 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
494 alignPanel.seqPanel.seqCanvas.repaint();
500 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
501 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
503 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
505 javax.help.HelpBroker hb = hs.createHelpBroker();
506 hb.setCurrentID("home");
507 hb.setDisplayed(true);
508 } catch (Exception ex)
510 ex.printStackTrace();
515 boolean toggleSeqs = !evt.isControlDown();
516 boolean toggleCols = !evt.isShiftDown();
517 toggleHiddenRegions(toggleSeqs, toggleCols);
520 case KeyEvent.VK_PAGE_UP:
521 if (viewport.wrapAlignment)
523 alignPanel.scrollUp(true);
527 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
528 - viewport.endSeq + viewport.startSeq);
531 case KeyEvent.VK_PAGE_DOWN:
532 if (viewport.wrapAlignment)
534 alignPanel.scrollUp(false);
538 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
539 + viewport.endSeq - viewport.startSeq);
546 public void keyReleased(KeyEvent evt)
548 switch (evt.getKeyCode())
550 case KeyEvent.VK_LEFT:
551 if (evt.isAltDown() || !viewport.cursorMode)
552 viewport.firePropertyChange("alignment", null, viewport
553 .getAlignment().getSequences());
556 case KeyEvent.VK_RIGHT:
557 if (evt.isAltDown() || !viewport.cursorMode)
558 viewport.firePropertyChange("alignment", null, viewport
559 .getAlignment().getSequences());
566 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
568 ap.alignFrame = this;
569 avc = new jalview.controller.AlignViewController(this, viewport, alignPanel);
571 alignPanels.addElement(ap);
573 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
575 int aSize = alignPanels.size();
577 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
579 if (aSize == 1 && ap.av.viewName == null)
581 this.getContentPane().add(ap, BorderLayout.CENTER);
587 setInitialTabVisible();
590 expandViews.setEnabled(true);
591 gatherViews.setEnabled(true);
592 tabbedPane.addTab(ap.av.viewName, ap);
594 ap.setVisible(false);
599 if (ap.av.isPadGaps())
601 ap.av.getAlignment().padGaps();
603 ap.av.updateConservation(ap);
604 ap.av.updateConsensus(ap);
605 ap.av.updateStrucConsensus(ap);
609 public void setInitialTabVisible()
611 expandViews.setEnabled(true);
612 gatherViews.setEnabled(true);
613 tabbedPane.setVisible(true);
614 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
615 tabbedPane.addTab(first.av.viewName, first);
616 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
619 public AlignViewport getViewport()
624 /* Set up intrinsic listeners for dynamically generated GUI bits. */
625 private void addServiceListeners()
627 final java.beans.PropertyChangeListener thisListener;
628 Desktop.instance.addJalviewPropertyChangeListener("services",
629 thisListener = new java.beans.PropertyChangeListener()
632 public void propertyChange(PropertyChangeEvent evt)
634 // // System.out.println("Discoverer property change.");
635 // if (evt.getPropertyName().equals("services"))
637 SwingUtilities.invokeLater(new Runnable()
644 .println("Rebuild WS Menu for service change");
645 BuildWebServiceMenu();
652 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
655 public void internalFrameClosed(
656 javax.swing.event.InternalFrameEvent evt)
658 System.out.println("deregistering discoverer listener");
659 Desktop.instance.removeJalviewPropertyChangeListener("services",
661 closeMenuItem_actionPerformed(true);
664 // Finally, build the menu once to get current service state
665 new Thread(new Runnable()
670 BuildWebServiceMenu();
675 public void setGUINucleotide(boolean nucleotide)
677 showTranslation.setVisible(nucleotide);
678 conservationMenuItem.setEnabled(!nucleotide);
679 modifyConservation.setEnabled(!nucleotide);
680 showGroupConservation.setEnabled(!nucleotide);
681 rnahelicesColour.setEnabled(nucleotide);
682 purinePyrimidineColour.setEnabled(nucleotide);
683 // Remember AlignFrame always starts as protein
687 // calculateMenu.remove(calculateMenu.getItemCount() - 2);
692 * set up menus for the currently viewport. This may be called after any
693 * operation that affects the data in the current view (selection changed,
694 * etc) to update the menus to reflect the new state.
696 public void setMenusForViewport()
698 setMenusFromViewport(viewport);
702 * Need to call this method when tabs are selected for multiple views, or when
703 * loading from Jalview2XML.java
708 void setMenusFromViewport(AlignViewport av)
710 padGapsMenuitem.setSelected(av.isPadGaps());
711 colourTextMenuItem.setSelected(av.showColourText);
712 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
713 conservationMenuItem.setSelected(av.getConservationSelected());
714 seqLimits.setSelected(av.getShowJVSuffix());
715 idRightAlign.setSelected(av.rightAlignIds);
716 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
717 renderGapsMenuItem.setSelected(av.renderGaps);
718 wrapMenuItem.setSelected(av.wrapAlignment);
719 scaleAbove.setVisible(av.wrapAlignment);
720 scaleLeft.setVisible(av.wrapAlignment);
721 scaleRight.setVisible(av.wrapAlignment);
722 annotationPanelMenuItem.setState(av.showAnnotation);
723 viewBoxesMenuItem.setSelected(av.showBoxes);
724 viewTextMenuItem.setSelected(av.showText);
725 showNonconservedMenuItem.setSelected(av.getShowUnconserved());
726 showGroupConsensus.setSelected(av.isShowGroupConsensus());
727 showGroupConservation.setSelected(av.isShowGroupConservation());
728 showConsensusHistogram.setSelected(av.isShowConsensusHistogram());
729 showSequenceLogo.setSelected(av.isShowSequenceLogo());
730 normaliseSequenceLogo.setSelected(av.isNormaliseSequenceLogo());
732 setColourSelected(ColourSchemeProperty.getColourName(av
733 .getGlobalColourScheme()));
735 showSeqFeatures.setSelected(av.showSequenceFeatures);
736 hiddenMarkers.setState(av.showHiddenMarkers);
737 applyToAllGroups.setState(av.getColourAppliesToAllGroups());
738 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
739 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
740 autoCalculate.setSelected(av.autoCalculateConsensus);
741 sortByTree.setSelected(av.sortByTree);
742 listenToViewSelections.setSelected(av.followSelection);
743 rnahelicesColour.setEnabled(av.getAlignment().hasRNAStructure());
745 .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
746 setShowProductsEnabled();
750 // methods for implementing IProgressIndicator
751 // need to refactor to a reusable stub class
752 Hashtable progressBars, progressBarHandlers;
757 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
760 public void setProgressBar(String message, long id)
762 if (progressBars == null)
764 progressBars = new Hashtable();
765 progressBarHandlers = new Hashtable();
768 JPanel progressPanel;
769 Long lId = new Long(id);
770 GridLayout layout = (GridLayout) statusPanel.getLayout();
771 if (progressBars.get(lId) != null)
773 progressPanel = (JPanel) progressBars.get(new Long(id));
774 statusPanel.remove(progressPanel);
775 progressBars.remove(lId);
776 progressPanel = null;
779 statusBar.setText(message);
781 if (progressBarHandlers.contains(lId))
783 progressBarHandlers.remove(lId);
785 layout.setRows(layout.getRows() - 1);
789 progressPanel = new JPanel(new BorderLayout(10, 5));
791 JProgressBar progressBar = new JProgressBar();
792 progressBar.setIndeterminate(true);
794 progressPanel.add(new JLabel(message), BorderLayout.WEST);
795 progressPanel.add(progressBar, BorderLayout.CENTER);
797 layout.setRows(layout.getRows() + 1);
798 statusPanel.add(progressPanel);
800 progressBars.put(lId, progressPanel);
803 // setMenusForViewport();
808 public void registerHandler(final long id,
809 final IProgressIndicatorHandler handler)
811 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
814 "call setProgressBar before registering the progress bar's handler.");
816 progressBarHandlers.put(new Long(id), handler);
817 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
818 if (handler.canCancel())
820 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
821 final IProgressIndicator us = this;
822 cancel.addActionListener(new ActionListener()
826 public void actionPerformed(ActionEvent e)
828 handler.cancelActivity(id);
831 + ((JLabel) progressPanel.getComponent(0))
835 progressPanel.add(cancel, BorderLayout.EAST);
841 * @return true if any progress bars are still active
844 public boolean operationInProgress()
846 if (progressBars != null && progressBars.size() > 0)
854 public void setStatus(String text) {
855 statusBar.setText(text);
858 * Added so Castor Mapping file can obtain Jalview Version
860 public String getVersion()
862 return jalview.bin.Cache.getProperty("VERSION");
865 public FeatureRenderer getFeatureRenderer()
867 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
871 public void fetchSequence_actionPerformed(ActionEvent e)
873 new SequenceFetcher(this);
877 public void addFromFile_actionPerformed(ActionEvent e)
879 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
883 public void reload_actionPerformed(ActionEvent e)
885 if (fileName != null)
887 // TODO: JAL-1108 - ensure all associated frames are closed regardless of
888 // originating file's format
889 // TODO: work out how to recover feature settings for correct view(s) when
891 if (currentFileFormat.equals("Jalview"))
893 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
894 for (int i = 0; i < frames.length; i++)
896 if (frames[i] instanceof AlignFrame && frames[i] != this
897 && ((AlignFrame) frames[i]).fileName != null
898 && ((AlignFrame) frames[i]).fileName.equals(fileName))
902 frames[i].setSelected(true);
903 Desktop.instance.closeAssociatedWindows();
904 } catch (java.beans.PropertyVetoException ex)
910 Desktop.instance.closeAssociatedWindows();
912 FileLoader loader = new FileLoader();
913 String protocol = fileName.startsWith("http:") ? "URL" : "File";
914 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
918 Rectangle bounds = this.getBounds();
920 FileLoader loader = new FileLoader();
921 String protocol = fileName.startsWith("http:") ? "URL" : "File";
922 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
923 protocol, currentFileFormat);
925 newframe.setBounds(bounds);
926 if (featureSettings != null && featureSettings.isShowing())
928 final Rectangle fspos = featureSettings.frame.getBounds();
929 // TODO: need a 'show feature settings' function that takes bounds -
930 // need to refactor Desktop.addFrame
931 newframe.featureSettings_actionPerformed(null);
932 final FeatureSettings nfs = newframe.featureSettings;
933 SwingUtilities.invokeLater(new Runnable()
938 nfs.frame.setBounds(fspos);
941 this.featureSettings.close();
942 this.featureSettings = null;
944 this.closeMenuItem_actionPerformed(true);
950 public void addFromText_actionPerformed(ActionEvent e)
952 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
956 public void addFromURL_actionPerformed(ActionEvent e)
958 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
962 public void save_actionPerformed(ActionEvent e)
965 || (currentFileFormat == null || !jalview.io.FormatAdapter
966 .isValidIOFormat(currentFileFormat, true))
967 || fileName.startsWith("http"))
969 saveAs_actionPerformed(null);
973 saveAlignment(fileName, currentFileFormat);
984 public void saveAs_actionPerformed(ActionEvent e)
986 JalviewFileChooser chooser = new JalviewFileChooser(
987 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
988 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
989 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
990 currentFileFormat, false);
992 chooser.setFileView(new JalviewFileView());
993 chooser.setDialogTitle("Save Alignment to file");
994 chooser.setToolTipText(MessageManager.getString("action.save"));
\r
996 int value = chooser.showSaveDialog(this);
998 if (value == JalviewFileChooser.APPROVE_OPTION)
1000 currentFileFormat = chooser.getSelectedFormat();
1001 if (currentFileFormat == null)
1003 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1004 MessageManager.getString("label.select_file_format_before_saving"),
1005 MessageManager.getString("label.file_format_not_specified"), JOptionPane.WARNING_MESSAGE);
1006 value = chooser.showSaveDialog(this);
1010 fileName = chooser.getSelectedFile().getPath();
1012 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
1015 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
1016 if (currentFileFormat.indexOf(" ") > -1)
1018 currentFileFormat = currentFileFormat.substring(0,
1019 currentFileFormat.indexOf(" "));
1021 saveAlignment(fileName, currentFileFormat);
1025 public boolean saveAlignment(String file, String format)
1027 boolean success = true;
1029 if (format.equalsIgnoreCase("Jalview"))
1031 String shortName = title;
1033 if (shortName.indexOf(java.io.File.separatorChar) > -1)
1035 shortName = shortName.substring(shortName
1036 .lastIndexOf(java.io.File.separatorChar) + 1);
1039 success = new Jalview2XML().SaveAlignment(this, file, shortName);
1041 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1047 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
1049 warningMessage("Cannot save file " + fileName + " using format "
1050 + format, "Alignment output format not supported");
1051 saveAs_actionPerformed(null);
1052 // JBPNote need to have a raise_gui flag here
1056 String[] omitHidden = null;
1058 if (viewport.hasHiddenColumns())
1060 int reply = JOptionPane
1061 .showInternalConfirmDialog(
1063 MessageManager.getString("label.alignment_contains_hidden_columns"),
1064 MessageManager.getString("action.save_omit_hidden_columns"),
1065 JOptionPane.YES_NO_OPTION,
1066 JOptionPane.QUESTION_MESSAGE);
1068 if (reply == JOptionPane.YES_OPTION)
1070 omitHidden = viewport.getViewAsString(false);
1073 FormatAdapter f = new FormatAdapter();
1074 String output = f.formatSequences(format,
1075 viewport.getAlignment(), // class cast exceptions will
1076 // occur in the distant future
1077 omitHidden, f.getCacheSuffixDefault(format),
1078 viewport.getColumnSelection());
1088 java.io.PrintWriter out = new java.io.PrintWriter(
1089 new java.io.FileWriter(file));
1093 this.setTitle(file);
1094 statusBar.setText(MessageManager.formatMessage("label.successfully_saved_to_file_in_format",new String[]{fileName, format}));
1095 } catch (Exception ex)
1098 ex.printStackTrace();
1105 JOptionPane.showInternalMessageDialog(this, MessageManager.formatMessage("label.couldnt_save_file", new String[]{fileName}),
1106 MessageManager.getString("label.error_saving_file"), JOptionPane.WARNING_MESSAGE);
1112 private void warningMessage(String warning, String title)
1114 if (new jalview.util.Platform().isHeadless())
1116 System.err.println("Warning: " + title + "\nWarning: " + warning);
1121 JOptionPane.showInternalMessageDialog(this, warning, title,
1122 JOptionPane.WARNING_MESSAGE);
1134 protected void outputText_actionPerformed(ActionEvent e)
1136 String[] omitHidden = null;
1138 if (viewport.hasHiddenColumns())
1140 int reply = JOptionPane
1141 .showInternalConfirmDialog(
1143 MessageManager.getString("label.alignment_contains_hidden_columns"),
1144 MessageManager.getString("action.save_omit_hidden_columns"),
1145 JOptionPane.YES_NO_OPTION,
1146 JOptionPane.QUESTION_MESSAGE);
1148 if (reply == JOptionPane.YES_OPTION)
1150 omitHidden = viewport.getViewAsString(false);
1154 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1155 cap.setForInput(null);
1159 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1160 viewport.getAlignment(), omitHidden,
1161 viewport.getColumnSelection()));
1162 Desktop.addInternalFrame(cap,
1163 MessageManager.formatMessage("label.alignment_output_command", new String[]{e.getActionCommand()}), 600, 500);
\r
1164 } catch (OutOfMemoryError oom)
1166 new OOMWarning("Outputting alignment as " + e.getActionCommand(), oom);
1179 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1181 new HTMLOutput(alignPanel,
1182 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
1183 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1186 public void createImageMap(File file, String image)
1188 alignPanel.makePNGImageMap(file, image);
1198 public void createPNG(File f)
1200 alignPanel.makePNG(f);
1210 public void createEPS(File f)
1212 alignPanel.makeEPS(f);
1216 public void pageSetup_actionPerformed(ActionEvent e)
1218 PrinterJob printJob = PrinterJob.getPrinterJob();
1219 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1229 public void printMenuItem_actionPerformed(ActionEvent e)
1231 // Putting in a thread avoids Swing painting problems
1232 PrintThread thread = new PrintThread(alignPanel);
1237 public void exportFeatures_actionPerformed(ActionEvent e)
1239 new AnnotationExporter().exportFeatures(alignPanel);
1243 public void exportAnnotations_actionPerformed(ActionEvent e)
1245 new AnnotationExporter().exportAnnotations(alignPanel,
1246 viewport.showAnnotation ? viewport.getAlignment()
1247 .getAlignmentAnnotation() : null, viewport
1248 .getAlignment().getGroups(), ((Alignment) viewport
1249 .getAlignment()).alignmentProperties);
1253 public void associatedData_actionPerformed(ActionEvent e)
1255 // Pick the tree file
1256 JalviewFileChooser chooser = new JalviewFileChooser(
1257 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1258 chooser.setFileView(new JalviewFileView());
1259 chooser.setDialogTitle(MessageManager.getString("label.load_jalview_annotations"));
\r
1260 chooser.setToolTipText(MessageManager.getString("label.load_jalview_annotations"));
\r
1262 int value = chooser.showOpenDialog(null);
1264 if (value == JalviewFileChooser.APPROVE_OPTION)
1266 String choice = chooser.getSelectedFile().getPath();
1267 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1268 loadJalviewDataFile(choice, null, null, null);
1274 * Close the current view or all views in the alignment frame. If the frame
1275 * only contains one view then the alignment will be removed from memory.
1277 * @param closeAllTabs
1280 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1282 if (alignPanels != null && alignPanels.size() < 2)
1284 closeAllTabs = true;
1289 if (alignPanels != null)
1293 if (this.isClosed())
1295 // really close all the windows - otherwise wait till
1296 // setClosed(true) is called
1297 for (int i = 0; i < alignPanels.size(); i++)
1299 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1306 closeView(alignPanel);
1312 this.setClosed(true);
1314 } catch (Exception ex)
1316 ex.printStackTrace();
1321 * close alignPanel2 and shuffle tabs appropriately.
1323 * @param alignPanel2
1325 public void closeView(AlignmentPanel alignPanel2)
1327 int index = tabbedPane.getSelectedIndex();
1328 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1329 alignPanels.removeElement(alignPanel2);
1331 // if (viewport == alignPanel2.av)
1335 alignPanel2.closePanel();
1338 tabbedPane.removeTabAt(closedindex);
1339 tabbedPane.validate();
1341 if (index > closedindex || index == tabbedPane.getTabCount())
1343 // modify currently selected tab index if necessary.
1347 this.tabSelectionChanged(index);
1353 void updateEditMenuBar()
1356 if (viewport.historyList.size() > 0)
1358 undoMenuItem.setEnabled(true);
1359 CommandI command = (CommandI) viewport.historyList.peek();
1360 undoMenuItem.setText(MessageManager.formatMessage("label.undo_command", new String[]{command.getDescription()}));
1364 undoMenuItem.setEnabled(false);
1365 undoMenuItem.setText(MessageManager.getString("action.undo"));
1368 if (viewport.redoList.size() > 0)
1370 redoMenuItem.setEnabled(true);
1372 CommandI command = (CommandI) viewport.redoList.peek();
1373 redoMenuItem.setText(MessageManager.formatMessage("label.redo_command", new String[]{command.getDescription()}));
1377 redoMenuItem.setEnabled(false);
1378 redoMenuItem.setText(MessageManager.getString("action.redo"));
1382 public void addHistoryItem(CommandI command)
1384 if (command.getSize() > 0)
1386 viewport.historyList.push(command);
1387 viewport.redoList.clear();
1388 updateEditMenuBar();
1389 viewport.updateHiddenColumns();
1390 // viewport.hasHiddenColumns = (viewport.getColumnSelection() != null
1391 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1392 // viewport.getColumnSelection()
1393 // .getHiddenColumns().size() > 0);
1399 * @return alignment objects for all views
1401 AlignmentI[] getViewAlignments()
1403 if (alignPanels != null)
1405 Enumeration e = alignPanels.elements();
1406 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1407 for (int i = 0; e.hasMoreElements(); i++)
1409 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1413 if (viewport != null)
1415 return new AlignmentI[]
1416 { viewport.getAlignment() };
1428 protected void undoMenuItem_actionPerformed(ActionEvent e)
1430 if (viewport.historyList.empty())
1432 CommandI command = (CommandI) viewport.historyList.pop();
1433 viewport.redoList.push(command);
1434 command.undoCommand(getViewAlignments());
1436 AlignViewport originalSource = getOriginatingSource(command);
1437 updateEditMenuBar();
1439 if (originalSource != null)
1441 if (originalSource != viewport)
1444 .warn("Implementation worry: mismatch of viewport origin for undo");
1446 originalSource.updateHiddenColumns();
1447 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1449 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1450 // viewport.getColumnSelection()
1451 // .getHiddenColumns().size() > 0);
1452 originalSource.firePropertyChange("alignment", null, originalSource
1453 .getAlignment().getSequences());
1464 protected void redoMenuItem_actionPerformed(ActionEvent e)
1466 if (viewport.redoList.size() < 1)
1471 CommandI command = (CommandI) viewport.redoList.pop();
1472 viewport.historyList.push(command);
1473 command.doCommand(getViewAlignments());
1475 AlignViewport originalSource = getOriginatingSource(command);
1476 updateEditMenuBar();
1478 if (originalSource != null)
1481 if (originalSource != viewport)
1484 .warn("Implementation worry: mismatch of viewport origin for redo");
1486 originalSource.updateHiddenColumns();
1487 // originalSource.hasHiddenColumns = (viewport.getColumnSelection() !=
1489 // && viewport.getColumnSelection().getHiddenColumns() != null &&
1490 // viewport.getColumnSelection()
1491 // .getHiddenColumns().size() > 0);
1492 originalSource.firePropertyChange("alignment", null, originalSource
1493 .getAlignment().getSequences());
1497 AlignViewport getOriginatingSource(CommandI command)
1499 AlignViewport originalSource = null;
1500 // For sequence removal and addition, we need to fire
1501 // the property change event FROM the viewport where the
1502 // original alignment was altered
1503 AlignmentI al = null;
1504 if (command instanceof EditCommand)
1506 EditCommand editCommand = (EditCommand) command;
1507 al = editCommand.getAlignment();
1508 Vector comps = (Vector) PaintRefresher.components.get(viewport
1509 .getSequenceSetId());
1511 for (int i = 0; i < comps.size(); i++)
1513 if (comps.elementAt(i) instanceof AlignmentPanel)
1515 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1517 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1524 if (originalSource == null)
1526 // The original view is closed, we must validate
1527 // the current view against the closed view first
1530 PaintRefresher.validateSequences(al, viewport.getAlignment());
1533 originalSource = viewport;
1536 return originalSource;
1545 public void moveSelectedSequences(boolean up)
1547 SequenceGroup sg = viewport.getSelectionGroup();
1553 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1554 viewport.getHiddenRepSequences(), up);
1555 alignPanel.paintAlignment(true);
1558 synchronized void slideSequences(boolean right, int size)
1560 List<SequenceI> sg = new Vector();
1561 if (viewport.cursorMode)
1563 sg.add(viewport.getAlignment().getSequenceAt(
1564 alignPanel.seqPanel.seqCanvas.cursorY));
1566 else if (viewport.getSelectionGroup() != null
1567 && viewport.getSelectionGroup().getSize() != viewport
1568 .getAlignment().getHeight())
1570 sg = viewport.getSelectionGroup().getSequences(
1571 viewport.getHiddenRepSequences());
1579 Vector invertGroup = new Vector();
1581 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1583 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1584 invertGroup.add(viewport.getAlignment().getSequenceAt(i));
1587 SequenceI[] seqs1 = sg.toArray(new SequenceI[0]);
1589 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1590 for (int i = 0; i < invertGroup.size(); i++)
1591 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1593 SlideSequencesCommand ssc;
1595 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1596 size, viewport.getGapCharacter());
1598 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1599 size, viewport.getGapCharacter());
1601 int groupAdjustment = 0;
1602 if (ssc.getGapsInsertedBegin() && right)
1604 if (viewport.cursorMode)
1605 alignPanel.seqPanel.moveCursor(size, 0);
1607 groupAdjustment = size;
1609 else if (!ssc.getGapsInsertedBegin() && !right)
1611 if (viewport.cursorMode)
1612 alignPanel.seqPanel.moveCursor(-size, 0);
1614 groupAdjustment = -size;
1617 if (groupAdjustment != 0)
1619 viewport.getSelectionGroup().setStartRes(
1620 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1621 viewport.getSelectionGroup().setEndRes(
1622 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1625 boolean appendHistoryItem = false;
1626 if (viewport.historyList != null && viewport.historyList.size() > 0
1627 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1629 appendHistoryItem = ssc
1630 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1634 if (!appendHistoryItem)
1635 addHistoryItem(ssc);
1647 protected void copy_actionPerformed(ActionEvent e)
1650 if (viewport.getSelectionGroup() == null)
1654 // TODO: preserve the ordering of displayed alignment annotation in any
1655 // internal paste (particularly sequence associated annotation)
1656 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1657 String[] omitHidden = null;
1659 if (viewport.hasHiddenColumns())
1661 omitHidden = viewport.getViewAsString(true);
1664 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1667 StringSelection ss = new StringSelection(output);
1671 jalview.gui.Desktop.internalCopy = true;
1672 // Its really worth setting the clipboard contents
1673 // to empty before setting the large StringSelection!!
1674 Toolkit.getDefaultToolkit().getSystemClipboard()
1675 .setContents(new StringSelection(""), null);
1677 Toolkit.getDefaultToolkit().getSystemClipboard()
1678 .setContents(ss, Desktop.instance);
1679 } catch (OutOfMemoryError er)
1681 new OOMWarning("copying region", er);
1685 Vector hiddenColumns = null;
1686 if (viewport.hasHiddenColumns())
1688 hiddenColumns = new Vector();
1689 int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport
1690 .getSelectionGroup().getEndRes();
1691 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1694 int[] region = (int[]) viewport.getColumnSelection()
1695 .getHiddenColumns().elementAt(i);
1696 if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff)
1698 hiddenColumns.addElement(new int[]
1699 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1704 Desktop.jalviewClipboard = new Object[]
1705 { seqs, viewport.getAlignment().getDataset(), hiddenColumns };
1706 statusBar.setText(MessageManager.formatMessage("label.copied_sequences_to_clipboard", new String[]{Integer.valueOf(seqs.length).toString()}));
1716 protected void pasteNew_actionPerformed(ActionEvent e)
1728 protected void pasteThis_actionPerformed(ActionEvent e)
1734 * Paste contents of Jalview clipboard
1736 * @param newAlignment
1737 * true to paste to a new alignment, otherwise add to this.
1739 void paste(boolean newAlignment)
1741 boolean externalPaste = true;
1744 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1745 Transferable contents = c.getContents(this);
1747 if (contents == null)
1755 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1756 if (str.length() < 1)
1761 format = new IdentifyFile().Identify(str, "Paste");
1763 } catch (OutOfMemoryError er)
1765 new OOMWarning("Out of memory pasting sequences!!", er);
1769 SequenceI[] sequences;
1770 boolean annotationAdded = false;
1771 AlignmentI alignment = null;
1773 if (Desktop.jalviewClipboard != null)
1775 // The clipboard was filled from within Jalview, we must use the
1777 // And dataset from the copied alignment
1778 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1779 // be doubly sure that we create *new* sequence objects.
1780 sequences = new SequenceI[newseq.length];
1781 for (int i = 0; i < newseq.length; i++)
1783 sequences[i] = new Sequence(newseq[i]);
1785 alignment = new Alignment(sequences);
1786 externalPaste = false;
1790 // parse the clipboard as an alignment.
1791 alignment = new FormatAdapter().readFile(str, "Paste", format);
1792 sequences = alignment.getSequencesArray();
1796 ArrayList<Integer> newGraphGroups = new ArrayList<Integer>();
1802 if (Desktop.jalviewClipboard != null)
1804 // dataset is inherited
1805 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1809 // new dataset is constructed
1810 alignment.setDataset(null);
1812 alwidth = alignment.getWidth() + 1;
1816 AlignmentI pastedal = alignment; // preserve pasted alignment object
1817 // Add pasted sequences and dataset into existing alignment.
1818 alignment = viewport.getAlignment();
1819 alwidth = alignment.getWidth() + 1;
1820 // decide if we need to import sequences from an existing dataset
1821 boolean importDs = Desktop.jalviewClipboard != null
1822 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1823 // importDs==true instructs us to copy over new dataset sequences from
1824 // an existing alignment
1825 Vector newDs = (importDs) ? new Vector() : null; // used to create
1826 // minimum dataset set
1828 for (int i = 0; i < sequences.length; i++)
1832 newDs.addElement(null);
1834 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1836 if (importDs && ds != null)
1838 if (!newDs.contains(ds))
1840 newDs.setElementAt(ds, i);
1841 ds = new Sequence(ds);
1842 // update with new dataset sequence
1843 sequences[i].setDatasetSequence(ds);
1847 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1852 // copy and derive new dataset sequence
1853 sequences[i] = sequences[i].deriveSequence();
1854 alignment.getDataset().addSequence(
1855 sequences[i].getDatasetSequence());
1856 // TODO: avoid creation of duplicate dataset sequences with a
1857 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1859 alignment.addSequence(sequences[i]); // merges dataset
1863 newDs.clear(); // tidy up
1865 if (alignment.getAlignmentAnnotation() != null)
1867 for (AlignmentAnnotation alan : alignment
1868 .getAlignmentAnnotation())
1870 if (alan.graphGroup > fgroup)
1872 fgroup = alan.graphGroup;
1876 if (pastedal.getAlignmentAnnotation() != null)
1878 // Add any annotation attached to alignment.
1879 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1880 for (int i = 0; i < alann.length; i++)
1882 annotationAdded = true;
1883 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1885 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1886 if (newann.graphGroup > -1)
1888 if (newGraphGroups.size() <= newann.graphGroup
1889 || newGraphGroups.get(newann.graphGroup) == null)
1891 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1893 newGraphGroups.add(q, null);
1895 newGraphGroups.set(newann.graphGroup, new Integer(
1898 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1902 newann.padAnnotation(alwidth);
1903 alignment.addAnnotation(newann);
1913 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1914 sequences, 0, alignment.getWidth(), alignment));
1916 // Add any annotations attached to sequences
1917 for (int i = 0; i < sequences.length; i++)
1919 if (sequences[i].getAnnotation() != null)
1921 AlignmentAnnotation newann;
1922 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1924 annotationAdded = true;
1925 newann = sequences[i].getAnnotation()[a];
1926 newann.adjustForAlignment();
1927 newann.padAnnotation(alwidth);
1928 if (newann.graphGroup > -1)
1930 if (newann.graphGroup > -1)
1932 if (newGraphGroups.size() <= newann.graphGroup
1933 || newGraphGroups.get(newann.graphGroup) == null)
1935 for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++)
1937 newGraphGroups.add(q, null);
1939 newGraphGroups.set(newann.graphGroup, new Integer(
1942 newann.graphGroup = newGraphGroups.get(newann.graphGroup)
1946 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1951 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1958 // propagate alignment changed.
1959 viewport.setEndSeq(alignment.getHeight());
1960 if (annotationAdded)
1962 // Duplicate sequence annotation in all views.
1963 AlignmentI[] alview = this.getViewAlignments();
1964 for (int i = 0; i < sequences.length; i++)
1966 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1969 for (int avnum = 0; avnum < alview.length; avnum++)
1971 if (alview[avnum] != alignment)
1973 // duplicate in a view other than the one with input focus
1974 int avwidth = alview[avnum].getWidth() + 1;
1975 // this relies on sann being preserved after we
1976 // modify the sequence's annotation array for each duplication
1977 for (int a = 0; a < sann.length; a++)
1979 AlignmentAnnotation newann = new AlignmentAnnotation(
1981 sequences[i].addAlignmentAnnotation(newann);
1982 newann.padAnnotation(avwidth);
1983 alview[avnum].addAnnotation(newann); // annotation was
1984 // duplicated earlier
1985 // TODO JAL-1145 graphGroups are not updated for sequence
1986 // annotation added to several views. This may cause
1988 alview[avnum].setAnnotationIndex(newann, a);
1993 buildSortByAnnotationScoresMenu();
1995 viewport.firePropertyChange("alignment", null,
1996 alignment.getSequences());
1997 if (alignPanels != null)
1999 for (AlignmentPanel ap : ((Vector<AlignmentPanel>) alignPanels))
2001 ap.validateAnnotationDimensions(false);
2006 alignPanel.validateAnnotationDimensions(false);
2012 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
2014 String newtitle = new String("Copied sequences");
2016 if (Desktop.jalviewClipboard != null
2017 && Desktop.jalviewClipboard[2] != null)
2019 Vector hc = (Vector) Desktop.jalviewClipboard[2];
2020 for (int i = 0; i < hc.size(); i++)
2022 int[] region = (int[]) hc.elementAt(i);
2023 af.viewport.hideColumns(region[0], region[1]);
2027 // >>>This is a fix for the moment, until a better solution is
2029 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
2031 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
2033 // TODO: maintain provenance of an alignment, rather than just make the
2034 // title a concatenation of operations.
2037 if (title.startsWith("Copied sequences"))
2043 newtitle = newtitle.concat("- from " + title);
2048 newtitle = new String("Pasted sequences");
2051 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
2056 } catch (Exception ex)
2058 ex.printStackTrace();
2059 System.out.println("Exception whilst pasting: " + ex);
2060 // could be anything being pasted in here
2072 protected void cut_actionPerformed(ActionEvent e)
2074 copy_actionPerformed(null);
2075 delete_actionPerformed(null);
2085 protected void delete_actionPerformed(ActionEvent evt)
2088 SequenceGroup sg = viewport.getSelectionGroup();
2094 Vector seqs = new Vector();
2096 for (int i = 0; i < sg.getSize(); i++)
2098 seq = sg.getSequenceAt(i);
2099 seqs.addElement(seq);
2102 // If the cut affects all sequences, remove highlighted columns
2103 if (sg.getSize() == viewport.getAlignment().getHeight())
2105 viewport.getColumnSelection().removeElements(sg.getStartRes(),
2106 sg.getEndRes() + 1);
2109 SequenceI[] cut = new SequenceI[seqs.size()];
2110 for (int i = 0; i < seqs.size(); i++)
2112 cut[i] = (SequenceI) seqs.elementAt(i);
2116 * //ADD HISTORY ITEM
2118 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
2119 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
2120 viewport.getAlignment()));
2122 viewport.setSelectionGroup(null);
2123 viewport.sendSelection();
2124 viewport.getAlignment().deleteGroup(sg);
2126 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2128 if (viewport.getAlignment().getHeight() < 1)
2132 this.setClosed(true);
2133 } catch (Exception ex)
2146 protected void deleteGroups_actionPerformed(ActionEvent e)
2148 if (avc.deleteGroups()) {
2149 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
2150 alignPanel.updateAnnotation();
2151 alignPanel.paintAlignment(true);
2162 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2164 SequenceGroup sg = new SequenceGroup();
2166 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2168 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
2171 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
2172 viewport.setSelectionGroup(sg);
2173 viewport.sendSelection();
2174 alignPanel.paintAlignment(true);
2175 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2185 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
2187 if (viewport.cursorMode)
2189 alignPanel.seqPanel.keyboardNo1 = null;
2190 alignPanel.seqPanel.keyboardNo2 = null;
2192 viewport.setSelectionGroup(null);
2193 viewport.getColumnSelection().clear();
2194 viewport.setSelectionGroup(null);
2195 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
2196 alignPanel.idPanel.idCanvas.searchResults = null;
2197 alignPanel.paintAlignment(true);
2198 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2199 viewport.sendSelection();
2209 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
2211 SequenceGroup sg = viewport.getSelectionGroup();
2215 selectAllSequenceMenuItem_actionPerformed(null);
2220 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2222 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
2225 alignPanel.paintAlignment(true);
2226 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
2227 viewport.sendSelection();
2231 public void invertColSel_actionPerformed(ActionEvent e)
2233 viewport.invertColumnSelection();
2234 alignPanel.paintAlignment(true);
2235 viewport.sendSelection();
2245 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2247 trimAlignment(true);
2257 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2259 trimAlignment(false);
2262 void trimAlignment(boolean trimLeft)
2264 ColumnSelection colSel = viewport.getColumnSelection();
2267 if (colSel.size() > 0)
2271 column = colSel.getMin();
2275 column = colSel.getMax();
2279 if (viewport.getSelectionGroup() != null)
2281 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2282 viewport.getHiddenRepSequences());
2286 seqs = viewport.getAlignment().getSequencesArray();
2289 TrimRegionCommand trimRegion;
2292 trimRegion = new TrimRegionCommand("Remove Left",
2293 TrimRegionCommand.TRIM_LEFT, seqs, column,
2294 viewport.getAlignment(), viewport.getColumnSelection(),
2295 viewport.getSelectionGroup());
2296 viewport.setStartRes(0);
2300 trimRegion = new TrimRegionCommand("Remove Right",
2301 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2302 viewport.getAlignment(), viewport.getColumnSelection(),
2303 viewport.getSelectionGroup());
2306 statusBar.setText(MessageManager.formatMessage("label.removed_columns", new String[]{Integer.valueOf(trimRegion.getSize()).toString()}));
2308 addHistoryItem(trimRegion);
2310 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2312 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2313 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2315 viewport.getAlignment().deleteGroup(sg);
2319 viewport.firePropertyChange("alignment", null, viewport
2320 .getAlignment().getSequences());
2331 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2333 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2336 if (viewport.getSelectionGroup() != null)
2338 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2339 viewport.getHiddenRepSequences());
2340 start = viewport.getSelectionGroup().getStartRes();
2341 end = viewport.getSelectionGroup().getEndRes();
2345 seqs = viewport.getAlignment().getSequencesArray();
2348 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2349 "Remove Gapped Columns", seqs, start, end,
2350 viewport.getAlignment());
2352 addHistoryItem(removeGapCols);
2354 statusBar.setText(MessageManager.formatMessage("label.removed_empty_columns", new String[]{Integer.valueOf(removeGapCols.getSize()).toString()}));
2356 // This is to maintain viewport position on first residue
2357 // of first sequence
2358 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2359 int startRes = seq.findPosition(viewport.startRes);
2360 // ShiftList shifts;
2361 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2362 // edit.alColumnChanges=shifts.getInverse();
2363 // if (viewport.hasHiddenColumns)
2364 // viewport.getColumnSelection().compensateForEdits(shifts);
2365 viewport.setStartRes(seq.findIndex(startRes) - 1);
2366 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2378 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2380 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2383 if (viewport.getSelectionGroup() != null)
2385 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2386 viewport.getHiddenRepSequences());
2387 start = viewport.getSelectionGroup().getStartRes();
2388 end = viewport.getSelectionGroup().getEndRes();
2392 seqs = viewport.getAlignment().getSequencesArray();
2395 // This is to maintain viewport position on first residue
2396 // of first sequence
2397 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2398 int startRes = seq.findPosition(viewport.startRes);
2400 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2401 viewport.getAlignment()));
2403 viewport.setStartRes(seq.findIndex(startRes) - 1);
2405 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2417 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2419 viewport.setPadGaps(padGapsMenuitem.isSelected());
2420 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2426 // if (justifySeqs>0)
2428 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2441 public void findMenuItem_actionPerformed(ActionEvent e)
2447 public void newView_actionPerformed(ActionEvent e)
2454 * @param copyAnnotation
2455 * if true then duplicate all annnotation, groups and settings
2456 * @return new alignment panel, already displayed.
2458 public AlignmentPanel newView(boolean copyAnnotation)
2460 return newView(null, copyAnnotation);
2466 * title of newly created view
2467 * @return new alignment panel, already displayed.
2469 public AlignmentPanel newView(String viewTitle)
2471 return newView(viewTitle, true);
2477 * title of newly created view
2478 * @param copyAnnotation
2479 * if true then duplicate all annnotation, groups and settings
2480 * @return new alignment panel, already displayed.
2482 public AlignmentPanel newView(String viewTitle, boolean copyAnnotation)
2484 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2486 if (!copyAnnotation)
2488 // just remove all the current annotation except for the automatic stuff
2489 newap.av.getAlignment().deleteAllGroups();
2490 for (AlignmentAnnotation alan : newap.av.getAlignment()
2491 .getAlignmentAnnotation())
2493 if (!alan.autoCalculated)
2495 newap.av.getAlignment().deleteAnnotation(alan);
2501 newap.av.gatherViewsHere = false;
2503 if (viewport.viewName == null)
2505 viewport.viewName = "Original";
2508 newap.av.historyList = viewport.historyList;
2509 newap.av.redoList = viewport.redoList;
2511 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2512 // make sure the new view has a unique name - this is essential for Jalview
2514 boolean addFirstIndex = false;
2515 if (viewTitle == null || viewTitle.trim().length() == 0)
2518 addFirstIndex = true;
2522 index = 1;// we count from 1 if given a specific name
2524 String newViewName = viewTitle + ((addFirstIndex) ? " " + index : "");
2525 Vector comps = (Vector) PaintRefresher.components.get(viewport
2526 .getSequenceSetId());
2527 Vector existingNames = new Vector();
2528 for (int i = 0; i < comps.size(); i++)
2530 if (comps.elementAt(i) instanceof AlignmentPanel)
2532 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2533 if (!existingNames.contains(ap.av.viewName))
2535 existingNames.addElement(ap.av.viewName);
2540 while (existingNames.contains(newViewName))
2542 newViewName = viewTitle + " " + (++index);
2545 newap.av.viewName = newViewName;
2547 addAlignmentPanel(newap, true);
2548 newap.alignmentChanged();
2550 if (alignPanels.size() == 2)
2552 viewport.gatherViewsHere = true;
2554 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2559 public void expandViews_actionPerformed(ActionEvent e)
2561 Desktop.instance.explodeViews(this);
2565 public void gatherViews_actionPerformed(ActionEvent e)
2567 Desktop.instance.gatherViews(this);
2577 public void font_actionPerformed(ActionEvent e)
2579 new FontChooser(alignPanel);
2589 protected void seqLimit_actionPerformed(ActionEvent e)
2591 viewport.setShowJVSuffix(seqLimits.isSelected());
2593 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2594 .calculateIdWidth());
2595 alignPanel.paintAlignment(true);
2599 public void idRightAlign_actionPerformed(ActionEvent e)
2601 viewport.rightAlignIds = idRightAlign.isSelected();
2602 alignPanel.paintAlignment(true);
2606 public void centreColumnLabels_actionPerformed(ActionEvent e)
2608 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2609 alignPanel.paintAlignment(true);
2615 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2618 protected void followHighlight_actionPerformed()
2620 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2622 alignPanel.scrollToPosition(
2623 alignPanel.seqPanel.seqCanvas.searchResults, false);
2634 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2636 viewport.setColourText(colourTextMenuItem.isSelected());
2637 alignPanel.paintAlignment(true);
2647 public void wrapMenuItem_actionPerformed(ActionEvent e)
2649 scaleAbove.setVisible(wrapMenuItem.isSelected());
2650 scaleLeft.setVisible(wrapMenuItem.isSelected());
2651 scaleRight.setVisible(wrapMenuItem.isSelected());
2652 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2653 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2657 public void showAllSeqs_actionPerformed(ActionEvent e)
2659 viewport.showAllHiddenSeqs();
2663 public void showAllColumns_actionPerformed(ActionEvent e)
2665 viewport.showAllHiddenColumns();
2670 public void hideSelSequences_actionPerformed(ActionEvent e)
2672 viewport.hideAllSelectedSeqs();
2673 alignPanel.paintAlignment(true);
2677 * called by key handler and the hide all/show all menu items
2682 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
2685 boolean hide = false;
2686 SequenceGroup sg = viewport.getSelectionGroup();
2687 if (!toggleSeqs && !toggleCols)
2689 // Hide everything by the current selection - this is a hack - we do the
2690 // invert and then hide
2691 // first check that there will be visible columns after the invert.
2692 if ((viewport.getColumnSelection() != null
2693 && viewport.getColumnSelection().getSelected() != null && viewport
2694 .getColumnSelection().getSelected().size() > 0)
2695 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
2698 // now invert the sequence set, if required - empty selection implies
2699 // that no hiding is required.
2702 invertSequenceMenuItem_actionPerformed(null);
2703 sg = viewport.getSelectionGroup();
2707 viewport.expandColSelection(sg, true);
2708 // finally invert the column selection and get the new sequence
2710 invertColSel_actionPerformed(null);
2717 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
2719 hideSelSequences_actionPerformed(null);
2722 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
2725 showAllSeqs_actionPerformed(null);
2731 if (viewport.getColumnSelection().getSelected().size() > 0)
2733 hideSelColumns_actionPerformed(null);
2736 viewport.setSelectionGroup(sg);
2741 showAllColumns_actionPerformed(null);
2750 * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt.
2751 * event.ActionEvent)
2754 public void hideAllButSelection_actionPerformed(ActionEvent e)
2756 toggleHiddenRegions(false, false);
2763 * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event
2767 public void hideAllSelection_actionPerformed(ActionEvent e)
2769 SequenceGroup sg = viewport.getSelectionGroup();
2770 viewport.expandColSelection(sg, false);
2771 viewport.hideAllSelectedSeqs();
2772 viewport.hideSelectedColumns();
2773 alignPanel.paintAlignment(true);
2780 * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event.
2784 public void showAllhidden_actionPerformed(ActionEvent e)
2786 viewport.showAllHiddenColumns();
2787 viewport.showAllHiddenSeqs();
2788 alignPanel.paintAlignment(true);
2792 public void hideSelColumns_actionPerformed(ActionEvent e)
2794 viewport.hideSelectedColumns();
2795 alignPanel.paintAlignment(true);
2799 public void hiddenMarkers_actionPerformed(ActionEvent e)
2801 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2812 protected void scaleAbove_actionPerformed(ActionEvent e)
2814 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2815 alignPanel.paintAlignment(true);
2825 protected void scaleLeft_actionPerformed(ActionEvent e)
2827 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2828 alignPanel.paintAlignment(true);
2838 protected void scaleRight_actionPerformed(ActionEvent e)
2840 viewport.setScaleRightWrapped(scaleRight.isSelected());
2841 alignPanel.paintAlignment(true);
2851 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2853 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2854 alignPanel.paintAlignment(true);
2864 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2866 viewport.setShowText(viewTextMenuItem.isSelected());
2867 alignPanel.paintAlignment(true);
2877 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2879 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2880 alignPanel.paintAlignment(true);
2883 public FeatureSettings featureSettings;
2886 public void featureSettings_actionPerformed(ActionEvent e)
2888 if (featureSettings != null)
2890 featureSettings.close();
2891 featureSettings = null;
2893 if (!showSeqFeatures.isSelected())
2895 // make sure features are actually displayed
2896 showSeqFeatures.setSelected(true);
2897 showSeqFeatures_actionPerformed(null);
2899 featureSettings = new FeatureSettings(this);
2903 * Set or clear 'Show Sequence Features'
2909 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2911 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2912 alignPanel.paintAlignment(true);
2913 if (alignPanel.getOverviewPanel() != null)
2915 alignPanel.getOverviewPanel().updateOverviewImage();
2920 * Set or clear 'Show Sequence Features'
2926 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2928 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2930 if (viewport.getShowSequenceFeaturesHeight())
2932 // ensure we're actually displaying features
2933 viewport.setShowSequenceFeatures(true);
2934 showSeqFeatures.setSelected(true);
2936 alignPanel.paintAlignment(true);
2937 if (alignPanel.getOverviewPanel() != null)
2939 alignPanel.getOverviewPanel().updateOverviewImage();
2950 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2952 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2953 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2957 public void alignmentProperties()
2959 JEditorPane editPane = new JEditorPane("text/html", "");
2960 editPane.setEditable(false);
2961 StringBuffer contents = new AlignmentProperties(viewport.getAlignment())
2963 editPane.setText(MessageManager.formatMessage("label.html_content", new String[]{contents.toString()}));
2964 JInternalFrame frame = new JInternalFrame();
2965 frame.getContentPane().add(new JScrollPane(editPane));
2967 Desktop.instance.addInternalFrame(frame, MessageManager.formatMessage("label.alignment_properties", new String[]{getTitle()}), 500, 400);
\r
2977 public void overviewMenuItem_actionPerformed(ActionEvent e)
2979 if (alignPanel.overviewPanel != null)
2984 JInternalFrame frame = new JInternalFrame();
2985 OverviewPanel overview = new OverviewPanel(alignPanel);
2986 frame.setContentPane(overview);
2987 Desktop.addInternalFrame(frame, MessageManager.formatMessage("label.overview_params", new String[]{this.getTitle()}),
\r
2988 frame.getWidth(), frame.getHeight());
2990 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2991 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2994 public void internalFrameClosed(
2995 javax.swing.event.InternalFrameEvent evt)
2997 alignPanel.setOverviewPanel(null);
3001 alignPanel.setOverviewPanel(overview);
3005 public void textColour_actionPerformed(ActionEvent e)
3007 new TextColourChooser().chooseColour(alignPanel, null);
3017 protected void noColourmenuItem_actionPerformed(ActionEvent e)
3029 public void clustalColour_actionPerformed(ActionEvent e)
3031 changeColour(new ClustalxColourScheme(viewport.getAlignment(),
3032 viewport.getHiddenRepSequences()));
3042 public void zappoColour_actionPerformed(ActionEvent e)
3044 changeColour(new ZappoColourScheme());
3054 public void taylorColour_actionPerformed(ActionEvent e)
3056 changeColour(new TaylorColourScheme());
3066 public void hydrophobicityColour_actionPerformed(ActionEvent e)
3068 changeColour(new HydrophobicColourScheme());
3078 public void helixColour_actionPerformed(ActionEvent e)
3080 changeColour(new HelixColourScheme());
3090 public void strandColour_actionPerformed(ActionEvent e)
3092 changeColour(new StrandColourScheme());
3102 public void turnColour_actionPerformed(ActionEvent e)
3104 changeColour(new TurnColourScheme());
3114 public void buriedColour_actionPerformed(ActionEvent e)
3116 changeColour(new BuriedColourScheme());
3126 public void nucleotideColour_actionPerformed(ActionEvent e)
3128 changeColour(new NucleotideColourScheme());
3132 public void purinePyrimidineColour_actionPerformed(ActionEvent e)
3134 changeColour(new PurinePyrimidineColourScheme());
3138 * public void covariationColour_actionPerformed(ActionEvent e) {
3140 * CovariationColourScheme(viewport.getAlignment().getAlignmentAnnotation
3144 public void annotationColour_actionPerformed(ActionEvent e)
3146 new AnnotationColourChooser(viewport, alignPanel);
3150 public void rnahelicesColour_actionPerformed(ActionEvent e)
3152 new RNAHelicesColourChooser(viewport, alignPanel);
3162 protected void applyToAllGroups_actionPerformed(ActionEvent e)
3164 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
3173 public void changeColour(ColourSchemeI cs)
3175 // TODO: compare with applet and pull up to model method
3180 if (viewport.getAbovePIDThreshold())
3182 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
3185 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3187 viewport.setGlobalColourScheme(cs);
3191 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3194 if (viewport.getConservationSelected())
3197 Alignment al = (Alignment) viewport.getAlignment();
3198 Conservation c = new Conservation("All",
3199 ResidueProperties.propHash, 3, al.getSequences(), 0,
3203 c.verdict(false, viewport.getConsPercGaps());
3205 cs.setConservation(c);
3207 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
3212 cs.setConservation(null);
3215 cs.setConsensus(viewport.getSequenceConsensusHash());
3218 viewport.setGlobalColourScheme(cs);
3220 if (viewport.getColourAppliesToAllGroups())
3223 for (SequenceGroup sg : viewport.getAlignment().getGroups())
3231 if (cs instanceof ClustalxColourScheme)
3233 sg.cs = new ClustalxColourScheme(sg,
3234 viewport.getHiddenRepSequences());
3236 else if (cs instanceof UserColourScheme)
3238 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
3244 sg.cs = cs.getClass().newInstance();
3245 } catch (Exception ex)
3250 if (viewport.getAbovePIDThreshold()
3251 || cs instanceof PIDColourScheme
3252 || cs instanceof Blosum62ColourScheme)
3254 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
3256 sg.cs.setConsensus(AAFrequency.calculate(
3257 sg.getSequences(viewport.getHiddenRepSequences()),
3258 sg.getStartRes(), sg.getEndRes() + 1));
3262 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
3265 if (viewport.getConservationSelected())
3267 Conservation c = new Conservation("Group",
3268 ResidueProperties.propHash, 3, sg.getSequences(viewport
3269 .getHiddenRepSequences()), sg.getStartRes(),
3270 sg.getEndRes() + 1);
3272 c.verdict(false, viewport.getConsPercGaps());
3273 sg.cs.setConservation(c);
3277 sg.cs.setConservation(null);
3282 if (alignPanel.getOverviewPanel() != null)
3284 alignPanel.getOverviewPanel().updateOverviewImage();
3287 alignPanel.paintAlignment(true);
3297 protected void modifyPID_actionPerformed(ActionEvent e)
3299 if (viewport.getAbovePIDThreshold()
3300 && viewport.getGlobalColourScheme() != null)
3302 SliderPanel.setPIDSliderSource(alignPanel,
3303 viewport.getGlobalColourScheme(), "Background");
3304 SliderPanel.showPIDSlider();
3315 protected void modifyConservation_actionPerformed(ActionEvent e)
3317 if (viewport.getConservationSelected()
3318 && viewport.getGlobalColourScheme() != null)
3320 SliderPanel.setConservationSlider(alignPanel,
3321 viewport.getGlobalColourScheme(), "Background");
3322 SliderPanel.showConservationSlider();
3333 protected void conservationMenuItem_actionPerformed(ActionEvent e)
3335 viewport.setConservationSelected(conservationMenuItem.isSelected());
3337 viewport.setAbovePIDThreshold(false);
3338 abovePIDThreshold.setSelected(false);
3340 changeColour(viewport.getGlobalColourScheme());
3342 modifyConservation_actionPerformed(null);
3352 public void abovePIDThreshold_actionPerformed(ActionEvent e)
3354 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
3356 conservationMenuItem.setSelected(false);
3357 viewport.setConservationSelected(false);
3359 changeColour(viewport.getGlobalColourScheme());
3361 modifyPID_actionPerformed(null);
3371 public void userDefinedColour_actionPerformed(ActionEvent e)
3373 if (e.getActionCommand().equals(MessageManager.getString("action.user_defined")))
\r
3375 new UserDefinedColours(alignPanel, null);
3379 UserColourScheme udc = (UserColourScheme) UserDefinedColours
3380 .getUserColourSchemes().get(e.getActionCommand());
3386 public void updateUserColourMenu()
3389 Component[] menuItems = colourMenu.getMenuComponents();
3390 int i, iSize = menuItems.length;
3391 for (i = 0; i < iSize; i++)
3393 if (menuItems[i].getName() != null
3394 && menuItems[i].getName().equals("USER_DEFINED"))
3396 colourMenu.remove(menuItems[i]);
3400 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
3402 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
3403 .getUserColourSchemes().keys();
3405 while (userColours.hasMoreElements())
3407 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
3408 userColours.nextElement().toString());
3409 radioItem.setName("USER_DEFINED");
3410 radioItem.addMouseListener(new MouseAdapter()
3413 public void mousePressed(MouseEvent evt)
3415 if (evt.isControlDown()
3416 || SwingUtilities.isRightMouseButton(evt))
3418 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
3420 int option = JOptionPane.showInternalConfirmDialog(
3421 jalview.gui.Desktop.desktop,
3422 MessageManager.getString("label.remove_from_default_list"),
3423 MessageManager.getString("label.remove_user_defined_colour"),
3424 JOptionPane.YES_NO_OPTION);
3425 if (option == JOptionPane.YES_OPTION)
3427 jalview.gui.UserDefinedColours
3428 .removeColourFromDefaults(radioItem.getText());
3429 colourMenu.remove(radioItem);
3433 radioItem.addActionListener(new ActionListener()
3436 public void actionPerformed(ActionEvent evt)
3438 userDefinedColour_actionPerformed(evt);
3445 radioItem.addActionListener(new ActionListener()
3448 public void actionPerformed(ActionEvent evt)
3450 userDefinedColour_actionPerformed(evt);
3454 colourMenu.insert(radioItem, 15);
3455 colours.add(radioItem);
3467 public void PIDColour_actionPerformed(ActionEvent e)
3469 changeColour(new PIDColourScheme());
3479 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3481 changeColour(new Blosum62ColourScheme());
3491 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3493 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3494 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3495 .getAlignment().getSequenceAt(0), null);
3496 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3497 viewport.getAlignment()));
3498 alignPanel.paintAlignment(true);
3508 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3510 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3511 AlignmentSorter.sortByID(viewport.getAlignment());
3512 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
3513 viewport.getAlignment()));
3514 alignPanel.paintAlignment(true);
3524 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3526 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3527 AlignmentSorter.sortByLength(viewport.getAlignment());
3528 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3529 viewport.getAlignment()));
3530 alignPanel.paintAlignment(true);
3540 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3542 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3543 AlignmentSorter.sortByGroup(viewport.getAlignment());
3544 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3545 viewport.getAlignment()));
3547 alignPanel.paintAlignment(true);
3557 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3559 new RedundancyPanel(alignPanel, this);
3569 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3571 if ((viewport.getSelectionGroup() == null)
3572 || (viewport.getSelectionGroup().getSize() < 2))
3574 JOptionPane.showInternalMessageDialog(this,
3575 MessageManager.getString("label.you_must_select_least_two_sequences"), MessageManager.getString("label.invalid_selection"),
3576 JOptionPane.WARNING_MESSAGE);
3580 JInternalFrame frame = new JInternalFrame();
3581 frame.setContentPane(new PairwiseAlignPanel(viewport));
3582 Desktop.addInternalFrame(frame, MessageManager.getString("action.pairwise_alignment"), 600, 500);
\r
3593 public void PCAMenuItem_actionPerformed(ActionEvent e)
3595 if (((viewport.getSelectionGroup() != null)
3596 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3597 .getSelectionGroup().getSize() > 0))
3598 || (viewport.getAlignment().getHeight() < 4))
3600 JOptionPane.showInternalMessageDialog(this,
3601 MessageManager.getString("label.principal_component_analysis_must_take_least_four_input_sequences"),
3602 MessageManager.getString("label.sequence_selection_insufficient"),
3603 JOptionPane.WARNING_MESSAGE);
3608 new PCAPanel(alignPanel);
3612 public void autoCalculate_actionPerformed(ActionEvent e)
3614 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3615 if (viewport.autoCalculateConsensus)
3617 viewport.firePropertyChange("alignment", null, viewport
3618 .getAlignment().getSequences());
3623 public void sortByTreeOption_actionPerformed(ActionEvent e)
3625 viewport.sortByTree = sortByTree.isSelected();
3629 protected void listenToViewSelections_actionPerformed(ActionEvent e)
3631 viewport.followSelection = listenToViewSelections.isSelected();
3641 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3643 NewTreePanel("AV", "PID", "Average distance tree using PID");
3653 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3655 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3665 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3667 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3677 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3679 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3692 void NewTreePanel(String type, String pwType, String title)
3696 if (viewport.getSelectionGroup() != null
3697 && viewport.getSelectionGroup().getSize() > 0)
3699 if (viewport.getSelectionGroup().getSize() < 3)
3704 MessageManager.getString("label.you_need_more_two_sequences_selected_build_tree"),
3705 MessageManager.getString("label.not_enough_sequences"), JOptionPane.WARNING_MESSAGE);
3709 SequenceGroup sg = viewport.getSelectionGroup();
3711 /* Decide if the selection is a column region */
3712 for (SequenceI _s : sg.getSequences())
3714 if (_s.getLength() < sg.getEndRes())
3719 MessageManager.getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"),
3720 MessageManager.getString("label.sequences_selection_not_aligned"),
3721 JOptionPane.WARNING_MESSAGE);
3727 title = title + " on region";
3728 tp = new TreePanel(alignPanel, type, pwType);
3732 // are the visible sequences aligned?
3733 if (!viewport.getAlignment().isAligned(false))
3738 MessageManager.getString("label.sequences_must_be_aligned_before_creating_tree"),
3739 MessageManager.getString("label.sequences_not_aligned"),
3740 JOptionPane.WARNING_MESSAGE);
3745 if (viewport.getAlignment().getHeight() < 2)
3750 tp = new TreePanel(alignPanel, type, pwType);
3755 if (viewport.viewName != null)
3757 title += viewport.viewName + " of ";
3760 title += this.title;
3762 Desktop.addInternalFrame(tp, title, 600, 500);
3773 public void addSortByOrderMenuItem(String title,
3774 final AlignmentOrder order)
3776 final JMenuItem item = new JMenuItem("by " + title);
3778 item.addActionListener(new java.awt.event.ActionListener()
3781 public void actionPerformed(ActionEvent e)
3783 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3785 // TODO: JBPNote - have to map order entries to curent SequenceI
3787 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3789 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport
3792 alignPanel.paintAlignment(true);
3798 * Add a new sort by annotation score menu item
3801 * the menu to add the option to
3803 * the label used to retrieve scores for each sequence on the
3806 public void addSortByAnnotScoreMenuItem(JMenu sort,
3807 final String scoreLabel)
3809 final JMenuItem item = new JMenuItem(scoreLabel);
3811 item.addActionListener(new java.awt.event.ActionListener()
3814 public void actionPerformed(ActionEvent e)
3816 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3817 AlignmentSorter.sortByAnnotationScore(scoreLabel,
3818 viewport.getAlignment());// ,viewport.getSelectionGroup());
3819 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3820 viewport.getAlignment()));
3821 alignPanel.paintAlignment(true);
3827 * last hash for alignment's annotation array - used to minimise cost of
3830 protected int _annotationScoreVectorHash;
3833 * search the alignment and rebuild the sort by annotation score submenu the
3834 * last alignment annotation vector hash is stored to minimize cost of
3835 * rebuilding in subsequence calls.
3839 public void buildSortByAnnotationScoresMenu()
3841 if (viewport.getAlignment().getAlignmentAnnotation() == null)
3846 if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3848 sortByAnnotScore.removeAll();
3849 // almost certainly a quicker way to do this - but we keep it simple
3850 Hashtable scoreSorts = new Hashtable();
3851 AlignmentAnnotation aann[];
3852 for (SequenceI sqa : viewport.getAlignment().getSequences())
3854 aann = sqa.getAnnotation();
3855 for (int i = 0; aann != null && i < aann.length; i++)
3857 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3859 scoreSorts.put(aann[i].label, aann[i].label);
3863 Enumeration labels = scoreSorts.keys();
3864 while (labels.hasMoreElements())
3866 addSortByAnnotScoreMenuItem(sortByAnnotScore,
3867 (String) labels.nextElement());
3869 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3872 _annotationScoreVectorHash = viewport.getAlignment()
3873 .getAlignmentAnnotation().hashCode();
3878 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3879 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3880 * call. Listeners are added to remove the menu item when the treePanel is
3881 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3885 * Displayed tree window.
3887 * SortBy menu item title.
3890 public void buildTreeMenu()
3892 calculateTree.removeAll();
3893 // build the calculate menu
3894 for (final String type:new String[] {"NJ", "AV"})
3896 for (final Object pwtype: ResidueProperties.scoreMatrices.keySet())
3898 JMenuItem tm = new JMenuItem();
3899 ScoreModelI sm = ResidueProperties.scoreMatrices.get(pwtype);
3900 final String title="Calculate "+type+" using "+sm.getName();
3901 tm.setText(title);// MessageManager.getString("label.neighbour_blosum62"));
3903 .addActionListener(new java.awt.event.ActionListener()
3905 public void actionPerformed(ActionEvent e)
3907 NewTreePanel(type, (String) pwtype, title);
3910 calculateTree.add(tm);
3914 sortByTreeMenu.removeAll();
3916 Vector comps = (Vector) PaintRefresher.components.get(viewport
3917 .getSequenceSetId());
3918 Vector treePanels = new Vector();
3919 int i, iSize = comps.size();
3920 for (i = 0; i < iSize; i++)
3922 if (comps.elementAt(i) instanceof TreePanel)
3924 treePanels.add(comps.elementAt(i));
3928 iSize = treePanels.size();
3932 sortByTreeMenu.setVisible(false);
3936 sortByTreeMenu.setVisible(true);
3938 for (i = 0; i < treePanels.size(); i++)
3940 final TreePanel tp = (TreePanel) treePanels.elementAt(i);
3941 final JMenuItem item = new JMenuItem(tp.getTitle());
3942 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3943 item.addActionListener(new java.awt.event.ActionListener()
3946 public void actionPerformed(ActionEvent e)
3948 tp.sortByTree_actionPerformed(null);
3949 addHistoryItem(tp.sortAlignmentIn(alignPanel));
3954 sortByTreeMenu.add(item);
3958 public boolean sortBy(AlignmentOrder alorder, String undoname)
3960 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3961 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
3962 if (undoname != null)
3964 addHistoryItem(new OrderCommand(undoname, oldOrder,
3965 viewport.getAlignment()));
3967 alignPanel.paintAlignment(true);
3972 * Work out whether the whole set of sequences or just the selected set will
3973 * be submitted for multiple alignment.
3976 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3978 // Now, check we have enough sequences
3979 AlignmentView msa = null;
3981 if ((viewport.getSelectionGroup() != null)
3982 && (viewport.getSelectionGroup().getSize() > 1))
3984 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3985 // some common interface!
3987 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3988 * SequenceI[sz = seqs.getSize(false)];
3990 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3991 * seqs.getSequenceAt(i); }
3993 msa = viewport.getAlignmentView(true);
3998 * Vector seqs = viewport.getAlignment().getSequences();
4000 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
4002 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
4003 * seqs.elementAt(i); } }
4005 msa = viewport.getAlignmentView(false);
4011 * Decides what is submitted to a secondary structure prediction service: the
4012 * first sequence in the alignment, or in the current selection, or, if the
4013 * alignment is 'aligned' (ie padded with gaps), then the currently selected
4014 * region or the whole alignment. (where the first sequence in the set is the
4015 * one that the prediction will be for).
4017 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
4019 AlignmentView seqs = null;
4021 if ((viewport.getSelectionGroup() != null)
4022 && (viewport.getSelectionGroup().getSize() > 0))
4024 seqs = viewport.getAlignmentView(true);
4028 seqs = viewport.getAlignmentView(false);
4030 // limit sequences - JBPNote in future - could spawn multiple prediction
4032 // TODO: viewport.getAlignment().isAligned is a global state - the local
4033 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
4034 if (!viewport.getAlignment().isAligned(false))
4036 seqs.setSequences(new SeqCigar[]
4037 { seqs.getSequences()[0] });
4038 // TODO: if seqs.getSequences().length>1 then should really have warned
4052 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
4054 // Pick the tree file
4055 JalviewFileChooser chooser = new JalviewFileChooser(
4056 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
4057 chooser.setFileView(new JalviewFileView());
4058 chooser.setDialogTitle(MessageManager.getString("label.select_newick_like_tree_file"));
\r
4059 chooser.setToolTipText(MessageManager.getString("label.load_tree_file"));
\r
4061 int value = chooser.showOpenDialog(null);
4063 if (value == JalviewFileChooser.APPROVE_OPTION)
4065 String choice = chooser.getSelectedFile().getPath();
4066 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
4067 jalview.io.NewickFile fin = null;
4070 fin = new jalview.io.NewickFile(choice, "File");
4071 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
4072 } catch (Exception ex)
4074 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
4075 MessageManager.getString("label.problem_reading_tree_file"), JOptionPane.WARNING_MESSAGE);
4076 ex.printStackTrace();
4078 if (fin != null && fin.hasWarningMessage())
4080 JOptionPane.showMessageDialog(Desktop.desktop,
4081 fin.getWarningMessage(), MessageManager.getString("label.possible_problem_with_tree_file"),
4082 JOptionPane.WARNING_MESSAGE);
4088 protected void tcoffeeColorScheme_actionPerformed(ActionEvent e)
4090 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
4093 public TreePanel ShowNewickTree(NewickFile nf, String title)
4095 return ShowNewickTree(nf, title, 600, 500, 4, 5);
4098 public TreePanel ShowNewickTree(NewickFile nf, String title,
4099 AlignmentView input)
4101 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
4104 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
4105 int h, int x, int y)
4107 return ShowNewickTree(nf, title, null, w, h, x, y);
4111 * Add a treeviewer for the tree extracted from a newick file object to the
4112 * current alignment view
4119 * Associated alignment input data (or null)
4128 * @return TreePanel handle
4130 public TreePanel ShowNewickTree(NewickFile nf, String title,
4131 AlignmentView input, int w, int h, int x, int y)
4133 TreePanel tp = null;
4139 if (nf.getTree() != null)
4141 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
4147 tp.setLocation(x, y);
4150 Desktop.addInternalFrame(tp, title, w, h);
4152 } catch (Exception ex)
4154 ex.printStackTrace();
4160 private boolean buildingMenu = false;
4163 * Generates menu items and listener event actions for web service clients
4166 public void BuildWebServiceMenu()
4168 while (buildingMenu)
4172 System.err.println("Waiting for building menu to finish.");
4174 } catch (Exception e)
4179 final AlignFrame me = this;
4180 buildingMenu = true;
4181 new Thread(new Runnable()
4186 final List<JMenuItem> legacyItems=new ArrayList<JMenuItem>();
4189 System.err.println("Building ws menu again "
4190 + Thread.currentThread());
4191 // TODO: add support for context dependent disabling of services based
4193 // alignment and current selection
4194 // TODO: add additional serviceHandle parameter to specify abstract
4196 // class independently of AbstractName
4197 // TODO: add in rediscovery GUI function to restart discoverer
4198 // TODO: group services by location as well as function and/or
4200 // object broker mechanism.
4201 final Vector<JMenu> wsmenu = new Vector<JMenu>();
4202 final IProgressIndicator af = me;
4203 final JMenu msawsmenu = new JMenu("Alignment");
4204 final JMenu secstrmenu = new JMenu(
4205 "Secondary Structure Prediction");
4206 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
4207 final JMenu analymenu = new JMenu("Analysis");
4208 final JMenu dismenu = new JMenu("Protein Disorder");
4209 // JAL-940 - only show secondary structure prediction services from
4210 // the legacy server
4211 if (// Cache.getDefault("SHOW_JWS1_SERVICES", true)
4213 Discoverer.services != null && (Discoverer.services.size() > 0))
4215 // TODO: refactor to allow list of AbstractName/Handler bindings to
4217 // stored or retrieved from elsewhere
4218 // No MSAWS used any more:
4219 // Vector msaws = null; // (Vector) Discoverer.services.get("MsaWS");
4220 Vector secstrpr = (Vector) Discoverer.services
4222 if (secstrpr != null)
4224 // Add any secondary structure prediction services
4225 for (int i = 0, j = secstrpr.size(); i < j; i++)
4227 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
4229 jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer
4230 .getServiceClient(sh);
4231 int p=secstrmenu.getItemCount();
4232 impl.attachWSMenuEntry(secstrmenu, me);
4233 int q=secstrmenu.getItemCount();
4234 for (int litm=p;litm<q; litm++)
4236 legacyItems.add(secstrmenu.getItem(litm));
4242 // Add all submenus in the order they should appear on the web
4244 wsmenu.add(msawsmenu);
4245 wsmenu.add(secstrmenu);
4246 wsmenu.add(dismenu);
4247 wsmenu.add(analymenu);
4248 // No search services yet
4249 // wsmenu.add(seqsrchmenu);
4251 javax.swing.SwingUtilities.invokeLater(new Runnable()
4258 webService.removeAll();
4259 // first, add discovered services onto the webservices menu
4260 if (wsmenu.size() > 0)
4262 for (int i = 0, j = wsmenu.size(); i < j; i++)
4264 webService.add(wsmenu.get(i));
4269 webService.add(me.webServiceNoServices);
4271 // TODO: move into separate menu builder class.
4272 boolean new_sspred=false;
4273 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
4275 Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer();
4276 if (jws2servs != null)
4278 if (jws2servs.hasServices())
4280 jws2servs.attachWSMenuEntry(webService, me);
4281 for (Jws2Instance sv:jws2servs.getServices()) {
4282 if (sv.description.toLowerCase().contains("jpred"))
4284 for (JMenuItem jmi:legacyItems)
4286 jmi.setVisible(false);
4292 if (jws2servs.isRunning())
4294 JMenuItem tm = new JMenuItem(
4295 "Still discovering JABA Services");
4296 tm.setEnabled(false);
4301 build_urlServiceMenu(me.webService);
4302 build_fetchdbmenu(webService);
4303 for (JMenu item : wsmenu)
4305 if (item.getItemCount() == 0)
4307 item.setEnabled(false);
4311 item.setEnabled(true);
4314 } catch (Exception e)
4317 .debug("Exception during web service menu building process.",
4323 } catch (Exception e)
4328 buildingMenu = false;
4335 * construct any groupURL type service menu entries.
4339 private void build_urlServiceMenu(JMenu webService)
4341 // TODO: remove this code when 2.7 is released
4342 // DEBUG - alignmentView
4344 * JMenuItem testAlView = new JMenuItem("Test AlignmentView"); final
4345 * AlignFrame af = this; testAlView.addActionListener(new ActionListener() {
4347 * @Override public void actionPerformed(ActionEvent e) {
4348 * jalview.datamodel.AlignmentView
4349 * .testSelectionViews(af.viewport.getAlignment(),
4350 * af.viewport.getColumnSelection(), af.viewport.selectionGroup); }
4352 * }); webService.add(testAlView);
4354 // TODO: refactor to RestClient discoverer and merge menu entries for
4355 // rest-style services with other types of analysis/calculation service
4356 // SHmmr test client - still being implemented.
4357 // DEBUG - alignmentView
4359 for (jalview.ws.rest.RestClient client : jalview.ws.rest.RestClient
4362 client.attachWSMenuEntry(
4363 JvSwingUtils.findOrCreateMenu(webService, client.getAction()),
4367 if (Cache.getDefault("SHOW_ENFIN_SERVICES", true))
4369 jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry(
4375 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
4376 * chooser = new JalviewFileChooser(jalview.bin.Cache.
4377 * getProperty("LAST_DIRECTORY"));
4379 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
4380 * to Vamsas file"); chooser.setToolTipText("Export");
4382 * int value = chooser.showSaveDialog(this);
4384 * if (value == JalviewFileChooser.APPROVE_OPTION) {
4385 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
4386 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
4387 * chooser.getSelectedFile().getAbsolutePath(), this); } }
4390 * prototype of an automatically enabled/disabled analysis function
4393 protected void setShowProductsEnabled()
4395 SequenceI[] selection = viewport.getSequenceSelection();
4396 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
4397 viewport.getAlignment().getDataset()))
4399 showProducts.setEnabled(true);
4404 showProducts.setEnabled(false);
4409 * search selection for sequence xRef products and build the show products
4414 * @return true if showProducts menu should be enabled.
4416 public boolean canShowProducts(SequenceI[] selection,
4417 boolean isRegionSelection, Alignment dataset)
4419 boolean showp = false;
4422 showProducts.removeAll();
4423 final boolean dna = viewport.getAlignment().isNucleotide();
4424 final Alignment ds = dataset;
4425 String[] ptypes = (selection == null || selection.length == 0) ? null
4426 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
4428 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
4429 // selection, dataset, true);
4430 final SequenceI[] sel = selection;
4431 for (int t = 0; ptypes != null && t < ptypes.length; t++)
4434 final boolean isRegSel = isRegionSelection;
4435 final AlignFrame af = this;
4436 final String source = ptypes[t];
4437 JMenuItem xtype = new JMenuItem(ptypes[t]);
4438 xtype.addActionListener(new ActionListener()
4442 public void actionPerformed(ActionEvent e)
4444 // TODO: new thread for this call with vis-delay
4445 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
4446 isRegSel, dna, source);
4450 showProducts.add(xtype);
4452 showProducts.setVisible(showp);
4453 showProducts.setEnabled(showp);
4454 } catch (Exception e)
4456 jalview.bin.Cache.log
4457 .warn("canTranslate threw an exception - please report to help@jalview.org",
4464 protected void showProductsFor(SequenceI[] sel, Alignment ds,
4465 boolean isRegSel, boolean dna, String source)
4467 final boolean fisRegSel = isRegSel;
4468 final boolean fdna = dna;
4469 final String fsrc = source;
4470 final AlignFrame ths = this;
4471 final SequenceI[] fsel = sel;
4472 Runnable foo = new Runnable()
4478 final long sttime = System.currentTimeMillis();
4479 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
4482 Alignment ds = ths.getViewport().getAlignment().getDataset(); // update
4486 Alignment prods = CrossRef
4487 .findXrefSequences(fsel, fdna, fsrc, ds);
4490 SequenceI[] sprods = new SequenceI[prods.getHeight()];
4491 for (int s = 0; s < sprods.length; s++)
4493 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
4494 if (ds.getSequences() == null
4495 || !ds.getSequences().contains(
4496 sprods[s].getDatasetSequence()))
4497 ds.addSequence(sprods[s].getDatasetSequence());
4498 sprods[s].updatePDBIds();
4500 Alignment al = new Alignment(sprods);
4501 AlignedCodonFrame[] cf = prods.getCodonFrames();
4503 for (int s = 0; cf != null && s < cf.length; s++)
4505 al.addCodonFrame(cf[s]);
4508 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
4510 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
4511 + " for " + ((fisRegSel) ? "selected region of " : "")
4513 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
4518 System.err.println("No Sequences generated for xRef type "
4521 } catch (Exception e)
4523 jalview.bin.Cache.log.error(
4524 "Exception when finding crossreferences", e);
4525 } catch (OutOfMemoryError e)
4527 new OOMWarning("whilst fetching crossreferences", e);
4530 jalview.bin.Cache.log.error("Error when finding crossreferences",
4533 ths.setProgressBar("Finished searching for sequences from " + fsrc,
4538 Thread frunner = new Thread(foo);
4542 public boolean canShowTranslationProducts(SequenceI[] selection,
4543 AlignmentI alignment)
4548 return (jalview.analysis.Dna.canTranslate(selection,
4549 viewport.getViewAsVisibleContigs(true)));
4550 } catch (Exception e)
4552 jalview.bin.Cache.log
4553 .warn("canTranslate threw an exception - please report to help@jalview.org",
4560 public void showProducts_actionPerformed(ActionEvent e)
4562 // /////////////////////////////
4563 // Collect Data to be translated/transferred
4565 SequenceI[] selection = viewport.getSequenceSelection();
4566 AlignmentI al = null;
4569 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
4570 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
4571 viewport.getAlignment().getDataset());
4572 } catch (Exception ex)
4575 jalview.bin.Cache.log.debug("Exception during translation.", ex);
4582 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4583 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4587 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4588 Desktop.addInternalFrame(af, MessageManager.formatMessage("label.translation_of_params", new String[]{this.getTitle()}),
\r
4589 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4594 public void showTranslation_actionPerformed(ActionEvent e)
4596 // /////////////////////////////
4597 // Collect Data to be translated/transferred
4599 SequenceI[] selection = viewport.getSequenceSelection();
4600 String[] seqstring = viewport.getViewAsString(true);
4601 AlignmentI al = null;
4604 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
4605 viewport.getViewAsVisibleContigs(true), viewport
4606 .getGapCharacter(), viewport.getAlignment()
4607 .getAlignmentAnnotation(), viewport.getAlignment()
4608 .getWidth(), viewport.getAlignment().getDataset());
4609 } catch (Exception ex)
4612 jalview.bin.Cache.log.error("Exception during translation. Please report this !", ex);
4616 MessageManager.getString("label.error_when_translating_sequences_submit_bug_report"),
4617 MessageManager.getString("label.implementation_error") + MessageManager.getString("translation_failed"), JOptionPane.ERROR_MESSAGE);
4625 MessageManager.getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"),
4626 MessageManager.getString("label.translation_failed"), JOptionPane.WARNING_MESSAGE);
4630 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
4631 Desktop.addInternalFrame(af, MessageManager.formatMessage("label.translation_of_params", new String[]{this.getTitle()}),
\r
4632 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4637 * Try to load a features file onto the alignment.
4640 * contents or path to retrieve file
4642 * access mode of file (see jalview.io.AlignFile)
4643 * @return true if features file was parsed corectly.
4645 public boolean parseFeaturesFile(String file, String type)
4647 boolean featuresFile = false;
4650 featuresFile = new FeaturesFile(file, type).parse(viewport
4651 .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas
4652 .getFeatureRenderer().featureColours, false,
4653 jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false));
4654 } catch (Exception ex)
4656 ex.printStackTrace();
4661 viewport.showSequenceFeatures = true;
4662 showSeqFeatures.setSelected(true);
4663 if (alignPanel.seqPanel.seqCanvas.fr != null)
4665 // update the min/max ranges where necessary
4666 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4668 if (featureSettings != null)
4670 featureSettings.setTableData();
4672 alignPanel.paintAlignment(true);
4675 return featuresFile;
4679 public void dragEnter(DropTargetDragEvent evt)
4684 public void dragExit(DropTargetEvent evt)
4689 public void dragOver(DropTargetDragEvent evt)
4694 public void dropActionChanged(DropTargetDragEvent evt)
4699 public void drop(DropTargetDropEvent evt)
4701 Transferable t = evt.getTransferable();
4702 java.util.List files = null;
4706 DataFlavor uriListFlavor = new DataFlavor(
4707 "text/uri-list;class=java.lang.String");
4708 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4710 // Works on Windows and MacOSX
4711 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4712 files = (java.util.List) t
4713 .getTransferData(DataFlavor.javaFileListFlavor);
4715 else if (t.isDataFlavorSupported(uriListFlavor))
4717 // This is used by Unix drag system
4718 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4719 String data = (String) t.getTransferData(uriListFlavor);
4720 files = new java.util.ArrayList(1);
4721 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4722 data, "\r\n"); st.hasMoreTokens();)
4724 String s = st.nextToken();
4725 if (s.startsWith("#"))
4727 // the line is a comment (as per the RFC 2483)
4731 java.net.URI uri = new java.net.URI(s);
4732 // check to see if we can handle this kind of URI
4733 if (uri.getScheme().toLowerCase().startsWith("http"))
4735 files.add(uri.toString());
4739 // otherwise preserve old behaviour: catch all for file objects
4740 java.io.File file = new java.io.File(uri);
4741 files.add(file.toString());
4745 } catch (Exception e)
4747 e.printStackTrace();
4753 // check to see if any of these files have names matching sequences in
4755 SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4756 .getAlignment().getSequencesArray());
4758 * Object[] { String,SequenceI}
4760 ArrayList<Object[]> filesmatched = new ArrayList<Object[]>();
4761 ArrayList<String> filesnotmatched = new ArrayList<String>();
4762 for (int i = 0; i < files.size(); i++)
4764 String file = files.get(i).toString();
4766 String protocol = FormatAdapter.checkProtocol(file);
4767 if (protocol == jalview.io.FormatAdapter.FILE)
4769 File fl = new File(file);
4770 pdbfn = fl.getName();
4772 else if (protocol == jalview.io.FormatAdapter.URL)
4774 URL url = new URL(file);
4775 pdbfn = url.getFile();
4777 if (pdbfn.length() > 0)
4779 // attempt to find a match in the alignment
4780 SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
4781 int l = 0, c = pdbfn.indexOf(".");
4782 while (mtch == null && c != -1)
4787 } while ((c = pdbfn.indexOf(".", l)) > l);
4790 pdbfn = pdbfn.substring(0, l);
4792 mtch = idm.findAllIdMatches(pdbfn);
4799 type = new IdentifyFile().Identify(file, protocol);
4800 } catch (Exception ex)
4806 if (type.equalsIgnoreCase("PDB"))
4808 filesmatched.add(new Object[]
4809 { file, protocol, mtch });
4814 // File wasn't named like one of the sequences or wasn't a PDB file.
4815 filesnotmatched.add(file);
4819 if (filesmatched.size() > 0)
4821 if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
4825 MessageManager.formatMessage("label.automatically_associate_pdb_files_with_sequences_same_name",
4826 new String[]{Integer.valueOf(filesmatched.size()).toString()}),
4827 MessageManager.getString("label.automatically_associate_pdb_files_by_name"),
4828 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
4831 for (Object[] fm : filesmatched)
4833 // try and associate
4834 // TODO: may want to set a standard ID naming formalism for
4835 // associating PDB files which have no IDs.
4836 for (SequenceI toassoc : (SequenceI[]) fm[2])
4838 PDBEntry pe = new AssociatePdbFileWithSeq()
4839 .associatePdbWithSeq((String) fm[0],
4840 (String) fm[1], toassoc, false);
4843 System.err.println("Associated file : "
4844 + ((String) fm[0]) + " with "
4845 + toassoc.getDisplayId(true));
4849 alignPanel.paintAlignment(true);
4853 if (filesnotmatched.size() > 0)
4856 && (Cache.getDefault(
4857 "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
4860 MessageManager.formatMessage("label.ignore_unmatched_dropped_files_info", new String[]{Integer.valueOf(filesnotmatched.size()).toString()}),
4861 MessageManager.getString("label.ignore_unmatched_dropped_files"),
4862 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
4866 for (String fn : filesnotmatched)
4868 loadJalviewDataFile(fn, null, null, null);
4872 } catch (Exception ex)
4874 ex.printStackTrace();
4880 * Attempt to load a "dropped" file or URL string: First by testing whether
4881 * it's and Annotation file, then a JNet file, and finally a features file. If
4882 * all are false then the user may have dropped an alignment file onto this
4886 * either a filename or a URL string.
4888 public void loadJalviewDataFile(String file, String protocol,
4889 String format, SequenceI assocSeq)
4893 if (protocol == null)
4895 protocol = jalview.io.FormatAdapter.checkProtocol(file);
4897 // if the file isn't identified, or not positively identified as some
4898 // other filetype (PFAM is default unidentified alignment file type) then
4899 // try to parse as annotation.
4900 boolean isAnnotation = (format == null || format
4901 .equalsIgnoreCase("PFAM")) ? new AnnotationFile()
4902 .readAnnotationFile(viewport.getAlignment(), file, protocol)
4907 // first see if its a T-COFFEE score file
4908 TCoffeeScoreFile tcf = null;
4911 tcf = new TCoffeeScoreFile(file, protocol);
4914 if (tcf.annotateAlignment(viewport.getAlignment(), true))
4916 tcoffeeColour.setEnabled(true);
4917 tcoffeeColour.setSelected(true);
4918 changeColour(new TCoffeeColourScheme(viewport.getAlignment()));
4919 isAnnotation = true;
4920 statusBar.setText(MessageManager.getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
4924 // some problem - if no warning its probable that the ID matching
4925 // process didn't work
4929 tcf.getWarningMessage() == null ? MessageManager.getString("label.check_file_matches_sequence_ids_alignment")
4930 : tcf.getWarningMessage(),
4931 MessageManager.getString("label.problem_reading_tcoffee_score_file"),
4932 JOptionPane.WARNING_MESSAGE);
4939 } catch (Exception x)
4942 .debug("Exception when processing data source as T-COFFEE score file",
4948 // try to see if its a JNet 'concise' style annotation file *before*
4950 // try to parse it as a features file
4953 format = new IdentifyFile().Identify(file, protocol);
4955 if (format.equalsIgnoreCase("JnetFile"))
4957 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
4959 new JnetAnnotationMaker().add_annotation(predictions,
4960 viewport.getAlignment(), 0, false);
4961 isAnnotation = true;
4966 * if (format.equalsIgnoreCase("PDB")) {
4968 * String pdbfn = ""; // try to match up filename with sequence id
4969 * try { if (protocol == jalview.io.FormatAdapter.FILE) { File fl =
4970 * new File(file); pdbfn = fl.getName(); } else if (protocol ==
4971 * jalview.io.FormatAdapter.URL) { URL url = new URL(file); pdbfn =
4972 * url.getFile(); } } catch (Exception e) { } ; if (assocSeq ==
4973 * null) { SequenceIdMatcher idm = new SequenceIdMatcher(viewport
4974 * .getAlignment().getSequencesArray()); if (pdbfn.length() > 0) {
4975 * // attempt to find a match in the alignment SequenceI mtch =
4976 * idm.findIdMatch(pdbfn); int l = 0, c = pdbfn.indexOf("."); while
4977 * (mtch == null && c != -1) { while ((c = pdbfn.indexOf(".", l)) >
4978 * l) { l = c; } if (l > -1) { pdbfn = pdbfn.substring(0, l); } mtch
4979 * = idm.findIdMatch(pdbfn); } if (mtch != null) { // try and
4980 * associate // prompt ? PDBEntry pe = new AssociatePdbFileWithSeq()
4981 * .associatePdbWithSeq(file, protocol, mtch, true); if (pe != null)
4982 * { System.err.println("Associated file : " + file + " with " +
4983 * mtch.getDisplayId(true)); alignPanel.paintAlignment(true); } } //
4984 * TODO: maybe need to load as normal otherwise return; } }
4986 // try to parse it as a features file
4987 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4988 // if it wasn't a features file then we just treat it as a general
4989 // alignment file to load into the current view.
4992 new FileLoader().LoadFile(viewport, file, protocol, format);
4996 alignPanel.paintAlignment(true);
5004 alignPanel.adjustAnnotationHeight();
5005 viewport.updateSequenceIdColours();
5006 buildSortByAnnotationScoresMenu();
5007 alignPanel.paintAlignment(true);
5009 } catch (Exception ex)
5011 ex.printStackTrace();
5012 } catch (OutOfMemoryError oom)
5017 } catch (Exception x)
5023 + (protocol != null ? (protocol.equals(FormatAdapter.PASTE) ? "from clipboard."
5024 : "using " + protocol + " from " + file)
5026 + (format != null ? "(parsing as '" + format
5027 + "' file)" : ""), oom, Desktop.desktop);
5032 public void tabSelectionChanged(int index)
5036 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
5037 viewport = alignPanel.av;
5038 avc.setViewportAndAlignmentPanel(viewport, alignPanel);
5039 setMenusFromViewport(viewport);
5044 public void tabbedPane_mousePressed(MouseEvent e)
5046 if (SwingUtilities.isRightMouseButton(e))
5048 String reply = JOptionPane.showInternalInputDialog(this,
5049 MessageManager.getString("label.enter_view_name"), MessageManager.getString("label.enter_view_name"),
5050 JOptionPane.QUESTION_MESSAGE);
5054 viewport.viewName = reply;
5055 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
5060 public AlignViewport getCurrentView()
5066 * Open the dialog for regex description parsing.
5069 protected void extractScores_actionPerformed(ActionEvent e)
5071 ParseProperties pp = new jalview.analysis.ParseProperties(
5072 viewport.getAlignment());
5073 // TODO: verify regex and introduce GUI dialog for version 2.5
5074 // if (pp.getScoresFromDescription("col", "score column ",
5075 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
5077 if (pp.getScoresFromDescription("description column",
5078 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
5080 buildSortByAnnotationScoresMenu();
5088 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
5092 protected void showDbRefs_actionPerformed(ActionEvent e)
5094 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
5100 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
5104 protected void showNpFeats_actionPerformed(ActionEvent e)
5106 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
5110 * find the viewport amongst the tabs in this alignment frame and close that
5115 public boolean closeView(AlignViewport av)
5119 this.closeMenuItem_actionPerformed(false);
5122 Component[] comp = tabbedPane.getComponents();
5123 for (int i = 0; comp != null && i < comp.length; i++)
5125 if (comp[i] instanceof AlignmentPanel)
5127 if (((AlignmentPanel) comp[i]).av == av)
5130 closeView((AlignmentPanel) comp[i]);
5138 protected void build_fetchdbmenu(JMenu webService)
5140 // Temporary hack - DBRef Fetcher always top level ws entry.
5141 // TODO We probably want to store a sequence database checklist in
5142 // preferences and have checkboxes.. rather than individual sources selected
5144 final JMenu rfetch = new JMenu(MessageManager.getString("action.fetch_db_references"));
\r
5145 rfetch.setToolTipText(MessageManager.getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences"));
\r
5146 webService.add(rfetch);
5148 JMenuItem fetchr = new JMenuItem(MessageManager.getString("label.standard_databases"));
\r
5149 fetchr.setToolTipText(MessageManager.getString("label.fetch_embl_uniprot"));
\r
5150 fetchr.addActionListener(new ActionListener()
5154 public void actionPerformed(ActionEvent e)
5156 new Thread(new Runnable()
5162 new jalview.ws.DBRefFetcher(alignPanel.av
5163 .getSequenceSelection(), alignPanel.alignFrame)
5164 .fetchDBRefs(false);
5172 final AlignFrame me = this;
5173 new Thread(new Runnable()
5178 final jalview.ws.SequenceFetcher sf = SequenceFetcher
5179 .getSequenceFetcherSingleton(me);
5180 javax.swing.SwingUtilities.invokeLater(new Runnable()
5185 String[] dbclasses = sf.getOrderedSupportedSources();
5186 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
5187 // jalview.util.QuickSort.sort(otherdb, otherdb);
5188 List<DbSourceProxy> otherdb;
5189 JMenu dfetch = new JMenu();
5190 JMenu ifetch = new JMenu();
5191 JMenuItem fetchr = null;
5192 int comp = 0, icomp = 0, mcomp = 15;
5193 String mname = null;
5195 for (String dbclass : dbclasses)
5197 otherdb = sf.getSourceProxy(dbclass);
5198 // add a single entry for this class, or submenu allowing 'fetch
5200 if (otherdb == null || otherdb.size() < 1)
5204 // List<DbSourceProxy> dbs=otherdb;
5205 // otherdb=new ArrayList<DbSourceProxy>();
5206 // for (DbSourceProxy db:dbs)
5208 // if (!db.isA(DBRefSource.ALIGNMENTDB)
5212 mname = "From " + dbclass;
5214 if (otherdb.size() == 1)
5216 final DbSourceProxy[] dassource = otherdb
5217 .toArray(new DbSourceProxy[0]);
5218 DbSourceProxy src = otherdb.get(0);
5219 fetchr = new JMenuItem(src.getDbSource());
5220 fetchr.addActionListener(new ActionListener()
5224 public void actionPerformed(ActionEvent e)
5226 new Thread(new Runnable()
5232 new jalview.ws.DBRefFetcher(alignPanel.av
5233 .getSequenceSelection(),
5234 alignPanel.alignFrame, dassource)
5235 .fetchDBRefs(false);
5241 fetchr.setToolTipText("<html>"
5242 + JvSwingUtils.wrapTooltip("Retrieve from "
5243 + src.getDbName()) + "<html>");
5249 final DbSourceProxy[] dassource = otherdb
5250 .toArray(new DbSourceProxy[0]);
5252 DbSourceProxy src = otherdb.get(0);
5253 fetchr = new JMenuItem(MessageManager.formatMessage("label.fetch_all_param", new String[]{src.getDbSource()}));
\r
5254 fetchr.addActionListener(new ActionListener()
5257 public void actionPerformed(ActionEvent e)
5259 new Thread(new Runnable()
5265 new jalview.ws.DBRefFetcher(alignPanel.av
5266 .getSequenceSelection(),
5267 alignPanel.alignFrame, dassource)
5268 .fetchDBRefs(false);
5274 fetchr.setToolTipText("<html>"
5275 + JvSwingUtils.wrapTooltip("Retrieve from all "
5276 + otherdb.size() + " sources in "
5277 + src.getDbSource() + "<br>First is :"
5278 + src.getDbName()) + "<html>");
5281 // and then build the rest of the individual menus
5282 ifetch = new JMenu("Sources from " + src.getDbSource());
5284 String imname = null;
5286 for (DbSourceProxy sproxy : otherdb)
5288 String dbname = sproxy.getDbName();
5289 String sname = dbname.length() > 5 ? dbname.substring(0,
5290 5) + "..." : dbname;
5291 String msname = dbname.length() > 10 ? dbname.substring(
5292 0, 10) + "..." : dbname;
5295 imname = "from '" + sname + "'";
5297 fetchr = new JMenuItem(msname);
5298 final DbSourceProxy[] dassrc =
5300 fetchr.addActionListener(new ActionListener()
5304 public void actionPerformed(ActionEvent e)
5306 new Thread(new Runnable()
5312 new jalview.ws.DBRefFetcher(alignPanel.av
5313 .getSequenceSelection(),
5314 alignPanel.alignFrame, dassrc)
5315 .fetchDBRefs(false);
5321 fetchr.setToolTipText("<html>"
5322 + JvSwingUtils.wrapTooltip("Retrieve from "
5323 + dbname) + "</html>");
5326 if (++icomp >= mcomp || i == (otherdb.size()))
5328 ifetch.setText(MessageManager.formatMessage("label.source_to_target",imname,sname));
5330 ifetch = new JMenu();
5338 if (comp >= mcomp || dbi >= (dbclasses.length))
5340 dfetch.setText(MessageManager.formatMessage("label.source_to_target",mname,dbclass));
5342 dfetch = new JMenu();
5355 * Left justify the whole alignment.
5358 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
5360 AlignmentI al = viewport.getAlignment();
5362 viewport.firePropertyChange("alignment", null, al);
5366 * Right justify the whole alignment.
5369 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
5371 AlignmentI al = viewport.getAlignment();
5373 viewport.firePropertyChange("alignment", null, al);
5376 public void setShowSeqFeatures(boolean b)
5378 showSeqFeatures.setSelected(true);
5379 viewport.setShowSequenceFeatures(true);
5386 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
5387 * awt.event.ActionEvent)
5390 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
5392 viewport.setShowUnconserved(showNonconservedMenuItem.getState());
5393 alignPanel.paintAlignment(true);
5400 * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
5404 protected void showGroupConsensus_actionPerformed(ActionEvent e)
5406 viewport.setShowGroupConsensus(showGroupConsensus.getState());
5407 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5415 * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
5416 * .event.ActionEvent)
5419 protected void showGroupConservation_actionPerformed(ActionEvent e)
5421 viewport.setShowGroupConservation(showGroupConservation.getState());
5422 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5429 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
5430 * .event.ActionEvent)
5433 protected void showConsensusHistogram_actionPerformed(ActionEvent e)
5435 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
5436 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5443 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
5444 * .event.ActionEvent)
5447 protected void showSequenceLogo_actionPerformed(ActionEvent e)
5449 viewport.setShowSequenceLogo(showSequenceLogo.getState());
5450 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5454 protected void normaliseSequenceLogo_actionPerformed(ActionEvent e)
5456 showSequenceLogo.setState(true);
5457 viewport.setShowSequenceLogo(true);
5458 viewport.setNormaliseSequenceLogo(normaliseSequenceLogo.getState());
5459 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5463 protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e)
5465 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
5472 * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
5473 * .event.ActionEvent)
5476 protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
5478 if (avc.makeGroupsFromSelection()) {
5479 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
5480 alignPanel.updateAnnotation();
5481 alignPanel.paintAlignment(true);
5486 protected void createGroup_actionPerformed(ActionEvent e)
5488 if (avc.createGroup())
5490 alignPanel.alignmentChanged();
5495 protected void unGroup_actionPerformed(ActionEvent e)
5499 alignPanel.alignmentChanged();
5504 * make the given alignmentPanel the currently selected tab
5506 * @param alignmentPanel
5508 public void setDisplayedView(AlignmentPanel alignmentPanel)
5510 if (!viewport.getSequenceSetId().equals(
5511 alignmentPanel.av.getSequenceSetId()))
5514 "Implementation error: cannot show a view from another alignment in an AlignFrame.");
5516 if (tabbedPane != null
5517 & alignPanels.indexOf(alignmentPanel) != tabbedPane
5518 .getSelectedIndex())
5520 tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel));
5525 class PrintThread extends Thread
5529 public PrintThread(AlignmentPanel ap)
5534 static PageFormat pf;
5539 PrinterJob printJob = PrinterJob.getPrinterJob();
5543 printJob.setPrintable(ap, pf);
5547 printJob.setPrintable(ap);
5550 if (printJob.printDialog())
5555 } catch (Exception PrintException)
5557 PrintException.printStackTrace();