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;
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();
632 JPanel progressPanel;
633 GridLayout layout = (GridLayout) statusPanel.getLayout();
634 if (progressBars.get(new Long(id)) != null)
636 progressPanel = (JPanel) progressBars.get(new Long(id));
637 statusPanel.remove(progressPanel);
638 progressBars.remove(progressPanel);
639 progressPanel = null;
642 statusBar.setText(message);
645 layout.setRows(layout.getRows() - 1);
649 progressPanel = new JPanel(new BorderLayout(10, 5));
651 JProgressBar progressBar = new JProgressBar();
652 progressBar.setIndeterminate(true);
654 progressPanel.add(new JLabel(message), BorderLayout.WEST);
655 progressPanel.add(progressBar, BorderLayout.CENTER);
657 layout.setRows(layout.getRows() + 1);
658 statusPanel.add(progressPanel);
660 progressBars.put(new Long(id), progressPanel);
663 setMenusForViewport();
669 * @return true if any progress bars are still active
671 public boolean operationInProgress()
673 if (progressBars != null && progressBars.size() > 0)
681 * Added so Castor Mapping file can obtain Jalview Version
683 public String getVersion()
685 return jalview.bin.Cache.getProperty("VERSION");
688 public FeatureRenderer getFeatureRenderer()
690 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
693 public void fetchSequence_actionPerformed(ActionEvent e)
695 new SequenceFetcher(this);
698 public void addFromFile_actionPerformed(ActionEvent e)
700 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
703 public void reload_actionPerformed(ActionEvent e)
705 if (fileName != null)
707 if (currentFileFormat.equals("Jalview"))
709 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
710 for (int i = 0; i < frames.length; i++)
712 if (frames[i] instanceof AlignFrame && frames[i] != this
713 && ((AlignFrame) frames[i]).fileName.equals(fileName))
717 frames[i].setSelected(true);
718 Desktop.instance.closeAssociatedWindows();
719 } catch (java.beans.PropertyVetoException ex)
725 Desktop.instance.closeAssociatedWindows();
727 FileLoader loader = new FileLoader();
728 String protocol = fileName.startsWith("http:") ? "URL" : "File";
729 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
733 Rectangle bounds = this.getBounds();
735 FileLoader loader = new FileLoader();
736 String protocol = fileName.startsWith("http:") ? "URL" : "File";
737 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
738 protocol, currentFileFormat);
740 newframe.setBounds(bounds);
742 this.closeMenuItem_actionPerformed(true);
747 public void addFromText_actionPerformed(ActionEvent e)
749 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
752 public void addFromURL_actionPerformed(ActionEvent e)
754 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
757 public void save_actionPerformed(ActionEvent e)
760 || (currentFileFormat == null
761 || !jalview.io.FormatAdapter.isValidIOFormat(currentFileFormat, true))
762 || fileName.startsWith("http"))
764 saveAs_actionPerformed(null);
768 saveAlignment(fileName, currentFileFormat);
778 public void saveAs_actionPerformed(ActionEvent e)
780 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
781 .getProperty("LAST_DIRECTORY"),
782 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
783 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
784 currentFileFormat, false);
786 chooser.setFileView(new JalviewFileView());
787 chooser.setDialogTitle("Save Alignment to file");
788 chooser.setToolTipText("Save");
790 int value = chooser.showSaveDialog(this);
792 if (value == JalviewFileChooser.APPROVE_OPTION)
794 currentFileFormat = chooser.getSelectedFormat();
795 if (currentFileFormat == null)
797 JOptionPane.showInternalMessageDialog(Desktop.desktop,
798 "You must select a file format before saving!",
799 "File format not specified", JOptionPane.WARNING_MESSAGE);
800 value = chooser.showSaveDialog(this);
804 fileName = chooser.getSelectedFile().getPath();
806 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
809 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
810 if (currentFileFormat.indexOf(" ") > -1)
812 currentFileFormat = currentFileFormat.substring(0,
813 currentFileFormat.indexOf(" "));
815 saveAlignment(fileName, currentFileFormat);
819 public boolean saveAlignment(String file, String format)
821 boolean success = true;
823 if (format.equalsIgnoreCase("Jalview"))
825 String shortName = title;
827 if (shortName.indexOf(java.io.File.separatorChar) > -1)
829 shortName = shortName.substring(shortName
830 .lastIndexOf(java.io.File.separatorChar) + 1);
833 success = new Jalview2XML().SaveAlignment(this, file, shortName);
835 statusBar.setText("Successfully saved to file: " + fileName + " in "
836 + format + " format.");
841 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
843 // JBPNote need to have a raise_gui flag here
844 JOptionPane.showInternalMessageDialog(this, "Cannot save file "
845 + fileName + " using format " + format,
846 "Alignment output format not supported",
847 JOptionPane.WARNING_MESSAGE);
848 saveAs_actionPerformed(null);
852 String[] omitHidden = null;
854 if (viewport.hasHiddenColumns)
856 int reply = JOptionPane
857 .showInternalConfirmDialog(
859 "The Alignment contains hidden columns."
860 + "\nDo you want to save only the visible alignment?",
861 "Save / Omit Hidden Columns",
862 JOptionPane.YES_NO_OPTION,
863 JOptionPane.QUESTION_MESSAGE);
865 if (reply == JOptionPane.YES_OPTION)
867 omitHidden = viewport.getViewAsString(false);
870 FormatAdapter f = new FormatAdapter();
871 String output = f.formatSequences(format,
872 (Alignment) viewport.alignment, // class cast exceptions will
873 // occur in the distant future
874 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
884 java.io.PrintWriter out = new java.io.PrintWriter(
885 new java.io.FileWriter(file));
890 statusBar.setText("Successfully saved to file: " + fileName
891 + " in " + format + " format.");
892 } catch (Exception ex)
895 ex.printStackTrace();
902 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
903 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
915 protected void outputText_actionPerformed(ActionEvent e)
917 String[] omitHidden = null;
919 if (viewport.hasHiddenColumns)
921 int reply = JOptionPane
922 .showInternalConfirmDialog(
924 "The Alignment contains hidden columns."
925 + "\nDo you want to output only the visible alignment?",
926 "Save / Omit Hidden Columns",
927 JOptionPane.YES_NO_OPTION,
928 JOptionPane.QUESTION_MESSAGE);
930 if (reply == JOptionPane.YES_OPTION)
932 omitHidden = viewport.getViewAsString(false);
936 CutAndPasteTransfer cap = new CutAndPasteTransfer();
937 cap.setForInput(null);
938 Desktop.addInternalFrame(cap, "Alignment output - "
939 + e.getActionCommand(), 600, 500);
941 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
942 viewport.alignment, omitHidden, viewport.colSel));
951 protected void htmlMenuItem_actionPerformed(ActionEvent e)
953 new HTMLOutput(alignPanel, alignPanel.seqPanel.seqCanvas
954 .getSequenceRenderer(), alignPanel.seqPanel.seqCanvas
955 .getFeatureRenderer());
958 public void createImageMap(File file, String image)
960 alignPanel.makePNGImageMap(file, image);
969 public void createPNG(File f)
971 alignPanel.makePNG(f);
980 public void createEPS(File f)
982 alignPanel.makeEPS(f);
985 public void pageSetup_actionPerformed(ActionEvent e)
987 PrinterJob printJob = PrinterJob.getPrinterJob();
988 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
997 public void printMenuItem_actionPerformed(ActionEvent e)
999 // Putting in a thread avoids Swing painting problems
1000 PrintThread thread = new PrintThread(alignPanel);
1004 public void exportFeatures_actionPerformed(ActionEvent e)
1006 new AnnotationExporter().exportFeatures(alignPanel);
1009 public void exportAnnotations_actionPerformed(ActionEvent e)
1011 new AnnotationExporter().exportAnnotations(alignPanel,
1012 viewport.showAnnotation ? viewport.alignment
1013 .getAlignmentAnnotation() : null, viewport.alignment
1015 ((Alignment) viewport.alignment).alignmentProperties);
1018 public void associatedData_actionPerformed(ActionEvent e)
1020 // Pick the tree file
1021 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1022 .getProperty("LAST_DIRECTORY"));
1023 chooser.setFileView(new JalviewFileView());
1024 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1025 chooser.setToolTipText("Load Jalview Annotations / Features file");
1027 int value = chooser.showOpenDialog(null);
1029 if (value == JalviewFileChooser.APPROVE_OPTION)
1031 String choice = chooser.getSelectedFile().getPath();
1032 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1033 loadJalviewDataFile(choice);
1039 * Close the current view or all views in the alignment frame.
1040 * If the frame only contains one view then the alignment will be removed from memory.
1042 * @param closeAllTabs
1044 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1046 if (alignPanels != null && alignPanels.size() < 2)
1048 closeAllTabs = true;
1053 if (alignPanels != null)
1057 for (int i = 0; i < alignPanels.size(); i++)
1059 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1060 jalview.structure.StructureSelectionManager ssm =
1061 jalview.structure.StructureSelectionManager
1062 .getStructureSelectionManager();
1063 ssm.removeStructureViewerListener(ap.seqPanel, null);
1064 ssm.removeSelectionListener(ap.seqPanel);
1065 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
1066 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
1067 PaintRefresher.RemoveComponent(ap);
1068 ap.av.alignment = null;
1073 closeView(alignPanel);
1080 this.setClosed(true);
1082 } catch (Exception ex)
1084 ex.printStackTrace();
1088 public void closeView(AlignmentPanel alignPanel2)
1090 int index = tabbedPane.getSelectedIndex();
1091 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1092 alignPanels.removeElement(alignPanel2);
1093 PaintRefresher.RemoveComponent(alignPanel2.seqPanel.seqCanvas);
1094 PaintRefresher.RemoveComponent(alignPanel2.idPanel.idCanvas);
1095 PaintRefresher.RemoveComponent(alignPanel2);
1096 alignPanel2.av.alignment = null;
1098 if (viewport == alignPanel2.av)
1104 tabbedPane.removeTabAt(closedindex);
1105 tabbedPane.validate();
1107 if (index > closedindex || index == tabbedPane.getTabCount())
1109 // modify currently selected tab index if necessary.
1113 this.tabSelectionChanged(index);
1119 void updateEditMenuBar()
1122 if (viewport.historyList.size() > 0)
1124 undoMenuItem.setEnabled(true);
1125 CommandI command = (CommandI) viewport.historyList.peek();
1126 undoMenuItem.setText("Undo " + command.getDescription());
1130 undoMenuItem.setEnabled(false);
1131 undoMenuItem.setText("Undo");
1134 if (viewport.redoList.size() > 0)
1136 redoMenuItem.setEnabled(true);
1138 CommandI command = (CommandI) viewport.redoList.peek();
1139 redoMenuItem.setText("Redo " + command.getDescription());
1143 redoMenuItem.setEnabled(false);
1144 redoMenuItem.setText("Redo");
1148 public void addHistoryItem(CommandI command)
1150 if (command.getSize() > 0)
1152 viewport.historyList.push(command);
1153 viewport.redoList.clear();
1154 updateEditMenuBar();
1155 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1161 * @return alignment objects for all views
1163 AlignmentI[] getViewAlignments()
1165 if (alignPanels != null)
1167 Enumeration e = alignPanels.elements();
1168 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1169 for (int i = 0; e.hasMoreElements(); i++)
1171 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1175 if (viewport != null)
1177 return new AlignmentI[]
1178 { viewport.alignment };
1189 protected void undoMenuItem_actionPerformed(ActionEvent e)
1191 if (viewport.historyList.empty())
1193 CommandI command = (CommandI) viewport.historyList.pop();
1194 viewport.redoList.push(command);
1195 command.undoCommand(getViewAlignments());
1197 AlignViewport originalSource = getOriginatingSource(command);
1198 updateEditMenuBar();
1200 if (originalSource != null)
1202 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1203 originalSource.firePropertyChange("alignment", null,
1204 originalSource.alignment.getSequences());
1214 protected void redoMenuItem_actionPerformed(ActionEvent e)
1216 if (viewport.redoList.size() < 1)
1221 CommandI command = (CommandI) viewport.redoList.pop();
1222 viewport.historyList.push(command);
1223 command.doCommand(getViewAlignments());
1225 AlignViewport originalSource = getOriginatingSource(command);
1226 updateEditMenuBar();
1228 if (originalSource != null)
1230 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1231 originalSource.firePropertyChange("alignment", null,
1232 originalSource.alignment.getSequences());
1236 AlignViewport getOriginatingSource(CommandI command)
1238 AlignViewport originalSource = null;
1239 // For sequence removal and addition, we need to fire
1240 // the property change event FROM the viewport where the
1241 // original alignment was altered
1242 AlignmentI al = null;
1243 if (command instanceof EditCommand)
1245 EditCommand editCommand = (EditCommand) command;
1246 al = editCommand.getAlignment();
1247 Vector comps = (Vector) PaintRefresher.components.get(viewport
1248 .getSequenceSetId());
1250 for (int i = 0; i < comps.size(); i++)
1252 if (comps.elementAt(i) instanceof AlignmentPanel)
1254 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1256 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1263 if (originalSource == null)
1265 // The original view is closed, we must validate
1266 // the current view against the closed view first
1269 PaintRefresher.validateSequences(al, viewport.alignment);
1272 originalSource = viewport;
1275 return originalSource;
1284 public void moveSelectedSequences(boolean up)
1286 SequenceGroup sg = viewport.getSelectionGroup();
1295 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1297 SequenceI seq = viewport.alignment.getSequenceAt(i);
1299 if (!sg.getSequences(null).contains(seq))
1304 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1306 if (sg.getSequences(null).contains(temp))
1311 viewport.alignment.getSequences().setElementAt(temp, i);
1312 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1317 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1319 SequenceI seq = viewport.alignment.getSequenceAt(i);
1321 if (!sg.getSequences(null).contains(seq))
1326 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1328 if (sg.getSequences(null).contains(temp))
1333 viewport.alignment.getSequences().setElementAt(temp, i);
1334 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1338 alignPanel.paintAlignment(true);
1341 synchronized void slideSequences(boolean right, int size)
1343 Vector sg = new Vector();
1344 if (viewport.cursorMode)
1346 sg.addElement(viewport.alignment
1347 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1349 else if (viewport.getSelectionGroup() != null
1350 && viewport.getSelectionGroup().getSize() != viewport.alignment
1353 sg = viewport.getSelectionGroup().getSequences(
1354 viewport.hiddenRepSequences);
1362 Vector invertGroup = new Vector();
1364 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1366 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1367 invertGroup.add(viewport.alignment.getSequenceAt(i));
1370 SequenceI[] seqs1 = new SequenceI[sg.size()];
1371 for (int i = 0; i < sg.size(); i++)
1372 seqs1[i] = (SequenceI) sg.elementAt(i);
1374 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1375 for (int i = 0; i < invertGroup.size(); i++)
1376 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1378 SlideSequencesCommand ssc;
1380 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1381 size, viewport.getGapCharacter());
1383 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1384 size, viewport.getGapCharacter());
1386 int groupAdjustment = 0;
1387 if (ssc.getGapsInsertedBegin() && right)
1389 if (viewport.cursorMode)
1390 alignPanel.seqPanel.moveCursor(size, 0);
1392 groupAdjustment = size;
1394 else if (!ssc.getGapsInsertedBegin() && !right)
1396 if (viewport.cursorMode)
1397 alignPanel.seqPanel.moveCursor(-size, 0);
1399 groupAdjustment = -size;
1402 if (groupAdjustment != 0)
1404 viewport.getSelectionGroup().setStartRes(
1405 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1406 viewport.getSelectionGroup().setEndRes(
1407 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1410 boolean appendHistoryItem = false;
1411 if (viewport.historyList != null && viewport.historyList.size() > 0
1412 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1414 appendHistoryItem = ssc
1415 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1419 if (!appendHistoryItem)
1420 addHistoryItem(ssc);
1431 protected void copy_actionPerformed(ActionEvent e)
1434 if (viewport.getSelectionGroup() == null)
1438 // TODO: preserve the ordering of displayed alignment annotation in any
1439 // internal paste (particularly sequence associated annotation)
1440 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1441 String[] omitHidden = null;
1443 if (viewport.hasHiddenColumns)
1445 omitHidden = viewport.getViewAsString(true);
1448 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1451 StringSelection ss = new StringSelection(output);
1455 jalview.gui.Desktop.internalCopy = true;
1456 // Its really worth setting the clipboard contents
1457 // to empty before setting the large StringSelection!!
1458 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
1459 new StringSelection(""), null);
1461 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
1463 } catch (OutOfMemoryError er)
1465 new OOMWarning("copying region", er);
1469 Vector hiddenColumns = null;
1470 if (viewport.hasHiddenColumns)
1472 hiddenColumns = new Vector();
1473 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1474 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1477 int[] region = (int[]) viewport.getColumnSelection()
1478 .getHiddenColumns().elementAt(i);
1480 hiddenColumns.addElement(new int[]
1481 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1485 Desktop.jalviewClipboard = new Object[]
1486 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1487 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1496 protected void pasteNew_actionPerformed(ActionEvent e)
1507 protected void pasteThis_actionPerformed(ActionEvent e)
1513 * Paste contents of Jalview clipboard
1515 * @param newAlignment
1516 * true to paste to a new alignment, otherwise add to this.
1518 void paste(boolean newAlignment)
1520 boolean externalPaste = true;
1523 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1524 Transferable contents = c.getContents(this);
1526 if (contents == null)
1534 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1535 if (str.length() < 1)
1540 format = new IdentifyFile().Identify(str, "Paste");
1542 } catch (OutOfMemoryError er)
1544 new OOMWarning("Out of memory pasting sequences!!", er);
1548 SequenceI[] sequences;
1549 boolean annotationAdded = false;
1550 AlignmentI alignment = null;
1552 if (Desktop.jalviewClipboard != null)
1554 // The clipboard was filled from within Jalview, we must use the
1556 // And dataset from the copied alignment
1557 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1558 // be doubly sure that we create *new* sequence objects.
1559 sequences = new SequenceI[newseq.length];
1560 for (int i = 0; i < newseq.length; i++)
1562 sequences[i] = new Sequence(newseq[i]);
1564 alignment = new Alignment(sequences);
1565 externalPaste = false;
1569 // parse the clipboard as an alignment.
1570 alignment = new FormatAdapter().readFile(str, "Paste", format);
1571 sequences = alignment.getSequencesArray();
1579 if (Desktop.jalviewClipboard != null)
1581 // dataset is inherited
1582 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1586 // new dataset is constructed
1587 alignment.setDataset(null);
1589 alwidth = alignment.getWidth() + 1;
1593 AlignmentI pastedal = alignment; // preserve pasted alignment object
1594 // Add pasted sequences and dataset into existing alignment.
1595 alignment = viewport.getAlignment();
1596 alwidth = alignment.getWidth() + 1;
1597 // decide if we need to import sequences from an existing dataset
1598 boolean importDs = Desktop.jalviewClipboard != null
1599 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1600 // importDs==true instructs us to copy over new dataset sequences from
1601 // an existing alignment
1602 Vector newDs = (importDs) ? new Vector() : null; // used to create
1603 // minimum dataset set
1605 for (int i = 0; i < sequences.length; i++)
1609 newDs.addElement(null);
1611 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1613 if (importDs && ds != null)
1615 if (!newDs.contains(ds))
1617 newDs.setElementAt(ds, i);
1618 ds = new Sequence(ds);
1619 // update with new dataset sequence
1620 sequences[i].setDatasetSequence(ds);
1624 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1629 // copy and derive new dataset sequence
1630 sequences[i] = sequences[i].deriveSequence();
1631 alignment.getDataset().addSequence(
1632 sequences[i].getDatasetSequence());
1633 // TODO: avoid creation of duplicate dataset sequences with a
1634 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1636 alignment.addSequence(sequences[i]); // merges dataset
1640 newDs.clear(); // tidy up
1642 if (pastedal.getAlignmentAnnotation() != null)
1644 // Add any annotation attached to alignment.
1645 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1646 for (int i = 0; i < alann.length; i++)
1648 annotationAdded = true;
1649 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1651 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1652 newann.padAnnotation(alwidth);
1653 alignment.addAnnotation(newann);
1663 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1664 sequences, 0, alignment.getWidth(), alignment));
1666 // Add any annotations attached to sequences
1667 for (int i = 0; i < sequences.length; i++)
1669 if (sequences[i].getAnnotation() != null)
1671 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1673 annotationAdded = true;
1674 sequences[i].getAnnotation()[a].adjustForAlignment();
1675 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1676 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1681 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1688 // propagate alignment changed.
1689 viewport.setEndSeq(alignment.getHeight());
1690 if (annotationAdded)
1692 // Duplicate sequence annotation in all views.
1693 AlignmentI[] alview = this.getViewAlignments();
1694 for (int i = 0; i < sequences.length; i++)
1696 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1699 for (int avnum = 0; avnum < alview.length; avnum++)
1701 if (alview[avnum] != alignment)
1703 // duplicate in a view other than the one with input focus
1704 int avwidth = alview[avnum].getWidth() + 1;
1705 // this relies on sann being preserved after we
1706 // modify the sequence's annotation array for each duplication
1707 for (int a = 0; a < sann.length; a++)
1709 AlignmentAnnotation newann = new AlignmentAnnotation(
1711 sequences[i].addAlignmentAnnotation(newann);
1712 newann.padAnnotation(avwidth);
1713 alview[avnum].addAnnotation(newann); // annotation was
1714 // duplicated earlier
1715 alview[avnum].setAnnotationIndex(newann, a);
1720 buildSortByAnnotationScoresMenu();
1722 viewport.firePropertyChange("alignment", null, alignment
1728 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1730 String newtitle = new String("Copied sequences");
1732 if (Desktop.jalviewClipboard != null
1733 && Desktop.jalviewClipboard[2] != null)
1735 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1736 for (int i = 0; i < hc.size(); i++)
1738 int[] region = (int[]) hc.elementAt(i);
1739 af.viewport.hideColumns(region[0], region[1]);
1743 // >>>This is a fix for the moment, until a better solution is
1745 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1747 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1749 // TODO: maintain provenance of an alignment, rather than just make the
1750 // title a concatenation of operations.
1753 if (title.startsWith("Copied sequences"))
1759 newtitle = newtitle.concat("- from " + title);
1764 newtitle = new String("Pasted sequences");
1767 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1772 } catch (Exception ex)
1774 ex.printStackTrace();
1775 System.out.println("Exception whilst pasting: " + ex);
1776 // could be anything being pasted in here
1787 protected void cut_actionPerformed(ActionEvent e)
1789 copy_actionPerformed(null);
1790 delete_actionPerformed(null);
1799 protected void delete_actionPerformed(ActionEvent evt)
1802 SequenceGroup sg = viewport.getSelectionGroup();
1808 Vector seqs = new Vector();
1810 for (int i = 0; i < sg.getSize(); i++)
1812 seq = sg.getSequenceAt(i);
1813 seqs.addElement(seq);
1816 // If the cut affects all sequences, remove highlighted columns
1817 if (sg.getSize() == viewport.alignment.getHeight())
1819 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1820 sg.getEndRes() + 1);
1823 SequenceI[] cut = new SequenceI[seqs.size()];
1824 for (int i = 0; i < seqs.size(); i++)
1826 cut[i] = (SequenceI) seqs.elementAt(i);
1830 * //ADD HISTORY ITEM
1832 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
1833 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
1834 viewport.alignment));
1836 viewport.setSelectionGroup(null);
1837 viewport.sendSelection();
1838 viewport.alignment.deleteGroup(sg);
1840 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
1842 if (viewport.getAlignment().getHeight() < 1)
1846 this.setClosed(true);
1847 } catch (Exception ex)
1859 protected void deleteGroups_actionPerformed(ActionEvent e)
1861 viewport.alignment.deleteAllGroups();
1862 viewport.sequenceColours = null;
1863 viewport.setSelectionGroup(null);
1864 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1865 alignPanel.paintAlignment(true);
1874 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1876 SequenceGroup sg = new SequenceGroup();
1878 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1880 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1883 sg.setEndRes(viewport.alignment.getWidth() - 1);
1884 viewport.setSelectionGroup(sg);
1885 viewport.sendSelection();
1886 alignPanel.paintAlignment(true);
1887 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1896 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1898 if (viewport.cursorMode)
1900 alignPanel.seqPanel.keyboardNo1 = null;
1901 alignPanel.seqPanel.keyboardNo2 = null;
1903 viewport.setSelectionGroup(null);
1904 viewport.getColumnSelection().clear();
1905 viewport.setSelectionGroup(null);
1906 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1907 alignPanel.idPanel.idCanvas.searchResults = null;
1908 alignPanel.paintAlignment(true);
1909 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1918 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1920 SequenceGroup sg = viewport.getSelectionGroup();
1924 selectAllSequenceMenuItem_actionPerformed(null);
1929 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1931 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1934 alignPanel.paintAlignment(true);
1935 viewport.sendSelection();
1936 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1939 public void invertColSel_actionPerformed(ActionEvent e)
1941 viewport.invertColumnSelection();
1942 alignPanel.paintAlignment(true);
1951 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1953 trimAlignment(true);
1962 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1964 trimAlignment(false);
1967 void trimAlignment(boolean trimLeft)
1969 ColumnSelection colSel = viewport.getColumnSelection();
1972 if (colSel.size() > 0)
1976 column = colSel.getMin();
1980 column = colSel.getMax();
1984 if (viewport.getSelectionGroup() != null)
1986 seqs = viewport.getSelectionGroup().getSequencesAsArray(
1987 viewport.hiddenRepSequences);
1991 seqs = viewport.alignment.getSequencesArray();
1994 TrimRegionCommand trimRegion;
1997 trimRegion = new TrimRegionCommand("Remove Left",
1998 TrimRegionCommand.TRIM_LEFT, seqs, column,
1999 viewport.alignment, viewport.colSel,
2000 viewport.selectionGroup);
2001 viewport.setStartRes(0);
2005 trimRegion = new TrimRegionCommand("Remove Right",
2006 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2007 viewport.alignment, viewport.colSel,
2008 viewport.selectionGroup);
2011 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2013 addHistoryItem(trimRegion);
2015 Vector groups = viewport.alignment.getGroups();
2017 for (int i = 0; i < groups.size(); i++)
2019 SequenceGroup sg = (SequenceGroup) groups.get(i);
2021 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2022 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2024 viewport.alignment.deleteGroup(sg);
2028 viewport.firePropertyChange("alignment", null, viewport
2029 .getAlignment().getSequences());
2039 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2041 int start = 0, end = viewport.alignment.getWidth() - 1;
2044 if (viewport.getSelectionGroup() != null)
2046 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2047 viewport.hiddenRepSequences);
2048 start = viewport.getSelectionGroup().getStartRes();
2049 end = viewport.getSelectionGroup().getEndRes();
2053 seqs = viewport.alignment.getSequencesArray();
2056 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2057 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2059 addHistoryItem(removeGapCols);
2061 statusBar.setText("Removed " + removeGapCols.getSize()
2062 + " empty columns.");
2064 // This is to maintain viewport position on first residue
2065 // of first sequence
2066 SequenceI seq = viewport.alignment.getSequenceAt(0);
2067 int startRes = seq.findPosition(viewport.startRes);
2068 // ShiftList shifts;
2069 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2070 // edit.alColumnChanges=shifts.getInverse();
2071 // if (viewport.hasHiddenColumns)
2072 // viewport.getColumnSelection().compensateForEdits(shifts);
2073 viewport.setStartRes(seq.findIndex(startRes) - 1);
2074 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2085 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2087 int start = 0, end = viewport.alignment.getWidth() - 1;
2090 if (viewport.getSelectionGroup() != null)
2092 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2093 viewport.hiddenRepSequences);
2094 start = viewport.getSelectionGroup().getStartRes();
2095 end = viewport.getSelectionGroup().getEndRes();
2099 seqs = viewport.alignment.getSequencesArray();
2102 // This is to maintain viewport position on first residue
2103 // of first sequence
2104 SequenceI seq = viewport.alignment.getSequenceAt(0);
2105 int startRes = seq.findPosition(viewport.startRes);
2107 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2108 viewport.alignment));
2110 viewport.setStartRes(seq.findIndex(startRes) - 1);
2112 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2123 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2125 viewport.padGaps = padGapsMenuitem.isSelected();
2127 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2137 public void findMenuItem_actionPerformed(ActionEvent e)
2142 public void newView_actionPerformed(ActionEvent e)
2144 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2147 newap.av.gatherViewsHere = false;
2149 if (viewport.viewName == null)
2151 viewport.viewName = "Original";
2154 newap.av.historyList = viewport.historyList;
2155 newap.av.redoList = viewport.redoList;
2157 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2158 String newViewName = "View " + index;
2160 Vector comps = (Vector) PaintRefresher.components.get(viewport
2161 .getSequenceSetId());
2162 Vector existingNames = new Vector();
2163 for (int i = 0; i < comps.size(); i++)
2165 if (comps.elementAt(i) instanceof AlignmentPanel)
2167 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2168 if (!existingNames.contains(ap.av.viewName))
2170 existingNames.addElement(ap.av.viewName);
2175 while (existingNames.contains(newViewName))
2177 newViewName = "View " + (++index);
2180 newap.av.viewName = newViewName;
2182 addAlignmentPanel(newap, true);
2184 if (alignPanels.size() == 2)
2186 viewport.gatherViewsHere = true;
2188 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2191 public void expandViews_actionPerformed(ActionEvent e)
2193 Desktop.instance.explodeViews(this);
2196 public void gatherViews_actionPerformed(ActionEvent e)
2198 Desktop.instance.gatherViews(this);
2207 public void font_actionPerformed(ActionEvent e)
2209 new FontChooser(alignPanel);
2218 protected void seqLimit_actionPerformed(ActionEvent e)
2220 viewport.setShowJVSuffix(seqLimits.isSelected());
2222 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2223 .calculateIdWidth());
2224 alignPanel.paintAlignment(true);
2227 public void idRightAlign_actionPerformed(ActionEvent e)
2229 viewport.rightAlignIds = idRightAlign.isSelected();
2230 alignPanel.paintAlignment(true);
2233 public void centreColumnLabels_actionPerformed(ActionEvent e)
2235 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2236 alignPanel.paintAlignment(true);
2239 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2241 protected void followHighlight_actionPerformed()
2243 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2245 alignPanel.scrollToPosition(alignPanel.seqPanel.seqCanvas.searchResults, false);
2255 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2257 viewport.setColourText(colourTextMenuItem.isSelected());
2258 alignPanel.paintAlignment(true);
2267 public void wrapMenuItem_actionPerformed(ActionEvent e)
2269 scaleAbove.setVisible(wrapMenuItem.isSelected());
2270 scaleLeft.setVisible(wrapMenuItem.isSelected());
2271 scaleRight.setVisible(wrapMenuItem.isSelected());
2272 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2273 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2276 public void showAllSeqs_actionPerformed(ActionEvent e)
2278 viewport.showAllHiddenSeqs();
2281 public void showAllColumns_actionPerformed(ActionEvent e)
2283 viewport.showAllHiddenColumns();
2287 public void hideSelSequences_actionPerformed(ActionEvent e)
2289 viewport.hideAllSelectedSeqs();
2290 alignPanel.paintAlignment(true);
2293 public void hideSelColumns_actionPerformed(ActionEvent e)
2295 viewport.hideSelectedColumns();
2296 alignPanel.paintAlignment(true);
2299 public void hiddenMarkers_actionPerformed(ActionEvent e)
2301 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2311 protected void scaleAbove_actionPerformed(ActionEvent e)
2313 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2314 alignPanel.paintAlignment(true);
2323 protected void scaleLeft_actionPerformed(ActionEvent e)
2325 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2326 alignPanel.paintAlignment(true);
2335 protected void scaleRight_actionPerformed(ActionEvent e)
2337 viewport.setScaleRightWrapped(scaleRight.isSelected());
2338 alignPanel.paintAlignment(true);
2347 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2349 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2350 alignPanel.paintAlignment(true);
2359 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2361 viewport.setShowText(viewTextMenuItem.isSelected());
2362 alignPanel.paintAlignment(true);
2371 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2373 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2374 alignPanel.paintAlignment(true);
2377 public FeatureSettings featureSettings;
2379 public void featureSettings_actionPerformed(ActionEvent e)
2381 if (featureSettings != null)
2383 featureSettings.close();
2384 featureSettings = null;
2386 featureSettings = new FeatureSettings(this);
2395 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2397 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2398 alignPanel.paintAlignment(true);
2399 if (alignPanel.getOverviewPanel() != null)
2401 alignPanel.getOverviewPanel().updateOverviewImage();
2411 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2413 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2414 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2417 public void alignmentProperties()
2419 JEditorPane editPane = new JEditorPane("text/html", "");
2420 editPane.setEditable(false);
2421 StringBuffer contents = new StringBuffer("<html>");
2424 int min = Integer.MAX_VALUE, max = 0;
2425 for (int i = 0; i < viewport.alignment.getHeight(); i++)
2427 int size = viewport.alignment.getSequenceAt(i).getEnd()
2428 - viewport.alignment.getSequenceAt(i).getStart();
2435 avg = avg / (float) viewport.alignment.getHeight();
2437 contents.append("<br>Sequences: " + viewport.alignment.getHeight());
2438 contents.append("<br>Minimum Sequence Length: " + min);
2439 contents.append("<br>Maximum Sequence Length: " + max);
2440 contents.append("<br>Average Length: " + (int) avg);
2442 if (((Alignment) viewport.alignment).getProperties() != null)
2444 Hashtable props = ((Alignment) viewport.alignment).getProperties();
2445 Enumeration en = props.keys();
2446 contents.append("<br><br><table border=\"1\">");
2447 while (en.hasMoreElements())
2449 String key = en.nextElement().toString();
2450 StringBuffer val = new StringBuffer();
2451 String vals = props.get(key).toString();
2455 npos = vals.indexOf("\n", pos);
2458 val.append(vals.substring(pos));
2462 val.append(vals.substring(pos, npos));
2466 } while (npos != -1);
2468 .append("<tr><td>" + key + "</td><td>" + val + "</td></tr>");
2470 contents.append("</table>");
2472 editPane.setText(contents.toString() + "</html>");
2473 JInternalFrame frame = new JInternalFrame();
2474 frame.getContentPane().add(new JScrollPane(editPane));
2476 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2477 + getTitle(), 500, 400);
2486 public void overviewMenuItem_actionPerformed(ActionEvent e)
2488 if (alignPanel.overviewPanel != null)
2493 JInternalFrame frame = new JInternalFrame();
2494 OverviewPanel overview = new OverviewPanel(alignPanel);
2495 frame.setContentPane(overview);
2496 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(), frame
2497 .getWidth(), frame.getHeight());
2499 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2501 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2503 public void internalFrameClosed(
2504 javax.swing.event.InternalFrameEvent evt)
2506 alignPanel.setOverviewPanel(null);
2510 alignPanel.setOverviewPanel(overview);
2513 public void textColour_actionPerformed(ActionEvent e)
2515 new TextColourChooser().chooseColour(alignPanel, null);
2524 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2535 public void clustalColour_actionPerformed(ActionEvent e)
2537 changeColour(new ClustalxColourScheme(
2538 viewport.alignment.getSequences(), viewport.alignment
2548 public void zappoColour_actionPerformed(ActionEvent e)
2550 changeColour(new ZappoColourScheme());
2559 public void taylorColour_actionPerformed(ActionEvent e)
2561 changeColour(new TaylorColourScheme());
2570 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2572 changeColour(new HydrophobicColourScheme());
2581 public void helixColour_actionPerformed(ActionEvent e)
2583 changeColour(new HelixColourScheme());
2592 public void strandColour_actionPerformed(ActionEvent e)
2594 changeColour(new StrandColourScheme());
2603 public void turnColour_actionPerformed(ActionEvent e)
2605 changeColour(new TurnColourScheme());
2614 public void buriedColour_actionPerformed(ActionEvent e)
2616 changeColour(new BuriedColourScheme());
2625 public void nucleotideColour_actionPerformed(ActionEvent e)
2627 changeColour(new NucleotideColourScheme());
2630 public void annotationColour_actionPerformed(ActionEvent e)
2632 new AnnotationColourChooser(viewport, alignPanel);
2641 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2643 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2652 public void changeColour(ColourSchemeI cs)
2658 if (viewport.getAbovePIDThreshold())
2660 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2663 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2665 viewport.setGlobalColourScheme(cs);
2669 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2672 if (viewport.getConservationSelected())
2675 Alignment al = (Alignment) viewport.alignment;
2676 Conservation c = new Conservation("All",
2677 ResidueProperties.propHash, 3, al.getSequences(), 0, al
2681 c.verdict(false, viewport.ConsPercGaps);
2683 cs.setConservation(c);
2685 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
2690 cs.setConservation(null);
2693 cs.setConsensus(viewport.hconsensus);
2696 viewport.setGlobalColourScheme(cs);
2698 if (viewport.getColourAppliesToAllGroups())
2700 Vector groups = viewport.alignment.getGroups();
2702 for (int i = 0; i < groups.size(); i++)
2704 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2712 if (cs instanceof ClustalxColourScheme)
2714 sg.cs = new ClustalxColourScheme(sg
2715 .getSequences(viewport.hiddenRepSequences), sg.getWidth());
2717 else if (cs instanceof UserColourScheme)
2719 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
2725 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2726 } catch (Exception ex)
2731 if (viewport.getAbovePIDThreshold()
2732 || cs instanceof PIDColourScheme
2733 || cs instanceof Blosum62ColourScheme)
2735 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2737 sg.cs.setConsensus(AAFrequency.calculate(sg
2738 .getSequences(viewport.hiddenRepSequences), sg
2739 .getStartRes(), sg.getEndRes() + 1));
2743 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2746 if (viewport.getConservationSelected())
2748 Conservation c = new Conservation("Group",
2749 ResidueProperties.propHash, 3, sg
2750 .getSequences(viewport.hiddenRepSequences), sg
2751 .getStartRes(), sg.getEndRes() + 1);
2753 c.verdict(false, viewport.ConsPercGaps);
2754 sg.cs.setConservation(c);
2758 sg.cs.setConservation(null);
2763 if (alignPanel.getOverviewPanel() != null)
2765 alignPanel.getOverviewPanel().updateOverviewImage();
2768 alignPanel.paintAlignment(true);
2777 protected void modifyPID_actionPerformed(ActionEvent e)
2779 if (viewport.getAbovePIDThreshold()
2780 && viewport.globalColourScheme != null)
2782 SliderPanel.setPIDSliderSource(alignPanel, viewport
2783 .getGlobalColourScheme(), "Background");
2784 SliderPanel.showPIDSlider();
2794 protected void modifyConservation_actionPerformed(ActionEvent e)
2796 if (viewport.getConservationSelected()
2797 && viewport.globalColourScheme != null)
2799 SliderPanel.setConservationSlider(alignPanel,
2800 viewport.globalColourScheme, "Background");
2801 SliderPanel.showConservationSlider();
2811 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2813 viewport.setConservationSelected(conservationMenuItem.isSelected());
2815 viewport.setAbovePIDThreshold(false);
2816 abovePIDThreshold.setSelected(false);
2818 changeColour(viewport.getGlobalColourScheme());
2820 modifyConservation_actionPerformed(null);
2829 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2831 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2833 conservationMenuItem.setSelected(false);
2834 viewport.setConservationSelected(false);
2836 changeColour(viewport.getGlobalColourScheme());
2838 modifyPID_actionPerformed(null);
2847 public void userDefinedColour_actionPerformed(ActionEvent e)
2849 if (e.getActionCommand().equals("User Defined..."))
2851 new UserDefinedColours(alignPanel, null);
2855 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2856 .getUserColourSchemes().get(e.getActionCommand());
2862 public void updateUserColourMenu()
2865 Component[] menuItems = colourMenu.getMenuComponents();
2866 int i, iSize = menuItems.length;
2867 for (i = 0; i < iSize; i++)
2869 if (menuItems[i].getName() != null
2870 && menuItems[i].getName().equals("USER_DEFINED"))
2872 colourMenu.remove(menuItems[i]);
2876 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2878 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
2879 .getUserColourSchemes().keys();
2881 while (userColours.hasMoreElements())
2883 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2884 userColours.nextElement().toString());
2885 radioItem.setName("USER_DEFINED");
2886 radioItem.addMouseListener(new MouseAdapter()
2888 public void mousePressed(MouseEvent evt)
2890 if (evt.isControlDown()
2891 || SwingUtilities.isRightMouseButton(evt))
2894 .removeActionListener(radioItem.getActionListeners()[0]);
2896 int option = JOptionPane.showInternalConfirmDialog(
2897 jalview.gui.Desktop.desktop,
2898 "Remove from default list?",
2899 "Remove user defined colour",
2900 JOptionPane.YES_NO_OPTION);
2901 if (option == JOptionPane.YES_OPTION)
2903 jalview.gui.UserDefinedColours
2904 .removeColourFromDefaults(radioItem.getText());
2905 colourMenu.remove(radioItem);
2909 radioItem.addActionListener(new ActionListener()
2911 public void actionPerformed(ActionEvent evt)
2913 userDefinedColour_actionPerformed(evt);
2920 radioItem.addActionListener(new ActionListener()
2922 public void actionPerformed(ActionEvent evt)
2924 userDefinedColour_actionPerformed(evt);
2928 colourMenu.insert(radioItem, 15);
2929 colours.add(radioItem);
2940 public void PIDColour_actionPerformed(ActionEvent e)
2942 changeColour(new PIDColourScheme());
2951 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2953 changeColour(new Blosum62ColourScheme());
2962 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2964 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2965 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
2966 .getAlignment().getSequenceAt(0), null);
2967 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2968 viewport.alignment));
2969 alignPanel.paintAlignment(true);
2978 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2980 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2981 AlignmentSorter.sortByID(viewport.getAlignment());
2982 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2983 alignPanel.paintAlignment(true);
2992 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2994 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2995 AlignmentSorter.sortByGroup(viewport.getAlignment());
2996 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2997 viewport.alignment));
2999 alignPanel.paintAlignment(true);
3008 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3010 new RedundancyPanel(alignPanel, this);
3019 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3021 if ((viewport.getSelectionGroup() == null)
3022 || (viewport.getSelectionGroup().getSize() < 2))
3024 JOptionPane.showInternalMessageDialog(this,
3025 "You must select at least 2 sequences.", "Invalid Selection",
3026 JOptionPane.WARNING_MESSAGE);
3030 JInternalFrame frame = new JInternalFrame();
3031 frame.setContentPane(new PairwiseAlignPanel(viewport));
3032 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3042 public void PCAMenuItem_actionPerformed(ActionEvent e)
3044 if (((viewport.getSelectionGroup() != null)
3045 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3046 .getSelectionGroup().getSize() > 0))
3047 || (viewport.getAlignment().getHeight() < 4))
3049 JOptionPane.showInternalMessageDialog(this,
3050 "Principal component analysis must take\n"
3051 + "at least 4 input sequences.",
3052 "Sequence selection insufficient",
3053 JOptionPane.WARNING_MESSAGE);
3058 new PCAPanel(alignPanel);
3061 public void autoCalculate_actionPerformed(ActionEvent e)
3063 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3064 if (viewport.autoCalculateConsensus)
3066 viewport.firePropertyChange("alignment", null, viewport
3067 .getAlignment().getSequences());
3077 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3079 NewTreePanel("AV", "PID", "Average distance tree using PID");
3088 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3090 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3099 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3101 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3110 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3112 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3125 void NewTreePanel(String type, String pwType, String title)
3129 if (viewport.getSelectionGroup() != null)
3131 if (viewport.getSelectionGroup().getSize() < 3)
3136 "You need to have more than two sequences selected to build a tree!",
3137 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3142 SequenceGroup sg = viewport.getSelectionGroup();
3144 /* Decide if the selection is a column region */
3145 while (s < sg.getSize())
3147 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3153 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3154 + "Try using the Pad function in the edit menu,\n"
3155 + "or one of the multiple sequence alignment web services.",
3156 "Sequences in selection are not aligned",
3157 JOptionPane.WARNING_MESSAGE);
3163 title = title + " on region";
3164 tp = new TreePanel(alignPanel, type, pwType);
3168 // are the sequences aligned?
3169 if (!viewport.alignment.isAligned())
3174 "The sequences must be aligned before creating a tree.\n"
3175 + "Try using the Pad function in the edit menu,\n"
3176 + "or one of the multiple sequence alignment web services.",
3177 "Sequences not aligned",
3178 JOptionPane.WARNING_MESSAGE);
3183 if (viewport.alignment.getHeight() < 2)
3188 tp = new TreePanel(alignPanel, type, pwType);
3193 if (viewport.viewName != null)
3195 title += viewport.viewName + " of ";
3198 title += this.title;
3200 Desktop.addInternalFrame(tp, title, 600, 500);
3211 public void addSortByOrderMenuItem(String title,
3212 final AlignmentOrder order)
3214 final JMenuItem item = new JMenuItem("by " + title);
3216 item.addActionListener(new java.awt.event.ActionListener()
3218 public void actionPerformed(ActionEvent e)
3220 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3222 // TODO: JBPNote - have to map order entries to curent SequenceI
3224 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3226 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3227 viewport.alignment));
3229 alignPanel.paintAlignment(true);
3235 * Add a new sort by annotation score menu item
3238 * the menu to add the option to
3240 * the label used to retrieve scores for each sequence on the
3243 public void addSortByAnnotScoreMenuItem(JMenu sort,
3244 final String scoreLabel)
3246 final JMenuItem item = new JMenuItem(scoreLabel);
3248 item.addActionListener(new java.awt.event.ActionListener()
3250 public void actionPerformed(ActionEvent e)
3252 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3253 AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport
3254 .getAlignment());// ,viewport.getSelectionGroup());
3255 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3256 viewport.alignment));
3257 alignPanel.paintAlignment(true);
3263 * last hash for alignment's annotation array - used to minimise cost of
3266 protected int _annotationScoreVectorHash;
3269 * search the alignment and rebuild the sort by annotation score submenu the
3270 * last alignment annotation vector hash is stored to minimize cost of
3271 * rebuilding in subsequence calls.
3274 public void buildSortByAnnotationScoresMenu()
3276 if (viewport.alignment.getAlignmentAnnotation() == null)
3281 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3283 sortByAnnotScore.removeAll();
3284 // almost certainly a quicker way to do this - but we keep it simple
3285 Hashtable scoreSorts = new Hashtable();
3286 AlignmentAnnotation aann[];
3287 Enumeration sq = viewport.alignment.getSequences().elements();
3288 while (sq.hasMoreElements())
3290 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3291 for (int i = 0; aann != null && i < aann.length; i++)
3293 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3295 scoreSorts.put(aann[i].label, aann[i].label);
3299 Enumeration labels = scoreSorts.keys();
3300 while (labels.hasMoreElements())
3302 addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels
3305 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3308 _annotationScoreVectorHash = viewport.alignment
3309 .getAlignmentAnnotation().hashCode();
3314 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3315 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3316 * call. Listeners are added to remove the menu item when the treePanel is
3317 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3321 * Displayed tree window.
3323 * SortBy menu item title.
3325 public void buildTreeMenu()
3327 sortByTreeMenu.removeAll();
3329 Vector comps = (Vector) PaintRefresher.components.get(viewport
3330 .getSequenceSetId());
3331 Vector treePanels = new Vector();
3332 int i, iSize = comps.size();
3333 for (i = 0; i < iSize; i++)
3335 if (comps.elementAt(i) instanceof TreePanel)
3337 treePanels.add(comps.elementAt(i));
3341 iSize = treePanels.size();
3345 sortByTreeMenu.setVisible(false);
3349 sortByTreeMenu.setVisible(true);
3351 for (i = 0; i < treePanels.size(); i++)
3353 TreePanel tp = (TreePanel) treePanels.elementAt(i);
3354 final JMenuItem item = new JMenuItem(tp.getTitle());
3355 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3356 item.addActionListener(new java.awt.event.ActionListener()
3358 public void actionPerformed(ActionEvent e)
3360 SequenceI[] oldOrder = viewport.getAlignment()
3361 .getSequencesArray();
3362 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3364 addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
3365 viewport.alignment));
3367 alignPanel.paintAlignment(true);
3371 sortByTreeMenu.add(item);
3376 * Work out whether the whole set of sequences or just the selected set will
3377 * be submitted for multiple alignment.
3380 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3382 // Now, check we have enough sequences
3383 AlignmentView msa = null;
3385 if ((viewport.getSelectionGroup() != null)
3386 && (viewport.getSelectionGroup().getSize() > 1))
3388 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3389 // some common interface!
3391 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3392 * SequenceI[sz = seqs.getSize(false)];
3394 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3395 * seqs.getSequenceAt(i); }
3397 msa = viewport.getAlignmentView(true);
3402 * Vector seqs = viewport.getAlignment().getSequences();
3404 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3406 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3407 * seqs.elementAt(i); } }
3409 msa = viewport.getAlignmentView(false);
3415 * Decides what is submitted to a secondary structure prediction service: the
3416 * first sequence in the alignment, or in the current selection, or, if the
3417 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3418 * region or the whole alignment. (where the first sequence in the set is the
3419 * one that the prediction will be for).
3421 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3423 AlignmentView seqs = null;
3425 if ((viewport.getSelectionGroup() != null)
3426 && (viewport.getSelectionGroup().getSize() > 0))
3428 seqs = viewport.getAlignmentView(true);
3432 seqs = viewport.getAlignmentView(false);
3434 // limit sequences - JBPNote in future - could spawn multiple prediction
3436 // TODO: viewport.alignment.isAligned is a global state - the local
3437 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3438 if (!viewport.alignment.isAligned())
3440 seqs.setSequences(new SeqCigar[]
3441 { seqs.getSequences()[0] });
3452 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3454 // Pick the tree file
3455 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
3456 .getProperty("LAST_DIRECTORY"));
3457 chooser.setFileView(new JalviewFileView());
3458 chooser.setDialogTitle("Select a newick-like tree file");
3459 chooser.setToolTipText("Load a tree file");
3461 int value = chooser.showOpenDialog(null);
3463 if (value == JalviewFileChooser.APPROVE_OPTION)
3465 String choice = chooser.getSelectedFile().getPath();
3466 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3467 jalview.io.NewickFile fin = null;
3470 fin = new jalview.io.NewickFile(choice, "File");
3471 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3472 } catch (Exception ex)
3474 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3475 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3476 ex.printStackTrace();
3478 if (fin != null && fin.hasWarningMessage())
3480 JOptionPane.showMessageDialog(Desktop.desktop, fin
3481 .getWarningMessage(), "Possible problem with tree file",
3482 JOptionPane.WARNING_MESSAGE);
3487 public TreePanel ShowNewickTree(NewickFile nf, String title)
3489 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3492 public TreePanel ShowNewickTree(NewickFile nf, String title,
3493 AlignmentView input)
3495 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3498 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3499 int h, int x, int y)
3501 return ShowNewickTree(nf, title, null, w, h, x, y);
3505 * Add a treeviewer for the tree extracted from a newick file object to the
3506 * current alignment view
3513 * Associated alignment input data (or null)
3522 * @return TreePanel handle
3524 public TreePanel ShowNewickTree(NewickFile nf, String title,
3525 AlignmentView input, int w, int h, int x, int y)
3527 TreePanel tp = null;
3533 if (nf.getTree() != null)
3535 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3541 tp.setLocation(x, y);
3544 Desktop.addInternalFrame(tp, title, w, h);
3546 } catch (Exception ex)
3548 ex.printStackTrace();
3555 * Generates menu items and listener event actions for web service clients
3558 public void BuildWebServiceMenu()
3560 // TODO: add support for context dependent disabling of services based on
3561 // alignment and current selection
3562 // TODO: add additional serviceHandle parameter to specify abstract handler
3563 // class independently of AbstractName
3564 // TODO: add in rediscovery GUI function to restart discoverer
3565 // TODO: group services by location as well as function and/or introduce
3566 // object broker mechanism.
3567 if ((Discoverer.services != null) && (Discoverer.services.size() > 0))
3569 // TODO: refactor to allow list of AbstractName/Handler bindings to be
3570 // stored or retrieved from elsewhere
3571 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3572 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3573 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3574 // TODO: move GUI generation code onto service implementation - so a
3575 // client instance attaches itself to the GUI with method call like
3576 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
3578 Vector wsmenu = new Vector();
3579 final IProgressIndicator af = this;
3582 // Add any Multiple Sequence Alignment Services
3583 final JMenu msawsmenu = new JMenu("Alignment");
3584 for (int i = 0, j = msaws.size(); i < j; i++)
3586 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
3588 jalview.ws.WSClient impl = jalview.ws.Discoverer
3589 .getServiceClient(sh);
3590 impl.attachWSMenuEntry(msawsmenu, this);
3593 wsmenu.add(msawsmenu);
3595 if (secstrpr != null)
3597 // Add any secondary structure prediction services
3598 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3599 for (int i = 0, j = secstrpr.size(); i < j; i++)
3601 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
3603 jalview.ws.WSClient impl = jalview.ws.Discoverer
3604 .getServiceClient(sh);
3605 impl.attachWSMenuEntry(secstrmenu, this);
3607 wsmenu.add(secstrmenu);
3609 if (seqsrch != null)
3611 // Add any sequence search services
3612 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
3613 for (int i = 0, j = seqsrch.size(); i < j; i++)
3615 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
3617 jalview.ws.WSClient impl = jalview.ws.Discoverer
3618 .getServiceClient(sh);
3619 impl.attachWSMenuEntry(seqsrchmenu, this);
3621 // finally, add the whole shebang onto the webservices menu
3622 wsmenu.add(seqsrchmenu);
3624 resetWebServiceMenu();
3625 for (int i = 0, j = wsmenu.size(); i < j; i++)
3627 webService.add((JMenu) wsmenu.get(i));
3632 resetWebServiceMenu();
3633 this.webService.add(this.webServiceNoServices);
3638 * empty the web service menu and add any ad-hoc functions not dynamically
3642 private void resetWebServiceMenu()
3644 webService.removeAll();
3645 build_fetchdbmenu(webService);
3649 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
3650 * chooser = new JalviewFileChooser(jalview.bin.Cache.
3651 * getProperty("LAST_DIRECTORY"));
3653 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
3654 * to Vamsas file"); chooser.setToolTipText("Export");
3656 * int value = chooser.showSaveDialog(this);
3658 * if (value == JalviewFileChooser.APPROVE_OPTION) {
3659 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3660 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
3661 * chooser.getSelectedFile().getAbsolutePath(), this); } }
3664 * prototype of an automatically enabled/disabled analysis function
3667 protected void setShowProductsEnabled()
3669 SequenceI[] selection = viewport.getSequenceSelection();
3670 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
3671 viewport.getAlignment().getDataset()))
3673 showProducts.setEnabled(true);
3678 showProducts.setEnabled(false);
3683 * search selection for sequence xRef products and build the show products
3688 * @return true if showProducts menu should be enabled.
3690 public boolean canShowProducts(SequenceI[] selection,
3691 boolean isRegionSelection, Alignment dataset)
3693 boolean showp = false;
3696 showProducts.removeAll();
3697 final boolean dna = viewport.getAlignment().isNucleotide();
3698 final Alignment ds = dataset;
3699 String[] ptypes = CrossRef.findSequenceXrefTypes(dna, selection,
3702 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
3703 // selection, dataset, true);
3704 final SequenceI[] sel = selection;
3705 for (int t = 0; ptypes != null && t < ptypes.length; t++)
3708 final boolean isRegSel = isRegionSelection;
3709 final AlignFrame af = this;
3710 final String source = ptypes[t];
3711 JMenuItem xtype = new JMenuItem(ptypes[t]);
3712 xtype.addActionListener(new ActionListener()
3715 public void actionPerformed(ActionEvent e)
3717 // TODO: new thread for this call with vis-delay
3718 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
3719 isRegSel, dna, source);
3723 showProducts.add(xtype);
3725 showProducts.setVisible(showp);
3726 showProducts.setEnabled(showp);
3727 } catch (Exception e)
3729 jalview.bin.Cache.log
3731 "canTranslate threw an exception - please report to help@jalview.org",
3738 protected void showProductsFor(SequenceI[] sel, Alignment ds,
3739 boolean isRegSel, boolean dna, String source)
3741 final boolean fisRegSel = isRegSel;
3742 final boolean fdna = dna;
3743 final String fsrc = source;
3744 final AlignFrame ths = this;
3745 final SequenceI[] fsel = sel;
3746 Runnable foo = new Runnable()
3751 final long sttime = System.currentTimeMillis();
3752 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
3755 Alignment ds = ths.getViewport().alignment.getDataset(); // update
3759 Alignment prods = CrossRef
3760 .findXrefSequences(fsel, fdna, fsrc, ds);
3763 SequenceI[] sprods = new SequenceI[prods.getHeight()];
3764 for (int s = 0; s < sprods.length; s++)
3766 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
3767 if (ds.getSequences() == null
3768 || !ds.getSequences().contains(
3769 sprods[s].getDatasetSequence()))
3770 ds.addSequence(sprods[s].getDatasetSequence());
3771 sprods[s].updatePDBIds();
3773 Alignment al = new Alignment(sprods);
3774 AlignedCodonFrame[] cf = prods.getCodonFrames();
3776 for (int s = 0; cf != null && s < cf.length; s++)
3778 al.addCodonFrame(cf[s]);
3781 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
3783 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
3784 + " for " + ((fisRegSel) ? "selected region of " : "")
3786 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
3791 System.err.println("No Sequences generated for xRef type "
3794 } catch (Exception e)
3796 jalview.bin.Cache.log.error(
3797 "Exception when finding crossreferences", e);
3798 } catch (OutOfMemoryError e)
3800 new OOMWarning("whilst fetching crossreferences", e);
3803 jalview.bin.Cache.log.error("Error when finding crossreferences",
3806 ths.setProgressBar("Finished searching for sequences from " + fsrc,
3811 Thread frunner = new Thread(foo);
3815 public boolean canShowTranslationProducts(SequenceI[] selection,
3816 AlignmentI alignment)
3821 return (jalview.analysis.Dna.canTranslate(selection, viewport
3822 .getViewAsVisibleContigs(true)));
3823 } catch (Exception e)
3825 jalview.bin.Cache.log
3827 "canTranslate threw an exception - please report to help@jalview.org",
3833 public void showProducts_actionPerformed(ActionEvent e)
3835 // /////////////////////////////
3836 // Collect Data to be translated/transferred
3838 SequenceI[] selection = viewport.getSequenceSelection();
3839 AlignmentI al = null;
3842 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
3843 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
3844 viewport.getAlignment().getDataset());
3845 } catch (Exception ex)
3848 jalview.bin.Cache.log.debug("Exception during translation.", ex);
3855 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3856 "Translation Failed", JOptionPane.WARNING_MESSAGE);
3860 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3861 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
3862 DEFAULT_WIDTH, DEFAULT_HEIGHT);
3866 public void showTranslation_actionPerformed(ActionEvent e)
3868 // /////////////////////////////
3869 // Collect Data to be translated/transferred
3871 SequenceI[] selection = viewport.getSequenceSelection();
3872 String[] seqstring = viewport.getViewAsString(true);
3873 AlignmentI al = null;
3876 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
3877 viewport.getViewAsVisibleContigs(true), viewport
3878 .getGapCharacter(), viewport.alignment
3879 .getAlignmentAnnotation(), viewport.alignment
3880 .getWidth(), viewport.getAlignment().getDataset());
3881 } catch (Exception ex)
3884 jalview.bin.Cache.log.debug("Exception during translation.", ex);
3891 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3892 "Translation Failed", JOptionPane.WARNING_MESSAGE);
3896 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3897 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
3898 DEFAULT_WIDTH, DEFAULT_HEIGHT);
3903 * Try to load a features file onto the alignment.
3906 * contents or path to retrieve file
3908 * access mode of file (see jalview.io.AlignFile)
3909 * @return true if features file was parsed corectly.
3911 public boolean parseFeaturesFile(String file, String type)
3913 boolean featuresFile = false;
3916 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment
3917 .getDataset(), alignPanel.seqPanel.seqCanvas
3918 .getFeatureRenderer().featureColours, false);
3919 } catch (Exception ex)
3921 ex.printStackTrace();
3926 viewport.showSequenceFeatures = true;
3927 showSeqFeatures.setSelected(true);
3928 alignPanel.paintAlignment(true);
3931 return featuresFile;
3934 public void dragEnter(DropTargetDragEvent evt)
3938 public void dragExit(DropTargetEvent evt)
3942 public void dragOver(DropTargetDragEvent evt)
3946 public void dropActionChanged(DropTargetDragEvent evt)
3950 public void drop(DropTargetDropEvent evt)
3952 Transferable t = evt.getTransferable();
3953 java.util.List files = null;
3957 DataFlavor uriListFlavor = new DataFlavor(
3958 "text/uri-list;class=java.lang.String");
3959 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3961 // Works on Windows and MacOSX
3962 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3963 files = (java.util.List) t
3964 .getTransferData(DataFlavor.javaFileListFlavor);
3966 else if (t.isDataFlavorSupported(uriListFlavor))
3968 // This is used by Unix drag system
3969 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3970 String data = (String) t.getTransferData(uriListFlavor);
3971 files = new java.util.ArrayList(1);
3972 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3973 data, "\r\n"); st.hasMoreTokens();)
3975 String s = st.nextToken();
3976 if (s.startsWith("#"))
3978 // the line is a comment (as per the RFC 2483)
3982 java.net.URI uri = new java.net.URI(s);
3983 java.io.File file = new java.io.File(uri);
3987 } catch (Exception e)
3989 e.printStackTrace();
3996 for (int i = 0; i < files.size(); i++)
3998 loadJalviewDataFile(files.get(i).toString());
4000 } catch (Exception ex)
4002 ex.printStackTrace();
4008 * Attempt to load a "dropped" file: First by testing whether it's and
4009 * Annotation file, then a JNet file, and finally a features file. If all are
4010 * false then the user may have dropped an alignment file onto this
4014 * either a filename or a URL string.
4016 public void loadJalviewDataFile(String file)
4020 String protocol = "File";
4022 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
4027 boolean isAnnotation = new AnnotationFile().readAnnotationFile(
4028 viewport.alignment, file, protocol);
4032 // try to see if its a JNet 'concise' style annotation file *before* we
4033 // try to parse it as a features file
4034 String format = new IdentifyFile().Identify(file, protocol);
4035 if (format.equalsIgnoreCase("JnetFile"))
4037 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4039 new JnetAnnotationMaker().add_annotation(predictions, viewport
4040 .getAlignment(), 0, false);
4041 isAnnotation = true;
4045 // try to parse it as a features file
4046 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4047 // if it wasn't a features file then we just treat it as a general
4048 // alignment file to load into the current view.
4051 new FileLoader().LoadFile(viewport, file, protocol, format);
4055 alignPanel.paintAlignment(true);
4062 alignPanel.adjustAnnotationHeight();
4063 viewport.updateSequenceIdColours();
4064 buildSortByAnnotationScoresMenu();
4065 alignPanel.paintAlignment(true);
4067 } catch (Exception ex)
4069 ex.printStackTrace();
4073 public void tabSelectionChanged(int index)
4077 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4078 viewport = alignPanel.av;
4079 setMenusFromViewport(viewport);
4083 public void tabbedPane_mousePressed(MouseEvent e)
4085 if (SwingUtilities.isRightMouseButton(e))
4087 String reply = JOptionPane.showInternalInputDialog(this,
4088 "Enter View Name", "Edit View Name",
4089 JOptionPane.QUESTION_MESSAGE);
4093 viewport.viewName = reply;
4094 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4099 public AlignViewport getCurrentView()
4105 * Open the dialog for regex description parsing.
4107 protected void extractScores_actionPerformed(ActionEvent e)
4109 ParseProperties pp = new jalview.analysis.ParseProperties(
4110 viewport.alignment);
4111 // TODO: verify regex and introduce GUI dialog for version 2.5
4112 // if (pp.getScoresFromDescription("col", "score column ",
4113 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4115 if (pp.getScoresFromDescription("description column",
4116 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4118 buildSortByAnnotationScoresMenu();
4123 * @see jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent)
4125 protected void showDbRefs_actionPerformed(ActionEvent e)
4127 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4131 * @see jalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.ActionEvent)
4133 protected void showNpFeats_actionPerformed(ActionEvent e)
4135 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4139 * find the viewport amongst the tabs in this alignment frame and close that tab
4142 public boolean closeView(AlignViewport av)
4146 this.closeMenuItem_actionPerformed(false);
4149 Component[] comp = tabbedPane.getComponents();
4150 for (int i=0;comp!=null && i<comp.length;i++)
4152 if (comp[i] instanceof AlignmentPanel)
4154 if (((AlignmentPanel) comp[i]).av == av)
4157 closeView((AlignmentPanel) comp[i]);
4164 protected void build_fetchdbmenu(JMenu webService) {
4165 // Temporary hack - DBRef Fetcher always top level ws entry.
4166 // TODO We probably want to store a sequence database checklist in preferences and have checkboxes.. rather than individual sources selected here
4167 JMenu rfetch = new JMenu("Fetch DB References");
4169 .setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4170 webService.add(rfetch);
4172 JMenuItem fetchr = new JMenuItem("Standard Databases");
4173 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4174 fetchr.addActionListener(new ActionListener()
4177 public void actionPerformed(ActionEvent e)
4179 new Thread(new Runnable()
4184 new jalview.ws.DBRefFetcher(alignPanel.av
4185 .getSequenceSelection(), alignPanel.alignFrame)
4186 .fetchDBRefs(false);
4194 JMenu dfetch = new JMenu();
4196 jalview.ws.SequenceFetcher sf = SequenceFetcher.getSequenceFetcherSingleton(this);
4197 String[] otherdb = sf.getOrderedSupportedSources();
4198 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4199 // jalview.util.QuickSort.sort(otherdb, otherdb);
4200 int comp=0,mcomp=15;
4202 if (otherdb!=null && otherdb.length>0)
4204 for (int i=0; i<otherdb.length; i++)
4206 String dbname =sf.getSourceProxy(otherdb[i]).getDbName();
4209 mname = "from '"+dbname+"'";
4211 fetchr = new JMenuItem(otherdb[i]);
4212 final String[] dassource = new String[] { otherdb[i] };
4213 fetchr.addActionListener(new ActionListener()
4216 public void actionPerformed(ActionEvent e)
4218 new Thread(new Runnable()
4223 new jalview.ws.DBRefFetcher(alignPanel.av
4224 .getSequenceSelection(), alignPanel.alignFrame, dassource)
4225 .fetchDBRefs(false);
4231 fetchr.setToolTipText("Retrieve from "+dbname);
4233 if (comp++==mcomp || i==(otherdb.length-1))
4235 dfetch.setText(mname+" to '"+dbname+"'");
4237 dfetch = new JMenu();
4246 class PrintThread extends Thread
4250 public PrintThread(AlignmentPanel ap)
4255 static PageFormat pf;
4259 PrinterJob printJob = PrinterJob.getPrinterJob();
4263 printJob.setPrintable(ap, pf);
4267 printJob.setPrintable(ap);
4270 if (printJob.printDialog())
4275 } catch (Exception PrintException)
4277 PrintException.printStackTrace();