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 if (!fileName.startsWith("http"))
157 reload.setEnabled(true);
160 void addKeyListener()
162 addKeyListener(new KeyAdapter()
164 public void keyPressed(KeyEvent evt)
166 if (viewport.cursorMode
167 && evt.getKeyCode() >= KeyEvent.VK_0
168 && evt.getKeyCode() <= KeyEvent.VK_9)
170 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
173 switch (evt.getKeyCode())
176 case 27: // escape key
177 deselectAllSequenceMenuItem_actionPerformed(null);
181 case KeyEvent.VK_DOWN:
182 if (viewport.cursorMode)
184 alignPanel.seqPanel.moveCursor(0, 1);
187 moveSelectedSequences(false);
191 if (viewport.cursorMode)
193 alignPanel.seqPanel.moveCursor(0, -1);
196 moveSelectedSequences(true);
199 case KeyEvent.VK_LEFT:
200 if (viewport.cursorMode)
202 alignPanel.seqPanel.moveCursor( -1, 0);
206 case KeyEvent.VK_RIGHT:
207 if (viewport.cursorMode)
209 alignPanel.seqPanel.moveCursor(1, 0);
213 case KeyEvent.VK_SPACE:
214 if (viewport.cursorMode)
216 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
222 case KeyEvent.VK_DELETE:
223 case KeyEvent.VK_BACK_SPACE:
224 if (!viewport.cursorMode)
226 cut_actionPerformed(null);
229 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
236 if (viewport.cursorMode)
238 alignPanel.seqPanel.setCursorRow();
242 if (viewport.cursorMode && !evt.isControlDown())
244 alignPanel.seqPanel.setCursorColumn();
248 if (viewport.cursorMode)
250 alignPanel.seqPanel.setCursorPosition();
254 case KeyEvent.VK_ENTER:
255 case KeyEvent.VK_COMMA:
256 if (viewport.cursorMode)
258 alignPanel.seqPanel.setCursorRowAndColumn();
263 if (viewport.cursorMode)
265 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
269 if (viewport.cursorMode)
271 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
276 viewport.cursorMode = !viewport.cursorMode;
277 statusBar.setText("Keyboard editing mode is " +
278 (viewport.cursorMode ? "on" : "off"));
279 if (viewport.cursorMode)
281 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
282 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
284 alignPanel.seqPanel.seqCanvas.repaint();
290 ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
291 java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
292 javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
294 javax.help.HelpBroker hb = hs.createHelpBroker();
295 hb.setCurrentID("home");
296 hb.setDisplayed(true);
300 ex.printStackTrace();
306 boolean toggleSeqs = !evt.isControlDown();
307 boolean toggleCols = !evt.isShiftDown();
309 boolean hide = false;
311 SequenceGroup sg = viewport.getSelectionGroup();
314 if (sg != null && sg.getSize(false) != viewport.alignment.getHeight())
316 hideSelSequences_actionPerformed(null);
319 else if (! (toggleCols && viewport.colSel.getSelected().size() > 0))
320 showAllSeqs_actionPerformed(null);
325 if (viewport.colSel.getSelected().size() > 0)
327 hideSelColumns_actionPerformed(null);
329 viewport.selectionGroup = sg;
332 showAllColumns_actionPerformed(null);
336 case KeyEvent.VK_PAGE_UP:
337 if (viewport.wrapAlignment)
338 alignPanel.scrollUp(true);
340 alignPanel.setScrollValues(viewport.startRes,
342 - viewport.endSeq + viewport.startSeq);
344 case KeyEvent.VK_PAGE_DOWN:
345 if (viewport.wrapAlignment)
346 alignPanel.scrollUp(false);
348 alignPanel.setScrollValues(viewport.startRes,
350 + viewport.endSeq - viewport.startSeq);
358 public void addAlignmentPanel(final AlignmentPanel ap,
361 ap.alignFrame = this;
363 alignPanels.addElement(ap);
365 PaintRefresher.Register(ap, ap.av.getSequenceSetId());
367 int aSize = alignPanels.size();
369 tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
371 if (aSize == 1 && ap.av.viewName==null)
373 this.getContentPane().add(ap, BorderLayout.CENTER);
379 setInitialTabVisible();
382 expandViews.setEnabled(true);
383 gatherViews.setEnabled(true);
384 tabbedPane.addTab(ap.av.viewName, ap);
386 ap.setVisible(false);
392 ap.av.alignment.padGaps();
393 ap.av.updateConservation(ap);
394 ap.av.updateConsensus(ap);
398 public void setInitialTabVisible()
400 expandViews.setEnabled(true);
401 gatherViews.setEnabled(true);
402 tabbedPane.setVisible(true);
403 AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
404 tabbedPane.addTab(first.av.viewName,first);
405 this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
409 public AlignViewport getViewport()
414 /* Set up intrinsic listeners for dynamically generated GUI bits. */
415 private void addServiceListeners()
417 final java.beans.PropertyChangeListener thisListener;
418 // Do this once to get current state
419 BuildWebServiceMenu();
420 Desktop.discoverer.addPropertyChangeListener(
421 thisListener = new java.beans.PropertyChangeListener()
423 public void propertyChange(PropertyChangeEvent evt)
425 // System.out.println("Discoverer property change.");
426 if (evt.getPropertyName().equals("services"))
428 // System.out.println("Rebuilding web service menu");
429 BuildWebServiceMenu();
434 addInternalFrameListener(new javax.swing.event.
435 InternalFrameAdapter()
437 public void internalFrameClosed(
438 javax.swing.event.InternalFrameEvent evt)
440 // System.out.println("deregistering discoverer listener");
441 Desktop.discoverer.removePropertyChangeListener(thisListener);
442 closeMenuItem_actionPerformed(true);
448 public void setGUINucleotide(boolean nucleotide)
450 showTranslation.setVisible( nucleotide );
451 conservationMenuItem.setEnabled( !nucleotide );
452 modifyConservation.setEnabled( !nucleotide );
454 //Remember AlignFrame always starts as protein
457 calculateMenu.remove(calculateMenu.getItemCount()-2);
462 * Need to call this method when tabs are selected for multiple views,
463 * or when loading from Jalview2XML.java
464 * @param av AlignViewport
466 void setMenusFromViewport(AlignViewport av)
468 padGapsMenuitem.setSelected(av.padGaps);
469 colourTextMenuItem.setSelected(av.showColourText);
470 abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
471 conservationMenuItem.setSelected(av.getConservationSelected());
472 seqLimits.setSelected(av.getShowJVSuffix());
473 idRightAlign.setSelected(av.rightAlignIds);
474 renderGapsMenuItem.setSelected(av.renderGaps);
475 wrapMenuItem.setSelected(av.wrapAlignment);
476 annotationPanelMenuItem.setState(av.showAnnotation);
477 viewBoxesMenuItem.setSelected(av.showBoxes);
478 viewTextMenuItem.setSelected(av.showText);
480 setColourSelected(ColourSchemeProperty.
481 getColourName(av.getGlobalColourScheme()));
483 showSeqFeatures.setSelected(av.showSequenceFeatures);
484 hiddenMarkers.setState(av.showHiddenMarkers);
485 applyToAllGroups.setState(av.colourAppliesToAllGroups);
491 Hashtable progressBars;
492 public void setProgressBar(String message, long id)
494 if(progressBars == null)
495 progressBars = new Hashtable();
497 JPanel progressPanel;
498 GridLayout layout = (GridLayout) statusPanel.getLayout();
499 if(progressBars.get( new Long(id) )!=null)
501 progressPanel = (JPanel)progressBars.get( new Long(id) );
502 statusPanel.remove(progressPanel);
503 progressBars.remove( progressPanel );
504 progressPanel = null;
506 statusBar.setText(message);
508 layout.setRows(layout.getRows() - 1);
512 progressPanel = new JPanel(new BorderLayout(10, 5));
514 JProgressBar progressBar = new JProgressBar();
515 progressBar.setIndeterminate(true);
517 progressPanel.add(new JLabel(message), BorderLayout.WEST);
518 progressPanel.add(progressBar, BorderLayout.CENTER);
520 layout.setRows(layout.getRows() + 1);
521 statusPanel.add(progressPanel);
523 progressBars.put(new Long(id), progressPanel);
533 Added so Castor Mapping file can obtain Jalview Version
535 public String getVersion()
537 return jalview.bin.Cache.getProperty("VERSION");
540 public FeatureRenderer getFeatureRenderer()
542 return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
546 public void fetchSequence_actionPerformed(ActionEvent e)
548 new SequenceFetcher(this);
551 public void addFromFile_actionPerformed(ActionEvent e)
553 Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
556 public void reload_actionPerformed(ActionEvent e)
560 if(currentFileFormat.equals("Jalview"))
562 JInternalFrame [] frames = Desktop.desktop.getAllFrames();
563 for(int i=0; i<frames.length; i++)
565 if (frames[i] instanceof AlignFrame
567 && ( (AlignFrame) frames[i]).fileName.equals(fileName))
570 frames[i].setSelected(true);
571 Desktop.instance.closeAssociatedWindows();
572 }catch(java.beans.PropertyVetoException ex){}
576 Desktop.instance.closeAssociatedWindows();
581 viewport.alignment.deleteAllGroups();
582 viewport.sequenceColours=null;
583 while (viewport.alignment.getHeight() > 0)
585 viewport.alignment.deleteSequence(0);
588 viewport.historyList.clear();
589 viewport.redoList.clear();
590 Alignment dset = viewport.alignment.getDataset();
591 while (dset.getHeight() > 0)
593 dset.deleteSequence(0);
596 firePropertyChange("Alignment", null, null);
601 FileLoader loader = new FileLoader();
602 String protocol = fileName.startsWith("http:")? "URL":"File";
603 loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
609 public void addFromText_actionPerformed(ActionEvent e)
611 Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
614 public void addFromURL_actionPerformed(ActionEvent e)
616 Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
620 public void save_actionPerformed(ActionEvent e)
622 if(fileName==null || currentFileFormat==null)
623 saveAs_actionPerformed(null);
625 saveAlignment(fileName, currentFileFormat);
631 * @param e DOCUMENT ME!
633 public void saveAs_actionPerformed(ActionEvent e)
635 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
636 getProperty( "LAST_DIRECTORY"),
638 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
640 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
645 chooser.setFileView(new JalviewFileView());
646 chooser.setDialogTitle("Save Alignment to file");
647 chooser.setToolTipText("Save");
649 int value = chooser.showSaveDialog(this);
651 if (value == JalviewFileChooser.APPROVE_OPTION)
653 currentFileFormat = chooser.getSelectedFormat();
654 if (currentFileFormat == null)
656 JOptionPane.showInternalMessageDialog(Desktop.desktop,
657 "You must select a file format before saving!",
658 "File format not specified",
659 JOptionPane.WARNING_MESSAGE);
660 value = chooser.showSaveDialog(this);
664 fileName = chooser.getSelectedFile().getPath();
666 jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
669 jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
671 saveAlignment(fileName, currentFileFormat);
675 public boolean saveAlignment(String file, String format)
677 if (format.equalsIgnoreCase("Jalview"))
679 String shortName = title;
681 if (shortName.indexOf(java.io.File.separatorChar) > -1)
683 shortName = shortName.substring(shortName.lastIndexOf(
684 java.io.File.separatorChar) + 1);
687 new Jalview2XML().SaveAlignment(this, file, shortName);
689 statusBar.setText("Successfully saved to file: "
691 +format +" format.");
694 // USE Jalview2XML to save this file
700 String[] omitHidden = null;
702 if (viewport.hasHiddenColumns)
704 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
705 "The Alignment contains hidden columns."
706 + "\nDo you want to save only the visible alignment?",
707 "Save / Omit Hidden Columns",
708 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
710 if (reply == JOptionPane.YES_OPTION)
711 omitHidden = viewport.getViewAsString(false);
714 String output = new FormatAdapter().formatSequences(
716 viewport.alignment.getSequencesArray(),
726 java.io.PrintWriter out = new java.io.PrintWriter(
727 new java.io.FileWriter(file));
732 statusBar.setText("Successfully saved to file: "
734 +format +" format.");
739 ex.printStackTrace();
748 * @param e DOCUMENT ME!
750 protected void outputText_actionPerformed(ActionEvent e)
752 String [] omitHidden = null;
754 if(viewport.hasHiddenColumns)
756 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
757 "The Alignment contains hidden columns."
758 +"\nDo you want to output only the visible alignment?",
759 "Save / Omit Hidden Columns",
760 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
762 if(reply==JOptionPane.YES_OPTION)
764 omitHidden = viewport.getViewAsString(false);
768 CutAndPasteTransfer cap = new CutAndPasteTransfer();
769 cap.setForInput(null);
770 Desktop.addInternalFrame(cap,
771 "Alignment output - " + e.getActionCommand(), 600,
775 cap.setText(new FormatAdapter().formatSequences(
776 e.getActionCommand(),
777 viewport.alignment.getSequencesArray(),
784 * @param e DOCUMENT ME!
786 protected void htmlMenuItem_actionPerformed(ActionEvent e)
788 new HTMLOutput(viewport,
789 alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
790 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
793 public void createImageMap(File file, String image)
795 alignPanel.makePNGImageMap(file, image);
801 * @param e DOCUMENT ME!
803 public void createPNG(File f)
805 alignPanel.makePNG(f);
811 * @param e DOCUMENT ME!
813 public void createEPS(File f)
815 alignPanel.makeEPS(f);
821 * @param e DOCUMENT ME!
823 public void printMenuItem_actionPerformed(ActionEvent e)
825 //Putting in a thread avoids Swing painting problems
826 PrintThread thread = new PrintThread();
830 public void exportFeatures_actionPerformed(ActionEvent e)
832 new AnnotationExporter().exportFeatures(alignPanel);
836 public void exportAnnotations_actionPerformed(ActionEvent e)
838 new AnnotationExporter().exportAnnotations(
840 viewport.alignment.getAlignmentAnnotation()
845 public void associatedData_actionPerformed(ActionEvent e)
847 // Pick the tree file
848 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
851 chooser.setFileView(new JalviewFileView());
852 chooser.setDialogTitle("Load Jalview Annotations or Features File");
853 chooser.setToolTipText("Load Jalview Annotations / Features file");
855 int value = chooser.showOpenDialog(null);
857 if (value == JalviewFileChooser.APPROVE_OPTION)
859 String choice = chooser.getSelectedFile().getPath();
860 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
861 loadJalviewDataFile(choice);
870 * @param e DOCUMENT ME!
872 public void closeMenuItem_actionPerformed(boolean closeAllTabs)
874 if(alignPanels!=null && alignPanels.size()<2)
879 if(alignPanels!=null)
882 for (int i = 0; i < alignPanels.size(); i++)
884 AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
885 PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
886 PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
887 PaintRefresher.RemoveComponent(ap);
891 int index = tabbedPane.getSelectedIndex();
893 alignPanels.removeElement(alignPanel);
894 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
895 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
896 PaintRefresher.RemoveComponent(alignPanel);
900 tabbedPane.removeTabAt(index);
901 tabbedPane.validate();
903 if(index==tabbedPane.getTabCount())
906 this.tabSelectionChanged(index);
911 this.setClosed(true);
915 ex.printStackTrace();
923 void updateEditMenuBar()
926 if (viewport.historyList.size() > 0)
928 undoMenuItem.setEnabled(true);
929 CommandI command = (CommandI) viewport.historyList.peek();
930 undoMenuItem.setText("Undo " + command.getDescription());
934 undoMenuItem.setEnabled(false);
935 undoMenuItem.setText("Undo");
938 if (viewport.redoList.size() > 0)
940 redoMenuItem.setEnabled(true);
942 CommandI command = (CommandI) viewport.redoList.peek();
943 redoMenuItem.setText("Redo " + command.getDescription());
947 redoMenuItem.setEnabled(false);
948 redoMenuItem.setText("Redo");
953 public void addHistoryItem(CommandI command)
955 if(command.getSize()>0)
957 viewport.historyList.push(command);
958 viewport.redoList.clear();
960 viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
969 * @param e DOCUMENT ME!
971 protected void undoMenuItem_actionPerformed(ActionEvent e)
973 CommandI command = (CommandI)viewport.historyList.pop();
974 viewport.redoList.push(command);
975 command.undoCommand();
977 AlignViewport originalSource = getOriginatingSource(command);
980 if(originalSource!=null)
982 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
983 originalSource.firePropertyChange("alignment", null,null);
990 * @param e DOCUMENT ME!
992 protected void redoMenuItem_actionPerformed(ActionEvent e)
994 if(viewport.redoList.size()<1)
997 CommandI command = (CommandI) viewport.redoList.pop();
998 viewport.historyList.push(command);
1001 AlignViewport originalSource = getOriginatingSource(command);
1002 updateEditMenuBar();
1004 if(originalSource!=null)
1006 originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
1007 originalSource.firePropertyChange("alignment", null,null);
1011 AlignViewport getOriginatingSource(CommandI command)
1013 AlignViewport originalSource = null;
1014 //For sequence removal and addition, we need to fire
1015 //the property change event FROM the viewport where the
1016 //original alignment was altered
1018 if (command instanceof EditCommand)
1020 EditCommand editCommand = (EditCommand) command;
1021 al = editCommand.getAlignment();
1022 Vector comps = (Vector) PaintRefresher.components
1023 .get(viewport.getSequenceSetId());
1025 for (int i = 0; i < comps.size(); i++)
1027 if (comps.elementAt(i) instanceof AlignmentPanel)
1029 if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
1031 originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
1038 if (originalSource == null)
1040 //The original view is closed, we must validate
1041 //the current view against the closed view first
1043 PaintRefresher.validateSequences(al, viewport.alignment);
1045 originalSource = viewport;
1048 return originalSource;
1054 * @param up DOCUMENT ME!
1056 public void moveSelectedSequences(boolean up)
1058 SequenceGroup sg = viewport.getSelectionGroup();
1067 for (int i = 1; i < viewport.alignment.getHeight(); i++)
1069 SequenceI seq = viewport.alignment.getSequenceAt(i);
1071 if (!sg.getSequences(false).contains(seq))
1076 SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
1078 if (sg.getSequences(false).contains(temp))
1083 viewport.alignment.getSequences().setElementAt(temp, i);
1084 viewport.alignment.getSequences().setElementAt(seq, i - 1);
1089 for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
1091 SequenceI seq = viewport.alignment.getSequenceAt(i);
1093 if (!sg.getSequences(false).contains(seq))
1098 SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
1100 if (sg.getSequences(false).contains(temp))
1105 viewport.alignment.getSequences().setElementAt(temp, i);
1106 viewport.alignment.getSequences().setElementAt(seq, i + 1);
1110 alignPanel.repaint();
1118 * @param e DOCUMENT ME!
1120 protected void copy_actionPerformed(ActionEvent e)
1123 if (viewport.getSelectionGroup() == null)
1128 SequenceI [] seqs = viewport.getSelectionAsNewSequence();
1129 String[] omitHidden = null;
1131 if (viewport.hasHiddenColumns)
1133 omitHidden = viewport.getViewAsString(true);
1136 String output = new FormatAdapter().formatSequences(
1141 StringSelection ss = new StringSelection(output);
1145 //Its really worth setting the clipboard contents
1146 //to empty before setting the large StringSelection!!
1147 Toolkit.getDefaultToolkit().getSystemClipboard()
1148 .setContents(new StringSelection(""), null);
1150 Toolkit.getDefaultToolkit().getSystemClipboard()
1151 .setContents(ss, Desktop.instance);
1153 catch (OutOfMemoryError er)
1155 er.printStackTrace();
1156 javax.swing.SwingUtilities.invokeLater(new Runnable()
1160 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1161 "Out of memory copying region!!"
1163 "\nSee help files for increasing Java Virtual Machine memory."
1165 javax.swing.JOptionPane.WARNING_MESSAGE);
1172 Vector hiddenColumns = null;
1173 if(viewport.hasHiddenColumns)
1175 hiddenColumns =new Vector();
1176 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1177 for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)
1179 int[] region = (int[])
1180 viewport.getColumnSelection().getHiddenColumns().elementAt(i);
1182 hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,
1183 region[1]-hiddenOffset});
1189 Desktop.jalviewClipboard = new Object[]{ seqs,
1190 viewport.alignment.getDataset(),
1192 statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
1198 * @param e DOCUMENT ME!
1200 protected void pasteNew_actionPerformed(ActionEvent e)
1208 * @param e DOCUMENT ME!
1210 protected void pasteThis_actionPerformed(ActionEvent e)
1218 * @param newAlignment DOCUMENT ME!
1220 void paste(boolean newAlignment)
1224 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
1225 Transferable contents = c.getContents(this);
1227 if (contents == null)
1235 str = (String) contents.getTransferData(DataFlavor.stringFlavor);
1236 if (str.length() < 1)
1239 format = new IdentifyFile().Identify(str, "Paste");
1242 catch (OutOfMemoryError er)
1244 er.printStackTrace();
1245 javax.swing.SwingUtilities.invokeLater(new Runnable()
1249 javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
1250 "Out of memory pasting sequences!!"
1252 "\nSee help files for increasing Java Virtual Machine memory."
1254 javax.swing.JOptionPane.WARNING_MESSAGE);
1261 SequenceI[] sequences;
1264 if(Desktop.jalviewClipboard!=null)
1266 // The clipboard was filled from within Jalview, we must use the sequences
1267 // And dataset from the copied alignment
1268 sequences = (SequenceI[])Desktop.jalviewClipboard[0];
1272 sequences = new FormatAdapter().readFile(str, "Paste", format);
1275 AlignmentI alignment = null;
1279 alignment = new Alignment(sequences);
1281 if (Desktop.jalviewClipboard != null)
1282 alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
1284 alignment.setDataset(null);
1288 alignment = viewport.getAlignment();
1291 SequenceI [] newseqs = new SequenceI[sequences.length];
1292 for (int i = 0; i < sequences.length; i++)
1294 newseqs[i] = new Sequence(sequences[i].getName(),
1295 sequences[i].getSequence(), sequences[i].getStart(),
1296 sequences[i].getEnd());
1298 alignment.addSequence(newseqs[i]);
1304 addHistoryItem(new EditCommand(
1309 alignment.getWidth(),
1314 viewport.setEndSeq(alignment.getHeight());
1315 alignment.getWidth();
1316 viewport.firePropertyChange("alignment", null, alignment.getSequences());
1321 // Add any annotations attached to sequences
1322 for (int i = 0; i < sequences.length; i++)
1324 if (sequences[i].getAnnotation() != null)
1326 for (int a = 0; a < sequences[i].getAnnotation().length; a++)
1328 AlignmentAnnotation newAnnot =
1329 new AlignmentAnnotation(
1330 sequences[i].getAnnotation()[a].label,
1331 sequences[i].getAnnotation()[a].description,
1332 sequences[i].getAnnotation()[a].annotations,
1333 sequences[i].getAnnotation()[a].graphMin,
1334 sequences[i].getAnnotation()[a].graphMax,
1335 sequences[i].getAnnotation()[a].graph);
1337 sequences[i].getAnnotation()[a] = newAnnot;
1338 newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].
1340 newAnnot.sequenceRef = sequences[i];
1341 newAnnot.adjustForAlignment();
1342 alignment.addAnnotation(newAnnot);
1343 alignment.setAnnotationIndex(newAnnot, a);
1346 alignPanel.annotationPanel.adjustPanelHeight();
1352 AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
1353 String newtitle = new String("Copied sequences");
1355 if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
1357 Vector hc = (Vector)Desktop.jalviewClipboard[2];
1358 for(int i=0; i<hc.size(); i++)
1360 int [] region = (int[]) hc.elementAt(i);
1361 af.viewport.hideColumns(region[0], region[1]);
1366 //>>>This is a fix for the moment, until a better solution is found!!<<<
1367 af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
1368 alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
1371 if (title.startsWith("Copied sequences"))
1377 newtitle = newtitle.concat("- from " + title);
1380 Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
1387 catch (Exception ex)
1389 ex.printStackTrace();
1390 System.out.println("Exception whilst pasting: "+ex);
1391 // could be anything being pasted in here
1400 * @param e DOCUMENT ME!
1402 protected void cut_actionPerformed(ActionEvent e)
1404 copy_actionPerformed(null);
1405 delete_actionPerformed(null);
1411 * @param e DOCUMENT ME!
1413 protected void delete_actionPerformed(ActionEvent evt)
1416 SequenceGroup sg = viewport.getSelectionGroup();
1422 Vector seqs = new Vector();
1424 for (int i = 0; i < sg.getSize(false); i++)
1426 seq = sg.getSequenceAt(i);
1427 seqs.addElement(seq);
1431 // If the cut affects all sequences, remove highlighted columns
1432 if (sg.getSize(false) == viewport.alignment.getHeight())
1434 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1435 sg.getEndRes() + 1);
1439 SequenceI [] cut = new SequenceI[seqs.size()];
1440 for(int i=0; i<seqs.size(); i++)
1441 cut[i] = (SequenceI)seqs.elementAt(i);
1447 addHistoryItem(new EditCommand("Cut Sequences",
1451 sg.getEndRes()-sg.getStartRes()+1,
1452 viewport.alignment));
1455 viewport.setSelectionGroup(null);
1456 viewport.alignment.deleteGroup(sg);
1458 viewport.firePropertyChange("alignment", null,
1459 viewport.getAlignment().getSequences());
1461 if (viewport.getAlignment().getHeight() < 1)
1465 this.setClosed(true);
1467 catch (Exception ex)
1476 * @param e DOCUMENT ME!
1478 protected void deleteGroups_actionPerformed(ActionEvent e)
1480 viewport.alignment.deleteAllGroups();
1481 viewport.sequenceColours = null;
1482 viewport.setSelectionGroup(null);
1483 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1484 alignPanel.repaint();
1490 * @param e DOCUMENT ME!
1492 public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1494 SequenceGroup sg = new SequenceGroup();
1496 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1499 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1502 sg.setEndRes(viewport.alignment.getWidth() - 1);
1503 viewport.setSelectionGroup(sg);
1504 alignPanel.repaint();
1505 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1511 * @param e DOCUMENT ME!
1513 public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
1515 if(viewport.cursorMode)
1517 alignPanel.seqPanel.keyboardNo1 = null;
1518 alignPanel.seqPanel.keyboardNo2 = null;
1520 viewport.setSelectionGroup(null);
1521 viewport.getColumnSelection().clear();
1522 viewport.setSelectionGroup(null);
1523 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1524 alignPanel.idPanel.idCanvas.searchResults = null;
1525 alignPanel.repaint();
1526 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1532 * @param e DOCUMENT ME!
1534 public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
1536 SequenceGroup sg = viewport.getSelectionGroup();
1540 selectAllSequenceMenuItem_actionPerformed(null);
1545 for (int i = 0; i < viewport.getAlignment().getSequences().size();
1548 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1551 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1554 public void invertColSel_actionPerformed(ActionEvent e)
1556 viewport.invertColumnSelection();
1557 alignPanel.repaint();
1564 * @param e DOCUMENT ME!
1566 public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
1568 trimAlignment(true);
1574 * @param e DOCUMENT ME!
1576 public void remove2RightMenuItem_actionPerformed(ActionEvent e)
1578 trimAlignment(false);
1581 void trimAlignment(boolean trimLeft)
1583 ColumnSelection colSel = viewport.getColumnSelection();
1586 if (colSel.size() > 0)
1589 column = colSel.getMin();
1591 column = colSel.getMax();
1594 if(viewport.getSelectionGroup()!=null)
1595 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1597 seqs = viewport.alignment.getSequencesArray();
1600 TrimRegionCommand trimRegion;
1603 trimRegion = new TrimRegionCommand("Remove Left",
1604 TrimRegionCommand.TRIM_LEFT,
1609 viewport.selectionGroup);
1610 viewport.setStartRes(0);
1614 trimRegion = new TrimRegionCommand("Remove Right",
1615 TrimRegionCommand.TRIM_RIGHT,
1620 viewport.selectionGroup);
1623 statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
1626 addHistoryItem(trimRegion);
1628 Vector groups = viewport.alignment.getGroups();
1630 for (int i = 0; i < groups.size(); i++)
1632 SequenceGroup sg = (SequenceGroup) groups.get(i);
1634 if ( (trimLeft && !sg.adjustForRemoveLeft(column))
1635 || (!trimLeft && !sg.adjustForRemoveRight(column)))
1637 viewport.alignment.deleteGroup(sg);
1641 viewport.firePropertyChange("alignment", null,
1642 viewport.getAlignment().getSequences());
1649 * @param e DOCUMENT ME!
1651 public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
1653 int start = 0, end = viewport.alignment.getWidth()-1;
1656 if (viewport.getSelectionGroup() != null)
1658 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1659 start = viewport.getSelectionGroup().getStartRes();
1660 end = viewport.getSelectionGroup().getEndRes();
1663 seqs = viewport.alignment.getSequencesArray();
1666 RemoveGapColCommand removeGapCols =
1667 new RemoveGapColCommand("Remove Gapped Columns",
1670 viewport.getGapCharacter());
1672 addHistoryItem(removeGapCols);
1674 statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
1676 //This is to maintain viewport position on first residue
1678 SequenceI seq = viewport.alignment.getSequenceAt(0);
1679 int startRes = seq.findPosition(viewport.startRes);
1680 // ShiftList shifts;
1681 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
1682 // edit.alColumnChanges=shifts.getInverse();
1683 // if (viewport.hasHiddenColumns)
1684 // viewport.getColumnSelection().compensateForEdits(shifts);
1685 viewport.setStartRes(seq.findIndex(startRes)-1);
1686 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1693 * @param e DOCUMENT ME!
1695 public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
1697 int start = 0, end = viewport.alignment.getWidth()-1;
1700 if (viewport.getSelectionGroup() != null)
1702 seqs = viewport.getSelectionGroup().getSequencesAsArray(true);
1703 start = viewport.getSelectionGroup().getStartRes();
1704 end = viewport.getSelectionGroup().getEndRes();
1707 seqs = viewport.alignment.getSequencesArray();
1709 //This is to maintain viewport position on first residue
1711 SequenceI seq = viewport.alignment.getSequenceAt(0);
1712 int startRes = seq.findPosition(viewport.startRes);
1714 addHistoryItem(new RemoveGapsCommand("Remove Gaps",
1717 viewport.getGapCharacter()));
1719 viewport.setStartRes(seq.findIndex(startRes)-1);
1721 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
1728 * @param e DOCUMENT ME!
1730 public void padGapsMenuitem_actionPerformed(ActionEvent e)
1732 viewport.padGaps = padGapsMenuitem.isSelected();
1734 viewport.firePropertyChange("alignment",
1736 viewport.getAlignment().getSequences());
1742 * @param e DOCUMENT ME!
1744 public void findMenuItem_actionPerformed(ActionEvent e)
1749 public void newView_actionPerformed(ActionEvent e)
1751 AlignmentPanel newap =
1752 new Jalview2XML().copyAlignPanel(alignPanel, true);
1754 if (viewport.viewName == null)
1755 viewport.viewName = "Original";
1757 newap.av.historyList = viewport.historyList;
1758 newap.av.redoList = viewport.redoList;
1760 int index = Desktop.getViewCount(viewport.getSequenceSetId());
1761 String newViewName = "View " +index;
1763 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
1764 Vector existingNames = new Vector();
1765 for(int i=0; i<comps.size(); i++)
1767 if(comps.elementAt(i) instanceof AlignmentPanel)
1769 AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
1770 if(!existingNames.contains(ap.av.viewName))
1771 existingNames.addElement(ap.av.viewName);
1775 while(existingNames.contains(newViewName))
1777 newViewName = "View "+ (++index);
1780 newap.av.viewName = newViewName;
1782 addAlignmentPanel(newap, false);
1784 if(alignPanels.size()==2)
1786 viewport.gatherViewsHere = true;
1788 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
1791 public void expandViews_actionPerformed(ActionEvent e)
1793 Desktop.instance.explodeViews(this);
1796 public void gatherViews_actionPerformed(ActionEvent e)
1798 Desktop.instance.gatherViews(this);
1806 * @param e DOCUMENT ME!
1808 public void font_actionPerformed(ActionEvent e)
1810 new FontChooser(alignPanel);
1817 * @param e DOCUMENT ME!
1819 protected void seqLimit_actionPerformed(ActionEvent e)
1821 viewport.setShowJVSuffix(seqLimits.isSelected());
1823 alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
1824 alignPanel.repaint();
1827 public void idRightAlign_actionPerformed(ActionEvent e)
1829 viewport.rightAlignIds = idRightAlign.isSelected();
1830 alignPanel.repaint();
1838 * @param e DOCUMENT ME!
1840 protected void colourTextMenuItem_actionPerformed(ActionEvent e)
1842 viewport.setColourText(colourTextMenuItem.isSelected());
1843 alignPanel.repaint();
1849 * @param e DOCUMENT ME!
1851 public void wrapMenuItem_actionPerformed(ActionEvent e)
1853 scaleAbove.setVisible(wrapMenuItem.isSelected());
1854 scaleLeft.setVisible(wrapMenuItem.isSelected());
1855 scaleRight.setVisible(wrapMenuItem.isSelected());
1856 viewport.setWrapAlignment(wrapMenuItem.isSelected());
1857 alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
1860 public void showAllSeqs_actionPerformed(ActionEvent e)
1862 viewport.showAllHiddenSeqs();
1865 public void showAllColumns_actionPerformed(ActionEvent e)
1867 viewport.showAllHiddenColumns();
1871 public void hideSelSequences_actionPerformed(ActionEvent e)
1873 viewport.hideAllSelectedSeqs();
1874 alignPanel.repaint();
1877 public void hideSelColumns_actionPerformed(ActionEvent e)
1879 viewport.hideSelectedColumns();
1880 alignPanel.repaint();
1883 public void hiddenMarkers_actionPerformed(ActionEvent e)
1885 viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
1892 * @param e DOCUMENT ME!
1894 protected void scaleAbove_actionPerformed(ActionEvent e)
1896 viewport.setScaleAboveWrapped(scaleAbove.isSelected());
1897 alignPanel.repaint();
1903 * @param e DOCUMENT ME!
1905 protected void scaleLeft_actionPerformed(ActionEvent e)
1907 viewport.setScaleLeftWrapped(scaleLeft.isSelected());
1908 alignPanel.repaint();
1914 * @param e DOCUMENT ME!
1916 protected void scaleRight_actionPerformed(ActionEvent e)
1918 viewport.setScaleRightWrapped(scaleRight.isSelected());
1919 alignPanel.repaint();
1925 * @param e DOCUMENT ME!
1927 public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
1929 viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
1930 alignPanel.repaint();
1936 * @param e DOCUMENT ME!
1938 public void viewTextMenuItem_actionPerformed(ActionEvent e)
1940 viewport.setShowText(viewTextMenuItem.isSelected());
1941 alignPanel.repaint();
1947 * @param e DOCUMENT ME!
1949 protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
1951 viewport.setRenderGaps(renderGapsMenuItem.isSelected());
1952 alignPanel.repaint();
1956 public FeatureSettings featureSettings;
1957 public void featureSettings_actionPerformed(ActionEvent e)
1959 if(featureSettings !=null )
1961 featureSettings.close();
1962 featureSettings = null;
1964 featureSettings = new FeatureSettings(this);
1970 * @param evt DOCUMENT ME!
1972 public void showSeqFeatures_actionPerformed(ActionEvent evt)
1974 viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
1975 alignPanel.repaint();
1976 if (alignPanel.getOverviewPanel() != null)
1978 alignPanel.getOverviewPanel().updateOverviewImage();
1985 * @param e DOCUMENT ME!
1987 public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
1989 viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
1990 alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
1996 * @param e DOCUMENT ME!
1998 public void overviewMenuItem_actionPerformed(ActionEvent e)
2000 if (alignPanel.overviewPanel != null)
2005 JInternalFrame frame = new JInternalFrame();
2006 OverviewPanel overview = new OverviewPanel(alignPanel);
2007 frame.setContentPane(overview);
2008 Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
2009 frame.getWidth(), frame.getHeight());
2011 frame.setLayer(JLayeredPane.PALETTE_LAYER);
2012 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
2014 public void internalFrameClosed(
2015 javax.swing.event.InternalFrameEvent evt)
2017 alignPanel.setOverviewPanel(null);
2022 alignPanel.setOverviewPanel(overview);
2025 public void textColour_actionPerformed(ActionEvent e)
2027 new TextColourChooser().chooseColour(alignPanel, null);
2033 * @param e DOCUMENT ME!
2035 protected void noColourmenuItem_actionPerformed(ActionEvent e)
2043 * @param e DOCUMENT ME!
2045 public void clustalColour_actionPerformed(ActionEvent e)
2047 changeColour(new ClustalxColourScheme(
2048 viewport.alignment.getSequences(), viewport.alignment.getWidth()));
2054 * @param e DOCUMENT ME!
2056 public void zappoColour_actionPerformed(ActionEvent e)
2058 changeColour(new ZappoColourScheme());
2064 * @param e DOCUMENT ME!
2066 public void taylorColour_actionPerformed(ActionEvent e)
2068 changeColour(new TaylorColourScheme());
2074 * @param e DOCUMENT ME!
2076 public void hydrophobicityColour_actionPerformed(ActionEvent e)
2078 changeColour(new HydrophobicColourScheme());
2084 * @param e DOCUMENT ME!
2086 public void helixColour_actionPerformed(ActionEvent e)
2088 changeColour(new HelixColourScheme());
2094 * @param e DOCUMENT ME!
2096 public void strandColour_actionPerformed(ActionEvent e)
2098 changeColour(new StrandColourScheme());
2104 * @param e DOCUMENT ME!
2106 public void turnColour_actionPerformed(ActionEvent e)
2108 changeColour(new TurnColourScheme());
2114 * @param e DOCUMENT ME!
2116 public void buriedColour_actionPerformed(ActionEvent e)
2118 changeColour(new BuriedColourScheme());
2124 * @param e DOCUMENT ME!
2126 public void nucleotideColour_actionPerformed(ActionEvent e)
2128 changeColour(new NucleotideColourScheme());
2131 public void annotationColour_actionPerformed(ActionEvent e)
2133 new AnnotationColourChooser(viewport, alignPanel);
2140 * @param e DOCUMENT ME!
2142 protected void applyToAllGroups_actionPerformed(ActionEvent e)
2144 viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
2150 * @param cs DOCUMENT ME!
2152 public void changeColour(ColourSchemeI cs)
2158 if (viewport.getAbovePIDThreshold())
2160 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2163 cs.setThreshold(threshold,
2164 viewport.getIgnoreGapsConsensus());
2166 viewport.setGlobalColourScheme(cs);
2170 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2173 if (viewport.getConservationSelected())
2176 Alignment al = (Alignment) viewport.alignment;
2177 Conservation c = new Conservation("All",
2178 ResidueProperties.propHash, 3,
2179 al.getSequences(), 0,
2183 c.verdict(false, viewport.ConsPercGaps);
2185 cs.setConservation(c);
2187 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
2192 cs.setConservation(null);
2195 cs.setConsensus(viewport.hconsensus);
2198 viewport.setGlobalColourScheme(cs);
2200 if (viewport.getColourAppliesToAllGroups())
2202 Vector groups = viewport.alignment.getGroups();
2204 for (int i = 0; i < groups.size(); i++)
2206 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
2214 if (cs instanceof ClustalxColourScheme)
2216 sg.cs = new ClustalxColourScheme(
2217 sg.getSequences(true), sg.getWidth());
2219 else if (cs instanceof UserColourScheme)
2221 sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
2227 sg.cs = (ColourSchemeI) cs.getClass().newInstance();
2229 catch (Exception ex)
2234 if (viewport.getAbovePIDThreshold()
2235 || cs instanceof PIDColourScheme
2236 || cs instanceof Blosum62ColourScheme)
2238 sg.cs.setThreshold(threshold,
2239 viewport.getIgnoreGapsConsensus());
2241 sg.cs.setConsensus(AAFrequency.calculate(
2242 sg.getSequences(true), sg.getStartRes(),
2246 sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2249 if (viewport.getConservationSelected())
2251 Conservation c = new Conservation("Group",
2252 ResidueProperties.propHash, 3,
2253 sg.getSequences(true),
2257 c.verdict(false, viewport.ConsPercGaps);
2258 sg.cs.setConservation(c);
2261 sg.cs.setConservation(null);
2265 if (alignPanel.getOverviewPanel() != null)
2267 alignPanel.getOverviewPanel().updateOverviewImage();
2270 alignPanel.repaint();
2276 * @param e DOCUMENT ME!
2278 protected void modifyPID_actionPerformed(ActionEvent e)
2280 if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
2282 SliderPanel.setPIDSliderSource(alignPanel,
2283 viewport.getGlobalColourScheme(),
2285 SliderPanel.showPIDSlider();
2292 * @param e DOCUMENT ME!
2294 protected void modifyConservation_actionPerformed(ActionEvent e)
2296 if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
2298 SliderPanel.setConservationSlider(alignPanel,
2299 viewport.globalColourScheme,
2301 SliderPanel.showConservationSlider();
2308 * @param e DOCUMENT ME!
2310 protected void conservationMenuItem_actionPerformed(ActionEvent e)
2312 viewport.setConservationSelected(conservationMenuItem.isSelected());
2314 viewport.setAbovePIDThreshold(false);
2315 abovePIDThreshold.setSelected(false);
2317 changeColour(viewport.getGlobalColourScheme());
2319 modifyConservation_actionPerformed(null);
2325 * @param e DOCUMENT ME!
2327 public void abovePIDThreshold_actionPerformed(ActionEvent e)
2329 viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
2331 conservationMenuItem.setSelected(false);
2332 viewport.setConservationSelected(false);
2334 changeColour(viewport.getGlobalColourScheme());
2336 modifyPID_actionPerformed(null);
2342 * @param e DOCUMENT ME!
2344 public void userDefinedColour_actionPerformed(ActionEvent e)
2346 if (e.getActionCommand().equals("User Defined..."))
2348 new UserDefinedColours(alignPanel, null);
2352 UserColourScheme udc = (UserColourScheme) UserDefinedColours.
2353 getUserColourSchemes().get(e.getActionCommand());
2359 public void updateUserColourMenu()
2362 Component[] menuItems = colourMenu.getMenuComponents();
2363 int i, iSize = menuItems.length;
2364 for (i = 0; i < iSize; i++)
2366 if (menuItems[i].getName() != null &&
2367 menuItems[i].getName().equals("USER_DEFINED"))
2369 colourMenu.remove(menuItems[i]);
2373 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
2375 java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
2376 getUserColourSchemes().keys();
2378 while (userColours.hasMoreElements())
2380 final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.
2381 nextElement().toString());
2382 radioItem.setName("USER_DEFINED");
2383 radioItem.addMouseListener(new MouseAdapter()
2385 public void mousePressed(MouseEvent evt)
2387 if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
2389 radioItem.removeActionListener(radioItem.getActionListeners()[0]);
2391 int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,
2392 "Remove from default list?",
2393 "Remove user defined colour",
2394 JOptionPane.YES_NO_OPTION);
2395 if(option == JOptionPane.YES_OPTION)
2397 jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());
2398 colourMenu.remove(radioItem);
2401 radioItem.addActionListener(new ActionListener()
2403 public void actionPerformed(ActionEvent evt)
2405 userDefinedColour_actionPerformed(evt);
2411 radioItem.addActionListener(new ActionListener()
2413 public void actionPerformed(ActionEvent evt)
2415 userDefinedColour_actionPerformed(evt);
2419 colourMenu.insert(radioItem, 15);
2420 colours.add(radioItem);
2428 * @param e DOCUMENT ME!
2430 public void PIDColour_actionPerformed(ActionEvent e)
2432 changeColour(new PIDColourScheme());
2438 * @param e DOCUMENT ME!
2440 public void BLOSUM62Colour_actionPerformed(ActionEvent e)
2442 changeColour(new Blosum62ColourScheme());
2448 * @param e DOCUMENT ME!
2450 public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
2452 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2453 AlignmentSorter.sortByPID(viewport.getAlignment(),
2454 viewport.getAlignment().getSequenceAt(0));
2455 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.alignment));
2456 alignPanel.repaint();
2462 * @param e DOCUMENT ME!
2464 public void sortIDMenuItem_actionPerformed(ActionEvent e)
2466 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2467 AlignmentSorter.sortByID(viewport.getAlignment());
2468 addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
2469 alignPanel.repaint();
2475 * @param e DOCUMENT ME!
2477 public void sortGroupMenuItem_actionPerformed(ActionEvent e)
2479 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2480 AlignmentSorter.sortByGroup(viewport.getAlignment());
2481 addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
2483 alignPanel.repaint();
2489 * @param e DOCUMENT ME!
2491 public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
2493 new RedundancyPanel(alignPanel, this);
2500 * @param e DOCUMENT ME!
2502 public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
2504 if ( (viewport.getSelectionGroup() == null) ||
2505 (viewport.getSelectionGroup().getSize(false) < 2))
2507 JOptionPane.showInternalMessageDialog(this,
2508 "You must select at least 2 sequences.",
2509 "Invalid Selection",
2510 JOptionPane.WARNING_MESSAGE);
2514 JInternalFrame frame = new JInternalFrame();
2515 frame.setContentPane(new PairwiseAlignPanel(viewport));
2516 Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
2523 * @param e DOCUMENT ME!
2525 public void PCAMenuItem_actionPerformed(ActionEvent e)
2527 if ( ( (viewport.getSelectionGroup() != null) &&
2528 (viewport.getSelectionGroup().getSize(false) < 4) &&
2529 (viewport.getSelectionGroup().getSize(false) > 0)) ||
2530 (viewport.getAlignment().getHeight() < 4))
2532 JOptionPane.showInternalMessageDialog(this,
2533 "Principal component analysis must take\n" +
2534 "at least 4 input sequences.",
2535 "Sequence selection insufficient",
2536 JOptionPane.WARNING_MESSAGE);
2541 new PCAPanel(alignPanel);
2545 public void autoCalculate_actionPerformed(ActionEvent e)
2547 viewport.autoCalculateConsensus = autoCalculate.isSelected();
2548 if(viewport.autoCalculateConsensus)
2550 viewport.firePropertyChange("alignment",
2552 viewport.getAlignment().getSequences());
2560 * @param e DOCUMENT ME!
2562 public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
2564 NewTreePanel("AV", "PID", "Average distance tree using PID");
2570 * @param e DOCUMENT ME!
2572 public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
2574 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2580 * @param e DOCUMENT ME!
2582 protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2584 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2590 * @param e DOCUMENT ME!
2592 protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
2594 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2600 * @param type DOCUMENT ME!
2601 * @param pwType DOCUMENT ME!
2602 * @param title DOCUMENT ME!
2604 void NewTreePanel(String type, String pwType, String title)
2608 if (viewport.getSelectionGroup() != null) {
2609 if (viewport.getSelectionGroup().getSize(false) < 3) {
2610 JOptionPane.showMessageDialog(Desktop.desktop,
2611 "You need to have more than two sequences selected to build a tree!",
2612 "Not enough sequences",
2613 JOptionPane.WARNING_MESSAGE);
2618 SequenceGroup sg = viewport.getSelectionGroup();
2620 /* Decide if the selection is a column region */
2621 while (s < sg.getSize(false))
2623 if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <
2626 JOptionPane.showMessageDialog(Desktop.desktop,
2627 "The selected region to create a tree may\nonly contain residues or gaps.\n" +
2628 "Try using the Pad function in the edit menu,\n" +
2629 "or one of the multiple sequence alignment web services.",
2630 "Sequences in selection are not aligned",
2631 JOptionPane.WARNING_MESSAGE);
2637 title = title + " on region";
2638 tp = new TreePanel(alignPanel, type, pwType);
2642 //are the sequences aligned?
2643 if (!viewport.alignment.isAligned())
2645 JOptionPane.showMessageDialog(Desktop.desktop,
2646 "The sequences must be aligned before creating a tree.\n" +
2647 "Try using the Pad function in the edit menu,\n" +
2648 "or one of the multiple sequence alignment web services.",
2649 "Sequences not aligned",
2650 JOptionPane.WARNING_MESSAGE);
2655 if(viewport.alignment.getHeight()<2)
2658 tp = new TreePanel(alignPanel, type, pwType);
2661 title = title + " from " + this.title;
2662 if(viewport.viewName!=null)
2663 title+= " ("+viewport.viewName+")";
2665 Desktop.addInternalFrame(tp, title, 600, 500);
2671 * @param title DOCUMENT ME!
2672 * @param order DOCUMENT ME!
2674 public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
2676 final JMenuItem item = new JMenuItem("by " + title);
2678 item.addActionListener(new java.awt.event.ActionListener()
2680 public void actionPerformed(ActionEvent e)
2682 SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
2684 // TODO: JBPNote - have to map order entries to curent SequenceI pointers
2685 AlignmentSorter.sortBy(viewport.getAlignment(), order);
2687 addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport.alignment));
2689 alignPanel.repaint();
2695 * Maintain the Order by->Displayed Tree menu.
2696 * Creates a new menu item for a TreePanel with an appropriate
2697 * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
2698 * to remove the menu item when the treePanel is closed, and adjust
2699 * the tree leaf to sequence mapping when the alignment is modified.
2700 * @param treePanel Displayed tree window.
2701 * @param title SortBy menu item title.
2703 public void buildTreeMenu()
2705 sortByTreeMenu.removeAll();
2707 Vector comps = (Vector)PaintRefresher.components.get(viewport.getSequenceSetId());
2708 Vector treePanels = new Vector();
2709 int i, iSize = comps.size();
2710 for(i=0; i<iSize; i++)
2712 if(comps.elementAt(i) instanceof TreePanel)
2714 treePanels.add(comps.elementAt(i));
2718 iSize = treePanels.size();
2722 sortByTreeMenu.setVisible(false);
2726 sortByTreeMenu.setVisible(true);
2728 for(i=0; i<treePanels.size(); i++)
2730 TreePanel tp = (TreePanel)treePanels.elementAt(i);
2731 final JMenuItem item = new JMenuItem(tp.getTitle());
2732 final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
2733 item.addActionListener(new java.awt.event.ActionListener()
2735 public void actionPerformed(ActionEvent e)
2737 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2738 AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
2740 addHistoryItem(new OrderCommand("Tree Sort",
2742 viewport.alignment));
2744 alignPanel.repaint();
2748 sortByTreeMenu.add(item);
2753 * Work out whether the whole set of sequences
2754 * or just the selected set will be submitted for multiple alignment.
2757 private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
2759 // Now, check we have enough sequences
2760 AlignmentView msa = null;
2762 if ( (viewport.getSelectionGroup() != null) &&
2763 (viewport.getSelectionGroup().getSize(false) > 1))
2765 // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
2766 /*SequenceGroup seqs = viewport.getSelectionGroup();
2768 msa = new SequenceI[sz = seqs.getSize(false)];
2770 for (int i = 0; i < sz; i++)
2772 msa[i] = (SequenceI) seqs.getSequenceAt(i);
2774 msa = viewport.getAlignmentView(true);
2778 /*Vector seqs = viewport.getAlignment().getSequences();
2780 if (seqs.size() > 1)
2782 msa = new SequenceI[seqs.size()];
2784 for (int i = 0; i < seqs.size(); i++)
2786 msa[i] = (SequenceI) seqs.elementAt(i);
2789 msa = viewport.getAlignmentView(false);
2795 * Decides what is submitted to a secondary structure prediction service,
2796 * the currently selected sequence, or the currently selected alignment
2797 * (where the first sequence in the set is the one that the prediction
2800 AlignmentView gatherSeqOrMsaForSecStrPrediction()
2802 AlignmentView seqs = null;
2804 if ( (viewport.getSelectionGroup() != null) &&
2805 (viewport.getSelectionGroup().getSize(false) > 0))
2807 seqs = viewport.getAlignmentView(true);
2811 seqs = viewport.getAlignmentView(false);
2813 // limit sequences - JBPNote in future - could spawn multiple prediction jobs
2814 // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
2815 if (!viewport.alignment.isAligned())
2817 seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] } );
2824 * @param e DOCUMENT ME!
2826 protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
2828 // Pick the tree file
2829 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2832 chooser.setFileView(new JalviewFileView());
2833 chooser.setDialogTitle("Select a newick-like tree file");
2834 chooser.setToolTipText("Load a tree file");
2836 int value = chooser.showOpenDialog(null);
2838 if (value == JalviewFileChooser.APPROVE_OPTION)
2840 String choice = chooser.getSelectedFile().getPath();
2841 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
2845 jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
2847 viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
2849 catch (Exception ex)
2851 JOptionPane.showMessageDialog(Desktop.desktop,
2852 "Problem reading tree file",
2854 JOptionPane.WARNING_MESSAGE);
2855 ex.printStackTrace();
2861 public TreePanel ShowNewickTree(NewickFile nf, String title)
2863 return ShowNewickTree(nf,title,600,500,4,5);
2865 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input)
2867 return ShowNewickTree(nf,title, input, 600,500,4,5);
2869 public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y) {
2870 return ShowNewickTree(nf, title, null, w, h, x, y);
2873 * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
2875 * @param nf the tree
2876 * @param title tree viewer title
2877 * @param input Associated alignment input data (or null)
2882 * @return TreePanel handle
2884 public TreePanel ShowNewickTree(NewickFile nf, String title, AlignmentView input, int w,int h,int x, int y) {
2885 TreePanel tp = null;
2891 if (nf.getTree() != null)
2893 tp = new TreePanel(alignPanel,
2901 tp.setLocation(x,y);
2904 Desktop.addInternalFrame(tp, title, w, h);
2907 catch (Exception ex)
2909 ex.printStackTrace();
2920 PrinterJob printJob = PrinterJob.getPrinterJob();
2921 PageFormat pf = printJob.pageDialog(printJob.defaultPage());
2922 printJob.setPrintable(alignPanel, pf);
2924 if (printJob.printDialog())
2930 catch (Exception PrintException)
2932 PrintException.printStackTrace();
2939 * Generates menu items and listener event actions for web service clients
2942 public void BuildWebServiceMenu()
2944 if ( (Discoverer.services != null)
2945 && (Discoverer.services.size() > 0))
2947 Vector msaws = (Vector) Discoverer.services.get("MsaWS");
2948 Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
2949 Vector wsmenu = new Vector();
2950 final AlignFrame af = this;
2953 // Add any Multiple Sequence Alignment Services
2954 final JMenu msawsmenu = new JMenu("Alignment");
2955 for (int i = 0, j = msaws.size(); i < j; i++)
2957 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
2959 final JMenuItem method = new JMenuItem(sh.getName());
2960 method.addActionListener(new ActionListener()
2962 public void actionPerformed(ActionEvent e)
2964 AlignmentView msa = gatherSequencesForAlignment();
2965 new jalview.ws.MsaWSClient(sh, title, msa,
2966 false, true, viewport.getAlignment().getDataset(), af);
2971 msawsmenu.add(method);
2972 // Deal with services that we know accept partial alignments.
2973 if (sh.getName().indexOf("lustal") > -1)
2975 // We know that ClustalWS can accept partial alignments for refinement.
2976 final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
2977 methodR.addActionListener(new ActionListener()
2979 public void actionPerformed(ActionEvent e)
2981 AlignmentView msa = gatherSequencesForAlignment();
2982 new jalview.ws.MsaWSClient(sh, title, msa,
2983 true, true, viewport.getAlignment().getDataset(), af);
2988 msawsmenu.add(methodR);
2992 wsmenu.add(msawsmenu);
2994 if (secstrpr != null)
2996 // Add any secondary structure prediction services
2997 final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
2998 for (int i = 0, j = secstrpr.size(); i < j; i++)
3000 final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
3002 final JMenuItem method = new JMenuItem(sh.getName());
3003 method.addActionListener(new ActionListener()
3005 public void actionPerformed(ActionEvent e)
3007 AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
3008 if (msa.getSequences().length == 1)
3010 // Single Sequence prediction
3011 new jalview.ws.JPredClient(sh, title, false, msa, af, true);
3015 if (msa.getSequences().length > 1)
3017 // Sequence profile based prediction
3018 new jalview.ws.JPredClient(sh,
3019 title, true, msa, af, true);
3024 secstrmenu.add(method);
3026 wsmenu.add(secstrmenu);
3028 this.webService.removeAll();
3029 for (int i = 0, j = wsmenu.size(); i < j; i++)
3031 webService.add( (JMenu) wsmenu.get(i));
3036 this.webService.removeAll();
3037 this.webService.add(this.webServiceNoServices);
3039 // TODO: add in rediscovery function
3040 // TODO: reduce code redundancy.
3041 // TODO: group services by location as well as function.
3044 /* public void vamsasStore_actionPerformed(ActionEvent e)
3046 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
3047 getProperty("LAST_DIRECTORY"));
3049 chooser.setFileView(new JalviewFileView());
3050 chooser.setDialogTitle("Export to Vamsas file");
3051 chooser.setToolTipText("Export");
3053 int value = chooser.showSaveDialog(this);
3055 if (value == JalviewFileChooser.APPROVE_OPTION)
3057 jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
3058 //vs.store(chooser.getSelectedFile().getAbsolutePath() );
3059 vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
3066 public void showTranslation_actionPerformed(ActionEvent e)
3068 SequenceI [] selection = viewport.getSelectionAsNewSequence();
3069 String [] seqstring = viewport.getViewAsString(true);
3071 int s, sSize = selection.length;
3072 SequenceI [] newSeq = new SequenceI[sSize];
3075 StringBuffer protein;
3077 for(s=0; s<sSize; s++)
3079 protein = new StringBuffer();
3080 seq = AlignSeq.extractGaps("-. ", seqstring[s]);
3081 resSize = seq.length();
3082 resSize -= resSize%3;
3084 for(res = 0; res < resSize; res+=3)
3086 String codon = seq.substring(res, res+3);
3087 codon = codon.replace('U', 'T');
3088 String aa = ResidueProperties.codonTranslate(codon);
3090 protein.append(viewport.getGapCharacter());
3091 else if(aa.equals("STOP"))
3092 protein.append("X");
3094 protein.append( aa );
3096 newSeq[s] = new Sequence(selection[s].getName(),
3097 protein.toString());
3101 AlignmentI al = new Alignment(newSeq);
3102 al.setDataset(null);
3105 ////////////////////////////////
3106 // Copy annotations across
3107 jalview.datamodel.AlignmentAnnotation[] annotations
3108 = viewport.alignment.getAlignmentAnnotation();
3110 if(annotations!=null)
3112 for (int i = 0; i < annotations.length; i++)
3114 if (annotations[i].label.equals("Quality") ||
3115 annotations[i].label.equals("Conservation") ||
3116 annotations[i].label.equals("Consensus"))
3121 aSize = viewport.alignment.getWidth() / 3;
3122 jalview.datamodel.Annotation[] anots =
3123 new jalview.datamodel.Annotation[aSize];
3125 for (a = 0; a < viewport.alignment.getWidth(); a++)
3127 if (annotations[i].annotations[a] == null
3128 || annotations[i].annotations[a] == null)
3131 anots[a / 3] = new Annotation(
3132 annotations[i].annotations[a].displayCharacter,
3133 annotations[i].annotations[a].description,
3134 annotations[i].annotations[a].secondaryStructure,
3135 annotations[i].annotations[a].value,
3136 annotations[i].annotations[a].colour);
3139 jalview.datamodel.AlignmentAnnotation aa
3140 = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,
3141 annotations[i].description, anots);
3142 al.addAnnotation(aa);
3146 AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
3147 Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
3159 * @param String DOCUMENT ME!
3161 public boolean parseFeaturesFile(String file, String type)
3163 boolean featuresFile = false;
3165 featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),
3166 alignPanel.seqPanel.seqCanvas.
3167 getFeatureRenderer().featureColours,
3172 ex.printStackTrace();
3177 viewport.showSequenceFeatures = true;
3178 showSeqFeatures.setSelected(true);
3179 alignPanel.repaint();
3182 return featuresFile;
3185 public void dragEnter(DropTargetDragEvent evt)
3188 public void dragExit(DropTargetEvent evt)
3191 public void dragOver(DropTargetDragEvent evt)
3194 public void dropActionChanged(DropTargetDragEvent evt)
3197 public void drop(DropTargetDropEvent evt)
3199 Transferable t = evt.getTransferable();
3200 java.util.List files = null;
3204 DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
3205 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3207 //Works on Windows and MacOSX
3208 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3209 files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);
3211 else if (t.isDataFlavorSupported(uriListFlavor))
3213 // This is used by Unix drag system
3214 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3215 String data = (String) t.getTransferData(uriListFlavor);
3216 files = new java.util.ArrayList(1);
3217 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3220 st.hasMoreTokens(); )
3222 String s = st.nextToken();
3223 if (s.startsWith("#"))
3225 // the line is a comment (as per the RFC 2483)
3229 java.net.URI uri = new java.net.URI(s);
3230 java.io.File file = new java.io.File(uri);
3237 e.printStackTrace();
3244 for (int i = 0; i < files.size(); i++)
3246 loadJalviewDataFile(files.get(i).toString());
3249 catch (Exception ex)
3251 ex.printStackTrace();
3256 // This method will attempt to load a "dropped" file first by testing
3257 // whether its and Annotation file, then features file. If both are
3258 // false then the user may have dropped an alignment file onto this
3260 public void loadJalviewDataFile(String file)
3263 String protocol = "File";
3265 if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
3270 boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
3275 boolean isGroupsFile = parseFeaturesFile(file,protocol);
3278 String format = new IdentifyFile().Identify(file, protocol);
3280 if(format.equalsIgnoreCase("JnetFile"))
3282 jalview.io.JPredFile predictions = new jalview.io.JPredFile(
3284 new JnetAnnotationMaker().add_annotation(predictions,
3285 viewport.getAlignment(),
3287 alignPanel.adjustAnnotationHeight();
3288 alignPanel.repaint();
3291 new FileLoader().LoadFile(viewport, file, protocol, format);
3297 alignPanel.adjustAnnotationHeight();
3300 }catch(Exception ex)
3302 ex.printStackTrace();
3306 public void tabSelectionChanged(int index)
3310 alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
3311 viewport = alignPanel.av;
3312 setMenusFromViewport(viewport);
3316 public void tabbedPane_mousePressed(MouseEvent e)
3318 if(SwingUtilities.isRightMouseButton(e))
3320 String reply = JOptionPane.showInternalInputDialog(this,
3323 JOptionPane.QUESTION_MESSAGE);
3327 viewport.viewName = reply;
3328 tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
3334 public AlignViewport getCurrentView()