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;
69 * Creates a new AlignFrame object.
71 * @param al DOCUMENT ME!
73 public AlignFrame(AlignmentI al, int width, int height)
75 this(al, null, width, height);
80 * new alignment window with hidden columns
81 * @param al AlignmentI
82 * @param hiddenColumns ColumnSelection or null
84 public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
85 int width, int height)
87 this.setSize(width, height);
88 viewport = new AlignViewport(al, hiddenColumns);
90 alignPanel = new AlignmentPanel(this, viewport);
92 if(al.getDataset()==null)
97 addAlignmentPanel(alignPanel, true);
102 * Make a new AlignFrame from exisiting alignmentPanels
103 * @param ap AlignmentPanel
104 * @param av AlignViewport
106 public AlignFrame(AlignmentPanel ap)
110 addAlignmentPanel(ap, false);
116 this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
118 if (viewport.conservation == null)
120 BLOSUM62Colour.setEnabled(false);
121 conservationMenuItem.setEnabled(false);
122 modifyConservation.setEnabled(false);
123 // PIDColour.setEnabled(false);
124 // abovePIDThreshold.setEnabled(false);
125 // modifyPID.setEnabled(false);
128 String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
130 if (sortby.equals("Id"))
131 sortIDMenuItem_actionPerformed(null);
132 else if (sortby.equals("Pairwise Identity"))
133 sortPairwiseMenuItem_actionPerformed(null);
135 if (Desktop.desktop != null)
137 addServiceListeners();
138 setGUINucleotide(viewport.alignment.isNucleotide());
141 setMenusFromViewport(viewport);
143 if (viewport.wrapAlignment)
145 wrapMenuItem_actionPerformed(null);
152 public void setFileName(String file, String format)
155 currentFileFormat = format;
156 reload.setEnabled(true);
159 void addKeyListener()
161 addKeyListener(new KeyAdapter()
163 public void keyPressed(KeyEvent evt)
165 if (viewport.cursorMode
166 && evt.getKeyCode() >= KeyEvent.VK_0
167 && evt.getKeyCode() <= KeyEvent.VK_9)
169 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
172 switch (evt.getKeyCode())
175 case 27: // escape key
176 deselectAllSequenceMenuItem_actionPerformed(null);
180 case KeyEvent.VK_DOWN:
181 if (viewport.cursorMode)
183 alignPanel.seqPanel.moveCursor(0, 1);
186 moveSelectedSequences(false);
190 if (viewport.cursorMode)
192 alignPanel.seqPanel.moveCursor(0, -1);
195 moveSelectedSequences(true);
198 case KeyEvent.VK_LEFT:
199 if (viewport.cursorMode)
201 alignPanel.seqPanel.moveCursor( -1, 0);
205 case KeyEvent.VK_RIGHT:
206 if (viewport.cursorMode)
208 alignPanel.seqPanel.moveCursor(1, 0);
212 case KeyEvent.VK_SPACE:
213 if (viewport.cursorMode)
215 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
221 case KeyEvent.VK_DELETE:
222 case KeyEvent.VK_BACK_SPACE:
223 if (!viewport.cursorMode)
225 cut_actionPerformed(null);
228 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
235 if (viewport.cursorMode)
237 alignPanel.seqPanel.setCursorRow();
241 if (viewport.cursorMode && !evt.isControlDown())
243 alignPanel.seqPanel.setCursorColumn();
247 if (viewport.cursorMode)
249 alignPanel.seqPanel.setCursorPosition();
253 case KeyEvent.VK_ENTER:
254 case KeyEvent.VK_COMMA:
255 if (viewport.cursorMode)
257 alignPanel.seqPanel.setCursorRowAndColumn();
262 if (viewport.cursorMode)
264 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
268 if (viewport.cursorMode)
270 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
275 viewport.cursorMode = !viewport.cursorMode;
276 statusBar.setText("Keyboard editing mode is " +
277 (viewport.cursorMode ? "on" : "off"));
278 if (viewport.cursorMode)
280 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
281 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
283 alignPanel.seqPanel.seqCanvas.repaint();
289 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
290 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
291 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
293 javax.help.HelpBroker hb = hs.createHelpBroker();
294 hb.setCurrentID("home");
295 hb.setDisplayed(true);
299 ex.printStackTrace();
305 boolean toggleSeqs = !evt.isControlDown();
306 boolean toggleCols = !evt.isShiftDown();
308 boolean hide = false;
310 SequenceGroup sg = viewport.getSelectionGroup();
313 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
315 hideSelSequences_actionPerformed(null);
318 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
319 showAllSeqs_actionPerformed(null);
324 if (viewport.colSel.getSelected().size() > 0)
326 hideSelColumns_actionPerformed(null);
328 viewport.selectionGroup = sg;
331 showAllColumns_actionPerformed(null);
335 case KeyEvent.VK_PAGE_UP:
336 if (viewport.wrapAlignment)
337 alignPanel.scrollUp(true);
339 alignPanel.setScrollValues(viewport.startRes,
341 - viewport.endSeq + viewport.startSeq);
343 case KeyEvent.VK_PAGE_DOWN:
344 if (viewport.wrapAlignment)
345 alignPanel.scrollUp(false);
347 alignPanel.setScrollValues(viewport.startRes,
349 + viewport.endSeq - viewport.startSeq);
357 public void addAlignmentPanel(final AlignmentPanel ap,
360 ap.alignFrame = this;
362 alignPanels.addElement(ap);
364 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
366 int aSize = alignPanels.size();
368 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
370 if (aSize == 1 && ap.av.viewName==null)
372 this.getContentPane().add(ap, BorderLayout.CENTER);
378 setInitialTabVisible();
381 expandViews.setEnabled(true);
382 gatherViews.setEnabled(true);
383 tabbedPane.addTab(ap.av.viewName, ap);
385 ap.setVisible(false);
391 ap.av.alignment.padGaps();
392 ap.av.updateConservation(ap);
393 ap.av.updateConsensus(ap);
397 public void setInitialTabVisible()
399 expandViews.setEnabled(true);
400 gatherViews.setEnabled(true);
401 tabbedPane.setVisible(true);
402 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
403 tabbedPane.addTab(first.av.viewName,first);
404 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
408 public AlignViewport getViewport()
413 /* Set up intrinsic listeners for dynamically generated GUI bits. */
414 private void addServiceListeners()
416 final java.beans.PropertyChangeListener thisListener;
417 // Do this once to get current state
418 BuildWebServiceMenu();
419 Desktop.discoverer.addPropertyChangeListener(
420 thisListener = new java.beans.PropertyChangeListener()
422 public void propertyChange(PropertyChangeEvent evt)
424 // System.out.println("Discoverer property change.");
425 if (evt.getPropertyName().equals("services"))
427 // System.out.println("Rebuilding web service menu");
428 BuildWebServiceMenu();
433 addInternalFrameListener(new javax.swing.event.
434 InternalFrameAdapter()
436 public void internalFrameClosed(
437 javax.swing.event.InternalFrameEvent evt)
439 // System.out.println("deregistering discoverer listener");
440 Desktop.discoverer.removePropertyChangeListener(thisListener);
441 closeMenuItem_actionPerformed(true);
447 public void setGUINucleotide(boolean nucleotide)
449 showTranslation.setVisible( nucleotide );
450 conservationMenuItem.setEnabled( !nucleotide );
451 modifyConservation.setEnabled( !nucleotide );
453 //Remember AlignFrame always starts as protein
456 calculateMenu.remove(calculateMenu.getItemCount()-2);
461 * Need to call this method when tabs are selected for multiple views,
462 * or when loading from Jalview2XML.java
463 * @param av AlignViewport
465 void setMenusFromViewport(AlignViewport av)
467 padGapsMenuitem.setSelected(av.padGaps);
468 colourTextMenuItem.setSelected(av.showColourText);
469 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
470 conservationMenuItem.setSelected(av.getConservationSelected());
471 seqLimits.setSelected(av.getShowJVSuffix());
472 idRightAlign.setSelected(av.rightAlignIds);
473 renderGapsMenuItem.setSelected(av.renderGaps);
474 wrapMenuItem.setSelected(av.wrapAlignment);
475 annotationPanelMenuItem.setState(av.showAnnotation);
476 viewBoxesMenuItem.setSelected(av.showBoxes);
477 viewTextMenuItem.setSelected(av.showText);
479 setColourSelected(ColourSchemeProperty.
480 getColourName(av.getGlobalColourScheme()));
482 showSeqFeatures.setSelected(av.showSequenceFeatures);
483 hiddenMarkers.setState(av.showHiddenMarkers);
484 applyToAllGroups.setState(av.colourAppliesToAllGroups);
490 Hashtable progressBars;
491 public void setProgressBar(String message, long id)
493 if(progressBars == null)
494 progressBars = new Hashtable();
496 JPanel progressPanel;
497 GridLayout layout = (GridLayout) statusPanel.getLayout();
498 if(progressBars.get( new Long(id) )!=null)
500 progressPanel = (JPanel)progressBars.get( new Long(id) );
501 statusPanel.remove(progressPanel);
502 progressBars.remove( progressPanel );
503 progressPanel = null;
505 statusBar.setText(message);
507 layout.setRows(layout.getRows() - 1);
511 progressPanel = new JPanel(new BorderLayout(10, 5));
513 JProgressBar progressBar = new JProgressBar();
514 progressBar.setIndeterminate(true);
516 progressPanel.add(new JLabel(message), BorderLayout.WEST);
517 progressPanel.add(progressBar, BorderLayout.CENTER);
519 layout.setRows(layout.getRows() + 1);
520 statusPanel.add(progressPanel);
522 progressBars.put(new Long(id), progressPanel);
532 Added so Castor Mapping file can obtain Jalview Version
534 public String getVersion()
536 return jalview.bin.Cache.getProperty("VERSION");
539 public FeatureRenderer getFeatureRenderer()
541 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
545 public void fetchSequence_actionPerformed(ActionEvent e)
547 new SequenceFetcher(this);
550 public void addFromFile_actionPerformed(ActionEvent e)
552 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
555 public void reload_actionPerformed(ActionEvent e)
559 if(currentFileFormat.equals("Jalview"))
561 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
562 for(int i=0; i<frames.length; i++)
564 if (frames[i] instanceof AlignFrame
566 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
569 frames[i].setSelected(true);
570 Desktop.instance.closeAssociatedWindows();
571 }catch(java.beans.PropertyVetoException ex){}
575 Desktop.instance.closeAssociatedWindows();
580 viewport.alignment.deleteAllGroups();
581 viewport.sequenceColours=null;
582 while (viewport.alignment.getHeight() > 0)
584 viewport.alignment.deleteSequence(0);
587 viewport.historyList.clear();
588 viewport.redoList.clear();
589 Alignment dset = viewport.alignment.getDataset();
590 while (dset.getHeight() > 0)
592 dset.deleteSequence(0);
595 firePropertyChange("Alignment", null, null);
600 FileLoader loader = new FileLoader();
601 String protocol = fileName.startsWith("http:")? "URL":"File";
602 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
608 public void addFromText_actionPerformed(ActionEvent e)
610 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
613 public void addFromURL_actionPerformed(ActionEvent e)
615 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
619 public void save_actionPerformed(ActionEvent e)
621 if(fileName==null || currentFileFormat==null)
622 saveAs_actionPerformed(null);
624 saveAlignment(fileName, currentFileFormat);
630 * @param e DOCUMENT ME!
632 public void saveAs_actionPerformed(ActionEvent e)
634 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
635 getProperty( "LAST_DIRECTORY"),
637 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
639 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
644 chooser.setFileView(new JalviewFileView());
645 chooser.setDialogTitle("Save Alignment to file");
646 chooser.setToolTipText("Save");
648 int value = chooser.showSaveDialog(this);
650 if (value == JalviewFileChooser.APPROVE_OPTION)
652 currentFileFormat = chooser.getSelectedFormat();
653 if (currentFileFormat == null)
655 JOptionPane.showInternalMessageDialog(Desktop.desktop,
656 "You must select a file format before saving!",
657 "File format not specified",
658 JOptionPane.WARNING_MESSAGE);
659 value = chooser.showSaveDialog(this);
663 fileName = chooser.getSelectedFile().getPath();
665 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
668 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
670 saveAlignment(fileName, currentFileFormat);
674 public boolean saveAlignment(String file, String format)
676 if (format.equalsIgnoreCase("Jalview"))
678 String shortName = title;
680 if (shortName.indexOf(java.io.File.separatorChar) > -1)
682 shortName = shortName.substring(shortName.lastIndexOf(
683 java.io.File.separatorChar) + 1);
686 new Jalview2XML().SaveAlignment(this, file, shortName);
688 statusBar.setText("Successfully saved to file: "
690 +format +" format.");
693 // USE Jalview2XML to save this file
699 String[] omitHidden = null;
701 if (viewport.hasHiddenColumns)
703 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
704 "The Alignment contains hidden columns."
705 + "\nDo you want to save only the visible alignment?",
706 "Save / Omit Hidden Columns",
707 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
709 if (reply == JOptionPane.YES_OPTION)
710 omitHidden = viewport.getViewAsString(false);
713 String output = new FormatAdapter().formatSequences(
715 viewport.alignment.getSequencesArray(),
725 java.io.PrintWriter out = new java.io.PrintWriter(
726 new java.io.FileWriter(file));
731 statusBar.setText("Successfully saved to file: "
733 +format +" format.");
738 ex.printStackTrace();
747 * @param e DOCUMENT ME!
749 protected void outputText_actionPerformed(ActionEvent e)
751 String [] omitHidden = null;
753 if(viewport.hasHiddenColumns)
755 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
756 "The Alignment contains hidden columns."
757 +"\nDo you want to output only the visible alignment?",
758 "Save / Omit Hidden Columns",
759 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
761 if(reply==JOptionPane.YES_OPTION)
763 omitHidden = viewport.getViewAsString(false);
767 CutAndPasteTransfer cap = new CutAndPasteTransfer();
768 cap.setForInput(null);
769 Desktop.addInternalFrame(cap,
770 "Alignment output - " + e.getActionCommand(), 600,
774 cap.setText(new FormatAdapter().formatSequences(
775 e.getActionCommand(),
776 viewport.alignment.getSequencesArray(),
783 * @param e DOCUMENT ME!
785 protected void htmlMenuItem_actionPerformed(ActionEvent e)
787 new HTMLOutput(viewport,
788 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
789 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
792 public void createImageMap(File file, String image)
794 alignPanel.makePNGImageMap(file, image);
800 * @param e DOCUMENT ME!
802 public void createPNG(File f)
804 alignPanel.makePNG(f);
810 * @param e DOCUMENT ME!
812 public void createEPS(File f)
814 alignPanel.makeEPS(f);
820 * @param e DOCUMENT ME!
822 public void printMenuItem_actionPerformed(ActionEvent e)
824 //Putting in a thread avoids Swing painting problems
825 PrintThread thread = new PrintThread();
829 public void exportFeatures_actionPerformed(ActionEvent e)
831 new AnnotationExporter().exportFeatures(alignPanel);
835 public void exportAnnotations_actionPerformed(ActionEvent e)
837 new AnnotationExporter().exportAnnotations(
839 viewport.alignment.getAlignmentAnnotation()
844 public void associatedData_actionPerformed(ActionEvent e)
846 // Pick the tree file
847 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
850 chooser.setFileView(new JalviewFileView());
851 chooser.setDialogTitle("Load Jalview Annotations or Features File");
852 chooser.setToolTipText("Load Jalview Annotations / Features file");
854 int value = chooser.showOpenDialog(null);
856 if (value == JalviewFileChooser.APPROVE_OPTION)
858 String choice = chooser.getSelectedFile().getPath();
859 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
860 loadJalviewDataFile(choice);
869 * @param e DOCUMENT ME!
871 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
873 if(alignPanels!=null && alignPanels.size()<2)
878 if(alignPanels!=null)
881 for (int i = 0; i < alignPanels.size(); i++)
883 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
884 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
885 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
886 PaintRefresher.RemoveComponent(ap);
890 int index = tabbedPane.getSelectedIndex();
892 alignPanels.removeElement(alignPanel);
893 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
894 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
895 PaintRefresher.RemoveComponent(alignPanel);
899 tabbedPane.removeTabAt(index);
900 tabbedPane.validate();
902 if(index==tabbedPane.getTabCount())
905 this.tabSelectionChanged(index);
910 this.setClosed(true);
914 ex.printStackTrace();
922 void updateEditMenuBar()
925 if (viewport.historyList.size() > 0)
927 undoMenuItem.setEnabled(true);
928 CommandI command = (CommandI) viewport.historyList.peek();
929 undoMenuItem.setText("Undo " + command.getDescription());
933 undoMenuItem.setEnabled(false);
934 undoMenuItem.setText("Undo");
937 if (viewport.redoList.size() > 0)
939 redoMenuItem.setEnabled(true);
941 CommandI command = (CommandI) viewport.redoList.peek();
942 redoMenuItem.setText("Redo " + command.getDescription());
946 redoMenuItem.setEnabled(false);
947 redoMenuItem.setText("Redo");
952 public void addHistoryItem(CommandI command)
954 if(command.getSize()>0)
956 viewport.historyList.push(command);
957 viewport.redoList.clear();
959 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
968 * @param e DOCUMENT ME!
970 protected void undoMenuItem_actionPerformed(ActionEvent e)
972 CommandI command = (CommandI)viewport.historyList.pop();
973 viewport.redoList.push(command);
974 command.undoCommand();
976 AlignViewport originalSource = getOriginatingSource(command);
979 if(originalSource!=null)
981 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
982 originalSource.firePropertyChange("alignment", null,null);
989 * @param e DOCUMENT ME!
991 protected void redoMenuItem_actionPerformed(ActionEvent e)
993 CommandI command = (CommandI) viewport.redoList.pop();
994 viewport.historyList.push(command);
997 AlignViewport originalSource = getOriginatingSource(command);
1000 if(originalSource!=null)
1002 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1003 originalSource.firePropertyChange("alignment", null,null);
1007 AlignViewport getOriginatingSource(CommandI command)
1009 AlignViewport originalSource = null;
1010 //For sequence removal and addition, we need to fire
1011 //the property change event FROM the viewport where the
1012 //original alignment was altered
1013 if (command instanceof EditCommand)
1015 EditCommand editCommand = (EditCommand) command;
1016 AlignmentI al = editCommand.getAlignment();
1017 Vector comps = (Vector) PaintRefresher.components
1018 .get(viewport.getSequenceSetId());
1020 for (int i = 0; i < comps.size(); i++)
1022 if (comps.elementAt(i) instanceof AlignmentPanel)
1024 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1026 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1031 if (originalSource == null)
1033 //The original view is closed, we must validate
1034 //the current view against the closed view first
1036 PaintRefresher.validateSequences(al, viewport.alignment);
1038 originalSource = viewport;
1044 return originalSource;
1050 * @param up DOCUMENT ME!
1052 public void moveSelectedSequences(boolean up)
1054 SequenceGroup sg = viewport.getSelectionGroup();
1063 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1065 SequenceI seq = viewport.alignment.getSequenceAt(i);
1067 if (!sg.getSequences(false).contains(seq))
1072 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1074 if (sg.getSequences(false).contains(temp))
1079 viewport.alignment.getSequences().setElementAt(temp, i);
1080 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1085 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1087 SequenceI seq = viewport.alignment.getSequenceAt(i);
1089 if (!sg.getSequences(false).contains(seq))
1094 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1096 if (sg.getSequences(false).contains(temp))
1101 viewport.alignment.getSequences().setElementAt(temp, i);
1102 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1106 alignPanel.repaint();
1114 * @param e DOCUMENT ME!
1116 protected void copy_actionPerformed(ActionEvent e)
1119 if (viewport.getSelectionGroup() == null)
1124 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1125 String[] omitHidden = null;
1127 if (viewport.hasHiddenColumns)
1129 omitHidden = viewport.getViewAsString(true);
1132 String output = new FormatAdapter().formatSequences(
1137 StringSelection ss = new StringSelection(output);
1141 //Its really worth setting the clipboard contents
1142 //to empty before setting the large StringSelection!!
1143 Toolkit.getDefaultToolkit().getSystemClipboard()
1144 .setContents(new StringSelection(""), null);
1146 Toolkit.getDefaultToolkit().getSystemClipboard()
1147 .setContents(ss, Desktop.instance);
1149 catch (OutOfMemoryError er)
1151 er.printStackTrace();
1152 javax.swing.SwingUtilities.invokeLater(new Runnable()
1156 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1157 "Out of memory copying region!!"
1159 "\nSee help files for increasing Java Virtual Machine memory."
1161 javax.swing.JOptionPane.WARNING_MESSAGE);
1168 Vector hiddenColumns = null;
1169 if(viewport.hasHiddenColumns)
1171 hiddenColumns =new Vector();
1172 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1173 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1175 int[] region = (int[])
1176 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1178 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1179 region[1]-hiddenOffset});
1185 Desktop.jalviewClipboard = new Object[]{ seqs,
1186 viewport.alignment.getDataset(),
1188 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1194 * @param e DOCUMENT ME!
1196 protected void pasteNew_actionPerformed(ActionEvent e)
1204 * @param e DOCUMENT ME!
1206 protected void pasteThis_actionPerformed(ActionEvent e)
1214 * @param newAlignment DOCUMENT ME!
1216 void paste(boolean newAlignment)
1220 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1221 Transferable contents = c.getContents(this);
1223 if (contents == null)
1231 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1232 if (str.length() < 1)
1235 format = new IdentifyFile().Identify(str, "Paste");
1238 catch (OutOfMemoryError er)
1240 er.printStackTrace();
1241 javax.swing.SwingUtilities.invokeLater(new Runnable()
1245 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1246 "Out of memory pasting sequences!!"
1248 "\nSee help files for increasing Java Virtual Machine memory."
1250 javax.swing.JOptionPane.WARNING_MESSAGE);
1257 SequenceI[] sequences;
1260 if(Desktop.jalviewClipboard!=null)
1262 // The clipboard was filled from within Jalview, we must use the sequences
1263 // And dataset from the copied alignment
1264 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1268 sequences = new FormatAdapter().readFile(str, "Paste", format);
1271 AlignmentI alignment = null;
1275 alignment = new Alignment(sequences);
1277 if (Desktop.jalviewClipboard != null)
1278 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1280 alignment.setDataset(null);
1284 alignment = viewport.getAlignment();
1287 SequenceI [] newseqs = new SequenceI[sequences.length];
1288 for (int i = 0; i < sequences.length; i++)
1290 newseqs[i] = new Sequence(sequences[i].getName(),
1291 sequences[i].getSequence(), sequences[i].getStart(),
1292 sequences[i].getEnd());
1294 alignment.addSequence(newseqs[i]);
1300 addHistoryItem(new EditCommand(
1305 alignment.getWidth(),
1310 viewport.setEndSeq(alignment.getHeight());
1311 alignment.getWidth();
1312 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1317 // Add any annotations attached to sequences
1318 for (int i = 0; i < sequences.length; i++)
1320 if (sequences[i].getAnnotation() != null)
1322 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1324 AlignmentAnnotation newAnnot =
1325 new AlignmentAnnotation(
1326 sequences[i].getAnnotation()[a].label,
1327 sequences[i].getAnnotation()[a].description,
1328 sequences[i].getAnnotation()[a].annotations,
1329 sequences[i].getAnnotation()[a].graphMin,
1330 sequences[i].getAnnotation()[a].graphMax,
1331 sequences[i].getAnnotation()[a].graph);
1333 sequences[i].getAnnotation()[a] = newAnnot;
1334 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1336 newAnnot.sequenceRef = sequences[i];
1337 newAnnot.adjustForAlignment();
1338 alignment.addAnnotation(newAnnot);
1339 alignment.setAnnotationIndex(newAnnot, a);
1342 alignPanel.annotationPanel.adjustPanelHeight();
1348 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1349 String newtitle = new String("Copied sequences");
1351 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1353 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1354 for(int i=0; i<hc.size(); i++)
1356 int [] region = (int[]) hc.elementAt(i);
1357 af.viewport.hideColumns(region[0], region[1]);
1362 //>>>This is a fix for the moment, until a better solution is found!!<<<
1363 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1364 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1367 if (title.startsWith("Copied sequences"))
1373 newtitle = newtitle.concat("- from " + title);
1376 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1383 catch (Exception ex)
1385 ex.printStackTrace();
1386 System.out.println("Exception whilst pasting: "+ex);
1387 // could be anything being pasted in here
1396 * @param e DOCUMENT ME!
1398 protected void cut_actionPerformed(ActionEvent e)
1400 copy_actionPerformed(null);
1401 delete_actionPerformed(null);
1407 * @param e DOCUMENT ME!
1409 protected void delete_actionPerformed(ActionEvent evt)
1412 SequenceGroup sg = viewport.getSelectionGroup();
1418 Vector seqs = new Vector();
1420 for (int i = 0; i < sg.getSize(false); i++)
1422 seq = sg.getSequenceAt(i);
1423 seqs.addElement(seq);
1427 // If the cut affects all sequences, remove highlighted columns
1428 if (sg.getSize(false) == viewport.alignment.getHeight())
1430 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1431 sg.getEndRes() + 1);
1435 SequenceI [] cut = new SequenceI[seqs.size()];
1436 for(int i=0; i<seqs.size(); i++)
1437 cut[i] = (SequenceI)seqs.elementAt(i);
1443 addHistoryItem(new EditCommand("Cut Sequences",
1447 sg.getEndRes()-sg.getStartRes()+1,
1448 viewport.alignment));
1451 viewport.setSelectionGroup(null);
1452 viewport.alignment.deleteGroup(sg);
1454 viewport.firePropertyChange("alignment", null,
1455 viewport.getAlignment().getSequences());
1457 if (viewport.getAlignment().getHeight() < 1)
1461 this.setClosed(true);
1463 catch (Exception ex)
1472 * @param e DOCUMENT ME!
1474 protected void deleteGroups_actionPerformed(ActionEvent e)
1476 viewport.alignment.deleteAllGroups();
1477 viewport.sequenceColours.clear();
1478 viewport.setSelectionGroup(null);
1479 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1480 alignPanel.repaint();
1486 * @param e DOCUMENT ME!
1488 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1490 SequenceGroup sg = new SequenceGroup();
1492 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1495 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1498 sg.setEndRes(viewport.alignment.getWidth() - 1);
1499 viewport.setSelectionGroup(sg);
1500 alignPanel.repaint();
1501 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1507 * @param e DOCUMENT ME!
1509 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1511 if(viewport.cursorMode)
1513 alignPanel.seqPanel.keyboardNo1 = null;
1514 alignPanel.seqPanel.keyboardNo2 = null;
1516 viewport.setSelectionGroup(null);
1517 viewport.getColumnSelection().clear();
1518 viewport.setSelectionGroup(null);
1519 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1520 alignPanel.idPanel.idCanvas.searchResults = null;
1521 alignPanel.repaint();
1522 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1528 * @param e DOCUMENT ME!
1530 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1532 SequenceGroup sg = viewport.getSelectionGroup();
1536 selectAllSequenceMenuItem_actionPerformed(null);
1541 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1544 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1547 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1550 public void invertColSel_actionPerformed(ActionEvent e)
1552 viewport.invertColumnSelection();
1553 alignPanel.repaint();
1560 * @param e DOCUMENT ME!
1562 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1564 trimAlignment(true);
1570 * @param e DOCUMENT ME!
1572 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1574 trimAlignment(false);
1577 void trimAlignment(boolean trimLeft)
1579 ColumnSelection colSel = viewport.getColumnSelection();
1582 if (colSel.size() > 0)
1585 column = colSel.getMin();
1587 column = colSel.getMax();
1590 if(viewport.getSelectionGroup()!=null)
1591 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1593 seqs = viewport.alignment.getSequencesArray();
1596 TrimRegionCommand trimRegion;
1599 trimRegion = new TrimRegionCommand("Remove Left",
1600 TrimRegionCommand.TRIM_LEFT,
1605 viewport.selectionGroup);
1606 viewport.setStartRes(0);
1610 trimRegion = new TrimRegionCommand("Remove Right",
1611 TrimRegionCommand.TRIM_RIGHT,
1616 viewport.selectionGroup);
1619 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1622 addHistoryItem(trimRegion);
1624 Vector groups = viewport.alignment.getGroups();
1626 for (int i = 0; i < groups.size(); i++)
1628 SequenceGroup sg = (SequenceGroup) groups.get(i);
1630 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1631 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1633 viewport.alignment.deleteGroup(sg);
1637 viewport.firePropertyChange("alignment", null,
1638 viewport.getAlignment().getSequences());
1645 * @param e DOCUMENT ME!
1647 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1649 int start = 0, end = viewport.alignment.getWidth()-1;
1652 if (viewport.getSelectionGroup() != null)
1654 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1655 start = viewport.getSelectionGroup().getStartRes();
1656 end = viewport.getSelectionGroup().getEndRes();
1659 seqs = viewport.alignment.getSequencesArray();
1662 RemoveGapColCommand removeGapCols =
1663 new RemoveGapColCommand("Remove Gapped Columns",
1666 viewport.getGapCharacter());
1668 addHistoryItem(removeGapCols);
1670 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1672 //This is to maintain viewport position on first residue
1674 SequenceI seq = viewport.alignment.getSequenceAt(0);
1675 int startRes = seq.findPosition(viewport.startRes);
1676 // ShiftList shifts;
1677 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1678 // edit.alColumnChanges=shifts.getInverse();
1679 // if (viewport.hasHiddenColumns)
1680 // viewport.getColumnSelection().compensateForEdits(shifts);
1681 viewport.setStartRes(seq.findIndex(startRes)-1);
1682 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1689 * @param e DOCUMENT ME!
1691 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1693 int start = 0, end = viewport.alignment.getWidth()-1;
1696 if (viewport.getSelectionGroup() != null)
1698 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1699 start = viewport.getSelectionGroup().getStartRes();
1700 end = viewport.getSelectionGroup().getEndRes();
1703 seqs = viewport.alignment.getSequencesArray();
1705 //This is to maintain viewport position on first residue
1707 SequenceI seq = viewport.alignment.getSequenceAt(0);
1708 int startRes = seq.findPosition(viewport.startRes);
1710 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1713 viewport.getGapCharacter()));
1715 viewport.setStartRes(seq.findIndex(startRes)-1);
1717 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1724 * @param e DOCUMENT ME!
1726 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1728 viewport.padGaps = padGapsMenuitem.isSelected();
1730 viewport.firePropertyChange("alignment",
1732 viewport.getAlignment().getSequences());
1738 * @param e DOCUMENT ME!
1740 public void findMenuItem_actionPerformed(ActionEvent e)
1745 public void newView_actionPerformed(ActionEvent e)
1747 AlignmentPanel newap =
1748 new Jalview2XML().copyAlignPanel(alignPanel, true);
1750 if (viewport.viewName == null)
1751 viewport.viewName = "Original";
1753 newap.av.historyList = viewport.historyList;
1754 newap.av.redoList = viewport.redoList;
1756 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1757 String newViewName = "View " +index;
1759 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
1760 Vector existingNames = new Vector();
1761 for(int i=0; i<comps.size(); i++)
1763 if(comps.elementAt(i) instanceof AlignmentPanel)
1765 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
1766 if(!existingNames.contains(ap.av.viewName))
1767 existingNames.addElement(ap.av.viewName);
1771 while(existingNames.contains(newViewName))
1773 newViewName = "View "+ (++index);
1776 newap.av.viewName = newViewName;
1778 addAlignmentPanel(newap, false);
1780 if(alignPanels.size()==2)
1782 viewport.gatherViewsHere = true;
1784 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1787 public void expandViews_actionPerformed(ActionEvent e)
1789 Desktop.instance.explodeViews(this);
1792 public void gatherViews_actionPerformed(ActionEvent e)
1794 Desktop.instance.gatherViews(this);
1802 * @param e DOCUMENT ME!
1804 public void font_actionPerformed(ActionEvent e)
1806 new FontChooser(alignPanel);
1813 * @param e DOCUMENT ME!
1815 protected void seqLimit_actionPerformed(ActionEvent e)
1817 viewport.setShowJVSuffix(seqLimits.isSelected());
1819 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1820 alignPanel.repaint();
1823 public void idRightAlign_actionPerformed(ActionEvent e)
1825 viewport.rightAlignIds = idRightAlign.isSelected();
1826 alignPanel.repaint();
1834 * @param e DOCUMENT ME!
1836 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1838 viewport.setColourText(colourTextMenuItem.isSelected());
1839 alignPanel.repaint();
1845 * @param e DOCUMENT ME!
1847 public void wrapMenuItem_actionPerformed(ActionEvent e)
1849 scaleAbove.setVisible(wrapMenuItem.isSelected());
1850 scaleLeft.setVisible(wrapMenuItem.isSelected());
1851 scaleRight.setVisible(wrapMenuItem.isSelected());
1852 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1853 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1856 public void showAllSeqs_actionPerformed(ActionEvent e)
1858 viewport.showAllHiddenSeqs();
1861 public void showAllColumns_actionPerformed(ActionEvent e)
1863 viewport.showAllHiddenColumns();
1867 public void hideSelSequences_actionPerformed(ActionEvent e)
1869 viewport.hideAllSelectedSeqs();
1870 alignPanel.repaint();
1873 public void hideSelColumns_actionPerformed(ActionEvent e)
1875 viewport.hideSelectedColumns();
1876 alignPanel.repaint();
1879 public void hiddenMarkers_actionPerformed(ActionEvent e)
1881 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1888 * @param e DOCUMENT ME!
1890 protected void scaleAbove_actionPerformed(ActionEvent e)
1892 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1893 alignPanel.repaint();
1899 * @param e DOCUMENT ME!
1901 protected void scaleLeft_actionPerformed(ActionEvent e)
1903 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1904 alignPanel.repaint();
1910 * @param e DOCUMENT ME!
1912 protected void scaleRight_actionPerformed(ActionEvent e)
1914 viewport.setScaleRightWrapped(scaleRight.isSelected());
1915 alignPanel.repaint();
1921 * @param e DOCUMENT ME!
1923 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1925 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1926 alignPanel.repaint();
1932 * @param e DOCUMENT ME!
1934 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1936 viewport.setShowText(viewTextMenuItem.isSelected());
1937 alignPanel.repaint();
1943 * @param e DOCUMENT ME!
1945 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1947 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1948 alignPanel.repaint();
1952 public FeatureSettings featureSettings;
1953 public void featureSettings_actionPerformed(ActionEvent e)
1955 if(featureSettings !=null )
1957 featureSettings.close();
1958 featureSettings = null;
1960 featureSettings = new FeatureSettings(this);
1966 * @param evt DOCUMENT ME!
1968 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1970 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1971 alignPanel.repaint();
1972 if (alignPanel.getOverviewPanel() != null)
1974 alignPanel.getOverviewPanel().updateOverviewImage();
1981 * @param e DOCUMENT ME!
1983 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1985 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1986 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1992 * @param e DOCUMENT ME!
1994 public void overviewMenuItem_actionPerformed(ActionEvent e)
1996 if (alignPanel.overviewPanel != null)
2001 JInternalFrame frame = new JInternalFrame();
2002 OverviewPanel overview = new OverviewPanel(alignPanel);
2003 frame.setContentPane(overview);
2004 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2005 frame.getWidth(), frame.getHeight());
2007 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2008 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2010 public void internalFrameClosed(
2011 javax.swing.event.InternalFrameEvent evt)
2013 alignPanel.setOverviewPanel(null);
2018 alignPanel.setOverviewPanel(overview);
2021 public void textColour_actionPerformed(ActionEvent e)
2023 new TextColourChooser().chooseColour(alignPanel, null);
2029 * @param e DOCUMENT ME!
2031 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2039 * @param e DOCUMENT ME!
2041 public void clustalColour_actionPerformed(ActionEvent e)
2043 changeColour(new ClustalxColourScheme(
2044 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2050 * @param e DOCUMENT ME!
2052 public void zappoColour_actionPerformed(ActionEvent e)
2054 changeColour(new ZappoColourScheme());
2060 * @param e DOCUMENT ME!
2062 public void taylorColour_actionPerformed(ActionEvent e)
2064 changeColour(new TaylorColourScheme());
2070 * @param e DOCUMENT ME!
2072 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2074 changeColour(new HydrophobicColourScheme());
2080 * @param e DOCUMENT ME!
2082 public void helixColour_actionPerformed(ActionEvent e)
2084 changeColour(new HelixColourScheme());
2090 * @param e DOCUMENT ME!
2092 public void strandColour_actionPerformed(ActionEvent e)
2094 changeColour(new StrandColourScheme());
2100 * @param e DOCUMENT ME!
2102 public void turnColour_actionPerformed(ActionEvent e)
2104 changeColour(new TurnColourScheme());
2110 * @param e DOCUMENT ME!
2112 public void buriedColour_actionPerformed(ActionEvent e)
2114 changeColour(new BuriedColourScheme());
2120 * @param e DOCUMENT ME!
2122 public void nucleotideColour_actionPerformed(ActionEvent e)
2124 changeColour(new NucleotideColourScheme());
2127 public void annotationColour_actionPerformed(ActionEvent e)
2129 new AnnotationColourChooser(viewport, alignPanel);
2136 * @param e DOCUMENT ME!
2138 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2140 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2146 * @param cs DOCUMENT ME!
2148 public void changeColour(ColourSchemeI cs)
2154 if (viewport.getAbovePIDThreshold())
2156 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2159 cs.setThreshold(threshold,
2160 viewport.getIgnoreGapsConsensus());
2162 viewport.setGlobalColourScheme(cs);
2166 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2169 if (viewport.getConservationSelected())
2172 Alignment al = (Alignment) viewport.alignment;
2173 Conservation c = new Conservation("All",
2174 ResidueProperties.propHash, 3,
2175 al.getSequences(), 0,
2179 c.verdict(false, viewport.ConsPercGaps);
2181 cs.setConservation(c);
2183 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2188 cs.setConservation(null);
2191 cs.setConsensus(viewport.hconsensus);
2194 viewport.setGlobalColourScheme(cs);
2196 if (viewport.getColourAppliesToAllGroups())
2198 Vector groups = viewport.alignment.getGroups();
2200 for (int i = 0; i < groups.size(); i++)
2202 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2210 if (cs instanceof ClustalxColourScheme)
2212 sg.cs = new ClustalxColourScheme(
2213 sg.getSequences(true), sg.getWidth());
2215 else if (cs instanceof UserColourScheme)
2217 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2223 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2225 catch (Exception ex)
2230 if (viewport.getAbovePIDThreshold()
2231 || cs instanceof PIDColourScheme
2232 || cs instanceof Blosum62ColourScheme)
2234 sg.cs.setThreshold(threshold,
2235 viewport.getIgnoreGapsConsensus());
2237 sg.cs.setConsensus(AAFrequency.calculate(
2238 sg.getSequences(true), sg.getStartRes(),
2242 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2245 if (viewport.getConservationSelected())
2247 Conservation c = new Conservation("Group",
2248 ResidueProperties.propHash, 3,
2249 sg.getSequences(true),
2253 c.verdict(false, viewport.ConsPercGaps);
2254 sg.cs.setConservation(c);
2257 sg.cs.setConservation(null);
2261 if (alignPanel.getOverviewPanel() != null)
2263 alignPanel.getOverviewPanel().updateOverviewImage();
2266 alignPanel.repaint();
2272 * @param e DOCUMENT ME!
2274 protected void modifyPID_actionPerformed(ActionEvent e)
2276 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2278 SliderPanel.setPIDSliderSource(alignPanel,
2279 viewport.getGlobalColourScheme(),
2281 SliderPanel.showPIDSlider();
2288 * @param e DOCUMENT ME!
2290 protected void modifyConservation_actionPerformed(ActionEvent e)
2292 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2294 SliderPanel.setConservationSlider(alignPanel,
2295 viewport.globalColourScheme,
2297 SliderPanel.showConservationSlider();
2304 * @param e DOCUMENT ME!
2306 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2308 viewport.setConservationSelected(conservationMenuItem.isSelected());
2310 viewport.setAbovePIDThreshold(false);
2311 abovePIDThreshold.setSelected(false);
2313 changeColour(viewport.getGlobalColourScheme());
2315 modifyConservation_actionPerformed(null);
2321 * @param e DOCUMENT ME!
2323 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2325 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2327 conservationMenuItem.setSelected(false);
2328 viewport.setConservationSelected(false);
2330 changeColour(viewport.getGlobalColourScheme());
2332 modifyPID_actionPerformed(null);
2338 * @param e DOCUMENT ME!
2340 public void userDefinedColour_actionPerformed(ActionEvent e)
2342 if (e.getActionCommand().equals("User Defined..."))
2344 new UserDefinedColours(alignPanel, null);
2348 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2349 getUserColourSchemes().get(e.getActionCommand());
2355 public void updateUserColourMenu()
2358 Component[] menuItems = colourMenu.getMenuComponents();
2359 int i, iSize = menuItems.length;
2360 for (i = 0; i < iSize; i++)
2362 if (menuItems[i].getName() != null &&
2363 menuItems[i].getName().equals("USER_DEFINED"))
2365 colourMenu.remove(menuItems[i]);
2369 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2371 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2372 getUserColourSchemes().keys();
2374 while (userColours.hasMoreElements())
2376 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2377 nextElement().toString());
2378 radioItem.setName("USER_DEFINED");
2379 radioItem.addMouseListener(new MouseAdapter()
2381 public void mousePressed(MouseEvent evt)
2383 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2385 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2387 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2388 "Remove from default list?",
2389 "Remove user defined colour",
2390 JOptionPane.YES_NO_OPTION);
2391 if(option == JOptionPane.YES_OPTION)
2393 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2394 colourMenu.remove(radioItem);
2397 radioItem.addActionListener(new ActionListener()
2399 public void actionPerformed(ActionEvent evt)
2401 userDefinedColour_actionPerformed(evt);
2407 radioItem.addActionListener(new ActionListener()
2409 public void actionPerformed(ActionEvent evt)
2411 userDefinedColour_actionPerformed(evt);
2415 colourMenu.insert(radioItem, 15);
2416 colours.add(radioItem);
2424 * @param e DOCUMENT ME!
2426 public void PIDColour_actionPerformed(ActionEvent e)
2428 changeColour(new PIDColourScheme());
2434 * @param e DOCUMENT ME!
2436 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2438 changeColour(new Blosum62ColourScheme());
2444 * @param e DOCUMENT ME!
2446 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2448 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2449 AlignmentSorter.sortByPID(viewport.getAlignment(),
2450 viewport.getAlignment().getSequenceAt(0));
2451 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2452 alignPanel.repaint();
2458 * @param e DOCUMENT ME!
2460 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2462 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2463 AlignmentSorter.sortByID(viewport.getAlignment());
2464 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2465 alignPanel.repaint();
2471 * @param e DOCUMENT ME!
2473 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2475 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2476 AlignmentSorter.sortByGroup(viewport.getAlignment());
2477 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2479 alignPanel.repaint();
2485 * @param e DOCUMENT ME!
2487 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2489 new RedundancyPanel(alignPanel, this);
2496 * @param e DOCUMENT ME!
2498 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2500 if ( (viewport.getSelectionGroup() == null) ||
2501 (viewport.getSelectionGroup().getSize(false) < 2))
2503 JOptionPane.showInternalMessageDialog(this,
2504 "You must select at least 2 sequences.",
2505 "Invalid Selection",
2506 JOptionPane.WARNING_MESSAGE);
2510 JInternalFrame frame = new JInternalFrame();
2511 frame.setContentPane(new PairwiseAlignPanel(viewport));
2512 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2519 * @param e DOCUMENT ME!
2521 public void PCAMenuItem_actionPerformed(ActionEvent e)
2523 if ( ( (viewport.getSelectionGroup() != null) &&
2524 (viewport.getSelectionGroup().getSize(false) < 4) &&
2525 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2526 (viewport.getAlignment().getHeight() < 4))
2528 JOptionPane.showInternalMessageDialog(this,
2529 "Principal component analysis must take\n" +
2530 "at least 4 input sequences.",
2531 "Sequence selection insufficient",
2532 JOptionPane.WARNING_MESSAGE);
2537 new PCAPanel(alignPanel);
2541 public void autoCalculate_actionPerformed(ActionEvent e)
2543 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2544 if(viewport.autoCalculateConsensus)
2546 viewport.firePropertyChange("alignment",
2548 viewport.getAlignment().getSequences());
2556 * @param e DOCUMENT ME!
2558 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2560 NewTreePanel("AV", "PID", "Average distance tree using PID");
2566 * @param e DOCUMENT ME!
2568 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2570 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2576 * @param e DOCUMENT ME!
2578 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2580 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2586 * @param e DOCUMENT ME!
2588 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2590 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2596 * @param type DOCUMENT ME!
2597 * @param pwType DOCUMENT ME!
2598 * @param title DOCUMENT ME!
2600 void NewTreePanel(String type, String pwType, String title)
2604 if (viewport.getSelectionGroup() != null) {
2605 if (viewport.getSelectionGroup().getSize(false) < 3) {
2606 JOptionPane.showMessageDialog(Desktop.desktop,
2607 "You need to have more than two sequences selected to build a tree!",
2608 "Not enough sequences",
2609 JOptionPane.WARNING_MESSAGE);
2614 SequenceGroup sg = viewport.getSelectionGroup();
2616 /* Decide if the selection is a column region */
2617 while (s < sg.getSize(false))
2619 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2622 JOptionPane.showMessageDialog(Desktop.desktop,
2623 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2624 "Try using the Pad function in the edit menu,\n" +
2625 "or one of the multiple sequence alignment web services.",
2626 "Sequences in selection are not aligned",
2627 JOptionPane.WARNING_MESSAGE);
2633 title = title + " on region";
2634 tp = new TreePanel(alignPanel, type, pwType);
2638 //are the sequences aligned?
2639 if (!viewport.alignment.isAligned())
2641 JOptionPane.showMessageDialog(Desktop.desktop,
2642 "The sequences must be aligned before creating a tree.\n" +
2643 "Try using the Pad function in the edit menu,\n" +
2644 "or one of the multiple sequence alignment web services.",
2645 "Sequences not aligned",
2646 JOptionPane.WARNING_MESSAGE);
2651 if(viewport.alignment.getHeight()<2)
2654 tp = new TreePanel(alignPanel, type, pwType);
2657 title = title + " from " + this.title;
2658 if(viewport.viewName!=null)
2659 title+= " ("+viewport.viewName+")";
2661 Desktop.addInternalFrame(tp, title, 600, 500);
2667 * @param title DOCUMENT ME!
2668 * @param order DOCUMENT ME!
2670 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2672 final JMenuItem item = new JMenuItem("by " + title);
2674 item.addActionListener(new java.awt.event.ActionListener()
2676 public void actionPerformed(ActionEvent e)
2678 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2680 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2681 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2683 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2685 alignPanel.repaint();
2691 * Maintain the Order by->Displayed Tree menu.
2692 * Creates a new menu item for a TreePanel with an appropriate
2693 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2694 * to remove the menu item when the treePanel is closed, and adjust
2695 * the tree leaf to sequence mapping when the alignment is modified.
2696 * @param treePanel Displayed tree window.
2697 * @param title SortBy menu item title.
2699 public void buildTreeMenu()
2701 sortByTreeMenu.removeAll();
2703 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
2704 Vector treePanels = new Vector();
2705 int i, iSize = comps.size();
2706 for(i=0; i<iSize; i++)
2708 if(comps.elementAt(i) instanceof TreePanel)
2710 treePanels.add(comps.elementAt(i));
2714 iSize = treePanels.size();
2718 sortByTreeMenu.setVisible(false);
2722 sortByTreeMenu.setVisible(true);
2724 for(i=0; i<treePanels.size(); i++)
2726 TreePanel tp = (TreePanel)treePanels.elementAt(i);
2727 final JMenuItem item = new JMenuItem(tp.getTitle());
2728 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
2729 item.addActionListener(new java.awt.event.ActionListener()
2731 public void actionPerformed(ActionEvent e)
2733 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2734 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
2736 addHistoryItem(new OrderCommand("Tree Sort",
2738 viewport.alignment));
2740 alignPanel.repaint();
2744 sortByTreeMenu.add(item);
2749 * Work out whether the whole set of sequences
2750 * or just the selected set will be submitted for multiple alignment.
2753 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2755 // Now, check we have enough sequences
2756 AlignmentView msa = null;
2758 if ( (viewport.getSelectionGroup() != null) &&
2759 (viewport.getSelectionGroup().getSize(false) > 1))
2761 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2762 /*SequenceGroup seqs = viewport.getSelectionGroup();
2764 msa = new SequenceI[sz = seqs.getSize(false)];
2766 for (int i = 0; i < sz; i++)
2768 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2770 msa = viewport.getAlignmentView(true);
2774 /*Vector seqs = viewport.getAlignment().getSequences();
2776 if (seqs.size() > 1)
2778 msa = new SequenceI[seqs.size()];
2780 for (int i = 0; i < seqs.size(); i++)
2782 msa[i] = (SequenceI) seqs.elementAt(i);
2785 msa = viewport.getAlignmentView(false);
2791 * Decides what is submitted to a secondary structure prediction service,
2792 * the currently selected sequence, or the currently selected alignment
2793 * (where the first sequence in the set is the one that the prediction
2796 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2798 AlignmentView seqs = null;
2800 if ( (viewport.getSelectionGroup() != null) &&
2801 (viewport.getSelectionGroup().getSize(false) > 0))
2803 seqs = viewport.getAlignmentView(true);
2807 seqs = viewport.getAlignmentView(false);
2809 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2810 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2811 if (!viewport.alignment.isAligned())
2813 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2820 * @param e DOCUMENT ME!
2822 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2824 // Pick the tree file
2825 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2828 chooser.setFileView(new JalviewFileView());
2829 chooser.setDialogTitle("Select a newick-like tree file");
2830 chooser.setToolTipText("Load a tree file");
2832 int value = chooser.showOpenDialog(null);
2834 if (value == JalviewFileChooser.APPROVE_OPTION)
2836 String choice = chooser.getSelectedFile().getPath();
2837 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2841 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2843 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2845 catch (Exception ex)
2847 JOptionPane.showMessageDialog(Desktop.desktop,
2848 "Problem reading tree file",
2850 JOptionPane.WARNING_MESSAGE);
2851 ex.printStackTrace();
2857 public TreePanel ShowNewickTree(NewickFile nf, String title)
2859 return ShowNewickTree(nf,title,600,500,4,5);
2861 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2863 return ShowNewickTree(nf,title, input, 600,500,4,5);
2865 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2866 return ShowNewickTree(nf, title, null, w, h, x, y);
2869 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2871 * @param nf the tree
2872 * @param title tree viewer title
2873 * @param input Associated alignment input data (or null)
2878 * @return TreePanel handle
2880 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2881 TreePanel tp = null;
2887 if (nf.getTree() != null)
2889 tp = new TreePanel(alignPanel,
2897 tp.setLocation(x,y);
2900 Desktop.addInternalFrame(tp, title, w, h);
2903 catch (Exception ex)
2905 ex.printStackTrace();
2916 PrinterJob printJob = PrinterJob.getPrinterJob();
2917 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2918 printJob.setPrintable(alignPanel, pf);
2920 if (printJob.printDialog())
2926 catch (Exception PrintException)
2928 PrintException.printStackTrace();
2935 * Generates menu items and listener event actions for web service clients
2938 public void BuildWebServiceMenu()
2940 if ( (Discoverer.services != null)
2941 && (Discoverer.services.size() > 0))
2943 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2944 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2945 Vector wsmenu = new Vector();
2946 final AlignFrame af = this;
2949 // Add any Multiple Sequence Alignment Services
2950 final JMenu msawsmenu = new JMenu("Alignment");
2951 for (int i = 0, j = msaws.size(); i < j; i++)
2953 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2955 final JMenuItem method = new JMenuItem(sh.getName());
2956 method.addActionListener(new ActionListener()
2958 public void actionPerformed(ActionEvent e)
2960 AlignmentView msa = gatherSequencesForAlignment();
2961 new jalview.ws.MsaWSClient(sh, title, msa,
2962 false, true, viewport.getAlignment().getDataset(), af);
2967 msawsmenu.add(method);
2968 // Deal with services that we know accept partial alignments.
2969 if (sh.getName().indexOf("lustal") > -1)
2971 // We know that ClustalWS can accept partial alignments for refinement.
2972 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2973 methodR.addActionListener(new ActionListener()
2975 public void actionPerformed(ActionEvent e)
2977 AlignmentView msa = gatherSequencesForAlignment();
2978 new jalview.ws.MsaWSClient(sh, title, msa,
2979 true, true, viewport.getAlignment().getDataset(), af);
2984 msawsmenu.add(methodR);
2988 wsmenu.add(msawsmenu);
2990 if (secstrpr != null)
2992 // Add any secondary structure prediction services
2993 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2994 for (int i = 0, j = secstrpr.size(); i < j; i++)
2996 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2998 final JMenuItem method = new JMenuItem(sh.getName());
2999 method.addActionListener(new ActionListener()
3001 public void actionPerformed(ActionEvent e)
3003 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3004 if (msa.getSequences().length == 1)
3006 // Single Sequence prediction
3007 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3011 if (msa.getSequences().length > 1)
3013 // Sequence profile based prediction
3014 new jalview.ws.JPredClient(sh,
3015 title, true, msa, af, true);
3020 secstrmenu.add(method);
3022 wsmenu.add(secstrmenu);
3024 this.webService.removeAll();
3025 for (int i = 0, j = wsmenu.size(); i < j; i++)
3027 webService.add( (JMenu) wsmenu.get(i));
3032 this.webService.removeAll();
3033 this.webService.add(this.webServiceNoServices);
3035 // TODO: add in rediscovery function
3036 // TODO: reduce code redundancy.
3037 // TODO: group services by location as well as function.
3040 /* public void vamsasStore_actionPerformed(ActionEvent e)
3042 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3043 getProperty("LAST_DIRECTORY"));
3045 chooser.setFileView(new JalviewFileView());
3046 chooser.setDialogTitle("Export to Vamsas file");
3047 chooser.setToolTipText("Export");
3049 int value = chooser.showSaveDialog(this);
3051 if (value == JalviewFileChooser.APPROVE_OPTION)
3053 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3054 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3055 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3062 public void showTranslation_actionPerformed(ActionEvent e)
3064 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3065 String [] seqstring = viewport.getViewAsString(true);
3067 int s, sSize = selection.length;
3068 SequenceI [] newSeq = new SequenceI[sSize];
3071 StringBuffer protein;
3073 for(s=0; s<sSize; s++)
3075 protein = new StringBuffer();
3076 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3077 resSize = seq.length();
3078 resSize -= resSize%3;
3080 for(res = 0; res < resSize; res+=3)
3082 String codon = seq.substring(res, res+3);
3083 codon = codon.replace('U', 'T');
3084 String aa = ResidueProperties.codonTranslate(codon);
3086 protein.append(viewport.getGapCharacter());
3087 else if(aa.equals("STOP"))
3088 protein.append("X");
3090 protein.append( aa );
3092 newSeq[s] = new Sequence(selection[s].getName(),
3093 protein.toString());
3097 AlignmentI al = new Alignment(newSeq);
3098 al.setDataset(null);
3101 ////////////////////////////////
3102 // Copy annotations across
3103 jalview.datamodel.AlignmentAnnotation[] annotations
3104 = viewport.alignment.getAlignmentAnnotation();
3106 if(annotations!=null)
3108 for (int i = 0; i < annotations.length; i++)
3110 if (annotations[i].label.equals("Quality") ||
3111 annotations[i].label.equals("Conservation") ||
3112 annotations[i].label.equals("Consensus"))
3117 aSize = viewport.alignment.getWidth() / 3;
3118 jalview.datamodel.Annotation[] anots =
3119 new jalview.datamodel.Annotation[aSize];
3121 for (a = 0; a < viewport.alignment.getWidth(); a++)
3123 if (annotations[i].annotations[a] == null
3124 || annotations[i].annotations[a] == null)
3127 anots[a / 3] = new Annotation(
3128 annotations[i].annotations[a].displayCharacter,
3129 annotations[i].annotations[a].description,
3130 annotations[i].annotations[a].secondaryStructure,
3131 annotations[i].annotations[a].value,
3132 annotations[i].annotations[a].colour);
3135 jalview.datamodel.AlignmentAnnotation aa
3136 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3137 annotations[i].description, anots);
3138 al.addAnnotation(aa);
3142 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3143 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3155 * @param String DOCUMENT ME!
3157 public boolean parseFeaturesFile(String file, String type)
3159 boolean featuresFile = false;
3161 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3162 alignPanel.seqPanel.seqCanvas.
3163 getFeatureRenderer().featureColours,
3168 ex.printStackTrace();
3173 viewport.showSequenceFeatures = true;
3174 showSeqFeatures.setSelected(true);
3175 alignPanel.repaint();
3178 return featuresFile;
3181 public void dragEnter(DropTargetDragEvent evt)
3184 public void dragExit(DropTargetEvent evt)
3187 public void dragOver(DropTargetDragEvent evt)
3190 public void dropActionChanged(DropTargetDragEvent evt)
3193 public void drop(DropTargetDropEvent evt)
3195 Transferable t = evt.getTransferable();
3196 java.util.List files = null;
3200 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3201 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3203 //Works on Windows and MacOSX
3204 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3205 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3207 else if (t.isDataFlavorSupported(uriListFlavor))
3209 // This is used by Unix drag system
3210 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3211 String data = (String) t.getTransferData(uriListFlavor);
3212 files = new java.util.ArrayList(1);
3213 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3216 st.hasMoreTokens(); )
3218 String s = st.nextToken();
3219 if (s.startsWith("#"))
3221 // the line is a comment (as per the RFC 2483)
3225 java.net.URI uri = new java.net.URI(s);
3226 java.io.File file = new java.io.File(uri);
3233 e.printStackTrace();
3240 for (int i = 0; i < files.size(); i++)
3242 loadJalviewDataFile(files.get(i).toString());
3245 catch (Exception ex)
3247 ex.printStackTrace();
3252 // This method will attempt to load a "dropped" file first by testing
3253 // whether its and Annotation file, then features file. If both are
3254 // false then the user may have dropped an alignment file onto this
3256 public void loadJalviewDataFile(String file)
3259 String protocol = "File";
3261 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3266 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3271 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3274 String format = new IdentifyFile().Identify(file, protocol);
3276 if(format.equalsIgnoreCase("JnetFile"))
3278 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3280 new JnetAnnotationMaker().add_annotation(predictions,
3281 viewport.getAlignment(),
3283 alignPanel.adjustAnnotationHeight();
3284 alignPanel.repaint();
3287 new FileLoader().LoadFile(viewport, file, protocol, format);
3293 alignPanel.adjustAnnotationHeight();
3296 }catch(Exception ex)
3298 ex.printStackTrace();
3302 public void tabSelectionChanged(int index)
3306 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3307 viewport = alignPanel.av;
3308 setMenusFromViewport(viewport);
3312 public void tabbedPane_mousePressed(MouseEvent e)
3314 if(SwingUtilities.isRightMouseButton(e))
3316 String reply = JOptionPane.showInternalInputDialog(this,
3319 JOptionPane.QUESTION_MESSAGE);
3323 viewport.viewName = reply;
3324 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3330 public AlignViewport getCurrentView()