-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Softwarechang\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
- */\r
-package jalview.gui;\r
-\r
-import java.beans.*;\r
-import java.io.*;\r
-import java.util.*;\r
-\r
-import java.awt.*;\r
-import java.awt.datatransfer.*;\r
-import java.awt.event.*;\r
-import java.awt.print.*;\r
-import javax.swing.*;\r
-\r
-import jalview.analysis.*;\r
-import jalview.datamodel.*;\r
-import jalview.io.*;\r
-import jalview.jbgui.*;\r
-import jalview.schemes.*;\r
-import jalview.ws.*;\r
-import java.awt.dnd.*;\r
-import org.biojava.dasobert.eventmodel.*;\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @author $author$\r
- * @version $Revision$\r
- */\r
-public class AlignFrame\r
- extends GAlignFrame implements DropTargetListener, FeatureListener\r
-{\r
- /** DOCUMENT ME!! */\r
- public static final int NEW_WINDOW_WIDTH = 700;\r
-\r
- /** DOCUMENT ME!! */\r
- public static final int NEW_WINDOW_HEIGHT = 500;\r
- AlignmentPanel alignPanel;\r
- AlignViewport viewport;\r
-\r
- /** DOCUMENT ME!! */\r
- public String currentFileFormat = null;\r
- Stack historyList = new Stack();\r
- Stack redoList = new Stack();\r
- private int treeCount = 0;\r
-\r
-\r
- /**\r
- * Creates a new AlignFrame object.\r
- *\r
- * @param al DOCUMENT ME!\r
- */\r
- public AlignFrame(AlignmentI al)\r
- {\r
-\r
- viewport = new AlignViewport(al);\r
-\r
- this.setDropTarget(new java.awt.dnd.DropTarget(this, this));\r
-\r
- if(viewport.vconsensus==null)\r
- {\r
- //Out of memory calculating consensus.\r
- BLOSUM62Colour.setEnabled(false);\r
- PIDColour.setEnabled(false);\r
- conservationMenuItem.setEnabled(false);\r
- modifyConservation.setEnabled(false);\r
- abovePIDThreshold.setEnabled(false);\r
- modifyPID.setEnabled(false);\r
- }\r
-\r
- alignPanel = new AlignmentPanel(this, viewport);\r
-\r
- String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");\r
-\r
- if(sortby.equals("Id"))\r
- sortIDMenuItem_actionPerformed(null);\r
- else if(sortby.equals("Pairwise Identity"))\r
- sortPairwiseMenuItem_actionPerformed(null);\r
-\r
- // remove(tabbedPane);\r
- getContentPane().add(alignPanel, BorderLayout.CENTER);\r
-\r
-\r
-\r
- // tabbedPane.add(al.isNucleotide() ? "DNA":"Protein", alignPanel);\r
-\r
- ///Dataset tab\r
- /////////////////////////\r
- if(al.getDataset()==null)\r
- {\r
- al.setDataset(null);\r
- }\r
- // AlignViewport ds = new AlignViewport(al.getDataset(), true);\r
- // AlignmentPanel dap = new AlignmentPanel(this, ds);\r
- // tabbedPane.add("Dataset", dap);\r
- // viewports.add(ds);\r
- // alignPanels.add(dap);\r
- /////////////////////////\r
-\r
-\r
- viewport.addPropertyChangeListener(new PropertyChangeListener()\r
- {\r
- public void propertyChange(PropertyChangeEvent evt)\r
- {\r
- if (evt.getPropertyName().equals("alignment"))\r
- {\r
- alignmentChanged();\r
- }\r
- }\r
- });\r
-\r
-\r
- if (Desktop.desktop != null)\r
- {\r
- addServiceListeners();\r
- setGUINucleotide(al.isNucleotide());\r
- }\r
-\r
-\r
- if (jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false))\r
- {\r
- wrapMenuItem.setSelected(true);\r
- wrapMenuItem_actionPerformed(null);\r
- }\r
-\r
- }\r
-\r
- public AlignViewport getViewport()\r
- {\r
- return viewport;\r
- }\r
-\r
- /* Set up intrinsic listeners for dynamically generated GUI bits. */\r
- private void addServiceListeners()\r
- {\r
- final java.beans.PropertyChangeListener thisListener;\r
- // Do this once to get current state\r
- BuildWebServiceMenu();\r
- Desktop.discoverer.addPropertyChangeListener(\r
- thisListener = new java.beans.PropertyChangeListener()\r
- {\r
- public void propertyChange(PropertyChangeEvent evt)\r
- {\r
- // System.out.println("Discoverer property change.");\r
- if (evt.getPropertyName().equals("services"))\r
- {\r
- // System.out.println("Rebuilding web service menu");\r
- BuildWebServiceMenu();\r
- }\r
- }\r
- });\r
- addInternalFrameListener(new javax.swing.event.\r
- InternalFrameAdapter()\r
- {\r
- public void internalFrameClosed(\r
- javax.swing.event.InternalFrameEvent evt)\r
- {\r
- // System.out.println("deregistering discoverer listener");\r
- Desktop.discoverer.removePropertyChangeListener(thisListener);\r
- closeMenuItem_actionPerformed(null);\r
- }\r
- ;\r
- });\r
- }\r
-\r
- public void setGUINucleotide(boolean nucleotide)\r
- {\r
- showTranslation.setVisible( nucleotide );\r
- //sequenceFeatures.setVisible(!nucleotide );\r
- //featureSettings.setVisible( !nucleotide );\r
- conservationMenuItem.setVisible( !nucleotide );\r
- modifyConservation.setVisible( !nucleotide );\r
-\r
- //Remember AlignFrame always starts as protein\r
- if(!nucleotide)\r
- {\r
- calculateMenu.remove(calculateMenu.getItemCount()-2);\r
- }\r
- }\r
-\r
- public void comeBackLater(FeatureEvent evt)\r
- {}\r
-\r
- public void newFeatures(FeatureEvent evt)\r
- {\r
- if (evt.getFeatures().length > 0)\r
- {\r
- alignPanel.seqPanel.seqCanvas.fr.featuresAdded();\r
- alignPanel.repaint();\r
- if(featureSettings!=null)\r
- featureSettings.setTableData();\r
- }\r
- }\r
-\r
- Hashtable progressBars;\r
- public void setProgressBar(String message, long id)\r
- {\r
- if(progressBars == null)\r
- progressBars = new Hashtable();\r
-\r
- JPanel progressPanel;\r
- GridLayout layout = (GridLayout) statusPanel.getLayout();\r
- if(progressBars.get( new Long(id) )!=null)\r
- {\r
- progressPanel = (JPanel)progressBars.get( new Long(id) );\r
- statusPanel.remove(progressPanel);\r
- progressBars.remove( progressPanel );\r
- progressPanel = null;\r
- if(message!=null)\r
- statusBar.setText(message);\r
-\r
- layout.setRows(layout.getRows() - 1);\r
- }\r
- else\r
- {\r
- progressPanel = new JPanel(new BorderLayout(10, 5));\r
-\r
- JProgressBar progressBar = new JProgressBar();\r
- progressBar.setIndeterminate(true);\r
-\r
- progressPanel.add(new JLabel(message), BorderLayout.WEST);\r
- progressPanel.add(progressBar, BorderLayout.CENTER);\r
-\r
- layout.setRows(layout.getRows() + 1);\r
- statusPanel.add(progressPanel);\r
-\r
- progressBars.put(new Long(id), progressPanel);\r
- }\r
-\r
- validate();\r
- }\r
-\r
-\r
- /*\r
- Added so Castor Mapping file can obtain Jalview Version\r
- */\r
- public String getVersion()\r
- {\r
- return jalview.bin.Cache.getProperty("VERSION");\r
- }\r
-\r
- public FeatureRenderer getFeatureRenderer()\r
- {\r
- return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();\r
- }\r
-\r
-\r
- public void fetchSequence_actionPerformed(ActionEvent e)\r
- {\r
- new SequenceFetcher(this);\r
- }\r
-\r
- public void addFromFile_actionPerformed(ActionEvent e)\r
- {\r
- Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);\r
- }\r
-\r
- public void addFromText_actionPerformed(ActionEvent e)\r
- {\r
- Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);\r
- }\r
-\r
- public void addFromURL_actionPerformed(ActionEvent e)\r
- {\r
- Desktop.instance.inputURLMenuItem_actionPerformed(viewport);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void saveAlignmentMenu_actionPerformed(ActionEvent e)\r
- {\r
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
- getProperty( "LAST_DIRECTORY"),\r
- new String[]\r
- { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },\r
- new String[]\r
- { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },\r
- currentFileFormat,\r
- false);\r
-\r
-\r
- chooser.setFileView(new JalviewFileView());\r
- chooser.setDialogTitle("Save Alignment to file");\r
- chooser.setToolTipText("Save");\r
-\r
- int value = chooser.showSaveDialog(this);\r
-\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
- {\r
- currentFileFormat = chooser.getSelectedFormat();\r
-\r
- if (currentFileFormat == null)\r
- {\r
- JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "You must select a file format before saving!",\r
- "File format not specified",\r
- JOptionPane.WARNING_MESSAGE);\r
- value = chooser.showSaveDialog(this);\r
- return;\r
- }\r
-\r
- jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",\r
- currentFileFormat);\r
-\r
- String choice = chooser.getSelectedFile().getPath();\r
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);\r
-\r
- saveAlignment(choice, currentFileFormat);\r
- }\r
- }\r
-\r
- public boolean saveAlignment(String file, String format)\r
- {\r
- if (format.equalsIgnoreCase("Jalview"))\r
- {\r
- String shortName = title;\r
-\r
- if (shortName.indexOf(java.io.File.separatorChar) > -1)\r
- {\r
- shortName = shortName.substring(shortName.lastIndexOf(\r
- java.io.File.separatorChar) + 1);\r
- }\r
-\r
- new Jalview2XML().SaveAlignment(this, file, shortName);\r
-\r
- // USE Jalview2XML to save this file\r
- return true;\r
- }\r
- else\r
- {\r
-\r
- String[] omitHidden = null;\r
-\r
- if (viewport.hasHiddenColumns)\r
- {\r
- int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
- "The Alignment contains hidden columns."\r
- + "\nDo you want to save only the visible alignment?",\r
- "Save / Omit Hidden Columns",\r
- JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);\r
-\r
- if (reply == JOptionPane.YES_OPTION)\r
- omitHidden = viewport.getViewAsString(false);\r
- }\r
-\r
- String output = new FormatAdapter().formatSequences(\r
- format,\r
- viewport.alignment.getSequencesArray(),\r
- omitHidden);\r
-\r
- if (output == null)\r
- {\r
- return false;\r
- }\r
-\r
- try\r
- {\r
- java.io.PrintWriter out = new java.io.PrintWriter(\r
- new java.io.FileWriter(file));\r
-\r
- out.print(output);\r
- out.close();\r
- this.setTitle(file);\r
- return true;\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void outputText_actionPerformed(ActionEvent e)\r
- {\r
- String [] omitHidden = null;\r
-\r
- if(viewport.hasHiddenColumns)\r
- {\r
- int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
- "The Alignment contains hidden columns."\r
- +"\nDo you want to output only the visible alignment?",\r
- "Save / Omit Hidden Columns",\r
- JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);\r
-\r
- if(reply==JOptionPane.YES_OPTION)\r
- {\r
- omitHidden = viewport.getViewAsString(false);\r
- }\r
- }\r
-\r
- CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
- Desktop.addInternalFrame(cap,\r
- "Alignment output - " + e.getActionCommand(), 600,\r
- 500);\r
-\r
-\r
- cap.setText(new FormatAdapter().formatSequences(\r
- e.getActionCommand(),\r
- viewport.alignment.getSequencesArray(),\r
- omitHidden));\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void htmlMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- new HTMLOutput(viewport,\r
- alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),\r
- alignPanel.seqPanel.seqCanvas.getFeatureRenderer());\r
- }\r
-\r
- public void createImageMap(File file, String image)\r
- {\r
- alignPanel.makePNGImageMap(file, image);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void createPNG(File f)\r
- {\r
- alignPanel.makePNG(f);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void createEPS(File f)\r
- {\r
- alignPanel.makeEPS(f);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void printMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- //Putting in a thread avoids Swing painting problems\r
- PrintThread thread = new PrintThread();\r
- thread.start();\r
- }\r
-\r
- public void exportFeatures_actionPerformed(ActionEvent e)\r
- {\r
- new AnnotationExporter().exportFeatures(alignPanel);\r
- }\r
-\r
-\r
- public void exportAnnotations_actionPerformed(ActionEvent e)\r
- {\r
- new AnnotationExporter().exportAnnotations(\r
- alignPanel,\r
- viewport.alignment.getAlignmentAnnotation()\r
- );\r
- }\r
-\r
-\r
- public void associatedData_actionPerformed(ActionEvent e)\r
- {\r
- // Pick the tree file\r
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
- getProperty(\r
- "LAST_DIRECTORY"));\r
- chooser.setFileView(new JalviewFileView());\r
- chooser.setDialogTitle("Load Jalview Annotations or Features File");\r
- chooser.setToolTipText("Load Jalview Annotations / Features file");\r
-\r
- int value = chooser.showOpenDialog(null);\r
-\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
- {\r
- String choice = chooser.getSelectedFile().getPath();\r
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);\r
- loadJalviewDataFile(choice);\r
- }\r
-\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void closeMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- try\r
- {\r
- PaintRefresher.components.remove(viewport.alignment);\r
- this.setClosed(true);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- */\r
- void updateEditMenuBar()\r
- {\r
- if (historyList.size() > 0)\r
- {\r
- undoMenuItem.setEnabled(true);\r
-\r
- HistoryItem hi = (HistoryItem) historyList.peek();\r
- undoMenuItem.setText("Undo " + hi.getDescription());\r
- }\r
- else\r
- {\r
- undoMenuItem.setEnabled(false);\r
- undoMenuItem.setText("Undo");\r
- }\r
-\r
- if (redoList.size() > 0)\r
- {\r
- redoMenuItem.setEnabled(true);\r
-\r
- HistoryItem hi = (HistoryItem) redoList.peek();\r
- redoMenuItem.setText("Redo " + hi.getDescription());\r
- }\r
- else\r
- {\r
- redoMenuItem.setEnabled(false);\r
- redoMenuItem.setText("Redo");\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param hi DOCUMENT ME!\r
- */\r
- public void addHistoryItem(HistoryItem hi)\r
- {\r
- historyList.push(hi);\r
- updateEditMenuBar();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void undoMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- HistoryItem hi = (HistoryItem) historyList.pop();\r
- redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment,\r
- HistoryItem.HIDE));\r
- restoreHistoryItem(hi);\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void redoMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- HistoryItem hi = (HistoryItem) redoList.pop();\r
- restoreHistoryItem(hi);\r
- updateEditMenuBar();\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
- }\r
-\r
- // used by undo and redo\r
- void restoreHistoryItem(HistoryItem hi)\r
- {\r
-\r
- hi.restore();\r
-\r
- updateEditMenuBar();\r
-\r
- viewport.firePropertyChange("alignment", null,\r
- viewport.getAlignment().getSequences());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param up DOCUMENT ME!\r
- */\r
- public void moveSelectedSequences(boolean up)\r
- {\r
- SequenceGroup sg = viewport.getSelectionGroup();\r
-\r
- if (sg == null)\r
- {\r
- return;\r
- }\r
-\r
- if (up)\r
- {\r
- for (int i = 1; i < viewport.alignment.getHeight(); i++)\r
- {\r
- SequenceI seq = viewport.alignment.getSequenceAt(i);\r
-\r
- if (!sg.getSequences(false).contains(seq))\r
- {\r
- continue;\r
- }\r
-\r
- SequenceI temp = viewport.alignment.getSequenceAt(i - 1);\r
-\r
- if (sg.getSequences(false).contains(temp))\r
- {\r
- continue;\r
- }\r
-\r
- viewport.alignment.getSequences().setElementAt(temp, i);\r
- viewport.alignment.getSequences().setElementAt(seq, i - 1);\r
- }\r
- }\r
- else\r
- {\r
- for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)\r
- {\r
- SequenceI seq = viewport.alignment.getSequenceAt(i);\r
-\r
- if (!sg.getSequences(false).contains(seq))\r
- {\r
- continue;\r
- }\r
-\r
- SequenceI temp = viewport.alignment.getSequenceAt(i + 1);\r
-\r
- if (sg.getSequences(false).contains(temp))\r
- {\r
- continue;\r
- }\r
-\r
- viewport.alignment.getSequences().setElementAt(temp, i);\r
- viewport.alignment.getSequences().setElementAt(seq, i + 1);\r
- }\r
- }\r
-\r
- alignPanel.repaint();\r
- }\r
-\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void copy_actionPerformed(ActionEvent e)\r
- {\r
- if (viewport.getSelectionGroup() == null)\r
- {\r
- return;\r
- }\r
-\r
- SequenceI [] seqs = viewport.getSelectionAsNewSequence();\r
- String[] omitHidden = null;\r
-\r
- if (viewport.hasHiddenColumns)\r
- {\r
- omitHidden = viewport.getViewAsString(true);\r
- }\r
-\r
- String output = new FormatAdapter().formatSequences(\r
- "Fasta",\r
- seqs,\r
- omitHidden);\r
-\r
-\r
- Toolkit.getDefaultToolkit().getSystemClipboard()\r
- .setContents(new StringSelection(output), Desktop.instance);\r
-\r
- Vector hiddenColumns = null;\r
- if(viewport.hasHiddenColumns && viewport.getSelectionGroup()!=null)\r
- {\r
- hiddenColumns =new Vector();\r
- int hiddenOffset = viewport.getSelectionGroup().getStartRes();\r
- for(int i=0; i<viewport.getColumnSelection().getHiddenColumns().size(); i++)\r
- {\r
- int[] region = (int[])\r
- viewport.getColumnSelection().getHiddenColumns().elementAt(i);\r
-\r
- hiddenColumns.addElement(new int[]{region[0]-hiddenOffset,\r
- region[1]-hiddenOffset});\r
- }\r
- }\r
-\r
- Desktop.jalviewClipboard = new Object[]{ seqs,\r
- viewport.alignment.getDataset(),\r
- hiddenColumns};\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void pasteNew_actionPerformed(ActionEvent e)\r
- {\r
- paste(true);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void pasteThis_actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,\r
- HistoryItem.PASTE));\r
- paste(false);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param newAlignment DOCUMENT ME!\r
- */\r
- void paste(boolean newAlignment)\r
- {\r
- try\r
- {\r
- Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();\r
- Transferable contents = c.getContents(this);\r
-\r
- if (contents == null)\r
- {\r
- return;\r
- }\r
-\r
- String str = (String) contents.getTransferData(DataFlavor.stringFlavor);\r
- if(str.length()<1)\r
- return;\r
-\r
- String format = new IdentifyFile().Identify(str, "Paste");\r
- SequenceI[] sequences;\r
-\r
-\r
- if(Desktop.jalviewClipboard!=null)\r
- {\r
- // The clipboard was filled from within Jalview, we must use the sequences\r
- // And dataset from the copied alignment\r
- sequences = (SequenceI[])Desktop.jalviewClipboard[0];\r
- }\r
- else\r
- {\r
- sequences = new FormatAdapter().readFile(str, "Paste", format);\r
- }\r
-\r
- AlignmentI alignment = null;\r
-\r
- if (newAlignment)\r
- {\r
- System.out.println(format +" 2");\r
- alignment = new Alignment(sequences);\r
-\r
- if(Desktop.jalviewClipboard!=null)\r
- alignment.setDataset( (Alignment)Desktop.jalviewClipboard[1] );\r
- else\r
- alignment.setDataset( null );\r
-\r
- }\r
- else\r
- {\r
- System.out.println(format +" 24");\r
- alignment = viewport.getAlignment();\r
-\r
- //!newAlignment\r
- for (int i = 0; i < sequences.length; i++)\r
- {\r
- Sequence newseq = new Sequence(sequences[i].getName(),\r
- sequences[i].getSequence(), sequences[i].getStart(),\r
- sequences[i].getEnd());\r
-\r
- alignment.addSequence(newseq);\r
- }\r
-\r
-\r
- viewport.setEndSeq(alignment.getHeight());\r
- alignment.getWidth();\r
- viewport.firePropertyChange("alignment", null, alignment.getSequences());\r
- }\r
-\r
-\r
-\r
-\r
-\r
- // Add any annotations attached to sequences\r
- for (int i = 0; i < sequences.length; i++)\r
- {\r
- if (sequences[i].getAnnotation() != null)\r
- {\r
- for (int a = 0; a < sequences[i].getAnnotation().length; a++)\r
- {\r
- AlignmentAnnotation newAnnot =\r
- new AlignmentAnnotation(\r
- sequences[i].getAnnotation()[a].label,\r
- sequences[i].getAnnotation()[a].description,\r
- sequences[i].getAnnotation()[a].annotations,\r
- sequences[i].getAnnotation()[a].graphMin,\r
- sequences[i].getAnnotation()[a].graphMax,\r
- sequences[i].getAnnotation()[a].graph);\r
-\r
- sequences[i].getAnnotation()[a] = newAnnot;\r
- newAnnot.sequenceMapping = sequences[i].getAnnotation()[a].\r
- sequenceMapping;\r
- newAnnot.sequenceRef = sequences[i];\r
- newAnnot.adjustForAlignment();\r
- alignment.addAnnotation(newAnnot);\r
- alignment.setAnnotationIndex(newAnnot, a);\r
- }\r
-\r
- alignPanel.annotationPanel.adjustPanelHeight();\r
- }\r
- }\r
-\r
- if(newAlignment)\r
- {\r
- AlignFrame af = new AlignFrame(alignment);\r
- String newtitle = new String("Copied sequences");\r
-\r
- if(Desktop.jalviewClipboard[2]!=null)\r
- {\r
- Vector hc = (Vector)Desktop.jalviewClipboard[2];\r
- for(int i=0; i<hc.size(); i++)\r
- {\r
- int [] region = (int[]) hc.elementAt(i);\r
- af.viewport.hideColumns(region[0], region[1]);\r
- }\r
- }\r
-\r
-\r
- //>>>This is a fix for the moment, until a better solution is found!!<<<\r
- af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(\r
- alignPanel.seqPanel.seqCanvas.getFeatureRenderer());\r
-\r
-\r
- if (title.startsWith("Copied sequences"))\r
- {\r
- newtitle = title;\r
- }\r
- else\r
- {\r
- newtitle = newtitle.concat("- from " + title);\r
- }\r
-\r
- Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH,\r
- NEW_WINDOW_HEIGHT);\r
-\r
- }\r
-\r
-\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- System.out.println("Exception whilst pasting: "+ex);\r
- // could be anything being pasted in here\r
- }\r
-\r
-\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void cut_actionPerformed(ActionEvent e)\r
- {\r
- copy_actionPerformed(null);\r
- delete_actionPerformed(null);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void delete_actionPerformed(ActionEvent e)\r
- {\r
-\r
- if (viewport.getSelectionGroup() == null)\r
- {\r
- return;\r
- }\r
-\r
-\r
- SequenceGroup sg = viewport.getSelectionGroup();\r
-\r
-\r
-\r
- //Jalview no longer allows deletion of residues.\r
- //Check here whether any residues are in selection area\r
- /* if( sg.getEndRes()-sg.getStartRes() < viewport.alignment.getWidth()-1)\r
- {\r
- for (int i = 0; i < sg.sequences.size(); i++)\r
- {\r
- SequenceI seq = sg.getSequenceAt(i);\r
- int j = sg.getStartRes();\r
- do\r
- {\r
- if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))\r
- {\r
- JOptionPane.showInternalMessageDialog(\r
- Desktop.desktop, "Cannot delete residues from alignment!\n"\r
- + "Try hiding columns instead.",\r
- "Deletion of residues not permitted",\r
- JOptionPane.WARNING_MESSAGE);\r
-\r
- return;\r
- }\r
- j++;\r
- }while(j<=sg.getEndRes());\r
- }\r
- }*/\r
-\r
-\r
- addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,\r
- HistoryItem.HIDE));\r
-\r
-\r
- for (int i = 0; i < sg.getSize(false); i++)\r
- {\r
- SequenceI seq = sg.getSequenceAt(i);\r
- int index = viewport.getAlignment().findIndex(seq);\r
-\r
- seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);\r
-\r
- // If the cut affects all sequences, remove highlighted columns\r
- if (sg.getSize(false) == viewport.alignment.getHeight())\r
- {\r
- viewport.getColumnSelection().removeElements(sg.getStartRes(),\r
- sg.getEndRes() + 1);\r
- }\r
-\r
- if (seq.getSequence().length() < 1)\r
- {\r
- viewport.getAlignment().deleteSequence(seq);\r
- }\r
- else\r
- {\r
- viewport.getAlignment().getSequences().setElementAt(seq, index);\r
- }\r
- }\r
-\r
- viewport.setSelectionGroup(null);\r
- viewport.alignment.deleteGroup(sg);\r
-\r
- viewport.firePropertyChange("alignment", null,\r
- viewport.getAlignment().getSequences());\r
-\r
-\r
-\r
- if (viewport.getAlignment().getHeight() < 1)\r
- {\r
- try\r
- {\r
- this.setClosed(true);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void deleteGroups_actionPerformed(ActionEvent e)\r
- {\r
- viewport.alignment.deleteAllGroups();\r
- viewport.setSelectionGroup(null);\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- SequenceGroup sg = new SequenceGroup();\r
-\r
- for (int i = 0; i < viewport.getAlignment().getSequences().size();\r
- i++)\r
- {\r
- sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);\r
- }\r
-\r
- sg.setEndRes(viewport.alignment.getWidth() - 1);\r
- viewport.setSelectionGroup(sg);\r
- PaintRefresher.Refresh(null, viewport.alignment);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- if(viewport.cursorMode)\r
- {\r
- alignPanel.seqPanel.keyboardNo1 = null;\r
- alignPanel.seqPanel.keyboardNo2 = null;\r
- }\r
- viewport.setSelectionGroup(null);\r
- viewport.getColumnSelection().clear();\r
- viewport.setSelectionGroup(null);\r
- alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);\r
- alignPanel.idPanel.idCanvas.searchResults = null;\r
- alignPanel.repaint();\r
- PaintRefresher.Refresh(null, viewport.alignment);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void invertSequenceMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- SequenceGroup sg = viewport.getSelectionGroup();\r
-\r
- if (sg == null)\r
- {\r
- selectAllSequenceMenuItem_actionPerformed(null);\r
-\r
- return;\r
- }\r
-\r
- for (int i = 0; i < viewport.getAlignment().getSequences().size();\r
- i++)\r
- {\r
- sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);\r
- }\r
-\r
- PaintRefresher.Refresh(null, viewport.alignment);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void remove2LeftMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- ColumnSelection colSel = viewport.getColumnSelection();\r
-\r
- if (colSel.size() > 0)\r
- {\r
- addHistoryItem(new HistoryItem("Remove Left", viewport.alignment,\r
- HistoryItem.HIDE));\r
-\r
- int min = colSel.getMin();\r
- viewport.getAlignment().trimLeft(min);\r
- colSel.compensateForEdit(0, min);\r
-\r
- if (viewport.getSelectionGroup() != null)\r
- {\r
- viewport.getSelectionGroup().adjustForRemoveLeft(min);\r
- }\r
-\r
- Vector groups = viewport.alignment.getGroups();\r
-\r
- for (int i = 0; i < groups.size(); i++)\r
- {\r
- SequenceGroup sg = (SequenceGroup) groups.get(i);\r
-\r
- if (!sg.adjustForRemoveLeft(min))\r
- {\r
- viewport.alignment.deleteGroup(sg);\r
- }\r
- }\r
-\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void remove2RightMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- ColumnSelection colSel = viewport.getColumnSelection();\r
-\r
- if (colSel.size() > 0)\r
- {\r
- addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,\r
- HistoryItem.HIDE));\r
-\r
- int max = colSel.getMax();\r
- viewport.getAlignment().trimRight(max);\r
-\r
- if (viewport.getSelectionGroup() != null)\r
- {\r
- viewport.getSelectionGroup().adjustForRemoveRight(max);\r
- }\r
-\r
- Vector groups = viewport.alignment.getGroups();\r
-\r
- for (int i = 0; i < groups.size(); i++)\r
- {\r
- SequenceGroup sg = (SequenceGroup) groups.get(i);\r
-\r
- if (!sg.adjustForRemoveRight(max))\r
- {\r
- viewport.alignment.deleteGroup(sg);\r
- }\r
- }\r
-\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("Remove Gapped Columns",\r
- viewport.alignment, HistoryItem.HIDE));\r
-\r
- //This is to maintain viewport position on first residue\r
- //of first sequence\r
- SequenceI seq = viewport.alignment.getSequenceAt(0);\r
- int startRes = seq.findPosition(viewport.startRes);\r
-\r
- viewport.getAlignment().removeGaps();\r
-\r
- viewport.setStartRes(seq.findIndex(startRes)-1);\r
-\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,\r
- HistoryItem.HIDE));\r
-\r
- //This is to maintain viewport position on first residue\r
- //of first sequence\r
- SequenceI seq = viewport.alignment.getSequenceAt(0);\r
- int startRes = seq.findPosition(viewport.startRes);\r
-\r
-\r
- SequenceI current;\r
- int jSize;\r
-\r
- Vector seqs = null;\r
-\r
- int start = 0;\r
- int end = viewport.alignment.getWidth();\r
-\r
- if (viewport.getSelectionGroup() != null\r
- && viewport.getSelectionGroup().getSequences(true) != null\r
- && viewport.getSelectionGroup().getSize(true) > 0)\r
- {\r
- seqs = viewport.getSelectionGroup().getSequences(true);\r
- start = viewport.getSelectionGroup().getStartRes();\r
- end = viewport.getSelectionGroup().getEndRes()+1;\r
- }\r
- else\r
- {\r
- seqs = viewport.alignment.getSequences();\r
- }\r
-\r
- for (int i = 0; i < seqs.size(); i++)\r
- {\r
- current = (SequenceI) seqs.elementAt(i);\r
- jSize = current.getLength();\r
-\r
- // Removing a range is much quicker than removing gaps\r
- // one by one for long sequences\r
- int j = start;\r
- int rangeStart=-1, rangeEnd=-1;\r
-\r
- do\r
- {\r
- if (jalview.util.Comparison.isGap(current.getCharAt(j)))\r
- {\r
- if(rangeStart==-1)\r
- {\r
- rangeStart = j;\r
- rangeEnd = j+1;\r
- }\r
- else\r
- {\r
- rangeEnd++;\r
- }\r
- j++;\r
- }\r
- else\r
- {\r
- if(rangeStart>-1)\r
- {\r
- current.deleteChars(rangeStart, rangeEnd);\r
- j-=rangeEnd-rangeStart;\r
- jSize-=rangeEnd-rangeStart;\r
- rangeStart = -1;\r
- rangeEnd = -1;\r
- }\r
- else\r
- j++;\r
- }\r
- }\r
- while (j < end && j < jSize);\r
- if(rangeStart>-1)\r
- {\r
- current.deleteChars(rangeStart, rangeEnd);\r
- }\r
- }\r
-\r
- viewport.setStartRes(seq.findIndex(startRes)-1);\r
-\r
- viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
- }\r
-\r
- public void alignmentChanged()\r
- {\r
- if(viewport.padGaps)\r
- viewport.getAlignment().padGaps();\r
-\r
- if(viewport.vconsensus!=null && viewport.autoCalculateConsensus)\r
- {\r
- viewport.updateConsensus();\r
- viewport.updateConservation();\r
- }\r
- resetAllColourSchemes();\r
- if(alignPanel.overviewPanel!=null)\r
- alignPanel.overviewPanel.updateOverviewImage();\r
-\r
- viewport.alignment.adjustSequenceAnnotations();\r
-\r
- alignPanel.repaint();\r
- }\r
-\r
- void resetAllColourSchemes()\r
- {\r
- ColourSchemeI cs = viewport.globalColourScheme;\r
- if(cs!=null)\r
- {\r
- if (cs instanceof ClustalxColourScheme)\r
- {\r
- ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).\r
- resetClustalX(viewport.alignment.getSequences(),\r
- viewport.alignment.getWidth());\r
- }\r
-\r
- cs.setConsensus(viewport.vconsensus);\r
- if (cs.conservationApplied())\r
- {\r
- Alignment al = (Alignment) viewport.alignment;\r
- Conservation c = new Conservation("All",\r
- ResidueProperties.propHash, 3,\r
- al.getSequences(), 0,\r
- al.getWidth() - 1);\r
- c.calculate();\r
- c.verdict(false, viewport.ConsPercGaps);\r
-\r
- cs.setConservation(c);\r
- }\r
- }\r
-\r
- int s, sSize = viewport.alignment.getGroups().size();\r
- for(s=0; s<sSize; s++)\r
- {\r
- SequenceGroup sg = (SequenceGroup)viewport.alignment.getGroups().elementAt(s);\r
- if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)\r
- {\r
- ((ClustalxColourScheme)sg.cs).resetClustalX(\r
- sg.getSequences(true), sg.getWidth());\r
- }\r
- sg.recalcConservation();\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void padGapsMenuitem_actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,\r
- HistoryItem.HIDE));\r
-\r
- viewport.padGaps = padGapsMenuitem.isSelected();\r
-\r
- // if (viewport.padGaps)\r
- alignmentChanged();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void findMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- JInternalFrame frame = new JInternalFrame();\r
- Finder finder = new Finder(viewport, alignPanel, frame);\r
- frame.setContentPane(finder);\r
- frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
- Desktop.addInternalFrame(frame, "Find", 340, 110);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void font_actionPerformed(ActionEvent e)\r
- {\r
- new FontChooser(alignPanel);\r
- }\r
-\r
- public void smoothFont_actionPerformed(ActionEvent e)\r
- {\r
- viewport.antiAlias = smoothFont.isSelected();\r
- alignPanel.annotationPanel.image = null;\r
- alignPanel.repaint();\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void seqLimit_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setShowJVSuffix(seqLimits.isSelected());\r
-\r
- alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());\r
- alignPanel.repaint();\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void colourTextMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setColourText(colourTextMenuItem.isSelected());\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void wrapMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- scaleAbove.setVisible(wrapMenuItem.isSelected());\r
- scaleLeft.setVisible(wrapMenuItem.isSelected());\r
- scaleRight.setVisible(wrapMenuItem.isSelected());\r
- viewport.setWrapAlignment(wrapMenuItem.isSelected());\r
- alignPanel.setWrapAlignment(wrapMenuItem.isSelected());\r
- }\r
-\r
- public void showAllSeqs_actionPerformed(ActionEvent e)\r
- {\r
- viewport.showAllHiddenSeqs();\r
- repaint();\r
- }\r
-\r
- public void showAllColumns_actionPerformed(ActionEvent e)\r
- {\r
- viewport.showAllHiddenColumns();\r
- }\r
-\r
- public void hideSelSequences_actionPerformed(ActionEvent e)\r
- {\r
- if(viewport.getSelectionGroup()==null)\r
- return;\r
-\r
- SequenceI [] seqs = viewport.getSelectionGroup().getSequencesInOrder(\r
- viewport.alignment\r
- );\r
-\r
- for(int i=0; i<seqs.length; i++)\r
- {\r
- viewport.hideSequence(seqs[i]);\r
- }\r
-\r
- alignPanel.repaint();\r
- }\r
-\r
- public void hideSelColumns_actionPerformed(ActionEvent e)\r
- {\r
- viewport.hideSelectedColumns();\r
- alignPanel.repaint();\r
- }\r
-\r
- public void hiddenMarkers_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());\r
- repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void scaleAbove_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setScaleAboveWrapped(scaleAbove.isSelected());\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void scaleLeft_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setScaleLeftWrapped(scaleLeft.isSelected());\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void scaleRight_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setScaleRightWrapped(scaleRight.isSelected());\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void viewBoxesMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setShowBoxes(viewBoxesMenuItem.isSelected());\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void viewTextMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setShowText(viewTextMenuItem.isSelected());\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void renderGapsMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setRenderGaps(renderGapsMenuItem.isSelected());\r
- alignPanel.repaint();\r
- }\r
-\r
-\r
- FeatureSettings featureSettings;\r
- public void featureSettings_actionPerformed(ActionEvent e)\r
- {\r
- if(featureSettings !=null )\r
- {\r
- featureSettings.close();\r
- featureSettings = null;\r
- }\r
- featureSettings = new FeatureSettings(this);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void showSeqFeatures_actionPerformed(ActionEvent evt)\r
- {\r
- viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());\r
- alignPanel.repaint();\r
- if (alignPanel.getOverviewPanel() != null)\r
- {\r
- alignPanel.getOverviewPanel().updateOverviewImage();\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void annotationPanelMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());\r
- alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void overviewMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- if (alignPanel.overviewPanel != null)\r
- {\r
- return;\r
- }\r
-\r
- JInternalFrame frame = new JInternalFrame();\r
- OverviewPanel overview = new OverviewPanel(alignPanel);\r
- frame.setContentPane(overview);\r
- Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),\r
- frame.getWidth(), frame.getHeight());\r
- frame.pack();\r
- frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
- frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
- {\r
- public void internalFrameClosed(\r
- javax.swing.event.InternalFrameEvent evt)\r
- {\r
- alignPanel.setOverviewPanel(null);\r
- }\r
- ;\r
- });\r
-\r
- alignPanel.setOverviewPanel(overview);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void noColourmenuItem_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(null);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void clustalColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new ClustalxColourScheme(\r
- viewport.alignment.getSequences(), viewport.alignment.getWidth()));\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void zappoColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new ZappoColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void taylorColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new TaylorColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void hydrophobicityColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new HydrophobicColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void helixColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new HelixColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void strandColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new StrandColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void turnColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new TurnColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void buriedColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new BuriedColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void nucleotideColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new NucleotideColourScheme());\r
- }\r
-\r
- public void annotationColour_actionPerformed(ActionEvent e)\r
- {\r
- new AnnotationColourChooser(viewport, alignPanel);\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void applyToAllGroups_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param cs DOCUMENT ME!\r
- */\r
- public void changeColour(ColourSchemeI cs)\r
- {\r
- int threshold = 0;\r
-\r
- if(cs!=null)\r
- {\r
- if (viewport.getAbovePIDThreshold())\r
- {\r
- threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,\r
- "Background");\r
-\r
- cs.setThreshold(threshold,\r
- viewport.getIgnoreGapsConsensus());\r
-\r
- viewport.setGlobalColourScheme(cs);\r
- }\r
- else\r
- {\r
- cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
- }\r
-\r
- if (viewport.getConservationSelected())\r
- {\r
-\r
- Alignment al = (Alignment) viewport.alignment;\r
- Conservation c = new Conservation("All",\r
- ResidueProperties.propHash, 3,\r
- al.getSequences(), 0,\r
- al.getWidth() - 1);\r
-\r
- c.calculate();\r
- c.verdict(false, viewport.ConsPercGaps);\r
-\r
- cs.setConservation(c);\r
-\r
- cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,\r
- "Background"));\r
- }\r
- else\r
- {\r
- cs.setConservation(null);\r
- }\r
-\r
- cs.setConsensus(viewport.vconsensus);\r
- }\r
-\r
- viewport.setGlobalColourScheme(cs);\r
-\r
- if (viewport.getColourAppliesToAllGroups())\r
- {\r
- Vector groups = viewport.alignment.getGroups();\r
-\r
- for (int i = 0; i < groups.size(); i++)\r
- {\r
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
-\r
- if (cs == null)\r
- {\r
- sg.cs = null;\r
- continue;\r
- }\r
-\r
- if (cs instanceof ClustalxColourScheme)\r
- {\r
- sg.cs = new ClustalxColourScheme(\r
- sg.getSequences(true), sg.getWidth());\r
- }\r
- else if (cs instanceof UserColourScheme)\r
- {\r
- sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());\r
- }\r
- else\r
- {\r
- try\r
- {\r
- sg.cs = (ColourSchemeI) cs.getClass().newInstance();\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
-\r
- if (viewport.getAbovePIDThreshold()\r
- || cs instanceof PIDColourScheme\r
- || cs instanceof Blosum62ColourScheme)\r
- {\r
- sg.cs.setThreshold(threshold,\r
- viewport.getIgnoreGapsConsensus());\r
-\r
- sg.cs.setConsensus(AAFrequency.calculate(\r
- sg.getSequences(true), 0,\r
- sg.getWidth()));\r
- }\r
- else\r
- sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
-\r
-\r
- if (viewport.getConservationSelected())\r
- {\r
- Conservation c = new Conservation("Group",\r
- ResidueProperties.propHash, 3,\r
- sg.getSequences(true), 0,\r
- viewport.alignment.getWidth() - 1);\r
- c.calculate();\r
- c.verdict(false, viewport.ConsPercGaps);\r
- sg.cs.setConservation(c);\r
- }\r
- else\r
- sg.cs.setConservation(null);\r
- }\r
- }\r
-\r
- if (alignPanel.getOverviewPanel() != null)\r
- {\r
- alignPanel.getOverviewPanel().updateOverviewImage();\r
- }\r
-\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void modifyPID_actionPerformed(ActionEvent e)\r
- {\r
- if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)\r
- {\r
- SliderPanel.setPIDSliderSource(alignPanel,\r
- viewport.getGlobalColourScheme(),\r
- "Background");\r
- SliderPanel.showPIDSlider();\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void modifyConservation_actionPerformed(ActionEvent e)\r
- {\r
- if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)\r
- {\r
- SliderPanel.setConservationSlider(alignPanel,\r
- viewport.globalColourScheme,\r
- "Background");\r
- SliderPanel.showConservationSlider();\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void conservationMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setConservationSelected(conservationMenuItem.isSelected());\r
-\r
- viewport.setAbovePIDThreshold(false);\r
- abovePIDThreshold.setSelected(false);\r
-\r
- changeColour(viewport.getGlobalColourScheme());\r
-\r
- modifyConservation_actionPerformed(null);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void abovePIDThreshold_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());\r
-\r
- conservationMenuItem.setSelected(false);\r
- viewport.setConservationSelected(false);\r
-\r
- changeColour(viewport.getGlobalColourScheme());\r
-\r
- modifyPID_actionPerformed(null);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void userDefinedColour_actionPerformed(ActionEvent e)\r
- {\r
- if (e.getActionCommand().equals("User Defined..."))\r
- {\r
- new UserDefinedColours(alignPanel, null);\r
- }\r
- else\r
- {\r
- UserColourScheme udc = (UserColourScheme) UserDefinedColours.\r
- getUserColourSchemes().get(e.getActionCommand());\r
-\r
- changeColour(udc);\r
- }\r
- }\r
-\r
- public void updateUserColourMenu()\r
- {\r
-\r
- Component[] menuItems = colourMenu.getMenuComponents();\r
- int i, iSize = menuItems.length;\r
- for (i = 0; i < iSize; i++)\r
- {\r
- if (menuItems[i].getName() != null &&\r
- menuItems[i].getName().equals("USER_DEFINED"))\r
- {\r
- colourMenu.remove(menuItems[i]);\r
- iSize--;\r
- }\r
- }\r
- if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)\r
- {\r
- java.util.Enumeration userColours = jalview.gui.UserDefinedColours.\r
- getUserColourSchemes().keys();\r
-\r
- while (userColours.hasMoreElements())\r
- {\r
- final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.\r
- nextElement().toString());\r
- radioItem.setName("USER_DEFINED");\r
- radioItem.addMouseListener(new MouseAdapter()\r
- {\r
- public void mousePressed(MouseEvent evt)\r
- {\r
- if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))\r
- {\r
- radioItem.removeActionListener(radioItem.getActionListeners()[0]);\r
-\r
- int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,\r
- "Remove from default list?",\r
- "Remove user defined colour",\r
- JOptionPane.YES_NO_OPTION);\r
- if(option == JOptionPane.YES_OPTION)\r
- {\r
- jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());\r
- colourMenu.remove(radioItem);\r
- }\r
- else\r
- radioItem.addActionListener(new ActionListener()\r
- {\r
- public void actionPerformed(ActionEvent evt)\r
- {\r
- userDefinedColour_actionPerformed(evt);\r
- }\r
- });\r
- }\r
- }\r
- });\r
- radioItem.addActionListener(new ActionListener()\r
- {\r
- public void actionPerformed(ActionEvent evt)\r
- {\r
- userDefinedColour_actionPerformed(evt);\r
- }\r
- });\r
-\r
- colourMenu.insert(radioItem, 15);\r
- colours.add(radioItem);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void PIDColour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new PIDColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void BLOSUM62Colour_actionPerformed(ActionEvent e)\r
- {\r
- changeColour(new Blosum62ColourScheme());\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,\r
- HistoryItem.SORT));\r
- AlignmentSorter.sortByPID(viewport.getAlignment(),\r
- viewport.getAlignment().getSequenceAt(0));\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void sortIDMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,\r
- HistoryItem.SORT));\r
- AlignmentSorter.sortByID(viewport.getAlignment());\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void sortGroupMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,\r
- HistoryItem.SORT));\r
-\r
- AlignmentSorter.sortByGroup(viewport.getAlignment());\r
- alignPanel.repaint();\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- new RedundancyPanel(alignPanel, this);\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- if ( (viewport.getSelectionGroup() == null) ||\r
- (viewport.getSelectionGroup().getSize(false) < 2))\r
- {\r
- JOptionPane.showInternalMessageDialog(this,\r
- "You must select at least 2 sequences.",\r
- "Invalid Selection",\r
- JOptionPane.WARNING_MESSAGE);\r
- }\r
- else\r
- {\r
- JInternalFrame frame = new JInternalFrame();\r
- frame.setContentPane(new PairwiseAlignPanel(viewport));\r
- Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void PCAMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- if ( ( (viewport.getSelectionGroup() != null) &&\r
- (viewport.getSelectionGroup().getSize(false) < 4) &&\r
- (viewport.getSelectionGroup().getSize(false) > 0)) ||\r
- (viewport.getAlignment().getHeight() < 4))\r
- {\r
- JOptionPane.showInternalMessageDialog(this,\r
- "Principal component analysis must take\n" +\r
- "at least 4 input sequences.",\r
- "Sequence selection insufficient",\r
- JOptionPane.WARNING_MESSAGE);\r
-\r
- return;\r
- }\r
-\r
- new PCAPanel(viewport);\r
- }\r
-\r
-\r
- public void autoCalculate_actionPerformed(ActionEvent e)\r
- {\r
- viewport.autoCalculateConsensus = autoCalculate.isSelected();\r
- if(viewport.autoCalculateConsensus)\r
- {\r
- alignmentChanged();\r
- }\r
- }\r
-\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- NewTreePanel("AV", "PID", "Average distance tree using PID");\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param type DOCUMENT ME!\r
- * @param pwType DOCUMENT ME!\r
- * @param title DOCUMENT ME!\r
- */\r
- void NewTreePanel(String type, String pwType, String title)\r
- {\r
- TreePanel tp;\r
-\r
- if ( (viewport.getSelectionGroup() != null) &&\r
- (viewport.getSelectionGroup().getSize(false) > 3))\r
- {\r
- int s = 0;\r
- SequenceGroup sg = viewport.getSelectionGroup();\r
-\r
- /* Decide if the selection is a column region */\r
- while (s < sg.getSize(false))\r
- {\r
- if ( ( (SequenceI) sg.getSequences(false).elementAt(s++)).getLength() <\r
- sg.getEndRes())\r
- {\r
- JOptionPane.showMessageDialog(Desktop.desktop,\r
- "The selected region to create a tree may\nonly contain residues or gaps.\n" +\r
- "Try using the Pad function in the edit menu,\n" +\r
- "or one of the multiple sequence alignment web services.",\r
- "Sequences in selection are not aligned",\r
- JOptionPane.WARNING_MESSAGE);\r
-\r
- return;\r
- }\r
- }\r
-\r
- title = title + " on region";\r
- tp = new TreePanel(viewport, type, pwType);\r
- }\r
- else\r
- {\r
- //are the sequences aligned?\r
- if (!viewport.alignment.isAligned())\r
- {\r
- JOptionPane.showMessageDialog(Desktop.desktop,\r
- "The sequences must be aligned before creating a tree.\n" +\r
- "Try using the Pad function in the edit menu,\n" +\r
- "or one of the multiple sequence alignment web services.",\r
- "Sequences not aligned",\r
- JOptionPane.WARNING_MESSAGE);\r
-\r
- return;\r
- }\r
-\r
- if(viewport.alignment.getHeight()<2)\r
- return;\r
-\r
- tp = new TreePanel(viewport, type, pwType);\r
- }\r
-\r
- addTreeMenuItem(tp, title);\r
-\r
- Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param title DOCUMENT ME!\r
- * @param order DOCUMENT ME!\r
- */\r
- public void addSortByOrderMenuItem(String title, final AlignmentOrder order)\r
- {\r
- final JMenuItem item = new JMenuItem("by " + title);\r
- sort.add(item);\r
- item.addActionListener(new java.awt.event.ActionListener()\r
- {\r
- public void actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("Sort", viewport.alignment,\r
- HistoryItem.SORT));\r
-\r
- // TODO: JBPNote - have to map order entries to curent SequenceI pointers\r
- AlignmentSorter.sortBy(viewport.getAlignment(), order);\r
- alignPanel.repaint();\r
- }\r
- });\r
- }\r
-\r
- /**\r
- * Maintain the Order by->Displayed Tree menu.\r
- * Creates a new menu item for a TreePanel with an appropriate\r
- * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added\r
- * to remove the menu item when the treePanel is closed, and adjust\r
- * the tree leaf to sequence mapping when the alignment is modified.\r
- * @param treePanel Displayed tree window.\r
- * @param title SortBy menu item title.\r
- */\r
- void addTreeMenuItem(final TreePanel treePanel, String title)\r
- {\r
- final JMenuItem item = new JMenuItem(title);\r
-\r
- treeCount++;\r
-\r
- if (treeCount == 1)\r
- {\r
- sort.add(sortByTreeMenu);\r
- }\r
-\r
- sortByTreeMenu.add(item);\r
- item.addActionListener(new java.awt.event.ActionListener()\r
- {\r
- public void actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem(new HistoryItem("Tree Sort",\r
- viewport.alignment, HistoryItem.SORT));\r
- AlignmentSorter.sortByTree(viewport.getAlignment(),\r
- treePanel.getTree());\r
- alignPanel.repaint();\r
- }\r
- });\r
-\r
- treePanel.addInternalFrameListener(new javax.swing.event.\r
- InternalFrameAdapter()\r
- {\r
- public void internalFrameClosed(\r
- javax.swing.event.InternalFrameEvent evt)\r
- {\r
- treeCount--;\r
- sortByTreeMenu.remove(item);\r
-\r
- if (treeCount == 0)\r
- {\r
- sort.remove(sortByTreeMenu);\r
- }\r
- }\r
- ;\r
- });\r
- }\r
-\r
- /**\r
- * Work out whether the whole set of sequences\r
- * or just the selected set will be submitted for multiple alignment.\r
- *\r
- */\r
- private SequenceI[] gatherSequencesForAlignment()\r
- {\r
- // Now, check we have enough sequences\r
- SequenceI[] msa = null;\r
-\r
- if ( (viewport.getSelectionGroup() != null) &&\r
- (viewport.getSelectionGroup().getSize(false) > 1))\r
- {\r
- // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!\r
- SequenceGroup seqs = viewport.getSelectionGroup();\r
- int sz;\r
- msa = new SequenceI[sz = seqs.getSize(false)];\r
-\r
- for (int i = 0; i < sz; i++)\r
- {\r
- msa[i] = (SequenceI) seqs.getSequenceAt(i);\r
- }\r
- }\r
- else\r
- {\r
- Vector seqs = viewport.getAlignment().getSequences();\r
-\r
- if (seqs.size() > 1)\r
- {\r
- msa = new SequenceI[seqs.size()];\r
-\r
- for (int i = 0; i < seqs.size(); i++)\r
- {\r
- msa[i] = (SequenceI) seqs.elementAt(i);\r
- }\r
- }\r
- }\r
- return msa;\r
- }\r
-\r
- /**\r
- * Decides what is submitted to a secondary structure prediction service,\r
- * the currently selected sequence, or the currently selected alignment\r
- * (where the first sequence in the set is the one that the prediction\r
- * will be for).\r
- */\r
- SequenceI[] gatherSeqOrMsaForSecStrPrediction()\r
- {\r
- SequenceI seq = null;\r
- SequenceI[] msa = null;\r
-\r
- if ( (viewport.getSelectionGroup() != null) &&\r
- (viewport.getSelectionGroup().getSize(false) > 0))\r
- {\r
- // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!\r
- SequenceGroup seqs = viewport.getSelectionGroup();\r
-\r
- if ( (seqs.getSize(false) == 1) || !viewport.alignment.isAligned())\r
- {\r
- seq = (SequenceI) seqs.getSequenceAt(0);\r
- }\r
- else\r
- {\r
- int sz;\r
- msa = new SequenceI[sz = seqs.getSize(false)];\r
-\r
- for (int i = 0; i < sz; i++)\r
- {\r
- msa[i] = (SequenceI) seqs.getSequenceAt(i);\r
- }\r
- }\r
- }\r
- else\r
- {\r
- Vector seqs = viewport.getAlignment().getSequences();\r
-\r
- if ( (seqs.size() == 1) || !viewport.alignment.isAligned())\r
- {\r
- seq = (SequenceI) seqs.elementAt(0);\r
- }\r
- else\r
- {\r
- msa = new SequenceI[seqs.size()];\r
-\r
- for (int i = 0; i < seqs.size(); i++)\r
- {\r
- msa[i] = (SequenceI) seqs.elementAt(i);\r
- }\r
- }\r
- }\r
- if (msa != null)\r
- {\r
- return msa;\r
- }\r
- else\r
- {\r
- if (seq != null)\r
- {\r
- return new SequenceI[]\r
- {\r
- seq};\r
- }\r
- }\r
- return null;\r
- }\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- // Pick the tree file\r
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
- getProperty(\r
- "LAST_DIRECTORY"));\r
- chooser.setFileView(new JalviewFileView());\r
- chooser.setDialogTitle("Select a newick-like tree file");\r
- chooser.setToolTipText("Load a tree file");\r
-\r
- int value = chooser.showOpenDialog(null);\r
-\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
- {\r
- String choice = chooser.getSelectedFile().getPath();\r
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);\r
-\r
- try\r
- {\r
- jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,\r
- "File");\r
- viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());\r
- }\r
- catch (Exception ex)\r
- {\r
- JOptionPane.showMessageDialog(Desktop.desktop,\r
- "Problem reading tree file",\r
- ex.getMessage(),\r
- JOptionPane.WARNING_MESSAGE);\r
- ex.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
-\r
- public TreePanel ShowNewickTree(NewickFile nf, String title)\r
- {\r
- return ShowNewickTree(nf,title,600,500,4,5);\r
- }\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param nf DOCUMENT ME!\r
- * @param title DOCUMENT ME!\r
- *\r
- * @return DOCUMENT ME!\r
- */\r
- public TreePanel ShowNewickTree(NewickFile nf, String title, int w,int h,int x, int y)\r
- {\r
- TreePanel tp = null;\r
-\r
- try\r
- {\r
- nf.parse();\r
-\r
- if (nf.getTree() != null)\r
- {\r
- tp = new TreePanel(viewport,\r
- "FromFile",\r
- title,\r
- nf);\r
-\r
- tp.setSize(w,h);\r
-\r
- if(x>0 && y>0)\r
- tp.setLocation(x,y);\r
-\r
-\r
- Desktop.addInternalFrame(tp, title, w, h);\r
- addTreeMenuItem(tp, title);\r
- }\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
-\r
- return tp;\r
- }\r
-\r
- class PrintThread\r
- extends Thread\r
- {\r
- public void run()\r
- {\r
- PrinterJob printJob = PrinterJob.getPrinterJob();\r
- PageFormat pf = printJob.pageDialog(printJob.defaultPage());\r
- printJob.setPrintable(alignPanel, pf);\r
-\r
- if (printJob.printDialog())\r
- {\r
- try\r
- {\r
- printJob.print();\r
- }\r
- catch (Exception PrintException)\r
- {\r
- PrintException.printStackTrace();\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * Generates menu items and listener event actions for web service clients\r
- *\r
- */\r
- public void BuildWebServiceMenu()\r
- {\r
- if ( (Discoverer.services != null)\r
- && (Discoverer.services.size() > 0))\r
- {\r
- Vector msaws = (Vector) Discoverer.services.get("MsaWS");\r
- Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");\r
- Vector wsmenu = new Vector();\r
- if (msaws != null)\r
- {\r
- // Add any Multiple Sequence Alignment Services\r
- final JMenu msawsmenu = new JMenu("Alignment");\r
- final AlignFrame af = this;\r
- for (int i = 0, j = msaws.size(); i < j; i++)\r
- {\r
- final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.\r
- get(i);\r
- final JMenuItem method = new JMenuItem(sh.getName());\r
- method.addActionListener(new ActionListener()\r
- {\r
- public void actionPerformed(ActionEvent e)\r
- {\r
- SequenceI[] msa = gatherSequencesForAlignment();\r
- new jalview.ws.MsaWSClient(sh, title, msa,\r
- false, true, viewport.getAlignment().getDataset(), af);\r
-\r
- }\r
-\r
- });\r
- msawsmenu.add(method);\r
- // Deal with services that we know accept partial alignments.\r
- if (sh.getName().indexOf("lustal") > -1)\r
- {\r
- // We know that ClustalWS can accept partial alignments for refinement.\r
- final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");\r
- methodR.addActionListener(new ActionListener()\r
- {\r
- public void actionPerformed(ActionEvent e)\r
- {\r
- SequenceI[] msa = gatherSequencesForAlignment();\r
- new jalview.ws.MsaWSClient(sh, title, msa,\r
- true, true, viewport.getAlignment().getDataset(), af);\r
-\r
- }\r
-\r
- });\r
- msawsmenu.add(methodR);\r
-\r
- }\r
- }\r
- wsmenu.add(msawsmenu);\r
- }\r
- if (secstrpr != null)\r
- {\r
- // Add any secondary structure prediction services\r
- final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");\r
- for (int i = 0, j = secstrpr.size(); i < j; i++)\r
- {\r
- final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)\r
- secstrpr.get(i);\r
- final JMenuItem method = new JMenuItem(sh.getName());\r
- method.addActionListener(new ActionListener()\r
- {\r
- public void actionPerformed(ActionEvent e)\r
- {\r
- SequenceI[] msa = gatherSeqOrMsaForSecStrPrediction();\r
- if (msa.length == 1)\r
- {\r
- // Single Sequence prediction\r
- new jalview.ws.JPredClient(sh,title, msa[0]);\r
- }\r
- else\r
- {\r
- if (msa.length > 1)\r
- {\r
- // Single Sequence prediction\r
- jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh,\r
- title, msa);\r
- }\r
- }\r
- }\r
- });\r
- secstrmenu.add(method);\r
- }\r
- wsmenu.add(secstrmenu);\r
- }\r
- this.webService.removeAll();\r
- for (int i = 0, j = wsmenu.size(); i < j; i++)\r
- {\r
- webService.add( (JMenu) wsmenu.get(i));\r
- }\r
- }\r
- else\r
- {\r
- this.webService.removeAll();\r
- this.webService.add(this.webServiceNoServices);\r
- }\r
- // TODO: add in rediscovery function\r
- // TODO: reduce code redundancy.\r
- // TODO: group services by location as well as function.\r
- }\r
-\r
- /* public void vamsasStore_actionPerformed(ActionEvent e)\r
- {\r
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
- getProperty("LAST_DIRECTORY"));\r
-\r
- chooser.setFileView(new JalviewFileView());\r
- chooser.setDialogTitle("Export to Vamsas file");\r
- chooser.setToolTipText("Export");\r
-\r
- int value = chooser.showSaveDialog(this);\r
-\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
- {\r
- jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);\r
- //vs.store(chooser.getSelectedFile().getAbsolutePath() );\r
- vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);\r
- }\r
- }*/\r
-\r
-\r
-\r
-\r
-public void showTranslation_actionPerformed(ActionEvent e)\r
-{\r
- SequenceI [] selection = viewport.getSelectionAsNewSequence();\r
- String [] seqstring = viewport.getViewAsString(true);\r
-\r
- int s, sSize = selection.length;\r
- SequenceI [] newSeq = new SequenceI[sSize];\r
-\r
- int res, resSize;\r
- StringBuffer protein;\r
- String seq;\r
- for(s=0; s<sSize; s++)\r
- {\r
- protein = new StringBuffer();\r
- seq = AlignSeq.extractGaps("-. ", seqstring[s]);\r
- resSize = seq.length();\r
- resSize -= resSize%3;\r
-\r
- for(res = 0; res < resSize; res+=3)\r
- {\r
- String codon = seq.substring(res, res+3);\r
- codon = codon.replace('U', 'T');\r
- String aa = ResidueProperties.codonTranslate(codon);\r
- if(aa==null)\r
- protein.append(viewport.getGapCharacter());\r
- else if(aa.equals("STOP"))\r
- protein.append("X");\r
- else\r
- protein.append( aa );\r
- }\r
- newSeq[s] = new Sequence(selection[s].getName(),\r
- protein.toString());\r
- }\r
-\r
-\r
- AlignmentI al = new Alignment(newSeq);\r
- al.setDataset(null);\r
-\r
-\r
- ////////////////////////////////\r
- // Copy annotations across\r
- jalview.datamodel.AlignmentAnnotation[] annotations\r
- = viewport.alignment.getAlignmentAnnotation();\r
- int a, aSize;\r
- if(annotations!=null)\r
- {\r
- for (int i = 0; i < annotations.length; i++)\r
- {\r
- if (annotations[i].label.equals("Quality") ||\r
- annotations[i].label.equals("Conservation") ||\r
- annotations[i].label.equals("Consensus"))\r
- {\r
- continue;\r
- }\r
-\r
- aSize = viewport.alignment.getWidth() / 3;\r
- jalview.datamodel.Annotation[] anots =\r
- new jalview.datamodel.Annotation[aSize];\r
-\r
- for (a = 0; a < viewport.alignment.getWidth(); a++)\r
- {\r
- if (annotations[i].annotations[a] == null\r
- || annotations[i].annotations[a] == null)\r
- continue;\r
-\r
- anots[a / 3] = new Annotation(\r
- annotations[i].annotations[a].displayCharacter,\r
- annotations[i].annotations[a].description,\r
- annotations[i].annotations[a].secondaryStructure,\r
- annotations[i].annotations[a].value,\r
- annotations[i].annotations[a].colour);\r
- }\r
-\r
- jalview.datamodel.AlignmentAnnotation aa\r
- = new jalview.datamodel.AlignmentAnnotation(annotations[i].label,\r
- annotations[i].description, anots);\r
- al.addAnnotation(aa);\r
- }\r
- }\r
-\r
- AlignFrame af = new AlignFrame(al);\r
- Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),\r
- NEW_WINDOW_WIDTH,\r
- NEW_WINDOW_HEIGHT);\r
-\r
-\r
- // AlignViewport newViewport = new AlignViewport(al);\r
- // AlignmentPanel ap = new AlignmentPanel(this, newViewport);\r
- // tabbedPane.add("Protein", ap);\r
- // viewports.add(newViewport);\r
- // alignPanels.add(ap);\r
-\r
- ///Dataset tab\r
- /////////////////////////\r
-\r
- // AlignViewport ds = new AlignViewport(al.getDataset());\r
- // ds.setDataset(true);\r
- // AlignmentPanel dap = new AlignmentPanel(this, ds);\r
- // tabbedPane.add("Dataset", dap);\r
- // viewports.add(ds);\r
- // alignPanels.add(dap);\r
- /////////////////////////\r
-\r
-\r
-}\r
-\r
-/*public void tabSelected()\r
- {\r
- int index = tabbedPane.getSelectedIndex();\r
- viewport = (AlignViewport)viewports.elementAt(index);\r
- alignPanel = (AlignmentPanel)alignPanels.elementAt(index);\r
- }*/\r
-\r
-/**\r
- * DOCUMENT ME!\r
- *\r
- * @param String DOCUMENT ME!\r
- */\r
-public boolean parseFeaturesFile(String file, String type)\r
-{\r
- boolean featuresFile = false;\r
- try{\r
- featuresFile = new FeaturesFile(file, type).parse(viewport.alignment.getDataset(),\r
- alignPanel.seqPanel.seqCanvas.\r
- getFeatureRenderer().featureColours,\r
- false);\r
- }\r
- catch(Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
-\r
- if(featuresFile)\r
- {\r
- viewport.showSequenceFeatures = true;\r
- showSeqFeatures.setSelected(true);\r
- alignPanel.repaint();\r
- }\r
-\r
- return featuresFile;\r
-}\r
-\r
-public void dragEnter(DropTargetDragEvent evt)\r
-{}\r
-\r
-public void dragExit(DropTargetEvent evt)\r
-{}\r
-\r
-public void dragOver(DropTargetDragEvent evt)\r
-{}\r
-\r
-public void dropActionChanged(DropTargetDragEvent evt)\r
-{}\r
-\r
-public void drop(DropTargetDropEvent evt)\r
-{\r
- Transferable t = evt.getTransferable();\r
- java.util.List files = null;\r
-\r
- try\r
- {\r
- DataFlavor uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");\r
- if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))\r
- {\r
- //Works on Windows and MacOSX\r
- evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);\r
- files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor);\r
- }\r
- else if (t.isDataFlavorSupported(uriListFlavor))\r
- {\r
- // This is used by Unix drag system\r
- evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);\r
- String data = (String) t.getTransferData(uriListFlavor);\r
- files = new java.util.ArrayList(1);\r
- for (java.util.StringTokenizer st = new java.util.StringTokenizer(\r
- data,\r
- "\r\n");\r
- st.hasMoreTokens(); )\r
- {\r
- String s = st.nextToken();\r
- if (s.startsWith("#"))\r
- {\r
- // the line is a comment (as per the RFC 2483)\r
- continue;\r
- }\r
-\r
- java.net.URI uri = new java.net.URI(s);\r
- java.io.File file = new java.io.File(uri);\r
- files.add(file);\r
- }\r
- }\r
- }\r
- catch (Exception e)\r
- {\r
- e.printStackTrace();\r
- }\r
- if (files != null)\r
- {\r
- try\r
- {\r
-\r
- for (int i = 0; i < files.size(); i++)\r
- {\r
- loadJalviewDataFile(files.get(i).toString());\r
- }\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
- }\r
-}\r
-\r
- // This method will attempt to load a "dropped" file first by testing\r
- // whether its and Annotation file, then features file. If both are\r
- // false then the user may have dropped an alignment file onto this\r
- // AlignFrame\r
- public void loadJalviewDataFile(String file)\r
- {\r
- try{\r
- boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.\r
- alignment, file);\r
-\r
- if (!isAnnotation)\r
- {\r
- boolean isGroupsFile = parseFeaturesFile(file,\r
- AppletFormatAdapter.FILE);\r
- if (!isGroupsFile)\r
- {\r
- String format = new IdentifyFile().Identify(file, FormatAdapter.FILE);\r
- new FileLoader().LoadFile(viewport, file, FormatAdapter.FILE, format);\r
- }\r
- }\r
- else\r
- {\r
- // (isAnnotation)\r
- alignPanel.adjustAnnotationHeight();\r
- }\r
-\r
- }catch(Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
- }\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Softwarechang
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.gui;
+
+import java.beans.*;
+import java.io.*;
+import java.util.*;
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.awt.event.*;
+import java.awt.print.*;
+import javax.swing.*;
+import javax.swing.event.MenuEvent;
+
+import jalview.analysis.*;
+import jalview.commands.*;
+import jalview.datamodel.*;
+import jalview.io.*;
+import jalview.jbgui.*;
+import jalview.schemes.*;
+import jalview.ws.*;
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class AlignFrame
+ extends GAlignFrame implements DropTargetListener
+{
+ /** DOCUMENT ME!! */
+ public static final int DEFAULT_WIDTH = 700;
+
+ /** DOCUMENT ME!! */
+ public static final int DEFAULT_HEIGHT = 500;
+ public AlignmentPanel alignPanel;
+
+ AlignViewport viewport;
+
+ Vector alignPanels = new Vector();
+
+
+ /** DOCUMENT ME!! */
+ String currentFileFormat = null;
+
+ String fileName = null;
+
+
+ /**
+ * Creates a new AlignFrame object.
+ *
+ * @param al DOCUMENT ME!
+ */
+ public AlignFrame(AlignmentI al, int width, int height)
+ {
+ this(al, null, width, height);
+ }
+
+
+ /**
+ * new alignment window with hidden columns
+ * @param al AlignmentI
+ * @param hiddenColumns ColumnSelection or null
+ */
+ public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns,
+ int width, int height)
+ {
+ this.setSize(width, height);
+ viewport = new AlignViewport(al, hiddenColumns);
+
+ alignPanel = new AlignmentPanel(this, viewport);
+
+ if(al.getDataset()==null)
+ {
+ al.setDataset(null);
+ }
+
+ addAlignmentPanel(alignPanel, true);
+ init();
+ }
+
+ /**
+ * Make a new AlignFrame from exisiting alignmentPanels
+ * @param ap AlignmentPanel
+ * @param av AlignViewport
+ */
+ public AlignFrame(AlignmentPanel ap)
+ {
+ viewport = ap.av;
+ alignPanel = ap;
+ addAlignmentPanel(ap, false);
+ init();
+ }
+
+ void init()
+ {
+ if (viewport.conservation == null)
+ {
+ BLOSUM62Colour.setEnabled(false);
+ conservationMenuItem.setEnabled(false);
+ modifyConservation.setEnabled(false);
+ // PIDColour.setEnabled(false);
+ // abovePIDThreshold.setEnabled(false);
+ // modifyPID.setEnabled(false);
+ }
+
+ String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", "No sort");
+
+ if (sortby.equals("Id"))
+ {
+ sortIDMenuItem_actionPerformed(null);
+ }
+ else if (sortby.equals("Pairwise Identity"))
+ {
+ sortPairwiseMenuItem_actionPerformed(null);
+ }
+
+ if (Desktop.desktop != null)
+ {
+ this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
+ addServiceListeners();
+ setGUINucleotide(viewport.alignment.isNucleotide());
+ }
+
+ setMenusFromViewport(viewport);
+ buildSortByAnnotationScoresMenu();
+ if (viewport.wrapAlignment)
+ {
+ wrapMenuItem_actionPerformed(null);
+ }
+
+ if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW",false))
+ {
+ this.overviewMenuItem_actionPerformed(null);
+ }
+
+ addKeyListener();
+
+ }
+
+ public void setFileName(String file, String format)
+ {
+ fileName = file;
+ currentFileFormat = format;
+ reload.setEnabled(true);
+ }
+
+ void addKeyListener()
+ {
+ addKeyListener(new KeyAdapter()
+ {
+ public void keyPressed(KeyEvent evt)
+ {
+ if (viewport.cursorMode &&
+ ( (evt.getKeyCode() >= KeyEvent.VK_0 &&
+ evt.getKeyCode() <= KeyEvent.VK_9)
+ ||
+ (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0 &&
+ evt.getKeyCode() <= KeyEvent.VK_NUMPAD9)
+ )
+ && Character.isDigit(evt.getKeyChar()))
+ alignPanel.seqPanel.numberPressed(evt.getKeyChar());
+
+ switch (evt.getKeyCode())
+ {
+
+ case 27: // escape key
+ deselectAllSequenceMenuItem_actionPerformed(null);
+
+ break;
+
+ case KeyEvent.VK_DOWN:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ moveSelectedSequences(false);
+ if (viewport.cursorMode)
+ alignPanel.seqPanel.moveCursor(0, 1);
+ break;
+
+ case KeyEvent.VK_UP:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ moveSelectedSequences(true);
+ if (viewport.cursorMode)
+ alignPanel.seqPanel.moveCursor(0, -1);
+
+ break;
+
+ case KeyEvent.VK_LEFT:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ slideSequences(false,
+ alignPanel.seqPanel.getKeyboardNo1());
+ else
+ alignPanel.seqPanel.moveCursor( -1, 0);
+
+
+ break;
+
+ case KeyEvent.VK_RIGHT:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ slideSequences(true,
+ alignPanel.seqPanel.getKeyboardNo1());
+ else
+ alignPanel.seqPanel.moveCursor(1, 0);
+ break;
+
+ case KeyEvent.VK_SPACE:
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
+ || evt.isShiftDown()
+ || evt.isAltDown());
+ }
+ break;
+
+ case KeyEvent.VK_DELETE:
+ case KeyEvent.VK_BACK_SPACE:
+ if (!viewport.cursorMode)
+ {
+ cut_actionPerformed(null);
+ }
+ else
+ {
+ alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
+ || evt.isShiftDown()
+ || evt.isAltDown());
+ }
+
+ break;
+
+ case KeyEvent.VK_S:
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setCursorRow();
+ }
+ break;
+ case KeyEvent.VK_C:
+ if (viewport.cursorMode && !evt.isControlDown())
+ {
+ alignPanel.seqPanel.setCursorColumn();
+ }
+ break;
+ case KeyEvent.VK_P:
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setCursorPosition();
+ }
+ break;
+
+ case KeyEvent.VK_ENTER:
+ case KeyEvent.VK_COMMA:
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setCursorRowAndColumn();
+ }
+ break;
+
+ case KeyEvent.VK_Q:
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setSelectionAreaAtCursor(true);
+ }
+ break;
+ case KeyEvent.VK_M:
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.setSelectionAreaAtCursor(false);
+ }
+ break;
+
+ case KeyEvent.VK_F2:
+ viewport.cursorMode = !viewport.cursorMode;
+ statusBar.setText("Keyboard editing mode is " +
+ (viewport.cursorMode ? "on" : "off"));
+ if (viewport.cursorMode)
+ {
+ alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
+ alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
+ }
+ alignPanel.seqPanel.seqCanvas.repaint();
+ break;
+
+ case KeyEvent.VK_F1:
+ try
+ {
+ ClassLoader cl = jalview.gui.Desktop.class.getClassLoader();
+ java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help");
+ javax.help.HelpSet hs = new javax.help.HelpSet(cl, url);
+
+ javax.help.HelpBroker hb = hs.createHelpBroker();
+ hb.setCurrentID("home");
+ hb.setDisplayed(true);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ break
+ ;
+ case KeyEvent.VK_H:
+ {
+ boolean toggleSeqs = !evt.isControlDown();
+ boolean toggleCols = !evt.isShiftDown();
+
+ boolean hide = false;
+
+ SequenceGroup sg = viewport.getSelectionGroup();
+ if (toggleSeqs)
+ {
+ if (sg != null && sg.getSize() != viewport.alignment.getHeight())
+ {
+ hideSelSequences_actionPerformed(null);
+ hide = true;
+ }
+ else if (! (toggleCols &&
+ viewport.colSel.getSelected().size() > 0))
+ {
+ showAllSeqs_actionPerformed(null);
+ }
+ }
+
+ if (toggleCols)
+ {
+ if (viewport.colSel.getSelected().size() > 0)
+ {
+ hideSelColumns_actionPerformed(null);
+ if (!toggleSeqs)
+ {
+ viewport.selectionGroup = sg;
+ }
+ }
+ else if (!hide)
+ {
+ showAllColumns_actionPerformed(null);
+ }
+ }
+ break;
+ }
+ case KeyEvent.VK_PAGE_UP:
+ if (viewport.wrapAlignment)
+ {
+ alignPanel.scrollUp(true);
+ }
+ else
+ {
+ alignPanel.setScrollValues(viewport.startRes,
+ viewport.startSeq
+ - viewport.endSeq + viewport.startSeq);
+ }
+ break;
+ case KeyEvent.VK_PAGE_DOWN:
+ if (viewport.wrapAlignment)
+ {
+ alignPanel.scrollUp(false);
+ }
+ else
+ {
+ alignPanel.setScrollValues(viewport.startRes,
+ viewport.startSeq
+ + viewport.endSeq - viewport.startSeq);
+ }
+ break;
+ }
+ }
+
+ public void keyReleased(KeyEvent evt)
+ {
+ switch(evt.getKeyCode())
+ {
+ case KeyEvent.VK_LEFT:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+ break;
+
+ case KeyEvent.VK_RIGHT:
+ if (evt.isAltDown() || !viewport.cursorMode)
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+ break;
+ }
+ }
+ });
+ }
+
+
+ public void addAlignmentPanel(final AlignmentPanel ap,
+ boolean newPanel)
+ {
+ ap.alignFrame = this;
+
+ alignPanels.addElement(ap);
+
+ PaintRefresher.Register(ap, ap.av.getSequenceSetId());
+
+ int aSize = alignPanels.size();
+
+ tabbedPane.setVisible(aSize>1 || ap.av.viewName!=null);
+
+ if (aSize == 1 && ap.av.viewName==null)
+ {
+ this.getContentPane().add(ap, BorderLayout.CENTER);
+ }
+ else
+ {
+ if (aSize == 2)
+ {
+ setInitialTabVisible();
+ }
+
+ expandViews.setEnabled(true);
+ gatherViews.setEnabled(true);
+ tabbedPane.addTab(ap.av.viewName, ap);
+
+ ap.setVisible(false);
+ }
+
+ if(newPanel)
+ {
+ if (ap.av.padGaps)
+ {
+ ap.av.alignment.padGaps();
+ }
+ ap.av.updateConservation(ap);
+ ap.av.updateConsensus(ap);
+ }
+ }
+
+ public void setInitialTabVisible()
+ {
+ expandViews.setEnabled(true);
+ gatherViews.setEnabled(true);
+ tabbedPane.setVisible(true);
+ AlignmentPanel first = (AlignmentPanel) alignPanels.firstElement();
+ tabbedPane.addTab(first.av.viewName,first);
+ this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
+ }
+
+
+ public AlignViewport getViewport()
+ {
+ return viewport;
+ }
+
+ /* Set up intrinsic listeners for dynamically generated GUI bits. */
+ private void addServiceListeners()
+ {
+ final java.beans.PropertyChangeListener thisListener;
+ // Do this once to get current state
+ BuildWebServiceMenu();
+ Desktop.discoverer.addPropertyChangeListener(
+ thisListener = new java.beans.PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ // System.out.println("Discoverer property change.");
+ if (evt.getPropertyName().equals("services"))
+ {
+ // System.out.println("Rebuilding web service menu");
+ BuildWebServiceMenu();
+ }
+ }
+ });
+
+ addInternalFrameListener(new javax.swing.event.
+ InternalFrameAdapter()
+ {
+ public void internalFrameClosed(
+ javax.swing.event.InternalFrameEvent evt)
+ {
+ // System.out.println("deregistering discoverer listener");
+ Desktop.discoverer.removePropertyChangeListener(thisListener);
+ closeMenuItem_actionPerformed(true);
+ }
+ ;
+ });
+ }
+
+ public void setGUINucleotide(boolean nucleotide)
+ {
+ showTranslation.setVisible( nucleotide );
+ conservationMenuItem.setEnabled( !nucleotide );
+ modifyConservation.setEnabled( !nucleotide );
+
+ //Remember AlignFrame always starts as protein
+ if(!nucleotide)
+ {
+ calculateMenu.remove(calculateMenu.getItemCount()-2);
+ }
+ }
+
+ /**
+ * Need to call this method when tabs are selected for multiple views,
+ * or when loading from Jalview2XML.java
+ * @param av AlignViewport
+ */
+ void setMenusFromViewport(AlignViewport av)
+ {
+ padGapsMenuitem.setSelected(av.padGaps);
+ colourTextMenuItem.setSelected(av.showColourText);
+ abovePIDThreshold.setSelected(av.getAbovePIDThreshold());
+ conservationMenuItem.setSelected(av.getConservationSelected());
+ seqLimits.setSelected(av.getShowJVSuffix());
+ idRightAlign.setSelected(av.rightAlignIds);
+ renderGapsMenuItem.setSelected(av.renderGaps);
+ wrapMenuItem.setSelected(av.wrapAlignment);
+ scaleAbove.setVisible(av.wrapAlignment);
+ scaleLeft.setVisible(av.wrapAlignment);
+ scaleRight.setVisible(av.wrapAlignment);
+ annotationPanelMenuItem.setState(av.showAnnotation);
+ viewBoxesMenuItem.setSelected(av.showBoxes);
+ viewTextMenuItem.setSelected(av.showText);
+
+ setColourSelected(ColourSchemeProperty.
+ getColourName(av.getGlobalColourScheme()));
+
+ showSeqFeatures.setSelected(av.showSequenceFeatures);
+ hiddenMarkers.setState(av.showHiddenMarkers);
+ applyToAllGroups.setState(av.colourAppliesToAllGroups);
+
+ updateEditMenuBar();
+ }
+
+
+ Hashtable progressBars;
+ public void setProgressBar(String message, long id)
+ {
+ if(progressBars == null)
+ {
+ progressBars = new Hashtable();
+ }
+
+ JPanel progressPanel;
+ GridLayout layout = (GridLayout) statusPanel.getLayout();
+ if(progressBars.get( new Long(id) )!=null)
+ {
+ progressPanel = (JPanel)progressBars.get( new Long(id) );
+ statusPanel.remove(progressPanel);
+ progressBars.remove( progressPanel );
+ progressPanel = null;
+ if(message!=null)
+ {
+ statusBar.setText(message);
+ }
+
+ layout.setRows(layout.getRows() - 1);
+ }
+ else
+ {
+ progressPanel = new JPanel(new BorderLayout(10, 5));
+
+ JProgressBar progressBar = new JProgressBar();
+ progressBar.setIndeterminate(true);
+
+ progressPanel.add(new JLabel(message), BorderLayout.WEST);
+ progressPanel.add(progressBar, BorderLayout.CENTER);
+
+ layout.setRows(layout.getRows() + 1);
+ statusPanel.add(progressPanel);
+
+ progressBars.put(new Long(id), progressPanel);
+ }
+
+ validate();
+ }
+
+
+
+
+ /*
+ Added so Castor Mapping file can obtain Jalview Version
+ */
+ public String getVersion()
+ {
+ return jalview.bin.Cache.getProperty("VERSION");
+ }
+
+ public FeatureRenderer getFeatureRenderer()
+ {
+ return alignPanel.seqPanel.seqCanvas.getFeatureRenderer();
+ }
+
+
+ public void fetchSequence_actionPerformed(ActionEvent e)
+ {
+ new SequenceFetcher(this);
+ }
+
+ public void addFromFile_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.inputLocalFileMenuItem_actionPerformed(viewport);
+ }
+
+ public void reload_actionPerformed(ActionEvent e)
+ {
+ if(fileName!=null)
+ {
+ if(currentFileFormat.equals("Jalview"))
+ {
+ JInternalFrame [] frames = Desktop.desktop.getAllFrames();
+ for(int i=0; i<frames.length; i++)
+ {
+ if (frames[i] instanceof AlignFrame
+ && frames[i] != this
+ && ( (AlignFrame) frames[i]).fileName.equals(fileName))
+ {
+ try
+ {
+ frames[i].setSelected(true);
+ Desktop.instance.closeAssociatedWindows();
+ }
+ catch (java.beans.PropertyVetoException ex)
+ {}
+ }
+
+ }
+ Desktop.instance.closeAssociatedWindows();
+
+ FileLoader loader = new FileLoader();
+ String protocol = fileName.startsWith("http:")? "URL":"File";
+ loader.LoadFile(viewport, fileName, protocol, currentFileFormat);
+ }
+ else
+ {
+ Rectangle bounds = this.getBounds();
+
+ FileLoader loader = new FileLoader();
+ String protocol = fileName.startsWith("http:") ? "URL" : "File";
+ AlignFrame newframe =
+ loader.LoadFileWaitTillLoaded(fileName, protocol, currentFileFormat);
+
+ newframe.setBounds(bounds);
+
+ this.closeMenuItem_actionPerformed(true);
+ }
+ }
+ }
+
+
+ public void addFromText_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport);
+ }
+
+ public void addFromURL_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.inputURLMenuItem_actionPerformed(viewport);
+ }
+
+
+ public void save_actionPerformed(ActionEvent e)
+ {
+ if(fileName==null
+ || currentFileFormat==null
+ || fileName.startsWith("http")
+ )
+ {
+ saveAs_actionPerformed(null);
+ }
+ else
+ {
+ saveAlignment(fileName, currentFileFormat);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void saveAs_actionPerformed(ActionEvent e)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ getProperty( "LAST_DIRECTORY"),
+ new String[]
+ { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","jar" },
+ new String[]
+ { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
+ currentFileFormat,
+ false);
+
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Save Alignment to file");
+ chooser.setToolTipText("Save");
+
+ int value = chooser.showSaveDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ currentFileFormat = chooser.getSelectedFormat();
+ if (currentFileFormat == null)
+ {
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "You must select a file format before saving!",
+ "File format not specified",
+ JOptionPane.WARNING_MESSAGE);
+ value = chooser.showSaveDialog(this);
+ return;
+ }
+
+ fileName = chooser.getSelectedFile().getPath();
+
+ jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",
+ currentFileFormat);
+
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", fileName);
+
+ saveAlignment(fileName, currentFileFormat);
+ }
+ }
+
+ public boolean saveAlignment(String file, String format)
+ {
+ boolean success = true;
+
+ if (format.equalsIgnoreCase("Jalview"))
+ {
+ String shortName = title;
+
+ if (shortName.indexOf(java.io.File.separatorChar) > -1)
+ {
+ shortName = shortName.substring(shortName.lastIndexOf(
+ java.io.File.separatorChar) + 1);
+ }
+
+ success = new Jalview2XML().SaveAlignment(this, file, shortName);
+
+ statusBar.setText("Successfully saved to file: "
+ +fileName+" in "
+ +format +" format.");
+
+ }
+ else
+ {
+
+ String[] omitHidden = null;
+
+ if (viewport.hasHiddenColumns)
+ {
+ int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+ "The Alignment contains hidden columns."
+ + "\nDo you want to save only the visible alignment?",
+ "Save / Omit Hidden Columns",
+ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+
+ if (reply == JOptionPane.YES_OPTION)
+ {
+ omitHidden = viewport.getViewAsString(false);
+ }
+ }
+
+ String output = new FormatAdapter().formatSequences(
+ format,
+ viewport.alignment.getSequencesArray(),
+ omitHidden);
+
+ if (output == null)
+ {
+ success = false;
+ }
+ else
+ {
+ try
+ {
+ java.io.PrintWriter out = new java.io.PrintWriter(
+ new java.io.FileWriter(file));
+
+ out.print(output);
+ out.close();
+ this.setTitle(file);
+ statusBar.setText("Successfully saved to file: "
+ + fileName + " in "
+ + format + " format.");
+ }
+ catch (Exception ex)
+ {
+ success = false;
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ if (!success)
+ {
+ JOptionPane.showInternalMessageDialog(
+ this, "Couldn't save file: " + fileName,
+ "Error Saving File",
+ JOptionPane.WARNING_MESSAGE);
+ }
+
+ return success;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void outputText_actionPerformed(ActionEvent e)
+ {
+ String [] omitHidden = null;
+
+ if(viewport.hasHiddenColumns)
+ {
+ int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+ "The Alignment contains hidden columns."
+ +"\nDo you want to output only the visible alignment?",
+ "Save / Omit Hidden Columns",
+ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+
+ if(reply==JOptionPane.YES_OPTION)
+ {
+ omitHidden = viewport.getViewAsString(false);
+ }
+ }
+
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ cap.setForInput(null);
+ Desktop.addInternalFrame(cap,
+ "Alignment output - " + e.getActionCommand(), 600,
+ 500);
+
+
+ cap.setText(new FormatAdapter().formatSequences(
+ e.getActionCommand(),
+ viewport.alignment.getSequencesArray(),
+ omitHidden));
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void htmlMenuItem_actionPerformed(ActionEvent e)
+ {
+ new HTMLOutput(alignPanel,
+ alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
+ alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
+ }
+
+ public void createImageMap(File file, String image)
+ {
+ alignPanel.makePNGImageMap(file, image);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void createPNG(File f)
+ {
+ alignPanel.makePNG(f);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void createEPS(File f)
+ {
+ alignPanel.makeEPS(f);
+ }
+
+
+ public void pageSetup_actionPerformed(ActionEvent e)
+ {
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+ PrintThread.pf = printJob.pageDialog(printJob.defaultPage());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void printMenuItem_actionPerformed(ActionEvent e)
+ {
+ //Putting in a thread avoids Swing painting problems
+ PrintThread thread = new PrintThread(alignPanel);
+ thread.start();
+ }
+
+ public void exportFeatures_actionPerformed(ActionEvent e)
+ {
+ new AnnotationExporter().exportFeatures(alignPanel);
+ }
+
+
+ public void exportAnnotations_actionPerformed(ActionEvent e)
+ {
+ new AnnotationExporter().exportAnnotations(
+ alignPanel,
+ viewport.showAnnotation ? viewport.alignment.getAlignmentAnnotation() : null,
+ viewport.alignment.getGroups(),
+ ((Alignment)viewport.alignment).alignmentProperties
+ );
+ }
+
+
+ public void associatedData_actionPerformed(ActionEvent e)
+ {
+ // Pick the tree file
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ getProperty(
+ "LAST_DIRECTORY"));
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Load Jalview Annotations or Features File");
+ chooser.setToolTipText("Load Jalview Annotations / Features file");
+
+ int value = chooser.showOpenDialog(null);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ String choice = chooser.getSelectedFile().getPath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+ loadJalviewDataFile(choice);
+ }
+
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void closeMenuItem_actionPerformed(boolean closeAllTabs)
+ {
+ if(alignPanels!=null && alignPanels.size()<2)
+ {
+ closeAllTabs = true;
+ }
+
+ try
+ {
+ if(alignPanels!=null)
+ {
+ if (closeAllTabs)
+ {
+ for (int i = 0; i < alignPanels.size(); i++)
+ {
+ AlignmentPanel ap = (AlignmentPanel) alignPanels.elementAt(i);
+ jalview.structure.StructureSelectionManager.getStructureSelectionManager()
+ .removeStructureViewerListener(ap.seqPanel, null);
+ PaintRefresher.RemoveComponent(ap.seqPanel.seqCanvas);
+ PaintRefresher.RemoveComponent(ap.idPanel.idCanvas);
+ PaintRefresher.RemoveComponent(ap);
+ ap.av.alignment = null;
+ }
+ }
+ else
+ {
+ int index = tabbedPane.getSelectedIndex();
+
+ alignPanels.removeElement(alignPanel);
+ PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
+ PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
+ PaintRefresher.RemoveComponent(alignPanel);
+ viewport.alignment = null;
+ alignPanel = null;
+ viewport = null;
+
+ tabbedPane.removeTabAt(index);
+ tabbedPane.validate();
+
+ if(index==tabbedPane.getTabCount())
+ {
+ index --;
+ }
+
+ this.tabSelectionChanged(index);
+ }
+ }
+
+ if (closeAllTabs)
+ {
+ this.setClosed(true);
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ */
+ void updateEditMenuBar()
+ {
+
+ if (viewport.historyList.size() > 0)
+ {
+ undoMenuItem.setEnabled(true);
+ CommandI command = (CommandI) viewport.historyList.peek();
+ undoMenuItem.setText("Undo " + command.getDescription());
+ }
+ else
+ {
+ undoMenuItem.setEnabled(false);
+ undoMenuItem.setText("Undo");
+ }
+
+ if (viewport.redoList.size() > 0)
+ {
+ redoMenuItem.setEnabled(true);
+
+ CommandI command = (CommandI) viewport.redoList.peek();
+ redoMenuItem.setText("Redo " + command.getDescription());
+ }
+ else
+ {
+ redoMenuItem.setEnabled(false);
+ redoMenuItem.setText("Redo");
+ }
+ }
+
+
+ public void addHistoryItem(CommandI command)
+ {
+ if(command.getSize()>0)
+ {
+ viewport.historyList.push(command);
+ viewport.redoList.clear();
+ updateEditMenuBar();
+ viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
+ }
+ }
+
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void undoMenuItem_actionPerformed(ActionEvent e)
+ {
+ CommandI command = (CommandI)viewport.historyList.pop();
+ viewport.redoList.push(command);
+ command.undoCommand();
+
+ AlignViewport originalSource = getOriginatingSource(command);
+ updateEditMenuBar();
+
+ if(originalSource!=null)
+ {
+ originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
+ originalSource.firePropertyChange("alignment",
+ null,
+ originalSource.alignment.getSequences());
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void redoMenuItem_actionPerformed(ActionEvent e)
+ {
+ if(viewport.redoList.size()<1)
+ {
+ return;
+ }
+
+ CommandI command = (CommandI) viewport.redoList.pop();
+ viewport.historyList.push(command);
+ command.doCommand();
+
+ AlignViewport originalSource = getOriginatingSource(command);
+ updateEditMenuBar();
+
+ if(originalSource!=null)
+ {
+ originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null;
+ originalSource.firePropertyChange("alignment",
+ null,
+ originalSource.alignment.getSequences());
+ }
+ }
+
+ AlignViewport getOriginatingSource(CommandI command)
+ {
+ AlignViewport originalSource = null;
+ //For sequence removal and addition, we need to fire
+ //the property change event FROM the viewport where the
+ //original alignment was altered
+ AlignmentI al=null;
+ if (command instanceof EditCommand)
+ {
+ EditCommand editCommand = (EditCommand) command;
+ al = editCommand.getAlignment();
+ Vector comps = (Vector) PaintRefresher.components
+ .get(viewport.getSequenceSetId());
+
+ for (int i = 0; i < comps.size(); i++)
+ {
+ if (comps.elementAt(i) instanceof AlignmentPanel)
+ {
+ if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment)
+ {
+ originalSource = ( (AlignmentPanel) comps.elementAt(i)).av;
+ break;
+ }
+ }
+ }
+ }
+
+ if (originalSource == null)
+ {
+ //The original view is closed, we must validate
+ //the current view against the closed view first
+ if (al != null)
+ {
+ PaintRefresher.validateSequences(al, viewport.alignment);
+ }
+
+ originalSource = viewport;
+ }
+
+ return originalSource;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param up DOCUMENT ME!
+ */
+ public void moveSelectedSequences(boolean up)
+ {
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+ if (sg == null)
+ {
+ return;
+ }
+
+ if (up)
+ {
+ for (int i = 1; i < viewport.alignment.getHeight(); i++)
+ {
+ SequenceI seq = viewport.alignment.getSequenceAt(i);
+
+ if (!sg.getSequences(null).contains(seq))
+ {
+ continue;
+ }
+
+ SequenceI temp = viewport.alignment.getSequenceAt(i - 1);
+
+ if (sg.getSequences(null).contains(temp))
+ {
+ continue;
+ }
+
+ viewport.alignment.getSequences().setElementAt(temp, i);
+ viewport.alignment.getSequences().setElementAt(seq, i - 1);
+ }
+ }
+ else
+ {
+ for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)
+ {
+ SequenceI seq = viewport.alignment.getSequenceAt(i);
+
+ if (!sg.getSequences(null).contains(seq))
+ {
+ continue;
+ }
+
+ SequenceI temp = viewport.alignment.getSequenceAt(i + 1);
+
+ if (sg.getSequences(null).contains(temp))
+ {
+ continue;
+ }
+
+ viewport.alignment.getSequences().setElementAt(temp, i);
+ viewport.alignment.getSequences().setElementAt(seq, i + 1);
+ }
+ }
+
+ alignPanel.paintAlignment(true);
+ }
+
+
+
+
+ synchronized void slideSequences(boolean right, int size)
+ {
+ Vector sg = new Vector();
+ if(viewport.cursorMode)
+ {
+ sg.addElement(viewport.alignment.getSequenceAt(
+ alignPanel.seqPanel.seqCanvas.cursorY));
+ }
+ else if(viewport.getSelectionGroup()!=null
+ && viewport.getSelectionGroup().getSize()!=viewport.alignment.getHeight())
+ {
+ sg = viewport.getSelectionGroup().getSequences(
+ viewport.hiddenRepSequences);
+ }
+
+ if(sg.size()<1)
+ {
+ return;
+ }
+
+ Vector invertGroup = new Vector();
+
+ for (int i = 0; i < viewport.alignment.getHeight(); i++)
+ {
+ if(!sg.contains(viewport.alignment.getSequenceAt(i)))
+ invertGroup.add(viewport.alignment.getSequenceAt(i));
+ }
+
+ SequenceI[] seqs1 = new SequenceI[sg.size()];
+ for (int i = 0; i < sg.size(); i++)
+ seqs1[i] = (SequenceI) sg.elementAt(i);
+
+ SequenceI[] seqs2 = new SequenceI[invertGroup.size()];
+ for (int i = 0; i < invertGroup.size(); i++)
+ seqs2[i] = (SequenceI) invertGroup.elementAt(i);
+
+ SlideSequencesCommand ssc;
+ if (right)
+ ssc = new SlideSequencesCommand("Slide Sequences",
+ seqs2, seqs1, size,
+ viewport.getGapCharacter()
+ );
+ else
+ ssc = new SlideSequencesCommand("Slide Sequences",
+ seqs1, seqs2, size,
+ viewport.getGapCharacter()
+ );
+
+ int groupAdjustment = 0;
+ if (ssc.getGapsInsertedBegin() && right)
+ {
+ if (viewport.cursorMode)
+ alignPanel.seqPanel.moveCursor(size, 0);
+ else
+ groupAdjustment = size;
+ }
+ else if (!ssc.getGapsInsertedBegin() && !right)
+ {
+ if (viewport.cursorMode)
+ alignPanel.seqPanel.moveCursor( -size, 0);
+ else
+ groupAdjustment = -size;
+ }
+
+ if (groupAdjustment != 0)
+ {
+ viewport.getSelectionGroup().setStartRes(
+ viewport.getSelectionGroup().getStartRes() + groupAdjustment);
+ viewport.getSelectionGroup().setEndRes(
+ viewport.getSelectionGroup().getEndRes() + groupAdjustment);
+ }
+
+
+ boolean appendHistoryItem = false;
+ if(viewport.historyList!=null
+ && viewport.historyList.size()>0
+ && viewport.historyList.peek() instanceof SlideSequencesCommand)
+ {
+ appendHistoryItem = ssc.appendSlideCommand(
+ (SlideSequencesCommand)viewport.historyList.peek())
+ ;
+ }
+
+ if(!appendHistoryItem)
+ addHistoryItem(ssc);
+
+ repaint();
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void copy_actionPerformed(ActionEvent e)
+ {
+ System.gc();
+ if (viewport.getSelectionGroup() == null)
+ {
+ return;
+ }
+ // TODO: preserve the ordering of displayed alignment annotation in any internal paste (particularly sequence associated annotation)
+ SequenceI [] seqs = viewport.getSelectionAsNewSequence();
+ String[] omitHidden = null;
+
+ if (viewport.hasHiddenColumns)
+ {
+ omitHidden = viewport.getViewAsString(true);
+ }
+
+ String output = new FormatAdapter().formatSequences(
+ "Fasta",
+ seqs,
+ omitHidden);
+
+ StringSelection ss = new StringSelection(output);
+
+ try
+ {
+ jalview.gui.Desktop.internalCopy = true;
+ //Its really worth setting the clipboard contents
+ //to empty before setting the large StringSelection!!
+ Toolkit.getDefaultToolkit().getSystemClipboard()
+ .setContents(new StringSelection(""), null);
+
+ Toolkit.getDefaultToolkit().getSystemClipboard()
+ .setContents(ss, Desktop.instance);
+ }
+ catch (OutOfMemoryError er)
+ {
+ er.printStackTrace();
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Out of memory copying region!!"
+ +
+ "\nSee help files for increasing Java Virtual Machine memory."
+ , "Out of memory",
+ javax.swing.JOptionPane.WARNING_MESSAGE);
+ }
+ });
+
+ return;
+ }
+
+ Vector hiddenColumns = null;
+ if(viewport.hasHiddenColumns)
+ {
+ hiddenColumns =new Vector();
+ int hiddenOffset = viewport.getSelectionGroup().getStartRes();
+ for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size();
+ i++)
+ {
+ int[] region = (int[])
+ viewport.getColumnSelection().getHiddenColumns().elementAt(i);
+
+ hiddenColumns.addElement(new int[]
+ {region[0] - hiddenOffset,
+ region[1]-hiddenOffset});
+ }
+ }
+
+ Desktop.jalviewClipboard = new Object[]
+ {
+ seqs,
+ viewport.alignment.getDataset(),
+ hiddenColumns};
+ statusBar.setText("Copied "+seqs.length+" sequences to clipboard.");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void pasteNew_actionPerformed(ActionEvent e)
+ {
+ paste(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void pasteThis_actionPerformed(ActionEvent e)
+ {
+ paste(false);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param newAlignment DOCUMENT ME!
+ */
+ void paste(boolean newAlignment)
+ {
+ boolean externalPaste=true;
+ try
+ {
+ Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
+ Transferable contents = c.getContents(this);
+
+ if (contents == null)
+ {
+ return;
+ }
+
+ String str, format;
+ try
+ {
+ str = (String) contents.getTransferData(DataFlavor.stringFlavor);
+ if (str.length() < 1)
+ {
+ return;
+ }
+
+ format = new IdentifyFile().Identify(str, "Paste");
+
+ }
+ catch (OutOfMemoryError er)
+ {
+ er.printStackTrace();
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ javax.swing.JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "Out of memory pasting sequences!!"
+ +
+ "\nSee help files for increasing Java Virtual Machine memory."
+ , "Out of memory",
+ javax.swing.JOptionPane.WARNING_MESSAGE);
+ }
+ });
+
+ return;
+ }
+
+ SequenceI[] sequences;
+ boolean annotationAdded = false;
+ AlignmentI alignment = null;
+
+ if(Desktop.jalviewClipboard!=null)
+ {
+ // The clipboard was filled from within Jalview, we must use the sequences
+ // And dataset from the copied alignment
+ SequenceI[] newseq = (SequenceI[])Desktop.jalviewClipboard[0];
+ // be doubly sure that we create *new* sequence objects.
+ sequences = new SequenceI[newseq.length];
+ for (int i=0;i<newseq.length;i++) {
+ sequences[i] = new Sequence(newseq[i]);
+ }
+ alignment = new Alignment(sequences);
+ externalPaste = false;
+ }
+ else
+ {
+ // parse the clipboard as an alignment.
+ alignment = new FormatAdapter().readFile(str, "Paste", format);
+ sequences = alignment.getSequencesArray();
+ }
+
+ int alwidth=0;
+
+ if (newAlignment)
+ {
+
+ if (Desktop.jalviewClipboard != null)
+ {
+ // dataset is inherited
+ alignment.setDataset( (Alignment) Desktop.jalviewClipboard[1]);
+ }
+ else
+ {
+ // new dataset is constructed
+ alignment.setDataset(null);
+ }
+ alwidth = alignment.getWidth()+1;
+ }
+ else
+ {
+ AlignmentI pastedal = alignment; // preserve pasted alignment object
+ // Add pasted sequences and dataset into existing alignment.
+ alignment = viewport.getAlignment();
+ alwidth = alignment.getWidth()+1;
+ // decide if we need to import sequences from an existing dataset
+ boolean importDs = Desktop.jalviewClipboard != null
+ && Desktop.jalviewClipboard[1] != alignment.getDataset();
+ // importDs==true instructs us to copy over new dataset sequences from
+ // an existing alignment
+ Vector newDs = (importDs) ? new Vector() : null; // used to create
+ // minimum dataset set
+
+ for (int i = 0; i < sequences.length; i++)
+ {
+ if (importDs)
+ {
+ newDs.addElement(null);
+ }
+ SequenceI ds = sequences[i].getDatasetSequence(); // null for a simple
+ // paste
+ if (importDs && ds != null)
+ {
+ if (!newDs.contains(ds))
+ {
+ newDs.setElementAt(ds, i);
+ ds = new Sequence(ds);
+ // update with new dataset sequence
+ sequences[i].setDatasetSequence(ds);
+ }
+ else
+ {
+ ds = sequences[newDs.indexOf(ds)].getDatasetSequence();
+ }
+ }
+ else
+ {
+ // copy and derive new dataset sequence
+ sequences[i] = sequences[i].deriveSequence();
+ alignment.getDataset().addSequence(sequences[i].getDatasetSequence());
+ // TODO: avoid creation of duplicate dataset sequences with a
+ // 'contains' method using SequenceI.equals()/SequenceI.contains()
+ }
+ alignment.addSequence(sequences[i]); // merges dataset
+ }
+ if (newDs != null)
+ {
+ newDs.clear(); // tidy up
+ }
+ if (pastedal.getAlignmentAnnotation()!=null) {
+ // Add any annotation attached to alignment.
+ AlignmentAnnotation[] alann = pastedal.getAlignmentAnnotation();
+ for (int i=0; i<alann.length; i++)
+ {
+ annotationAdded=true;
+ if (alann[i].sequenceRef==null && !alann[i].autoCalculated) {
+ AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]);
+ newann.padAnnotation(alwidth);
+ alignment.addAnnotation(newann);
+ }
+ }
+ }
+ }
+ if (!newAlignment) {
+ ///////
+ // ADD HISTORY ITEM
+ //
+ addHistoryItem(new EditCommand(
+ "Add sequences",
+ EditCommand.PASTE,
+ sequences,
+ 0,
+ alignment.getWidth(),
+ alignment)
+ );
+ }
+ // Add any annotations attached to sequences
+ for (int i = 0; i < sequences.length; i++)
+ {
+ if (sequences[i].getAnnotation() != null)
+ {
+ for (int a = 0; a < sequences[i].getAnnotation().length; a++)
+ {
+ annotationAdded=true;
+ sequences[i].getAnnotation()[a].adjustForAlignment();
+ sequences[i].getAnnotation()[a].padAnnotation(alwidth);
+ alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation was duplicated earlier
+ alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a);
+ }
+
+
+ }
+ }
+ if (!newAlignment) {
+ // propagate alignment changed.
+ viewport.setEndSeq(alignment.getHeight());
+ if (annotationAdded)
+ {
+ alignPanel.annotationPanel.adjustPanelHeight();
+ buildSortByAnnotationScoresMenu();
+ }
+ viewport.firePropertyChange("alignment", null, alignment.getSequences());
+ } else {
+ AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ String newtitle = new String("Copied sequences");
+
+ if(Desktop.jalviewClipboard!=null && Desktop.jalviewClipboard[2]!=null)
+ {
+ Vector hc = (Vector)Desktop.jalviewClipboard[2];
+ for(int i=0; i<hc.size(); i++)
+ {
+ int [] region = (int[]) hc.elementAt(i);
+ af.viewport.hideColumns(region[0], region[1]);
+ }
+ }
+
+
+ //>>>This is a fix for the moment, until a better solution is found!!<<<
+ af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().transferSettings(
+ alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
+
+ // TODO: maintain provenance of an alignment, rather than just make the title a concatenation of operations.
+ if (!externalPaste) {
+ if (title.startsWith("Copied sequences"))
+ {
+ newtitle = title;
+ }
+ else
+ {
+ newtitle = newtitle.concat("- from " + title);
+ }
+ } else {
+ newtitle = new String("Pasted sequences");
+ }
+
+ Desktop.addInternalFrame(af, newtitle, DEFAULT_WIDTH,
+ DEFAULT_HEIGHT);
+
+ }
+
+
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println("Exception whilst pasting: "+ex);
+ // could be anything being pasted in here
+ }
+
+
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void cut_actionPerformed(ActionEvent e)
+ {
+ copy_actionPerformed(null);
+ delete_actionPerformed(null);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void delete_actionPerformed(ActionEvent evt)
+ {
+
+ SequenceGroup sg = viewport.getSelectionGroup();
+ if (sg == null)
+ {
+ return;
+ }
+
+ Vector seqs = new Vector();
+ SequenceI seq;
+ for (int i = 0; i < sg.getSize(); i++)
+ {
+ seq = sg.getSequenceAt(i);
+ seqs.addElement(seq);
+ }
+
+
+ // If the cut affects all sequences, remove highlighted columns
+ if (sg.getSize() == viewport.alignment.getHeight())
+ {
+ viewport.getColumnSelection().removeElements(sg.getStartRes(),
+ sg.getEndRes() + 1);
+ }
+
+
+ SequenceI [] cut = new SequenceI[seqs.size()];
+ for(int i=0; i<seqs.size(); i++)
+ {
+ cut[i] = (SequenceI)seqs.elementAt(i);
+ }
+
+
+ /*
+ //ADD HISTORY ITEM
+ */
+ addHistoryItem(new EditCommand("Cut Sequences",
+ EditCommand.CUT,
+ cut,
+ sg.getStartRes(),
+ sg.getEndRes()-sg.getStartRes()+1,
+ viewport.alignment));
+
+
+ viewport.setSelectionGroup(null);
+ viewport.alignment.deleteGroup(sg);
+
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+
+ if (viewport.getAlignment().getHeight() < 1)
+ {
+ try
+ {
+ this.setClosed(true);
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void deleteGroups_actionPerformed(ActionEvent e)
+ {
+ viewport.alignment.deleteAllGroups();
+ viewport.sequenceColours = null;
+ viewport.setSelectionGroup(null);
+ PaintRefresher.Refresh(this, viewport.getSequenceSetId());
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)
+ {
+ SequenceGroup sg = new SequenceGroup();
+
+ for (int i = 0; i < viewport.getAlignment().getSequences().size();
+ i++)
+ {
+ sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
+ }
+
+ sg.setEndRes(viewport.alignment.getWidth() - 1);
+ viewport.setSelectionGroup(sg);
+ alignPanel.paintAlignment(true);
+ PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)
+ {
+ if(viewport.cursorMode)
+ {
+ alignPanel.seqPanel.keyboardNo1 = null;
+ alignPanel.seqPanel.keyboardNo2 = null;
+ }
+ viewport.setSelectionGroup(null);
+ viewport.getColumnSelection().clear();
+ viewport.setSelectionGroup(null);
+ alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
+ alignPanel.idPanel.idCanvas.searchResults = null;
+ alignPanel.paintAlignment(true);
+ PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void invertSequenceMenuItem_actionPerformed(ActionEvent e)
+ {
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+ if (sg == null)
+ {
+ selectAllSequenceMenuItem_actionPerformed(null);
+
+ return;
+ }
+
+ for (int i = 0; i < viewport.getAlignment().getSequences().size();
+ i++)
+ {
+ sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
+ }
+
+ alignPanel.paintAlignment(true);
+
+ PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
+ }
+
+ public void invertColSel_actionPerformed(ActionEvent e)
+ {
+ viewport.invertColumnSelection();
+ alignPanel.paintAlignment(true);
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void remove2LeftMenuItem_actionPerformed(ActionEvent e)
+ {
+ trimAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void remove2RightMenuItem_actionPerformed(ActionEvent e)
+ {
+ trimAlignment(false);
+ }
+
+ void trimAlignment(boolean trimLeft)
+ {
+ ColumnSelection colSel = viewport.getColumnSelection();
+ int column;
+
+ if (colSel.size() > 0)
+ {
+ if(trimLeft)
+ {
+ column = colSel.getMin();
+ }
+ else
+ {
+ column = colSel.getMax();
+ }
+
+ SequenceI [] seqs;
+ if(viewport.getSelectionGroup()!=null)
+ {
+ seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
+ hiddenRepSequences);
+ }
+ else
+ {
+ seqs = viewport.alignment.getSequencesArray();
+ }
+
+
+ TrimRegionCommand trimRegion;
+ if(trimLeft)
+ {
+ trimRegion = new TrimRegionCommand("Remove Left",
+ TrimRegionCommand.TRIM_LEFT,
+ seqs,
+ column,
+ viewport.alignment,
+ viewport.colSel,
+ viewport.selectionGroup);
+ viewport.setStartRes(0);
+ }
+ else
+ {
+ trimRegion = new TrimRegionCommand("Remove Right",
+ TrimRegionCommand.TRIM_RIGHT,
+ seqs,
+ column,
+ viewport.alignment,
+ viewport.colSel,
+ viewport.selectionGroup);
+ }
+
+ statusBar.setText("Removed "+trimRegion.getSize()+" columns.");
+
+
+ addHistoryItem(trimRegion);
+
+ Vector groups = viewport.alignment.getGroups();
+
+ for (int i = 0; i < groups.size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.get(i);
+
+ if ( (trimLeft && !sg.adjustForRemoveLeft(column))
+ || (!trimLeft && !sg.adjustForRemoveRight(column)))
+ {
+ viewport.alignment.deleteGroup(sg);
+ }
+ }
+
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e)
+ {
+ int start = 0, end = viewport.alignment.getWidth()-1;
+
+ SequenceI[] seqs;
+ if (viewport.getSelectionGroup() != null)
+ {
+ seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
+ hiddenRepSequences);
+ start = viewport.getSelectionGroup().getStartRes();
+ end = viewport.getSelectionGroup().getEndRes();
+ }
+ else
+ {
+ seqs = viewport.alignment.getSequencesArray();
+ }
+
+
+ RemoveGapColCommand removeGapCols =
+ new RemoveGapColCommand("Remove Gapped Columns",
+ seqs,
+ start, end,
+ viewport.alignment);
+
+ addHistoryItem(removeGapCols);
+
+ statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns.");
+
+ //This is to maintain viewport position on first residue
+ //of first sequence
+ SequenceI seq = viewport.alignment.getSequenceAt(0);
+ int startRes = seq.findPosition(viewport.startRes);
+ // ShiftList shifts;
+ // viewport.getAlignment().removeGaps(shifts=new ShiftList());
+ // edit.alColumnChanges=shifts.getInverse();
+ // if (viewport.hasHiddenColumns)
+ // viewport.getColumnSelection().compensateForEdits(shifts);
+ viewport.setStartRes(seq.findIndex(startRes)-1);
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void removeAllGapsMenuItem_actionPerformed(ActionEvent e)
+ {
+ int start = 0, end = viewport.alignment.getWidth()-1;
+
+ SequenceI[] seqs;
+ if (viewport.getSelectionGroup() != null)
+ {
+ seqs = viewport.getSelectionGroup().getSequencesAsArray(viewport.
+ hiddenRepSequences);
+ start = viewport.getSelectionGroup().getStartRes();
+ end = viewport.getSelectionGroup().getEndRes();
+ }
+ else
+ {
+ seqs = viewport.alignment.getSequencesArray();
+ }
+
+ //This is to maintain viewport position on first residue
+ //of first sequence
+ SequenceI seq = viewport.alignment.getSequenceAt(0);
+ int startRes = seq.findPosition(viewport.startRes);
+
+ addHistoryItem(new RemoveGapsCommand("Remove Gaps",
+ seqs,
+ start, end,
+ viewport.alignment));
+
+ viewport.setStartRes(seq.findIndex(startRes)-1);
+
+ viewport.firePropertyChange("alignment", null,
+ viewport.getAlignment().getSequences());
+
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void padGapsMenuitem_actionPerformed(ActionEvent e)
+ {
+ viewport.padGaps = padGapsMenuitem.isSelected();
+
+ viewport.firePropertyChange("alignment",
+ null,
+ viewport.getAlignment().getSequences());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void findMenuItem_actionPerformed(ActionEvent e)
+ {
+ new Finder();
+ }
+
+ public void newView_actionPerformed(ActionEvent e)
+ {
+ AlignmentPanel newap =
+ new Jalview2XML().copyAlignPanel(alignPanel, true);
+
+ newap.av.gatherViewsHere = false;
+
+ if (viewport.viewName == null)
+ {
+ viewport.viewName = "Original";
+ }
+
+ newap.av.historyList = viewport.historyList;
+ newap.av.redoList = viewport.redoList;
+
+ int index = Desktop.getViewCount(viewport.getSequenceSetId());
+ String newViewName = "View " +index;
+
+ Vector comps = (Vector) PaintRefresher.components.get(viewport.
+ getSequenceSetId());
+ Vector existingNames = new Vector();
+ for(int i=0; i<comps.size(); i++)
+ {
+ if(comps.elementAt(i) instanceof AlignmentPanel)
+ {
+ AlignmentPanel ap = (AlignmentPanel)comps.elementAt(i);
+ if(!existingNames.contains(ap.av.viewName))
+ {
+ existingNames.addElement(ap.av.viewName);
+ }
+ }
+ }
+
+ while(existingNames.contains(newViewName))
+ {
+ newViewName = "View "+ (++index);
+ }
+
+ newap.av.viewName = newViewName;
+
+ addAlignmentPanel(newap, false);
+
+ if(alignPanels.size()==2)
+ {
+ viewport.gatherViewsHere = true;
+ }
+ tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
+ }
+
+ public void expandViews_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.explodeViews(this);
+ }
+
+ public void gatherViews_actionPerformed(ActionEvent e)
+ {
+ Desktop.instance.gatherViews(this);
+ }
+
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void font_actionPerformed(ActionEvent e)
+ {
+ new FontChooser(alignPanel);
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void seqLimit_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowJVSuffix(seqLimits.isSelected());
+
+ alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());
+ alignPanel.paintAlignment(true);
+ }
+
+ public void idRightAlign_actionPerformed(ActionEvent e)
+ {
+ viewport.rightAlignIds = idRightAlign.isSelected();
+ alignPanel.paintAlignment(true);
+ }
+
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void colourTextMenuItem_actionPerformed(ActionEvent e)
+ {
+ viewport.setColourText(colourTextMenuItem.isSelected());
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void wrapMenuItem_actionPerformed(ActionEvent e)
+ {
+ scaleAbove.setVisible(wrapMenuItem.isSelected());
+ scaleLeft.setVisible(wrapMenuItem.isSelected());
+ scaleRight.setVisible(wrapMenuItem.isSelected());
+ viewport.setWrapAlignment(wrapMenuItem.isSelected());
+ alignPanel.setWrapAlignment(wrapMenuItem.isSelected());
+ }
+
+ public void showAllSeqs_actionPerformed(ActionEvent e)
+ {
+ viewport.showAllHiddenSeqs();
+ }
+
+ public void showAllColumns_actionPerformed(ActionEvent e)
+ {
+ viewport.showAllHiddenColumns();
+ repaint();
+ }
+
+ public void hideSelSequences_actionPerformed(ActionEvent e)
+ {
+ viewport.hideAllSelectedSeqs();
+ alignPanel.paintAlignment(true);
+ }
+
+ public void hideSelColumns_actionPerformed(ActionEvent e)
+ {
+ viewport.hideSelectedColumns();
+ alignPanel.paintAlignment(true);
+ }
+
+ public void hiddenMarkers_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowHiddenMarkers(hiddenMarkers.isSelected());
+ repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void scaleAbove_actionPerformed(ActionEvent e)
+ {
+ viewport.setScaleAboveWrapped(scaleAbove.isSelected());
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void scaleLeft_actionPerformed(ActionEvent e)
+ {
+ viewport.setScaleLeftWrapped(scaleLeft.isSelected());
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void scaleRight_actionPerformed(ActionEvent e)
+ {
+ viewport.setScaleRightWrapped(scaleRight.isSelected());
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void viewBoxesMenuItem_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowBoxes(viewBoxesMenuItem.isSelected());
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void viewTextMenuItem_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowText(viewTextMenuItem.isSelected());
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void renderGapsMenuItem_actionPerformed(ActionEvent e)
+ {
+ viewport.setRenderGaps(renderGapsMenuItem.isSelected());
+ alignPanel.paintAlignment(true);
+ }
+
+
+ public FeatureSettings featureSettings;
+ public void featureSettings_actionPerformed(ActionEvent e)
+ {
+ if(featureSettings !=null )
+ {
+ featureSettings.close();
+ featureSettings = null;
+ }
+ featureSettings = new FeatureSettings(this);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
+ public void showSeqFeatures_actionPerformed(ActionEvent evt)
+ {
+ viewport.setShowSequenceFeatures(showSeqFeatures.isSelected());
+ alignPanel.paintAlignment(true);
+ if (alignPanel.getOverviewPanel() != null)
+ {
+ alignPanel.getOverviewPanel().updateOverviewImage();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void annotationPanelMenuItem_actionPerformed(ActionEvent e)
+ {
+ viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());
+ alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());
+ }
+
+ public void alignmentProperties()
+ {
+ JEditorPane editPane = new JEditorPane("text/html","");
+ editPane.setEditable(false);
+ StringBuffer contents = new StringBuffer("<html>");
+
+ float avg = 0;
+ int min=Integer.MAX_VALUE, max=0;
+ for(int i=0; i<viewport.alignment.getHeight(); i++)
+ {
+ int size = viewport.alignment.getSequenceAt(i).getEnd()
+ -viewport.alignment.getSequenceAt(i).getStart();
+ avg += size;
+ if(size>max)
+ max = size;
+ if(size<min)
+ min = size;
+ }
+ avg = avg/(float)viewport.alignment.getHeight();
+
+ contents.append("<br>Sequences: "+ viewport.alignment.getHeight());
+ contents.append("<br>Minimum Sequence Length: "+min);
+ contents.append("<br>Maximum Sequence Length: "+max);
+ contents.append("<br>Average Length: "+(int)avg);
+
+ if (((Alignment)viewport.alignment).getProperties() != null)
+ {
+ Hashtable props = ((Alignment)viewport.alignment).getProperties();
+ Enumeration en = props.keys();
+ contents.append("<br><br><table border=\"1\">");
+ while(en.hasMoreElements())
+ {
+ String key = en.nextElement().toString();
+ StringBuffer val = new StringBuffer();
+ String vals = props.get(key).toString();
+ int pos=0, npos;
+ do {
+ npos = vals.indexOf("\n",pos);
+ if (npos==-1)
+ {
+ val.append(vals.substring(pos));
+ } else {
+ val.append(vals.substring(pos, npos));
+ val.append("<br>");
+ }
+ pos = npos+1;
+ } while (npos!=-1);
+ contents.append("<tr><td>"+key+"</td><td>"+val+"</td></tr>");
+ }
+ contents.append("</table>");
+ }
+ editPane.setText(contents.toString()+"</html>");
+ JInternalFrame frame = new JInternalFrame();
+ frame.getContentPane().add(new JScrollPane(editPane));
+
+ Desktop.instance.addInternalFrame(frame,"Alignment Properties: "+getTitle(),500,400);
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void overviewMenuItem_actionPerformed(ActionEvent e)
+ {
+ if (alignPanel.overviewPanel != null)
+ {
+ return;
+ }
+
+ JInternalFrame frame = new JInternalFrame();
+ OverviewPanel overview = new OverviewPanel(alignPanel);
+ frame.setContentPane(overview);
+ Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),
+ frame.getWidth(), frame.getHeight());
+ frame.pack();
+ frame.setLayer(JLayeredPane.PALETTE_LAYER);
+ frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+ {
+ public void internalFrameClosed(
+ javax.swing.event.InternalFrameEvent evt)
+ {
+ alignPanel.setOverviewPanel(null);
+ }
+ ;
+ });
+
+ alignPanel.setOverviewPanel(overview);
+ }
+
+ public void textColour_actionPerformed(ActionEvent e)
+ {
+ new TextColourChooser().chooseColour(alignPanel, null);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void noColourmenuItem_actionPerformed(ActionEvent e)
+ {
+ changeColour(null);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void clustalColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new ClustalxColourScheme(
+ viewport.alignment.getSequences(), viewport.alignment.getWidth()));
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void zappoColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new ZappoColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void taylorColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new TaylorColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void hydrophobicityColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new HydrophobicColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void helixColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new HelixColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void strandColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new StrandColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void turnColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new TurnColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void buriedColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new BuriedColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void nucleotideColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new NucleotideColourScheme());
+ }
+
+ public void annotationColour_actionPerformed(ActionEvent e)
+ {
+ new AnnotationColourChooser(viewport, alignPanel);
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void applyToAllGroups_actionPerformed(ActionEvent e)
+ {
+ viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param cs DOCUMENT ME!
+ */
+ public void changeColour(ColourSchemeI cs)
+ {
+ int threshold = 0;
+
+ if(cs!=null)
+ {
+ if (viewport.getAbovePIDThreshold())
+ {
+ threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
+ "Background");
+
+ cs.setThreshold(threshold,
+ viewport.getIgnoreGapsConsensus());
+
+ viewport.setGlobalColourScheme(cs);
+ }
+ else
+ {
+ cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
+ }
+
+ if (viewport.getConservationSelected())
+ {
+
+ Alignment al = (Alignment) viewport.alignment;
+ Conservation c = new Conservation("All",
+ ResidueProperties.propHash, 3,
+ al.getSequences(), 0,
+ al.getWidth() - 1);
+
+ c.calculate();
+ c.verdict(false, viewport.ConsPercGaps);
+
+ cs.setConservation(c);
+
+ cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,
+ "Background"));
+ }
+ else
+ {
+ cs.setConservation(null);
+ }
+
+ cs.setConsensus(viewport.hconsensus);
+ }
+
+ viewport.setGlobalColourScheme(cs);
+
+ if (viewport.getColourAppliesToAllGroups())
+ {
+ Vector groups = viewport.alignment.getGroups();
+
+ for (int i = 0; i < groups.size(); i++)
+ {
+ SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
+
+ if (cs == null)
+ {
+ sg.cs = null;
+ continue;
+ }
+
+ if (cs instanceof ClustalxColourScheme)
+ {
+ sg.cs = new ClustalxColourScheme(
+ sg.getSequences(viewport.hiddenRepSequences), sg.getWidth());
+ }
+ else if (cs instanceof UserColourScheme)
+ {
+ sg.cs = new UserColourScheme( ( (UserColourScheme) cs).getColours());
+ }
+ else
+ {
+ try
+ {
+ sg.cs = (ColourSchemeI) cs.getClass().newInstance();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ if (viewport.getAbovePIDThreshold()
+ || cs instanceof PIDColourScheme
+ || cs instanceof Blosum62ColourScheme)
+ {
+ sg.cs.setThreshold(threshold,
+ viewport.getIgnoreGapsConsensus());
+
+ sg.cs.setConsensus(AAFrequency.calculate(
+ sg.getSequences(viewport.hiddenRepSequences), sg.getStartRes(),
+ sg.getEndRes()+1));
+ }
+ else
+ {
+ sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
+ }
+
+
+ if (viewport.getConservationSelected())
+ {
+ Conservation c = new Conservation("Group",
+ ResidueProperties.propHash, 3,
+ sg.getSequences(viewport.
+ hiddenRepSequences),
+ sg.getStartRes(),
+ sg.getEndRes()+1);
+ c.calculate();
+ c.verdict(false, viewport.ConsPercGaps);
+ sg.cs.setConservation(c);
+ }
+ else
+ {
+ sg.cs.setConservation(null);
+ }
+ }
+ }
+
+ if (alignPanel.getOverviewPanel() != null)
+ {
+ alignPanel.getOverviewPanel().updateOverviewImage();
+ }
+
+
+
+
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void modifyPID_actionPerformed(ActionEvent e)
+ {
+ if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)
+ {
+ SliderPanel.setPIDSliderSource(alignPanel,
+ viewport.getGlobalColourScheme(),
+ "Background");
+ SliderPanel.showPIDSlider();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void modifyConservation_actionPerformed(ActionEvent e)
+ {
+ if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)
+ {
+ SliderPanel.setConservationSlider(alignPanel,
+ viewport.globalColourScheme,
+ "Background");
+ SliderPanel.showConservationSlider();
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void conservationMenuItem_actionPerformed(ActionEvent e)
+ {
+ viewport.setConservationSelected(conservationMenuItem.isSelected());
+
+ viewport.setAbovePIDThreshold(false);
+ abovePIDThreshold.setSelected(false);
+
+ changeColour(viewport.getGlobalColourScheme());
+
+ modifyConservation_actionPerformed(null);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void abovePIDThreshold_actionPerformed(ActionEvent e)
+ {
+ viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());
+
+ conservationMenuItem.setSelected(false);
+ viewport.setConservationSelected(false);
+
+ changeColour(viewport.getGlobalColourScheme());
+
+ modifyPID_actionPerformed(null);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void userDefinedColour_actionPerformed(ActionEvent e)
+ {
+ if (e.getActionCommand().equals("User Defined..."))
+ {
+ new UserDefinedColours(alignPanel, null);
+ }
+ else
+ {
+ UserColourScheme udc = (UserColourScheme) UserDefinedColours.
+ getUserColourSchemes().get(e.getActionCommand());
+
+ changeColour(udc);
+ }
+ }
+
+ public void updateUserColourMenu()
+ {
+
+ Component[] menuItems = colourMenu.getMenuComponents();
+ int i, iSize = menuItems.length;
+ for (i = 0; i < iSize; i++)
+ {
+ if (menuItems[i].getName() != null &&
+ menuItems[i].getName().equals("USER_DEFINED"))
+ {
+ colourMenu.remove(menuItems[i]);
+ iSize--;
+ }
+ }
+ if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
+ {
+ java.util.Enumeration userColours = jalview.gui.UserDefinedColours.
+ getUserColourSchemes().keys();
+
+ while (userColours.hasMoreElements())
+ {
+ final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(
+ userColours.
+ nextElement().toString());
+ radioItem.setName("USER_DEFINED");
+ radioItem.addMouseListener(new MouseAdapter()
+ {
+ public void mousePressed(MouseEvent evt)
+ {
+ if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))
+ {
+ radioItem.removeActionListener(radioItem.getActionListeners()[0]);
+
+ int option = JOptionPane.showInternalConfirmDialog(jalview.gui.
+ Desktop.desktop,
+ "Remove from default list?",
+ "Remove user defined colour",
+ JOptionPane.YES_NO_OPTION);
+ if(option == JOptionPane.YES_OPTION)
+ {
+ jalview.gui.UserDefinedColours.removeColourFromDefaults(
+ radioItem.getText());
+ colourMenu.remove(radioItem);
+ }
+ else
+ {
+ radioItem.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent evt)
+ {
+ userDefinedColour_actionPerformed(evt);
+ }
+ });
+ }
+ }
+ }
+ });
+ radioItem.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent evt)
+ {
+ userDefinedColour_actionPerformed(evt);
+ }
+ });
+
+ colourMenu.insert(radioItem, 15);
+ colours.add(radioItem);
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void PIDColour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new PIDColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void BLOSUM62Colour_actionPerformed(ActionEvent e)
+ {
+ changeColour(new Blosum62ColourScheme());
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)
+ {
+ SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByPID(viewport.getAlignment(),
+ viewport.getAlignment().getSequenceAt(0));
+ addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
+ viewport.alignment));
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void sortIDMenuItem_actionPerformed(ActionEvent e)
+ {
+ SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByID(viewport.getAlignment());
+ addHistoryItem(new OrderCommand("ID Sort", oldOrder, viewport.alignment));
+ alignPanel.paintAlignment(true);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void sortGroupMenuItem_actionPerformed(ActionEvent e)
+ {
+ SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByGroup(viewport.getAlignment());
+ addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.alignment));
+
+ alignPanel.paintAlignment(true);
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void removeRedundancyMenuItem_actionPerformed(ActionEvent e)
+ {
+ new RedundancyPanel(alignPanel, this);
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)
+ {
+ if ( (viewport.getSelectionGroup() == null) ||
+ (viewport.getSelectionGroup().getSize() < 2))
+ {
+ JOptionPane.showInternalMessageDialog(this,
+ "You must select at least 2 sequences.",
+ "Invalid Selection",
+ JOptionPane.WARNING_MESSAGE);
+ }
+ else
+ {
+ JInternalFrame frame = new JInternalFrame();
+ frame.setContentPane(new PairwiseAlignPanel(viewport));
+ Desktop.addInternalFrame(frame, "Pairwise Alignment", 600, 500);
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void PCAMenuItem_actionPerformed(ActionEvent e)
+ {
+ if ( ( (viewport.getSelectionGroup() != null) &&
+ (viewport.getSelectionGroup().getSize() < 4) &&
+ (viewport.getSelectionGroup().getSize() > 0)) ||
+ (viewport.getAlignment().getHeight() < 4))
+ {
+ JOptionPane.showInternalMessageDialog(this,
+ "Principal component analysis must take\n" +
+ "at least 4 input sequences.",
+ "Sequence selection insufficient",
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+
+ new PCAPanel(alignPanel);
+ }
+
+
+ public void autoCalculate_actionPerformed(ActionEvent e)
+ {
+ viewport.autoCalculateConsensus = autoCalculate.isSelected();
+ if(viewport.autoCalculateConsensus)
+ {
+ viewport.firePropertyChange("alignment",
+ null,
+ viewport.getAlignment().getSequences());
+ }
+ }
+
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e)
+ {
+ NewTreePanel("AV", "PID", "Average distance tree using PID");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void neighbourTreeMenuItem_actionPerformed(ActionEvent e)
+ {
+ NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e)
+ {
+ NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e)
+ {
+ NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param type DOCUMENT ME!
+ * @param pwType DOCUMENT ME!
+ * @param title DOCUMENT ME!
+ */
+ void NewTreePanel(String type, String pwType, String title)
+ {
+ TreePanel tp;
+
+ if (viewport.getSelectionGroup() != null)
+ {
+ if (viewport.getSelectionGroup().getSize() < 3)
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "You need to have more than two sequences selected to build a tree!",
+ "Not enough sequences",
+ JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ int s = 0;
+ SequenceGroup sg = viewport.getSelectionGroup();
+
+ /* Decide if the selection is a column region */
+ while (s < sg.getSize())
+ {
+ if ( ( (SequenceI) sg.getSequences(null).elementAt(s++)).getLength() <
+ sg.getEndRes())
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "The selected region to create a tree may\nonly contain residues or gaps.\n" +
+ "Try using the Pad function in the edit menu,\n" +
+ "or one of the multiple sequence alignment web services.",
+ "Sequences in selection are not aligned",
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+ }
+
+ title = title + " on region";
+ tp = new TreePanel(alignPanel, type, pwType);
+ }
+ else
+ {
+ //are the sequences aligned?
+ if (!viewport.alignment.isAligned())
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "The sequences must be aligned before creating a tree.\n" +
+ "Try using the Pad function in the edit menu,\n" +
+ "or one of the multiple sequence alignment web services.",
+ "Sequences not aligned",
+ JOptionPane.WARNING_MESSAGE);
+
+ return;
+ }
+
+ if(viewport.alignment.getHeight()<2)
+ {
+ return;
+ }
+
+ tp = new TreePanel(alignPanel, type, pwType);
+ }
+
+ title += " from ";
+
+ if(viewport.viewName!=null)
+ {
+ title+= viewport.viewName+" of ";
+ }
+
+ title += this.title;
+
+ Desktop.addInternalFrame(tp, title, 600, 500);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param title DOCUMENT ME!
+ * @param order DOCUMENT ME!
+ */
+ public void addSortByOrderMenuItem(String title, final AlignmentOrder order)
+ {
+ final JMenuItem item = new JMenuItem("by " + title);
+ sort.add(item);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
+
+ // TODO: JBPNote - have to map order entries to curent SequenceI pointers
+ AlignmentSorter.sortBy(viewport.getAlignment(), order);
+
+ addHistoryItem(new OrderCommand(order.getName(), oldOrder,
+ viewport.alignment));
+
+ alignPanel.paintAlignment(true);
+ }
+ });
+ }
+ /**
+ * Add a new sort by annotation score menu item
+ * @param sort the menu to add the option to
+ * @param scoreLabel the label used to retrieve scores for each sequence on the alignment
+ */
+ public void addSortByAnnotScoreMenuItem(JMenu sort, final String scoreLabel)
+ {
+ final JMenuItem item = new JMenuItem(scoreLabel);
+ sort.add(item);
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ SequenceI [] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByAnnotationScore(scoreLabel, viewport.getAlignment());
+ addHistoryItem(new OrderCommand("Sort by "+scoreLabel, oldOrder, viewport.alignment));
+ alignPanel.paintAlignment(true);
+ }
+ });
+ }
+ /**
+ * last hash for alignment's annotation array - used to minimise cost of rebuild.
+ */
+ protected int _annotationScoreVectorHash;
+ /**
+ * search the alignment and rebuild the sort by annotation score submenu
+ * the last alignment annotation vector hash is stored to minimize
+ * cost of rebuilding in subsequence calls.
+ *
+ */
+ public void buildSortByAnnotationScoresMenu()
+ {
+ if (viewport.alignment.getAlignmentAnnotation().hashCode()!=_annotationScoreVectorHash)
+ {
+ sortByAnnotScore.removeAll();
+ // almost certainly a quicker way to do this - but we keep it simple
+ Hashtable scoreSorts=new Hashtable();
+ AlignmentAnnotation aann[];
+ Enumeration sq = viewport.alignment.getSequences().elements();
+ while (sq.hasMoreElements())
+ {
+ aann = ((SequenceI) sq.nextElement()).getAnnotation();
+ for (int i=0;aann!=null && i<aann.length; i++)
+ {
+ if (aann[i].hasScore() && aann[i].sequenceRef!=null)
+ {
+ scoreSorts.put(aann[i].label, aann[i].label);
+ }
+ }
+ }
+ Enumeration labels = scoreSorts.keys();
+ while (labels.hasMoreElements())
+ {
+ addSortByAnnotScoreMenuItem(sortByAnnotScore, (String) labels.nextElement());
+ }
+ sortByAnnotScore.setVisible(scoreSorts.size()>0);
+ scoreSorts.clear();
+ }
+ }
+
+ /**
+ * Maintain the Order by->Displayed Tree menu.
+ * Creates a new menu item for a TreePanel with an appropriate
+ * <code>jalview.analysis.AlignmentSorter</code> call. Listeners are added
+ * to remove the menu item when the treePanel is closed, and adjust
+ * the tree leaf to sequence mapping when the alignment is modified.
+ * @param treePanel Displayed tree window.
+ * @param title SortBy menu item title.
+ */
+ public void buildTreeMenu()
+ {
+ sortByTreeMenu.removeAll();
+
+ Vector comps = (Vector) PaintRefresher.components.get(viewport.
+ getSequenceSetId());
+ Vector treePanels = new Vector();
+ int i, iSize = comps.size();
+ for(i=0; i<iSize; i++)
+ {
+ if(comps.elementAt(i) instanceof TreePanel)
+ {
+ treePanels.add(comps.elementAt(i));
+ }
+ }
+
+ iSize = treePanels.size();
+
+ if(iSize<1)
+ {
+ sortByTreeMenu.setVisible(false);
+ return;
+ }
+
+ sortByTreeMenu.setVisible(true);
+
+ for(i=0; i<treePanels.size(); i++)
+ {
+ TreePanel tp = (TreePanel)treePanels.elementAt(i);
+ final JMenuItem item = new JMenuItem(tp.getTitle());
+ final NJTree tree = ((TreePanel)treePanels.elementAt(i)).getTree();
+ item.addActionListener(new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
+ AlignmentSorter.sortByTree(viewport.getAlignment(), tree);
+
+ addHistoryItem(new OrderCommand("Tree Sort",
+ oldOrder,
+ viewport.alignment));
+
+ alignPanel.paintAlignment(true);
+ }
+ });
+
+ sortByTreeMenu.add(item);
+ }
+ }
+
+ /**
+ * Work out whether the whole set of sequences
+ * or just the selected set will be submitted for multiple alignment.
+ *
+ */
+ private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
+ {
+ // Now, check we have enough sequences
+ AlignmentView msa = null;
+
+ if ( (viewport.getSelectionGroup() != null) &&
+ (viewport.getSelectionGroup().getSize() > 1))
+ {
+ // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
+ /*SequenceGroup seqs = viewport.getSelectionGroup();
+ int sz;
+ msa = new SequenceI[sz = seqs.getSize(false)];
+
+ for (int i = 0; i < sz; i++)
+ {
+ msa[i] = (SequenceI) seqs.getSequenceAt(i);
+ } */
+ msa = viewport.getAlignmentView(true);
+ }
+ else
+ {
+ /*Vector seqs = viewport.getAlignment().getSequences();
+
+ if (seqs.size() > 1)
+ {
+ msa = new SequenceI[seqs.size()];
+
+ for (int i = 0; i < seqs.size(); i++)
+ {
+ msa[i] = (SequenceI) seqs.elementAt(i);
+ }
+ }*/
+ msa = viewport.getAlignmentView(false);
+ }
+ return msa;
+ }
+
+ /**
+ * Decides what is submitted to a secondary structure prediction service,
+ * the currently selected sequence, or the currently selected alignment
+ * (where the first sequence in the set is the one that the prediction
+ * will be for).
+ */
+ AlignmentView gatherSeqOrMsaForSecStrPrediction()
+ {
+ AlignmentView seqs = null;
+
+ if ( (viewport.getSelectionGroup() != null) &&
+ (viewport.getSelectionGroup().getSize() > 0))
+ {
+ seqs = viewport.getAlignmentView(true);
+ }
+ else
+ {
+ seqs = viewport.getAlignmentView(false);
+ }
+ // limit sequences - JBPNote in future - could spawn multiple prediction jobs
+ // TODO: viewport.alignment.isAligned is a global state - the local selection may well be aligned - we preserve 2.0.8 behaviour for moment.
+ if (!viewport.alignment.isAligned())
+ {
+ seqs.setSequences(new SeqCigar[]
+ {seqs.getSequences()[0]});
+ }
+ return seqs;
+ }
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ protected void LoadtreeMenuItem_actionPerformed(ActionEvent e)
+ {
+ // Pick the tree file
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ getProperty(
+ "LAST_DIRECTORY"));
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Select a newick-like tree file");
+ chooser.setToolTipText("Load a tree file");
+
+ int value = chooser.showOpenDialog(null);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ String choice = chooser.getSelectedFile().getPath();
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
+
+ try
+ {
+ jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
+ "File");
+ viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
+ }
+ catch (Exception ex)
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "Problem reading tree file",
+ ex.getMessage(),
+ JOptionPane.WARNING_MESSAGE);
+ ex.printStackTrace();
+ }
+ }
+ }
+
+
+ public TreePanel ShowNewickTree(NewickFile nf, String title)
+ {
+ return ShowNewickTree(nf,title,600,500,4,5);
+ }
+
+ public TreePanel ShowNewickTree(NewickFile nf, String title,
+ AlignmentView input)
+ {
+ return ShowNewickTree(nf,title, input, 600,500,4,5);
+ }
+
+ public TreePanel ShowNewickTree(NewickFile nf, String title, int w, int h,
+ int x, int y)
+ {
+ return ShowNewickTree(nf, title, null, w, h, x, y);
+ }
+ /**
+ * Add a treeviewer for the tree extracted from a newick file object to the current alignment view
+ *
+ * @param nf the tree
+ * @param title tree viewer title
+ * @param input Associated alignment input data (or null)
+ * @param w width
+ * @param h height
+ * @param x position
+ * @param y position
+ * @return TreePanel handle
+ */
+ public TreePanel ShowNewickTree(NewickFile nf, String title,
+ AlignmentView input, int w, int h, int x,
+ int y)
+ {
+ TreePanel tp = null;
+
+ try
+ {
+ nf.parse();
+
+ if (nf.getTree() != null)
+ {
+ tp = new TreePanel(alignPanel,
+ "FromFile",
+ title,
+ nf, input);
+
+ tp.setSize(w,h);
+
+ if(x>0 && y>0)
+ {
+ tp.setLocation(x,y);
+ }
+
+
+ Desktop.addInternalFrame(tp, title, w, h);
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+
+ return tp;
+ }
+
+
+ /**
+ * Generates menu items and listener event actions for web service clients
+ *
+ */
+ public void BuildWebServiceMenu()
+ {
+ if ( (Discoverer.services != null)
+ && (Discoverer.services.size() > 0))
+ {
+ Vector msaws = (Vector) Discoverer.services.get("MsaWS");
+ Vector secstrpr = (Vector) Discoverer.services.get("SecStrPred");
+ Vector wsmenu = new Vector();
+ final AlignFrame af = this;
+ if (msaws != null)
+ {
+ // Add any Multiple Sequence Alignment Services
+ final JMenu msawsmenu = new JMenu("Alignment");
+ for (int i = 0, j = msaws.size(); i < j; i++)
+ {
+ final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) msaws.
+ get(i);
+ final JMenuItem method = new JMenuItem(sh.getName());
+ method.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentView msa = gatherSequencesForAlignment();
+ new jalview.ws.MsaWSClient(sh, title, msa,
+ false, true,
+ viewport.getAlignment().getDataset(),
+ af);
+
+ }
+
+ });
+ msawsmenu.add(method);
+ // Deal with services that we know accept partial alignments.
+ if (sh.getName().indexOf("lustal") > -1)
+ {
+ // We know that ClustalWS can accept partial alignments for refinement.
+ final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");
+ methodR.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentView msa = gatherSequencesForAlignment();
+ new jalview.ws.MsaWSClient(sh, title, msa,
+ true, true,
+ viewport.getAlignment().getDataset(),
+ af);
+
+ }
+
+ });
+ msawsmenu.add(methodR);
+
+ }
+ }
+ wsmenu.add(msawsmenu);
+ }
+ if (secstrpr != null)
+ {
+ // Add any secondary structure prediction services
+ final JMenu secstrmenu = new JMenu("Secondary Structure Prediction");
+ for (int i = 0, j = secstrpr.size(); i < j; i++)
+ {
+ final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle)
+ secstrpr.get(i);
+ final JMenuItem method = new JMenuItem(sh.getName());
+ method.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentView msa = gatherSeqOrMsaForSecStrPrediction();
+ if (msa.getSequences().length == 1)
+ {
+ // Single Sequence prediction
+ new jalview.ws.JPredClient(sh, title, false, msa, af, true);
+ }
+ else
+ {
+ if (msa.getSequences().length > 1)
+ {
+ // Sequence profile based prediction
+ new jalview.ws.JPredClient(sh,
+ title, true, msa, af, true);
+ }
+ }
+ }
+ });
+ secstrmenu.add(method);
+ }
+ wsmenu.add(secstrmenu);
+ }
+ resetWebServiceMenu();
+ for (int i = 0, j = wsmenu.size(); i < j; i++)
+ {
+ webService.add( (JMenu) wsmenu.get(i));
+ }
+ }
+ else
+ {
+ resetWebServiceMenu();
+ this.webService.add(this.webServiceNoServices);
+ }
+ // TODO: add in rediscovery function
+ // TODO: reduce code redundancy.
+ // TODO: group services by location as well as function.
+ }
+
+
+ /**
+ * empty the web service menu and add any ad-hoc functions
+ * not dynamically discovered.
+ *
+ */
+ private void resetWebServiceMenu()
+ {
+ webService.removeAll();
+ // Temporary hack - DBRef Fetcher always top level ws entry.
+ JMenuItem rfetch = new JMenuItem("Fetch DB References");
+ rfetch.setToolTipText("Retrieve and parse uniprot records for the alignment or the currently selected sequences");
+ webService.add(rfetch);
+ rfetch.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ new jalview.io.DBRefFetcher(
+ alignPanel.av.getSequenceSelection(),
+ alignPanel.alignFrame).fetchDBRefs(false);
+ }
+
+ });
+ }
+
+ /* public void vamsasStore_actionPerformed(ActionEvent e)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
+ getProperty("LAST_DIRECTORY"));
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Export to Vamsas file");
+ chooser.setToolTipText("Export");
+
+ int value = chooser.showSaveDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ jalview.io.VamsasDatastore vs = new jalview.io.VamsasDatastore(viewport);
+ //vs.store(chooser.getSelectedFile().getAbsolutePath() );
+ vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this);
+ }
+ }*/
+
+
+
+public void showTranslation_actionPerformed(ActionEvent e)
+{
+ ///////////////////////////////
+ // Collect Data to be translated/transferred
+
+ SequenceI [] selection = viewport.getSequenceSelection();
+ String [] seqstring = viewport.getViewAsString(true);
+ AlignmentI al = null;
+ try {
+ al = jalview.analysis.Dna.CdnaTranslate(selection, seqstring, viewport.getViewAsVisibleContigs(true),
+ viewport.getGapCharacter(), viewport.alignment.getAlignmentAnnotation(),
+ viewport.alignment.getWidth());
+ } catch (Exception ex) {
+ al = null;
+ jalview.bin.Cache.log.debug("Exception during translation.",ex);
+ }
+ if (al==null)
+ {
+ JOptionPane.showMessageDialog(Desktop.desktop,
+ "Please select at least three bases in at least one sequence in order to perform a cDNA translation.",
+ "Translation Failed",
+ JOptionPane.WARNING_MESSAGE);
+ } else {
+ AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+ Desktop.addInternalFrame(af, "Translation of "+this.getTitle(),
+ DEFAULT_WIDTH,
+ DEFAULT_HEIGHT);
+ }
+}
+
+/**
+ * DOCUMENT ME!
+ *
+ * @param String DOCUMENT ME!
+ */
+public boolean parseFeaturesFile(String file, String type)
+{
+ boolean featuresFile = false;
+ try
+ {
+ featuresFile = new FeaturesFile(file,
+ type).parse(viewport.alignment.getDataset(),
+ alignPanel.seqPanel.seqCanvas.
+ getFeatureRenderer().featureColours,
+ false);
+ }
+ catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+
+ if(featuresFile)
+ {
+ viewport.showSequenceFeatures = true;
+ showSeqFeatures.setSelected(true);
+ alignPanel.paintAlignment(true);
+ }
+
+ return featuresFile;
+}
+
+public void dragEnter(DropTargetDragEvent evt)
+{}
+
+public void dragExit(DropTargetEvent evt)
+{}
+
+public void dragOver(DropTargetDragEvent evt)
+{}
+
+public void dropActionChanged(DropTargetDragEvent evt)
+{}
+
+public void drop(DropTargetDropEvent evt)
+{
+ Transferable t = evt.getTransferable();
+ java.util.List files = null;
+
+ try
+ {
+ DataFlavor uriListFlavor = new DataFlavor(
+ "text/uri-list;class=java.lang.String");
+ if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
+ {
+ //Works on Windows and MacOSX
+ evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+ files = (java.util.List) t.getTransferData(DataFlavor.
+ javaFileListFlavor);
+ }
+ else if (t.isDataFlavorSupported(uriListFlavor))
+ {
+ // This is used by Unix drag system
+ evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+ String data = (String) t.getTransferData(uriListFlavor);
+ files = new java.util.ArrayList(1);
+ for (java.util.StringTokenizer st = new java.util.StringTokenizer(
+ data,
+ "\r\n");
+ st.hasMoreTokens(); )
+ {
+ String s = st.nextToken();
+ if (s.startsWith("#"))
+ {
+ // the line is a comment (as per the RFC 2483)
+ continue;
+ }
+
+ java.net.URI uri = new java.net.URI(s);
+ java.io.File file = new java.io.File(uri);
+ files.add(file);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ if (files != null)
+ {
+ try
+ {
+
+ for (int i = 0; i < files.size(); i++)
+ {
+ loadJalviewDataFile(files.get(i).toString());
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
+
+ // This method will attempt to load a "dropped" file first by testing
+ // whether its and Annotation file, then features file. If both are
+ // false then the user may have dropped an alignment file onto this
+ // AlignFrame
+ public void loadJalviewDataFile(String file)
+ {
+ try
+ {
+ String protocol = "File";
+
+ if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1)
+ {
+ protocol = "URL";
+ }
+
+ boolean isAnnotation = new AnnotationFile().readAnnotationFile(viewport.
+ alignment, file, protocol);
+
+ if (!isAnnotation)
+ {
+ boolean isGroupsFile = parseFeaturesFile(file,protocol);
+ if (!isGroupsFile)
+ {
+ String format = new IdentifyFile().Identify(file, protocol);
+
+ if(format.equalsIgnoreCase("JnetFile"))
+ {
+ jalview.io.JPredFile predictions = new jalview.io.JPredFile(
+ file, protocol);
+ new JnetAnnotationMaker().add_annotation(predictions,
+ viewport.getAlignment(),
+ 0, false);
+ alignPanel.adjustAnnotationHeight();
+ alignPanel.paintAlignment(true);
+ }
+ else
+ {
+ new FileLoader().LoadFile(viewport, file, protocol, format);
+ }
+ }
+ }
+ else
+ {
+ // (isAnnotation)
+ alignPanel.adjustAnnotationHeight();
+ buildSortByAnnotationScoresMenu();
+ }
+
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void tabSelectionChanged(int index)
+ {
+ if (index > -1)
+ {
+ alignPanel = (AlignmentPanel) alignPanels.elementAt(index);
+ viewport = alignPanel.av;
+ setMenusFromViewport(viewport);
+ }
+ }
+
+ public void tabbedPane_mousePressed(MouseEvent e)
+ {
+ if(SwingUtilities.isRightMouseButton(e))
+ {
+ String reply = JOptionPane.showInternalInputDialog(this,
+ "Enter View Name",
+ "Edit View Name",
+ JOptionPane.QUESTION_MESSAGE);
+
+ if (reply != null)
+ {
+ viewport.viewName = reply;
+ tabbedPane.setTitleAt( tabbedPane.getSelectedIndex() ,reply);
+ }
+ }
+ }
+
+
+ public AlignViewport getCurrentView()
+ {
+ return viewport;
+ }
+
+
+ /**
+ * Open the dialog for regex description parsing.
+ */
+ protected void extractScores_actionPerformed(ActionEvent e)
+ {
+ ParseProperties pp = new jalview.analysis.ParseProperties(viewport.alignment);
+ if (pp.getScoresFromDescription("col", "score column ", "\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)\\W+([-+]?\\d*\\.?\\d*e?-?\\d*)")>0)
+ {
+ buildSortByAnnotationScoresMenu();
+ }
+ }
+}
+
+class PrintThread
+ extends Thread
+{
+ AlignmentPanel ap;
+ public PrintThread(AlignmentPanel ap)
+ {
+ this.ap = ap;
+ }
+ static PageFormat pf;
+ public void run()
+ {
+ PrinterJob printJob = PrinterJob.getPrinterJob();
+
+ if (pf != null)
+ {
+ printJob.setPrintable(ap, pf);
+ }
+ else
+ {
+ printJob.setPrintable(ap);
+ }
+
+ if (printJob.printDialog())
+ {
+ try
+ {
+ printJob.print();
+ }
+ catch (Exception PrintException)
+ {
+ PrintException.printStackTrace();
+ }
+ }
+ }
+}