2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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.event.*;
28 import java.awt.print.*;
31 import jalview.analysis.*;
32 import jalview.datamodel.*;
34 import jalview.jbgui.*;
35 import jalview.schemes.*;
36 import jalview.commands.*;
38 import java.awt.dnd.*;
46 public class AlignFrame extends GAlignFrame implements DropTargetListener
49 public static final int DEFAULT_WIDTH = 700;
52 public static final int DEFAULT_HEIGHT = 500;
53 public AlignmentPanel alignPanel;
55 AlignViewport viewport;
57 Vector alignPanels = new Vector();
61 public String currentFileFormat = null;
63 private int treeCount = 0;
66 * Creates a new AlignFrame object.
68 * @param al DOCUMENT ME!
70 public AlignFrame(AlignmentI al, int width, int height)
72 this(al, null, width, height);
77 * new alignment window with hidden columns
78 * @param al AlignmentI
79 * @param hiddenColumns ColumnSelection or null
81 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
82 int width, int height)
84 this.setSize(width, height);
85 viewport = new AlignViewport(al, hiddenColumns);
87 alignPanel = new AlignmentPanel(this, viewport);
89 if(al.getDataset()==null)
94 addAlignmentPanel(alignPanel, true);
99 * Make a new AlignFrame from exisiting alignmentPanels
100 * @param ap AlignmentPanel
101 * @param av AlignViewport
103 public AlignFrame(AlignmentPanel ap)
107 addAlignmentPanel(ap, false);
113 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
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"))
128 sortIDMenuItem_actionPerformed(null);
129 else if (sortby.equals("Pairwise Identity"))
130 sortPairwiseMenuItem_actionPerformed(null);
132 if (Desktop.desktop != null)
134 addServiceListeners();
135 setGUINucleotide(viewport.alignment.isNucleotide());
138 setMenusFromViewport(viewport);
140 if (viewport.wrapAlignment)
142 wrapMenuItem_actionPerformed(null);
150 void addKeyListener()
152 final AlignFrame af = this;
153 addKeyListener(new KeyAdapter()
155 public void keyPressed(KeyEvent evt)
157 if (viewport.cursorMode
158 && evt.getKeyCode() >= KeyEvent.VK_0
159 && evt.getKeyCode() <= KeyEvent.VK_9)
161 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
164 switch (evt.getKeyCode())
167 if (!evt.isControlDown())
169 AlignmentPanel newap =
170 new Jalview2XML().copyAlignPanel(alignPanel, true);
172 if(viewport.viewName==null)
173 viewport.viewName="View 1";
175 newap.av.historyList = viewport.historyList;
176 newap.av.redoList = viewport.redoList;
177 newap.av.viewName = "View " +
178 (Desktop.getViewCount(viewport.getSequenceSetId())+1);
180 addAlignmentPanel(newap, false);
182 tabbedPane.setSelectedIndex(tabbedPane.getTabCount()-1);
187 Desktop.instance.gatherViews(af);
191 if (!evt.isControlDown())
193 Desktop.instance.explodeViews(af);
198 case 27: // escape key
199 deselectAllSequenceMenuItem_actionPerformed(null);
203 case KeyEvent.VK_DOWN:
204 if (viewport.cursorMode)
206 alignPanel.seqPanel.moveCursor(0, 1);
209 moveSelectedSequences(false);
213 if (viewport.cursorMode)
215 alignPanel.seqPanel.moveCursor(0, -1);
218 moveSelectedSequences(true);
221 case KeyEvent.VK_LEFT:
222 if (viewport.cursorMode)
224 alignPanel.seqPanel.moveCursor( -1, 0);
228 case KeyEvent.VK_RIGHT:
229 if (viewport.cursorMode)
231 alignPanel.seqPanel.moveCursor(1, 0);
235 case KeyEvent.VK_SPACE:
236 if (viewport.cursorMode)
238 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
244 case KeyEvent.VK_DELETE:
245 case KeyEvent.VK_BACK_SPACE:
246 if (!viewport.cursorMode)
248 cut_actionPerformed(null);
251 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
258 if (viewport.cursorMode)
260 alignPanel.seqPanel.setCursorRow();
264 if (viewport.cursorMode && !evt.isControlDown())
266 alignPanel.seqPanel.setCursorColumn();
270 if (viewport.cursorMode)
272 alignPanel.seqPanel.setCursorPosition();
276 case KeyEvent.VK_ENTER:
277 case KeyEvent.VK_COMMA:
278 if (viewport.cursorMode)
280 alignPanel.seqPanel.setCursorRowAndColumn();
285 if (viewport.cursorMode)
287 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
291 if (viewport.cursorMode)
293 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
298 viewport.cursorMode = !viewport.cursorMode;
299 statusBar.setText("Keyboard editing mode is " +
300 (viewport.cursorMode ? "on" : "off"));
301 if (viewport.cursorMode)
303 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
304 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
306 alignPanel.seqPanel.seqCanvas.repaint();
312 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
313 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
314 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
316 javax.help.HelpBroker hb = hs.createHelpBroker();
317 hb.setCurrentID("home");
318 hb.setDisplayed(true);
322 ex.printStackTrace();
328 boolean toggleSeqs = !evt.isControlDown();
329 boolean toggleCols = !evt.isShiftDown();
331 boolean hide = false;
333 SequenceGroup sg = viewport.getSelectionGroup();
336 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
338 hideSelSequences_actionPerformed(null);
341 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
342 showAllSeqs_actionPerformed(null);
347 if (viewport.colSel.getSelected().size() > 0)
349 hideSelColumns_actionPerformed(null);
351 viewport.selectionGroup = sg;
354 showAllColumns_actionPerformed(null);
358 case KeyEvent.VK_PAGE_UP:
359 if (viewport.wrapAlignment)
360 alignPanel.scrollUp(true);
362 alignPanel.setScrollValues(viewport.startRes,
364 - viewport.endSeq + viewport.startSeq);
366 case KeyEvent.VK_PAGE_DOWN:
367 if (viewport.wrapAlignment)
368 alignPanel.scrollUp(false);
370 alignPanel.setScrollValues(viewport.startRes,
372 + viewport.endSeq - viewport.startSeq);
380 public void addAlignmentPanel(final AlignmentPanel ap,
383 ap.alignFrame = this;
385 alignPanels.addElement(ap);
387 int aSize = alignPanels.size();
389 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
391 if (aSize == 1 && ap.av.viewName==null)
393 this.getContentPane().add(ap, BorderLayout.CENTER);
399 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
400 tabbedPane.addTab(first.av.viewName==null?"Original":first.av.viewName,first);
402 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
405 tabbedPane.addTab(ap.av.viewName==null?"Original":ap.av.viewName, ap);
407 ap.setVisible(false);
412 ap.av.updateConsensus(ap);
413 ap.av.updateConservation(ap);
418 public AlignViewport getViewport()
423 /* Set up intrinsic listeners for dynamically generated GUI bits. */
424 private void addServiceListeners()
426 final java.beans.PropertyChangeListener thisListener;
427 // Do this once to get current state
428 BuildWebServiceMenu();
429 Desktop.discoverer.addPropertyChangeListener(
430 thisListener = new java.beans.PropertyChangeListener()
432 public void propertyChange(PropertyChangeEvent evt)
434 // System.out.println("Discoverer property change.");
435 if (evt.getPropertyName().equals("services"))
437 // System.out.println("Rebuilding web service menu");
438 BuildWebServiceMenu();
443 addInternalFrameListener(new javax.swing.event.
444 InternalFrameAdapter()
446 public void internalFrameClosed(
447 javax.swing.event.InternalFrameEvent evt)
449 // System.out.println("deregistering discoverer listener");
450 Desktop.discoverer.removePropertyChangeListener(thisListener);
451 closeMenuItem_actionPerformed(null);
457 public void setGUINucleotide(boolean nucleotide)
459 showTranslation.setVisible( nucleotide );
460 conservationMenuItem.setEnabled( !nucleotide );
461 modifyConservation.setEnabled( !nucleotide );
463 //Remember AlignFrame always starts as protein
466 calculateMenu.remove(calculateMenu.getItemCount()-2);
471 * Need to call this method when tabs are selected for multiple views,
472 * or when loading from Jalview2XML.java
473 * @param av AlignViewport
475 void setMenusFromViewport(AlignViewport av)
477 colourTextMenuItem.setSelected(av.showColourText);
478 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
479 conservationMenuItem.setSelected(av.getConservationSelected());
480 seqLimits.setSelected(av.getShowJVSuffix());
481 renderGapsMenuItem.setSelected(av.renderGaps);
482 wrapMenuItem.setSelected(av.wrapAlignment);
483 annotationPanelMenuItem.setState(av.showAnnotation);
484 viewBoxesMenuItem.setSelected(av.showBoxes);
485 viewTextMenuItem.setSelected(av.showText);
487 setColourSelected(ColourSchemeProperty.
488 getColourName(av.getGlobalColourScheme()));
490 showSeqFeatures.setSelected(av.showSequenceFeatures);
491 hiddenMarkers.setState(av.showHiddenMarkers);
492 applyToAllGroups.setState(av.colourAppliesToAllGroups);
493 smoothFont.setState(av.antiAlias);
499 Hashtable progressBars;
500 public void setProgressBar(String message, long id)
502 if(progressBars == null)
503 progressBars = new Hashtable();
505 JPanel progressPanel;
506 GridLayout layout = (GridLayout) statusPanel.getLayout();
507 if(progressBars.get( new Long(id) )!=null)
509 progressPanel = (JPanel)progressBars.get( new Long(id) );
510 statusPanel.remove(progressPanel);
511 progressBars.remove( progressPanel );
512 progressPanel = null;
514 statusBar.setText(message);
516 layout.setRows(layout.getRows() - 1);
520 progressPanel = new JPanel(new BorderLayout(10, 5));
522 JProgressBar progressBar = new JProgressBar();
523 progressBar.setIndeterminate(true);
525 progressPanel.add(new JLabel(message), BorderLayout.WEST);
526 progressPanel.add(progressBar, BorderLayout.CENTER);
528 layout.setRows(layout.getRows() + 1);
529 statusPanel.add(progressPanel);
531 progressBars.put(new Long(id), progressPanel);
541 Added so Castor Mapping file can obtain Jalview Version
543 public String getVersion()
545 return jalview.bin.Cache.getProperty("VERSION");
548 public FeatureRenderer getFeatureRenderer()
550 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
554 public void fetchSequence_actionPerformed(ActionEvent e)
556 new SequenceFetcher(this);
559 public void addFromFile_actionPerformed(ActionEvent e)
561 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
564 public void addFromText_actionPerformed(ActionEvent e)
566 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
569 public void addFromURL_actionPerformed(ActionEvent e)
571 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
577 * @param e DOCUMENT ME!
579 public void saveAlignmentMenu_actionPerformed(ActionEvent e)
581 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
582 getProperty( "LAST_DIRECTORY"),
584 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
586 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
591 chooser.setFileView(new JalviewFileView());
592 chooser.setDialogTitle("Save Alignment to file");
593 chooser.setToolTipText("Save");
595 int value = chooser.showSaveDialog(this);
597 if (value == JalviewFileChooser.APPROVE_OPTION)
599 currentFileFormat = chooser.getSelectedFormat();
601 if (currentFileFormat == null)
603 JOptionPane.showInternalMessageDialog(Desktop.desktop,
604 "You must select a file format before saving!",
605 "File format not specified",
606 JOptionPane.WARNING_MESSAGE);
607 value = chooser.showSaveDialog(this);
611 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
614 String choice = chooser.getSelectedFile().getPath();
615 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
617 saveAlignment(choice, currentFileFormat);
621 public boolean saveAlignment(String file, String format)
623 if (format.equalsIgnoreCase("Jalview"))
625 String shortName = title;
627 if (shortName.indexOf(java.io.File.separatorChar) > -1)
629 shortName = shortName.substring(shortName.lastIndexOf(
630 java.io.File.separatorChar) + 1);
633 new Jalview2XML().SaveAlignment(this, file, shortName);
635 // USE Jalview2XML to save this file
641 String[] omitHidden = null;
643 if (viewport.hasHiddenColumns)
645 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
646 "The Alignment contains hidden columns."
647 + "\nDo you want to save only the visible alignment?",
648 "Save / Omit Hidden Columns",
649 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
651 if (reply == JOptionPane.YES_OPTION)
652 omitHidden = viewport.getViewAsString(false);
655 String output = new FormatAdapter().formatSequences(
657 viewport.alignment.getSequencesArray(),
667 java.io.PrintWriter out = new java.io.PrintWriter(
668 new java.io.FileWriter(file));
677 ex.printStackTrace();
686 * @param e DOCUMENT ME!
688 protected void outputText_actionPerformed(ActionEvent e)
690 String [] omitHidden = null;
692 if(viewport.hasHiddenColumns)
694 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
695 "The Alignment contains hidden columns."
696 +"\nDo you want to output only the visible alignment?",
697 "Save / Omit Hidden Columns",
698 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
700 if(reply==JOptionPane.YES_OPTION)
702 omitHidden = viewport.getViewAsString(false);
706 CutAndPasteTransfer cap = new CutAndPasteTransfer();
707 Desktop.addInternalFrame(cap,
708 "Alignment output - " + e.getActionCommand(), 600,
712 cap.setText(new FormatAdapter().formatSequences(
713 e.getActionCommand(),
714 viewport.alignment.getSequencesArray(),
721 * @param e DOCUMENT ME!
723 protected void htmlMenuItem_actionPerformed(ActionEvent e)
725 new HTMLOutput(viewport,
726 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
727 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
730 public void createImageMap(File file, String image)
732 alignPanel.makePNGImageMap(file, image);
738 * @param e DOCUMENT ME!
740 public void createPNG(File f)
742 alignPanel.makePNG(f);
748 * @param e DOCUMENT ME!
750 public void createEPS(File f)
752 alignPanel.makeEPS(f);
758 * @param e DOCUMENT ME!
760 public void printMenuItem_actionPerformed(ActionEvent e)
762 //Putting in a thread avoids Swing painting problems
763 PrintThread thread = new PrintThread();
767 public void exportFeatures_actionPerformed(ActionEvent e)
769 new AnnotationExporter().exportFeatures(alignPanel);
773 public void exportAnnotations_actionPerformed(ActionEvent e)
775 new AnnotationExporter().exportAnnotations(
777 viewport.alignment.getAlignmentAnnotation()
782 public void associatedData_actionPerformed(ActionEvent e)
784 // Pick the tree file
785 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
788 chooser.setFileView(new JalviewFileView());
789 chooser.setDialogTitle("Load Jalview Annotations or Features File");
790 chooser.setToolTipText("Load Jalview Annotations / Features file");
792 int value = chooser.showOpenDialog(null);
794 if (value == JalviewFileChooser.APPROVE_OPTION)
796 String choice = chooser.getSelectedFile().getPath();
797 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
798 loadJalviewDataFile(choice);
807 * @param e DOCUMENT ME!
809 public void closeMenuItem_actionPerformed(ActionEvent e)
813 if(alignPanels!=null)
815 for (int i = 0; i < alignPanels.size(); i++)
817 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
818 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
819 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
820 PaintRefresher.RemoveComponent(ap);
822 // alignPanels = null;
825 System.out.println("null one here");
827 // alignPanel = null;
830 this.setClosed(true);
834 ex.printStackTrace();
842 void updateEditMenuBar()
845 if (viewport.historyList.size() > 0)
847 undoMenuItem.setEnabled(true);
848 CommandI command = (CommandI) viewport.historyList.peek();
849 undoMenuItem.setText("Undo " + command.getDescription());
853 undoMenuItem.setEnabled(false);
854 undoMenuItem.setText("Undo");
857 if (viewport.redoList.size() > 0)
859 redoMenuItem.setEnabled(true);
861 CommandI command = (CommandI) viewport.redoList.peek();
862 redoMenuItem.setText("Redo " + command.getDescription());
866 redoMenuItem.setEnabled(false);
867 redoMenuItem.setText("Redo");
872 public void addHistoryItem(CommandI command)
874 if(command.getSize()>0)
876 viewport.historyList.push(command);
877 viewport.redoList.clear();
879 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
888 * @param e DOCUMENT ME!
890 protected void undoMenuItem_actionPerformed(ActionEvent e)
892 CommandI command = (CommandI)viewport.historyList.pop();
893 viewport.redoList.push(command);
894 command.undoCommand();
896 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
898 viewport.firePropertyChange("alignment", null,
899 viewport.getAlignment().getSequences());
905 * @param e DOCUMENT ME!
907 protected void redoMenuItem_actionPerformed(ActionEvent e)
909 CommandI command = (CommandI) viewport.redoList.pop();
910 viewport.historyList.push(command);
912 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null;
915 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
922 * @param up DOCUMENT ME!
924 public void moveSelectedSequences(boolean up)
926 SequenceGroup sg = viewport.getSelectionGroup();
935 for (int i = 1; i < viewport.alignment.getHeight(); i++)
937 SequenceI seq = viewport.alignment.getSequenceAt(i);
939 if (!sg.getSequences(false).contains(seq))
944 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
946 if (sg.getSequences(false).contains(temp))
951 viewport.alignment.getSequences().setElementAt(temp, i);
952 viewport.alignment.getSequences().setElementAt(seq, i - 1);
957 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
959 SequenceI seq = viewport.alignment.getSequenceAt(i);
961 if (!sg.getSequences(false).contains(seq))
966 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
968 if (sg.getSequences(false).contains(temp))
973 viewport.alignment.getSequences().setElementAt(temp, i);
974 viewport.alignment.getSequences().setElementAt(seq, i + 1);
978 alignPanel.repaint();
986 * @param e DOCUMENT ME!
988 protected void copy_actionPerformed(ActionEvent e)
991 if (viewport.getSelectionGroup() == null)
996 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
997 String[] omitHidden = null;
999 if (viewport.hasHiddenColumns)
1001 omitHidden = viewport.getViewAsString(true);
1004 String output = new FormatAdapter().formatSequences(
1009 StringSelection ss = new StringSelection(output);
1013 //Its really worth setting the clipboard contents
1014 //to empty before setting the large StringSelection!!
1015 Toolkit.getDefaultToolkit().getSystemClipboard()
1016 .setContents(new StringSelection(""), null);
1018 Toolkit.getDefaultToolkit().getSystemClipboard()
1019 .setContents(ss, Desktop.instance);
1021 catch (OutOfMemoryError er)
1023 er.printStackTrace();
1024 javax.swing.SwingUtilities.invokeLater(new Runnable()
1028 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1029 "Out of memory copying region!!"
1031 "\nSee help files for increasing Java Virtual Machine memory."
1033 javax.swing.JOptionPane.WARNING_MESSAGE);
1040 Vector hiddenColumns = null;
1041 if(viewport.hasHiddenColumns)
1043 hiddenColumns =new Vector();
1044 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1045 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1047 int[] region = (int[])
1048 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1050 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1051 region[1]-hiddenOffset});
1057 Desktop.jalviewClipboard = new Object[]{ seqs,
1058 viewport.alignment.getDataset(),
1060 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1066 * @param e DOCUMENT ME!
1068 protected void pasteNew_actionPerformed(ActionEvent e)
1076 * @param e DOCUMENT ME!
1078 protected void pasteThis_actionPerformed(ActionEvent e)
1086 * @param newAlignment DOCUMENT ME!
1088 void paste(boolean newAlignment)
1092 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1093 Transferable contents = c.getContents(this);
1095 if (contents == null)
1103 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1104 if (str.length() < 1)
1107 format = new IdentifyFile().Identify(str, "Paste");
1110 catch (OutOfMemoryError er)
1112 er.printStackTrace();
1113 javax.swing.SwingUtilities.invokeLater(new Runnable()
1117 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1118 "Out of memory pasting sequences!!"
1120 "\nSee help files for increasing Java Virtual Machine memory."
1122 javax.swing.JOptionPane.WARNING_MESSAGE);
1129 SequenceI[] sequences;
1132 if(Desktop.jalviewClipboard!=null)
1134 // The clipboard was filled from within Jalview, we must use the sequences
1135 // And dataset from the copied alignment
1136 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1140 sequences = new FormatAdapter().readFile(str, "Paste", format);
1143 AlignmentI alignment = null;
1147 alignment = new Alignment(sequences);
1149 if (Desktop.jalviewClipboard != null)
1150 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1152 alignment.setDataset(null);
1156 alignment = viewport.getAlignment();
1159 SequenceI [] newseqs = new SequenceI[sequences.length];
1160 for (int i = 0; i < sequences.length; i++)
1162 newseqs[i] = new Sequence(sequences[i].getName(),
1163 sequences[i].getSequence(), sequences[i].getStart(),
1164 sequences[i].getEnd());
1166 alignment.addSequence(newseqs[i]);
1172 addHistoryItem(new EditCommand(
1177 alignment.getWidth(),
1182 viewport.setEndSeq(alignment.getHeight());
1183 alignment.getWidth();
1184 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1189 // Add any annotations attached to sequences
1190 for (int i = 0; i < sequences.length; i++)
1192 if (sequences[i].getAnnotation() != null)
1194 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1196 AlignmentAnnotation newAnnot =
1197 new AlignmentAnnotation(
1198 sequences[i].getAnnotation()[a].label,
1199 sequences[i].getAnnotation()[a].description,
1200 sequences[i].getAnnotation()[a].annotations,
1201 sequences[i].getAnnotation()[a].graphMin,
1202 sequences[i].getAnnotation()[a].graphMax,
1203 sequences[i].getAnnotation()[a].graph);
1205 sequences[i].getAnnotation()[a] = newAnnot;
1206 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1208 newAnnot.sequenceRef = sequences[i];
1209 newAnnot.adjustForAlignment();
1210 alignment.addAnnotation(newAnnot);
1211 alignment.setAnnotationIndex(newAnnot, a);
1214 alignPanel.annotationPanel.adjustPanelHeight();
1220 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1221 String newtitle = new String("Copied sequences");
1223 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1225 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1226 for(int i=0; i<hc.size(); i++)
1228 int [] region = (int[]) hc.elementAt(i);
1229 af.viewport.hideColumns(region[0], region[1]);
1234 //>>>This is a fix for the moment, until a better solution is found!!<<<
1235 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1236 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1239 if (title.startsWith("Copied sequences"))
1245 newtitle = newtitle.concat("- from " + title);
1248 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1255 catch (Exception ex)
1257 ex.printStackTrace();
1258 System.out.println("Exception whilst pasting: "+ex);
1259 // could be anything being pasted in here
1268 * @param e DOCUMENT ME!
1270 protected void cut_actionPerformed(ActionEvent e)
1272 copy_actionPerformed(null);
1273 delete_actionPerformed(null);
1279 * @param e DOCUMENT ME!
1281 protected void delete_actionPerformed(ActionEvent e)
1284 SequenceGroup sg = viewport.getSelectionGroup();
1290 Vector seqs = new Vector();
1291 int cutLength = sg.getEndRes()-sg.getStartRes()+1;
1292 boolean seqsCut = false;
1294 for (int i = 0; i < sg.getSize(false); i++)
1296 seq = sg.getSequenceAt(i);
1297 seqs.addElement(seq);
1298 if(seq.getLength()<=cutLength)
1303 // If the cut affects all sequences, remove highlighted columns
1304 if (sg.getSize(false) == viewport.alignment.getHeight())
1306 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1307 sg.getEndRes() + 1);
1311 SequenceI [] cut = new SequenceI[seqs.size()];
1312 for(int i=0; i<seqs.size(); i++)
1313 cut[i] = (SequenceI)seqs.elementAt(i);
1319 addHistoryItem(new EditCommand("Cut Sequences",
1323 sg.getEndRes()-sg.getStartRes()+1,
1324 viewport.alignment));
1327 viewport.setSelectionGroup(null);
1328 viewport.alignment.deleteGroup(sg);
1330 viewport.firePropertyChange("alignment", null,
1331 viewport.getAlignment().getSequences());
1333 if (viewport.getAlignment().getHeight() < 1)
1337 this.setClosed(true);
1339 catch (Exception ex)
1348 * @param e DOCUMENT ME!
1350 protected void deleteGroups_actionPerformed(ActionEvent e)
1352 viewport.alignment.deleteAllGroups();
1353 viewport.setSelectionGroup(null);
1354 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1355 alignPanel.repaint();
1361 * @param e DOCUMENT ME!
1363 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1365 SequenceGroup sg = new SequenceGroup();
1367 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1370 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1373 sg.setEndRes(viewport.alignment.getWidth() - 1);
1374 viewport.setSelectionGroup(sg);
1375 alignPanel.repaint();
1376 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1382 * @param e DOCUMENT ME!
1384 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1386 if(viewport.cursorMode)
1388 alignPanel.seqPanel.keyboardNo1 = null;
1389 alignPanel.seqPanel.keyboardNo2 = null;
1391 viewport.setSelectionGroup(null);
1392 viewport.getColumnSelection().clear();
1393 viewport.setSelectionGroup(null);
1394 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1395 alignPanel.idPanel.idCanvas.searchResults = null;
1396 alignPanel.repaint();
1397 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1403 * @param e DOCUMENT ME!
1405 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1407 SequenceGroup sg = viewport.getSelectionGroup();
1411 selectAllSequenceMenuItem_actionPerformed(null);
1416 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1419 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1422 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1425 public void invertColSel_actionPerformed(ActionEvent e)
1427 viewport.invertColumnSelection();
1428 alignPanel.repaint();
1435 * @param e DOCUMENT ME!
1437 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1439 trimAlignment(true);
1445 * @param e DOCUMENT ME!
1447 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1449 trimAlignment(false);
1452 void trimAlignment(boolean trimLeft)
1454 ColumnSelection colSel = viewport.getColumnSelection();
1457 if (colSel.size() > 0)
1460 column = colSel.getMin();
1462 column = colSel.getMax();
1465 if(viewport.getSelectionGroup()!=null)
1466 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1468 seqs = viewport.alignment.getSequencesArray();
1471 TrimRegionCommand trimRegion;
1474 trimRegion = new TrimRegionCommand("Remove Left",
1475 TrimRegionCommand.TRIM_LEFT,
1480 viewport.selectionGroup);
1484 trimRegion = new TrimRegionCommand("Remove Right",
1485 TrimRegionCommand.TRIM_RIGHT,
1490 viewport.selectionGroup);
1493 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1496 addHistoryItem(trimRegion);
1498 Vector groups = viewport.alignment.getGroups();
1500 for (int i = 0; i < groups.size(); i++)
1502 SequenceGroup sg = (SequenceGroup) groups.get(i);
1504 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1505 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1507 viewport.alignment.deleteGroup(sg);
1511 viewport.firePropertyChange("alignment", null,
1512 viewport.getAlignment().getSequences());
1519 * @param e DOCUMENT ME!
1521 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1523 int start = 0, end = viewport.alignment.getWidth()-1;
1526 if (viewport.getSelectionGroup() != null)
1528 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1529 start = viewport.getSelectionGroup().getStartRes();
1530 end = viewport.getSelectionGroup().getEndRes();
1533 seqs = viewport.alignment.getSequencesArray();
1536 RemoveGapColCommand removeGapCols =
1537 new RemoveGapColCommand("Remove Gapped Columns",
1540 viewport.getGapCharacter());
1542 addHistoryItem(removeGapCols);
1544 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1546 //This is to maintain viewport position on first residue
1548 SequenceI seq = viewport.alignment.getSequenceAt(0);
1549 int startRes = seq.findPosition(viewport.startRes);
1550 // ShiftList shifts;
1551 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1552 // edit.alColumnChanges=shifts.getInverse();
1553 // if (viewport.hasHiddenColumns)
1554 // viewport.getColumnSelection().compensateForEdits(shifts);
1555 viewport.setStartRes(seq.findIndex(startRes)-1);
1556 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1563 * @param e DOCUMENT ME!
1565 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1567 int start = 0, end = viewport.alignment.getWidth()-1;
1570 if (viewport.getSelectionGroup() != null)
1572 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1573 start = viewport.getSelectionGroup().getStartRes();
1574 end = viewport.getSelectionGroup().getEndRes();
1577 seqs = viewport.alignment.getSequencesArray();
1579 //This is to maintain viewport position on first residue
1581 SequenceI seq = viewport.alignment.getSequenceAt(0);
1582 int startRes = seq.findPosition(viewport.startRes);
1584 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1587 viewport.getGapCharacter()));
1589 viewport.setStartRes(seq.findIndex(startRes)-1);
1591 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1598 * @param e DOCUMENT ME!
1600 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1602 viewport.padGaps = padGapsMenuitem.isSelected();
1604 viewport.firePropertyChange("alignment",
1606 viewport.getAlignment().getSequences());
1612 * @param e DOCUMENT ME!
1614 public void findMenuItem_actionPerformed(ActionEvent e)
1616 JInternalFrame frame = new JInternalFrame();
1617 Finder finder = new Finder(viewport, alignPanel, frame);
1618 frame.setContentPane(finder);
1619 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1620 Desktop.addInternalFrame(frame, "Find", 340, 110);
1626 * @param e DOCUMENT ME!
1628 public void font_actionPerformed(ActionEvent e)
1630 new FontChooser(alignPanel);
1633 public void smoothFont_actionPerformed(ActionEvent e)
1635 viewport.antiAlias = smoothFont.isSelected();
1636 alignPanel.annotationPanel.image = null;
1637 alignPanel.repaint();
1644 * @param e DOCUMENT ME!
1646 protected void seqLimit_actionPerformed(ActionEvent e)
1648 viewport.setShowJVSuffix(seqLimits.isSelected());
1650 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1651 alignPanel.repaint();
1658 * @param e DOCUMENT ME!
1660 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1662 viewport.setColourText(colourTextMenuItem.isSelected());
1663 alignPanel.repaint();
1669 * @param e DOCUMENT ME!
1671 public void wrapMenuItem_actionPerformed(ActionEvent e)
1673 scaleAbove.setVisible(wrapMenuItem.isSelected());
1674 scaleLeft.setVisible(wrapMenuItem.isSelected());
1675 scaleRight.setVisible(wrapMenuItem.isSelected());
1676 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1677 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1680 public void showAllSeqs_actionPerformed(ActionEvent e)
1682 viewport.showAllHiddenSeqs();
1685 public void showAllColumns_actionPerformed(ActionEvent e)
1687 viewport.showAllHiddenColumns();
1691 public void hideSelSequences_actionPerformed(ActionEvent e)
1693 viewport.hideAllSelectedSeqs();
1694 alignPanel.repaint();
1697 public void hideSelColumns_actionPerformed(ActionEvent e)
1699 viewport.hideSelectedColumns();
1700 alignPanel.repaint();
1703 public void hiddenMarkers_actionPerformed(ActionEvent e)
1705 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1712 * @param e DOCUMENT ME!
1714 protected void scaleAbove_actionPerformed(ActionEvent e)
1716 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1717 alignPanel.repaint();
1723 * @param e DOCUMENT ME!
1725 protected void scaleLeft_actionPerformed(ActionEvent e)
1727 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1728 alignPanel.repaint();
1734 * @param e DOCUMENT ME!
1736 protected void scaleRight_actionPerformed(ActionEvent e)
1738 viewport.setScaleRightWrapped(scaleRight.isSelected());
1739 alignPanel.repaint();
1745 * @param e DOCUMENT ME!
1747 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1749 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1750 alignPanel.repaint();
1756 * @param e DOCUMENT ME!
1758 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1760 viewport.setShowText(viewTextMenuItem.isSelected());
1761 alignPanel.repaint();
1767 * @param e DOCUMENT ME!
1769 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1771 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1772 alignPanel.repaint();
1776 public FeatureSettings featureSettings;
1777 public void featureSettings_actionPerformed(ActionEvent e)
1779 if(featureSettings !=null )
1781 featureSettings.close();
1782 featureSettings = null;
1784 featureSettings = new FeatureSettings(this);
1790 * @param evt DOCUMENT ME!
1792 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1794 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1795 alignPanel.repaint();
1796 if (alignPanel.getOverviewPanel() != null)
1798 alignPanel.getOverviewPanel().updateOverviewImage();
1805 * @param e DOCUMENT ME!
1807 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1809 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1810 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1816 * @param e DOCUMENT ME!
1818 public void overviewMenuItem_actionPerformed(ActionEvent e)
1820 if (alignPanel.overviewPanel != null)
1825 JInternalFrame frame = new JInternalFrame();
1826 OverviewPanel overview = new OverviewPanel(alignPanel);
1827 frame.setContentPane(overview);
1828 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1829 frame.getWidth(), frame.getHeight());
1831 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1832 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1834 public void internalFrameClosed(
1835 javax.swing.event.InternalFrameEvent evt)
1837 alignPanel.setOverviewPanel(null);
1842 alignPanel.setOverviewPanel(overview);
1848 * @param e DOCUMENT ME!
1850 protected void noColourmenuItem_actionPerformed(ActionEvent e)
1858 * @param e DOCUMENT ME!
1860 public void clustalColour_actionPerformed(ActionEvent e)
1862 changeColour(new ClustalxColourScheme(
1863 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
1869 * @param e DOCUMENT ME!
1871 public void zappoColour_actionPerformed(ActionEvent e)
1873 changeColour(new ZappoColourScheme());
1879 * @param e DOCUMENT ME!
1881 public void taylorColour_actionPerformed(ActionEvent e)
1883 changeColour(new TaylorColourScheme());
1889 * @param e DOCUMENT ME!
1891 public void hydrophobicityColour_actionPerformed(ActionEvent e)
1893 changeColour(new HydrophobicColourScheme());
1899 * @param e DOCUMENT ME!
1901 public void helixColour_actionPerformed(ActionEvent e)
1903 changeColour(new HelixColourScheme());
1909 * @param e DOCUMENT ME!
1911 public void strandColour_actionPerformed(ActionEvent e)
1913 changeColour(new StrandColourScheme());
1919 * @param e DOCUMENT ME!
1921 public void turnColour_actionPerformed(ActionEvent e)
1923 changeColour(new TurnColourScheme());
1929 * @param e DOCUMENT ME!
1931 public void buriedColour_actionPerformed(ActionEvent e)
1933 changeColour(new BuriedColourScheme());
1939 * @param e DOCUMENT ME!
1941 public void nucleotideColour_actionPerformed(ActionEvent e)
1943 changeColour(new NucleotideColourScheme());
1946 public void annotationColour_actionPerformed(ActionEvent e)
1948 new AnnotationColourChooser(viewport, alignPanel);
1955 * @param e DOCUMENT ME!
1957 protected void applyToAllGroups_actionPerformed(ActionEvent e)
1959 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
1965 * @param cs DOCUMENT ME!
1967 public void changeColour(ColourSchemeI cs)
1973 if (viewport.getAbovePIDThreshold())
1975 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
1978 cs.setThreshold(threshold,
1979 viewport.getIgnoreGapsConsensus());
1981 viewport.setGlobalColourScheme(cs);
1985 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
1988 if (viewport.getConservationSelected())
1991 Alignment al = (Alignment) viewport.alignment;
1992 Conservation c = new Conservation("All",
1993 ResidueProperties.propHash, 3,
1994 al.getSequences(), 0,
1998 c.verdict(false, viewport.ConsPercGaps);
2000 cs.setConservation(c);
2002 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2007 cs.setConservation(null);
2010 cs.setConsensus(viewport.hconsensus);
2013 viewport.setGlobalColourScheme(cs);
2015 if (viewport.getColourAppliesToAllGroups())
2017 Vector groups = viewport.alignment.getGroups();
2019 for (int i = 0; i < groups.size(); i++)
2021 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2029 if (cs instanceof ClustalxColourScheme)
2031 sg.cs = new ClustalxColourScheme(
2032 sg.getSequences(true), sg.getWidth());
2034 else if (cs instanceof UserColourScheme)
2036 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2042 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2044 catch (Exception ex)
2049 if (viewport.getAbovePIDThreshold()
2050 || cs instanceof PIDColourScheme
2051 || cs instanceof Blosum62ColourScheme)
2053 sg.cs.setThreshold(threshold,
2054 viewport.getIgnoreGapsConsensus());
2056 sg.cs.setConsensus(AAFrequency.calculate(
2057 sg.getSequences(true), 0,
2061 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2064 if (viewport.getConservationSelected())
2066 Conservation c = new Conservation("Group",
2067 ResidueProperties.propHash, 3,
2068 sg.getSequences(true), 0,
2069 viewport.alignment.getWidth() - 1);
2071 c.verdict(false, viewport.ConsPercGaps);
2072 sg.cs.setConservation(c);
2075 sg.cs.setConservation(null);
2079 if (alignPanel.getOverviewPanel() != null)
2081 alignPanel.getOverviewPanel().updateOverviewImage();
2084 alignPanel.repaint();
2090 * @param e DOCUMENT ME!
2092 protected void modifyPID_actionPerformed(ActionEvent e)
2094 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2096 SliderPanel.setPIDSliderSource(alignPanel,
2097 viewport.getGlobalColourScheme(),
2099 SliderPanel.showPIDSlider();
2106 * @param e DOCUMENT ME!
2108 protected void modifyConservation_actionPerformed(ActionEvent e)
2110 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2112 SliderPanel.setConservationSlider(alignPanel,
2113 viewport.globalColourScheme,
2115 SliderPanel.showConservationSlider();
2122 * @param e DOCUMENT ME!
2124 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2126 viewport.setConservationSelected(conservationMenuItem.isSelected());
2128 viewport.setAbovePIDThreshold(false);
2129 abovePIDThreshold.setSelected(false);
2131 changeColour(viewport.getGlobalColourScheme());
2133 modifyConservation_actionPerformed(null);
2139 * @param e DOCUMENT ME!
2141 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2143 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2145 conservationMenuItem.setSelected(false);
2146 viewport.setConservationSelected(false);
2148 changeColour(viewport.getGlobalColourScheme());
2150 modifyPID_actionPerformed(null);
2156 * @param e DOCUMENT ME!
2158 public void userDefinedColour_actionPerformed(ActionEvent e)
2160 if (e.getActionCommand().equals("User Defined..."))
2162 new UserDefinedColours(alignPanel, null);
2166 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2167 getUserColourSchemes().get(e.getActionCommand());
2173 public void updateUserColourMenu()
2176 Component[] menuItems = colourMenu.getMenuComponents();
2177 int i, iSize = menuItems.length;
2178 for (i = 0; i < iSize; i++)
2180 if (menuItems[i].getName() != null &&
2181 menuItems[i].getName().equals("USER_DEFINED"))
2183 colourMenu.remove(menuItems[i]);
2187 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2189 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2190 getUserColourSchemes().keys();
2192 while (userColours.hasMoreElements())
2194 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2195 nextElement().toString());
2196 radioItem.setName("USER_DEFINED");
2197 radioItem.addMouseListener(new MouseAdapter()
2199 public void mousePressed(MouseEvent evt)
2201 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2203 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2205 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2206 "Remove from default list?",
2207 "Remove user defined colour",
2208 JOptionPane.YES_NO_OPTION);
2209 if(option == JOptionPane.YES_OPTION)
2211 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2212 colourMenu.remove(radioItem);
2215 radioItem.addActionListener(new ActionListener()
2217 public void actionPerformed(ActionEvent evt)
2219 userDefinedColour_actionPerformed(evt);
2225 radioItem.addActionListener(new ActionListener()
2227 public void actionPerformed(ActionEvent evt)
2229 userDefinedColour_actionPerformed(evt);
2233 colourMenu.insert(radioItem, 15);
2234 colours.add(radioItem);
2242 * @param e DOCUMENT ME!
2244 public void PIDColour_actionPerformed(ActionEvent e)
2246 changeColour(new PIDColourScheme());
2252 * @param e DOCUMENT ME!
2254 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2256 changeColour(new Blosum62ColourScheme());
2262 * @param e DOCUMENT ME!
2264 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2266 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2267 AlignmentSorter.sortByPID(viewport.getAlignment(),
2268 viewport.getAlignment().getSequenceAt(0));
2269 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2270 alignPanel.repaint();
2276 * @param e DOCUMENT ME!
2278 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2280 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2281 AlignmentSorter.sortByID(viewport.getAlignment());
2282 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2283 alignPanel.repaint();
2289 * @param e DOCUMENT ME!
2291 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2293 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2294 AlignmentSorter.sortByGroup(viewport.getAlignment());
2295 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2297 alignPanel.repaint();
2303 * @param e DOCUMENT ME!
2305 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2307 new RedundancyPanel(alignPanel, this);
2314 * @param e DOCUMENT ME!
2316 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2318 if ( (viewport.getSelectionGroup() == null) ||
2319 (viewport.getSelectionGroup().getSize(false) < 2))
2321 JOptionPane.showInternalMessageDialog(this,
2322 "You must select at least 2 sequences.",
2323 "Invalid Selection",
2324 JOptionPane.WARNING_MESSAGE);
2328 JInternalFrame frame = new JInternalFrame();
2329 frame.setContentPane(new PairwiseAlignPanel(viewport));
2330 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2337 * @param e DOCUMENT ME!
2339 public void PCAMenuItem_actionPerformed(ActionEvent e)
2341 if ( ( (viewport.getSelectionGroup() != null) &&
2342 (viewport.getSelectionGroup().getSize(false) < 4) &&
2343 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2344 (viewport.getAlignment().getHeight() < 4))
2346 JOptionPane.showInternalMessageDialog(this,
2347 "Principal component analysis must take\n" +
2348 "at least 4 input sequences.",
2349 "Sequence selection insufficient",
2350 JOptionPane.WARNING_MESSAGE);
2355 new PCAPanel(viewport);
2359 public void autoCalculate_actionPerformed(ActionEvent e)
2361 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2362 if(viewport.autoCalculateConsensus)
2364 viewport.firePropertyChange("alignment",
2366 viewport.getAlignment().getSequences());
2374 * @param e DOCUMENT ME!
2376 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2378 NewTreePanel("AV", "PID", "Average distance tree using PID");
2384 * @param e DOCUMENT ME!
2386 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2388 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2394 * @param e DOCUMENT ME!
2396 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2398 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2404 * @param e DOCUMENT ME!
2406 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2408 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2414 * @param type DOCUMENT ME!
2415 * @param pwType DOCUMENT ME!
2416 * @param title DOCUMENT ME!
2418 void NewTreePanel(String type, String pwType, String title)
2422 if (viewport.getSelectionGroup() != null) {
2423 if (viewport.getSelectionGroup().getSize(false) < 3) {
2424 JOptionPane.showMessageDialog(Desktop.desktop,
2425 "You need to have more than two sequences selected to build a tree!",
2426 "Not enough sequences",
2427 JOptionPane.WARNING_MESSAGE);
2432 SequenceGroup sg = viewport.getSelectionGroup();
2434 /* Decide if the selection is a column region */
2435 while (s < sg.getSize(false))
2437 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2440 JOptionPane.showMessageDialog(Desktop.desktop,
2441 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2442 "Try using the Pad function in the edit menu,\n" +
2443 "or one of the multiple sequence alignment web services.",
2444 "Sequences in selection are not aligned",
2445 JOptionPane.WARNING_MESSAGE);
2451 title = title + " on region";
2452 tp = new TreePanel(alignPanel, type, pwType);
2456 //are the sequences aligned?
2457 if (!viewport.alignment.isAligned())
2459 JOptionPane.showMessageDialog(Desktop.desktop,
2460 "The sequences must be aligned before creating a tree.\n" +
2461 "Try using the Pad function in the edit menu,\n" +
2462 "or one of the multiple sequence alignment web services.",
2463 "Sequences not aligned",
2464 JOptionPane.WARNING_MESSAGE);
2469 if(viewport.alignment.getHeight()<2)
2472 tp = new TreePanel(alignPanel, type, pwType);
2475 addTreeMenuItem(tp, title);
2477 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2483 * @param title DOCUMENT ME!
2484 * @param order DOCUMENT ME!
2486 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2488 final JMenuItem item = new JMenuItem("by " + title);
2490 item.addActionListener(new java.awt.event.ActionListener()
2492 public void actionPerformed(ActionEvent e)
2494 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2496 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2497 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2499 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2501 alignPanel.repaint();
2507 * Maintain the Order by->Displayed Tree menu.
2508 * Creates a new menu item for a TreePanel with an appropriate
2509 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2510 * to remove the menu item when the treePanel is closed, and adjust
2511 * the tree leaf to sequence mapping when the alignment is modified.
2512 * @param treePanel Displayed tree window.
2513 * @param title SortBy menu item title.
2515 void addTreeMenuItem(final TreePanel treePanel, String title)
2517 final JMenuItem item = new JMenuItem(title);
2523 sort.add(sortByTreeMenu);
2526 sortByTreeMenu.add(item);
2527 item.addActionListener(new java.awt.event.ActionListener()
2529 public void actionPerformed(ActionEvent e)
2531 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2532 AlignmentSorter.sortByTree(viewport.getAlignment(),
2533 treePanel.getTree());
2535 addHistoryItem(new OrderCommand("Tree Sort",
2537 viewport.alignment));
2540 alignPanel.repaint();
2544 treePanel.addInternalFrameListener(new javax.swing.event.
2545 InternalFrameAdapter()
2547 public void internalFrameClosed(
2548 javax.swing.event.InternalFrameEvent evt)
2551 sortByTreeMenu.remove(item);
2555 sort.remove(sortByTreeMenu);
2563 * Work out whether the whole set of sequences
2564 * or just the selected set will be submitted for multiple alignment.
2567 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2569 // Now, check we have enough sequences
2570 AlignmentView msa = null;
2572 if ( (viewport.getSelectionGroup() != null) &&
2573 (viewport.getSelectionGroup().getSize(false) > 1))
2575 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2576 /*SequenceGroup seqs = viewport.getSelectionGroup();
2578 msa = new SequenceI[sz = seqs.getSize(false)];
2580 for (int i = 0; i < sz; i++)
2582 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2584 msa = viewport.getAlignmentView(true);
2588 /*Vector seqs = viewport.getAlignment().getSequences();
2590 if (seqs.size() > 1)
2592 msa = new SequenceI[seqs.size()];
2594 for (int i = 0; i < seqs.size(); i++)
2596 msa[i] = (SequenceI) seqs.elementAt(i);
2599 msa = viewport.getAlignmentView(false);
2605 * Decides what is submitted to a secondary structure prediction service,
2606 * the currently selected sequence, or the currently selected alignment
2607 * (where the first sequence in the set is the one that the prediction
2610 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2612 AlignmentView seqs = null;
2614 if ( (viewport.getSelectionGroup() != null) &&
2615 (viewport.getSelectionGroup().getSize(false) > 0))
2617 seqs = viewport.getAlignmentView(true);
2621 seqs = viewport.getAlignmentView(false);
2623 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2624 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2625 if (!viewport.alignment.isAligned())
2627 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2634 * @param e DOCUMENT ME!
2636 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2638 // Pick the tree file
2639 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2642 chooser.setFileView(new JalviewFileView());
2643 chooser.setDialogTitle("Select a newick-like tree file");
2644 chooser.setToolTipText("Load a tree file");
2646 int value = chooser.showOpenDialog(null);
2648 if (value == JalviewFileChooser.APPROVE_OPTION)
2650 String choice = chooser.getSelectedFile().getPath();
2651 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2655 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2657 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2659 catch (Exception ex)
2661 JOptionPane.showMessageDialog(Desktop.desktop,
2662 "Problem reading tree file",
2664 JOptionPane.WARNING_MESSAGE);
2665 ex.printStackTrace();
2671 public TreePanel ShowNewickTree(NewickFile nf, String title)
2673 return ShowNewickTree(nf,title,600,500,4,5);
2675 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2677 return ShowNewickTree(nf,title, input, 600,500,4,5);
2679 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2680 return ShowNewickTree(nf, title, null, w, h, x, y);
2683 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2685 * @param nf the tree
2686 * @param title tree viewer title
2687 * @param input Associated alignment input data (or null)
2692 * @return TreePanel handle
2694 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2695 TreePanel tp = null;
2701 if (nf.getTree() != null)
2703 tp = new TreePanel(alignPanel,
2711 tp.setLocation(x,y);
2714 Desktop.addInternalFrame(tp, title, w, h);
2715 addTreeMenuItem(tp, title);
2718 catch (Exception ex)
2720 ex.printStackTrace();
2731 PrinterJob printJob = PrinterJob.getPrinterJob();
2732 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2733 printJob.setPrintable(alignPanel, pf);
2735 if (printJob.printDialog())
2741 catch (Exception PrintException)
2743 PrintException.printStackTrace();
2750 * Generates menu items and listener event actions for web service clients
2753 public void BuildWebServiceMenu()
2755 if ( (Discoverer.services != null)
2756 && (Discoverer.services.size() > 0))
2758 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2759 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2760 Vector wsmenu = new Vector();
2761 final AlignFrame af = this;
2764 // Add any Multiple Sequence Alignment Services
2765 final JMenu msawsmenu = new JMenu("Alignment");
2766 for (int i = 0, j = msaws.size(); i < j; i++)
2768 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2770 final JMenuItem method = new JMenuItem(sh.getName());
2771 method.addActionListener(new ActionListener()
2773 public void actionPerformed(ActionEvent e)
2775 AlignmentView msa = gatherSequencesForAlignment();
2776 new jalview.ws.MsaWSClient(sh, title, msa,
2777 false, true, viewport.getAlignment().getDataset(), af);
2782 msawsmenu.add(method);
2783 // Deal with services that we know accept partial alignments.
2784 if (sh.getName().indexOf("lustal") > -1)
2786 // We know that ClustalWS can accept partial alignments for refinement.
2787 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2788 methodR.addActionListener(new ActionListener()
2790 public void actionPerformed(ActionEvent e)
2792 AlignmentView msa = gatherSequencesForAlignment();
2793 new jalview.ws.MsaWSClient(sh, title, msa,
2794 true, true, viewport.getAlignment().getDataset(), af);
2799 msawsmenu.add(methodR);
2803 wsmenu.add(msawsmenu);
2805 if (secstrpr != null)
2807 // Add any secondary structure prediction services
2808 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2809 for (int i = 0, j = secstrpr.size(); i < j; i++)
2811 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2813 final JMenuItem method = new JMenuItem(sh.getName());
2814 method.addActionListener(new ActionListener()
2816 public void actionPerformed(ActionEvent e)
2818 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2819 if (msa.getSequences().length == 1)
2821 // Single Sequence prediction
2822 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
2826 if (msa.getSequences().length > 1)
2828 // Sequence profile based prediction
2829 new jalview.ws.JPredClient(sh,
2830 title, true, msa, af, true);
2835 secstrmenu.add(method);
2837 wsmenu.add(secstrmenu);
2839 this.webService.removeAll();
2840 for (int i = 0, j = wsmenu.size(); i < j; i++)
2842 webService.add( (JMenu) wsmenu.get(i));
2847 this.webService.removeAll();
2848 this.webService.add(this.webServiceNoServices);
2850 // TODO: add in rediscovery function
2851 // TODO: reduce code redundancy.
2852 // TODO: group services by location as well as function.
2855 /* public void vamsasStore_actionPerformed(ActionEvent e)
2857 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2858 getProperty("LAST_DIRECTORY"));
2860 chooser.setFileView(new JalviewFileView());
2861 chooser.setDialogTitle("Export to Vamsas file");
2862 chooser.setToolTipText("Export");
2864 int value = chooser.showSaveDialog(this);
2866 if (value == JalviewFileChooser.APPROVE_OPTION)
2868 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
2869 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
2870 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
2877 public void showTranslation_actionPerformed(ActionEvent e)
2879 SequenceI [] selection = viewport.getSelectionAsNewSequence();
2880 String [] seqstring = viewport.getViewAsString(true);
2882 int s, sSize = selection.length;
2883 SequenceI [] newSeq = new SequenceI[sSize];
2886 StringBuffer protein;
2888 for(s=0; s<sSize; s++)
2890 protein = new StringBuffer();
2891 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
2892 resSize = seq.length();
2893 resSize -= resSize%3;
2895 for(res = 0; res < resSize; res+=3)
2897 String codon = seq.substring(res, res+3);
2898 codon = codon.replace('U', 'T');
2899 String aa = ResidueProperties.codonTranslate(codon);
2901 protein.append(viewport.getGapCharacter());
2902 else if(aa.equals("STOP"))
2903 protein.append("X");
2905 protein.append( aa );
2907 newSeq[s] = new Sequence(selection[s].getName(),
2908 protein.toString());
2912 AlignmentI al = new Alignment(newSeq);
2913 al.setDataset(null);
2916 ////////////////////////////////
2917 // Copy annotations across
2918 jalview.datamodel.AlignmentAnnotation[] annotations
2919 = viewport.alignment.getAlignmentAnnotation();
2921 if(annotations!=null)
2923 for (int i = 0; i < annotations.length; i++)
2925 if (annotations[i].label.equals("Quality") ||
2926 annotations[i].label.equals("Conservation") ||
2927 annotations[i].label.equals("Consensus"))
2932 aSize = viewport.alignment.getWidth() / 3;
2933 jalview.datamodel.Annotation[] anots =
2934 new jalview.datamodel.Annotation[aSize];
2936 for (a = 0; a < viewport.alignment.getWidth(); a++)
2938 if (annotations[i].annotations[a] == null
2939 || annotations[i].annotations[a] == null)
2942 anots[a / 3] = new Annotation(
2943 annotations[i].annotations[a].displayCharacter,
2944 annotations[i].annotations[a].description,
2945 annotations[i].annotations[a].secondaryStructure,
2946 annotations[i].annotations[a].value,
2947 annotations[i].annotations[a].colour);
2950 jalview.datamodel.AlignmentAnnotation aa
2951 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
2952 annotations[i].description, anots);
2953 al.addAnnotation(aa);
2957 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2958 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
2970 * @param String DOCUMENT ME!
2972 public boolean parseFeaturesFile(String file, String type)
2974 boolean featuresFile = false;
2976 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
2977 alignPanel.seqPanel.seqCanvas.
2978 getFeatureRenderer().featureColours,
2983 ex.printStackTrace();
2988 viewport.showSequenceFeatures = true;
2989 showSeqFeatures.setSelected(true);
2990 alignPanel.repaint();
2993 return featuresFile;
2996 public void dragEnter(DropTargetDragEvent evt)
2999 public void dragExit(DropTargetEvent evt)
3002 public void dragOver(DropTargetDragEvent evt)
3005 public void dropActionChanged(DropTargetDragEvent evt)
3008 public void drop(DropTargetDropEvent evt)
3010 Transferable t = evt.getTransferable();
3011 java.util.List files = null;
3015 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3016 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3018 //Works on Windows and MacOSX
3019 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3020 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3022 else if (t.isDataFlavorSupported(uriListFlavor))
3024 // This is used by Unix drag system
3025 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3026 String data = (String) t.getTransferData(uriListFlavor);
3027 files = new java.util.ArrayList(1);
3028 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3031 st.hasMoreTokens(); )
3033 String s = st.nextToken();
3034 if (s.startsWith("#"))
3036 // the line is a comment (as per the RFC 2483)
3040 java.net.URI uri = new java.net.URI(s);
3041 java.io.File file = new java.io.File(uri);
3048 e.printStackTrace();
3055 for (int i = 0; i < files.size(); i++)
3057 loadJalviewDataFile(files.get(i).toString());
3060 catch (Exception ex)
3062 ex.printStackTrace();
3067 // This method will attempt to load a "dropped" file first by testing
3068 // whether its and Annotation file, then features file. If both are
3069 // false then the user may have dropped an alignment file onto this
3071 public void loadJalviewDataFile(String file)
3074 String protocol = "File";
3076 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3081 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3086 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3089 String format = new IdentifyFile().Identify(file, protocol);
3091 if(format.equalsIgnoreCase("JnetFile"))
3093 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3095 new JnetAnnotationMaker().add_annotation(predictions,
3096 viewport.getAlignment(),
3098 alignPanel.adjustAnnotationHeight();
3099 alignPanel.repaint();
3102 new FileLoader().LoadFile(viewport, file, protocol, format);
3108 alignPanel.adjustAnnotationHeight();
3111 }catch(Exception ex)
3113 ex.printStackTrace();
3117 public void tabSelectionChanged(int index)
3121 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3122 viewport = alignPanel.av;
3123 setMenusFromViewport(viewport);
3127 public void tabbedPane_mousePressed(MouseEvent e)
3129 if(SwingUtilities.isRightMouseButton(e))
3131 String reply = JOptionPane.showInternalInputDialog(this,
3134 JOptionPane.QUESTION_MESSAGE);
3138 viewport.viewName = reply;
3139 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3145 public AlignViewport getCurrentView()