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);
86 * Creates a new AlignFrame object with specific width, height and
92 * @param sequenceSetId
94 public AlignFrame(AlignmentI al, int width, int height,
97 this(al, null, width, height, sequenceSetId);
101 * Creates a new AlignFrame object with specific width, height and
107 * @param sequenceSetId
110 public AlignFrame(AlignmentI al, int width, int height,
111 String sequenceSetId, String viewId)
113 this(al, null, width, height, sequenceSetId, viewId);
117 * new alignment window with hidden columns
121 * @param hiddenColumns
122 * ColumnSelection or null
124 * Width of alignment frame
128 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
129 int width, int height)
131 this(al, hiddenColumns, width, height, null);
135 * Create alignment frame for al with hiddenColumns, a specific width and
136 * height, and specific sequenceId
139 * @param hiddenColumns
142 * @param sequenceSetId
145 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
146 int width, int height, String sequenceSetId)
148 this(al, hiddenColumns, width, height, sequenceSetId, null);
152 * Create alignment frame for al with hiddenColumns, a specific width and
153 * height, and specific sequenceId
156 * @param hiddenColumns
159 * @param sequenceSetId
164 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
165 int width, int height, String sequenceSetId, String viewId)
167 setSize(width, height);
168 viewport = new AlignViewport(al, hiddenColumns, sequenceSetId, viewId);
170 alignPanel = new AlignmentPanel(this, viewport);
172 if (al.getDataset() == null)
177 addAlignmentPanel(alignPanel, true);
182 * Make a new AlignFrame from exisiting alignmentPanels
189 public AlignFrame(AlignmentPanel ap)
193 addAlignmentPanel(ap, false);
198 * initalise the alignframe from the underlying viewport data and the
203 if (viewport.conservation == null)
205 BLOSUM62Colour.setEnabled(false);
206 conservationMenuItem.setEnabled(false);
207 modifyConservation.setEnabled(false);
208 // PIDColour.setEnabled(false);
209 // abovePIDThreshold.setEnabled(false);
210 // modifyPID.setEnabled(false);
213 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT",
216 if (sortby.equals("Id"))
218 sortIDMenuItem_actionPerformed(null);
220 else if (sortby.equals("Pairwise Identity"))
222 sortPairwiseMenuItem_actionPerformed(null);
225 if (Desktop.desktop != null)
227 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
228 addServiceListeners();
229 setGUINucleotide(viewport.alignment.isNucleotide());
232 setMenusFromViewport(viewport);
233 buildSortByAnnotationScoresMenu();
234 if (viewport.wrapAlignment)
236 wrapMenuItem_actionPerformed(null);
239 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false))
241 this.overviewMenuItem_actionPerformed(null);
249 * Change the filename and format for the alignment, and enable the 'reload'
250 * button functionality.
257 public void setFileName(String file, String format)
260 currentFileFormat = format;
261 reload.setEnabled(true);
264 void addKeyListener()
266 addKeyListener(new KeyAdapter()
268 public void keyPressed(KeyEvent evt)
270 if (viewport.cursorMode
271 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
272 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
273 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
274 && Character.isDigit(evt.getKeyChar()))
275 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
277 switch (evt.getKeyCode())
280 case 27: // escape key
281 deselectAllSequenceMenuItem_actionPerformed(null);
285 case KeyEvent.VK_DOWN:
286 if (evt.isAltDown() || !viewport.cursorMode)
287 moveSelectedSequences(false);
288 if (viewport.cursorMode)
289 alignPanel.seqPanel.moveCursor(0, 1);
293 if (evt.isAltDown() || !viewport.cursorMode)
294 moveSelectedSequences(true);
295 if (viewport.cursorMode)
296 alignPanel.seqPanel.moveCursor(0, -1);
300 case KeyEvent.VK_LEFT:
301 if (evt.isAltDown() || !viewport.cursorMode)
302 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
304 alignPanel.seqPanel.moveCursor(-1, 0);
308 case KeyEvent.VK_RIGHT:
309 if (evt.isAltDown() || !viewport.cursorMode)
310 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
312 alignPanel.seqPanel.moveCursor(1, 0);
315 case KeyEvent.VK_SPACE:
316 if (viewport.cursorMode)
318 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
319 || evt.isShiftDown() || evt.isAltDown());
323 case KeyEvent.VK_DELETE:
324 case KeyEvent.VK_BACK_SPACE:
325 if (!viewport.cursorMode)
327 cut_actionPerformed(null);
331 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
332 || evt.isShiftDown() || evt.isAltDown());
338 if (viewport.cursorMode)
340 alignPanel.seqPanel.setCursorRow();
344 if (viewport.cursorMode && !evt.isControlDown())
346 alignPanel.seqPanel.setCursorColumn();
350 if (viewport.cursorMode)
352 alignPanel.seqPanel.setCursorPosition();
356 case KeyEvent.VK_ENTER:
357 case KeyEvent.VK_COMMA:
358 if (viewport.cursorMode)
360 alignPanel.seqPanel.setCursorRowAndColumn();
365 if (viewport.cursorMode)
367 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
371 if (viewport.cursorMode)
373 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
378 viewport.cursorMode = !viewport.cursorMode;
379 statusBar.setText("Keyboard editing mode is "
380 + (viewport.cursorMode ? "on" : "off"));
381 if (viewport.cursorMode)
383 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
384 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
386 alignPanel.seqPanel.seqCanvas.repaint();
392 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
393 java.net.URL url = javax.help.HelpSet.findHelpSet(cl,
395 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
397 javax.help.HelpBroker hb = hs.createHelpBroker();
398 hb.setCurrentID("home");
399 hb.setDisplayed(true);
400 } catch (Exception ex)
402 ex.printStackTrace();
407 boolean toggleSeqs = !evt.isControlDown();
408 boolean toggleCols = !evt.isShiftDown();
410 boolean hide = false;
412 SequenceGroup sg = viewport.getSelectionGroup();
416 && sg.getSize() != viewport.alignment.getHeight())
418 hideSelSequences_actionPerformed(null);
421 else if (!(toggleCols && viewport.colSel.getSelected().size() > 0))
423 showAllSeqs_actionPerformed(null);
429 if (viewport.colSel.getSelected().size() > 0)
431 hideSelColumns_actionPerformed(null);
434 viewport.selectionGroup = sg;
439 showAllColumns_actionPerformed(null);
444 case KeyEvent.VK_PAGE_UP:
445 if (viewport.wrapAlignment)
447 alignPanel.scrollUp(true);
451 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
452 - viewport.endSeq + viewport.startSeq);
455 case KeyEvent.VK_PAGE_DOWN:
456 if (viewport.wrapAlignment)
458 alignPanel.scrollUp(false);
462 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
463 + viewport.endSeq - viewport.startSeq);
469 public void keyReleased(KeyEvent evt)
471 switch (evt.getKeyCode())
473 case KeyEvent.VK_LEFT:
474 if (evt.isAltDown() || !viewport.cursorMode)
475 viewport.firePropertyChange("alignment", null, viewport
476 .getAlignment().getSequences());
479 case KeyEvent.VK_RIGHT:
480 if (evt.isAltDown() || !viewport.cursorMode)
481 viewport.firePropertyChange("alignment", null, viewport
482 .getAlignment().getSequences());
489 public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel)
491 ap.alignFrame = this;
493 alignPanels.addElement(ap);
495 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
497 int aSize = alignPanels.size();
499 tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null);
501 if (aSize == 1 && ap.av.viewName == null)
503 this.getContentPane().add(ap, BorderLayout.CENTER);
509 setInitialTabVisible();
512 expandViews.setEnabled(true);
513 gatherViews.setEnabled(true);
514 tabbedPane.addTab(ap.av.viewName, ap);
516 ap.setVisible(false);
523 ap.av.alignment.padGaps();
525 ap.av.updateConservation(ap);
526 ap.av.updateConsensus(ap);
530 public void setInitialTabVisible()
532 expandViews.setEnabled(true);
533 gatherViews.setEnabled(true);
534 tabbedPane.setVisible(true);
535 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
536 tabbedPane.addTab(first.av.viewName, first);
537 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
540 public AlignViewport getViewport()
545 /* Set up intrinsic listeners for dynamically generated GUI bits. */
546 private void addServiceListeners()
548 final java.beans.PropertyChangeListener thisListener;
549 // Do this once to get current state
550 BuildWebServiceMenu();
552 .addPropertyChangeListener(thisListener = new java.beans.PropertyChangeListener()
554 public void propertyChange(PropertyChangeEvent evt)
556 // System.out.println("Discoverer property change.");
557 if (evt.getPropertyName().equals("services"))
559 // System.out.println("Rebuilding web service menu");
560 BuildWebServiceMenu();
565 addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
567 public void internalFrameClosed(
568 javax.swing.event.InternalFrameEvent evt)
570 // System.out.println("deregistering discoverer listener");
571 Desktop.discoverer.removePropertyChangeListener(thisListener);
572 closeMenuItem_actionPerformed(true);
577 public void setGUINucleotide(boolean nucleotide)
579 showTranslation.setVisible(nucleotide);
580 conservationMenuItem.setEnabled(!nucleotide);
581 modifyConservation.setEnabled(!nucleotide);
583 // Remember AlignFrame always starts as protein
586 calculateMenu.remove(calculateMenu.getItemCount() - 2);
591 * set up menus for the currently viewport. This may be called after any
592 * operation that affects the data in the current view (selection changed,
593 * etc) to update the menus to reflect the new state.
595 public void setMenusForViewport()
597 setMenusFromViewport(viewport);
601 * Need to call this method when tabs are selected for multiple views, or when
602 * loading from Jalview2XML.java
607 void setMenusFromViewport(AlignViewport av)
609 padGapsMenuitem.setSelected(av.padGaps);
610 colourTextMenuItem.setSelected(av.showColourText);
611 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
612 conservationMenuItem.setSelected(av.getConservationSelected());
613 seqLimits.setSelected(av.getShowJVSuffix());
614 idRightAlign.setSelected(av.rightAlignIds);
615 centreColumnLabelsMenuItem.setState(av.centreColumnLabels);
616 renderGapsMenuItem.setSelected(av.renderGaps);
617 wrapMenuItem.setSelected(av.wrapAlignment);
618 scaleAbove.setVisible(av.wrapAlignment);
619 scaleLeft.setVisible(av.wrapAlignment);
620 scaleRight.setVisible(av.wrapAlignment);
621 annotationPanelMenuItem.setState(av.showAnnotation);
622 viewBoxesMenuItem.setSelected(av.showBoxes);
623 viewTextMenuItem.setSelected(av.showText);
624 showUnconservedMenuItem.setSelected(av.showUnconserved);
625 setColourSelected(ColourSchemeProperty.getColourName(av
626 .getGlobalColourScheme()));
628 showSeqFeatures.setSelected(av.showSequenceFeatures);
629 hiddenMarkers.setState(av.showHiddenMarkers);
630 applyToAllGroups.setState(av.colourAppliesToAllGroups);
631 showNpFeatsMenuitem.setSelected(av.isShowNpFeats());
632 showDbRefsMenuitem.setSelected(av.isShowDbRefs());
634 setShowProductsEnabled();
639 Hashtable progressBars, progressBarHandlers;
644 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
646 public void setProgressBar(String message, long id)
648 if (progressBars == null)
650 progressBars = new Hashtable();
651 progressBarHandlers = new Hashtable();
654 JPanel progressPanel;
655 GridLayout layout = (GridLayout) statusPanel.getLayout();
656 if (progressBars.get(new Long(id)) != null)
658 progressPanel = (JPanel) progressBars.get(new Long(id));
659 statusPanel.remove(progressPanel);
660 progressBars.remove(progressPanel);
661 progressPanel = null;
664 statusBar.setText(message);
666 if (progressBarHandlers.contains(new Long(id)))
668 progressBarHandlers.remove(new Long(id));
670 layout.setRows(layout.getRows() - 1);
674 progressPanel = new JPanel(new BorderLayout(10, 5));
676 JProgressBar progressBar = new JProgressBar();
677 progressBar.setIndeterminate(true);
679 progressPanel.add(new JLabel(message), BorderLayout.WEST);
680 progressPanel.add(progressBar, BorderLayout.CENTER);
682 layout.setRows(layout.getRows() + 1);
683 statusPanel.add(progressPanel);
685 progressBars.put(new Long(id), progressPanel);
688 setMenusForViewport();
692 public void registerHandler(final long id,
693 final IProgressIndicatorHandler handler)
695 if (progressBarHandlers == null || !progressBars.contains(new Long(id)))
698 "call setProgressBar before registering the progress bar's handler.");
700 progressBarHandlers.put(new Long(id), handler);
701 final JPanel progressPanel = (JPanel) progressBars.get(new Long(id));
702 if (handler.canCancel())
704 JButton cancel = new JButton("Cancel");
705 final IProgressIndicator us = this;
706 cancel.addActionListener(new ActionListener()
709 public void actionPerformed(ActionEvent e)
711 handler.cancelActivity(id);
712 us.setProgressBar("Cancelled "
713 + ((JLabel) progressPanel.getComponent(0)).getText(), id);
716 progressPanel.add(cancel, BorderLayout.EAST);
722 * @return true if any progress bars are still active
724 public boolean operationInProgress()
726 if (progressBars != null && progressBars.size() > 0)
734 * Added so Castor Mapping file can obtain Jalview Version
736 public String getVersion()
738 return jalview.bin.Cache.getProperty("VERSION");
741 public FeatureRenderer getFeatureRenderer()
743 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
746 public void fetchSequence_actionPerformed(ActionEvent e)
748 new SequenceFetcher(this);
751 public void addFromFile_actionPerformed(ActionEvent e)
753 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
756 public void reload_actionPerformed(ActionEvent e)
758 if (fileName != null)
760 if (currentFileFormat.equals("Jalview"))
762 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
763 for (int i = 0; i < frames.length; i++)
765 if (frames[i] instanceof AlignFrame && frames[i] != this
766 && ((AlignFrame) frames[i]).fileName.equals(fileName))
770 frames[i].setSelected(true);
771 Desktop.instance.closeAssociatedWindows();
772 } catch (java.beans.PropertyVetoException ex)
778 Desktop.instance.closeAssociatedWindows();
780 FileLoader loader = new FileLoader();
781 String protocol = fileName.startsWith("http:") ? "URL" : "File";
782 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
786 Rectangle bounds = this.getBounds();
788 FileLoader loader = new FileLoader();
789 String protocol = fileName.startsWith("http:") ? "URL" : "File";
790 AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName,
791 protocol, currentFileFormat);
793 newframe.setBounds(bounds);
795 this.closeMenuItem_actionPerformed(true);
800 public void addFromText_actionPerformed(ActionEvent e)
802 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
805 public void addFromURL_actionPerformed(ActionEvent e)
807 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
810 public void save_actionPerformed(ActionEvent e)
813 || (currentFileFormat == null || !jalview.io.FormatAdapter
814 .isValidIOFormat(currentFileFormat, true))
815 || fileName.startsWith("http"))
817 saveAs_actionPerformed(null);
821 saveAlignment(fileName, currentFileFormat);
831 public void saveAs_actionPerformed(ActionEvent e)
833 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
834 .getProperty("LAST_DIRECTORY"),
835 jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
836 jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
837 currentFileFormat, false);
839 chooser.setFileView(new JalviewFileView());
840 chooser.setDialogTitle("Save Alignment to file");
841 chooser.setToolTipText("Save");
843 int value = chooser.showSaveDialog(this);
845 if (value == JalviewFileChooser.APPROVE_OPTION)
847 currentFileFormat = chooser.getSelectedFormat();
848 if (currentFileFormat == null)
850 JOptionPane.showInternalMessageDialog(Desktop.desktop,
851 "You must select a file format before saving!",
852 "File format not specified", JOptionPane.WARNING_MESSAGE);
853 value = chooser.showSaveDialog(this);
857 fileName = chooser.getSelectedFile().getPath();
859 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
862 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
863 if (currentFileFormat.indexOf(" ") > -1)
865 currentFileFormat = currentFileFormat.substring(0,
866 currentFileFormat.indexOf(" "));
868 saveAlignment(fileName, currentFileFormat);
872 public boolean saveAlignment(String file, String format)
874 boolean success = true;
876 if (format.equalsIgnoreCase("Jalview"))
878 String shortName = title;
880 if (shortName.indexOf(java.io.File.separatorChar) > -1)
882 shortName = shortName.substring(shortName
883 .lastIndexOf(java.io.File.separatorChar) + 1);
886 success = new Jalview2XML().SaveAlignment(this, file, shortName);
888 statusBar.setText("Successfully saved to file: " + fileName + " in "
889 + format + " format.");
894 if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
896 // JBPNote need to have a raise_gui flag here
897 JOptionPane.showInternalMessageDialog(this, "Cannot save file "
898 + fileName + " using format " + format,
899 "Alignment output format not supported",
900 JOptionPane.WARNING_MESSAGE);
901 saveAs_actionPerformed(null);
905 String[] omitHidden = null;
907 if (viewport.hasHiddenColumns)
909 int reply = JOptionPane
910 .showInternalConfirmDialog(
912 "The Alignment contains hidden columns."
913 + "\nDo you want to save only the visible alignment?",
914 "Save / Omit Hidden Columns",
915 JOptionPane.YES_NO_OPTION,
916 JOptionPane.QUESTION_MESSAGE);
918 if (reply == JOptionPane.YES_OPTION)
920 omitHidden = viewport.getViewAsString(false);
923 FormatAdapter f = new FormatAdapter();
924 String output = f.formatSequences(format,
925 (Alignment) viewport.alignment, // class cast exceptions will
926 // occur in the distant future
927 omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
937 java.io.PrintWriter out = new java.io.PrintWriter(
938 new java.io.FileWriter(file));
943 statusBar.setText("Successfully saved to file: " + fileName
944 + " in " + format + " format.");
945 } catch (Exception ex)
948 ex.printStackTrace();
955 JOptionPane.showInternalMessageDialog(this, "Couldn't save file: "
956 + fileName, "Error Saving File", JOptionPane.WARNING_MESSAGE);
968 protected void outputText_actionPerformed(ActionEvent e)
970 String[] omitHidden = null;
972 if (viewport.hasHiddenColumns)
974 int reply = JOptionPane
975 .showInternalConfirmDialog(
977 "The Alignment contains hidden columns."
978 + "\nDo you want to output only the visible alignment?",
979 "Save / Omit Hidden Columns",
980 JOptionPane.YES_NO_OPTION,
981 JOptionPane.QUESTION_MESSAGE);
983 if (reply == JOptionPane.YES_OPTION)
985 omitHidden = viewport.getViewAsString(false);
989 CutAndPasteTransfer cap = new CutAndPasteTransfer();
990 cap.setForInput(null);
991 Desktop.addInternalFrame(cap, "Alignment output - "
992 + e.getActionCommand(), 600, 500);
994 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
995 viewport.alignment, omitHidden, viewport.colSel));
1004 protected void htmlMenuItem_actionPerformed(ActionEvent e)
1006 new HTMLOutput(alignPanel, alignPanel.seqPanel.seqCanvas
1007 .getSequenceRenderer(), alignPanel.seqPanel.seqCanvas
1008 .getFeatureRenderer());
1011 public void createImageMap(File file, String image)
1013 alignPanel.makePNGImageMap(file, image);
1022 public void createPNG(File f)
1024 alignPanel.makePNG(f);
1033 public void createEPS(File f)
1035 alignPanel.makeEPS(f);
1038 public void pageSetup_actionPerformed(ActionEvent e)
1040 PrinterJob printJob = PrinterJob.getPrinterJob();
1041 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
1050 public void printMenuItem_actionPerformed(ActionEvent e)
1052 // Putting in a thread avoids Swing painting problems
1053 PrintThread thread = new PrintThread(alignPanel);
1057 public void exportFeatures_actionPerformed(ActionEvent e)
1059 new AnnotationExporter().exportFeatures(alignPanel);
1062 public void exportAnnotations_actionPerformed(ActionEvent e)
1064 new AnnotationExporter().exportAnnotations(alignPanel,
1065 viewport.showAnnotation ? viewport.alignment
1066 .getAlignmentAnnotation() : null, viewport.alignment
1068 ((Alignment) viewport.alignment).alignmentProperties);
1071 public void associatedData_actionPerformed(ActionEvent e)
1073 // Pick the tree file
1074 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
1075 .getProperty("LAST_DIRECTORY"));
1076 chooser.setFileView(new JalviewFileView());
1077 chooser.setDialogTitle("Load Jalview Annotations or Features File");
1078 chooser.setToolTipText("Load Jalview Annotations / Features file");
1080 int value = chooser.showOpenDialog(null);
1082 if (value == JalviewFileChooser.APPROVE_OPTION)
1084 String choice = chooser.getSelectedFile().getPath();
1085 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1086 loadJalviewDataFile(choice);
1092 * Close the current view or all views in the alignment frame. If the frame
1093 * only contains one view then the alignment will be removed from memory.
1095 * @param closeAllTabs
1097 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
1099 if (alignPanels != null && alignPanels.size() < 2)
1101 closeAllTabs = true;
1106 if (alignPanels != null)
1110 if (this.isClosed())
1112 // really close all the windows - otherwise wait till
1113 // setClosed(true) is called
1114 for (int i = 0; i < alignPanels.size(); i++)
1116 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
1123 closeView(alignPanel);
1129 this.setClosed(true);
1131 } catch (Exception ex)
1133 ex.printStackTrace();
1138 * close alignPanel2 and shuffle tabs appropriately.
1140 * @param alignPanel2
1142 public void closeView(AlignmentPanel alignPanel2)
1144 int index = tabbedPane.getSelectedIndex();
1145 int closedindex = tabbedPane.indexOfComponent(alignPanel2);
1146 alignPanels.removeElement(alignPanel2);
1148 // if (viewport == alignPanel2.av)
1152 alignPanel2.closePanel();
1155 tabbedPane.removeTabAt(closedindex);
1156 tabbedPane.validate();
1158 if (index > closedindex || index == tabbedPane.getTabCount())
1160 // modify currently selected tab index if necessary.
1164 this.tabSelectionChanged(index);
1170 void updateEditMenuBar()
1173 if (viewport.historyList.size() > 0)
1175 undoMenuItem.setEnabled(true);
1176 CommandI command = (CommandI) viewport.historyList.peek();
1177 undoMenuItem.setText("Undo " + command.getDescription());
1181 undoMenuItem.setEnabled(false);
1182 undoMenuItem.setText("Undo");
1185 if (viewport.redoList.size() > 0)
1187 redoMenuItem.setEnabled(true);
1189 CommandI command = (CommandI) viewport.redoList.peek();
1190 redoMenuItem.setText("Redo " + command.getDescription());
1194 redoMenuItem.setEnabled(false);
1195 redoMenuItem.setText("Redo");
1199 public void addHistoryItem(CommandI command)
1201 if (command.getSize() > 0)
1203 viewport.historyList.push(command);
1204 viewport.redoList.clear();
1205 updateEditMenuBar();
1206 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1212 * @return alignment objects for all views
1214 AlignmentI[] getViewAlignments()
1216 if (alignPanels != null)
1218 Enumeration e = alignPanels.elements();
1219 AlignmentI[] als = new AlignmentI[alignPanels.size()];
1220 for (int i = 0; e.hasMoreElements(); i++)
1222 als[i] = ((AlignmentPanel) e.nextElement()).av.getAlignment();
1226 if (viewport != null)
1228 return new AlignmentI[]
1229 { viewport.alignment };
1240 protected void undoMenuItem_actionPerformed(ActionEvent e)
1242 if (viewport.historyList.empty())
1244 CommandI command = (CommandI) viewport.historyList.pop();
1245 viewport.redoList.push(command);
1246 command.undoCommand(getViewAlignments());
1248 AlignViewport originalSource = getOriginatingSource(command);
1249 updateEditMenuBar();
1251 if (originalSource != null)
1253 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1254 originalSource.firePropertyChange("alignment", null,
1255 originalSource.alignment.getSequences());
1265 protected void redoMenuItem_actionPerformed(ActionEvent e)
1267 if (viewport.redoList.size() < 1)
1272 CommandI command = (CommandI) viewport.redoList.pop();
1273 viewport.historyList.push(command);
1274 command.doCommand(getViewAlignments());
1276 AlignViewport originalSource = getOriginatingSource(command);
1277 updateEditMenuBar();
1279 if (originalSource != null)
1281 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1282 originalSource.firePropertyChange("alignment", null,
1283 originalSource.alignment.getSequences());
1287 AlignViewport getOriginatingSource(CommandI command)
1289 AlignViewport originalSource = null;
1290 // For sequence removal and addition, we need to fire
1291 // the property change event FROM the viewport where the
1292 // original alignment was altered
1293 AlignmentI al = null;
1294 if (command instanceof EditCommand)
1296 EditCommand editCommand = (EditCommand) command;
1297 al = editCommand.getAlignment();
1298 Vector comps = (Vector) PaintRefresher.components.get(viewport
1299 .getSequenceSetId());
1301 for (int i = 0; i < comps.size(); i++)
1303 if (comps.elementAt(i) instanceof AlignmentPanel)
1305 if (al == ((AlignmentPanel) comps.elementAt(i)).av.alignment)
1307 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1314 if (originalSource == null)
1316 // The original view is closed, we must validate
1317 // the current view against the closed view first
1320 PaintRefresher.validateSequences(al, viewport.alignment);
1323 originalSource = viewport;
1326 return originalSource;
1335 public void moveSelectedSequences(boolean up)
1337 SequenceGroup sg = viewport.getSelectionGroup();
1346 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1348 SequenceI seq = viewport.alignment.getSequenceAt(i);
1350 if (!sg.getSequences(null).contains(seq))
1355 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1357 if (sg.getSequences(null).contains(temp))
1362 viewport.alignment.getSequences().setElementAt(temp, i);
1363 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1368 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1370 SequenceI seq = viewport.alignment.getSequenceAt(i);
1372 if (!sg.getSequences(null).contains(seq))
1377 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1379 if (sg.getSequences(null).contains(temp))
1384 viewport.alignment.getSequences().setElementAt(temp, i);
1385 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1389 alignPanel.paintAlignment(true);
1392 synchronized void slideSequences(boolean right, int size)
1394 Vector sg = new Vector();
1395 if (viewport.cursorMode)
1397 sg.addElement(viewport.alignment
1398 .getSequenceAt(alignPanel.seqPanel.seqCanvas.cursorY));
1400 else if (viewport.getSelectionGroup() != null
1401 && viewport.getSelectionGroup().getSize() != viewport.alignment
1404 sg = viewport.getSelectionGroup().getSequences(
1405 viewport.hiddenRepSequences);
1413 Vector invertGroup = new Vector();
1415 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1417 if (!sg.contains(viewport.alignment.getSequenceAt(i)))
1418 invertGroup.add(viewport.alignment.getSequenceAt(i));
1421 SequenceI[] seqs1 = new SequenceI[sg.size()];
1422 for (int i = 0; i < sg.size(); i++)
1423 seqs1[i] = (SequenceI) sg.elementAt(i);
1425 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1426 for (int i = 0; i < invertGroup.size(); i++)
1427 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1429 SlideSequencesCommand ssc;
1431 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1432 size, viewport.getGapCharacter());
1434 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1435 size, viewport.getGapCharacter());
1437 int groupAdjustment = 0;
1438 if (ssc.getGapsInsertedBegin() && right)
1440 if (viewport.cursorMode)
1441 alignPanel.seqPanel.moveCursor(size, 0);
1443 groupAdjustment = size;
1445 else if (!ssc.getGapsInsertedBegin() && !right)
1447 if (viewport.cursorMode)
1448 alignPanel.seqPanel.moveCursor(-size, 0);
1450 groupAdjustment = -size;
1453 if (groupAdjustment != 0)
1455 viewport.getSelectionGroup().setStartRes(
1456 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1457 viewport.getSelectionGroup().setEndRes(
1458 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1461 boolean appendHistoryItem = false;
1462 if (viewport.historyList != null && viewport.historyList.size() > 0
1463 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1465 appendHistoryItem = ssc
1466 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1470 if (!appendHistoryItem)
1471 addHistoryItem(ssc);
1482 protected void copy_actionPerformed(ActionEvent e)
1485 if (viewport.getSelectionGroup() == null)
1489 // TODO: preserve the ordering of displayed alignment annotation in any
1490 // internal paste (particularly sequence associated annotation)
1491 SequenceI[] seqs = viewport.getSelectionAsNewSequence();
1492 String[] omitHidden = null;
1494 if (viewport.hasHiddenColumns)
1496 omitHidden = viewport.getViewAsString(true);
1499 String output = new FormatAdapter().formatSequences("Fasta", seqs,
1502 StringSelection ss = new StringSelection(output);
1506 jalview.gui.Desktop.internalCopy = true;
1507 // Its really worth setting the clipboard contents
1508 // to empty before setting the large StringSelection!!
1509 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
1510 new StringSelection(""), null);
1512 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,
1514 } catch (OutOfMemoryError er)
1516 new OOMWarning("copying region", er);
1520 Vector hiddenColumns = null;
1521 if (viewport.hasHiddenColumns)
1523 hiddenColumns = new Vector();
1524 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1525 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1528 int[] region = (int[]) viewport.getColumnSelection()
1529 .getHiddenColumns().elementAt(i);
1531 hiddenColumns.addElement(new int[]
1532 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1536 Desktop.jalviewClipboard = new Object[]
1537 { seqs, viewport.alignment.getDataset(), hiddenColumns };
1538 statusBar.setText("Copied " + seqs.length + " sequences to clipboard.");
1547 protected void pasteNew_actionPerformed(ActionEvent e)
1558 protected void pasteThis_actionPerformed(ActionEvent e)
1564 * Paste contents of Jalview clipboard
1566 * @param newAlignment
1567 * true to paste to a new alignment, otherwise add to this.
1569 void paste(boolean newAlignment)
1571 boolean externalPaste = true;
1574 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1575 Transferable contents = c.getContents(this);
1577 if (contents == null)
1585 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1586 if (str.length() < 1)
1591 format = new IdentifyFile().Identify(str, "Paste");
1593 } catch (OutOfMemoryError er)
1595 new OOMWarning("Out of memory pasting sequences!!", er);
1599 SequenceI[] sequences;
1600 boolean annotationAdded = false;
1601 AlignmentI alignment = null;
1603 if (Desktop.jalviewClipboard != null)
1605 // The clipboard was filled from within Jalview, we must use the
1607 // And dataset from the copied alignment
1608 SequenceI[] newseq = (SequenceI[]) Desktop.jalviewClipboard[0];
1609 // be doubly sure that we create *new* sequence objects.
1610 sequences = new SequenceI[newseq.length];
1611 for (int i = 0; i < newseq.length; i++)
1613 sequences[i] = new Sequence(newseq[i]);
1615 alignment = new Alignment(sequences);
1616 externalPaste = false;
1620 // parse the clipboard as an alignment.
1621 alignment = new FormatAdapter().readFile(str, "Paste", format);
1622 sequences = alignment.getSequencesArray();
1630 if (Desktop.jalviewClipboard != null)
1632 // dataset is inherited
1633 alignment.setDataset((Alignment) Desktop.jalviewClipboard[1]);
1637 // new dataset is constructed
1638 alignment.setDataset(null);
1640 alwidth = alignment.getWidth() + 1;
1644 AlignmentI pastedal = alignment; // preserve pasted alignment object
1645 // Add pasted sequences and dataset into existing alignment.
1646 alignment = viewport.getAlignment();
1647 alwidth = alignment.getWidth() + 1;
1648 // decide if we need to import sequences from an existing dataset
1649 boolean importDs = Desktop.jalviewClipboard != null
1650 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1651 // importDs==true instructs us to copy over new dataset sequences from
1652 // an existing alignment
1653 Vector newDs = (importDs) ? new Vector() : null; // used to create
1654 // minimum dataset set
1656 for (int i = 0; i < sequences.length; i++)
1660 newDs.addElement(null);
1662 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1664 if (importDs && ds != null)
1666 if (!newDs.contains(ds))
1668 newDs.setElementAt(ds, i);
1669 ds = new Sequence(ds);
1670 // update with new dataset sequence
1671 sequences[i].setDatasetSequence(ds);
1675 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1680 // copy and derive new dataset sequence
1681 sequences[i] = sequences[i].deriveSequence();
1682 alignment.getDataset().addSequence(
1683 sequences[i].getDatasetSequence());
1684 // TODO: avoid creation of duplicate dataset sequences with a
1685 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1687 alignment.addSequence(sequences[i]); // merges dataset
1691 newDs.clear(); // tidy up
1693 if (pastedal.getAlignmentAnnotation() != null)
1695 // Add any annotation attached to alignment.
1696 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1697 for (int i = 0; i < alann.length; i++)
1699 annotationAdded = true;
1700 if (alann[i].sequenceRef == null && !alann[i].autoCalculated)
1702 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1703 newann.padAnnotation(alwidth);
1704 alignment.addAnnotation(newann);
1714 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1715 sequences, 0, alignment.getWidth(), alignment));
1717 // Add any annotations attached to sequences
1718 for (int i = 0; i < sequences.length; i++)
1720 if (sequences[i].getAnnotation() != null)
1722 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1724 annotationAdded = true;
1725 sequences[i].getAnnotation()[a].adjustForAlignment();
1726 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1727 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
1732 .setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1739 // propagate alignment changed.
1740 viewport.setEndSeq(alignment.getHeight());
1741 if (annotationAdded)
1743 // Duplicate sequence annotation in all views.
1744 AlignmentI[] alview = this.getViewAlignments();
1745 for (int i = 0; i < sequences.length; i++)
1747 AlignmentAnnotation sann[] = sequences[i].getAnnotation();
1750 for (int avnum = 0; avnum < alview.length; avnum++)
1752 if (alview[avnum] != alignment)
1754 // duplicate in a view other than the one with input focus
1755 int avwidth = alview[avnum].getWidth() + 1;
1756 // this relies on sann being preserved after we
1757 // modify the sequence's annotation array for each duplication
1758 for (int a = 0; a < sann.length; a++)
1760 AlignmentAnnotation newann = new AlignmentAnnotation(
1762 sequences[i].addAlignmentAnnotation(newann);
1763 newann.padAnnotation(avwidth);
1764 alview[avnum].addAnnotation(newann); // annotation was
1765 // duplicated earlier
1766 alview[avnum].setAnnotationIndex(newann, a);
1771 buildSortByAnnotationScoresMenu();
1773 viewport.firePropertyChange("alignment", null, alignment
1779 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH,
1781 String newtitle = new String("Copied sequences");
1783 if (Desktop.jalviewClipboard != null
1784 && Desktop.jalviewClipboard[2] != null)
1786 Vector hc = (Vector) Desktop.jalviewClipboard[2];
1787 for (int i = 0; i < hc.size(); i++)
1789 int[] region = (int[]) hc.elementAt(i);
1790 af.viewport.hideColumns(region[0], region[1]);
1794 // >>>This is a fix for the moment, until a better solution is
1796 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer()
1798 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1800 // TODO: maintain provenance of an alignment, rather than just make the
1801 // title a concatenation of operations.
1804 if (title.startsWith("Copied sequences"))
1810 newtitle = newtitle.concat("- from " + title);
1815 newtitle = new String("Pasted sequences");
1818 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1823 } catch (Exception ex)
1825 ex.printStackTrace();
1826 System.out.println("Exception whilst pasting: " + ex);
1827 // could be anything being pasted in here
1838 protected void cut_actionPerformed(ActionEvent e)
1840 copy_actionPerformed(null);
1841 delete_actionPerformed(null);
1850 protected void delete_actionPerformed(ActionEvent evt)
1853 SequenceGroup sg = viewport.getSelectionGroup();
1859 Vector seqs = new Vector();
1861 for (int i = 0; i < sg.getSize(); i++)
1863 seq = sg.getSequenceAt(i);
1864 seqs.addElement(seq);
1867 // If the cut affects all sequences, remove highlighted columns
1868 if (sg.getSize() == viewport.alignment.getHeight())
1870 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1871 sg.getEndRes() + 1);
1874 SequenceI[] cut = new SequenceI[seqs.size()];
1875 for (int i = 0; i < seqs.size(); i++)
1877 cut[i] = (SequenceI) seqs.elementAt(i);
1881 * //ADD HISTORY ITEM
1883 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
1884 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
1885 viewport.alignment));
1887 viewport.setSelectionGroup(null);
1888 viewport.sendSelection();
1889 viewport.alignment.deleteGroup(sg);
1891 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
1893 if (viewport.getAlignment().getHeight() < 1)
1897 this.setClosed(true);
1898 } catch (Exception ex)
1910 protected void deleteGroups_actionPerformed(ActionEvent e)
1912 viewport.alignment.deleteAllGroups();
1913 viewport.sequenceColours = null;
1914 viewport.setSelectionGroup(null);
1915 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1916 alignPanel.paintAlignment(true);
1925 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1927 SequenceGroup sg = new SequenceGroup();
1929 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1931 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1934 sg.setEndRes(viewport.alignment.getWidth() - 1);
1935 viewport.setSelectionGroup(sg);
1936 viewport.sendSelection();
1937 alignPanel.paintAlignment(true);
1938 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1947 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1949 if (viewport.cursorMode)
1951 alignPanel.seqPanel.keyboardNo1 = null;
1952 alignPanel.seqPanel.keyboardNo2 = null;
1954 viewport.setSelectionGroup(null);
1955 viewport.getColumnSelection().clear();
1956 viewport.setSelectionGroup(null);
1957 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1958 alignPanel.idPanel.idCanvas.searchResults = null;
1959 alignPanel.paintAlignment(true);
1960 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1969 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1971 SequenceGroup sg = viewport.getSelectionGroup();
1975 selectAllSequenceMenuItem_actionPerformed(null);
1980 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1982 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1985 alignPanel.paintAlignment(true);
1986 viewport.sendSelection();
1987 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1990 public void invertColSel_actionPerformed(ActionEvent e)
1992 viewport.invertColumnSelection();
1993 alignPanel.paintAlignment(true);
2002 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
2004 trimAlignment(true);
2013 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
2015 trimAlignment(false);
2018 void trimAlignment(boolean trimLeft)
2020 ColumnSelection colSel = viewport.getColumnSelection();
2023 if (colSel.size() > 0)
2027 column = colSel.getMin();
2031 column = colSel.getMax();
2035 if (viewport.getSelectionGroup() != null)
2037 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2038 viewport.hiddenRepSequences);
2042 seqs = viewport.alignment.getSequencesArray();
2045 TrimRegionCommand trimRegion;
2048 trimRegion = new TrimRegionCommand("Remove Left",
2049 TrimRegionCommand.TRIM_LEFT, seqs, column,
2050 viewport.alignment, viewport.colSel,
2051 viewport.selectionGroup);
2052 viewport.setStartRes(0);
2056 trimRegion = new TrimRegionCommand("Remove Right",
2057 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2058 viewport.alignment, viewport.colSel,
2059 viewport.selectionGroup);
2062 statusBar.setText("Removed " + trimRegion.getSize() + " columns.");
2064 addHistoryItem(trimRegion);
2066 Vector groups = viewport.alignment.getGroups();
2068 for (int i = 0; i < groups.size(); i++)
2070 SequenceGroup sg = (SequenceGroup) groups.get(i);
2072 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2073 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2075 viewport.alignment.deleteGroup(sg);
2079 viewport.firePropertyChange("alignment", null, viewport
2080 .getAlignment().getSequences());
2090 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
2092 int start = 0, end = viewport.alignment.getWidth() - 1;
2095 if (viewport.getSelectionGroup() != null)
2097 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2098 viewport.hiddenRepSequences);
2099 start = viewport.getSelectionGroup().getStartRes();
2100 end = viewport.getSelectionGroup().getEndRes();
2104 seqs = viewport.alignment.getSequencesArray();
2107 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2108 "Remove Gapped Columns", seqs, start, end, viewport.alignment);
2110 addHistoryItem(removeGapCols);
2112 statusBar.setText("Removed " + removeGapCols.getSize()
2113 + " empty columns.");
2115 // This is to maintain viewport position on first residue
2116 // of first sequence
2117 SequenceI seq = viewport.alignment.getSequenceAt(0);
2118 int startRes = seq.findPosition(viewport.startRes);
2119 // ShiftList shifts;
2120 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2121 // edit.alColumnChanges=shifts.getInverse();
2122 // if (viewport.hasHiddenColumns)
2123 // viewport.getColumnSelection().compensateForEdits(shifts);
2124 viewport.setStartRes(seq.findIndex(startRes) - 1);
2125 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2136 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
2138 int start = 0, end = viewport.alignment.getWidth() - 1;
2141 if (viewport.getSelectionGroup() != null)
2143 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2144 viewport.hiddenRepSequences);
2145 start = viewport.getSelectionGroup().getStartRes();
2146 end = viewport.getSelectionGroup().getEndRes();
2150 seqs = viewport.alignment.getSequencesArray();
2153 // This is to maintain viewport position on first residue
2154 // of first sequence
2155 SequenceI seq = viewport.alignment.getSequenceAt(0);
2156 int startRes = seq.findPosition(viewport.startRes);
2158 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2159 viewport.alignment));
2161 viewport.setStartRes(seq.findIndex(startRes) - 1);
2163 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2174 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2176 viewport.padGaps = padGapsMenuitem.isSelected();
2177 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2183 // if (justifySeqs>0)
2185 // alignment.justify(justifySeqs!=RIGHT_JUSTIFY);
2197 public void findMenuItem_actionPerformed(ActionEvent e)
2202 public void newView_actionPerformed(ActionEvent e)
2204 AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel,
2207 newap.av.gatherViewsHere = false;
2209 if (viewport.viewName == null)
2211 viewport.viewName = "Original";
2214 newap.av.historyList = viewport.historyList;
2215 newap.av.redoList = viewport.redoList;
2217 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2218 String newViewName = "View " + index;
2220 Vector comps = (Vector) PaintRefresher.components.get(viewport
2221 .getSequenceSetId());
2222 Vector existingNames = new Vector();
2223 for (int i = 0; i < comps.size(); i++)
2225 if (comps.elementAt(i) instanceof AlignmentPanel)
2227 AlignmentPanel ap = (AlignmentPanel) comps.elementAt(i);
2228 if (!existingNames.contains(ap.av.viewName))
2230 existingNames.addElement(ap.av.viewName);
2235 while (existingNames.contains(newViewName))
2237 newViewName = "View " + (++index);
2240 newap.av.viewName = newViewName;
2242 addAlignmentPanel(newap, true);
2244 if (alignPanels.size() == 2)
2246 viewport.gatherViewsHere = true;
2248 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2251 public void expandViews_actionPerformed(ActionEvent e)
2253 Desktop.instance.explodeViews(this);
2256 public void gatherViews_actionPerformed(ActionEvent e)
2258 Desktop.instance.gatherViews(this);
2267 public void font_actionPerformed(ActionEvent e)
2269 new FontChooser(alignPanel);
2278 protected void seqLimit_actionPerformed(ActionEvent e)
2280 viewport.setShowJVSuffix(seqLimits.isSelected());
2282 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel
2283 .calculateIdWidth());
2284 alignPanel.paintAlignment(true);
2287 public void idRightAlign_actionPerformed(ActionEvent e)
2289 viewport.rightAlignIds = idRightAlign.isSelected();
2290 alignPanel.paintAlignment(true);
2293 public void centreColumnLabels_actionPerformed(ActionEvent e)
2295 viewport.centreColumnLabels = centreColumnLabelsMenuItem.getState();
2296 alignPanel.paintAlignment(true);
2302 * @see jalview.jbgui.GAlignFrame#followHighlight_actionPerformed()
2304 protected void followHighlight_actionPerformed()
2306 if (viewport.followHighlight = this.followHighlightMenuItem.getState())
2308 alignPanel.scrollToPosition(
2309 alignPanel.seqPanel.seqCanvas.searchResults, false);
2319 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2321 viewport.setColourText(colourTextMenuItem.isSelected());
2322 alignPanel.paintAlignment(true);
2331 public void wrapMenuItem_actionPerformed(ActionEvent e)
2333 scaleAbove.setVisible(wrapMenuItem.isSelected());
2334 scaleLeft.setVisible(wrapMenuItem.isSelected());
2335 scaleRight.setVisible(wrapMenuItem.isSelected());
2336 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2337 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2340 public void showAllSeqs_actionPerformed(ActionEvent e)
2342 viewport.showAllHiddenSeqs();
2345 public void showAllColumns_actionPerformed(ActionEvent e)
2347 viewport.showAllHiddenColumns();
2351 public void hideSelSequences_actionPerformed(ActionEvent e)
2353 viewport.hideAllSelectedSeqs();
2354 alignPanel.paintAlignment(true);
2357 public void hideSelColumns_actionPerformed(ActionEvent e)
2359 viewport.hideSelectedColumns();
2360 alignPanel.paintAlignment(true);
2363 public void hiddenMarkers_actionPerformed(ActionEvent e)
2365 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2375 protected void scaleAbove_actionPerformed(ActionEvent e)
2377 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2378 alignPanel.paintAlignment(true);
2387 protected void scaleLeft_actionPerformed(ActionEvent e)
2389 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2390 alignPanel.paintAlignment(true);
2399 protected void scaleRight_actionPerformed(ActionEvent e)
2401 viewport.setScaleRightWrapped(scaleRight.isSelected());
2402 alignPanel.paintAlignment(true);
2411 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2413 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2414 alignPanel.paintAlignment(true);
2423 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2425 viewport.setShowText(viewTextMenuItem.isSelected());
2426 alignPanel.paintAlignment(true);
2435 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2437 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2438 alignPanel.paintAlignment(true);
2441 public FeatureSettings featureSettings;
2443 public void featureSettings_actionPerformed(ActionEvent e)
2445 if (featureSettings != null)
2447 featureSettings.close();
2448 featureSettings = null;
2450 featureSettings = new FeatureSettings(this);
2454 * Set or clear 'Show Sequence Features'
2459 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2461 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2462 alignPanel.paintAlignment(true);
2463 if (alignPanel.getOverviewPanel() != null)
2465 alignPanel.getOverviewPanel().updateOverviewImage();
2470 * Set or clear 'Show Sequence Features'
2475 public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt)
2477 viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight
2479 if (viewport.getShowSequenceFeaturesHeight())
2481 // ensure we're actually displaying features
2482 viewport.setShowSequenceFeatures(true);
2483 showSeqFeatures.setSelected(true);
2485 alignPanel.paintAlignment(true);
2486 if (alignPanel.getOverviewPanel() != null)
2488 alignPanel.getOverviewPanel().updateOverviewImage();
2498 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2500 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2501 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2504 public void alignmentProperties()
2506 JEditorPane editPane = new JEditorPane("text/html", "");
2507 editPane.setEditable(false);
2508 StringBuffer contents = new StringBuffer("<html>");
2511 int min = Integer.MAX_VALUE, max = 0;
2512 for (int i = 0; i < viewport.alignment.getHeight(); i++)
2514 int size = viewport.alignment.getSequenceAt(i).getEnd()
2515 - viewport.alignment.getSequenceAt(i).getStart();
2522 avg = avg / (float) viewport.alignment.getHeight();
2524 contents.append("<br>Sequences: " + viewport.alignment.getHeight());
2525 contents.append("<br>Minimum Sequence Length: " + min);
2526 contents.append("<br>Maximum Sequence Length: " + max);
2527 contents.append("<br>Average Length: " + (int) avg);
2529 if (((Alignment) viewport.alignment).getProperties() != null)
2531 Hashtable props = ((Alignment) viewport.alignment).getProperties();
2532 Enumeration en = props.keys();
2533 contents.append("<br><br><table border=\"1\">");
2534 while (en.hasMoreElements())
2536 String key = en.nextElement().toString();
2537 StringBuffer val = new StringBuffer();
2538 String vals = props.get(key).toString();
2542 npos = vals.indexOf("\n", pos);
2545 val.append(vals.substring(pos));
2549 val.append(vals.substring(pos, npos));
2553 } while (npos != -1);
2555 .append("<tr><td>" + key + "</td><td>" + val + "</td></tr>");
2557 contents.append("</table>");
2559 editPane.setText(contents.toString() + "</html>");
2560 JInternalFrame frame = new JInternalFrame();
2561 frame.getContentPane().add(new JScrollPane(editPane));
2563 Desktop.instance.addInternalFrame(frame, "Alignment Properties: "
2564 + getTitle(), 500, 400);
2573 public void overviewMenuItem_actionPerformed(ActionEvent e)
2575 if (alignPanel.overviewPanel != null)
2580 JInternalFrame frame = new JInternalFrame();
2581 OverviewPanel overview = new OverviewPanel(alignPanel);
2582 frame.setContentPane(overview);
2583 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(), frame
2584 .getWidth(), frame.getHeight());
2586 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2588 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2590 public void internalFrameClosed(
2591 javax.swing.event.InternalFrameEvent evt)
2593 alignPanel.setOverviewPanel(null);
2597 alignPanel.setOverviewPanel(overview);
2600 public void textColour_actionPerformed(ActionEvent e)
2602 new TextColourChooser().chooseColour(alignPanel, null);
2611 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2622 public void clustalColour_actionPerformed(ActionEvent e)
2624 changeColour(new ClustalxColourScheme(
2625 viewport.alignment.getSequences(), viewport.alignment
2635 public void zappoColour_actionPerformed(ActionEvent e)
2637 changeColour(new ZappoColourScheme());
2646 public void taylorColour_actionPerformed(ActionEvent e)
2648 changeColour(new TaylorColourScheme());
2657 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2659 changeColour(new HydrophobicColourScheme());
2668 public void helixColour_actionPerformed(ActionEvent e)
2670 changeColour(new HelixColourScheme());
2679 public void strandColour_actionPerformed(ActionEvent e)
2681 changeColour(new StrandColourScheme());
2690 public void turnColour_actionPerformed(ActionEvent e)
2692 changeColour(new TurnColourScheme());
2701 public void buriedColour_actionPerformed(ActionEvent e)
2703 changeColour(new BuriedColourScheme());
2712 public void nucleotideColour_actionPerformed(ActionEvent e)
2714 changeColour(new NucleotideColourScheme());
2717 public void annotationColour_actionPerformed(ActionEvent e)
2719 new AnnotationColourChooser(viewport, alignPanel);
2728 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2730 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2739 public void changeColour(ColourSchemeI cs)
2745 if (viewport.getAbovePIDThreshold())
2747 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2750 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2752 viewport.setGlobalColourScheme(cs);
2756 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2759 if (viewport.getConservationSelected())
2762 Alignment al = (Alignment) viewport.alignment;
2763 Conservation c = new Conservation("All",
2764 ResidueProperties.propHash, 3, al.getSequences(), 0, al
2768 c.verdict(false, viewport.ConsPercGaps);
2770 cs.setConservation(c);
2772 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
2777 cs.setConservation(null);
2780 cs.setConsensus(viewport.hconsensus);
2783 viewport.setGlobalColourScheme(cs);
2785 if (viewport.getColourAppliesToAllGroups())
2787 Vector groups = viewport.alignment.getGroups();
2789 for (int i = 0; i < groups.size(); i++)
2791 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2799 if (cs instanceof ClustalxColourScheme)
2801 sg.cs = new ClustalxColourScheme(sg
2802 .getSequences(viewport.hiddenRepSequences), sg.getWidth());
2804 else if (cs instanceof UserColourScheme)
2806 sg.cs = new UserColourScheme(((UserColourScheme) cs).getColours());
2812 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2813 } catch (Exception ex)
2818 if (viewport.getAbovePIDThreshold()
2819 || cs instanceof PIDColourScheme
2820 || cs instanceof Blosum62ColourScheme)
2822 sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2824 sg.cs.setConsensus(AAFrequency.calculate(sg
2825 .getSequences(viewport.hiddenRepSequences), sg
2826 .getStartRes(), sg.getEndRes() + 1));
2830 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2833 if (viewport.getConservationSelected())
2835 Conservation c = new Conservation("Group",
2836 ResidueProperties.propHash, 3, sg
2837 .getSequences(viewport.hiddenRepSequences), sg
2838 .getStartRes(), sg.getEndRes() + 1);
2840 c.verdict(false, viewport.ConsPercGaps);
2841 sg.cs.setConservation(c);
2845 sg.cs.setConservation(null);
2850 if (alignPanel.getOverviewPanel() != null)
2852 alignPanel.getOverviewPanel().updateOverviewImage();
2855 alignPanel.paintAlignment(true);
2864 protected void modifyPID_actionPerformed(ActionEvent e)
2866 if (viewport.getAbovePIDThreshold()
2867 && viewport.globalColourScheme != null)
2869 SliderPanel.setPIDSliderSource(alignPanel, viewport
2870 .getGlobalColourScheme(), "Background");
2871 SliderPanel.showPIDSlider();
2881 protected void modifyConservation_actionPerformed(ActionEvent e)
2883 if (viewport.getConservationSelected()
2884 && viewport.globalColourScheme != null)
2886 SliderPanel.setConservationSlider(alignPanel,
2887 viewport.globalColourScheme, "Background");
2888 SliderPanel.showConservationSlider();
2898 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2900 viewport.setConservationSelected(conservationMenuItem.isSelected());
2902 viewport.setAbovePIDThreshold(false);
2903 abovePIDThreshold.setSelected(false);
2905 changeColour(viewport.getGlobalColourScheme());
2907 modifyConservation_actionPerformed(null);
2916 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2918 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2920 conservationMenuItem.setSelected(false);
2921 viewport.setConservationSelected(false);
2923 changeColour(viewport.getGlobalColourScheme());
2925 modifyPID_actionPerformed(null);
2934 public void userDefinedColour_actionPerformed(ActionEvent e)
2936 if (e.getActionCommand().equals("User Defined..."))
2938 new UserDefinedColours(alignPanel, null);
2942 UserColourScheme udc = (UserColourScheme) UserDefinedColours
2943 .getUserColourSchemes().get(e.getActionCommand());
2949 public void updateUserColourMenu()
2952 Component[] menuItems = colourMenu.getMenuComponents();
2953 int i, iSize = menuItems.length;
2954 for (i = 0; i < iSize; i++)
2956 if (menuItems[i].getName() != null
2957 && menuItems[i].getName().equals("USER_DEFINED"))
2959 colourMenu.remove(menuItems[i]);
2963 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2965 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
2966 .getUserColourSchemes().keys();
2968 while (userColours.hasMoreElements())
2970 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2971 userColours.nextElement().toString());
2972 radioItem.setName("USER_DEFINED");
2973 radioItem.addMouseListener(new MouseAdapter()
2975 public void mousePressed(MouseEvent evt)
2977 if (evt.isControlDown()
2978 || SwingUtilities.isRightMouseButton(evt))
2981 .removeActionListener(radioItem.getActionListeners()[0]);
2983 int option = JOptionPane.showInternalConfirmDialog(
2984 jalview.gui.Desktop.desktop,
2985 "Remove from default list?",
2986 "Remove user defined colour",
2987 JOptionPane.YES_NO_OPTION);
2988 if (option == JOptionPane.YES_OPTION)
2990 jalview.gui.UserDefinedColours
2991 .removeColourFromDefaults(radioItem.getText());
2992 colourMenu.remove(radioItem);
2996 radioItem.addActionListener(new ActionListener()
2998 public void actionPerformed(ActionEvent evt)
3000 userDefinedColour_actionPerformed(evt);
3007 radioItem.addActionListener(new ActionListener()
3009 public void actionPerformed(ActionEvent evt)
3011 userDefinedColour_actionPerformed(evt);
3015 colourMenu.insert(radioItem, 15);
3016 colours.add(radioItem);
3027 public void PIDColour_actionPerformed(ActionEvent e)
3029 changeColour(new PIDColourScheme());
3038 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
3040 changeColour(new Blosum62ColourScheme());
3049 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
3051 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3052 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
3053 .getAlignment().getSequenceAt(0), null);
3054 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
3055 viewport.alignment));
3056 alignPanel.paintAlignment(true);
3065 public void sortIDMenuItem_actionPerformed(ActionEvent e)
3067 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3068 AlignmentSorter.sortByID(viewport.getAlignment());
3069 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
3070 alignPanel.paintAlignment(true);
3079 public void sortLengthMenuItem_actionPerformed(ActionEvent e)
3081 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3082 AlignmentSorter.sortByLength(viewport.getAlignment());
3083 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
3084 viewport.alignment));
3085 alignPanel.paintAlignment(true);
3094 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
3096 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3097 AlignmentSorter.sortByGroup(viewport.getAlignment());
3098 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
3099 viewport.alignment));
3101 alignPanel.paintAlignment(true);
3110 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
3112 new RedundancyPanel(alignPanel, this);
3121 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
3123 if ((viewport.getSelectionGroup() == null)
3124 || (viewport.getSelectionGroup().getSize() < 2))
3126 JOptionPane.showInternalMessageDialog(this,
3127 "You must select at least 2 sequences.", "Invalid Selection",
3128 JOptionPane.WARNING_MESSAGE);
3132 JInternalFrame frame = new JInternalFrame();
3133 frame.setContentPane(new PairwiseAlignPanel(viewport));
3134 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
3144 public void PCAMenuItem_actionPerformed(ActionEvent e)
3146 if (((viewport.getSelectionGroup() != null)
3147 && (viewport.getSelectionGroup().getSize() < 4) && (viewport
3148 .getSelectionGroup().getSize() > 0))
3149 || (viewport.getAlignment().getHeight() < 4))
3151 JOptionPane.showInternalMessageDialog(this,
3152 "Principal component analysis must take\n"
3153 + "at least 4 input sequences.",
3154 "Sequence selection insufficient",
3155 JOptionPane.WARNING_MESSAGE);
3160 new PCAPanel(alignPanel);
3163 public void autoCalculate_actionPerformed(ActionEvent e)
3165 viewport.autoCalculateConsensus = autoCalculate.isSelected();
3166 if (viewport.autoCalculateConsensus)
3168 viewport.firePropertyChange("alignment", null, viewport
3169 .getAlignment().getSequences());
3179 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
3181 NewTreePanel("AV", "PID", "Average distance tree using PID");
3190 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
3192 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
3201 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3203 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
3212 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
3214 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
3227 void NewTreePanel(String type, String pwType, String title)
3231 if (viewport.getSelectionGroup() != null)
3233 if (viewport.getSelectionGroup().getSize() < 3)
3238 "You need to have more than two sequences selected to build a tree!",
3239 "Not enough sequences", JOptionPane.WARNING_MESSAGE);
3244 SequenceGroup sg = viewport.getSelectionGroup();
3246 /* Decide if the selection is a column region */
3247 while (s < sg.getSize())
3249 if (((SequenceI) sg.getSequences(null).elementAt(s++)).getLength() < sg
3255 "The selected region to create a tree may\nonly contain residues or gaps.\n"
3256 + "Try using the Pad function in the edit menu,\n"
3257 + "or one of the multiple sequence alignment web services.",
3258 "Sequences in selection are not aligned",
3259 JOptionPane.WARNING_MESSAGE);
3265 title = title + " on region";
3266 tp = new TreePanel(alignPanel, type, pwType);
3270 // are the sequences aligned?
3271 if (!viewport.alignment.isAligned())
3276 "The sequences must be aligned before creating a tree.\n"
3277 + "Try using the Pad function in the edit menu,\n"
3278 + "or one of the multiple sequence alignment web services.",
3279 "Sequences not aligned",
3280 JOptionPane.WARNING_MESSAGE);
3285 if (viewport.alignment.getHeight() < 2)
3290 tp = new TreePanel(alignPanel, type, pwType);
3295 if (viewport.viewName != null)
3297 title += viewport.viewName + " of ";
3300 title += this.title;
3302 Desktop.addInternalFrame(tp, title, 600, 500);
3313 public void addSortByOrderMenuItem(String title,
3314 final AlignmentOrder order)
3316 final JMenuItem item = new JMenuItem("by " + title);
3318 item.addActionListener(new java.awt.event.ActionListener()
3320 public void actionPerformed(ActionEvent e)
3322 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3324 // TODO: JBPNote - have to map order entries to curent SequenceI
3326 AlignmentSorter.sortBy(viewport.getAlignment(), order);
3328 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
3329 viewport.alignment));
3331 alignPanel.paintAlignment(true);
3337 * Add a new sort by annotation score menu item
3340 * the menu to add the option to
3342 * the label used to retrieve scores for each sequence on the
3345 public void addSortByAnnotScoreMenuItem(JMenu sort,
3346 final String scoreLabel)
3348 final JMenuItem item = new JMenuItem(scoreLabel);
3350 item.addActionListener(new java.awt.event.ActionListener()
3352 public void actionPerformed(ActionEvent e)
3354 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3355 AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport
3356 .getAlignment());// ,viewport.getSelectionGroup());
3357 addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder,
3358 viewport.alignment));
3359 alignPanel.paintAlignment(true);
3365 * last hash for alignment's annotation array - used to minimise cost of
3368 protected int _annotationScoreVectorHash;
3371 * search the alignment and rebuild the sort by annotation score submenu the
3372 * last alignment annotation vector hash is stored to minimize cost of
3373 * rebuilding in subsequence calls.
3376 public void buildSortByAnnotationScoresMenu()
3378 if (viewport.alignment.getAlignmentAnnotation() == null)
3383 if (viewport.alignment.getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash)
3385 sortByAnnotScore.removeAll();
3386 // almost certainly a quicker way to do this - but we keep it simple
3387 Hashtable scoreSorts = new Hashtable();
3388 AlignmentAnnotation aann[];
3389 Enumeration sq = viewport.alignment.getSequences().elements();
3390 while (sq.hasMoreElements())
3392 aann = ((SequenceI) sq.nextElement()).getAnnotation();
3393 for (int i = 0; aann != null && i < aann.length; i++)
3395 if (aann[i].hasScore() && aann[i].sequenceRef != null)
3397 scoreSorts.put(aann[i].label, aann[i].label);
3401 Enumeration labels = scoreSorts.keys();
3402 while (labels.hasMoreElements())
3404 addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels
3407 sortByAnnotScore.setVisible(scoreSorts.size() > 0);
3410 _annotationScoreVectorHash = viewport.alignment
3411 .getAlignmentAnnotation().hashCode();
3416 * Maintain the Order by->Displayed Tree menu. Creates a new menu item for a
3417 * TreePanel with an appropriate <code>jalview.analysis.AlignmentSorter</code>
3418 * call. Listeners are added to remove the menu item when the treePanel is
3419 * closed, and adjust the tree leaf to sequence mapping when the alignment is
3423 * Displayed tree window.
3425 * SortBy menu item title.
3427 public void buildTreeMenu()
3429 sortByTreeMenu.removeAll();
3431 Vector comps = (Vector) PaintRefresher.components.get(viewport
3432 .getSequenceSetId());
3433 Vector treePanels = new Vector();
3434 int i, iSize = comps.size();
3435 for (i = 0; i < iSize; i++)
3437 if (comps.elementAt(i) instanceof TreePanel)
3439 treePanels.add(comps.elementAt(i));
3443 iSize = treePanels.size();
3447 sortByTreeMenu.setVisible(false);
3451 sortByTreeMenu.setVisible(true);
3453 for (i = 0; i < treePanels.size(); i++)
3455 TreePanel tp = (TreePanel) treePanels.elementAt(i);
3456 final JMenuItem item = new JMenuItem(tp.getTitle());
3457 final NJTree tree = ((TreePanel) treePanels.elementAt(i)).getTree();
3458 item.addActionListener(new java.awt.event.ActionListener()
3460 public void actionPerformed(ActionEvent e)
3462 SequenceI[] oldOrder = viewport.getAlignment()
3463 .getSequencesArray();
3464 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3466 addHistoryItem(new OrderCommand("Tree Sort", oldOrder,
3467 viewport.alignment));
3469 alignPanel.paintAlignment(true);
3473 sortByTreeMenu.add(item);
3478 * Work out whether the whole set of sequences or just the selected set will
3479 * be submitted for multiple alignment.
3482 public jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3484 // Now, check we have enough sequences
3485 AlignmentView msa = null;
3487 if ((viewport.getSelectionGroup() != null)
3488 && (viewport.getSelectionGroup().getSize() > 1))
3490 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to
3491 // some common interface!
3493 * SequenceGroup seqs = viewport.getSelectionGroup(); int sz; msa = new
3494 * SequenceI[sz = seqs.getSize(false)];
3496 * for (int i = 0; i < sz; i++) { msa[i] = (SequenceI)
3497 * seqs.getSequenceAt(i); }
3499 msa = viewport.getAlignmentView(true);
3504 * Vector seqs = viewport.getAlignment().getSequences();
3506 * if (seqs.size() > 1) { msa = new SequenceI[seqs.size()];
3508 * for (int i = 0; i < seqs.size(); i++) { msa[i] = (SequenceI)
3509 * seqs.elementAt(i); } }
3511 msa = viewport.getAlignmentView(false);
3517 * Decides what is submitted to a secondary structure prediction service: the
3518 * first sequence in the alignment, or in the current selection, or, if the
3519 * alignment is 'aligned' (ie padded with gaps), then the currently selected
3520 * region or the whole alignment. (where the first sequence in the set is the
3521 * one that the prediction will be for).
3523 public AlignmentView gatherSeqOrMsaForSecStrPrediction()
3525 AlignmentView seqs = null;
3527 if ((viewport.getSelectionGroup() != null)
3528 && (viewport.getSelectionGroup().getSize() > 0))
3530 seqs = viewport.getAlignmentView(true);
3534 seqs = viewport.getAlignmentView(false);
3536 // limit sequences - JBPNote in future - could spawn multiple prediction
3538 // TODO: viewport.alignment.isAligned is a global state - the local
3539 // selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3540 if (!viewport.alignment.isAligned())
3542 seqs.setSequences(new SeqCigar[]
3543 { seqs.getSequences()[0] });
3554 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3556 // Pick the tree file
3557 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
3558 .getProperty("LAST_DIRECTORY"));
3559 chooser.setFileView(new JalviewFileView());
3560 chooser.setDialogTitle("Select a newick-like tree file");
3561 chooser.setToolTipText("Load a tree file");
3563 int value = chooser.showOpenDialog(null);
3565 if (value == JalviewFileChooser.APPROVE_OPTION)
3567 String choice = chooser.getSelectedFile().getPath();
3568 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3569 jalview.io.NewickFile fin = null;
3572 fin = new jalview.io.NewickFile(choice, "File");
3573 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3574 } catch (Exception ex)
3576 JOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
3577 "Problem reading tree file", JOptionPane.WARNING_MESSAGE);
3578 ex.printStackTrace();
3580 if (fin != null && fin.hasWarningMessage())
3582 JOptionPane.showMessageDialog(Desktop.desktop, fin
3583 .getWarningMessage(), "Possible problem with tree file",
3584 JOptionPane.WARNING_MESSAGE);
3589 public TreePanel ShowNewickTree(NewickFile nf, String title)
3591 return ShowNewickTree(nf, title, 600, 500, 4, 5);
3594 public TreePanel ShowNewickTree(NewickFile nf, String title,
3595 AlignmentView input)
3597 return ShowNewickTree(nf, title, input, 600, 500, 4, 5);
3600 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,
3601 int h, int x, int y)
3603 return ShowNewickTree(nf, title, null, w, h, x, y);
3607 * Add a treeviewer for the tree extracted from a newick file object to the
3608 * current alignment view
3615 * Associated alignment input data (or null)
3624 * @return TreePanel handle
3626 public TreePanel ShowNewickTree(NewickFile nf, String title,
3627 AlignmentView input, int w, int h, int x, int y)
3629 TreePanel tp = null;
3635 if (nf.getTree() != null)
3637 tp = new TreePanel(alignPanel, "FromFile", title, nf, input);
3643 tp.setLocation(x, y);
3646 Desktop.addInternalFrame(tp, title, w, h);
3648 } catch (Exception ex)
3650 ex.printStackTrace();
3657 * Generates menu items and listener event actions for web service clients
3660 public void BuildWebServiceMenu()
3662 // TODO: add support for context dependent disabling of services based on
3663 // alignment and current selection
3664 // TODO: add additional serviceHandle parameter to specify abstract handler
3665 // class independently of AbstractName
3666 // TODO: add in rediscovery GUI function to restart discoverer
3667 // TODO: group services by location as well as function and/or introduce
3668 // object broker mechanism.
3669 if ((Discoverer.services != null) && (Discoverer.services.size() > 0))
3671 // TODO: refactor to allow list of AbstractName/Handler bindings to be
3672 // stored or retrieved from elsewhere
3673 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3674 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3675 Vector seqsrch = (Vector) Discoverer.services.get("SeqSearch");
3676 // TODO: move GUI generation code onto service implementation - so a
3677 // client instance attaches itself to the GUI with method call like
3678 // jalview.ws.MsaWSClient.bind(servicehandle, Desktop.instance,
3680 Vector wsmenu = new Vector();
3681 final IProgressIndicator af = this;
3684 // Add any Multiple Sequence Alignment Services
3685 final JMenu msawsmenu = new JMenu("Alignment");
3686 for (int i = 0, j = msaws.size(); i < j; i++)
3688 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws
3690 jalview.ws.WSClient impl = jalview.ws.Discoverer
3691 .getServiceClient(sh);
3692 impl.attachWSMenuEntry(msawsmenu, this);
3695 wsmenu.add(msawsmenu);
3697 if (secstrpr != null)
3699 // Add any secondary structure prediction services
3700 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3701 for (int i = 0, j = secstrpr.size(); i < j; i++)
3703 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr
3705 jalview.ws.WSClient impl = jalview.ws.Discoverer
3706 .getServiceClient(sh);
3707 impl.attachWSMenuEntry(secstrmenu, this);
3709 wsmenu.add(secstrmenu);
3711 if (seqsrch != null)
3713 // Add any sequence search services
3714 final JMenu seqsrchmenu = new JMenu("Sequence Database Search");
3715 for (int i = 0, j = seqsrch.size(); i < j; i++)
3717 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) seqsrch
3719 jalview.ws.WSClient impl = jalview.ws.Discoverer
3720 .getServiceClient(sh);
3721 impl.attachWSMenuEntry(seqsrchmenu, this);
3723 // finally, add the whole shebang onto the webservices menu
3724 wsmenu.add(seqsrchmenu);
3726 resetWebServiceMenu();
3727 for (int i = 0, j = wsmenu.size(); i < j; i++)
3729 webService.add((JMenu) wsmenu.get(i));
3734 resetWebServiceMenu();
3735 this.webService.add(this.webServiceNoServices);
3740 * empty the web service menu and add any ad-hoc functions not dynamically
3744 private void resetWebServiceMenu()
3746 webService.removeAll();
3747 build_fetchdbmenu(webService);
3751 * public void vamsasStore_actionPerformed(ActionEvent e) { JalviewFileChooser
3752 * chooser = new JalviewFileChooser(jalview.bin.Cache.
3753 * getProperty("LAST_DIRECTORY"));
3755 * chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle("Export
3756 * to Vamsas file"); chooser.setToolTipText("Export");
3758 * int value = chooser.showSaveDialog(this);
3760 * if (value == JalviewFileChooser.APPROVE_OPTION) {
3761 * jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3762 * //vs.store(chooser.getSelectedFile().getAbsolutePath() ); vs.storeJalview(
3763 * chooser.getSelectedFile().getAbsolutePath(), this); } }
3766 * prototype of an automatically enabled/disabled analysis function
3769 protected void setShowProductsEnabled()
3771 SequenceI[] selection = viewport.getSequenceSelection();
3772 if (canShowProducts(selection, viewport.getSelectionGroup() != null,
3773 viewport.getAlignment().getDataset()))
3775 showProducts.setEnabled(true);
3780 showProducts.setEnabled(false);
3785 * search selection for sequence xRef products and build the show products
3790 * @return true if showProducts menu should be enabled.
3792 public boolean canShowProducts(SequenceI[] selection,
3793 boolean isRegionSelection, Alignment dataset)
3795 boolean showp = false;
3798 showProducts.removeAll();
3799 final boolean dna = viewport.getAlignment().isNucleotide();
3800 final Alignment ds = dataset;
3801 String[] ptypes = (selection == null || selection.length == 0) ? null
3802 : CrossRef.findSequenceXrefTypes(dna, selection, dataset);
3804 // CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(),
3805 // selection, dataset, true);
3806 final SequenceI[] sel = selection;
3807 for (int t = 0; ptypes != null && t < ptypes.length; t++)
3810 final boolean isRegSel = isRegionSelection;
3811 final AlignFrame af = this;
3812 final String source = ptypes[t];
3813 JMenuItem xtype = new JMenuItem(ptypes[t]);
3814 xtype.addActionListener(new ActionListener()
3817 public void actionPerformed(ActionEvent e)
3819 // TODO: new thread for this call with vis-delay
3820 af.showProductsFor(af.viewport.getSequenceSelection(), ds,
3821 isRegSel, dna, source);
3825 showProducts.add(xtype);
3827 showProducts.setVisible(showp);
3828 showProducts.setEnabled(showp);
3829 } catch (Exception e)
3831 jalview.bin.Cache.log
3833 "canTranslate threw an exception - please report to help@jalview.org",
3840 protected void showProductsFor(SequenceI[] sel, Alignment ds,
3841 boolean isRegSel, boolean dna, String source)
3843 final boolean fisRegSel = isRegSel;
3844 final boolean fdna = dna;
3845 final String fsrc = source;
3846 final AlignFrame ths = this;
3847 final SequenceI[] fsel = sel;
3848 Runnable foo = new Runnable()
3853 final long sttime = System.currentTimeMillis();
3854 ths.setProgressBar("Searching for sequences from " + fsrc, sttime);
3857 Alignment ds = ths.getViewport().alignment.getDataset(); // update
3861 Alignment prods = CrossRef
3862 .findXrefSequences(fsel, fdna, fsrc, ds);
3865 SequenceI[] sprods = new SequenceI[prods.getHeight()];
3866 for (int s = 0; s < sprods.length; s++)
3868 sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
3869 if (ds.getSequences() == null
3870 || !ds.getSequences().contains(
3871 sprods[s].getDatasetSequence()))
3872 ds.addSequence(sprods[s].getDatasetSequence());
3873 sprods[s].updatePDBIds();
3875 Alignment al = new Alignment(sprods);
3876 AlignedCodonFrame[] cf = prods.getCodonFrames();
3878 for (int s = 0; cf != null && s < cf.length; s++)
3880 al.addCodonFrame(cf[s]);
3883 AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH,
3885 String newtitle = "" + ((fdna) ? "Proteins " : "Nucleotides ")
3886 + " for " + ((fisRegSel) ? "selected region of " : "")
3888 Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
3893 System.err.println("No Sequences generated for xRef type "
3896 } catch (Exception e)
3898 jalview.bin.Cache.log.error(
3899 "Exception when finding crossreferences", e);
3900 } catch (OutOfMemoryError e)
3902 new OOMWarning("whilst fetching crossreferences", e);
3905 jalview.bin.Cache.log.error("Error when finding crossreferences",
3908 ths.setProgressBar("Finished searching for sequences from " + fsrc,
3913 Thread frunner = new Thread(foo);
3917 public boolean canShowTranslationProducts(SequenceI[] selection,
3918 AlignmentI alignment)
3923 return (jalview.analysis.Dna.canTranslate(selection, viewport
3924 .getViewAsVisibleContigs(true)));
3925 } catch (Exception e)
3927 jalview.bin.Cache.log
3929 "canTranslate threw an exception - please report to help@jalview.org",
3935 public void showProducts_actionPerformed(ActionEvent e)
3937 // /////////////////////////////
3938 // Collect Data to be translated/transferred
3940 SequenceI[] selection = viewport.getSequenceSelection();
3941 AlignmentI al = null;
3944 al = jalview.analysis.Dna.CdnaTranslate(selection, viewport
3945 .getViewAsVisibleContigs(true), viewport.getGapCharacter(),
3946 viewport.getAlignment().getDataset());
3947 } catch (Exception ex)
3950 jalview.bin.Cache.log.debug("Exception during translation.", ex);
3957 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3958 "Translation Failed", JOptionPane.WARNING_MESSAGE);
3962 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3963 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
3964 DEFAULT_WIDTH, DEFAULT_HEIGHT);
3968 public void showTranslation_actionPerformed(ActionEvent e)
3970 // /////////////////////////////
3971 // Collect Data to be translated/transferred
3973 SequenceI[] selection = viewport.getSequenceSelection();
3974 String[] seqstring = viewport.getViewAsString(true);
3975 AlignmentI al = null;
3978 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring,
3979 viewport.getViewAsVisibleContigs(true), viewport
3980 .getGapCharacter(), viewport.alignment
3981 .getAlignmentAnnotation(), viewport.alignment
3982 .getWidth(), viewport.getAlignment().getDataset());
3983 } catch (Exception ex)
3986 jalview.bin.Cache.log.debug("Exception during translation.", ex);
3993 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3994 "Translation Failed", JOptionPane.WARNING_MESSAGE);
3998 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3999 Desktop.addInternalFrame(af, "Translation of " + this.getTitle(),
4000 DEFAULT_WIDTH, DEFAULT_HEIGHT);
4005 * Try to load a features file onto the alignment.
4008 * contents or path to retrieve file
4010 * access mode of file (see jalview.io.AlignFile)
4011 * @return true if features file was parsed corectly.
4013 public boolean parseFeaturesFile(String file, String type)
4015 boolean featuresFile = false;
4018 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment
4019 .getDataset(), alignPanel.seqPanel.seqCanvas
4020 .getFeatureRenderer().featureColours, false);
4021 } catch (Exception ex)
4023 ex.printStackTrace();
4028 viewport.showSequenceFeatures = true;
4029 showSeqFeatures.setSelected(true);
4030 if (alignPanel.seqPanel.seqCanvas.fr != null)
4032 // update the min/max ranges where necessary
4033 alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true);
4035 alignPanel.paintAlignment(true);
4038 return featuresFile;
4041 public void dragEnter(DropTargetDragEvent evt)
4045 public void dragExit(DropTargetEvent evt)
4049 public void dragOver(DropTargetDragEvent evt)
4053 public void dropActionChanged(DropTargetDragEvent evt)
4057 public void drop(DropTargetDropEvent evt)
4059 Transferable t = evt.getTransferable();
4060 java.util.List files = null;
4064 DataFlavor uriListFlavor = new DataFlavor(
4065 "text/uri-list;class=java.lang.String");
4066 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
4068 // Works on Windows and MacOSX
4069 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4070 files = (java.util.List) t
4071 .getTransferData(DataFlavor.javaFileListFlavor);
4073 else if (t.isDataFlavorSupported(uriListFlavor))
4075 // This is used by Unix drag system
4076 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
4077 String data = (String) t.getTransferData(uriListFlavor);
4078 files = new java.util.ArrayList(1);
4079 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
4080 data, "\r\n"); st.hasMoreTokens();)
4082 String s = st.nextToken();
4083 if (s.startsWith("#"))
4085 // the line is a comment (as per the RFC 2483)
4089 java.net.URI uri = new java.net.URI(s);
4090 // check to see if we can handle this kind of URI
4091 if (uri.getScheme().toLowerCase().startsWith("http"))
4093 files.add(uri.toString());
4097 // otherwise preserve old behaviour: catch all for file objects
4098 java.io.File file = new java.io.File(uri);
4099 files.add(file.toString());
4103 } catch (Exception e)
4105 e.printStackTrace();
4112 for (int i = 0; i < files.size(); i++)
4114 loadJalviewDataFile(files.get(i).toString());
4116 } catch (Exception ex)
4118 ex.printStackTrace();
4124 * Attempt to load a "dropped" file or URL string: First by testing whether it's and
4125 * Annotation file, then a JNet file, and finally a features file. If all are
4126 * false then the user may have dropped an alignment file onto this
4130 * either a filename or a URL string.
4132 public void loadJalviewDataFile(String file)
4136 String protocol = jalview.io.FormatAdapter.FILE;
4137 String f=file.toLowerCase();
4138 if (f.indexOf("http:") == 0 || f.indexOf("https:")==0 || f.indexOf("file:") == 0)
4140 protocol = jalview.io.FormatAdapter.URL;
4143 boolean isAnnotation = new AnnotationFile().readAnnotationFile(
4144 viewport.alignment, file, protocol);
4148 // try to see if its a JNet 'concise' style annotation file *before* we
4149 // try to parse it as a features file
4150 String format = new IdentifyFile().Identify(file, protocol);
4151 if (format.equalsIgnoreCase("JnetFile"))
4153 jalview.io.JPredFile predictions = new jalview.io.JPredFile(file,
4155 new JnetAnnotationMaker().add_annotation(predictions, viewport
4156 .getAlignment(), 0, false);
4157 isAnnotation = true;
4161 // try to parse it as a features file
4162 boolean isGroupsFile = parseFeaturesFile(file, protocol);
4163 // if it wasn't a features file then we just treat it as a general
4164 // alignment file to load into the current view.
4167 new FileLoader().LoadFile(viewport, file, protocol, format);
4171 alignPanel.paintAlignment(true);
4178 alignPanel.adjustAnnotationHeight();
4179 viewport.updateSequenceIdColours();
4180 buildSortByAnnotationScoresMenu();
4181 alignPanel.paintAlignment(true);
4183 } catch (Exception ex)
4185 ex.printStackTrace();
4189 public void tabSelectionChanged(int index)
4193 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
4194 viewport = alignPanel.av;
4195 setMenusFromViewport(viewport);
4199 public void tabbedPane_mousePressed(MouseEvent e)
4201 if (SwingUtilities.isRightMouseButton(e))
4203 String reply = JOptionPane.showInternalInputDialog(this,
4204 "Enter View Name", "Edit View Name",
4205 JOptionPane.QUESTION_MESSAGE);
4209 viewport.viewName = reply;
4210 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply);
4215 public AlignViewport getCurrentView()
4221 * Open the dialog for regex description parsing.
4223 protected void extractScores_actionPerformed(ActionEvent e)
4225 ParseProperties pp = new jalview.analysis.ParseProperties(
4226 viewport.alignment);
4227 // TODO: verify regex and introduce GUI dialog for version 2.5
4228 // if (pp.getScoresFromDescription("col", "score column ",
4229 // "\\W*([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)",
4231 if (pp.getScoresFromDescription("description column",
4232 "score in description column ", "\\W*([-+eE0-9.]+)", true) > 0)
4234 buildSortByAnnotationScoresMenu();
4242 * jalview.jbgui.GAlignFrame#showDbRefs_actionPerformed(java.awt.event.ActionEvent
4245 protected void showDbRefs_actionPerformed(ActionEvent e)
4247 viewport.setShowDbRefs(showDbRefsMenuitem.isSelected());
4253 * @seejalview.jbgui.GAlignFrame#showNpFeats_actionPerformed(java.awt.event.
4256 protected void showNpFeats_actionPerformed(ActionEvent e)
4258 viewport.setShowNpFeats(showNpFeatsMenuitem.isSelected());
4262 * find the viewport amongst the tabs in this alignment frame and close that
4267 public boolean closeView(AlignViewport av)
4271 this.closeMenuItem_actionPerformed(false);
4274 Component[] comp = tabbedPane.getComponents();
4275 for (int i = 0; comp != null && i < comp.length; i++)
4277 if (comp[i] instanceof AlignmentPanel)
4279 if (((AlignmentPanel) comp[i]).av == av)
4282 closeView((AlignmentPanel) comp[i]);
4290 protected void build_fetchdbmenu(JMenu webService)
4292 // Temporary hack - DBRef Fetcher always top level ws entry.
4293 // TODO We probably want to store a sequence database checklist in
4294 // preferences and have checkboxes.. rather than individual sources selected
4296 JMenu rfetch = new JMenu("Fetch DB References");
4298 .setToolTipText("Retrieve and parse sequence database records for the alignment or the currently selected sequences");
4299 webService.add(rfetch);
4301 JMenuItem fetchr = new JMenuItem("Standard Databases");
4303 .setToolTipText("Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources");
4304 fetchr.addActionListener(new ActionListener()
4307 public void actionPerformed(ActionEvent e)
4309 new Thread(new Runnable()
4314 new jalview.ws.DBRefFetcher(alignPanel.av
4315 .getSequenceSelection(), alignPanel.alignFrame)
4316 .fetchDBRefs(false);
4324 JMenu dfetch = new JMenu();
4326 jalview.ws.SequenceFetcher sf = SequenceFetcher
4327 .getSequenceFetcherSingleton(this);
4328 String[] otherdb = sf.getOrderedSupportedSources();
4329 // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
4330 // jalview.util.QuickSort.sort(otherdb, otherdb);
4331 int comp = 0, mcomp = 15;
4332 String mname = null;
4333 if (otherdb != null && otherdb.length > 0)
4335 for (int i = 0; i < otherdb.length; i++)
4337 String dbname = sf.getSourceProxy(otherdb[i]).getDbName();
4340 mname = "from '" + dbname + "'";
4342 fetchr = new JMenuItem(otherdb[i]);
4343 final String[] dassource = new String[]
4345 fetchr.addActionListener(new ActionListener()
4348 public void actionPerformed(ActionEvent e)
4350 new Thread(new Runnable()
4355 new jalview.ws.DBRefFetcher(alignPanel.av
4356 .getSequenceSelection(), alignPanel.alignFrame,
4357 dassource).fetchDBRefs(false);
4363 fetchr.setToolTipText("Retrieve from " + dbname);
4365 if (comp++ == mcomp || i == (otherdb.length - 1))
4367 dfetch.setText(mname + " to '" + dbname + "'");
4369 dfetch = new JMenu();
4378 * Left justify the whole alignment.
4380 protected void justifyLeftMenuItem_actionPerformed(ActionEvent e)
4382 AlignmentI al = viewport.getAlignment();
4384 viewport.firePropertyChange("alignment", null, al);
4388 * Right justify the whole alignment.
4390 protected void justifyRightMenuItem_actionPerformed(ActionEvent e)
4392 AlignmentI al = viewport.getAlignment();
4394 viewport.firePropertyChange("alignment", null, al);
4397 public void setShowSeqFeatures(boolean b)
4399 showSeqFeatures.setSelected(true);
4400 viewport.setShowSequenceFeatures(true);
4407 * jalview.jbgui.GAlignFrame#showUnconservedMenuItem_actionPerformed(java.
4408 * awt.event.ActionEvent)
4410 protected void showUnconservedMenuItem_actionPerformed(ActionEvent e)
4412 viewport.setShowUnconserved(showUnconservedMenuItem.getState());
4413 alignPanel.paintAlignment(true);
4417 class PrintThread extends Thread
4421 public PrintThread(AlignmentPanel ap)
4426 static PageFormat pf;
4430 PrinterJob printJob = PrinterJob.getPrinterJob();
4434 printJob.setPrintable(ap, pf);
4438 printJob.setPrintable(ap);
4441 if (printJob.printDialog())
4446 } catch (Exception PrintException)
4448 PrintException.printStackTrace();