2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Softwarechang
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 import java.awt.datatransfer.*;
27 import java.awt.event.*;
28 import java.awt.print.*;
31 import jalview.analysis.*;
32 import jalview.datamodel.*;
34 import jalview.jbgui.*;
35 import jalview.schemes.*;
36 import jalview.commands.*;
38 import java.awt.dnd.*;
39 import javax.swing.event.ChangeListener;
40 import javax.swing.event.ChangeEvent;
48 public class AlignFrame extends GAlignFrame implements DropTargetListener
51 public static final int DEFAULT_WIDTH = 700;
54 public static final int DEFAULT_HEIGHT = 500;
55 public AlignmentPanel alignPanel;
57 AlignViewport viewport;
59 Vector alignPanels = new Vector();
63 String currentFileFormat = null;
65 String fileName = null;
67 private int treeCount = 0;
70 * Creates a new AlignFrame object.
72 * @param al DOCUMENT ME!
74 public AlignFrame(AlignmentI al, int width, int height)
76 this(al, null, width, height);
81 * new alignment window with hidden columns
82 * @param al AlignmentI
83 * @param hiddenColumns ColumnSelection or null
85 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
86 int width, int height)
88 this.setSize(width, height);
89 viewport = new AlignViewport(al, hiddenColumns);
91 alignPanel = new AlignmentPanel(this, viewport);
93 if(al.getDataset()==null)
98 addAlignmentPanel(alignPanel, true);
103 * Make a new AlignFrame from exisiting alignmentPanels
104 * @param ap AlignmentPanel
105 * @param av AlignViewport
107 public AlignFrame(AlignmentPanel ap)
111 addAlignmentPanel(ap, false);
117 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
119 if (viewport.conservation == null)
121 BLOSUM62Colour.setEnabled(false);
122 conservationMenuItem.setEnabled(false);
123 modifyConservation.setEnabled(false);
124 // PIDColour.setEnabled(false);
125 // abovePIDThreshold.setEnabled(false);
126 // modifyPID.setEnabled(false);
129 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
131 if (sortby.equals("Id"))
132 sortIDMenuItem_actionPerformed(null);
133 else if (sortby.equals("Pairwise Identity"))
134 sortPairwiseMenuItem_actionPerformed(null);
136 if (Desktop.desktop != null)
138 addServiceListeners();
139 setGUINucleotide(viewport.alignment.isNucleotide());
142 setMenusFromViewport(viewport);
144 if (viewport.wrapAlignment)
146 wrapMenuItem_actionPerformed(null);
153 public void setFileName(String file, String format)
156 currentFileFormat = format;
157 reload.setEnabled(true);
160 void addKeyListener()
162 addKeyListener(new KeyAdapter()
164 public void keyPressed(KeyEvent evt)
166 if (viewport.cursorMode
167 && evt.getKeyCode() >= KeyEvent.VK_0
168 && evt.getKeyCode() <= KeyEvent.VK_9)
170 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
173 switch (evt.getKeyCode())
176 case 27: // escape key
177 deselectAllSequenceMenuItem_actionPerformed(null);
181 case KeyEvent.VK_DOWN:
182 if (viewport.cursorMode)
184 alignPanel.seqPanel.moveCursor(0, 1);
187 moveSelectedSequences(false);
191 if (viewport.cursorMode)
193 alignPanel.seqPanel.moveCursor(0, -1);
196 moveSelectedSequences(true);
199 case KeyEvent.VK_LEFT:
200 if (viewport.cursorMode)
202 alignPanel.seqPanel.moveCursor( -1, 0);
206 case KeyEvent.VK_RIGHT:
207 if (viewport.cursorMode)
209 alignPanel.seqPanel.moveCursor(1, 0);
213 case KeyEvent.VK_SPACE:
214 if (viewport.cursorMode)
216 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
222 case KeyEvent.VK_DELETE:
223 case KeyEvent.VK_BACK_SPACE:
224 if (!viewport.cursorMode)
226 cut_actionPerformed(null);
229 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
236 if (viewport.cursorMode)
238 alignPanel.seqPanel.setCursorRow();
242 if (viewport.cursorMode && !evt.isControlDown())
244 alignPanel.seqPanel.setCursorColumn();
248 if (viewport.cursorMode)
250 alignPanel.seqPanel.setCursorPosition();
254 case KeyEvent.VK_ENTER:
255 case KeyEvent.VK_COMMA:
256 if (viewport.cursorMode)
258 alignPanel.seqPanel.setCursorRowAndColumn();
263 if (viewport.cursorMode)
265 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
269 if (viewport.cursorMode)
271 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
276 viewport.cursorMode = !viewport.cursorMode;
277 statusBar.setText("Keyboard editing mode is " +
278 (viewport.cursorMode ? "on" : "off"));
279 if (viewport.cursorMode)
281 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
282 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
284 alignPanel.seqPanel.seqCanvas.repaint();
290 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
291 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
292 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
294 javax.help.HelpBroker hb = hs.createHelpBroker();
295 hb.setCurrentID("home");
296 hb.setDisplayed(true);
300 ex.printStackTrace();
306 boolean toggleSeqs = !evt.isControlDown();
307 boolean toggleCols = !evt.isShiftDown();
309 boolean hide = false;
311 SequenceGroup sg = viewport.getSelectionGroup();
314 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
316 hideSelSequences_actionPerformed(null);
319 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
320 showAllSeqs_actionPerformed(null);
325 if (viewport.colSel.getSelected().size() > 0)
327 hideSelColumns_actionPerformed(null);
329 viewport.selectionGroup = sg;
332 showAllColumns_actionPerformed(null);
336 case KeyEvent.VK_PAGE_UP:
337 if (viewport.wrapAlignment)
338 alignPanel.scrollUp(true);
340 alignPanel.setScrollValues(viewport.startRes,
342 - viewport.endSeq + viewport.startSeq);
344 case KeyEvent.VK_PAGE_DOWN:
345 if (viewport.wrapAlignment)
346 alignPanel.scrollUp(false);
348 alignPanel.setScrollValues(viewport.startRes,
350 + viewport.endSeq - viewport.startSeq);
358 public void addAlignmentPanel(final AlignmentPanel ap,
361 ap.alignFrame = this;
363 alignPanels.addElement(ap);
365 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
367 int aSize = alignPanels.size();
369 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
371 if (aSize == 1 && ap.av.viewName==null)
373 this.getContentPane().add(ap, BorderLayout.CENTER);
379 setInitialTabVisible();
382 expandViews.setEnabled(true);
383 gatherViews.setEnabled(true);
384 tabbedPane.addTab(ap.av.viewName, ap);
386 ap.setVisible(false);
392 ap.av.alignment.padGaps();
393 ap.av.updateConservation(ap);
394 ap.av.updateConsensus(ap);
398 public void setInitialTabVisible()
400 expandViews.setEnabled(true);
401 gatherViews.setEnabled(true);
402 tabbedPane.setVisible(true);
403 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
404 tabbedPane.addTab(first.av.viewName,first);
405 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
409 public AlignViewport getViewport()
414 /* Set up intrinsic listeners for dynamically generated GUI bits. */
415 private void addServiceListeners()
417 final java.beans.PropertyChangeListener thisListener;
418 // Do this once to get current state
419 BuildWebServiceMenu();
420 Desktop.discoverer.addPropertyChangeListener(
421 thisListener = new java.beans.PropertyChangeListener()
423 public void propertyChange(PropertyChangeEvent evt)
425 // System.out.println("Discoverer property change.");
426 if (evt.getPropertyName().equals("services"))
428 // System.out.println("Rebuilding web service menu");
429 BuildWebServiceMenu();
434 addInternalFrameListener(new javax.swing.event.
435 InternalFrameAdapter()
437 public void internalFrameClosed(
438 javax.swing.event.InternalFrameEvent evt)
440 // System.out.println("deregistering discoverer listener");
441 Desktop.discoverer.removePropertyChangeListener(thisListener);
442 closeMenuItem_actionPerformed(true);
448 public void setGUINucleotide(boolean nucleotide)
450 showTranslation.setVisible( nucleotide );
451 conservationMenuItem.setEnabled( !nucleotide );
452 modifyConservation.setEnabled( !nucleotide );
454 //Remember AlignFrame always starts as protein
457 calculateMenu.remove(calculateMenu.getItemCount()-2);
462 * Need to call this method when tabs are selected for multiple views,
463 * or when loading from Jalview2XML.java
464 * @param av AlignViewport
466 void setMenusFromViewport(AlignViewport av)
468 padGapsMenuitem.setSelected(av.padGaps);
469 colourTextMenuItem.setSelected(av.showColourText);
470 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
471 conservationMenuItem.setSelected(av.getConservationSelected());
472 seqLimits.setSelected(av.getShowJVSuffix());
473 idRightAlign.setSelected(av.rightAlignIds);
474 renderGapsMenuItem.setSelected(av.renderGaps);
475 wrapMenuItem.setSelected(av.wrapAlignment);
476 annotationPanelMenuItem.setState(av.showAnnotation);
477 viewBoxesMenuItem.setSelected(av.showBoxes);
478 viewTextMenuItem.setSelected(av.showText);
480 setColourSelected(ColourSchemeProperty.
481 getColourName(av.getGlobalColourScheme()));
483 showSeqFeatures.setSelected(av.showSequenceFeatures);
484 hiddenMarkers.setState(av.showHiddenMarkers);
485 applyToAllGroups.setState(av.colourAppliesToAllGroups);
491 Hashtable progressBars;
492 public void setProgressBar(String message, long id)
494 if(progressBars == null)
495 progressBars = new Hashtable();
497 JPanel progressPanel;
498 GridLayout layout = (GridLayout) statusPanel.getLayout();
499 if(progressBars.get( new Long(id) )!=null)
501 progressPanel = (JPanel)progressBars.get( new Long(id) );
502 statusPanel.remove(progressPanel);
503 progressBars.remove( progressPanel );
504 progressPanel = null;
506 statusBar.setText(message);
508 layout.setRows(layout.getRows() - 1);
512 progressPanel = new JPanel(new BorderLayout(10, 5));
514 JProgressBar progressBar = new JProgressBar();
515 progressBar.setIndeterminate(true);
517 progressPanel.add(new JLabel(message), BorderLayout.WEST);
518 progressPanel.add(progressBar, BorderLayout.CENTER);
520 layout.setRows(layout.getRows() + 1);
521 statusPanel.add(progressPanel);
523 progressBars.put(new Long(id), progressPanel);
533 Added so Castor Mapping file can obtain Jalview Version
535 public String getVersion()
537 return jalview.bin.Cache.getProperty("VERSION");
540 public FeatureRenderer getFeatureRenderer()
542 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
546 public void fetchSequence_actionPerformed(ActionEvent e)
548 new SequenceFetcher(this);
551 public void addFromFile_actionPerformed(ActionEvent e)
553 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
556 public void reload_actionPerformed(ActionEvent e)
560 if(currentFileFormat.equals("Jalview"))
562 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
563 for(int i=0; i<frames.length; i++)
565 if (frames[i] instanceof AlignFrame
567 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
570 frames[i].setSelected(true);
571 Desktop.instance.closeAssociatedWindows();
572 }catch(java.beans.PropertyVetoException ex){}
576 Desktop.instance.closeAssociatedWindows();
581 viewport.alignment.deleteAllGroups();
582 viewport.sequenceColours=null;
583 while (viewport.alignment.getHeight() > 0)
585 viewport.alignment.deleteSequence(0);
588 viewport.historyList.clear();
589 viewport.redoList.clear();
590 Alignment dset = viewport.alignment.getDataset();
591 while (dset.getHeight() > 0)
593 dset.deleteSequence(0);
596 firePropertyChange("Alignment", null, null);
601 FileLoader loader = new FileLoader();
602 String protocol = fileName.startsWith("http:")? "URL":"File";
603 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
609 public void addFromText_actionPerformed(ActionEvent e)
611 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
614 public void addFromURL_actionPerformed(ActionEvent e)
616 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
620 public void save_actionPerformed(ActionEvent e)
622 if(fileName==null || currentFileFormat==null)
623 saveAs_actionPerformed(null);
625 saveAlignment(fileName, currentFileFormat);
631 * @param e DOCUMENT ME!
633 public void saveAs_actionPerformed(ActionEvent e)
635 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
636 getProperty( "LAST_DIRECTORY"),
638 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
640 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
645 chooser.setFileView(new JalviewFileView());
646 chooser.setDialogTitle("Save Alignment to file");
647 chooser.setToolTipText("Save");
649 int value = chooser.showSaveDialog(this);
651 if (value == JalviewFileChooser.APPROVE_OPTION)
653 currentFileFormat = chooser.getSelectedFormat();
654 if (currentFileFormat == null)
656 JOptionPane.showInternalMessageDialog(Desktop.desktop,
657 "You must select a file format before saving!",
658 "File format not specified",
659 JOptionPane.WARNING_MESSAGE);
660 value = chooser.showSaveDialog(this);
664 fileName = chooser.getSelectedFile().getPath();
666 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
669 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
671 saveAlignment(fileName, currentFileFormat);
675 public boolean saveAlignment(String file, String format)
677 if (format.equalsIgnoreCase("Jalview"))
679 String shortName = title;
681 if (shortName.indexOf(java.io.File.separatorChar) > -1)
683 shortName = shortName.substring(shortName.lastIndexOf(
684 java.io.File.separatorChar) + 1);
687 new Jalview2XML().SaveAlignment(this, file, shortName);
689 statusBar.setText("Successfully saved to file: "
691 +format +" format.");
694 // USE Jalview2XML to save this file
700 String[] omitHidden = null;
702 if (viewport.hasHiddenColumns)
704 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
705 "The Alignment contains hidden columns."
706 + "\nDo you want to save only the visible alignment?",
707 "Save / Omit Hidden Columns",
708 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
710 if (reply == JOptionPane.YES_OPTION)
711 omitHidden = viewport.getViewAsString(false);
714 String output = new FormatAdapter().formatSequences(
716 viewport.alignment.getSequencesArray(),
726 java.io.PrintWriter out = new java.io.PrintWriter(
727 new java.io.FileWriter(file));
732 statusBar.setText("Successfully saved to file: "
734 +format +" format.");
739 ex.printStackTrace();
748 * @param e DOCUMENT ME!
750 protected void outputText_actionPerformed(ActionEvent e)
752 String [] omitHidden = null;
754 if(viewport.hasHiddenColumns)
756 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
757 "The Alignment contains hidden columns."
758 +"\nDo you want to output only the visible alignment?",
759 "Save / Omit Hidden Columns",
760 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
762 if(reply==JOptionPane.YES_OPTION)
764 omitHidden = viewport.getViewAsString(false);
768 CutAndPasteTransfer cap = new CutAndPasteTransfer();
769 cap.setForInput(null);
770 Desktop.addInternalFrame(cap,
771 "Alignment output - " + e.getActionCommand(), 600,
775 cap.setText(new FormatAdapter().formatSequences(
776 e.getActionCommand(),
777 viewport.alignment.getSequencesArray(),
784 * @param e DOCUMENT ME!
786 protected void htmlMenuItem_actionPerformed(ActionEvent e)
788 new HTMLOutput(viewport,
789 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
790 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
793 public void createImageMap(File file, String image)
795 alignPanel.makePNGImageMap(file, image);
801 * @param e DOCUMENT ME!
803 public void createPNG(File f)
805 alignPanel.makePNG(f);
811 * @param e DOCUMENT ME!
813 public void createEPS(File f)
815 alignPanel.makeEPS(f);
821 * @param e DOCUMENT ME!
823 public void printMenuItem_actionPerformed(ActionEvent e)
825 //Putting in a thread avoids Swing painting problems
826 PrintThread thread = new PrintThread();
830 public void exportFeatures_actionPerformed(ActionEvent e)
832 new AnnotationExporter().exportFeatures(alignPanel);
836 public void exportAnnotations_actionPerformed(ActionEvent e)
838 new AnnotationExporter().exportAnnotations(
840 viewport.alignment.getAlignmentAnnotation()
845 public void associatedData_actionPerformed(ActionEvent e)
847 // Pick the tree file
848 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
851 chooser.setFileView(new JalviewFileView());
852 chooser.setDialogTitle("Load Jalview Annotations or Features File");
853 chooser.setToolTipText("Load Jalview Annotations / Features file");
855 int value = chooser.showOpenDialog(null);
857 if (value == JalviewFileChooser.APPROVE_OPTION)
859 String choice = chooser.getSelectedFile().getPath();
860 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
861 loadJalviewDataFile(choice);
870 * @param e DOCUMENT ME!
872 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
874 if(alignPanels!=null && alignPanels.size()<2)
879 if(alignPanels!=null)
882 for (int i = 0; i < alignPanels.size(); i++)
884 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
885 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
886 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
887 PaintRefresher.RemoveComponent(ap);
891 int index = tabbedPane.getSelectedIndex();
893 alignPanels.removeElement(alignPanel);
894 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
895 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
896 PaintRefresher.RemoveComponent(alignPanel);
900 tabbedPane.removeTabAt(index);
901 tabbedPane.validate();
903 if(index==tabbedPane.getTabCount())
906 this.tabSelectionChanged(index);
911 this.setClosed(true);
915 ex.printStackTrace();
923 void updateEditMenuBar()
926 if (viewport.historyList.size() > 0)
928 undoMenuItem.setEnabled(true);
929 CommandI command = (CommandI) viewport.historyList.peek();
930 undoMenuItem.setText("Undo " + command.getDescription());
934 undoMenuItem.setEnabled(false);
935 undoMenuItem.setText("Undo");
938 if (viewport.redoList.size() > 0)
940 redoMenuItem.setEnabled(true);
942 CommandI command = (CommandI) viewport.redoList.peek();
943 redoMenuItem.setText("Redo " + command.getDescription());
947 redoMenuItem.setEnabled(false);
948 redoMenuItem.setText("Redo");
953 public void addHistoryItem(CommandI command)
955 if(command.getSize()>0)
957 viewport.historyList.push(command);
958 viewport.redoList.clear();
960 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
969 * @param e DOCUMENT ME!
971 protected void undoMenuItem_actionPerformed(ActionEvent e)
973 CommandI command = (CommandI)viewport.historyList.pop();
974 viewport.redoList.push(command);
975 command.undoCommand();
977 AlignViewport originalSource = getOriginatingSource(command);
979 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
981 originalSource.firePropertyChange("alignment", null,viewport.getAlignment().getSequences());
987 * @param e DOCUMENT ME!
989 protected void redoMenuItem_actionPerformed(ActionEvent e)
991 CommandI command = (CommandI) viewport.redoList.pop();
992 viewport.historyList.push(command);
995 AlignViewport originalSource = getOriginatingSource(command);
996 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null;
999 originalSource.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1002 AlignViewport getOriginatingSource(CommandI command)
1004 AlignViewport originalSource = viewport;
1005 //For sequence removal and addition, we need to fire
1006 //the property change event FROM the viewport where the
1007 //original alignment was altered
1008 if (command instanceof EditCommand)
1010 EditCommand editCommand = (EditCommand) command;
1011 AlignmentI al = editCommand.getAlignment();
1012 Vector comps = (Vector) PaintRefresher.components
1013 .get(viewport.getSequenceSetId());
1014 for (int i = 0; i < comps.size(); i++)
1016 if (comps.elementAt(i) instanceof AlignmentPanel)
1018 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1020 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1026 return originalSource;
1032 * @param up DOCUMENT ME!
1034 public void moveSelectedSequences(boolean up)
1036 SequenceGroup sg = viewport.getSelectionGroup();
1045 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1047 SequenceI seq = viewport.alignment.getSequenceAt(i);
1049 if (!sg.getSequences(false).contains(seq))
1054 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1056 if (sg.getSequences(false).contains(temp))
1061 viewport.alignment.getSequences().setElementAt(temp, i);
1062 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1067 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1069 SequenceI seq = viewport.alignment.getSequenceAt(i);
1071 if (!sg.getSequences(false).contains(seq))
1076 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1078 if (sg.getSequences(false).contains(temp))
1083 viewport.alignment.getSequences().setElementAt(temp, i);
1084 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1088 alignPanel.repaint();
1096 * @param e DOCUMENT ME!
1098 protected void copy_actionPerformed(ActionEvent e)
1101 if (viewport.getSelectionGroup() == null)
1106 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1107 String[] omitHidden = null;
1109 if (viewport.hasHiddenColumns)
1111 omitHidden = viewport.getViewAsString(true);
1114 String output = new FormatAdapter().formatSequences(
1119 StringSelection ss = new StringSelection(output);
1123 //Its really worth setting the clipboard contents
1124 //to empty before setting the large StringSelection!!
1125 Toolkit.getDefaultToolkit().getSystemClipboard()
1126 .setContents(new StringSelection(""), null);
1128 Toolkit.getDefaultToolkit().getSystemClipboard()
1129 .setContents(ss, Desktop.instance);
1131 catch (OutOfMemoryError er)
1133 er.printStackTrace();
1134 javax.swing.SwingUtilities.invokeLater(new Runnable()
1138 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1139 "Out of memory copying region!!"
1141 "\nSee help files for increasing Java Virtual Machine memory."
1143 javax.swing.JOptionPane.WARNING_MESSAGE);
1150 Vector hiddenColumns = null;
1151 if(viewport.hasHiddenColumns)
1153 hiddenColumns =new Vector();
1154 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1155 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1157 int[] region = (int[])
1158 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1160 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1161 region[1]-hiddenOffset});
1167 Desktop.jalviewClipboard = new Object[]{ seqs,
1168 viewport.alignment.getDataset(),
1170 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1176 * @param e DOCUMENT ME!
1178 protected void pasteNew_actionPerformed(ActionEvent e)
1186 * @param e DOCUMENT ME!
1188 protected void pasteThis_actionPerformed(ActionEvent e)
1196 * @param newAlignment DOCUMENT ME!
1198 void paste(boolean newAlignment)
1202 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1203 Transferable contents = c.getContents(this);
1205 if (contents == null)
1213 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1214 if (str.length() < 1)
1217 format = new IdentifyFile().Identify(str, "Paste");
1220 catch (OutOfMemoryError er)
1222 er.printStackTrace();
1223 javax.swing.SwingUtilities.invokeLater(new Runnable()
1227 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1228 "Out of memory pasting sequences!!"
1230 "\nSee help files for increasing Java Virtual Machine memory."
1232 javax.swing.JOptionPane.WARNING_MESSAGE);
1239 SequenceI[] sequences;
1242 if(Desktop.jalviewClipboard!=null)
1244 // The clipboard was filled from within Jalview, we must use the sequences
1245 // And dataset from the copied alignment
1246 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1250 sequences = new FormatAdapter().readFile(str, "Paste", format);
1253 AlignmentI alignment = null;
1257 alignment = new Alignment(sequences);
1259 if (Desktop.jalviewClipboard != null)
1260 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1262 alignment.setDataset(null);
1266 alignment = viewport.getAlignment();
1269 SequenceI [] newseqs = new SequenceI[sequences.length];
1270 for (int i = 0; i < sequences.length; i++)
1272 newseqs[i] = new Sequence(sequences[i].getName(),
1273 sequences[i].getSequence(), sequences[i].getStart(),
1274 sequences[i].getEnd());
1276 alignment.addSequence(newseqs[i]);
1282 addHistoryItem(new EditCommand(
1287 alignment.getWidth(),
1292 viewport.setEndSeq(alignment.getHeight());
1293 alignment.getWidth();
1294 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1299 // Add any annotations attached to sequences
1300 for (int i = 0; i < sequences.length; i++)
1302 if (sequences[i].getAnnotation() != null)
1304 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1306 AlignmentAnnotation newAnnot =
1307 new AlignmentAnnotation(
1308 sequences[i].getAnnotation()[a].label,
1309 sequences[i].getAnnotation()[a].description,
1310 sequences[i].getAnnotation()[a].annotations,
1311 sequences[i].getAnnotation()[a].graphMin,
1312 sequences[i].getAnnotation()[a].graphMax,
1313 sequences[i].getAnnotation()[a].graph);
1315 sequences[i].getAnnotation()[a] = newAnnot;
1316 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1318 newAnnot.sequenceRef = sequences[i];
1319 newAnnot.adjustForAlignment();
1320 alignment.addAnnotation(newAnnot);
1321 alignment.setAnnotationIndex(newAnnot, a);
1324 alignPanel.annotationPanel.adjustPanelHeight();
1330 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1331 String newtitle = new String("Copied sequences");
1333 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1335 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1336 for(int i=0; i<hc.size(); i++)
1338 int [] region = (int[]) hc.elementAt(i);
1339 af.viewport.hideColumns(region[0], region[1]);
1344 //>>>This is a fix for the moment, until a better solution is found!!<<<
1345 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1346 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1349 if (title.startsWith("Copied sequences"))
1355 newtitle = newtitle.concat("- from " + title);
1358 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1365 catch (Exception ex)
1367 ex.printStackTrace();
1368 System.out.println("Exception whilst pasting: "+ex);
1369 // could be anything being pasted in here
1378 * @param e DOCUMENT ME!
1380 protected void cut_actionPerformed(ActionEvent e)
1382 copy_actionPerformed(null);
1383 delete_actionPerformed(null);
1389 * @param e DOCUMENT ME!
1391 protected void delete_actionPerformed(ActionEvent evt)
1394 SequenceGroup sg = viewport.getSelectionGroup();
1400 Vector seqs = new Vector();
1402 for (int i = 0; i < sg.getSize(false); i++)
1404 seq = sg.getSequenceAt(i);
1405 seqs.addElement(seq);
1409 // If the cut affects all sequences, remove highlighted columns
1410 if (sg.getSize(false) == viewport.alignment.getHeight())
1412 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1413 sg.getEndRes() + 1);
1417 SequenceI [] cut = new SequenceI[seqs.size()];
1418 for(int i=0; i<seqs.size(); i++)
1419 cut[i] = (SequenceI)seqs.elementAt(i);
1425 addHistoryItem(new EditCommand("Cut Sequences",
1429 sg.getEndRes()-sg.getStartRes()+1,
1430 viewport.alignment));
1433 viewport.setSelectionGroup(null);
1434 viewport.alignment.deleteGroup(sg);
1436 viewport.firePropertyChange("alignment", null,
1437 viewport.getAlignment().getSequences());
1439 if (viewport.getAlignment().getHeight() < 1)
1443 this.setClosed(true);
1445 catch (Exception ex)
1454 * @param e DOCUMENT ME!
1456 protected void deleteGroups_actionPerformed(ActionEvent e)
1458 viewport.alignment.deleteAllGroups();
1459 viewport.sequenceColours.clear();
1460 viewport.setSelectionGroup(null);
1461 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1462 alignPanel.repaint();
1468 * @param e DOCUMENT ME!
1470 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1472 SequenceGroup sg = new SequenceGroup();
1474 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1477 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1480 sg.setEndRes(viewport.alignment.getWidth() - 1);
1481 viewport.setSelectionGroup(sg);
1482 alignPanel.repaint();
1483 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1489 * @param e DOCUMENT ME!
1491 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1493 if(viewport.cursorMode)
1495 alignPanel.seqPanel.keyboardNo1 = null;
1496 alignPanel.seqPanel.keyboardNo2 = null;
1498 viewport.setSelectionGroup(null);
1499 viewport.getColumnSelection().clear();
1500 viewport.setSelectionGroup(null);
1501 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1502 alignPanel.idPanel.idCanvas.searchResults = null;
1503 alignPanel.repaint();
1504 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1510 * @param e DOCUMENT ME!
1512 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1514 SequenceGroup sg = viewport.getSelectionGroup();
1518 selectAllSequenceMenuItem_actionPerformed(null);
1523 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1526 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1529 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1532 public void invertColSel_actionPerformed(ActionEvent e)
1534 viewport.invertColumnSelection();
1535 alignPanel.repaint();
1542 * @param e DOCUMENT ME!
1544 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1546 trimAlignment(true);
1552 * @param e DOCUMENT ME!
1554 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1556 trimAlignment(false);
1559 void trimAlignment(boolean trimLeft)
1561 ColumnSelection colSel = viewport.getColumnSelection();
1564 if (colSel.size() > 0)
1567 column = colSel.getMin();
1569 column = colSel.getMax();
1572 if(viewport.getSelectionGroup()!=null)
1573 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1575 seqs = viewport.alignment.getSequencesArray();
1578 TrimRegionCommand trimRegion;
1581 trimRegion = new TrimRegionCommand("Remove Left",
1582 TrimRegionCommand.TRIM_LEFT,
1587 viewport.selectionGroup);
1588 viewport.setStartRes(0);
1592 trimRegion = new TrimRegionCommand("Remove Right",
1593 TrimRegionCommand.TRIM_RIGHT,
1598 viewport.selectionGroup);
1601 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1604 addHistoryItem(trimRegion);
1606 Vector groups = viewport.alignment.getGroups();
1608 for (int i = 0; i < groups.size(); i++)
1610 SequenceGroup sg = (SequenceGroup) groups.get(i);
1612 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1613 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1615 viewport.alignment.deleteGroup(sg);
1619 viewport.firePropertyChange("alignment", null,
1620 viewport.getAlignment().getSequences());
1627 * @param e DOCUMENT ME!
1629 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1631 int start = 0, end = viewport.alignment.getWidth()-1;
1634 if (viewport.getSelectionGroup() != null)
1636 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1637 start = viewport.getSelectionGroup().getStartRes();
1638 end = viewport.getSelectionGroup().getEndRes();
1641 seqs = viewport.alignment.getSequencesArray();
1644 RemoveGapColCommand removeGapCols =
1645 new RemoveGapColCommand("Remove Gapped Columns",
1648 viewport.getGapCharacter());
1650 addHistoryItem(removeGapCols);
1652 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1654 //This is to maintain viewport position on first residue
1656 SequenceI seq = viewport.alignment.getSequenceAt(0);
1657 int startRes = seq.findPosition(viewport.startRes);
1658 // ShiftList shifts;
1659 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1660 // edit.alColumnChanges=shifts.getInverse();
1661 // if (viewport.hasHiddenColumns)
1662 // viewport.getColumnSelection().compensateForEdits(shifts);
1663 viewport.setStartRes(seq.findIndex(startRes)-1);
1664 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1671 * @param e DOCUMENT ME!
1673 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1675 int start = 0, end = viewport.alignment.getWidth()-1;
1678 if (viewport.getSelectionGroup() != null)
1680 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1681 start = viewport.getSelectionGroup().getStartRes();
1682 end = viewport.getSelectionGroup().getEndRes();
1685 seqs = viewport.alignment.getSequencesArray();
1687 //This is to maintain viewport position on first residue
1689 SequenceI seq = viewport.alignment.getSequenceAt(0);
1690 int startRes = seq.findPosition(viewport.startRes);
1692 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1695 viewport.getGapCharacter()));
1697 viewport.setStartRes(seq.findIndex(startRes)-1);
1699 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1706 * @param e DOCUMENT ME!
1708 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1710 viewport.padGaps = padGapsMenuitem.isSelected();
1712 viewport.firePropertyChange("alignment",
1714 viewport.getAlignment().getSequences());
1720 * @param e DOCUMENT ME!
1722 public void findMenuItem_actionPerformed(ActionEvent e)
1727 public void newView_actionPerformed(ActionEvent e)
1729 AlignmentPanel newap =
1730 new Jalview2XML().copyAlignPanel(alignPanel, true);
1732 if (viewport.viewName == null)
1733 viewport.viewName = "Original";
1735 newap.av.historyList = viewport.historyList;
1736 newap.av.redoList = viewport.redoList;
1738 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1739 String newViewName = "View " +index;
1741 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
1742 Vector existingNames = new Vector();
1743 for(int i=0; i<comps.size(); i++)
1745 if(comps.elementAt(i) instanceof AlignmentPanel)
1747 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
1748 if(!existingNames.contains(ap.av.viewName))
1749 existingNames.addElement(ap.av.viewName);
1753 while(existingNames.contains(newViewName))
1755 newViewName = "View "+ (++index);
1758 newap.av.viewName = newViewName;
1760 addAlignmentPanel(newap, false);
1762 if(alignPanels.size()==2)
1764 viewport.gatherViewsHere = true;
1766 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1769 public void expandViews_actionPerformed(ActionEvent e)
1771 Desktop.instance.explodeViews(this);
1774 public void gatherViews_actionPerformed(ActionEvent e)
1776 Desktop.instance.gatherViews(this);
1784 * @param e DOCUMENT ME!
1786 public void font_actionPerformed(ActionEvent e)
1788 new FontChooser(alignPanel);
1795 * @param e DOCUMENT ME!
1797 protected void seqLimit_actionPerformed(ActionEvent e)
1799 viewport.setShowJVSuffix(seqLimits.isSelected());
1801 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1802 alignPanel.repaint();
1805 public void idRightAlign_actionPerformed(ActionEvent e)
1807 viewport.rightAlignIds = idRightAlign.isSelected();
1808 alignPanel.repaint();
1816 * @param e DOCUMENT ME!
1818 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1820 viewport.setColourText(colourTextMenuItem.isSelected());
1821 alignPanel.repaint();
1827 * @param e DOCUMENT ME!
1829 public void wrapMenuItem_actionPerformed(ActionEvent e)
1831 scaleAbove.setVisible(wrapMenuItem.isSelected());
1832 scaleLeft.setVisible(wrapMenuItem.isSelected());
1833 scaleRight.setVisible(wrapMenuItem.isSelected());
1834 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1835 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1838 public void showAllSeqs_actionPerformed(ActionEvent e)
1840 viewport.showAllHiddenSeqs();
1843 public void showAllColumns_actionPerformed(ActionEvent e)
1845 viewport.showAllHiddenColumns();
1849 public void hideSelSequences_actionPerformed(ActionEvent e)
1851 viewport.hideAllSelectedSeqs();
1852 alignPanel.repaint();
1855 public void hideSelColumns_actionPerformed(ActionEvent e)
1857 viewport.hideSelectedColumns();
1858 alignPanel.repaint();
1861 public void hiddenMarkers_actionPerformed(ActionEvent e)
1863 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1870 * @param e DOCUMENT ME!
1872 protected void scaleAbove_actionPerformed(ActionEvent e)
1874 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1875 alignPanel.repaint();
1881 * @param e DOCUMENT ME!
1883 protected void scaleLeft_actionPerformed(ActionEvent e)
1885 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1886 alignPanel.repaint();
1892 * @param e DOCUMENT ME!
1894 protected void scaleRight_actionPerformed(ActionEvent e)
1896 viewport.setScaleRightWrapped(scaleRight.isSelected());
1897 alignPanel.repaint();
1903 * @param e DOCUMENT ME!
1905 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1907 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1908 alignPanel.repaint();
1914 * @param e DOCUMENT ME!
1916 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1918 viewport.setShowText(viewTextMenuItem.isSelected());
1919 alignPanel.repaint();
1925 * @param e DOCUMENT ME!
1927 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1929 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1930 alignPanel.repaint();
1934 public FeatureSettings featureSettings;
1935 public void featureSettings_actionPerformed(ActionEvent e)
1937 if(featureSettings !=null )
1939 featureSettings.close();
1940 featureSettings = null;
1942 featureSettings = new FeatureSettings(this);
1948 * @param evt DOCUMENT ME!
1950 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1952 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1953 alignPanel.repaint();
1954 if (alignPanel.getOverviewPanel() != null)
1956 alignPanel.getOverviewPanel().updateOverviewImage();
1963 * @param e DOCUMENT ME!
1965 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1967 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1968 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1974 * @param e DOCUMENT ME!
1976 public void overviewMenuItem_actionPerformed(ActionEvent e)
1978 if (alignPanel.overviewPanel != null)
1983 JInternalFrame frame = new JInternalFrame();
1984 OverviewPanel overview = new OverviewPanel(alignPanel);
1985 frame.setContentPane(overview);
1986 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1987 frame.getWidth(), frame.getHeight());
1989 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1990 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1992 public void internalFrameClosed(
1993 javax.swing.event.InternalFrameEvent evt)
1995 alignPanel.setOverviewPanel(null);
2000 alignPanel.setOverviewPanel(overview);
2003 public void textColour_actionPerformed(ActionEvent e)
2005 new TextColourChooser().chooseColour(alignPanel, null);
2011 * @param e DOCUMENT ME!
2013 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2021 * @param e DOCUMENT ME!
2023 public void clustalColour_actionPerformed(ActionEvent e)
2025 changeColour(new ClustalxColourScheme(
2026 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2032 * @param e DOCUMENT ME!
2034 public void zappoColour_actionPerformed(ActionEvent e)
2036 changeColour(new ZappoColourScheme());
2042 * @param e DOCUMENT ME!
2044 public void taylorColour_actionPerformed(ActionEvent e)
2046 changeColour(new TaylorColourScheme());
2052 * @param e DOCUMENT ME!
2054 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2056 changeColour(new HydrophobicColourScheme());
2062 * @param e DOCUMENT ME!
2064 public void helixColour_actionPerformed(ActionEvent e)
2066 changeColour(new HelixColourScheme());
2072 * @param e DOCUMENT ME!
2074 public void strandColour_actionPerformed(ActionEvent e)
2076 changeColour(new StrandColourScheme());
2082 * @param e DOCUMENT ME!
2084 public void turnColour_actionPerformed(ActionEvent e)
2086 changeColour(new TurnColourScheme());
2092 * @param e DOCUMENT ME!
2094 public void buriedColour_actionPerformed(ActionEvent e)
2096 changeColour(new BuriedColourScheme());
2102 * @param e DOCUMENT ME!
2104 public void nucleotideColour_actionPerformed(ActionEvent e)
2106 changeColour(new NucleotideColourScheme());
2109 public void annotationColour_actionPerformed(ActionEvent e)
2111 new AnnotationColourChooser(viewport, alignPanel);
2118 * @param e DOCUMENT ME!
2120 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2122 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2128 * @param cs DOCUMENT ME!
2130 public void changeColour(ColourSchemeI cs)
2136 if (viewport.getAbovePIDThreshold())
2138 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2141 cs.setThreshold(threshold,
2142 viewport.getIgnoreGapsConsensus());
2144 viewport.setGlobalColourScheme(cs);
2148 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2151 if (viewport.getConservationSelected())
2154 Alignment al = (Alignment) viewport.alignment;
2155 Conservation c = new Conservation("All",
2156 ResidueProperties.propHash, 3,
2157 al.getSequences(), 0,
2161 c.verdict(false, viewport.ConsPercGaps);
2163 cs.setConservation(c);
2165 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2170 cs.setConservation(null);
2173 cs.setConsensus(viewport.hconsensus);
2176 viewport.setGlobalColourScheme(cs);
2178 if (viewport.getColourAppliesToAllGroups())
2180 Vector groups = viewport.alignment.getGroups();
2182 for (int i = 0; i < groups.size(); i++)
2184 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2192 if (cs instanceof ClustalxColourScheme)
2194 sg.cs = new ClustalxColourScheme(
2195 sg.getSequences(true), sg.getWidth());
2197 else if (cs instanceof UserColourScheme)
2199 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2205 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2207 catch (Exception ex)
2212 if (viewport.getAbovePIDThreshold()
2213 || cs instanceof PIDColourScheme
2214 || cs instanceof Blosum62ColourScheme)
2216 sg.cs.setThreshold(threshold,
2217 viewport.getIgnoreGapsConsensus());
2219 sg.cs.setConsensus(AAFrequency.calculate(
2220 sg.getSequences(true), sg.getStartRes(),
2224 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2227 if (viewport.getConservationSelected())
2229 Conservation c = new Conservation("Group",
2230 ResidueProperties.propHash, 3,
2231 sg.getSequences(true),
2235 c.verdict(false, viewport.ConsPercGaps);
2236 sg.cs.setConservation(c);
2239 sg.cs.setConservation(null);
2243 if (alignPanel.getOverviewPanel() != null)
2245 alignPanel.getOverviewPanel().updateOverviewImage();
2248 alignPanel.repaint();
2254 * @param e DOCUMENT ME!
2256 protected void modifyPID_actionPerformed(ActionEvent e)
2258 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2260 SliderPanel.setPIDSliderSource(alignPanel,
2261 viewport.getGlobalColourScheme(),
2263 SliderPanel.showPIDSlider();
2270 * @param e DOCUMENT ME!
2272 protected void modifyConservation_actionPerformed(ActionEvent e)
2274 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2276 SliderPanel.setConservationSlider(alignPanel,
2277 viewport.globalColourScheme,
2279 SliderPanel.showConservationSlider();
2286 * @param e DOCUMENT ME!
2288 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2290 viewport.setConservationSelected(conservationMenuItem.isSelected());
2292 viewport.setAbovePIDThreshold(false);
2293 abovePIDThreshold.setSelected(false);
2295 changeColour(viewport.getGlobalColourScheme());
2297 modifyConservation_actionPerformed(null);
2303 * @param e DOCUMENT ME!
2305 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2307 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2309 conservationMenuItem.setSelected(false);
2310 viewport.setConservationSelected(false);
2312 changeColour(viewport.getGlobalColourScheme());
2314 modifyPID_actionPerformed(null);
2320 * @param e DOCUMENT ME!
2322 public void userDefinedColour_actionPerformed(ActionEvent e)
2324 if (e.getActionCommand().equals("User Defined..."))
2326 new UserDefinedColours(alignPanel, null);
2330 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2331 getUserColourSchemes().get(e.getActionCommand());
2337 public void updateUserColourMenu()
2340 Component[] menuItems = colourMenu.getMenuComponents();
2341 int i, iSize = menuItems.length;
2342 for (i = 0; i < iSize; i++)
2344 if (menuItems[i].getName() != null &&
2345 menuItems[i].getName().equals("USER_DEFINED"))
2347 colourMenu.remove(menuItems[i]);
2351 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2353 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2354 getUserColourSchemes().keys();
2356 while (userColours.hasMoreElements())
2358 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2359 nextElement().toString());
2360 radioItem.setName("USER_DEFINED");
2361 radioItem.addMouseListener(new MouseAdapter()
2363 public void mousePressed(MouseEvent evt)
2365 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2367 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2369 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2370 "Remove from default list?",
2371 "Remove user defined colour",
2372 JOptionPane.YES_NO_OPTION);
2373 if(option == JOptionPane.YES_OPTION)
2375 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2376 colourMenu.remove(radioItem);
2379 radioItem.addActionListener(new ActionListener()
2381 public void actionPerformed(ActionEvent evt)
2383 userDefinedColour_actionPerformed(evt);
2389 radioItem.addActionListener(new ActionListener()
2391 public void actionPerformed(ActionEvent evt)
2393 userDefinedColour_actionPerformed(evt);
2397 colourMenu.insert(radioItem, 15);
2398 colours.add(radioItem);
2406 * @param e DOCUMENT ME!
2408 public void PIDColour_actionPerformed(ActionEvent e)
2410 changeColour(new PIDColourScheme());
2416 * @param e DOCUMENT ME!
2418 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2420 changeColour(new Blosum62ColourScheme());
2426 * @param e DOCUMENT ME!
2428 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2430 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2431 AlignmentSorter.sortByPID(viewport.getAlignment(),
2432 viewport.getAlignment().getSequenceAt(0));
2433 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2434 alignPanel.repaint();
2440 * @param e DOCUMENT ME!
2442 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2444 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2445 AlignmentSorter.sortByID(viewport.getAlignment());
2446 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2447 alignPanel.repaint();
2453 * @param e DOCUMENT ME!
2455 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2457 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2458 AlignmentSorter.sortByGroup(viewport.getAlignment());
2459 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2461 alignPanel.repaint();
2467 * @param e DOCUMENT ME!
2469 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2471 new RedundancyPanel(alignPanel, this);
2478 * @param e DOCUMENT ME!
2480 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2482 if ( (viewport.getSelectionGroup() == null) ||
2483 (viewport.getSelectionGroup().getSize(false) < 2))
2485 JOptionPane.showInternalMessageDialog(this,
2486 "You must select at least 2 sequences.",
2487 "Invalid Selection",
2488 JOptionPane.WARNING_MESSAGE);
2492 JInternalFrame frame = new JInternalFrame();
2493 frame.setContentPane(new PairwiseAlignPanel(viewport));
2494 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2501 * @param e DOCUMENT ME!
2503 public void PCAMenuItem_actionPerformed(ActionEvent e)
2505 if ( ( (viewport.getSelectionGroup() != null) &&
2506 (viewport.getSelectionGroup().getSize(false) < 4) &&
2507 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2508 (viewport.getAlignment().getHeight() < 4))
2510 JOptionPane.showInternalMessageDialog(this,
2511 "Principal component analysis must take\n" +
2512 "at least 4 input sequences.",
2513 "Sequence selection insufficient",
2514 JOptionPane.WARNING_MESSAGE);
2519 new PCAPanel(viewport);
2523 public void autoCalculate_actionPerformed(ActionEvent e)
2525 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2526 if(viewport.autoCalculateConsensus)
2528 viewport.firePropertyChange("alignment",
2530 viewport.getAlignment().getSequences());
2538 * @param e DOCUMENT ME!
2540 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2542 NewTreePanel("AV", "PID", "Average distance tree using PID");
2548 * @param e DOCUMENT ME!
2550 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2552 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2558 * @param e DOCUMENT ME!
2560 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2562 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2568 * @param e DOCUMENT ME!
2570 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2572 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2578 * @param type DOCUMENT ME!
2579 * @param pwType DOCUMENT ME!
2580 * @param title DOCUMENT ME!
2582 void NewTreePanel(String type, String pwType, String title)
2586 if (viewport.getSelectionGroup() != null) {
2587 if (viewport.getSelectionGroup().getSize(false) < 3) {
2588 JOptionPane.showMessageDialog(Desktop.desktop,
2589 "You need to have more than two sequences selected to build a tree!",
2590 "Not enough sequences",
2591 JOptionPane.WARNING_MESSAGE);
2596 SequenceGroup sg = viewport.getSelectionGroup();
2598 /* Decide if the selection is a column region */
2599 while (s < sg.getSize(false))
2601 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2604 JOptionPane.showMessageDialog(Desktop.desktop,
2605 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2606 "Try using the Pad function in the edit menu,\n" +
2607 "or one of the multiple sequence alignment web services.",
2608 "Sequences in selection are not aligned",
2609 JOptionPane.WARNING_MESSAGE);
2615 title = title + " on region";
2616 tp = new TreePanel(alignPanel, type, pwType);
2620 //are the sequences aligned?
2621 if (!viewport.alignment.isAligned())
2623 JOptionPane.showMessageDialog(Desktop.desktop,
2624 "The sequences must be aligned before creating a tree.\n" +
2625 "Try using the Pad function in the edit menu,\n" +
2626 "or one of the multiple sequence alignment web services.",
2627 "Sequences not aligned",
2628 JOptionPane.WARNING_MESSAGE);
2633 if(viewport.alignment.getHeight()<2)
2636 tp = new TreePanel(alignPanel, type, pwType);
2639 addTreeMenuItem(tp, title);
2641 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2647 * @param title DOCUMENT ME!
2648 * @param order DOCUMENT ME!
2650 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2652 final JMenuItem item = new JMenuItem("by " + title);
2654 item.addActionListener(new java.awt.event.ActionListener()
2656 public void actionPerformed(ActionEvent e)
2658 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2660 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2661 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2663 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2665 alignPanel.repaint();
2671 * Maintain the Order by->Displayed Tree menu.
2672 * Creates a new menu item for a TreePanel with an appropriate
2673 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2674 * to remove the menu item when the treePanel is closed, and adjust
2675 * the tree leaf to sequence mapping when the alignment is modified.
2676 * @param treePanel Displayed tree window.
2677 * @param title SortBy menu item title.
2679 void addTreeMenuItem(final TreePanel treePanel, String title)
2681 final JMenuItem item = new JMenuItem(title);
2687 sort.add(sortByTreeMenu);
2690 sortByTreeMenu.add(item);
2691 item.addActionListener(new java.awt.event.ActionListener()
2693 public void actionPerformed(ActionEvent e)
2695 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2696 AlignmentSorter.sortByTree(viewport.getAlignment(),
2697 treePanel.getTree());
2699 addHistoryItem(new OrderCommand("Tree Sort",
2701 viewport.alignment));
2704 alignPanel.repaint();
2708 treePanel.addInternalFrameListener(new javax.swing.event.
2709 InternalFrameAdapter()
2711 public void internalFrameClosed(
2712 javax.swing.event.InternalFrameEvent evt)
2715 sortByTreeMenu.remove(item);
2719 sort.remove(sortByTreeMenu);
2727 * Work out whether the whole set of sequences
2728 * or just the selected set will be submitted for multiple alignment.
2731 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2733 // Now, check we have enough sequences
2734 AlignmentView msa = null;
2736 if ( (viewport.getSelectionGroup() != null) &&
2737 (viewport.getSelectionGroup().getSize(false) > 1))
2739 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2740 /*SequenceGroup seqs = viewport.getSelectionGroup();
2742 msa = new SequenceI[sz = seqs.getSize(false)];
2744 for (int i = 0; i < sz; i++)
2746 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2748 msa = viewport.getAlignmentView(true);
2752 /*Vector seqs = viewport.getAlignment().getSequences();
2754 if (seqs.size() > 1)
2756 msa = new SequenceI[seqs.size()];
2758 for (int i = 0; i < seqs.size(); i++)
2760 msa[i] = (SequenceI) seqs.elementAt(i);
2763 msa = viewport.getAlignmentView(false);
2769 * Decides what is submitted to a secondary structure prediction service,
2770 * the currently selected sequence, or the currently selected alignment
2771 * (where the first sequence in the set is the one that the prediction
2774 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2776 AlignmentView seqs = null;
2778 if ( (viewport.getSelectionGroup() != null) &&
2779 (viewport.getSelectionGroup().getSize(false) > 0))
2781 seqs = viewport.getAlignmentView(true);
2785 seqs = viewport.getAlignmentView(false);
2787 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2788 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2789 if (!viewport.alignment.isAligned())
2791 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2798 * @param e DOCUMENT ME!
2800 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2802 // Pick the tree file
2803 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2806 chooser.setFileView(new JalviewFileView());
2807 chooser.setDialogTitle("Select a newick-like tree file");
2808 chooser.setToolTipText("Load a tree file");
2810 int value = chooser.showOpenDialog(null);
2812 if (value == JalviewFileChooser.APPROVE_OPTION)
2814 String choice = chooser.getSelectedFile().getPath();
2815 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2819 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2821 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2823 catch (Exception ex)
2825 JOptionPane.showMessageDialog(Desktop.desktop,
2826 "Problem reading tree file",
2828 JOptionPane.WARNING_MESSAGE);
2829 ex.printStackTrace();
2835 public TreePanel ShowNewickTree(NewickFile nf, String title)
2837 return ShowNewickTree(nf,title,600,500,4,5);
2839 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2841 return ShowNewickTree(nf,title, input, 600,500,4,5);
2843 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2844 return ShowNewickTree(nf, title, null, w, h, x, y);
2847 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2849 * @param nf the tree
2850 * @param title tree viewer title
2851 * @param input Associated alignment input data (or null)
2856 * @return TreePanel handle
2858 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2859 TreePanel tp = null;
2865 if (nf.getTree() != null)
2867 tp = new TreePanel(alignPanel,
2875 tp.setLocation(x,y);
2878 Desktop.addInternalFrame(tp, title, w, h);
2879 addTreeMenuItem(tp, title);
2882 catch (Exception ex)
2884 ex.printStackTrace();
2895 PrinterJob printJob = PrinterJob.getPrinterJob();
2896 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2897 printJob.setPrintable(alignPanel, pf);
2899 if (printJob.printDialog())
2905 catch (Exception PrintException)
2907 PrintException.printStackTrace();
2914 * Generates menu items and listener event actions for web service clients
2917 public void BuildWebServiceMenu()
2919 if ( (Discoverer.services != null)
2920 && (Discoverer.services.size() > 0))
2922 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2923 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2924 Vector wsmenu = new Vector();
2925 final AlignFrame af = this;
2928 // Add any Multiple Sequence Alignment Services
2929 final JMenu msawsmenu = new JMenu("Alignment");
2930 for (int i = 0, j = msaws.size(); i < j; i++)
2932 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2934 final JMenuItem method = new JMenuItem(sh.getName());
2935 method.addActionListener(new ActionListener()
2937 public void actionPerformed(ActionEvent e)
2939 AlignmentView msa = gatherSequencesForAlignment();
2940 new jalview.ws.MsaWSClient(sh, title, msa,
2941 false, true, viewport.getAlignment().getDataset(), af);
2946 msawsmenu.add(method);
2947 // Deal with services that we know accept partial alignments.
2948 if (sh.getName().indexOf("lustal") > -1)
2950 // We know that ClustalWS can accept partial alignments for refinement.
2951 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2952 methodR.addActionListener(new ActionListener()
2954 public void actionPerformed(ActionEvent e)
2956 AlignmentView msa = gatherSequencesForAlignment();
2957 new jalview.ws.MsaWSClient(sh, title, msa,
2958 true, true, viewport.getAlignment().getDataset(), af);
2963 msawsmenu.add(methodR);
2967 wsmenu.add(msawsmenu);
2969 if (secstrpr != null)
2971 // Add any secondary structure prediction services
2972 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2973 for (int i = 0, j = secstrpr.size(); i < j; i++)
2975 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2977 final JMenuItem method = new JMenuItem(sh.getName());
2978 method.addActionListener(new ActionListener()
2980 public void actionPerformed(ActionEvent e)
2982 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2983 if (msa.getSequences().length == 1)
2985 // Single Sequence prediction
2986 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
2990 if (msa.getSequences().length > 1)
2992 // Sequence profile based prediction
2993 new jalview.ws.JPredClient(sh,
2994 title, true, msa, af, true);
2999 secstrmenu.add(method);
3001 wsmenu.add(secstrmenu);
3003 this.webService.removeAll();
3004 for (int i = 0, j = wsmenu.size(); i < j; i++)
3006 webService.add( (JMenu) wsmenu.get(i));
3011 this.webService.removeAll();
3012 this.webService.add(this.webServiceNoServices);
3014 // TODO: add in rediscovery function
3015 // TODO: reduce code redundancy.
3016 // TODO: group services by location as well as function.
3019 /* public void vamsasStore_actionPerformed(ActionEvent e)
3021 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3022 getProperty("LAST_DIRECTORY"));
3024 chooser.setFileView(new JalviewFileView());
3025 chooser.setDialogTitle("Export to Vamsas file");
3026 chooser.setToolTipText("Export");
3028 int value = chooser.showSaveDialog(this);
3030 if (value == JalviewFileChooser.APPROVE_OPTION)
3032 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3033 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3034 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3041 public void showTranslation_actionPerformed(ActionEvent e)
3043 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3044 String [] seqstring = viewport.getViewAsString(true);
3046 int s, sSize = selection.length;
3047 SequenceI [] newSeq = new SequenceI[sSize];
3050 StringBuffer protein;
3052 for(s=0; s<sSize; s++)
3054 protein = new StringBuffer();
3055 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3056 resSize = seq.length();
3057 resSize -= resSize%3;
3059 for(res = 0; res < resSize; res+=3)
3061 String codon = seq.substring(res, res+3);
3062 codon = codon.replace('U', 'T');
3063 String aa = ResidueProperties.codonTranslate(codon);
3065 protein.append(viewport.getGapCharacter());
3066 else if(aa.equals("STOP"))
3067 protein.append("X");
3069 protein.append( aa );
3071 newSeq[s] = new Sequence(selection[s].getName(),
3072 protein.toString());
3076 AlignmentI al = new Alignment(newSeq);
3077 al.setDataset(null);
3080 ////////////////////////////////
3081 // Copy annotations across
3082 jalview.datamodel.AlignmentAnnotation[] annotations
3083 = viewport.alignment.getAlignmentAnnotation();
3085 if(annotations!=null)
3087 for (int i = 0; i < annotations.length; i++)
3089 if (annotations[i].label.equals("Quality") ||
3090 annotations[i].label.equals("Conservation") ||
3091 annotations[i].label.equals("Consensus"))
3096 aSize = viewport.alignment.getWidth() / 3;
3097 jalview.datamodel.Annotation[] anots =
3098 new jalview.datamodel.Annotation[aSize];
3100 for (a = 0; a < viewport.alignment.getWidth(); a++)
3102 if (annotations[i].annotations[a] == null
3103 || annotations[i].annotations[a] == null)
3106 anots[a / 3] = new Annotation(
3107 annotations[i].annotations[a].displayCharacter,
3108 annotations[i].annotations[a].description,
3109 annotations[i].annotations[a].secondaryStructure,
3110 annotations[i].annotations[a].value,
3111 annotations[i].annotations[a].colour);
3114 jalview.datamodel.AlignmentAnnotation aa
3115 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3116 annotations[i].description, anots);
3117 al.addAnnotation(aa);
3121 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3122 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3134 * @param String DOCUMENT ME!
3136 public boolean parseFeaturesFile(String file, String type)
3138 boolean featuresFile = false;
3140 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3141 alignPanel.seqPanel.seqCanvas.
3142 getFeatureRenderer().featureColours,
3147 ex.printStackTrace();
3152 viewport.showSequenceFeatures = true;
3153 showSeqFeatures.setSelected(true);
3154 alignPanel.repaint();
3157 return featuresFile;
3160 public void dragEnter(DropTargetDragEvent evt)
3163 public void dragExit(DropTargetEvent evt)
3166 public void dragOver(DropTargetDragEvent evt)
3169 public void dropActionChanged(DropTargetDragEvent evt)
3172 public void drop(DropTargetDropEvent evt)
3174 Transferable t = evt.getTransferable();
3175 java.util.List files = null;
3179 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3180 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3182 //Works on Windows and MacOSX
3183 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3184 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3186 else if (t.isDataFlavorSupported(uriListFlavor))
3188 // This is used by Unix drag system
3189 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3190 String data = (String) t.getTransferData(uriListFlavor);
3191 files = new java.util.ArrayList(1);
3192 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3195 st.hasMoreTokens(); )
3197 String s = st.nextToken();
3198 if (s.startsWith("#"))
3200 // the line is a comment (as per the RFC 2483)
3204 java.net.URI uri = new java.net.URI(s);
3205 java.io.File file = new java.io.File(uri);
3212 e.printStackTrace();
3219 for (int i = 0; i < files.size(); i++)
3221 loadJalviewDataFile(files.get(i).toString());
3224 catch (Exception ex)
3226 ex.printStackTrace();
3231 // This method will attempt to load a "dropped" file first by testing
3232 // whether its and Annotation file, then features file. If both are
3233 // false then the user may have dropped an alignment file onto this
3235 public void loadJalviewDataFile(String file)
3238 String protocol = "File";
3240 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3245 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3250 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3253 String format = new IdentifyFile().Identify(file, protocol);
3255 if(format.equalsIgnoreCase("JnetFile"))
3257 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3259 new JnetAnnotationMaker().add_annotation(predictions,
3260 viewport.getAlignment(),
3262 alignPanel.adjustAnnotationHeight();
3263 alignPanel.repaint();
3266 new FileLoader().LoadFile(viewport, file, protocol, format);
3272 alignPanel.adjustAnnotationHeight();
3275 }catch(Exception ex)
3277 ex.printStackTrace();
3281 public void tabSelectionChanged(int index)
3285 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3286 viewport = alignPanel.av;
3287 setMenusFromViewport(viewport);
3291 public void tabbedPane_mousePressed(MouseEvent e)
3293 if(SwingUtilities.isRightMouseButton(e))
3295 String reply = JOptionPane.showInternalInputDialog(this,
3298 JOptionPane.QUESTION_MESSAGE);
3302 viewport.viewName = reply;
3303 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3309 public AlignViewport getCurrentView()