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.util.ShiftList;
38 import java.awt.dnd.*;
39 import org.biojava.dasobert.eventmodel.*;
47 public class AlignFrame
48 extends GAlignFrame implements DropTargetListener, FeatureListener
51 public static final int DEFAULT_WIDTH = 700;
54 public static final int DEFAULT_HEIGHT = 500;
55 public AlignmentPanel alignPanel;
56 AlignViewport viewport;
59 Vector alignPanels = new Vector();
63 public String currentFileFormat = null;
64 Stack historyList = new Stack();
65 Stack redoList = new Stack();
66 private int treeCount = 0;
69 * Creates a new AlignFrame object.
71 * @param al DOCUMENT ME!
73 public AlignFrame(AlignmentI al, int width, int height)
75 this(al, null, width, height);
80 * new alignment window with hidden columns
81 * @param al AlignmentI
82 * @param hiddenColumns ColumnSelection or null
84 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
85 int width, int height)
87 this.setSize(width, height);
88 viewport = new AlignViewport(al, hiddenColumns);
90 alignPanel = new AlignmentPanel(this, viewport);
92 if(al.getDataset()==null)
97 addAlignmentPanel(alignPanel);
102 * Make a new AlignFrame from exisiting alignmentPanels
103 * @param ap AlignmentPanel
104 * @param av AlignViewport
106 public AlignFrame(AlignmentPanel ap)
110 addAlignmentPanel(ap);
116 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
118 if (viewport.hconsensus == null)
120 //Out of memory calculating consensus.
121 BLOSUM62Colour.setEnabled(false);
122 PIDColour.setEnabled(false);
123 conservationMenuItem.setEnabled(false);
124 modifyConservation.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 if (jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false))
144 wrapMenuItem.setSelected(true);
145 wrapMenuItem_actionPerformed(null);
151 void addKeyListener()
153 final AlignFrame af = this;
154 addKeyListener(new KeyAdapter()
156 public void keyPressed(KeyEvent evt)
158 if (viewport.cursorMode
159 && evt.getKeyCode() >= KeyEvent.VK_0
160 && evt.getKeyCode() <= KeyEvent.VK_9)
162 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
165 switch (evt.getKeyCode())
168 if (!evt.isControlDown())
171 if(viewport.hasHiddenRows)
173 al = viewport.alignment.getHiddenSequences().getFullAlignment();
176 al = new Alignment(viewport.alignment.getSequencesArray());
178 AlignViewport newview = new AlignViewport(al);
180 AlignmentPanel copy = new AlignmentPanel(af, newview);
182 if(viewport.viewName==null)
183 viewport.viewName="View 1";
185 copy.av.sequenceSetID = viewport.getSequenceSetId();
186 copy.av.viewName = "View " +
187 (Desktop.getViewCount(viewport.getSequenceSetId())+1);
190 addAlignmentPanel(copy);
191 PaintRefresher.Register(copy, viewport.getSequenceSetId());
192 PaintRefresher.Register(alignPanel,
193 viewport.getSequenceSetId());
198 Desktop.instance.gatherViews(af);
202 if (!evt.isControlDown())
204 Desktop.instance.explodeViews(af);
209 case 27: // escape key
210 deselectAllSequenceMenuItem_actionPerformed(null);
214 case KeyEvent.VK_DOWN:
215 if (viewport.cursorMode)
217 alignPanel.seqPanel.moveCursor(0, 1);
220 moveSelectedSequences(false);
224 if (viewport.cursorMode)
226 alignPanel.seqPanel.moveCursor(0, -1);
229 moveSelectedSequences(true);
232 case KeyEvent.VK_LEFT:
233 if (viewport.cursorMode)
235 alignPanel.seqPanel.moveCursor( -1, 0);
239 case KeyEvent.VK_RIGHT:
240 if (viewport.cursorMode)
242 alignPanel.seqPanel.moveCursor(1, 0);
246 case KeyEvent.VK_SPACE:
247 if (viewport.cursorMode)
249 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
255 case KeyEvent.VK_DELETE:
256 case KeyEvent.VK_BACK_SPACE:
257 if (!viewport.cursorMode)
259 cut_actionPerformed(null);
262 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
269 if (viewport.cursorMode)
271 alignPanel.seqPanel.setCursorRow();
275 if (viewport.cursorMode && !evt.isControlDown())
277 alignPanel.seqPanel.setCursorColumn();
281 if (viewport.cursorMode)
283 alignPanel.seqPanel.setCursorPosition();
287 case KeyEvent.VK_ENTER:
288 case KeyEvent.VK_COMMA:
289 if (viewport.cursorMode)
291 alignPanel.seqPanel.setCursorRowAndColumn();
296 if (viewport.cursorMode)
298 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
302 if (viewport.cursorMode)
304 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
309 viewport.cursorMode = !viewport.cursorMode;
310 statusBar.setText("Keyboard editing mode is " +
311 (viewport.cursorMode ? "on" : "off"));
312 if (viewport.cursorMode)
314 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
315 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
317 alignPanel.seqPanel.seqCanvas.repaint();
323 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
324 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
325 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
327 javax.help.HelpBroker hb = hs.createHelpBroker();
328 hb.setCurrentID("home");
329 hb.setDisplayed(true);
333 ex.printStackTrace();
339 boolean toggleSeqs = !evt.isControlDown();
340 boolean toggleCols = !evt.isShiftDown();
342 boolean hide = false;
344 SequenceGroup sg = viewport.getSelectionGroup();
347 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
349 hideSelSequences_actionPerformed(null);
352 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
353 showAllSeqs_actionPerformed(null);
358 if (viewport.colSel.getSelected().size() > 0)
360 hideSelColumns_actionPerformed(null);
362 viewport.selectionGroup = sg;
365 showAllColumns_actionPerformed(null);
369 case KeyEvent.VK_PAGE_UP:
370 if (viewport.wrapAlignment)
371 alignPanel.scrollUp(true);
373 alignPanel.setScrollValues(viewport.startRes,
375 - viewport.endSeq + viewport.startSeq);
377 case KeyEvent.VK_PAGE_DOWN:
378 if (viewport.wrapAlignment)
379 alignPanel.scrollUp(false);
381 alignPanel.setScrollValues(viewport.startRes,
383 + viewport.endSeq - viewport.startSeq);
393 public void addAlignmentPanel(final AlignmentPanel ap)
395 alignPanels.addElement(ap);
397 int aSize = alignPanels.size();
399 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
401 if (aSize == 1 && ap.av.viewName==null)
403 this.getContentPane().add(ap, BorderLayout.CENTER);
409 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
410 tabbedPane.addTab(first.av.viewName==null?"Original":first.av.viewName,first);
412 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
415 tabbedPane.addTab(ap.av.viewName==null?"Original":ap.av.viewName, ap);
418 ap.av.updateConsensus(ap);
419 ap.av.updateConservation(ap);
422 ap.av.addPropertyChangeListener(new PropertyChangeListener()
424 public void propertyChange(PropertyChangeEvent evt)
426 if (evt.getPropertyName().equals("alignment"))
428 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
439 public AlignViewport getViewport()
444 /* Set up intrinsic listeners for dynamically generated GUI bits. */
445 private void addServiceListeners()
447 final java.beans.PropertyChangeListener thisListener;
448 // Do this once to get current state
449 BuildWebServiceMenu();
450 Desktop.discoverer.addPropertyChangeListener(
451 thisListener = new java.beans.PropertyChangeListener()
453 public void propertyChange(PropertyChangeEvent evt)
455 // System.out.println("Discoverer property change.");
456 if (evt.getPropertyName().equals("services"))
458 // System.out.println("Rebuilding web service menu");
459 BuildWebServiceMenu();
464 addInternalFrameListener(new javax.swing.event.
465 InternalFrameAdapter()
467 public void internalFrameClosed(
468 javax.swing.event.InternalFrameEvent evt)
470 // System.out.println("deregistering discoverer listener");
471 Desktop.discoverer.removePropertyChangeListener(thisListener);
472 closeMenuItem_actionPerformed(null);
478 public void setGUINucleotide(boolean nucleotide)
480 showTranslation.setVisible( nucleotide );
481 //sequenceFeatures.setVisible(!nucleotide );
482 //featureSettings.setVisible( !nucleotide );
483 conservationMenuItem.setVisible( !nucleotide );
484 modifyConservation.setVisible( !nucleotide );
486 //Remember AlignFrame always starts as protein
489 calculateMenu.remove(calculateMenu.getItemCount()-2);
493 public void comeBackLater(FeatureEvent evt)
496 public void newFeatures(FeatureEvent evt)
498 if (evt.getFeatures().length > 0)
500 alignPanel.seqPanel.seqCanvas.fr.featuresAdded();
501 alignPanel.repaint();
505 Hashtable progressBars;
506 public void setProgressBar(String message, long id)
508 if(progressBars == null)
509 progressBars = new Hashtable();
511 JPanel progressPanel;
512 GridLayout layout = (GridLayout) statusPanel.getLayout();
513 if(progressBars.get( new Long(id) )!=null)
515 progressPanel = (JPanel)progressBars.get( new Long(id) );
516 statusPanel.remove(progressPanel);
517 progressBars.remove( progressPanel );
518 progressPanel = null;
520 statusBar.setText(message);
522 layout.setRows(layout.getRows() - 1);
526 progressPanel = new JPanel(new BorderLayout(10, 5));
528 JProgressBar progressBar = new JProgressBar();
529 progressBar.setIndeterminate(true);
531 progressPanel.add(new JLabel(message), BorderLayout.WEST);
532 progressPanel.add(progressBar, BorderLayout.CENTER);
534 layout.setRows(layout.getRows() + 1);
535 statusPanel.add(progressPanel);
537 progressBars.put(new Long(id), progressPanel);
545 Added so Castor Mapping file can obtain Jalview Version
547 public String getVersion()
549 return jalview.bin.Cache.getProperty("VERSION");
552 public FeatureRenderer getFeatureRenderer()
554 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
558 public void fetchSequence_actionPerformed(ActionEvent e)
560 new SequenceFetcher(this);
563 public void addFromFile_actionPerformed(ActionEvent e)
565 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
568 public void addFromText_actionPerformed(ActionEvent e)
570 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
573 public void addFromURL_actionPerformed(ActionEvent e)
575 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
581 * @param e DOCUMENT ME!
583 public void saveAlignmentMenu_actionPerformed(ActionEvent e)
585 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
586 getProperty( "LAST_DIRECTORY"),
588 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
590 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
595 chooser.setFileView(new JalviewFileView());
596 chooser.setDialogTitle("Save Alignment to file");
597 chooser.setToolTipText("Save");
599 int value = chooser.showSaveDialog(this);
601 if (value == JalviewFileChooser.APPROVE_OPTION)
603 currentFileFormat = chooser.getSelectedFormat();
605 if (currentFileFormat == null)
607 JOptionPane.showInternalMessageDialog(Desktop.desktop,
608 "You must select a file format before saving!",
609 "File format not specified",
610 JOptionPane.WARNING_MESSAGE);
611 value = chooser.showSaveDialog(this);
615 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
618 String choice = chooser.getSelectedFile().getPath();
619 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
621 saveAlignment(choice, currentFileFormat);
625 public boolean saveAlignment(String file, String format)
627 if (format.equalsIgnoreCase("Jalview"))
629 String shortName = title;
631 if (shortName.indexOf(java.io.File.separatorChar) > -1)
633 shortName = shortName.substring(shortName.lastIndexOf(
634 java.io.File.separatorChar) + 1);
637 new Jalview2XML().SaveAlignment(this, file, shortName);
639 // USE Jalview2XML to save this file
645 String[] omitHidden = null;
647 if (viewport.hasHiddenColumns)
649 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
650 "The Alignment contains hidden columns."
651 + "\nDo you want to save only the visible alignment?",
652 "Save / Omit Hidden Columns",
653 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
655 if (reply == JOptionPane.YES_OPTION)
656 omitHidden = viewport.getViewAsString(false);
659 String output = new FormatAdapter().formatSequences(
661 viewport.alignment.getSequencesArray(),
671 java.io.PrintWriter out = new java.io.PrintWriter(
672 new java.io.FileWriter(file));
681 ex.printStackTrace();
690 * @param e DOCUMENT ME!
692 protected void outputText_actionPerformed(ActionEvent e)
694 String [] omitHidden = null;
696 if(viewport.hasHiddenColumns)
698 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
699 "The Alignment contains hidden columns."
700 +"\nDo you want to output only the visible alignment?",
701 "Save / Omit Hidden Columns",
702 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
704 if(reply==JOptionPane.YES_OPTION)
706 omitHidden = viewport.getViewAsString(false);
710 CutAndPasteTransfer cap = new CutAndPasteTransfer();
711 Desktop.addInternalFrame(cap,
712 "Alignment output - " + e.getActionCommand(), 600,
716 cap.setText(new FormatAdapter().formatSequences(
717 e.getActionCommand(),
718 viewport.alignment.getSequencesArray(),
725 * @param e DOCUMENT ME!
727 protected void htmlMenuItem_actionPerformed(ActionEvent e)
729 new HTMLOutput(viewport,
730 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
731 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
734 public void createImageMap(File file, String image)
736 alignPanel.makePNGImageMap(file, image);
742 * @param e DOCUMENT ME!
744 public void createPNG(File f)
746 alignPanel.makePNG(f);
752 * @param e DOCUMENT ME!
754 public void createEPS(File f)
756 alignPanel.makeEPS(f);
762 * @param e DOCUMENT ME!
764 public void printMenuItem_actionPerformed(ActionEvent e)
766 //Putting in a thread avoids Swing painting problems
767 PrintThread thread = new PrintThread();
771 public void exportFeatures_actionPerformed(ActionEvent e)
773 new AnnotationExporter().exportFeatures(alignPanel);
777 public void exportAnnotations_actionPerformed(ActionEvent e)
779 new AnnotationExporter().exportAnnotations(
781 viewport.alignment.getAlignmentAnnotation()
786 public void associatedData_actionPerformed(ActionEvent e)
788 // Pick the tree file
789 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
792 chooser.setFileView(new JalviewFileView());
793 chooser.setDialogTitle("Load Jalview Annotations or Features File");
794 chooser.setToolTipText("Load Jalview Annotations / Features file");
796 int value = chooser.showOpenDialog(null);
798 if (value == JalviewFileChooser.APPROVE_OPTION)
800 String choice = chooser.getSelectedFile().getPath();
801 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
802 loadJalviewDataFile(choice);
811 * @param e DOCUMENT ME!
813 public void closeMenuItem_actionPerformed(ActionEvent e)
817 for(int i=0; i<alignPanels.size(); i++)
819 AlignmentPanel ap = (AlignmentPanel)alignPanels.elementAt(i);
820 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
821 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
822 PaintRefresher.RemoveComponent(ap);
825 this.setClosed(true);
836 void updateEditMenuBar()
838 /* if (historyList.size() > 0)
840 undoMenuItem.setEnabled(true);
842 HistoryItem hi = (HistoryItem) historyList.peek();
843 undoMenuItem.setText("Undo " + hi.getDescription());
847 undoMenuItem.setEnabled(false);
848 undoMenuItem.setText("Undo");
851 if (redoList.size() > 0)
853 redoMenuItem.setEnabled(true);
855 HistoryItem hi = (HistoryItem) redoList.peek();
856 redoMenuItem.setText("Redo " + hi.getDescription());
860 redoMenuItem.setEnabled(false);
861 redoMenuItem.setText("Redo");
868 * @param hi DOCUMENT ME!
870 public void addHistoryItem(HistoryItem hi)
872 historyList.push(hi);
880 * @param e DOCUMENT ME!
882 protected void undoMenuItem_actionPerformed(ActionEvent e)
884 HistoryItem nh,hi = (HistoryItem) historyList.pop();
885 redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
887 if (hi.alColumnChanges!=null)
888 nh.alColumnChanges = hi.alColumnChanges.getInverse();
889 restoreHistoryItem(hi);
890 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
896 * @param e DOCUMENT ME!
898 protected void redoMenuItem_actionPerformed(ActionEvent e)
900 HistoryItem nh,hi = (HistoryItem) redoList.pop();
901 historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
903 if (hi.alColumnChanges!=null)
904 nh.alColumnChanges=hi.alColumnChanges.getInverse();
905 restoreHistoryItem(hi);
907 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
910 // used by undo and redo
911 void restoreHistoryItem(HistoryItem hi)
914 hi.restore(viewport.getColumnSelection());
918 viewport.firePropertyChange("alignment", null,
919 viewport.getAlignment().getSequences());
925 * @param up DOCUMENT ME!
927 public void moveSelectedSequences(boolean up)
929 SequenceGroup sg = viewport.getSelectionGroup();
938 for (int i = 1; i < viewport.alignment.getHeight(); i++)
940 SequenceI seq = viewport.alignment.getSequenceAt(i);
942 if (!sg.getSequences(false).contains(seq))
947 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
949 if (sg.getSequences(false).contains(temp))
954 viewport.alignment.getSequences().setElementAt(temp, i);
955 viewport.alignment.getSequences().setElementAt(seq, i - 1);
960 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
962 SequenceI seq = viewport.alignment.getSequenceAt(i);
964 if (!sg.getSequences(false).contains(seq))
969 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
971 if (sg.getSequences(false).contains(temp))
976 viewport.alignment.getSequences().setElementAt(temp, i);
977 viewport.alignment.getSequences().setElementAt(seq, i + 1);
981 alignPanel.repaint();
989 * @param e DOCUMENT ME!
991 protected void copy_actionPerformed(ActionEvent e)
994 if (viewport.getSelectionGroup() == null)
999 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1000 String[] omitHidden = null;
1002 if (viewport.hasHiddenColumns)
1004 omitHidden = viewport.getViewAsString(true);
1007 String output = new FormatAdapter().formatSequences(
1012 StringSelection ss = new StringSelection(output);
1016 //Its really worth setting the clipboard contents
1017 //to empty before setting the large StringSelection!!
1018 Toolkit.getDefaultToolkit().getSystemClipboard()
1019 .setContents(new StringSelection(""), null);
1021 Toolkit.getDefaultToolkit().getSystemClipboard()
1022 .setContents(ss, Desktop.instance);
1024 catch (OutOfMemoryError er)
1026 er.printStackTrace();
1027 javax.swing.SwingUtilities.invokeLater(new Runnable()
1031 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1032 "Out of memory copying region!!"
1034 "\nSee help files for increasing Java Virtual Machine memory."
1036 javax.swing.JOptionPane.WARNING_MESSAGE);
1043 Vector hiddenColumns = null;
1044 if(viewport.hasHiddenColumns)
1046 hiddenColumns =new Vector();
1047 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1048 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1050 int[] region = (int[])
1051 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1053 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1054 region[1]-hiddenOffset});
1060 Desktop.jalviewClipboard = new Object[]{ seqs,
1061 viewport.alignment.getDataset(),
1063 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1069 * @param e DOCUMENT ME!
1071 protected void pasteNew_actionPerformed(ActionEvent e)
1079 * @param e DOCUMENT ME!
1081 protected void pasteThis_actionPerformed(ActionEvent e)
1083 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,
1084 HistoryItem.PASTE));
1091 * @param newAlignment DOCUMENT ME!
1093 void paste(boolean newAlignment)
1097 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1098 Transferable contents = c.getContents(this);
1100 if (contents == null)
1108 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1109 if (str.length() < 1)
1112 format = new IdentifyFile().Identify(str, "Paste");
1115 catch (OutOfMemoryError er)
1117 er.printStackTrace();
1118 javax.swing.SwingUtilities.invokeLater(new Runnable()
1122 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1123 "Out of memory pasting sequences!!"
1125 "\nSee help files for increasing Java Virtual Machine memory."
1127 javax.swing.JOptionPane.WARNING_MESSAGE);
1134 SequenceI[] sequences;
1137 if(Desktop.jalviewClipboard!=null)
1139 // The clipboard was filled from within Jalview, we must use the sequences
1140 // And dataset from the copied alignment
1141 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1145 sequences = new FormatAdapter().readFile(str, "Paste", format);
1148 AlignmentI alignment = null;
1152 alignment = new Alignment(sequences);
1154 if (Desktop.jalviewClipboard != null)
1155 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1157 alignment.setDataset(null);
1161 alignment = viewport.getAlignment();
1164 for (int i = 0; i < sequences.length; i++)
1166 Sequence newseq = new Sequence(sequences[i].getName(),
1167 sequences[i].getSequence(), sequences[i].getStart(),
1168 sequences[i].getEnd());
1170 alignment.addSequence(newseq);
1171 PaintRefresher.Refresh(alignPanel,
1172 alignPanel.av.getSequenceSetId(),
1177 viewport.setEndSeq(alignment.getHeight());
1178 alignment.getWidth();
1179 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1184 // Add any annotations attached to sequences
1185 for (int i = 0; i < sequences.length; i++)
1187 if (sequences[i].getAnnotation() != null)
1189 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1191 AlignmentAnnotation newAnnot =
1192 new AlignmentAnnotation(
1193 sequences[i].getAnnotation()[a].label,
1194 sequences[i].getAnnotation()[a].description,
1195 sequences[i].getAnnotation()[a].annotations,
1196 sequences[i].getAnnotation()[a].graphMin,
1197 sequences[i].getAnnotation()[a].graphMax,
1198 sequences[i].getAnnotation()[a].graph);
1200 sequences[i].getAnnotation()[a] = newAnnot;
1201 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1203 newAnnot.sequenceRef = sequences[i];
1204 newAnnot.adjustForAlignment();
1205 alignment.addAnnotation(newAnnot);
1206 alignment.setAnnotationIndex(newAnnot, a);
1209 alignPanel.annotationPanel.adjustPanelHeight();
1215 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1216 String newtitle = new String("Copied sequences");
1218 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1220 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1221 for(int i=0; i<hc.size(); i++)
1223 int [] region = (int[]) hc.elementAt(i);
1224 af.viewport.hideColumns(region[0], region[1]);
1229 //>>>This is a fix for the moment, until a better solution is found!!<<<
1230 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1231 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1234 if (title.startsWith("Copied sequences"))
1240 newtitle = newtitle.concat("- from " + title);
1243 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1250 catch (Exception ex)
1252 ex.printStackTrace();
1253 System.out.println("Exception whilst pasting: "+ex);
1254 // could be anything being pasted in here
1263 * @param e DOCUMENT ME!
1265 protected void cut_actionPerformed(ActionEvent e)
1267 copy_actionPerformed(null);
1268 delete_actionPerformed(null);
1274 * @param e DOCUMENT ME!
1276 protected void delete_actionPerformed(ActionEvent e)
1279 if (viewport.getSelectionGroup() == null)
1285 SequenceGroup sg = viewport.getSelectionGroup();
1288 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
1292 for (int i = 0; i < sg.getSize(false); i++)
1294 SequenceI seq = sg.getSequenceAt(i);
1295 seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);
1297 // If the cut affects all sequences, remove highlighted columns
1298 if (sg.getSize(false) == viewport.alignment.getHeight())
1300 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1301 sg.getEndRes() + 1);
1304 if (seq.getSequence().length() < 1)
1306 viewport.getAlignment().deleteSequence(seq);
1307 PaintRefresher.Refresh(alignPanel,alignPanel.av.getSequenceSetId(),seq,null);
1311 viewport.setSelectionGroup(null);
1312 viewport.alignment.deleteGroup(sg);
1314 viewport.firePropertyChange("alignment", null,
1315 viewport.getAlignment().getSequences());
1319 if (viewport.getAlignment().getHeight() < 1)
1323 this.setClosed(true);
1325 catch (Exception ex)
1334 * @param e DOCUMENT ME!
1336 protected void deleteGroups_actionPerformed(ActionEvent e)
1338 viewport.alignment.deleteAllGroups();
1339 viewport.setSelectionGroup(null);
1340 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1341 alignPanel.repaint();
1347 * @param e DOCUMENT ME!
1349 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1351 SequenceGroup sg = new SequenceGroup();
1353 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1356 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1359 sg.setEndRes(viewport.alignment.getWidth() - 1);
1360 viewport.setSelectionGroup(sg);
1361 alignPanel.repaint();
1362 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1368 * @param e DOCUMENT ME!
1370 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1372 if(viewport.cursorMode)
1374 alignPanel.seqPanel.keyboardNo1 = null;
1375 alignPanel.seqPanel.keyboardNo2 = null;
1377 viewport.setSelectionGroup(null);
1378 viewport.getColumnSelection().clear();
1379 viewport.setSelectionGroup(null);
1380 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1381 alignPanel.idPanel.idCanvas.searchResults = null;
1382 alignPanel.repaint();
1383 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1389 * @param e DOCUMENT ME!
1391 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1393 SequenceGroup sg = viewport.getSelectionGroup();
1397 selectAllSequenceMenuItem_actionPerformed(null);
1402 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1405 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1408 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1411 public void invertColSel_actionPerformed(ActionEvent e)
1413 viewport.invertColumnSelection();
1414 alignPanel.repaint();
1421 * @param e DOCUMENT ME!
1423 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1425 ColumnSelection colSel = viewport.getColumnSelection();
1427 if (colSel.size() > 0)
1430 addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment,
1433 int min = colSel.getMin();
1434 viewport.getAlignment().trimLeft(min);
1435 colSel.compensateForEdit(0, min);
1436 edit.addShift(0,min);
1437 if (viewport.getSelectionGroup() != null)
1439 viewport.getSelectionGroup().adjustForRemoveLeft(min);
1442 Vector groups = viewport.alignment.getGroups();
1444 for (int i = 0; i < groups.size(); i++)
1446 SequenceGroup sg = (SequenceGroup) groups.get(i);
1448 if (!sg.adjustForRemoveLeft(min))
1450 viewport.alignment.deleteGroup(sg);
1454 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1461 * @param e DOCUMENT ME!
1463 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1465 ColumnSelection colSel = viewport.getColumnSelection();
1467 if (colSel.size() > 0)
1469 addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
1472 int max = colSel.getMax();
1473 viewport.getAlignment().trimRight(max);
1474 // TODO: delete hidden column entries in colSel to right of max
1475 // TODO: record hidden columns in history for undo.
1476 if (viewport.getSelectionGroup() != null)
1478 viewport.getSelectionGroup().adjustForRemoveRight(max);
1481 Vector groups = viewport.alignment.getGroups();
1483 for (int i = 0; i < groups.size(); i++)
1485 SequenceGroup sg = (SequenceGroup) groups.get(i);
1487 if (!sg.adjustForRemoveRight(max))
1489 viewport.alignment.deleteGroup(sg);
1493 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1500 * @param e DOCUMENT ME!
1502 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1505 addHistoryItem(edit=new HistoryItem("Remove Gapped Columns",
1506 viewport.alignment, HistoryItem.HIDE));
1508 //This is to maintain viewport position on first residue
1510 SequenceI seq = viewport.alignment.getSequenceAt(0);
1511 int startRes = seq.findPosition(viewport.startRes);
1513 viewport.getAlignment().removeGaps(shifts=new ShiftList());
1514 edit.alColumnChanges=shifts.getInverse();
1515 if (viewport.hasHiddenColumns)
1516 viewport.getColumnSelection().compensateForEdits(shifts);
1517 viewport.setStartRes(seq.findIndex(startRes)-1);
1518 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1525 * @param e DOCUMENT ME!
1527 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1529 // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences
1530 // TODO: columnSelection.compensateforedits should be called (and passed to history item)
1531 addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
1534 //This is to maintain viewport position on first residue
1536 SequenceI seq = viewport.alignment.getSequenceAt(0);
1537 int startRes = seq.findPosition(viewport.startRes);
1545 int end = viewport.alignment.getWidth();
1547 if (viewport.getSelectionGroup() != null
1548 && viewport.getSelectionGroup().getSequences(true) != null
1549 && viewport.getSelectionGroup().getSize(true) > 0)
1551 seqs = viewport.getSelectionGroup().getSequences(true);
1552 start = viewport.getSelectionGroup().getStartRes();
1553 end = viewport.getSelectionGroup().getEndRes()+1;
1557 seqs = viewport.alignment.getSequences();
1559 /* Commented out regions below are partial implementation of todo above.
1560 * divide start,end into visible chunks, and for each:
1561 int diff=end-start+1;
1563 int dr[] = new int[seqs.size()];
1565 for (int i = 0; i < seqs.size(); i++)
1567 current = (SequenceI) seqs.elementAt(i);
1569 current.removeGaps(start, end);
1570 /*if (d<diff) // can only shift
1576 /* // after the end of each chunk -
1578 // record shift for history.
1579 editgaps.addShift(start, diff);
1580 if (viewport.hasHiddenColumns && diffmax>diff) {
1582 StringBuffer gaps=new StringBuffer(diffmax);
1583 for (int i=0,j=diffmax-diff; i<j; i++)
1584 gaps.append(viewport.getGapCharacter());
1585 for (int i=0, j=seqs.size(); i<j; i++) {
1586 current = (SequenceI) seqs.elementAt(i);
1588 String sq = current.getSequence();
1589 current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring());
1595 viewport.setStartRes(seq.findIndex(startRes)-1);
1597 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1601 public void alignmentChanged()
1606 for(int i=0; i<alignPanels.size(); i++)
1608 ap = (AlignmentPanel) alignPanels.elementAt(i);
1612 av.getAlignment().padGaps();
1614 if (av.hconsensus != null && av.autoCalculateConsensus)
1616 av.updateConsensus(ap);
1617 av.updateConservation(ap);
1618 ap.annotationPanel.repaint();
1621 resetAllColourSchemes();
1623 av.alignment.adjustSequenceAnnotations();
1625 if (ap.overviewPanel != null)
1626 ap.overviewPanel.updateOverviewImage();
1632 void resetAllColourSchemes()
1634 ColourSchemeI cs = viewport.globalColourScheme;
1637 if (cs instanceof ClustalxColourScheme)
1639 ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
1640 resetClustalX(viewport.alignment.getSequences(),
1641 viewport.alignment.getWidth());
1644 cs.setConsensus(viewport.hconsensus);
1645 if (cs.conservationApplied())
1647 Alignment al = (Alignment) viewport.alignment;
1648 Conservation c = new Conservation("All",
1649 ResidueProperties.propHash, 3,
1650 al.getSequences(), 0,
1653 c.verdict(false, viewport.ConsPercGaps);
1655 cs.setConservation(c);
1659 int s, sSize = viewport.alignment.getGroups().size();
1660 for(s=0; s<sSize; s++)
1662 SequenceGroup sg = (SequenceGroup)viewport.alignment.getGroups().elementAt(s);
1663 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1665 ((ClustalxColourScheme)sg.cs).resetClustalX(
1666 sg.getSequences(true), sg.getWidth());
1668 sg.recalcConservation();
1675 * @param e DOCUMENT ME!
1677 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1679 addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,
1682 viewport.padGaps = padGapsMenuitem.isSelected();
1684 viewport.firePropertyChange("alignment",
1686 viewport.getAlignment().getSequences());
1692 * @param e DOCUMENT ME!
1694 public void findMenuItem_actionPerformed(ActionEvent e)
1696 JInternalFrame frame = new JInternalFrame();
1697 Finder finder = new Finder(viewport, alignPanel, frame);
1698 frame.setContentPane(finder);
1699 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1700 Desktop.addInternalFrame(frame, "Find", 340, 110);
1706 * @param e DOCUMENT ME!
1708 public void font_actionPerformed(ActionEvent e)
1710 new FontChooser(alignPanel);
1713 public void smoothFont_actionPerformed(ActionEvent e)
1715 viewport.antiAlias = smoothFont.isSelected();
1716 alignPanel.annotationPanel.image = null;
1717 alignPanel.repaint();
1724 * @param e DOCUMENT ME!
1726 protected void seqLimit_actionPerformed(ActionEvent e)
1728 viewport.setShowJVSuffix(seqLimits.isSelected());
1730 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1731 alignPanel.repaint();
1738 * @param e DOCUMENT ME!
1740 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1742 viewport.setColourText(colourTextMenuItem.isSelected());
1743 alignPanel.repaint();
1749 * @param e DOCUMENT ME!
1751 public void wrapMenuItem_actionPerformed(ActionEvent e)
1753 scaleAbove.setVisible(wrapMenuItem.isSelected());
1754 scaleLeft.setVisible(wrapMenuItem.isSelected());
1755 scaleRight.setVisible(wrapMenuItem.isSelected());
1756 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1757 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1760 public void showAllSeqs_actionPerformed(ActionEvent e)
1762 viewport.showAllHiddenSeqs();
1765 public void showAllColumns_actionPerformed(ActionEvent e)
1767 viewport.showAllHiddenColumns();
1771 public void hideSelSequences_actionPerformed(ActionEvent e)
1773 viewport.hideAllSelectedSeqs();
1774 alignPanel.repaint();
1777 public void hideSelColumns_actionPerformed(ActionEvent e)
1779 viewport.hideSelectedColumns();
1780 alignPanel.repaint();
1783 public void hiddenMarkers_actionPerformed(ActionEvent e)
1785 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1792 * @param e DOCUMENT ME!
1794 protected void scaleAbove_actionPerformed(ActionEvent e)
1796 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1797 alignPanel.repaint();
1803 * @param e DOCUMENT ME!
1805 protected void scaleLeft_actionPerformed(ActionEvent e)
1807 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1808 alignPanel.repaint();
1814 * @param e DOCUMENT ME!
1816 protected void scaleRight_actionPerformed(ActionEvent e)
1818 viewport.setScaleRightWrapped(scaleRight.isSelected());
1819 alignPanel.repaint();
1825 * @param e DOCUMENT ME!
1827 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1829 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1830 alignPanel.repaint();
1836 * @param e DOCUMENT ME!
1838 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1840 viewport.setShowText(viewTextMenuItem.isSelected());
1841 alignPanel.repaint();
1847 * @param e DOCUMENT ME!
1849 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1851 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1852 alignPanel.repaint();
1856 public FeatureSettings featureSettings;
1857 public void featureSettings_actionPerformed(ActionEvent e)
1859 if(featureSettings !=null )
1861 featureSettings.close();
1862 featureSettings = null;
1864 featureSettings = new FeatureSettings(this);
1870 * @param evt DOCUMENT ME!
1872 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1874 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1875 alignPanel.repaint();
1876 if (alignPanel.getOverviewPanel() != null)
1878 alignPanel.getOverviewPanel().updateOverviewImage();
1885 * @param e DOCUMENT ME!
1887 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1889 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1890 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1896 * @param e DOCUMENT ME!
1898 public void overviewMenuItem_actionPerformed(ActionEvent e)
1900 if (alignPanel.overviewPanel != null)
1905 JInternalFrame frame = new JInternalFrame();
1906 OverviewPanel overview = new OverviewPanel(alignPanel);
1907 frame.setContentPane(overview);
1908 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1909 frame.getWidth(), frame.getHeight());
1911 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1912 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1914 public void internalFrameClosed(
1915 javax.swing.event.InternalFrameEvent evt)
1917 alignPanel.setOverviewPanel(null);
1922 alignPanel.setOverviewPanel(overview);
1928 * @param e DOCUMENT ME!
1930 protected void noColourmenuItem_actionPerformed(ActionEvent e)
1938 * @param e DOCUMENT ME!
1940 public void clustalColour_actionPerformed(ActionEvent e)
1942 changeColour(new ClustalxColourScheme(
1943 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
1949 * @param e DOCUMENT ME!
1951 public void zappoColour_actionPerformed(ActionEvent e)
1953 changeColour(new ZappoColourScheme());
1959 * @param e DOCUMENT ME!
1961 public void taylorColour_actionPerformed(ActionEvent e)
1963 changeColour(new TaylorColourScheme());
1969 * @param e DOCUMENT ME!
1971 public void hydrophobicityColour_actionPerformed(ActionEvent e)
1973 changeColour(new HydrophobicColourScheme());
1979 * @param e DOCUMENT ME!
1981 public void helixColour_actionPerformed(ActionEvent e)
1983 changeColour(new HelixColourScheme());
1989 * @param e DOCUMENT ME!
1991 public void strandColour_actionPerformed(ActionEvent e)
1993 changeColour(new StrandColourScheme());
1999 * @param e DOCUMENT ME!
2001 public void turnColour_actionPerformed(ActionEvent e)
2003 changeColour(new TurnColourScheme());
2009 * @param e DOCUMENT ME!
2011 public void buriedColour_actionPerformed(ActionEvent e)
2013 changeColour(new BuriedColourScheme());
2019 * @param e DOCUMENT ME!
2021 public void nucleotideColour_actionPerformed(ActionEvent e)
2023 changeColour(new NucleotideColourScheme());
2026 public void annotationColour_actionPerformed(ActionEvent e)
2028 new AnnotationColourChooser(viewport, alignPanel);
2035 * @param e DOCUMENT ME!
2037 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2039 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2045 * @param cs DOCUMENT ME!
2047 public void changeColour(ColourSchemeI cs)
2053 if (viewport.getAbovePIDThreshold())
2055 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2058 cs.setThreshold(threshold,
2059 viewport.getIgnoreGapsConsensus());
2061 viewport.setGlobalColourScheme(cs);
2065 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2068 if (viewport.getConservationSelected())
2071 Alignment al = (Alignment) viewport.alignment;
2072 Conservation c = new Conservation("All",
2073 ResidueProperties.propHash, 3,
2074 al.getSequences(), 0,
2078 c.verdict(false, viewport.ConsPercGaps);
2080 cs.setConservation(c);
2082 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2087 cs.setConservation(null);
2090 cs.setConsensus(viewport.hconsensus);
2093 viewport.setGlobalColourScheme(cs);
2095 if (viewport.getColourAppliesToAllGroups())
2097 Vector groups = viewport.alignment.getGroups();
2099 for (int i = 0; i < groups.size(); i++)
2101 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2109 if (cs instanceof ClustalxColourScheme)
2111 sg.cs = new ClustalxColourScheme(
2112 sg.getSequences(true), sg.getWidth());
2114 else if (cs instanceof UserColourScheme)
2116 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2122 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2124 catch (Exception ex)
2129 if (viewport.getAbovePIDThreshold()
2130 || cs instanceof PIDColourScheme
2131 || cs instanceof Blosum62ColourScheme)
2133 sg.cs.setThreshold(threshold,
2134 viewport.getIgnoreGapsConsensus());
2136 sg.cs.setConsensus(AAFrequency.calculate(
2137 sg.getSequences(true), 0,
2141 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2144 if (viewport.getConservationSelected())
2146 Conservation c = new Conservation("Group",
2147 ResidueProperties.propHash, 3,
2148 sg.getSequences(true), 0,
2149 viewport.alignment.getWidth() - 1);
2151 c.verdict(false, viewport.ConsPercGaps);
2152 sg.cs.setConservation(c);
2155 sg.cs.setConservation(null);
2159 if (alignPanel.getOverviewPanel() != null)
2161 alignPanel.getOverviewPanel().updateOverviewImage();
2164 alignPanel.repaint();
2170 * @param e DOCUMENT ME!
2172 protected void modifyPID_actionPerformed(ActionEvent e)
2174 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2176 SliderPanel.setPIDSliderSource(alignPanel,
2177 viewport.getGlobalColourScheme(),
2179 SliderPanel.showPIDSlider();
2186 * @param e DOCUMENT ME!
2188 protected void modifyConservation_actionPerformed(ActionEvent e)
2190 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2192 SliderPanel.setConservationSlider(alignPanel,
2193 viewport.globalColourScheme,
2195 SliderPanel.showConservationSlider();
2202 * @param e DOCUMENT ME!
2204 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2206 viewport.setConservationSelected(conservationMenuItem.isSelected());
2208 viewport.setAbovePIDThreshold(false);
2209 abovePIDThreshold.setSelected(false);
2211 changeColour(viewport.getGlobalColourScheme());
2213 modifyConservation_actionPerformed(null);
2219 * @param e DOCUMENT ME!
2221 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2223 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2225 conservationMenuItem.setSelected(false);
2226 viewport.setConservationSelected(false);
2228 changeColour(viewport.getGlobalColourScheme());
2230 modifyPID_actionPerformed(null);
2236 * @param e DOCUMENT ME!
2238 public void userDefinedColour_actionPerformed(ActionEvent e)
2240 if (e.getActionCommand().equals("User Defined..."))
2242 new UserDefinedColours(alignPanel, null);
2246 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2247 getUserColourSchemes().get(e.getActionCommand());
2253 public void updateUserColourMenu()
2256 Component[] menuItems = colourMenu.getMenuComponents();
2257 int i, iSize = menuItems.length;
2258 for (i = 0; i < iSize; i++)
2260 if (menuItems[i].getName() != null &&
2261 menuItems[i].getName().equals("USER_DEFINED"))
2263 colourMenu.remove(menuItems[i]);
2267 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2269 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2270 getUserColourSchemes().keys();
2272 while (userColours.hasMoreElements())
2274 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2275 nextElement().toString());
2276 radioItem.setName("USER_DEFINED");
2277 radioItem.addMouseListener(new MouseAdapter()
2279 public void mousePressed(MouseEvent evt)
2281 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2283 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2285 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2286 "Remove from default list?",
2287 "Remove user defined colour",
2288 JOptionPane.YES_NO_OPTION);
2289 if(option == JOptionPane.YES_OPTION)
2291 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2292 colourMenu.remove(radioItem);
2295 radioItem.addActionListener(new ActionListener()
2297 public void actionPerformed(ActionEvent evt)
2299 userDefinedColour_actionPerformed(evt);
2305 radioItem.addActionListener(new ActionListener()
2307 public void actionPerformed(ActionEvent evt)
2309 userDefinedColour_actionPerformed(evt);
2313 colourMenu.insert(radioItem, 15);
2314 colours.add(radioItem);
2322 * @param e DOCUMENT ME!
2324 public void PIDColour_actionPerformed(ActionEvent e)
2326 changeColour(new PIDColourScheme());
2332 * @param e DOCUMENT ME!
2334 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2336 changeColour(new Blosum62ColourScheme());
2342 * @param e DOCUMENT ME!
2344 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2346 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,
2348 AlignmentSorter.sortByPID(viewport.getAlignment(),
2349 viewport.getAlignment().getSequenceAt(0));
2350 alignPanel.repaint();
2356 * @param e DOCUMENT ME!
2358 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2360 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,
2362 AlignmentSorter.sortByID(viewport.getAlignment());
2363 alignPanel.repaint();
2369 * @param e DOCUMENT ME!
2371 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2373 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,
2376 AlignmentSorter.sortByGroup(viewport.getAlignment());
2377 alignPanel.repaint();
2383 * @param e DOCUMENT ME!
2385 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2387 new RedundancyPanel(alignPanel, this);
2394 * @param e DOCUMENT ME!
2396 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2398 if ( (viewport.getSelectionGroup() == null) ||
2399 (viewport.getSelectionGroup().getSize(false) < 2))
2401 JOptionPane.showInternalMessageDialog(this,
2402 "You must select at least 2 sequences.",
2403 "Invalid Selection",
2404 JOptionPane.WARNING_MESSAGE);
2408 JInternalFrame frame = new JInternalFrame();
2409 frame.setContentPane(new PairwiseAlignPanel(viewport));
2410 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2417 * @param e DOCUMENT ME!
2419 public void PCAMenuItem_actionPerformed(ActionEvent e)
2421 if ( ( (viewport.getSelectionGroup() != null) &&
2422 (viewport.getSelectionGroup().getSize(false) < 4) &&
2423 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2424 (viewport.getAlignment().getHeight() < 4))
2426 JOptionPane.showInternalMessageDialog(this,
2427 "Principal component analysis must take\n" +
2428 "at least 4 input sequences.",
2429 "Sequence selection insufficient",
2430 JOptionPane.WARNING_MESSAGE);
2435 new PCAPanel(viewport);
2439 public void autoCalculate_actionPerformed(ActionEvent e)
2441 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2442 if(viewport.autoCalculateConsensus)
2444 viewport.firePropertyChange("alignment",
2446 viewport.getAlignment().getSequences());
2454 * @param e DOCUMENT ME!
2456 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2458 NewTreePanel("AV", "PID", "Average distance tree using PID");
2464 * @param e DOCUMENT ME!
2466 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2468 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2474 * @param e DOCUMENT ME!
2476 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2478 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2484 * @param e DOCUMENT ME!
2486 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2488 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2494 * @param type DOCUMENT ME!
2495 * @param pwType DOCUMENT ME!
2496 * @param title DOCUMENT ME!
2498 void NewTreePanel(String type, String pwType, String title)
2502 if (viewport.getSelectionGroup() != null) {
2503 if (viewport.getSelectionGroup().getSize(false) < 3) {
2504 JOptionPane.showMessageDialog(Desktop.desktop,
2505 "You need to have more than two sequences selected to build a tree!",
2506 "Not enough sequences",
2507 JOptionPane.WARNING_MESSAGE);
2512 SequenceGroup sg = viewport.getSelectionGroup();
2514 /* Decide if the selection is a column region */
2515 while (s < sg.getSize(false))
2517 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2520 JOptionPane.showMessageDialog(Desktop.desktop,
2521 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2522 "Try using the Pad function in the edit menu,\n" +
2523 "or one of the multiple sequence alignment web services.",
2524 "Sequences in selection are not aligned",
2525 JOptionPane.WARNING_MESSAGE);
2531 title = title + " on region";
2532 tp = new TreePanel(alignPanel, type, pwType);
2536 //are the sequences aligned?
2537 if (!viewport.alignment.isAligned())
2539 JOptionPane.showMessageDialog(Desktop.desktop,
2540 "The sequences must be aligned before creating a tree.\n" +
2541 "Try using the Pad function in the edit menu,\n" +
2542 "or one of the multiple sequence alignment web services.",
2543 "Sequences not aligned",
2544 JOptionPane.WARNING_MESSAGE);
2549 if(viewport.alignment.getHeight()<2)
2552 tp = new TreePanel(alignPanel, type, pwType);
2555 addTreeMenuItem(tp, title);
2557 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2563 * @param title DOCUMENT ME!
2564 * @param order DOCUMENT ME!
2566 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2568 final JMenuItem item = new JMenuItem("by " + title);
2570 item.addActionListener(new java.awt.event.ActionListener()
2572 public void actionPerformed(ActionEvent e)
2574 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2577 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2578 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2579 alignPanel.repaint();
2585 * Maintain the Order by->Displayed Tree menu.
2586 * Creates a new menu item for a TreePanel with an appropriate
2587 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2588 * to remove the menu item when the treePanel is closed, and adjust
2589 * the tree leaf to sequence mapping when the alignment is modified.
2590 * @param treePanel Displayed tree window.
2591 * @param title SortBy menu item title.
2593 void addTreeMenuItem(final TreePanel treePanel, String title)
2595 final JMenuItem item = new JMenuItem(title);
2601 sort.add(sortByTreeMenu);
2604 sortByTreeMenu.add(item);
2605 item.addActionListener(new java.awt.event.ActionListener()
2607 public void actionPerformed(ActionEvent e)
2609 addHistoryItem(new HistoryItem("Tree Sort",
2610 viewport.alignment, HistoryItem.SORT));
2611 AlignmentSorter.sortByTree(viewport.getAlignment(),
2612 treePanel.getTree());
2613 alignPanel.repaint();
2617 treePanel.addInternalFrameListener(new javax.swing.event.
2618 InternalFrameAdapter()
2620 public void internalFrameClosed(
2621 javax.swing.event.InternalFrameEvent evt)
2624 sortByTreeMenu.remove(item);
2628 sort.remove(sortByTreeMenu);
2636 * Work out whether the whole set of sequences
2637 * or just the selected set will be submitted for multiple alignment.
2640 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2642 // Now, check we have enough sequences
2643 AlignmentView msa = null;
2645 if ( (viewport.getSelectionGroup() != null) &&
2646 (viewport.getSelectionGroup().getSize(false) > 1))
2648 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2649 /*SequenceGroup seqs = viewport.getSelectionGroup();
2651 msa = new SequenceI[sz = seqs.getSize(false)];
2653 for (int i = 0; i < sz; i++)
2655 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2657 msa = viewport.getAlignmentView(true);
2661 /*Vector seqs = viewport.getAlignment().getSequences();
2663 if (seqs.size() > 1)
2665 msa = new SequenceI[seqs.size()];
2667 for (int i = 0; i < seqs.size(); i++)
2669 msa[i] = (SequenceI) seqs.elementAt(i);
2672 msa = viewport.getAlignmentView(false);
2678 * Decides what is submitted to a secondary structure prediction service,
2679 * the currently selected sequence, or the currently selected alignment
2680 * (where the first sequence in the set is the one that the prediction
2683 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2685 AlignmentView seqs = null;
2687 if ( (viewport.getSelectionGroup() != null) &&
2688 (viewport.getSelectionGroup().getSize(false) > 0))
2690 seqs = viewport.getAlignmentView(true);
2694 seqs = viewport.getAlignmentView(false);
2696 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2697 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2698 if (!viewport.alignment.isAligned())
2700 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2707 * @param e DOCUMENT ME!
2709 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2711 // Pick the tree file
2712 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2715 chooser.setFileView(new JalviewFileView());
2716 chooser.setDialogTitle("Select a newick-like tree file");
2717 chooser.setToolTipText("Load a tree file");
2719 int value = chooser.showOpenDialog(null);
2721 if (value == JalviewFileChooser.APPROVE_OPTION)
2723 String choice = chooser.getSelectedFile().getPath();
2724 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2728 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2730 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2732 catch (Exception ex)
2734 JOptionPane.showMessageDialog(Desktop.desktop,
2735 "Problem reading tree file",
2737 JOptionPane.WARNING_MESSAGE);
2738 ex.printStackTrace();
2744 public TreePanel ShowNewickTree(NewickFile nf, String title)
2746 return ShowNewickTree(nf,title,600,500,4,5);
2748 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2750 return ShowNewickTree(nf,title, input, 600,500,4,5);
2752 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2753 return ShowNewickTree(nf, title, null, w, h, x, y);
2756 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2758 * @param nf the tree
2759 * @param title tree viewer title
2760 * @param input Associated alignment input data (or null)
2765 * @return TreePanel handle
2767 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2768 TreePanel tp = null;
2774 if (nf.getTree() != null)
2776 tp = new TreePanel(alignPanel,
2784 tp.setLocation(x,y);
2787 Desktop.addInternalFrame(tp, title, w, h);
2788 addTreeMenuItem(tp, title);
2791 catch (Exception ex)
2793 ex.printStackTrace();
2804 PrinterJob printJob = PrinterJob.getPrinterJob();
2805 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2806 printJob.setPrintable(alignPanel, pf);
2808 if (printJob.printDialog())
2814 catch (Exception PrintException)
2816 PrintException.printStackTrace();
2823 * Generates menu items and listener event actions for web service clients
2826 public void BuildWebServiceMenu()
2828 if ( (Discoverer.services != null)
2829 && (Discoverer.services.size() > 0))
2831 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2832 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2833 Vector wsmenu = new Vector();
2834 final AlignFrame af = this;
2837 // Add any Multiple Sequence Alignment Services
2838 final JMenu msawsmenu = new JMenu("Alignment");
2839 for (int i = 0, j = msaws.size(); i < j; i++)
2841 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2843 final JMenuItem method = new JMenuItem(sh.getName());
2844 method.addActionListener(new ActionListener()
2846 public void actionPerformed(ActionEvent e)
2848 AlignmentView msa = gatherSequencesForAlignment();
2849 new jalview.ws.MsaWSClient(sh, title, msa,
2850 false, true, viewport.getAlignment().getDataset(), af);
2855 msawsmenu.add(method);
2856 // Deal with services that we know accept partial alignments.
2857 if (sh.getName().indexOf("lustal") > -1)
2859 // We know that ClustalWS can accept partial alignments for refinement.
2860 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2861 methodR.addActionListener(new ActionListener()
2863 public void actionPerformed(ActionEvent e)
2865 AlignmentView msa = gatherSequencesForAlignment();
2866 new jalview.ws.MsaWSClient(sh, title, msa,
2867 true, true, viewport.getAlignment().getDataset(), af);
2872 msawsmenu.add(methodR);
2876 wsmenu.add(msawsmenu);
2878 if (secstrpr != null)
2880 // Add any secondary structure prediction services
2881 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2882 for (int i = 0, j = secstrpr.size(); i < j; i++)
2884 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2886 final JMenuItem method = new JMenuItem(sh.getName());
2887 method.addActionListener(new ActionListener()
2889 public void actionPerformed(ActionEvent e)
2891 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2892 if (msa.getSequences().length == 1)
2894 // Single Sequence prediction
2895 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
2899 if (msa.getSequences().length > 1)
2901 // Sequence profile based prediction
2902 new jalview.ws.JPredClient(sh,
2903 title, true, msa, af, true);
2908 secstrmenu.add(method);
2910 wsmenu.add(secstrmenu);
2912 this.webService.removeAll();
2913 for (int i = 0, j = wsmenu.size(); i < j; i++)
2915 webService.add( (JMenu) wsmenu.get(i));
2920 this.webService.removeAll();
2921 this.webService.add(this.webServiceNoServices);
2923 // TODO: add in rediscovery function
2924 // TODO: reduce code redundancy.
2925 // TODO: group services by location as well as function.
2928 /* public void vamsasStore_actionPerformed(ActionEvent e)
2930 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2931 getProperty("LAST_DIRECTORY"));
2933 chooser.setFileView(new JalviewFileView());
2934 chooser.setDialogTitle("Export to Vamsas file");
2935 chooser.setToolTipText("Export");
2937 int value = chooser.showSaveDialog(this);
2939 if (value == JalviewFileChooser.APPROVE_OPTION)
2941 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
2942 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
2943 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
2950 public void showTranslation_actionPerformed(ActionEvent e)
2952 SequenceI [] selection = viewport.getSelectionAsNewSequence();
2953 String [] seqstring = viewport.getViewAsString(true);
2955 int s, sSize = selection.length;
2956 SequenceI [] newSeq = new SequenceI[sSize];
2959 StringBuffer protein;
2961 for(s=0; s<sSize; s++)
2963 protein = new StringBuffer();
2964 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
2965 resSize = seq.length();
2966 resSize -= resSize%3;
2968 for(res = 0; res < resSize; res+=3)
2970 String codon = seq.substring(res, res+3);
2971 codon = codon.replace('U', 'T');
2972 String aa = ResidueProperties.codonTranslate(codon);
2974 protein.append(viewport.getGapCharacter());
2975 else if(aa.equals("STOP"))
2976 protein.append("X");
2978 protein.append( aa );
2980 newSeq[s] = new Sequence(selection[s].getName(),
2981 protein.toString());
2985 AlignmentI al = new Alignment(newSeq);
2986 al.setDataset(null);
2989 ////////////////////////////////
2990 // Copy annotations across
2991 jalview.datamodel.AlignmentAnnotation[] annotations
2992 = viewport.alignment.getAlignmentAnnotation();
2994 if(annotations!=null)
2996 for (int i = 0; i < annotations.length; i++)
2998 if (annotations[i].label.equals("Quality") ||
2999 annotations[i].label.equals("Conservation") ||
3000 annotations[i].label.equals("Consensus"))
3005 aSize = viewport.alignment.getWidth() / 3;
3006 jalview.datamodel.Annotation[] anots =
3007 new jalview.datamodel.Annotation[aSize];
3009 for (a = 0; a < viewport.alignment.getWidth(); a++)
3011 if (annotations[i].annotations[a] == null
3012 || annotations[i].annotations[a] == null)
3015 anots[a / 3] = new Annotation(
3016 annotations[i].annotations[a].displayCharacter,
3017 annotations[i].annotations[a].description,
3018 annotations[i].annotations[a].secondaryStructure,
3019 annotations[i].annotations[a].value,
3020 annotations[i].annotations[a].colour);
3023 jalview.datamodel.AlignmentAnnotation aa
3024 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3025 annotations[i].description, anots);
3026 al.addAnnotation(aa);
3030 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3031 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3043 * @param String DOCUMENT ME!
3045 public boolean parseFeaturesFile(String file, String type)
3047 boolean featuresFile = false;
3049 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3050 alignPanel.seqPanel.seqCanvas.
3051 getFeatureRenderer().featureColours,
3056 ex.printStackTrace();
3061 viewport.showSequenceFeatures = true;
3062 showSeqFeatures.setSelected(true);
3063 alignPanel.repaint();
3066 return featuresFile;
3069 public void dragEnter(DropTargetDragEvent evt)
3072 public void dragExit(DropTargetEvent evt)
3075 public void dragOver(DropTargetDragEvent evt)
3078 public void dropActionChanged(DropTargetDragEvent evt)
3081 public void drop(DropTargetDropEvent evt)
3083 Transferable t = evt.getTransferable();
3084 java.util.List files = null;
3088 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3089 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3091 //Works on Windows and MacOSX
3092 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3093 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3095 else if (t.isDataFlavorSupported(uriListFlavor))
3097 // This is used by Unix drag system
3098 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3099 String data = (String) t.getTransferData(uriListFlavor);
3100 files = new java.util.ArrayList(1);
3101 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3104 st.hasMoreTokens(); )
3106 String s = st.nextToken();
3107 if (s.startsWith("#"))
3109 // the line is a comment (as per the RFC 2483)
3113 java.net.URI uri = new java.net.URI(s);
3114 java.io.File file = new java.io.File(uri);
3121 e.printStackTrace();
3128 for (int i = 0; i < files.size(); i++)
3130 loadJalviewDataFile(files.get(i).toString());
3133 catch (Exception ex)
3135 ex.printStackTrace();
3140 // This method will attempt to load a "dropped" file first by testing
3141 // whether its and Annotation file, then features file. If both are
3142 // false then the user may have dropped an alignment file onto this
3144 public void loadJalviewDataFile(String file)
3147 String protocol = "File";
3149 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3154 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3159 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3162 String format = new IdentifyFile().Identify(file, protocol);
3164 if(format.equalsIgnoreCase("JnetFile"))
3166 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3168 new JnetAnnotationMaker().add_annotation(predictions,
3169 viewport.getAlignment(),
3171 alignPanel.adjustAnnotationHeight();
3172 alignPanel.repaint();
3175 new FileLoader().LoadFile(viewport, file, protocol, format);
3181 alignPanel.adjustAnnotationHeight();
3184 }catch(Exception ex)
3186 ex.printStackTrace();
3190 public void tabSelectionChanged(int index)
3194 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3195 viewport = alignPanel.av;
3199 public void tabbedPane_mousePressed(MouseEvent e)
3201 if(SwingUtilities.isRightMouseButton(e))
3203 String reply = JOptionPane.showInternalInputDialog(this,
3206 JOptionPane.QUESTION_MESSAGE);
3210 viewport.viewName = reply;
3211 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3217 public AlignViewport getCurrentView()