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);
978 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
980 originalSource.firePropertyChange("alignment", null,viewport.getAlignment().getSequences());
986 * @param e DOCUMENT ME!
988 protected void redoMenuItem_actionPerformed(ActionEvent e)
990 CommandI command = (CommandI) viewport.redoList.pop();
991 viewport.historyList.push(command);
994 AlignViewport originalSource = getOriginatingSource(command);
995 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null;
998 originalSource.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1001 AlignViewport getOriginatingSource(CommandI command)
1003 AlignViewport originalSource = viewport;
1004 //For sequence removal and addition, we need to fire
1005 //the property change event FROM the viewport where the
1006 //original alignment was altered
1007 if (command instanceof EditCommand)
1009 EditCommand editCommand = (EditCommand) command;
1010 AlignmentI al = editCommand.getAlignment();
1011 Vector comps = (Vector) PaintRefresher.components
1012 .get(viewport.getSequenceSetId());
1013 for (int i = 0; i < comps.size(); i++)
1015 if (comps.elementAt(i) instanceof AlignmentPanel)
1017 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1019 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1025 return originalSource;
1031 * @param up DOCUMENT ME!
1033 public void moveSelectedSequences(boolean up)
1035 SequenceGroup sg = viewport.getSelectionGroup();
1044 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1046 SequenceI seq = viewport.alignment.getSequenceAt(i);
1048 if (!sg.getSequences(false).contains(seq))
1053 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1055 if (sg.getSequences(false).contains(temp))
1060 viewport.alignment.getSequences().setElementAt(temp, i);
1061 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1066 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1068 SequenceI seq = viewport.alignment.getSequenceAt(i);
1070 if (!sg.getSequences(false).contains(seq))
1075 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1077 if (sg.getSequences(false).contains(temp))
1082 viewport.alignment.getSequences().setElementAt(temp, i);
1083 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1087 alignPanel.repaint();
1095 * @param e DOCUMENT ME!
1097 protected void copy_actionPerformed(ActionEvent e)
1100 if (viewport.getSelectionGroup() == null)
1105 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1106 String[] omitHidden = null;
1108 if (viewport.hasHiddenColumns)
1110 omitHidden = viewport.getViewAsString(true);
1113 String output = new FormatAdapter().formatSequences(
1118 StringSelection ss = new StringSelection(output);
1122 //Its really worth setting the clipboard contents
1123 //to empty before setting the large StringSelection!!
1124 Toolkit.getDefaultToolkit().getSystemClipboard()
1125 .setContents(new StringSelection(""), null);
1127 Toolkit.getDefaultToolkit().getSystemClipboard()
1128 .setContents(ss, Desktop.instance);
1130 catch (OutOfMemoryError er)
1132 er.printStackTrace();
1133 javax.swing.SwingUtilities.invokeLater(new Runnable()
1137 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1138 "Out of memory copying region!!"
1140 "\nSee help files for increasing Java Virtual Machine memory."
1142 javax.swing.JOptionPane.WARNING_MESSAGE);
1149 Vector hiddenColumns = null;
1150 if(viewport.hasHiddenColumns)
1152 hiddenColumns =new Vector();
1153 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1154 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1156 int[] region = (int[])
1157 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1159 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1160 region[1]-hiddenOffset});
1166 Desktop.jalviewClipboard = new Object[]{ seqs,
1167 viewport.alignment.getDataset(),
1169 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1175 * @param e DOCUMENT ME!
1177 protected void pasteNew_actionPerformed(ActionEvent e)
1185 * @param e DOCUMENT ME!
1187 protected void pasteThis_actionPerformed(ActionEvent e)
1195 * @param newAlignment DOCUMENT ME!
1197 void paste(boolean newAlignment)
1201 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1202 Transferable contents = c.getContents(this);
1204 if (contents == null)
1212 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1213 if (str.length() < 1)
1216 format = new IdentifyFile().Identify(str, "Paste");
1219 catch (OutOfMemoryError er)
1221 er.printStackTrace();
1222 javax.swing.SwingUtilities.invokeLater(new Runnable()
1226 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1227 "Out of memory pasting sequences!!"
1229 "\nSee help files for increasing Java Virtual Machine memory."
1231 javax.swing.JOptionPane.WARNING_MESSAGE);
1238 SequenceI[] sequences;
1241 if(Desktop.jalviewClipboard!=null)
1243 // The clipboard was filled from within Jalview, we must use the sequences
1244 // And dataset from the copied alignment
1245 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1249 sequences = new FormatAdapter().readFile(str, "Paste", format);
1252 AlignmentI alignment = null;
1256 alignment = new Alignment(sequences);
1258 if (Desktop.jalviewClipboard != null)
1259 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1261 alignment.setDataset(null);
1265 alignment = viewport.getAlignment();
1268 SequenceI [] newseqs = new SequenceI[sequences.length];
1269 for (int i = 0; i < sequences.length; i++)
1271 newseqs[i] = new Sequence(sequences[i].getName(),
1272 sequences[i].getSequence(), sequences[i].getStart(),
1273 sequences[i].getEnd());
1275 alignment.addSequence(newseqs[i]);
1281 addHistoryItem(new EditCommand(
1286 alignment.getWidth(),
1291 viewport.setEndSeq(alignment.getHeight());
1292 alignment.getWidth();
1293 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1298 // Add any annotations attached to sequences
1299 for (int i = 0; i < sequences.length; i++)
1301 if (sequences[i].getAnnotation() != null)
1303 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1305 AlignmentAnnotation newAnnot =
1306 new AlignmentAnnotation(
1307 sequences[i].getAnnotation()[a].label,
1308 sequences[i].getAnnotation()[a].description,
1309 sequences[i].getAnnotation()[a].annotations,
1310 sequences[i].getAnnotation()[a].graphMin,
1311 sequences[i].getAnnotation()[a].graphMax,
1312 sequences[i].getAnnotation()[a].graph);
1314 sequences[i].getAnnotation()[a] = newAnnot;
1315 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1317 newAnnot.sequenceRef = sequences[i];
1318 newAnnot.adjustForAlignment();
1319 alignment.addAnnotation(newAnnot);
1320 alignment.setAnnotationIndex(newAnnot, a);
1323 alignPanel.annotationPanel.adjustPanelHeight();
1329 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1330 String newtitle = new String("Copied sequences");
1332 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1334 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1335 for(int i=0; i<hc.size(); i++)
1337 int [] region = (int[]) hc.elementAt(i);
1338 af.viewport.hideColumns(region[0], region[1]);
1343 //>>>This is a fix for the moment, until a better solution is found!!<<<
1344 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1345 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1348 if (title.startsWith("Copied sequences"))
1354 newtitle = newtitle.concat("- from " + title);
1357 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1364 catch (Exception ex)
1366 ex.printStackTrace();
1367 System.out.println("Exception whilst pasting: "+ex);
1368 // could be anything being pasted in here
1377 * @param e DOCUMENT ME!
1379 protected void cut_actionPerformed(ActionEvent e)
1381 copy_actionPerformed(null);
1382 delete_actionPerformed(null);
1388 * @param e DOCUMENT ME!
1390 protected void delete_actionPerformed(ActionEvent evt)
1393 SequenceGroup sg = viewport.getSelectionGroup();
1399 Vector seqs = new Vector();
1401 for (int i = 0; i < sg.getSize(false); i++)
1403 seq = sg.getSequenceAt(i);
1404 seqs.addElement(seq);
1408 // If the cut affects all sequences, remove highlighted columns
1409 if (sg.getSize(false) == viewport.alignment.getHeight())
1411 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1412 sg.getEndRes() + 1);
1416 SequenceI [] cut = new SequenceI[seqs.size()];
1417 for(int i=0; i<seqs.size(); i++)
1418 cut[i] = (SequenceI)seqs.elementAt(i);
1424 addHistoryItem(new EditCommand("Cut Sequences",
1428 sg.getEndRes()-sg.getStartRes()+1,
1429 viewport.alignment));
1432 viewport.setSelectionGroup(null);
1433 viewport.alignment.deleteGroup(sg);
1435 viewport.firePropertyChange("alignment", null,
1436 viewport.getAlignment().getSequences());
1438 if (viewport.getAlignment().getHeight() < 1)
1442 this.setClosed(true);
1444 catch (Exception ex)
1453 * @param e DOCUMENT ME!
1455 protected void deleteGroups_actionPerformed(ActionEvent e)
1457 viewport.alignment.deleteAllGroups();
1458 viewport.sequenceColours.clear();
1459 viewport.setSelectionGroup(null);
1460 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1461 alignPanel.repaint();
1467 * @param e DOCUMENT ME!
1469 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1471 SequenceGroup sg = new SequenceGroup();
1473 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1476 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1479 sg.setEndRes(viewport.alignment.getWidth() - 1);
1480 viewport.setSelectionGroup(sg);
1481 alignPanel.repaint();
1482 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1488 * @param e DOCUMENT ME!
1490 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1492 if(viewport.cursorMode)
1494 alignPanel.seqPanel.keyboardNo1 = null;
1495 alignPanel.seqPanel.keyboardNo2 = null;
1497 viewport.setSelectionGroup(null);
1498 viewport.getColumnSelection().clear();
1499 viewport.setSelectionGroup(null);
1500 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1501 alignPanel.idPanel.idCanvas.searchResults = null;
1502 alignPanel.repaint();
1503 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1509 * @param e DOCUMENT ME!
1511 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1513 SequenceGroup sg = viewport.getSelectionGroup();
1517 selectAllSequenceMenuItem_actionPerformed(null);
1522 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1525 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1528 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1531 public void invertColSel_actionPerformed(ActionEvent e)
1533 viewport.invertColumnSelection();
1534 alignPanel.repaint();
1541 * @param e DOCUMENT ME!
1543 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1545 trimAlignment(true);
1551 * @param e DOCUMENT ME!
1553 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1555 trimAlignment(false);
1558 void trimAlignment(boolean trimLeft)
1560 ColumnSelection colSel = viewport.getColumnSelection();
1563 if (colSel.size() > 0)
1566 column = colSel.getMin();
1568 column = colSel.getMax();
1571 if(viewport.getSelectionGroup()!=null)
1572 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1574 seqs = viewport.alignment.getSequencesArray();
1577 TrimRegionCommand trimRegion;
1580 trimRegion = new TrimRegionCommand("Remove Left",
1581 TrimRegionCommand.TRIM_LEFT,
1586 viewport.selectionGroup);
1587 viewport.setStartRes(0);
1591 trimRegion = new TrimRegionCommand("Remove Right",
1592 TrimRegionCommand.TRIM_RIGHT,
1597 viewport.selectionGroup);
1600 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1603 addHistoryItem(trimRegion);
1605 Vector groups = viewport.alignment.getGroups();
1607 for (int i = 0; i < groups.size(); i++)
1609 SequenceGroup sg = (SequenceGroup) groups.get(i);
1611 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1612 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1614 viewport.alignment.deleteGroup(sg);
1618 viewport.firePropertyChange("alignment", null,
1619 viewport.getAlignment().getSequences());
1626 * @param e DOCUMENT ME!
1628 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1630 int start = 0, end = viewport.alignment.getWidth()-1;
1633 if (viewport.getSelectionGroup() != null)
1635 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1636 start = viewport.getSelectionGroup().getStartRes();
1637 end = viewport.getSelectionGroup().getEndRes();
1640 seqs = viewport.alignment.getSequencesArray();
1643 RemoveGapColCommand removeGapCols =
1644 new RemoveGapColCommand("Remove Gapped Columns",
1647 viewport.getGapCharacter());
1649 addHistoryItem(removeGapCols);
1651 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1653 //This is to maintain viewport position on first residue
1655 SequenceI seq = viewport.alignment.getSequenceAt(0);
1656 int startRes = seq.findPosition(viewport.startRes);
1657 // ShiftList shifts;
1658 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1659 // edit.alColumnChanges=shifts.getInverse();
1660 // if (viewport.hasHiddenColumns)
1661 // viewport.getColumnSelection().compensateForEdits(shifts);
1662 viewport.setStartRes(seq.findIndex(startRes)-1);
1663 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1670 * @param e DOCUMENT ME!
1672 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1674 int start = 0, end = viewport.alignment.getWidth()-1;
1677 if (viewport.getSelectionGroup() != null)
1679 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1680 start = viewport.getSelectionGroup().getStartRes();
1681 end = viewport.getSelectionGroup().getEndRes();
1684 seqs = viewport.alignment.getSequencesArray();
1686 //This is to maintain viewport position on first residue
1688 SequenceI seq = viewport.alignment.getSequenceAt(0);
1689 int startRes = seq.findPosition(viewport.startRes);
1691 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1694 viewport.getGapCharacter()));
1696 viewport.setStartRes(seq.findIndex(startRes)-1);
1698 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1705 * @param e DOCUMENT ME!
1707 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1709 viewport.padGaps = padGapsMenuitem.isSelected();
1711 viewport.firePropertyChange("alignment",
1713 viewport.getAlignment().getSequences());
1719 * @param e DOCUMENT ME!
1721 public void findMenuItem_actionPerformed(ActionEvent e)
1726 public void newView_actionPerformed(ActionEvent e)
1728 AlignmentPanel newap =
1729 new Jalview2XML().copyAlignPanel(alignPanel, true);
1731 if (viewport.viewName == null)
1732 viewport.viewName = "Original";
1734 newap.av.historyList = viewport.historyList;
1735 newap.av.redoList = viewport.redoList;
1737 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1738 String newViewName = "View " +index;
1740 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
1741 Vector existingNames = new Vector();
1742 for(int i=0; i<comps.size(); i++)
1744 if(comps.elementAt(i) instanceof AlignmentPanel)
1746 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
1747 if(!existingNames.contains(ap.av.viewName))
1748 existingNames.addElement(ap.av.viewName);
1752 while(existingNames.contains(newViewName))
1754 newViewName = "View "+ (++index);
1757 newap.av.viewName = newViewName;
1759 addAlignmentPanel(newap, false);
1761 if(alignPanels.size()==2)
1763 viewport.gatherViewsHere = true;
1765 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1768 public void expandViews_actionPerformed(ActionEvent e)
1770 Desktop.instance.explodeViews(this);
1773 public void gatherViews_actionPerformed(ActionEvent e)
1775 Desktop.instance.gatherViews(this);
1783 * @param e DOCUMENT ME!
1785 public void font_actionPerformed(ActionEvent e)
1787 new FontChooser(alignPanel);
1794 * @param e DOCUMENT ME!
1796 protected void seqLimit_actionPerformed(ActionEvent e)
1798 viewport.setShowJVSuffix(seqLimits.isSelected());
1800 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1801 alignPanel.repaint();
1804 public void idRightAlign_actionPerformed(ActionEvent e)
1806 viewport.rightAlignIds = idRightAlign.isSelected();
1807 alignPanel.repaint();
1815 * @param e DOCUMENT ME!
1817 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1819 viewport.setColourText(colourTextMenuItem.isSelected());
1820 alignPanel.repaint();
1826 * @param e DOCUMENT ME!
1828 public void wrapMenuItem_actionPerformed(ActionEvent e)
1830 scaleAbove.setVisible(wrapMenuItem.isSelected());
1831 scaleLeft.setVisible(wrapMenuItem.isSelected());
1832 scaleRight.setVisible(wrapMenuItem.isSelected());
1833 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1834 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1837 public void showAllSeqs_actionPerformed(ActionEvent e)
1839 viewport.showAllHiddenSeqs();
1842 public void showAllColumns_actionPerformed(ActionEvent e)
1844 viewport.showAllHiddenColumns();
1848 public void hideSelSequences_actionPerformed(ActionEvent e)
1850 viewport.hideAllSelectedSeqs();
1851 alignPanel.repaint();
1854 public void hideSelColumns_actionPerformed(ActionEvent e)
1856 viewport.hideSelectedColumns();
1857 alignPanel.repaint();
1860 public void hiddenMarkers_actionPerformed(ActionEvent e)
1862 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1869 * @param e DOCUMENT ME!
1871 protected void scaleAbove_actionPerformed(ActionEvent e)
1873 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1874 alignPanel.repaint();
1880 * @param e DOCUMENT ME!
1882 protected void scaleLeft_actionPerformed(ActionEvent e)
1884 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1885 alignPanel.repaint();
1891 * @param e DOCUMENT ME!
1893 protected void scaleRight_actionPerformed(ActionEvent e)
1895 viewport.setScaleRightWrapped(scaleRight.isSelected());
1896 alignPanel.repaint();
1902 * @param e DOCUMENT ME!
1904 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1906 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1907 alignPanel.repaint();
1913 * @param e DOCUMENT ME!
1915 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1917 viewport.setShowText(viewTextMenuItem.isSelected());
1918 alignPanel.repaint();
1924 * @param e DOCUMENT ME!
1926 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1928 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1929 alignPanel.repaint();
1933 public FeatureSettings featureSettings;
1934 public void featureSettings_actionPerformed(ActionEvent e)
1936 if(featureSettings !=null )
1938 featureSettings.close();
1939 featureSettings = null;
1941 featureSettings = new FeatureSettings(this);
1947 * @param evt DOCUMENT ME!
1949 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1951 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1952 alignPanel.repaint();
1953 if (alignPanel.getOverviewPanel() != null)
1955 alignPanel.getOverviewPanel().updateOverviewImage();
1962 * @param e DOCUMENT ME!
1964 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1966 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1967 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1973 * @param e DOCUMENT ME!
1975 public void overviewMenuItem_actionPerformed(ActionEvent e)
1977 if (alignPanel.overviewPanel != null)
1982 JInternalFrame frame = new JInternalFrame();
1983 OverviewPanel overview = new OverviewPanel(alignPanel);
1984 frame.setContentPane(overview);
1985 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
1986 frame.getWidth(), frame.getHeight());
1988 frame.setLayer(JLayeredPane.PALETTE_LAYER);
1989 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
1991 public void internalFrameClosed(
1992 javax.swing.event.InternalFrameEvent evt)
1994 alignPanel.setOverviewPanel(null);
1999 alignPanel.setOverviewPanel(overview);
2002 public void textColour_actionPerformed(ActionEvent e)
2004 new TextColourChooser().chooseColour(alignPanel, null);
2010 * @param e DOCUMENT ME!
2012 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2020 * @param e DOCUMENT ME!
2022 public void clustalColour_actionPerformed(ActionEvent e)
2024 changeColour(new ClustalxColourScheme(
2025 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2031 * @param e DOCUMENT ME!
2033 public void zappoColour_actionPerformed(ActionEvent e)
2035 changeColour(new ZappoColourScheme());
2041 * @param e DOCUMENT ME!
2043 public void taylorColour_actionPerformed(ActionEvent e)
2045 changeColour(new TaylorColourScheme());
2051 * @param e DOCUMENT ME!
2053 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2055 changeColour(new HydrophobicColourScheme());
2061 * @param e DOCUMENT ME!
2063 public void helixColour_actionPerformed(ActionEvent e)
2065 changeColour(new HelixColourScheme());
2071 * @param e DOCUMENT ME!
2073 public void strandColour_actionPerformed(ActionEvent e)
2075 changeColour(new StrandColourScheme());
2081 * @param e DOCUMENT ME!
2083 public void turnColour_actionPerformed(ActionEvent e)
2085 changeColour(new TurnColourScheme());
2091 * @param e DOCUMENT ME!
2093 public void buriedColour_actionPerformed(ActionEvent e)
2095 changeColour(new BuriedColourScheme());
2101 * @param e DOCUMENT ME!
2103 public void nucleotideColour_actionPerformed(ActionEvent e)
2105 changeColour(new NucleotideColourScheme());
2108 public void annotationColour_actionPerformed(ActionEvent e)
2110 new AnnotationColourChooser(viewport, alignPanel);
2117 * @param e DOCUMENT ME!
2119 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2121 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2127 * @param cs DOCUMENT ME!
2129 public void changeColour(ColourSchemeI cs)
2135 if (viewport.getAbovePIDThreshold())
2137 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2140 cs.setThreshold(threshold,
2141 viewport.getIgnoreGapsConsensus());
2143 viewport.setGlobalColourScheme(cs);
2147 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2150 if (viewport.getConservationSelected())
2153 Alignment al = (Alignment) viewport.alignment;
2154 Conservation c = new Conservation("All",
2155 ResidueProperties.propHash, 3,
2156 al.getSequences(), 0,
2160 c.verdict(false, viewport.ConsPercGaps);
2162 cs.setConservation(c);
2164 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2169 cs.setConservation(null);
2172 cs.setConsensus(viewport.hconsensus);
2175 viewport.setGlobalColourScheme(cs);
2177 if (viewport.getColourAppliesToAllGroups())
2179 Vector groups = viewport.alignment.getGroups();
2181 for (int i = 0; i < groups.size(); i++)
2183 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2191 if (cs instanceof ClustalxColourScheme)
2193 sg.cs = new ClustalxColourScheme(
2194 sg.getSequences(true), sg.getWidth());
2196 else if (cs instanceof UserColourScheme)
2198 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2204 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2206 catch (Exception ex)
2211 if (viewport.getAbovePIDThreshold()
2212 || cs instanceof PIDColourScheme
2213 || cs instanceof Blosum62ColourScheme)
2215 sg.cs.setThreshold(threshold,
2216 viewport.getIgnoreGapsConsensus());
2218 sg.cs.setConsensus(AAFrequency.calculate(
2219 sg.getSequences(true), sg.getStartRes(),
2223 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2226 if (viewport.getConservationSelected())
2228 Conservation c = new Conservation("Group",
2229 ResidueProperties.propHash, 3,
2230 sg.getSequences(true),
2234 c.verdict(false, viewport.ConsPercGaps);
2235 sg.cs.setConservation(c);
2238 sg.cs.setConservation(null);
2242 if (alignPanel.getOverviewPanel() != null)
2244 alignPanel.getOverviewPanel().updateOverviewImage();
2247 alignPanel.repaint();
2253 * @param e DOCUMENT ME!
2255 protected void modifyPID_actionPerformed(ActionEvent e)
2257 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2259 SliderPanel.setPIDSliderSource(alignPanel,
2260 viewport.getGlobalColourScheme(),
2262 SliderPanel.showPIDSlider();
2269 * @param e DOCUMENT ME!
2271 protected void modifyConservation_actionPerformed(ActionEvent e)
2273 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2275 SliderPanel.setConservationSlider(alignPanel,
2276 viewport.globalColourScheme,
2278 SliderPanel.showConservationSlider();
2285 * @param e DOCUMENT ME!
2287 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2289 viewport.setConservationSelected(conservationMenuItem.isSelected());
2291 viewport.setAbovePIDThreshold(false);
2292 abovePIDThreshold.setSelected(false);
2294 changeColour(viewport.getGlobalColourScheme());
2296 modifyConservation_actionPerformed(null);
2302 * @param e DOCUMENT ME!
2304 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2306 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2308 conservationMenuItem.setSelected(false);
2309 viewport.setConservationSelected(false);
2311 changeColour(viewport.getGlobalColourScheme());
2313 modifyPID_actionPerformed(null);
2319 * @param e DOCUMENT ME!
2321 public void userDefinedColour_actionPerformed(ActionEvent e)
2323 if (e.getActionCommand().equals("User Defined..."))
2325 new UserDefinedColours(alignPanel, null);
2329 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2330 getUserColourSchemes().get(e.getActionCommand());
2336 public void updateUserColourMenu()
2339 Component[] menuItems = colourMenu.getMenuComponents();
2340 int i, iSize = menuItems.length;
2341 for (i = 0; i < iSize; i++)
2343 if (menuItems[i].getName() != null &&
2344 menuItems[i].getName().equals("USER_DEFINED"))
2346 colourMenu.remove(menuItems[i]);
2350 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2352 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2353 getUserColourSchemes().keys();
2355 while (userColours.hasMoreElements())
2357 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2358 nextElement().toString());
2359 radioItem.setName("USER_DEFINED");
2360 radioItem.addMouseListener(new MouseAdapter()
2362 public void mousePressed(MouseEvent evt)
2364 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2366 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2368 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2369 "Remove from default list?",
2370 "Remove user defined colour",
2371 JOptionPane.YES_NO_OPTION);
2372 if(option == JOptionPane.YES_OPTION)
2374 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2375 colourMenu.remove(radioItem);
2378 radioItem.addActionListener(new ActionListener()
2380 public void actionPerformed(ActionEvent evt)
2382 userDefinedColour_actionPerformed(evt);
2388 radioItem.addActionListener(new ActionListener()
2390 public void actionPerformed(ActionEvent evt)
2392 userDefinedColour_actionPerformed(evt);
2396 colourMenu.insert(radioItem, 15);
2397 colours.add(radioItem);
2405 * @param e DOCUMENT ME!
2407 public void PIDColour_actionPerformed(ActionEvent e)
2409 changeColour(new PIDColourScheme());
2415 * @param e DOCUMENT ME!
2417 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2419 changeColour(new Blosum62ColourScheme());
2425 * @param e DOCUMENT ME!
2427 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2429 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2430 AlignmentSorter.sortByPID(viewport.getAlignment(),
2431 viewport.getAlignment().getSequenceAt(0));
2432 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2433 alignPanel.repaint();
2439 * @param e DOCUMENT ME!
2441 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2443 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2444 AlignmentSorter.sortByID(viewport.getAlignment());
2445 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2446 alignPanel.repaint();
2452 * @param e DOCUMENT ME!
2454 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2456 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2457 AlignmentSorter.sortByGroup(viewport.getAlignment());
2458 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2460 alignPanel.repaint();
2466 * @param e DOCUMENT ME!
2468 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2470 new RedundancyPanel(alignPanel, this);
2477 * @param e DOCUMENT ME!
2479 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2481 if ( (viewport.getSelectionGroup() == null) ||
2482 (viewport.getSelectionGroup().getSize(false) < 2))
2484 JOptionPane.showInternalMessageDialog(this,
2485 "You must select at least 2 sequences.",
2486 "Invalid Selection",
2487 JOptionPane.WARNING_MESSAGE);
2491 JInternalFrame frame = new JInternalFrame();
2492 frame.setContentPane(new PairwiseAlignPanel(viewport));
2493 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2500 * @param e DOCUMENT ME!
2502 public void PCAMenuItem_actionPerformed(ActionEvent e)
2504 if ( ( (viewport.getSelectionGroup() != null) &&
2505 (viewport.getSelectionGroup().getSize(false) < 4) &&
2506 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2507 (viewport.getAlignment().getHeight() < 4))
2509 JOptionPane.showInternalMessageDialog(this,
2510 "Principal component analysis must take\n" +
2511 "at least 4 input sequences.",
2512 "Sequence selection insufficient",
2513 JOptionPane.WARNING_MESSAGE);
2518 new PCAPanel(alignPanel);
2522 public void autoCalculate_actionPerformed(ActionEvent e)
2524 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2525 if(viewport.autoCalculateConsensus)
2527 viewport.firePropertyChange("alignment",
2529 viewport.getAlignment().getSequences());
2537 * @param e DOCUMENT ME!
2539 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2541 NewTreePanel("AV", "PID", "Average distance tree using PID");
2547 * @param e DOCUMENT ME!
2549 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2551 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2557 * @param e DOCUMENT ME!
2559 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2561 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2567 * @param e DOCUMENT ME!
2569 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2571 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2577 * @param type DOCUMENT ME!
2578 * @param pwType DOCUMENT ME!
2579 * @param title DOCUMENT ME!
2581 void NewTreePanel(String type, String pwType, String title)
2585 if (viewport.getSelectionGroup() != null) {
2586 if (viewport.getSelectionGroup().getSize(false) < 3) {
2587 JOptionPane.showMessageDialog(Desktop.desktop,
2588 "You need to have more than two sequences selected to build a tree!",
2589 "Not enough sequences",
2590 JOptionPane.WARNING_MESSAGE);
2595 SequenceGroup sg = viewport.getSelectionGroup();
2597 /* Decide if the selection is a column region */
2598 while (s < sg.getSize(false))
2600 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2603 JOptionPane.showMessageDialog(Desktop.desktop,
2604 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2605 "Try using the Pad function in the edit menu,\n" +
2606 "or one of the multiple sequence alignment web services.",
2607 "Sequences in selection are not aligned",
2608 JOptionPane.WARNING_MESSAGE);
2614 title = title + " on region";
2615 tp = new TreePanel(alignPanel, type, pwType);
2619 //are the sequences aligned?
2620 if (!viewport.alignment.isAligned())
2622 JOptionPane.showMessageDialog(Desktop.desktop,
2623 "The sequences must be aligned before creating a tree.\n" +
2624 "Try using the Pad function in the edit menu,\n" +
2625 "or one of the multiple sequence alignment web services.",
2626 "Sequences not aligned",
2627 JOptionPane.WARNING_MESSAGE);
2632 if(viewport.alignment.getHeight()<2)
2635 tp = new TreePanel(alignPanel, type, pwType);
2638 title = title + " from " + this.title;
2639 if(viewport.viewName!=null)
2640 title+= " ("+viewport.viewName+")";
2642 Desktop.addInternalFrame(tp, title, 600, 500);
2648 * @param title DOCUMENT ME!
2649 * @param order DOCUMENT ME!
2651 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2653 final JMenuItem item = new JMenuItem("by " + title);
2655 item.addActionListener(new java.awt.event.ActionListener()
2657 public void actionPerformed(ActionEvent e)
2659 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2661 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2662 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2664 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2666 alignPanel.repaint();
2672 * Maintain the Order by->Displayed Tree menu.
2673 * Creates a new menu item for a TreePanel with an appropriate
2674 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2675 * to remove the menu item when the treePanel is closed, and adjust
2676 * the tree leaf to sequence mapping when the alignment is modified.
2677 * @param treePanel Displayed tree window.
2678 * @param title SortBy menu item title.
2680 public void buildTreeMenu()
2682 sortByTreeMenu.removeAll();
2684 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
2685 Vector treePanels = new Vector();
2686 int i, iSize = comps.size();
2687 for(i=0; i<iSize; i++)
2689 if(comps.elementAt(i) instanceof TreePanel)
2691 treePanels.add(comps.elementAt(i));
2695 iSize = treePanels.size();
2699 sortByTreeMenu.setVisible(false);
2703 sortByTreeMenu.setVisible(true);
2705 for(i=0; i<treePanels.size(); i++)
2707 TreePanel tp = (TreePanel)treePanels.elementAt(i);
2708 final JMenuItem item = new JMenuItem(tp.getTitle());
2709 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
2710 item.addActionListener(new java.awt.event.ActionListener()
2712 public void actionPerformed(ActionEvent e)
2714 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2715 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
2717 addHistoryItem(new OrderCommand("Tree Sort",
2719 viewport.alignment));
2721 alignPanel.repaint();
2725 sortByTreeMenu.add(item);
2730 * Work out whether the whole set of sequences
2731 * or just the selected set will be submitted for multiple alignment.
2734 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2736 // Now, check we have enough sequences
2737 AlignmentView msa = null;
2739 if ( (viewport.getSelectionGroup() != null) &&
2740 (viewport.getSelectionGroup().getSize(false) > 1))
2742 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2743 /*SequenceGroup seqs = viewport.getSelectionGroup();
2745 msa = new SequenceI[sz = seqs.getSize(false)];
2747 for (int i = 0; i < sz; i++)
2749 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2751 msa = viewport.getAlignmentView(true);
2755 /*Vector seqs = viewport.getAlignment().getSequences();
2757 if (seqs.size() > 1)
2759 msa = new SequenceI[seqs.size()];
2761 for (int i = 0; i < seqs.size(); i++)
2763 msa[i] = (SequenceI) seqs.elementAt(i);
2766 msa = viewport.getAlignmentView(false);
2772 * Decides what is submitted to a secondary structure prediction service,
2773 * the currently selected sequence, or the currently selected alignment
2774 * (where the first sequence in the set is the one that the prediction
2777 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2779 AlignmentView seqs = null;
2781 if ( (viewport.getSelectionGroup() != null) &&
2782 (viewport.getSelectionGroup().getSize(false) > 0))
2784 seqs = viewport.getAlignmentView(true);
2788 seqs = viewport.getAlignmentView(false);
2790 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2791 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2792 if (!viewport.alignment.isAligned())
2794 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2801 * @param e DOCUMENT ME!
2803 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2805 // Pick the tree file
2806 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2809 chooser.setFileView(new JalviewFileView());
2810 chooser.setDialogTitle("Select a newick-like tree file");
2811 chooser.setToolTipText("Load a tree file");
2813 int value = chooser.showOpenDialog(null);
2815 if (value == JalviewFileChooser.APPROVE_OPTION)
2817 String choice = chooser.getSelectedFile().getPath();
2818 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2822 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2824 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2826 catch (Exception ex)
2828 JOptionPane.showMessageDialog(Desktop.desktop,
2829 "Problem reading tree file",
2831 JOptionPane.WARNING_MESSAGE);
2832 ex.printStackTrace();
2838 public TreePanel ShowNewickTree(NewickFile nf, String title)
2840 return ShowNewickTree(nf,title,600,500,4,5);
2842 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2844 return ShowNewickTree(nf,title, input, 600,500,4,5);
2846 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2847 return ShowNewickTree(nf, title, null, w, h, x, y);
2850 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2852 * @param nf the tree
2853 * @param title tree viewer title
2854 * @param input Associated alignment input data (or null)
2859 * @return TreePanel handle
2861 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2862 TreePanel tp = null;
2868 if (nf.getTree() != null)
2870 tp = new TreePanel(alignPanel,
2878 tp.setLocation(x,y);
2881 Desktop.addInternalFrame(tp, title, w, h);
2884 catch (Exception ex)
2886 ex.printStackTrace();
2897 PrinterJob printJob = PrinterJob.getPrinterJob();
2898 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2899 printJob.setPrintable(alignPanel, pf);
2901 if (printJob.printDialog())
2907 catch (Exception PrintException)
2909 PrintException.printStackTrace();
2916 * Generates menu items and listener event actions for web service clients
2919 public void BuildWebServiceMenu()
2921 if ( (Discoverer.services != null)
2922 && (Discoverer.services.size() > 0))
2924 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2925 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2926 Vector wsmenu = new Vector();
2927 final AlignFrame af = this;
2930 // Add any Multiple Sequence Alignment Services
2931 final JMenu msawsmenu = new JMenu("Alignment");
2932 for (int i = 0, j = msaws.size(); i < j; i++)
2934 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2936 final JMenuItem method = new JMenuItem(sh.getName());
2937 method.addActionListener(new ActionListener()
2939 public void actionPerformed(ActionEvent e)
2941 AlignmentView msa = gatherSequencesForAlignment();
2942 new jalview.ws.MsaWSClient(sh, title, msa,
2943 false, true, viewport.getAlignment().getDataset(), af);
2948 msawsmenu.add(method);
2949 // Deal with services that we know accept partial alignments.
2950 if (sh.getName().indexOf("lustal") > -1)
2952 // We know that ClustalWS can accept partial alignments for refinement.
2953 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2954 methodR.addActionListener(new ActionListener()
2956 public void actionPerformed(ActionEvent e)
2958 AlignmentView msa = gatherSequencesForAlignment();
2959 new jalview.ws.MsaWSClient(sh, title, msa,
2960 true, true, viewport.getAlignment().getDataset(), af);
2965 msawsmenu.add(methodR);
2969 wsmenu.add(msawsmenu);
2971 if (secstrpr != null)
2973 // Add any secondary structure prediction services
2974 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2975 for (int i = 0, j = secstrpr.size(); i < j; i++)
2977 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
2979 final JMenuItem method = new JMenuItem(sh.getName());
2980 method.addActionListener(new ActionListener()
2982 public void actionPerformed(ActionEvent e)
2984 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
2985 if (msa.getSequences().length == 1)
2987 // Single Sequence prediction
2988 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
2992 if (msa.getSequences().length > 1)
2994 // Sequence profile based prediction
2995 new jalview.ws.JPredClient(sh,
2996 title, true, msa, af, true);
3001 secstrmenu.add(method);
3003 wsmenu.add(secstrmenu);
3005 this.webService.removeAll();
3006 for (int i = 0, j = wsmenu.size(); i < j; i++)
3008 webService.add( (JMenu) wsmenu.get(i));
3013 this.webService.removeAll();
3014 this.webService.add(this.webServiceNoServices);
3016 // TODO: add in rediscovery function
3017 // TODO: reduce code redundancy.
3018 // TODO: group services by location as well as function.
3021 /* public void vamsasStore_actionPerformed(ActionEvent e)
3023 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3024 getProperty("LAST_DIRECTORY"));
3026 chooser.setFileView(new JalviewFileView());
3027 chooser.setDialogTitle("Export to Vamsas file");
3028 chooser.setToolTipText("Export");
3030 int value = chooser.showSaveDialog(this);
3032 if (value == JalviewFileChooser.APPROVE_OPTION)
3034 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3035 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3036 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3043 public void showTranslation_actionPerformed(ActionEvent e)
3045 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3046 String [] seqstring = viewport.getViewAsString(true);
3048 int s, sSize = selection.length;
3049 SequenceI [] newSeq = new SequenceI[sSize];
3052 StringBuffer protein;
3054 for(s=0; s<sSize; s++)
3056 protein = new StringBuffer();
3057 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3058 resSize = seq.length();
3059 resSize -= resSize%3;
3061 for(res = 0; res < resSize; res+=3)
3063 String codon = seq.substring(res, res+3);
3064 codon = codon.replace('U', 'T');
3065 String aa = ResidueProperties.codonTranslate(codon);
3067 protein.append(viewport.getGapCharacter());
3068 else if(aa.equals("STOP"))
3069 protein.append("X");
3071 protein.append( aa );
3073 newSeq[s] = new Sequence(selection[s].getName(),
3074 protein.toString());
3078 AlignmentI al = new Alignment(newSeq);
3079 al.setDataset(null);
3082 ////////////////////////////////
3083 // Copy annotations across
3084 jalview.datamodel.AlignmentAnnotation[] annotations
3085 = viewport.alignment.getAlignmentAnnotation();
3087 if(annotations!=null)
3089 for (int i = 0; i < annotations.length; i++)
3091 if (annotations[i].label.equals("Quality") ||
3092 annotations[i].label.equals("Conservation") ||
3093 annotations[i].label.equals("Consensus"))
3098 aSize = viewport.alignment.getWidth() / 3;
3099 jalview.datamodel.Annotation[] anots =
3100 new jalview.datamodel.Annotation[aSize];
3102 for (a = 0; a < viewport.alignment.getWidth(); a++)
3104 if (annotations[i].annotations[a] == null
3105 || annotations[i].annotations[a] == null)
3108 anots[a / 3] = new Annotation(
3109 annotations[i].annotations[a].displayCharacter,
3110 annotations[i].annotations[a].description,
3111 annotations[i].annotations[a].secondaryStructure,
3112 annotations[i].annotations[a].value,
3113 annotations[i].annotations[a].colour);
3116 jalview.datamodel.AlignmentAnnotation aa
3117 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3118 annotations[i].description, anots);
3119 al.addAnnotation(aa);
3123 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3124 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3136 * @param String DOCUMENT ME!
3138 public boolean parseFeaturesFile(String file, String type)
3140 boolean featuresFile = false;
3142 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3143 alignPanel.seqPanel.seqCanvas.
3144 getFeatureRenderer().featureColours,
3149 ex.printStackTrace();
3154 viewport.showSequenceFeatures = true;
3155 showSeqFeatures.setSelected(true);
3156 alignPanel.repaint();
3159 return featuresFile;
3162 public void dragEnter(DropTargetDragEvent evt)
3165 public void dragExit(DropTargetEvent evt)
3168 public void dragOver(DropTargetDragEvent evt)
3171 public void dropActionChanged(DropTargetDragEvent evt)
3174 public void drop(DropTargetDropEvent evt)
3176 Transferable t = evt.getTransferable();
3177 java.util.List files = null;
3181 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3182 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3184 //Works on Windows and MacOSX
3185 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3186 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3188 else if (t.isDataFlavorSupported(uriListFlavor))
3190 // This is used by Unix drag system
3191 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3192 String data = (String) t.getTransferData(uriListFlavor);
3193 files = new java.util.ArrayList(1);
3194 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3197 st.hasMoreTokens(); )
3199 String s = st.nextToken();
3200 if (s.startsWith("#"))
3202 // the line is a comment (as per the RFC 2483)
3206 java.net.URI uri = new java.net.URI(s);
3207 java.io.File file = new java.io.File(uri);
3214 e.printStackTrace();
3221 for (int i = 0; i < files.size(); i++)
3223 loadJalviewDataFile(files.get(i).toString());
3226 catch (Exception ex)
3228 ex.printStackTrace();
3233 // This method will attempt to load a "dropped" file first by testing
3234 // whether its and Annotation file, then features file. If both are
3235 // false then the user may have dropped an alignment file onto this
3237 public void loadJalviewDataFile(String file)
3240 String protocol = "File";
3242 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3247 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3252 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3255 String format = new IdentifyFile().Identify(file, protocol);
3257 if(format.equalsIgnoreCase("JnetFile"))
3259 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3261 new JnetAnnotationMaker().add_annotation(predictions,
3262 viewport.getAlignment(),
3264 alignPanel.adjustAnnotationHeight();
3265 alignPanel.repaint();
3268 new FileLoader().LoadFile(viewport, file, protocol, format);
3274 alignPanel.adjustAnnotationHeight();
3277 }catch(Exception ex)
3279 ex.printStackTrace();
3283 public void tabSelectionChanged(int index)
3287 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3288 viewport = alignPanel.av;
3289 setMenusFromViewport(viewport);
3293 public void tabbedPane_mousePressed(MouseEvent e)
3295 if(SwingUtilities.isRightMouseButton(e))
3297 String reply = JOptionPane.showInternalInputDialog(this,
3300 JOptionPane.QUESTION_MESSAGE);
3304 viewport.viewName = reply;
3305 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3311 public AlignViewport getCurrentView()