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)
1714 public void newView_actionPerformed(ActionEvent e)
1716 AlignmentPanel newap =
1717 new Jalview2XML().copyAlignPanel(alignPanel, true);
1719 if (viewport.viewName == null)
1720 viewport.viewName = "View 1";
1722 newap.av.historyList = viewport.historyList;
1723 newap.av.redoList = viewport.redoList;
1724 newap.av.viewName = "View " +
1725 (Desktop.getViewCount(viewport.getSequenceSetId()) + 1);
1727 addAlignmentPanel(newap, false);
1729 if(alignPanels.size()==2)
1731 viewport.gatherViewsHere = true;
1733 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1740 * @param e DOCUMENT ME!
1742 public void font_actionPerformed(ActionEvent e)
1744 new FontChooser(alignPanel);
1751 * @param e DOCUMENT ME!
1753 protected void seqLimit_actionPerformed(ActionEvent e)
1755 viewport.setShowJVSuffix(seqLimits.isSelected());
1757 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1758 alignPanel.repaint();
1761 public void idRightAlign_actionPerformed(ActionEvent e)
1763 viewport.idsAlignRight = idRightAlign.isSelected();
1764 alignPanel.repaint();
1772 * @param e DOCUMENT ME!
1774 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1776 viewport.setColourText(colourTextMenuItem.isSelected());
1777 alignPanel.repaint();
1783 * @param e DOCUMENT ME!
1785 public void wrapMenuItem_actionPerformed(ActionEvent e)
1787 scaleAbove.setVisible(wrapMenuItem.isSelected());
1788 scaleLeft.setVisible(wrapMenuItem.isSelected());
1789 scaleRight.setVisible(wrapMenuItem.isSelected());
1790 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1791 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1794 public void showAllSeqs_actionPerformed(ActionEvent e)
1796 viewport.showAllHiddenSeqs();
1799 public void showAllColumns_actionPerformed(ActionEvent e)
1801 viewport.showAllHiddenColumns();
1805 public void hideSelSequences_actionPerformed(ActionEvent e)
1807 viewport.hideAllSelectedSeqs();
1808 alignPanel.repaint();
1811 public void hideSelColumns_actionPerformed(ActionEvent e)
1813 viewport.hideSelectedColumns();
1814 alignPanel.repaint();
1817 public void hiddenMarkers_actionPerformed(ActionEvent e)
1819 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1826 * @param e DOCUMENT ME!
1828 protected void scaleAbove_actionPerformed(ActionEvent e)
1830 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1831 alignPanel.repaint();
1837 * @param e DOCUMENT ME!
1839 protected void scaleLeft_actionPerformed(ActionEvent e)
1841 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1842 alignPanel.repaint();
1848 * @param e DOCUMENT ME!
1850 protected void scaleRight_actionPerformed(ActionEvent e)
1852 viewport.setScaleRightWrapped(scaleRight.isSelected());
1853 alignPanel.repaint();
1859 * @param e DOCUMENT ME!
1861 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1863 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1864 alignPanel.repaint();
1870 * @param e DOCUMENT ME!
1872 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1874 viewport.setShowText(viewTextMenuItem.isSelected());
1875 alignPanel.repaint();
1881 * @param e DOCUMENT ME!
1883 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1885 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1886 alignPanel.repaint();
1890 public FeatureSettings featureSettings;
1891 public void featureSettings_actionPerformed(ActionEvent e)
1893 if(featureSettings !=null )
1895 featureSettings.close();
1896 featureSettings = null;
1898 featureSettings = new FeatureSettings(this);
1904 * @param evt DOCUMENT ME!
1906 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1908 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1909 alignPanel.repaint();
1910 if (alignPanel.getOverviewPanel() != null)
1912 alignPanel.getOverviewPanel().updateOverviewImage();
1919 * @param e DOCUMENT ME!
1921 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1923 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1924 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1930 * @param e DOCUMENT ME!
1932 public void overviewMenuItem_actionPerformed(ActionEvent e)
1934 if (alignPanel.overviewPanel != null)
1939 JInternalFrame frame = new JInternalFrame();
1940 OverviewPanel overview = new OverviewPanel(alignPanel);
1941 frame.setContentPane(overview);
1942 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1943 frame.getWidth(), frame.getHeight());
1945 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1946 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1948 public void internalFrameClosed(
1949 javax.swing.event.InternalFrameEvent evt)
1951 alignPanel.setOverviewPanel(null);
1956 alignPanel.setOverviewPanel(overview);
1959 public void textColour_actionPerformed(ActionEvent e)
1961 int original1 = viewport.textColour.getRGB();
1962 int original2 = viewport.textColour2.getRGB();
1963 int thresh = viewport.thresholdTextColour;
1964 final JSlider slider = new JSlider(0, 750, viewport.thresholdTextColour);
1965 final JButton col1 = new JButton("DARK");
1966 col1.setBackground(viewport.textColour);
1967 col1.setForeground(viewport.textColour);
1968 final JButton col2 = new JButton("LIGHT");
1969 col2.setBackground(viewport.textColour2);
1970 col2.setForeground(viewport.textColour2);
1971 final JPanel bigpanel = new JPanel(new BorderLayout());
1972 JPanel panel = new JPanel();
1973 bigpanel.add(panel, BorderLayout.CENTER);
1974 bigpanel.add(new JLabel(
1975 "<html><i>Select a dark and light text colour, then set the threshold to"
1976 +"<br>switch between colours, based on background colour</i></html>"),
1977 BorderLayout.NORTH);
1982 col1.addActionListener(new ActionListener()
1984 public void actionPerformed(ActionEvent e)
1986 Color col = JColorChooser.showDialog(bigpanel,
1987 "Select Colour for Text",
1988 viewport.textColour);
1991 viewport.textColour = col;
1992 col1.setBackground(col);
1993 col1.setForeground(col);
1994 if(viewport.colourAppliesToAllGroups)
1995 setGroupTextColour();
1997 alignPanel.repaint();
2001 col2.addActionListener(new ActionListener()
2003 public void actionPerformed(ActionEvent e)
2005 Color col = JColorChooser.showDialog(bigpanel,
2006 "Select Colour for Text",
2007 viewport.textColour);
2010 viewport.textColour2 = col;
2011 col2.setBackground(col);
2012 col2.setForeground(col);
2013 if(viewport.colourAppliesToAllGroups)
2014 setGroupTextColour();
2016 alignPanel.repaint();
2021 slider.addChangeListener(new ChangeListener()
2023 public void stateChanged(ChangeEvent evt)
2025 viewport.thresholdTextColour = slider.getValue();
2026 if(viewport.colourAppliesToAllGroups)
2027 setGroupTextColour();
2028 alignPanel.repaint();
2032 int reply = JOptionPane.showInternalOptionDialog(this,
2034 "Adjust Foreground Text Colour Threshold",
2035 JOptionPane.OK_CANCEL_OPTION,
2036 JOptionPane.QUESTION_MESSAGE,
2040 if(reply==JOptionPane.CANCEL_OPTION)
2042 viewport.textColour = new Color(original1);
2043 viewport.textColour2 = new Color(original2);
2044 viewport.thresholdTextColour = thresh;
2048 void setGroupTextColour()
2050 if(viewport.alignment.getGroups()==null)
2053 Vector groups = viewport.alignment.getGroups();
2055 for(int i=0; i<groups.size(); i++)
2057 SequenceGroup sg = (SequenceGroup)groups.elementAt(i);
2058 sg.textColour = viewport.textColour;
2059 sg.textColour2 = viewport.textColour2;
2060 sg.thresholdTextColour = viewport.thresholdTextColour;
2070 * @param e DOCUMENT ME!
2072 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2080 * @param e DOCUMENT ME!
2082 public void clustalColour_actionPerformed(ActionEvent e)
2084 changeColour(new ClustalxColourScheme(
2085 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2091 * @param e DOCUMENT ME!
2093 public void zappoColour_actionPerformed(ActionEvent e)
2095 changeColour(new ZappoColourScheme());
2101 * @param e DOCUMENT ME!
2103 public void taylorColour_actionPerformed(ActionEvent e)
2105 changeColour(new TaylorColourScheme());
2111 * @param e DOCUMENT ME!
2113 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2115 changeColour(new HydrophobicColourScheme());
2121 * @param e DOCUMENT ME!
2123 public void helixColour_actionPerformed(ActionEvent e)
2125 changeColour(new HelixColourScheme());
2131 * @param e DOCUMENT ME!
2133 public void strandColour_actionPerformed(ActionEvent e)
2135 changeColour(new StrandColourScheme());
2141 * @param e DOCUMENT ME!
2143 public void turnColour_actionPerformed(ActionEvent e)
2145 changeColour(new TurnColourScheme());
2151 * @param e DOCUMENT ME!
2153 public void buriedColour_actionPerformed(ActionEvent e)
2155 changeColour(new BuriedColourScheme());
2161 * @param e DOCUMENT ME!
2163 public void nucleotideColour_actionPerformed(ActionEvent e)
2165 changeColour(new NucleotideColourScheme());
2168 public void annotationColour_actionPerformed(ActionEvent e)
2170 new AnnotationColourChooser(viewport, alignPanel);
2177 * @param e DOCUMENT ME!
2179 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2181 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2187 * @param cs DOCUMENT ME!
2189 public void changeColour(ColourSchemeI cs)
2195 if (viewport.getAbovePIDThreshold())
2197 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2200 cs.setThreshold(threshold,
2201 viewport.getIgnoreGapsConsensus());
2203 viewport.setGlobalColourScheme(cs);
2207 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2210 if (viewport.getConservationSelected())
2213 Alignment al = (Alignment) viewport.alignment;
2214 Conservation c = new Conservation("All",
2215 ResidueProperties.propHash, 3,
2216 al.getSequences(), 0,
2220 c.verdict(false, viewport.ConsPercGaps);
2222 cs.setConservation(c);
2224 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2229 cs.setConservation(null);
2232 cs.setConsensus(viewport.hconsensus);
2235 viewport.setGlobalColourScheme(cs);
2237 if (viewport.getColourAppliesToAllGroups())
2239 Vector groups = viewport.alignment.getGroups();
2241 for (int i = 0; i < groups.size(); i++)
2243 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2251 if (cs instanceof ClustalxColourScheme)
2253 sg.cs = new ClustalxColourScheme(
2254 sg.getSequences(true), sg.getWidth());
2256 else if (cs instanceof UserColourScheme)
2258 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2264 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2266 catch (Exception ex)
2271 if (viewport.getAbovePIDThreshold()
2272 || cs instanceof PIDColourScheme
2273 || cs instanceof Blosum62ColourScheme)
2275 sg.cs.setThreshold(threshold,
2276 viewport.getIgnoreGapsConsensus());
2278 sg.cs.setConsensus(AAFrequency.calculate(
2279 sg.getSequences(true), sg.getStartRes(),
2283 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2286 if (viewport.getConservationSelected())
2288 Conservation c = new Conservation("Group",
2289 ResidueProperties.propHash, 3,
2290 sg.getSequences(true),
2294 c.verdict(false, viewport.ConsPercGaps);
2295 sg.cs.setConservation(c);
2298 sg.cs.setConservation(null);
2302 if (alignPanel.getOverviewPanel() != null)
2304 alignPanel.getOverviewPanel().updateOverviewImage();
2307 alignPanel.repaint();
2313 * @param e DOCUMENT ME!
2315 protected void modifyPID_actionPerformed(ActionEvent e)
2317 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2319 SliderPanel.setPIDSliderSource(alignPanel,
2320 viewport.getGlobalColourScheme(),
2322 SliderPanel.showPIDSlider();
2329 * @param e DOCUMENT ME!
2331 protected void modifyConservation_actionPerformed(ActionEvent e)
2333 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2335 SliderPanel.setConservationSlider(alignPanel,
2336 viewport.globalColourScheme,
2338 SliderPanel.showConservationSlider();
2345 * @param e DOCUMENT ME!
2347 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2349 viewport.setConservationSelected(conservationMenuItem.isSelected());
2351 viewport.setAbovePIDThreshold(false);
2352 abovePIDThreshold.setSelected(false);
2354 changeColour(viewport.getGlobalColourScheme());
2356 modifyConservation_actionPerformed(null);
2362 * @param e DOCUMENT ME!
2364 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2366 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2368 conservationMenuItem.setSelected(false);
2369 viewport.setConservationSelected(false);
2371 changeColour(viewport.getGlobalColourScheme());
2373 modifyPID_actionPerformed(null);
2379 * @param e DOCUMENT ME!
2381 public void userDefinedColour_actionPerformed(ActionEvent e)
2383 if (e.getActionCommand().equals("User Defined..."))
2385 new UserDefinedColours(alignPanel, null);
2389 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2390 getUserColourSchemes().get(e.getActionCommand());
2396 public void updateUserColourMenu()
2399 Component[] menuItems = colourMenu.getMenuComponents();
2400 int i, iSize = menuItems.length;
2401 for (i = 0; i < iSize; i++)
2403 if (menuItems[i].getName() != null &&
2404 menuItems[i].getName().equals("USER_DEFINED"))
2406 colourMenu.remove(menuItems[i]);
2410 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2412 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2413 getUserColourSchemes().keys();
2415 while (userColours.hasMoreElements())
2417 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2418 nextElement().toString());
2419 radioItem.setName("USER_DEFINED");
2420 radioItem.addMouseListener(new MouseAdapter()
2422 public void mousePressed(MouseEvent evt)
2424 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2426 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2428 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2429 "Remove from default list?",
2430 "Remove user defined colour",
2431 JOptionPane.YES_NO_OPTION);
2432 if(option == JOptionPane.YES_OPTION)
2434 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2435 colourMenu.remove(radioItem);
2438 radioItem.addActionListener(new ActionListener()
2440 public void actionPerformed(ActionEvent evt)
2442 userDefinedColour_actionPerformed(evt);
2448 radioItem.addActionListener(new ActionListener()
2450 public void actionPerformed(ActionEvent evt)
2452 userDefinedColour_actionPerformed(evt);
2456 colourMenu.insert(radioItem, 15);
2457 colours.add(radioItem);
2465 * @param e DOCUMENT ME!
2467 public void PIDColour_actionPerformed(ActionEvent e)
2469 changeColour(new PIDColourScheme());
2475 * @param e DOCUMENT ME!
2477 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2479 changeColour(new Blosum62ColourScheme());
2485 * @param e DOCUMENT ME!
2487 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2489 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2490 AlignmentSorter.sortByPID(viewport.getAlignment(),
2491 viewport.getAlignment().getSequenceAt(0));
2492 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2493 alignPanel.repaint();
2499 * @param e DOCUMENT ME!
2501 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2503 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2504 AlignmentSorter.sortByID(viewport.getAlignment());
2505 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2506 alignPanel.repaint();
2512 * @param e DOCUMENT ME!
2514 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2516 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2517 AlignmentSorter.sortByGroup(viewport.getAlignment());
2518 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2520 alignPanel.repaint();
2526 * @param e DOCUMENT ME!
2528 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2530 new RedundancyPanel(alignPanel, this);
2537 * @param e DOCUMENT ME!
2539 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2541 if ( (viewport.getSelectionGroup() == null) ||
2542 (viewport.getSelectionGroup().getSize(false) < 2))
2544 JOptionPane.showInternalMessageDialog(this,
2545 "You must select at least 2 sequences.",
2546 "Invalid Selection",
2547 JOptionPane.WARNING_MESSAGE);
2551 JInternalFrame frame = new JInternalFrame();
2552 frame.setContentPane(new PairwiseAlignPanel(viewport));
2553 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2560 * @param e DOCUMENT ME!
2562 public void PCAMenuItem_actionPerformed(ActionEvent e)
2564 if ( ( (viewport.getSelectionGroup() != null) &&
2565 (viewport.getSelectionGroup().getSize(false) < 4) &&
2566 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2567 (viewport.getAlignment().getHeight() < 4))
2569 JOptionPane.showInternalMessageDialog(this,
2570 "Principal component analysis must take\n" +
2571 "at least 4 input sequences.",
2572 "Sequence selection insufficient",
2573 JOptionPane.WARNING_MESSAGE);
2578 new PCAPanel(viewport);
2582 public void autoCalculate_actionPerformed(ActionEvent e)
2584 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2585 if(viewport.autoCalculateConsensus)
2587 viewport.firePropertyChange("alignment",
2589 viewport.getAlignment().getSequences());
2597 * @param e DOCUMENT ME!
2599 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2601 NewTreePanel("AV", "PID", "Average distance tree using PID");
2607 * @param e DOCUMENT ME!
2609 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2611 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2617 * @param e DOCUMENT ME!
2619 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2621 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2627 * @param e DOCUMENT ME!
2629 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2631 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2637 * @param type DOCUMENT ME!
2638 * @param pwType DOCUMENT ME!
2639 * @param title DOCUMENT ME!
2641 void NewTreePanel(String type, String pwType, String title)
2645 if (viewport.getSelectionGroup() != null) {
2646 if (viewport.getSelectionGroup().getSize(false) < 3) {
2647 JOptionPane.showMessageDialog(Desktop.desktop,
2648 "You need to have more than two sequences selected to build a tree!",
2649 "Not enough sequences",
2650 JOptionPane.WARNING_MESSAGE);
2655 SequenceGroup sg = viewport.getSelectionGroup();
2657 /* Decide if the selection is a column region */
2658 while (s < sg.getSize(false))
2660 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2663 JOptionPane.showMessageDialog(Desktop.desktop,
2664 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2665 "Try using the Pad function in the edit menu,\n" +
2666 "or one of the multiple sequence alignment web services.",
2667 "Sequences in selection are not aligned",
2668 JOptionPane.WARNING_MESSAGE);
2674 title = title + " on region";
2675 tp = new TreePanel(alignPanel, type, pwType);
2679 //are the sequences aligned?
2680 if (!viewport.alignment.isAligned())
2682 JOptionPane.showMessageDialog(Desktop.desktop,
2683 "The sequences must be aligned before creating a tree.\n" +
2684 "Try using the Pad function in the edit menu,\n" +
2685 "or one of the multiple sequence alignment web services.",
2686 "Sequences not aligned",
2687 JOptionPane.WARNING_MESSAGE);
2692 if(viewport.alignment.getHeight()<2)
2695 tp = new TreePanel(alignPanel, type, pwType);
2698 addTreeMenuItem(tp, title);
2700 Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);
2706 * @param title DOCUMENT ME!
2707 * @param order DOCUMENT ME!
2709 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2711 final JMenuItem item = new JMenuItem("by " + title);
2713 item.addActionListener(new java.awt.event.ActionListener()
2715 public void actionPerformed(ActionEvent e)
2717 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2719 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2720 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2722 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2724 alignPanel.repaint();
2730 * Maintain the Order by->Displayed Tree menu.
2731 * Creates a new menu item for a TreePanel with an appropriate
2732 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2733 * to remove the menu item when the treePanel is closed, and adjust
2734 * the tree leaf to sequence mapping when the alignment is modified.
2735 * @param treePanel Displayed tree window.
2736 * @param title SortBy menu item title.
2738 void addTreeMenuItem(final TreePanel treePanel, String title)
2740 final JMenuItem item = new JMenuItem(title);
2746 sort.add(sortByTreeMenu);
2749 sortByTreeMenu.add(item);
2750 item.addActionListener(new java.awt.event.ActionListener()
2752 public void actionPerformed(ActionEvent e)
2754 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2755 AlignmentSorter.sortByTree(viewport.getAlignment(),
2756 treePanel.getTree());
2758 addHistoryItem(new OrderCommand("Tree Sort",
2760 viewport.alignment));
2763 alignPanel.repaint();
2767 treePanel.addInternalFrameListener(new javax.swing.event.
2768 InternalFrameAdapter()
2770 public void internalFrameClosed(
2771 javax.swing.event.InternalFrameEvent evt)
2774 sortByTreeMenu.remove(item);
2778 sort.remove(sortByTreeMenu);
2786 * Work out whether the whole set of sequences
2787 * or just the selected set will be submitted for multiple alignment.
2790 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2792 // Now, check we have enough sequences
2793 AlignmentView msa = null;
2795 if ( (viewport.getSelectionGroup() != null) &&
2796 (viewport.getSelectionGroup().getSize(false) > 1))
2798 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2799 /*SequenceGroup seqs = viewport.getSelectionGroup();
2801 msa = new SequenceI[sz = seqs.getSize(false)];
2803 for (int i = 0; i < sz; i++)
2805 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2807 msa = viewport.getAlignmentView(true);
2811 /*Vector seqs = viewport.getAlignment().getSequences();
2813 if (seqs.size() > 1)
2815 msa = new SequenceI[seqs.size()];
2817 for (int i = 0; i < seqs.size(); i++)
2819 msa[i] = (SequenceI) seqs.elementAt(i);
2822 msa = viewport.getAlignmentView(false);
2828 * Decides what is submitted to a secondary structure prediction service,
2829 * the currently selected sequence, or the currently selected alignment
2830 * (where the first sequence in the set is the one that the prediction
2833 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2835 AlignmentView seqs = null;
2837 if ( (viewport.getSelectionGroup() != null) &&
2838 (viewport.getSelectionGroup().getSize(false) > 0))
2840 seqs = viewport.getAlignmentView(true);
2844 seqs = viewport.getAlignmentView(false);
2846 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2847 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2848 if (!viewport.alignment.isAligned())
2850 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2857 * @param e DOCUMENT ME!
2859 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2861 // Pick the tree file
2862 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2865 chooser.setFileView(new JalviewFileView());
2866 chooser.setDialogTitle("Select a newick-like tree file");
2867 chooser.setToolTipText("Load a tree file");
2869 int value = chooser.showOpenDialog(null);
2871 if (value == JalviewFileChooser.APPROVE_OPTION)
2873 String choice = chooser.getSelectedFile().getPath();
2874 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2878 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2880 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2882 catch (Exception ex)
2884 JOptionPane.showMessageDialog(Desktop.desktop,
2885 "Problem reading tree file",
2887 JOptionPane.WARNING_MESSAGE);
2888 ex.printStackTrace();
2894 public TreePanel ShowNewickTree(NewickFile nf, String title)
2896 return ShowNewickTree(nf,title,600,500,4,5);
2898 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2900 return ShowNewickTree(nf,title, input, 600,500,4,5);
2902 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2903 return ShowNewickTree(nf, title, null, w, h, x, y);
2906 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2908 * @param nf the tree
2909 * @param title tree viewer title
2910 * @param input Associated alignment input data (or null)
2915 * @return TreePanel handle
2917 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2918 TreePanel tp = null;
2924 if (nf.getTree() != null)
2926 tp = new TreePanel(alignPanel,
2934 tp.setLocation(x,y);
2937 Desktop.addInternalFrame(tp, title, w, h);
2938 addTreeMenuItem(tp, title);
2941 catch (Exception ex)
2943 ex.printStackTrace();
2954 PrinterJob printJob = PrinterJob.getPrinterJob();
2955 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2956 printJob.setPrintable(alignPanel, pf);
2958 if (printJob.printDialog())
2964 catch (Exception PrintException)
2966 PrintException.printStackTrace();
2973 * Generates menu items and listener event actions for web service clients
2976 public void BuildWebServiceMenu()
2978 if ( (Discoverer.services != null)
2979 && (Discoverer.services.size() > 0))
2981 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2982 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2983 Vector wsmenu = new Vector();
2984 final AlignFrame af = this;
2987 // Add any Multiple Sequence Alignment Services
2988 final JMenu msawsmenu = new JMenu("Alignment");
2989 for (int i = 0, j = msaws.size(); i < j; i++)
2991 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2993 final JMenuItem method = new JMenuItem(sh.getName());
2994 method.addActionListener(new ActionListener()
2996 public void actionPerformed(ActionEvent e)
2998 AlignmentView msa = gatherSequencesForAlignment();
2999 new jalview.ws.MsaWSClient(sh, title, msa,
3000 false, true, viewport.getAlignment().getDataset(), af);
3005 msawsmenu.add(method);
3006 // Deal with services that we know accept partial alignments.
3007 if (sh.getName().indexOf("lustal") > -1)
3009 // We know that ClustalWS can accept partial alignments for refinement.
3010 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
3011 methodR.addActionListener(new ActionListener()
3013 public void actionPerformed(ActionEvent e)
3015 AlignmentView msa = gatherSequencesForAlignment();
3016 new jalview.ws.MsaWSClient(sh, title, msa,
3017 true, true, viewport.getAlignment().getDataset(), af);
3022 msawsmenu.add(methodR);
3026 wsmenu.add(msawsmenu);
3028 if (secstrpr != null)
3030 // Add any secondary structure prediction services
3031 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
3032 for (int i = 0, j = secstrpr.size(); i < j; i++)
3034 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3036 final JMenuItem method = new JMenuItem(sh.getName());
3037 method.addActionListener(new ActionListener()
3039 public void actionPerformed(ActionEvent e)
3041 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3042 if (msa.getSequences().length == 1)
3044 // Single Sequence prediction
3045 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3049 if (msa.getSequences().length > 1)
3051 // Sequence profile based prediction
3052 new jalview.ws.JPredClient(sh,
3053 title, true, msa, af, true);
3058 secstrmenu.add(method);
3060 wsmenu.add(secstrmenu);
3062 this.webService.removeAll();
3063 for (int i = 0, j = wsmenu.size(); i < j; i++)
3065 webService.add( (JMenu) wsmenu.get(i));
3070 this.webService.removeAll();
3071 this.webService.add(this.webServiceNoServices);
3073 // TODO: add in rediscovery function
3074 // TODO: reduce code redundancy.
3075 // TODO: group services by location as well as function.
3078 /* public void vamsasStore_actionPerformed(ActionEvent e)
3080 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3081 getProperty("LAST_DIRECTORY"));
3083 chooser.setFileView(new JalviewFileView());
3084 chooser.setDialogTitle("Export to Vamsas file");
3085 chooser.setToolTipText("Export");
3087 int value = chooser.showSaveDialog(this);
3089 if (value == JalviewFileChooser.APPROVE_OPTION)
3091 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3092 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3093 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3100 public void showTranslation_actionPerformed(ActionEvent e)
3102 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3103 String [] seqstring = viewport.getViewAsString(true);
3105 int s, sSize = selection.length;
3106 SequenceI [] newSeq = new SequenceI[sSize];
3109 StringBuffer protein;
3111 for(s=0; s<sSize; s++)
3113 protein = new StringBuffer();
3114 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3115 resSize = seq.length();
3116 resSize -= resSize%3;
3118 for(res = 0; res < resSize; res+=3)
3120 String codon = seq.substring(res, res+3);
3121 codon = codon.replace('U', 'T');
3122 String aa = ResidueProperties.codonTranslate(codon);
3124 protein.append(viewport.getGapCharacter());
3125 else if(aa.equals("STOP"))
3126 protein.append("X");
3128 protein.append( aa );
3130 newSeq[s] = new Sequence(selection[s].getName(),
3131 protein.toString());
3135 AlignmentI al = new Alignment(newSeq);
3136 al.setDataset(null);
3139 ////////////////////////////////
3140 // Copy annotations across
3141 jalview.datamodel.AlignmentAnnotation[] annotations
3142 = viewport.alignment.getAlignmentAnnotation();
3144 if(annotations!=null)
3146 for (int i = 0; i < annotations.length; i++)
3148 if (annotations[i].label.equals("Quality") ||
3149 annotations[i].label.equals("Conservation") ||
3150 annotations[i].label.equals("Consensus"))
3155 aSize = viewport.alignment.getWidth() / 3;
3156 jalview.datamodel.Annotation[] anots =
3157 new jalview.datamodel.Annotation[aSize];
3159 for (a = 0; a < viewport.alignment.getWidth(); a++)
3161 if (annotations[i].annotations[a] == null
3162 || annotations[i].annotations[a] == null)
3165 anots[a / 3] = new Annotation(
3166 annotations[i].annotations[a].displayCharacter,
3167 annotations[i].annotations[a].description,
3168 annotations[i].annotations[a].secondaryStructure,
3169 annotations[i].annotations[a].value,
3170 annotations[i].annotations[a].colour);
3173 jalview.datamodel.AlignmentAnnotation aa
3174 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3175 annotations[i].description, anots);
3176 al.addAnnotation(aa);
3180 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3181 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3193 * @param String DOCUMENT ME!
3195 public boolean parseFeaturesFile(String file, String type)
3197 boolean featuresFile = false;
3199 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3200 alignPanel.seqPanel.seqCanvas.
3201 getFeatureRenderer().featureColours,
3206 ex.printStackTrace();
3211 viewport.showSequenceFeatures = true;
3212 showSeqFeatures.setSelected(true);
3213 alignPanel.repaint();
3216 return featuresFile;
3219 public void dragEnter(DropTargetDragEvent evt)
3222 public void dragExit(DropTargetEvent evt)
3225 public void dragOver(DropTargetDragEvent evt)
3228 public void dropActionChanged(DropTargetDragEvent evt)
3231 public void drop(DropTargetDropEvent evt)
3233 Transferable t = evt.getTransferable();
3234 java.util.List files = null;
3238 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3239 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3241 //Works on Windows and MacOSX
3242 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3243 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3245 else if (t.isDataFlavorSupported(uriListFlavor))
3247 // This is used by Unix drag system
3248 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3249 String data = (String) t.getTransferData(uriListFlavor);
3250 files = new java.util.ArrayList(1);
3251 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3254 st.hasMoreTokens(); )
3256 String s = st.nextToken();
3257 if (s.startsWith("#"))
3259 // the line is a comment (as per the RFC 2483)
3263 java.net.URI uri = new java.net.URI(s);
3264 java.io.File file = new java.io.File(uri);
3271 e.printStackTrace();
3278 for (int i = 0; i < files.size(); i++)
3280 loadJalviewDataFile(files.get(i).toString());
3283 catch (Exception ex)
3285 ex.printStackTrace();
3290 // This method will attempt to load a "dropped" file first by testing
3291 // whether its and Annotation file, then features file. If both are
3292 // false then the user may have dropped an alignment file onto this
3294 public void loadJalviewDataFile(String file)
3297 String protocol = "File";
3299 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3304 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3309 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3312 String format = new IdentifyFile().Identify(file, protocol);
3314 if(format.equalsIgnoreCase("JnetFile"))
3316 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3318 new JnetAnnotationMaker().add_annotation(predictions,
3319 viewport.getAlignment(),
3321 alignPanel.adjustAnnotationHeight();
3322 alignPanel.repaint();
3325 new FileLoader().LoadFile(viewport, file, protocol, format);
3331 alignPanel.adjustAnnotationHeight();
3334 }catch(Exception ex)
3336 ex.printStackTrace();
3340 public void tabSelectionChanged(int index)
3344 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3345 viewport = alignPanel.av;
3346 setMenusFromViewport(viewport);
3350 public void tabbedPane_mousePressed(MouseEvent e)
3352 if(SwingUtilities.isRightMouseButton(e))
3354 String reply = JOptionPane.showInternalInputDialog(this,
3357 JOptionPane.QUESTION_MESSAGE);
3361 viewport.viewName = reply;
3362 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3368 public AlignViewport getCurrentView()