2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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 Softwarechang
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.*;
32 import jalview.analysis.*;
33 import jalview.commands.*;
34 import jalview.datamodel.*;
36 import jalview.jbgui.*;
37 import jalview.schemes.*;
46 public class AlignFrame
47 extends GAlignFrame implements DropTargetListener
50 public static final int DEFAULT_WIDTH = 700;
53 public static final int DEFAULT_HEIGHT = 500;
54 public AlignmentPanel alignPanel;
56 AlignViewport viewport;
58 Vector alignPanels = new Vector();
62 String currentFileFormat = null;
64 String fileName = null;
68 * Creates a new AlignFrame object.
70 * @param al DOCUMENT ME!
72 public AlignFrame(AlignmentI al, int width, int height)
74 this(al, null, width, height);
79 * new alignment window with hidden columns
80 * @param al AlignmentI
81 * @param hiddenColumns ColumnSelection or null
83 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
84 int width, int height)
86 this.setSize(width, height);
87 viewport = new AlignViewport(al, hiddenColumns);
89 alignPanel = new AlignmentPanel(this, viewport);
91 if(al.getDataset()==null)
96 addAlignmentPanel(alignPanel, true);
101 * Make a new AlignFrame from exisiting alignmentPanels
102 * @param ap AlignmentPanel
103 * @param av AlignViewport
105 public AlignFrame(AlignmentPanel ap)
109 addAlignmentPanel(ap, false);
115 if (viewport.conservation == null)
117 BLOSUM62Colour.setEnabled(false);
118 conservationMenuItem.setEnabled(false);
119 modifyConservation.setEnabled(false);
120 // PIDColour.setEnabled(false);
121 // abovePIDThreshold.setEnabled(false);
122 // modifyPID.setEnabled(false);
125 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
127 if (sortby.equals("Id"))
129 sortIDMenuItem_actionPerformed(null);
131 else if (sortby.equals("Pairwise Identity"))
133 sortPairwiseMenuItem_actionPerformed(null);
136 if (Desktop.desktop != null)
138 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
139 addServiceListeners();
140 setGUINucleotide(viewport.alignment.isNucleotide());
143 setMenusFromViewport(viewport);
145 if (viewport.wrapAlignment)
147 wrapMenuItem_actionPerformed(null);
150 if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW",false))
152 this.overviewMenuItem_actionPerformed(null);
159 public void setFileName(String file, String format)
162 currentFileFormat = format;
163 reload.setEnabled(true);
166 void addKeyListener()
168 addKeyListener(new KeyAdapter()
170 public void keyPressed(KeyEvent evt)
172 if (viewport.cursorMode &&
173 ( (evt.getKeyCode() >= KeyEvent.VK_0 &&
174 evt.getKeyCode() <= KeyEvent.VK_9)
176 (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0 &&
177 evt.getKeyCode() <= KeyEvent.VK_NUMPAD9)
179 && Character.isDigit(evt.getKeyChar()))
180 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
182 switch (evt.getKeyCode())
185 case 27: // escape key
186 deselectAllSequenceMenuItem_actionPerformed(null);
190 case KeyEvent.VK_DOWN:
191 if (evt.isAltDown() || !viewport.cursorMode)
192 moveSelectedSequences(false);
193 if (viewport.cursorMode)
194 alignPanel.seqPanel.moveCursor(0, 1);
198 if (evt.isAltDown() || !viewport.cursorMode)
199 moveSelectedSequences(true);
200 if (viewport.cursorMode)
201 alignPanel.seqPanel.moveCursor(0, -1);
205 case KeyEvent.VK_LEFT:
206 if (evt.isAltDown() || !viewport.cursorMode)
207 slideSequences(false,
208 alignPanel.seqPanel.getKeyboardNo1());
210 alignPanel.seqPanel.moveCursor( -1, 0);
215 case KeyEvent.VK_RIGHT:
216 if (evt.isAltDown() || !viewport.cursorMode)
218 alignPanel.seqPanel.getKeyboardNo1());
220 alignPanel.seqPanel.moveCursor(1, 0);
223 case KeyEvent.VK_SPACE:
224 if (viewport.cursorMode)
226 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
232 case KeyEvent.VK_DELETE:
233 case KeyEvent.VK_BACK_SPACE:
234 if (!viewport.cursorMode)
236 cut_actionPerformed(null);
240 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
248 if (viewport.cursorMode)
250 alignPanel.seqPanel.setCursorRow();
254 if (viewport.cursorMode && !evt.isControlDown())
256 alignPanel.seqPanel.setCursorColumn();
260 if (viewport.cursorMode)
262 alignPanel.seqPanel.setCursorPosition();
266 case KeyEvent.VK_ENTER:
267 case KeyEvent.VK_COMMA:
268 if (viewport.cursorMode)
270 alignPanel.seqPanel.setCursorRowAndColumn();
275 if (viewport.cursorMode)
277 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
281 if (viewport.cursorMode)
283 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
288 viewport.cursorMode = !viewport.cursorMode;
289 statusBar.setText("Keyboard editing mode is " +
290 (viewport.cursorMode ? "on" : "off"));
291 if (viewport.cursorMode)
293 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
294 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
296 alignPanel.seqPanel.seqCanvas.repaint();
302 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
303 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
304 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
306 javax.help.HelpBroker hb = hs.createHelpBroker();
307 hb.setCurrentID("home");
308 hb.setDisplayed(true);
312 ex.printStackTrace();
318 boolean toggleSeqs = !evt.isControlDown();
319 boolean toggleCols = !evt.isShiftDown();
321 boolean hide = false;
323 SequenceGroup sg = viewport.getSelectionGroup();
326 if (sg != null && sg.getSize() != viewport.alignment.getHeight())
328 hideSelSequences_actionPerformed(null);
331 else if (! (toggleCols &&
332 viewport.colSel.getSelected().size() > 0))
334 showAllSeqs_actionPerformed(null);
340 if (viewport.colSel.getSelected().size() > 0)
342 hideSelColumns_actionPerformed(null);
345 viewport.selectionGroup = sg;
350 showAllColumns_actionPerformed(null);
355 case KeyEvent.VK_PAGE_UP:
356 if (viewport.wrapAlignment)
358 alignPanel.scrollUp(true);
362 alignPanel.setScrollValues(viewport.startRes,
364 - viewport.endSeq + viewport.startSeq);
367 case KeyEvent.VK_PAGE_DOWN:
368 if (viewport.wrapAlignment)
370 alignPanel.scrollUp(false);
374 alignPanel.setScrollValues(viewport.startRes,
376 + viewport.endSeq - viewport.startSeq);
382 public void keyReleased(KeyEvent evt)
384 switch(evt.getKeyCode())
386 case KeyEvent.VK_LEFT:
387 if (evt.isAltDown() || !viewport.cursorMode)
388 viewport.firePropertyChange("alignment", null,
389 viewport.getAlignment().getSequences());
392 case KeyEvent.VK_RIGHT:
393 if (evt.isAltDown() || !viewport.cursorMode)
394 viewport.firePropertyChange("alignment", null,
395 viewport.getAlignment().getSequences());
403 public void addAlignmentPanel(final AlignmentPanel ap,
406 ap.alignFrame = this;
408 alignPanels.addElement(ap);
410 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
412 int aSize = alignPanels.size();
414 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
416 if (aSize == 1 && ap.av.viewName==null)
418 this.getContentPane().add(ap, BorderLayout.CENTER);
424 setInitialTabVisible();
427 expandViews.setEnabled(true);
428 gatherViews.setEnabled(true);
429 tabbedPane.addTab(ap.av.viewName, ap);
431 ap.setVisible(false);
438 ap.av.alignment.padGaps();
440 ap.av.updateConservation(ap);
441 ap.av.updateConsensus(ap);
445 public void setInitialTabVisible()
447 expandViews.setEnabled(true);
448 gatherViews.setEnabled(true);
449 tabbedPane.setVisible(true);
450 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
451 tabbedPane.addTab(first.av.viewName,first);
452 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
456 public AlignViewport getViewport()
461 /* Set up intrinsic listeners for dynamically generated GUI bits. */
462 private void addServiceListeners()
464 final java.beans.PropertyChangeListener thisListener;
465 // Do this once to get current state
466 BuildWebServiceMenu();
467 Desktop.discoverer.addPropertyChangeListener(
468 thisListener = new java.beans.PropertyChangeListener()
470 public void propertyChange(PropertyChangeEvent evt)
472 // System.out.println("Discoverer property change.");
473 if (evt.getPropertyName().equals("services"))
475 // System.out.println("Rebuilding web service menu");
476 BuildWebServiceMenu();
481 addInternalFrameListener(new javax.swing.event.
482 InternalFrameAdapter()
484 public void internalFrameClosed(
485 javax.swing.event.InternalFrameEvent evt)
487 // System.out.println("deregistering discoverer listener");
488 Desktop.discoverer.removePropertyChangeListener(thisListener);
489 closeMenuItem_actionPerformed(true);
495 public void setGUINucleotide(boolean nucleotide)
497 showTranslation.setVisible( nucleotide );
498 conservationMenuItem.setEnabled( !nucleotide );
499 modifyConservation.setEnabled( !nucleotide );
501 //Remember AlignFrame always starts as protein
504 calculateMenu.remove(calculateMenu.getItemCount()-2);
509 * Need to call this method when tabs are selected for multiple views,
510 * or when loading from Jalview2XML.java
511 * @param av AlignViewport
513 void setMenusFromViewport(AlignViewport av)
515 padGapsMenuitem.setSelected(av.padGaps);
516 colourTextMenuItem.setSelected(av.showColourText);
517 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
518 conservationMenuItem.setSelected(av.getConservationSelected());
519 seqLimits.setSelected(av.getShowJVSuffix());
520 idRightAlign.setSelected(av.rightAlignIds);
521 renderGapsMenuItem.setSelected(av.renderGaps);
522 wrapMenuItem.setSelected(av.wrapAlignment);
523 scaleAbove.setVisible(av.wrapAlignment);
524 scaleLeft.setVisible(av.wrapAlignment);
525 scaleRight.setVisible(av.wrapAlignment);
526 annotationPanelMenuItem.setState(av.showAnnotation);
527 viewBoxesMenuItem.setSelected(av.showBoxes);
528 viewTextMenuItem.setSelected(av.showText);
530 setColourSelected(ColourSchemeProperty.
531 getColourName(av.getGlobalColourScheme()));
533 showSeqFeatures.setSelected(av.showSequenceFeatures);
534 hiddenMarkers.setState(av.showHiddenMarkers);
535 applyToAllGroups.setState(av.colourAppliesToAllGroups);
541 Hashtable progressBars;
542 public void setProgressBar(String message, long id)
544 if(progressBars == null)
546 progressBars = new Hashtable();
549 JPanel progressPanel;
550 GridLayout layout = (GridLayout) statusPanel.getLayout();
551 if(progressBars.get( new Long(id) )!=null)
553 progressPanel = (JPanel)progressBars.get( new Long(id) );
554 statusPanel.remove(progressPanel);
555 progressBars.remove( progressPanel );
556 progressPanel = null;
559 statusBar.setText(message);
562 layout.setRows(layout.getRows() - 1);
566 progressPanel = new JPanel(new BorderLayout(10, 5));
568 JProgressBar progressBar = new JProgressBar();
569 progressBar.setIndeterminate(true);
571 progressPanel.add(new JLabel(message), BorderLayout.WEST);
572 progressPanel.add(progressBar, BorderLayout.CENTER);
574 layout.setRows(layout.getRows() + 1);
575 statusPanel.add(progressPanel);
577 progressBars.put(new Long(id), progressPanel);
587 Added so Castor Mapping file can obtain Jalview Version
589 public String getVersion()
591 return jalview.bin.Cache.getProperty("VERSION");
594 public FeatureRenderer getFeatureRenderer()
596 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
600 public void fetchSequence_actionPerformed(ActionEvent e)
602 new SequenceFetcher(this);
605 public void addFromFile_actionPerformed(ActionEvent e)
607 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
610 public void reload_actionPerformed(ActionEvent e)
614 if(currentFileFormat.equals("Jalview"))
616 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
617 for(int i=0; i<frames.length; i++)
619 if (frames[i] instanceof AlignFrame
621 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
625 frames[i].setSelected(true);
626 Desktop.instance.closeAssociatedWindows();
628 catch (java.beans.PropertyVetoException ex)
633 Desktop.instance.closeAssociatedWindows();
635 FileLoader loader = new FileLoader();
636 String protocol = fileName.startsWith("http:")? "URL":"File";
637 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
641 Rectangle bounds = this.getBounds();
643 FileLoader loader = new FileLoader();
644 String protocol = fileName.startsWith("http:") ? "URL" : "File";
645 AlignFrame newframe =
646 loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
648 newframe.setBounds(bounds);
650 this.closeMenuItem_actionPerformed(true);
656 public void addFromText_actionPerformed(ActionEvent e)
658 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
661 public void addFromURL_actionPerformed(ActionEvent e)
663 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
667 public void save_actionPerformed(ActionEvent e)
670 || currentFileFormat==null
671 || fileName.startsWith("http")
674 saveAs_actionPerformed(null);
678 saveAlignment(fileName, currentFileFormat);
685 * @param e DOCUMENT ME!
687 public void saveAs_actionPerformed(ActionEvent e)
689 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
690 getProperty( "LAST_DIRECTORY"),
692 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
694 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
699 chooser.setFileView(new JalviewFileView());
700 chooser.setDialogTitle("Save Alignment to file");
701 chooser.setToolTipText("Save");
703 int value = chooser.showSaveDialog(this);
705 if (value == JalviewFileChooser.APPROVE_OPTION)
707 currentFileFormat = chooser.getSelectedFormat();
708 if (currentFileFormat == null)
710 JOptionPane.showInternalMessageDialog(Desktop.desktop,
711 "You must select a file format before saving!",
712 "File format not specified",
713 JOptionPane.WARNING_MESSAGE);
714 value = chooser.showSaveDialog(this);
718 fileName = chooser.getSelectedFile().getPath();
720 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
723 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
725 saveAlignment(fileName, currentFileFormat);
729 public boolean saveAlignment(String file, String format)
731 boolean success = true;
733 if (format.equalsIgnoreCase("Jalview"))
735 String shortName = title;
737 if (shortName.indexOf(java.io.File.separatorChar) > -1)
739 shortName = shortName.substring(shortName.lastIndexOf(
740 java.io.File.separatorChar) + 1);
743 success = new Jalview2XML().SaveAlignment(this, file, shortName);
745 statusBar.setText("Successfully saved to file: "
747 +format +" format.");
753 String[] omitHidden = null;
755 if (viewport.hasHiddenColumns)
757 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
758 "The Alignment contains hidden columns."
759 + "\nDo you want to save only the visible alignment?",
760 "Save / Omit Hidden Columns",
761 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
763 if (reply == JOptionPane.YES_OPTION)
765 omitHidden = viewport.getViewAsString(false);
769 String output = new FormatAdapter().formatSequences(
771 viewport.alignment.getSequencesArray(),
782 java.io.PrintWriter out = new java.io.PrintWriter(
783 new java.io.FileWriter(file));
788 statusBar.setText("Successfully saved to file: "
790 + format + " format.");
795 ex.printStackTrace();
802 JOptionPane.showInternalMessageDialog(
803 this, "Couldn't save file: " + fileName,
805 JOptionPane.WARNING_MESSAGE);
814 * @param e DOCUMENT ME!
816 protected void outputText_actionPerformed(ActionEvent e)
818 String [] omitHidden = null;
820 if(viewport.hasHiddenColumns)
822 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
823 "The Alignment contains hidden columns."
824 +"\nDo you want to output only the visible alignment?",
825 "Save / Omit Hidden Columns",
826 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
828 if(reply==JOptionPane.YES_OPTION)
830 omitHidden = viewport.getViewAsString(false);
834 CutAndPasteTransfer cap = new CutAndPasteTransfer();
835 cap.setForInput(null);
836 Desktop.addInternalFrame(cap,
837 "Alignment output - " + e.getActionCommand(), 600,
841 cap.setText(new FormatAdapter().formatSequences(
842 e.getActionCommand(),
843 viewport.alignment.getSequencesArray(),
850 * @param e DOCUMENT ME!
852 protected void htmlMenuItem_actionPerformed(ActionEvent e)
854 new HTMLOutput(alignPanel,
855 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
856 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
859 public void createImageMap(File file, String image)
861 alignPanel.makePNGImageMap(file, image);
867 * @param e DOCUMENT ME!
869 public void createPNG(File f)
871 alignPanel.makePNG(f);
877 * @param e DOCUMENT ME!
879 public void createEPS(File f)
881 alignPanel.makeEPS(f);
885 public void pageSetup_actionPerformed(ActionEvent e)
887 PrinterJob printJob = PrinterJob.getPrinterJob();
888 PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
894 * @param e DOCUMENT ME!
896 public void printMenuItem_actionPerformed(ActionEvent e)
898 //Putting in a thread avoids Swing painting problems
899 PrintThread thread = new PrintThread(alignPanel);
903 public void exportFeatures_actionPerformed(ActionEvent e)
905 new AnnotationExporter().exportFeatures(alignPanel);
909 public void exportAnnotations_actionPerformed(ActionEvent e)
911 new AnnotationExporter().exportAnnotations(
913 viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
914 viewport.alignment.getGroups()
919 public void associatedData_actionPerformed(ActionEvent e)
921 // Pick the tree file
922 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
925 chooser.setFileView(new JalviewFileView());
926 chooser.setDialogTitle("Load Jalview Annotations or Features File");
927 chooser.setToolTipText("Load Jalview Annotations / Features file");
929 int value = chooser.showOpenDialog(null);
931 if (value == JalviewFileChooser.APPROVE_OPTION)
933 String choice = chooser.getSelectedFile().getPath();
934 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
935 loadJalviewDataFile(choice);
944 * @param e DOCUMENT ME!
946 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
948 if(alignPanels!=null && alignPanels.size()<2)
955 if(alignPanels!=null)
959 for (int i = 0; i < alignPanels.size(); i++)
961 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
962 jalview.structure.StructureSelectionManager.getStructureSelectionManager()
963 .removeStructureViewerListener(ap.seqPanel, null);
964 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
965 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
966 PaintRefresher.RemoveComponent(ap);
967 ap.av.alignment = null;
972 int index = tabbedPane.getSelectedIndex();
974 alignPanels.removeElement(alignPanel);
975 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
976 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
977 PaintRefresher.RemoveComponent(alignPanel);
978 viewport.alignment = null;
982 tabbedPane.removeTabAt(index);
983 tabbedPane.validate();
985 if(index==tabbedPane.getTabCount())
990 this.tabSelectionChanged(index);
996 this.setClosed(true);
1001 ex.printStackTrace();
1009 void updateEditMenuBar()
1012 if (viewport.historyList.size() > 0)
1014 undoMenuItem.setEnabled(true);
1015 CommandI command = (CommandI) viewport.historyList.peek();
1016 undoMenuItem.setText("Undo " + command.getDescription());
1020 undoMenuItem.setEnabled(false);
1021 undoMenuItem.setText("Undo");
1024 if (viewport.redoList.size() > 0)
1026 redoMenuItem.setEnabled(true);
1028 CommandI command = (CommandI) viewport.redoList.peek();
1029 redoMenuItem.setText("Redo " + command.getDescription());
1033 redoMenuItem.setEnabled(false);
1034 redoMenuItem.setText("Redo");
1039 public void addHistoryItem(CommandI command)
1041 if(command.getSize()>0)
1043 viewport.historyList.push(command);
1044 viewport.redoList.clear();
1045 updateEditMenuBar();
1046 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1055 * @param e DOCUMENT ME!
1057 protected void undoMenuItem_actionPerformed(ActionEvent e)
1059 CommandI command = (CommandI)viewport.historyList.pop();
1060 viewport.redoList.push(command);
1061 command.undoCommand();
1063 AlignViewport originalSource = getOriginatingSource(command);
1064 updateEditMenuBar();
1066 if(originalSource!=null)
1068 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1069 originalSource.firePropertyChange("alignment",
1071 originalSource.alignment.getSequences());
1078 * @param e DOCUMENT ME!
1080 protected void redoMenuItem_actionPerformed(ActionEvent e)
1082 if(viewport.redoList.size()<1)
1087 CommandI command = (CommandI) viewport.redoList.pop();
1088 viewport.historyList.push(command);
1089 command.doCommand();
1091 AlignViewport originalSource = getOriginatingSource(command);
1092 updateEditMenuBar();
1094 if(originalSource!=null)
1096 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1097 originalSource.firePropertyChange("alignment",
1099 originalSource.alignment.getSequences());
1103 AlignViewport getOriginatingSource(CommandI command)
1105 AlignViewport originalSource = null;
1106 //For sequence removal and addition, we need to fire
1107 //the property change event FROM the viewport where the
1108 //original alignment was altered
1110 if (command instanceof EditCommand)
1112 EditCommand editCommand = (EditCommand) command;
1113 al = editCommand.getAlignment();
1114 Vector comps = (Vector) PaintRefresher.components
1115 .get(viewport.getSequenceSetId());
1117 for (int i = 0; i < comps.size(); i++)
1119 if (comps.elementAt(i) instanceof AlignmentPanel)
1121 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1123 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1130 if (originalSource == null)
1132 //The original view is closed, we must validate
1133 //the current view against the closed view first
1136 PaintRefresher.validateSequences(al, viewport.alignment);
1139 originalSource = viewport;
1142 return originalSource;
1148 * @param up DOCUMENT ME!
1150 public void moveSelectedSequences(boolean up)
1152 SequenceGroup sg = viewport.getSelectionGroup();
1161 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1163 SequenceI seq = viewport.alignment.getSequenceAt(i);
1165 if (!sg.getSequences(null).contains(seq))
1170 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1172 if (sg.getSequences(null).contains(temp))
1177 viewport.alignment.getSequences().setElementAt(temp, i);
1178 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1183 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1185 SequenceI seq = viewport.alignment.getSequenceAt(i);
1187 if (!sg.getSequences(null).contains(seq))
1192 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1194 if (sg.getSequences(null).contains(temp))
1199 viewport.alignment.getSequences().setElementAt(temp, i);
1200 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1204 alignPanel.paintAlignment(true);
1210 synchronized void slideSequences(boolean right, int size)
1212 Vector sg = new Vector();
1213 if(viewport.cursorMode)
1215 sg.addElement(viewport.alignment.getSequenceAt(
1216 alignPanel.seqPanel.seqCanvas.cursorY));
1218 else if(viewport.getSelectionGroup()!=null
1219 && viewport.getSelectionGroup().getSize()!=viewport.alignment.getHeight())
1221 sg = viewport.getSelectionGroup().getSequences(
1222 viewport.hiddenRepSequences);
1230 Vector invertGroup = new Vector();
1232 for (int i = 0; i < viewport.alignment.getHeight(); i++)
1234 if(!sg.contains(viewport.alignment.getSequenceAt(i)))
1235 invertGroup.add(viewport.alignment.getSequenceAt(i));
1238 SequenceI[] seqs1 = new SequenceI[sg.size()];
1239 for (int i = 0; i < sg.size(); i++)
1240 seqs1[i] = (SequenceI) sg.elementAt(i);
1242 SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
1243 for (int i = 0; i < invertGroup.size(); i++)
1244 seqs2[i] = (SequenceI) invertGroup.elementAt(i);
1246 SlideSequencesCommand ssc;
1248 ssc = new SlideSequencesCommand("Slide Sequences",
1250 viewport.getGapCharacter()
1253 ssc = new SlideSequencesCommand("Slide Sequences",
1255 viewport.getGapCharacter()
1258 int groupAdjustment = 0;
1259 if (ssc.getGapsInsertedBegin() && right)
1261 if (viewport.cursorMode)
1262 alignPanel.seqPanel.moveCursor(size, 0);
1264 groupAdjustment = size;
1266 else if (!ssc.getGapsInsertedBegin() && !right)
1268 if (viewport.cursorMode)
1269 alignPanel.seqPanel.moveCursor( -size, 0);
1271 groupAdjustment = -size;
1274 if (groupAdjustment != 0)
1276 viewport.getSelectionGroup().setStartRes(
1277 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1278 viewport.getSelectionGroup().setEndRes(
1279 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1283 boolean appendHistoryItem = false;
1284 if(viewport.historyList!=null
1285 && viewport.historyList.size()>0
1286 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1288 appendHistoryItem = ssc.appendSlideCommand(
1289 (SlideSequencesCommand)viewport.historyList.peek())
1293 if(!appendHistoryItem)
1294 addHistoryItem(ssc);
1303 * @param e DOCUMENT ME!
1305 protected void copy_actionPerformed(ActionEvent e)
1308 if (viewport.getSelectionGroup() == null)
1312 // TODO: preserve the ordering of displayed alignment annotation in any internal paste (particularly sequence associated annotation)
1313 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1314 String[] omitHidden = null;
1316 if (viewport.hasHiddenColumns)
1318 omitHidden = viewport.getViewAsString(true);
1321 String output = new FormatAdapter().formatSequences(
1326 StringSelection ss = new StringSelection(output);
1330 jalview.gui.Desktop.internalCopy = true;
1331 //Its really worth setting the clipboard contents
1332 //to empty before setting the large StringSelection!!
1333 Toolkit.getDefaultToolkit().getSystemClipboard()
1334 .setContents(new StringSelection(""), null);
1336 Toolkit.getDefaultToolkit().getSystemClipboard()
1337 .setContents(ss, Desktop.instance);
1339 catch (OutOfMemoryError er)
1341 er.printStackTrace();
1342 javax.swing.SwingUtilities.invokeLater(new Runnable()
1346 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1347 "Out of memory copying region!!"
1349 "\nSee help files for increasing Java Virtual Machine memory."
1351 javax.swing.JOptionPane.WARNING_MESSAGE);
1358 Vector hiddenColumns = null;
1359 if(viewport.hasHiddenColumns)
1361 hiddenColumns =new Vector();
1362 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1363 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
1366 int[] region = (int[])
1367 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1369 hiddenColumns.addElement(new int[]
1370 {region[0] - hiddenOffset,
1371 region[1]-hiddenOffset});
1375 Desktop.jalviewClipboard = new Object[]
1378 viewport.alignment.getDataset(),
1380 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1386 * @param e DOCUMENT ME!
1388 protected void pasteNew_actionPerformed(ActionEvent e)
1396 * @param e DOCUMENT ME!
1398 protected void pasteThis_actionPerformed(ActionEvent e)
1406 * @param newAlignment DOCUMENT ME!
1408 void paste(boolean newAlignment)
1410 boolean externalPaste=true;
1413 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1414 Transferable contents = c.getContents(this);
1416 if (contents == null)
1424 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1425 if (str.length() < 1)
1430 format = new IdentifyFile().Identify(str, "Paste");
1433 catch (OutOfMemoryError er)
1435 er.printStackTrace();
1436 javax.swing.SwingUtilities.invokeLater(new Runnable()
1440 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1441 "Out of memory pasting sequences!!"
1443 "\nSee help files for increasing Java Virtual Machine memory."
1445 javax.swing.JOptionPane.WARNING_MESSAGE);
1452 SequenceI[] sequences;
1453 boolean annotationAdded = false;
1454 AlignmentI alignment = null;
1456 if(Desktop.jalviewClipboard!=null)
1458 // The clipboard was filled from within Jalview, we must use the sequences
1459 // And dataset from the copied alignment
1460 SequenceI[] newseq = (SequenceI[])Desktop.jalviewClipboard[0];
1461 // be doubly sure that we create *new* sequence objects.
1462 sequences = new SequenceI[newseq.length];
1463 for (int i=0;i<newseq.length;i++) {
1464 sequences[i] = new Sequence(newseq[i]);
1466 alignment = new Alignment(sequences);
1467 externalPaste = false;
1471 // parse the clipboard as an alignment.
1472 alignment = new FormatAdapter().readFile(str, "Paste", format);
1473 sequences = alignment.getSequencesArray();
1481 if (Desktop.jalviewClipboard != null)
1483 // dataset is inherited
1484 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1488 // new dataset is constructed
1489 alignment.setDataset(null);
1491 alwidth = alignment.getWidth()+1;
1495 AlignmentI pastedal = alignment; // preserve pasted alignment object
1496 // Add pasted sequences and dataset into existing alignment.
1497 alignment = viewport.getAlignment();
1498 alwidth = alignment.getWidth()+1;
1499 // decide if we need to import sequences from an existing dataset
1500 boolean importDs = Desktop.jalviewClipboard != null
1501 && Desktop.jalviewClipboard[1] != alignment.getDataset();
1502 // importDs==true instructs us to copy over new dataset sequences from
1503 // an existing alignment
1504 Vector newDs = (importDs) ? new Vector() : null; // used to create
1505 // minimum dataset set
1507 for (int i = 0; i < sequences.length; i++)
1511 newDs.addElement(null);
1513 SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
1515 if (importDs && ds != null)
1517 if (!newDs.contains(ds))
1519 newDs.setElementAt(ds, i);
1520 ds = new Sequence(ds);
1521 // update with new dataset sequence
1522 sequences[i].setDatasetSequence(ds);
1526 ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
1531 // copy and derive new dataset sequence
1532 sequences[i] = sequences[i].deriveSequence();
1533 alignment.getDataset().addSequence(sequences[i].getDatasetSequence());
1534 // TODO: avoid creation of duplicate dataset sequences with a
1535 // 'contains' method using SequenceI.equals()/SequenceI.contains()
1537 alignment.addSequence(sequences[i]); // merges dataset
1541 newDs.clear(); // tidy up
1543 if (pastedal.getAlignmentAnnotation()!=null) {
1544 // Add any annotation attached to alignment.
1545 AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
1546 for (int i=0; i<alann.length; i++)
1548 annotationAdded=true;
1549 if (alann[i].sequenceRef==null && !alann[i].autoCalculated) {
1550 AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
1551 newann.padAnnotation(alwidth);
1552 alignment.addAnnotation(newann);
1557 if (!newAlignment) {
1561 addHistoryItem(new EditCommand(
1566 alignment.getWidth(),
1570 // Add any annotations attached to sequences
1571 for (int i = 0; i < sequences.length; i++)
1573 if (sequences[i].getAnnotation() != null)
1575 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1577 annotationAdded=true;
1578 sequences[i].getAnnotation()[a].adjustForAlignment();
1579 sequences[i].getAnnotation()[a].padAnnotation(alwidth);
1580 alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
1581 alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
1587 if (!newAlignment) {
1588 // propagate alignment changed.
1589 viewport.setEndSeq(alignment.getHeight());
1590 if (annotationAdded)
1592 alignPanel.annotationPanel.adjustPanelHeight();
1594 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1596 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1597 String newtitle = new String("Copied sequences");
1599 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1601 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1602 for(int i=0; i<hc.size(); i++)
1604 int [] region = (int[]) hc.elementAt(i);
1605 af.viewport.hideColumns(region[0], region[1]);
1610 //>>>This is a fix for the moment, until a better solution is found!!<<<
1611 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1612 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1614 // TODO: maintain provenance of an alignment, rather than just make the title a concatenation of operations.
1615 if (!externalPaste) {
1616 if (title.startsWith("Copied sequences"))
1622 newtitle = newtitle.concat("- from " + title);
1625 newtitle = new String("Pasted sequences");
1628 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1635 catch (Exception ex)
1637 ex.printStackTrace();
1638 System.out.println("Exception whilst pasting: "+ex);
1639 // could be anything being pasted in here
1648 * @param e DOCUMENT ME!
1650 protected void cut_actionPerformed(ActionEvent e)
1652 copy_actionPerformed(null);
1653 delete_actionPerformed(null);
1659 * @param e DOCUMENT ME!
1661 protected void delete_actionPerformed(ActionEvent evt)
1664 SequenceGroup sg = viewport.getSelectionGroup();
1670 Vector seqs = new Vector();
1672 for (int i = 0; i < sg.getSize(); i++)
1674 seq = sg.getSequenceAt(i);
1675 seqs.addElement(seq);
1679 // If the cut affects all sequences, remove highlighted columns
1680 if (sg.getSize() == viewport.alignment.getHeight())
1682 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1683 sg.getEndRes() + 1);
1687 SequenceI [] cut = new SequenceI[seqs.size()];
1688 for(int i=0; i<seqs.size(); i++)
1690 cut[i] = (SequenceI)seqs.elementAt(i);
1697 addHistoryItem(new EditCommand("Cut Sequences",
1701 sg.getEndRes()-sg.getStartRes()+1,
1702 viewport.alignment));
1705 viewport.setSelectionGroup(null);
1706 viewport.alignment.deleteGroup(sg);
1708 viewport.firePropertyChange("alignment", null,
1709 viewport.getAlignment().getSequences());
1711 if (viewport.getAlignment().getHeight() < 1)
1715 this.setClosed(true);
1717 catch (Exception ex)
1726 * @param e DOCUMENT ME!
1728 protected void deleteGroups_actionPerformed(ActionEvent e)
1730 viewport.alignment.deleteAllGroups();
1731 viewport.sequenceColours = null;
1732 viewport.setSelectionGroup(null);
1733 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1734 alignPanel.paintAlignment(true);
1740 * @param e DOCUMENT ME!
1742 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1744 SequenceGroup sg = new SequenceGroup();
1746 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1749 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1752 sg.setEndRes(viewport.alignment.getWidth() - 1);
1753 viewport.setSelectionGroup(sg);
1754 alignPanel.paintAlignment(true);
1755 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1761 * @param e DOCUMENT ME!
1763 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1765 if(viewport.cursorMode)
1767 alignPanel.seqPanel.keyboardNo1 = null;
1768 alignPanel.seqPanel.keyboardNo2 = null;
1770 viewport.setSelectionGroup(null);
1771 viewport.getColumnSelection().clear();
1772 viewport.setSelectionGroup(null);
1773 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1774 alignPanel.idPanel.idCanvas.searchResults = null;
1775 alignPanel.paintAlignment(true);
1776 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1782 * @param e DOCUMENT ME!
1784 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1786 SequenceGroup sg = viewport.getSelectionGroup();
1790 selectAllSequenceMenuItem_actionPerformed(null);
1795 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1798 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1801 alignPanel.paintAlignment(true);
1803 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1806 public void invertColSel_actionPerformed(ActionEvent e)
1808 viewport.invertColumnSelection();
1809 alignPanel.paintAlignment(true);
1816 * @param e DOCUMENT ME!
1818 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1820 trimAlignment(true);
1826 * @param e DOCUMENT ME!
1828 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1830 trimAlignment(false);
1833 void trimAlignment(boolean trimLeft)
1835 ColumnSelection colSel = viewport.getColumnSelection();
1838 if (colSel.size() > 0)
1842 column = colSel.getMin();
1846 column = colSel.getMax();
1850 if(viewport.getSelectionGroup()!=null)
1852 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1853 hiddenRepSequences);
1857 seqs = viewport.alignment.getSequencesArray();
1861 TrimRegionCommand trimRegion;
1864 trimRegion = new TrimRegionCommand("Remove Left",
1865 TrimRegionCommand.TRIM_LEFT,
1870 viewport.selectionGroup);
1871 viewport.setStartRes(0);
1875 trimRegion = new TrimRegionCommand("Remove Right",
1876 TrimRegionCommand.TRIM_RIGHT,
1881 viewport.selectionGroup);
1884 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1887 addHistoryItem(trimRegion);
1889 Vector groups = viewport.alignment.getGroups();
1891 for (int i = 0; i < groups.size(); i++)
1893 SequenceGroup sg = (SequenceGroup) groups.get(i);
1895 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1896 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1898 viewport.alignment.deleteGroup(sg);
1902 viewport.firePropertyChange("alignment", null,
1903 viewport.getAlignment().getSequences());
1910 * @param e DOCUMENT ME!
1912 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1914 int start = 0, end = viewport.alignment.getWidth()-1;
1917 if (viewport.getSelectionGroup() != null)
1919 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1920 hiddenRepSequences);
1921 start = viewport.getSelectionGroup().getStartRes();
1922 end = viewport.getSelectionGroup().getEndRes();
1926 seqs = viewport.alignment.getSequencesArray();
1930 RemoveGapColCommand removeGapCols =
1931 new RemoveGapColCommand("Remove Gapped Columns",
1934 viewport.alignment);
1936 addHistoryItem(removeGapCols);
1938 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1940 //This is to maintain viewport position on first residue
1942 SequenceI seq = viewport.alignment.getSequenceAt(0);
1943 int startRes = seq.findPosition(viewport.startRes);
1944 // ShiftList shifts;
1945 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1946 // edit.alColumnChanges=shifts.getInverse();
1947 // if (viewport.hasHiddenColumns)
1948 // viewport.getColumnSelection().compensateForEdits(shifts);
1949 viewport.setStartRes(seq.findIndex(startRes)-1);
1950 viewport.firePropertyChange("alignment", null,
1951 viewport.getAlignment().getSequences());
1958 * @param e DOCUMENT ME!
1960 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1962 int start = 0, end = viewport.alignment.getWidth()-1;
1965 if (viewport.getSelectionGroup() != null)
1967 seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
1968 hiddenRepSequences);
1969 start = viewport.getSelectionGroup().getStartRes();
1970 end = viewport.getSelectionGroup().getEndRes();
1974 seqs = viewport.alignment.getSequencesArray();
1977 //This is to maintain viewport position on first residue
1979 SequenceI seq = viewport.alignment.getSequenceAt(0);
1980 int startRes = seq.findPosition(viewport.startRes);
1982 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1985 viewport.alignment));
1987 viewport.setStartRes(seq.findIndex(startRes)-1);
1989 viewport.firePropertyChange("alignment", null,
1990 viewport.getAlignment().getSequences());
1997 * @param e DOCUMENT ME!
1999 public void padGapsMenuitem_actionPerformed(ActionEvent e)
2001 viewport.padGaps = padGapsMenuitem.isSelected();
2003 viewport.firePropertyChange("alignment",
2005 viewport.getAlignment().getSequences());
2011 * @param e DOCUMENT ME!
2013 public void findMenuItem_actionPerformed(ActionEvent e)
2018 public void newView_actionPerformed(ActionEvent e)
2020 AlignmentPanel newap =
2021 new Jalview2XML().copyAlignPanel(alignPanel, true);
2023 newap.av.gatherViewsHere = false;
2025 if (viewport.viewName == null)
2027 viewport.viewName = "Original";
2030 newap.av.historyList = viewport.historyList;
2031 newap.av.redoList = viewport.redoList;
2033 int index = Desktop.getViewCount(viewport.getSequenceSetId());
2034 String newViewName = "View " +index;
2036 Vector comps = (Vector) PaintRefresher.components.get(viewport.
2037 getSequenceSetId());
2038 Vector existingNames = new Vector();
2039 for(int i=0; i<comps.size(); i++)
2041 if(comps.elementAt(i) instanceof AlignmentPanel)
2043 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
2044 if(!existingNames.contains(ap.av.viewName))
2046 existingNames.addElement(ap.av.viewName);
2051 while(existingNames.contains(newViewName))
2053 newViewName = "View "+ (++index);
2056 newap.av.viewName = newViewName;
2058 addAlignmentPanel(newap, false);
2060 if(alignPanels.size()==2)
2062 viewport.gatherViewsHere = true;
2064 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
2067 public void expandViews_actionPerformed(ActionEvent e)
2069 Desktop.instance.explodeViews(this);
2072 public void gatherViews_actionPerformed(ActionEvent e)
2074 Desktop.instance.gatherViews(this);
2082 * @param e DOCUMENT ME!
2084 public void font_actionPerformed(ActionEvent e)
2086 new FontChooser(alignPanel);
2093 * @param e DOCUMENT ME!
2095 protected void seqLimit_actionPerformed(ActionEvent e)
2097 viewport.setShowJVSuffix(seqLimits.isSelected());
2099 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
2100 alignPanel.paintAlignment(true);
2103 public void idRightAlign_actionPerformed(ActionEvent e)
2105 viewport.rightAlignIds = idRightAlign.isSelected();
2106 alignPanel.paintAlignment(true);
2114 * @param e DOCUMENT ME!
2116 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
2118 viewport.setColourText(colourTextMenuItem.isSelected());
2119 alignPanel.paintAlignment(true);
2125 * @param e DOCUMENT ME!
2127 public void wrapMenuItem_actionPerformed(ActionEvent e)
2129 scaleAbove.setVisible(wrapMenuItem.isSelected());
2130 scaleLeft.setVisible(wrapMenuItem.isSelected());
2131 scaleRight.setVisible(wrapMenuItem.isSelected());
2132 viewport.setWrapAlignment(wrapMenuItem.isSelected());
2133 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
2136 public void showAllSeqs_actionPerformed(ActionEvent e)
2138 viewport.showAllHiddenSeqs();
2141 public void showAllColumns_actionPerformed(ActionEvent e)
2143 viewport.showAllHiddenColumns();
2147 public void hideSelSequences_actionPerformed(ActionEvent e)
2149 viewport.hideAllSelectedSeqs();
2150 alignPanel.paintAlignment(true);
2153 public void hideSelColumns_actionPerformed(ActionEvent e)
2155 viewport.hideSelectedColumns();
2156 alignPanel.paintAlignment(true);
2159 public void hiddenMarkers_actionPerformed(ActionEvent e)
2161 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
2168 * @param e DOCUMENT ME!
2170 protected void scaleAbove_actionPerformed(ActionEvent e)
2172 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
2173 alignPanel.paintAlignment(true);
2179 * @param e DOCUMENT ME!
2181 protected void scaleLeft_actionPerformed(ActionEvent e)
2183 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
2184 alignPanel.paintAlignment(true);
2190 * @param e DOCUMENT ME!
2192 protected void scaleRight_actionPerformed(ActionEvent e)
2194 viewport.setScaleRightWrapped(scaleRight.isSelected());
2195 alignPanel.paintAlignment(true);
2201 * @param e DOCUMENT ME!
2203 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
2205 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
2206 alignPanel.paintAlignment(true);
2212 * @param e DOCUMENT ME!
2214 public void viewTextMenuItem_actionPerformed(ActionEvent e)
2216 viewport.setShowText(viewTextMenuItem.isSelected());
2217 alignPanel.paintAlignment(true);
2223 * @param e DOCUMENT ME!
2225 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
2227 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
2228 alignPanel.paintAlignment(true);
2232 public FeatureSettings featureSettings;
2233 public void featureSettings_actionPerformed(ActionEvent e)
2235 if(featureSettings !=null )
2237 featureSettings.close();
2238 featureSettings = null;
2240 featureSettings = new FeatureSettings(this);
2246 * @param evt DOCUMENT ME!
2248 public void showSeqFeatures_actionPerformed(ActionEvent evt)
2250 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
2251 alignPanel.paintAlignment(true);
2252 if (alignPanel.getOverviewPanel() != null)
2254 alignPanel.getOverviewPanel().updateOverviewImage();
2261 * @param e DOCUMENT ME!
2263 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
2265 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
2266 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
2272 * @param e DOCUMENT ME!
2274 public void overviewMenuItem_actionPerformed(ActionEvent e)
2276 if (alignPanel.overviewPanel != null)
2281 JInternalFrame frame = new JInternalFrame();
2282 OverviewPanel overview = new OverviewPanel(alignPanel);
2283 frame.setContentPane(overview);
2284 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2285 frame.getWidth(), frame.getHeight());
2287 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2288 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2290 public void internalFrameClosed(
2291 javax.swing.event.InternalFrameEvent evt)
2293 alignPanel.setOverviewPanel(null);
2298 alignPanel.setOverviewPanel(overview);
2301 public void textColour_actionPerformed(ActionEvent e)
2303 new TextColourChooser().chooseColour(alignPanel, null);
2309 * @param e DOCUMENT ME!
2311 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2319 * @param e DOCUMENT ME!
2321 public void clustalColour_actionPerformed(ActionEvent e)
2323 changeColour(new ClustalxColourScheme(
2324 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2330 * @param e DOCUMENT ME!
2332 public void zappoColour_actionPerformed(ActionEvent e)
2334 changeColour(new ZappoColourScheme());
2340 * @param e DOCUMENT ME!
2342 public void taylorColour_actionPerformed(ActionEvent e)
2344 changeColour(new TaylorColourScheme());
2350 * @param e DOCUMENT ME!
2352 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2354 changeColour(new HydrophobicColourScheme());
2360 * @param e DOCUMENT ME!
2362 public void helixColour_actionPerformed(ActionEvent e)
2364 changeColour(new HelixColourScheme());
2370 * @param e DOCUMENT ME!
2372 public void strandColour_actionPerformed(ActionEvent e)
2374 changeColour(new StrandColourScheme());
2380 * @param e DOCUMENT ME!
2382 public void turnColour_actionPerformed(ActionEvent e)
2384 changeColour(new TurnColourScheme());
2390 * @param e DOCUMENT ME!
2392 public void buriedColour_actionPerformed(ActionEvent e)
2394 changeColour(new BuriedColourScheme());
2400 * @param e DOCUMENT ME!
2402 public void nucleotideColour_actionPerformed(ActionEvent e)
2404 changeColour(new NucleotideColourScheme());
2407 public void annotationColour_actionPerformed(ActionEvent e)
2409 new AnnotationColourChooser(viewport, alignPanel);
2416 * @param e DOCUMENT ME!
2418 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2420 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2426 * @param cs DOCUMENT ME!
2428 public void changeColour(ColourSchemeI cs)
2434 if (viewport.getAbovePIDThreshold())
2436 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2439 cs.setThreshold(threshold,
2440 viewport.getIgnoreGapsConsensus());
2442 viewport.setGlobalColourScheme(cs);
2446 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2449 if (viewport.getConservationSelected())
2452 Alignment al = (Alignment) viewport.alignment;
2453 Conservation c = new Conservation("All",
2454 ResidueProperties.propHash, 3,
2455 al.getSequences(), 0,
2459 c.verdict(false, viewport.ConsPercGaps);
2461 cs.setConservation(c);
2463 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2468 cs.setConservation(null);
2471 cs.setConsensus(viewport.hconsensus);
2474 viewport.setGlobalColourScheme(cs);
2476 if (viewport.getColourAppliesToAllGroups())
2478 Vector groups = viewport.alignment.getGroups();
2480 for (int i = 0; i < groups.size(); i++)
2482 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2490 if (cs instanceof ClustalxColourScheme)
2492 sg.cs = new ClustalxColourScheme(
2493 sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
2495 else if (cs instanceof UserColourScheme)
2497 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2503 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2505 catch (Exception ex)
2510 if (viewport.getAbovePIDThreshold()
2511 || cs instanceof PIDColourScheme
2512 || cs instanceof Blosum62ColourScheme)
2514 sg.cs.setThreshold(threshold,
2515 viewport.getIgnoreGapsConsensus());
2517 sg.cs.setConsensus(AAFrequency.calculate(
2518 sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
2523 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2527 if (viewport.getConservationSelected())
2529 Conservation c = new Conservation("Group",
2530 ResidueProperties.propHash, 3,
2531 sg.getSequences(viewport.
2532 hiddenRepSequences),
2536 c.verdict(false, viewport.ConsPercGaps);
2537 sg.cs.setConservation(c);
2541 sg.cs.setConservation(null);
2546 if (alignPanel.getOverviewPanel() != null)
2548 alignPanel.getOverviewPanel().updateOverviewImage();
2554 alignPanel.paintAlignment(true);
2560 * @param e DOCUMENT ME!
2562 protected void modifyPID_actionPerformed(ActionEvent e)
2564 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2566 SliderPanel.setPIDSliderSource(alignPanel,
2567 viewport.getGlobalColourScheme(),
2569 SliderPanel.showPIDSlider();
2576 * @param e DOCUMENT ME!
2578 protected void modifyConservation_actionPerformed(ActionEvent e)
2580 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2582 SliderPanel.setConservationSlider(alignPanel,
2583 viewport.globalColourScheme,
2585 SliderPanel.showConservationSlider();
2592 * @param e DOCUMENT ME!
2594 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2596 viewport.setConservationSelected(conservationMenuItem.isSelected());
2598 viewport.setAbovePIDThreshold(false);
2599 abovePIDThreshold.setSelected(false);
2601 changeColour(viewport.getGlobalColourScheme());
2603 modifyConservation_actionPerformed(null);
2609 * @param e DOCUMENT ME!
2611 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2613 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2615 conservationMenuItem.setSelected(false);
2616 viewport.setConservationSelected(false);
2618 changeColour(viewport.getGlobalColourScheme());
2620 modifyPID_actionPerformed(null);
2626 * @param e DOCUMENT ME!
2628 public void userDefinedColour_actionPerformed(ActionEvent e)
2630 if (e.getActionCommand().equals("User Defined..."))
2632 new UserDefinedColours(alignPanel, null);
2636 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2637 getUserColourSchemes().get(e.getActionCommand());
2643 public void updateUserColourMenu()
2646 Component[] menuItems = colourMenu.getMenuComponents();
2647 int i, iSize = menuItems.length;
2648 for (i = 0; i < iSize; i++)
2650 if (menuItems[i].getName() != null &&
2651 menuItems[i].getName().equals("USER_DEFINED"))
2653 colourMenu.remove(menuItems[i]);
2657 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2659 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2660 getUserColourSchemes().keys();
2662 while (userColours.hasMoreElements())
2664 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
2666 nextElement().toString());
2667 radioItem.setName("USER_DEFINED");
2668 radioItem.addMouseListener(new MouseAdapter()
2670 public void mousePressed(MouseEvent evt)
2672 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2674 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2676 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
2678 "Remove from default list?",
2679 "Remove user defined colour",
2680 JOptionPane.YES_NO_OPTION);
2681 if(option == JOptionPane.YES_OPTION)
2683 jalview.gui.UserDefinedColours.removeColourFromDefaults(
2684 radioItem.getText());
2685 colourMenu.remove(radioItem);
2689 radioItem.addActionListener(new ActionListener()
2691 public void actionPerformed(ActionEvent evt)
2693 userDefinedColour_actionPerformed(evt);
2700 radioItem.addActionListener(new ActionListener()
2702 public void actionPerformed(ActionEvent evt)
2704 userDefinedColour_actionPerformed(evt);
2708 colourMenu.insert(radioItem, 15);
2709 colours.add(radioItem);
2717 * @param e DOCUMENT ME!
2719 public void PIDColour_actionPerformed(ActionEvent e)
2721 changeColour(new PIDColourScheme());
2727 * @param e DOCUMENT ME!
2729 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2731 changeColour(new Blosum62ColourScheme());
2737 * @param e DOCUMENT ME!
2739 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2741 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2742 AlignmentSorter.sortByPID(viewport.getAlignment(),
2743 viewport.getAlignment().getSequenceAt(0));
2744 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2745 viewport.alignment));
2746 alignPanel.paintAlignment(true);
2752 * @param e DOCUMENT ME!
2754 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2756 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2757 AlignmentSorter.sortByID(viewport.getAlignment());
2758 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2759 alignPanel.paintAlignment(true);
2765 * @param e DOCUMENT ME!
2767 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2769 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2770 AlignmentSorter.sortByGroup(viewport.getAlignment());
2771 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2773 alignPanel.paintAlignment(true);
2779 * @param e DOCUMENT ME!
2781 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2783 new RedundancyPanel(alignPanel, this);
2790 * @param e DOCUMENT ME!
2792 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2794 if ( (viewport.getSelectionGroup() == null) ||
2795 (viewport.getSelectionGroup().getSize() < 2))
2797 JOptionPane.showInternalMessageDialog(this,
2798 "You must select at least 2 sequences.",
2799 "Invalid Selection",
2800 JOptionPane.WARNING_MESSAGE);
2804 JInternalFrame frame = new JInternalFrame();
2805 frame.setContentPane(new PairwiseAlignPanel(viewport));
2806 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2813 * @param e DOCUMENT ME!
2815 public void PCAMenuItem_actionPerformed(ActionEvent e)
2817 if ( ( (viewport.getSelectionGroup() != null) &&
2818 (viewport.getSelectionGroup().getSize() < 4) &&
2819 (viewport.getSelectionGroup().getSize() > 0)) ||
2820 (viewport.getAlignment().getHeight() < 4))
2822 JOptionPane.showInternalMessageDialog(this,
2823 "Principal component analysis must take\n" +
2824 "at least 4 input sequences.",
2825 "Sequence selection insufficient",
2826 JOptionPane.WARNING_MESSAGE);
2831 new PCAPanel(alignPanel);
2835 public void autoCalculate_actionPerformed(ActionEvent e)
2837 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2838 if(viewport.autoCalculateConsensus)
2840 viewport.firePropertyChange("alignment",
2842 viewport.getAlignment().getSequences());
2850 * @param e DOCUMENT ME!
2852 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2854 NewTreePanel("AV", "PID", "Average distance tree using PID");
2860 * @param e DOCUMENT ME!
2862 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2864 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2870 * @param e DOCUMENT ME!
2872 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2874 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2880 * @param e DOCUMENT ME!
2882 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2884 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2890 * @param type DOCUMENT ME!
2891 * @param pwType DOCUMENT ME!
2892 * @param title DOCUMENT ME!
2894 void NewTreePanel(String type, String pwType, String title)
2898 if (viewport.getSelectionGroup() != null)
2900 if (viewport.getSelectionGroup().getSize() < 3)
2902 JOptionPane.showMessageDialog(Desktop.desktop,
2903 "You need to have more than two sequences selected to build a tree!",
2904 "Not enough sequences",
2905 JOptionPane.WARNING_MESSAGE);
2910 SequenceGroup sg = viewport.getSelectionGroup();
2912 /* Decide if the selection is a column region */
2913 while (s < sg.getSize())
2915 if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
2918 JOptionPane.showMessageDialog(Desktop.desktop,
2919 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2920 "Try using the Pad function in the edit menu,\n" +
2921 "or one of the multiple sequence alignment web services.",
2922 "Sequences in selection are not aligned",
2923 JOptionPane.WARNING_MESSAGE);
2929 title = title + " on region";
2930 tp = new TreePanel(alignPanel, type, pwType);
2934 //are the sequences aligned?
2935 if (!viewport.alignment.isAligned())
2937 JOptionPane.showMessageDialog(Desktop.desktop,
2938 "The sequences must be aligned before creating a tree.\n" +
2939 "Try using the Pad function in the edit menu,\n" +
2940 "or one of the multiple sequence alignment web services.",
2941 "Sequences not aligned",
2942 JOptionPane.WARNING_MESSAGE);
2947 if(viewport.alignment.getHeight()<2)
2952 tp = new TreePanel(alignPanel, type, pwType);
2957 if(viewport.viewName!=null)
2959 title+= viewport.viewName+" of ";
2962 title += this.title;
2964 Desktop.addInternalFrame(tp, title, 600, 500);
2970 * @param title DOCUMENT ME!
2971 * @param order DOCUMENT ME!
2973 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2975 final JMenuItem item = new JMenuItem("by " + title);
2977 item.addActionListener(new java.awt.event.ActionListener()
2979 public void actionPerformed(ActionEvent e)
2981 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2983 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2984 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2986 addHistoryItem(new OrderCommand(order.getName(), oldOrder,
2987 viewport.alignment));
2989 alignPanel.paintAlignment(true);
2995 * Maintain the Order by->Displayed Tree menu.
2996 * Creates a new menu item for a TreePanel with an appropriate
2997 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2998 * to remove the menu item when the treePanel is closed, and adjust
2999 * the tree leaf to sequence mapping when the alignment is modified.
3000 * @param treePanel Displayed tree window.
3001 * @param title SortBy menu item title.
3003 public void buildTreeMenu()
3005 sortByTreeMenu.removeAll();
3007 Vector comps = (Vector) PaintRefresher.components.get(viewport.
3008 getSequenceSetId());
3009 Vector treePanels = new Vector();
3010 int i, iSize = comps.size();
3011 for(i=0; i<iSize; i++)
3013 if(comps.elementAt(i) instanceof TreePanel)
3015 treePanels.add(comps.elementAt(i));
3019 iSize = treePanels.size();
3023 sortByTreeMenu.setVisible(false);
3027 sortByTreeMenu.setVisible(true);
3029 for(i=0; i<treePanels.size(); i++)
3031 TreePanel tp = (TreePanel)treePanels.elementAt(i);
3032 final JMenuItem item = new JMenuItem(tp.getTitle());
3033 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
3034 item.addActionListener(new java.awt.event.ActionListener()
3036 public void actionPerformed(ActionEvent e)
3038 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
3039 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
3041 addHistoryItem(new OrderCommand("Tree Sort",
3043 viewport.alignment));
3045 alignPanel.paintAlignment(true);
3049 sortByTreeMenu.add(item);
3054 * Work out whether the whole set of sequences
3055 * or just the selected set will be submitted for multiple alignment.
3058 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
3060 // Now, check we have enough sequences
3061 AlignmentView msa = null;
3063 if ( (viewport.getSelectionGroup() != null) &&
3064 (viewport.getSelectionGroup().getSize() > 1))
3066 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
3067 /*SequenceGroup seqs = viewport.getSelectionGroup();
3069 msa = new SequenceI[sz = seqs.getSize(false)];
3071 for (int i = 0; i < sz; i++)
3073 msa[i] = (SequenceI) seqs.getSequenceAt(i);
3075 msa = viewport.getAlignmentView(true);
3079 /*Vector seqs = viewport.getAlignment().getSequences();
3081 if (seqs.size() > 1)
3083 msa = new SequenceI[seqs.size()];
3085 for (int i = 0; i < seqs.size(); i++)
3087 msa[i] = (SequenceI) seqs.elementAt(i);
3090 msa = viewport.getAlignmentView(false);
3096 * Decides what is submitted to a secondary structure prediction service,
3097 * the currently selected sequence, or the currently selected alignment
3098 * (where the first sequence in the set is the one that the prediction
3101 AlignmentView gatherSeqOrMsaForSecStrPrediction()
3103 AlignmentView seqs = null;
3105 if ( (viewport.getSelectionGroup() != null) &&
3106 (viewport.getSelectionGroup().getSize() > 0))
3108 seqs = viewport.getAlignmentView(true);
3112 seqs = viewport.getAlignmentView(false);
3114 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
3115 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
3116 if (!viewport.alignment.isAligned())
3118 seqs.setSequences(new SeqCigar[]
3119 {seqs.getSequences()[0]});
3126 * @param e DOCUMENT ME!
3128 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
3130 // Pick the tree file
3131 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3134 chooser.setFileView(new JalviewFileView());
3135 chooser.setDialogTitle("Select a newick-like tree file");
3136 chooser.setToolTipText("Load a tree file");
3138 int value = chooser.showOpenDialog(null);
3140 if (value == JalviewFileChooser.APPROVE_OPTION)
3142 String choice = chooser.getSelectedFile().getPath();
3143 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
3147 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
3149 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
3151 catch (Exception ex)
3153 JOptionPane.showMessageDialog(Desktop.desktop,
3154 "Problem reading tree file",
3156 JOptionPane.WARNING_MESSAGE);
3157 ex.printStackTrace();
3163 public TreePanel ShowNewickTree(NewickFile nf, String title)
3165 return ShowNewickTree(nf,title,600,500,4,5);
3168 public TreePanel ShowNewickTree(NewickFile nf, String title,
3169 AlignmentView input)
3171 return ShowNewickTree(nf,title, input, 600,500,4,5);
3174 public TreePanel ShowNewickTree(NewickFile nf, String title, int w, int h,
3177 return ShowNewickTree(nf, title, null, w, h, x, y);
3180 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
3182 * @param nf the tree
3183 * @param title tree viewer title
3184 * @param input Associated alignment input data (or null)
3189 * @return TreePanel handle
3191 public TreePanel ShowNewickTree(NewickFile nf, String title,
3192 AlignmentView input, int w, int h, int x,
3195 TreePanel tp = null;
3201 if (nf.getTree() != null)
3203 tp = new TreePanel(alignPanel,
3212 tp.setLocation(x,y);
3216 Desktop.addInternalFrame(tp, title, w, h);
3219 catch (Exception ex)
3221 ex.printStackTrace();
3229 * Generates menu items and listener event actions for web service clients
3232 public void BuildWebServiceMenu()
3234 if ( (Discoverer.services != null)
3235 && (Discoverer.services.size() > 0))
3237 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
3238 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
3239 Vector wsmenu = new Vector();
3240 final AlignFrame af = this;
3243 // Add any Multiple Sequence Alignment Services
3244 final JMenu msawsmenu = new JMenu("Alignment");
3245 for (int i = 0, j = msaws.size(); i < j; i++)
3247 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
3249 final JMenuItem method = new JMenuItem(sh.getName());
3250 method.addActionListener(new ActionListener()
3252 public void actionPerformed(ActionEvent e)
3254 AlignmentView msa = gatherSequencesForAlignment();
3255 new jalview.ws.MsaWSClient(sh, title, msa,
3257 viewport.getAlignment().getDataset(),
3263 msawsmenu.add(method);
3264 // Deal with services that we know accept partial alignments.
3265 if (sh.getName().indexOf("lustal") > -1)
3267 // We know that ClustalWS can accept partial alignments for refinement.
3268 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
3269 methodR.addActionListener(new ActionListener()
3271 public void actionPerformed(ActionEvent e)
3273 AlignmentView msa = gatherSequencesForAlignment();
3274 new jalview.ws.MsaWSClient(sh, title, msa,
3276 viewport.getAlignment().getDataset(),
3282 msawsmenu.add(methodR);
3286 wsmenu.add(msawsmenu);
3288 if (secstrpr != null)
3290 // Add any secondary structure prediction services
3291 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3292 for (int i = 0, j = secstrpr.size(); i < j; i++)
3294 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3296 final JMenuItem method = new JMenuItem(sh.getName());
3297 method.addActionListener(new ActionListener()
3299 public void actionPerformed(ActionEvent e)
3301 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3302 if (msa.getSequences().length == 1)
3304 // Single Sequence prediction
3305 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3309 if (msa.getSequences().length > 1)
3311 // Sequence profile based prediction
3312 new jalview.ws.JPredClient(sh,
3313 title, true, msa, af, true);
3318 secstrmenu.add(method);
3320 wsmenu.add(secstrmenu);
3322 resetWebServiceMenu();
3323 for (int i = 0, j = wsmenu.size(); i < j; i++)
3325 webService.add( (JMenu) wsmenu.get(i));
3330 resetWebServiceMenu();
3331 this.webService.add(this.webServiceNoServices);
3333 // TODO: add in rediscovery function
3334 // TODO: reduce code redundancy.
3335 // TODO: group services by location as well as function.
3340 * empty the web service menu and add any ad-hoc functions
3341 * not dynamically discovered.
3344 private void resetWebServiceMenu()
3346 webService.removeAll();
3347 // Temporary hack - DBRef Fetcher always top level ws entry.
3348 JMenuItem rfetch = new JMenuItem("Fetch DB References");
3349 rfetch.setToolTipText("Retrieve and parse uniprot records for the alignment or the currently selected sequences");
3350 webService.add(rfetch);
3351 rfetch.addActionListener(new ActionListener() {
3353 public void actionPerformed(ActionEvent e)
3355 new jalview.io.DBRefFetcher(
3356 alignPanel.av.getSequenceSelection(),
3357 alignPanel.alignFrame).fetchDBRefs(false);
3363 /* public void vamsasStore_actionPerformed(ActionEvent e)
3365 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3366 getProperty("LAST_DIRECTORY"));
3368 chooser.setFileView(new JalviewFileView());
3369 chooser.setDialogTitle("Export to Vamsas file");
3370 chooser.setToolTipText("Export");
3372 int value = chooser.showSaveDialog(this);
3374 if (value == JalviewFileChooser.APPROVE_OPTION)
3376 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3377 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3378 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3384 public void showTranslation_actionPerformed(ActionEvent e)
3386 ///////////////////////////////
3387 // Collect Data to be translated/transferred
3389 SequenceI [] selection = viewport.getSequenceSelection();
3390 String [] seqstring = viewport.getViewAsString(true);
3391 AlignmentI al = null;
3393 al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring, viewport.getViewAsVisibleContigs(true),
3394 viewport.getGapCharacter(), viewport.alignment.getAlignmentAnnotation(),
3395 viewport.alignment.getWidth());
3396 } catch (Exception ex) {
3398 jalview.bin.Cache.log.debug("Exception during translation.",ex);
3402 JOptionPane.showMessageDialog(Desktop.desktop,
3403 "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
3404 "Translation Failed",
3405 JOptionPane.WARNING_MESSAGE);
3407 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3408 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3417 * @param String DOCUMENT ME!
3419 public boolean parseFeaturesFile(String file, String type)
3421 boolean featuresFile = false;
3424 featuresFile = new FeaturesFile(file,
3425 type).parse(viewport.alignment.getDataset(),
3426 alignPanel.seqPanel.seqCanvas.
3427 getFeatureRenderer().featureColours,
3432 ex.printStackTrace();
3437 viewport.showSequenceFeatures = true;
3438 showSeqFeatures.setSelected(true);
3439 alignPanel.paintAlignment(true);
3442 return featuresFile;
3445 public void dragEnter(DropTargetDragEvent evt)
3448 public void dragExit(DropTargetEvent evt)
3451 public void dragOver(DropTargetDragEvent evt)
3454 public void dropActionChanged(DropTargetDragEvent evt)
3457 public void drop(DropTargetDropEvent evt)
3459 Transferable t = evt.getTransferable();
3460 java.util.List files = null;
3464 DataFlavor uriListFlavor = new DataFlavor(
3465 "text/uri-list;class=java.lang.String");
3466 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3468 //Works on Windows and MacOSX
3469 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3470 files = (java.util.List) t.getTransferData(DataFlavor.
3471 javaFileListFlavor);
3473 else if (t.isDataFlavorSupported(uriListFlavor))
3475 // This is used by Unix drag system
3476 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3477 String data = (String) t.getTransferData(uriListFlavor);
3478 files = new java.util.ArrayList(1);
3479 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3482 st.hasMoreTokens(); )
3484 String s = st.nextToken();
3485 if (s.startsWith("#"))
3487 // the line is a comment (as per the RFC 2483)
3491 java.net.URI uri = new java.net.URI(s);
3492 java.io.File file = new java.io.File(uri);
3499 e.printStackTrace();
3506 for (int i = 0; i < files.size(); i++)
3508 loadJalviewDataFile(files.get(i).toString());
3511 catch (Exception ex)
3513 ex.printStackTrace();
3518 // This method will attempt to load a "dropped" file first by testing
3519 // whether its and Annotation file, then features file. If both are
3520 // false then the user may have dropped an alignment file onto this
3522 public void loadJalviewDataFile(String file)
3526 String protocol = "File";
3528 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3533 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3534 alignment, file, protocol);
3538 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3541 String format = new IdentifyFile().Identify(file, protocol);
3543 if(format.equalsIgnoreCase("JnetFile"))
3545 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3547 new JnetAnnotationMaker().add_annotation(predictions,
3548 viewport.getAlignment(),
3550 alignPanel.adjustAnnotationHeight();
3551 alignPanel.paintAlignment(true);
3555 new FileLoader().LoadFile(viewport, file, protocol, format);
3562 alignPanel.adjustAnnotationHeight();
3566 catch (Exception ex)
3568 ex.printStackTrace();
3572 public void tabSelectionChanged(int index)
3576 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3577 viewport = alignPanel.av;
3578 setMenusFromViewport(viewport);
3582 public void tabbedPane_mousePressed(MouseEvent e)
3584 if(SwingUtilities.isRightMouseButton(e))
3586 String reply = JOptionPane.showInternalInputDialog(this,
3589 JOptionPane.QUESTION_MESSAGE);
3593 viewport.viewName = reply;
3594 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3600 public AlignViewport getCurrentView()
3610 public PrintThread(AlignmentPanel ap)
3614 static PageFormat pf;
3617 PrinterJob printJob = PrinterJob.getPrinterJob();
3621 printJob.setPrintable(ap, pf);
3625 printJob.setPrintable(ap);
3628 if (printJob.printDialog())
3634 catch (Exception PrintException)
3636 PrintException.printStackTrace();