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 public String fileName = null;
65 private int treeCount = 0;
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 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
117 if (viewport.conservation == null)
119 BLOSUM62Colour.setEnabled(false);
120 conservationMenuItem.setEnabled(false);
121 modifyConservation.setEnabled(false);
122 // PIDColour.setEnabled(false);
123 // abovePIDThreshold.setEnabled(false);
124 // modifyPID.setEnabled(false);
127 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
129 if (sortby.equals("Id"))
130 sortIDMenuItem_actionPerformed(null);
131 else if (sortby.equals("Pairwise Identity"))
132 sortPairwiseMenuItem_actionPerformed(null);
134 if (Desktop.desktop != null)
136 addServiceListeners();
137 setGUINucleotide(viewport.alignment.isNucleotide());
140 setMenusFromViewport(viewport);
142 if (viewport.wrapAlignment)
144 wrapMenuItem_actionPerformed(null);
152 void addKeyListener()
154 final AlignFrame af = this;
155 addKeyListener(new KeyAdapter()
157 public void keyPressed(KeyEvent evt)
159 if (viewport.cursorMode
160 && evt.getKeyCode() >= KeyEvent.VK_0
161 && evt.getKeyCode() <= KeyEvent.VK_9)
163 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
166 switch (evt.getKeyCode())
169 if (!evt.isControlDown())
171 AlignmentPanel newap =
172 new Jalview2XML().copyAlignPanel(alignPanel, true);
174 if(viewport.viewName==null)
175 viewport.viewName="View 1";
177 newap.av.historyList = viewport.historyList;
178 newap.av.redoList = viewport.redoList;
179 newap.av.viewName = "View " +
180 (Desktop.getViewCount(viewport.getSequenceSetId())+1);
182 addAlignmentPanel(newap, false);
184 tabbedPane.setSelectedIndex(tabbedPane.getTabCount()-1);
189 Desktop.instance.gatherViews(af);
193 if (!evt.isControlDown())
195 Desktop.instance.explodeViews(af);
200 case 27: // escape key
201 deselectAllSequenceMenuItem_actionPerformed(null);
205 case KeyEvent.VK_DOWN:
206 if (viewport.cursorMode)
208 alignPanel.seqPanel.moveCursor(0, 1);
211 moveSelectedSequences(false);
215 if (viewport.cursorMode)
217 alignPanel.seqPanel.moveCursor(0, -1);
220 moveSelectedSequences(true);
223 case KeyEvent.VK_LEFT:
224 if (viewport.cursorMode)
226 alignPanel.seqPanel.moveCursor( -1, 0);
230 case KeyEvent.VK_RIGHT:
231 if (viewport.cursorMode)
233 alignPanel.seqPanel.moveCursor(1, 0);
237 case KeyEvent.VK_SPACE:
238 if (viewport.cursorMode)
240 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
246 case KeyEvent.VK_DELETE:
247 case KeyEvent.VK_BACK_SPACE:
248 if (!viewport.cursorMode)
250 cut_actionPerformed(null);
253 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
260 if (viewport.cursorMode)
262 alignPanel.seqPanel.setCursorRow();
266 if (viewport.cursorMode && !evt.isControlDown())
268 alignPanel.seqPanel.setCursorColumn();
272 if (viewport.cursorMode)
274 alignPanel.seqPanel.setCursorPosition();
278 case KeyEvent.VK_ENTER:
279 case KeyEvent.VK_COMMA:
280 if (viewport.cursorMode)
282 alignPanel.seqPanel.setCursorRowAndColumn();
287 if (viewport.cursorMode)
289 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
293 if (viewport.cursorMode)
295 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
300 viewport.cursorMode = !viewport.cursorMode;
301 statusBar.setText("Keyboard editing mode is " +
302 (viewport.cursorMode ? "on" : "off"));
303 if (viewport.cursorMode)
305 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
306 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
308 alignPanel.seqPanel.seqCanvas.repaint();
314 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
315 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
316 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
318 javax.help.HelpBroker hb = hs.createHelpBroker();
319 hb.setCurrentID("home");
320 hb.setDisplayed(true);
324 ex.printStackTrace();
330 boolean toggleSeqs = !evt.isControlDown();
331 boolean toggleCols = !evt.isShiftDown();
333 boolean hide = false;
335 SequenceGroup sg = viewport.getSelectionGroup();
338 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
340 hideSelSequences_actionPerformed(null);
343 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
344 showAllSeqs_actionPerformed(null);
349 if (viewport.colSel.getSelected().size() > 0)
351 hideSelColumns_actionPerformed(null);
353 viewport.selectionGroup = sg;
356 showAllColumns_actionPerformed(null);
360 case KeyEvent.VK_PAGE_UP:
361 if (viewport.wrapAlignment)
362 alignPanel.scrollUp(true);
364 alignPanel.setScrollValues(viewport.startRes,
366 - viewport.endSeq + viewport.startSeq);
368 case KeyEvent.VK_PAGE_DOWN:
369 if (viewport.wrapAlignment)
370 alignPanel.scrollUp(false);
372 alignPanel.setScrollValues(viewport.startRes,
374 + viewport.endSeq - viewport.startSeq);
382 public void addAlignmentPanel(final AlignmentPanel ap,
385 ap.alignFrame = this;
387 alignPanels.addElement(ap);
389 int aSize = alignPanels.size();
391 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
393 if (aSize == 1 && ap.av.viewName==null)
395 this.getContentPane().add(ap, BorderLayout.CENTER);
401 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
402 tabbedPane.addTab(first.av.viewName==null?"Original":first.av.viewName,first);
404 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
407 tabbedPane.addTab(ap.av.viewName==null?"Original":ap.av.viewName, ap);
409 ap.setVisible(false);
414 ap.av.updateConsensus(ap);
415 ap.av.updateConservation(ap);
420 public AlignViewport getViewport()
425 /* Set up intrinsic listeners for dynamically generated GUI bits. */
426 private void addServiceListeners()
428 final java.beans.PropertyChangeListener thisListener;
429 // Do this once to get current state
430 BuildWebServiceMenu();
431 Desktop.discoverer.addPropertyChangeListener(
432 thisListener = new java.beans.PropertyChangeListener()
434 public void propertyChange(PropertyChangeEvent evt)
436 // System.out.println("Discoverer property change.");
437 if (evt.getPropertyName().equals("services"))
439 // System.out.println("Rebuilding web service menu");
440 BuildWebServiceMenu();
445 addInternalFrameListener(new javax.swing.event.
446 InternalFrameAdapter()
448 public void internalFrameClosed(
449 javax.swing.event.InternalFrameEvent evt)
451 // System.out.println("deregistering discoverer listener");
452 Desktop.discoverer.removePropertyChangeListener(thisListener);
453 closeMenuItem_actionPerformed(null);
459 public void setGUINucleotide(boolean nucleotide)
461 showTranslation.setVisible( nucleotide );
462 conservationMenuItem.setEnabled( !nucleotide );
463 modifyConservation.setEnabled( !nucleotide );
465 //Remember AlignFrame always starts as protein
468 calculateMenu.remove(calculateMenu.getItemCount()-2);
473 * Need to call this method when tabs are selected for multiple views,
474 * or when loading from Jalview2XML.java
475 * @param av AlignViewport
477 void setMenusFromViewport(AlignViewport av)
479 colourTextMenuItem.setSelected(av.showColourText);
480 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
481 conservationMenuItem.setSelected(av.getConservationSelected());
482 seqLimits.setSelected(av.getShowJVSuffix());
483 renderGapsMenuItem.setSelected(av.renderGaps);
484 wrapMenuItem.setSelected(av.wrapAlignment);
485 annotationPanelMenuItem.setState(av.showAnnotation);
486 viewBoxesMenuItem.setSelected(av.showBoxes);
487 viewTextMenuItem.setSelected(av.showText);
489 setColourSelected(ColourSchemeProperty.
490 getColourName(av.getGlobalColourScheme()));
492 showSeqFeatures.setSelected(av.showSequenceFeatures);
493 hiddenMarkers.setState(av.showHiddenMarkers);
494 applyToAllGroups.setState(av.colourAppliesToAllGroups);
495 smoothFont.setState(av.antiAlias);
501 Hashtable progressBars;
502 public void setProgressBar(String message, long id)
504 if(progressBars == null)
505 progressBars = new Hashtable();
507 JPanel progressPanel;
508 GridLayout layout = (GridLayout) statusPanel.getLayout();
509 if(progressBars.get( new Long(id) )!=null)
511 progressPanel = (JPanel)progressBars.get( new Long(id) );
512 statusPanel.remove(progressPanel);
513 progressBars.remove( progressPanel );
514 progressPanel = null;
516 statusBar.setText(message);
518 layout.setRows(layout.getRows() - 1);
522 progressPanel = new JPanel(new BorderLayout(10, 5));
524 JProgressBar progressBar = new JProgressBar();
525 progressBar.setIndeterminate(true);
527 progressPanel.add(new JLabel(message), BorderLayout.WEST);
528 progressPanel.add(progressBar, BorderLayout.CENTER);
530 layout.setRows(layout.getRows() + 1);
531 statusPanel.add(progressPanel);
533 progressBars.put(new Long(id), progressPanel);
543 Added so Castor Mapping file can obtain Jalview Version
545 public String getVersion()
547 return jalview.bin.Cache.getProperty("VERSION");
550 public FeatureRenderer getFeatureRenderer()
552 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
556 public void fetchSequence_actionPerformed(ActionEvent e)
558 new SequenceFetcher(this);
561 public void addFromFile_actionPerformed(ActionEvent e)
563 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
566 public void addFromText_actionPerformed(ActionEvent e)
568 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
571 public void addFromURL_actionPerformed(ActionEvent e)
573 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
577 public void save_actionPerformed(ActionEvent e)
579 if(fileName==null || currentFileFormat==null)
580 saveAs_actionPerformed(null);
582 saveAlignment(fileName, currentFileFormat);
588 * @param e DOCUMENT ME!
590 public void saveAs_actionPerformed(ActionEvent e)
592 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
593 getProperty( "LAST_DIRECTORY"),
595 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
597 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
602 chooser.setFileView(new JalviewFileView());
603 chooser.setDialogTitle("Save Alignment to file");
604 chooser.setToolTipText("Save");
606 int value = chooser.showSaveDialog(this);
608 if (value == JalviewFileChooser.APPROVE_OPTION)
610 currentFileFormat = chooser.getSelectedFormat();
611 if (currentFileFormat == null)
613 JOptionPane.showInternalMessageDialog(Desktop.desktop,
614 "You must select a file format before saving!",
615 "File format not specified",
616 JOptionPane.WARNING_MESSAGE);
617 value = chooser.showSaveDialog(this);
621 fileName = chooser.getSelectedFile().getPath();
623 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
626 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
628 saveAlignment(fileName, currentFileFormat);
632 public boolean saveAlignment(String file, String format)
634 if (format.equalsIgnoreCase("Jalview"))
636 String shortName = title;
638 if (shortName.indexOf(java.io.File.separatorChar) > -1)
640 shortName = shortName.substring(shortName.lastIndexOf(
641 java.io.File.separatorChar) + 1);
644 new Jalview2XML().SaveAlignment(this, file, shortName);
646 statusBar.setText("Successfully saved to file: "
648 +format +" format.");
651 // USE Jalview2XML to save this file
657 String[] omitHidden = null;
659 if (viewport.hasHiddenColumns)
661 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
662 "The Alignment contains hidden columns."
663 + "\nDo you want to save only the visible alignment?",
664 "Save / Omit Hidden Columns",
665 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
667 if (reply == JOptionPane.YES_OPTION)
668 omitHidden = viewport.getViewAsString(false);
671 String output = new FormatAdapter().formatSequences(
673 viewport.alignment.getSequencesArray(),
683 java.io.PrintWriter out = new java.io.PrintWriter(
684 new java.io.FileWriter(file));
689 statusBar.setText("Successfully saved to file: "
691 +format +" format.");
696 ex.printStackTrace();
705 * @param e DOCUMENT ME!
707 protected void outputText_actionPerformed(ActionEvent e)
709 String [] omitHidden = null;
711 if(viewport.hasHiddenColumns)
713 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
714 "The Alignment contains hidden columns."
715 +"\nDo you want to output only the visible alignment?",
716 "Save / Omit Hidden Columns",
717 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
719 if(reply==JOptionPane.YES_OPTION)
721 omitHidden = viewport.getViewAsString(false);
725 CutAndPasteTransfer cap = new CutAndPasteTransfer();
726 Desktop.addInternalFrame(cap,
727 "Alignment output - " + e.getActionCommand(), 600,
731 cap.setText(new FormatAdapter().formatSequences(
732 e.getActionCommand(),
733 viewport.alignment.getSequencesArray(),
740 * @param e DOCUMENT ME!
742 protected void htmlMenuItem_actionPerformed(ActionEvent e)
744 new HTMLOutput(viewport,
745 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
746 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
749 public void createImageMap(File file, String image)
751 alignPanel.makePNGImageMap(file, image);
757 * @param e DOCUMENT ME!
759 public void createPNG(File f)
761 alignPanel.makePNG(f);
767 * @param e DOCUMENT ME!
769 public void createEPS(File f)
771 alignPanel.makeEPS(f);
777 * @param e DOCUMENT ME!
779 public void printMenuItem_actionPerformed(ActionEvent e)
781 //Putting in a thread avoids Swing painting problems
782 PrintThread thread = new PrintThread();
786 public void exportFeatures_actionPerformed(ActionEvent e)
788 new AnnotationExporter().exportFeatures(alignPanel);
792 public void exportAnnotations_actionPerformed(ActionEvent e)
794 new AnnotationExporter().exportAnnotations(
796 viewport.alignment.getAlignmentAnnotation()
801 public void associatedData_actionPerformed(ActionEvent e)
803 // Pick the tree file
804 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
807 chooser.setFileView(new JalviewFileView());
808 chooser.setDialogTitle("Load Jalview Annotations or Features File");
809 chooser.setToolTipText("Load Jalview Annotations / Features file");
811 int value = chooser.showOpenDialog(null);
813 if (value == JalviewFileChooser.APPROVE_OPTION)
815 String choice = chooser.getSelectedFile().getPath();
816 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
817 loadJalviewDataFile(choice);
826 * @param e DOCUMENT ME!
828 public void closeMenuItem_actionPerformed(ActionEvent e)
832 if(alignPanels!=null)
834 for (int i = 0; i < alignPanels.size(); i++)
836 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
837 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
838 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
839 PaintRefresher.RemoveComponent(ap);
841 // alignPanels = null;
844 // System.out.println("null one here");
846 // alignPanel = null;
849 this.setClosed(true);
853 ex.printStackTrace();
861 void updateEditMenuBar()
864 if (viewport.historyList.size() > 0)
866 undoMenuItem.setEnabled(true);
867 CommandI command = (CommandI) viewport.historyList.peek();
868 undoMenuItem.setText("Undo " + command.getDescription());
872 undoMenuItem.setEnabled(false);
873 undoMenuItem.setText("Undo");
876 if (viewport.redoList.size() > 0)
878 redoMenuItem.setEnabled(true);
880 CommandI command = (CommandI) viewport.redoList.peek();
881 redoMenuItem.setText("Redo " + command.getDescription());
885 redoMenuItem.setEnabled(false);
886 redoMenuItem.setText("Redo");
891 public void addHistoryItem(CommandI command)
893 if(command.getSize()>0)
895 viewport.historyList.push(command);
896 viewport.redoList.clear();
898 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
907 * @param e DOCUMENT ME!
909 protected void undoMenuItem_actionPerformed(ActionEvent e)
911 CommandI command = (CommandI)viewport.historyList.pop();
912 viewport.redoList.push(command);
913 command.undoCommand();
915 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
917 viewport.firePropertyChange("alignment", null,
918 viewport.getAlignment().getSequences());
924 * @param e DOCUMENT ME!
926 protected void redoMenuItem_actionPerformed(ActionEvent e)
928 CommandI command = (CommandI) viewport.redoList.pop();
929 viewport.historyList.push(command);
931 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null;
934 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
941 * @param up DOCUMENT ME!
943 public void moveSelectedSequences(boolean up)
945 SequenceGroup sg = viewport.getSelectionGroup();
954 for (int i = 1; i < viewport.alignment.getHeight(); i++)
956 SequenceI seq = viewport.alignment.getSequenceAt(i);
958 if (!sg.getSequences(false).contains(seq))
963 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
965 if (sg.getSequences(false).contains(temp))
970 viewport.alignment.getSequences().setElementAt(temp, i);
971 viewport.alignment.getSequences().setElementAt(seq, i - 1);
976 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
978 SequenceI seq = viewport.alignment.getSequenceAt(i);
980 if (!sg.getSequences(false).contains(seq))
985 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
987 if (sg.getSequences(false).contains(temp))
992 viewport.alignment.getSequences().setElementAt(temp, i);
993 viewport.alignment.getSequences().setElementAt(seq, i + 1);
997 alignPanel.repaint();
1005 * @param e DOCUMENT ME!
1007 protected void copy_actionPerformed(ActionEvent e)
1010 if (viewport.getSelectionGroup() == null)
1015 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1016 String[] omitHidden = null;
1018 if (viewport.hasHiddenColumns)
1020 omitHidden = viewport.getViewAsString(true);
1023 String output = new FormatAdapter().formatSequences(
1028 StringSelection ss = new StringSelection(output);
1032 //Its really worth setting the clipboard contents
1033 //to empty before setting the large StringSelection!!
1034 Toolkit.getDefaultToolkit().getSystemClipboard()
1035 .setContents(new StringSelection(""), null);
1037 Toolkit.getDefaultToolkit().getSystemClipboard()
1038 .setContents(ss, Desktop.instance);
1040 catch (OutOfMemoryError er)
1042 er.printStackTrace();
1043 javax.swing.SwingUtilities.invokeLater(new Runnable()
1047 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1048 "Out of memory copying region!!"
1050 "\nSee help files for increasing Java Virtual Machine memory."
1052 javax.swing.JOptionPane.WARNING_MESSAGE);
1059 Vector hiddenColumns = null;
1060 if(viewport.hasHiddenColumns)
1062 hiddenColumns =new Vector();
1063 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1064 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1066 int[] region = (int[])
1067 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1069 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1070 region[1]-hiddenOffset});
1076 Desktop.jalviewClipboard = new Object[]{ seqs,
1077 viewport.alignment.getDataset(),
1079 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1085 * @param e DOCUMENT ME!
1087 protected void pasteNew_actionPerformed(ActionEvent e)
1095 * @param e DOCUMENT ME!
1097 protected void pasteThis_actionPerformed(ActionEvent e)
1105 * @param newAlignment DOCUMENT ME!
1107 void paste(boolean newAlignment)
1111 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1112 Transferable contents = c.getContents(this);
1114 if (contents == null)
1122 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1123 if (str.length() < 1)
1126 format = new IdentifyFile().Identify(str, "Paste");
1129 catch (OutOfMemoryError er)
1131 er.printStackTrace();
1132 javax.swing.SwingUtilities.invokeLater(new Runnable()
1136 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1137 "Out of memory pasting sequences!!"
1139 "\nSee help files for increasing Java Virtual Machine memory."
1141 javax.swing.JOptionPane.WARNING_MESSAGE);
1148 SequenceI[] sequences;
1151 if(Desktop.jalviewClipboard!=null)
1153 // The clipboard was filled from within Jalview, we must use the sequences
1154 // And dataset from the copied alignment
1155 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1159 sequences = new FormatAdapter().readFile(str, "Paste", format);
1162 AlignmentI alignment = null;
1166 alignment = new Alignment(sequences);
1168 if (Desktop.jalviewClipboard != null)
1169 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1171 alignment.setDataset(null);
1175 alignment = viewport.getAlignment();
1178 SequenceI [] newseqs = new SequenceI[sequences.length];
1179 for (int i = 0; i < sequences.length; i++)
1181 newseqs[i] = new Sequence(sequences[i].getName(),
1182 sequences[i].getSequence(), sequences[i].getStart(),
1183 sequences[i].getEnd());
1185 alignment.addSequence(newseqs[i]);
1191 addHistoryItem(new EditCommand(
1196 alignment.getWidth(),
1201 viewport.setEndSeq(alignment.getHeight());
1202 alignment.getWidth();
1203 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1208 // Add any annotations attached to sequences
1209 for (int i = 0; i < sequences.length; i++)
1211 if (sequences[i].getAnnotation() != null)
1213 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1215 AlignmentAnnotation newAnnot =
1216 new AlignmentAnnotation(
1217 sequences[i].getAnnotation()[a].label,
1218 sequences[i].getAnnotation()[a].description,
1219 sequences[i].getAnnotation()[a].annotations,
1220 sequences[i].getAnnotation()[a].graphMin,
1221 sequences[i].getAnnotation()[a].graphMax,
1222 sequences[i].getAnnotation()[a].graph);
1224 sequences[i].getAnnotation()[a] = newAnnot;
1225 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1227 newAnnot.sequenceRef = sequences[i];
1228 newAnnot.adjustForAlignment();
1229 alignment.addAnnotation(newAnnot);
1230 alignment.setAnnotationIndex(newAnnot, a);
1233 alignPanel.annotationPanel.adjustPanelHeight();
1239 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1240 String newtitle = new String("Copied sequences");
1242 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1244 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1245 for(int i=0; i<hc.size(); i++)
1247 int [] region = (int[]) hc.elementAt(i);
1248 af.viewport.hideColumns(region[0], region[1]);
1253 //>>>This is a fix for the moment, until a better solution is found!!<<<
1254 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1255 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1258 if (title.startsWith("Copied sequences"))
1264 newtitle = newtitle.concat("- from " + title);
1267 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1274 catch (Exception ex)
1276 ex.printStackTrace();
1277 System.out.println("Exception whilst pasting: "+ex);
1278 // could be anything being pasted in here
1287 * @param e DOCUMENT ME!
1289 protected void cut_actionPerformed(ActionEvent e)
1291 copy_actionPerformed(null);
1292 delete_actionPerformed(null);
1298 * @param e DOCUMENT ME!
1300 protected void delete_actionPerformed(ActionEvent e)
1303 SequenceGroup sg = viewport.getSelectionGroup();
1309 Vector seqs = new Vector();
1310 int cutLength = sg.getEndRes()-sg.getStartRes()+1;
1311 boolean seqsCut = false;
1313 for (int i = 0; i < sg.getSize(false); i++)
1315 seq = sg.getSequenceAt(i);
1316 seqs.addElement(seq);
1317 if(seq.getLength()<=cutLength)
1322 // If the cut affects all sequences, remove highlighted columns
1323 if (sg.getSize(false) == viewport.alignment.getHeight())
1325 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1326 sg.getEndRes() + 1);
1330 SequenceI [] cut = new SequenceI[seqs.size()];
1331 for(int i=0; i<seqs.size(); i++)
1332 cut[i] = (SequenceI)seqs.elementAt(i);
1338 addHistoryItem(new EditCommand("Cut Sequences",
1342 sg.getEndRes()-sg.getStartRes()+1,
1343 viewport.alignment));
1346 viewport.setSelectionGroup(null);
1347 viewport.alignment.deleteGroup(sg);
1349 viewport.firePropertyChange("alignment", null,
1350 viewport.getAlignment().getSequences());
1352 if (viewport.getAlignment().getHeight() < 1)
1356 this.setClosed(true);
1358 catch (Exception ex)
1367 * @param e DOCUMENT ME!
1369 protected void deleteGroups_actionPerformed(ActionEvent e)
1371 viewport.alignment.deleteAllGroups();
1372 viewport.setSelectionGroup(null);
1373 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1374 alignPanel.repaint();
1380 * @param e DOCUMENT ME!
1382 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1384 SequenceGroup sg = new SequenceGroup();
1386 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1389 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1392 sg.setEndRes(viewport.alignment.getWidth() - 1);
1393 viewport.setSelectionGroup(sg);
1394 alignPanel.repaint();
1395 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1401 * @param e DOCUMENT ME!
1403 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1405 if(viewport.cursorMode)
1407 alignPanel.seqPanel.keyboardNo1 = null;
1408 alignPanel.seqPanel.keyboardNo2 = null;
1410 viewport.setSelectionGroup(null);
1411 viewport.getColumnSelection().clear();
1412 viewport.setSelectionGroup(null);
1413 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1414 alignPanel.idPanel.idCanvas.searchResults = null;
1415 alignPanel.repaint();
1416 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1422 * @param e DOCUMENT ME!
1424 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1426 SequenceGroup sg = viewport.getSelectionGroup();
1430 selectAllSequenceMenuItem_actionPerformed(null);
1435 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1438 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1441 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1444 public void invertColSel_actionPerformed(ActionEvent e)
1446 viewport.invertColumnSelection();
1447 alignPanel.repaint();
1454 * @param e DOCUMENT ME!
1456 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1458 trimAlignment(true);
1464 * @param e DOCUMENT ME!
1466 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1468 trimAlignment(false);
1471 void trimAlignment(boolean trimLeft)
1473 ColumnSelection colSel = viewport.getColumnSelection();
1476 if (colSel.size() > 0)
1479 column = colSel.getMin();
1481 column = colSel.getMax();
1484 if(viewport.getSelectionGroup()!=null)
1485 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1487 seqs = viewport.alignment.getSequencesArray();
1490 TrimRegionCommand trimRegion;
1493 trimRegion = new TrimRegionCommand("Remove Left",
1494 TrimRegionCommand.TRIM_LEFT,
1499 viewport.selectionGroup);
1503 trimRegion = new TrimRegionCommand("Remove Right",
1504 TrimRegionCommand.TRIM_RIGHT,
1509 viewport.selectionGroup);
1512 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1515 addHistoryItem(trimRegion);
1517 Vector groups = viewport.alignment.getGroups();
1519 for (int i = 0; i < groups.size(); i++)
1521 SequenceGroup sg = (SequenceGroup) groups.get(i);
1523 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1524 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1526 viewport.alignment.deleteGroup(sg);
1530 viewport.firePropertyChange("alignment", null,
1531 viewport.getAlignment().getSequences());
1538 * @param e DOCUMENT ME!
1540 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1542 int start = 0, end = viewport.alignment.getWidth()-1;
1545 if (viewport.getSelectionGroup() != null)
1547 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1548 start = viewport.getSelectionGroup().getStartRes();
1549 end = viewport.getSelectionGroup().getEndRes();
1552 seqs = viewport.alignment.getSequencesArray();
1555 RemoveGapColCommand removeGapCols =
1556 new RemoveGapColCommand("Remove Gapped Columns",
1559 viewport.getGapCharacter());
1561 addHistoryItem(removeGapCols);
1563 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1565 //This is to maintain viewport position on first residue
1567 SequenceI seq = viewport.alignment.getSequenceAt(0);
1568 int startRes = seq.findPosition(viewport.startRes);
1569 // ShiftList shifts;
1570 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1571 // edit.alColumnChanges=shifts.getInverse();
1572 // if (viewport.hasHiddenColumns)
1573 // viewport.getColumnSelection().compensateForEdits(shifts);
1574 viewport.setStartRes(seq.findIndex(startRes)-1);
1575 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1582 * @param e DOCUMENT ME!
1584 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1586 int start = 0, end = viewport.alignment.getWidth()-1;
1589 if (viewport.getSelectionGroup() != null)
1591 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1592 start = viewport.getSelectionGroup().getStartRes();
1593 end = viewport.getSelectionGroup().getEndRes();
1596 seqs = viewport.alignment.getSequencesArray();
1598 //This is to maintain viewport position on first residue
1600 SequenceI seq = viewport.alignment.getSequenceAt(0);
1601 int startRes = seq.findPosition(viewport.startRes);
1603 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1606 viewport.getGapCharacter()));
1608 viewport.setStartRes(seq.findIndex(startRes)-1);
1610 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1617 * @param e DOCUMENT ME!
1619 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1621 viewport.padGaps = padGapsMenuitem.isSelected();
1623 viewport.firePropertyChange("alignment",
1625 viewport.getAlignment().getSequences());
1631 * @param e DOCUMENT ME!
1633 public void findMenuItem_actionPerformed(ActionEvent e)
1635 JInternalFrame frame = new JInternalFrame();
1636 Finder finder = new Finder(viewport, alignPanel, frame);
1637 frame.setContentPane(finder);
1638 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1639 Desktop.addInternalFrame(frame, "Find", 340, 110);
1645 * @param e DOCUMENT ME!
1647 public void font_actionPerformed(ActionEvent e)
1649 new FontChooser(alignPanel);
1652 public void smoothFont_actionPerformed(ActionEvent e)
1654 viewport.antiAlias = smoothFont.isSelected();
1655 alignPanel.annotationPanel.image = null;
1656 alignPanel.repaint();
1663 * @param e DOCUMENT ME!
1665 protected void seqLimit_actionPerformed(ActionEvent e)
1667 viewport.setShowJVSuffix(seqLimits.isSelected());
1669 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1670 alignPanel.repaint();
1677 * @param e DOCUMENT ME!
1679 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1681 viewport.setColourText(colourTextMenuItem.isSelected());
1682 alignPanel.repaint();
1688 * @param e DOCUMENT ME!
1690 public void wrapMenuItem_actionPerformed(ActionEvent e)
1692 scaleAbove.setVisible(wrapMenuItem.isSelected());
1693 scaleLeft.setVisible(wrapMenuItem.isSelected());
1694 scaleRight.setVisible(wrapMenuItem.isSelected());
1695 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1696 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1699 public void showAllSeqs_actionPerformed(ActionEvent e)
1701 viewport.showAllHiddenSeqs();
1704 public void showAllColumns_actionPerformed(ActionEvent e)
1706 viewport.showAllHiddenColumns();
1710 public void hideSelSequences_actionPerformed(ActionEvent e)
1712 viewport.hideAllSelectedSeqs();
1713 alignPanel.repaint();
1716 public void hideSelColumns_actionPerformed(ActionEvent e)
1718 viewport.hideSelectedColumns();
1719 alignPanel.repaint();
1722 public void hiddenMarkers_actionPerformed(ActionEvent e)
1724 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1731 * @param e DOCUMENT ME!
1733 protected void scaleAbove_actionPerformed(ActionEvent e)
1735 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1736 alignPanel.repaint();
1742 * @param e DOCUMENT ME!
1744 protected void scaleLeft_actionPerformed(ActionEvent e)
1746 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1747 alignPanel.repaint();
1753 * @param e DOCUMENT ME!
1755 protected void scaleRight_actionPerformed(ActionEvent e)
1757 viewport.setScaleRightWrapped(scaleRight.isSelected());
1758 alignPanel.repaint();
1764 * @param e DOCUMENT ME!
1766 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1768 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1769 alignPanel.repaint();
1775 * @param e DOCUMENT ME!
1777 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1779 viewport.setShowText(viewTextMenuItem.isSelected());
1780 alignPanel.repaint();
1786 * @param e DOCUMENT ME!
1788 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1790 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1791 alignPanel.repaint();
1795 public FeatureSettings featureSettings;
1796 public void featureSettings_actionPerformed(ActionEvent e)
1798 if(featureSettings !=null )
1800 featureSettings.close();
1801 featureSettings = null;
1803 featureSettings = new FeatureSettings(this);
1809 * @param evt DOCUMENT ME!
1811 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1813 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1814 alignPanel.repaint();
1815 if (alignPanel.getOverviewPanel() != null)
1817 alignPanel.getOverviewPanel().updateOverviewImage();
1824 * @param e DOCUMENT ME!
1826 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1828 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1829 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1835 * @param e DOCUMENT ME!
1837 public void overviewMenuItem_actionPerformed(ActionEvent e)
1839 if (alignPanel.overviewPanel != null)
1844 JInternalFrame frame = new JInternalFrame();
1845 OverviewPanel overview = new OverviewPanel(alignPanel);
1846 frame.setContentPane(overview);
1847 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1848 frame.getWidth(), frame.getHeight());
1850 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1851 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1853 public void internalFrameClosed(
1854 javax.swing.event.InternalFrameEvent evt)
1856 alignPanel.setOverviewPanel(null);
1861 alignPanel.setOverviewPanel(overview);
1867 * @param e DOCUMENT ME!
1869 protected void noColourmenuItem_actionPerformed(ActionEvent e)
1877 * @param e DOCUMENT ME!
1879 public void clustalColour_actionPerformed(ActionEvent e)
1881 changeColour(new ClustalxColourScheme(
1882 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
1888 * @param e DOCUMENT ME!
1890 public void zappoColour_actionPerformed(ActionEvent e)
1892 changeColour(new ZappoColourScheme());
1898 * @param e DOCUMENT ME!
1900 public void taylorColour_actionPerformed(ActionEvent e)
1902 changeColour(new TaylorColourScheme());
1908 * @param e DOCUMENT ME!
1910 public void hydrophobicityColour_actionPerformed(ActionEvent e)
1912 changeColour(new HydrophobicColourScheme());
1918 * @param e DOCUMENT ME!
1920 public void helixColour_actionPerformed(ActionEvent e)
1922 changeColour(new HelixColourScheme());
1928 * @param e DOCUMENT ME!
1930 public void strandColour_actionPerformed(ActionEvent e)
1932 changeColour(new StrandColourScheme());
1938 * @param e DOCUMENT ME!
1940 public void turnColour_actionPerformed(ActionEvent e)
1942 changeColour(new TurnColourScheme());
1948 * @param e DOCUMENT ME!
1950 public void buriedColour_actionPerformed(ActionEvent e)
1952 changeColour(new BuriedColourScheme());
1958 * @param e DOCUMENT ME!
1960 public void nucleotideColour_actionPerformed(ActionEvent e)
1962 changeColour(new NucleotideColourScheme());
1965 public void annotationColour_actionPerformed(ActionEvent e)
1967 new AnnotationColourChooser(viewport, alignPanel);
1974 * @param e DOCUMENT ME!
1976 protected void applyToAllGroups_actionPerformed(ActionEvent e)
1978 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
1984 * @param cs DOCUMENT ME!
1986 public void changeColour(ColourSchemeI cs)
1992 if (viewport.getAbovePIDThreshold())
1994 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
1997 cs.setThreshold(threshold,
1998 viewport.getIgnoreGapsConsensus());
2000 viewport.setGlobalColourScheme(cs);
2004 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2007 if (viewport.getConservationSelected())
2010 Alignment al = (Alignment) viewport.alignment;
2011 Conservation c = new Conservation("All",
2012 ResidueProperties.propHash, 3,
2013 al.getSequences(), 0,
2017 c.verdict(false, viewport.ConsPercGaps);
2019 cs.setConservation(c);
2021 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2026 cs.setConservation(null);
2029 cs.setConsensus(viewport.hconsensus);
2032 viewport.setGlobalColourScheme(cs);
2034 if (viewport.getColourAppliesToAllGroups())
2036 Vector groups = viewport.alignment.getGroups();
2038 for (int i = 0; i < groups.size(); i++)
2040 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2048 if (cs instanceof ClustalxColourScheme)
2050 sg.cs = new ClustalxColourScheme(
2051 sg.getSequences(true), sg.getWidth());
2053 else if (cs instanceof UserColourScheme)
2055 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2061 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2063 catch (Exception ex)
2068 if (viewport.getAbovePIDThreshold()
2069 || cs instanceof PIDColourScheme
2070 || cs instanceof Blosum62ColourScheme)
2072 sg.cs.setThreshold(threshold,
2073 viewport.getIgnoreGapsConsensus());
2075 sg.cs.setConsensus(AAFrequency.calculate(
2076 sg.getSequences(true), 0,
2080 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2083 if (viewport.getConservationSelected())
2085 Conservation c = new Conservation("Group",
2086 ResidueProperties.propHash, 3,
2087 sg.getSequences(true), 0,
2088 viewport.alignment.getWidth() - 1);
2090 c.verdict(false, viewport.ConsPercGaps);
2091 sg.cs.setConservation(c);
2094 sg.cs.setConservation(null);
2098 if (alignPanel.getOverviewPanel() != null)
2100 alignPanel.getOverviewPanel().updateOverviewImage();
2103 alignPanel.repaint();
2109 * @param e DOCUMENT ME!
2111 protected void modifyPID_actionPerformed(ActionEvent e)
2113 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2115 SliderPanel.setPIDSliderSource(alignPanel,
2116 viewport.getGlobalColourScheme(),
2118 SliderPanel.showPIDSlider();
2125 * @param e DOCUMENT ME!
2127 protected void modifyConservation_actionPerformed(ActionEvent e)
2129 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2131 SliderPanel.setConservationSlider(alignPanel,
2132 viewport.globalColourScheme,
2134 SliderPanel.showConservationSlider();
2141 * @param e DOCUMENT ME!
2143 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2145 viewport.setConservationSelected(conservationMenuItem.isSelected());
2147 viewport.setAbovePIDThreshold(false);
2148 abovePIDThreshold.setSelected(false);
2150 changeColour(viewport.getGlobalColourScheme());
2152 modifyConservation_actionPerformed(null);
2158 * @param e DOCUMENT ME!
2160 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2162 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2164 conservationMenuItem.setSelected(false);
2165 viewport.setConservationSelected(false);
2167 changeColour(viewport.getGlobalColourScheme());
2169 modifyPID_actionPerformed(null);
2175 * @param e DOCUMENT ME!
2177 public void userDefinedColour_actionPerformed(ActionEvent e)
2179 if (e.getActionCommand().equals("User Defined..."))
2181 new UserDefinedColours(alignPanel, null);
2185 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2186 getUserColourSchemes().get(e.getActionCommand());
2192 public void updateUserColourMenu()
2195 Component[] menuItems = colourMenu.getMenuComponents();
2196 int i, iSize = menuItems.length;
2197 for (i = 0; i < iSize; i++)
2199 if (menuItems[i].getName() != null &&
2200 menuItems[i].getName().equals("USER_DEFINED"))
2202 colourMenu.remove(menuItems[i]);
2206 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2208 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2209 getUserColourSchemes().keys();
2211 while (userColours.hasMoreElements())
2213 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2214 nextElement().toString());
2215 radioItem.setName("USER_DEFINED");
2216 radioItem.addMouseListener(new MouseAdapter()
2218 public void mousePressed(MouseEvent evt)
2220 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2222 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2224 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2225 "Remove from default list?",
2226 "Remove user defined colour",
2227 JOptionPane.YES_NO_OPTION);
2228 if(option == JOptionPane.YES_OPTION)
2230 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2231 colourMenu.remove(radioItem);
2234 radioItem.addActionListener(new ActionListener()
2236 public void actionPerformed(ActionEvent evt)
2238 userDefinedColour_actionPerformed(evt);
2244 radioItem.addActionListener(new ActionListener()
2246 public void actionPerformed(ActionEvent evt)
2248 userDefinedColour_actionPerformed(evt);
2252 colourMenu.insert(radioItem, 15);
2253 colours.add(radioItem);
2261 * @param e DOCUMENT ME!
2263 public void PIDColour_actionPerformed(ActionEvent e)
2265 changeColour(new PIDColourScheme());
2271 * @param e DOCUMENT ME!
2273 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2275 changeColour(new Blosum62ColourScheme());
2281 * @param e DOCUMENT ME!
2283 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2285 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2286 AlignmentSorter.sortByPID(viewport.getAlignment(),
2287 viewport.getAlignment().getSequenceAt(0));
2288 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2289 alignPanel.repaint();
2295 * @param e DOCUMENT ME!
2297 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2299 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2300 AlignmentSorter.sortByID(viewport.getAlignment());
2301 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2302 alignPanel.repaint();
2308 * @param e DOCUMENT ME!
2310 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2312 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2313 AlignmentSorter.sortByGroup(viewport.getAlignment());
2314 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2316 alignPanel.repaint();
2322 * @param e DOCUMENT ME!
2324 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2326 new RedundancyPanel(alignPanel, this);
2333 * @param e DOCUMENT ME!
2335 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2337 if ( (viewport.getSelectionGroup() == null) ||
2338 (viewport.getSelectionGroup().getSize(false) < 2))
2340 JOptionPane.showInternalMessageDialog(this,
2341 "You must select at least 2 sequences.",
2342 "Invalid Selection",
2343 JOptionPane.WARNING_MESSAGE);
2347 JInternalFrame frame = new JInternalFrame();
2348 frame.setContentPane(new PairwiseAlignPanel(viewport));
2349 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2356 * @param e DOCUMENT ME!
2358 public void PCAMenuItem_actionPerformed(ActionEvent e)
2360 if ( ( (viewport.getSelectionGroup() != null) &&
2361 (viewport.getSelectionGroup().getSize(false) < 4) &&
2362 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2363 (viewport.getAlignment().getHeight() < 4))
2365 JOptionPane.showInternalMessageDialog(this,
2366 "Principal component analysis must take\n" +
2367 "at least 4 input sequences.",
2368 "Sequence selection insufficient",
2369 JOptionPane.WARNING_MESSAGE);
2374 new PCAPanel(viewport);
2378 public void autoCalculate_actionPerformed(ActionEvent e)
2380 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2381 if(viewport.autoCalculateConsensus)
2383 viewport.firePropertyChange("alignment",
2385 viewport.getAlignment().getSequences());
2393 * @param e DOCUMENT ME!
2395 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2397 NewTreePanel("AV", "PID", "Average distance tree using PID");
2403 * @param e DOCUMENT ME!
2405 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2407 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2413 * @param e DOCUMENT ME!
2415 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2417 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2423 * @param e DOCUMENT ME!
2425 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2427 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2433 * @param type DOCUMENT ME!
2434 * @param pwType DOCUMENT ME!
2435 * @param title DOCUMENT ME!
2437 void NewTreePanel(String type, String pwType, String title)
2441 if (viewport.getSelectionGroup() != null) {
2442 if (viewport.getSelectionGroup().getSize(false) < 3) {
2443 JOptionPane.showMessageDialog(Desktop.desktop,
2444 "You need to have more than two sequences selected to build a tree!",
2445 "Not enough sequences",
2446 JOptionPane.WARNING_MESSAGE);
2451 SequenceGroup sg = viewport.getSelectionGroup();
2453 /* Decide if the selection is a column region */
2454 while (s < sg.getSize(false))
2456 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2459 JOptionPane.showMessageDialog(Desktop.desktop,
2460 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2461 "Try using the Pad function in the edit menu,\n" +
2462 "or one of the multiple sequence alignment web services.",
2463 "Sequences in selection are not aligned",
2464 JOptionPane.WARNING_MESSAGE);
2470 title = title + " on region";
2471 tp = new TreePanel(alignPanel, type, pwType);
2475 //are the sequences aligned?
2476 if (!viewport.alignment.isAligned())
2478 JOptionPane.showMessageDialog(Desktop.desktop,
2479 "The sequences must be aligned before creating a tree.\n" +
2480 "Try using the Pad function in the edit menu,\n" +
2481 "or one of the multiple sequence alignment web services.",
2482 "Sequences not aligned",
2483 JOptionPane.WARNING_MESSAGE);
2488 if(viewport.alignment.getHeight()<2)
2491 tp = new TreePanel(alignPanel, type, pwType);
2494 addTreeMenuItem(tp, title);
2496 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2502 * @param title DOCUMENT ME!
2503 * @param order DOCUMENT ME!
2505 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2507 final JMenuItem item = new JMenuItem("by " + title);
2509 item.addActionListener(new java.awt.event.ActionListener()
2511 public void actionPerformed(ActionEvent e)
2513 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2515 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2516 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2518 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2520 alignPanel.repaint();
2526 * Maintain the Order by->Displayed Tree menu.
2527 * Creates a new menu item for a TreePanel with an appropriate
2528 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2529 * to remove the menu item when the treePanel is closed, and adjust
2530 * the tree leaf to sequence mapping when the alignment is modified.
2531 * @param treePanel Displayed tree window.
2532 * @param title SortBy menu item title.
2534 void addTreeMenuItem(final TreePanel treePanel, String title)
2536 final JMenuItem item = new JMenuItem(title);
2542 sort.add(sortByTreeMenu);
2545 sortByTreeMenu.add(item);
2546 item.addActionListener(new java.awt.event.ActionListener()
2548 public void actionPerformed(ActionEvent e)
2550 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2551 AlignmentSorter.sortByTree(viewport.getAlignment(),
2552 treePanel.getTree());
2554 addHistoryItem(new OrderCommand("Tree Sort",
2556 viewport.alignment));
2559 alignPanel.repaint();
2563 treePanel.addInternalFrameListener(new javax.swing.event.
2564 InternalFrameAdapter()
2566 public void internalFrameClosed(
2567 javax.swing.event.InternalFrameEvent evt)
2570 sortByTreeMenu.remove(item);
2574 sort.remove(sortByTreeMenu);
2582 * Work out whether the whole set of sequences
2583 * or just the selected set will be submitted for multiple alignment.
2586 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2588 // Now, check we have enough sequences
2589 AlignmentView msa = null;
2591 if ( (viewport.getSelectionGroup() != null) &&
2592 (viewport.getSelectionGroup().getSize(false) > 1))
2594 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2595 /*SequenceGroup seqs = viewport.getSelectionGroup();
2597 msa = new SequenceI[sz = seqs.getSize(false)];
2599 for (int i = 0; i < sz; i++)
2601 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2603 msa = viewport.getAlignmentView(true);
2607 /*Vector seqs = viewport.getAlignment().getSequences();
2609 if (seqs.size() > 1)
2611 msa = new SequenceI[seqs.size()];
2613 for (int i = 0; i < seqs.size(); i++)
2615 msa[i] = (SequenceI) seqs.elementAt(i);
2618 msa = viewport.getAlignmentView(false);
2624 * Decides what is submitted to a secondary structure prediction service,
2625 * the currently selected sequence, or the currently selected alignment
2626 * (where the first sequence in the set is the one that the prediction
2629 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2631 AlignmentView seqs = null;
2633 if ( (viewport.getSelectionGroup() != null) &&
2634 (viewport.getSelectionGroup().getSize(false) > 0))
2636 seqs = viewport.getAlignmentView(true);
2640 seqs = viewport.getAlignmentView(false);
2642 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2643 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2644 if (!viewport.alignment.isAligned())
2646 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2653 * @param e DOCUMENT ME!
2655 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2657 // Pick the tree file
2658 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2661 chooser.setFileView(new JalviewFileView());
2662 chooser.setDialogTitle("Select a newick-like tree file");
2663 chooser.setToolTipText("Load a tree file");
2665 int value = chooser.showOpenDialog(null);
2667 if (value == JalviewFileChooser.APPROVE_OPTION)
2669 String choice = chooser.getSelectedFile().getPath();
2670 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2674 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2676 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2678 catch (Exception ex)
2680 JOptionPane.showMessageDialog(Desktop.desktop,
2681 "Problem reading tree file",
2683 JOptionPane.WARNING_MESSAGE);
2684 ex.printStackTrace();
2690 public TreePanel ShowNewickTree(NewickFile nf, String title)
2692 return ShowNewickTree(nf,title,600,500,4,5);
2694 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2696 return ShowNewickTree(nf,title, input, 600,500,4,5);
2698 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2699 return ShowNewickTree(nf, title, null, w, h, x, y);
2702 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2704 * @param nf the tree
2705 * @param title tree viewer title
2706 * @param input Associated alignment input data (or null)
2711 * @return TreePanel handle
2713 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2714 TreePanel tp = null;
2720 if (nf.getTree() != null)
2722 tp = new TreePanel(alignPanel,
2730 tp.setLocation(x,y);
2733 Desktop.addInternalFrame(tp, title, w, h);
2734 addTreeMenuItem(tp, title);
2737 catch (Exception ex)
2739 ex.printStackTrace();
2750 PrinterJob printJob = PrinterJob.getPrinterJob();
2751 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2752 printJob.setPrintable(alignPanel, pf);
2754 if (printJob.printDialog())
2760 catch (Exception PrintException)
2762 PrintException.printStackTrace();
2769 * Generates menu items and listener event actions for web service clients
2772 public void BuildWebServiceMenu()
2774 if ( (Discoverer.services != null)
2775 && (Discoverer.services.size() > 0))
2777 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2778 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2779 Vector wsmenu = new Vector();
2780 final AlignFrame af = this;
2783 // Add any Multiple Sequence Alignment Services
2784 final JMenu msawsmenu = new JMenu("Alignment");
2785 for (int i = 0, j = msaws.size(); i < j; i++)
2787 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2789 final JMenuItem method = new JMenuItem(sh.getName());
2790 method.addActionListener(new ActionListener()
2792 public void actionPerformed(ActionEvent e)
2794 AlignmentView msa = gatherSequencesForAlignment();
2795 new jalview.ws.MsaWSClient(sh, title, msa,
2796 false, true, viewport.getAlignment().getDataset(), af);
2801 msawsmenu.add(method);
2802 // Deal with services that we know accept partial alignments.
2803 if (sh.getName().indexOf("lustal") > -1)
2805 // We know that ClustalWS can accept partial alignments for refinement.
2806 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2807 methodR.addActionListener(new ActionListener()
2809 public void actionPerformed(ActionEvent e)
2811 AlignmentView msa = gatherSequencesForAlignment();
2812 new jalview.ws.MsaWSClient(sh, title, msa,
2813 true, true, viewport.getAlignment().getDataset(), af);
2818 msawsmenu.add(methodR);
2822 wsmenu.add(msawsmenu);
2824 if (secstrpr != null)
2826 // Add any secondary structure prediction services
2827 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2828 for (int i = 0, j = secstrpr.size(); i < j; i++)
2830 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2832 final JMenuItem method = new JMenuItem(sh.getName());
2833 method.addActionListener(new ActionListener()
2835 public void actionPerformed(ActionEvent e)
2837 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2838 if (msa.getSequences().length == 1)
2840 // Single Sequence prediction
2841 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
2845 if (msa.getSequences().length > 1)
2847 // Sequence profile based prediction
2848 new jalview.ws.JPredClient(sh,
2849 title, true, msa, af, true);
2854 secstrmenu.add(method);
2856 wsmenu.add(secstrmenu);
2858 this.webService.removeAll();
2859 for (int i = 0, j = wsmenu.size(); i < j; i++)
2861 webService.add( (JMenu) wsmenu.get(i));
2866 this.webService.removeAll();
2867 this.webService.add(this.webServiceNoServices);
2869 // TODO: add in rediscovery function
2870 // TODO: reduce code redundancy.
2871 // TODO: group services by location as well as function.
2874 /* public void vamsasStore_actionPerformed(ActionEvent e)
2876 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2877 getProperty("LAST_DIRECTORY"));
2879 chooser.setFileView(new JalviewFileView());
2880 chooser.setDialogTitle("Export to Vamsas file");
2881 chooser.setToolTipText("Export");
2883 int value = chooser.showSaveDialog(this);
2885 if (value == JalviewFileChooser.APPROVE_OPTION)
2887 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
2888 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
2889 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
2896 public void showTranslation_actionPerformed(ActionEvent e)
2898 SequenceI [] selection = viewport.getSelectionAsNewSequence();
2899 String [] seqstring = viewport.getViewAsString(true);
2901 int s, sSize = selection.length;
2902 SequenceI [] newSeq = new SequenceI[sSize];
2905 StringBuffer protein;
2907 for(s=0; s<sSize; s++)
2909 protein = new StringBuffer();
2910 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
2911 resSize = seq.length();
2912 resSize -= resSize%3;
2914 for(res = 0; res < resSize; res+=3)
2916 String codon = seq.substring(res, res+3);
2917 codon = codon.replace('U', 'T');
2918 String aa = ResidueProperties.codonTranslate(codon);
2920 protein.append(viewport.getGapCharacter());
2921 else if(aa.equals("STOP"))
2922 protein.append("X");
2924 protein.append( aa );
2926 newSeq[s] = new Sequence(selection[s].getName(),
2927 protein.toString());
2931 AlignmentI al = new Alignment(newSeq);
2932 al.setDataset(null);
2935 ////////////////////////////////
2936 // Copy annotations across
2937 jalview.datamodel.AlignmentAnnotation[] annotations
2938 = viewport.alignment.getAlignmentAnnotation();
2940 if(annotations!=null)
2942 for (int i = 0; i < annotations.length; i++)
2944 if (annotations[i].label.equals("Quality") ||
2945 annotations[i].label.equals("Conservation") ||
2946 annotations[i].label.equals("Consensus"))
2951 aSize = viewport.alignment.getWidth() / 3;
2952 jalview.datamodel.Annotation[] anots =
2953 new jalview.datamodel.Annotation[aSize];
2955 for (a = 0; a < viewport.alignment.getWidth(); a++)
2957 if (annotations[i].annotations[a] == null
2958 || annotations[i].annotations[a] == null)
2961 anots[a / 3] = new Annotation(
2962 annotations[i].annotations[a].displayCharacter,
2963 annotations[i].annotations[a].description,
2964 annotations[i].annotations[a].secondaryStructure,
2965 annotations[i].annotations[a].value,
2966 annotations[i].annotations[a].colour);
2969 jalview.datamodel.AlignmentAnnotation aa
2970 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
2971 annotations[i].description, anots);
2972 al.addAnnotation(aa);
2976 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
2977 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
2989 * @param String DOCUMENT ME!
2991 public boolean parseFeaturesFile(String file, String type)
2993 boolean featuresFile = false;
2995 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
2996 alignPanel.seqPanel.seqCanvas.
2997 getFeatureRenderer().featureColours,
3002 ex.printStackTrace();
3007 viewport.showSequenceFeatures = true;
3008 showSeqFeatures.setSelected(true);
3009 alignPanel.repaint();
3012 return featuresFile;
3015 public void dragEnter(DropTargetDragEvent evt)
3018 public void dragExit(DropTargetEvent evt)
3021 public void dragOver(DropTargetDragEvent evt)
3024 public void dropActionChanged(DropTargetDragEvent evt)
3027 public void drop(DropTargetDropEvent evt)
3029 Transferable t = evt.getTransferable();
3030 java.util.List files = null;
3034 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3035 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3037 //Works on Windows and MacOSX
3038 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3039 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3041 else if (t.isDataFlavorSupported(uriListFlavor))
3043 // This is used by Unix drag system
3044 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3045 String data = (String) t.getTransferData(uriListFlavor);
3046 files = new java.util.ArrayList(1);
3047 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3050 st.hasMoreTokens(); )
3052 String s = st.nextToken();
3053 if (s.startsWith("#"))
3055 // the line is a comment (as per the RFC 2483)
3059 java.net.URI uri = new java.net.URI(s);
3060 java.io.File file = new java.io.File(uri);
3067 e.printStackTrace();
3074 for (int i = 0; i < files.size(); i++)
3076 loadJalviewDataFile(files.get(i).toString());
3079 catch (Exception ex)
3081 ex.printStackTrace();
3086 // This method will attempt to load a "dropped" file first by testing
3087 // whether its and Annotation file, then features file. If both are
3088 // false then the user may have dropped an alignment file onto this
3090 public void loadJalviewDataFile(String file)
3093 String protocol = "File";
3095 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3100 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3105 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3108 String format = new IdentifyFile().Identify(file, protocol);
3110 if(format.equalsIgnoreCase("JnetFile"))
3112 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3114 new JnetAnnotationMaker().add_annotation(predictions,
3115 viewport.getAlignment(),
3117 alignPanel.adjustAnnotationHeight();
3118 alignPanel.repaint();
3121 new FileLoader().LoadFile(viewport, file, protocol, format);
3127 alignPanel.adjustAnnotationHeight();
3130 }catch(Exception ex)
3132 ex.printStackTrace();
3136 public void tabSelectionChanged(int index)
3140 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3141 viewport = alignPanel.av;
3142 setMenusFromViewport(viewport);
3146 public void tabbedPane_mousePressed(MouseEvent e)
3148 if(SwingUtilities.isRightMouseButton(e))
3150 String reply = JOptionPane.showInternalInputDialog(this,
3153 JOptionPane.QUESTION_MESSAGE);
3157 viewport.viewName = reply;
3158 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3164 public AlignViewport getCurrentView()