2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Softwarechang
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import java.beans.*;
\r
26 import java.awt.datatransfer.*;
\r
27 import java.awt.event.*;
\r
28 import java.awt.print.*;
\r
29 import javax.swing.*;
\r
31 import jalview.analysis.*;
\r
32 import jalview.datamodel.*;
\r
33 import jalview.io.*;
\r
34 import jalview.jbgui.*;
\r
35 import jalview.schemes.*;
\r
36 import jalview.ws.*;
\r
37 import java.awt.dnd.*;
\r
38 import org.biojava.dasobert.eventmodel.*;
\r
45 * @version $Revision$
\r
47 public class AlignFrame
\r
48 extends GAlignFrame implements DropTargetListener, FeatureListener
\r
50 /** DOCUMENT ME!! */
\r
51 public static final int NEW_WINDOW_WIDTH = 700;
\r
53 /** DOCUMENT ME!! */
\r
54 public static final int NEW_WINDOW_HEIGHT = 500;
\r
55 AlignmentPanel alignPanel;
\r
56 AlignViewport viewport;
\r
58 /** DOCUMENT ME!! */
\r
59 public String currentFileFormat = null;
\r
60 Stack historyList = new Stack();
\r
61 Stack redoList = new Stack();
\r
62 private int treeCount = 0;
\r
66 * Creates a new AlignFrame object.
\r
68 * @param al DOCUMENT ME!
\r
70 public AlignFrame(AlignmentI al)
\r
72 viewport = new AlignViewport(al);
\r
74 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
\r
76 if(viewport.vconsensus==null)
\r
78 //Out of memory calculating consensus.
\r
79 BLOSUM62Colour.setEnabled(false);
\r
80 PIDColour.setEnabled(false);
\r
81 conservationMenuItem.setEnabled(false);
\r
82 modifyConservation.setEnabled(false);
\r
83 abovePIDThreshold.setEnabled(false);
\r
84 modifyPID.setEnabled(false);
\r
87 alignPanel = new AlignmentPanel(this, viewport);
\r
89 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
\r
91 if(sortby.equals("Id"))
\r
92 sortIDMenuItem_actionPerformed(null);
\r
93 else if(sortby.equals("Pairwise Identity"))
\r
94 sortPairwiseMenuItem_actionPerformed(null);
\r
96 // remove(tabbedPane);
\r
97 getContentPane().add(alignPanel, BorderLayout.CENTER);
\r
101 // tabbedPane.add(al.isNucleotide() ? "DNA":"Protein", alignPanel);
\r
104 /////////////////////////
\r
105 if(al.getDataset()==null)
\r
107 al.setDataset(null);
\r
109 // AlignViewport ds = new AlignViewport(al.getDataset(), true);
\r
110 // AlignmentPanel dap = new AlignmentPanel(this, ds);
\r
111 // tabbedPane.add("Dataset", dap);
\r
112 // viewports.add(ds);
\r
113 // alignPanels.add(dap);
\r
114 /////////////////////////
\r
117 viewport.addPropertyChangeListener(new PropertyChangeListener()
\r
119 public void propertyChange(PropertyChangeEvent evt)
\r
121 if (evt.getPropertyName().equals("alignment"))
\r
123 alignmentChanged();
\r
129 if (Desktop.desktop != null)
\r
131 addServiceListeners();
\r
132 setGUINucleotide(al.isNucleotide());
\r
136 if (jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false))
\r
138 wrapMenuItem.setSelected(true);
\r
139 wrapMenuItem_actionPerformed(null);
\r
144 public AlignViewport getViewport()
\r
149 /* Set up intrinsic listeners for dynamically generated GUI bits. */
\r
150 private void addServiceListeners()
\r
152 final java.beans.PropertyChangeListener thisListener;
\r
153 // Do this once to get current state
\r
154 BuildWebServiceMenu();
\r
155 Desktop.discoverer.addPropertyChangeListener(
\r
156 thisListener = new java.beans.PropertyChangeListener()
\r
158 public void propertyChange(PropertyChangeEvent evt)
\r
160 // System.out.println("Discoverer property change.");
\r
161 if (evt.getPropertyName().equals("services"))
\r
163 // System.out.println("Rebuilding web service menu");
\r
164 BuildWebServiceMenu();
\r
168 addInternalFrameListener(new javax.swing.event.
\r
169 InternalFrameAdapter()
\r
171 public void internalFrameClosed(
\r
172 javax.swing.event.InternalFrameEvent evt)
\r
174 // System.out.println("deregistering discoverer listener");
\r
175 Desktop.discoverer.removePropertyChangeListener(thisListener);
\r
176 closeMenuItem_actionPerformed(null);
\r
182 public void setGUINucleotide(boolean nucleotide)
\r
184 showTranslation.setVisible( nucleotide );
\r
185 //sequenceFeatures.setVisible(!nucleotide );
\r
186 //featureSettings.setVisible( !nucleotide );
\r
187 conservationMenuItem.setVisible( !nucleotide );
\r
188 modifyConservation.setVisible( !nucleotide );
\r
190 //Remember AlignFrame always starts as protein
\r
193 calculateMenu.remove(calculateMenu.getItemCount()-2);
\r
197 public void comeBackLater(FeatureEvent evt)
\r
200 public void newFeatures(FeatureEvent evt)
\r
202 if (evt.getFeatures().length > 0)
\r
204 alignPanel.seqPanel.seqCanvas.fr.featuresAdded();
\r
205 alignPanel.repaint();
\r
206 if(featureSettings!=null)
\r
207 featureSettings.setTableData();
\r
211 Hashtable progressBars;
\r
212 public void setProgressBar(String message, long id)
\r
214 if(progressBars == null)
\r
215 progressBars = new Hashtable();
\r
217 JPanel progressPanel;
\r
218 GridLayout layout = (GridLayout) statusPanel.getLayout();
\r
219 if(progressBars.get( new Long(id) )!=null)
\r
221 progressPanel = (JPanel)progressBars.get( new Long(id) );
\r
222 statusPanel.remove(progressPanel);
\r
223 progressBars.remove( progressPanel );
\r
224 progressPanel = null;
\r
226 statusBar.setText(message);
\r
228 layout.setRows(layout.getRows() - 1);
\r
232 progressPanel = new JPanel(new BorderLayout(10, 5));
\r
234 JProgressBar progressBar = new JProgressBar();
\r
235 progressBar.setIndeterminate(true);
\r
237 progressPanel.add(new JLabel(message), BorderLayout.WEST);
\r
238 progressPanel.add(progressBar, BorderLayout.CENTER);
\r
240 layout.setRows(layout.getRows() + 1);
\r
241 statusPanel.add(progressPanel);
\r
243 progressBars.put(new Long(id), progressPanel);
\r
251 Added so Castor Mapping file can obtain Jalview Version
\r
253 public String getVersion()
\r
255 return jalview.bin.Cache.getProperty("VERSION");
\r
258 public FeatureRenderer getFeatureRenderer()
\r
260 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
\r
264 public void fetchSequence_actionPerformed(ActionEvent e)
\r
266 new SequenceFetcher(this);
\r
269 public void addFromFile_actionPerformed(ActionEvent e)
\r
271 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
\r
274 public void addFromText_actionPerformed(ActionEvent e)
\r
276 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
\r
279 public void addFromURL_actionPerformed(ActionEvent e)
\r
281 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
\r
287 * @param e DOCUMENT ME!
\r
289 public void saveAlignmentMenu_actionPerformed(ActionEvent e)
\r
291 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
\r
292 getProperty( "LAST_DIRECTORY"),
\r
294 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
\r
296 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
\r
301 chooser.setFileView(new JalviewFileView());
\r
302 chooser.setDialogTitle("Save Alignment to file");
\r
303 chooser.setToolTipText("Save");
\r
305 int value = chooser.showSaveDialog(this);
\r
307 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
309 currentFileFormat = chooser.getSelectedFormat();
\r
311 if (currentFileFormat == null)
\r
313 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
314 "You must select a file format before saving!",
\r
315 "File format not specified",
\r
316 JOptionPane.WARNING_MESSAGE);
\r
317 value = chooser.showSaveDialog(this);
\r
321 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
\r
322 currentFileFormat);
\r
324 String choice = chooser.getSelectedFile().getPath();
\r
325 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
\r
327 saveAlignment(choice, currentFileFormat);
\r
331 public boolean saveAlignment(String file, String format)
\r
333 if (format.equalsIgnoreCase("Jalview"))
\r
335 String shortName = title;
\r
337 if (shortName.indexOf(java.io.File.separatorChar) > -1)
\r
339 shortName = shortName.substring(shortName.lastIndexOf(
\r
340 java.io.File.separatorChar) + 1);
\r
343 new Jalview2XML().SaveAlignment(this, file, shortName);
\r
345 // USE Jalview2XML to save this file
\r
351 String[] omitHidden = null;
\r
353 if (viewport.hasHiddenColumns)
\r
355 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
356 "The Alignment contains hidden columns."
\r
357 + "\nDo you want to save only the visible alignment?",
\r
358 "Save / Omit Hidden Columns",
\r
359 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
\r
361 if (reply == JOptionPane.YES_OPTION)
\r
362 omitHidden = viewport.getViewAsString(false);
\r
365 String output = new FormatAdapter().formatSequences(
\r
367 viewport.alignment.getSequencesArray(),
\r
370 if (output == null)
\r
377 java.io.PrintWriter out = new java.io.PrintWriter(
\r
378 new java.io.FileWriter(file));
\r
382 this.setTitle(file);
\r
385 catch (Exception ex)
\r
387 ex.printStackTrace();
\r
396 * @param e DOCUMENT ME!
\r
398 protected void outputText_actionPerformed(ActionEvent e)
\r
400 String [] omitHidden = null;
\r
402 if(viewport.hasHiddenColumns)
\r
404 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
405 "The Alignment contains hidden columns."
\r
406 +"\nDo you want to output only the visible alignment?",
\r
407 "Save / Omit Hidden Columns",
\r
408 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
\r
410 if(reply==JOptionPane.YES_OPTION)
\r
412 omitHidden = viewport.getViewAsString(false);
\r
416 CutAndPasteTransfer cap = new CutAndPasteTransfer();
\r
417 Desktop.addInternalFrame(cap,
\r
418 "Alignment output - " + e.getActionCommand(), 600,
\r
422 cap.setText(new FormatAdapter().formatSequences(
\r
423 e.getActionCommand(),
\r
424 viewport.alignment.getSequencesArray(),
\r
431 * @param e DOCUMENT ME!
\r
433 protected void htmlMenuItem_actionPerformed(ActionEvent e)
\r
435 new HTMLOutput(viewport,
\r
436 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
\r
437 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
\r
440 public void createImageMap(File file, String image)
\r
442 alignPanel.makePNGImageMap(file, image);
\r
448 * @param e DOCUMENT ME!
\r
450 public void createPNG(File f)
\r
452 alignPanel.makePNG(f);
\r
458 * @param e DOCUMENT ME!
\r
460 public void createEPS(File f)
\r
462 alignPanel.makeEPS(f);
\r
468 * @param e DOCUMENT ME!
\r
470 public void printMenuItem_actionPerformed(ActionEvent e)
\r
472 //Putting in a thread avoids Swing painting problems
\r
473 PrintThread thread = new PrintThread();
\r
477 public void exportFeatures_actionPerformed(ActionEvent e)
\r
479 new AnnotationExporter().exportFeatures(alignPanel);
\r
482 public void exportAnnotations_actionPerformed(ActionEvent e)
\r
484 new AnnotationExporter().exportAnnotations(
\r
486 viewport.alignment.getAlignmentAnnotation()
\r
491 public void associatedData_actionPerformed(ActionEvent e)
\r
493 // Pick the tree file
\r
494 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
\r
496 "LAST_DIRECTORY"));
\r
497 chooser.setFileView(new JalviewFileView());
\r
498 chooser.setDialogTitle("Load Jalview Annotations or Features File");
\r
499 chooser.setToolTipText("Load Jalview Annotations / Features file");
\r
501 int value = chooser.showOpenDialog(null);
\r
503 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
505 String choice = chooser.getSelectedFile().getPath();
\r
506 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
\r
507 loadJalviewDataFile(choice);
\r
515 * @param e DOCUMENT ME!
\r
517 public void closeMenuItem_actionPerformed(ActionEvent e)
\r
521 PaintRefresher.components.remove(viewport.alignment);
\r
522 this.setClosed(true);
\r
524 catch (Exception ex)
\r
532 void updateEditMenuBar()
\r
534 if (historyList.size() > 0)
\r
536 undoMenuItem.setEnabled(true);
\r
538 HistoryItem hi = (HistoryItem) historyList.peek();
\r
539 undoMenuItem.setText("Undo " + hi.getDescription());
\r
543 undoMenuItem.setEnabled(false);
\r
544 undoMenuItem.setText("Undo");
\r
547 if (redoList.size() > 0)
\r
549 redoMenuItem.setEnabled(true);
\r
551 HistoryItem hi = (HistoryItem) redoList.peek();
\r
552 redoMenuItem.setText("Redo " + hi.getDescription());
\r
556 redoMenuItem.setEnabled(false);
\r
557 redoMenuItem.setText("Redo");
\r
564 * @param hi DOCUMENT ME!
\r
566 public void addHistoryItem(HistoryItem hi)
\r
568 historyList.push(hi);
\r
569 updateEditMenuBar();
\r
575 * @param e DOCUMENT ME!
\r
577 protected void undoMenuItem_actionPerformed(ActionEvent e)
\r
579 HistoryItem hi = (HistoryItem) historyList.pop();
\r
580 redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment,
\r
581 HistoryItem.HIDE));
\r
582 restoreHistoryItem(hi);
\r
583 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
\r
589 * @param e DOCUMENT ME!
\r
591 protected void redoMenuItem_actionPerformed(ActionEvent e)
\r
593 HistoryItem hi = (HistoryItem) redoList.pop();
\r
594 restoreHistoryItem(hi);
\r
595 updateEditMenuBar();
\r
596 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
\r
599 // used by undo and redo
\r
600 void restoreHistoryItem(HistoryItem hi)
\r
605 updateEditMenuBar();
\r
607 viewport.firePropertyChange("alignment", null,
\r
608 viewport.getAlignment().getSequences());
\r
614 * @param up DOCUMENT ME!
\r
616 public void moveSelectedSequences(boolean up)
\r
618 SequenceGroup sg = viewport.getSelectionGroup();
\r
627 for (int i = 1; i < viewport.alignment.getHeight(); i++)
\r
629 SequenceI seq = viewport.alignment.getSequenceAt(i);
\r
631 if (!sg.getSequences(false).contains(seq))
\r
636 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
\r
638 if (sg.getSequences(false).contains(temp))
\r
643 viewport.alignment.getSequences().setElementAt(temp, i);
\r
644 viewport.alignment.getSequences().setElementAt(seq, i - 1);
\r
649 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
\r
651 SequenceI seq = viewport.alignment.getSequenceAt(i);
\r
653 if (!sg.getSequences(false).contains(seq))
\r
658 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
\r
660 if (sg.getSequences(false).contains(temp))
\r
665 viewport.alignment.getSequences().setElementAt(temp, i);
\r
666 viewport.alignment.getSequences().setElementAt(seq, i + 1);
\r
670 alignPanel.repaint();
\r
678 * @param e DOCUMENT ME!
\r
680 protected void copy_actionPerformed(ActionEvent e)
\r
682 if (viewport.getSelectionGroup() == null)
\r
687 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
\r
688 String[] omitHidden = null;
\r
690 if (viewport.hasHiddenColumns)
\r
692 omitHidden = viewport.getViewAsString(true);
\r
695 String output = new FormatAdapter().formatSequences(
\r
701 Toolkit.getDefaultToolkit().getSystemClipboard()
\r
702 .setContents(new StringSelection(output), Desktop.instance);
\r
704 Vector hiddenColumns = null;
\r
705 if(viewport.hasHiddenColumns && viewport.getSelectionGroup()!=null)
\r
707 hiddenColumns =new Vector();
\r
708 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
\r
709 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
\r
711 int[] region = (int[])
\r
712 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
\r
714 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
\r
715 region[1]-hiddenOffset});
\r
719 Desktop.jalviewClipboard = new Object[]{ seqs,
\r
720 viewport.alignment.getDataset(),
\r
727 * @param e DOCUMENT ME!
\r
729 protected void pasteNew_actionPerformed(ActionEvent e)
\r
737 * @param e DOCUMENT ME!
\r
739 protected void pasteThis_actionPerformed(ActionEvent e)
\r
741 addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,
\r
742 HistoryItem.PASTE));
\r
749 * @param newAlignment DOCUMENT ME!
\r
751 void paste(boolean newAlignment)
\r
755 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
\r
756 Transferable contents = c.getContents(this);
\r
758 if (contents == null)
\r
763 String str = (String) contents.getTransferData(DataFlavor.stringFlavor);
\r
767 String format = new IdentifyFile().Identify(str, "Paste");
\r
768 SequenceI[] sequences;
\r
770 if(Desktop.jalviewClipboard!=null)
\r
772 // The clipboard was filled from within Jalview, we must use the sequences
\r
773 // And dataset from the copied alignment
\r
774 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
\r
778 sequences = new FormatAdapter().readFile(str, "Paste", format);
\r
781 AlignmentI alignment = null;
\r
785 alignment = new Alignment(sequences);
\r
787 if(Desktop.jalviewClipboard!=null)
\r
788 alignment.setDataset( (Alignment)Desktop.jalviewClipboard[1] );
\r
790 alignment.setDataset( null );
\r
794 alignment = viewport.getAlignment();
\r
797 for (int i = 0; i < sequences.length; i++)
\r
800 Sequence newseq = new Sequence(sequences[i].getName(),
\r
801 sequences[i].getSequence(), sequences[i].getStart(),
\r
802 sequences[i].getEnd());
\r
804 alignment.addSequence(newseq);
\r
806 viewport.setEndSeq(alignment.getHeight());
\r
807 alignment.getWidth();
\r
808 viewport.firePropertyChange("alignment", null, alignment.getSequences());
\r
811 // Add any annotations attached to sequences
\r
812 for (int i = 0; i < sequences.length; i++)
\r
814 if (sequences[i].getAnnotation() != null)
\r
816 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
\r
818 AlignmentAnnotation newAnnot =
\r
819 new AlignmentAnnotation(
\r
820 sequences[i].getAnnotation()[a].label,
\r
821 sequences[i].getAnnotation()[a].description,
\r
822 sequences[i].getAnnotation()[a].annotations,
\r
823 sequences[i].getAnnotation()[a].graphMin,
\r
824 sequences[i].getAnnotation()[a].graphMax,
\r
825 sequences[i].getAnnotation()[a].graph);
\r
827 sequences[i].getAnnotation()[a] = newAnnot;
\r
828 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
\r
830 newAnnot.sequenceRef = sequences[i];
\r
831 newAnnot.adjustForAlignment();
\r
832 alignment.addAnnotation(newAnnot);
\r
833 alignment.setAnnotationIndex(newAnnot, a);
\r
836 alignPanel.annotationPanel.adjustPanelHeight();
\r
842 AlignFrame af = new AlignFrame(alignment);
\r
843 String newtitle = new String("Copied sequences");
\r
845 if(Desktop.jalviewClipboard[2]!=null)
\r
847 Vector hc = (Vector)Desktop.jalviewClipboard[2];
\r
848 for(int i=0; i<hc.size(); i++)
\r
850 int [] region = (int[]) hc.elementAt(i);
\r
851 af.viewport.hideColumns(region[0], region[1]+1);
\r
856 //>>>This is a fix for the moment, until a better solution is found!!<<<
\r
857 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
\r
858 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
\r
861 if (title.startsWith("Copied sequences"))
\r
867 newtitle = newtitle.concat("- from " + title);
\r
870 Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH,
\r
871 NEW_WINDOW_HEIGHT);
\r
877 catch (Exception ex)
\r
879 ex.printStackTrace();
\r
880 System.out.println("Exception whilst pasting: "+ex);
\r
881 // could be anything being pasted in here
\r
890 * @param e DOCUMENT ME!
\r
892 protected void cut_actionPerformed(ActionEvent e)
\r
894 copy_actionPerformed(null);
\r
895 delete_actionPerformed(null);
\r
901 * @param e DOCUMENT ME!
\r
903 protected void delete_actionPerformed(ActionEvent e)
\r
906 if (viewport.getSelectionGroup() == null)
\r
912 SequenceGroup sg = viewport.getSelectionGroup();
\r
916 //Jalview no longer allows deletion of residues.
\r
917 //Check here whether any residues are in selection area
\r
918 /* if( sg.getEndRes()-sg.getStartRes() < viewport.alignment.getWidth()-1)
\r
920 for (int i = 0; i < sg.sequences.size(); i++)
\r
922 SequenceI seq = sg.getSequenceAt(i);
\r
923 int j = sg.getStartRes();
\r
926 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
928 JOptionPane.showInternalMessageDialog(
\r
929 Desktop.desktop, "Cannot delete residues from alignment!\n"
\r
930 + "Try hiding columns instead.",
\r
931 "Deletion of residues not permitted",
\r
932 JOptionPane.WARNING_MESSAGE);
\r
937 }while(j<=sg.getEndRes());
\r
942 addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,
\r
943 HistoryItem.HIDE));
\r
946 for (int i = 0; i < sg.getSize(false); i++)
\r
948 SequenceI seq = sg.getSequenceAt(i);
\r
949 int index = viewport.getAlignment().findIndex(seq);
\r
951 seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);
\r
953 // If the cut affects all sequences, remove highlighted columns
\r
954 if (sg.getSize(false) == viewport.alignment.getHeight())
\r
956 viewport.getColumnSelection().removeElements(sg.getStartRes(),
\r
957 sg.getEndRes() + 1);
\r
960 if (seq.getSequence().length() < 1)
\r
962 viewport.getAlignment().deleteSequence(seq);
\r
966 viewport.getAlignment().getSequences().setElementAt(seq, index);
\r
970 viewport.setSelectionGroup(null);
\r
971 viewport.alignment.deleteGroup(sg);
\r
973 viewport.firePropertyChange("alignment", null,
\r
974 viewport.getAlignment().getSequences());
\r
978 if (viewport.getAlignment().getHeight() < 1)
\r
982 this.setClosed(true);
\r
984 catch (Exception ex)
\r
993 * @param e DOCUMENT ME!
\r
995 protected void deleteGroups_actionPerformed(ActionEvent e)
\r
997 viewport.alignment.deleteAllGroups();
\r
998 viewport.setSelectionGroup(null);
\r
999 alignPanel.repaint();
\r
1005 * @param e DOCUMENT ME!
\r
1007 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
\r
1009 SequenceGroup sg = new SequenceGroup();
\r
1011 for (int i = 0; i < viewport.getAlignment().getSequences().size();
\r
1014 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
\r
1017 sg.setEndRes(viewport.alignment.getWidth() - 1);
\r
1018 viewport.setSelectionGroup(sg);
\r
1019 PaintRefresher.Refresh(null, viewport.alignment);
\r
1025 * @param e DOCUMENT ME!
\r
1027 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
\r
1029 if(viewport.cursorMode)
\r
1031 alignPanel.seqPanel.keyboardNo1 = null;
\r
1032 alignPanel.seqPanel.keyboardNo2 = null;
\r
1034 viewport.setSelectionGroup(null);
\r
1035 viewport.getColumnSelection().clear();
\r
1036 viewport.setSelectionGroup(null);
\r
1037 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
\r
1038 alignPanel.idPanel.idCanvas.searchResults = null;
\r
1039 alignPanel.repaint();
\r
1040 PaintRefresher.Refresh(null, viewport.alignment);
\r
1046 * @param e DOCUMENT ME!
\r
1048 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
\r
1050 SequenceGroup sg = viewport.getSelectionGroup();
\r
1054 selectAllSequenceMenuItem_actionPerformed(null);
\r
1059 for (int i = 0; i < viewport.getAlignment().getSequences().size();
\r
1062 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
\r
1065 PaintRefresher.Refresh(null, viewport.alignment);
\r
1071 * @param e DOCUMENT ME!
\r
1073 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
\r
1075 ColumnSelection colSel = viewport.getColumnSelection();
\r
1077 if (colSel.size() > 0)
\r
1079 addHistoryItem(new HistoryItem("Remove Left", viewport.alignment,
\r
1080 HistoryItem.HIDE));
\r
1082 int min = colSel.getMin();
\r
1083 viewport.getAlignment().trimLeft(min);
\r
1084 colSel.compensateForEdit(0, min);
\r
1086 if (viewport.getSelectionGroup() != null)
\r
1088 viewport.getSelectionGroup().adjustForRemoveLeft(min);
\r
1091 Vector groups = viewport.alignment.getGroups();
\r
1093 for (int i = 0; i < groups.size(); i++)
\r
1095 SequenceGroup sg = (SequenceGroup) groups.get(i);
\r
1097 if (!sg.adjustForRemoveLeft(min))
\r
1099 viewport.alignment.deleteGroup(sg);
\r
1103 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
\r
1110 * @param e DOCUMENT ME!
\r
1112 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
\r
1114 ColumnSelection colSel = viewport.getColumnSelection();
\r
1116 if (colSel.size() > 0)
\r
1118 addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,
\r
1119 HistoryItem.HIDE));
\r
1121 int max = colSel.getMax();
\r
1122 viewport.getAlignment().trimRight(max);
\r
1124 if (viewport.getSelectionGroup() != null)
\r
1126 viewport.getSelectionGroup().adjustForRemoveRight(max);
\r
1129 Vector groups = viewport.alignment.getGroups();
\r
1131 for (int i = 0; i < groups.size(); i++)
\r
1133 SequenceGroup sg = (SequenceGroup) groups.get(i);
\r
1135 if (!sg.adjustForRemoveRight(max))
\r
1137 viewport.alignment.deleteGroup(sg);
\r
1141 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
\r
1148 * @param e DOCUMENT ME!
\r
1150 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
\r
1152 addHistoryItem(new HistoryItem("Remove Gapped Columns",
\r
1153 viewport.alignment, HistoryItem.HIDE));
\r
1155 //This is to maintain viewport position on first residue
\r
1156 //of first sequence
\r
1157 SequenceI seq = viewport.alignment.getSequenceAt(0);
\r
1158 int startRes = seq.findPosition(viewport.startRes);
\r
1160 viewport.getAlignment().removeGaps();
\r
1162 viewport.setStartRes(seq.findIndex(startRes)-1);
\r
1164 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
\r
1170 * @param e DOCUMENT ME!
\r
1172 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
\r
1174 addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,
\r
1175 HistoryItem.HIDE));
\r
1177 //This is to maintain viewport position on first residue
\r
1178 //of first sequence
\r
1179 SequenceI seq = viewport.alignment.getSequenceAt(0);
\r
1180 int startRes = seq.findPosition(viewport.startRes);
\r
1183 SequenceI current;
\r
1186 Vector seqs = null;
\r
1189 int end = viewport.alignment.getWidth();
\r
1191 if (viewport.getSelectionGroup() != null
\r
1192 && viewport.getSelectionGroup().getSequences(true) != null
\r
1193 && viewport.getSelectionGroup().getSize(true) > 0)
\r
1195 seqs = viewport.getSelectionGroup().getSequences(true);
\r
1196 start = viewport.getSelectionGroup().getStartRes();
\r
1197 end = viewport.getSelectionGroup().getEndRes()+1;
\r
1201 seqs = viewport.alignment.getSequences();
\r
1204 for (int i = 0; i < seqs.size(); i++)
\r
1206 current = (SequenceI) seqs.elementAt(i);
\r
1207 jSize = current.getLength();
\r
1209 // Removing a range is much quicker than removing gaps
\r
1210 // one by one for long sequences
\r
1212 int rangeStart=-1, rangeEnd=-1;
\r
1216 if (jalview.util.Comparison.isGap(current.getCharAt(j)))
\r
1218 if(rangeStart==-1)
\r
1233 current.deleteChars(rangeStart, rangeEnd);
\r
1234 j-=rangeEnd-rangeStart;
\r
1235 jSize-=rangeEnd-rangeStart;
\r
1243 while (j < end && j < jSize);
\r
1246 current.deleteChars(rangeStart, rangeEnd);
\r
1250 viewport.setStartRes(seq.findIndex(startRes)-1);
\r
1252 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
\r
1255 public void alignmentChanged()
\r
1257 if(viewport.padGaps)
\r
1258 viewport.getAlignment().padGaps();
\r
1260 if(viewport.vconsensus!=null && viewport.autoCalculateConsensus)
\r
1262 viewport.updateConsensus();
\r
1263 viewport.updateConservation();
\r
1265 resetAllColourSchemes();
\r
1266 if(alignPanel.overviewPanel!=null)
\r
1267 alignPanel.overviewPanel.updateOverviewImage();
\r
1269 viewport.alignment.adjustSequenceAnnotations();
\r
1271 alignPanel.repaint();
\r
1274 void resetAllColourSchemes()
\r
1276 ColourSchemeI cs = viewport.globalColourScheme;
\r
1279 if (cs instanceof ClustalxColourScheme)
\r
1281 ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).
\r
1282 resetClustalX(viewport.alignment.getSequences(),
\r
1283 viewport.alignment.getWidth());
\r
1286 cs.setConsensus(viewport.vconsensus);
\r
1287 if (cs.conservationApplied())
\r
1289 Alignment al = (Alignment) viewport.alignment;
\r
1290 Conservation c = new Conservation("All",
\r
1291 ResidueProperties.propHash, 3,
\r
1292 al.getSequences(), 0,
\r
1293 al.getWidth() - 1);
\r
1295 c.verdict(false, viewport.ConsPercGaps);
\r
1297 cs.setConservation(c);
\r
1301 int s, sSize = viewport.alignment.getGroups().size();
\r
1302 for(s=0; s<sSize; s++)
\r
1304 SequenceGroup sg = (SequenceGroup)viewport.alignment.getGroups().elementAt(s);
\r
1305 if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
\r
1307 ((ClustalxColourScheme)sg.cs).resetClustalX(
\r
1308 sg.getSequences(true), sg.getWidth());
\r
1310 sg.recalcConservation();
\r
1317 * @param e DOCUMENT ME!
\r
1319 public void padGapsMenuitem_actionPerformed(ActionEvent e)
\r
1321 addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,
\r
1322 HistoryItem.HIDE));
\r
1324 viewport.padGaps = padGapsMenuitem.isSelected();
\r
1326 // if (viewport.padGaps)
\r
1327 alignmentChanged();
\r
1333 * @param e DOCUMENT ME!
\r
1335 public void findMenuItem_actionPerformed(ActionEvent e)
\r
1337 JInternalFrame frame = new JInternalFrame();
\r
1338 Finder finder = new Finder(viewport, alignPanel, frame);
\r
1339 frame.setContentPane(finder);
\r
1340 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
1341 Desktop.addInternalFrame(frame, "Find", 340, 110);
\r
1347 * @param e DOCUMENT ME!
\r
1349 public void font_actionPerformed(ActionEvent e)
\r
1351 new FontChooser(alignPanel);
\r
1354 public void smoothFont_actionPerformed(ActionEvent e)
\r
1356 viewport.antiAlias = smoothFont.isSelected();
\r
1357 alignPanel.annotationPanel.image = null;
\r
1358 alignPanel.repaint();
\r
1365 * @param e DOCUMENT ME!
\r
1367 protected void seqLimit_actionPerformed(ActionEvent e)
\r
1369 viewport.setShowJVSuffix(seqLimits.isSelected());
\r
1371 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
\r
1372 alignPanel.repaint();
\r
1379 * @param e DOCUMENT ME!
\r
1381 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
\r
1383 viewport.setColourText(colourTextMenuItem.isSelected());
\r
1384 alignPanel.repaint();
\r
1390 * @param e DOCUMENT ME!
\r
1392 public void wrapMenuItem_actionPerformed(ActionEvent e)
\r
1394 scaleAbove.setVisible(wrapMenuItem.isSelected());
\r
1395 scaleLeft.setVisible(wrapMenuItem.isSelected());
\r
1396 scaleRight.setVisible(wrapMenuItem.isSelected());
\r
1397 viewport.setWrapAlignment(wrapMenuItem.isSelected());
\r
1398 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
\r
1401 public void showAllSeqs_actionPerformed(ActionEvent e)
\r
1403 viewport.showAllHiddenSeqs();
\r
1407 public void showAllColumns_actionPerformed(ActionEvent e)
\r
1409 viewport.getColumnSelection().revealAllHiddenColumns(viewport);
\r
1412 public void hideSelSequences_actionPerformed(ActionEvent e)
\r
1414 if(viewport.getSelectionGroup()==null)
\r
1417 SequenceI [] seqs = viewport.getSelectionGroup().getSequencesInOrder(
\r
1418 viewport.alignment
\r
1421 for(int i=0; i<seqs.length; i++)
\r
1423 viewport.hideSequence(seqs[i]);
\r
1428 public void hideSelColumns_actionPerformed(ActionEvent e)
\r
1430 viewport.hideSelectedColumns();
\r
1434 public void hiddenMarkers_actionPerformed(ActionEvent e)
\r
1436 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
\r
1443 * @param e DOCUMENT ME!
\r
1445 protected void scaleAbove_actionPerformed(ActionEvent e)
\r
1447 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
\r
1448 alignPanel.repaint();
\r
1454 * @param e DOCUMENT ME!
\r
1456 protected void scaleLeft_actionPerformed(ActionEvent e)
\r
1458 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
\r
1459 alignPanel.repaint();
\r
1465 * @param e DOCUMENT ME!
\r
1467 protected void scaleRight_actionPerformed(ActionEvent e)
\r
1469 viewport.setScaleRightWrapped(scaleRight.isSelected());
\r
1470 alignPanel.repaint();
\r
1476 * @param e DOCUMENT ME!
\r
1478 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
\r
1480 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
\r
1481 alignPanel.repaint();
\r
1487 * @param e DOCUMENT ME!
\r
1489 public void viewTextMenuItem_actionPerformed(ActionEvent e)
\r
1491 viewport.setShowText(viewTextMenuItem.isSelected());
\r
1492 alignPanel.repaint();
\r
1498 * @param e DOCUMENT ME!
\r
1500 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
\r
1502 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
\r
1503 alignPanel.repaint();
\r
1507 FeatureSettings featureSettings;
\r
1508 public void featureSettings_actionPerformed(ActionEvent e)
\r
1510 if(featureSettings !=null )
\r
1512 featureSettings.close();
\r
1513 featureSettings = null;
\r
1515 featureSettings = new FeatureSettings(this);
\r
1521 * @param evt DOCUMENT ME!
\r
1523 public void showSeqFeatures_actionPerformed(ActionEvent evt)
\r
1525 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
\r
1526 alignPanel.repaint();
\r
1527 if (alignPanel.getOverviewPanel() != null)
\r
1529 alignPanel.getOverviewPanel().updateOverviewImage();
\r
1536 * @param e DOCUMENT ME!
\r
1538 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
\r
1540 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
\r
1541 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
\r
1547 * @param e DOCUMENT ME!
\r
1549 public void overviewMenuItem_actionPerformed(ActionEvent e)
\r
1551 if (alignPanel.overviewPanel != null)
\r
1556 JInternalFrame frame = new JInternalFrame();
\r
1557 OverviewPanel overview = new OverviewPanel(alignPanel);
\r
1558 frame.setContentPane(overview);
\r
1559 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
\r
1560 frame.getWidth(), frame.getHeight());
\r
1562 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
1563 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
\r
1565 public void internalFrameClosed(
\r
1566 javax.swing.event.InternalFrameEvent evt)
\r
1568 alignPanel.setOverviewPanel(null);
\r
1573 alignPanel.setOverviewPanel(overview);
\r
1579 * @param e DOCUMENT ME!
\r
1581 protected void noColourmenuItem_actionPerformed(ActionEvent e)
\r
1583 changeColour(null);
\r
1589 * @param e DOCUMENT ME!
\r
1591 public void clustalColour_actionPerformed(ActionEvent e)
\r
1593 changeColour(new ClustalxColourScheme(
\r
1594 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
\r
1600 * @param e DOCUMENT ME!
\r
1602 public void zappoColour_actionPerformed(ActionEvent e)
\r
1604 changeColour(new ZappoColourScheme());
\r
1610 * @param e DOCUMENT ME!
\r
1612 public void taylorColour_actionPerformed(ActionEvent e)
\r
1614 changeColour(new TaylorColourScheme());
\r
1620 * @param e DOCUMENT ME!
\r
1622 public void hydrophobicityColour_actionPerformed(ActionEvent e)
\r
1624 changeColour(new HydrophobicColourScheme());
\r
1630 * @param e DOCUMENT ME!
\r
1632 public void helixColour_actionPerformed(ActionEvent e)
\r
1634 changeColour(new HelixColourScheme());
\r
1640 * @param e DOCUMENT ME!
\r
1642 public void strandColour_actionPerformed(ActionEvent e)
\r
1644 changeColour(new StrandColourScheme());
\r
1650 * @param e DOCUMENT ME!
\r
1652 public void turnColour_actionPerformed(ActionEvent e)
\r
1654 changeColour(new TurnColourScheme());
\r
1660 * @param e DOCUMENT ME!
\r
1662 public void buriedColour_actionPerformed(ActionEvent e)
\r
1664 changeColour(new BuriedColourScheme());
\r
1670 * @param e DOCUMENT ME!
\r
1672 public void nucleotideColour_actionPerformed(ActionEvent e)
\r
1674 changeColour(new NucleotideColourScheme());
\r
1677 public void annotationColour_actionPerformed(ActionEvent e)
\r
1679 new AnnotationColourChooser(viewport, alignPanel);
\r
1686 * @param e DOCUMENT ME!
\r
1688 protected void applyToAllGroups_actionPerformed(ActionEvent e)
\r
1690 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
\r
1696 * @param cs DOCUMENT ME!
\r
1698 public void changeColour(ColourSchemeI cs)
\r
1700 int threshold = 0;
\r
1704 if (viewport.getAbovePIDThreshold())
\r
1706 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
\r
1709 cs.setThreshold(threshold,
\r
1710 viewport.getIgnoreGapsConsensus());
\r
1712 viewport.setGlobalColourScheme(cs);
\r
1716 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
\r
1719 if (viewport.getConservationSelected())
\r
1722 Alignment al = (Alignment) viewport.alignment;
\r
1723 Conservation c = new Conservation("All",
\r
1724 ResidueProperties.propHash, 3,
\r
1725 al.getSequences(), 0,
\r
1726 al.getWidth() - 1);
\r
1729 c.verdict(false, viewport.ConsPercGaps);
\r
1731 cs.setConservation(c);
\r
1733 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
\r
1738 cs.setConservation(null);
\r
1741 cs.setConsensus(viewport.vconsensus);
\r
1744 viewport.setGlobalColourScheme(cs);
\r
1746 if (viewport.getColourAppliesToAllGroups())
\r
1748 Vector groups = viewport.alignment.getGroups();
\r
1750 for (int i = 0; i < groups.size(); i++)
\r
1752 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
\r
1760 if (cs instanceof ClustalxColourScheme)
\r
1762 sg.cs = new ClustalxColourScheme(
\r
1763 sg.getSequences(true), sg.getWidth());
\r
1765 else if (cs instanceof UserColourScheme)
\r
1767 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
\r
1773 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
\r
1775 catch (Exception ex)
\r
1780 if (viewport.getAbovePIDThreshold()
\r
1781 || cs instanceof PIDColourScheme
\r
1782 || cs instanceof Blosum62ColourScheme)
\r
1784 sg.cs.setThreshold(threshold,
\r
1785 viewport.getIgnoreGapsConsensus());
\r
1787 sg.cs.setConsensus(AAFrequency.calculate(
\r
1788 sg.getSequences(true), 0,
\r
1792 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
\r
1795 if (viewport.getConservationSelected())
\r
1797 Conservation c = new Conservation("Group",
\r
1798 ResidueProperties.propHash, 3,
\r
1799 sg.getSequences(true), 0,
\r
1800 viewport.alignment.getWidth() - 1);
\r
1802 c.verdict(false, viewport.ConsPercGaps);
\r
1803 sg.cs.setConservation(c);
\r
1806 sg.cs.setConservation(null);
\r
1810 if (alignPanel.getOverviewPanel() != null)
\r
1812 alignPanel.getOverviewPanel().updateOverviewImage();
\r
1815 alignPanel.repaint();
\r
1821 * @param e DOCUMENT ME!
\r
1823 protected void modifyPID_actionPerformed(ActionEvent e)
\r
1825 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
\r
1827 SliderPanel.setPIDSliderSource(alignPanel,
\r
1828 viewport.getGlobalColourScheme(),
\r
1830 SliderPanel.showPIDSlider();
\r
1837 * @param e DOCUMENT ME!
\r
1839 protected void modifyConservation_actionPerformed(ActionEvent e)
\r
1841 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
\r
1843 SliderPanel.setConservationSlider(alignPanel,
\r
1844 viewport.globalColourScheme,
\r
1846 SliderPanel.showConservationSlider();
\r
1853 * @param e DOCUMENT ME!
\r
1855 protected void conservationMenuItem_actionPerformed(ActionEvent e)
\r
1857 viewport.setConservationSelected(conservationMenuItem.isSelected());
\r
1859 viewport.setAbovePIDThreshold(false);
\r
1860 abovePIDThreshold.setSelected(false);
\r
1862 changeColour(viewport.getGlobalColourScheme());
\r
1864 modifyConservation_actionPerformed(null);
\r
1870 * @param e DOCUMENT ME!
\r
1872 public void abovePIDThreshold_actionPerformed(ActionEvent e)
\r
1874 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
\r
1876 conservationMenuItem.setSelected(false);
\r
1877 viewport.setConservationSelected(false);
\r
1879 changeColour(viewport.getGlobalColourScheme());
\r
1881 modifyPID_actionPerformed(null);
\r
1887 * @param e DOCUMENT ME!
\r
1889 public void userDefinedColour_actionPerformed(ActionEvent e)
\r
1891 if (e.getActionCommand().equals("User Defined..."))
\r
1893 new UserDefinedColours(alignPanel, null);
\r
1897 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
\r
1898 getUserColourSchemes().get(e.getActionCommand());
\r
1900 changeColour(udc);
\r
1904 public void updateUserColourMenu()
\r
1907 Component[] menuItems = colourMenu.getMenuComponents();
\r
1908 int i, iSize = menuItems.length;
\r
1909 for (i = 0; i < iSize; i++)
\r
1911 if (menuItems[i].getName() != null &&
\r
1912 menuItems[i].getName().equals("USER_DEFINED"))
\r
1914 colourMenu.remove(menuItems[i]);
\r
1918 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
\r
1920 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
\r
1921 getUserColourSchemes().keys();
\r
1923 while (userColours.hasMoreElements())
\r
1925 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
\r
1926 nextElement().toString());
\r
1927 radioItem.setName("USER_DEFINED");
\r
1928 radioItem.addMouseListener(new MouseAdapter()
\r
1930 public void mousePressed(MouseEvent evt)
\r
1932 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
\r
1934 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
\r
1936 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
\r
1937 "Remove from default list?",
\r
1938 "Remove user defined colour",
\r
1939 JOptionPane.YES_NO_OPTION);
\r
1940 if(option == JOptionPane.YES_OPTION)
\r
1942 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
\r
1943 colourMenu.remove(radioItem);
\r
1946 radioItem.addActionListener(new ActionListener()
\r
1948 public void actionPerformed(ActionEvent evt)
\r
1950 userDefinedColour_actionPerformed(evt);
\r
1956 radioItem.addActionListener(new ActionListener()
\r
1958 public void actionPerformed(ActionEvent evt)
\r
1960 userDefinedColour_actionPerformed(evt);
\r
1964 colourMenu.insert(radioItem, 15);
\r
1965 colours.add(radioItem);
\r
1973 * @param e DOCUMENT ME!
\r
1975 public void PIDColour_actionPerformed(ActionEvent e)
\r
1977 changeColour(new PIDColourScheme());
\r
1983 * @param e DOCUMENT ME!
\r
1985 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
\r
1987 changeColour(new Blosum62ColourScheme());
\r
1993 * @param e DOCUMENT ME!
\r
1995 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
\r
1997 addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,
\r
1998 HistoryItem.SORT));
\r
1999 AlignmentSorter.sortByPID(viewport.getAlignment(),
\r
2000 viewport.getAlignment().getSequenceAt(0));
\r
2001 alignPanel.repaint();
\r
2007 * @param e DOCUMENT ME!
\r
2009 public void sortIDMenuItem_actionPerformed(ActionEvent e)
\r
2011 addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,
\r
2012 HistoryItem.SORT));
\r
2013 AlignmentSorter.sortByID(viewport.getAlignment());
\r
2014 alignPanel.repaint();
\r
2020 * @param e DOCUMENT ME!
\r
2022 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
\r
2024 addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,
\r
2025 HistoryItem.SORT));
\r
2027 AlignmentSorter.sortByGroup(viewport.getAlignment());
\r
2028 alignPanel.repaint();
\r
2034 * @param e DOCUMENT ME!
\r
2036 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
\r
2038 new RedundancyPanel(alignPanel, this);
\r
2045 * @param e DOCUMENT ME!
\r
2047 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
\r
2049 if ( (viewport.getSelectionGroup() == null) ||
\r
2050 (viewport.getSelectionGroup().getSize(false) < 2))
\r
2052 JOptionPane.showInternalMessageDialog(this,
\r
2053 "You must select at least 2 sequences.",
\r
2054 "Invalid Selection",
\r
2055 JOptionPane.WARNING_MESSAGE);
\r
2059 JInternalFrame frame = new JInternalFrame();
\r
2060 frame.setContentPane(new PairwiseAlignPanel(viewport));
\r
2061 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
\r
2068 * @param e DOCUMENT ME!
\r
2070 public void PCAMenuItem_actionPerformed(ActionEvent e)
\r
2072 if ( ( (viewport.getSelectionGroup() != null) &&
\r
2073 (viewport.getSelectionGroup().getSize(false) < 4) &&
\r
2074 (viewport.getSelectionGroup().getSize(false) > 0)) ||
\r
2075 (viewport.getAlignment().getHeight() < 4))
\r
2077 JOptionPane.showInternalMessageDialog(this,
\r
2078 "Principal component analysis must take\n" +
\r
2079 "at least 4 input sequences.",
\r
2080 "Sequence selection insufficient",
\r
2081 JOptionPane.WARNING_MESSAGE);
\r
2086 new PCAPanel(viewport);
\r
2090 public void autoCalculate_actionPerformed(ActionEvent e)
\r
2092 viewport.autoCalculateConsensus = autoCalculate.isSelected();
\r
2093 if(viewport.autoCalculateConsensus)
\r
2095 alignmentChanged();
\r
2103 * @param e DOCUMENT ME!
\r
2105 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
\r
2107 NewTreePanel("AV", "PID", "Average distance tree using PID");
\r
2113 * @param e DOCUMENT ME!
\r
2115 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
\r
2117 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
\r
2123 * @param e DOCUMENT ME!
\r
2125 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
\r
2127 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
\r
2133 * @param e DOCUMENT ME!
\r
2135 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
\r
2137 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
\r
2143 * @param type DOCUMENT ME!
\r
2144 * @param pwType DOCUMENT ME!
\r
2145 * @param title DOCUMENT ME!
\r
2147 void NewTreePanel(String type, String pwType, String title)
\r
2151 if ( (viewport.getSelectionGroup() != null) &&
\r
2152 (viewport.getSelectionGroup().getSize(false) > 3))
\r
2155 SequenceGroup sg = viewport.getSelectionGroup();
\r
2157 /* Decide if the selection is a column region */
\r
2158 while (s < sg.getSize(false))
\r
2160 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
\r
2163 JOptionPane.showMessageDialog(Desktop.desktop,
\r
2164 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
\r
2165 "Try using the Pad function in the edit menu,\n" +
\r
2166 "or one of the multiple sequence alignment web services.",
\r
2167 "Sequences in selection are not aligned",
\r
2168 JOptionPane.WARNING_MESSAGE);
\r
2174 title = title + " on region";
\r
2175 tp = new TreePanel(viewport, type, pwType);
\r
2179 //are the sequences aligned?
\r
2180 if (!viewport.alignment.isAligned())
\r
2182 JOptionPane.showMessageDialog(Desktop.desktop,
\r
2183 "The sequences must be aligned before creating a tree.\n" +
\r
2184 "Try using the Pad function in the edit menu,\n" +
\r
2185 "or one of the multiple sequence alignment web services.",
\r
2186 "Sequences not aligned",
\r
2187 JOptionPane.WARNING_MESSAGE);
\r
2192 tp = new TreePanel(viewport, type, pwType);
\r
2195 addTreeMenuItem(tp, title);
\r
2197 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
\r
2203 * @param title DOCUMENT ME!
\r
2204 * @param order DOCUMENT ME!
\r
2206 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
\r
2208 final JMenuItem item = new JMenuItem("by " + title);
\r
2210 item.addActionListener(new java.awt.event.ActionListener()
\r
2212 public void actionPerformed(ActionEvent e)
\r
2214 addHistoryItem(new HistoryItem("Sort", viewport.alignment,
\r
2215 HistoryItem.SORT));
\r
2217 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
\r
2218 AlignmentSorter.sortBy(viewport.getAlignment(), order);
\r
2219 alignPanel.repaint();
\r
2225 * Maintain the Order by->Displayed Tree menu.
\r
2226 * Creates a new menu item for a TreePanel with an appropriate
\r
2227 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
\r
2228 * to remove the menu item when the treePanel is closed, and adjust
\r
2229 * the tree leaf to sequence mapping when the alignment is modified.
\r
2230 * @param treePanel Displayed tree window.
\r
2231 * @param title SortBy menu item title.
\r
2233 void addTreeMenuItem(final TreePanel treePanel, String title)
\r
2235 final JMenuItem item = new JMenuItem(title);
\r
2239 if (treeCount == 1)
\r
2241 sort.add(sortByTreeMenu);
\r
2244 sortByTreeMenu.add(item);
\r
2245 item.addActionListener(new java.awt.event.ActionListener()
\r
2247 public void actionPerformed(ActionEvent e)
\r
2249 addHistoryItem(new HistoryItem("Tree Sort",
\r
2250 viewport.alignment, HistoryItem.SORT));
\r
2251 AlignmentSorter.sortByTree(viewport.getAlignment(),
\r
2252 treePanel.getTree());
\r
2253 alignPanel.repaint();
\r
2257 treePanel.addInternalFrameListener(new javax.swing.event.
\r
2258 InternalFrameAdapter()
\r
2260 public void internalFrameClosed(
\r
2261 javax.swing.event.InternalFrameEvent evt)
\r
2264 sortByTreeMenu.remove(item);
\r
2266 if (treeCount == 0)
\r
2268 sort.remove(sortByTreeMenu);
\r
2276 * Work out whether the whole set of sequences
\r
2277 * or just the selected set will be submitted for multiple alignment.
\r
2280 private SequenceI[] gatherSequencesForAlignment()
\r
2282 // Now, check we have enough sequences
\r
2283 SequenceI[] msa = null;
\r
2285 if ( (viewport.getSelectionGroup() != null) &&
\r
2286 (viewport.getSelectionGroup().getSize(false) > 1))
\r
2288 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
\r
2289 SequenceGroup seqs = viewport.getSelectionGroup();
\r
2291 msa = new SequenceI[sz = seqs.getSize(false)];
\r
2293 for (int i = 0; i < sz; i++)
\r
2295 msa[i] = (SequenceI) seqs.getSequenceAt(i);
\r
2300 Vector seqs = viewport.getAlignment().getSequences();
\r
2302 if (seqs.size() > 1)
\r
2304 msa = new SequenceI[seqs.size()];
\r
2306 for (int i = 0; i < seqs.size(); i++)
\r
2308 msa[i] = (SequenceI) seqs.elementAt(i);
\r
2316 * Decides what is submitted to a secondary structure prediction service,
\r
2317 * the currently selected sequence, or the currently selected alignment
\r
2318 * (where the first sequence in the set is the one that the prediction
\r
2321 SequenceI[] gatherSeqOrMsaForSecStrPrediction()
\r
2323 SequenceI seq = null;
\r
2324 SequenceI[] msa = null;
\r
2326 if ( (viewport.getSelectionGroup() != null) &&
\r
2327 (viewport.getSelectionGroup().getSize(false) > 0))
\r
2329 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
\r
2330 SequenceGroup seqs = viewport.getSelectionGroup();
\r
2332 if ( (seqs.getSize(false) == 1) || !viewport.alignment.isAligned())
\r
2334 seq = (SequenceI) seqs.getSequenceAt(0);
\r
2339 msa = new SequenceI[sz = seqs.getSize(false)];
\r
2341 for (int i = 0; i < sz; i++)
\r
2343 msa[i] = (SequenceI) seqs.getSequenceAt(i);
\r
2349 Vector seqs = viewport.getAlignment().getSequences();
\r
2351 if ( (seqs.size() == 1) || !viewport.alignment.isAligned())
\r
2353 seq = (SequenceI) seqs.elementAt(0);
\r
2357 msa = new SequenceI[seqs.size()];
\r
2359 for (int i = 0; i < seqs.size(); i++)
\r
2361 msa[i] = (SequenceI) seqs.elementAt(i);
\r
2373 return new SequenceI[]
\r
2383 * @param e DOCUMENT ME!
\r
2385 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
\r
2387 // Pick the tree file
\r
2388 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
\r
2390 "LAST_DIRECTORY"));
\r
2391 chooser.setFileView(new JalviewFileView());
\r
2392 chooser.setDialogTitle("Select a newick-like tree file");
\r
2393 chooser.setToolTipText("Load a tree file");
\r
2395 int value = chooser.showOpenDialog(null);
\r
2397 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
2399 String choice = chooser.getSelectedFile().getPath();
\r
2400 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
\r
2404 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
\r
2406 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
\r
2408 catch (Exception ex)
\r
2410 JOptionPane.showMessageDialog(Desktop.desktop,
\r
2411 "Problem reading tree file",
\r
2413 JOptionPane.WARNING_MESSAGE);
\r
2414 ex.printStackTrace();
\r
2420 public TreePanel ShowNewickTree(NewickFile nf, String title)
\r
2422 return ShowNewickTree(nf,title,600,500,4,5);
\r
2427 * @param nf DOCUMENT ME!
\r
2428 * @param title DOCUMENT ME!
\r
2430 * @return DOCUMENT ME!
\r
2432 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y)
\r
2434 TreePanel tp = null;
\r
2440 if (nf.getTree() != null)
\r
2442 tp = new TreePanel(viewport,
\r
2450 tp.setLocation(x,y);
\r
2453 Desktop.addInternalFrame(tp, title, w, h);
\r
2454 addTreeMenuItem(tp, title);
\r
2457 catch (Exception ex)
\r
2459 ex.printStackTrace();
\r
2470 PrinterJob printJob = PrinterJob.getPrinterJob();
\r
2471 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
\r
2472 printJob.setPrintable(alignPanel, pf);
\r
2474 if (printJob.printDialog())
\r
2480 catch (Exception PrintException)
\r
2482 PrintException.printStackTrace();
\r
2489 * Generates menu items and listener event actions for web service clients
\r
2492 public void BuildWebServiceMenu()
\r
2494 if ( (Discoverer.services != null)
\r
2495 && (Discoverer.services.size() > 0))
\r
2497 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
\r
2498 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
\r
2499 Vector wsmenu = new Vector();
\r
2500 if (msaws != null)
\r
2502 // Add any Multiple Sequence Alignment Services
\r
2503 final JMenu msawsmenu = new JMenu("Alignment");
\r
2504 final AlignFrame af = this;
\r
2505 for (int i = 0, j = msaws.size(); i < j; i++)
\r
2507 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
\r
2509 final JMenuItem method = new JMenuItem(sh.getName());
\r
2510 method.addActionListener(new ActionListener()
\r
2512 public void actionPerformed(ActionEvent e)
\r
2514 SequenceI[] msa = gatherSequencesForAlignment();
\r
2515 new jalview.ws.MsaWSClient(sh, title, msa,
\r
2516 false, true, viewport.getAlignment().getDataset(), af);
\r
2521 msawsmenu.add(method);
\r
2522 // Deal with services that we know accept partial alignments.
\r
2523 if (sh.getName().indexOf("lustal") > -1)
\r
2525 // We know that ClustalWS can accept partial alignments for refinement.
\r
2526 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
\r
2527 methodR.addActionListener(new ActionListener()
\r
2529 public void actionPerformed(ActionEvent e)
\r
2531 SequenceI[] msa = gatherSequencesForAlignment();
\r
2532 new jalview.ws.MsaWSClient(sh, title, msa,
\r
2533 true, true, viewport.getAlignment().getDataset(), af);
\r
2538 msawsmenu.add(methodR);
\r
2542 wsmenu.add(msawsmenu);
\r
2544 if (secstrpr != null)
\r
2546 // Add any secondary structure prediction services
\r
2547 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
\r
2548 for (int i = 0, j = secstrpr.size(); i < j; i++)
\r
2550 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
\r
2552 final JMenuItem method = new JMenuItem(sh.getName());
\r
2553 method.addActionListener(new ActionListener()
\r
2555 public void actionPerformed(ActionEvent e)
\r
2557 SequenceI[] msa = gatherSeqOrMsaForSecStrPrediction();
\r
2558 if (msa.length == 1)
\r
2560 // Single Sequence prediction
\r
2561 new jalview.ws.JPredClient(sh,title, msa[0]);
\r
2565 if (msa.length > 1)
\r
2567 // Single Sequence prediction
\r
2568 jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh,
\r
2574 secstrmenu.add(method);
\r
2576 wsmenu.add(secstrmenu);
\r
2578 this.webService.removeAll();
\r
2579 for (int i = 0, j = wsmenu.size(); i < j; i++)
\r
2581 webService.add( (JMenu) wsmenu.get(i));
\r
2586 this.webService.removeAll();
\r
2587 this.webService.add(this.webServiceNoServices);
\r
2589 // TODO: add in rediscovery function
\r
2590 // TODO: reduce code redundancy.
\r
2591 // TODO: group services by location as well as function.
\r
2594 /* public void vamsasStore_actionPerformed(ActionEvent e)
\r
2596 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
\r
2597 getProperty("LAST_DIRECTORY"));
\r
2599 chooser.setFileView(new JalviewFileView());
\r
2600 chooser.setDialogTitle("Export to Vamsas file");
\r
2601 chooser.setToolTipText("Export");
\r
2603 int value = chooser.showSaveDialog(this);
\r
2605 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
2607 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
\r
2608 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
\r
2609 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
\r
2616 public void showTranslation_actionPerformed(ActionEvent e)
\r
2618 SequenceI [] selection = viewport.getSelectionAsNewSequence();
\r
2619 String [] seqstring = viewport.getViewAsString(true);
\r
2621 int s, sSize = selection.length;
\r
2622 SequenceI [] newSeq = new SequenceI[sSize];
\r
2625 StringBuffer protein;
\r
2627 for(s=0; s<sSize; s++)
\r
2629 protein = new StringBuffer();
\r
2630 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
\r
2631 resSize = seq.length();
\r
2632 resSize -= resSize%3;
\r
2634 for(res = 0; res < resSize; res+=3)
\r
2636 String codon = seq.substring(res, res+3);
\r
2637 codon = codon.replace('U', 'T');
\r
2638 String aa = ResidueProperties.codonTranslate(codon);
\r
2640 protein.append(viewport.getGapCharacter());
\r
2641 else if(aa.equals("STOP"))
\r
2642 protein.append("X");
\r
2644 protein.append( aa );
\r
2646 newSeq[s] = new Sequence(selection[s].getName(),
\r
2647 protein.toString());
\r
2651 AlignmentI al = new Alignment(newSeq);
\r
2652 al.setDataset(null);
\r
2655 ////////////////////////////////
\r
2656 // Copy annotations across
\r
2657 jalview.datamodel.AlignmentAnnotation[] annotations
\r
2658 = viewport.alignment.getAlignmentAnnotation();
\r
2660 if(annotations!=null)
\r
2662 for (int i = 0; i < annotations.length; i++)
\r
2664 if (annotations[i].label.equals("Quality") ||
\r
2665 annotations[i].label.equals("Conservation") ||
\r
2666 annotations[i].label.equals("Consensus"))
\r
2671 aSize = viewport.alignment.getWidth() / 3;
\r
2672 jalview.datamodel.Annotation[] anots =
\r
2673 new jalview.datamodel.Annotation[aSize];
\r
2675 for (a = 0; a < viewport.alignment.getWidth(); a++)
\r
2677 if (annotations[i].annotations[a] == null
\r
2678 || annotations[i].annotations[a] == null)
\r
2681 anots[a / 3] = new Annotation(
\r
2682 annotations[i].annotations[a].displayCharacter,
\r
2683 annotations[i].annotations[a].description,
\r
2684 annotations[i].annotations[a].secondaryStructure,
\r
2685 annotations[i].annotations[a].value,
\r
2686 annotations[i].annotations[a].colour);
\r
2689 jalview.datamodel.AlignmentAnnotation aa
\r
2690 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
\r
2691 annotations[i].description, anots);
\r
2692 al.addAnnotation(aa);
\r
2696 AlignFrame af = new AlignFrame(al);
\r
2697 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
\r
2699 NEW_WINDOW_HEIGHT);
\r
2702 // AlignViewport newViewport = new AlignViewport(al);
\r
2703 // AlignmentPanel ap = new AlignmentPanel(this, newViewport);
\r
2704 // tabbedPane.add("Protein", ap);
\r
2705 // viewports.add(newViewport);
\r
2706 // alignPanels.add(ap);
\r
2709 /////////////////////////
\r
2711 // AlignViewport ds = new AlignViewport(al.getDataset());
\r
2712 // ds.setDataset(true);
\r
2713 // AlignmentPanel dap = new AlignmentPanel(this, ds);
\r
2714 // tabbedPane.add("Dataset", dap);
\r
2715 // viewports.add(ds);
\r
2716 // alignPanels.add(dap);
\r
2717 /////////////////////////
\r
2722 /*public void tabSelected()
\r
2724 int index = tabbedPane.getSelectedIndex();
\r
2725 viewport = (AlignViewport)viewports.elementAt(index);
\r
2726 alignPanel = (AlignmentPanel)alignPanels.elementAt(index);
\r
2732 * @param String DOCUMENT ME!
\r
2734 public boolean parseFeaturesFile(String file, String type)
\r
2736 boolean featuresFile = false;
\r
2738 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
\r
2739 alignPanel.seqPanel.seqCanvas.
\r
2740 getFeatureRenderer().featureColours,
\r
2743 catch(Exception ex)
\r
2745 ex.printStackTrace();
\r
2750 viewport.showSequenceFeatures = true;
\r
2751 showSeqFeatures.setSelected(true);
\r
2752 alignPanel.repaint();
\r
2755 return featuresFile;
\r
2758 public void dragEnter(DropTargetDragEvent evt)
\r
2761 public void dragExit(DropTargetEvent evt)
\r
2764 public void dragOver(DropTargetDragEvent evt)
\r
2767 public void dropActionChanged(DropTargetDragEvent evt)
\r
2770 public void drop(DropTargetDropEvent evt)
\r
2772 Transferable t = evt.getTransferable();
\r
2773 java.util.List files = null;
\r
2777 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
\r
2778 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
\r
2780 //Works on Windows and MacOSX
\r
2781 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
\r
2782 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
\r
2784 else if (t.isDataFlavorSupported(uriListFlavor))
\r
2786 // This is used by Unix drag system
\r
2787 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
\r
2788 String data = (String) t.getTransferData(uriListFlavor);
\r
2789 files = new java.util.ArrayList(1);
\r
2790 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
\r
2793 st.hasMoreTokens(); )
\r
2795 String s = st.nextToken();
\r
2796 if (s.startsWith("#"))
\r
2798 // the line is a comment (as per the RFC 2483)
\r
2802 java.net.URI uri = new java.net.URI(s);
\r
2803 java.io.File file = new java.io.File(uri);
\r
2808 catch (Exception e)
\r
2810 e.printStackTrace();
\r
2812 if (files != null)
\r
2817 for (int i = 0; i < files.size(); i++)
\r
2819 loadJalviewDataFile(files.get(i).toString());
\r
2822 catch (Exception ex)
\r
2824 ex.printStackTrace();
\r
2829 // This method will attempt to load a "dropped" file first by testing
\r
2830 // whether its and Annotation file, then features file. If both are
\r
2831 // false then the user may have dropped an alignment file onto this
\r
2833 public void loadJalviewDataFile(String file)
\r
2836 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
\r
2839 if (!isAnnotation)
\r
2841 boolean isGroupsFile = parseFeaturesFile(file,
\r
2842 AppletFormatAdapter.FILE);
\r
2843 if (!isGroupsFile)
\r
2845 String protocol = "File";
\r
2846 String format = new IdentifyFile().Identify(file, protocol);
\r
2847 SequenceI[] sequences = new FormatAdapter().readFile(file, protocol,
\r
2850 FastaFile ff = new FastaFile();
\r
2851 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
\r
2852 c.setContents(new StringSelection(ff.print(sequences)), Desktop.instance);
\r
2854 this.paste(false);
\r
2860 alignPanel.adjustAnnotationHeight();
\r
2863 }catch(Exception ex)
\r
2865 ex.printStackTrace();
\r