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.*;
39 import javax.swing.event.ChangeListener;
40 import javax.swing.event.ChangeEvent;
48 public class AlignFrame extends GAlignFrame implements DropTargetListener
51 public static final int DEFAULT_WIDTH = 700;
54 public static final int DEFAULT_HEIGHT = 500;
55 public AlignmentPanel alignPanel;
57 AlignViewport viewport;
59 Vector alignPanels = new Vector();
63 String currentFileFormat = null;
65 String fileName = null;
67 private int treeCount = 0;
70 * Creates a new AlignFrame object.
72 * @param al DOCUMENT ME!
74 public AlignFrame(AlignmentI al, int width, int height)
76 this(al, null, width, height);
81 * new alignment window with hidden columns
82 * @param al AlignmentI
83 * @param hiddenColumns ColumnSelection or null
85 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
86 int width, int height)
88 this.setSize(width, height);
89 viewport = new AlignViewport(al, hiddenColumns);
91 alignPanel = new AlignmentPanel(this, viewport);
93 if(al.getDataset()==null)
98 addAlignmentPanel(alignPanel, true);
103 * Make a new AlignFrame from exisiting alignmentPanels
104 * @param ap AlignmentPanel
105 * @param av AlignViewport
107 public AlignFrame(AlignmentPanel ap)
111 addAlignmentPanel(ap, false);
117 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
119 if (viewport.conservation == null)
121 BLOSUM62Colour.setEnabled(false);
122 conservationMenuItem.setEnabled(false);
123 modifyConservation.setEnabled(false);
124 // PIDColour.setEnabled(false);
125 // abovePIDThreshold.setEnabled(false);
126 // modifyPID.setEnabled(false);
129 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
131 if (sortby.equals("Id"))
132 sortIDMenuItem_actionPerformed(null);
133 else if (sortby.equals("Pairwise Identity"))
134 sortPairwiseMenuItem_actionPerformed(null);
136 if (Desktop.desktop != null)
138 addServiceListeners();
139 setGUINucleotide(viewport.alignment.isNucleotide());
142 setMenusFromViewport(viewport);
144 if (viewport.wrapAlignment)
146 wrapMenuItem_actionPerformed(null);
153 public void setFileName(String file, String format)
156 currentFileFormat = format;
157 reload.setEnabled(true);
160 void addKeyListener()
162 addKeyListener(new KeyAdapter()
164 public void keyPressed(KeyEvent evt)
166 if (viewport.cursorMode
167 && evt.getKeyCode() >= KeyEvent.VK_0
168 && evt.getKeyCode() <= KeyEvent.VK_9)
170 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
173 switch (evt.getKeyCode())
176 case 27: // escape key
177 deselectAllSequenceMenuItem_actionPerformed(null);
181 case KeyEvent.VK_DOWN:
182 if (viewport.cursorMode)
184 alignPanel.seqPanel.moveCursor(0, 1);
187 moveSelectedSequences(false);
191 if (viewport.cursorMode)
193 alignPanel.seqPanel.moveCursor(0, -1);
196 moveSelectedSequences(true);
199 case KeyEvent.VK_LEFT:
200 if (viewport.cursorMode)
202 alignPanel.seqPanel.moveCursor( -1, 0);
206 case KeyEvent.VK_RIGHT:
207 if (viewport.cursorMode)
209 alignPanel.seqPanel.moveCursor(1, 0);
213 case KeyEvent.VK_SPACE:
214 if (viewport.cursorMode)
216 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
222 case KeyEvent.VK_DELETE:
223 case KeyEvent.VK_BACK_SPACE:
224 if (!viewport.cursorMode)
226 cut_actionPerformed(null);
229 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
236 if (viewport.cursorMode)
238 alignPanel.seqPanel.setCursorRow();
242 if (viewport.cursorMode && !evt.isControlDown())
244 alignPanel.seqPanel.setCursorColumn();
248 if (viewport.cursorMode)
250 alignPanel.seqPanel.setCursorPosition();
254 case KeyEvent.VK_ENTER:
255 case KeyEvent.VK_COMMA:
256 if (viewport.cursorMode)
258 alignPanel.seqPanel.setCursorRowAndColumn();
263 if (viewport.cursorMode)
265 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
269 if (viewport.cursorMode)
271 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
276 viewport.cursorMode = !viewport.cursorMode;
277 statusBar.setText("Keyboard editing mode is " +
278 (viewport.cursorMode ? "on" : "off"));
279 if (viewport.cursorMode)
281 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
282 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
284 alignPanel.seqPanel.seqCanvas.repaint();
290 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
291 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
292 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
294 javax.help.HelpBroker hb = hs.createHelpBroker();
295 hb.setCurrentID("home");
296 hb.setDisplayed(true);
300 ex.printStackTrace();
306 boolean toggleSeqs = !evt.isControlDown();
307 boolean toggleCols = !evt.isShiftDown();
309 boolean hide = false;
311 SequenceGroup sg = viewport.getSelectionGroup();
314 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
316 hideSelSequences_actionPerformed(null);
319 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
320 showAllSeqs_actionPerformed(null);
325 if (viewport.colSel.getSelected().size() > 0)
327 hideSelColumns_actionPerformed(null);
329 viewport.selectionGroup = sg;
332 showAllColumns_actionPerformed(null);
336 case KeyEvent.VK_PAGE_UP:
337 if (viewport.wrapAlignment)
338 alignPanel.scrollUp(true);
340 alignPanel.setScrollValues(viewport.startRes,
342 - viewport.endSeq + viewport.startSeq);
344 case KeyEvent.VK_PAGE_DOWN:
345 if (viewport.wrapAlignment)
346 alignPanel.scrollUp(false);
348 alignPanel.setScrollValues(viewport.startRes,
350 + viewport.endSeq - viewport.startSeq);
358 public void addAlignmentPanel(final AlignmentPanel ap,
361 ap.alignFrame = this;
363 alignPanels.addElement(ap);
365 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
367 int aSize = alignPanels.size();
369 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
371 if (aSize == 1 && ap.av.viewName==null)
373 this.getContentPane().add(ap, BorderLayout.CENTER);
379 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
380 tabbedPane.addTab(first.av.viewName==null?"Original":first.av.viewName,first);
382 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
385 expandViews.setEnabled(true);
386 gatherViews.setEnabled(true);
387 tabbedPane.addTab(ap.av.viewName==null?"Original":ap.av.viewName, ap);
389 ap.setVisible(false);
395 ap.av.alignment.padGaps();
396 ap.av.updateConservation(ap);
397 ap.av.updateConsensus(ap);
402 public AlignViewport getViewport()
407 /* Set up intrinsic listeners for dynamically generated GUI bits. */
408 private void addServiceListeners()
410 final java.beans.PropertyChangeListener thisListener;
411 // Do this once to get current state
412 BuildWebServiceMenu();
413 Desktop.discoverer.addPropertyChangeListener(
414 thisListener = new java.beans.PropertyChangeListener()
416 public void propertyChange(PropertyChangeEvent evt)
418 // System.out.println("Discoverer property change.");
419 if (evt.getPropertyName().equals("services"))
421 // System.out.println("Rebuilding web service menu");
422 BuildWebServiceMenu();
427 addInternalFrameListener(new javax.swing.event.
428 InternalFrameAdapter()
430 public void internalFrameClosed(
431 javax.swing.event.InternalFrameEvent evt)
433 // System.out.println("deregistering discoverer listener");
434 Desktop.discoverer.removePropertyChangeListener(thisListener);
435 closeMenuItem_actionPerformed(true);
441 public void setGUINucleotide(boolean nucleotide)
443 showTranslation.setVisible( nucleotide );
444 conservationMenuItem.setEnabled( !nucleotide );
445 modifyConservation.setEnabled( !nucleotide );
447 //Remember AlignFrame always starts as protein
450 calculateMenu.remove(calculateMenu.getItemCount()-2);
455 * Need to call this method when tabs are selected for multiple views,
456 * or when loading from Jalview2XML.java
457 * @param av AlignViewport
459 void setMenusFromViewport(AlignViewport av)
461 padGapsMenuitem.setSelected(av.padGaps);
462 colourTextMenuItem.setSelected(av.showColourText);
463 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
464 conservationMenuItem.setSelected(av.getConservationSelected());
465 seqLimits.setSelected(av.getShowJVSuffix());
466 idRightAlign.setSelected(av.idsAlignRight);
467 renderGapsMenuItem.setSelected(av.renderGaps);
468 wrapMenuItem.setSelected(av.wrapAlignment);
469 annotationPanelMenuItem.setState(av.showAnnotation);
470 viewBoxesMenuItem.setSelected(av.showBoxes);
471 viewTextMenuItem.setSelected(av.showText);
473 setColourSelected(ColourSchemeProperty.
474 getColourName(av.getGlobalColourScheme()));
476 showSeqFeatures.setSelected(av.showSequenceFeatures);
477 hiddenMarkers.setState(av.showHiddenMarkers);
478 applyToAllGroups.setState(av.colourAppliesToAllGroups);
484 Hashtable progressBars;
485 public void setProgressBar(String message, long id)
487 if(progressBars == null)
488 progressBars = new Hashtable();
490 JPanel progressPanel;
491 GridLayout layout = (GridLayout) statusPanel.getLayout();
492 if(progressBars.get( new Long(id) )!=null)
494 progressPanel = (JPanel)progressBars.get( new Long(id) );
495 statusPanel.remove(progressPanel);
496 progressBars.remove( progressPanel );
497 progressPanel = null;
499 statusBar.setText(message);
501 layout.setRows(layout.getRows() - 1);
505 progressPanel = new JPanel(new BorderLayout(10, 5));
507 JProgressBar progressBar = new JProgressBar();
508 progressBar.setIndeterminate(true);
510 progressPanel.add(new JLabel(message), BorderLayout.WEST);
511 progressPanel.add(progressBar, BorderLayout.CENTER);
513 layout.setRows(layout.getRows() + 1);
514 statusPanel.add(progressPanel);
516 progressBars.put(new Long(id), progressPanel);
526 Added so Castor Mapping file can obtain Jalview Version
528 public String getVersion()
530 return jalview.bin.Cache.getProperty("VERSION");
533 public FeatureRenderer getFeatureRenderer()
535 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
539 public void fetchSequence_actionPerformed(ActionEvent e)
541 new SequenceFetcher(this);
544 public void addFromFile_actionPerformed(ActionEvent e)
546 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
549 public void reload_actionPerformed(ActionEvent e)
553 if(currentFileFormat.equals("Jalview"))
555 this.closeMenuItem_actionPerformed(true);
559 viewport.alignment.deleteAllGroups();
560 viewport.sequenceColours=null;
561 while (viewport.alignment.getHeight() > 0)
563 viewport.alignment.deleteSequence(0);
566 viewport.historyList.clear();
567 viewport.redoList.clear();
568 Alignment dset = viewport.alignment.getDataset();
569 while (dset.getHeight() > 0)
571 dset.deleteSequence(0);
574 firePropertyChange("Alignment", null, null);
579 FileLoader loader = new FileLoader();
580 String protocol = fileName.startsWith("http:")? "URL":"File";
581 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
587 public void addFromText_actionPerformed(ActionEvent e)
589 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
592 public void addFromURL_actionPerformed(ActionEvent e)
594 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
598 public void save_actionPerformed(ActionEvent e)
600 if(fileName==null || currentFileFormat==null)
601 saveAs_actionPerformed(null);
603 saveAlignment(fileName, currentFileFormat);
609 * @param e DOCUMENT ME!
611 public void saveAs_actionPerformed(ActionEvent e)
613 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
614 getProperty( "LAST_DIRECTORY"),
616 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
618 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
623 chooser.setFileView(new JalviewFileView());
624 chooser.setDialogTitle("Save Alignment to file");
625 chooser.setToolTipText("Save");
627 int value = chooser.showSaveDialog(this);
629 if (value == JalviewFileChooser.APPROVE_OPTION)
631 currentFileFormat = chooser.getSelectedFormat();
632 if (currentFileFormat == null)
634 JOptionPane.showInternalMessageDialog(Desktop.desktop,
635 "You must select a file format before saving!",
636 "File format not specified",
637 JOptionPane.WARNING_MESSAGE);
638 value = chooser.showSaveDialog(this);
642 fileName = chooser.getSelectedFile().getPath();
644 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
647 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
649 saveAlignment(fileName, currentFileFormat);
653 public boolean saveAlignment(String file, String format)
655 if (format.equalsIgnoreCase("Jalview"))
657 String shortName = title;
659 if (shortName.indexOf(java.io.File.separatorChar) > -1)
661 shortName = shortName.substring(shortName.lastIndexOf(
662 java.io.File.separatorChar) + 1);
665 new Jalview2XML().SaveAlignment(this, file, shortName);
667 statusBar.setText("Successfully saved to file: "
669 +format +" format.");
672 // USE Jalview2XML to save this file
678 String[] omitHidden = null;
680 if (viewport.hasHiddenColumns)
682 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
683 "The Alignment contains hidden columns."
684 + "\nDo you want to save only the visible alignment?",
685 "Save / Omit Hidden Columns",
686 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
688 if (reply == JOptionPane.YES_OPTION)
689 omitHidden = viewport.getViewAsString(false);
692 String output = new FormatAdapter().formatSequences(
694 viewport.alignment.getSequencesArray(),
704 java.io.PrintWriter out = new java.io.PrintWriter(
705 new java.io.FileWriter(file));
710 statusBar.setText("Successfully saved to file: "
712 +format +" format.");
717 ex.printStackTrace();
726 * @param e DOCUMENT ME!
728 protected void outputText_actionPerformed(ActionEvent e)
730 String [] omitHidden = null;
732 if(viewport.hasHiddenColumns)
734 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
735 "The Alignment contains hidden columns."
736 +"\nDo you want to output only the visible alignment?",
737 "Save / Omit Hidden Columns",
738 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
740 if(reply==JOptionPane.YES_OPTION)
742 omitHidden = viewport.getViewAsString(false);
746 CutAndPasteTransfer cap = new CutAndPasteTransfer();
747 cap.setForInput(null);
748 Desktop.addInternalFrame(cap,
749 "Alignment output - " + e.getActionCommand(), 600,
753 cap.setText(new FormatAdapter().formatSequences(
754 e.getActionCommand(),
755 viewport.alignment.getSequencesArray(),
762 * @param e DOCUMENT ME!
764 protected void htmlMenuItem_actionPerformed(ActionEvent e)
766 new HTMLOutput(viewport,
767 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
768 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
771 public void createImageMap(File file, String image)
773 alignPanel.makePNGImageMap(file, image);
779 * @param e DOCUMENT ME!
781 public void createPNG(File f)
783 alignPanel.makePNG(f);
789 * @param e DOCUMENT ME!
791 public void createEPS(File f)
793 alignPanel.makeEPS(f);
799 * @param e DOCUMENT ME!
801 public void printMenuItem_actionPerformed(ActionEvent e)
803 //Putting in a thread avoids Swing painting problems
804 PrintThread thread = new PrintThread();
808 public void exportFeatures_actionPerformed(ActionEvent e)
810 new AnnotationExporter().exportFeatures(alignPanel);
814 public void exportAnnotations_actionPerformed(ActionEvent e)
816 new AnnotationExporter().exportAnnotations(
818 viewport.alignment.getAlignmentAnnotation()
823 public void associatedData_actionPerformed(ActionEvent e)
825 // Pick the tree file
826 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
829 chooser.setFileView(new JalviewFileView());
830 chooser.setDialogTitle("Load Jalview Annotations or Features File");
831 chooser.setToolTipText("Load Jalview Annotations / Features file");
833 int value = chooser.showOpenDialog(null);
835 if (value == JalviewFileChooser.APPROVE_OPTION)
837 String choice = chooser.getSelectedFile().getPath();
838 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
839 loadJalviewDataFile(choice);
848 * @param e DOCUMENT ME!
850 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
852 if(alignPanels!=null && alignPanels.size()<2)
857 if(alignPanels!=null)
860 for (int i = 0; i < alignPanels.size(); i++)
862 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
863 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
864 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
865 PaintRefresher.RemoveComponent(ap);
869 int index = tabbedPane.getSelectedIndex();
871 tabbedPane.removeTabAt(index);
872 alignPanels.removeElement(alignPanel);
873 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
874 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
875 PaintRefresher.RemoveComponent(alignPanel);
878 tabbedPane.validate();
880 if(index==tabbedPane.getTabCount())
883 this.tabSelectionChanged(index);
888 this.setClosed(true);
892 ex.printStackTrace();
900 void updateEditMenuBar()
903 if (viewport.historyList.size() > 0)
905 undoMenuItem.setEnabled(true);
906 CommandI command = (CommandI) viewport.historyList.peek();
907 undoMenuItem.setText("Undo " + command.getDescription());
911 undoMenuItem.setEnabled(false);
912 undoMenuItem.setText("Undo");
915 if (viewport.redoList.size() > 0)
917 redoMenuItem.setEnabled(true);
919 CommandI command = (CommandI) viewport.redoList.peek();
920 redoMenuItem.setText("Redo " + command.getDescription());
924 redoMenuItem.setEnabled(false);
925 redoMenuItem.setText("Redo");
930 public void addHistoryItem(CommandI command)
932 if(command.getSize()>0)
934 viewport.historyList.push(command);
935 viewport.redoList.clear();
937 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
946 * @param e DOCUMENT ME!
948 protected void undoMenuItem_actionPerformed(ActionEvent e)
950 CommandI command = (CommandI)viewport.historyList.pop();
951 viewport.redoList.push(command);
952 command.undoCommand();
954 AlignViewport originalSource = getOriginatingSource(command);
956 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
958 originalSource.firePropertyChange("alignment", null,null);
964 * @param e DOCUMENT ME!
966 protected void redoMenuItem_actionPerformed(ActionEvent e)
968 CommandI command = (CommandI) viewport.redoList.pop();
969 viewport.historyList.push(command);
972 AlignViewport originalSource = getOriginatingSource(command);
973 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null;
976 originalSource.firePropertyChange("alignment", null, null);
979 AlignViewport getOriginatingSource(CommandI command)
981 AlignViewport originalSource = viewport;
982 //For sequence removal and addition, we need to fire
983 //the property change event FROM the viewport where the
984 //original alignment was altered
985 if (command instanceof EditCommand)
987 EditCommand editCommand = (EditCommand) command;
988 AlignmentI al = editCommand.getAlignment();
989 Vector comps = (Vector) PaintRefresher.components
990 .get(viewport.getSequenceSetId());
991 for (int i = 0; i < comps.size(); i++)
993 if (comps.elementAt(i) instanceof AlignmentPanel)
995 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
997 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1003 return originalSource;
1009 * @param up DOCUMENT ME!
1011 public void moveSelectedSequences(boolean up)
1013 SequenceGroup sg = viewport.getSelectionGroup();
1022 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1024 SequenceI seq = viewport.alignment.getSequenceAt(i);
1026 if (!sg.getSequences(false).contains(seq))
1031 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1033 if (sg.getSequences(false).contains(temp))
1038 viewport.alignment.getSequences().setElementAt(temp, i);
1039 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1044 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1046 SequenceI seq = viewport.alignment.getSequenceAt(i);
1048 if (!sg.getSequences(false).contains(seq))
1053 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1055 if (sg.getSequences(false).contains(temp))
1060 viewport.alignment.getSequences().setElementAt(temp, i);
1061 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1065 alignPanel.repaint();
1073 * @param e DOCUMENT ME!
1075 protected void copy_actionPerformed(ActionEvent e)
1078 if (viewport.getSelectionGroup() == null)
1083 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1084 String[] omitHidden = null;
1086 if (viewport.hasHiddenColumns)
1088 omitHidden = viewport.getViewAsString(true);
1091 String output = new FormatAdapter().formatSequences(
1096 StringSelection ss = new StringSelection(output);
1100 //Its really worth setting the clipboard contents
1101 //to empty before setting the large StringSelection!!
1102 Toolkit.getDefaultToolkit().getSystemClipboard()
1103 .setContents(new StringSelection(""), null);
1105 Toolkit.getDefaultToolkit().getSystemClipboard()
1106 .setContents(ss, Desktop.instance);
1108 catch (OutOfMemoryError er)
1110 er.printStackTrace();
1111 javax.swing.SwingUtilities.invokeLater(new Runnable()
1115 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1116 "Out of memory copying region!!"
1118 "\nSee help files for increasing Java Virtual Machine memory."
1120 javax.swing.JOptionPane.WARNING_MESSAGE);
1127 Vector hiddenColumns = null;
1128 if(viewport.hasHiddenColumns)
1130 hiddenColumns =new Vector();
1131 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1132 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1134 int[] region = (int[])
1135 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1137 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1138 region[1]-hiddenOffset});
1144 Desktop.jalviewClipboard = new Object[]{ seqs,
1145 viewport.alignment.getDataset(),
1147 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1153 * @param e DOCUMENT ME!
1155 protected void pasteNew_actionPerformed(ActionEvent e)
1163 * @param e DOCUMENT ME!
1165 protected void pasteThis_actionPerformed(ActionEvent e)
1173 * @param newAlignment DOCUMENT ME!
1175 void paste(boolean newAlignment)
1179 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1180 Transferable contents = c.getContents(this);
1182 if (contents == null)
1190 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1191 if (str.length() < 1)
1194 format = new IdentifyFile().Identify(str, "Paste");
1197 catch (OutOfMemoryError er)
1199 er.printStackTrace();
1200 javax.swing.SwingUtilities.invokeLater(new Runnable()
1204 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1205 "Out of memory pasting sequences!!"
1207 "\nSee help files for increasing Java Virtual Machine memory."
1209 javax.swing.JOptionPane.WARNING_MESSAGE);
1216 SequenceI[] sequences;
1219 if(Desktop.jalviewClipboard!=null)
1221 // The clipboard was filled from within Jalview, we must use the sequences
1222 // And dataset from the copied alignment
1223 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1227 sequences = new FormatAdapter().readFile(str, "Paste", format);
1230 AlignmentI alignment = null;
1234 alignment = new Alignment(sequences);
1236 if (Desktop.jalviewClipboard != null)
1237 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1239 alignment.setDataset(null);
1243 alignment = viewport.getAlignment();
1246 SequenceI [] newseqs = new SequenceI[sequences.length];
1247 for (int i = 0; i < sequences.length; i++)
1249 newseqs[i] = new Sequence(sequences[i].getName(),
1250 sequences[i].getSequence(), sequences[i].getStart(),
1251 sequences[i].getEnd());
1253 alignment.addSequence(newseqs[i]);
1259 addHistoryItem(new EditCommand(
1264 alignment.getWidth(),
1269 viewport.setEndSeq(alignment.getHeight());
1270 alignment.getWidth();
1271 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1276 // Add any annotations attached to sequences
1277 for (int i = 0; i < sequences.length; i++)
1279 if (sequences[i].getAnnotation() != null)
1281 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1283 AlignmentAnnotation newAnnot =
1284 new AlignmentAnnotation(
1285 sequences[i].getAnnotation()[a].label,
1286 sequences[i].getAnnotation()[a].description,
1287 sequences[i].getAnnotation()[a].annotations,
1288 sequences[i].getAnnotation()[a].graphMin,
1289 sequences[i].getAnnotation()[a].graphMax,
1290 sequences[i].getAnnotation()[a].graph);
1292 sequences[i].getAnnotation()[a] = newAnnot;
1293 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1295 newAnnot.sequenceRef = sequences[i];
1296 newAnnot.adjustForAlignment();
1297 alignment.addAnnotation(newAnnot);
1298 alignment.setAnnotationIndex(newAnnot, a);
1301 alignPanel.annotationPanel.adjustPanelHeight();
1307 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1308 String newtitle = new String("Copied sequences");
1310 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1312 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1313 for(int i=0; i<hc.size(); i++)
1315 int [] region = (int[]) hc.elementAt(i);
1316 af.viewport.hideColumns(region[0], region[1]);
1321 //>>>This is a fix for the moment, until a better solution is found!!<<<
1322 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1323 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1326 if (title.startsWith("Copied sequences"))
1332 newtitle = newtitle.concat("- from " + title);
1335 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1342 catch (Exception ex)
1344 ex.printStackTrace();
1345 System.out.println("Exception whilst pasting: "+ex);
1346 // could be anything being pasted in here
1355 * @param e DOCUMENT ME!
1357 protected void cut_actionPerformed(ActionEvent e)
1359 copy_actionPerformed(null);
1360 delete_actionPerformed(null);
1366 * @param e DOCUMENT ME!
1368 protected void delete_actionPerformed(ActionEvent evt)
1371 SequenceGroup sg = viewport.getSelectionGroup();
1377 Vector seqs = new Vector();
1379 for (int i = 0; i < sg.getSize(false); i++)
1381 seq = sg.getSequenceAt(i);
1382 seqs.addElement(seq);
1386 // If the cut affects all sequences, remove highlighted columns
1387 if (sg.getSize(false) == viewport.alignment.getHeight())
1389 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1390 sg.getEndRes() + 1);
1394 SequenceI [] cut = new SequenceI[seqs.size()];
1395 for(int i=0; i<seqs.size(); i++)
1396 cut[i] = (SequenceI)seqs.elementAt(i);
1402 addHistoryItem(new EditCommand("Cut Sequences",
1406 sg.getEndRes()-sg.getStartRes()+1,
1407 viewport.alignment));
1410 viewport.setSelectionGroup(null);
1411 viewport.alignment.deleteGroup(sg);
1413 viewport.firePropertyChange("alignment", null,
1414 viewport.getAlignment().getSequences());
1416 if (viewport.getAlignment().getHeight() < 1)
1420 this.setClosed(true);
1422 catch (Exception ex)
1431 * @param e DOCUMENT ME!
1433 protected void deleteGroups_actionPerformed(ActionEvent e)
1435 viewport.alignment.deleteAllGroups();
1436 viewport.sequenceColours.clear();
1437 viewport.setSelectionGroup(null);
1438 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1439 alignPanel.repaint();
1445 * @param e DOCUMENT ME!
1447 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1449 SequenceGroup sg = new SequenceGroup();
1451 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1454 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1457 sg.setEndRes(viewport.alignment.getWidth() - 1);
1458 viewport.setSelectionGroup(sg);
1459 alignPanel.repaint();
1460 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1466 * @param e DOCUMENT ME!
1468 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1470 if(viewport.cursorMode)
1472 alignPanel.seqPanel.keyboardNo1 = null;
1473 alignPanel.seqPanel.keyboardNo2 = null;
1475 viewport.setSelectionGroup(null);
1476 viewport.getColumnSelection().clear();
1477 viewport.setSelectionGroup(null);
1478 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1479 alignPanel.idPanel.idCanvas.searchResults = null;
1480 alignPanel.repaint();
1481 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1487 * @param e DOCUMENT ME!
1489 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1491 SequenceGroup sg = viewport.getSelectionGroup();
1495 selectAllSequenceMenuItem_actionPerformed(null);
1500 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1503 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1506 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1509 public void invertColSel_actionPerformed(ActionEvent e)
1511 viewport.invertColumnSelection();
1512 alignPanel.repaint();
1519 * @param e DOCUMENT ME!
1521 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1523 trimAlignment(true);
1529 * @param e DOCUMENT ME!
1531 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1533 trimAlignment(false);
1536 void trimAlignment(boolean trimLeft)
1538 ColumnSelection colSel = viewport.getColumnSelection();
1541 if (colSel.size() > 0)
1544 column = colSel.getMin();
1546 column = colSel.getMax();
1549 if(viewport.getSelectionGroup()!=null)
1550 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1552 seqs = viewport.alignment.getSequencesArray();
1555 TrimRegionCommand trimRegion;
1558 trimRegion = new TrimRegionCommand("Remove Left",
1559 TrimRegionCommand.TRIM_LEFT,
1564 viewport.selectionGroup);
1565 viewport.setStartRes(0);
1569 trimRegion = new TrimRegionCommand("Remove Right",
1570 TrimRegionCommand.TRIM_RIGHT,
1575 viewport.selectionGroup);
1578 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1581 addHistoryItem(trimRegion);
1583 Vector groups = viewport.alignment.getGroups();
1585 for (int i = 0; i < groups.size(); i++)
1587 SequenceGroup sg = (SequenceGroup) groups.get(i);
1589 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1590 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1592 viewport.alignment.deleteGroup(sg);
1596 viewport.firePropertyChange("alignment", null,
1597 viewport.getAlignment().getSequences());
1604 * @param e DOCUMENT ME!
1606 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1608 int start = 0, end = viewport.alignment.getWidth()-1;
1611 if (viewport.getSelectionGroup() != null)
1613 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1614 start = viewport.getSelectionGroup().getStartRes();
1615 end = viewport.getSelectionGroup().getEndRes();
1618 seqs = viewport.alignment.getSequencesArray();
1621 RemoveGapColCommand removeGapCols =
1622 new RemoveGapColCommand("Remove Gapped Columns",
1625 viewport.getGapCharacter());
1627 addHistoryItem(removeGapCols);
1629 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1631 //This is to maintain viewport position on first residue
1633 SequenceI seq = viewport.alignment.getSequenceAt(0);
1634 int startRes = seq.findPosition(viewport.startRes);
1635 // ShiftList shifts;
1636 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1637 // edit.alColumnChanges=shifts.getInverse();
1638 // if (viewport.hasHiddenColumns)
1639 // viewport.getColumnSelection().compensateForEdits(shifts);
1640 viewport.setStartRes(seq.findIndex(startRes)-1);
1641 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1648 * @param e DOCUMENT ME!
1650 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1652 int start = 0, end = viewport.alignment.getWidth()-1;
1655 if (viewport.getSelectionGroup() != null)
1657 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1658 start = viewport.getSelectionGroup().getStartRes();
1659 end = viewport.getSelectionGroup().getEndRes();
1662 seqs = viewport.alignment.getSequencesArray();
1664 //This is to maintain viewport position on first residue
1666 SequenceI seq = viewport.alignment.getSequenceAt(0);
1667 int startRes = seq.findPosition(viewport.startRes);
1669 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1672 viewport.getGapCharacter()));
1674 viewport.setStartRes(seq.findIndex(startRes)-1);
1676 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1683 * @param e DOCUMENT ME!
1685 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1687 viewport.padGaps = padGapsMenuitem.isSelected();
1689 viewport.firePropertyChange("alignment",
1691 viewport.getAlignment().getSequences());
1697 * @param e DOCUMENT ME!
1699 public void findMenuItem_actionPerformed(ActionEvent e)
1704 public void newView_actionPerformed(ActionEvent e)
1706 AlignmentPanel newap =
1707 new Jalview2XML().copyAlignPanel(alignPanel, true);
1709 if (viewport.viewName == null)
1710 viewport.viewName = "View 1";
1712 newap.av.historyList = viewport.historyList;
1713 newap.av.redoList = viewport.redoList;
1714 newap.av.viewName = "View " +
1715 (Desktop.getViewCount(viewport.getSequenceSetId()) + 1);
1717 addAlignmentPanel(newap, false);
1719 if(alignPanels.size()==2)
1721 viewport.gatherViewsHere = true;
1723 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1726 public void expandViews_actionPerformed(ActionEvent e)
1728 Desktop.instance.explodeViews(this);
1731 public void gatherViews_actionPerformed(ActionEvent e)
1733 Desktop.instance.gatherViews(this);
1741 * @param e DOCUMENT ME!
1743 public void font_actionPerformed(ActionEvent e)
1745 new FontChooser(alignPanel);
1752 * @param e DOCUMENT ME!
1754 protected void seqLimit_actionPerformed(ActionEvent e)
1756 viewport.setShowJVSuffix(seqLimits.isSelected());
1758 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1759 alignPanel.repaint();
1762 public void idRightAlign_actionPerformed(ActionEvent e)
1764 viewport.idsAlignRight = idRightAlign.isSelected();
1765 alignPanel.repaint();
1773 * @param e DOCUMENT ME!
1775 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1777 viewport.setColourText(colourTextMenuItem.isSelected());
1778 alignPanel.repaint();
1784 * @param e DOCUMENT ME!
1786 public void wrapMenuItem_actionPerformed(ActionEvent e)
1788 scaleAbove.setVisible(wrapMenuItem.isSelected());
1789 scaleLeft.setVisible(wrapMenuItem.isSelected());
1790 scaleRight.setVisible(wrapMenuItem.isSelected());
1791 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1792 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1795 public void showAllSeqs_actionPerformed(ActionEvent e)
1797 viewport.showAllHiddenSeqs();
1800 public void showAllColumns_actionPerformed(ActionEvent e)
1802 viewport.showAllHiddenColumns();
1806 public void hideSelSequences_actionPerformed(ActionEvent e)
1808 viewport.hideAllSelectedSeqs();
1809 alignPanel.repaint();
1812 public void hideSelColumns_actionPerformed(ActionEvent e)
1814 viewport.hideSelectedColumns();
1815 alignPanel.repaint();
1818 public void hiddenMarkers_actionPerformed(ActionEvent e)
1820 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1827 * @param e DOCUMENT ME!
1829 protected void scaleAbove_actionPerformed(ActionEvent e)
1831 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1832 alignPanel.repaint();
1838 * @param e DOCUMENT ME!
1840 protected void scaleLeft_actionPerformed(ActionEvent e)
1842 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1843 alignPanel.repaint();
1849 * @param e DOCUMENT ME!
1851 protected void scaleRight_actionPerformed(ActionEvent e)
1853 viewport.setScaleRightWrapped(scaleRight.isSelected());
1854 alignPanel.repaint();
1860 * @param e DOCUMENT ME!
1862 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1864 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1865 alignPanel.repaint();
1871 * @param e DOCUMENT ME!
1873 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1875 viewport.setShowText(viewTextMenuItem.isSelected());
1876 alignPanel.repaint();
1882 * @param e DOCUMENT ME!
1884 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1886 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1887 alignPanel.repaint();
1891 public FeatureSettings featureSettings;
1892 public void featureSettings_actionPerformed(ActionEvent e)
1894 if(featureSettings !=null )
1896 featureSettings.close();
1897 featureSettings = null;
1899 featureSettings = new FeatureSettings(this);
1905 * @param evt DOCUMENT ME!
1907 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1909 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1910 alignPanel.repaint();
1911 if (alignPanel.getOverviewPanel() != null)
1913 alignPanel.getOverviewPanel().updateOverviewImage();
1920 * @param e DOCUMENT ME!
1922 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1924 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1925 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1931 * @param e DOCUMENT ME!
1933 public void overviewMenuItem_actionPerformed(ActionEvent e)
1935 if (alignPanel.overviewPanel != null)
1940 JInternalFrame frame = new JInternalFrame();
1941 OverviewPanel overview = new OverviewPanel(alignPanel);
1942 frame.setContentPane(overview);
1943 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1944 frame.getWidth(), frame.getHeight());
1946 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1947 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1949 public void internalFrameClosed(
1950 javax.swing.event.InternalFrameEvent evt)
1952 alignPanel.setOverviewPanel(null);
1957 alignPanel.setOverviewPanel(overview);
1960 public void textColour_actionPerformed(ActionEvent e)
1962 int original1 = viewport.textColour.getRGB();
1963 int original2 = viewport.textColour2.getRGB();
1964 int thresh = viewport.thresholdTextColour;
1965 final JSlider slider = new JSlider(0, 750, viewport.thresholdTextColour);
1966 final JButton col1 = new JButton("DARK");
1967 col1.setBackground(viewport.textColour);
1968 col1.setForeground(viewport.textColour);
1969 final JButton col2 = new JButton("LIGHT");
1970 col2.setBackground(viewport.textColour2);
1971 col2.setForeground(viewport.textColour2);
1972 final JPanel bigpanel = new JPanel(new BorderLayout());
1973 JPanel panel = new JPanel();
1974 bigpanel.add(panel, BorderLayout.CENTER);
1975 bigpanel.add(new JLabel(
1976 "<html><i>Select a dark and light text colour, then set the threshold to"
1977 +"<br>switch between colours, based on background colour</i></html>"),
1978 BorderLayout.NORTH);
1983 col1.addActionListener(new ActionListener()
1985 public void actionPerformed(ActionEvent e)
1987 Color col = JColorChooser.showDialog(bigpanel,
1988 "Select Colour for Text",
1989 viewport.textColour);
1992 viewport.textColour = col;
1993 col1.setBackground(col);
1994 col1.setForeground(col);
1995 if(viewport.colourAppliesToAllGroups)
1996 setGroupTextColour();
1998 alignPanel.repaint();
2002 col2.addActionListener(new ActionListener()
2004 public void actionPerformed(ActionEvent e)
2006 Color col = JColorChooser.showDialog(bigpanel,
2007 "Select Colour for Text",
2008 viewport.textColour);
2011 viewport.textColour2 = col;
2012 col2.setBackground(col);
2013 col2.setForeground(col);
2014 if(viewport.colourAppliesToAllGroups)
2015 setGroupTextColour();
2017 alignPanel.repaint();
2022 slider.addChangeListener(new ChangeListener()
2024 public void stateChanged(ChangeEvent evt)
2026 viewport.thresholdTextColour = slider.getValue();
2027 if(viewport.colourAppliesToAllGroups)
2028 setGroupTextColour();
2029 alignPanel.repaint();
2033 int reply = JOptionPane.showInternalOptionDialog(this,
2035 "Adjust Foreground Text Colour Threshold",
2036 JOptionPane.OK_CANCEL_OPTION,
2037 JOptionPane.QUESTION_MESSAGE,
2041 if(reply==JOptionPane.CANCEL_OPTION)
2043 viewport.textColour = new Color(original1);
2044 viewport.textColour2 = new Color(original2);
2045 viewport.thresholdTextColour = thresh;
2049 void setGroupTextColour()
2051 if(viewport.alignment.getGroups()==null)
2054 Vector groups = viewport.alignment.getGroups();
2056 for(int i=0; i<groups.size(); i++)
2058 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
2059 sg.textColour = viewport.textColour;
2060 sg.textColour2 = viewport.textColour2;
2061 sg.thresholdTextColour = viewport.thresholdTextColour;
2071 * @param e DOCUMENT ME!
2073 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2081 * @param e DOCUMENT ME!
2083 public void clustalColour_actionPerformed(ActionEvent e)
2085 changeColour(new ClustalxColourScheme(
2086 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2092 * @param e DOCUMENT ME!
2094 public void zappoColour_actionPerformed(ActionEvent e)
2096 changeColour(new ZappoColourScheme());
2102 * @param e DOCUMENT ME!
2104 public void taylorColour_actionPerformed(ActionEvent e)
2106 changeColour(new TaylorColourScheme());
2112 * @param e DOCUMENT ME!
2114 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2116 changeColour(new HydrophobicColourScheme());
2122 * @param e DOCUMENT ME!
2124 public void helixColour_actionPerformed(ActionEvent e)
2126 changeColour(new HelixColourScheme());
2132 * @param e DOCUMENT ME!
2134 public void strandColour_actionPerformed(ActionEvent e)
2136 changeColour(new StrandColourScheme());
2142 * @param e DOCUMENT ME!
2144 public void turnColour_actionPerformed(ActionEvent e)
2146 changeColour(new TurnColourScheme());
2152 * @param e DOCUMENT ME!
2154 public void buriedColour_actionPerformed(ActionEvent e)
2156 changeColour(new BuriedColourScheme());
2162 * @param e DOCUMENT ME!
2164 public void nucleotideColour_actionPerformed(ActionEvent e)
2166 changeColour(new NucleotideColourScheme());
2169 public void annotationColour_actionPerformed(ActionEvent e)
2171 new AnnotationColourChooser(viewport, alignPanel);
2178 * @param e DOCUMENT ME!
2180 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2182 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2188 * @param cs DOCUMENT ME!
2190 public void changeColour(ColourSchemeI cs)
2196 if (viewport.getAbovePIDThreshold())
2198 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2201 cs.setThreshold(threshold,
2202 viewport.getIgnoreGapsConsensus());
2204 viewport.setGlobalColourScheme(cs);
2208 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2211 if (viewport.getConservationSelected())
2214 Alignment al = (Alignment) viewport.alignment;
2215 Conservation c = new Conservation("All",
2216 ResidueProperties.propHash, 3,
2217 al.getSequences(), 0,
2221 c.verdict(false, viewport.ConsPercGaps);
2223 cs.setConservation(c);
2225 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2230 cs.setConservation(null);
2233 cs.setConsensus(viewport.hconsensus);
2236 viewport.setGlobalColourScheme(cs);
2238 if (viewport.getColourAppliesToAllGroups())
2240 Vector groups = viewport.alignment.getGroups();
2242 for (int i = 0; i < groups.size(); i++)
2244 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2252 if (cs instanceof ClustalxColourScheme)
2254 sg.cs = new ClustalxColourScheme(
2255 sg.getSequences(true), sg.getWidth());
2257 else if (cs instanceof UserColourScheme)
2259 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2265 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2267 catch (Exception ex)
2272 if (viewport.getAbovePIDThreshold()
2273 || cs instanceof PIDColourScheme
2274 || cs instanceof Blosum62ColourScheme)
2276 sg.cs.setThreshold(threshold,
2277 viewport.getIgnoreGapsConsensus());
2279 sg.cs.setConsensus(AAFrequency.calculate(
2280 sg.getSequences(true), sg.getStartRes(),
2284 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2287 if (viewport.getConservationSelected())
2289 Conservation c = new Conservation("Group",
2290 ResidueProperties.propHash, 3,
2291 sg.getSequences(true),
2295 c.verdict(false, viewport.ConsPercGaps);
2296 sg.cs.setConservation(c);
2299 sg.cs.setConservation(null);
2303 if (alignPanel.getOverviewPanel() != null)
2305 alignPanel.getOverviewPanel().updateOverviewImage();
2308 alignPanel.repaint();
2314 * @param e DOCUMENT ME!
2316 protected void modifyPID_actionPerformed(ActionEvent e)
2318 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2320 SliderPanel.setPIDSliderSource(alignPanel,
2321 viewport.getGlobalColourScheme(),
2323 SliderPanel.showPIDSlider();
2330 * @param e DOCUMENT ME!
2332 protected void modifyConservation_actionPerformed(ActionEvent e)
2334 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2336 SliderPanel.setConservationSlider(alignPanel,
2337 viewport.globalColourScheme,
2339 SliderPanel.showConservationSlider();
2346 * @param e DOCUMENT ME!
2348 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2350 viewport.setConservationSelected(conservationMenuItem.isSelected());
2352 viewport.setAbovePIDThreshold(false);
2353 abovePIDThreshold.setSelected(false);
2355 changeColour(viewport.getGlobalColourScheme());
2357 modifyConservation_actionPerformed(null);
2363 * @param e DOCUMENT ME!
2365 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2367 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2369 conservationMenuItem.setSelected(false);
2370 viewport.setConservationSelected(false);
2372 changeColour(viewport.getGlobalColourScheme());
2374 modifyPID_actionPerformed(null);
2380 * @param e DOCUMENT ME!
2382 public void userDefinedColour_actionPerformed(ActionEvent e)
2384 if (e.getActionCommand().equals("User Defined..."))
2386 new UserDefinedColours(alignPanel, null);
2390 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2391 getUserColourSchemes().get(e.getActionCommand());
2397 public void updateUserColourMenu()
2400 Component[] menuItems = colourMenu.getMenuComponents();
2401 int i, iSize = menuItems.length;
2402 for (i = 0; i < iSize; i++)
2404 if (menuItems[i].getName() != null &&
2405 menuItems[i].getName().equals("USER_DEFINED"))
2407 colourMenu.remove(menuItems[i]);
2411 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2413 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2414 getUserColourSchemes().keys();
2416 while (userColours.hasMoreElements())
2418 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2419 nextElement().toString());
2420 radioItem.setName("USER_DEFINED");
2421 radioItem.addMouseListener(new MouseAdapter()
2423 public void mousePressed(MouseEvent evt)
2425 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2427 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2429 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2430 "Remove from default list?",
2431 "Remove user defined colour",
2432 JOptionPane.YES_NO_OPTION);
2433 if(option == JOptionPane.YES_OPTION)
2435 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2436 colourMenu.remove(radioItem);
2439 radioItem.addActionListener(new ActionListener()
2441 public void actionPerformed(ActionEvent evt)
2443 userDefinedColour_actionPerformed(evt);
2449 radioItem.addActionListener(new ActionListener()
2451 public void actionPerformed(ActionEvent evt)
2453 userDefinedColour_actionPerformed(evt);
2457 colourMenu.insert(radioItem, 15);
2458 colours.add(radioItem);
2466 * @param e DOCUMENT ME!
2468 public void PIDColour_actionPerformed(ActionEvent e)
2470 changeColour(new PIDColourScheme());
2476 * @param e DOCUMENT ME!
2478 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2480 changeColour(new Blosum62ColourScheme());
2486 * @param e DOCUMENT ME!
2488 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2490 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2491 AlignmentSorter.sortByPID(viewport.getAlignment(),
2492 viewport.getAlignment().getSequenceAt(0));
2493 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2494 alignPanel.repaint();
2500 * @param e DOCUMENT ME!
2502 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2504 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2505 AlignmentSorter.sortByID(viewport.getAlignment());
2506 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2507 alignPanel.repaint();
2513 * @param e DOCUMENT ME!
2515 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2517 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2518 AlignmentSorter.sortByGroup(viewport.getAlignment());
2519 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2521 alignPanel.repaint();
2527 * @param e DOCUMENT ME!
2529 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2531 new RedundancyPanel(alignPanel, this);
2538 * @param e DOCUMENT ME!
2540 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2542 if ( (viewport.getSelectionGroup() == null) ||
2543 (viewport.getSelectionGroup().getSize(false) < 2))
2545 JOptionPane.showInternalMessageDialog(this,
2546 "You must select at least 2 sequences.",
2547 "Invalid Selection",
2548 JOptionPane.WARNING_MESSAGE);
2552 JInternalFrame frame = new JInternalFrame();
2553 frame.setContentPane(new PairwiseAlignPanel(viewport));
2554 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2561 * @param e DOCUMENT ME!
2563 public void PCAMenuItem_actionPerformed(ActionEvent e)
2565 if ( ( (viewport.getSelectionGroup() != null) &&
2566 (viewport.getSelectionGroup().getSize(false) < 4) &&
2567 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2568 (viewport.getAlignment().getHeight() < 4))
2570 JOptionPane.showInternalMessageDialog(this,
2571 "Principal component analysis must take\n" +
2572 "at least 4 input sequences.",
2573 "Sequence selection insufficient",
2574 JOptionPane.WARNING_MESSAGE);
2579 new PCAPanel(viewport);
2583 public void autoCalculate_actionPerformed(ActionEvent e)
2585 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2586 if(viewport.autoCalculateConsensus)
2588 viewport.firePropertyChange("alignment",
2590 viewport.getAlignment().getSequences());
2598 * @param e DOCUMENT ME!
2600 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2602 NewTreePanel("AV", "PID", "Average distance tree using PID");
2608 * @param e DOCUMENT ME!
2610 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2612 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2618 * @param e DOCUMENT ME!
2620 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2622 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2628 * @param e DOCUMENT ME!
2630 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2632 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2638 * @param type DOCUMENT ME!
2639 * @param pwType DOCUMENT ME!
2640 * @param title DOCUMENT ME!
2642 void NewTreePanel(String type, String pwType, String title)
2646 if (viewport.getSelectionGroup() != null) {
2647 if (viewport.getSelectionGroup().getSize(false) < 3) {
2648 JOptionPane.showMessageDialog(Desktop.desktop,
2649 "You need to have more than two sequences selected to build a tree!",
2650 "Not enough sequences",
2651 JOptionPane.WARNING_MESSAGE);
2656 SequenceGroup sg = viewport.getSelectionGroup();
2658 /* Decide if the selection is a column region */
2659 while (s < sg.getSize(false))
2661 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2664 JOptionPane.showMessageDialog(Desktop.desktop,
2665 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2666 "Try using the Pad function in the edit menu,\n" +
2667 "or one of the multiple sequence alignment web services.",
2668 "Sequences in selection are not aligned",
2669 JOptionPane.WARNING_MESSAGE);
2675 title = title + " on region";
2676 tp = new TreePanel(alignPanel, type, pwType);
2680 //are the sequences aligned?
2681 if (!viewport.alignment.isAligned())
2683 JOptionPane.showMessageDialog(Desktop.desktop,
2684 "The sequences must be aligned before creating a tree.\n" +
2685 "Try using the Pad function in the edit menu,\n" +
2686 "or one of the multiple sequence alignment web services.",
2687 "Sequences not aligned",
2688 JOptionPane.WARNING_MESSAGE);
2693 if(viewport.alignment.getHeight()<2)
2696 tp = new TreePanel(alignPanel, type, pwType);
2699 addTreeMenuItem(tp, title);
2701 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2707 * @param title DOCUMENT ME!
2708 * @param order DOCUMENT ME!
2710 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2712 final JMenuItem item = new JMenuItem("by " + title);
2714 item.addActionListener(new java.awt.event.ActionListener()
2716 public void actionPerformed(ActionEvent e)
2718 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2720 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2721 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2723 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2725 alignPanel.repaint();
2731 * Maintain the Order by->Displayed Tree menu.
2732 * Creates a new menu item for a TreePanel with an appropriate
2733 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2734 * to remove the menu item when the treePanel is closed, and adjust
2735 * the tree leaf to sequence mapping when the alignment is modified.
2736 * @param treePanel Displayed tree window.
2737 * @param title SortBy menu item title.
2739 void addTreeMenuItem(final TreePanel treePanel, String title)
2741 final JMenuItem item = new JMenuItem(title);
2747 sort.add(sortByTreeMenu);
2750 sortByTreeMenu.add(item);
2751 item.addActionListener(new java.awt.event.ActionListener()
2753 public void actionPerformed(ActionEvent e)
2755 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2756 AlignmentSorter.sortByTree(viewport.getAlignment(),
2757 treePanel.getTree());
2759 addHistoryItem(new OrderCommand("Tree Sort",
2761 viewport.alignment));
2764 alignPanel.repaint();
2768 treePanel.addInternalFrameListener(new javax.swing.event.
2769 InternalFrameAdapter()
2771 public void internalFrameClosed(
2772 javax.swing.event.InternalFrameEvent evt)
2775 sortByTreeMenu.remove(item);
2779 sort.remove(sortByTreeMenu);
2787 * Work out whether the whole set of sequences
2788 * or just the selected set will be submitted for multiple alignment.
2791 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2793 // Now, check we have enough sequences
2794 AlignmentView msa = null;
2796 if ( (viewport.getSelectionGroup() != null) &&
2797 (viewport.getSelectionGroup().getSize(false) > 1))
2799 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2800 /*SequenceGroup seqs = viewport.getSelectionGroup();
2802 msa = new SequenceI[sz = seqs.getSize(false)];
2804 for (int i = 0; i < sz; i++)
2806 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2808 msa = viewport.getAlignmentView(true);
2812 /*Vector seqs = viewport.getAlignment().getSequences();
2814 if (seqs.size() > 1)
2816 msa = new SequenceI[seqs.size()];
2818 for (int i = 0; i < seqs.size(); i++)
2820 msa[i] = (SequenceI) seqs.elementAt(i);
2823 msa = viewport.getAlignmentView(false);
2829 * Decides what is submitted to a secondary structure prediction service,
2830 * the currently selected sequence, or the currently selected alignment
2831 * (where the first sequence in the set is the one that the prediction
2834 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2836 AlignmentView seqs = null;
2838 if ( (viewport.getSelectionGroup() != null) &&
2839 (viewport.getSelectionGroup().getSize(false) > 0))
2841 seqs = viewport.getAlignmentView(true);
2845 seqs = viewport.getAlignmentView(false);
2847 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2848 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2849 if (!viewport.alignment.isAligned())
2851 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2858 * @param e DOCUMENT ME!
2860 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2862 // Pick the tree file
2863 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2866 chooser.setFileView(new JalviewFileView());
2867 chooser.setDialogTitle("Select a newick-like tree file");
2868 chooser.setToolTipText("Load a tree file");
2870 int value = chooser.showOpenDialog(null);
2872 if (value == JalviewFileChooser.APPROVE_OPTION)
2874 String choice = chooser.getSelectedFile().getPath();
2875 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2879 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2881 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2883 catch (Exception ex)
2885 JOptionPane.showMessageDialog(Desktop.desktop,
2886 "Problem reading tree file",
2888 JOptionPane.WARNING_MESSAGE);
2889 ex.printStackTrace();
2895 public TreePanel ShowNewickTree(NewickFile nf, String title)
2897 return ShowNewickTree(nf,title,600,500,4,5);
2899 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2901 return ShowNewickTree(nf,title, input, 600,500,4,5);
2903 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2904 return ShowNewickTree(nf, title, null, w, h, x, y);
2907 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2909 * @param nf the tree
2910 * @param title tree viewer title
2911 * @param input Associated alignment input data (or null)
2916 * @return TreePanel handle
2918 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2919 TreePanel tp = null;
2925 if (nf.getTree() != null)
2927 tp = new TreePanel(alignPanel,
2935 tp.setLocation(x,y);
2938 Desktop.addInternalFrame(tp, title, w, h);
2939 addTreeMenuItem(tp, title);
2942 catch (Exception ex)
2944 ex.printStackTrace();
2955 PrinterJob printJob = PrinterJob.getPrinterJob();
2956 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2957 printJob.setPrintable(alignPanel, pf);
2959 if (printJob.printDialog())
2965 catch (Exception PrintException)
2967 PrintException.printStackTrace();
2974 * Generates menu items and listener event actions for web service clients
2977 public void BuildWebServiceMenu()
2979 if ( (Discoverer.services != null)
2980 && (Discoverer.services.size() > 0))
2982 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2983 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2984 Vector wsmenu = new Vector();
2985 final AlignFrame af = this;
2988 // Add any Multiple Sequence Alignment Services
2989 final JMenu msawsmenu = new JMenu("Alignment");
2990 for (int i = 0, j = msaws.size(); i < j; i++)
2992 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2994 final JMenuItem method = new JMenuItem(sh.getName());
2995 method.addActionListener(new ActionListener()
2997 public void actionPerformed(ActionEvent e)
2999 AlignmentView msa = gatherSequencesForAlignment();
3000 new jalview.ws.MsaWSClient(sh, title, msa,
3001 false, true, viewport.getAlignment().getDataset(), af);
3006 msawsmenu.add(method);
3007 // Deal with services that we know accept partial alignments.
3008 if (sh.getName().indexOf("lustal") > -1)
3010 // We know that ClustalWS can accept partial alignments for refinement.
3011 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
3012 methodR.addActionListener(new ActionListener()
3014 public void actionPerformed(ActionEvent e)
3016 AlignmentView msa = gatherSequencesForAlignment();
3017 new jalview.ws.MsaWSClient(sh, title, msa,
3018 true, true, viewport.getAlignment().getDataset(), af);
3023 msawsmenu.add(methodR);
3027 wsmenu.add(msawsmenu);
3029 if (secstrpr != null)
3031 // Add any secondary structure prediction services
3032 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3033 for (int i = 0, j = secstrpr.size(); i < j; i++)
3035 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3037 final JMenuItem method = new JMenuItem(sh.getName());
3038 method.addActionListener(new ActionListener()
3040 public void actionPerformed(ActionEvent e)
3042 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3043 if (msa.getSequences().length == 1)
3045 // Single Sequence prediction
3046 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3050 if (msa.getSequences().length > 1)
3052 // Sequence profile based prediction
3053 new jalview.ws.JPredClient(sh,
3054 title, true, msa, af, true);
3059 secstrmenu.add(method);
3061 wsmenu.add(secstrmenu);
3063 this.webService.removeAll();
3064 for (int i = 0, j = wsmenu.size(); i < j; i++)
3066 webService.add( (JMenu) wsmenu.get(i));
3071 this.webService.removeAll();
3072 this.webService.add(this.webServiceNoServices);
3074 // TODO: add in rediscovery function
3075 // TODO: reduce code redundancy.
3076 // TODO: group services by location as well as function.
3079 /* public void vamsasStore_actionPerformed(ActionEvent e)
3081 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3082 getProperty("LAST_DIRECTORY"));
3084 chooser.setFileView(new JalviewFileView());
3085 chooser.setDialogTitle("Export to Vamsas file");
3086 chooser.setToolTipText("Export");
3088 int value = chooser.showSaveDialog(this);
3090 if (value == JalviewFileChooser.APPROVE_OPTION)
3092 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3093 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3094 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3101 public void showTranslation_actionPerformed(ActionEvent e)
3103 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3104 String [] seqstring = viewport.getViewAsString(true);
3106 int s, sSize = selection.length;
3107 SequenceI [] newSeq = new SequenceI[sSize];
3110 StringBuffer protein;
3112 for(s=0; s<sSize; s++)
3114 protein = new StringBuffer();
3115 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3116 resSize = seq.length();
3117 resSize -= resSize%3;
3119 for(res = 0; res < resSize; res+=3)
3121 String codon = seq.substring(res, res+3);
3122 codon = codon.replace('U', 'T');
3123 String aa = ResidueProperties.codonTranslate(codon);
3125 protein.append(viewport.getGapCharacter());
3126 else if(aa.equals("STOP"))
3127 protein.append("X");
3129 protein.append( aa );
3131 newSeq[s] = new Sequence(selection[s].getName(),
3132 protein.toString());
3136 AlignmentI al = new Alignment(newSeq);
3137 al.setDataset(null);
3140 ////////////////////////////////
3141 // Copy annotations across
3142 jalview.datamodel.AlignmentAnnotation[] annotations
3143 = viewport.alignment.getAlignmentAnnotation();
3145 if(annotations!=null)
3147 for (int i = 0; i < annotations.length; i++)
3149 if (annotations[i].label.equals("Quality") ||
3150 annotations[i].label.equals("Conservation") ||
3151 annotations[i].label.equals("Consensus"))
3156 aSize = viewport.alignment.getWidth() / 3;
3157 jalview.datamodel.Annotation[] anots =
3158 new jalview.datamodel.Annotation[aSize];
3160 for (a = 0; a < viewport.alignment.getWidth(); a++)
3162 if (annotations[i].annotations[a] == null
3163 || annotations[i].annotations[a] == null)
3166 anots[a / 3] = new Annotation(
3167 annotations[i].annotations[a].displayCharacter,
3168 annotations[i].annotations[a].description,
3169 annotations[i].annotations[a].secondaryStructure,
3170 annotations[i].annotations[a].value,
3171 annotations[i].annotations[a].colour);
3174 jalview.datamodel.AlignmentAnnotation aa
3175 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3176 annotations[i].description, anots);
3177 al.addAnnotation(aa);
3181 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3182 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3194 * @param String DOCUMENT ME!
3196 public boolean parseFeaturesFile(String file, String type)
3198 boolean featuresFile = false;
3200 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3201 alignPanel.seqPanel.seqCanvas.
3202 getFeatureRenderer().featureColours,
3207 ex.printStackTrace();
3212 viewport.showSequenceFeatures = true;
3213 showSeqFeatures.setSelected(true);
3214 alignPanel.repaint();
3217 return featuresFile;
3220 public void dragEnter(DropTargetDragEvent evt)
3223 public void dragExit(DropTargetEvent evt)
3226 public void dragOver(DropTargetDragEvent evt)
3229 public void dropActionChanged(DropTargetDragEvent evt)
3232 public void drop(DropTargetDropEvent evt)
3234 Transferable t = evt.getTransferable();
3235 java.util.List files = null;
3239 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3240 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3242 //Works on Windows and MacOSX
3243 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3244 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3246 else if (t.isDataFlavorSupported(uriListFlavor))
3248 // This is used by Unix drag system
3249 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3250 String data = (String) t.getTransferData(uriListFlavor);
3251 files = new java.util.ArrayList(1);
3252 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3255 st.hasMoreTokens(); )
3257 String s = st.nextToken();
3258 if (s.startsWith("#"))
3260 // the line is a comment (as per the RFC 2483)
3264 java.net.URI uri = new java.net.URI(s);
3265 java.io.File file = new java.io.File(uri);
3272 e.printStackTrace();
3279 for (int i = 0; i < files.size(); i++)
3281 loadJalviewDataFile(files.get(i).toString());
3284 catch (Exception ex)
3286 ex.printStackTrace();
3291 // This method will attempt to load a "dropped" file first by testing
3292 // whether its and Annotation file, then features file. If both are
3293 // false then the user may have dropped an alignment file onto this
3295 public void loadJalviewDataFile(String file)
3298 String protocol = "File";
3300 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3305 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3310 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3313 String format = new IdentifyFile().Identify(file, protocol);
3315 if(format.equalsIgnoreCase("JnetFile"))
3317 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3319 new JnetAnnotationMaker().add_annotation(predictions,
3320 viewport.getAlignment(),
3322 alignPanel.adjustAnnotationHeight();
3323 alignPanel.repaint();
3326 new FileLoader().LoadFile(viewport, file, protocol, format);
3332 alignPanel.adjustAnnotationHeight();
3335 }catch(Exception ex)
3337 ex.printStackTrace();
3341 public void tabSelectionChanged(int index)
3345 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3346 viewport = alignPanel.av;
3347 setMenusFromViewport(viewport);
3351 public void tabbedPane_mousePressed(MouseEvent e)
3353 if(SwingUtilities.isRightMouseButton(e))
3355 String reply = JOptionPane.showInternalInputDialog(this,
3358 JOptionPane.QUESTION_MESSAGE);
3362 viewport.viewName = reply;
3363 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3369 public AlignViewport getCurrentView()