2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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);
603 showUnconservedMenuItem.setSelected(av.showUnconserved);
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);
1091 closeView(alignPanel);
1098 this.setClosed(true);
1100 } catch (Exception ex)
1102 ex.printStackTrace();
1107 * close alignPanel2 and shuffle tabs appropriately.
1108 * @param alignPanel2
1110 public void closeView(AlignmentPanel alignPanel2)
1112 int index = tabbedPane.getSelectedIndex();
1113 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1114 alignPanels.removeElement(alignPanel2);
1116 if (viewport == alignPanel2.av)
1120 alignPanel2.closePanel();
1123 tabbedPane.removeTabAt(closedindex);
1124 tabbedPane.validate();
1126 if (index > closedindex || index == tabbedPane.getTabCount())
1128 // modify currently selected tab index if necessary.
1132 this.tabSelectionChanged(index);
1138 void updateEditMenuBar()
1141 if (viewport.historyList.size() > 0)
1143 undoMenuItem.setEnabled(true);
1144 CommandI command = (CommandI) viewport.historyList.peek();
1145 undoMenuItem.setText("Undo " + command.getDescription());
1149 undoMenuItem.setEnabled(false);
1150 undoMenuItem.setText("Undo");
1153 if (viewport.redoList.size() > 0)
1155 redoMenuItem.setEnabled(true);
1157 CommandI command = (CommandI) viewport.redoList.peek();
1158 redoMenuItem.setText("Redo " + command.getDescription());
1162 redoMenuItem.setEnabled(false);
1163 redoMenuItem.setText("Redo");
1167 public void addHistoryItem(CommandI command)
1169 if (command.getSize() > 0)
1171 viewport.historyList.push(command);
1172 viewport.redoList.clear();
1173 updateEditMenuBar();
1174 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1180 * @return alignment objects for all views
1182 AlignmentI[] getViewAlignments()
1184 if (alignPanels != null)
1186 Enumeration e = alignPanels.elements();
1187 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1188 for (int i = 0; e.hasMoreElements(); i++)
1190 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1194 if (viewport != null)
1196 return new AlignmentI[]
1197 { viewport.alignment };
1208 protected void undoMenuItem_actionPerformed(ActionEvent e)
1210 if (viewport.historyList.empty())
1212 CommandI command = (CommandI) viewport.historyList.pop();
1213 viewport.redoList.push(command);
1214 command.undoCommand(getViewAlignments());
1216 AlignViewport originalSource = getOriginatingSource(command);
1217 updateEditMenuBar();
1219 if (originalSource != null)
1221 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1222 originalSource.firePropertyChange("alignment", null,
1223 originalSource.alignment.getSequences());
1233 protected void redoMenuItem_actionPerformed(ActionEvent e)
1235 if (viewport.redoList.size() < 1)
1240 CommandI command = (CommandI) viewport.redoList.pop();
1241 viewport.historyList.push(command);
1242 command.doCommand(getViewAlignments());
1244 AlignViewport originalSource = getOriginatingSource(command);
1245 updateEditMenuBar();
1247 if (originalSource != null)
1249 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1250 originalSource.firePropertyChange("alignment", null,
1251 originalSource.alignment.getSequences());
1255 AlignViewport getOriginatingSource(CommandI command)
1257 AlignViewport originalSource = null;
1258 // For sequence removal and addition, we need to fire
1259 // the property change event FROM the viewport where the
1260 // original alignment was altered
1261 AlignmentI al = null;
1262 if (command instanceof EditCommand)
1264 EditCommand editCommand = (EditCommand) command;
1265 al = editCommand.getAlignment();
1266 Vector comps = (Vector) PaintRefresher.components.get(viewport
1267 .getSequenceSetId());
1269 for (int i = 0; i < comps.size(); i++)
1271 if (comps.elementAt(i) instanceof AlignmentPanel)
1273 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1275 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1282 if (originalSource == null)
1284 // The original view is closed, we must validate
1285 // the current view against the closed view first
1288 PaintRefresher.validateSequences(al, viewport.alignment);
1291 originalSource = viewport;
1294 return originalSource;
1303 public void moveSelectedSequences(boolean up)
1305 SequenceGroup sg = viewport.getSelectionGroup();
1314 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1316 SequenceI seq = viewport.alignment.getSequenceAt(i);
1318 if (!sg.getSequences(null).contains(seq))
1323 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1325 if (sg.getSequences(null).contains(temp))
1330 viewport.alignment.getSequences().setElementAt(temp, i);
1331 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1336 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1338 SequenceI seq = viewport.alignment.getSequenceAt(i);
1340 if (!sg.getSequences(null).contains(seq))
1345 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1347 if (sg.getSequences(null).contains(temp))
1352 viewport.alignment.getSequences().setElementAt(temp, i);
1353 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1357 alignPanel.paintAlignment(true);
1360 synchronized void slideSequences(boolean right, int size)
1362 Vector sg = new Vector();
1363 if (viewport.cursorMode)
1365 sg.addElement(viewport.alignment
1366 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1368 else if (viewport.getSelectionGroup() != null
1369 && viewport.getSelectionGroup().getSize() != viewport.alignment
1372 sg = viewport.getSelectionGroup().getSequences(
1373 viewport.hiddenRepSequences);
1381 Vector invertGroup = new Vector();
1383 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1385 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1386 invertGroup.add(viewport.alignment.getSequenceAt(i));
1389 SequenceI[] seqs1 = new SequenceI[sg.size()];
1390 for (int i = 0; i < sg.size(); i++)
1391 seqs1[i] = (SequenceI) sg.elementAt(i);
1393 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1394 for (int i = 0; i < invertGroup.size(); i++)
1395 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1397 SlideSequencesCommand ssc;
1399 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1400 size, viewport.getGapCharacter());
1402 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1403 size, viewport.getGapCharacter());
1405 int groupAdjustment = 0;
1406 if (ssc.getGapsInsertedBegin() && right)
1408 if (viewport.cursorMode)
1409 alignPanel.seqPanel.moveCursor(size, 0);
1411 groupAdjustment = size;
1413 else if (!ssc.getGapsInsertedBegin() && !right)
1415 if (viewport.cursorMode)
1416 alignPanel.seqPanel.moveCursor(-size, 0);
1418 groupAdjustment = -size;
1421 if (groupAdjustment != 0)
1423 viewport.getSelectionGroup().setStartRes(
1424 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1425 viewport.getSelectionGroup().setEndRes(
1426 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1429 boolean appendHistoryItem = false;
1430 if (viewport.historyList != null && viewport.historyList.size() > 0
1431 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1433 appendHistoryItem = ssc
1434 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1438 if (!appendHistoryItem)
1439 addHistoryItem(ssc);
1450 protected void copy_actionPerformed(ActionEvent e)
1453 if (viewport.getSelectionGroup() == null)
1457 // TODO: preserve the ordering of displayed alignment annotation in any
1458 // internal paste (particularly sequence associated annotation)
1459 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1460 String[] omitHidden = null;
1462 if (viewport.hasHiddenColumns)
1464 omitHidden = viewport.getViewAsString(true);
1467 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1470 StringSelection ss = new StringSelection(output);
1474 jalview.gui.Desktop.internalCopy = true;
1475 // Its really worth setting the clipboard contents
1476 // to empty before setting the large StringSelection!!
1477 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
1478 new StringSelection(""), null);
1480 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
1482 } catch (OutOfMemoryError er)
1484 new OOMWarning("copying region", er);
1488 Vector hiddenColumns = null;
1489 if (viewport.hasHiddenColumns)
1491 hiddenColumns = new Vector();
1492 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1493 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1496 int[] region = (int[]) viewport.getColumnSelection()
1497 .getHiddenColumns().elementAt(i);
1499 hiddenColumns.addElement(new int[]
1500 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1504 Desktop.jalviewClipboard = new Object[]
1505 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1506 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1515 protected void pasteNew_actionPerformed(ActionEvent e)
1526 protected void pasteThis_actionPerformed(ActionEvent e)
1532 * Paste contents of Jalview clipboard
1534 * @param newAlignment
1535 * true to paste to a new alignment, otherwise add to this.
1537 void paste(boolean newAlignment)
1539 boolean externalPaste = true;
1542 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1543 Transferable contents = c.getContents(this);
1545 if (contents == null)
1553 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1554 if (str.length() < 1)
1559 format = new IdentifyFile().Identify(str, "Paste");
1561 } catch (OutOfMemoryError er)
1563 new OOMWarning("Out of memory pasting sequences!!", er);
1567 SequenceI[] sequences;
1568 boolean annotationAdded = false;
1569 AlignmentI alignment = null;
1571 if (Desktop.jalviewClipboard != null)
1573 // The clipboard was filled from within Jalview, we must use the
1575 // And dataset from the copied alignment
1576 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1577 // be doubly sure that we create *new* sequence objects.
1578 sequences = new SequenceI[newseq.length];
1579 for (int i = 0; i < newseq.length; i++)
1581 sequences[i] = new Sequence(newseq[i]);
1583 alignment = new Alignment(sequences);
1584 externalPaste = false;
1588 // parse the clipboard as an alignment.
1589 alignment = new FormatAdapter().readFile(str, "Paste", format);
1590 sequences = alignment.getSequencesArray();
1598 if (Desktop.jalviewClipboard != null)
1600 // dataset is inherited
1601 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1605 // new dataset is constructed
1606 alignment.setDataset(null);
1608 alwidth = alignment.getWidth() + 1;
1612 AlignmentI pastedal = alignment; // preserve pasted alignment object
1613 // Add pasted sequences and dataset into existing alignment.
1614 alignment = viewport.getAlignment();
1615 alwidth = alignment.getWidth() + 1;
1616 // decide if we need to import sequences from an existing dataset
1617 boolean importDs = Desktop.jalviewClipboard != null
1618 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1619 // importDs==true instructs us to copy over new dataset sequences from
1620 // an existing alignment
1621 Vector newDs = (importDs) ? new Vector() : null; // used to create
1622 // minimum dataset set
1624 for (int i = 0; i < sequences.length; i++)
1628 newDs.addElement(null);
1630 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1632 if (importDs && ds != null)
1634 if (!newDs.contains(ds))
1636 newDs.setElementAt(ds, i);
1637 ds = new Sequence(ds);
1638 // update with new dataset sequence
1639 sequences[i].setDatasetSequence(ds);
1643 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1648 // copy and derive new dataset sequence
1649 sequences[i] = sequences[i].deriveSequence();
1650 alignment.getDataset().addSequence(
1651 sequences[i].getDatasetSequence());
1652 // TODO: avoid creation of duplicate dataset sequences with a
1653 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1655 alignment.addSequence(sequences[i]); // merges dataset
1659 newDs.clear(); // tidy up
1661 if (pastedal.getAlignmentAnnotation() != null)
1663 // Add any annotation attached to alignment.
1664 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1665 for (int i = 0; i < alann.length; i++)
1667 annotationAdded = true;
1668 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1670 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1671 newann.padAnnotation(alwidth);
1672 alignment.addAnnotation(newann);
1682 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1683 sequences, 0, alignment.getWidth(), alignment));
1685 // Add any annotations attached to sequences
1686 for (int i = 0; i < sequences.length; i++)
1688 if (sequences[i].getAnnotation() != null)
1690 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1692 annotationAdded = true;
1693 sequences[i].getAnnotation()[a].adjustForAlignment();
1694 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1695 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1700 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1707 // propagate alignment changed.
1708 viewport.setEndSeq(alignment.getHeight());
1709 if (annotationAdded)
1711 // Duplicate sequence annotation in all views.
1712 AlignmentI[] alview = this.getViewAlignments();
1713 for (int i = 0; i < sequences.length; i++)
1715 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1718 for (int avnum = 0; avnum < alview.length; avnum++)
1720 if (alview[avnum] != alignment)
1722 // duplicate in a view other than the one with input focus
1723 int avwidth = alview[avnum].getWidth() + 1;
1724 // this relies on sann being preserved after we
1725 // modify the sequence's annotation array for each duplication
1726 for (int a = 0; a < sann.length; a++)
1728 AlignmentAnnotation newann = new AlignmentAnnotation(
1730 sequences[i].addAlignmentAnnotation(newann);
1731 newann.padAnnotation(avwidth);
1732 alview[avnum].addAnnotation(newann); // annotation was
1733 // duplicated earlier
1734 alview[avnum].setAnnotationIndex(newann, a);
1739 buildSortByAnnotationScoresMenu();
1741 viewport.firePropertyChange("alignment", null, alignment
1747 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1749 String newtitle = new String("Copied sequences");
1751 if (Desktop.jalviewClipboard != null
1752 && Desktop.jalviewClipboard[2] != null)
1754 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1755 for (int i = 0; i < hc.size(); i++)
1757 int[] region = (int[]) hc.elementAt(i);
1758 af.viewport.hideColumns(region[0], region[1]);
1762 // >>>This is a fix for the moment, until a better solution is
1764 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1766 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1768 // TODO: maintain provenance of an alignment, rather than just make the
1769 // title a concatenation of operations.
1772 if (title.startsWith("Copied sequences"))
1778 newtitle = newtitle.concat("- from " + title);
1783 newtitle = new String("Pasted sequences");
1786 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1791 } catch (Exception ex)
1793 ex.printStackTrace();
1794 System.out.println("Exception whilst pasting: " + ex);
1795 // could be anything being pasted in here
1806 protected void cut_actionPerformed(ActionEvent e)
1808 copy_actionPerformed(null);
1809 delete_actionPerformed(null);
1818 protected void delete_actionPerformed(ActionEvent evt)
1821 SequenceGroup sg = viewport.getSelectionGroup();
1827 Vector seqs = new Vector();
1829 for (int i = 0; i < sg.getSize(); i++)
1831 seq = sg.getSequenceAt(i);
1832 seqs.addElement(seq);
1835 // If the cut affects all sequences, remove highlighted columns
1836 if (sg.getSize() == viewport.alignment.getHeight())
1838 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1839 sg.getEndRes() + 1);
1842 SequenceI[] cut = new SequenceI[seqs.size()];
1843 for (int i = 0; i < seqs.size(); i++)
1845 cut[i] = (SequenceI) seqs.elementAt(i);
1849 * //ADD HISTORY ITEM
1851 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
1852 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
1853 viewport.alignment));
1855 viewport.setSelectionGroup(null);
1856 viewport.sendSelection();
1857 viewport.alignment.deleteGroup(sg);
1859 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
1861 if (viewport.getAlignment().getHeight() < 1)
1865 this.setClosed(true);
1866 } catch (Exception ex)
1878 protected void deleteGroups_actionPerformed(ActionEvent e)
1880 viewport.alignment.deleteAllGroups();
1881 viewport.sequenceColours = null;
1882 viewport.setSelectionGroup(null);
1883 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1884 alignPanel.paintAlignment(true);
1893 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1895 SequenceGroup sg = new SequenceGroup();
1897 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1899 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1902 sg.setEndRes(viewport.alignment.getWidth() - 1);
1903 viewport.setSelectionGroup(sg);
1904 viewport.sendSelection();
1905 alignPanel.paintAlignment(true);
1906 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1915 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1917 if (viewport.cursorMode)
1919 alignPanel.seqPanel.keyboardNo1 = null;
1920 alignPanel.seqPanel.keyboardNo2 = null;
1922 viewport.setSelectionGroup(null);
1923 viewport.getColumnSelection().clear();
1924 viewport.setSelectionGroup(null);
1925 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1926 alignPanel.idPanel.idCanvas.searchResults = null;
1927 alignPanel.paintAlignment(true);
1928 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1937 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1939 SequenceGroup sg = viewport.getSelectionGroup();
1943 selectAllSequenceMenuItem_actionPerformed(null);
1948 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1950 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1953 alignPanel.paintAlignment(true);
1954 viewport.sendSelection();
1955 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1958 public void invertColSel_actionPerformed(ActionEvent e)
1960 viewport.invertColumnSelection();
1961 alignPanel.paintAlignment(true);
1970 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1972 trimAlignment(true);
1981 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1983 trimAlignment(false);
1986 void trimAlignment(boolean trimLeft)
1988 ColumnSelection colSel = viewport.getColumnSelection();
1991 if (colSel.size() > 0)
1995 column = colSel.getMin();
1999 column = colSel.getMax();
2003 if (viewport.getSelectionGroup() != null)
2005 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2006 viewport.hiddenRepSequences);
2010 seqs = viewport.alignment.getSequencesArray();
2013 TrimRegionCommand trimRegion;
2016 trimRegion = new TrimRegionCommand("Remove Left",
2017 TrimRegionCommand.TRIM_LEFT, seqs, column,
2018 viewport.alignment, viewport.colSel,
2019 viewport.selectionGroup);
2020 viewport.setStartRes(0);
2024 trimRegion = new TrimRegionCommand("Remove Right",
2025 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2026 viewport.alignment, viewport.colSel,
2027 viewport.selectionGroup);
2030 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2032 addHistoryItem(trimRegion);
2034 Vector groups = viewport.alignment.getGroups();
2036 for (int i = 0; i < groups.size(); i++)
2038 SequenceGroup sg = (SequenceGroup) groups.get(i);
2040 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2041 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2043 viewport.alignment.deleteGroup(sg);
2047 viewport.firePropertyChange("alignment", null, viewport
2048 .getAlignment().getSequences());
2058 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2060 int start = 0, end = viewport.alignment.getWidth() - 1;
2063 if (viewport.getSelectionGroup() != null)
2065 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2066 viewport.hiddenRepSequences);
2067 start = viewport.getSelectionGroup().getStartRes();
2068 end = viewport.getSelectionGroup().getEndRes();
2072 seqs = viewport.alignment.getSequencesArray();
2075 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2076 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2078 addHistoryItem(removeGapCols);
2080 statusBar.setText("Removed " + removeGapCols.getSize()
2081 + " empty columns.");
2083 // This is to maintain viewport position on first residue
2084 // of first sequence
2085 SequenceI seq = viewport.alignment.getSequenceAt(0);
2086 int startRes = seq.findPosition(viewport.startRes);
2087 // ShiftList shifts;
2088 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2089 // edit.alColumnChanges=shifts.getInverse();
2090 // if (viewport.hasHiddenColumns)
2091 // viewport.getColumnSelection().compensateForEdits(shifts);
2092 viewport.setStartRes(seq.findIndex(startRes) - 1);
2093 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2104 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2106 int start = 0, end = viewport.alignment.getWidth() - 1;
2109 if (viewport.getSelectionGroup() != null)
2111 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2112 viewport.hiddenRepSequences);
2113 start = viewport.getSelectionGroup().getStartRes();
2114 end = viewport.getSelectionGroup().getEndRes();
2118 seqs = viewport.alignment.getSequencesArray();
2121 // This is to maintain viewport position on first residue
2122 // of first sequence
2123 SequenceI seq = viewport.alignment.getSequenceAt(0);
2124 int startRes = seq.findPosition(viewport.startRes);
2126 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2127 viewport.alignment));
2129 viewport.setStartRes(seq.findIndex(startRes) - 1);
2131 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2142 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2144 viewport.padGaps = padGapsMenuitem.isSelected();
2145 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2151 // if (justifySeqs>0)
2153 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2164 public void findMenuItem_actionPerformed(ActionEvent e)
2169 public void newView_actionPerformed(ActionEvent e)
2171 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2174 newap.av.gatherViewsHere = false;
2176 if (viewport.viewName == null)
2178 viewport.viewName = "Original";
2181 newap.av.historyList = viewport.historyList;
2182 newap.av.redoList = viewport.redoList;
2184 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2185 String newViewName = "View " + index;
2187 Vector comps = (Vector) PaintRefresher.components.get(viewport
2188 .getSequenceSetId());
2189 Vector existingNames = new Vector();
2190 for (int i = 0; i < comps.size(); i++)
2192 if (comps.elementAt(i) instanceof AlignmentPanel)
2194 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2195 if (!existingNames.contains(ap.av.viewName))
2197 existingNames.addElement(ap.av.viewName);
2202 while (existingNames.contains(newViewName))
2204 newViewName = "View " + (++index);
2207 newap.av.viewName = newViewName;
2209 addAlignmentPanel(newap, true);
2211 if (alignPanels.size() == 2)
2213 viewport.gatherViewsHere = true;
2215 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2218 public void expandViews_actionPerformed(ActionEvent e)
2220 Desktop.instance.explodeViews(this);
2223 public void gatherViews_actionPerformed(ActionEvent e)
2225 Desktop.instance.gatherViews(this);
2234 public void font_actionPerformed(ActionEvent e)
2236 new FontChooser(alignPanel);
2245 protected void seqLimit_actionPerformed(ActionEvent e)
2247 viewport.setShowJVSuffix(seqLimits.isSelected());
2249 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2250 .calculateIdWidth());
2251 alignPanel.paintAlignment(true);
2254 public void idRightAlign_actionPerformed(ActionEvent e)
2256 viewport.rightAlignIds = idRightAlign.isSelected();
2257 alignPanel.paintAlignment(true);
2260 public void centreColumnLabels_actionPerformed(ActionEvent e)
2262 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2263 alignPanel.paintAlignment(true);
2266 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2268 protected void followHighlight_actionPerformed()
2270 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2272 alignPanel.scrollToPosition(alignPanel.seqPanel.seqCanvas.searchResults, false);
2282 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2284 viewport.setColourText(colourTextMenuItem.isSelected());
2285 alignPanel.paintAlignment(true);
2294 public void wrapMenuItem_actionPerformed(ActionEvent e)
2296 scaleAbove.setVisible(wrapMenuItem.isSelected());
2297 scaleLeft.setVisible(wrapMenuItem.isSelected());
2298 scaleRight.setVisible(wrapMenuItem.isSelected());
2299 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2300 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2303 public void showAllSeqs_actionPerformed(ActionEvent e)
2305 viewport.showAllHiddenSeqs();
2308 public void showAllColumns_actionPerformed(ActionEvent e)
2310 viewport.showAllHiddenColumns();
2314 public void hideSelSequences_actionPerformed(ActionEvent e)
2316 viewport.hideAllSelectedSeqs();
2317 alignPanel.paintAlignment(true);
2320 public void hideSelColumns_actionPerformed(ActionEvent e)
2322 viewport.hideSelectedColumns();
2323 alignPanel.paintAlignment(true);
2326 public void hiddenMarkers_actionPerformed(ActionEvent e)
2328 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2338 protected void scaleAbove_actionPerformed(ActionEvent e)
2340 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2341 alignPanel.paintAlignment(true);
2350 protected void scaleLeft_actionPerformed(ActionEvent e)
2352 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2353 alignPanel.paintAlignment(true);
2362 protected void scaleRight_actionPerformed(ActionEvent e)
2364 viewport.setScaleRightWrapped(scaleRight.isSelected());
2365 alignPanel.paintAlignment(true);
2374 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2376 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2377 alignPanel.paintAlignment(true);
2386 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2388 viewport.setShowText(viewTextMenuItem.isSelected());
2389 alignPanel.paintAlignment(true);
2398 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2400 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2401 alignPanel.paintAlignment(true);
2404 public FeatureSettings featureSettings;
2406 public void featureSettings_actionPerformed(ActionEvent e)
2408 if (featureSettings != null)
2410 featureSettings.close();
2411 featureSettings = null;
2413 featureSettings = new FeatureSettings(this);
2417 * Set or clear 'Show Sequence Features'
2422 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2424 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2425 alignPanel.paintAlignment(true);
2426 if (alignPanel.getOverviewPanel() != null)
2428 alignPanel.getOverviewPanel().updateOverviewImage();
2432 * Set or clear 'Show Sequence Features'
2437 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2439 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight.isSelected());
2440 if (viewport.getShowSequenceFeaturesHeight())
2442 // ensure we're actually displaying features
2443 viewport.setShowSequenceFeatures(true);
2444 showSeqFeatures.setSelected(true);
2446 alignPanel.paintAlignment(true);
2447 if (alignPanel.getOverviewPanel() != null)
2449 alignPanel.getOverviewPanel().updateOverviewImage();
2459 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2461 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2462 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2465 public void alignmentProperties()
2467 JEditorPane editPane = new JEditorPane("text/html", "");
2468 editPane.setEditable(false);
2469 StringBuffer contents = new StringBuffer("<html>");
2472 int min = Integer.MAX_VALUE, max = 0;
2473 for (int i = 0; i < viewport.alignment.getHeight(); i++)
2475 int size = viewport.alignment.getSequenceAt(i).getEnd()
2476 - viewport.alignment.getSequenceAt(i).getStart();
2483 avg = avg / (float) viewport.alignment.getHeight();
2485 contents.append("<br>Sequences: " + viewport.alignment.getHeight());
2486 contents.append("<br>Minimum Sequence Length: " + min);
2487 contents.append("<br>Maximum Sequence Length: " + max);
2488 contents.append("<br>Average Length: " + (int) avg);
2490 if (((Alignment) viewport.alignment).getProperties() != null)
2492 Hashtable props = ((Alignment) viewport.alignment).getProperties();
2493 Enumeration en = props.keys();
2494 contents.append("<br><br><table border=\"1\">");
2495 while (en.hasMoreElements())
2497 String key = en.nextElement().toString();
2498 StringBuffer val = new StringBuffer();
2499 String vals = props.get(key).toString();
2503 npos = vals.indexOf("\n", pos);
2506 val.append(vals.substring(pos));
2510 val.append(vals.substring(pos, npos));
2514 } while (npos != -1);
2516 .append("<tr><td>" + key + "</td><td>" + val + "</td></tr>");
2518 contents.append("</table>");
2520 editPane.setText(contents.toString() + "</html>");
2521 JInternalFrame frame = new JInternalFrame();
2522 frame.getContentPane().add(new JScrollPane(editPane));
2524 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2525 + getTitle(), 500, 400);
2534 public void overviewMenuItem_actionPerformed(ActionEvent e)
2536 if (alignPanel.overviewPanel != null)
2541 JInternalFrame frame = new JInternalFrame();
2542 OverviewPanel overview = new OverviewPanel(alignPanel);
2543 frame.setContentPane(overview);
2544 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(), frame
2545 .getWidth(), frame.getHeight());
2547 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2549 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2551 public void internalFrameClosed(
2552 javax.swing.event.InternalFrameEvent evt)
2554 alignPanel.setOverviewPanel(null);
2558 alignPanel.setOverviewPanel(overview);
2561 public void textColour_actionPerformed(ActionEvent e)
2563 new TextColourChooser().chooseColour(alignPanel, null);
2572 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2583 public void clustalColour_actionPerformed(ActionEvent e)
2585 changeColour(new ClustalxColourScheme(
2586 viewport.alignment.getSequences(), viewport.alignment
2596 public void zappoColour_actionPerformed(ActionEvent e)
2598 changeColour(new ZappoColourScheme());
2607 public void taylorColour_actionPerformed(ActionEvent e)
2609 changeColour(new TaylorColourScheme());
2618 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2620 changeColour(new HydrophobicColourScheme());
2629 public void helixColour_actionPerformed(ActionEvent e)
2631 changeColour(new HelixColourScheme());
2640 public void strandColour_actionPerformed(ActionEvent e)
2642 changeColour(new StrandColourScheme());
2651 public void turnColour_actionPerformed(ActionEvent e)
2653 changeColour(new TurnColourScheme());
2662 public void buriedColour_actionPerformed(ActionEvent e)
2664 changeColour(new BuriedColourScheme());
2673 public void nucleotideColour_actionPerformed(ActionEvent e)
2675 changeColour(new NucleotideColourScheme());
2678 public void annotationColour_actionPerformed(ActionEvent e)
2680 new AnnotationColourChooser(viewport, alignPanel);
2689 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2691 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2700 public void changeColour(ColourSchemeI cs)
2706 if (viewport.getAbovePIDThreshold())
2708 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2711 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2713 viewport.setGlobalColourScheme(cs);
2717 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2720 if (viewport.getConservationSelected())
2723 Alignment al = (Alignment) viewport.alignment;
2724 Conservation c = new Conservation("All",
2725 ResidueProperties.propHash, 3, al.getSequences(), 0, al
2729 c.verdict(false, viewport.ConsPercGaps);
2731 cs.setConservation(c);
2733 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
2738 cs.setConservation(null);
2741 cs.setConsensus(viewport.hconsensus);
2744 viewport.setGlobalColourScheme(cs);
2746 if (viewport.getColourAppliesToAllGroups())
2748 Vector groups = viewport.alignment.getGroups();
2750 for (int i = 0; i < groups.size(); i++)
2752 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2760 if (cs instanceof ClustalxColourScheme)
2762 sg.cs = new ClustalxColourScheme(sg
2763 .getSequences(viewport.hiddenRepSequences), sg.getWidth());
2765 else if (cs instanceof UserColourScheme)
2767 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
2773 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2774 } catch (Exception ex)
2779 if (viewport.getAbovePIDThreshold()
2780 || cs instanceof PIDColourScheme
2781 || cs instanceof Blosum62ColourScheme)
2783 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2785 sg.cs.setConsensus(AAFrequency.calculate(sg
2786 .getSequences(viewport.hiddenRepSequences), sg
2787 .getStartRes(), sg.getEndRes() + 1));
2791 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2794 if (viewport.getConservationSelected())
2796 Conservation c = new Conservation("Group",
2797 ResidueProperties.propHash, 3, sg
2798 .getSequences(viewport.hiddenRepSequences), sg
2799 .getStartRes(), sg.getEndRes() + 1);
2801 c.verdict(false, viewport.ConsPercGaps);
2802 sg.cs.setConservation(c);
2806 sg.cs.setConservation(null);
2811 if (alignPanel.getOverviewPanel() != null)
2813 alignPanel.getOverviewPanel().updateOverviewImage();
2816 alignPanel.paintAlignment(true);
2825 protected void modifyPID_actionPerformed(ActionEvent e)
2827 if (viewport.getAbovePIDThreshold()
2828 && viewport.globalColourScheme != null)
2830 SliderPanel.setPIDSliderSource(alignPanel, viewport
2831 .getGlobalColourScheme(), "Background");
2832 SliderPanel.showPIDSlider();
2842 protected void modifyConservation_actionPerformed(ActionEvent e)
2844 if (viewport.getConservationSelected()
2845 && viewport.globalColourScheme != null)
2847 SliderPanel.setConservationSlider(alignPanel,
2848 viewport.globalColourScheme, "Background");
2849 SliderPanel.showConservationSlider();
2859 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2861 viewport.setConservationSelected(conservationMenuItem.isSelected());
2863 viewport.setAbovePIDThreshold(false);
2864 abovePIDThreshold.setSelected(false);
2866 changeColour(viewport.getGlobalColourScheme());
2868 modifyConservation_actionPerformed(null);
2877 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2879 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2881 conservationMenuItem.setSelected(false);
2882 viewport.setConservationSelected(false);
2884 changeColour(viewport.getGlobalColourScheme());
2886 modifyPID_actionPerformed(null);
2895 public void userDefinedColour_actionPerformed(ActionEvent e)
2897 if (e.getActionCommand().equals("User Defined..."))
2899 new UserDefinedColours(alignPanel, null);
2903 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2904 .getUserColourSchemes().get(e.getActionCommand());
2910 public void updateUserColourMenu()
2913 Component[] menuItems = colourMenu.getMenuComponents();
2914 int i, iSize = menuItems.length;
2915 for (i = 0; i < iSize; i++)
2917 if (menuItems[i].getName() != null
2918 && menuItems[i].getName().equals("USER_DEFINED"))
2920 colourMenu.remove(menuItems[i]);
2924 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2926 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
2927 .getUserColourSchemes().keys();
2929 while (userColours.hasMoreElements())
2931 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2932 userColours.nextElement().toString());
2933 radioItem.setName("USER_DEFINED");
2934 radioItem.addMouseListener(new MouseAdapter()
2936 public void mousePressed(MouseEvent evt)
2938 if (evt.isControlDown()
2939 || SwingUtilities.isRightMouseButton(evt))
2942 .removeActionListener(radioItem.getActionListeners()[0]);
2944 int option = JOptionPane.showInternalConfirmDialog(
2945 jalview.gui.Desktop.desktop,
2946 "Remove from default list?",
2947 "Remove user defined colour",
2948 JOptionPane.YES_NO_OPTION);
2949 if (option == JOptionPane.YES_OPTION)
2951 jalview.gui.UserDefinedColours
2952 .removeColourFromDefaults(radioItem.getText());
2953 colourMenu.remove(radioItem);
2957 radioItem.addActionListener(new ActionListener()
2959 public void actionPerformed(ActionEvent evt)
2961 userDefinedColour_actionPerformed(evt);
2968 radioItem.addActionListener(new ActionListener()
2970 public void actionPerformed(ActionEvent evt)
2972 userDefinedColour_actionPerformed(evt);
2976 colourMenu.insert(radioItem, 15);
2977 colours.add(radioItem);
2988 public void PIDColour_actionPerformed(ActionEvent e)
2990 changeColour(new PIDColourScheme());
2999 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3001 changeColour(new Blosum62ColourScheme());
3010 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3012 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3013 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3014 .getAlignment().getSequenceAt(0), null);
3015 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3016 viewport.alignment));
3017 alignPanel.paintAlignment(true);
3026 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3028 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3029 AlignmentSorter.sortByID(viewport.getAlignment());
3030 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
3031 alignPanel.paintAlignment(true);
3039 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3041 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3042 AlignmentSorter.sortByLength(viewport.getAlignment());
3043 addHistoryItem(new OrderCommand("Length Sort", oldOrder, viewport.alignment));
3044 alignPanel.paintAlignment(true);
3053 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3055 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3056 AlignmentSorter.sortByGroup(viewport.getAlignment());
3057 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3058 viewport.alignment));
3060 alignPanel.paintAlignment(true);
3069 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3071 new RedundancyPanel(alignPanel, this);
3080 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3082 if ((viewport.getSelectionGroup() == null)
3083 || (viewport.getSelectionGroup().getSize() < 2))
3085 JOptionPane.showInternalMessageDialog(this,
3086 "You must select at least 2 sequences.", "Invalid Selection",
3087 JOptionPane.WARNING_MESSAGE);
3091 JInternalFrame frame = new JInternalFrame();
3092 frame.setContentPane(new PairwiseAlignPanel(viewport));
3093 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3103 public void PCAMenuItem_actionPerformed(ActionEvent e)
3105 if (((viewport.getSelectionGroup() != null)
3106 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3107 .getSelectionGroup().getSize() > 0))
3108 || (viewport.getAlignment().getHeight() < 4))
3110 JOptionPane.showInternalMessageDialog(this,
3111 "Principal component analysis must take\n"
3112 + "at least 4 input sequences.",
3113 "Sequence selection insufficient",
3114 JOptionPane.WARNING_MESSAGE);
3119 new PCAPanel(alignPanel);
3122 public void autoCalculate_actionPerformed(ActionEvent e)
3124 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3125 if (viewport.autoCalculateConsensus)
3127 viewport.firePropertyChange("alignment", null, viewport
3128 .getAlignment().getSequences());
3138 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3140 NewTreePanel("AV", "PID", "Average distance tree using PID");
3149 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3151 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3160 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3162 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3171 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3173 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3186 void NewTreePanel(String type, String pwType, String title)
3190 if (viewport.getSelectionGroup() != null)
3192 if (viewport.getSelectionGroup().getSize() < 3)
3197 "You need to have more than two sequences selected to build a tree!",
3198 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3203 SequenceGroup sg = viewport.getSelectionGroup();
3205 /* Decide if the selection is a column region */
3206 while (s < sg.getSize())
3208 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3214 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3215 + "Try using the Pad function in the edit menu,\n"
3216 + "or one of the multiple sequence alignment web services.",
3217 "Sequences in selection are not aligned",
3218 JOptionPane.WARNING_MESSAGE);
3224 title = title + " on region";
3225 tp = new TreePanel(alignPanel, type, pwType);
3229 // are the sequences aligned?
3230 if (!viewport.alignment.isAligned())
3235 "The sequences must be aligned before creating a tree.\n"
3236 + "Try using the Pad function in the edit menu,\n"
3237 + "or one of the multiple sequence alignment web services.",
3238 "Sequences not aligned",
3239 JOptionPane.WARNING_MESSAGE);
3244 if (viewport.alignment.getHeight() < 2)
3249 tp = new TreePanel(alignPanel, type, pwType);
3254 if (viewport.viewName != null)
3256 title += viewport.viewName + " of ";
3259 title += this.title;
3261 Desktop.addInternalFrame(tp, title, 600, 500);
3272 public void addSortByOrderMenuItem(String title,
3273 final AlignmentOrder order)
3275 final JMenuItem item = new JMenuItem("by " + title);
3277 item.addActionListener(new java.awt.event.ActionListener()
3279 public void actionPerformed(ActionEvent e)
3281 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3283 // TODO: JBPNote - have to map order entries to curent SequenceI
3285 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3287 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3288 viewport.alignment));
3290 alignPanel.paintAlignment(true);
3296 * Add a new sort by annotation score menu item
3299 * the menu to add the option to
3301 * the label used to retrieve scores for each sequence on the
3304 public void addSortByAnnotScoreMenuItem(JMenu sort,
3305 final String scoreLabel)
3307 final JMenuItem item = new JMenuItem(scoreLabel);
3309 item.addActionListener(new java.awt.event.ActionListener()
3311 public void actionPerformed(ActionEvent e)
3313 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3314 AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport
3315 .getAlignment());// ,viewport.getSelectionGroup());
3316 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3317 viewport.alignment));
3318 alignPanel.paintAlignment(true);
3324 * last hash for alignment's annotation array - used to minimise cost of
3327 protected int _annotationScoreVectorHash;
3330 * search the alignment and rebuild the sort by annotation score submenu the
3331 * last alignment annotation vector hash is stored to minimize cost of
3332 * rebuilding in subsequence calls.
3335 public void buildSortByAnnotationScoresMenu()
3337 if (viewport.alignment.getAlignmentAnnotation() == null)
3342 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3344 sortByAnnotScore.removeAll();
3345 // almost certainly a quicker way to do this - but we keep it simple
3346 Hashtable scoreSorts = new Hashtable();
3347 AlignmentAnnotation aann[];
3348 Enumeration sq = viewport.alignment.getSequences().elements();
3349 while (sq.hasMoreElements())
3351 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3352 for (int i = 0; aann != null && i < aann.length; i++)
3354 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3356 scoreSorts.put(aann[i].label, aann[i].label);
3360 Enumeration labels = scoreSorts.keys();
3361 while (labels.hasMoreElements())
3363 addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels
3366 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3369 _annotationScoreVectorHash = viewport.alignment
3370 .getAlignmentAnnotation().hashCode();
3375 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3376 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3377 * call. Listeners are added to remove the menu item when the treePanel is
3378 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3382 * Displayed tree window.
3384 * SortBy menu item title.
3386 public void buildTreeMenu()
3388 sortByTreeMenu.removeAll();
3390 Vector comps = (Vector) PaintRefresher.components.get(viewport
3391 .getSequenceSetId());
3392 Vector treePanels = new Vector();
3393 int i, iSize = comps.size();
3394 for (i = 0; i < iSize; i++)
3396 if (comps.elementAt(i) instanceof TreePanel)
3398 treePanels.add(comps.elementAt(i));
3402 iSize = treePanels.size();
3406 sortByTreeMenu.setVisible(false);
3410 sortByTreeMenu.setVisible(true);
3412 for (i = 0; i < treePanels.size(); i++)
3414 TreePanel tp = (TreePanel) treePanels.elementAt(i);
3415 final JMenuItem item = new JMenuItem(tp.getTitle());
3416 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3417 item.addActionListener(new java.awt.event.ActionListener()
3419 public void actionPerformed(ActionEvent e)
3421 SequenceI[] oldOrder = viewport.getAlignment()
3422 .getSequencesArray();
3423 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3425 addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
3426 viewport.alignment));
3428 alignPanel.paintAlignment(true);
3432 sortByTreeMenu.add(item);
3437 * Work out whether the whole set of sequences or just the selected set will
3438 * be submitted for multiple alignment.
3441 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3443 // Now, check we have enough sequences
3444 AlignmentView msa = null;
3446 if ((viewport.getSelectionGroup() != null)
3447 && (viewport.getSelectionGroup().getSize() > 1))
3449 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3450 // some common interface!
3452 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3453 * SequenceI[sz = seqs.getSize(false)];
3455 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3456 * seqs.getSequenceAt(i); }
3458 msa = viewport.getAlignmentView(true);
3463 * Vector seqs = viewport.getAlignment().getSequences();
3465 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3467 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3468 * seqs.elementAt(i); } }
3470 msa = viewport.getAlignmentView(false);
3476 * Decides what is submitted to a secondary structure prediction service: the
3477 * first sequence in the alignment, or in the current selection, or, if the
3478 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3479 * region or the whole alignment. (where the first sequence in the set is the
3480 * one that the prediction will be for).
3482 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3484 AlignmentView seqs = null;
3486 if ((viewport.getSelectionGroup() != null)
3487 && (viewport.getSelectionGroup().getSize() > 0))
3489 seqs = viewport.getAlignmentView(true);
3493 seqs = viewport.getAlignmentView(false);
3495 // limit sequences - JBPNote in future - could spawn multiple prediction
3497 // TODO: viewport.alignment.isAligned is a global state - the local
3498 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3499 if (!viewport.alignment.isAligned())
3501 seqs.setSequences(new SeqCigar[]
3502 { seqs.getSequences()[0] });
3513 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3515 // Pick the tree file
3516 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
3517 .getProperty("LAST_DIRECTORY"));
3518 chooser.setFileView(new JalviewFileView());
3519 chooser.setDialogTitle("Select a newick-like tree file");
3520 chooser.setToolTipText("Load a tree file");
3522 int value = chooser.showOpenDialog(null);
3524 if (value == JalviewFileChooser.APPROVE_OPTION)
3526 String choice = chooser.getSelectedFile().getPath();
3527 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3528 jalview.io.NewickFile fin = null;
3531 fin = new jalview.io.NewickFile(choice, "File");
3532 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3533 } catch (Exception ex)
3535 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3536 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3537 ex.printStackTrace();
3539 if (fin != null && fin.hasWarningMessage())
3541 JOptionPane.showMessageDialog(Desktop.desktop, fin
3542 .getWarningMessage(), "Possible problem with tree file",
3543 JOptionPane.WARNING_MESSAGE);
3548 public TreePanel ShowNewickTree(NewickFile nf, String title)
3550 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3553 public TreePanel ShowNewickTree(NewickFile nf, String title,
3554 AlignmentView input)
3556 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3559 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3560 int h, int x, int y)
3562 return ShowNewickTree(nf, title, null, w, h, x, y);
3566 * Add a treeviewer for the tree extracted from a newick file object to the
3567 * current alignment view
3574 * Associated alignment input data (or null)
3583 * @return TreePanel handle
3585 public TreePanel ShowNewickTree(NewickFile nf, String title,
3586 AlignmentView input, int w, int h, int x, int y)
3588 TreePanel tp = null;
3594 if (nf.getTree() != null)
3596 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3602 tp.setLocation(x, y);
3605 Desktop.addInternalFrame(tp, title, w, h);
3607 } catch (Exception ex)
3609 ex.printStackTrace();
3616 * Generates menu items and listener event actions for web service clients
3619 public void BuildWebServiceMenu()
3621 // TODO: add support for context dependent disabling of services based on
3622 // alignment and current selection
3623 // TODO: add additional serviceHandle parameter to specify abstract handler
3624 // class independently of AbstractName
3625 // TODO: add in rediscovery GUI function to restart discoverer
3626 // TODO: group services by location as well as function and/or introduce
3627 // object broker mechanism.
3628 if ((Discoverer.services != null) && (Discoverer.services.size() > 0))
3630 // TODO: refactor to allow list of AbstractName/Handler bindings to be
3631 // stored or retrieved from elsewhere
3632 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3633 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3634 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3635 // TODO: move GUI generation code onto service implementation - so a
3636 // client instance attaches itself to the GUI with method call like
3637 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
3639 Vector wsmenu = new Vector();
3640 final IProgressIndicator af = this;
3643 // Add any Multiple Sequence Alignment Services
3644 final JMenu msawsmenu = new JMenu("Alignment");
3645 for (int i = 0, j = msaws.size(); i < j; i++)
3647 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
3649 jalview.ws.WSClient impl = jalview.ws.Discoverer
3650 .getServiceClient(sh);
3651 impl.attachWSMenuEntry(msawsmenu, this);
3654 wsmenu.add(msawsmenu);
3656 if (secstrpr != null)
3658 // Add any secondary structure prediction services
3659 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3660 for (int i = 0, j = secstrpr.size(); i < j; i++)
3662 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
3664 jalview.ws.WSClient impl = jalview.ws.Discoverer
3665 .getServiceClient(sh);
3666 impl.attachWSMenuEntry(secstrmenu, this);
3668 wsmenu.add(secstrmenu);
3670 if (seqsrch != null)
3672 // Add any sequence search services
3673 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
3674 for (int i = 0, j = seqsrch.size(); i < j; i++)
3676 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
3678 jalview.ws.WSClient impl = jalview.ws.Discoverer
3679 .getServiceClient(sh);
3680 impl.attachWSMenuEntry(seqsrchmenu, this);
3682 // finally, add the whole shebang onto the webservices menu
3683 wsmenu.add(seqsrchmenu);
3685 resetWebServiceMenu();
3686 for (int i = 0, j = wsmenu.size(); i < j; i++)
3688 webService.add((JMenu) wsmenu.get(i));
3693 resetWebServiceMenu();
3694 this.webService.add(this.webServiceNoServices);
3699 * empty the web service menu and add any ad-hoc functions not dynamically
3703 private void resetWebServiceMenu()
3705 webService.removeAll();
3706 build_fetchdbmenu(webService);
3710 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
3711 * chooser = new JalviewFileChooser(jalview.bin.Cache.
3712 * getProperty("LAST_DIRECTORY"));
3714 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
3715 * to Vamsas file"); chooser.setToolTipText("Export");
3717 * int value = chooser.showSaveDialog(this);
3719 * if (value == JalviewFileChooser.APPROVE_OPTION) {
3720 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3721 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
3722 * chooser.getSelectedFile().getAbsolutePath(), this); } }
3725 * prototype of an automatically enabled/disabled analysis function
3728 protected void setShowProductsEnabled()
3730 SequenceI[] selection = viewport.getSequenceSelection();
3731 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
3732 viewport.getAlignment().getDataset()))
3734 showProducts.setEnabled(true);
3739 showProducts.setEnabled(false);
3744 * search selection for sequence xRef products and build the show products
3749 * @return true if showProducts menu should be enabled.
3751 public boolean canShowProducts(SequenceI[] selection,
3752 boolean isRegionSelection, Alignment dataset)
3754 boolean showp = false;
3757 showProducts.removeAll();
3758 final boolean dna = viewport.getAlignment().isNucleotide();
3759 final Alignment ds = dataset;
3760 String[] ptypes = (selection==null || selection.length==0) ? null
3761 : CrossRef.findSequenceXrefTypes(dna, selection,
3764 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
3765 // selection, dataset, true);
3766 final SequenceI[] sel = selection;
3767 for (int t = 0; ptypes != null && t < ptypes.length; t++)
3770 final boolean isRegSel = isRegionSelection;
3771 final AlignFrame af = this;
3772 final String source = ptypes[t];
3773 JMenuItem xtype = new JMenuItem(ptypes[t]);
3774 xtype.addActionListener(new ActionListener()
3777 public void actionPerformed(ActionEvent e)
3779 // TODO: new thread for this call with vis-delay
3780 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
3781 isRegSel, dna, source);
3785 showProducts.add(xtype);
3787 showProducts.setVisible(showp);
3788 showProducts.setEnabled(showp);
3789 } catch (Exception e)
3791 jalview.bin.Cache.log
3793 "canTranslate threw an exception - please report to help@jalview.org",
3800 protected void showProductsFor(SequenceI[] sel, Alignment ds,
3801 boolean isRegSel, boolean dna, String source)
3803 final boolean fisRegSel = isRegSel;
3804 final boolean fdna = dna;
3805 final String fsrc = source;
3806 final AlignFrame ths = this;
3807 final SequenceI[] fsel = sel;
3808 Runnable foo = new Runnable()
3813 final long sttime = System.currentTimeMillis();
3814 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
3817 Alignment ds = ths.getViewport().alignment.getDataset(); // update
3821 Alignment prods = CrossRef
3822 .findXrefSequences(fsel, fdna, fsrc, ds);
3825 SequenceI[] sprods = new SequenceI[prods.getHeight()];
3826 for (int s = 0; s < sprods.length; s++)
3828 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
3829 if (ds.getSequences() == null
3830 || !ds.getSequences().contains(
3831 sprods[s].getDatasetSequence()))
3832 ds.addSequence(sprods[s].getDatasetSequence());
3833 sprods[s].updatePDBIds();
3835 Alignment al = new Alignment(sprods);
3836 AlignedCodonFrame[] cf = prods.getCodonFrames();
3838 for (int s = 0; cf != null && s < cf.length; s++)
3840 al.addCodonFrame(cf[s]);
3843 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
3845 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
3846 + " for " + ((fisRegSel) ? "selected region of " : "")
3848 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
3853 System.err.println("No Sequences generated for xRef type "
3856 } catch (Exception e)
3858 jalview.bin.Cache.log.error(
3859 "Exception when finding crossreferences", e);
3860 } catch (OutOfMemoryError e)
3862 new OOMWarning("whilst fetching crossreferences", e);
3865 jalview.bin.Cache.log.error("Error when finding crossreferences",
3868 ths.setProgressBar("Finished searching for sequences from " + fsrc,
3873 Thread frunner = new Thread(foo);
3877 public boolean canShowTranslationProducts(SequenceI[] selection,
3878 AlignmentI alignment)
3883 return (jalview.analysis.Dna.canTranslate(selection, viewport
3884 .getViewAsVisibleContigs(true)));
3885 } catch (Exception e)
3887 jalview.bin.Cache.log
3889 "canTranslate threw an exception - please report to help@jalview.org",
3895 public void showProducts_actionPerformed(ActionEvent e)
3897 // /////////////////////////////
3898 // Collect Data to be translated/transferred
3900 SequenceI[] selection = viewport.getSequenceSelection();
3901 AlignmentI al = null;
3904 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
3905 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
3906 viewport.getAlignment().getDataset());
3907 } catch (Exception ex)
3910 jalview.bin.Cache.log.debug("Exception during translation.", ex);
3917 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3918 "Translation Failed", JOptionPane.WARNING_MESSAGE);
3922 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3923 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
3924 DEFAULT_WIDTH, DEFAULT_HEIGHT);
3928 public void showTranslation_actionPerformed(ActionEvent e)
3930 // /////////////////////////////
3931 // Collect Data to be translated/transferred
3933 SequenceI[] selection = viewport.getSequenceSelection();
3934 String[] seqstring = viewport.getViewAsString(true);
3935 AlignmentI al = null;
3938 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
3939 viewport.getViewAsVisibleContigs(true), viewport
3940 .getGapCharacter(), viewport.alignment
3941 .getAlignmentAnnotation(), viewport.alignment
3942 .getWidth(), viewport.getAlignment().getDataset());
3943 } catch (Exception ex)
3946 jalview.bin.Cache.log.debug("Exception during translation.", ex);
3953 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3954 "Translation Failed", JOptionPane.WARNING_MESSAGE);
3958 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3959 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
3960 DEFAULT_WIDTH, DEFAULT_HEIGHT);
3965 * Try to load a features file onto the alignment.
3968 * contents or path to retrieve file
3970 * access mode of file (see jalview.io.AlignFile)
3971 * @return true if features file was parsed corectly.
3973 public boolean parseFeaturesFile(String file, String type)
3975 boolean featuresFile = false;
3978 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment
3979 .getDataset(), alignPanel.seqPanel.seqCanvas
3980 .getFeatureRenderer().featureColours, false);
3981 } catch (Exception ex)
3983 ex.printStackTrace();
3988 viewport.showSequenceFeatures = true;
3989 showSeqFeatures.setSelected(true);
3990 if (alignPanel.seqPanel.seqCanvas.fr!=null)
3992 // update the min/max ranges where necessary
3993 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
3995 alignPanel.paintAlignment(true);
3998 return featuresFile;
4001 public void dragEnter(DropTargetDragEvent evt)
4005 public void dragExit(DropTargetEvent evt)
4009 public void dragOver(DropTargetDragEvent evt)
4013 public void dropActionChanged(DropTargetDragEvent evt)
4017 public void drop(DropTargetDropEvent evt)
4019 Transferable t = evt.getTransferable();
4020 java.util.List files = null;
4024 DataFlavor uriListFlavor = new DataFlavor(
4025 "text/uri-list;class=java.lang.String");
4026 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4028 // Works on Windows and MacOSX
4029 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4030 files = (java.util.List) t
4031 .getTransferData(DataFlavor.javaFileListFlavor);
4033 else if (t.isDataFlavorSupported(uriListFlavor))
4035 // This is used by Unix drag system
4036 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4037 String data = (String) t.getTransferData(uriListFlavor);
4038 files = new java.util.ArrayList(1);
4039 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4040 data, "\r\n"); st.hasMoreTokens();)
4042 String s = st.nextToken();
4043 if (s.startsWith("#"))
4045 // the line is a comment (as per the RFC 2483)
4049 java.net.URI uri = new java.net.URI(s);
4050 java.io.File file = new java.io.File(uri);
4054 } catch (Exception e)
4056 e.printStackTrace();
4063 for (int i = 0; i < files.size(); i++)
4065 loadJalviewDataFile(files.get(i).toString());
4067 } catch (Exception ex)
4069 ex.printStackTrace();
4075 * Attempt to load a "dropped" file: First by testing whether it's and
4076 * Annotation file, then a JNet file, and finally a features file. If all are
4077 * false then the user may have dropped an alignment file onto this
4081 * either a filename or a URL string.
4083 public void loadJalviewDataFile(String file)
4087 String protocol = "File";
4089 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
4094 boolean isAnnotation = new AnnotationFile().readAnnotationFile(
4095 viewport.alignment, file, protocol);
4099 // try to see if its a JNet 'concise' style annotation file *before* we
4100 // try to parse it as a features file
4101 String format = new IdentifyFile().Identify(file, protocol);
4102 if (format.equalsIgnoreCase("JnetFile"))
4104 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4106 new JnetAnnotationMaker().add_annotation(predictions, viewport
4107 .getAlignment(), 0, false);
4108 isAnnotation = true;
4112 // try to parse it as a features file
4113 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4114 // if it wasn't a features file then we just treat it as a general
4115 // alignment file to load into the current view.
4118 new FileLoader().LoadFile(viewport, file, protocol, format);
4122 alignPanel.paintAlignment(true);
4129 alignPanel.adjustAnnotationHeight();
4130 viewport.updateSequenceIdColours();
4131 buildSortByAnnotationScoresMenu();
4132 alignPanel.paintAlignment(true);
4134 } catch (Exception ex)
4136 ex.printStackTrace();
4140 public void tabSelectionChanged(int index)
4144 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4145 viewport = alignPanel.av;
4146 setMenusFromViewport(viewport);
4150 public void tabbedPane_mousePressed(MouseEvent e)
4152 if (SwingUtilities.isRightMouseButton(e))
4154 String reply = JOptionPane.showInternalInputDialog(this,
4155 "Enter View Name", "Edit View Name",
4156 JOptionPane.QUESTION_MESSAGE);
4160 viewport.viewName = reply;
4161 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4166 public AlignViewport getCurrentView()
4172 * Open the dialog for regex description parsing.
4174 protected void extractScores_actionPerformed(ActionEvent e)
4176 ParseProperties pp = new jalview.analysis.ParseProperties(
4177 viewport.alignment);
4178 // TODO: verify regex and introduce GUI dialog for version 2.5
4179 // if (pp.getScoresFromDescription("col", "score column ",
4180 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4182 if (pp.getScoresFromDescription("description column",
4183 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4185 buildSortByAnnotationScoresMenu();
4190 * @see jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent)
4192 protected void showDbRefs_actionPerformed(ActionEvent e)
4194 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4198 * @see jalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.ActionEvent)
4200 protected void showNpFeats_actionPerformed(ActionEvent e)
4202 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4206 * find the viewport amongst the tabs in this alignment frame and close that tab
4209 public boolean closeView(AlignViewport av)
4213 this.closeMenuItem_actionPerformed(false);
4216 Component[] comp = tabbedPane.getComponents();
4217 for (int i=0;comp!=null && i<comp.length;i++)
4219 if (comp[i] instanceof AlignmentPanel)
4221 if (((AlignmentPanel) comp[i]).av == av)
4224 closeView((AlignmentPanel) comp[i]);
4231 protected void build_fetchdbmenu(JMenu webService) {
4232 // Temporary hack - DBRef Fetcher always top level ws entry.
4233 // TODO We probably want to store a sequence database checklist in preferences and have checkboxes.. rather than individual sources selected here
4234 JMenu rfetch = new JMenu("Fetch DB References");
4236 .setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4237 webService.add(rfetch);
4239 JMenuItem fetchr = new JMenuItem("Standard Databases");
4240 fetchr.setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4241 fetchr.addActionListener(new ActionListener()
4244 public void actionPerformed(ActionEvent e)
4246 new Thread(new Runnable()
4251 new jalview.ws.DBRefFetcher(alignPanel.av
4252 .getSequenceSelection(), alignPanel.alignFrame)
4253 .fetchDBRefs(false);
4261 JMenu dfetch = new JMenu();
4263 jalview.ws.SequenceFetcher sf = SequenceFetcher.getSequenceFetcherSingleton(this);
4264 String[] otherdb = sf.getOrderedSupportedSources();
4265 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4266 // jalview.util.QuickSort.sort(otherdb, otherdb);
4267 int comp=0,mcomp=15;
4269 if (otherdb!=null && otherdb.length>0)
4271 for (int i=0; i<otherdb.length; i++)
4273 String dbname =sf.getSourceProxy(otherdb[i]).getDbName();
4276 mname = "from '"+dbname+"'";
4278 fetchr = new JMenuItem(otherdb[i]);
4279 final String[] dassource = new String[] { otherdb[i] };
4280 fetchr.addActionListener(new ActionListener()
4283 public void actionPerformed(ActionEvent e)
4285 new Thread(new Runnable()
4290 new jalview.ws.DBRefFetcher(alignPanel.av
4291 .getSequenceSelection(), alignPanel.alignFrame, dassource)
4292 .fetchDBRefs(false);
4298 fetchr.setToolTipText("Retrieve from "+dbname);
4300 if (comp++==mcomp || i==(otherdb.length-1))
4302 dfetch.setText(mname+" to '"+dbname+"'");
4304 dfetch = new JMenu();
4312 * Left justify the whole alignment.
4314 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4316 AlignmentI al = viewport.getAlignment();
4318 viewport.firePropertyChange("alignment", null, al);
4321 * Right justify the whole alignment.
4323 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4325 AlignmentI al = viewport.getAlignment();
4327 viewport.firePropertyChange("alignment", null, al);
4329 public void setShowSeqFeatures(boolean b)
4331 showSeqFeatures.setSelected(true);
4332 viewport.setShowSequenceFeatures(true);
4335 * @see jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.awt.event.ActionEvent)
4337 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
4339 viewport.setShowUnconserved(showUnconservedMenuItem.getState());
4340 alignPanel.paintAlignment(true);
4344 class PrintThread extends Thread
4348 public PrintThread(AlignmentPanel ap)
4353 static PageFormat pf;
4357 PrinterJob printJob = PrinterJob.getPrinterJob();
4361 printJob.setPrintable(ap, pf);
4365 printJob.setPrintable(ap);
4368 if (printJob.printDialog())
4373 } catch (Exception PrintException)
4375 PrintException.printStackTrace();