From 9b9afd73c1bad3a4a098f3bc3185cf9315a9b1a8 Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 17 Aug 2005 16:30:02 +0000 Subject: [PATCH] Gui Modifications for Service Discovery. --- src/jalview/gui/AlignFrame.java | 3923 ++++++++++++++++++----------------- src/jalview/gui/AlignViewport.java | 4 +- src/jalview/gui/Desktop.java | 1078 +++++----- src/jalview/gui/WebserviceInfo.java | 24 +- 4 files changed, 2554 insertions(+), 2475 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 22c0a1d..3475e7a 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -18,32 +18,23 @@ */ package jalview.gui; -import jalview.analysis.*; - -import jalview.datamodel.*; - -import jalview.io.*; - -import jalview.jbgui.*; - -import jalview.schemes.*; - -import jalview.ws.*; +import java.beans.*; +import java.io.*; +import java.util.*; import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; import java.awt.print.*; - -import java.io.*; - -import java.beans.*; - -import java.util.*; - import javax.swing.*; import javax.swing.event.*; +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.io.*; +import jalview.jbgui.*; +import jalview.schemes.*; +import jalview.ws.*; /** * DOCUMENT ME! @@ -51,2164 +42,2250 @@ import javax.swing.event.*; * @author $author$ * @version $Revision$ */ -public class AlignFrame extends GAlignFrame +public class AlignFrame + extends GAlignFrame { - /** DOCUMENT ME!! */ - public static final int NEW_WINDOW_WIDTH = 700; - - /** DOCUMENT ME!! */ - public static final int NEW_WINDOW_HEIGHT = 500; - final AlignmentPanel alignPanel; - final AlignViewport viewport; - - /** DOCUMENT ME!! */ - public String currentFileFormat = null; - Stack historyList = new Stack(); - Stack redoList = new Stack(); - private int treeCount = 0; - - /** - * Creates a new AlignFrame object. - * - * @param al DOCUMENT ME! - */ - public AlignFrame(AlignmentI al) - { - viewport = new AlignViewport(al); - - alignPanel = new AlignmentPanel(this, viewport); - alignPanel.annotationPanel.adjustPanelHeight(); - alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel.annotationPanel.getPreferredSize()); - alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel.getPreferredSize()); - alignPanel.setAnnotationVisible(viewport.getShowAnnotation()); - - getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); - - addInternalFrameListener(new InternalFrameAdapter() - { - public void internalFrameActivated(InternalFrameEvent evt) - { - javax.swing.SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - alignPanel.requestFocus(); - } - }); - } - }); - } - - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void parseGroupsFile(String file) - { - try{ - BufferedReader in = new BufferedReader(new FileReader(file)); - SequenceI seq=null; - String line, text, token; - UserColourScheme ucs; - int index, start, end; - StringTokenizer st; - SequenceGroup sg; - while( (line = in.readLine())!=null) + /** DOCUMENT ME!! */ + public static final int NEW_WINDOW_WIDTH = 700; + + /** DOCUMENT ME!! */ + public static final int NEW_WINDOW_HEIGHT = 500; + final AlignmentPanel alignPanel; + final AlignViewport viewport; + + /** DOCUMENT ME!! */ + public String currentFileFormat = null; + Stack historyList = new Stack(); + Stack redoList = new Stack(); + private int treeCount = 0; + + /** + * Creates a new AlignFrame object. + * + * @param al DOCUMENT ME! + */ + public AlignFrame(AlignmentI al) + { + viewport = new AlignViewport(al); + + alignPanel = new AlignmentPanel(this, viewport); + alignPanel.annotationPanel.adjustPanelHeight(); + alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel. + annotationPanel.getPreferredSize()); + alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel. + getPreferredSize()); + alignPanel.setAnnotationVisible(viewport.getShowAnnotation()); + + getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); + + addInternalFrameListener(new InternalFrameAdapter() + { + public void internalFrameActivated(InternalFrameEvent evt) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() { - st = new StringTokenizer(line, "\t"); - if(st.countTokens()!=6) + public void run() { - System.out.println("Groups file "+file+" is invalid. Read help file."); - System.exit(1); + alignPanel.requestFocus(); } + }); + } + }); + addServiceListeners(); + } + + /* Set up intrinsic listeners for dynamically generated GUI bits. */ + private void addServiceListeners() + { + + final AlignFrame thisFrame = this; + final java.beans.PropertyChangeListener thisListener; + // Do this once to get current state + thisFrame.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"); + thisFrame.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); + } + ; + }); + + } + + /** + * DOCUMENT ME! + * + * @param String DOCUMENT ME! + */ + + public void parseGroupsFile(String file) + { + try + { + BufferedReader in = new BufferedReader(new FileReader(file)); + SequenceI seq = null; + String line, text, token; + UserColourScheme ucs; + int index, start, end; + StringTokenizer st; + SequenceGroup sg; + while ( (line = in.readLine()) != null) + { + st = new StringTokenizer(line, "\t"); + if (st.countTokens() != 6) + { + System.out.println("Groups file " + file + + " is invalid. Read help file."); + System.exit(1); + } - while(st.hasMoreElements()) + while (st.hasMoreElements()) + { + text = st.nextToken(); + token = st.nextToken(); + if (!token.equals("ID_NOT_SPECIFIED")) { - text = st.nextToken(); - token = st.nextToken(); - if(!token.equals("ID_NOT_SPECIFIED")) - { - index = viewport.alignment.findIndex(viewport.alignment.findName( - token)); - st.nextToken(); - } - else - index = Integer.parseInt( st.nextToken() ); + index = viewport.alignment.findIndex(viewport.alignment.findName( + token)); + st.nextToken(); + } + else + { + index = Integer.parseInt(st.nextToken()); + } - start=Integer.parseInt( st.nextToken() ); - end = Integer.parseInt( st.nextToken() ); - ucs = new UserColourScheme(st.nextToken()); + start = Integer.parseInt(st.nextToken()); + end = Integer.parseInt(st.nextToken()); + ucs = new UserColourScheme(st.nextToken()); - seq = viewport.alignment.getSequenceAt(index); - start = seq.findIndex(start)-1; - end = seq.findIndex(end)-1; + seq = viewport.alignment.getSequenceAt(index); + start = seq.findIndex(start) - 1; + end = seq.findIndex(end) - 1; - sg = new SequenceGroup(text,ucs,true,true,false,start,end); - sg.addSequence( seq,true); + sg = new SequenceGroup(text, ucs, true, true, false, start, end); + sg.addSequence(seq, true); - viewport.alignment.addGroup(sg); - } + viewport.alignment.addGroup(sg); } + } - }catch(Exception ex){System.out.println("Error parsing groups file: "+ex);} } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void saveAlignmentMenu_actionPerformed(ActionEvent e) + catch (Exception ex) { - 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); + System.out.println("Error parsing groups file: " + ex); + } + } - chooser.setAcceptAllFileFilterUsed(false); - chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle("Save Alignment to file"); - chooser.setToolTipText("Save"); + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void saveAlignmentMenu_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); - int value = chooser.showSaveDialog(this); + chooser.setAcceptAllFileFilterUsed(false); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Save Alignment to file"); + chooser.setToolTipText("Save"); - if (value == JalviewFileChooser.APPROVE_OPTION) - { - currentFileFormat = chooser.getSelectedFormat(); - jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", - currentFileFormat); + int value = chooser.showSaveDialog(this); - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + if (value == JalviewFileChooser.APPROVE_OPTION) + { + currentFileFormat = chooser.getSelectedFormat(); + jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", + currentFileFormat); - saveAlignment(choice, currentFileFormat); - } + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + + saveAlignment(choice, currentFileFormat); } + } - public boolean saveAlignment(String file, String format) + public boolean saveAlignment(String file, String format) + { + if (format.equalsIgnoreCase("Jalview")) { - if (format.equalsIgnoreCase("Jalview")) + String shortName = title; + + if (shortName.indexOf(java.io.File.separatorChar) > -1) { - String shortName = title; + shortName = shortName.substring(shortName.lastIndexOf( + java.io.File.separatorChar) + 1); + } - if (shortName.indexOf(java.io.File.separatorChar) > -1) - { - shortName = shortName.substring(shortName.lastIndexOf( - java.io.File.separatorChar) + 1); - } + Jalview2XML.SaveAlignment(this, file, shortName); - Jalview2XML.SaveAlignment(this, file, shortName); + // USE Jalview2XML to save this file + return true; + } + else + { + String output = FormatAdapter.formatSequences(format, + viewport.getAlignment(). + getSequences()); + if (output == null) + { + return false; + } - // USE Jalview2XML to save this file + try + { + java.io.PrintWriter out = new java.io.PrintWriter( + new java.io.FileWriter(file)); + out.println(output); + out.close(); return true; } - else + catch (Exception ex) + { + ex.printStackTrace(); + } + } + return false; + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void outputText_actionPerformed(ActionEvent e) + { + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + Desktop.addInternalFrame(cap, + "Alignment output - " + e.getActionCommand(), 600, + 500); + cap.setText(FormatAdapter.formatSequences(e.getActionCommand(), + viewport.getAlignment(). + getSequences())); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void htmlMenuItem_actionPerformed(ActionEvent e) + { + new HTMLOutput(viewport); + } + + 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); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void printMenuItem_actionPerformed(ActionEvent e) + { + //Putting in a thread avoids Swing painting problems + PrintThread thread = new PrintThread(); + thread.start(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void closeMenuItem_actionPerformed(ActionEvent e) + { + try + { + this.setClosed(true); + } + catch (Exception ex) + { + } + } + + /** + * DOCUMENT ME! + */ + void updateEditMenuBar() + { + if (historyList.size() > 0) + { + undoMenuItem.setEnabled(true); + + HistoryItem hi = (HistoryItem) historyList.peek(); + undoMenuItem.setText("Undo " + hi.getDescription()); + } + else + { + undoMenuItem.setEnabled(false); + undoMenuItem.setText("Undo"); + } + + if (redoList.size() > 0) + { + redoMenuItem.setEnabled(true); + + HistoryItem hi = (HistoryItem) redoList.peek(); + redoMenuItem.setText("Redo " + hi.getDescription()); + } + else + { + redoMenuItem.setEnabled(false); + redoMenuItem.setText("Redo"); + } + } + + /** + * DOCUMENT ME! + * + * @param hi DOCUMENT ME! + */ + public void addHistoryItem(HistoryItem hi) + { + historyList.push(hi); + updateEditMenuBar(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void undoMenuItem_actionPerformed(ActionEvent e) + { + HistoryItem hi = (HistoryItem) historyList.pop(); + redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, + HistoryItem.HIDE)); + restoreHistoryItem(hi); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void redoMenuItem_actionPerformed(ActionEvent e) + { + HistoryItem hi = (HistoryItem) redoList.pop(); + restoreHistoryItem(hi); + updateEditMenuBar(); + viewport.updateConsensus(); + alignPanel.repaint(); + alignPanel.repaint(); + } + + // used by undo and redo + void restoreHistoryItem(HistoryItem hi) + { + if (hi.getType() == HistoryItem.SORT) + { + for (int i = 0; i < hi.getSequences().size(); i++) + { + viewport.alignment.getSequences().setElementAt(hi.getSequences() + .elementAt(i), + i); + } + } + else + { + for (int i = 0; i < hi.getSequences().size(); i++) { - String output = FormatAdapter.formatSequences(format, - viewport.getAlignment(). - getSequences()); - if(output==null) - return false; + SequenceI restore = (SequenceI) hi.getSequences().elementAt(i); - try + if (restore.getLength() == 0) { - java.io.PrintWriter out = new java.io.PrintWriter( - new java.io.FileWriter(file)); - out.println(output); - out.close(); - return true; + restore.setSequence(hi.getHidden().elementAt(i).toString()); + viewport.alignment.getSequences().insertElementAt(restore, + hi.getAlignIndex(i)); } - catch (Exception ex) + else { - ex.printStackTrace(); + restore.setSequence(hi.getHidden().elementAt(i).toString()); } } - return false; - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void outputText_actionPerformed(ActionEvent e) - { - CutAndPasteTransfer cap = new CutAndPasteTransfer(); - Desktop.addInternalFrame(cap, - "Alignment output - " + e.getActionCommand(), 600, 500); - cap.setText(FormatAdapter.formatSequences(e.getActionCommand(), - viewport.getAlignment().getSequences())); + if (hi.getType() == HistoryItem.PASTE) + { + for (int i = viewport.alignment.getHeight() - 1; + i > (hi.getSequences().size() - 1); i--) + { + viewport.alignment.deleteSequence(i); + } + } } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void htmlMenuItem_actionPerformed(ActionEvent e) - { - new HTMLOutput(viewport); - } + updateEditMenuBar(); - public void createImageMap(File file, String image) - { - alignPanel.makePNGImageMap(file, image); - } + viewport.updateConsensus(); + viewport.updateConservation(); + alignPanel.repaint(); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void createPNG(File f) - { - alignPanel.makePNG(f); - } + /** + * DOCUMENT ME! + * + * @param up DOCUMENT ME! + */ + public void moveSelectedSequences(boolean up) + { + SequenceGroup sg = viewport.getSelectionGroup(); - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void createEPS(File f) + if (sg == null) { - alignPanel.makeEPS(f); + return; } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void printMenuItem_actionPerformed(ActionEvent e) + if (up) { - //Putting in a thread avoids Swing painting problems - PrintThread thread = new PrintThread(); - thread.start(); - } + for (int i = 1; i < viewport.alignment.getHeight(); i++) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void closeMenuItem_actionPerformed(ActionEvent e) - { - try + if (!sg.sequences.contains(seq)) { - this.setClosed(true); + continue; } - catch (Exception ex) + + SequenceI temp = viewport.alignment.getSequenceAt(i - 1); + + if (sg.sequences.contains(temp)) { + continue; } - } - /** - * DOCUMENT ME! - */ - void updateEditMenuBar() + viewport.alignment.getSequences().setElementAt(temp, i); + viewport.alignment.getSequences().setElementAt(seq, i - 1); + } + } + else { - if (historyList.size() > 0) - { - undoMenuItem.setEnabled(true); + for (int i = viewport.alignment.getHeight() - 2; i > -1; i--) + { + SequenceI seq = viewport.alignment.getSequenceAt(i); - HistoryItem hi = (HistoryItem) historyList.peek(); - undoMenuItem.setText("Undo " + hi.getDescription()); - } - else + if (!sg.sequences.contains(seq)) { - undoMenuItem.setEnabled(false); - undoMenuItem.setText("Undo"); + continue; } - if (redoList.size() > 0) - { - redoMenuItem.setEnabled(true); + SequenceI temp = viewport.alignment.getSequenceAt(i + 1); - HistoryItem hi = (HistoryItem) redoList.peek(); - redoMenuItem.setText("Redo " + hi.getDescription()); - } - else + if (sg.sequences.contains(temp)) { - redoMenuItem.setEnabled(false); - redoMenuItem.setText("Redo"); + continue; } - } - /** - * DOCUMENT ME! - * - * @param hi DOCUMENT ME! - */ - public void addHistoryItem(HistoryItem hi) - { - historyList.push(hi); - updateEditMenuBar(); + viewport.alignment.getSequences().setElementAt(temp, i); + viewport.alignment.getSequences().setElementAt(seq, i + 1); + } } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void undoMenuItem_actionPerformed(ActionEvent e) + alignPanel.repaint(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void copy_actionPerformed(ActionEvent e) + { + if (viewport.getSelectionGroup() == null) { - HistoryItem hi = (HistoryItem) historyList.pop(); - redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, - HistoryItem.HIDE)); - restoreHistoryItem(hi); + return; } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void redoMenuItem_actionPerformed(ActionEvent e) + SequenceGroup sg = viewport.getSelectionGroup(); + + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuffer buffer = new StringBuffer(); + + Hashtable orderedSeqs = new Hashtable(); + + for (int i = 0; i < sg.getSize(); i++) { - HistoryItem hi = (HistoryItem) redoList.pop(); - restoreHistoryItem(hi); - updateEditMenuBar(); - viewport.updateConsensus(); - alignPanel.repaint(); - alignPanel.repaint(); + SequenceI seq = sg.getSequenceAt(i); + int index = viewport.alignment.findIndex(seq); + orderedSeqs.put(index + "", seq); } - // used by undo and redo - void restoreHistoryItem(HistoryItem hi) + int index = 0, startRes, endRes; + char ch; + + for (int i = 0; i < sg.getSize(); i++) { - if (hi.getType() == HistoryItem.SORT) + SequenceI seq = null; + + while (seq == null) + { + if (orderedSeqs.containsKey(index + "")) { - for (int i = 0; i < hi.getSequences().size(); i++) - { - viewport.alignment.getSequences().setElementAt(hi.getSequences() - .elementAt(i), - i); - } + seq = (SequenceI) orderedSeqs.get(index + ""); + index++; + + break; } else { - for (int i = 0; i < hi.getSequences().size(); i++) - { - SequenceI restore = (SequenceI) hi.getSequences().elementAt(i); + index++; + } + } + //FIND START RES + //Returns residue following index if gap + startRes = seq.findPosition(sg.getStartRes()); - if (restore.getLength() == 0) - { - restore.setSequence(hi.getHidden().elementAt(i).toString()); - viewport.alignment.getSequences().insertElementAt(restore, - hi.getAlignIndex(i)); - } - else - { - restore.setSequence(hi.getHidden().elementAt(i).toString()); - } - } + //FIND END RES + //Need to find the residue preceeding index if gap + endRes = 0; - if (hi.getType() == HistoryItem.PASTE) - { - for (int i = viewport.alignment.getHeight() - 1; - i > (hi.getSequences().size() - 1); i--) - { - viewport.alignment.deleteSequence(i); - } - } + for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++) + { + ch = seq.getCharAt(j); + if (!jalview.util.Comparison.isGap( (ch))) + { + endRes++; } + } - updateEditMenuBar(); + if (endRes > 0) + { + endRes += seq.getStart() - 1; + } - viewport.updateConsensus(); - viewport.updateConservation(); - alignPanel.repaint(); - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); - } + buffer.append(seq.getName() + "\t" + + startRes + "\t" + + endRes + "\t" + + seq.getSequence(sg.getStartRes(), + sg.getEndRes() + 1) + "\n"); + } + + c.setContents(new StringSelection(buffer.toString()), null); + } + + /** + * 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) + { + addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, + HistoryItem.PASTE)); + paste(false); + } + + /** + * DOCUMENT ME! + * + * @param newAlignment DOCUMENT ME! + */ + void paste(boolean newAlignment) + { + try + { + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable contents = c.getContents(this); + + if (contents == null) + { + return; + } - /** - * DOCUMENT ME! - * - * @param up DOCUMENT ME! - */ - public void moveSelectedSequences(boolean up) - { - SequenceGroup sg = viewport.getSelectionGroup(); + String str = (String) contents.getTransferData(DataFlavor.stringFlavor); + StringTokenizer st = new StringTokenizer(str); + ArrayList seqs = new ArrayList(); + + while (st.hasMoreElements()) + { + String name = st.nextToken(); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + Sequence sequence = new Sequence(name, st.nextToken(), start, + end); - if (sg == null) + if (!newAlignment) { - return; + viewport.alignment.addSequence(sequence); } - - if (up) + else { - for (int i = 1; i < viewport.alignment.getHeight(); i++) - { - SequenceI seq = viewport.alignment.getSequenceAt(i); - - if (!sg.sequences.contains(seq)) - { - continue; - } + seqs.add(sequence); + } + } - SequenceI temp = viewport.alignment.getSequenceAt(i - 1); + if (newAlignment) + { + SequenceI[] newSeqs = new SequenceI[seqs.size()]; + seqs.toArray(newSeqs); - if (sg.sequences.contains(temp)) - { - continue; - } + AlignFrame af = new AlignFrame(new Alignment(newSeqs)); + String newtitle = new String("Copied sequences"); - viewport.alignment.getSequences().setElementAt(temp, i); - viewport.alignment.getSequences().setElementAt(seq, i - 1); - } + if (title.startsWith("Copied sequences")) + { + newtitle = title; } else { - for (int i = viewport.alignment.getHeight() - 2; i > -1; i--) - { - SequenceI seq = viewport.alignment.getSequenceAt(i); + newtitle = newtitle.concat("- from " + title); + } - if (!sg.sequences.contains(seq)) - { - continue; - } + Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, + NEW_WINDOW_HEIGHT); + } + else + { + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + viewport.setEndSeq(viewport.alignment.getHeight()); + viewport.alignment.getWidth(); + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } + } + catch (Exception ex) + { + } - SequenceI temp = viewport.alignment.getSequenceAt(i + 1); + // could be anything being pasted in here + } - if (sg.sequences.contains(temp)) - { - continue; - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void cut_actionPerformed(ActionEvent e) + { + copy_actionPerformed(null); + delete_actionPerformed(null); + } - viewport.alignment.getSequences().setElementAt(temp, i); - viewport.alignment.getSequences().setElementAt(seq, i + 1); - } - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void delete_actionPerformed(ActionEvent e) + { + boolean seqsdeleted = false; - alignPanel.repaint(); + if (viewport.getSelectionGroup() == null) + { + return; } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void copy_actionPerformed(ActionEvent e) + addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, + HistoryItem.HIDE)); + + SequenceGroup sg = viewport.getSelectionGroup(); + boolean allSequences = false; + if (sg.sequences.size() == viewport.alignment.getHeight()) { - if (viewport.getSelectionGroup() == null) - { - return; - } + allSequences = true; + } + + for (int i = 0; i < sg.sequences.size(); i++) + { + SequenceI seq = sg.getSequenceAt(i); + int index = viewport.getAlignment().findIndex(seq); + seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1); - SequenceGroup sg = viewport.getSelectionGroup(); + // If the cut affects all sequences, remove highlighted columns + if (allSequences) + { + viewport.getColumnSelection().removeElements(sg.getStartRes(), + sg.getEndRes() + 1); + } - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - StringBuffer buffer = new StringBuffer(); + if (seq.getSequence().length() < 1) + { + seqsdeleted = true; + viewport.getAlignment().deleteSequence(seq); + } + else + { + viewport.getAlignment().getSequences().setElementAt(seq, index); + } + } - Hashtable orderedSeqs = new Hashtable(); + viewport.setSelectionGroup(null); + viewport.alignment.deleteGroup(sg); - for (int i = 0; i < sg.getSize(); i++) - { - SequenceI seq = sg.getSequenceAt(i); - int index = viewport.alignment.findIndex(seq); - orderedSeqs.put(index + "", seq); - } + if (seqsdeleted) + { + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + } - int index = 0, startRes, endRes; - char ch; + viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getHeight()); - for (int i = 0; i < sg.getSize(); i++) + if (viewport.getAlignment().getHeight() < 1) + { + try + { + this.setClosed(true); + } + catch (Exception ex) + { + } + } + + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void deleteGroups_actionPerformed(ActionEvent e) + { + viewport.alignment.deleteAllGroups(); + viewport.setSelectionGroup(null); + alignPanel.repaint(); + } + + /** + * 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); + PaintRefresher.Refresh(null, viewport.alignment); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e) + { + viewport.setSelectionGroup(null); + viewport.getColumnSelection().clear(); + viewport.setSelectionGroup(null); + alignPanel.annotationPanel.activeRes = null; + PaintRefresher.Refresh(null, viewport.alignment); + } + + /** + * 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); + } + + PaintRefresher.Refresh(null, viewport.alignment); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void remove2LeftMenuItem_actionPerformed(ActionEvent e) + { + ColumnSelection colSel = viewport.getColumnSelection(); + + if (colSel.size() > 0) + { + addHistoryItem(new HistoryItem("Remove Left", viewport.alignment, + HistoryItem.HIDE)); + + int min = colSel.getMin(); + viewport.getAlignment().trimLeft(min); + colSel.compensateForEdit(0, min); + + if (viewport.getSelectionGroup() != null) + { + viewport.getSelectionGroup().adjustForRemoveLeft(min); + } + + Vector groups = viewport.alignment.getGroups(); + + for (int i = 0; i < groups.size(); i++) + { + SequenceGroup sg = (SequenceGroup) groups.get(i); + + if (!sg.adjustForRemoveLeft(min)) { - SequenceI seq = null; + viewport.alignment.deleteGroup(sg); + } + } - while (seq == null) - { - if (orderedSeqs.containsKey(index + "")) - { - seq = (SequenceI) orderedSeqs.get(index + ""); - index++; + alignPanel.repaint(); + } + } - break; - } - else - { - index++; - } - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void remove2RightMenuItem_actionPerformed(ActionEvent e) + { + ColumnSelection colSel = viewport.getColumnSelection(); - //FIND START RES - //Returns residue following index if gap - startRes = seq.findPosition(sg.getStartRes()); + if (colSel.size() > 0) + { + addHistoryItem(new HistoryItem("Remove Right", viewport.alignment, + HistoryItem.HIDE)); - //FIND END RES - //Need to find the residue preceeding index if gap - endRes = 0; + int max = colSel.getMax(); + viewport.getAlignment().trimRight(max); - for (int j = 0; j < sg.getEndRes()+1 && j < seq.getLength(); j++) - { - ch = seq.getCharAt(j); - if (!jalview.util.Comparison.isGap( (ch))) - { - endRes++; - } - } + if (viewport.getSelectionGroup() != null) + { + viewport.getSelectionGroup().adjustForRemoveRight(max); + } - if(endRes>0) - { - endRes += seq.getStart() -1; - } + Vector groups = viewport.alignment.getGroups(); + + for (int i = 0; i < groups.size(); i++) + { + SequenceGroup sg = (SequenceGroup) groups.get(i); - buffer.append(seq.getName() + "\t" + - startRes + "\t" + - endRes + "\t" + - seq.getSequence(sg.getStartRes(), - sg.getEndRes() + 1) + "\n"); + if (!sg.adjustForRemoveRight(max)) + { + viewport.alignment.deleteGroup(sg); } + } - c.setContents(new StringSelection(buffer.toString()), null); + alignPanel.repaint(); } + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Remove Gapped Columns", + viewport.alignment, HistoryItem.HIDE)); + + viewport.getAlignment().removeGaps(); + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment, + HistoryItem.HIDE)); + + SequenceI current; + int jSize; + + Vector seqs = null; - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void pasteNew_actionPerformed(ActionEvent e) + int start = 0; + int end = viewport.alignment.getWidth(); + + if (viewport.getSelectionGroup() != null + && viewport.getSelectionGroup().sequences != null + && viewport.getSelectionGroup().sequences.size() > 0) { - paste(true); + seqs = viewport.getSelectionGroup().sequences; + start = viewport.getSelectionGroup().getStartRes(); + end = viewport.getSelectionGroup().getEndRes(); } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void pasteThis_actionPerformed(ActionEvent e) + else { - addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, - HistoryItem.PASTE)); - paste(false); + seqs = viewport.alignment.getSequences(); } - /** - * DOCUMENT ME! - * - * @param newAlignment DOCUMENT ME! - */ - void paste(boolean newAlignment) + for (int i = 0; i < seqs.size(); i++) { - try - { - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - Transferable contents = c.getContents(this); + current = (SequenceI) seqs.elementAt(i); + jSize = current.getLength(); - if (contents == null) - { - return; - } + int j = start; - String str = (String) contents.getTransferData(DataFlavor.stringFlavor); - StringTokenizer st = new StringTokenizer(str); - ArrayList seqs = new ArrayList(); - - while (st.hasMoreElements()) - { - String name = st.nextToken(); - int start = Integer.parseInt(st.nextToken()); - int end = Integer.parseInt(st.nextToken()); - Sequence sequence = new Sequence(name, st.nextToken(), start, - end); - - if (!newAlignment) - { - viewport.alignment.addSequence(sequence); - } - else - { - seqs.add(sequence); - } - } - - if (newAlignment) - { - SequenceI[] newSeqs = new SequenceI[seqs.size()]; - seqs.toArray(newSeqs); - - AlignFrame af = new AlignFrame(new Alignment(newSeqs)); - String newtitle = new String("Copied sequences"); - - if (title.startsWith("Copied sequences")) - { - newtitle = title; - } - else - { - newtitle = newtitle.concat("- from " + title); - } - - Desktop.addInternalFrame(af, newtitle, NEW_WINDOW_WIDTH, - NEW_WINDOW_HEIGHT); - } - else - { - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); - viewport.setEndSeq(viewport.alignment.getHeight()); - viewport.alignment.getWidth(); - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); - } - } - catch (Exception 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 e) - { - boolean seqsdeleted = false; - - if (viewport.getSelectionGroup() == null) - { - return; - } - - addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, - HistoryItem.HIDE)); - - SequenceGroup sg = viewport.getSelectionGroup(); - boolean allSequences = false; - if(sg.sequences.size()==viewport.alignment.getHeight()) - allSequences = true; - - for (int i = 0; i < sg.sequences.size(); i++) - { - SequenceI seq = sg.getSequenceAt(i); - int index = viewport.getAlignment().findIndex(seq); - seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1); - - // If the cut affects all sequences, remove highlighted columns - if(allSequences) - { - viewport.getColumnSelection().removeElements(sg.getStartRes(), sg.getEndRes()+1); - } - - - if (seq.getSequence().length() < 1) - { - seqsdeleted = true; - viewport.getAlignment().deleteSequence(seq); - } - else - { - viewport.getAlignment().getSequences().setElementAt(seq, index); - } - } - - viewport.setSelectionGroup(null); - viewport.alignment.deleteGroup(sg); - - if (seqsdeleted) - { - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); - } - - viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getHeight()); - - if (viewport.getAlignment().getHeight() < 1) - { - try - { - this.setClosed(true); - } - catch (Exception ex) - { - } - } - - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void deleteGroups_actionPerformed(ActionEvent e) - { - viewport.alignment.deleteAllGroups(); - viewport.setSelectionGroup(null); - alignPanel.repaint(); - } - - /** - * 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); - PaintRefresher.Refresh(null, viewport.alignment); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e) - { - viewport.setSelectionGroup(null); - viewport.getColumnSelection().clear(); - viewport.setSelectionGroup(null); - alignPanel.annotationPanel.activeRes = null; - PaintRefresher.Refresh(null, viewport.alignment); - } - - /** - * 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); - } - - PaintRefresher.Refresh(null, viewport.alignment); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void remove2LeftMenuItem_actionPerformed(ActionEvent e) - { - ColumnSelection colSel = viewport.getColumnSelection(); - - if (colSel.size() > 0) - { - addHistoryItem(new HistoryItem("Remove Left", viewport.alignment, - HistoryItem.HIDE)); - - int min = colSel.getMin(); - viewport.getAlignment().trimLeft(min); - colSel.compensateForEdit(0, min); - - if (viewport.getSelectionGroup() != null) - { - viewport.getSelectionGroup().adjustForRemoveLeft(min); - } - - Vector groups = viewport.alignment.getGroups(); - - for (int i = 0; i < groups.size(); i++) - { - SequenceGroup sg = (SequenceGroup) groups.get(i); - - if (!sg.adjustForRemoveLeft(min)) - { - viewport.alignment.deleteGroup(sg); - } - } - - alignPanel.repaint(); - } - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void remove2RightMenuItem_actionPerformed(ActionEvent e) - { - ColumnSelection colSel = viewport.getColumnSelection(); - - if (colSel.size() > 0) - { - addHistoryItem(new HistoryItem("Remove Right", viewport.alignment, - HistoryItem.HIDE)); - - int max = colSel.getMax(); - viewport.getAlignment().trimRight(max); - - if (viewport.getSelectionGroup() != null) - { - viewport.getSelectionGroup().adjustForRemoveRight(max); - } - - Vector groups = viewport.alignment.getGroups(); - - for (int i = 0; i < groups.size(); i++) - { - SequenceGroup sg = (SequenceGroup) groups.get(i); - - if (!sg.adjustForRemoveRight(max)) - { - viewport.alignment.deleteGroup(sg); - } - } - - alignPanel.repaint(); - } - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void removeGappedColumnMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem(new HistoryItem("Remove Gapped Columns", - viewport.alignment, HistoryItem.HIDE)); - - viewport.getAlignment().removeGaps(); - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void removeAllGapsMenuItem_actionPerformed(ActionEvent e) - { - addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment, - HistoryItem.HIDE)); - - SequenceI current; - int jSize; - - Vector seqs = null; - - int start = 0; - int end = viewport.alignment.getWidth(); - - - if (viewport.getSelectionGroup() != null - && viewport.getSelectionGroup().sequences != null - && viewport.getSelectionGroup().sequences.size()>0) - { - seqs = viewport.getSelectionGroup().sequences; - start = viewport.getSelectionGroup().getStartRes(); - end = viewport.getSelectionGroup().getEndRes(); - } - else - { - seqs = viewport.alignment.getSequences(); - } - - for (int i = 0; i < seqs.size(); i++) - { - current = (SequenceI) seqs.elementAt(i); - jSize = current.getLength(); - - int j = start; - - do - { - if (jalview.util.Comparison.isGap(current.getCharAt(j))) - { - current.deleteCharAt(j); - j--; - jSize--; - } - - j++; - } - while (j < end && j < jSize); - } - - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void padGapsMenuitem_actionPerformed(ActionEvent e) - { - addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, - HistoryItem.HIDE)); - - SequenceI current; - int Width = viewport.getAlignment().getWidth(); - - for (int i = 0; i < viewport.getAlignment().getSequences().size(); - i++) - { - current = viewport.getAlignment().getSequenceAt(i); - - if (current.getLength() < Width) - { - current.insertCharAt(Width - 1, viewport.getGapCharacter()); - } - } - - viewport.updateConservation(); - viewport.updateConsensus(); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void findMenuItem_actionPerformed(ActionEvent e) - { - JInternalFrame frame = new JInternalFrame(); - Finder finder = new Finder(viewport, alignPanel, frame); - frame.setContentPane(finder); - Desktop.addInternalFrame(frame, "Find", 340, 110); - frame.setLayer(JLayeredPane.PALETTE_LAYER); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void font_actionPerformed(ActionEvent e) - { - FontChooser fc = new FontChooser(alignPanel); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void fullSeqId_actionPerformed(ActionEvent e) - { - viewport.setShowFullId(fullSeqId.isSelected()); - - alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel.calculateIdWidth()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void colourTextMenuItem_actionPerformed(ActionEvent e) - { - viewport.setColourText(colourTextMenuItem.isSelected()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void wrapMenuItem_actionPerformed(ActionEvent e) - { - viewport.setWrapAlignment(wrapMenuItem.isSelected()); - alignPanel.setWrapAlignment(wrapMenuItem.isSelected()); - scaleAbove.setVisible(wrapMenuItem.isSelected()); - scaleLeft.setVisible(wrapMenuItem.isSelected()); - scaleRight.setVisible(wrapMenuItem.isSelected()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void scaleAbove_actionPerformed(ActionEvent e) - { - viewport.setScaleAboveWrapped(scaleAbove.isSelected()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void scaleLeft_actionPerformed(ActionEvent e) - { - viewport.setScaleLeftWrapped(scaleLeft.isSelected()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void scaleRight_actionPerformed(ActionEvent e) - { - viewport.setScaleRightWrapped(scaleRight.isSelected()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void viewBoxesMenuItem_actionPerformed(ActionEvent e) - { - viewport.setShowBoxes(viewBoxesMenuItem.isSelected()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void viewTextMenuItem_actionPerformed(ActionEvent e) - { - viewport.setShowText(viewTextMenuItem.isSelected()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void renderGapsMenuItem_actionPerformed(ActionEvent e) - { - viewport.setRenderGaps(renderGapsMenuItem.isSelected()); - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void sequenceFeatures_actionPerformed(ActionEvent evt) - { - viewport.showSequenceFeatures(sequenceFeatures.isSelected()); - - if (viewport.showSequenceFeatures && - !((Alignment) viewport.alignment).featuresAdded) - { - SequenceFeatureFetcher sft = new SequenceFeatureFetcher(viewport.alignment, - alignPanel); - ((Alignment) viewport.alignment).featuresAdded = true; - } - - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void annotationPanelMenuItem_actionPerformed(ActionEvent e) - { - if (annotationPanelMenuItem.isSelected() && - viewport.getWrapAlignment()) - { - annotationPanelMenuItem.setSelected(false); - - return; - } - - viewport.setShowAnnotation(annotationPanelMenuItem.isSelected()); - alignPanel.setAnnotationVisible(annotationPanelMenuItem.isSelected()); - } - - /** - * 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); - } - - /** - * 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()); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void applyToAllGroups_actionPerformed(ActionEvent e) - { - viewport.setColourAppliesToAllGroups(applyToAllGroups.isSelected()); - } - - /** - * DOCUMENT ME! - * - * @param cs DOCUMENT ME! - */ - void changeColour(ColourSchemeI cs) - { - int threshold = 0; - - if (viewport.getAbovePIDThreshold()) - { - threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, - "Background"); - - if (cs instanceof ResidueColourScheme) - { - ((ResidueColourScheme) cs).setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - } - else if (cs instanceof ScoreColourScheme) - { - ((ScoreColourScheme) cs).setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - } - - viewport.setGlobalColourScheme(cs); - } - else if (cs instanceof ResidueColourScheme) - { - ((ResidueColourScheme) cs).setThreshold(0, viewport.getIgnoreGapsConsensus()); - } - else if (cs instanceof ScoreColourScheme) - { - ((ScoreColourScheme) cs).setThreshold(0, viewport.getIgnoreGapsConsensus()); - } - - if (viewport.getConservationSelected()) - { - ConservationColourScheme ccs = null; - - 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); - - ccs = new ConservationColourScheme(c, cs); - - - viewport.setGlobalColourScheme(ccs); - - ccs.inc = SliderPanel.setConservationSlider(alignPanel, ccs, - "Background"); - } - else - { - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - if (cs != null) - { - cs.setConsensus(viewport.vconsensus); - } - - 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; - } - else if (cs instanceof ClustalxColourScheme) - { - sg.cs = new ClustalxColourScheme(sg.sequences, 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()) - { - if (sg.cs instanceof ResidueColourScheme) - { - ((ResidueColourScheme) sg.cs).setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - } - else if (sg.cs instanceof ScoreColourScheme) - { - ((ScoreColourScheme) sg.cs).setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - } - - sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, - sg.getWidth())); - } - - if (viewport.getConservationSelected()) - { - Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, sg.sequences, 0, - viewport.alignment.getWidth() - 1); - c.calculate(); - c.verdict(false, viewport.ConsPercGaps); - - ConservationColourScheme ccs = new ConservationColourScheme(c, - sg.cs); - - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - ccs.setConsensus(AAFrequency.calculate(sg.sequences, 0, - sg.getWidth())); - sg.cs = ccs; - } - else if (cs != null) - { - // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! - sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, - sg.getWidth())); - } - } - } - - if (alignPanel.getOverviewPanel() != null) - { - alignPanel.getOverviewPanel().updateOverviewImage(); - } - - alignPanel.repaint(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void modifyPID_actionPerformed(ActionEvent e) - { - if (viewport.getAbovePIDThreshold()) - { - SliderPanel.setPIDSliderSource(alignPanel, - viewport.getGlobalColourScheme(), "Background"); - SliderPanel.showPIDSlider(); - } - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void modifyConservation_actionPerformed(ActionEvent e) - { - if (viewport.getConservationSelected()) + do + { + if (jalview.util.Comparison.isGap(current.getCharAt(j))) { - SliderPanel.setConservationSlider(alignPanel, - viewport.globalColourScheme, "Background"); - SliderPanel.showConservationSlider(); + current.deleteCharAt(j); + j--; + jSize--; } + j++; + } + while (j < end && j < jSize); } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void conservationMenuItem_actionPerformed(ActionEvent e) - { - viewport.setConservationSelected(conservationMenuItem.isSelected()); - - viewport.setAbovePIDThreshold(false); - abovePIDThreshold.setSelected(false); - - ColourSchemeI cs = viewport.getGlobalColourScheme(); + viewport.updateConservation(); + viewport.updateConsensus(); + alignPanel.repaint(); + } - if (cs instanceof ConservationColourScheme) - { - changeColour(((ConservationColourScheme) cs).cs); - } - else - { - changeColour(cs); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void padGapsMenuitem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Pad Gaps", viewport.alignment, + HistoryItem.HIDE)); - modifyConservation_actionPerformed(null); - } + SequenceI current; + int Width = viewport.getAlignment().getWidth(); - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void abovePIDThreshold_actionPerformed(ActionEvent e) + for (int i = 0; i < viewport.getAlignment().getSequences().size(); + i++) { - viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected()); - - conservationMenuItem.setSelected(false); - viewport.setConservationSelected(false); - - ColourSchemeI cs = viewport.getGlobalColourScheme(); - - if (cs instanceof ConservationColourScheme) - { - changeColour(((ConservationColourScheme) cs).cs); - } - else - { - changeColour(cs); - } - - modifyPID_actionPerformed(null); - } + current = viewport.getAlignment().getSequenceAt(i); - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void userDefinedColour_actionPerformed(ActionEvent e) - { - if(e.getActionCommand().equals("User Defined...")) - new UserDefinedColours(alignPanel, null); - else + if (current.getLength() < Width) { - UserColourScheme udc = (UserColourScheme)UserDefinedColours. - getUserColourSchemes().get(e.getActionCommand()); - - changeColour(udc); + current.insertCharAt(Width - 1, viewport.getGapCharacter()); } } - public void updateUserColourMenu() - { - - Component [] menuItems = colourMenu.getMenuComponents(); - int i, iSize = menuItems.length; - for(i=0; i 0)) || - (viewport.getAlignment().getHeight() < 4)) + if (viewport.getAbovePIDThreshold()) { - JOptionPane.showInternalMessageDialog(this, - "Principal component analysis must take\n" + - "at least 4 input sequences.", - "Sequence selection insufficient", JOptionPane.WARNING_MESSAGE); + if (sg.cs instanceof ResidueColourScheme) + { + ( (ResidueColourScheme) sg.cs).setThreshold(threshold, + viewport.getIgnoreGapsConsensus()); + } + else if (sg.cs instanceof ScoreColourScheme) + { + ( (ScoreColourScheme) sg.cs).setThreshold(threshold, + viewport.getIgnoreGapsConsensus()); + } - return; + sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, + sg.getWidth())); } - try + if (viewport.getConservationSelected()) { - PCAPanel pcaPanel = new PCAPanel(viewport, null); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(pcaPanel); - Desktop.addInternalFrame(frame, "Principal component analysis", - 400, 400); + Conservation c = new Conservation("Group", + ResidueProperties.propHash, 3, + sg.sequences, 0, + viewport.alignment.getWidth() - 1); + c.calculate(); + c.verdict(false, viewport.ConsPercGaps); + + ConservationColourScheme ccs = new ConservationColourScheme(c, + sg.cs); + + // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! + ccs.setConsensus(AAFrequency.calculate(sg.sequences, 0, + sg.getWidth())); + sg.cs = ccs; } - catch (java.lang.OutOfMemoryError ex) + else if (cs != null) { - JOptionPane.showInternalMessageDialog(this, - "Too many sequences selected\nfor Principal Component Analysis!!", - "Out of memory", JOptionPane.WARNING_MESSAGE); + // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS! + sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0, + sg.getWidth())); } + } } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void averageDistanceTreeMenuItem_actionPerformed(ActionEvent e) + if (alignPanel.getOverviewPanel() != null) { - NewTreePanel("AV", "PID", "Average distance tree using PID"); + alignPanel.getOverviewPanel().updateOverviewImage(); } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void neighbourTreeMenuItem_actionPerformed(ActionEvent e) - { - NewTreePanel("NJ", "PID", "Neighbour joining tree using PID"); - } + alignPanel.repaint(); + } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void njTreeBlosumMenuItem_actionPerformed(ActionEvent e) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void modifyPID_actionPerformed(ActionEvent e) + { + if (viewport.getAbovePIDThreshold()) { - NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62"); + SliderPanel.setPIDSliderSource(alignPanel, + viewport.getGlobalColourScheme(), + "Background"); + SliderPanel.showPIDSlider(); } + } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void avTreeBlosumMenuItem_actionPerformed(ActionEvent e) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void modifyConservation_actionPerformed(ActionEvent e) + { + if (viewport.getConservationSelected()) { - NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62"); + SliderPanel.setConservationSlider(alignPanel, + viewport.globalColourScheme, + "Background"); + SliderPanel.showConservationSlider(); } + } - /** - * DOCUMENT ME! - * - * @param type DOCUMENT ME! - * @param pwType DOCUMENT ME! - * @param title DOCUMENT ME! - */ - void NewTreePanel(String type, String pwType, String title) - { - final TreePanel tp; + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void conservationMenuItem_actionPerformed(ActionEvent e) + { + viewport.setConservationSelected(conservationMenuItem.isSelected()); - if ((viewport.getSelectionGroup() != null) && - (viewport.getSelectionGroup().getSize() > 3)) - { - int s = 0; - SequenceGroup sg = viewport.getSelectionGroup(); + viewport.setAbovePIDThreshold(false); + abovePIDThreshold.setSelected(false); - /* Decide if the selection is a column region */ - while (s < sg.sequences.size()) - { - if (((SequenceI) sg.sequences.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; - } - } + ColourSchemeI cs = viewport.getGlobalColourScheme(); - title = title + " on region"; - tp = new TreePanel(viewport, - viewport.getSelectionGroup().sequences, type, pwType, - sg.getStartRes(), sg.getEndRes()); - } - 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); + if (cs instanceof ConservationColourScheme) + { + changeColour( ( (ConservationColourScheme) cs).cs); + } + else + { + changeColour(cs); + } - return; - } + modifyConservation_actionPerformed(null); + } - tp = new TreePanel(viewport, - viewport.getAlignment().getSequences(), type, pwType, 0, - viewport.alignment.getWidth()); - } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void abovePIDThreshold_actionPerformed(ActionEvent e) + { + viewport.setAbovePIDThreshold(abovePIDThreshold.isSelected()); - addTreeMenuItem(tp, title); - viewport.setCurrentTree(tp.getTree()); + conservationMenuItem.setSelected(false); + viewport.setConservationSelected(false); - Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500); - } + ColourSchemeI cs = viewport.getGlobalColourScheme(); - /** - * DOCUMENT ME! - * - * @param title DOCUMENT ME! - * @param order DOCUMENT ME! - */ - public void addSortByOrderMenuItem(String title, final AlignmentOrder order) + if (cs instanceof ConservationColourScheme) { - final JMenuItem item = new JMenuItem("by " + title); - sort.add(item); - item.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - addHistoryItem(new HistoryItem("Sort", viewport.alignment, - HistoryItem.SORT)); - - // TODO: JBPNote - have to map order entries to curent SequenceI pointers - AlignmentSorter.sortBy(viewport.getAlignment(), order); - alignPanel.repaint(); - } - }); + changeColour( ( (ConservationColourScheme) cs).cs); } - - /** - * DOCUMENT ME! - * - * @param treePanel DOCUMENT ME! - * @param title DOCUMENT ME! - */ - void addTreeMenuItem(final TreePanel treePanel, String title) + else { - final JMenuItem item = new JMenuItem(title); + changeColour(cs); + } - treeCount++; + modifyPID_actionPerformed(null); + } - if (treeCount == 1) - { - sort.add(sortByTreeMenu); - } + /** + * 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()); - sortByTreeMenu.add(item); - item.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - addHistoryItem(new HistoryItem("Tree Sort", - viewport.alignment, HistoryItem.SORT)); - AlignmentSorter.sortByTree(viewport.getAlignment(), - treePanel.getTree()); - alignPanel.repaint(); - } - }); + changeColour(udc); + } + } - treePanel.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() - { - public void internalFrameClosed( - javax.swing.event.InternalFrameEvent evt) - { - treeCount--; - sortByTreeMenu.remove(item); + public void updateUserColourMenu() + { - if (treeCount == 0) - { - sort.remove(sortByTreeMenu); - } - } - ; - }); - viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener() - { - public void propertyChange(PropertyChangeEvent evt) - { - if (evt.getPropertyName().equals("alignment")) - { - treePanel.getTree().UpdatePlaceHolders((Vector) evt.getNewValue()); - treePanel.repaint(); - } - } - }); + 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--; + } } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void clustalAlignMenuItem_actionPerformed(ActionEvent e) + if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null) { - // TODO:resolve which menu item was actually selected - // Now, check we have enough sequences - SequenceI[] msa = null; + java.util.Enumeration userColours = jalview.gui.UserDefinedColours. + getUserColourSchemes().keys(); - if ((viewport.getSelectionGroup() != null) && - (viewport.getSelectionGroup().getSize() > 1)) + while (userColours.hasMoreElements()) + { + JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours. + nextElement().toString()); + radioItem.addActionListener(new ActionListener() { - // 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()]; - - for (int i = 0; i < sz; i++) - { - msa[i] = (SequenceI) seqs.getSequenceAt(i); - } - } - else + 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) + { + addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment, + HistoryItem.SORT)); + AlignmentSorter.sortByPID(viewport.getAlignment(), + viewport.getAlignment().getSequenceAt(0)); + alignPanel.repaint(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void sortIDMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("ID Sort", viewport.alignment, + HistoryItem.SORT)); + AlignmentSorter.sortByID(viewport.getAlignment()); + alignPanel.repaint(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void sortGroupMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Group Sort", viewport.alignment, + HistoryItem.SORT)); + + AlignmentSorter.sortByGroup(viewport.getAlignment()); + alignPanel.repaint(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void removeRedundancyMenuItem_actionPerformed(ActionEvent e) + { + RedundancyPanel sp = new RedundancyPanel(alignPanel, this); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(sp); + Desktop.addInternalFrame(frame, "Redundancy threshold selection", 400, + 100, false); + } + + /** + * 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; + } + + try + { + PCAPanel pcaPanel = new PCAPanel(viewport, null); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(pcaPanel); + Desktop.addInternalFrame(frame, "Principal component analysis", + 400, 400); + } + catch (java.lang.OutOfMemoryError ex) + { + JOptionPane.showInternalMessageDialog(this, + "Too many sequences selected\nfor Principal Component Analysis!!", + "Out of memory", + JOptionPane.WARNING_MESSAGE); + } + } + + /** + * 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) + { + final TreePanel tp; + + if ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 3)) + { + int s = 0; + SequenceGroup sg = viewport.getSelectionGroup(); + + /* Decide if the selection is a column region */ + while (s < sg.sequences.size()) + { + if ( ( (SequenceI) sg.sequences.elementAt(s++)).getLength() < + sg.getEndRes()) { - Vector seqs = viewport.getAlignment().getSequences(); - - if (seqs.size() > 1) - { - msa = new SequenceI[seqs.size()]; + 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); - for (int i = 0; i < seqs.size(); i++) - { - msa[i] = (SequenceI) seqs.elementAt(i); - } - } + return; } + } - if (msa != null) - { - jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", - title, msa, false, true); - } + title = title + " on region"; + tp = new TreePanel(viewport, + viewport.getSelectionGroup().sequences, type, pwType, + sg.getStartRes(), sg.getEndRes()); } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void ClustalRealign_actionPerformed(ActionEvent e) + else { - // TODO:resolve which menu item was actually selected - // Now, check we have enough sequences - SequenceI[] 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()]; - - for (int i = 0; i < sz; i++) - { - msa[i] = (SequenceI) seqs.getSequenceAt(i); - } - } - else - { - Vector seqs = viewport.getAlignment().getSequences(); + //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 (seqs.size() > 1) - { - msa = new SequenceI[seqs.size()]; + tp = new TreePanel(viewport, + viewport.getAlignment().getSequences(), type, pwType, + 0, + viewport.alignment.getWidth()); + } - for (int i = 0; i < seqs.size(); i++) - { - msa[i] = (SequenceI) seqs.elementAt(i); - } - } - } + addTreeMenuItem(tp, title); + viewport.setCurrentTree(tp.getTree()); - if (msa != null) - { - jalview.ws.MsaWSClient ct = new jalview.ws.MsaWSClient("ClustalWS", - title, msa, true, true); - } - } + Desktop.addInternalFrame(tp, title + " from " + this.title, 600, 500); + } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void jpred_actionPerformed(ActionEvent e) + /** + * 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() { - SequenceI seq = null; - SequenceI[] msa = null; + public void actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Sort", viewport.alignment, + HistoryItem.SORT)); - if ((viewport.getSelectionGroup() != null) && - (viewport.getSelectionGroup().getSize() > 0)) - { - // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! - SequenceGroup seqs = viewport.getSelectionGroup(); + // TODO: JBPNote - have to map order entries to curent SequenceI pointers + AlignmentSorter.sortBy(viewport.getAlignment(), order); + alignPanel.repaint(); + } + }); + } - if ((seqs.getSize() == 1) || !viewport.alignment.isAligned()) - { - seq = (SequenceI) seqs.getSequenceAt(0); - } - else - { - int sz; - msa = new SequenceI[sz = seqs.getSize()]; + /** + * Maintain the Order by->Displayed Tree menu. + * Creates a new menu item for a TreePanel with an appropriate + * jalview.analysis.AlignmentSorter 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. + */ + void addTreeMenuItem(final TreePanel treePanel, String title) + { + final JMenuItem item = new JMenuItem(title); - for (int i = 0; i < sz; i++) - { - msa[i] = (SequenceI) seqs.getSequenceAt(i); - } - } - } - else - { - Vector seqs = viewport.getAlignment().getSequences(); + treeCount++; - if ((seqs.size() == 1) || !viewport.alignment.isAligned()) - { - seq = (SequenceI) seqs.elementAt(0); - } - else - { - msa = new SequenceI[seqs.size()]; + if (treeCount == 1) + { + sort.add(sortByTreeMenu); + } - for (int i = 0; i < seqs.size(); i++) - { - msa[i] = (SequenceI) seqs.elementAt(i); - } - } - } + sortByTreeMenu.add(item); + item.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + addHistoryItem(new HistoryItem("Tree Sort", + viewport.alignment, HistoryItem.SORT)); + AlignmentSorter.sortByTree(viewport.getAlignment(), + treePanel.getTree()); + alignPanel.repaint(); + } + }); + + treePanel.addInternalFrameListener(new javax.swing.event. + InternalFrameAdapter() + { + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + treeCount--; + sortByTreeMenu.remove(item); - if (msa != null) + if (treeCount == 0) { - JPredClient ct = new JPredClient(title, msa); + sort.remove(sortByTreeMenu); } - else if (seq != null) + } + ; + }); + viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + if (evt.getPropertyName().equals("alignment")) { - JPredClient ct = new JPredClient(title, seq); + treePanel.getTree().UpdatePlaceHolders( (Vector) evt.getNewValue()); + treePanel.repaint(); } - else + } + }); + } + + /** + * Work out whether the whole set of sequences + * or just the selected set will be submitted for multiple alignment. + * + */ + private SequenceI[] gatherSequencesForAlignment() + { + // Now, check we have enough sequences + SequenceI[] 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()]; + + for (int i = 0; i < sz; i++) + { + msa[i] = (SequenceI) seqs.getSequenceAt(i); + } + } + else + { + Vector seqs = viewport.getAlignment().getSequences(); + + if (seqs.size() > 1) + { + msa = new SequenceI[seqs.size()]; + + for (int i = 0; i < seqs.size(); i++) { - System.err.print( - "JALVIEW ERROR! - Unexpected JPred selection state!\n"); + msa[i] = (SequenceI) seqs.elementAt(i); } + } } + return msa; + } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void msaAlignMenuItem_actionPerformed(ActionEvent e) + /** + * 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). + */ + SequenceI[] gatherSeqOrMsaForSecStrPrediction() + { + SequenceI seq = null; + SequenceI[] msa = null; + + if ( (viewport.getSelectionGroup() != null) && + (viewport.getSelectionGroup().getSize() > 0)) { - // TODO:resolve which menu item was actually selected - // Now, check we have enough sequences - SequenceI[] msa = null; + // JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface! + SequenceGroup seqs = viewport.getSelectionGroup(); - 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()]; + if ( (seqs.getSize() == 1) || !viewport.alignment.isAligned()) + { + seq = (SequenceI) seqs.getSequenceAt(0); + } + else + { + int sz; + msa = new SequenceI[sz = seqs.getSize()]; - for (int i = 0; i < sz; i++) - { - msa[i] = (SequenceI) seqs.getSequenceAt(i); - } - } - else + for (int i = 0; i < sz; i++) { - 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[i] = (SequenceI) seqs.getSequenceAt(i); } + } + } + else + { + Vector seqs = viewport.getAlignment().getSequences(); + + if ( (seqs.size() == 1) || !viewport.alignment.isAligned()) + { + seq = (SequenceI) seqs.elementAt(0); + } + else + { + msa = new SequenceI[seqs.size()]; - if (msa != null) + for (int i = 0; i < seqs.size(); i++) { - MsaWSClient ct = new jalview.ws.MsaWSClient("MuscleWS", title, msa, - false, true); + msa[i] = (SequenceI) seqs.elementAt(i); } + } } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) + if (msa != null) + { + return msa; + } + else { - // 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"); + if (seq != null) + { + return new SequenceI[] + { + seq}; + } + } + return null; + } + /** + * 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(); + } + } + } - int value = chooser.showOpenDialog(null); + /** + * DOCUMENT ME! + * + * @param nf DOCUMENT ME! + * @param title DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public TreePanel ShowNewickTree(NewickFile nf, String title) + { + TreePanel tp = null; - if (value == JalviewFileChooser.APPROVE_OPTION) - { - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + try + { + nf.parse(); - 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(); - } - } + if (nf.getTree() != null) + { + tp = new TreePanel(viewport, + viewport.getAlignment().getSequences(), nf, + "FromFile", + title); + Desktop.addInternalFrame(tp, title, 600, 500); + addTreeMenuItem(tp, title); + } + } + catch (Exception ex) + { + ex.printStackTrace(); } - /** - * DOCUMENT ME! - * - * @param nf DOCUMENT ME! - * @param title DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public TreePanel ShowNewickTree(NewickFile nf, String title) + return tp; + } + + class PrintThread + extends Thread + { + public void run() { - TreePanel tp = null; + PrinterJob printJob = PrinterJob.getPrinterJob(); + PageFormat pf = printJob.pageDialog(printJob.defaultPage()); + printJob.setPrintable(alignPanel, pf); + if (printJob.printDialog()) + { try { - nf.parse(); - - if (nf.getTree() != null) - { - tp = new TreePanel(viewport, - viewport.getAlignment().getSequences(), nf, "FromFile", - title); - Desktop.addInternalFrame(tp, title, 600, 500); - addTreeMenuItem(tp, title); - } + printJob.print(); } - catch (Exception ex) + catch (Exception PrintException) { - ex.printStackTrace(); + PrintException.printStackTrace(); } - - return tp; + } } + } + + /** + * Generates menu items and listener event actions for web service clients + * + */ + public void BuildWebServiceMenu() + { + if ( (Desktop.discoverer.services != null) + && (Desktop.discoverer.services.size() > 0)) + { + Vector msaws = (Vector) Desktop.discoverer.services.get("MsaWS"); + Vector secstrpr = (Vector) Desktop.discoverer.services.get("SecStrPred"); + Vector wsmenu = new Vector(); + 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) + { + SequenceI[] msa = gatherSequencesForAlignment(); + MsaWSClient ct = new jalview.ws.MsaWSClient(sh, title, msa, + false, true); - class PrintThread extends Thread - { - public void run() - { - PrinterJob printJob = PrinterJob.getPrinterJob(); - PageFormat pf = printJob.pageDialog(printJob.defaultPage()); - printJob.setPrintable(alignPanel, pf); + } - if (printJob.printDialog()) + }); + 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() { - try - { - printJob.print(); - } - catch (Exception PrintException) + public void actionPerformed(ActionEvent e) + { + SequenceI[] msa = gatherSequencesForAlignment(); + MsaWSClient ct = new jalview.ws.MsaWSClient(sh, title, msa, + true, true); + + } + + }); + 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) + { + SequenceI[] msa = gatherSeqOrMsaForSecStrPrediction(); + if (msa.length == 1) + { + // Single Sequence prediction + jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh, + title, msa[0]); + } + else + { + if (msa.length > 1) { - PrintException.printStackTrace(); + // Single Sequence prediction + jalview.ws.JPredClient ct = new jalview.ws.JPredClient(sh, + title, msa); } + } } + }); + secstrmenu.add(method); } + wsmenu.add(secstrmenu); + } + this.webService.removeAll(); + for (int i = 0, j = wsmenu.size(); i < j; i++) + { + webService.add( (JMenu) wsmenu.get(i)); + } + } + else + { + this.webService.removeAll(); + this.webService.add(this.webServiceNoServices); } + // TODO: add in rediscovery function + // TODO: reduce code redundancy. + // TODO: group services by location as well as function. + } + } diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index e98fb9f..dd3f980 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1002,7 +1002,7 @@ public class AlignViewport } /** - * DOCUMENT ME! + * Property change listener for changes in alignment * * @param listener DOCUMENT ME! */ @@ -1024,7 +1024,7 @@ public class AlignViewport } /** - * DOCUMENT ME! + * Property change listener for changes in alignment * * @param prop DOCUMENT ME! * @param oldvalue DOCUMENT ME! diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 020a420..642a872 100755 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -1,538 +1,540 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 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 Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ -package jalview.gui; - -import jalview.io.*; - -import java.awt.*; -import java.awt.datatransfer.*; -import java.awt.dnd.*; -import java.awt.event.*; - -import javax.swing.*; - - -/** - * DOCUMENT ME! - * - * @author $author$ - * @version $Revision$ - */ -public class Desktop extends jalview.jbgui.GDesktop - implements DropTargetListener -{ - /** DOCUMENT ME!! */ - public static JDesktopPane desktop; - static int openFrameCount = 0; - static final int xOffset = 30; - static final int yOffset = 30; - - /** - * Creates a new Desktop object. - */ - public Desktop() - { - Image image = null; - - try - { - java.net.URL url = getClass().getResource("/images/logo.gif"); - - if (url != null) - { - image = java.awt.Toolkit.getDefaultToolkit().createImage(url); - - MediaTracker mt = new MediaTracker(this); - mt.addImage(image, 0); - mt.waitForID(0); - setIconImage(image); - } - } - catch (Exception ex) - { - } - - setTitle("Jalview 2005"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - desktop = new JDesktopPane(); - desktop.setBackground(Color.white); - setContentPane(desktop); - desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); - - // This line prevents Windows Look&Feel resizing all new windows to maximum - // if previous window was maximised - desktop.setDesktopManager(new DefaultDesktopManager()); - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - String x = jalview.bin.Cache.getProperty("SCREEN_X"); - String y = jalview.bin.Cache.getProperty("SCREEN_Y"); - String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH"); - String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT"); - - if ((x != null) && (y != null) && (width != null) && (height != null)) - { - setBounds(Integer.parseInt(x), Integer.parseInt(y), - Integer.parseInt(width), Integer.parseInt(height)); - } - else - { - setBounds((int) (screenSize.width - 900) / 2, - (int) (screenSize.height - 650) / 2, 900, 650); - } - - this.addWindowListener(new WindowAdapter() - { - public void windowClosing(WindowEvent evt) - { - quit(); - } - }); - - this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); - - /////////Add a splashscreen on startup - /////////Add a splashscreen on startup - JInternalFrame frame = new JInternalFrame(); - - SplashScreen splash = new SplashScreen(frame, image); - frame.setContentPane(splash); - frame.setLayer(JLayeredPane.PALETTE_LAYER); - addInternalFrame(frame, "", 750, 160, false); - frame.setLocation((int) ((getWidth() - 750) / 2), - (int) ((getHeight() - 160) / 2)); - } - - /** - * DOCUMENT ME! - * - * @param frame DOCUMENT ME! - * @param title DOCUMENT ME! - * @param w DOCUMENT ME! - * @param h DOCUMENT ME! - */ - public static void addInternalFrame(final JInternalFrame frame, - String title, int w, int h) - { - addInternalFrame(frame, title, w, h, true); - } - - /** - * DOCUMENT ME! - * - * @param frame DOCUMENT ME! - * @param title DOCUMENT ME! - * @param w DOCUMENT ME! - * @param h DOCUMENT ME! - * @param resizable DOCUMENT ME! - */ - public static void addInternalFrame(final JInternalFrame frame, - String title, int w, int h, boolean resizable) - { - - frame.setTitle(title); - frame.setSize(w, h); - - // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN - // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN - // IF JALVIEW IS RUNNING HEADLESS - ///////////////////////////////////////////////// - if (System.getProperty("java.awt.headless") != null - && System.getProperty("java.awt.headless").equals("true")) - { - return; - } - - - desktop.add(frame); - openFrameCount++; - - try - { - frame.setSelected(true); - } - catch (java.beans.PropertyVetoException e) - { - } - - frame.setClosable(true); - frame.setResizable(resizable); - frame.setMaximizable(resizable); - frame.setIconifiable(resizable); - frame.setFrameIcon(null); - frame.setLocation(xOffset * openFrameCount, yOffset * openFrameCount); - frame.toFront(); - - final JMenuItem menuItem = new JMenuItem(title); - frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() - { - public void internalFrameClosed( - javax.swing.event.InternalFrameEvent evt) - { - openFrameCount--; - windowMenu.remove(menuItem); - } - ; - }); - - menuItem.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - try - { - frame.setSelected(true); - frame.setIcon(false); - } - catch (java.beans.PropertyVetoException ex) - { - } - - ; - } - }); - - frame.setVisible(true); - windowMenu.add(menuItem); - } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void dragEnter(DropTargetDragEvent evt) - { - } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void dragExit(DropTargetEvent evt) - { - } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void dragOver(DropTargetDragEvent evt) - { - } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void dropActionChanged(DropTargetDragEvent evt) - { - } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void drop(DropTargetDropEvent evt) - { - Transferable t = evt.getTransferable(); - - if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) - { - return; - } - - evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); - - try - { - java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor); - - for (int i = 0; i < files.size(); i++) - { - String file = files.get(i).toString(); - String protocol = "File"; - String format = null; - - if (file.endsWith(".jar")) - { - format = "Jalview"; - - } - else - { - format = jalview.io.IdentifyFile.Identify(file, - protocol); - } - LoadFile(file, protocol, format); - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void inputLocalFileMenuItem_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" - }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); - - chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle("Open local file"); - chooser.setToolTipText("Open"); - - int value = chooser.showOpenDialog(this); - - if (value == JalviewFileChooser.APPROVE_OPTION) - { - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - - String format = null; - if (chooser.getSelectedFormat().equals("Jalview")) - { - format = "Jalview"; - } - else - { - format = IdentifyFile.Identify(choice, "File"); - } - - jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format); - LoadFile(choice, "File", format); - } - } - - /** - * DOCUMENT ME! - * - * @param file DOCUMENT ME! - * @param protocol DOCUMENT ME! - * @param format DOCUMENT ME! - */ - public void LoadFile(String file, String protocol, String format) - { - FileLoader fileLoader = new FileLoader(); - fileLoader.LoadFile(file, protocol, format); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void inputURLMenuItem_actionPerformed(ActionEvent e) - { - String url = JOptionPane.showInternalInputDialog(Desktop.desktop, - "Enter url of input file", "Input alignment from URL", - JOptionPane.QUESTION_MESSAGE, null, null, "http://www.") - .toString(); - - if (url == null) - { - return; - } - - if (url.trim().toLowerCase().endsWith(".jar")) - { - jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", "Jalview"); - Jalview2XML.LoadJalviewAlign(url); - } - else - { - - String format = IdentifyFile.Identify(url, "URL"); - - if (format.equals("URL NOT FOUND")) - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Couldn't locate " + url, - "URL not found", - JOptionPane.WARNING_MESSAGE); - - return; - } - - LoadFile(url, "URL", format); - } - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void inputTextboxMenuItem_actionPerformed(ActionEvent e) - { - CutAndPasteTransfer cap = new CutAndPasteTransfer(); - cap.setForInput(); - Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500); - } - - /* - * Exit the program - */ - public void quit() - { - jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + ""); - jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + ""); - jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + ""); - jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + ""); - System.exit(0); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void aboutMenuItem_actionPerformed(ActionEvent e) - { - StringBuffer message = new StringBuffer("JalView 2005 version " + - jalview.bin.Cache.getProperty( - "VERSION") + - "; last updated: " + - jalview.bin. - Cache.getDefault("BUILD_DATE", "unknown")); - - if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals( - jalview.bin.Cache.getProperty("VERSION"))) - { - message.append("\n\n!! Jalview version " - + jalview.bin.Cache.getProperty("LATEST_VERSION") - + " is available for download from http://www.jalview.org !!\n"); - - } - - message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." + - "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." + - "\nFor all issues relating to Jalview, email help@jalview.org" + - "\n\nIf you use JalView, please cite:" + - "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" + - "\nBioinformatics, 2004 12;426-7."); - - JOptionPane.showInternalMessageDialog(Desktop.desktop, - - message.toString(), "About Jalview", - JOptionPane.INFORMATION_MESSAGE); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void documentationMenuItem_actionPerformed(ActionEvent e) - { - 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.setLocation(new Point(200, 50)); - hb.setSize(new Dimension(800, 700)); - hb.setCurrentID("home"); - hb.setDisplayed(true); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void preferences_actionPerformed(ActionEvent e) - { - new Preferences(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void saveState_actionPerformed(ActionEvent e) - { - JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY"), new String[] { "jar" }, - new String[] { "Jalview Project" }, "Jalview Project"); - - chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle("Save State"); - - int value = chooser.showSaveDialog(this); - - if (value == JalviewFileChooser.APPROVE_OPTION) - { - java.io.File choice = chooser.getSelectedFile(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); - Jalview2XML.SaveState(choice); - } - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void loadState_actionPerformed(ActionEvent e) - { - JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty( - "LAST_DIRECTORY"), new String[] { "jar" }, - new String[] { "Jalview Project" }, "Jalview Project"); - chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle("Restore state"); - - int value = chooser.showOpenDialog(this); - - if (value == JalviewFileChooser.APPROVE_OPTION) - { - String choice = chooser.getSelectedFile().getAbsolutePath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); - Jalview2XML.LoadJalviewAlign(choice); - } - } - -} +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2005 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 Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package jalview.gui; + +import jalview.io.*; + +import java.awt.*; +import java.awt.datatransfer.*; +import java.awt.dnd.*; +import java.awt.event.*; + +import javax.swing.*; + + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class Desktop extends jalview.jbgui.GDesktop + implements DropTargetListener +{ + /** DOCUMENT ME!! */ + public static JDesktopPane desktop; + static int openFrameCount = 0; + static final int xOffset = 30; + static final int yOffset = 30; + public static jalview.ws.Discoverer discoverer; + /** + * Creates a new Desktop object. + */ + public Desktop() + { + Image image = null; + + try + { + java.net.URL url = getClass().getResource("/images/logo.gif"); + + if (url != null) + { + image = java.awt.Toolkit.getDefaultToolkit().createImage(url); + + MediaTracker mt = new MediaTracker(this); + mt.addImage(image, 0); + mt.waitForID(0); + setIconImage(image); + } + } + catch (Exception ex) + { + } + + setTitle("Jalview 2005"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + desktop = new JDesktopPane(); + desktop.setBackground(Color.white); + setContentPane(desktop); + desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); + + // This line prevents Windows Look&Feel resizing all new windows to maximum + // if previous window was maximised + desktop.setDesktopManager(new DefaultDesktopManager()); + + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + String x = jalview.bin.Cache.getProperty("SCREEN_X"); + String y = jalview.bin.Cache.getProperty("SCREEN_Y"); + String width = jalview.bin.Cache.getProperty("SCREEN_WIDTH"); + String height = jalview.bin.Cache.getProperty("SCREEN_HEIGHT"); + + if ((x != null) && (y != null) && (width != null) && (height != null)) + { + setBounds(Integer.parseInt(x), Integer.parseInt(y), + Integer.parseInt(width), Integer.parseInt(height)); + } + else + { + setBounds((int) (screenSize.width - 900) / 2, + (int) (screenSize.height - 650) / 2, 900, 650); + } + + this.addWindowListener(new WindowAdapter() + { + public void windowClosing(WindowEvent evt) + { + quit(); + } + }); + + this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this)); + + /////////Add a splashscreen on startup + /////////Add a splashscreen on startup + JInternalFrame frame = new JInternalFrame(); + + SplashScreen splash = new SplashScreen(frame, image); + frame.setContentPane(splash); + frame.setLayer(JLayeredPane.PALETTE_LAYER); + addInternalFrame(frame, "", 750, 160, false); + frame.setLocation((int) ((getWidth() - 750) / 2), + (int) ((getHeight() - 160) / 2)); + discoverer=new jalview.ws.Discoverer(); // Only gets started if gui is displayed. + } + + /** + * DOCUMENT ME! + * + * @param frame DOCUMENT ME! + * @param title DOCUMENT ME! + * @param w DOCUMENT ME! + * @param h DOCUMENT ME! + */ + public static void addInternalFrame(final JInternalFrame frame, + String title, int w, int h) + { + addInternalFrame(frame, title, w, h, true); + } + + /** + * DOCUMENT ME! + * + * @param frame DOCUMENT ME! + * @param title DOCUMENT ME! + * @param w DOCUMENT ME! + * @param h DOCUMENT ME! + * @param resizable DOCUMENT ME! + */ + public static void addInternalFrame(final JInternalFrame frame, + String title, int w, int h, boolean resizable) + { + + frame.setTitle(title); + frame.setSize(w, h); + + // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN + // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN + // IF JALVIEW IS RUNNING HEADLESS + ///////////////////////////////////////////////// + if (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true")) + { + return; + } + + + desktop.add(frame); + openFrameCount++; + + try + { + frame.setSelected(true); + } + catch (java.beans.PropertyVetoException e) + { + } + + frame.setClosable(true); + frame.setResizable(resizable); + frame.setMaximizable(resizable); + frame.setIconifiable(resizable); + frame.setFrameIcon(null); + frame.setLocation(xOffset * openFrameCount, yOffset * openFrameCount); + frame.toFront(); + + final JMenuItem menuItem = new JMenuItem(title); + frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + { + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + openFrameCount--; + windowMenu.remove(menuItem); + } + ; + }); + + menuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + try + { + frame.setSelected(true); + frame.setIcon(false); + } + catch (java.beans.PropertyVetoException ex) + { + } + + ; + } + }); + + frame.setVisible(true); + windowMenu.add(menuItem); + } + + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void dragEnter(DropTargetDragEvent evt) + { + } + + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void dragExit(DropTargetEvent evt) + { + } + + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void dragOver(DropTargetDragEvent evt) + { + } + + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void dropActionChanged(DropTargetDragEvent evt) + { + } + + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void drop(DropTargetDropEvent evt) + { + Transferable t = evt.getTransferable(); + + if (!t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) + { + return; + } + + evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); + + try + { + java.util.List files = (java.util.List) t.getTransferData(DataFlavor.javaFileListFlavor); + + for (int i = 0; i < files.size(); i++) + { + String file = files.get(i).toString(); + String protocol = "File"; + String format = null; + + if (file.endsWith(".jar")) + { + format = "Jalview"; + + } + else + { + format = jalview.io.IdentifyFile.Identify(file, + protocol); + } + LoadFile(file, protocol, format); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void inputLocalFileMenuItem_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" + }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); + + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Open local file"); + chooser.setToolTipText("Open"); + + int value = chooser.showOpenDialog(this); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + chooser.getSelectedFile().getParent()); + + String format = null; + if (chooser.getSelectedFormat().equals("Jalview")) + { + format = "Jalview"; + } + else + { + format = IdentifyFile.Identify(choice, "File"); + } + + jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", format); + LoadFile(choice, "File", format); + } + } + + /** + * DOCUMENT ME! + * + * @param file DOCUMENT ME! + * @param protocol DOCUMENT ME! + * @param format DOCUMENT ME! + */ + public void LoadFile(String file, String protocol, String format) + { + FileLoader fileLoader = new FileLoader(); + fileLoader.LoadFile(file, protocol, format); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void inputURLMenuItem_actionPerformed(ActionEvent e) + { + String url = JOptionPane.showInternalInputDialog(Desktop.desktop, + "Enter url of input file", "Input alignment from URL", + JOptionPane.QUESTION_MESSAGE, null, null, "http://www.") + .toString(); + + if (url == null) + { + return; + } + + if (url.trim().toLowerCase().endsWith(".jar")) + { + jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", "Jalview"); + Jalview2XML.LoadJalviewAlign(url); + } + else + { + + String format = IdentifyFile.Identify(url, "URL"); + + if (format.equals("URL NOT FOUND")) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Couldn't locate " + url, + "URL not found", + JOptionPane.WARNING_MESSAGE); + + return; + } + + LoadFile(url, "URL", format); + } + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void inputTextboxMenuItem_actionPerformed(ActionEvent e) + { + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + cap.setForInput(); + Desktop.addInternalFrame(cap, "Cut & Paste Alignment File", 600, 500); + } + + /* + * Exit the program + */ + public void quit() + { + jalview.bin.Cache.setProperty("SCREEN_X", getBounds().x + ""); + jalview.bin.Cache.setProperty("SCREEN_Y", getBounds().y + ""); + jalview.bin.Cache.setProperty("SCREEN_WIDTH", getWidth() + ""); + jalview.bin.Cache.setProperty("SCREEN_HEIGHT", getHeight() + ""); + System.exit(0); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void aboutMenuItem_actionPerformed(ActionEvent e) + { + StringBuffer message = new StringBuffer("JalView 2005 version " + + jalview.bin.Cache.getProperty( + "VERSION") + + "; last updated: " + + jalview.bin. + Cache.getDefault("BUILD_DATE", "unknown")); + + if (!jalview.bin.Cache.getProperty("LATEST_VERSION").equals( + jalview.bin.Cache.getProperty("VERSION"))) + { + message.append("\n\n!! Jalview version " + + jalview.bin.Cache.getProperty("LATEST_VERSION") + + " is available for download from http://www.jalview.org !!\n"); + + } + + message.append( "\nAuthors: Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton." + + "\nCurrent development managed by Andrew Waterhouse; Barton Group, University of Dundee." + + "\nFor all issues relating to Jalview, email help@jalview.org" + + "\n\nIf you use JalView, please cite:" + + "\n\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"" + + "\nBioinformatics, 2004 12;426-7."); + + JOptionPane.showInternalMessageDialog(Desktop.desktop, + + message.toString(), "About Jalview", + JOptionPane.INFORMATION_MESSAGE); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void documentationMenuItem_actionPerformed(ActionEvent e) + { + 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.setLocation(new Point(200, 50)); + hb.setSize(new Dimension(800, 700)); + hb.setCurrentID("home"); + hb.setDisplayed(true); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void preferences_actionPerformed(ActionEvent e) + { + new Preferences(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void saveState_actionPerformed(ActionEvent e) + { + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[] { "jar" }, + new String[] { "Jalview Project" }, "Jalview Project"); + + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Save State"); + + int value = chooser.showSaveDialog(this); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + java.io.File choice = chooser.getSelectedFile(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); + Jalview2XML.SaveState(choice); + } + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void loadState_actionPerformed(ActionEvent e) + { + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[] { "jar" }, + new String[] { "Jalview Project" }, "Jalview Project"); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Restore state"); + + int value = chooser.showOpenDialog(this); + + if (value == JalviewFileChooser.APPROVE_OPTION) + { + String choice = chooser.getSelectedFile().getAbsolutePath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + chooser.getSelectedFile().getParent()); + Jalview2XML.LoadJalviewAlign(choice); + } + } + +} + diff --git a/src/jalview/gui/WebserviceInfo.java b/src/jalview/gui/WebserviceInfo.java index 5241ec4..a260072 100755 --- a/src/jalview/gui/WebserviceInfo.java +++ b/src/jalview/gui/WebserviceInfo.java @@ -27,29 +27,29 @@ import javax.swing.*; /** - * DOCUMENT ME! + * Base class for web service client thread and gui * * @author $author$ * @version $Revision$ */ public class WebserviceInfo extends GWebserviceInfo { - /** DOCUMENT ME!! */ + /** Job is Queued */ public static final int STATE_QUEUING = 0; - /** DOCUMENT ME!! */ + /** Job is Running */ public static final int STATE_RUNNING = 1; - /** DOCUMENT ME!! */ + /** Job has finished with no errors */ public static final int STATE_STOPPED_OK = 2; - /** DOCUMENT ME!! */ + /** Job has been cancelled with no errors */ public static final int STATE_CANCELLED_OK = 3; - /** DOCUMENT ME!! */ + /** job has stopped because of some error */ public static final int STATE_STOPPED_ERROR = 4; - /** DOCUMENT ME!! */ + /** job has failed because of some unavoidable service interruption */ public static final int STATE_STOPPED_SERVERERROR = 5; int currentStatus = STATE_QUEUING; Image image; @@ -61,8 +61,8 @@ public class WebserviceInfo extends GWebserviceInfo /** * Creates a new WebserviceInfo object. * - * @param title DOCUMENT ME! - * @param info DOCUMENT ME! + * @param title short name and job type + * @param info reference or other human readable description */ public WebserviceInfo(String title, String info) { @@ -144,7 +144,7 @@ public class WebserviceInfo extends GWebserviceInfo /** * DOCUMENT ME! * - * @param status DOCUMENT ME! + * @param status integer status from state constants */ public void setStatus(int status) { @@ -212,7 +212,7 @@ public class WebserviceInfo extends GWebserviceInfo } /** - * DOCUMENT ME! + * Gui action for cancelling the current job, if possible. * * @param e DOCUMENT ME! */ @@ -221,7 +221,7 @@ public class WebserviceInfo extends GWebserviceInfo if (!serviceIsCancellable) { JOptionPane.showInternalMessageDialog(Desktop.desktop, - "This job cannot be cancelled.", "Cancel job", + "This job cannot be cancelled.\nJust close the window.", "Cancel job", JOptionPane.WARNING_MESSAGE); } else -- 1.7.10.2