2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 import java.awt.datatransfer.*;
27 import java.awt.dnd.*;
28 import java.awt.event.*;
29 import java.awt.print.*;
31 import javax.swing.event.MenuEvent;
33 import jalview.analysis.*;
34 import jalview.commands.*;
35 import jalview.datamodel.*;
37 import jalview.jbgui.*;
38 import jalview.schemes.*;
47 public class AlignFrame extends GAlignFrame implements DropTargetListener,
52 public static final int DEFAULT_WIDTH = 700;
55 public static final int DEFAULT_HEIGHT = 500;
57 public AlignmentPanel alignPanel;
59 AlignViewport viewport;
61 Vector alignPanels = new Vector();
64 * Last format used to load or save alignments in this window
66 String currentFileFormat = null;
69 * Current filename for this alignment
71 String fileName = null;
74 * Creates a new AlignFrame object with specific width and height.
80 public AlignFrame(AlignmentI al, int width, int height)
82 this(al, null, width, height);
85 * Creates a new AlignFrame object with specific width, height and sequenceSetId
89 * @param sequenceSetId
91 public AlignFrame(AlignmentI al, int width, int height, String sequenceSetId)
93 this(al, null, width, height, sequenceSetId);
96 * Creates a new AlignFrame object with specific width, height and sequenceSetId
100 * @param sequenceSetId
103 public AlignFrame(AlignmentI al, int width, int height, String sequenceSetId, String viewId)
105 this(al, null, width, height, sequenceSetId, viewId);
108 * new alignment window with hidden columns
112 * @param hiddenColumns
113 * ColumnSelection or null
114 * @param width Width of alignment frame
115 * @param height height of frame.
117 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
118 int width, int height)
120 this(al, hiddenColumns, width, height, null);
123 * Create alignment frame for al with hiddenColumns, a specific width and height, and specific sequenceId
125 * @param hiddenColumns
128 * @param sequenceSetId (may be null)
130 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
131 int width, int height, String sequenceSetId)
133 this(al, hiddenColumns, width, height, sequenceSetId, null);
137 * Create alignment frame for al with hiddenColumns, a specific width and height, and specific sequenceId
139 * @param hiddenColumns
142 * @param sequenceSetId (may be null)
143 * @param viewId (may be null)
145 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns, int width, int height,
146 String sequenceSetId, String viewId)
148 setSize(width, height);
149 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
151 alignPanel = new AlignmentPanel(this, viewport);
153 if (al.getDataset() == null)
158 addAlignmentPanel(alignPanel, true);
163 * Make a new AlignFrame from exisiting alignmentPanels
170 public AlignFrame(AlignmentPanel ap)
174 addAlignmentPanel(ap, false);
178 * initalise the alignframe from the underlying viewport data and the configurations
182 if (viewport.conservation == null)
184 BLOSUM62Colour.setEnabled(false);
185 conservationMenuItem.setEnabled(false);
186 modifyConservation.setEnabled(false);
187 // PIDColour.setEnabled(false);
188 // abovePIDThreshold.setEnabled(false);
189 // modifyPID.setEnabled(false);
192 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
195 if (sortby.equals("Id"))
197 sortIDMenuItem_actionPerformed(null);
199 else if (sortby.equals("Pairwise Identity"))
201 sortPairwiseMenuItem_actionPerformed(null);
204 if (Desktop.desktop != null)
206 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
207 addServiceListeners();
208 setGUINucleotide(viewport.alignment.isNucleotide());
211 setMenusFromViewport(viewport);
212 buildSortByAnnotationScoresMenu();
213 if (viewport.wrapAlignment)
215 wrapMenuItem_actionPerformed(null);
218 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
220 this.overviewMenuItem_actionPerformed(null);
228 * Change the filename and format for the alignment, and enable the 'reload'
229 * button functionality.
236 public void setFileName(String file, String format)
239 currentFileFormat = format;
240 reload.setEnabled(true);
243 void addKeyListener()
245 addKeyListener(new KeyAdapter()
247 public void keyPressed(KeyEvent evt)
249 if (viewport.cursorMode
250 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
251 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
252 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
253 && Character.isDigit(evt.getKeyChar()))
254 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
256 switch (evt.getKeyCode())
259 case 27: // escape key
260 deselectAllSequenceMenuItem_actionPerformed(null);
264 case KeyEvent.VK_DOWN:
265 if (evt.isAltDown() || !viewport.cursorMode)
266 moveSelectedSequences(false);
267 if (viewport.cursorMode)
268 alignPanel.seqPanel.moveCursor(0, 1);
272 if (evt.isAltDown() || !viewport.cursorMode)
273 moveSelectedSequences(true);
274 if (viewport.cursorMode)
275 alignPanel.seqPanel.moveCursor(0, -1);
279 case KeyEvent.VK_LEFT:
280 if (evt.isAltDown() || !viewport.cursorMode)
281 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
283 alignPanel.seqPanel.moveCursor(-1, 0);
287 case KeyEvent.VK_RIGHT:
288 if (evt.isAltDown() || !viewport.cursorMode)
289 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
291 alignPanel.seqPanel.moveCursor(1, 0);
294 case KeyEvent.VK_SPACE:
295 if (viewport.cursorMode)
297 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
298 || evt.isShiftDown() || evt.isAltDown());
302 case KeyEvent.VK_DELETE:
303 case KeyEvent.VK_BACK_SPACE:
304 if (!viewport.cursorMode)
306 cut_actionPerformed(null);
310 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
311 || evt.isShiftDown() || evt.isAltDown());
317 if (viewport.cursorMode)
319 alignPanel.seqPanel.setCursorRow();
323 if (viewport.cursorMode && !evt.isControlDown())
325 alignPanel.seqPanel.setCursorColumn();
329 if (viewport.cursorMode)
331 alignPanel.seqPanel.setCursorPosition();
335 case KeyEvent.VK_ENTER:
336 case KeyEvent.VK_COMMA:
337 if (viewport.cursorMode)
339 alignPanel.seqPanel.setCursorRowAndColumn();
344 if (viewport.cursorMode)
346 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
350 if (viewport.cursorMode)
352 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
357 viewport.cursorMode = !viewport.cursorMode;
358 statusBar.setText("Keyboard editing mode is "
359 + (viewport.cursorMode ? "on" : "off"));
360 if (viewport.cursorMode)
362 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
363 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
365 alignPanel.seqPanel.seqCanvas.repaint();
371 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
372 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
374 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
376 javax.help.HelpBroker hb = hs.createHelpBroker();
377 hb.setCurrentID("home");
378 hb.setDisplayed(true);
379 } catch (Exception ex)
381 ex.printStackTrace();
386 boolean toggleSeqs = !evt.isControlDown();
387 boolean toggleCols = !evt.isShiftDown();
389 boolean hide = false;
391 SequenceGroup sg = viewport.getSelectionGroup();
395 && sg.getSize() != viewport.alignment.getHeight())
397 hideSelSequences_actionPerformed(null);
400 else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))
402 showAllSeqs_actionPerformed(null);
408 if (viewport.colSel.getSelected().size() > 0)
410 hideSelColumns_actionPerformed(null);
413 viewport.selectionGroup = sg;
418 showAllColumns_actionPerformed(null);
423 case KeyEvent.VK_PAGE_UP:
424 if (viewport.wrapAlignment)
426 alignPanel.scrollUp(true);
430 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
431 - viewport.endSeq + viewport.startSeq);
434 case KeyEvent.VK_PAGE_DOWN:
435 if (viewport.wrapAlignment)
437 alignPanel.scrollUp(false);
441 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
442 + viewport.endSeq - viewport.startSeq);
448 public void keyReleased(KeyEvent evt)
450 switch (evt.getKeyCode())
452 case KeyEvent.VK_LEFT:
453 if (evt.isAltDown() || !viewport.cursorMode)
454 viewport.firePropertyChange("alignment", null, viewport
455 .getAlignment().getSequences());
458 case KeyEvent.VK_RIGHT:
459 if (evt.isAltDown() || !viewport.cursorMode)
460 viewport.firePropertyChange("alignment", null, viewport
461 .getAlignment().getSequences());
468 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
470 ap.alignFrame = this;
472 alignPanels.addElement(ap);
474 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
476 int aSize = alignPanels.size();
478 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
480 if (aSize == 1 && ap.av.viewName == null)
482 this.getContentPane().add(ap, BorderLayout.CENTER);
488 setInitialTabVisible();
491 expandViews.setEnabled(true);
492 gatherViews.setEnabled(true);
493 tabbedPane.addTab(ap.av.viewName, ap);
495 ap.setVisible(false);
502 ap.av.alignment.padGaps();
504 ap.av.updateConservation(ap);
505 ap.av.updateConsensus(ap);
509 public void setInitialTabVisible()
511 expandViews.setEnabled(true);
512 gatherViews.setEnabled(true);
513 tabbedPane.setVisible(true);
514 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
515 tabbedPane.addTab(first.av.viewName, first);
516 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
519 public AlignViewport getViewport()
524 /* Set up intrinsic listeners for dynamically generated GUI bits. */
525 private void addServiceListeners()
527 final java.beans.PropertyChangeListener thisListener;
528 // Do this once to get current state
529 BuildWebServiceMenu();
531 .addPropertyChangeListener(thisListener = new java.beans.PropertyChangeListener()
533 public void propertyChange(PropertyChangeEvent evt)
535 // System.out.println("Discoverer property change.");
536 if (evt.getPropertyName().equals("services"))
538 // System.out.println("Rebuilding web service menu");
539 BuildWebServiceMenu();
544 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
546 public void internalFrameClosed(
547 javax.swing.event.InternalFrameEvent evt)
549 // System.out.println("deregistering discoverer listener");
550 Desktop.discoverer.removePropertyChangeListener(thisListener);
551 closeMenuItem_actionPerformed(true);
556 public void setGUINucleotide(boolean nucleotide)
558 showTranslation.setVisible(nucleotide);
559 conservationMenuItem.setEnabled(!nucleotide);
560 modifyConservation.setEnabled(!nucleotide);
562 // Remember AlignFrame always starts as protein
565 calculateMenu.remove(calculateMenu.getItemCount() - 2);
570 * set up menus for the currently viewport. This may be called after any
571 * operation that affects the data in the current view (selection changed,
572 * etc) to update the menus to reflect the new state.
574 public void setMenusForViewport()
576 setMenusFromViewport(viewport);
580 * Need to call this method when tabs are selected for multiple views, or when
581 * loading from Jalview2XML.java
586 void setMenusFromViewport(AlignViewport av)
588 padGapsMenuitem.setSelected(av.padGaps);
589 colourTextMenuItem.setSelected(av.showColourText);
590 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
591 conservationMenuItem.setSelected(av.getConservationSelected());
592 seqLimits.setSelected(av.getShowJVSuffix());
593 idRightAlign.setSelected(av.rightAlignIds);
594 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
595 renderGapsMenuItem.setSelected(av.renderGaps);
596 wrapMenuItem.setSelected(av.wrapAlignment);
597 scaleAbove.setVisible(av.wrapAlignment);
598 scaleLeft.setVisible(av.wrapAlignment);
599 scaleRight.setVisible(av.wrapAlignment);
600 annotationPanelMenuItem.setState(av.showAnnotation);
601 viewBoxesMenuItem.setSelected(av.showBoxes);
602 viewTextMenuItem.setSelected(av.showText);
604 setColourSelected(ColourSchemeProperty.getColourName(av
605 .getGlobalColourScheme()));
607 showSeqFeatures.setSelected(av.showSequenceFeatures);
608 hiddenMarkers.setState(av.showHiddenMarkers);
609 applyToAllGroups.setState(av.colourAppliesToAllGroups);
610 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
611 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
613 setShowProductsEnabled();
618 Hashtable progressBars, progressBarHandlers;
623 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
625 public void setProgressBar(String message, long id)
627 if (progressBars == null)
629 progressBars = new Hashtable();
630 progressBarHandlers = new Hashtable();
633 JPanel progressPanel;
634 GridLayout layout = (GridLayout) statusPanel.getLayout();
635 if (progressBars.get(new Long(id)) != null)
637 progressPanel = (JPanel) progressBars.get(new Long(id));
638 statusPanel.remove(progressPanel);
639 progressBars.remove(progressPanel);
640 progressPanel = null;
643 statusBar.setText(message);
645 if (progressBarHandlers.contains(new Long(id)))
647 progressBarHandlers.remove(new Long(id));
649 layout.setRows(layout.getRows() - 1);
653 progressPanel = new JPanel(new BorderLayout(10, 5));
655 JProgressBar progressBar = new JProgressBar();
656 progressBar.setIndeterminate(true);
658 progressPanel.add(new JLabel(message), BorderLayout.WEST);
659 progressPanel.add(progressBar, BorderLayout.CENTER);
661 layout.setRows(layout.getRows() + 1);
662 statusPanel.add(progressPanel);
664 progressBars.put(new Long(id), progressPanel);
667 setMenusForViewport();
670 public void registerHandler(final long id, final IProgressIndicatorHandler handler)
672 if (progressBarHandlers==null || !progressBars.contains(new Long(id)))
674 throw new Error("call setProgressBar before registering the progress bar's handler.");
676 progressBarHandlers.put(new Long(id), handler);
677 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
678 if (handler.canCancel())
680 JButton cancel = new JButton("Cancel");
681 final IProgressIndicator us=this;
682 cancel.addActionListener(new ActionListener() {
684 public void actionPerformed(ActionEvent e)
686 handler.cancelActivity(id);
687 us.setProgressBar("Cancelled "+((JLabel)progressPanel.getComponent(0)).getText(), id);
690 progressPanel.add(cancel, BorderLayout.EAST);
695 * @return true if any progress bars are still active
697 public boolean operationInProgress()
699 if (progressBars != null && progressBars.size() > 0)
707 * Added so Castor Mapping file can obtain Jalview Version
709 public String getVersion()
711 return jalview.bin.Cache.getProperty("VERSION");
714 public FeatureRenderer getFeatureRenderer()
716 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
719 public void fetchSequence_actionPerformed(ActionEvent e)
721 new SequenceFetcher(this);
724 public void addFromFile_actionPerformed(ActionEvent e)
726 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
729 public void reload_actionPerformed(ActionEvent e)
731 if (fileName != null)
733 if (currentFileFormat.equals("Jalview"))
735 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
736 for (int i = 0; i < frames.length; i++)
738 if (frames[i] instanceof AlignFrame && frames[i] != this
739 && ((AlignFrame) frames[i]).fileName.equals(fileName))
743 frames[i].setSelected(true);
744 Desktop.instance.closeAssociatedWindows();
745 } catch (java.beans.PropertyVetoException ex)
751 Desktop.instance.closeAssociatedWindows();
753 FileLoader loader = new FileLoader();
754 String protocol = fileName.startsWith("http:") ? "URL" : "File";
755 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
759 Rectangle bounds = this.getBounds();
761 FileLoader loader = new FileLoader();
762 String protocol = fileName.startsWith("http:") ? "URL" : "File";
763 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
764 protocol, currentFileFormat);
766 newframe.setBounds(bounds);
768 this.closeMenuItem_actionPerformed(true);
773 public void addFromText_actionPerformed(ActionEvent e)
775 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
778 public void addFromURL_actionPerformed(ActionEvent e)
780 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
783 public void save_actionPerformed(ActionEvent e)
786 || (currentFileFormat == null
787 || !jalview.io.FormatAdapter.isValidIOFormat(currentFileFormat, true))
788 || fileName.startsWith("http"))
790 saveAs_actionPerformed(null);
794 saveAlignment(fileName, currentFileFormat);
804 public void saveAs_actionPerformed(ActionEvent e)
806 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
807 .getProperty("LAST_DIRECTORY"),
808 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
809 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
810 currentFileFormat, false);
812 chooser.setFileView(new JalviewFileView());
813 chooser.setDialogTitle("Save Alignment to file");
814 chooser.setToolTipText("Save");
816 int value = chooser.showSaveDialog(this);
818 if (value == JalviewFileChooser.APPROVE_OPTION)
820 currentFileFormat = chooser.getSelectedFormat();
821 if (currentFileFormat == null)
823 JOptionPane.showInternalMessageDialog(Desktop.desktop,
824 "You must select a file format before saving!",
825 "File format not specified", JOptionPane.WARNING_MESSAGE);
826 value = chooser.showSaveDialog(this);
830 fileName = chooser.getSelectedFile().getPath();
832 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
835 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
836 if (currentFileFormat.indexOf(" ") > -1)
838 currentFileFormat = currentFileFormat.substring(0,
839 currentFileFormat.indexOf(" "));
841 saveAlignment(fileName, currentFileFormat);
845 public boolean saveAlignment(String file, String format)
847 boolean success = true;
849 if (format.equalsIgnoreCase("Jalview"))
851 String shortName = title;
853 if (shortName.indexOf(java.io.File.separatorChar) > -1)
855 shortName = shortName.substring(shortName
856 .lastIndexOf(java.io.File.separatorChar) + 1);
859 success = new Jalview2XML().SaveAlignment(this, file, shortName);
861 statusBar.setText("Successfully saved to file: " + fileName + " in "
862 + format + " format.");
867 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
869 // JBPNote need to have a raise_gui flag here
870 JOptionPane.showInternalMessageDialog(this, "Cannot save file "
871 + fileName + " using format " + format,
872 "Alignment output format not supported",
873 JOptionPane.WARNING_MESSAGE);
874 saveAs_actionPerformed(null);
878 String[] omitHidden = null;
880 if (viewport.hasHiddenColumns)
882 int reply = JOptionPane
883 .showInternalConfirmDialog(
885 "The Alignment contains hidden columns."
886 + "\nDo you want to save only the visible alignment?",
887 "Save / Omit Hidden Columns",
888 JOptionPane.YES_NO_OPTION,
889 JOptionPane.QUESTION_MESSAGE);
891 if (reply == JOptionPane.YES_OPTION)
893 omitHidden = viewport.getViewAsString(false);
896 FormatAdapter f = new FormatAdapter();
897 String output = f.formatSequences(format,
898 (Alignment) viewport.alignment, // class cast exceptions will
899 // occur in the distant future
900 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
910 java.io.PrintWriter out = new java.io.PrintWriter(
911 new java.io.FileWriter(file));
916 statusBar.setText("Successfully saved to file: " + fileName
917 + " in " + format + " format.");
918 } catch (Exception ex)
921 ex.printStackTrace();
928 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
929 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
941 protected void outputText_actionPerformed(ActionEvent e)
943 String[] omitHidden = null;
945 if (viewport.hasHiddenColumns)
947 int reply = JOptionPane
948 .showInternalConfirmDialog(
950 "The Alignment contains hidden columns."
951 + "\nDo you want to output only the visible alignment?",
952 "Save / Omit Hidden Columns",
953 JOptionPane.YES_NO_OPTION,
954 JOptionPane.QUESTION_MESSAGE);
956 if (reply == JOptionPane.YES_OPTION)
958 omitHidden = viewport.getViewAsString(false);
962 CutAndPasteTransfer cap = new CutAndPasteTransfer();
963 cap.setForInput(null);
964 Desktop.addInternalFrame(cap, "Alignment output - "
965 + e.getActionCommand(), 600, 500);
967 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
968 viewport.alignment, omitHidden, viewport.colSel));
977 protected void htmlMenuItem_actionPerformed(ActionEvent e)
979 new HTMLOutput(alignPanel, alignPanel.seqPanel.seqCanvas
980 .getSequenceRenderer(), alignPanel.seqPanel.seqCanvas
981 .getFeatureRenderer());
984 public void createImageMap(File file, String image)
986 alignPanel.makePNGImageMap(file, image);
995 public void createPNG(File f)
997 alignPanel.makePNG(f);
1006 public void createEPS(File f)
1008 alignPanel.makeEPS(f);
1011 public void pageSetup_actionPerformed(ActionEvent e)
1013 PrinterJob printJob = PrinterJob.getPrinterJob();
1014 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1023 public void printMenuItem_actionPerformed(ActionEvent e)
1025 // Putting in a thread avoids Swing painting problems
1026 PrintThread thread = new PrintThread(alignPanel);
1030 public void exportFeatures_actionPerformed(ActionEvent e)
1032 new AnnotationExporter().exportFeatures(alignPanel);
1035 public void exportAnnotations_actionPerformed(ActionEvent e)
1037 new AnnotationExporter().exportAnnotations(alignPanel,
1038 viewport.showAnnotation ? viewport.alignment
1039 .getAlignmentAnnotation() : null, viewport.alignment
1041 ((Alignment) viewport.alignment).alignmentProperties);
1044 public void associatedData_actionPerformed(ActionEvent e)
1046 // Pick the tree file
1047 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1048 .getProperty("LAST_DIRECTORY"));
1049 chooser.setFileView(new JalviewFileView());
1050 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1051 chooser.setToolTipText("Load Jalview Annotations / Features file");
1053 int value = chooser.showOpenDialog(null);
1055 if (value == JalviewFileChooser.APPROVE_OPTION)
1057 String choice = chooser.getSelectedFile().getPath();
1058 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1059 loadJalviewDataFile(choice);
1065 * Close the current view or all views in the alignment frame.
1066 * If the frame only contains one view then the alignment will be removed from memory.
1068 * @param closeAllTabs
1070 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1072 if (alignPanels != null && alignPanels.size() < 2)
1074 closeAllTabs = true;
1079 if (alignPanels != null)
1083 for (int i = 0; i < alignPanels.size(); i++)
1085 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1086 jalview.structure.StructureSelectionManager ssm =
1087 jalview.structure.StructureSelectionManager
1088 .getStructureSelectionManager();
1089 ssm.removeStructureViewerListener(ap.seqPanel, null);
1090 ssm.removeSelectionListener(ap.seqPanel);
1091 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
1092 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
1093 PaintRefresher.RemoveComponent(ap);
1094 ap.av.alignment = null;
1099 closeView(alignPanel);
1106 this.setClosed(true);
1108 } catch (Exception ex)
1110 ex.printStackTrace();
1114 public void closeView(AlignmentPanel alignPanel2)
1116 int index = tabbedPane.getSelectedIndex();
1117 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1118 alignPanels.removeElement(alignPanel2);
1119 PaintRefresher.RemoveComponent(alignPanel2.seqPanel.seqCanvas);
1120 PaintRefresher.RemoveComponent(alignPanel2.idPanel.idCanvas);
1121 PaintRefresher.RemoveComponent(alignPanel2);
1122 alignPanel2.av.alignment = null;
1124 if (viewport == alignPanel2.av)
1130 tabbedPane.removeTabAt(closedindex);
1131 tabbedPane.validate();
1133 if (index > closedindex || index == tabbedPane.getTabCount())
1135 // modify currently selected tab index if necessary.
1139 this.tabSelectionChanged(index);
1145 void updateEditMenuBar()
1148 if (viewport.historyList.size() > 0)
1150 undoMenuItem.setEnabled(true);
1151 CommandI command = (CommandI) viewport.historyList.peek();
1152 undoMenuItem.setText("Undo " + command.getDescription());
1156 undoMenuItem.setEnabled(false);
1157 undoMenuItem.setText("Undo");
1160 if (viewport.redoList.size() > 0)
1162 redoMenuItem.setEnabled(true);
1164 CommandI command = (CommandI) viewport.redoList.peek();
1165 redoMenuItem.setText("Redo " + command.getDescription());
1169 redoMenuItem.setEnabled(false);
1170 redoMenuItem.setText("Redo");
1174 public void addHistoryItem(CommandI command)
1176 if (command.getSize() > 0)
1178 viewport.historyList.push(command);
1179 viewport.redoList.clear();
1180 updateEditMenuBar();
1181 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1187 * @return alignment objects for all views
1189 AlignmentI[] getViewAlignments()
1191 if (alignPanels != null)
1193 Enumeration e = alignPanels.elements();
1194 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1195 for (int i = 0; e.hasMoreElements(); i++)
1197 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1201 if (viewport != null)
1203 return new AlignmentI[]
1204 { viewport.alignment };
1215 protected void undoMenuItem_actionPerformed(ActionEvent e)
1217 if (viewport.historyList.empty())
1219 CommandI command = (CommandI) viewport.historyList.pop();
1220 viewport.redoList.push(command);
1221 command.undoCommand(getViewAlignments());
1223 AlignViewport originalSource = getOriginatingSource(command);
1224 updateEditMenuBar();
1226 if (originalSource != null)
1228 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1229 originalSource.firePropertyChange("alignment", null,
1230 originalSource.alignment.getSequences());
1240 protected void redoMenuItem_actionPerformed(ActionEvent e)
1242 if (viewport.redoList.size() < 1)
1247 CommandI command = (CommandI) viewport.redoList.pop();
1248 viewport.historyList.push(command);
1249 command.doCommand(getViewAlignments());
1251 AlignViewport originalSource = getOriginatingSource(command);
1252 updateEditMenuBar();
1254 if (originalSource != null)
1256 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1257 originalSource.firePropertyChange("alignment", null,
1258 originalSource.alignment.getSequences());
1262 AlignViewport getOriginatingSource(CommandI command)
1264 AlignViewport originalSource = null;
1265 // For sequence removal and addition, we need to fire
1266 // the property change event FROM the viewport where the
1267 // original alignment was altered
1268 AlignmentI al = null;
1269 if (command instanceof EditCommand)
1271 EditCommand editCommand = (EditCommand) command;
1272 al = editCommand.getAlignment();
1273 Vector comps = (Vector) PaintRefresher.components.get(viewport
1274 .getSequenceSetId());
1276 for (int i = 0; i < comps.size(); i++)
1278 if (comps.elementAt(i) instanceof AlignmentPanel)
1280 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1282 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1289 if (originalSource == null)
1291 // The original view is closed, we must validate
1292 // the current view against the closed view first
1295 PaintRefresher.validateSequences(al, viewport.alignment);
1298 originalSource = viewport;
1301 return originalSource;
1310 public void moveSelectedSequences(boolean up)
1312 SequenceGroup sg = viewport.getSelectionGroup();
1321 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1323 SequenceI seq = viewport.alignment.getSequenceAt(i);
1325 if (!sg.getSequences(null).contains(seq))
1330 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1332 if (sg.getSequences(null).contains(temp))
1337 viewport.alignment.getSequences().setElementAt(temp, i);
1338 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1343 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1345 SequenceI seq = viewport.alignment.getSequenceAt(i);
1347 if (!sg.getSequences(null).contains(seq))
1352 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1354 if (sg.getSequences(null).contains(temp))
1359 viewport.alignment.getSequences().setElementAt(temp, i);
1360 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1364 alignPanel.paintAlignment(true);
1367 synchronized void slideSequences(boolean right, int size)
1369 Vector sg = new Vector();
1370 if (viewport.cursorMode)
1372 sg.addElement(viewport.alignment
1373 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1375 else if (viewport.getSelectionGroup() != null
1376 && viewport.getSelectionGroup().getSize() != viewport.alignment
1379 sg = viewport.getSelectionGroup().getSequences(
1380 viewport.hiddenRepSequences);
1388 Vector invertGroup = new Vector();
1390 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1392 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1393 invertGroup.add(viewport.alignment.getSequenceAt(i));
1396 SequenceI[] seqs1 = new SequenceI[sg.size()];
1397 for (int i = 0; i < sg.size(); i++)
1398 seqs1[i] = (SequenceI) sg.elementAt(i);
1400 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1401 for (int i = 0; i < invertGroup.size(); i++)
1402 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1404 SlideSequencesCommand ssc;
1406 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1407 size, viewport.getGapCharacter());
1409 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1410 size, viewport.getGapCharacter());
1412 int groupAdjustment = 0;
1413 if (ssc.getGapsInsertedBegin() && right)
1415 if (viewport.cursorMode)
1416 alignPanel.seqPanel.moveCursor(size, 0);
1418 groupAdjustment = size;
1420 else if (!ssc.getGapsInsertedBegin() && !right)
1422 if (viewport.cursorMode)
1423 alignPanel.seqPanel.moveCursor(-size, 0);
1425 groupAdjustment = -size;
1428 if (groupAdjustment != 0)
1430 viewport.getSelectionGroup().setStartRes(
1431 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1432 viewport.getSelectionGroup().setEndRes(
1433 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1436 boolean appendHistoryItem = false;
1437 if (viewport.historyList != null && viewport.historyList.size() > 0
1438 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1440 appendHistoryItem = ssc
1441 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1445 if (!appendHistoryItem)
1446 addHistoryItem(ssc);
1457 protected void copy_actionPerformed(ActionEvent e)
1460 if (viewport.getSelectionGroup() == null)
1464 // TODO: preserve the ordering of displayed alignment annotation in any
1465 // internal paste (particularly sequence associated annotation)
1466 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1467 String[] omitHidden = null;
1469 if (viewport.hasHiddenColumns)
1471 omitHidden = viewport.getViewAsString(true);
1474 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1477 StringSelection ss = new StringSelection(output);
1481 jalview.gui.Desktop.internalCopy = true;
1482 // Its really worth setting the clipboard contents
1483 // to empty before setting the large StringSelection!!
1484 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
1485 new StringSelection(""), null);
1487 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
1489 } catch (OutOfMemoryError er)
1491 new OOMWarning("copying region", er);
1495 Vector hiddenColumns = null;
1496 if (viewport.hasHiddenColumns)
1498 hiddenColumns = new Vector();
1499 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1500 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1503 int[] region = (int[]) viewport.getColumnSelection()
1504 .getHiddenColumns().elementAt(i);
1506 hiddenColumns.addElement(new int[]
1507 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1511 Desktop.jalviewClipboard = new Object[]
1512 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1513 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1522 protected void pasteNew_actionPerformed(ActionEvent e)
1533 protected void pasteThis_actionPerformed(ActionEvent e)
1539 * Paste contents of Jalview clipboard
1541 * @param newAlignment
1542 * true to paste to a new alignment, otherwise add to this.
1544 void paste(boolean newAlignment)
1546 boolean externalPaste = true;
1549 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1550 Transferable contents = c.getContents(this);
1552 if (contents == null)
1560 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1561 if (str.length() < 1)
1566 format = new IdentifyFile().Identify(str, "Paste");
1568 } catch (OutOfMemoryError er)
1570 new OOMWarning("Out of memory pasting sequences!!", er);
1574 SequenceI[] sequences;
1575 boolean annotationAdded = false;
1576 AlignmentI alignment = null;
1578 if (Desktop.jalviewClipboard != null)
1580 // The clipboard was filled from within Jalview, we must use the
1582 // And dataset from the copied alignment
1583 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1584 // be doubly sure that we create *new* sequence objects.
1585 sequences = new SequenceI[newseq.length];
1586 for (int i = 0; i < newseq.length; i++)
1588 sequences[i] = new Sequence(newseq[i]);
1590 alignment = new Alignment(sequences);
1591 externalPaste = false;
1595 // parse the clipboard as an alignment.
1596 alignment = new FormatAdapter().readFile(str, "Paste", format);
1597 sequences = alignment.getSequencesArray();
1605 if (Desktop.jalviewClipboard != null)
1607 // dataset is inherited
1608 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1612 // new dataset is constructed
1613 alignment.setDataset(null);
1615 alwidth = alignment.getWidth() + 1;
1619 AlignmentI pastedal = alignment; // preserve pasted alignment object
1620 // Add pasted sequences and dataset into existing alignment.
1621 alignment = viewport.getAlignment();
1622 alwidth = alignment.getWidth() + 1;
1623 // decide if we need to import sequences from an existing dataset
1624 boolean importDs = Desktop.jalviewClipboard != null
1625 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1626 // importDs==true instructs us to copy over new dataset sequences from
1627 // an existing alignment
1628 Vector newDs = (importDs) ? new Vector() : null; // used to create
1629 // minimum dataset set
1631 for (int i = 0; i < sequences.length; i++)
1635 newDs.addElement(null);
1637 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1639 if (importDs && ds != null)
1641 if (!newDs.contains(ds))
1643 newDs.setElementAt(ds, i);
1644 ds = new Sequence(ds);
1645 // update with new dataset sequence
1646 sequences[i].setDatasetSequence(ds);
1650 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1655 // copy and derive new dataset sequence
1656 sequences[i] = sequences[i].deriveSequence();
1657 alignment.getDataset().addSequence(
1658 sequences[i].getDatasetSequence());
1659 // TODO: avoid creation of duplicate dataset sequences with a
1660 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1662 alignment.addSequence(sequences[i]); // merges dataset
1666 newDs.clear(); // tidy up
1668 if (pastedal.getAlignmentAnnotation() != null)
1670 // Add any annotation attached to alignment.
1671 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1672 for (int i = 0; i < alann.length; i++)
1674 annotationAdded = true;
1675 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1677 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1678 newann.padAnnotation(alwidth);
1679 alignment.addAnnotation(newann);
1689 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1690 sequences, 0, alignment.getWidth(), alignment));
1692 // Add any annotations attached to sequences
1693 for (int i = 0; i < sequences.length; i++)
1695 if (sequences[i].getAnnotation() != null)
1697 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1699 annotationAdded = true;
1700 sequences[i].getAnnotation()[a].adjustForAlignment();
1701 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1702 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1707 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1714 // propagate alignment changed.
1715 viewport.setEndSeq(alignment.getHeight());
1716 if (annotationAdded)
1718 // Duplicate sequence annotation in all views.
1719 AlignmentI[] alview = this.getViewAlignments();
1720 for (int i = 0; i < sequences.length; i++)
1722 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1725 for (int avnum = 0; avnum < alview.length; avnum++)
1727 if (alview[avnum] != alignment)
1729 // duplicate in a view other than the one with input focus
1730 int avwidth = alview[avnum].getWidth() + 1;
1731 // this relies on sann being preserved after we
1732 // modify the sequence's annotation array for each duplication
1733 for (int a = 0; a < sann.length; a++)
1735 AlignmentAnnotation newann = new AlignmentAnnotation(
1737 sequences[i].addAlignmentAnnotation(newann);
1738 newann.padAnnotation(avwidth);
1739 alview[avnum].addAnnotation(newann); // annotation was
1740 // duplicated earlier
1741 alview[avnum].setAnnotationIndex(newann, a);
1746 buildSortByAnnotationScoresMenu();
1748 viewport.firePropertyChange("alignment", null, alignment
1754 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1756 String newtitle = new String("Copied sequences");
1758 if (Desktop.jalviewClipboard != null
1759 && Desktop.jalviewClipboard[2] != null)
1761 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1762 for (int i = 0; i < hc.size(); i++)
1764 int[] region = (int[]) hc.elementAt(i);
1765 af.viewport.hideColumns(region[0], region[1]);
1769 // >>>This is a fix for the moment, until a better solution is
1771 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1773 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1775 // TODO: maintain provenance of an alignment, rather than just make the
1776 // title a concatenation of operations.
1779 if (title.startsWith("Copied sequences"))
1785 newtitle = newtitle.concat("- from " + title);
1790 newtitle = new String("Pasted sequences");
1793 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1798 } catch (Exception ex)
1800 ex.printStackTrace();
1801 System.out.println("Exception whilst pasting: " + ex);
1802 // could be anything being pasted in here
1813 protected void cut_actionPerformed(ActionEvent e)
1815 copy_actionPerformed(null);
1816 delete_actionPerformed(null);
1825 protected void delete_actionPerformed(ActionEvent evt)
1828 SequenceGroup sg = viewport.getSelectionGroup();
1834 Vector seqs = new Vector();
1836 for (int i = 0; i < sg.getSize(); i++)
1838 seq = sg.getSequenceAt(i);
1839 seqs.addElement(seq);
1842 // If the cut affects all sequences, remove highlighted columns
1843 if (sg.getSize() == viewport.alignment.getHeight())
1845 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1846 sg.getEndRes() + 1);
1849 SequenceI[] cut = new SequenceI[seqs.size()];
1850 for (int i = 0; i < seqs.size(); i++)
1852 cut[i] = (SequenceI) seqs.elementAt(i);
1856 * //ADD HISTORY ITEM
1858 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
1859 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
1860 viewport.alignment));
1862 viewport.setSelectionGroup(null);
1863 viewport.sendSelection();
1864 viewport.alignment.deleteGroup(sg);
1866 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
1868 if (viewport.getAlignment().getHeight() < 1)
1872 this.setClosed(true);
1873 } catch (Exception ex)
1885 protected void deleteGroups_actionPerformed(ActionEvent e)
1887 viewport.alignment.deleteAllGroups();
1888 viewport.sequenceColours = null;
1889 viewport.setSelectionGroup(null);
1890 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1891 alignPanel.paintAlignment(true);
1900 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1902 SequenceGroup sg = new SequenceGroup();
1904 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1906 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1909 sg.setEndRes(viewport.alignment.getWidth() - 1);
1910 viewport.setSelectionGroup(sg);
1911 viewport.sendSelection();
1912 alignPanel.paintAlignment(true);
1913 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1922 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1924 if (viewport.cursorMode)
1926 alignPanel.seqPanel.keyboardNo1 = null;
1927 alignPanel.seqPanel.keyboardNo2 = null;
1929 viewport.setSelectionGroup(null);
1930 viewport.getColumnSelection().clear();
1931 viewport.setSelectionGroup(null);
1932 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1933 alignPanel.idPanel.idCanvas.searchResults = null;
1934 alignPanel.paintAlignment(true);
1935 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1944 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1946 SequenceGroup sg = viewport.getSelectionGroup();
1950 selectAllSequenceMenuItem_actionPerformed(null);
1955 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1957 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1960 alignPanel.paintAlignment(true);
1961 viewport.sendSelection();
1962 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1965 public void invertColSel_actionPerformed(ActionEvent e)
1967 viewport.invertColumnSelection();
1968 alignPanel.paintAlignment(true);
1977 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1979 trimAlignment(true);
1988 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1990 trimAlignment(false);
1993 void trimAlignment(boolean trimLeft)
1995 ColumnSelection colSel = viewport.getColumnSelection();
1998 if (colSel.size() > 0)
2002 column = colSel.getMin();
2006 column = colSel.getMax();
2010 if (viewport.getSelectionGroup() != null)
2012 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2013 viewport.hiddenRepSequences);
2017 seqs = viewport.alignment.getSequencesArray();
2020 TrimRegionCommand trimRegion;
2023 trimRegion = new TrimRegionCommand("Remove Left",
2024 TrimRegionCommand.TRIM_LEFT, seqs, column,
2025 viewport.alignment, viewport.colSel,
2026 viewport.selectionGroup);
2027 viewport.setStartRes(0);
2031 trimRegion = new TrimRegionCommand("Remove Right",
2032 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2033 viewport.alignment, viewport.colSel,
2034 viewport.selectionGroup);
2037 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2039 addHistoryItem(trimRegion);
2041 Vector groups = viewport.alignment.getGroups();
2043 for (int i = 0; i < groups.size(); i++)
2045 SequenceGroup sg = (SequenceGroup) groups.get(i);
2047 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2048 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2050 viewport.alignment.deleteGroup(sg);
2054 viewport.firePropertyChange("alignment", null, viewport
2055 .getAlignment().getSequences());
2065 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2067 int start = 0, end = viewport.alignment.getWidth() - 1;
2070 if (viewport.getSelectionGroup() != null)
2072 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2073 viewport.hiddenRepSequences);
2074 start = viewport.getSelectionGroup().getStartRes();
2075 end = viewport.getSelectionGroup().getEndRes();
2079 seqs = viewport.alignment.getSequencesArray();
2082 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2083 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2085 addHistoryItem(removeGapCols);
2087 statusBar.setText("Removed " + removeGapCols.getSize()
2088 + " empty columns.");
2090 // This is to maintain viewport position on first residue
2091 // of first sequence
2092 SequenceI seq = viewport.alignment.getSequenceAt(0);
2093 int startRes = seq.findPosition(viewport.startRes);
2094 // ShiftList shifts;
2095 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2096 // edit.alColumnChanges=shifts.getInverse();
2097 // if (viewport.hasHiddenColumns)
2098 // viewport.getColumnSelection().compensateForEdits(shifts);
2099 viewport.setStartRes(seq.findIndex(startRes) - 1);
2100 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2111 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2113 int start = 0, end = viewport.alignment.getWidth() - 1;
2116 if (viewport.getSelectionGroup() != null)
2118 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2119 viewport.hiddenRepSequences);
2120 start = viewport.getSelectionGroup().getStartRes();
2121 end = viewport.getSelectionGroup().getEndRes();
2125 seqs = viewport.alignment.getSequencesArray();
2128 // This is to maintain viewport position on first residue
2129 // of first sequence
2130 SequenceI seq = viewport.alignment.getSequenceAt(0);
2131 int startRes = seq.findPosition(viewport.startRes);
2133 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2134 viewport.alignment));
2136 viewport.setStartRes(seq.findIndex(startRes) - 1);
2138 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2149 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2151 viewport.padGaps = padGapsMenuitem.isSelected();
2152 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2158 // if (justifySeqs>0)
2160 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2171 public void findMenuItem_actionPerformed(ActionEvent e)
2176 public void newView_actionPerformed(ActionEvent e)
2178 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2181 newap.av.gatherViewsHere = false;
2183 if (viewport.viewName == null)
2185 viewport.viewName = "Original";
2188 newap.av.historyList = viewport.historyList;
2189 newap.av.redoList = viewport.redoList;
2191 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2192 String newViewName = "View " + index;
2194 Vector comps = (Vector) PaintRefresher.components.get(viewport
2195 .getSequenceSetId());
2196 Vector existingNames = new Vector();
2197 for (int i = 0; i < comps.size(); i++)
2199 if (comps.elementAt(i) instanceof AlignmentPanel)
2201 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2202 if (!existingNames.contains(ap.av.viewName))
2204 existingNames.addElement(ap.av.viewName);
2209 while (existingNames.contains(newViewName))
2211 newViewName = "View " + (++index);
2214 newap.av.viewName = newViewName;
2216 addAlignmentPanel(newap, true);
2218 if (alignPanels.size() == 2)
2220 viewport.gatherViewsHere = true;
2222 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2225 public void expandViews_actionPerformed(ActionEvent e)
2227 Desktop.instance.explodeViews(this);
2230 public void gatherViews_actionPerformed(ActionEvent e)
2232 Desktop.instance.gatherViews(this);
2241 public void font_actionPerformed(ActionEvent e)
2243 new FontChooser(alignPanel);
2252 protected void seqLimit_actionPerformed(ActionEvent e)
2254 viewport.setShowJVSuffix(seqLimits.isSelected());
2256 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2257 .calculateIdWidth());
2258 alignPanel.paintAlignment(true);
2261 public void idRightAlign_actionPerformed(ActionEvent e)
2263 viewport.rightAlignIds = idRightAlign.isSelected();
2264 alignPanel.paintAlignment(true);
2267 public void centreColumnLabels_actionPerformed(ActionEvent e)
2269 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2270 alignPanel.paintAlignment(true);
2273 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2275 protected void followHighlight_actionPerformed()
2277 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2279 alignPanel.scrollToPosition(alignPanel.seqPanel.seqCanvas.searchResults, false);
2289 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2291 viewport.setColourText(colourTextMenuItem.isSelected());
2292 alignPanel.paintAlignment(true);
2301 public void wrapMenuItem_actionPerformed(ActionEvent e)
2303 scaleAbove.setVisible(wrapMenuItem.isSelected());
2304 scaleLeft.setVisible(wrapMenuItem.isSelected());
2305 scaleRight.setVisible(wrapMenuItem.isSelected());
2306 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2307 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2310 public void showAllSeqs_actionPerformed(ActionEvent e)
2312 viewport.showAllHiddenSeqs();
2315 public void showAllColumns_actionPerformed(ActionEvent e)
2317 viewport.showAllHiddenColumns();
2321 public void hideSelSequences_actionPerformed(ActionEvent e)
2323 viewport.hideAllSelectedSeqs();
2324 alignPanel.paintAlignment(true);
2327 public void hideSelColumns_actionPerformed(ActionEvent e)
2329 viewport.hideSelectedColumns();
2330 alignPanel.paintAlignment(true);
2333 public void hiddenMarkers_actionPerformed(ActionEvent e)
2335 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2345 protected void scaleAbove_actionPerformed(ActionEvent e)
2347 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2348 alignPanel.paintAlignment(true);
2357 protected void scaleLeft_actionPerformed(ActionEvent e)
2359 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2360 alignPanel.paintAlignment(true);
2369 protected void scaleRight_actionPerformed(ActionEvent e)
2371 viewport.setScaleRightWrapped(scaleRight.isSelected());
2372 alignPanel.paintAlignment(true);
2381 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2383 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2384 alignPanel.paintAlignment(true);
2393 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2395 viewport.setShowText(viewTextMenuItem.isSelected());
2396 alignPanel.paintAlignment(true);
2405 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2407 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2408 alignPanel.paintAlignment(true);
2411 public FeatureSettings featureSettings;
2413 public void featureSettings_actionPerformed(ActionEvent e)
2415 if (featureSettings != null)
2417 featureSettings.close();
2418 featureSettings = null;
2420 featureSettings = new FeatureSettings(this);
2424 * Set or clear 'Show Sequence Features'
2429 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2431 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2432 alignPanel.paintAlignment(true);
2433 if (alignPanel.getOverviewPanel() != null)
2435 alignPanel.getOverviewPanel().updateOverviewImage();
2439 * Set or clear 'Show Sequence Features'
2444 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2446 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight.isSelected());
2447 if (viewport.getShowSequenceFeaturesHeight())
2449 // ensure we're actually displaying features
2450 viewport.setShowSequenceFeatures(true);
2451 showSeqFeatures.setSelected(true);
2453 alignPanel.paintAlignment(true);
2454 if (alignPanel.getOverviewPanel() != null)
2456 alignPanel.getOverviewPanel().updateOverviewImage();
2466 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2468 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2469 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2472 public void alignmentProperties()
2474 JEditorPane editPane = new JEditorPane("text/html", "");
2475 editPane.setEditable(false);
2476 StringBuffer contents = new StringBuffer("<html>");
2479 int min = Integer.MAX_VALUE, max = 0;
2480 for (int i = 0; i < viewport.alignment.getHeight(); i++)
2482 int size = viewport.alignment.getSequenceAt(i).getEnd()
2483 - viewport.alignment.getSequenceAt(i).getStart();
2490 avg = avg / (float) viewport.alignment.getHeight();
2492 contents.append("<br>Sequences: " + viewport.alignment.getHeight());
2493 contents.append("<br>Minimum Sequence Length: " + min);
2494 contents.append("<br>Maximum Sequence Length: " + max);
2495 contents.append("<br>Average Length: " + (int) avg);
2497 if (((Alignment) viewport.alignment).getProperties() != null)
2499 Hashtable props = ((Alignment) viewport.alignment).getProperties();
2500 Enumeration en = props.keys();
2501 contents.append("<br><br><table border=\"1\">");
2502 while (en.hasMoreElements())
2504 String key = en.nextElement().toString();
2505 StringBuffer val = new StringBuffer();
2506 String vals = props.get(key).toString();
2510 npos = vals.indexOf("\n", pos);
2513 val.append(vals.substring(pos));
2517 val.append(vals.substring(pos, npos));
2521 } while (npos != -1);
2523 .append("<tr><td>" + key + "</td><td>" + val + "</td></tr>");
2525 contents.append("</table>");
2527 editPane.setText(contents.toString() + "</html>");
2528 JInternalFrame frame = new JInternalFrame();
2529 frame.getContentPane().add(new JScrollPane(editPane));
2531 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2532 + getTitle(), 500, 400);
2541 public void overviewMenuItem_actionPerformed(ActionEvent e)
2543 if (alignPanel.overviewPanel != null)
2548 JInternalFrame frame = new JInternalFrame();
2549 OverviewPanel overview = new OverviewPanel(alignPanel);
2550 frame.setContentPane(overview);
2551 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(), frame
2552 .getWidth(), frame.getHeight());
2554 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2556 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2558 public void internalFrameClosed(
2559 javax.swing.event.InternalFrameEvent evt)
2561 alignPanel.setOverviewPanel(null);
2565 alignPanel.setOverviewPanel(overview);
2568 public void textColour_actionPerformed(ActionEvent e)
2570 new TextColourChooser().chooseColour(alignPanel, null);
2579 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2590 public void clustalColour_actionPerformed(ActionEvent e)
2592 changeColour(new ClustalxColourScheme(
2593 viewport.alignment.getSequences(), viewport.alignment
2603 public void zappoColour_actionPerformed(ActionEvent e)
2605 changeColour(new ZappoColourScheme());
2614 public void taylorColour_actionPerformed(ActionEvent e)
2616 changeColour(new TaylorColourScheme());
2625 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2627 changeColour(new HydrophobicColourScheme());
2636 public void helixColour_actionPerformed(ActionEvent e)
2638 changeColour(new HelixColourScheme());
2647 public void strandColour_actionPerformed(ActionEvent e)
2649 changeColour(new StrandColourScheme());
2658 public void turnColour_actionPerformed(ActionEvent e)
2660 changeColour(new TurnColourScheme());
2669 public void buriedColour_actionPerformed(ActionEvent e)
2671 changeColour(new BuriedColourScheme());
2680 public void nucleotideColour_actionPerformed(ActionEvent e)
2682 changeColour(new NucleotideColourScheme());
2685 public void annotationColour_actionPerformed(ActionEvent e)
2687 new AnnotationColourChooser(viewport, alignPanel);
2696 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2698 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2707 public void changeColour(ColourSchemeI cs)
2713 if (viewport.getAbovePIDThreshold())
2715 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2718 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2720 viewport.setGlobalColourScheme(cs);
2724 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2727 if (viewport.getConservationSelected())
2730 Alignment al = (Alignment) viewport.alignment;
2731 Conservation c = new Conservation("All",
2732 ResidueProperties.propHash, 3, al.getSequences(), 0, al
2736 c.verdict(false, viewport.ConsPercGaps);
2738 cs.setConservation(c);
2740 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
2745 cs.setConservation(null);
2748 cs.setConsensus(viewport.hconsensus);
2751 viewport.setGlobalColourScheme(cs);
2753 if (viewport.getColourAppliesToAllGroups())
2755 Vector groups = viewport.alignment.getGroups();
2757 for (int i = 0; i < groups.size(); i++)
2759 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2767 if (cs instanceof ClustalxColourScheme)
2769 sg.cs = new ClustalxColourScheme(sg
2770 .getSequences(viewport.hiddenRepSequences), sg.getWidth());
2772 else if (cs instanceof UserColourScheme)
2774 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
2780 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2781 } catch (Exception ex)
2786 if (viewport.getAbovePIDThreshold()
2787 || cs instanceof PIDColourScheme
2788 || cs instanceof Blosum62ColourScheme)
2790 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2792 sg.cs.setConsensus(AAFrequency.calculate(sg
2793 .getSequences(viewport.hiddenRepSequences), sg
2794 .getStartRes(), sg.getEndRes() + 1));
2798 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2801 if (viewport.getConservationSelected())
2803 Conservation c = new Conservation("Group",
2804 ResidueProperties.propHash, 3, sg
2805 .getSequences(viewport.hiddenRepSequences), sg
2806 .getStartRes(), sg.getEndRes() + 1);
2808 c.verdict(false, viewport.ConsPercGaps);
2809 sg.cs.setConservation(c);
2813 sg.cs.setConservation(null);
2818 if (alignPanel.getOverviewPanel() != null)
2820 alignPanel.getOverviewPanel().updateOverviewImage();
2823 alignPanel.paintAlignment(true);
2832 protected void modifyPID_actionPerformed(ActionEvent e)
2834 if (viewport.getAbovePIDThreshold()
2835 && viewport.globalColourScheme != null)
2837 SliderPanel.setPIDSliderSource(alignPanel, viewport
2838 .getGlobalColourScheme(), "Background");
2839 SliderPanel.showPIDSlider();
2849 protected void modifyConservation_actionPerformed(ActionEvent e)
2851 if (viewport.getConservationSelected()
2852 && viewport.globalColourScheme != null)
2854 SliderPanel.setConservationSlider(alignPanel,
2855 viewport.globalColourScheme, "Background");
2856 SliderPanel.showConservationSlider();
2866 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2868 viewport.setConservationSelected(conservationMenuItem.isSelected());
2870 viewport.setAbovePIDThreshold(false);
2871 abovePIDThreshold.setSelected(false);
2873 changeColour(viewport.getGlobalColourScheme());
2875 modifyConservation_actionPerformed(null);
2884 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2886 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2888 conservationMenuItem.setSelected(false);
2889 viewport.setConservationSelected(false);
2891 changeColour(viewport.getGlobalColourScheme());
2893 modifyPID_actionPerformed(null);
2902 public void userDefinedColour_actionPerformed(ActionEvent e)
2904 if (e.getActionCommand().equals("User Defined..."))
2906 new UserDefinedColours(alignPanel, null);
2910 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2911 .getUserColourSchemes().get(e.getActionCommand());
2917 public void updateUserColourMenu()
2920 Component[] menuItems = colourMenu.getMenuComponents();
2921 int i, iSize = menuItems.length;
2922 for (i = 0; i < iSize; i++)
2924 if (menuItems[i].getName() != null
2925 && menuItems[i].getName().equals("USER_DEFINED"))
2927 colourMenu.remove(menuItems[i]);
2931 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2933 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
2934 .getUserColourSchemes().keys();
2936 while (userColours.hasMoreElements())
2938 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2939 userColours.nextElement().toString());
2940 radioItem.setName("USER_DEFINED");
2941 radioItem.addMouseListener(new MouseAdapter()
2943 public void mousePressed(MouseEvent evt)
2945 if (evt.isControlDown()
2946 || SwingUtilities.isRightMouseButton(evt))
2949 .removeActionListener(radioItem.getActionListeners()[0]);
2951 int option = JOptionPane.showInternalConfirmDialog(
2952 jalview.gui.Desktop.desktop,
2953 "Remove from default list?",
2954 "Remove user defined colour",
2955 JOptionPane.YES_NO_OPTION);
2956 if (option == JOptionPane.YES_OPTION)
2958 jalview.gui.UserDefinedColours
2959 .removeColourFromDefaults(radioItem.getText());
2960 colourMenu.remove(radioItem);
2964 radioItem.addActionListener(new ActionListener()
2966 public void actionPerformed(ActionEvent evt)
2968 userDefinedColour_actionPerformed(evt);
2975 radioItem.addActionListener(new ActionListener()
2977 public void actionPerformed(ActionEvent evt)
2979 userDefinedColour_actionPerformed(evt);
2983 colourMenu.insert(radioItem, 15);
2984 colours.add(radioItem);
2995 public void PIDColour_actionPerformed(ActionEvent e)
2997 changeColour(new PIDColourScheme());
3006 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3008 changeColour(new Blosum62ColourScheme());
3017 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3019 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3020 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3021 .getAlignment().getSequenceAt(0), null);
3022 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3023 viewport.alignment));
3024 alignPanel.paintAlignment(true);
3033 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3035 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3036 AlignmentSorter.sortByID(viewport.getAlignment());
3037 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
3038 alignPanel.paintAlignment(true);
3046 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3048 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3049 AlignmentSorter.sortByLength(viewport.getAlignment());
3050 addHistoryItem(new OrderCommand("Length Sort", oldOrder, viewport.alignment));
3051 alignPanel.paintAlignment(true);
3060 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3062 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3063 AlignmentSorter.sortByGroup(viewport.getAlignment());
3064 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3065 viewport.alignment));
3067 alignPanel.paintAlignment(true);
3076 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3078 new RedundancyPanel(alignPanel, this);
3087 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3089 if ((viewport.getSelectionGroup() == null)
3090 || (viewport.getSelectionGroup().getSize() < 2))
3092 JOptionPane.showInternalMessageDialog(this,
3093 "You must select at least 2 sequences.", "Invalid Selection",
3094 JOptionPane.WARNING_MESSAGE);
3098 JInternalFrame frame = new JInternalFrame();
3099 frame.setContentPane(new PairwiseAlignPanel(viewport));
3100 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3110 public void PCAMenuItem_actionPerformed(ActionEvent e)
3112 if (((viewport.getSelectionGroup() != null)
3113 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3114 .getSelectionGroup().getSize() > 0))
3115 || (viewport.getAlignment().getHeight() < 4))
3117 JOptionPane.showInternalMessageDialog(this,
3118 "Principal component analysis must take\n"
3119 + "at least 4 input sequences.",
3120 "Sequence selection insufficient",
3121 JOptionPane.WARNING_MESSAGE);
3126 new PCAPanel(alignPanel);
3129 public void autoCalculate_actionPerformed(ActionEvent e)
3131 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3132 if (viewport.autoCalculateConsensus)
3134 viewport.firePropertyChange("alignment", null, viewport
3135 .getAlignment().getSequences());
3145 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3147 NewTreePanel("AV", "PID", "Average distance tree using PID");
3156 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3158 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3167 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3169 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3178 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3180 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3193 void NewTreePanel(String type, String pwType, String title)
3197 if (viewport.getSelectionGroup() != null)
3199 if (viewport.getSelectionGroup().getSize() < 3)
3204 "You need to have more than two sequences selected to build a tree!",
3205 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3210 SequenceGroup sg = viewport.getSelectionGroup();
3212 /* Decide if the selection is a column region */
3213 while (s < sg.getSize())
3215 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3221 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3222 + "Try using the Pad function in the edit menu,\n"
3223 + "or one of the multiple sequence alignment web services.",
3224 "Sequences in selection are not aligned",
3225 JOptionPane.WARNING_MESSAGE);
3231 title = title + " on region";
3232 tp = new TreePanel(alignPanel, type, pwType);
3236 // are the sequences aligned?
3237 if (!viewport.alignment.isAligned())
3242 "The sequences must be aligned before creating a tree.\n"
3243 + "Try using the Pad function in the edit menu,\n"
3244 + "or one of the multiple sequence alignment web services.",
3245 "Sequences not aligned",
3246 JOptionPane.WARNING_MESSAGE);
3251 if (viewport.alignment.getHeight() < 2)
3256 tp = new TreePanel(alignPanel, type, pwType);
3261 if (viewport.viewName != null)
3263 title += viewport.viewName + " of ";
3266 title += this.title;
3268 Desktop.addInternalFrame(tp, title, 600, 500);
3279 public void addSortByOrderMenuItem(String title,
3280 final AlignmentOrder order)
3282 final JMenuItem item = new JMenuItem("by " + title);
3284 item.addActionListener(new java.awt.event.ActionListener()
3286 public void actionPerformed(ActionEvent e)
3288 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3290 // TODO: JBPNote - have to map order entries to curent SequenceI
3292 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3294 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3295 viewport.alignment));
3297 alignPanel.paintAlignment(true);
3303 * Add a new sort by annotation score menu item
3306 * the menu to add the option to
3308 * the label used to retrieve scores for each sequence on the
3311 public void addSortByAnnotScoreMenuItem(JMenu sort,
3312 final String scoreLabel)
3314 final JMenuItem item = new JMenuItem(scoreLabel);
3316 item.addActionListener(new java.awt.event.ActionListener()
3318 public void actionPerformed(ActionEvent e)
3320 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3321 AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport
3322 .getAlignment());// ,viewport.getSelectionGroup());
3323 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3324 viewport.alignment));
3325 alignPanel.paintAlignment(true);
3331 * last hash for alignment's annotation array - used to minimise cost of
3334 protected int _annotationScoreVectorHash;
3337 * search the alignment and rebuild the sort by annotation score submenu the
3338 * last alignment annotation vector hash is stored to minimize cost of
3339 * rebuilding in subsequence calls.
3342 public void buildSortByAnnotationScoresMenu()
3344 if (viewport.alignment.getAlignmentAnnotation() == null)
3349 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3351 sortByAnnotScore.removeAll();
3352 // almost certainly a quicker way to do this - but we keep it simple
3353 Hashtable scoreSorts = new Hashtable();
3354 AlignmentAnnotation aann[];
3355 Enumeration sq = viewport.alignment.getSequences().elements();
3356 while (sq.hasMoreElements())
3358 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3359 for (int i = 0; aann != null && i < aann.length; i++)
3361 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3363 scoreSorts.put(aann[i].label, aann[i].label);
3367 Enumeration labels = scoreSorts.keys();
3368 while (labels.hasMoreElements())
3370 addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels
3373 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3376 _annotationScoreVectorHash = viewport.alignment
3377 .getAlignmentAnnotation().hashCode();
3382 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3383 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3384 * call. Listeners are added to remove the menu item when the treePanel is
3385 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3389 * Displayed tree window.
3391 * SortBy menu item title.
3393 public void buildTreeMenu()
3395 sortByTreeMenu.removeAll();
3397 Vector comps = (Vector) PaintRefresher.components.get(viewport
3398 .getSequenceSetId());
3399 Vector treePanels = new Vector();
3400 int i, iSize = comps.size();
3401 for (i = 0; i < iSize; i++)
3403 if (comps.elementAt(i) instanceof TreePanel)
3405 treePanels.add(comps.elementAt(i));
3409 iSize = treePanels.size();
3413 sortByTreeMenu.setVisible(false);
3417 sortByTreeMenu.setVisible(true);
3419 for (i = 0; i < treePanels.size(); i++)
3421 TreePanel tp = (TreePanel) treePanels.elementAt(i);
3422 final JMenuItem item = new JMenuItem(tp.getTitle());
3423 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3424 item.addActionListener(new java.awt.event.ActionListener()
3426 public void actionPerformed(ActionEvent e)
3428 SequenceI[] oldOrder = viewport.getAlignment()
3429 .getSequencesArray();
3430 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3432 addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
3433 viewport.alignment));
3435 alignPanel.paintAlignment(true);
3439 sortByTreeMenu.add(item);
3444 * Work out whether the whole set of sequences or just the selected set will
3445 * be submitted for multiple alignment.
3448 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3450 // Now, check we have enough sequences
3451 AlignmentView msa = null;
3453 if ((viewport.getSelectionGroup() != null)
3454 && (viewport.getSelectionGroup().getSize() > 1))
3456 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3457 // some common interface!
3459 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3460 * SequenceI[sz = seqs.getSize(false)];
3462 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3463 * seqs.getSequenceAt(i); }
3465 msa = viewport.getAlignmentView(true);
3470 * Vector seqs = viewport.getAlignment().getSequences();
3472 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3474 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3475 * seqs.elementAt(i); } }
3477 msa = viewport.getAlignmentView(false);
3483 * Decides what is submitted to a secondary structure prediction service: the
3484 * first sequence in the alignment, or in the current selection, or, if the
3485 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3486 * region or the whole alignment. (where the first sequence in the set is the
3487 * one that the prediction will be for).
3489 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3491 AlignmentView seqs = null;
3493 if ((viewport.getSelectionGroup() != null)
3494 && (viewport.getSelectionGroup().getSize() > 0))
3496 seqs = viewport.getAlignmentView(true);
3500 seqs = viewport.getAlignmentView(false);
3502 // limit sequences - JBPNote in future - could spawn multiple prediction
3504 // TODO: viewport.alignment.isAligned is a global state - the local
3505 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3506 if (!viewport.alignment.isAligned())
3508 seqs.setSequences(new SeqCigar[]
3509 { seqs.getSequences()[0] });
3520 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3522 // Pick the tree file
3523 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
3524 .getProperty("LAST_DIRECTORY"));
3525 chooser.setFileView(new JalviewFileView());
3526 chooser.setDialogTitle("Select a newick-like tree file");
3527 chooser.setToolTipText("Load a tree file");
3529 int value = chooser.showOpenDialog(null);
3531 if (value == JalviewFileChooser.APPROVE_OPTION)
3533 String choice = chooser.getSelectedFile().getPath();
3534 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3535 jalview.io.NewickFile fin = null;
3538 fin = new jalview.io.NewickFile(choice, "File");
3539 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3540 } catch (Exception ex)
3542 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3543 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3544 ex.printStackTrace();
3546 if (fin != null && fin.hasWarningMessage())
3548 JOptionPane.showMessageDialog(Desktop.desktop, fin
3549 .getWarningMessage(), "Possible problem with tree file",
3550 JOptionPane.WARNING_MESSAGE);
3555 public TreePanel ShowNewickTree(NewickFile nf, String title)
3557 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3560 public TreePanel ShowNewickTree(NewickFile nf, String title,
3561 AlignmentView input)
3563 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3566 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3567 int h, int x, int y)
3569 return ShowNewickTree(nf, title, null, w, h, x, y);
3573 * Add a treeviewer for the tree extracted from a newick file object to the
3574 * current alignment view
3581 * Associated alignment input data (or null)
3590 * @return TreePanel handle
3592 public TreePanel ShowNewickTree(NewickFile nf, String title,
3593 AlignmentView input, int w, int h, int x, int y)
3595 TreePanel tp = null;
3601 if (nf.getTree() != null)
3603 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3609 tp.setLocation(x, y);
3612 Desktop.addInternalFrame(tp, title, w, h);
3614 } catch (Exception ex)
3616 ex.printStackTrace();
3623 * Generates menu items and listener event actions for web service clients
3626 public void BuildWebServiceMenu()
3628 // TODO: add support for context dependent disabling of services based on
3629 // alignment and current selection
3630 // TODO: add additional serviceHandle parameter to specify abstract handler
3631 // class independently of AbstractName
3632 // TODO: add in rediscovery GUI function to restart discoverer
3633 // TODO: group services by location as well as function and/or introduce
3634 // object broker mechanism.
3635 if ((Discoverer.services != null) && (Discoverer.services.size() > 0))
3637 // TODO: refactor to allow list of AbstractName/Handler bindings to be
3638 // stored or retrieved from elsewhere
3639 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3640 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3641 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3642 // TODO: move GUI generation code onto service implementation - so a
3643 // client instance attaches itself to the GUI with method call like
3644 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
3646 Vector wsmenu = new Vector();
3647 final IProgressIndicator af = this;
3650 // Add any Multiple Sequence Alignment Services
3651 final JMenu msawsmenu = new JMenu("Alignment");
3652 for (int i = 0, j = msaws.size(); i < j; i++)
3654 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
3656 jalview.ws.WSClient impl = jalview.ws.Discoverer
3657 .getServiceClient(sh);
3658 impl.attachWSMenuEntry(msawsmenu, this);
3661 wsmenu.add(msawsmenu);
3663 if (secstrpr != null)
3665 // Add any secondary structure prediction services
3666 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3667 for (int i = 0, j = secstrpr.size(); i < j; i++)
3669 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
3671 jalview.ws.WSClient impl = jalview.ws.Discoverer
3672 .getServiceClient(sh);
3673 impl.attachWSMenuEntry(secstrmenu, this);
3675 wsmenu.add(secstrmenu);
3677 if (seqsrch != null)
3679 // Add any sequence search services
3680 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
3681 for (int i = 0, j = seqsrch.size(); i < j; i++)
3683 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
3685 jalview.ws.WSClient impl = jalview.ws.Discoverer
3686 .getServiceClient(sh);
3687 impl.attachWSMenuEntry(seqsrchmenu, this);
3689 // finally, add the whole shebang onto the webservices menu
3690 wsmenu.add(seqsrchmenu);
3692 resetWebServiceMenu();
3693 for (int i = 0, j = wsmenu.size(); i < j; i++)
3695 webService.add((JMenu) wsmenu.get(i));
3700 resetWebServiceMenu();
3701 this.webService.add(this.webServiceNoServices);
3706 * empty the web service menu and add any ad-hoc functions not dynamically
3710 private void resetWebServiceMenu()
3712 webService.removeAll();
3713 build_fetchdbmenu(webService);
3717 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
3718 * chooser = new JalviewFileChooser(jalview.bin.Cache.
3719 * getProperty("LAST_DIRECTORY"));
3721 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
3722 * to Vamsas file"); chooser.setToolTipText("Export");
3724 * int value = chooser.showSaveDialog(this);
3726 * if (value == JalviewFileChooser.APPROVE_OPTION) {
3727 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3728 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
3729 * chooser.getSelectedFile().getAbsolutePath(), this); } }
3732 * prototype of an automatically enabled/disabled analysis function
3735 protected void setShowProductsEnabled()
3737 SequenceI[] selection = viewport.getSequenceSelection();
3738 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
3739 viewport.getAlignment().getDataset()))
3741 showProducts.setEnabled(true);
3746 showProducts.setEnabled(false);
3751 * search selection for sequence xRef products and build the show products
3756 * @return true if showProducts menu should be enabled.
3758 public boolean canShowProducts(SequenceI[] selection,
3759 boolean isRegionSelection, Alignment dataset)
3761 boolean showp = false;
3764 showProducts.removeAll();
3765 final boolean dna = viewport.getAlignment().isNucleotide();
3766 final Alignment ds = dataset;
3767 String[] ptypes = CrossRef.findSequenceXrefTypes(dna, selection,
3770 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
3771 // selection, dataset, true);
3772 final SequenceI[] sel = selection;
3773 for (int t = 0; ptypes != null && t < ptypes.length; t++)
3776 final boolean isRegSel = isRegionSelection;
3777 final AlignFrame af = this;
3778 final String source = ptypes[t];
3779 JMenuItem xtype = new JMenuItem(ptypes[t]);
3780 xtype.addActionListener(new ActionListener()
3783 public void actionPerformed(ActionEvent e)
3785 // TODO: new thread for this call with vis-delay
3786 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
3787 isRegSel, dna, source);
3791 showProducts.add(xtype);
3793 showProducts.setVisible(showp);
3794 showProducts.setEnabled(showp);
3795 } catch (Exception e)
3797 jalview.bin.Cache.log
3799 "canTranslate threw an exception - please report to help@jalview.org",
3806 protected void showProductsFor(SequenceI[] sel, Alignment ds,
3807 boolean isRegSel, boolean dna, String source)
3809 final boolean fisRegSel = isRegSel;
3810 final boolean fdna = dna;
3811 final String fsrc = source;
3812 final AlignFrame ths = this;
3813 final SequenceI[] fsel = sel;
3814 Runnable foo = new Runnable()
3819 final long sttime = System.currentTimeMillis();
3820 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
3823 Alignment ds = ths.getViewport().alignment.getDataset(); // update
3827 Alignment prods = CrossRef
3828 .findXrefSequences(fsel, fdna, fsrc, ds);
3831 SequenceI[] sprods = new SequenceI[prods.getHeight()];
3832 for (int s = 0; s < sprods.length; s++)
3834 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
3835 if (ds.getSequences() == null
3836 || !ds.getSequences().contains(
3837 sprods[s].getDatasetSequence()))
3838 ds.addSequence(sprods[s].getDatasetSequence());
3839 sprods[s].updatePDBIds();
3841 Alignment al = new Alignment(sprods);
3842 AlignedCodonFrame[] cf = prods.getCodonFrames();
3844 for (int s = 0; cf != null && s < cf.length; s++)
3846 al.addCodonFrame(cf[s]);
3849 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
3851 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
3852 + " for " + ((fisRegSel) ? "selected region of " : "")
3854 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
3859 System.err.println("No Sequences generated for xRef type "
3862 } catch (Exception e)
3864 jalview.bin.Cache.log.error(
3865 "Exception when finding crossreferences", e);
3866 } catch (OutOfMemoryError e)
3868 new OOMWarning("whilst fetching crossreferences", e);
3871 jalview.bin.Cache.log.error("Error when finding crossreferences",
3874 ths.setProgressBar("Finished searching for sequences from " + fsrc,
3879 Thread frunner = new Thread(foo);
3883 public boolean canShowTranslationProducts(SequenceI[] selection,
3884 AlignmentI alignment)
3889 return (jalview.analysis.Dna.canTranslate(selection, viewport
3890 .getViewAsVisibleContigs(true)));
3891 } catch (Exception e)
3893 jalview.bin.Cache.log
3895 "canTranslate threw an exception - please report to help@jalview.org",
3901 public void showProducts_actionPerformed(ActionEvent e)
3903 // /////////////////////////////
3904 // Collect Data to be translated/transferred
3906 SequenceI[] selection = viewport.getSequenceSelection();
3907 AlignmentI al = null;
3910 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
3911 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
3912 viewport.getAlignment().getDataset());
3913 } catch (Exception ex)
3916 jalview.bin.Cache.log.debug("Exception during translation.", ex);
3923 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3924 "Translation Failed", JOptionPane.WARNING_MESSAGE);
3928 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3929 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
3930 DEFAULT_WIDTH, DEFAULT_HEIGHT);
3934 public void showTranslation_actionPerformed(ActionEvent e)
3936 // /////////////////////////////
3937 // Collect Data to be translated/transferred
3939 SequenceI[] selection = viewport.getSequenceSelection();
3940 String[] seqstring = viewport.getViewAsString(true);
3941 AlignmentI al = null;
3944 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
3945 viewport.getViewAsVisibleContigs(true), viewport
3946 .getGapCharacter(), viewport.alignment
3947 .getAlignmentAnnotation(), viewport.alignment
3948 .getWidth(), viewport.getAlignment().getDataset());
3949 } catch (Exception ex)
3952 jalview.bin.Cache.log.debug("Exception during translation.", ex);
3959 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3960 "Translation Failed", JOptionPane.WARNING_MESSAGE);
3964 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3965 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
3966 DEFAULT_WIDTH, DEFAULT_HEIGHT);
3971 * Try to load a features file onto the alignment.
3974 * contents or path to retrieve file
3976 * access mode of file (see jalview.io.AlignFile)
3977 * @return true if features file was parsed corectly.
3979 public boolean parseFeaturesFile(String file, String type)
3981 boolean featuresFile = false;
3984 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment
3985 .getDataset(), alignPanel.seqPanel.seqCanvas
3986 .getFeatureRenderer().featureColours, false);
3987 } catch (Exception ex)
3989 ex.printStackTrace();
3994 viewport.showSequenceFeatures = true;
3995 showSeqFeatures.setSelected(true);
3996 alignPanel.paintAlignment(true);
3999 return featuresFile;
4002 public void dragEnter(DropTargetDragEvent evt)
4006 public void dragExit(DropTargetEvent evt)
4010 public void dragOver(DropTargetDragEvent evt)
4014 public void dropActionChanged(DropTargetDragEvent evt)
4018 public void drop(DropTargetDropEvent evt)
4020 Transferable t = evt.getTransferable();
4021 java.util.List files = null;
4025 DataFlavor uriListFlavor = new DataFlavor(
4026 "text/uri-list;class=java.lang.String");
4027 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4029 // Works on Windows and MacOSX
4030 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4031 files = (java.util.List) t
4032 .getTransferData(DataFlavor.javaFileListFlavor);
4034 else if (t.isDataFlavorSupported(uriListFlavor))
4036 // This is used by Unix drag system
4037 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4038 String data = (String) t.getTransferData(uriListFlavor);
4039 files = new java.util.ArrayList(1);
4040 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4041 data, "\r\n"); st.hasMoreTokens();)
4043 String s = st.nextToken();
4044 if (s.startsWith("#"))
4046 // the line is a comment (as per the RFC 2483)
4050 java.net.URI uri = new java.net.URI(s);
4051 java.io.File file = new java.io.File(uri);
4055 } catch (Exception e)
4057 e.printStackTrace();
4064 for (int i = 0; i < files.size(); i++)
4066 loadJalviewDataFile(files.get(i).toString());
4068 } catch (Exception ex)
4070 ex.printStackTrace();
4076 * Attempt to load a "dropped" file: First by testing whether it's and
4077 * Annotation file, then a JNet file, and finally a features file. If all are
4078 * false then the user may have dropped an alignment file onto this
4082 * either a filename or a URL string.
4084 public void loadJalviewDataFile(String file)
4088 String protocol = "File";
4090 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
4095 boolean isAnnotation = new AnnotationFile().readAnnotationFile(
4096 viewport.alignment, file, protocol);
4100 // try to see if its a JNet 'concise' style annotation file *before* we
4101 // try to parse it as a features file
4102 String format = new IdentifyFile().Identify(file, protocol);
4103 if (format.equalsIgnoreCase("JnetFile"))
4105 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4107 new JnetAnnotationMaker().add_annotation(predictions, viewport
4108 .getAlignment(), 0, false);
4109 isAnnotation = true;
4113 // try to parse it as a features file
4114 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4115 // if it wasn't a features file then we just treat it as a general
4116 // alignment file to load into the current view.
4119 new FileLoader().LoadFile(viewport, file, protocol, format);
4123 alignPanel.paintAlignment(true);
4130 alignPanel.adjustAnnotationHeight();
4131 viewport.updateSequenceIdColours();
4132 buildSortByAnnotationScoresMenu();
4133 alignPanel.paintAlignment(true);
4135 } catch (Exception ex)
4137 ex.printStackTrace();
4141 public void tabSelectionChanged(int index)
4145 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4146 viewport = alignPanel.av;
4147 setMenusFromViewport(viewport);
4151 public void tabbedPane_mousePressed(MouseEvent e)
4153 if (SwingUtilities.isRightMouseButton(e))
4155 String reply = JOptionPane.showInternalInputDialog(this,
4156 "Enter View Name", "Edit View Name",
4157 JOptionPane.QUESTION_MESSAGE);
4161 viewport.viewName = reply;
4162 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4167 public AlignViewport getCurrentView()
4173 * Open the dialog for regex description parsing.
4175 protected void extractScores_actionPerformed(ActionEvent e)
4177 ParseProperties pp = new jalview.analysis.ParseProperties(
4178 viewport.alignment);
4179 // TODO: verify regex and introduce GUI dialog for version 2.5
4180 // if (pp.getScoresFromDescription("col", "score column ",
4181 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4183 if (pp.getScoresFromDescription("description column",
4184 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4186 buildSortByAnnotationScoresMenu();
4191 * @see jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent)
4193 protected void showDbRefs_actionPerformed(ActionEvent e)
4195 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4199 * @see jalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.ActionEvent)
4201 protected void showNpFeats_actionPerformed(ActionEvent e)
4203 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4207 * find the viewport amongst the tabs in this alignment frame and close that tab
4210 public boolean closeView(AlignViewport av)
4214 this.closeMenuItem_actionPerformed(false);
4217 Component[] comp = tabbedPane.getComponents();
4218 for (int i=0;comp!=null && i<comp.length;i++)
4220 if (comp[i] instanceof AlignmentPanel)
4222 if (((AlignmentPanel) comp[i]).av == av)
4225 closeView((AlignmentPanel) comp[i]);
4232 protected void build_fetchdbmenu(JMenu webService) {
4233 // Temporary hack - DBRef Fetcher always top level ws entry.
4234 // TODO We probably want to store a sequence database checklist in preferences and have checkboxes.. rather than individual sources selected here
4235 JMenu rfetch = new JMenu("Fetch DB References");
4237 .setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4238 webService.add(rfetch);
4240 JMenuItem fetchr = new JMenuItem("Standard Databases");
4241 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4242 fetchr.addActionListener(new ActionListener()
4245 public void actionPerformed(ActionEvent e)
4247 new Thread(new Runnable()
4252 new jalview.ws.DBRefFetcher(alignPanel.av
4253 .getSequenceSelection(), alignPanel.alignFrame)
4254 .fetchDBRefs(false);
4262 JMenu dfetch = new JMenu();
4264 jalview.ws.SequenceFetcher sf = SequenceFetcher.getSequenceFetcherSingleton(this);
4265 String[] otherdb = sf.getOrderedSupportedSources();
4266 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4267 // jalview.util.QuickSort.sort(otherdb, otherdb);
4268 int comp=0,mcomp=15;
4270 if (otherdb!=null && otherdb.length>0)
4272 for (int i=0; i<otherdb.length; i++)
4274 String dbname =sf.getSourceProxy(otherdb[i]).getDbName();
4277 mname = "from '"+dbname+"'";
4279 fetchr = new JMenuItem(otherdb[i]);
4280 final String[] dassource = new String[] { otherdb[i] };
4281 fetchr.addActionListener(new ActionListener()
4284 public void actionPerformed(ActionEvent e)
4286 new Thread(new Runnable()
4291 new jalview.ws.DBRefFetcher(alignPanel.av
4292 .getSequenceSelection(), alignPanel.alignFrame, dassource)
4293 .fetchDBRefs(false);
4299 fetchr.setToolTipText("Retrieve from "+dbname);
4301 if (comp++==mcomp || i==(otherdb.length-1))
4303 dfetch.setText(mname+" to '"+dbname+"'");
4305 dfetch = new JMenu();
4313 * Left justify the whole alignment.
4315 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4317 AlignmentI al = viewport.getAlignment();
4319 viewport.firePropertyChange("alignment", null, al);
4322 * Right justify the whole alignment.
4324 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4326 AlignmentI al = viewport.getAlignment();
4328 viewport.firePropertyChange("alignment", null, al);
4330 public void setShowSeqFeatures(boolean b)
4332 showSeqFeatures.setSelected(true);
4333 viewport.setShowSequenceFeatures(true);
4337 class PrintThread extends Thread
4341 public PrintThread(AlignmentPanel ap)
4346 static PageFormat pf;
4350 PrinterJob printJob = PrinterJob.getPrinterJob();
4354 printJob.setPrintable(ap, pf);
4358 printJob.setPrintable(ap);
4361 if (printJob.printDialog())
4366 } catch (Exception PrintException)
4368 PrintException.printStackTrace();