-/********************\r
- * 2004 Jalview Reengineered\r
- * Barton Group\r
- * Dundee University\r
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
*\r
- * AM Waterhouse\r
- *******************/\r
-\r
-\r
-\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 jalview.jbgui.GAlignFrame;\r
-import jalview.schemes.*;\r
-import jalview.datamodel.*;\r
-import jalview.analysis.*;\r
-import jalview.io.*;\r
-import MCview.*;\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
import javax.swing.event.*;\r
-import java.util.*;\r
\r
-public class AlignFrame extends GAlignFrame\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
+\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+public class AlignFrame\r
+ extends GAlignFrame\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
final AlignmentPanel alignPanel;\r
final 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
+ * Creates a new AlignFrame object.\r
+ *\r
+ * @param al DOCUMENT ME!\r
+ */\r
public AlignFrame(AlignmentI al)\r
{\r
- super();\r
- viewport = new AlignViewport(al,true,true,true,false);\r
+ viewport = new AlignViewport(al);\r
+\r
+ if(viewport.vconsensus==null)\r
+ {\r
+ //Out of memory caluclating 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
+ alignPanel.annotationPanel.adjustPanelHeight();\r
+ alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel.\r
+ annotationPanel.getPreferredSize());\r
+ alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel.\r
+ getPreferredSize());\r
+ alignPanel.setAnnotationVisible(viewport.getShowAnnotation());\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
getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER);\r
- fontNameMenuItem.setText(viewport.getFont().getName());\r
- fontSizeMenuItem.setText(viewport.getFont().getSize()+"");\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
+ addServiceListeners();\r
}\r
\r
- protected void saveAs_actionPerformed(ActionEvent e)\r
+ /* Set up intrinsic listeners for dynamically generated GUI bits. */\r
+ private void addServiceListeners()\r
{\r
- JFileChooser chooser = new JFileChooser(jalview.bin.Cache.LAST_DIRECTORY);\r
- chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format.");\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
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param String DOCUMENT ME!\r
+ */\r
+\r
+ public void parseGroupsFile(String file)\r
+ {\r
+ try\r
+ {\r
+ BufferedReader in = new BufferedReader(new FileReader(file));\r
+ SequenceI seq = null;\r
+ String line, text, token;\r
+ UserColourScheme ucs;\r
+ int index, start, end;\r
+ StringTokenizer st;\r
+ SequenceGroup sg;\r
+ while ( (line = in.readLine()) != null)\r
+ {\r
+ st = new StringTokenizer(line, "\t");\r
+ if (st.countTokens() != 6)\r
+ {\r
+ System.out.println("Groups file " + file +\r
+ " is invalid. Read help file.");\r
+ System.exit(1);\r
+ }\r
+\r
+ while (st.hasMoreElements())\r
+ {\r
+ text = st.nextToken();\r
+ token = st.nextToken();\r
+ if (!token.equals("ID_NOT_SPECIFIED"))\r
+ {\r
+ index = viewport.alignment.findIndex(viewport.alignment.findName(\r
+ token));\r
+ st.nextToken();\r
+ }\r
+ else\r
+ {\r
+ index = Integer.parseInt(st.nextToken());\r
+ }\r
+\r
+ start = Integer.parseInt(st.nextToken());\r
+ end = Integer.parseInt(st.nextToken());\r
+ ucs = new UserColourScheme(st.nextToken());\r
+\r
+ seq = viewport.alignment.getSequenceAt(index);\r
+ start = seq.findIndex(start) - 1;\r
+ end = seq.findIndex(end) - 1;\r
+\r
+ sg = new SequenceGroup(text, ucs, true, true, false, start, end);\r
+ sg.addSequence(seq, true);\r
+\r
+ viewport.alignment.addGroup(sg);\r
+ }\r
+ }\r
+\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ System.out.println("Error parsing groups file: " + ex);\r
+ }\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(\r
+ "LAST_DIRECTORY"),\r
+ new String[]\r
+ {\r
+ "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",\r
+ "jar"\r
+ },\r
+ new String[]\r
+ {\r
+ "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"\r
+ }, currentFileFormat);\r
+\r
+ chooser.setAcceptAllFileFilterUsed(false);\r
+ chooser.setFileView(new JalviewFileView());\r
+ chooser.setDialogTitle("Save Alignment to file");\r
chooser.setToolTipText("Save");\r
+\r
int value = chooser.showSaveDialog(this);\r
- if(value == JFileChooser.APPROVE_OPTION)\r
- {\r
- String choice = chooser.getSelectedFile().getPath();\r
- jalview.bin.Cache.LAST_DIRECTORY = choice;\r
- String output = FormatAdapter.get(e.getActionCommand(), viewport.getAlignment().getSequences());\r
- try{\r
- java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) );\r
- out.println(output);\r
- out.close();\r
+\r
+ if (value == JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ currentFileFormat = chooser.getSelectedFormat();\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
- catch(Exception ex){}\r
+\r
+ Jalview2XML.SaveAlignment(this, file, shortName);\r
+\r
+ // USE Jalview2XML to save this file\r
+ return true;\r
}\r
+ else\r
+ {\r
+ String output = FormatAdapter.formatSequences(format,\r
+ viewport.getAlignment().\r
+ getSequences());\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
+ 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
- CutAndPasteTransfer cap = new CutAndPasteTransfer(false);\r
- JInternalFrame frame = new JInternalFrame();\r
- cap.formatForOutput();\r
- frame.setContentPane(cap);\r
- Desktop.addInternalFrame(frame, "Alignment output - "+e.getActionCommand(), 600, 500);\r
- cap.setText( FormatAdapter.get(e.getActionCommand(), viewport.getAlignment().getSequences()));\r
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
+ Desktop.addInternalFrame(cap,\r
+ "Alignment output - " + e.getActionCommand(), 600,\r
+ 500);\r
+ cap.setText(FormatAdapter.formatSequences(e.getActionCommand(),\r
+ viewport.getAlignment().\r
+ getSequences()));\r
}\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
protected void htmlMenuItem_actionPerformed(ActionEvent e)\r
{\r
- HTMLOutput htmlOutput = new HTMLOutput(viewport);\r
- htmlOutput = null;\r
+ new HTMLOutput(viewport);\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
thread.start();\r
}\r
\r
- class PrintThread extends Thread\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void closeMenuItem_actionPerformed(ActionEvent e)\r
{\r
- public void run()\r
+ try\r
{\r
- PrinterJob printJob = PrinterJob.getPrinterJob();\r
- PageFormat pf = printJob.pageDialog(printJob.defaultPage());\r
- printJob.setPrintable(alignPanel, pf);\r
- if (printJob.printDialog())\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
+ if (hi.getType() == HistoryItem.SORT)\r
+ {\r
+ for (int i = 0; i < hi.getSequences().size(); i++)\r
{\r
- try\r
+ viewport.alignment.getSequences().setElementAt(hi.getSequences()\r
+ .elementAt(i),\r
+ i);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ for (int i = 0; i < hi.getSequences().size(); i++)\r
+ {\r
+ SequenceI restore = (SequenceI) hi.getSequences().elementAt(i);\r
+\r
+ if (restore.getLength() == 0)\r
{\r
- printJob.print();\r
+ restore.setSequence(hi.getHidden().elementAt(i).toString());\r
+ viewport.alignment.getSequences().insertElementAt(restore,\r
+ hi.getAlignIndex(i));\r
}\r
- catch (Exception PrintException)\r
+ else\r
{\r
- PrintException.printStackTrace();\r
+ restore.setSequence(hi.getHidden().elementAt(i).toString());\r
+ }\r
+ }\r
+\r
+ if (hi.getType() == HistoryItem.PASTE)\r
+ {\r
+ for (int i = viewport.alignment.getHeight() - 1;\r
+ i > (hi.getSequences().size() - 1); i--)\r
+ {\r
+ viewport.alignment.deleteSequence(i);\r
}\r
}\r
}\r
\r
- }\r
-\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.sequences.contains(seq))\r
+ {\r
+ continue;\r
+ }\r
+\r
+ SequenceI temp = viewport.alignment.getSequenceAt(i - 1);\r
+\r
+ if (sg.sequences.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.sequences.contains(seq))\r
+ {\r
+ continue;\r
+ }\r
+\r
+ SequenceI temp = viewport.alignment.getSequenceAt(i + 1);\r
+\r
+ if (sg.sequences.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
+ * 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
+ SequenceGroup sg = viewport.getSelectionGroup();\r
+\r
+ Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();\r
+ StringBuffer buffer = new StringBuffer();\r
+\r
+ Hashtable orderedSeqs = new Hashtable();\r
+\r
+ for (int i = 0; i < sg.getSize(); i++)\r
+ {\r
+ SequenceI seq = sg.getSequenceAt(i);\r
+ int index = viewport.alignment.findIndex(seq);\r
+ orderedSeqs.put(index + "", seq);\r
+ }\r
+\r
+ int index = 0, startRes, endRes;\r
+ char ch;\r
+\r
+ for (int i = 0; i < sg.getSize(); i++)\r
+ {\r
+ SequenceI seq = null;\r
+\r
+ while (seq == null)\r
+ {\r
+ if (orderedSeqs.containsKey(index + ""))\r
+ {\r
+ seq = (SequenceI) orderedSeqs.get(index + "");\r
+ index++;\r
+\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ index++;\r
+ }\r
+ }\r
+ //FIND START RES\r
+ //Returns residue following index if gap\r
+ startRes = seq.findPosition(sg.getStartRes());\r
+\r
+ //FIND END RES\r
+ //Need to find the residue preceeding index if gap\r
+ endRes = 0;\r
+\r
+ for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)\r
+ {\r
+ ch = seq.getCharAt(j);\r
+ if (!jalview.util.Comparison.isGap( (ch)))\r
+ {\r
+ endRes++;\r
+ }\r
+ }\r
+\r
+ if (endRes > 0)\r
+ {\r
+ endRes += seq.getStart() - 1;\r
+ }\r
+\r
+ buffer.append(seq.getName() + "\t" +\r
+ startRes + "\t" +\r
+ endRes + "\t" +\r
+ seq.getSequence(sg.getStartRes(),\r
+ sg.getEndRes() + 1) + "\n");\r
+ }\r
+\r
+ c.setContents(new StringSelection(buffer.toString()), null);\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
+ StringTokenizer st = new StringTokenizer(str);\r
+ ArrayList seqs = new ArrayList();\r
+\r
+ while (st.hasMoreElements())\r
+ {\r
+ String name = st.nextToken();\r
+ int start = Integer.parseInt(st.nextToken());\r
+ int end = Integer.parseInt(st.nextToken());\r
+ Sequence sequence = new Sequence(name, st.nextToken(), start,\r
+ end);\r
+\r
+ if (!newAlignment)\r
+ {\r
+ viewport.alignment.addSequence(sequence);\r
+ }\r
+ else\r
+ {\r
+ seqs.add(sequence);\r
+ }\r
+ }\r
+\r
+ if (newAlignment)\r
+ {\r
+ SequenceI[] newSeqs = new SequenceI[seqs.size()];\r
+ seqs.toArray(newSeqs);\r
+\r
+ AlignFrame af = new AlignFrame(new Alignment(newSeqs));\r
+ String newtitle = new String("Copied sequences");\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
+ else\r
+ {\r
+ viewport.setEndSeq(viewport.alignment.getHeight());\r
+ viewport.alignment.getWidth();\r
+ viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
+ }\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ // could be anything being pasted in here\r
+ }\r
+\r
\r
+ }\r
\r
- public void closeMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void cut_actionPerformed(ActionEvent e)\r
{\r
- try{\r
- this.setClosed(true);\r
- }catch(Exception ex){}\r
+ copy_actionPerformed(null);\r
+ delete_actionPerformed(null);\r
}\r
\r
- ArrayList historyList = new ArrayList();\r
- ArrayList redoList = new ArrayList();\r
-\r
- void updateEditMenuBar()\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void delete_actionPerformed(ActionEvent e)\r
{\r
- if(historyList.size()>0)\r
- {\r
- undoMenuItem.setEnabled(true);\r
- Object [] history = (Object[])historyList.get(0);\r
- undoMenuItem.setText("Undo "+history[0]);\r
- }\r
- else\r
+ boolean seqsdeleted = false;\r
+\r
+ if (viewport.getSelectionGroup() == null)\r
{\r
- undoMenuItem.setEnabled(false);\r
- undoMenuItem.setText("Undo");\r
+ return;\r
}\r
\r
- if(redoList.size()>0)\r
- {\r
- redoMenuItem.setEnabled(true);\r
- Object [] history = (Object[])redoList.get(0);\r
- redoMenuItem.setText("Redo "+history[0]);\r
- }\r
- else\r
+ addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,\r
+ HistoryItem.HIDE));\r
+\r
+ SequenceGroup sg = viewport.getSelectionGroup();\r
+ boolean allSequences = false;\r
+ if (sg.sequences.size() == viewport.alignment.getHeight())\r
{\r
- redoMenuItem.setEnabled(false);\r
- redoMenuItem.setText("Redo");\r
+ allSequences = true;\r
}\r
- }\r
\r
- public void addHistoryItem(String type)\r
- {\r
- // must make sure we add new sequence objects her, not refs to the existing sequences\r
- redoList.clear();\r
- SequenceI[] seq = new SequenceI[viewport.getAlignment().getHeight()];\r
- for(int i=0; i<viewport.getAlignment().getHeight(); i++)\r
+ for (int i = 0; i < sg.sequences.size(); i++)\r
{\r
- seq[i] = new Sequence( viewport.getAlignment().getSequenceAt(i).getName(),\r
- viewport.getAlignment().getSequenceAt(i).getSequence());\r
- }\r
+ SequenceI seq = sg.getSequenceAt(i);\r
+ int index = viewport.getAlignment().findIndex(seq);\r
+ seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);\r
\r
- historyList.add(0, new Object[]{type, seq} );\r
- updateEditMenuBar();\r
- }\r
+ // If the cut affects all sequences, remove highlighted columns\r
+ if (allSequences)\r
+ {\r
+ viewport.getColumnSelection().removeElements(sg.getStartRes(),\r
+ sg.getEndRes() + 1);\r
+ }\r
\r
- protected void undoMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- Object [] history = (Object[])historyList.remove(0);\r
- // add the redo state before continuing!!\r
- SequenceI[] seq = new SequenceI[viewport.getAlignment().getHeight()];\r
- for (int i = 0; i < viewport.getAlignment().getHeight(); i++)\r
- {\r
- seq[i] = new Sequence(viewport.getAlignment().getSequenceAt(i).getName(),\r
- viewport.getAlignment().getSequenceAt(i).\r
- getSequence());\r
+ if (seq.getSequence().length() < 1)\r
+ {\r
+ seqsdeleted = true;\r
+ viewport.getAlignment().deleteSequence(seq);\r
+ }\r
+ else\r
+ {\r
+ viewport.getAlignment().getSequences().setElementAt(seq, index);\r
+ }\r
}\r
- /////////\r
\r
- redoList.add(0, new Object[] {history[0], seq});\r
+ viewport.setSelectionGroup(null);\r
+ viewport.alignment.deleteGroup(sg);\r
\r
- seq = (SequenceI[]) history[1];\r
- viewport.setAlignment( new Alignment(seq) );\r
- updateEditMenuBar();\r
- alignPanel.RefreshPanels();\r
- }\r
+ viewport.firePropertyChange("alignment", null,\r
+ viewport.getAlignment().getSequences());\r
\r
\r
- protected void redoMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- Object [] history = (Object[])redoList.remove(0);\r
- SequenceI[] seq = (SequenceI[]) history[1];\r
- viewport.setAlignment( new Alignment(seq) );\r
- updateEditMenuBar();\r
- alignPanel.RefreshPanels();\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
- public void groupsMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void deleteGroups_actionPerformed(ActionEvent e)\r
{\r
- GroupEditor geditor = new GroupEditor(viewport, alignPanel);\r
- JInternalFrame frame = new JInternalFrame();\r
- frame.setContentPane(geditor);\r
- Desktop.addInternalFrame(frame, "Group editor", 710, 410);\r
- frame.setResizable(false);\r
+ viewport.alignment.deleteAllGroups();\r
+ viewport.setSelectionGroup(null);\r
+ alignPanel.repaint();\r
}\r
\r
-\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)\r
{\r
- Selection sel = viewport.getSelection();\r
- for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)\r
- sel.addElement( viewport.getAlignment().getSequenceAt(i));\r
- PaintRefresher.Refresh(null);\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
- viewport.getSelection().clear();\r
- PaintRefresher.Refresh(null);\r
+ viewport.setSelectionGroup(null);\r
+ viewport.getColumnSelection().clear();\r
+ viewport.setSelectionGroup(null);\r
+ alignPanel.annotationPanel.activeRes = null;\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
- Selection sel = viewport.getSelection();\r
- for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)\r
+ SequenceGroup sg = viewport.getSelectionGroup();\r
+\r
+ if (sg == null)\r
{\r
- if (sel.contains(viewport.getAlignment().getSequenceAt(i)))\r
- sel.removeElement(viewport.getAlignment().getSequenceAt(i));\r
- else\r
- sel.addElement(viewport.getAlignment().getSequenceAt(i));\r
+ selectAllSequenceMenuItem_actionPerformed(null);\r
+\r
+ return;\r
}\r
- PaintRefresher.Refresh(null);\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
- public void deselectAllColumnsMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- viewport.getColumnSelection().clear();\r
- repaint();\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
- addHistoryItem("delete columns");\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
- alignPanel.RefreshPanels();\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
- addHistoryItem("delete columns");\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
- if(max>1)\r
- viewport.getAlignment().trimRight(max);\r
+ viewport.getAlignment().trimRight(max);\r
\r
- alignPanel.RefreshPanels();\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("delete gapped columns");\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
- alignPanel.RefreshPanels();\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("delete all gaps");\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
- for (int i=0; i < viewport.getAlignment().getSequences().size();i++)\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().sequences != null\r
+ && viewport.getSelectionGroup().sequences.size() > 0)\r
{\r
- current = viewport.getAlignment().getSequenceAt(i);\r
+ seqs = viewport.getSelectionGroup().sequences;\r
+ start = viewport.getSelectionGroup().getStartRes();\r
+ end = viewport.getSelectionGroup().getEndRes();\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
- for (int j=0; j < jSize; j++)\r
- if (current.getCharAt(j)=='-' || current.getCharAt(j)=='.' || current.getCharAt(j)==' ')\r
+\r
+ int j = start;\r
+\r
+ do\r
+ {\r
+ if (jalview.util.Comparison.isGap(current.getCharAt(j)))\r
{\r
current.deleteCharAt(j);\r
j--;\r
jSize--;\r
}\r
+ j++;\r
+ }\r
+ while (j < end && j < jSize);\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.vconsensus!=null)\r
+ {\r
+ viewport.updateConsensus();\r
+ viewport.updateConservation();\r
+ }\r
+ resetAllColourSchemes();\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
- alignPanel.RefreshPanels();\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(sg.sequences, sg.getWidth());\r
+ }\r
+ sg.recalcConservation();\r
+ }\r
}\r
\r
- public void setGapCharMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void padGapsMenuitem_actionPerformed(ActionEvent e)\r
{\r
- char thisChar = '-';\r
- char nextChar = '.';\r
- if(viewport.getGapCharacter()=='-')\r
+ addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment,\r
+ HistoryItem.HIDE));\r
+\r
+ SequenceI current;\r
+ int Width = viewport.getAlignment().getWidth();\r
+\r
+ for (int i = 0; i < viewport.getAlignment().getSequences().size();\r
+ i++)\r
{\r
- thisChar = '.';\r
- nextChar = '-';\r
+ current = viewport.getAlignment().getSequenceAt(i);\r
+\r
+ if (current.getLength() < Width)\r
+ {\r
+ current.insertCharAt(Width - 1, viewport.getGapCharacter());\r
+ }\r
}\r
- setGapCharMenuItem.setText("Set gap character to \""+nextChar+"\"");\r
- viewport.setGapCharacter(thisChar);\r
- alignPanel.RefreshPanels();\r
+\r
+ alignmentChanged();\r
}\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void findMenuItem_actionPerformed(ActionEvent e)\r
{\r
- JOptionPane op = new JOptionPane();\r
- JInternalFrame frame = op.createInternalFrame(this, "Find");\r
+ JInternalFrame frame = new JInternalFrame();\r
Finder finder = new Finder(viewport, alignPanel, frame);\r
frame.setContentPane(finder);\r
- frame.setSize(300,110);\r
- frame.setVisible(true);\r
+ Desktop.addInternalFrame(frame, "Find", 340, 110);\r
+ frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void font_actionPerformed(ActionEvent e)\r
+ {\r
+ FontChooser fc = new FontChooser(alignPanel);\r
}\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void fullSeqId_actionPerformed(ActionEvent e)\r
+ {\r
+ viewport.setShowFullId(fullSeqId.isSelected());\r
+\r
+ alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth());\r
+ alignPanel.repaint();\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
- public void fontNameMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void wrapMenuItem_actionPerformed(ActionEvent e)\r
{\r
- String fonts[] = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();\r
+ viewport.setWrapAlignment(wrapMenuItem.isSelected());\r
+ alignPanel.setWrapAlignment(wrapMenuItem.isSelected());\r
+ scaleAbove.setVisible(wrapMenuItem.isSelected());\r
+ scaleLeft.setVisible(wrapMenuItem.isSelected());\r
+ scaleRight.setVisible(wrapMenuItem.isSelected());\r
+ alignPanel.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
- String selection = JOptionPane.showInternalInputDialog(this,\r
- "Select font",\r
- "Font selection",\r
- JOptionPane.QUESTION_MESSAGE,\r
- null,fonts\r
- ,fontNameMenuItem.getText()).toString();\r
- if(selection!=null)\r
- {\r
- fontNameMenuItem.setText(selection);\r
- SetFont();\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
- public void fontSizeMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void viewBoxesMenuItem_actionPerformed(ActionEvent e)\r
{\r
- String selection = JOptionPane.showInternalInputDialog(this,\r
- "Select font size",\r
- "Font size",\r
- JOptionPane.QUESTION_MESSAGE,\r
- null, new String[]{"1","2","4","6","8","10","12","14","16","18","20"}\r
- ,fontSizeMenuItem.getText()).toString();\r
- if(selection!=null)\r
- {\r
- fontSizeMenuItem.setText(selection);\r
- SetFont();\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
- public void fontStyleMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void sequenceFeatures_actionPerformed(ActionEvent evt)\r
{\r
- String selection = JOptionPane.showInternalInputDialog(this,\r
- "Select font style",\r
- "Font style",\r
- JOptionPane.QUESTION_MESSAGE,\r
- null, new String[]{"plain", "bold", "italic"}\r
- ,fontStyleMenuItem.getText()).toString();\r
- if(selection!=null)\r
+ viewport.showSequenceFeatures(sequenceFeatures.isSelected());\r
+\r
+ if (viewport.showSequenceFeatures &&\r
+ ! ( (Alignment) viewport.alignment).featuresAdded)\r
{\r
- fontStyleMenuItem.setText(selection);\r
- SetFont();\r
+ SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport.\r
+ alignment,\r
+ alignPanel);\r
+ ( (Alignment) viewport.alignment).featuresAdded = true;\r
}\r
\r
+ alignPanel.repaint();\r
}\r
\r
- protected void colourTextMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void annotationPanelMenuItem_actionPerformed(ActionEvent e)\r
{\r
- viewport.setColourText( colourTextMenuItem.isSelected() );\r
- alignPanel.RefreshPanels();\r
+ if (annotationPanelMenuItem.isSelected() &&\r
+ viewport.getWrapAlignment())\r
+ {\r
+ annotationPanelMenuItem.setSelected(false);\r
+\r
+ return;\r
+ }\r
+\r
+ viewport.setShowAnnotation(annotationPanelMenuItem.isSelected());\r
+ alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected());\r
}\r
\r
- void SetFont()\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void overviewMenuItem_actionPerformed(ActionEvent e)\r
{\r
- int style = java.awt.Font.PLAIN;\r
- if(fontStyleMenuItem.getText().equals("bold"))\r
- style = java.awt.Font.BOLD;\r
- else if(fontStyleMenuItem.getText().equals("italic"))\r
- style = java.awt.Font.ITALIC;\r
+ if (alignPanel.overviewPanel != null)\r
+ {\r
+ return;\r
+ }\r
\r
- viewport.setFont(new java.awt.Font(fontNameMenuItem.getText(),\r
- style,\r
- Integer.parseInt(fontSizeMenuItem.getText())));\r
- alignPanel.RefreshPanels();\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
- protected void wrapMenuItem_actionPerformed(ActionEvent e)\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
- viewport.setWrapAlignment( wrapMenuItem.isSelected() );\r
- alignPanel.RefreshPanels();\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
- public void viewBoxesMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void taylorColour_actionPerformed(ActionEvent e)\r
{\r
- viewport.setShowBoxes( viewBoxesMenuItem.isSelected() );\r
- alignPanel.RefreshPanels();\r
+ changeColour(new TaylorColourScheme());\r
}\r
\r
- public void viewTextMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void hydrophobicityColour_actionPerformed(ActionEvent e)\r
{\r
- viewport.setShowText( viewTextMenuItem.isSelected() );\r
- alignPanel.RefreshPanels();\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
- protected void renderGapsMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void strandColour_actionPerformed(ActionEvent e)\r
{\r
- viewport.setRenderGaps(renderGapsMenuItem.isSelected());\r
- alignPanel.RefreshPanels();\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
- public void consensusGraphMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void nucleotideColour_actionPerformed(ActionEvent e)\r
{\r
- alignPanel.setGraphPanelVisible( consensusGraphMenuItem.isSelected() );\r
+ changeColour(new NucleotideColourScheme());\r
}\r
\r
- public void overviewMenuItem_actionPerformed(ActionEvent e)\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
+ 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(sg.sequences, 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
- JInternalFrame frame = new JInternalFrame();\r
- OverviewPanel overview = alignPanel.getOverviewPanel();\r
- try{\r
- overview = new OverviewPanel(alignPanel, viewport);\r
- frame.setContentPane(overview);\r
- Desktop.addInternalFrame(frame, "Overview " + this.getTitle(),\r
- frame.getWidth(), frame.getHeight());\r
- frame.pack();\r
- frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
- { public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt)\r
- {\r
- alignPanel.setOverviewPanel(null);\r
- };\r
- });\r
- alignPanel.setOverviewPanel( overview );\r
+ sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,\r
+ sg.getWidth()));\r
+ }\r
+ else\r
+ sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
\r
- }catch(java.lang.OutOfMemoryError ex)\r
- {\r
- JOptionPane.showInternalMessageDialog(this, "Sequence alignment too large to\nproduce overview image!!"\r
- +"\nTry reducing the font size.",\r
- "Out of memory", JOptionPane.WARNING_MESSAGE);\r
- }\r
\r
+ if (viewport.getConservationSelected())\r
+ {\r
+ Conservation c = new Conservation("Group",\r
+ ResidueProperties.propHash, 3,\r
+ sg.sequences, 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
- }\r
+ if (alignPanel.getOverviewPanel() != null)\r
+ {\r
+ alignPanel.getOverviewPanel().updateOverviewImage();\r
+ }\r
\r
- protected void noColourmenuItem_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setGlobalColourScheme( null );\r
- alignPanel.setColourScheme();\r
+ alignPanel.repaint();\r
}\r
\r
-\r
- public void clustalColour_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void modifyPID_actionPerformed(ActionEvent e)\r
{\r
- viewport.setGlobalColourScheme(new ClustalxColourScheme( ));\r
- alignPanel.setColourScheme( );\r
+ if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)\r
+ {\r
+ SliderPanel.setPIDSliderSource(alignPanel,\r
+ viewport.getGlobalColourScheme(),\r
+ "Background");\r
+ SliderPanel.showPIDSlider();\r
+ }\r
}\r
\r
- public void zappoColour_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void modifyConservation_actionPerformed(ActionEvent e)\r
{\r
- viewport.setGlobalColourScheme(new ZappoColourScheme() );\r
- alignPanel.setColourScheme( );\r
+ if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)\r
+ {\r
+ SliderPanel.setConservationSlider(alignPanel,\r
+ viewport.globalColourScheme,\r
+ "Background");\r
+ SliderPanel.showConservationSlider();\r
+ }\r
}\r
\r
- public void taylorColour_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void conservationMenuItem_actionPerformed(ActionEvent e)\r
{\r
- viewport.setGlobalColourScheme(new TaylorColourScheme() );\r
- alignPanel.setColourScheme( );\r
- }\r
+ viewport.setConservationSelected(conservationMenuItem.isSelected());\r
\r
+ viewport.setAbovePIDThreshold(false);\r
+ abovePIDThreshold.setSelected(false);\r
\r
- public void hydrophobicityColour_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setGlobalColourScheme( new HydrophobicColourScheme() );\r
- alignPanel.setColourScheme( );\r
- }\r
+ changeColour(viewport.getGlobalColourScheme());\r
\r
- public void helixColour_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setGlobalColourScheme( new HelixColourScheme() );\r
- alignPanel.setColourScheme();\r
+ modifyConservation_actionPerformed(null);\r
}\r
\r
-\r
- public void strandColour_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void abovePIDThreshold_actionPerformed(ActionEvent e)\r
{\r
- viewport.setGlobalColourScheme(new StrandColourScheme() );\r
- alignPanel.setColourScheme( );\r
- }\r
+ viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected());\r
\r
+ conservationMenuItem.setSelected(false);\r
+ viewport.setConservationSelected(false);\r
\r
- public void turnColour_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setGlobalColourScheme(new TurnColourScheme() );\r
- alignPanel.setColourScheme( );\r
- }\r
+ ColourSchemeI cs = viewport.getGlobalColourScheme();\r
\r
+ changeColour(viewport.getGlobalColourScheme());\r
\r
- public void buriedColour_actionPerformed(ActionEvent e)\r
- {\r
- viewport.setGlobalColourScheme( new BuriedColourScheme() );\r
- alignPanel.setColourScheme( );\r
+ modifyPID_actionPerformed(null);\r
}\r
\r
-\r
- protected void conservationMenuItem_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void userDefinedColour_actionPerformed(ActionEvent e)\r
{\r
- viewport.setConservationSelected(conservationMenuItem.isSelected());\r
- alignPanel.setColourScheme();\r
-\r
- if(conservationMenuItem.isSelected())\r
+ if (e.getActionCommand().equals("User Defined..."))\r
{\r
- SliderPanel sp = new SliderPanel(alignPanel, 30, true, viewport.getGlobalColourScheme());\r
- JInternalFrame frame = new JInternalFrame();\r
- frame.setContentPane(sp);\r
- Desktop.addInternalFrame(frame, "Conservation Colour Increment", 400, 90);\r
- frame.setMaximizable(false);\r
+ new UserDefinedColours(alignPanel, null);\r
}\r
- }\r
+ else\r
+ {\r
+ UserColourScheme udc = (UserColourScheme) UserDefinedColours.\r
+ getUserColourSchemes().get(e.getActionCommand());\r
\r
+ changeColour(udc);\r
+ }\r
+ }\r
\r
- public void abovePIDThreshold_actionPerformed(ActionEvent e)\r
+ public void updateUserColourMenu()\r
{\r
- if(abovePIDThreshold.isSelected())\r
+\r
+ Component[] menuItems = colourMenu.getMenuComponents();\r
+ int i, iSize = menuItems.length;\r
+ for (i = 0; i < iSize; i++)\r
{\r
- SliderPanel sp = new SliderPanel(alignPanel, 70, false,\r
- viewport.getGlobalColourScheme());\r
- JInternalFrame frame = new JInternalFrame();\r
- frame.setContentPane(sp);\r
- Desktop.addInternalFrame(frame, "Percentage Identity Threshold", 400, 90);\r
- frame.setMaximizable(false);\r
+ if (menuItems[i].getName() != null &&\r
+ menuItems[i].getName().equals("USER_DEFINED"))\r
+ {\r
+ colourMenu.remove(menuItems[i]);\r
+ iSize--;\r
+ }\r
}\r
- }\r
-\r
+ if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)\r
+ {\r
+ java.util.Enumeration userColours = jalview.gui.UserDefinedColours.\r
+ getUserColourSchemes().keys();\r
\r
- public void userDefinedColour_actionPerformed(ActionEvent e)\r
- {\r
- JInternalFrame frame = new JInternalFrame();\r
- UserDefinedColours chooser = new UserDefinedColours( frame, alignPanel, null);\r
- frame.setContentPane(chooser);\r
- Desktop.addInternalFrame(frame,"User defined colours", 450,540 );\r
- frame.setResizable(false);\r
- frame.setIconifiable(false);\r
- frame.setMaximizable(false);\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
- viewport.setGlobalColourScheme( new PIDColourScheme() );\r
- alignPanel.setColourScheme( );\r
+ changeColour(new PIDColourScheme());\r
}\r
\r
-\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void BLOSUM62Colour_actionPerformed(ActionEvent e)\r
{\r
- viewport.setGlobalColourScheme( new Blosum62ColourScheme(viewport) );\r
- alignPanel.setColourScheme();\r
- }\r
-\r
-\r
-\r
- protected void schemeKeyMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- ColourKey colourKey = new ColourKey( viewport.getGlobalColourScheme() );\r
- Desktop.addInternalFrame(colourKey, "Colour scheme key", 400, 320);\r
+ changeColour(new Blosum62ColourScheme());\r
}\r
\r
-\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void sortPairwiseMenuItem_actionPerformed(ActionEvent e)\r
{\r
- addHistoryItem("sort");\r
- AlignmentSorter.sortByPID(viewport.getAlignment(), viewport.getAlignment().getSequenceAt(0));\r
- alignPanel.RefreshPanels();\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("sort");\r
- AlignmentSorter.sortByID( viewport.getAlignment() );\r
- alignPanel.RefreshPanels();\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("sort");\r
- AlignmentSorter.sortByGroup(viewport.getAlignment());\r
- AlignmentSorter.sortGroups(viewport.getAlignment());\r
- alignPanel.RefreshPanels();\r
- }\r
-\r
- public void sortTreeOrderMenuItem_actionPerformed(ActionEvent e)\r
- {\r
- addHistoryItem("sort");\r
- if(viewport.getCurrentTree()==null)\r
- return;\r
+ addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,\r
+ HistoryItem.SORT));\r
\r
- AlignmentSorter.sortByTree(viewport.getAlignment(), viewport.getCurrentTree());\r
- alignPanel.RefreshPanels();\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
-\r
+ RedundancyPanel sp = new RedundancyPanel(alignPanel, this);\r
+ JInternalFrame frame = new JInternalFrame();\r
+ frame.setContentPane(sp);\r
+ Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400,\r
+ 100, false);\r
}\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)\r
{\r
- if(viewport.getSelection().size()<2)\r
- JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);\r
+ if ( (viewport.getSelectionGroup() == null) ||\r
+ (viewport.getSelectionGroup().getSize() < 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
}\r
}\r
\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
public void PCAMenuItem_actionPerformed(ActionEvent e)\r
{\r
- if( (viewport.getSelection().size()<4 && viewport.getSelection().size()>0)\r
- || viewport.getAlignment().getHeight()<4)\r
+ if ( ( (viewport.getSelectionGroup() != null) &&\r
+ (viewport.getSelectionGroup().getSize() < 4) &&\r
+ (viewport.getSelectionGroup().getSize() > 0)) ||\r
+ (viewport.getAlignment().getHeight() < 4))\r
{\r
- JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n"\r
- +"at least 4 input sequences.",\r
- "Sequence selection insufficient",\r
- JOptionPane.WARNING_MESSAGE);\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
- try{\r
+ try\r
+ {\r
PCAPanel pcaPanel = new PCAPanel(viewport, null);\r
JInternalFrame frame = new JInternalFrame();\r
frame.setContentPane(pcaPanel);\r
- Desktop.addInternalFrame(frame, "Principal component analysis", 400, 400);\r
- }catch(java.lang.OutOfMemoryError ex)\r
- {\r
- JOptionPane.showInternalMessageDialog(this, "Too many sequences selected\nfor Principal Component Analysis!!",\r
- "Out of memory", JOptionPane.WARNING_MESSAGE);\r
- }\r
-\r
-\r
+ Desktop.addInternalFrame(frame, "Principal component analysis",\r
+ 400, 400);\r
+ }\r
+ catch (java.lang.OutOfMemoryError ex)\r
+ {\r
+ JOptionPane.showInternalMessageDialog(this,\r
+ "Too many sequences selected\nfor Principal Component Analysis!!",\r
+ "Out of memory",\r
+ JOptionPane.WARNING_MESSAGE);\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
+ /**\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 BLOSUM62PID");\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
- JInternalFrame frame = new javax.swing.JInternalFrame();\r
- TreePanel tp=null;\r
- if (viewport.getSelection() != null && viewport.getSelection().size() > 3)\r
- {\r
- tp = new TreePanel(viewport, viewport.getSelection().asVector(),type, pwType,\r
- viewport.getStartRes(), viewport.getEndRes());\r
- }\r
- else\r
- {\r
- tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),\r
- type, pwType, viewport.getStartRes(),\r
- viewport.getEndRes());\r
- }\r
+ final TreePanel tp;\r
+\r
+ if ( (viewport.getSelectionGroup() != null) &&\r
+ (viewport.getSelectionGroup().getSize() > 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.sequences.size())\r
+ {\r
+ if ( ( (SequenceI) sg.sequences.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,\r
+ viewport.getSelectionGroup().sequences, type, pwType,\r
+ sg.getStartRes(), sg.getEndRes());\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
- frame.setContentPane(tp);\r
- Desktop.addInternalFrame(frame, title, 600, 500);\r
+ tp = new TreePanel(viewport,\r
+ viewport.getAlignment().getSequences(), type, pwType,\r
+ 0,\r
+ viewport.alignment.getWidth());\r
+ }\r
+\r
+ addTreeMenuItem(tp, title);\r
+ viewport.setCurrentTree(tp.getTree());\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
+ viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener()\r
+ {\r
+ public void propertyChange(PropertyChangeEvent evt)\r
+ {\r
+ if (evt.getPropertyName().equals("alignment"))\r
+ {\r
+ treePanel.getTree().UpdatePlaceHolders( (Vector) evt.getNewValue());\r
+ treePanel.repaint();\r
+ }\r
+ }\r
+ });\r
+ }\r
\r
- public void clustalAlignMenuItem_actionPerformed(ActionEvent e)\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
- JOptionPane.showInternalMessageDialog(this, "Jalview is currently being reengineered"\r
- +"\nwithin the Barton Group, Dundee University."\r
- +"\nThis will be available as a web service 2005",\r
- "Web service", JOptionPane.INFORMATION_MESSAGE);\r
+ // Now, check we have enough sequences\r
+ SequenceI[] msa = null;\r
+\r
+ if ( (viewport.getSelectionGroup() != null) &&\r
+ (viewport.getSelectionGroup().getSize() > 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()];\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
- public void pdbTest_actionPerformed(ActionEvent e)\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
- String reply = JOptionPane.showInternalInputDialog(this, "Enter pdb code", "PDB test viewer", JOptionPane.QUESTION_MESSAGE);\r
+ SequenceI seq = null;\r
+ SequenceI[] msa = null;\r
\r
- String url = "http://www.ebi.ac.uk/cgi-bin/pdbfetch?id=1a4u";\r
- if (reply.length()>1)\r
- url = "http://www.ebi.ac.uk/cgi-bin/pdbfetch?id="+reply;\r
+ if ( (viewport.getSelectionGroup() != null) &&\r
+ (viewport.getSelectionGroup().getSize() > 0))\r
+ {\r
+ // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!\r
+ SequenceGroup seqs = viewport.getSelectionGroup();\r
\r
- try\r
- {\r
- PDBfile pdb = new PDBfile(url,\r
- "URL");\r
- Sequence seq = (Sequence)viewport.getAlignment().getSequenceAt(0);\r
- seq.setPDBfile(pdb);\r
- ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).isVisible = true;\r
- ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).sequence = seq;\r
- // ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).colourBySequence();\r
-\r
- rotCanvas rc = new rotCanvas(pdb);\r
- JInternalFrame frame = new JInternalFrame();\r
- frame.setContentPane(rc);\r
- Desktop.addInternalFrame(frame, url, 400,400);\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
+ if ( (seqs.getSize() == 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()];\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 void doKeyPressed(KeyEvent evt)\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
+ viewport.getAlignment().getSequences(), nf,\r
+ "FromFile",\r
+ title);\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
- System.out.println(evt.getKeyChar());\r
- if(evt.isControlDown() && evt.getKeyChar()=='f')\r
- findMenuItem_actionPerformed(null);\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 ( (Desktop.discoverer.services != null)\r
+ && (Desktop.discoverer.services.size() > 0))\r
+ {\r
+ Vector msaws = (Vector) Desktop.discoverer.services.get("MsaWS");\r
+ Vector secstrpr = (Vector) Desktop.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
+ 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
+ MsaWSClient ct = new jalview.ws.MsaWSClient(sh, title, msa,\r
+ false, true);\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
+ MsaWSClient ct = new jalview.ws.MsaWSClient(sh, title, msa,\r
+ true, true);\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
+ jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh,\r
+ 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
}\r