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 final AlignFrame af = this;
163 addKeyListener(new KeyAdapter()
165 public void keyPressed(KeyEvent evt)
167 if (viewport.cursorMode
168 && evt.getKeyCode() >= KeyEvent.VK_0
169 && evt.getKeyCode() <= KeyEvent.VK_9)
171 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
174 switch (evt.getKeyCode())
177 Desktop.instance.gatherViews(af);
181 if (!evt.isControlDown())
183 Desktop.instance.explodeViews(af);
188 case 27: // escape key
189 deselectAllSequenceMenuItem_actionPerformed(null);
193 case KeyEvent.VK_DOWN:
194 if (viewport.cursorMode)
196 alignPanel.seqPanel.moveCursor(0, 1);
199 moveSelectedSequences(false);
203 if (viewport.cursorMode)
205 alignPanel.seqPanel.moveCursor(0, -1);
208 moveSelectedSequences(true);
211 case KeyEvent.VK_LEFT:
212 if (viewport.cursorMode)
214 alignPanel.seqPanel.moveCursor( -1, 0);
218 case KeyEvent.VK_RIGHT:
219 if (viewport.cursorMode)
221 alignPanel.seqPanel.moveCursor(1, 0);
225 case KeyEvent.VK_SPACE:
226 if (viewport.cursorMode)
228 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
234 case KeyEvent.VK_DELETE:
235 case KeyEvent.VK_BACK_SPACE:
236 if (!viewport.cursorMode)
238 cut_actionPerformed(null);
241 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
248 if (viewport.cursorMode)
250 alignPanel.seqPanel.setCursorRow();
254 if (viewport.cursorMode && !evt.isControlDown())
256 alignPanel.seqPanel.setCursorColumn();
260 if (viewport.cursorMode)
262 alignPanel.seqPanel.setCursorPosition();
266 case KeyEvent.VK_ENTER:
267 case KeyEvent.VK_COMMA:
268 if (viewport.cursorMode)
270 alignPanel.seqPanel.setCursorRowAndColumn();
275 if (viewport.cursorMode)
277 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
281 if (viewport.cursorMode)
283 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
288 viewport.cursorMode = !viewport.cursorMode;
289 statusBar.setText("Keyboard editing mode is " +
290 (viewport.cursorMode ? "on" : "off"));
291 if (viewport.cursorMode)
293 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
294 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
296 alignPanel.seqPanel.seqCanvas.repaint();
302 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
303 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
304 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
306 javax.help.HelpBroker hb = hs.createHelpBroker();
307 hb.setCurrentID("home");
308 hb.setDisplayed(true);
312 ex.printStackTrace();
318 boolean toggleSeqs = !evt.isControlDown();
319 boolean toggleCols = !evt.isShiftDown();
321 boolean hide = false;
323 SequenceGroup sg = viewport.getSelectionGroup();
326 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
328 hideSelSequences_actionPerformed(null);
331 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
332 showAllSeqs_actionPerformed(null);
337 if (viewport.colSel.getSelected().size() > 0)
339 hideSelColumns_actionPerformed(null);
341 viewport.selectionGroup = sg;
344 showAllColumns_actionPerformed(null);
348 case KeyEvent.VK_PAGE_UP:
349 if (viewport.wrapAlignment)
350 alignPanel.scrollUp(true);
352 alignPanel.setScrollValues(viewport.startRes,
354 - viewport.endSeq + viewport.startSeq);
356 case KeyEvent.VK_PAGE_DOWN:
357 if (viewport.wrapAlignment)
358 alignPanel.scrollUp(false);
360 alignPanel.setScrollValues(viewport.startRes,
362 + viewport.endSeq - viewport.startSeq);
370 public void addAlignmentPanel(final AlignmentPanel ap,
373 ap.alignFrame = this;
375 alignPanels.addElement(ap);
377 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
379 int aSize = alignPanels.size();
381 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
383 if (aSize == 1 && ap.av.viewName==null)
385 this.getContentPane().add(ap, BorderLayout.CENTER);
391 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
392 tabbedPane.addTab(first.av.viewName==null?"Original":first.av.viewName,first);
394 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
397 tabbedPane.addTab(ap.av.viewName==null?"Original":ap.av.viewName, ap);
399 ap.setVisible(false);
405 ap.av.alignment.padGaps();
406 ap.av.updateConservation(ap);
407 ap.av.updateConsensus(ap);
412 public AlignViewport getViewport()
417 /* Set up intrinsic listeners for dynamically generated GUI bits. */
418 private void addServiceListeners()
420 final java.beans.PropertyChangeListener thisListener;
421 // Do this once to get current state
422 BuildWebServiceMenu();
423 Desktop.discoverer.addPropertyChangeListener(
424 thisListener = new java.beans.PropertyChangeListener()
426 public void propertyChange(PropertyChangeEvent evt)
428 // System.out.println("Discoverer property change.");
429 if (evt.getPropertyName().equals("services"))
431 // System.out.println("Rebuilding web service menu");
432 BuildWebServiceMenu();
437 addInternalFrameListener(new javax.swing.event.
438 InternalFrameAdapter()
440 public void internalFrameClosed(
441 javax.swing.event.InternalFrameEvent evt)
443 // System.out.println("deregistering discoverer listener");
444 Desktop.discoverer.removePropertyChangeListener(thisListener);
445 closeMenuItem_actionPerformed(true);
451 public void setGUINucleotide(boolean nucleotide)
453 showTranslation.setVisible( nucleotide );
454 conservationMenuItem.setEnabled( !nucleotide );
455 modifyConservation.setEnabled( !nucleotide );
457 //Remember AlignFrame always starts as protein
460 calculateMenu.remove(calculateMenu.getItemCount()-2);
465 * Need to call this method when tabs are selected for multiple views,
466 * or when loading from Jalview2XML.java
467 * @param av AlignViewport
469 void setMenusFromViewport(AlignViewport av)
471 padGapsMenuitem.setSelected(av.padGaps);
472 colourTextMenuItem.setSelected(av.showColourText);
473 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
474 conservationMenuItem.setSelected(av.getConservationSelected());
475 seqLimits.setSelected(av.getShowJVSuffix());
476 idRightAlign.setSelected(av.idsAlignRight);
477 renderGapsMenuItem.setSelected(av.renderGaps);
478 wrapMenuItem.setSelected(av.wrapAlignment);
479 annotationPanelMenuItem.setState(av.showAnnotation);
480 viewBoxesMenuItem.setSelected(av.showBoxes);
481 viewTextMenuItem.setSelected(av.showText);
483 setColourSelected(ColourSchemeProperty.
484 getColourName(av.getGlobalColourScheme()));
486 showSeqFeatures.setSelected(av.showSequenceFeatures);
487 hiddenMarkers.setState(av.showHiddenMarkers);
488 applyToAllGroups.setState(av.colourAppliesToAllGroups);
494 Hashtable progressBars;
495 public void setProgressBar(String message, long id)
497 if(progressBars == null)
498 progressBars = new Hashtable();
500 JPanel progressPanel;
501 GridLayout layout = (GridLayout) statusPanel.getLayout();
502 if(progressBars.get( new Long(id) )!=null)
504 progressPanel = (JPanel)progressBars.get( new Long(id) );
505 statusPanel.remove(progressPanel);
506 progressBars.remove( progressPanel );
507 progressPanel = null;
509 statusBar.setText(message);
511 layout.setRows(layout.getRows() - 1);
515 progressPanel = new JPanel(new BorderLayout(10, 5));
517 JProgressBar progressBar = new JProgressBar();
518 progressBar.setIndeterminate(true);
520 progressPanel.add(new JLabel(message), BorderLayout.WEST);
521 progressPanel.add(progressBar, BorderLayout.CENTER);
523 layout.setRows(layout.getRows() + 1);
524 statusPanel.add(progressPanel);
526 progressBars.put(new Long(id), progressPanel);
536 Added so Castor Mapping file can obtain Jalview Version
538 public String getVersion()
540 return jalview.bin.Cache.getProperty("VERSION");
543 public FeatureRenderer getFeatureRenderer()
545 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
549 public void fetchSequence_actionPerformed(ActionEvent e)
551 new SequenceFetcher(this);
554 public void addFromFile_actionPerformed(ActionEvent e)
556 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
559 public void reload_actionPerformed(ActionEvent e)
563 if(currentFileFormat.equals("Jalview"))
565 this.closeMenuItem_actionPerformed(true);
569 viewport.alignment.deleteAllGroups();
570 viewport.sequenceColours=null;
571 while (viewport.alignment.getHeight() > 0)
573 viewport.alignment.deleteSequence(0);
576 viewport.historyList.clear();
577 viewport.redoList.clear();
578 Alignment dset = viewport.alignment.getDataset();
579 while (dset.getHeight() > 0)
581 dset.deleteSequence(0);
584 firePropertyChange("Alignment", null, null);
589 FileLoader loader = new FileLoader();
590 String protocol = fileName.startsWith("http:")? "URL":"File";
591 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
597 public void addFromText_actionPerformed(ActionEvent e)
599 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
602 public void addFromURL_actionPerformed(ActionEvent e)
604 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
608 public void save_actionPerformed(ActionEvent e)
610 if(fileName==null || currentFileFormat==null)
611 saveAs_actionPerformed(null);
613 saveAlignment(fileName, currentFileFormat);
619 * @param e DOCUMENT ME!
621 public void saveAs_actionPerformed(ActionEvent e)
623 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
624 getProperty( "LAST_DIRECTORY"),
626 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
628 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
633 chooser.setFileView(new JalviewFileView());
634 chooser.setDialogTitle("Save Alignment to file");
635 chooser.setToolTipText("Save");
637 int value = chooser.showSaveDialog(this);
639 if (value == JalviewFileChooser.APPROVE_OPTION)
641 currentFileFormat = chooser.getSelectedFormat();
642 if (currentFileFormat == null)
644 JOptionPane.showInternalMessageDialog(Desktop.desktop,
645 "You must select a file format before saving!",
646 "File format not specified",
647 JOptionPane.WARNING_MESSAGE);
648 value = chooser.showSaveDialog(this);
652 fileName = chooser.getSelectedFile().getPath();
654 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
657 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
659 saveAlignment(fileName, currentFileFormat);
663 public boolean saveAlignment(String file, String format)
665 if (format.equalsIgnoreCase("Jalview"))
667 String shortName = title;
669 if (shortName.indexOf(java.io.File.separatorChar) > -1)
671 shortName = shortName.substring(shortName.lastIndexOf(
672 java.io.File.separatorChar) + 1);
675 new Jalview2XML().SaveAlignment(this, file, shortName);
677 statusBar.setText("Successfully saved to file: "
679 +format +" format.");
682 // USE Jalview2XML to save this file
688 String[] omitHidden = null;
690 if (viewport.hasHiddenColumns)
692 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
693 "The Alignment contains hidden columns."
694 + "\nDo you want to save only the visible alignment?",
695 "Save / Omit Hidden Columns",
696 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
698 if (reply == JOptionPane.YES_OPTION)
699 omitHidden = viewport.getViewAsString(false);
702 String output = new FormatAdapter().formatSequences(
704 viewport.alignment.getSequencesArray(),
714 java.io.PrintWriter out = new java.io.PrintWriter(
715 new java.io.FileWriter(file));
720 statusBar.setText("Successfully saved to file: "
722 +format +" format.");
727 ex.printStackTrace();
736 * @param e DOCUMENT ME!
738 protected void outputText_actionPerformed(ActionEvent e)
740 String [] omitHidden = null;
742 if(viewport.hasHiddenColumns)
744 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
745 "The Alignment contains hidden columns."
746 +"\nDo you want to output only the visible alignment?",
747 "Save / Omit Hidden Columns",
748 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
750 if(reply==JOptionPane.YES_OPTION)
752 omitHidden = viewport.getViewAsString(false);
756 CutAndPasteTransfer cap = new CutAndPasteTransfer();
757 cap.setForInput(null);
758 Desktop.addInternalFrame(cap,
759 "Alignment output - " + e.getActionCommand(), 600,
763 cap.setText(new FormatAdapter().formatSequences(
764 e.getActionCommand(),
765 viewport.alignment.getSequencesArray(),
772 * @param e DOCUMENT ME!
774 protected void htmlMenuItem_actionPerformed(ActionEvent e)
776 new HTMLOutput(viewport,
777 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
778 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
781 public void createImageMap(File file, String image)
783 alignPanel.makePNGImageMap(file, image);
789 * @param e DOCUMENT ME!
791 public void createPNG(File f)
793 alignPanel.makePNG(f);
799 * @param e DOCUMENT ME!
801 public void createEPS(File f)
803 alignPanel.makeEPS(f);
809 * @param e DOCUMENT ME!
811 public void printMenuItem_actionPerformed(ActionEvent e)
813 //Putting in a thread avoids Swing painting problems
814 PrintThread thread = new PrintThread();
818 public void exportFeatures_actionPerformed(ActionEvent e)
820 new AnnotationExporter().exportFeatures(alignPanel);
824 public void exportAnnotations_actionPerformed(ActionEvent e)
826 new AnnotationExporter().exportAnnotations(
828 viewport.alignment.getAlignmentAnnotation()
833 public void associatedData_actionPerformed(ActionEvent e)
835 // Pick the tree file
836 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
839 chooser.setFileView(new JalviewFileView());
840 chooser.setDialogTitle("Load Jalview Annotations or Features File");
841 chooser.setToolTipText("Load Jalview Annotations / Features file");
843 int value = chooser.showOpenDialog(null);
845 if (value == JalviewFileChooser.APPROVE_OPTION)
847 String choice = chooser.getSelectedFile().getPath();
848 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
849 loadJalviewDataFile(choice);
858 * @param e DOCUMENT ME!
860 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
862 if(alignPanels!=null && alignPanels.size()<2)
867 if(alignPanels!=null)
870 for (int i = 0; i < alignPanels.size(); i++)
872 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
873 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
874 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
875 PaintRefresher.RemoveComponent(ap);
879 int index = tabbedPane.getSelectedIndex();
881 tabbedPane.removeTabAt(index);
882 alignPanels.removeElement(alignPanel);
883 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
884 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
885 PaintRefresher.RemoveComponent(alignPanel);
888 tabbedPane.validate();
890 if(index==tabbedPane.getTabCount())
893 this.tabSelectionChanged(index);
898 this.setClosed(true);
902 ex.printStackTrace();
910 void updateEditMenuBar()
913 if (viewport.historyList.size() > 0)
915 undoMenuItem.setEnabled(true);
916 CommandI command = (CommandI) viewport.historyList.peek();
917 undoMenuItem.setText("Undo " + command.getDescription());
921 undoMenuItem.setEnabled(false);
922 undoMenuItem.setText("Undo");
925 if (viewport.redoList.size() > 0)
927 redoMenuItem.setEnabled(true);
929 CommandI command = (CommandI) viewport.redoList.peek();
930 redoMenuItem.setText("Redo " + command.getDescription());
934 redoMenuItem.setEnabled(false);
935 redoMenuItem.setText("Redo");
940 public void addHistoryItem(CommandI command)
942 if(command.getSize()>0)
944 viewport.historyList.push(command);
945 viewport.redoList.clear();
947 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
956 * @param e DOCUMENT ME!
958 protected void undoMenuItem_actionPerformed(ActionEvent e)
960 CommandI command = (CommandI)viewport.historyList.pop();
961 viewport.redoList.push(command);
962 command.undoCommand();
964 AlignViewport originalSource = getOriginatingSource(command);
966 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
968 originalSource.firePropertyChange("alignment", null,null);
974 * @param e DOCUMENT ME!
976 protected void redoMenuItem_actionPerformed(ActionEvent e)
978 CommandI command = (CommandI) viewport.redoList.pop();
979 viewport.historyList.push(command);
982 AlignViewport originalSource = getOriginatingSource(command);
983 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null;
986 originalSource.firePropertyChange("alignment", null, null);
989 AlignViewport getOriginatingSource(CommandI command)
991 AlignViewport originalSource = viewport;
992 //For sequence removal and addition, we need to fire
993 //the property change event FROM the viewport where the
994 //original alignment was altered
995 if (command instanceof EditCommand)
997 EditCommand editCommand = (EditCommand) command;
998 AlignmentI al = editCommand.getAlignment();
999 Vector comps = (Vector) PaintRefresher.components
1000 .get(viewport.getSequenceSetId());
1001 for (int i = 0; i < comps.size(); i++)
1003 if (comps.elementAt(i) instanceof AlignmentPanel)
1005 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1007 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1013 return originalSource;
1019 * @param up DOCUMENT ME!
1021 public void moveSelectedSequences(boolean up)
1023 SequenceGroup sg = viewport.getSelectionGroup();
1032 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1034 SequenceI seq = viewport.alignment.getSequenceAt(i);
1036 if (!sg.getSequences(false).contains(seq))
1041 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1043 if (sg.getSequences(false).contains(temp))
1048 viewport.alignment.getSequences().setElementAt(temp, i);
1049 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1054 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1056 SequenceI seq = viewport.alignment.getSequenceAt(i);
1058 if (!sg.getSequences(false).contains(seq))
1063 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1065 if (sg.getSequences(false).contains(temp))
1070 viewport.alignment.getSequences().setElementAt(temp, i);
1071 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1075 alignPanel.repaint();
1083 * @param e DOCUMENT ME!
1085 protected void copy_actionPerformed(ActionEvent e)
1088 if (viewport.getSelectionGroup() == null)
1093 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1094 String[] omitHidden = null;
1096 if (viewport.hasHiddenColumns)
1098 omitHidden = viewport.getViewAsString(true);
1101 String output = new FormatAdapter().formatSequences(
1106 StringSelection ss = new StringSelection(output);
1110 //Its really worth setting the clipboard contents
1111 //to empty before setting the large StringSelection!!
1112 Toolkit.getDefaultToolkit().getSystemClipboard()
1113 .setContents(new StringSelection(""), null);
1115 Toolkit.getDefaultToolkit().getSystemClipboard()
1116 .setContents(ss, Desktop.instance);
1118 catch (OutOfMemoryError er)
1120 er.printStackTrace();
1121 javax.swing.SwingUtilities.invokeLater(new Runnable()
1125 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1126 "Out of memory copying region!!"
1128 "\nSee help files for increasing Java Virtual Machine memory."
1130 javax.swing.JOptionPane.WARNING_MESSAGE);
1137 Vector hiddenColumns = null;
1138 if(viewport.hasHiddenColumns)
1140 hiddenColumns =new Vector();
1141 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1142 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1144 int[] region = (int[])
1145 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1147 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1148 region[1]-hiddenOffset});
1154 Desktop.jalviewClipboard = new Object[]{ seqs,
1155 viewport.alignment.getDataset(),
1157 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1163 * @param e DOCUMENT ME!
1165 protected void pasteNew_actionPerformed(ActionEvent e)
1173 * @param e DOCUMENT ME!
1175 protected void pasteThis_actionPerformed(ActionEvent e)
1183 * @param newAlignment DOCUMENT ME!
1185 void paste(boolean newAlignment)
1189 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1190 Transferable contents = c.getContents(this);
1192 if (contents == null)
1200 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1201 if (str.length() < 1)
1204 format = new IdentifyFile().Identify(str, "Paste");
1207 catch (OutOfMemoryError er)
1209 er.printStackTrace();
1210 javax.swing.SwingUtilities.invokeLater(new Runnable()
1214 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1215 "Out of memory pasting sequences!!"
1217 "\nSee help files for increasing Java Virtual Machine memory."
1219 javax.swing.JOptionPane.WARNING_MESSAGE);
1226 SequenceI[] sequences;
1229 if(Desktop.jalviewClipboard!=null)
1231 // The clipboard was filled from within Jalview, we must use the sequences
1232 // And dataset from the copied alignment
1233 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1237 sequences = new FormatAdapter().readFile(str, "Paste", format);
1240 AlignmentI alignment = null;
1244 alignment = new Alignment(sequences);
1246 if (Desktop.jalviewClipboard != null)
1247 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1249 alignment.setDataset(null);
1253 alignment = viewport.getAlignment();
1256 SequenceI [] newseqs = new SequenceI[sequences.length];
1257 for (int i = 0; i < sequences.length; i++)
1259 newseqs[i] = new Sequence(sequences[i].getName(),
1260 sequences[i].getSequence(), sequences[i].getStart(),
1261 sequences[i].getEnd());
1263 alignment.addSequence(newseqs[i]);
1269 addHistoryItem(new EditCommand(
1274 alignment.getWidth(),
1279 viewport.setEndSeq(alignment.getHeight());
1280 alignment.getWidth();
1281 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1286 // Add any annotations attached to sequences
1287 for (int i = 0; i < sequences.length; i++)
1289 if (sequences[i].getAnnotation() != null)
1291 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1293 AlignmentAnnotation newAnnot =
1294 new AlignmentAnnotation(
1295 sequences[i].getAnnotation()[a].label,
1296 sequences[i].getAnnotation()[a].description,
1297 sequences[i].getAnnotation()[a].annotations,
1298 sequences[i].getAnnotation()[a].graphMin,
1299 sequences[i].getAnnotation()[a].graphMax,
1300 sequences[i].getAnnotation()[a].graph);
1302 sequences[i].getAnnotation()[a] = newAnnot;
1303 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1305 newAnnot.sequenceRef = sequences[i];
1306 newAnnot.adjustForAlignment();
1307 alignment.addAnnotation(newAnnot);
1308 alignment.setAnnotationIndex(newAnnot, a);
1311 alignPanel.annotationPanel.adjustPanelHeight();
1317 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1318 String newtitle = new String("Copied sequences");
1320 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1322 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1323 for(int i=0; i<hc.size(); i++)
1325 int [] region = (int[]) hc.elementAt(i);
1326 af.viewport.hideColumns(region[0], region[1]);
1331 //>>>This is a fix for the moment, until a better solution is found!!<<<
1332 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1333 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1336 if (title.startsWith("Copied sequences"))
1342 newtitle = newtitle.concat("- from " + title);
1345 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1352 catch (Exception ex)
1354 ex.printStackTrace();
1355 System.out.println("Exception whilst pasting: "+ex);
1356 // could be anything being pasted in here
1365 * @param e DOCUMENT ME!
1367 protected void cut_actionPerformed(ActionEvent e)
1369 copy_actionPerformed(null);
1370 delete_actionPerformed(null);
1376 * @param e DOCUMENT ME!
1378 protected void delete_actionPerformed(ActionEvent evt)
1381 SequenceGroup sg = viewport.getSelectionGroup();
1387 Vector seqs = new Vector();
1389 for (int i = 0; i < sg.getSize(false); i++)
1391 seq = sg.getSequenceAt(i);
1392 seqs.addElement(seq);
1396 // If the cut affects all sequences, remove highlighted columns
1397 if (sg.getSize(false) == viewport.alignment.getHeight())
1399 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1400 sg.getEndRes() + 1);
1404 SequenceI [] cut = new SequenceI[seqs.size()];
1405 for(int i=0; i<seqs.size(); i++)
1406 cut[i] = (SequenceI)seqs.elementAt(i);
1412 addHistoryItem(new EditCommand("Cut Sequences",
1416 sg.getEndRes()-sg.getStartRes()+1,
1417 viewport.alignment));
1420 viewport.setSelectionGroup(null);
1421 viewport.alignment.deleteGroup(sg);
1423 viewport.firePropertyChange("alignment", null,
1424 viewport.getAlignment().getSequences());
1426 if (viewport.getAlignment().getHeight() < 1)
1430 this.setClosed(true);
1432 catch (Exception ex)
1441 * @param e DOCUMENT ME!
1443 protected void deleteGroups_actionPerformed(ActionEvent e)
1445 viewport.alignment.deleteAllGroups();
1446 viewport.sequenceColours.clear();
1447 viewport.setSelectionGroup(null);
1448 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1449 alignPanel.repaint();
1455 * @param e DOCUMENT ME!
1457 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1459 SequenceGroup sg = new SequenceGroup();
1461 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1464 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1467 sg.setEndRes(viewport.alignment.getWidth() - 1);
1468 viewport.setSelectionGroup(sg);
1469 alignPanel.repaint();
1470 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1476 * @param e DOCUMENT ME!
1478 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1480 if(viewport.cursorMode)
1482 alignPanel.seqPanel.keyboardNo1 = null;
1483 alignPanel.seqPanel.keyboardNo2 = null;
1485 viewport.setSelectionGroup(null);
1486 viewport.getColumnSelection().clear();
1487 viewport.setSelectionGroup(null);
1488 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1489 alignPanel.idPanel.idCanvas.searchResults = null;
1490 alignPanel.repaint();
1491 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1497 * @param e DOCUMENT ME!
1499 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1501 SequenceGroup sg = viewport.getSelectionGroup();
1505 selectAllSequenceMenuItem_actionPerformed(null);
1510 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1513 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1516 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1519 public void invertColSel_actionPerformed(ActionEvent e)
1521 viewport.invertColumnSelection();
1522 alignPanel.repaint();
1529 * @param e DOCUMENT ME!
1531 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1533 trimAlignment(true);
1539 * @param e DOCUMENT ME!
1541 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1543 trimAlignment(false);
1546 void trimAlignment(boolean trimLeft)
1548 ColumnSelection colSel = viewport.getColumnSelection();
1551 if (colSel.size() > 0)
1554 column = colSel.getMin();
1556 column = colSel.getMax();
1559 if(viewport.getSelectionGroup()!=null)
1560 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1562 seqs = viewport.alignment.getSequencesArray();
1565 TrimRegionCommand trimRegion;
1568 trimRegion = new TrimRegionCommand("Remove Left",
1569 TrimRegionCommand.TRIM_LEFT,
1574 viewport.selectionGroup);
1575 viewport.setStartRes(0);
1579 trimRegion = new TrimRegionCommand("Remove Right",
1580 TrimRegionCommand.TRIM_RIGHT,
1585 viewport.selectionGroup);
1588 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1591 addHistoryItem(trimRegion);
1593 Vector groups = viewport.alignment.getGroups();
1595 for (int i = 0; i < groups.size(); i++)
1597 SequenceGroup sg = (SequenceGroup) groups.get(i);
1599 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1600 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1602 viewport.alignment.deleteGroup(sg);
1606 viewport.firePropertyChange("alignment", null,
1607 viewport.getAlignment().getSequences());
1614 * @param e DOCUMENT ME!
1616 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1618 int start = 0, end = viewport.alignment.getWidth()-1;
1621 if (viewport.getSelectionGroup() != null)
1623 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1624 start = viewport.getSelectionGroup().getStartRes();
1625 end = viewport.getSelectionGroup().getEndRes();
1628 seqs = viewport.alignment.getSequencesArray();
1631 RemoveGapColCommand removeGapCols =
1632 new RemoveGapColCommand("Remove Gapped Columns",
1635 viewport.getGapCharacter());
1637 addHistoryItem(removeGapCols);
1639 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1641 //This is to maintain viewport position on first residue
1643 SequenceI seq = viewport.alignment.getSequenceAt(0);
1644 int startRes = seq.findPosition(viewport.startRes);
1645 // ShiftList shifts;
1646 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1647 // edit.alColumnChanges=shifts.getInverse();
1648 // if (viewport.hasHiddenColumns)
1649 // viewport.getColumnSelection().compensateForEdits(shifts);
1650 viewport.setStartRes(seq.findIndex(startRes)-1);
1651 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1658 * @param e DOCUMENT ME!
1660 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1662 int start = 0, end = viewport.alignment.getWidth()-1;
1665 if (viewport.getSelectionGroup() != null)
1667 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1668 start = viewport.getSelectionGroup().getStartRes();
1669 end = viewport.getSelectionGroup().getEndRes();
1672 seqs = viewport.alignment.getSequencesArray();
1674 //This is to maintain viewport position on first residue
1676 SequenceI seq = viewport.alignment.getSequenceAt(0);
1677 int startRes = seq.findPosition(viewport.startRes);
1679 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1682 viewport.getGapCharacter()));
1684 viewport.setStartRes(seq.findIndex(startRes)-1);
1686 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1693 * @param e DOCUMENT ME!
1695 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1697 viewport.padGaps = padGapsMenuitem.isSelected();
1699 viewport.firePropertyChange("alignment",
1701 viewport.getAlignment().getSequences());
1707 * @param e DOCUMENT ME!
1709 public void findMenuItem_actionPerformed(ActionEvent e)
1711 JInternalFrame frame = new JInternalFrame();
1712 Finder finder = new Finder(viewport, alignPanel, frame);
1713 frame.setContentPane(finder);
1714 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1715 Desktop.addInternalFrame(frame, "Find", 340, 110);
1718 public void newView_actionPerformed(ActionEvent e)
1720 AlignmentPanel newap =
1721 new Jalview2XML().copyAlignPanel(alignPanel, true);
1723 if (viewport.viewName == null)
1724 viewport.viewName = "View 1";
1726 newap.av.historyList = viewport.historyList;
1727 newap.av.redoList = viewport.redoList;
1728 newap.av.viewName = "View " +
1729 (Desktop.getViewCount(viewport.getSequenceSetId()) + 1);
1731 addAlignmentPanel(newap, false);
1733 if(alignPanels.size()==2)
1735 viewport.gatherViewsHere = true;
1737 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1744 * @param e DOCUMENT ME!
1746 public void font_actionPerformed(ActionEvent e)
1748 new FontChooser(alignPanel);
1755 * @param e DOCUMENT ME!
1757 protected void seqLimit_actionPerformed(ActionEvent e)
1759 viewport.setShowJVSuffix(seqLimits.isSelected());
1761 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1762 alignPanel.repaint();
1765 public void idRightAlign_actionPerformed(ActionEvent e)
1767 viewport.idsAlignRight = idRightAlign.isSelected();
1768 alignPanel.repaint();
1776 * @param e DOCUMENT ME!
1778 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1780 viewport.setColourText(colourTextMenuItem.isSelected());
1781 alignPanel.repaint();
1787 * @param e DOCUMENT ME!
1789 public void wrapMenuItem_actionPerformed(ActionEvent e)
1791 scaleAbove.setVisible(wrapMenuItem.isSelected());
1792 scaleLeft.setVisible(wrapMenuItem.isSelected());
1793 scaleRight.setVisible(wrapMenuItem.isSelected());
1794 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1795 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1798 public void showAllSeqs_actionPerformed(ActionEvent e)
1800 viewport.showAllHiddenSeqs();
1803 public void showAllColumns_actionPerformed(ActionEvent e)
1805 viewport.showAllHiddenColumns();
1809 public void hideSelSequences_actionPerformed(ActionEvent e)
1811 viewport.hideAllSelectedSeqs();
1812 alignPanel.repaint();
1815 public void hideSelColumns_actionPerformed(ActionEvent e)
1817 viewport.hideSelectedColumns();
1818 alignPanel.repaint();
1821 public void hiddenMarkers_actionPerformed(ActionEvent e)
1823 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1830 * @param e DOCUMENT ME!
1832 protected void scaleAbove_actionPerformed(ActionEvent e)
1834 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1835 alignPanel.repaint();
1841 * @param e DOCUMENT ME!
1843 protected void scaleLeft_actionPerformed(ActionEvent e)
1845 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1846 alignPanel.repaint();
1852 * @param e DOCUMENT ME!
1854 protected void scaleRight_actionPerformed(ActionEvent e)
1856 viewport.setScaleRightWrapped(scaleRight.isSelected());
1857 alignPanel.repaint();
1863 * @param e DOCUMENT ME!
1865 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1867 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1868 alignPanel.repaint();
1874 * @param e DOCUMENT ME!
1876 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1878 viewport.setShowText(viewTextMenuItem.isSelected());
1879 alignPanel.repaint();
1885 * @param e DOCUMENT ME!
1887 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1889 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1890 alignPanel.repaint();
1894 public FeatureSettings featureSettings;
1895 public void featureSettings_actionPerformed(ActionEvent e)
1897 if(featureSettings !=null )
1899 featureSettings.close();
1900 featureSettings = null;
1902 featureSettings = new FeatureSettings(this);
1908 * @param evt DOCUMENT ME!
1910 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1912 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1913 alignPanel.repaint();
1914 if (alignPanel.getOverviewPanel() != null)
1916 alignPanel.getOverviewPanel().updateOverviewImage();
1923 * @param e DOCUMENT ME!
1925 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1927 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1928 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1934 * @param e DOCUMENT ME!
1936 public void overviewMenuItem_actionPerformed(ActionEvent e)
1938 if (alignPanel.overviewPanel != null)
1943 JInternalFrame frame = new JInternalFrame();
1944 OverviewPanel overview = new OverviewPanel(alignPanel);
1945 frame.setContentPane(overview);
1946 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1947 frame.getWidth(), frame.getHeight());
1949 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1950 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1952 public void internalFrameClosed(
1953 javax.swing.event.InternalFrameEvent evt)
1955 alignPanel.setOverviewPanel(null);
1960 alignPanel.setOverviewPanel(overview);
1963 public void textColour_actionPerformed(ActionEvent e)
1965 int original1 = viewport.textColour.getRGB();
1966 int original2 = viewport.textColour2.getRGB();
1967 int thresh = viewport.thresholdTextColour;
1968 final JSlider slider = new JSlider(0, 750, viewport.thresholdTextColour);
1969 final JButton col1 = new JButton("DARK");
1970 col1.setBackground(viewport.textColour);
1971 col1.setForeground(viewport.textColour);
1972 final JButton col2 = new JButton("LIGHT");
1973 col2.setBackground(viewport.textColour2);
1974 col2.setForeground(viewport.textColour2);
1975 final JPanel bigpanel = new JPanel(new BorderLayout());
1976 JPanel panel = new JPanel();
1977 bigpanel.add(panel, BorderLayout.CENTER);
1978 bigpanel.add(new JLabel(
1979 "<html><i>Select a dark and light text colour, then set the threshold to"
1980 +"<br>switch between colours, based on background colour</i></html>"),
1981 BorderLayout.NORTH);
1986 col1.addActionListener(new ActionListener()
1988 public void actionPerformed(ActionEvent e)
1990 Color col = JColorChooser.showDialog(bigpanel,
1991 "Select Colour for Text",
1992 viewport.textColour);
1995 viewport.textColour = col;
1996 col1.setBackground(col);
1997 col1.setForeground(col);
1998 if(viewport.colourAppliesToAllGroups)
1999 setGroupTextColour();
2001 alignPanel.repaint();
2005 col2.addActionListener(new ActionListener()
2007 public void actionPerformed(ActionEvent e)
2009 Color col = JColorChooser.showDialog(bigpanel,
2010 "Select Colour for Text",
2011 viewport.textColour);
2014 viewport.textColour2 = col;
2015 col2.setBackground(col);
2016 col2.setForeground(col);
2017 if(viewport.colourAppliesToAllGroups)
2018 setGroupTextColour();
2020 alignPanel.repaint();
2025 slider.addChangeListener(new ChangeListener()
2027 public void stateChanged(ChangeEvent evt)
2029 viewport.thresholdTextColour = slider.getValue();
2030 if(viewport.colourAppliesToAllGroups)
2031 setGroupTextColour();
2032 alignPanel.repaint();
2036 int reply = JOptionPane.showInternalOptionDialog(this,
2038 "Adjust Foreground Text Colour Threshold",
2039 JOptionPane.OK_CANCEL_OPTION,
2040 JOptionPane.QUESTION_MESSAGE,
2044 if(reply==JOptionPane.CANCEL_OPTION)
2046 viewport.textColour = new Color(original1);
2047 viewport.textColour2 = new Color(original2);
2048 viewport.thresholdTextColour = thresh;
2052 void setGroupTextColour()
2054 if(viewport.alignment.getGroups()==null)
2057 Vector groups = viewport.alignment.getGroups();
2059 for(int i=0; i<groups.size(); i++)
2061 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
2062 sg.textColour = viewport.textColour;
2063 sg.textColour2 = viewport.textColour2;
2064 sg.thresholdTextColour = viewport.thresholdTextColour;
2074 * @param e DOCUMENT ME!
2076 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2084 * @param e DOCUMENT ME!
2086 public void clustalColour_actionPerformed(ActionEvent e)
2088 changeColour(new ClustalxColourScheme(
2089 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2095 * @param e DOCUMENT ME!
2097 public void zappoColour_actionPerformed(ActionEvent e)
2099 changeColour(new ZappoColourScheme());
2105 * @param e DOCUMENT ME!
2107 public void taylorColour_actionPerformed(ActionEvent e)
2109 changeColour(new TaylorColourScheme());
2115 * @param e DOCUMENT ME!
2117 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2119 changeColour(new HydrophobicColourScheme());
2125 * @param e DOCUMENT ME!
2127 public void helixColour_actionPerformed(ActionEvent e)
2129 changeColour(new HelixColourScheme());
2135 * @param e DOCUMENT ME!
2137 public void strandColour_actionPerformed(ActionEvent e)
2139 changeColour(new StrandColourScheme());
2145 * @param e DOCUMENT ME!
2147 public void turnColour_actionPerformed(ActionEvent e)
2149 changeColour(new TurnColourScheme());
2155 * @param e DOCUMENT ME!
2157 public void buriedColour_actionPerformed(ActionEvent e)
2159 changeColour(new BuriedColourScheme());
2165 * @param e DOCUMENT ME!
2167 public void nucleotideColour_actionPerformed(ActionEvent e)
2169 changeColour(new NucleotideColourScheme());
2172 public void annotationColour_actionPerformed(ActionEvent e)
2174 new AnnotationColourChooser(viewport, alignPanel);
2181 * @param e DOCUMENT ME!
2183 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2185 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2191 * @param cs DOCUMENT ME!
2193 public void changeColour(ColourSchemeI cs)
2199 if (viewport.getAbovePIDThreshold())
2201 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2204 cs.setThreshold(threshold,
2205 viewport.getIgnoreGapsConsensus());
2207 viewport.setGlobalColourScheme(cs);
2211 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2214 if (viewport.getConservationSelected())
2217 Alignment al = (Alignment) viewport.alignment;
2218 Conservation c = new Conservation("All",
2219 ResidueProperties.propHash, 3,
2220 al.getSequences(), 0,
2224 c.verdict(false, viewport.ConsPercGaps);
2226 cs.setConservation(c);
2228 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2233 cs.setConservation(null);
2236 cs.setConsensus(viewport.hconsensus);
2239 viewport.setGlobalColourScheme(cs);
2241 if (viewport.getColourAppliesToAllGroups())
2243 Vector groups = viewport.alignment.getGroups();
2245 for (int i = 0; i < groups.size(); i++)
2247 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2255 if (cs instanceof ClustalxColourScheme)
2257 sg.cs = new ClustalxColourScheme(
2258 sg.getSequences(true), sg.getWidth());
2260 else if (cs instanceof UserColourScheme)
2262 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2268 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2270 catch (Exception ex)
2275 if (viewport.getAbovePIDThreshold()
2276 || cs instanceof PIDColourScheme
2277 || cs instanceof Blosum62ColourScheme)
2279 sg.cs.setThreshold(threshold,
2280 viewport.getIgnoreGapsConsensus());
2282 sg.cs.setConsensus(AAFrequency.calculate(
2283 sg.getSequences(true), sg.getStartRes(),
2287 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2290 if (viewport.getConservationSelected())
2292 Conservation c = new Conservation("Group",
2293 ResidueProperties.propHash, 3,
2294 sg.getSequences(true),
2298 c.verdict(false, viewport.ConsPercGaps);
2299 sg.cs.setConservation(c);
2302 sg.cs.setConservation(null);
2306 if (alignPanel.getOverviewPanel() != null)
2308 alignPanel.getOverviewPanel().updateOverviewImage();
2311 alignPanel.repaint();
2317 * @param e DOCUMENT ME!
2319 protected void modifyPID_actionPerformed(ActionEvent e)
2321 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2323 SliderPanel.setPIDSliderSource(alignPanel,
2324 viewport.getGlobalColourScheme(),
2326 SliderPanel.showPIDSlider();
2333 * @param e DOCUMENT ME!
2335 protected void modifyConservation_actionPerformed(ActionEvent e)
2337 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2339 SliderPanel.setConservationSlider(alignPanel,
2340 viewport.globalColourScheme,
2342 SliderPanel.showConservationSlider();
2349 * @param e DOCUMENT ME!
2351 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2353 viewport.setConservationSelected(conservationMenuItem.isSelected());
2355 viewport.setAbovePIDThreshold(false);
2356 abovePIDThreshold.setSelected(false);
2358 changeColour(viewport.getGlobalColourScheme());
2360 modifyConservation_actionPerformed(null);
2366 * @param e DOCUMENT ME!
2368 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2370 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2372 conservationMenuItem.setSelected(false);
2373 viewport.setConservationSelected(false);
2375 changeColour(viewport.getGlobalColourScheme());
2377 modifyPID_actionPerformed(null);
2383 * @param e DOCUMENT ME!
2385 public void userDefinedColour_actionPerformed(ActionEvent e)
2387 if (e.getActionCommand().equals("User Defined..."))
2389 new UserDefinedColours(alignPanel, null);
2393 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2394 getUserColourSchemes().get(e.getActionCommand());
2400 public void updateUserColourMenu()
2403 Component[] menuItems = colourMenu.getMenuComponents();
2404 int i, iSize = menuItems.length;
2405 for (i = 0; i < iSize; i++)
2407 if (menuItems[i].getName() != null &&
2408 menuItems[i].getName().equals("USER_DEFINED"))
2410 colourMenu.remove(menuItems[i]);
2414 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2416 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2417 getUserColourSchemes().keys();
2419 while (userColours.hasMoreElements())
2421 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2422 nextElement().toString());
2423 radioItem.setName("USER_DEFINED");
2424 radioItem.addMouseListener(new MouseAdapter()
2426 public void mousePressed(MouseEvent evt)
2428 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2430 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2432 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2433 "Remove from default list?",
2434 "Remove user defined colour",
2435 JOptionPane.YES_NO_OPTION);
2436 if(option == JOptionPane.YES_OPTION)
2438 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2439 colourMenu.remove(radioItem);
2442 radioItem.addActionListener(new ActionListener()
2444 public void actionPerformed(ActionEvent evt)
2446 userDefinedColour_actionPerformed(evt);
2452 radioItem.addActionListener(new ActionListener()
2454 public void actionPerformed(ActionEvent evt)
2456 userDefinedColour_actionPerformed(evt);
2460 colourMenu.insert(radioItem, 15);
2461 colours.add(radioItem);
2469 * @param e DOCUMENT ME!
2471 public void PIDColour_actionPerformed(ActionEvent e)
2473 changeColour(new PIDColourScheme());
2479 * @param e DOCUMENT ME!
2481 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2483 changeColour(new Blosum62ColourScheme());
2489 * @param e DOCUMENT ME!
2491 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2493 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2494 AlignmentSorter.sortByPID(viewport.getAlignment(),
2495 viewport.getAlignment().getSequenceAt(0));
2496 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2497 alignPanel.repaint();
2503 * @param e DOCUMENT ME!
2505 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2507 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2508 AlignmentSorter.sortByID(viewport.getAlignment());
2509 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2510 alignPanel.repaint();
2516 * @param e DOCUMENT ME!
2518 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2520 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2521 AlignmentSorter.sortByGroup(viewport.getAlignment());
2522 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2524 alignPanel.repaint();
2530 * @param e DOCUMENT ME!
2532 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2534 new RedundancyPanel(alignPanel, this);
2541 * @param e DOCUMENT ME!
2543 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2545 if ( (viewport.getSelectionGroup() == null) ||
2546 (viewport.getSelectionGroup().getSize(false) < 2))
2548 JOptionPane.showInternalMessageDialog(this,
2549 "You must select at least 2 sequences.",
2550 "Invalid Selection",
2551 JOptionPane.WARNING_MESSAGE);
2555 JInternalFrame frame = new JInternalFrame();
2556 frame.setContentPane(new PairwiseAlignPanel(viewport));
2557 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2564 * @param e DOCUMENT ME!
2566 public void PCAMenuItem_actionPerformed(ActionEvent e)
2568 if ( ( (viewport.getSelectionGroup() != null) &&
2569 (viewport.getSelectionGroup().getSize(false) < 4) &&
2570 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2571 (viewport.getAlignment().getHeight() < 4))
2573 JOptionPane.showInternalMessageDialog(this,
2574 "Principal component analysis must take\n" +
2575 "at least 4 input sequences.",
2576 "Sequence selection insufficient",
2577 JOptionPane.WARNING_MESSAGE);
2582 new PCAPanel(viewport);
2586 public void autoCalculate_actionPerformed(ActionEvent e)
2588 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2589 if(viewport.autoCalculateConsensus)
2591 viewport.firePropertyChange("alignment",
2593 viewport.getAlignment().getSequences());
2601 * @param e DOCUMENT ME!
2603 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2605 NewTreePanel("AV", "PID", "Average distance tree using PID");
2611 * @param e DOCUMENT ME!
2613 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2615 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2621 * @param e DOCUMENT ME!
2623 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2625 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2631 * @param e DOCUMENT ME!
2633 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2635 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2641 * @param type DOCUMENT ME!
2642 * @param pwType DOCUMENT ME!
2643 * @param title DOCUMENT ME!
2645 void NewTreePanel(String type, String pwType, String title)
2649 if (viewport.getSelectionGroup() != null) {
2650 if (viewport.getSelectionGroup().getSize(false) < 3) {
2651 JOptionPane.showMessageDialog(Desktop.desktop,
2652 "You need to have more than two sequences selected to build a tree!",
2653 "Not enough sequences",
2654 JOptionPane.WARNING_MESSAGE);
2659 SequenceGroup sg = viewport.getSelectionGroup();
2661 /* Decide if the selection is a column region */
2662 while (s < sg.getSize(false))
2664 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2667 JOptionPane.showMessageDialog(Desktop.desktop,
2668 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2669 "Try using the Pad function in the edit menu,\n" +
2670 "or one of the multiple sequence alignment web services.",
2671 "Sequences in selection are not aligned",
2672 JOptionPane.WARNING_MESSAGE);
2678 title = title + " on region";
2679 tp = new TreePanel(alignPanel, type, pwType);
2683 //are the sequences aligned?
2684 if (!viewport.alignment.isAligned())
2686 JOptionPane.showMessageDialog(Desktop.desktop,
2687 "The sequences must be aligned before creating a tree.\n" +
2688 "Try using the Pad function in the edit menu,\n" +
2689 "or one of the multiple sequence alignment web services.",
2690 "Sequences not aligned",
2691 JOptionPane.WARNING_MESSAGE);
2696 if(viewport.alignment.getHeight()<2)
2699 tp = new TreePanel(alignPanel, type, pwType);
2702 addTreeMenuItem(tp, title);
2704 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2710 * @param title DOCUMENT ME!
2711 * @param order DOCUMENT ME!
2713 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2715 final JMenuItem item = new JMenuItem("by " + title);
2717 item.addActionListener(new java.awt.event.ActionListener()
2719 public void actionPerformed(ActionEvent e)
2721 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2723 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2724 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2726 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2728 alignPanel.repaint();
2734 * Maintain the Order by->Displayed Tree menu.
2735 * Creates a new menu item for a TreePanel with an appropriate
2736 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2737 * to remove the menu item when the treePanel is closed, and adjust
2738 * the tree leaf to sequence mapping when the alignment is modified.
2739 * @param treePanel Displayed tree window.
2740 * @param title SortBy menu item title.
2742 void addTreeMenuItem(final TreePanel treePanel, String title)
2744 final JMenuItem item = new JMenuItem(title);
2750 sort.add(sortByTreeMenu);
2753 sortByTreeMenu.add(item);
2754 item.addActionListener(new java.awt.event.ActionListener()
2756 public void actionPerformed(ActionEvent e)
2758 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2759 AlignmentSorter.sortByTree(viewport.getAlignment(),
2760 treePanel.getTree());
2762 addHistoryItem(new OrderCommand("Tree Sort",
2764 viewport.alignment));
2767 alignPanel.repaint();
2771 treePanel.addInternalFrameListener(new javax.swing.event.
2772 InternalFrameAdapter()
2774 public void internalFrameClosed(
2775 javax.swing.event.InternalFrameEvent evt)
2778 sortByTreeMenu.remove(item);
2782 sort.remove(sortByTreeMenu);
2790 * Work out whether the whole set of sequences
2791 * or just the selected set will be submitted for multiple alignment.
2794 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2796 // Now, check we have enough sequences
2797 AlignmentView msa = null;
2799 if ( (viewport.getSelectionGroup() != null) &&
2800 (viewport.getSelectionGroup().getSize(false) > 1))
2802 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2803 /*SequenceGroup seqs = viewport.getSelectionGroup();
2805 msa = new SequenceI[sz = seqs.getSize(false)];
2807 for (int i = 0; i < sz; i++)
2809 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2811 msa = viewport.getAlignmentView(true);
2815 /*Vector seqs = viewport.getAlignment().getSequences();
2817 if (seqs.size() > 1)
2819 msa = new SequenceI[seqs.size()];
2821 for (int i = 0; i < seqs.size(); i++)
2823 msa[i] = (SequenceI) seqs.elementAt(i);
2826 msa = viewport.getAlignmentView(false);
2832 * Decides what is submitted to a secondary structure prediction service,
2833 * the currently selected sequence, or the currently selected alignment
2834 * (where the first sequence in the set is the one that the prediction
2837 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2839 AlignmentView seqs = null;
2841 if ( (viewport.getSelectionGroup() != null) &&
2842 (viewport.getSelectionGroup().getSize(false) > 0))
2844 seqs = viewport.getAlignmentView(true);
2848 seqs = viewport.getAlignmentView(false);
2850 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2851 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2852 if (!viewport.alignment.isAligned())
2854 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2861 * @param e DOCUMENT ME!
2863 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2865 // Pick the tree file
2866 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2869 chooser.setFileView(new JalviewFileView());
2870 chooser.setDialogTitle("Select a newick-like tree file");
2871 chooser.setToolTipText("Load a tree file");
2873 int value = chooser.showOpenDialog(null);
2875 if (value == JalviewFileChooser.APPROVE_OPTION)
2877 String choice = chooser.getSelectedFile().getPath();
2878 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2882 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2884 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2886 catch (Exception ex)
2888 JOptionPane.showMessageDialog(Desktop.desktop,
2889 "Problem reading tree file",
2891 JOptionPane.WARNING_MESSAGE);
2892 ex.printStackTrace();
2898 public TreePanel ShowNewickTree(NewickFile nf, String title)
2900 return ShowNewickTree(nf,title,600,500,4,5);
2902 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2904 return ShowNewickTree(nf,title, input, 600,500,4,5);
2906 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2907 return ShowNewickTree(nf, title, null, w, h, x, y);
2910 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2912 * @param nf the tree
2913 * @param title tree viewer title
2914 * @param input Associated alignment input data (or null)
2919 * @return TreePanel handle
2921 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2922 TreePanel tp = null;
2928 if (nf.getTree() != null)
2930 tp = new TreePanel(alignPanel,
2938 tp.setLocation(x,y);
2941 Desktop.addInternalFrame(tp, title, w, h);
2942 addTreeMenuItem(tp, title);
2945 catch (Exception ex)
2947 ex.printStackTrace();
2958 PrinterJob printJob = PrinterJob.getPrinterJob();
2959 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2960 printJob.setPrintable(alignPanel, pf);
2962 if (printJob.printDialog())
2968 catch (Exception PrintException)
2970 PrintException.printStackTrace();
2977 * Generates menu items and listener event actions for web service clients
2980 public void BuildWebServiceMenu()
2982 if ( (Discoverer.services != null)
2983 && (Discoverer.services.size() > 0))
2985 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2986 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2987 Vector wsmenu = new Vector();
2988 final AlignFrame af = this;
2991 // Add any Multiple Sequence Alignment Services
2992 final JMenu msawsmenu = new JMenu("Alignment");
2993 for (int i = 0, j = msaws.size(); i < j; i++)
2995 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2997 final JMenuItem method = new JMenuItem(sh.getName());
2998 method.addActionListener(new ActionListener()
3000 public void actionPerformed(ActionEvent e)
3002 AlignmentView msa = gatherSequencesForAlignment();
3003 new jalview.ws.MsaWSClient(sh, title, msa,
3004 false, true, viewport.getAlignment().getDataset(), af);
3009 msawsmenu.add(method);
3010 // Deal with services that we know accept partial alignments.
3011 if (sh.getName().indexOf("lustal") > -1)
3013 // We know that ClustalWS can accept partial alignments for refinement.
3014 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
3015 methodR.addActionListener(new ActionListener()
3017 public void actionPerformed(ActionEvent e)
3019 AlignmentView msa = gatherSequencesForAlignment();
3020 new jalview.ws.MsaWSClient(sh, title, msa,
3021 true, true, viewport.getAlignment().getDataset(), af);
3026 msawsmenu.add(methodR);
3030 wsmenu.add(msawsmenu);
3032 if (secstrpr != null)
3034 // Add any secondary structure prediction services
3035 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3036 for (int i = 0, j = secstrpr.size(); i < j; i++)
3038 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3040 final JMenuItem method = new JMenuItem(sh.getName());
3041 method.addActionListener(new ActionListener()
3043 public void actionPerformed(ActionEvent e)
3045 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3046 if (msa.getSequences().length == 1)
3048 // Single Sequence prediction
3049 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3053 if (msa.getSequences().length > 1)
3055 // Sequence profile based prediction
3056 new jalview.ws.JPredClient(sh,
3057 title, true, msa, af, true);
3062 secstrmenu.add(method);
3064 wsmenu.add(secstrmenu);
3066 this.webService.removeAll();
3067 for (int i = 0, j = wsmenu.size(); i < j; i++)
3069 webService.add( (JMenu) wsmenu.get(i));
3074 this.webService.removeAll();
3075 this.webService.add(this.webServiceNoServices);
3077 // TODO: add in rediscovery function
3078 // TODO: reduce code redundancy.
3079 // TODO: group services by location as well as function.
3082 /* public void vamsasStore_actionPerformed(ActionEvent e)
3084 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3085 getProperty("LAST_DIRECTORY"));
3087 chooser.setFileView(new JalviewFileView());
3088 chooser.setDialogTitle("Export to Vamsas file");
3089 chooser.setToolTipText("Export");
3091 int value = chooser.showSaveDialog(this);
3093 if (value == JalviewFileChooser.APPROVE_OPTION)
3095 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3096 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3097 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3104 public void showTranslation_actionPerformed(ActionEvent e)
3106 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3107 String [] seqstring = viewport.getViewAsString(true);
3109 int s, sSize = selection.length;
3110 SequenceI [] newSeq = new SequenceI[sSize];
3113 StringBuffer protein;
3115 for(s=0; s<sSize; s++)
3117 protein = new StringBuffer();
3118 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3119 resSize = seq.length();
3120 resSize -= resSize%3;
3122 for(res = 0; res < resSize; res+=3)
3124 String codon = seq.substring(res, res+3);
3125 codon = codon.replace('U', 'T');
3126 String aa = ResidueProperties.codonTranslate(codon);
3128 protein.append(viewport.getGapCharacter());
3129 else if(aa.equals("STOP"))
3130 protein.append("X");
3132 protein.append( aa );
3134 newSeq[s] = new Sequence(selection[s].getName(),
3135 protein.toString());
3139 AlignmentI al = new Alignment(newSeq);
3140 al.setDataset(null);
3143 ////////////////////////////////
3144 // Copy annotations across
3145 jalview.datamodel.AlignmentAnnotation[] annotations
3146 = viewport.alignment.getAlignmentAnnotation();
3148 if(annotations!=null)
3150 for (int i = 0; i < annotations.length; i++)
3152 if (annotations[i].label.equals("Quality") ||
3153 annotations[i].label.equals("Conservation") ||
3154 annotations[i].label.equals("Consensus"))
3159 aSize = viewport.alignment.getWidth() / 3;
3160 jalview.datamodel.Annotation[] anots =
3161 new jalview.datamodel.Annotation[aSize];
3163 for (a = 0; a < viewport.alignment.getWidth(); a++)
3165 if (annotations[i].annotations[a] == null
3166 || annotations[i].annotations[a] == null)
3169 anots[a / 3] = new Annotation(
3170 annotations[i].annotations[a].displayCharacter,
3171 annotations[i].annotations[a].description,
3172 annotations[i].annotations[a].secondaryStructure,
3173 annotations[i].annotations[a].value,
3174 annotations[i].annotations[a].colour);
3177 jalview.datamodel.AlignmentAnnotation aa
3178 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3179 annotations[i].description, anots);
3180 al.addAnnotation(aa);
3184 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3185 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3197 * @param String DOCUMENT ME!
3199 public boolean parseFeaturesFile(String file, String type)
3201 boolean featuresFile = false;
3203 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3204 alignPanel.seqPanel.seqCanvas.
3205 getFeatureRenderer().featureColours,
3210 ex.printStackTrace();
3215 viewport.showSequenceFeatures = true;
3216 showSeqFeatures.setSelected(true);
3217 alignPanel.repaint();
3220 return featuresFile;
3223 public void dragEnter(DropTargetDragEvent evt)
3226 public void dragExit(DropTargetEvent evt)
3229 public void dragOver(DropTargetDragEvent evt)
3232 public void dropActionChanged(DropTargetDragEvent evt)
3235 public void drop(DropTargetDropEvent evt)
3237 Transferable t = evt.getTransferable();
3238 java.util.List files = null;
3242 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3243 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3245 //Works on Windows and MacOSX
3246 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3247 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3249 else if (t.isDataFlavorSupported(uriListFlavor))
3251 // This is used by Unix drag system
3252 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3253 String data = (String) t.getTransferData(uriListFlavor);
3254 files = new java.util.ArrayList(1);
3255 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3258 st.hasMoreTokens(); )
3260 String s = st.nextToken();
3261 if (s.startsWith("#"))
3263 // the line is a comment (as per the RFC 2483)
3267 java.net.URI uri = new java.net.URI(s);
3268 java.io.File file = new java.io.File(uri);
3275 e.printStackTrace();
3282 for (int i = 0; i < files.size(); i++)
3284 loadJalviewDataFile(files.get(i).toString());
3287 catch (Exception ex)
3289 ex.printStackTrace();
3294 // This method will attempt to load a "dropped" file first by testing
3295 // whether its and Annotation file, then features file. If both are
3296 // false then the user may have dropped an alignment file onto this
3298 public void loadJalviewDataFile(String file)
3301 String protocol = "File";
3303 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3308 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3313 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3316 String format = new IdentifyFile().Identify(file, protocol);
3318 if(format.equalsIgnoreCase("JnetFile"))
3320 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3322 new JnetAnnotationMaker().add_annotation(predictions,
3323 viewport.getAlignment(),
3325 alignPanel.adjustAnnotationHeight();
3326 alignPanel.repaint();
3329 new FileLoader().LoadFile(viewport, file, protocol, format);
3335 alignPanel.adjustAnnotationHeight();
3338 }catch(Exception ex)
3340 ex.printStackTrace();
3344 public void tabSelectionChanged(int index)
3348 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3349 viewport = alignPanel.av;
3350 setMenusFromViewport(viewport);
3354 public void tabbedPane_mousePressed(MouseEvent e)
3356 if(SwingUtilities.isRightMouseButton(e))
3358 String reply = JOptionPane.showInternalInputDialog(this,
3361 JOptionPane.QUESTION_MESSAGE);
3365 viewport.viewName = reply;
3366 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3372 public AlignViewport getCurrentView()