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);
419 ap.av.addPropertyChangeListener(new PropertyChangeListener()
421 public void propertyChange(PropertyChangeEvent evt)
423 if (evt.getPropertyName().equals("alignment"))
425 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
436 public AlignViewport getViewport()
441 /* Set up intrinsic listeners for dynamically generated GUI bits. */
442 private void addServiceListeners()
444 final java.beans.PropertyChangeListener thisListener;
445 // Do this once to get current state
446 BuildWebServiceMenu();
447 Desktop.discoverer.addPropertyChangeListener(
448 thisListener = new java.beans.PropertyChangeListener()
450 public void propertyChange(PropertyChangeEvent evt)
452 // System.out.println("Discoverer property change.");
453 if (evt.getPropertyName().equals("services"))
455 // System.out.println("Rebuilding web service menu");
456 BuildWebServiceMenu();
461 addInternalFrameListener(new javax.swing.event.
462 InternalFrameAdapter()
464 public void internalFrameClosed(
465 javax.swing.event.InternalFrameEvent evt)
467 // System.out.println("deregistering discoverer listener");
468 Desktop.discoverer.removePropertyChangeListener(thisListener);
469 closeMenuItem_actionPerformed(null);
475 public void setGUINucleotide(boolean nucleotide)
477 showTranslation.setVisible( nucleotide );
478 //sequenceFeatures.setVisible(!nucleotide );
479 //featureSettings.setVisible( !nucleotide );
480 conservationMenuItem.setVisible( !nucleotide );
481 modifyConservation.setVisible( !nucleotide );
483 //Remember AlignFrame always starts as protein
486 calculateMenu.remove(calculateMenu.getItemCount()-2);
490 public void comeBackLater(FeatureEvent evt)
493 public void newFeatures(FeatureEvent evt)
495 if (evt.getFeatures().length > 0)
497 alignPanel.seqPanel.seqCanvas.fr.featuresAdded();
498 alignPanel.repaint();
502 Hashtable progressBars;
503 public void setProgressBar(String message, long id)
505 if(progressBars == null)
506 progressBars = new Hashtable();
508 JPanel progressPanel;
509 GridLayout layout = (GridLayout) statusPanel.getLayout();
510 if(progressBars.get( new Long(id) )!=null)
512 progressPanel = (JPanel)progressBars.get( new Long(id) );
513 statusPanel.remove(progressPanel);
514 progressBars.remove( progressPanel );
515 progressPanel = null;
517 statusBar.setText(message);
519 layout.setRows(layout.getRows() - 1);
523 progressPanel = new JPanel(new BorderLayout(10, 5));
525 JProgressBar progressBar = new JProgressBar();
526 progressBar.setIndeterminate(true);
528 progressPanel.add(new JLabel(message), BorderLayout.WEST);
529 progressPanel.add(progressBar, BorderLayout.CENTER);
531 layout.setRows(layout.getRows() + 1);
532 statusPanel.add(progressPanel);
534 progressBars.put(new Long(id), progressPanel);
542 Added so Castor Mapping file can obtain Jalview Version
544 public String getVersion()
546 return jalview.bin.Cache.getProperty("VERSION");
549 public FeatureRenderer getFeatureRenderer()
551 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
555 public void fetchSequence_actionPerformed(ActionEvent e)
557 new SequenceFetcher(this);
560 public void addFromFile_actionPerformed(ActionEvent e)
562 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
565 public void addFromText_actionPerformed(ActionEvent e)
567 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
570 public void addFromURL_actionPerformed(ActionEvent e)
572 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
578 * @param e DOCUMENT ME!
580 public void saveAlignmentMenu_actionPerformed(ActionEvent e)
582 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
583 getProperty( "LAST_DIRECTORY"),
585 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
587 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
592 chooser.setFileView(new JalviewFileView());
593 chooser.setDialogTitle("Save Alignment to file");
594 chooser.setToolTipText("Save");
596 int value = chooser.showSaveDialog(this);
598 if (value == JalviewFileChooser.APPROVE_OPTION)
600 currentFileFormat = chooser.getSelectedFormat();
602 if (currentFileFormat == null)
604 JOptionPane.showInternalMessageDialog(Desktop.desktop,
605 "You must select a file format before saving!",
606 "File format not specified",
607 JOptionPane.WARNING_MESSAGE);
608 value = chooser.showSaveDialog(this);
612 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
615 String choice = chooser.getSelectedFile().getPath();
616 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
618 saveAlignment(choice, currentFileFormat);
622 public boolean saveAlignment(String file, String format)
624 if (format.equalsIgnoreCase("Jalview"))
626 String shortName = title;
628 if (shortName.indexOf(java.io.File.separatorChar) > -1)
630 shortName = shortName.substring(shortName.lastIndexOf(
631 java.io.File.separatorChar) + 1);
634 new Jalview2XML().SaveAlignment(this, file, shortName);
636 // USE Jalview2XML to save this file
642 String[] omitHidden = null;
644 if (viewport.hasHiddenColumns)
646 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
647 "The Alignment contains hidden columns."
648 + "\nDo you want to save only the visible alignment?",
649 "Save / Omit Hidden Columns",
650 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
652 if (reply == JOptionPane.YES_OPTION)
653 omitHidden = viewport.getViewAsString(false);
656 String output = new FormatAdapter().formatSequences(
658 viewport.alignment.getSequencesArray(),
668 java.io.PrintWriter out = new java.io.PrintWriter(
669 new java.io.FileWriter(file));
678 ex.printStackTrace();
687 * @param e DOCUMENT ME!
689 protected void outputText_actionPerformed(ActionEvent e)
691 String [] omitHidden = null;
693 if(viewport.hasHiddenColumns)
695 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
696 "The Alignment contains hidden columns."
697 +"\nDo you want to output only the visible alignment?",
698 "Save / Omit Hidden Columns",
699 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
701 if(reply==JOptionPane.YES_OPTION)
703 omitHidden = viewport.getViewAsString(false);
707 CutAndPasteTransfer cap = new CutAndPasteTransfer();
708 Desktop.addInternalFrame(cap,
709 "Alignment output - " + e.getActionCommand(), 600,
713 cap.setText(new FormatAdapter().formatSequences(
714 e.getActionCommand(),
715 viewport.alignment.getSequencesArray(),
722 * @param e DOCUMENT ME!
724 protected void htmlMenuItem_actionPerformed(ActionEvent e)
726 new HTMLOutput(viewport,
727 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
728 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
731 public void createImageMap(File file, String image)
733 alignPanel.makePNGImageMap(file, image);
739 * @param e DOCUMENT ME!
741 public void createPNG(File f)
743 alignPanel.makePNG(f);
749 * @param e DOCUMENT ME!
751 public void createEPS(File f)
753 alignPanel.makeEPS(f);
759 * @param e DOCUMENT ME!
761 public void printMenuItem_actionPerformed(ActionEvent e)
763 //Putting in a thread avoids Swing painting problems
764 PrintThread thread = new PrintThread();
768 public void exportFeatures_actionPerformed(ActionEvent e)
770 new AnnotationExporter().exportFeatures(alignPanel);
774 public void exportAnnotations_actionPerformed(ActionEvent e)
776 new AnnotationExporter().exportAnnotations(
778 viewport.alignment.getAlignmentAnnotation()
783 public void associatedData_actionPerformed(ActionEvent e)
785 // Pick the tree file
786 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
789 chooser.setFileView(new JalviewFileView());
790 chooser.setDialogTitle("Load Jalview Annotations or Features File");
791 chooser.setToolTipText("Load Jalview Annotations / Features file");
793 int value = chooser.showOpenDialog(null);
795 if (value == JalviewFileChooser.APPROVE_OPTION)
797 String choice = chooser.getSelectedFile().getPath();
798 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
799 loadJalviewDataFile(choice);
808 * @param e DOCUMENT ME!
810 public void closeMenuItem_actionPerformed(ActionEvent e)
814 for(int i=0; i<alignPanels.size(); i++)
816 AlignmentPanel ap = (AlignmentPanel)alignPanels.elementAt(i);
817 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
818 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
819 PaintRefresher.RemoveComponent(ap);
822 this.setClosed(true);
833 void updateEditMenuBar()
835 /* if (historyList.size() > 0)
837 undoMenuItem.setEnabled(true);
839 HistoryItem hi = (HistoryItem) historyList.peek();
840 undoMenuItem.setText("Undo " + hi.getDescription());
844 undoMenuItem.setEnabled(false);
845 undoMenuItem.setText("Undo");
848 if (redoList.size() > 0)
850 redoMenuItem.setEnabled(true);
852 HistoryItem hi = (HistoryItem) redoList.peek();
853 redoMenuItem.setText("Redo " + hi.getDescription());
857 redoMenuItem.setEnabled(false);
858 redoMenuItem.setText("Redo");
865 * @param hi DOCUMENT ME!
867 public void addHistoryItem(HistoryItem hi)
869 historyList.push(hi);
877 * @param e DOCUMENT ME!
879 protected void undoMenuItem_actionPerformed(ActionEvent e)
881 HistoryItem nh,hi = (HistoryItem) historyList.pop();
882 redoList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
884 if (hi.alColumnChanges!=null)
885 nh.alColumnChanges = hi.alColumnChanges.getInverse();
886 restoreHistoryItem(hi);
887 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
893 * @param e DOCUMENT ME!
895 protected void redoMenuItem_actionPerformed(ActionEvent e)
897 HistoryItem nh,hi = (HistoryItem) redoList.pop();
898 historyList.push(nh=new HistoryItem(hi.getDescription(), viewport.alignment,
900 if (hi.alColumnChanges!=null)
901 nh.alColumnChanges=hi.alColumnChanges.getInverse();
902 restoreHistoryItem(hi);
904 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
907 // used by undo and redo
908 void restoreHistoryItem(HistoryItem hi)
911 hi.restore(viewport.getColumnSelection());
915 viewport.firePropertyChange("alignment", null,
916 viewport.getAlignment().getSequences());
922 * @param up DOCUMENT ME!
924 public void moveSelectedSequences(boolean up)
926 SequenceGroup sg = viewport.getSelectionGroup();
935 for (int i = 1; i < viewport.alignment.getHeight(); i++)
937 SequenceI seq = viewport.alignment.getSequenceAt(i);
939 if (!sg.getSequences(false).contains(seq))
944 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
946 if (sg.getSequences(false).contains(temp))
951 viewport.alignment.getSequences().setElementAt(temp, i);
952 viewport.alignment.getSequences().setElementAt(seq, i - 1);
957 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
959 SequenceI seq = viewport.alignment.getSequenceAt(i);
961 if (!sg.getSequences(false).contains(seq))
966 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
968 if (sg.getSequences(false).contains(temp))
973 viewport.alignment.getSequences().setElementAt(temp, i);
974 viewport.alignment.getSequences().setElementAt(seq, i + 1);
978 alignPanel.repaint();
986 * @param e DOCUMENT ME!
988 protected void copy_actionPerformed(ActionEvent e)
991 if (viewport.getSelectionGroup() == null)
996 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
997 String[] omitHidden = null;
999 if (viewport.hasHiddenColumns)
1001 omitHidden = viewport.getViewAsString(true);
1004 String output = new FormatAdapter().formatSequences(
1009 StringSelection ss = new StringSelection(output);
1013 //Its really worth setting the clipboard contents
1014 //to empty before setting the large StringSelection!!
1015 Toolkit.getDefaultToolkit().getSystemClipboard()
1016 .setContents(new StringSelection(""), null);
1018 Toolkit.getDefaultToolkit().getSystemClipboard()
1019 .setContents(ss, Desktop.instance);
1021 catch (OutOfMemoryError er)
1023 er.printStackTrace();
1024 javax.swing.SwingUtilities.invokeLater(new Runnable()
1028 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1029 "Out of memory copying region!!"
1031 "\nSee help files for increasing Java Virtual Machine memory."
1033 javax.swing.JOptionPane.WARNING_MESSAGE);
1040 Vector hiddenColumns = null;
1041 if(viewport.hasHiddenColumns)
1043 hiddenColumns =new Vector();
1044 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1045 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1047 int[] region = (int[])
1048 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1050 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1051 region[1]-hiddenOffset});
1057 Desktop.jalviewClipboard = new Object[]{ seqs,
1058 viewport.alignment.getDataset(),
1060 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1066 * @param e DOCUMENT ME!
1068 protected void pasteNew_actionPerformed(ActionEvent e)
1076 * @param e DOCUMENT ME!
1078 protected void pasteThis_actionPerformed(ActionEvent e)
1080 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,
1081 HistoryItem.PASTE));
1088 * @param newAlignment DOCUMENT ME!
1090 void paste(boolean newAlignment)
1094 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1095 Transferable contents = c.getContents(this);
1097 if (contents == null)
1105 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1106 if (str.length() < 1)
1109 format = new IdentifyFile().Identify(str, "Paste");
1112 catch (OutOfMemoryError er)
1114 er.printStackTrace();
1115 javax.swing.SwingUtilities.invokeLater(new Runnable()
1119 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1120 "Out of memory pasting sequences!!"
1122 "\nSee help files for increasing Java Virtual Machine memory."
1124 javax.swing.JOptionPane.WARNING_MESSAGE);
1131 SequenceI[] sequences;
1134 if(Desktop.jalviewClipboard!=null)
1136 // The clipboard was filled from within Jalview, we must use the sequences
1137 // And dataset from the copied alignment
1138 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1142 sequences = new FormatAdapter().readFile(str, "Paste", format);
1145 AlignmentI alignment = null;
1149 alignment = new Alignment(sequences);
1151 if (Desktop.jalviewClipboard != null)
1152 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1154 alignment.setDataset(null);
1158 alignment = viewport.getAlignment();
1161 for (int i = 0; i < sequences.length; i++)
1163 Sequence newseq = new Sequence(sequences[i].getName(),
1164 sequences[i].getSequence(), sequences[i].getStart(),
1165 sequences[i].getEnd());
1167 alignment.addSequence(newseq);
1168 PaintRefresher.Refresh(alignPanel,
1169 alignPanel.av.getSequenceSetId(),
1174 viewport.setEndSeq(alignment.getHeight());
1175 alignment.getWidth();
1176 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1181 // Add any annotations attached to sequences
1182 for (int i = 0; i < sequences.length; i++)
1184 if (sequences[i].getAnnotation() != null)
1186 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1188 AlignmentAnnotation newAnnot =
1189 new AlignmentAnnotation(
1190 sequences[i].getAnnotation()[a].label,
1191 sequences[i].getAnnotation()[a].description,
1192 sequences[i].getAnnotation()[a].annotations,
1193 sequences[i].getAnnotation()[a].graphMin,
1194 sequences[i].getAnnotation()[a].graphMax,
1195 sequences[i].getAnnotation()[a].graph);
1197 sequences[i].getAnnotation()[a] = newAnnot;
1198 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1200 newAnnot.sequenceRef = sequences[i];
1201 newAnnot.adjustForAlignment();
1202 alignment.addAnnotation(newAnnot);
1203 alignment.setAnnotationIndex(newAnnot, a);
1206 alignPanel.annotationPanel.adjustPanelHeight();
1212 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1213 String newtitle = new String("Copied sequences");
1215 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1217 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1218 for(int i=0; i<hc.size(); i++)
1220 int [] region = (int[]) hc.elementAt(i);
1221 af.viewport.hideColumns(region[0], region[1]);
1226 //>>>This is a fix for the moment, until a better solution is found!!<<<
1227 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1228 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1231 if (title.startsWith("Copied sequences"))
1237 newtitle = newtitle.concat("- from " + title);
1240 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1247 catch (Exception ex)
1249 ex.printStackTrace();
1250 System.out.println("Exception whilst pasting: "+ex);
1251 // could be anything being pasted in here
1260 * @param e DOCUMENT ME!
1262 protected void cut_actionPerformed(ActionEvent e)
1264 copy_actionPerformed(null);
1265 delete_actionPerformed(null);
1271 * @param e DOCUMENT ME!
1273 protected void delete_actionPerformed(ActionEvent e)
1276 if (viewport.getSelectionGroup() == null)
1282 SequenceGroup sg = viewport.getSelectionGroup();
1285 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
1289 for (int i = 0; i < sg.getSize(false); i++)
1291 SequenceI seq = sg.getSequenceAt(i);
1292 int index = viewport.getAlignment().findIndex(seq);
1294 seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);
1296 // If the cut affects all sequences, remove highlighted columns
1297 if (sg.getSize(false) == viewport.alignment.getHeight())
1299 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1300 sg.getEndRes() + 1);
1303 if (seq.getSequence().length() < 1)
1305 viewport.getAlignment().deleteSequence(seq);
1306 PaintRefresher.Refresh(alignPanel,alignPanel.av.getSequenceSetId(),seq,null);
1310 viewport.getAlignment().getSequences().setElementAt(seq, index);
1314 viewport.setSelectionGroup(null);
1315 viewport.alignment.deleteGroup(sg);
1317 viewport.firePropertyChange("alignment", null,
1318 viewport.getAlignment().getSequences());
1322 if (viewport.getAlignment().getHeight() < 1)
1326 this.setClosed(true);
1328 catch (Exception ex)
1337 * @param e DOCUMENT ME!
1339 protected void deleteGroups_actionPerformed(ActionEvent e)
1341 viewport.alignment.deleteAllGroups();
1342 viewport.setSelectionGroup(null);
1343 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1344 alignPanel.repaint();
1350 * @param e DOCUMENT ME!
1352 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1354 SequenceGroup sg = new SequenceGroup();
1356 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1359 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1362 sg.setEndRes(viewport.alignment.getWidth() - 1);
1363 viewport.setSelectionGroup(sg);
1364 alignPanel.repaint();
1365 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1371 * @param e DOCUMENT ME!
1373 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1375 if(viewport.cursorMode)
1377 alignPanel.seqPanel.keyboardNo1 = null;
1378 alignPanel.seqPanel.keyboardNo2 = null;
1380 viewport.setSelectionGroup(null);
1381 viewport.getColumnSelection().clear();
1382 viewport.setSelectionGroup(null);
1383 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1384 alignPanel.idPanel.idCanvas.searchResults = null;
1385 alignPanel.repaint();
1386 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1392 * @param e DOCUMENT ME!
1394 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1396 SequenceGroup sg = viewport.getSelectionGroup();
1400 selectAllSequenceMenuItem_actionPerformed(null);
1405 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1408 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1411 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1414 public void invertColSel_actionPerformed(ActionEvent e)
1416 viewport.invertColumnSelection();
1417 alignPanel.repaint();
1424 * @param e DOCUMENT ME!
1426 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1428 ColumnSelection colSel = viewport.getColumnSelection();
1430 if (colSel.size() > 0)
1433 addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment,
1436 int min = colSel.getMin();
1437 viewport.getAlignment().trimLeft(min);
1438 colSel.compensateForEdit(0, min);
1439 edit.addShift(0,min);
1440 if (viewport.getSelectionGroup() != null)
1442 viewport.getSelectionGroup().adjustForRemoveLeft(min);
1445 Vector groups = viewport.alignment.getGroups();
1447 for (int i = 0; i < groups.size(); i++)
1449 SequenceGroup sg = (SequenceGroup) groups.get(i);
1451 if (!sg.adjustForRemoveLeft(min))
1453 viewport.alignment.deleteGroup(sg);
1457 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1464 * @param e DOCUMENT ME!
1466 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1468 ColumnSelection colSel = viewport.getColumnSelection();
1470 if (colSel.size() > 0)
1472 addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
1475 int max = colSel.getMax();
1476 viewport.getAlignment().trimRight(max);
1477 // TODO: delete hidden column entries in colSel to right of max
1478 // TODO: record hidden columns in history for undo.
1479 if (viewport.getSelectionGroup() != null)
1481 viewport.getSelectionGroup().adjustForRemoveRight(max);
1484 Vector groups = viewport.alignment.getGroups();
1486 for (int i = 0; i < groups.size(); i++)
1488 SequenceGroup sg = (SequenceGroup) groups.get(i);
1490 if (!sg.adjustForRemoveRight(max))
1492 viewport.alignment.deleteGroup(sg);
1496 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1503 * @param e DOCUMENT ME!
1505 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1508 addHistoryItem(edit=new HistoryItem("Remove Gapped Columns",
1509 viewport.alignment, HistoryItem.HIDE));
1511 //This is to maintain viewport position on first residue
1513 SequenceI seq = viewport.alignment.getSequenceAt(0);
1514 int startRes = seq.findPosition(viewport.startRes);
1516 viewport.getAlignment().removeGaps(shifts=new ShiftList());
1517 edit.alColumnChanges=shifts.getInverse();
1518 if (viewport.hasHiddenColumns)
1519 viewport.getColumnSelection().compensateForEdits(shifts);
1520 viewport.setStartRes(seq.findIndex(startRes)-1);
1521 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1528 * @param e DOCUMENT ME!
1530 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1532 // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences
1533 // TODO: columnSelection.compensateforedits should be called (and passed to history item)
1534 addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
1537 //This is to maintain viewport position on first residue
1539 SequenceI seq = viewport.alignment.getSequenceAt(0);
1540 int startRes = seq.findPosition(viewport.startRes);
1548 int end = viewport.alignment.getWidth();
1550 if (viewport.getSelectionGroup() != null
1551 && viewport.getSelectionGroup().getSequences(true) != null
1552 && viewport.getSelectionGroup().getSize(true) > 0)
1554 seqs = viewport.getSelectionGroup().getSequences(true);
1555 start = viewport.getSelectionGroup().getStartRes();
1556 end = viewport.getSelectionGroup().getEndRes()+1;
1560 seqs = viewport.alignment.getSequences();
1562 /* Commented out regions below are partial implementation of todo above.
1563 * divide start,end into visible chunks, and for each:
1564 int diff=end-start+1;
1566 int dr[] = new int[seqs.size()];
1568 for (int i = 0; i < seqs.size(); i++)
1570 current = (SequenceI) seqs.elementAt(i);
1572 current.removeGaps(start, end);
1573 /*if (d<diff) // can only shift
1579 /* // after the end of each chunk -
1581 // record shift for history.
1582 editgaps.addShift(start, diff);
1583 if (viewport.hasHiddenColumns && diffmax>diff) {
1585 StringBuffer gaps=new StringBuffer(diffmax);
1586 for (int i=0,j=diffmax-diff; i<j; i++)
1587 gaps.append(viewport.getGapCharacter());
1588 for (int i=0, j=seqs.size(); i<j; i++) {
1589 current = (SequenceI) seqs.elementAt(i);
1591 String sq = current.getSequence();
1592 current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring());
1598 viewport.setStartRes(seq.findIndex(startRes)-1);
1600 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1604 public void alignmentChanged()
1609 for(int i=0; i<alignPanels.size(); i++)
1611 ap = (AlignmentPanel) alignPanels.elementAt(i);
1615 av.getAlignment().padGaps();
1617 if (av.hconsensus != null && av.autoCalculateConsensus)
1619 av.updateConsensus();
1620 av.updateConservation();
1623 resetAllColourSchemes();
1625 av.alignment.adjustSequenceAnnotations();
1627 if (ap.overviewPanel != null)
1628 ap.overviewPanel.updateOverviewImage();
1634 void resetAllColourSchemes()
1636 ColourSchemeI cs = viewport.globalColourScheme;
1639 if (cs instanceof ClustalxColourScheme)
1641 ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
1642 resetClustalX(viewport.alignment.getSequences(),
1643 viewport.alignment.getWidth());
1646 cs.setConsensus(viewport.hconsensus);
1647 if (cs.conservationApplied())
1649 Alignment al = (Alignment) viewport.alignment;
1650 Conservation c = new Conservation("All",
1651 ResidueProperties.propHash, 3,
1652 al.getSequences(), 0,
1655 c.verdict(false, viewport.ConsPercGaps);
1657 cs.setConservation(c);
1661 int s, sSize = viewport.alignment.getGroups().size();
1662 for(s=0; s<sSize; s++)
1664 SequenceGroup sg = (SequenceGroup)viewport.alignment.getGroups().elementAt(s);
1665 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1667 ((ClustalxColourScheme)sg.cs).resetClustalX(
1668 sg.getSequences(true), sg.getWidth());
1670 sg.recalcConservation();
1677 * @param e DOCUMENT ME!
1679 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1681 addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,
1684 viewport.padGaps = padGapsMenuitem.isSelected();
1686 viewport.firePropertyChange("alignment",
1688 viewport.getAlignment().getSequences());
1694 * @param e DOCUMENT ME!
1696 public void findMenuItem_actionPerformed(ActionEvent e)
1698 JInternalFrame frame = new JInternalFrame();
1699 Finder finder = new Finder(viewport, alignPanel, frame);
1700 frame.setContentPane(finder);
1701 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1702 Desktop.addInternalFrame(frame, "Find", 340, 110);
1708 * @param e DOCUMENT ME!
1710 public void font_actionPerformed(ActionEvent e)
1712 new FontChooser(alignPanel);
1715 public void smoothFont_actionPerformed(ActionEvent e)
1717 viewport.antiAlias = smoothFont.isSelected();
1718 alignPanel.annotationPanel.image = null;
1719 alignPanel.repaint();
1726 * @param e DOCUMENT ME!
1728 protected void seqLimit_actionPerformed(ActionEvent e)
1730 viewport.setShowJVSuffix(seqLimits.isSelected());
1732 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1733 alignPanel.repaint();
1740 * @param e DOCUMENT ME!
1742 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1744 viewport.setColourText(colourTextMenuItem.isSelected());
1745 alignPanel.repaint();
1751 * @param e DOCUMENT ME!
1753 public void wrapMenuItem_actionPerformed(ActionEvent e)
1755 scaleAbove.setVisible(wrapMenuItem.isSelected());
1756 scaleLeft.setVisible(wrapMenuItem.isSelected());
1757 scaleRight.setVisible(wrapMenuItem.isSelected());
1758 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1759 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1762 public void showAllSeqs_actionPerformed(ActionEvent e)
1764 viewport.showAllHiddenSeqs();
1767 public void showAllColumns_actionPerformed(ActionEvent e)
1769 viewport.showAllHiddenColumns();
1773 public void hideSelSequences_actionPerformed(ActionEvent e)
1775 viewport.hideAllSelectedSeqs();
1776 alignPanel.repaint();
1779 public void hideSelColumns_actionPerformed(ActionEvent e)
1781 viewport.hideSelectedColumns();
1782 alignPanel.repaint();
1785 public void hiddenMarkers_actionPerformed(ActionEvent e)
1787 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1794 * @param e DOCUMENT ME!
1796 protected void scaleAbove_actionPerformed(ActionEvent e)
1798 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1799 alignPanel.repaint();
1805 * @param e DOCUMENT ME!
1807 protected void scaleLeft_actionPerformed(ActionEvent e)
1809 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1810 alignPanel.repaint();
1816 * @param e DOCUMENT ME!
1818 protected void scaleRight_actionPerformed(ActionEvent e)
1820 viewport.setScaleRightWrapped(scaleRight.isSelected());
1821 alignPanel.repaint();
1827 * @param e DOCUMENT ME!
1829 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1831 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1832 alignPanel.repaint();
1838 * @param e DOCUMENT ME!
1840 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1842 viewport.setShowText(viewTextMenuItem.isSelected());
1843 alignPanel.repaint();
1849 * @param e DOCUMENT ME!
1851 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1853 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1854 alignPanel.repaint();
1858 public FeatureSettings featureSettings;
1859 public void featureSettings_actionPerformed(ActionEvent e)
1861 if(featureSettings !=null )
1863 featureSettings.close();
1864 featureSettings = null;
1866 featureSettings = new FeatureSettings(this);
1872 * @param evt DOCUMENT ME!
1874 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1876 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1877 alignPanel.repaint();
1878 if (alignPanel.getOverviewPanel() != null)
1880 alignPanel.getOverviewPanel().updateOverviewImage();
1887 * @param e DOCUMENT ME!
1889 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1891 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1892 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1898 * @param e DOCUMENT ME!
1900 public void overviewMenuItem_actionPerformed(ActionEvent e)
1902 if (alignPanel.overviewPanel != null)
1907 JInternalFrame frame = new JInternalFrame();
1908 OverviewPanel overview = new OverviewPanel(alignPanel);
1909 frame.setContentPane(overview);
1910 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1911 frame.getWidth(), frame.getHeight());
1913 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1914 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1916 public void internalFrameClosed(
1917 javax.swing.event.InternalFrameEvent evt)
1919 alignPanel.setOverviewPanel(null);
1924 alignPanel.setOverviewPanel(overview);
1930 * @param e DOCUMENT ME!
1932 protected void noColourmenuItem_actionPerformed(ActionEvent e)
1940 * @param e DOCUMENT ME!
1942 public void clustalColour_actionPerformed(ActionEvent e)
1944 changeColour(new ClustalxColourScheme(
1945 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
1951 * @param e DOCUMENT ME!
1953 public void zappoColour_actionPerformed(ActionEvent e)
1955 changeColour(new ZappoColourScheme());
1961 * @param e DOCUMENT ME!
1963 public void taylorColour_actionPerformed(ActionEvent e)
1965 changeColour(new TaylorColourScheme());
1971 * @param e DOCUMENT ME!
1973 public void hydrophobicityColour_actionPerformed(ActionEvent e)
1975 changeColour(new HydrophobicColourScheme());
1981 * @param e DOCUMENT ME!
1983 public void helixColour_actionPerformed(ActionEvent e)
1985 changeColour(new HelixColourScheme());
1991 * @param e DOCUMENT ME!
1993 public void strandColour_actionPerformed(ActionEvent e)
1995 changeColour(new StrandColourScheme());
2001 * @param e DOCUMENT ME!
2003 public void turnColour_actionPerformed(ActionEvent e)
2005 changeColour(new TurnColourScheme());
2011 * @param e DOCUMENT ME!
2013 public void buriedColour_actionPerformed(ActionEvent e)
2015 changeColour(new BuriedColourScheme());
2021 * @param e DOCUMENT ME!
2023 public void nucleotideColour_actionPerformed(ActionEvent e)
2025 changeColour(new NucleotideColourScheme());
2028 public void annotationColour_actionPerformed(ActionEvent e)
2030 new AnnotationColourChooser(viewport, alignPanel);
2037 * @param e DOCUMENT ME!
2039 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2041 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2047 * @param cs DOCUMENT ME!
2049 public void changeColour(ColourSchemeI cs)
2055 if (viewport.getAbovePIDThreshold())
2057 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2060 cs.setThreshold(threshold,
2061 viewport.getIgnoreGapsConsensus());
2063 viewport.setGlobalColourScheme(cs);
2067 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2070 if (viewport.getConservationSelected())
2073 Alignment al = (Alignment) viewport.alignment;
2074 Conservation c = new Conservation("All",
2075 ResidueProperties.propHash, 3,
2076 al.getSequences(), 0,
2080 c.verdict(false, viewport.ConsPercGaps);
2082 cs.setConservation(c);
2084 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2089 cs.setConservation(null);
2092 cs.setConsensus(viewport.hconsensus);
2095 viewport.setGlobalColourScheme(cs);
2097 if (viewport.getColourAppliesToAllGroups())
2099 Vector groups = viewport.alignment.getGroups();
2101 for (int i = 0; i < groups.size(); i++)
2103 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2111 if (cs instanceof ClustalxColourScheme)
2113 sg.cs = new ClustalxColourScheme(
2114 sg.getSequences(true), sg.getWidth());
2116 else if (cs instanceof UserColourScheme)
2118 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2124 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2126 catch (Exception ex)
2131 if (viewport.getAbovePIDThreshold()
2132 || cs instanceof PIDColourScheme
2133 || cs instanceof Blosum62ColourScheme)
2135 sg.cs.setThreshold(threshold,
2136 viewport.getIgnoreGapsConsensus());
2138 sg.cs.setConsensus(AAFrequency.calculate(
2139 sg.getSequences(true), 0,
2143 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2146 if (viewport.getConservationSelected())
2148 Conservation c = new Conservation("Group",
2149 ResidueProperties.propHash, 3,
2150 sg.getSequences(true), 0,
2151 viewport.alignment.getWidth() - 1);
2153 c.verdict(false, viewport.ConsPercGaps);
2154 sg.cs.setConservation(c);
2157 sg.cs.setConservation(null);
2161 if (alignPanel.getOverviewPanel() != null)
2163 alignPanel.getOverviewPanel().updateOverviewImage();
2166 alignPanel.repaint();
2172 * @param e DOCUMENT ME!
2174 protected void modifyPID_actionPerformed(ActionEvent e)
2176 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2178 SliderPanel.setPIDSliderSource(alignPanel,
2179 viewport.getGlobalColourScheme(),
2181 SliderPanel.showPIDSlider();
2188 * @param e DOCUMENT ME!
2190 protected void modifyConservation_actionPerformed(ActionEvent e)
2192 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2194 SliderPanel.setConservationSlider(alignPanel,
2195 viewport.globalColourScheme,
2197 SliderPanel.showConservationSlider();
2204 * @param e DOCUMENT ME!
2206 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2208 viewport.setConservationSelected(conservationMenuItem.isSelected());
2210 viewport.setAbovePIDThreshold(false);
2211 abovePIDThreshold.setSelected(false);
2213 changeColour(viewport.getGlobalColourScheme());
2215 modifyConservation_actionPerformed(null);
2221 * @param e DOCUMENT ME!
2223 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2225 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2227 conservationMenuItem.setSelected(false);
2228 viewport.setConservationSelected(false);
2230 changeColour(viewport.getGlobalColourScheme());
2232 modifyPID_actionPerformed(null);
2238 * @param e DOCUMENT ME!
2240 public void userDefinedColour_actionPerformed(ActionEvent e)
2242 if (e.getActionCommand().equals("User Defined..."))
2244 new UserDefinedColours(alignPanel, null);
2248 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2249 getUserColourSchemes().get(e.getActionCommand());
2255 public void updateUserColourMenu()
2258 Component[] menuItems = colourMenu.getMenuComponents();
2259 int i, iSize = menuItems.length;
2260 for (i = 0; i < iSize; i++)
2262 if (menuItems[i].getName() != null &&
2263 menuItems[i].getName().equals("USER_DEFINED"))
2265 colourMenu.remove(menuItems[i]);
2269 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2271 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2272 getUserColourSchemes().keys();
2274 while (userColours.hasMoreElements())
2276 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2277 nextElement().toString());
2278 radioItem.setName("USER_DEFINED");
2279 radioItem.addMouseListener(new MouseAdapter()
2281 public void mousePressed(MouseEvent evt)
2283 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2285 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2287 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2288 "Remove from default list?",
2289 "Remove user defined colour",
2290 JOptionPane.YES_NO_OPTION);
2291 if(option == JOptionPane.YES_OPTION)
2293 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2294 colourMenu.remove(radioItem);
2297 radioItem.addActionListener(new ActionListener()
2299 public void actionPerformed(ActionEvent evt)
2301 userDefinedColour_actionPerformed(evt);
2307 radioItem.addActionListener(new ActionListener()
2309 public void actionPerformed(ActionEvent evt)
2311 userDefinedColour_actionPerformed(evt);
2315 colourMenu.insert(radioItem, 15);
2316 colours.add(radioItem);
2324 * @param e DOCUMENT ME!
2326 public void PIDColour_actionPerformed(ActionEvent e)
2328 changeColour(new PIDColourScheme());
2334 * @param e DOCUMENT ME!
2336 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2338 changeColour(new Blosum62ColourScheme());
2344 * @param e DOCUMENT ME!
2346 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2348 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,
2350 AlignmentSorter.sortByPID(viewport.getAlignment(),
2351 viewport.getAlignment().getSequenceAt(0));
2352 alignPanel.repaint();
2358 * @param e DOCUMENT ME!
2360 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2362 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,
2364 AlignmentSorter.sortByID(viewport.getAlignment());
2365 alignPanel.repaint();
2371 * @param e DOCUMENT ME!
2373 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2375 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,
2378 AlignmentSorter.sortByGroup(viewport.getAlignment());
2379 alignPanel.repaint();
2385 * @param e DOCUMENT ME!
2387 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2389 new RedundancyPanel(alignPanel, this);
2396 * @param e DOCUMENT ME!
2398 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2400 if ( (viewport.getSelectionGroup() == null) ||
2401 (viewport.getSelectionGroup().getSize(false) < 2))
2403 JOptionPane.showInternalMessageDialog(this,
2404 "You must select at least 2 sequences.",
2405 "Invalid Selection",
2406 JOptionPane.WARNING_MESSAGE);
2410 JInternalFrame frame = new JInternalFrame();
2411 frame.setContentPane(new PairwiseAlignPanel(viewport));
2412 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2419 * @param e DOCUMENT ME!
2421 public void PCAMenuItem_actionPerformed(ActionEvent e)
2423 if ( ( (viewport.getSelectionGroup() != null) &&
2424 (viewport.getSelectionGroup().getSize(false) < 4) &&
2425 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2426 (viewport.getAlignment().getHeight() < 4))
2428 JOptionPane.showInternalMessageDialog(this,
2429 "Principal component analysis must take\n" +
2430 "at least 4 input sequences.",
2431 "Sequence selection insufficient",
2432 JOptionPane.WARNING_MESSAGE);
2437 new PCAPanel(viewport);
2441 public void autoCalculate_actionPerformed(ActionEvent e)
2443 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2444 if(viewport.autoCalculateConsensus)
2446 viewport.firePropertyChange("alignment",
2448 viewport.getAlignment().getSequences());
2456 * @param e DOCUMENT ME!
2458 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2460 NewTreePanel("AV", "PID", "Average distance tree using PID");
2466 * @param e DOCUMENT ME!
2468 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2470 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2476 * @param e DOCUMENT ME!
2478 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2480 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2486 * @param e DOCUMENT ME!
2488 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2490 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2496 * @param type DOCUMENT ME!
2497 * @param pwType DOCUMENT ME!
2498 * @param title DOCUMENT ME!
2500 void NewTreePanel(String type, String pwType, String title)
2504 if (viewport.getSelectionGroup() != null) {
2505 if (viewport.getSelectionGroup().getSize(false) < 3) {
2506 JOptionPane.showMessageDialog(Desktop.desktop,
2507 "You need to have more than two sequences selected to build a tree!",
2508 "Not enough sequences",
2509 JOptionPane.WARNING_MESSAGE);
2514 SequenceGroup sg = viewport.getSelectionGroup();
2516 /* Decide if the selection is a column region */
2517 while (s < sg.getSize(false))
2519 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2522 JOptionPane.showMessageDialog(Desktop.desktop,
2523 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2524 "Try using the Pad function in the edit menu,\n" +
2525 "or one of the multiple sequence alignment web services.",
2526 "Sequences in selection are not aligned",
2527 JOptionPane.WARNING_MESSAGE);
2533 title = title + " on region";
2534 tp = new TreePanel(alignPanel, type, pwType);
2538 //are the sequences aligned?
2539 if (!viewport.alignment.isAligned())
2541 JOptionPane.showMessageDialog(Desktop.desktop,
2542 "The sequences must be aligned before creating a tree.\n" +
2543 "Try using the Pad function in the edit menu,\n" +
2544 "or one of the multiple sequence alignment web services.",
2545 "Sequences not aligned",
2546 JOptionPane.WARNING_MESSAGE);
2551 if(viewport.alignment.getHeight()<2)
2554 tp = new TreePanel(alignPanel, type, pwType);
2557 addTreeMenuItem(tp, title);
2559 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2565 * @param title DOCUMENT ME!
2566 * @param order DOCUMENT ME!
2568 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2570 final JMenuItem item = new JMenuItem("by " + title);
2572 item.addActionListener(new java.awt.event.ActionListener()
2574 public void actionPerformed(ActionEvent e)
2576 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2579 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2580 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2581 alignPanel.repaint();
2587 * Maintain the Order by->Displayed Tree menu.
2588 * Creates a new menu item for a TreePanel with an appropriate
2589 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2590 * to remove the menu item when the treePanel is closed, and adjust
2591 * the tree leaf to sequence mapping when the alignment is modified.
2592 * @param treePanel Displayed tree window.
2593 * @param title SortBy menu item title.
2595 void addTreeMenuItem(final TreePanel treePanel, String title)
2597 final JMenuItem item = new JMenuItem(title);
2603 sort.add(sortByTreeMenu);
2606 sortByTreeMenu.add(item);
2607 item.addActionListener(new java.awt.event.ActionListener()
2609 public void actionPerformed(ActionEvent e)
2611 addHistoryItem(new HistoryItem("Tree Sort",
2612 viewport.alignment, HistoryItem.SORT));
2613 AlignmentSorter.sortByTree(viewport.getAlignment(),
2614 treePanel.getTree());
2615 alignPanel.repaint();
2619 treePanel.addInternalFrameListener(new javax.swing.event.
2620 InternalFrameAdapter()
2622 public void internalFrameClosed(
2623 javax.swing.event.InternalFrameEvent evt)
2626 sortByTreeMenu.remove(item);
2630 sort.remove(sortByTreeMenu);
2638 * Work out whether the whole set of sequences
2639 * or just the selected set will be submitted for multiple alignment.
2642 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2644 // Now, check we have enough sequences
2645 AlignmentView msa = null;
2647 if ( (viewport.getSelectionGroup() != null) &&
2648 (viewport.getSelectionGroup().getSize(false) > 1))
2650 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2651 /*SequenceGroup seqs = viewport.getSelectionGroup();
2653 msa = new SequenceI[sz = seqs.getSize(false)];
2655 for (int i = 0; i < sz; i++)
2657 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2659 msa = viewport.getAlignmentView(true);
2663 /*Vector seqs = viewport.getAlignment().getSequences();
2665 if (seqs.size() > 1)
2667 msa = new SequenceI[seqs.size()];
2669 for (int i = 0; i < seqs.size(); i++)
2671 msa[i] = (SequenceI) seqs.elementAt(i);
2674 msa = viewport.getAlignmentView(false);
2680 * Decides what is submitted to a secondary structure prediction service,
2681 * the currently selected sequence, or the currently selected alignment
2682 * (where the first sequence in the set is the one that the prediction
2685 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2687 AlignmentView seqs = null;
2689 if ( (viewport.getSelectionGroup() != null) &&
2690 (viewport.getSelectionGroup().getSize(false) > 0))
2692 seqs = viewport.getAlignmentView(true);
2696 seqs = viewport.getAlignmentView(false);
2698 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2699 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2700 if (!viewport.alignment.isAligned())
2702 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2709 * @param e DOCUMENT ME!
2711 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2713 // Pick the tree file
2714 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2717 chooser.setFileView(new JalviewFileView());
2718 chooser.setDialogTitle("Select a newick-like tree file");
2719 chooser.setToolTipText("Load a tree file");
2721 int value = chooser.showOpenDialog(null);
2723 if (value == JalviewFileChooser.APPROVE_OPTION)
2725 String choice = chooser.getSelectedFile().getPath();
2726 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2730 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2732 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2734 catch (Exception ex)
2736 JOptionPane.showMessageDialog(Desktop.desktop,
2737 "Problem reading tree file",
2739 JOptionPane.WARNING_MESSAGE);
2740 ex.printStackTrace();
2746 public TreePanel ShowNewickTree(NewickFile nf, String title)
2748 return ShowNewickTree(nf,title,600,500,4,5);
2750 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2752 return ShowNewickTree(nf,title, input, 600,500,4,5);
2754 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2755 return ShowNewickTree(nf, title, null, w, h, x, y);
2758 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2760 * @param nf the tree
2761 * @param title tree viewer title
2762 * @param input Associated alignment input data (or null)
2767 * @return TreePanel handle
2769 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2770 TreePanel tp = null;
2776 if (nf.getTree() != null)
2778 tp = new TreePanel(alignPanel,
2786 tp.setLocation(x,y);
2789 Desktop.addInternalFrame(tp, title, w, h);
2790 addTreeMenuItem(tp, title);
2793 catch (Exception ex)
2795 ex.printStackTrace();
2806 PrinterJob printJob = PrinterJob.getPrinterJob();
2807 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2808 printJob.setPrintable(alignPanel, pf);
2810 if (printJob.printDialog())
2816 catch (Exception PrintException)
2818 PrintException.printStackTrace();
2825 * Generates menu items and listener event actions for web service clients
2828 public void BuildWebServiceMenu()
2830 if ( (Discoverer.services != null)
2831 && (Discoverer.services.size() > 0))
2833 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2834 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2835 Vector wsmenu = new Vector();
2836 final AlignFrame af = this;
2839 // Add any Multiple Sequence Alignment Services
2840 final JMenu msawsmenu = new JMenu("Alignment");
2841 for (int i = 0, j = msaws.size(); i < j; i++)
2843 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2845 final JMenuItem method = new JMenuItem(sh.getName());
2846 method.addActionListener(new ActionListener()
2848 public void actionPerformed(ActionEvent e)
2850 AlignmentView msa = gatherSequencesForAlignment();
2851 new jalview.ws.MsaWSClient(sh, title, msa,
2852 false, true, viewport.getAlignment().getDataset(), af);
2857 msawsmenu.add(method);
2858 // Deal with services that we know accept partial alignments.
2859 if (sh.getName().indexOf("lustal") > -1)
2861 // We know that ClustalWS can accept partial alignments for refinement.
2862 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2863 methodR.addActionListener(new ActionListener()
2865 public void actionPerformed(ActionEvent e)
2867 AlignmentView msa = gatherSequencesForAlignment();
2868 new jalview.ws.MsaWSClient(sh, title, msa,
2869 true, true, viewport.getAlignment().getDataset(), af);
2874 msawsmenu.add(methodR);
2878 wsmenu.add(msawsmenu);
2880 if (secstrpr != null)
2882 // Add any secondary structure prediction services
2883 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2884 for (int i = 0, j = secstrpr.size(); i < j; i++)
2886 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2888 final JMenuItem method = new JMenuItem(sh.getName());
2889 method.addActionListener(new ActionListener()
2891 public void actionPerformed(ActionEvent e)
2893 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2894 if (msa.getSequences().length == 1)
2896 // Single Sequence prediction
2897 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
2901 if (msa.getSequences().length > 1)
2903 // Sequence profile based prediction
2904 new jalview.ws.JPredClient(sh,
2905 title, true, msa, af, true);
2910 secstrmenu.add(method);
2912 wsmenu.add(secstrmenu);
2914 this.webService.removeAll();
2915 for (int i = 0, j = wsmenu.size(); i < j; i++)
2917 webService.add( (JMenu) wsmenu.get(i));
2922 this.webService.removeAll();
2923 this.webService.add(this.webServiceNoServices);
2925 // TODO: add in rediscovery function
2926 // TODO: reduce code redundancy.
2927 // TODO: group services by location as well as function.
2930 /* public void vamsasStore_actionPerformed(ActionEvent e)
2932 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2933 getProperty("LAST_DIRECTORY"));
2935 chooser.setFileView(new JalviewFileView());
2936 chooser.setDialogTitle("Export to Vamsas file");
2937 chooser.setToolTipText("Export");
2939 int value = chooser.showSaveDialog(this);
2941 if (value == JalviewFileChooser.APPROVE_OPTION)
2943 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
2944 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
2945 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
2952 public void showTranslation_actionPerformed(ActionEvent e)
2954 SequenceI [] selection = viewport.getSelectionAsNewSequence();
2955 String [] seqstring = viewport.getViewAsString(true);
2957 int s, sSize = selection.length;
2958 SequenceI [] newSeq = new SequenceI[sSize];
2961 StringBuffer protein;
2963 for(s=0; s<sSize; s++)
2965 protein = new StringBuffer();
2966 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
2967 resSize = seq.length();
2968 resSize -= resSize%3;
2970 for(res = 0; res < resSize; res+=3)
2972 String codon = seq.substring(res, res+3);
2973 codon = codon.replace('U', 'T');
2974 String aa = ResidueProperties.codonTranslate(codon);
2976 protein.append(viewport.getGapCharacter());
2977 else if(aa.equals("STOP"))
2978 protein.append("X");
2980 protein.append( aa );
2982 newSeq[s] = new Sequence(selection[s].getName(),
2983 protein.toString());
2987 AlignmentI al = new Alignment(newSeq);
2988 al.setDataset(null);
2991 ////////////////////////////////
2992 // Copy annotations across
2993 jalview.datamodel.AlignmentAnnotation[] annotations
2994 = viewport.alignment.getAlignmentAnnotation();
2996 if(annotations!=null)
2998 for (int i = 0; i < annotations.length; i++)
3000 if (annotations[i].label.equals("Quality") ||
3001 annotations[i].label.equals("Conservation") ||
3002 annotations[i].label.equals("Consensus"))
3007 aSize = viewport.alignment.getWidth() / 3;
3008 jalview.datamodel.Annotation[] anots =
3009 new jalview.datamodel.Annotation[aSize];
3011 for (a = 0; a < viewport.alignment.getWidth(); a++)
3013 if (annotations[i].annotations[a] == null
3014 || annotations[i].annotations[a] == null)
3017 anots[a / 3] = new Annotation(
3018 annotations[i].annotations[a].displayCharacter,
3019 annotations[i].annotations[a].description,
3020 annotations[i].annotations[a].secondaryStructure,
3021 annotations[i].annotations[a].value,
3022 annotations[i].annotations[a].colour);
3025 jalview.datamodel.AlignmentAnnotation aa
3026 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3027 annotations[i].description, anots);
3028 al.addAnnotation(aa);
3032 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3033 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3045 * @param String DOCUMENT ME!
3047 public boolean parseFeaturesFile(String file, String type)
3049 boolean featuresFile = false;
3051 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3052 alignPanel.seqPanel.seqCanvas.
3053 getFeatureRenderer().featureColours,
3058 ex.printStackTrace();
3063 viewport.showSequenceFeatures = true;
3064 showSeqFeatures.setSelected(true);
3065 alignPanel.repaint();
3068 return featuresFile;
3071 public void dragEnter(DropTargetDragEvent evt)
3074 public void dragExit(DropTargetEvent evt)
3077 public void dragOver(DropTargetDragEvent evt)
3080 public void dropActionChanged(DropTargetDragEvent evt)
3083 public void drop(DropTargetDropEvent evt)
3085 Transferable t = evt.getTransferable();
3086 java.util.List files = null;
3090 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3091 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3093 //Works on Windows and MacOSX
3094 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3095 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3097 else if (t.isDataFlavorSupported(uriListFlavor))
3099 // This is used by Unix drag system
3100 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3101 String data = (String) t.getTransferData(uriListFlavor);
3102 files = new java.util.ArrayList(1);
3103 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3106 st.hasMoreTokens(); )
3108 String s = st.nextToken();
3109 if (s.startsWith("#"))
3111 // the line is a comment (as per the RFC 2483)
3115 java.net.URI uri = new java.net.URI(s);
3116 java.io.File file = new java.io.File(uri);
3123 e.printStackTrace();
3130 for (int i = 0; i < files.size(); i++)
3132 loadJalviewDataFile(files.get(i).toString());
3135 catch (Exception ex)
3137 ex.printStackTrace();
3142 // This method will attempt to load a "dropped" file first by testing
3143 // whether its and Annotation file, then features file. If both are
3144 // false then the user may have dropped an alignment file onto this
3146 public void loadJalviewDataFile(String file)
3149 String protocol = "File";
3151 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3156 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3161 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3164 String format = new IdentifyFile().Identify(file, protocol);
3166 if(format.equalsIgnoreCase("JnetFile"))
3168 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3170 new JnetAnnotationMaker().add_annotation(predictions,
3171 viewport.getAlignment(),
3173 alignPanel.adjustAnnotationHeight();
3174 alignPanel.repaint();
3177 new FileLoader().LoadFile(viewport, file, protocol, format);
3183 alignPanel.adjustAnnotationHeight();
3186 }catch(Exception ex)
3188 ex.printStackTrace();
3192 public void tabSelectionChanged(int index)
3196 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3197 viewport = alignPanel.av;
3201 public void tabbedPane_mousePressed(MouseEvent e)
3203 if(SwingUtilities.isRightMouseButton(e))
3205 String reply = JOptionPane.showInternalInputDialog(this,
3208 JOptionPane.QUESTION_MESSAGE);
3212 viewport.viewName = reply;
3213 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3219 public AlignViewport getCurrentView()