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 int index = viewport.getAlignment().findIndex(seq);
1297 seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);
1299 // If the cut affects all sequences, remove highlighted columns
1300 if (sg.getSize(false) == viewport.alignment.getHeight())
1302 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1303 sg.getEndRes() + 1);
1306 if (seq.getSequence().length() < 1)
1308 viewport.getAlignment().deleteSequence(seq);
1309 PaintRefresher.Refresh(alignPanel,alignPanel.av.getSequenceSetId(),seq,null);
1313 viewport.getAlignment().getSequences().setElementAt(seq, index);
1317 viewport.setSelectionGroup(null);
1318 viewport.alignment.deleteGroup(sg);
1320 viewport.firePropertyChange("alignment", null,
1321 viewport.getAlignment().getSequences());
1325 if (viewport.getAlignment().getHeight() < 1)
1329 this.setClosed(true);
1331 catch (Exception ex)
1340 * @param e DOCUMENT ME!
1342 protected void deleteGroups_actionPerformed(ActionEvent e)
1344 viewport.alignment.deleteAllGroups();
1345 viewport.setSelectionGroup(null);
1346 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1347 alignPanel.repaint();
1353 * @param e DOCUMENT ME!
1355 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1357 SequenceGroup sg = new SequenceGroup();
1359 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1362 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1365 sg.setEndRes(viewport.alignment.getWidth() - 1);
1366 viewport.setSelectionGroup(sg);
1367 alignPanel.repaint();
1368 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1374 * @param e DOCUMENT ME!
1376 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1378 if(viewport.cursorMode)
1380 alignPanel.seqPanel.keyboardNo1 = null;
1381 alignPanel.seqPanel.keyboardNo2 = null;
1383 viewport.setSelectionGroup(null);
1384 viewport.getColumnSelection().clear();
1385 viewport.setSelectionGroup(null);
1386 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1387 alignPanel.idPanel.idCanvas.searchResults = null;
1388 alignPanel.repaint();
1389 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1395 * @param e DOCUMENT ME!
1397 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1399 SequenceGroup sg = viewport.getSelectionGroup();
1403 selectAllSequenceMenuItem_actionPerformed(null);
1408 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1411 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1414 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1417 public void invertColSel_actionPerformed(ActionEvent e)
1419 viewport.invertColumnSelection();
1420 alignPanel.repaint();
1427 * @param e DOCUMENT ME!
1429 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1431 ColumnSelection colSel = viewport.getColumnSelection();
1433 if (colSel.size() > 0)
1436 addHistoryItem(edit=new HistoryItem("Remove Left", viewport.alignment,
1439 int min = colSel.getMin();
1440 viewport.getAlignment().trimLeft(min);
1441 colSel.compensateForEdit(0, min);
1442 edit.addShift(0,min);
1443 if (viewport.getSelectionGroup() != null)
1445 viewport.getSelectionGroup().adjustForRemoveLeft(min);
1448 Vector groups = viewport.alignment.getGroups();
1450 for (int i = 0; i < groups.size(); i++)
1452 SequenceGroup sg = (SequenceGroup) groups.get(i);
1454 if (!sg.adjustForRemoveLeft(min))
1456 viewport.alignment.deleteGroup(sg);
1460 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1467 * @param e DOCUMENT ME!
1469 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1471 ColumnSelection colSel = viewport.getColumnSelection();
1473 if (colSel.size() > 0)
1475 addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
1478 int max = colSel.getMax();
1479 viewport.getAlignment().trimRight(max);
1480 // TODO: delete hidden column entries in colSel to right of max
1481 // TODO: record hidden columns in history for undo.
1482 if (viewport.getSelectionGroup() != null)
1484 viewport.getSelectionGroup().adjustForRemoveRight(max);
1487 Vector groups = viewport.alignment.getGroups();
1489 for (int i = 0; i < groups.size(); i++)
1491 SequenceGroup sg = (SequenceGroup) groups.get(i);
1493 if (!sg.adjustForRemoveRight(max))
1495 viewport.alignment.deleteGroup(sg);
1499 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1506 * @param e DOCUMENT ME!
1508 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1511 addHistoryItem(edit=new HistoryItem("Remove Gapped Columns",
1512 viewport.alignment, HistoryItem.HIDE));
1514 //This is to maintain viewport position on first residue
1516 SequenceI seq = viewport.alignment.getSequenceAt(0);
1517 int startRes = seq.findPosition(viewport.startRes);
1519 viewport.getAlignment().removeGaps(shifts=new ShiftList());
1520 edit.alColumnChanges=shifts.getInverse();
1521 if (viewport.hasHiddenColumns)
1522 viewport.getColumnSelection().compensateForEdits(shifts);
1523 viewport.setStartRes(seq.findIndex(startRes)-1);
1524 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1531 * @param e DOCUMENT ME!
1533 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1535 // TODO: hidden regions should not be touched by removeAllGaps - a minimal number of gaps will remain in alignment segments containing uneven length subsequences
1536 // TODO: columnSelection.compensateforedits should be called (and passed to history item)
1537 addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
1540 //This is to maintain viewport position on first residue
1542 SequenceI seq = viewport.alignment.getSequenceAt(0);
1543 int startRes = seq.findPosition(viewport.startRes);
1551 int end = viewport.alignment.getWidth();
1553 if (viewport.getSelectionGroup() != null
1554 && viewport.getSelectionGroup().getSequences(true) != null
1555 && viewport.getSelectionGroup().getSize(true) > 0)
1557 seqs = viewport.getSelectionGroup().getSequences(true);
1558 start = viewport.getSelectionGroup().getStartRes();
1559 end = viewport.getSelectionGroup().getEndRes()+1;
1563 seqs = viewport.alignment.getSequences();
1565 /* Commented out regions below are partial implementation of todo above.
1566 * divide start,end into visible chunks, and for each:
1567 int diff=end-start+1;
1569 int dr[] = new int[seqs.size()];
1571 for (int i = 0; i < seqs.size(); i++)
1573 current = (SequenceI) seqs.elementAt(i);
1575 current.removeGaps(start, end);
1576 /*if (d<diff) // can only shift
1582 /* // after the end of each chunk -
1584 // record shift for history.
1585 editgaps.addShift(start, diff);
1586 if (viewport.hasHiddenColumns && diffmax>diff) {
1588 StringBuffer gaps=new StringBuffer(diffmax);
1589 for (int i=0,j=diffmax-diff; i<j; i++)
1590 gaps.append(viewport.getGapCharacter());
1591 for (int i=0, j=seqs.size(); i<j; i++) {
1592 current = (SequenceI) seqs.elementAt(i);
1594 String sq = current.getSequence();
1595 current.setSequence(sq.substring(0, hcend-dr[i])+gaps.substring(0, dr[i]-diff)+sq.substring());
1601 viewport.setStartRes(seq.findIndex(startRes)-1);
1603 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1607 public void alignmentChanged()
1612 for(int i=0; i<alignPanels.size(); i++)
1614 ap = (AlignmentPanel) alignPanels.elementAt(i);
1618 av.getAlignment().padGaps();
1620 if (av.hconsensus != null && av.autoCalculateConsensus)
1622 av.updateConsensus(ap);
1623 av.updateConservation(ap);
1624 ap.annotationPanel.repaint();
1627 resetAllColourSchemes();
1629 av.alignment.adjustSequenceAnnotations();
1631 if (ap.overviewPanel != null)
1632 ap.overviewPanel.updateOverviewImage();
1638 void resetAllColourSchemes()
1640 ColourSchemeI cs = viewport.globalColourScheme;
1643 if (cs instanceof ClustalxColourScheme)
1645 ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
1646 resetClustalX(viewport.alignment.getSequences(),
1647 viewport.alignment.getWidth());
1650 cs.setConsensus(viewport.hconsensus);
1651 if (cs.conservationApplied())
1653 Alignment al = (Alignment) viewport.alignment;
1654 Conservation c = new Conservation("All",
1655 ResidueProperties.propHash, 3,
1656 al.getSequences(), 0,
1659 c.verdict(false, viewport.ConsPercGaps);
1661 cs.setConservation(c);
1665 int s, sSize = viewport.alignment.getGroups().size();
1666 for(s=0; s<sSize; s++)
1668 SequenceGroup sg = (SequenceGroup)viewport.alignment.getGroups().elementAt(s);
1669 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
1671 ((ClustalxColourScheme)sg.cs).resetClustalX(
1672 sg.getSequences(true), sg.getWidth());
1674 sg.recalcConservation();
1681 * @param e DOCUMENT ME!
1683 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1685 addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,
1688 viewport.padGaps = padGapsMenuitem.isSelected();
1690 viewport.firePropertyChange("alignment",
1692 viewport.getAlignment().getSequences());
1698 * @param e DOCUMENT ME!
1700 public void findMenuItem_actionPerformed(ActionEvent e)
1702 JInternalFrame frame = new JInternalFrame();
1703 Finder finder = new Finder(viewport, alignPanel, frame);
1704 frame.setContentPane(finder);
1705 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1706 Desktop.addInternalFrame(frame, "Find", 340, 110);
1712 * @param e DOCUMENT ME!
1714 public void font_actionPerformed(ActionEvent e)
1716 new FontChooser(alignPanel);
1719 public void smoothFont_actionPerformed(ActionEvent e)
1721 viewport.antiAlias = smoothFont.isSelected();
1722 alignPanel.annotationPanel.image = null;
1723 alignPanel.repaint();
1730 * @param e DOCUMENT ME!
1732 protected void seqLimit_actionPerformed(ActionEvent e)
1734 viewport.setShowJVSuffix(seqLimits.isSelected());
1736 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1737 alignPanel.repaint();
1744 * @param e DOCUMENT ME!
1746 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1748 viewport.setColourText(colourTextMenuItem.isSelected());
1749 alignPanel.repaint();
1755 * @param e DOCUMENT ME!
1757 public void wrapMenuItem_actionPerformed(ActionEvent e)
1759 scaleAbove.setVisible(wrapMenuItem.isSelected());
1760 scaleLeft.setVisible(wrapMenuItem.isSelected());
1761 scaleRight.setVisible(wrapMenuItem.isSelected());
1762 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1763 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1766 public void showAllSeqs_actionPerformed(ActionEvent e)
1768 viewport.showAllHiddenSeqs();
1771 public void showAllColumns_actionPerformed(ActionEvent e)
1773 viewport.showAllHiddenColumns();
1777 public void hideSelSequences_actionPerformed(ActionEvent e)
1779 viewport.hideAllSelectedSeqs();
1780 alignPanel.repaint();
1783 public void hideSelColumns_actionPerformed(ActionEvent e)
1785 viewport.hideSelectedColumns();
1786 alignPanel.repaint();
1789 public void hiddenMarkers_actionPerformed(ActionEvent e)
1791 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1798 * @param e DOCUMENT ME!
1800 protected void scaleAbove_actionPerformed(ActionEvent e)
1802 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1803 alignPanel.repaint();
1809 * @param e DOCUMENT ME!
1811 protected void scaleLeft_actionPerformed(ActionEvent e)
1813 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1814 alignPanel.repaint();
1820 * @param e DOCUMENT ME!
1822 protected void scaleRight_actionPerformed(ActionEvent e)
1824 viewport.setScaleRightWrapped(scaleRight.isSelected());
1825 alignPanel.repaint();
1831 * @param e DOCUMENT ME!
1833 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1835 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1836 alignPanel.repaint();
1842 * @param e DOCUMENT ME!
1844 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1846 viewport.setShowText(viewTextMenuItem.isSelected());
1847 alignPanel.repaint();
1853 * @param e DOCUMENT ME!
1855 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1857 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1858 alignPanel.repaint();
1862 public FeatureSettings featureSettings;
1863 public void featureSettings_actionPerformed(ActionEvent e)
1865 if(featureSettings !=null )
1867 featureSettings.close();
1868 featureSettings = null;
1870 featureSettings = new FeatureSettings(this);
1876 * @param evt DOCUMENT ME!
1878 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1880 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1881 alignPanel.repaint();
1882 if (alignPanel.getOverviewPanel() != null)
1884 alignPanel.getOverviewPanel().updateOverviewImage();
1891 * @param e DOCUMENT ME!
1893 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1895 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1896 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1902 * @param e DOCUMENT ME!
1904 public void overviewMenuItem_actionPerformed(ActionEvent e)
1906 if (alignPanel.overviewPanel != null)
1911 JInternalFrame frame = new JInternalFrame();
1912 OverviewPanel overview = new OverviewPanel(alignPanel);
1913 frame.setContentPane(overview);
1914 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1915 frame.getWidth(), frame.getHeight());
1917 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1918 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1920 public void internalFrameClosed(
1921 javax.swing.event.InternalFrameEvent evt)
1923 alignPanel.setOverviewPanel(null);
1928 alignPanel.setOverviewPanel(overview);
1934 * @param e DOCUMENT ME!
1936 protected void noColourmenuItem_actionPerformed(ActionEvent e)
1944 * @param e DOCUMENT ME!
1946 public void clustalColour_actionPerformed(ActionEvent e)
1948 changeColour(new ClustalxColourScheme(
1949 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
1955 * @param e DOCUMENT ME!
1957 public void zappoColour_actionPerformed(ActionEvent e)
1959 changeColour(new ZappoColourScheme());
1965 * @param e DOCUMENT ME!
1967 public void taylorColour_actionPerformed(ActionEvent e)
1969 changeColour(new TaylorColourScheme());
1975 * @param e DOCUMENT ME!
1977 public void hydrophobicityColour_actionPerformed(ActionEvent e)
1979 changeColour(new HydrophobicColourScheme());
1985 * @param e DOCUMENT ME!
1987 public void helixColour_actionPerformed(ActionEvent e)
1989 changeColour(new HelixColourScheme());
1995 * @param e DOCUMENT ME!
1997 public void strandColour_actionPerformed(ActionEvent e)
1999 changeColour(new StrandColourScheme());
2005 * @param e DOCUMENT ME!
2007 public void turnColour_actionPerformed(ActionEvent e)
2009 changeColour(new TurnColourScheme());
2015 * @param e DOCUMENT ME!
2017 public void buriedColour_actionPerformed(ActionEvent e)
2019 changeColour(new BuriedColourScheme());
2025 * @param e DOCUMENT ME!
2027 public void nucleotideColour_actionPerformed(ActionEvent e)
2029 changeColour(new NucleotideColourScheme());
2032 public void annotationColour_actionPerformed(ActionEvent e)
2034 new AnnotationColourChooser(viewport, alignPanel);
2041 * @param e DOCUMENT ME!
2043 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2045 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2051 * @param cs DOCUMENT ME!
2053 public void changeColour(ColourSchemeI cs)
2059 if (viewport.getAbovePIDThreshold())
2061 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2064 cs.setThreshold(threshold,
2065 viewport.getIgnoreGapsConsensus());
2067 viewport.setGlobalColourScheme(cs);
2071 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2074 if (viewport.getConservationSelected())
2077 Alignment al = (Alignment) viewport.alignment;
2078 Conservation c = new Conservation("All",
2079 ResidueProperties.propHash, 3,
2080 al.getSequences(), 0,
2084 c.verdict(false, viewport.ConsPercGaps);
2086 cs.setConservation(c);
2088 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2093 cs.setConservation(null);
2096 cs.setConsensus(viewport.hconsensus);
2099 viewport.setGlobalColourScheme(cs);
2101 if (viewport.getColourAppliesToAllGroups())
2103 Vector groups = viewport.alignment.getGroups();
2105 for (int i = 0; i < groups.size(); i++)
2107 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2115 if (cs instanceof ClustalxColourScheme)
2117 sg.cs = new ClustalxColourScheme(
2118 sg.getSequences(true), sg.getWidth());
2120 else if (cs instanceof UserColourScheme)
2122 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2128 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2130 catch (Exception ex)
2135 if (viewport.getAbovePIDThreshold()
2136 || cs instanceof PIDColourScheme
2137 || cs instanceof Blosum62ColourScheme)
2139 sg.cs.setThreshold(threshold,
2140 viewport.getIgnoreGapsConsensus());
2142 sg.cs.setConsensus(AAFrequency.calculate(
2143 sg.getSequences(true), 0,
2147 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2150 if (viewport.getConservationSelected())
2152 Conservation c = new Conservation("Group",
2153 ResidueProperties.propHash, 3,
2154 sg.getSequences(true), 0,
2155 viewport.alignment.getWidth() - 1);
2157 c.verdict(false, viewport.ConsPercGaps);
2158 sg.cs.setConservation(c);
2161 sg.cs.setConservation(null);
2165 if (alignPanel.getOverviewPanel() != null)
2167 alignPanel.getOverviewPanel().updateOverviewImage();
2170 alignPanel.repaint();
2176 * @param e DOCUMENT ME!
2178 protected void modifyPID_actionPerformed(ActionEvent e)
2180 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2182 SliderPanel.setPIDSliderSource(alignPanel,
2183 viewport.getGlobalColourScheme(),
2185 SliderPanel.showPIDSlider();
2192 * @param e DOCUMENT ME!
2194 protected void modifyConservation_actionPerformed(ActionEvent e)
2196 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2198 SliderPanel.setConservationSlider(alignPanel,
2199 viewport.globalColourScheme,
2201 SliderPanel.showConservationSlider();
2208 * @param e DOCUMENT ME!
2210 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2212 viewport.setConservationSelected(conservationMenuItem.isSelected());
2214 viewport.setAbovePIDThreshold(false);
2215 abovePIDThreshold.setSelected(false);
2217 changeColour(viewport.getGlobalColourScheme());
2219 modifyConservation_actionPerformed(null);
2225 * @param e DOCUMENT ME!
2227 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2229 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2231 conservationMenuItem.setSelected(false);
2232 viewport.setConservationSelected(false);
2234 changeColour(viewport.getGlobalColourScheme());
2236 modifyPID_actionPerformed(null);
2242 * @param e DOCUMENT ME!
2244 public void userDefinedColour_actionPerformed(ActionEvent e)
2246 if (e.getActionCommand().equals("User Defined..."))
2248 new UserDefinedColours(alignPanel, null);
2252 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2253 getUserColourSchemes().get(e.getActionCommand());
2259 public void updateUserColourMenu()
2262 Component[] menuItems = colourMenu.getMenuComponents();
2263 int i, iSize = menuItems.length;
2264 for (i = 0; i < iSize; i++)
2266 if (menuItems[i].getName() != null &&
2267 menuItems[i].getName().equals("USER_DEFINED"))
2269 colourMenu.remove(menuItems[i]);
2273 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2275 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2276 getUserColourSchemes().keys();
2278 while (userColours.hasMoreElements())
2280 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2281 nextElement().toString());
2282 radioItem.setName("USER_DEFINED");
2283 radioItem.addMouseListener(new MouseAdapter()
2285 public void mousePressed(MouseEvent evt)
2287 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2289 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2291 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2292 "Remove from default list?",
2293 "Remove user defined colour",
2294 JOptionPane.YES_NO_OPTION);
2295 if(option == JOptionPane.YES_OPTION)
2297 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2298 colourMenu.remove(radioItem);
2301 radioItem.addActionListener(new ActionListener()
2303 public void actionPerformed(ActionEvent evt)
2305 userDefinedColour_actionPerformed(evt);
2311 radioItem.addActionListener(new ActionListener()
2313 public void actionPerformed(ActionEvent evt)
2315 userDefinedColour_actionPerformed(evt);
2319 colourMenu.insert(radioItem, 15);
2320 colours.add(radioItem);
2328 * @param e DOCUMENT ME!
2330 public void PIDColour_actionPerformed(ActionEvent e)
2332 changeColour(new PIDColourScheme());
2338 * @param e DOCUMENT ME!
2340 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2342 changeColour(new Blosum62ColourScheme());
2348 * @param e DOCUMENT ME!
2350 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2352 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,
2354 AlignmentSorter.sortByPID(viewport.getAlignment(),
2355 viewport.getAlignment().getSequenceAt(0));
2356 alignPanel.repaint();
2362 * @param e DOCUMENT ME!
2364 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2366 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,
2368 AlignmentSorter.sortByID(viewport.getAlignment());
2369 alignPanel.repaint();
2375 * @param e DOCUMENT ME!
2377 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2379 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,
2382 AlignmentSorter.sortByGroup(viewport.getAlignment());
2383 alignPanel.repaint();
2389 * @param e DOCUMENT ME!
2391 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2393 new RedundancyPanel(alignPanel, this);
2400 * @param e DOCUMENT ME!
2402 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2404 if ( (viewport.getSelectionGroup() == null) ||
2405 (viewport.getSelectionGroup().getSize(false) < 2))
2407 JOptionPane.showInternalMessageDialog(this,
2408 "You must select at least 2 sequences.",
2409 "Invalid Selection",
2410 JOptionPane.WARNING_MESSAGE);
2414 JInternalFrame frame = new JInternalFrame();
2415 frame.setContentPane(new PairwiseAlignPanel(viewport));
2416 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2423 * @param e DOCUMENT ME!
2425 public void PCAMenuItem_actionPerformed(ActionEvent e)
2427 if ( ( (viewport.getSelectionGroup() != null) &&
2428 (viewport.getSelectionGroup().getSize(false) < 4) &&
2429 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2430 (viewport.getAlignment().getHeight() < 4))
2432 JOptionPane.showInternalMessageDialog(this,
2433 "Principal component analysis must take\n" +
2434 "at least 4 input sequences.",
2435 "Sequence selection insufficient",
2436 JOptionPane.WARNING_MESSAGE);
2441 new PCAPanel(viewport);
2445 public void autoCalculate_actionPerformed(ActionEvent e)
2447 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2448 if(viewport.autoCalculateConsensus)
2450 viewport.firePropertyChange("alignment",
2452 viewport.getAlignment().getSequences());
2460 * @param e DOCUMENT ME!
2462 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2464 NewTreePanel("AV", "PID", "Average distance tree using PID");
2470 * @param e DOCUMENT ME!
2472 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2474 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2480 * @param e DOCUMENT ME!
2482 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2484 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2490 * @param e DOCUMENT ME!
2492 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2494 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2500 * @param type DOCUMENT ME!
2501 * @param pwType DOCUMENT ME!
2502 * @param title DOCUMENT ME!
2504 void NewTreePanel(String type, String pwType, String title)
2508 if (viewport.getSelectionGroup() != null) {
2509 if (viewport.getSelectionGroup().getSize(false) < 3) {
2510 JOptionPane.showMessageDialog(Desktop.desktop,
2511 "You need to have more than two sequences selected to build a tree!",
2512 "Not enough sequences",
2513 JOptionPane.WARNING_MESSAGE);
2518 SequenceGroup sg = viewport.getSelectionGroup();
2520 /* Decide if the selection is a column region */
2521 while (s < sg.getSize(false))
2523 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2526 JOptionPane.showMessageDialog(Desktop.desktop,
2527 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2528 "Try using the Pad function in the edit menu,\n" +
2529 "or one of the multiple sequence alignment web services.",
2530 "Sequences in selection are not aligned",
2531 JOptionPane.WARNING_MESSAGE);
2537 title = title + " on region";
2538 tp = new TreePanel(alignPanel, type, pwType);
2542 //are the sequences aligned?
2543 if (!viewport.alignment.isAligned())
2545 JOptionPane.showMessageDialog(Desktop.desktop,
2546 "The sequences must be aligned before creating a tree.\n" +
2547 "Try using the Pad function in the edit menu,\n" +
2548 "or one of the multiple sequence alignment web services.",
2549 "Sequences not aligned",
2550 JOptionPane.WARNING_MESSAGE);
2555 if(viewport.alignment.getHeight()<2)
2558 tp = new TreePanel(alignPanel, type, pwType);
2561 addTreeMenuItem(tp, title);
2563 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2569 * @param title DOCUMENT ME!
2570 * @param order DOCUMENT ME!
2572 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2574 final JMenuItem item = new JMenuItem("by " + title);
2576 item.addActionListener(new java.awt.event.ActionListener()
2578 public void actionPerformed(ActionEvent e)
2580 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2583 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2584 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2585 alignPanel.repaint();
2591 * Maintain the Order by->Displayed Tree menu.
2592 * Creates a new menu item for a TreePanel with an appropriate
2593 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2594 * to remove the menu item when the treePanel is closed, and adjust
2595 * the tree leaf to sequence mapping when the alignment is modified.
2596 * @param treePanel Displayed tree window.
2597 * @param title SortBy menu item title.
2599 void addTreeMenuItem(final TreePanel treePanel, String title)
2601 final JMenuItem item = new JMenuItem(title);
2607 sort.add(sortByTreeMenu);
2610 sortByTreeMenu.add(item);
2611 item.addActionListener(new java.awt.event.ActionListener()
2613 public void actionPerformed(ActionEvent e)
2615 addHistoryItem(new HistoryItem("Tree Sort",
2616 viewport.alignment, HistoryItem.SORT));
2617 AlignmentSorter.sortByTree(viewport.getAlignment(),
2618 treePanel.getTree());
2619 alignPanel.repaint();
2623 treePanel.addInternalFrameListener(new javax.swing.event.
2624 InternalFrameAdapter()
2626 public void internalFrameClosed(
2627 javax.swing.event.InternalFrameEvent evt)
2630 sortByTreeMenu.remove(item);
2634 sort.remove(sortByTreeMenu);
2642 * Work out whether the whole set of sequences
2643 * or just the selected set will be submitted for multiple alignment.
2646 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2648 // Now, check we have enough sequences
2649 AlignmentView msa = null;
2651 if ( (viewport.getSelectionGroup() != null) &&
2652 (viewport.getSelectionGroup().getSize(false) > 1))
2654 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2655 /*SequenceGroup seqs = viewport.getSelectionGroup();
2657 msa = new SequenceI[sz = seqs.getSize(false)];
2659 for (int i = 0; i < sz; i++)
2661 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2663 msa = viewport.getAlignmentView(true);
2667 /*Vector seqs = viewport.getAlignment().getSequences();
2669 if (seqs.size() > 1)
2671 msa = new SequenceI[seqs.size()];
2673 for (int i = 0; i < seqs.size(); i++)
2675 msa[i] = (SequenceI) seqs.elementAt(i);
2678 msa = viewport.getAlignmentView(false);
2684 * Decides what is submitted to a secondary structure prediction service,
2685 * the currently selected sequence, or the currently selected alignment
2686 * (where the first sequence in the set is the one that the prediction
2689 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2691 AlignmentView seqs = null;
2693 if ( (viewport.getSelectionGroup() != null) &&
2694 (viewport.getSelectionGroup().getSize(false) > 0))
2696 seqs = viewport.getAlignmentView(true);
2700 seqs = viewport.getAlignmentView(false);
2702 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2703 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2704 if (!viewport.alignment.isAligned())
2706 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2713 * @param e DOCUMENT ME!
2715 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2717 // Pick the tree file
2718 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2721 chooser.setFileView(new JalviewFileView());
2722 chooser.setDialogTitle("Select a newick-like tree file");
2723 chooser.setToolTipText("Load a tree file");
2725 int value = chooser.showOpenDialog(null);
2727 if (value == JalviewFileChooser.APPROVE_OPTION)
2729 String choice = chooser.getSelectedFile().getPath();
2730 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2734 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2736 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2738 catch (Exception ex)
2740 JOptionPane.showMessageDialog(Desktop.desktop,
2741 "Problem reading tree file",
2743 JOptionPane.WARNING_MESSAGE);
2744 ex.printStackTrace();
2750 public TreePanel ShowNewickTree(NewickFile nf, String title)
2752 return ShowNewickTree(nf,title,600,500,4,5);
2754 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2756 return ShowNewickTree(nf,title, input, 600,500,4,5);
2758 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2759 return ShowNewickTree(nf, title, null, w, h, x, y);
2762 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2764 * @param nf the tree
2765 * @param title tree viewer title
2766 * @param input Associated alignment input data (or null)
2771 * @return TreePanel handle
2773 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2774 TreePanel tp = null;
2780 if (nf.getTree() != null)
2782 tp = new TreePanel(alignPanel,
2790 tp.setLocation(x,y);
2793 Desktop.addInternalFrame(tp, title, w, h);
2794 addTreeMenuItem(tp, title);
2797 catch (Exception ex)
2799 ex.printStackTrace();
2810 PrinterJob printJob = PrinterJob.getPrinterJob();
2811 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2812 printJob.setPrintable(alignPanel, pf);
2814 if (printJob.printDialog())
2820 catch (Exception PrintException)
2822 PrintException.printStackTrace();
2829 * Generates menu items and listener event actions for web service clients
2832 public void BuildWebServiceMenu()
2834 if ( (Discoverer.services != null)
2835 && (Discoverer.services.size() > 0))
2837 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2838 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2839 Vector wsmenu = new Vector();
2840 final AlignFrame af = this;
2843 // Add any Multiple Sequence Alignment Services
2844 final JMenu msawsmenu = new JMenu("Alignment");
2845 for (int i = 0, j = msaws.size(); i < j; i++)
2847 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2849 final JMenuItem method = new JMenuItem(sh.getName());
2850 method.addActionListener(new ActionListener()
2852 public void actionPerformed(ActionEvent e)
2854 AlignmentView msa = gatherSequencesForAlignment();
2855 new jalview.ws.MsaWSClient(sh, title, msa,
2856 false, true, viewport.getAlignment().getDataset(), af);
2861 msawsmenu.add(method);
2862 // Deal with services that we know accept partial alignments.
2863 if (sh.getName().indexOf("lustal") > -1)
2865 // We know that ClustalWS can accept partial alignments for refinement.
2866 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2867 methodR.addActionListener(new ActionListener()
2869 public void actionPerformed(ActionEvent e)
2871 AlignmentView msa = gatherSequencesForAlignment();
2872 new jalview.ws.MsaWSClient(sh, title, msa,
2873 true, true, viewport.getAlignment().getDataset(), af);
2878 msawsmenu.add(methodR);
2882 wsmenu.add(msawsmenu);
2884 if (secstrpr != null)
2886 // Add any secondary structure prediction services
2887 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2888 for (int i = 0, j = secstrpr.size(); i < j; i++)
2890 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2892 final JMenuItem method = new JMenuItem(sh.getName());
2893 method.addActionListener(new ActionListener()
2895 public void actionPerformed(ActionEvent e)
2897 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2898 if (msa.getSequences().length == 1)
2900 // Single Sequence prediction
2901 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
2905 if (msa.getSequences().length > 1)
2907 // Sequence profile based prediction
2908 new jalview.ws.JPredClient(sh,
2909 title, true, msa, af, true);
2914 secstrmenu.add(method);
2916 wsmenu.add(secstrmenu);
2918 this.webService.removeAll();
2919 for (int i = 0, j = wsmenu.size(); i < j; i++)
2921 webService.add( (JMenu) wsmenu.get(i));
2926 this.webService.removeAll();
2927 this.webService.add(this.webServiceNoServices);
2929 // TODO: add in rediscovery function
2930 // TODO: reduce code redundancy.
2931 // TODO: group services by location as well as function.
2934 /* public void vamsasStore_actionPerformed(ActionEvent e)
2936 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2937 getProperty("LAST_DIRECTORY"));
2939 chooser.setFileView(new JalviewFileView());
2940 chooser.setDialogTitle("Export to Vamsas file");
2941 chooser.setToolTipText("Export");
2943 int value = chooser.showSaveDialog(this);
2945 if (value == JalviewFileChooser.APPROVE_OPTION)
2947 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
2948 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
2949 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
2956 public void showTranslation_actionPerformed(ActionEvent e)
2958 SequenceI [] selection = viewport.getSelectionAsNewSequence();
2959 String [] seqstring = viewport.getViewAsString(true);
2961 int s, sSize = selection.length;
2962 SequenceI [] newSeq = new SequenceI[sSize];
2965 StringBuffer protein;
2967 for(s=0; s<sSize; s++)
2969 protein = new StringBuffer();
2970 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
2971 resSize = seq.length();
2972 resSize -= resSize%3;
2974 for(res = 0; res < resSize; res+=3)
2976 String codon = seq.substring(res, res+3);
2977 codon = codon.replace('U', 'T');
2978 String aa = ResidueProperties.codonTranslate(codon);
2980 protein.append(viewport.getGapCharacter());
2981 else if(aa.equals("STOP"))
2982 protein.append("X");
2984 protein.append( aa );
2986 newSeq[s] = new Sequence(selection[s].getName(),
2987 protein.toString());
2991 AlignmentI al = new Alignment(newSeq);
2992 al.setDataset(null);
2995 ////////////////////////////////
2996 // Copy annotations across
2997 jalview.datamodel.AlignmentAnnotation[] annotations
2998 = viewport.alignment.getAlignmentAnnotation();
3000 if(annotations!=null)
3002 for (int i = 0; i < annotations.length; i++)
3004 if (annotations[i].label.equals("Quality") ||
3005 annotations[i].label.equals("Conservation") ||
3006 annotations[i].label.equals("Consensus"))
3011 aSize = viewport.alignment.getWidth() / 3;
3012 jalview.datamodel.Annotation[] anots =
3013 new jalview.datamodel.Annotation[aSize];
3015 for (a = 0; a < viewport.alignment.getWidth(); a++)
3017 if (annotations[i].annotations[a] == null
3018 || annotations[i].annotations[a] == null)
3021 anots[a / 3] = new Annotation(
3022 annotations[i].annotations[a].displayCharacter,
3023 annotations[i].annotations[a].description,
3024 annotations[i].annotations[a].secondaryStructure,
3025 annotations[i].annotations[a].value,
3026 annotations[i].annotations[a].colour);
3029 jalview.datamodel.AlignmentAnnotation aa
3030 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3031 annotations[i].description, anots);
3032 al.addAnnotation(aa);
3036 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3037 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3049 * @param String DOCUMENT ME!
3051 public boolean parseFeaturesFile(String file, String type)
3053 boolean featuresFile = false;
3055 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3056 alignPanel.seqPanel.seqCanvas.
3057 getFeatureRenderer().featureColours,
3062 ex.printStackTrace();
3067 viewport.showSequenceFeatures = true;
3068 showSeqFeatures.setSelected(true);
3069 alignPanel.repaint();
3072 return featuresFile;
3075 public void dragEnter(DropTargetDragEvent evt)
3078 public void dragExit(DropTargetEvent evt)
3081 public void dragOver(DropTargetDragEvent evt)
3084 public void dropActionChanged(DropTargetDragEvent evt)
3087 public void drop(DropTargetDropEvent evt)
3089 Transferable t = evt.getTransferable();
3090 java.util.List files = null;
3094 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3095 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3097 //Works on Windows and MacOSX
3098 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3099 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3101 else if (t.isDataFlavorSupported(uriListFlavor))
3103 // This is used by Unix drag system
3104 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3105 String data = (String) t.getTransferData(uriListFlavor);
3106 files = new java.util.ArrayList(1);
3107 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3110 st.hasMoreTokens(); )
3112 String s = st.nextToken();
3113 if (s.startsWith("#"))
3115 // the line is a comment (as per the RFC 2483)
3119 java.net.URI uri = new java.net.URI(s);
3120 java.io.File file = new java.io.File(uri);
3127 e.printStackTrace();
3134 for (int i = 0; i < files.size(); i++)
3136 loadJalviewDataFile(files.get(i).toString());
3139 catch (Exception ex)
3141 ex.printStackTrace();
3146 // This method will attempt to load a "dropped" file first by testing
3147 // whether its and Annotation file, then features file. If both are
3148 // false then the user may have dropped an alignment file onto this
3150 public void loadJalviewDataFile(String file)
3153 String protocol = "File";
3155 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3160 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3165 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3168 String format = new IdentifyFile().Identify(file, protocol);
3170 if(format.equalsIgnoreCase("JnetFile"))
3172 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3174 new JnetAnnotationMaker().add_annotation(predictions,
3175 viewport.getAlignment(),
3177 alignPanel.adjustAnnotationHeight();
3178 alignPanel.repaint();
3181 new FileLoader().LoadFile(viewport, file, protocol, format);
3187 alignPanel.adjustAnnotationHeight();
3190 }catch(Exception ex)
3192 ex.printStackTrace();
3196 public void tabSelectionChanged(int index)
3200 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3201 viewport = alignPanel.av;
3205 public void tabbedPane_mousePressed(MouseEvent e)
3207 if(SwingUtilities.isRightMouseButton(e))
3209 String reply = JOptionPane.showInternalInputDialog(this,
3212 JOptionPane.QUESTION_MESSAGE);
3216 viewport.viewName = reply;
3217 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3223 public AlignViewport getCurrentView()