X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAlignFrame.java;h=f7cfba092f430d4ec32699c7ee203966adf49805;hb=5a15b7773aaad3bba1bb342198e2bcf4cc2cdffe;hp=0aefe9b01b51d544ce42103ceb58fea4f0c904a2;hpb=6b544d4a85673db44b7f75f40c22d9b7425d444e;p=jalview.git diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 0aefe9b..f7cfba0 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -1,5 +1,5 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * * This file is part of Jalview. @@ -17,7 +17,6 @@ */ package jalview.appletgui; -import java.io.*; import java.net.*; import java.util.*; @@ -25,11 +24,13 @@ import java.awt.*; import java.awt.event.*; import jalview.analysis.*; +import jalview.api.SequenceStructureBinding; import jalview.bin.JalviewLite; import jalview.commands.*; import jalview.datamodel.*; import jalview.io.*; import jalview.schemes.*; +import jalview.structure.StructureSelectionManager; public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemListener, KeyListener @@ -69,6 +70,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, annotationPanelMenuItem.setState(viewport.showAnnotation); displayNonconservedMenuItem.setState(viewport.getShowunconserved()); + followMouseOverFlag.setState(viewport.getFollowHighlight()); + showGroupConsensus.setState(viewport.showGroupConsensus); + showGroupConservation.setState(viewport.showGroupConservation); + showConsensusHistogram.setState(viewport.showConsensusHistogram); + showSequenceLogo.setState(viewport.showSequenceLogo); seqLimits.setState(viewport.showJVSuffix); @@ -134,6 +140,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, alignPanel.idPanel.idCanvas.addKeyListener(this); alignPanel.scalePanel.addKeyListener(this); alignPanel.annotationPanel.addKeyListener(this); + alignPanel.annotationPanelHolder.addKeyListener(this); + alignPanel.annotationSpaceFillerHolder.addKeyListener(this); + alignPanel.alabels.addKeyListener(this); createAlignFrameWindow(embedded, title); alignPanel.validate(); alignPanel.paintAlignment(true); @@ -162,10 +171,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, boolean featuresFile = false; try { - featuresFile = new jalview.io.FeaturesFile(file, type).parse( - viewport.alignment, alignPanel.seqPanel.seqCanvas - .getFeatureRenderer().featureColours, featureLinks, - true); + featuresFile = new jalview.io.FeaturesFile(file, type) + .parse(viewport.alignment, + alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours, + featureLinks, true, viewport.applet.getDefaultParameter("relaxedidmatch", false)); } catch (Exception ex) { ex.printStackTrace(); @@ -201,6 +210,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { case 27: // escape key deselectAllSequenceMenuItem_actionPerformed(); + + alignPanel.alabels.cancelDrag(); break; case KeyEvent.VK_X: if (evt.isControlDown() || evt.isMetaDown()) @@ -596,7 +607,26 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { mouseOverFlag_stateChanged(); } - + else if (evt.getSource() == showGroupConsensus) + { + showGroupConsensus_actionPerformed(); + } + else if (evt.getSource() == showGroupConservation) + { + showGroupConservation_actionPerformed(); + } + else if (evt.getSource() == showSequenceLogo) + { + showSequenceLogo_actionPerformed(); + } + else if (evt.getSource() == showConsensusHistogram) + { + showConsensusHistogram_actionPerformed(); + } + else if (evt.getSource() == applyAutoAnnotationSettings) + { + applyAutoAnnotationSettings_actionPerformed(); + } alignPanel.paintAlignment(true); } @@ -786,44 +816,34 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport.showAllHiddenSeqs(); alignPanel.paintAlignment(true); } + else if (source == showGroupConsensus) + { + showGroupConsensus_actionPerformed(); + } + else if (source == showGroupConservation) + { + showGroupConservation_actionPerformed(); + } + else if (source == showSequenceLogo) + { + showSequenceLogo_actionPerformed(); + } + else if (source == showConsensusHistogram) + { + showConsensusHistogram_actionPerformed(); + } + else if (source == applyAutoAnnotationSettings) + { + applyAutoAnnotationSettings_actionPerformed(); + } else if (source == featureSettings) { new FeatureSettings(alignPanel); } else if (source == alProperties) { - StringBuffer contents = new StringBuffer(); - - float avg = 0; - int min = Integer.MAX_VALUE, max = 0; - for (int i = 0; i < viewport.alignment.getHeight(); i++) - { - int size = viewport.alignment.getSequenceAt(i).getEnd() - - viewport.alignment.getSequenceAt(i).getStart(); - avg += size; - if (size > max) - max = size; - if (size < min) - min = size; - } - avg = avg / (float) viewport.alignment.getHeight(); - - contents.append("\nSequences: " + viewport.alignment.getHeight()); - contents.append("\nMinimum Sequence Length: " + min); - contents.append("\nMaximum Sequence Length: " + max); - contents.append("\nAverage Length: " + (int) avg); - - if (((Alignment) viewport.alignment).alignmentProperties != null) - { - Hashtable props = ((Alignment) viewport.alignment).alignmentProperties; - Enumeration en = props.keys(); - while (en.hasMoreElements()) - { - String key = en.nextElement().toString(); - contents.append("\n" + key + "\t" + props.get(key)); - } - } - + StringBuffer contents = new jalview.io.AlignmentProperties( + viewport.alignment).formatAsString(); CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this); cap.setText(contents.toString()); Frame frame = new Frame(); @@ -842,8 +862,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, else if (source == clustalColour) { abovePIDThreshold.setState(false); - changeColour(new ClustalxColourScheme(viewport.alignment - .getSequences(), viewport.alignment.getWidth())); + changeColour(new ClustalxColourScheme( + viewport.alignment.getSequences(), + viewport.alignment.getWidth())); } else if (source == zappoColour) { @@ -969,10 +990,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this); Frame frame = new Frame(); frame.add(cap); - jalview.bin.JalviewLite.addFrame(frame, "Alignment output - " - + e.getActionCommand(), 600, 500); - cap.setText(new AppletFormatAdapter().formatSequences(e - .getActionCommand(), viewport.getAlignment(), + jalview.bin.JalviewLite.addFrame(frame, + "Alignment output - " + e.getActionCommand(), 600, 500); + cap.setText(new AppletFormatAdapter().formatSequences( + e.getActionCommand(), viewport.getAlignment(), viewport.showJVSuffix)); } @@ -1029,13 +1050,15 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, String features; if (format.equalsIgnoreCase("Jalview")) { - features = new FeaturesFile().printJalviewFormat(viewport.alignment - .getSequencesArray(), getDisplayedFeatureCols()); + features = new FeaturesFile().printJalviewFormat( + viewport.alignment.getSequencesArray(), + getDisplayedFeatureCols()); } else { - features = new FeaturesFile().printGFFFormat(viewport.alignment - .getSequencesArray(), getDisplayedFeatureCols()); + features = new FeaturesFile().printGFFFormat( + viewport.alignment.getSequencesArray(), + getDisplayedFeatureCols()); } if (displayTextbox) @@ -1067,9 +1090,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, if (viewport.applet.getParameter("annotations") != null) { url.append("&annotations="); - url - .append(appendProtocol(viewport.applet - .getParameter("annotations"))); + url.append(appendProtocol(viewport.applet.getParameter("annotations"))); } if (viewport.applet.getParameter("jnetfile") != null) @@ -1608,8 +1629,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport.setEndSeq(viewport.alignment.getHeight()); viewport.alignment.getWidth(); - viewport.firePropertyChange("alignment", null, viewport.alignment - .getSequences()); + viewport.firePropertyChange("alignment", null, + viewport.alignment.getSequences()); } @@ -1666,6 +1687,57 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { this.setVisible(false); } + viewport.sendSelection(); + } + + /** + * group consensus toggled + * + */ + protected void showGroupConsensus_actionPerformed() + { + viewport.setShowGroupConsensus(showGroupConsensus.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + + } + + /** + * group conservation toggled. + */ + protected void showGroupConservation_actionPerformed() + { + viewport.setShowGroupConservation(showGroupConservation.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt + * .event.ActionEvent) + */ + protected void showConsensusHistogram_actionPerformed() + { + viewport.setShowConsensusHistogram(showConsensusHistogram.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + } + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt + * .event.ActionEvent) + */ + protected void showSequenceLogo_actionPerformed() + { + viewport.setShowSequenceLogo(showSequenceLogo.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + } + + protected void applyAutoAnnotationSettings_actionPerformed() + { + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); } protected void makeGrpsFromSelection_actionPerformed() @@ -1673,8 +1745,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, if (viewport.getSelectionGroup() != null) { SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom( - viewport.getSequenceSelection(), viewport.getAlignmentView( - true).getSequenceStrings(viewport.getGapCharacter()), + viewport.getSequenceSelection(), + viewport.getAlignmentView(true).getSequenceStrings( + viewport.getGapCharacter()), viewport.alignment.getGroups()); viewport.alignment.deleteAllGroups(); viewport.sequenceColours = null; @@ -1685,8 +1758,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, // gps[g].setShowunconserved(viewport.getShowUnconserved()); gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo()); viewport.alignment.addGroup(gps[g]); - Color col = new Color((int) (Math.random() * 255), (int) (Math - .random() * 255), (int) (Math.random() * 255)); + Color col = new Color((int) (Math.random() * 255), + (int) (Math.random() * 255), (int) (Math.random() * 255)); col = col.brighter(); for (Enumeration sq = gps[g].getSequences(null).elements(); sq .hasMoreElements(); viewport.setSequenceColour( @@ -1694,7 +1767,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, ; } PaintRefresher.Refresh(this, viewport.getSequenceSetId()); - // alignPanel.updateAnnotation(); + alignPanel.updateAnnotation(); alignPanel.paintAlignment(true); } } @@ -1719,6 +1792,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport.setSelectionGroup(sg); alignPanel.paintAlignment(true); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); + viewport.sendSelection(); } public void deselectAllSequenceMenuItem_actionPerformed() @@ -1735,6 +1809,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, alignPanel.seqPanel.seqCanvas.highlightSearchResults(null); alignPanel.paintAlignment(true); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); + viewport.sendSelection(); } public void invertSequenceMenuItem_actionPerformed() @@ -1746,6 +1821,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); + viewport.sendSelection(); } public void invertColSel_actionPerformed() @@ -1753,6 +1829,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport.invertColumnSelection(); alignPanel.paintAlignment(true); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); + viewport.sendSelection(); } void trimAlignment(boolean trimLeft) @@ -1923,9 +2000,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { if (!viewport.alignment.getAlignmentAnnotation()[i].autoCalculated) { - newal - .addAnnotation(viewport.alignment - .getAlignmentAnnotation()[i]); + newal.addAnnotation(viewport.alignment.getAlignmentAnnotation()[i]); } } } @@ -1934,8 +2009,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, newaf.viewport.sequenceSetID = alignPanel.av.getSequenceSetId(); PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId()); - PaintRefresher.Register(newaf.alignPanel, newaf.alignPanel.av - .getSequenceSetId()); + PaintRefresher.Register(newaf.alignPanel, + newaf.alignPanel.av.getSequenceSetId()); PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas, newaf.alignPanel.av.getSequenceSetId()); @@ -2114,8 +2189,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, Alignment al = (Alignment) viewport.alignment; Conservation c = new Conservation("All", - ResidueProperties.propHash, 3, al.getSequences(), 0, al - .getWidth() - 1); + ResidueProperties.propHash, 3, al.getSequences(), 0, + al.getWidth() - 1); c.calculate(); c.verdict(false, viewport.ConsPercGaps); @@ -2150,8 +2225,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } if (cs instanceof ClustalxColourScheme) { - sg.cs = new ClustalxColourScheme(sg - .getSequences(viewport.hiddenRepSequences), sg.getWidth()); + sg.cs = new ClustalxColourScheme( + sg.getSequences(viewport.hiddenRepSequences), + sg.getWidth()); } else { @@ -2170,9 +2246,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, || cs instanceof Blosum62ColourScheme) { sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus()); - sg.cs.setConsensus(AAFrequency.calculate(sg - .getSequences(viewport.hiddenRepSequences), 0, sg - .getWidth())); + sg.cs.setConsensus(AAFrequency.calculate( + sg.getSequences(viewport.hiddenRepSequences), 0, + sg.getWidth())); } else { @@ -2182,8 +2258,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, if (viewport.getConservationSelected()) { Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, sg - .getSequences(viewport.hiddenRepSequences), 0, + ResidueProperties.propHash, 3, + sg.getSequences(viewport.hiddenRepSequences), 0, viewport.alignment.getWidth() - 1); c.calculate(); c.verdict(false, viewport.ConsPercGaps); @@ -2215,8 +2291,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme != null) { - SliderPanel.setPIDSliderSource(alignPanel, viewport - .getGlobalColourScheme(), "Background"); + SliderPanel.setPIDSliderSource(alignPanel, + viewport.getGlobalColourScheme(), "Background"); SliderPanel.showPIDSlider(); } } @@ -2279,7 +2355,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray(); AlignmentSorter.sortByLength(viewport.getAlignment()); - addHistoryItem(new OrderCommand("Length Sort", oldOrder, viewport.alignment)); + addHistoryItem(new OrderCommand("Length Sort", oldOrder, + viewport.alignment)); alignPanel.paintAlignment(true); } @@ -2393,7 +2470,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, || (viewport.getSelectionGroup() == null && viewport.alignment .getHeight() > 1)) { - final TreePanel tp = new TreePanel(viewport, type, pwType); + final TreePanel tp = new TreePanel(alignPanel, type, pwType); addTreeMenuItem(tp, title); @@ -2413,7 +2490,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, public void loadTree(jalview.io.NewickFile tree, String treeFile) { - TreePanel tp = new TreePanel(viewport, treeFile, "From File - ", tree); + TreePanel tp = new TreePanel(alignPanel, treeFile, "From File - ", tree); jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500); addTreeMenuItem(tp, treeFile); } @@ -2475,7 +2552,22 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, }; }); } - + public boolean sortBy(AlignmentOrder alorder, String undoname) + { + SequenceI[] oldOrder = viewport.getAlignment() + .getSequencesArray(); + if (viewport.applet.debug) + { + System.err.println("Sorting "+alorder.getOrder().size()+" in alignment '"+getTitle()+"'"); + } + AlignmentSorter.sortBy(viewport.getAlignment(), alorder); + if (undoname!=null) + { + addHistoryItem(new OrderCommand(undoname, oldOrder, viewport.alignment)); + } + alignPanel.paintAlignment(true); + return true; + } protected void documentation_actionPerformed() { showURL("http://www.jalview.org/help.html", "HELP"); @@ -2512,28 +2604,23 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, g.setFont(new Font("Helvetica", Font.BOLD, 12)); g.drawString("Build date: " + builddate, x, y += fh); g.setFont(new Font("Helvetica", Font.PLAIN, 12)); - g - .drawString( - "Authors: Andrew Waterhouse, Jim Procter, Michele Clamp, James Cuff, Steve Searle,", - x, y += fh * 1.5); + g.drawString( + "Authors: Jim Procter, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,", + x, y += fh * 1.5); g.drawString("David Martin & Geoff Barton.", x + 50, y += fh); - g - .drawString( - "Development managed by The Barton Group, University of Dundee, Scotland, UK.", - x, y += fh); - g - .drawString( - "For help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list", - x, y += fh); + g.drawString( + "Development managed by The Barton Group, University of Dundee, Scotland, UK.", + x, y += fh); + g.drawString( + "For help, see the FAQ at www.jalview.org and/or join the jalview-discuss@jalview.org mailing list", + x, y += fh); g.drawString("If you use Jalview, please cite:", x, y += fh + 8); - g - .drawString( - "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)", - x, y += fh); - g - .drawString( - "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench", - x, y += fh); + g.drawString( + "Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)", + x, y += fh); + g.drawString( + "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench", + x, y += fh); g.drawString("Bioinformatics doi: 10.1093/bioinformatics/btp033", x, y += fh); } @@ -2577,8 +2664,17 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { System.out.println("Show url: " + url); } - viewport.applet.getAppletContext().showDocument( - new java.net.URL(url), target); + if (url.indexOf("javascript:") == 0) + { + // no target for the javascript context + viewport.applet.getAppletContext().showDocument( + new java.net.URL(url)); + } + else + { + viewport.applet.getAppletContext().showDocument( + new java.net.URL(url), target); + } } catch (Exception ex) { ex.printStackTrace(); @@ -2759,8 +2855,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, CheckboxMenuItem seqLimits = new CheckboxMenuItem(); CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem(); - + CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem(); + Menu autoAnnMenu=new Menu(); + CheckboxMenuItem showSequenceLogo= new CheckboxMenuItem(); + CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem(); + CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem(); + CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem(); + CheckboxMenuItem showGroupConservation = new CheckboxMenuItem(); private void jbInit() throws Exception { @@ -2964,6 +3066,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, hideAllButSelection.setLabel("All but Selected Region (Shift+Ctrl+H)"); hideAllSelection.setLabel("Selected Region"); showAllHidden.setLabel("All Sequences and Columns"); + showGroupConsensus.setLabel("Group Consensus"); + showGroupConservation.setLabel("Group Conservation"); + showConsensusHistogram.setLabel("Show Consensus Histogram"); + showSequenceLogo.setLabel("Show Consensus Logo"); + applyAutoAnnotationSettings.setLabel("Apply to all groups"); + applyAutoAnnotationSettings.setState(true); + autoAnnMenu.setLabel("Autocalculated Annotation"); + invertColSel.addActionListener(this); showColumns.addActionListener(this); showSeqs.addActionListener(this); @@ -2972,6 +3082,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, hideAllButSelection.addActionListener(this); hideAllSelection.addActionListener(this); showAllHidden.addActionListener(this); + showGroupConsensus.addItemListener(this); + showGroupConservation.addItemListener(this); + showConsensusHistogram.addItemListener(this); + showSequenceLogo.addItemListener(this); + applyAutoAnnotationSettings.addItemListener(this); formatMenu.setLabel("Format"); selectMenu.setLabel("Select"); newView.setLabel("New View"); @@ -3021,6 +3136,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewMenu.addSeparator(); viewMenu.add(followMouseOverFlag); viewMenu.add(annotationPanelMenuItem); + autoAnnMenu.add(applyAutoAnnotationSettings); + autoAnnMenu.add(showConsensusHistogram); + autoAnnMenu.add(showSequenceLogo); + autoAnnMenu.addSeparator(); + autoAnnMenu.add(showGroupConservation); + autoAnnMenu.add(showGroupConsensus); + viewMenu.add(autoAnnMenu); viewMenu.addSeparator(); viewMenu.add(sequenceFeatures); viewMenu.add(featureSettings); @@ -3156,10 +3278,27 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport.applet.setLayout(new BorderLayout()); viewport.applet.add(embeddedMenu, BorderLayout.NORTH); viewport.applet.add(statusBar, BorderLayout.SOUTH); - alignPanel.setSize(viewport.applet.getSize().width, viewport.applet - .getSize().height - - embeddedMenu.HEIGHT - statusBar.HEIGHT); + alignPanel.setSize(viewport.applet.getSize().width, + viewport.applet.getSize().height - embeddedMenu.HEIGHT + - statusBar.HEIGHT); viewport.applet.add(alignPanel, BorderLayout.CENTER); + final AlignFrame me = this; + viewport.applet.addFocusListener(new FocusListener() + { + + @Override + public void focusLost(FocusEvent e) + { + if (me.viewport.applet.currentAlignFrame==me) { + me.viewport.applet.currentAlignFrame = null; + }} + + @Override + public void focusGained(FocusEvent e) + { + me.viewport.applet.currentAlignFrame = me; + } + }); viewport.applet.validate(); } else @@ -3180,4 +3319,242 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, DEFAULT_HEIGHT); } } + + /** + * create a new binding between structures in an existing jmol viewer instance + * and an alignpanel with sequences that have existing PDBFile entries. Note, + * this does not open a new Jmol window, or modify the display of the + * structures in the original jmol window. Note This method doesn't work + * without an additional javascript library to exchange messages between the + * distinct applets. See http://issues.jalview.org/browse/JAL-621 + * + * @param viewer + * JmolViewer instance + * @param sequenceIds + * - sequence Ids to search for associations + */ + public SequenceStructureBinding addStructureViewInstance( + Object jmolviewer, String[] sequenceIds) + { + org.jmol.api.JmolViewer viewer = null; + try + { + viewer = (org.jmol.api.JmolViewer) jmolviewer; + } catch (ClassCastException ex) + { + System.err.println("Unsupported viewer object :" + + jmolviewer.getClass()); + } + if (viewer == null) + { + System.err.println("Can't use this object as a structure viewer:" + + jmolviewer.getClass()); + return null; + } + SequenceI[] seqs = null; + if (sequenceIds == null || sequenceIds.length == 0) + { + seqs = viewport.getAlignment().getSequencesArray(); + } + else + { + Vector sqi = new Vector(); + AlignmentI al = viewport.getAlignment(); + for (int sid = 0; sid < sequenceIds.length; sid++) + { + SequenceI sq = al.findName(sequenceIds[sid]); + if (sq != null) + { + sqi.addElement(sq); + } + } + if (sqi.size() > 0) + { + seqs = new SequenceI[sqi.size()]; + for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++) + { + seqs[sid] = (SequenceI) sqi.elementAt(sid); + } + } + else + { + return null; + } + } + ExtJmol jmv = null; + // TODO: search for a jmv that involves viewer + if (jmv == null) + { // create a new viewer/jalview binding. + jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] {seqs}); + } + return jmv; + + } + + public boolean addPdbFile(String sequenceId, String pdbEntryString, + String pdbFile) + { + SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId); + boolean needtoadd = false; + if (toaddpdb != null) + { + Vector pdbe = toaddpdb.getPDBId(); + PDBEntry pdbentry = null; + if (pdbe != null && pdbe.size() > 0) + { + for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++) + { + pdbentry = (PDBEntry) pdbe.elementAt(pe); + if (!pdbentry.getId().equals(pdbEntryString) + && !pdbentry.getFile().equals(pdbFile)) + { + pdbentry = null; + } + else + { + continue; + } + } + } + if (pdbentry == null) + { + pdbentry = new PDBEntry(); + pdbentry.setId(pdbEntryString); + pdbentry.setFile(pdbFile); + needtoadd = true; // add this new entry to sequence. + } + // resolve data source + // TODO: this code should be a refactored to an io package + String protocol = AppletFormatAdapter.resolveProtocol(pdbFile, "PDB"); + if (protocol == null) + { + return false; + } + if (needtoadd) + { + // make a note of the access mode and add + if (pdbentry.getProperty() == null) + { + pdbentry.setProperty(new Hashtable()); + } + pdbentry.getProperty().put("protocol", protocol); + toaddpdb.addPDBId(pdbentry); + } + } + return true; + } + + private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains) + { + if (seqs != null) + { + Vector sequences = new Vector(); + for (int i = 0; i < seqs.length; i++) + { + if (seqs[i] != null) + { + sequences.addElement(new Object[] + { seqs[i], (chains != null) ? chains[i] : null }); + } + } + seqs = new SequenceI[sequences.size()]; + chains = new String[sequences.size()]; + for (int i = 0, isize = sequences.size(); i < isize; i++) + { + Object[] oj = (Object[]) sequences.elementAt(i); + + seqs[i] = (SequenceI) oj[0]; + chains[i] = (String) oj[1]; + } + } + return new Object[] + { seqs, chains }; + + } + + public void newStructureView(JalviewLite applet, PDBEntry pdb, + SequenceI[] seqs, String[] chains, String protocol) + { + // Scrub any null sequences from the array + Object[] sqch = cleanSeqChainArrays(seqs, chains); + seqs = (SequenceI[]) sqch[0]; + chains = (String[]) sqch[1]; + if (seqs == null || seqs.length == 0) + { + System.err + .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to."); + } + if (protocol == null || protocol.trim().length() == 0 + || protocol.equals("null")) + { + protocol = (String) pdb.getProperty().get("protocol"); + if (protocol == null) + { + System.err.println("Couldn't work out protocol to open structure: " + + pdb.getId()); + return; + } + } + if (applet.useXtrnalSviewer) + { + // register the association(s) and quit, don't create any windows. + StructureSelectionManager.getStructureSelectionManager().setMapping(seqs, chains, pdb.getFile(), protocol); + return; + } + if (applet.isAlignPdbStructures() && applet.jmolAvailable) + { + // can only do alignments with Jmol + // find the last jmol window assigned to this alignment + jalview.appletgui.AppletJmol ajm = null, tajm; + Vector jmols = applet + .getAppletWindow(jalview.appletgui.AppletJmol.class); + for (int i = 0, iSize = jmols.size(); i < iSize; i++) + { + tajm = (jalview.appletgui.AppletJmol) jmols.elementAt(i); + if (tajm.ap.alignFrame == this) + { + ajm = tajm; + break; + } + } + if (ajm != null) + { + System.err + .println("Incremental adding and aligning structure to existing Jmol view not yet implemented."); + // try and add the pdb structure + // ajm.addS + ajm = null; + } + } + // otherwise, create a new window + if (applet.jmolAvailable) + { + new jalview.appletgui.AppletJmol(pdb, seqs, chains, alignPanel, + protocol); + applet.lastFrameX += 40; + applet.lastFrameY += 40; + } + else + { + new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol); + } + + } + + public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb, + SequenceI[][] seqs, String[][] chains, String[] protocols) + { + // TODO Auto-generated method stub + System.err.println("Aligned Structure View: Not yet implemented."); + } + + /** + * modify the current selection, providing the user has not made a selection already. + * @param sel - sequences from this alignment + * @param csel - columns to be selected on the alignment + */ + public void select(SequenceGroup sel, ColumnSelection csel) + { + alignPanel.seqPanel.selection(sel, csel, null); + } }