From: hansonr Date: Sun, 19 May 2019 03:34:19 +0000 (-0500) Subject: Jalview-JS/JAL-3253-applet adds AlignFrameI empty interface to allow X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=418006c3714eb8da78234660698231597eb90fb1;p=jalview.git Jalview-JS/JAL-3253-applet adds AlignFrameI empty interface to allow JalviewLiteJSApi to serve with jalview.gui.AppletFrame as well as jalview.appletgui.AppletFrame. --- diff --git a/src/jalview/api/AlignFrameI.java b/src/jalview/api/AlignFrameI.java new file mode 100644 index 0000000..c675a6e --- /dev/null +++ b/src/jalview/api/AlignFrameI.java @@ -0,0 +1,13 @@ +package jalview.api; + +/** + * Common methods for jalview.appletgui.AlignFrame and jalview.gui.AlignFrame in + * relation to JalviewJS and the JalviewLiteJSApi + * + * @author hansonr + * + */ +public interface AlignFrameI +{ + +} diff --git a/src/jalview/api/AlignmentViewPanel.java b/src/jalview/api/AlignmentViewPanel.java index 0b1ca21..ad7800c 100644 --- a/src/jalview/api/AlignmentViewPanel.java +++ b/src/jalview/api/AlignmentViewPanel.java @@ -63,4 +63,6 @@ public interface AlignmentViewPanel extends OOMHandlerI * @return displayed name for the view */ String getViewName(); + + SequenceRenderer getSequenceRenderer(); } diff --git a/src/jalview/api/JalviewApp.java b/src/jalview/api/JalviewApp.java index 7215227..0548c85 100644 --- a/src/jalview/api/JalviewApp.java +++ b/src/jalview/api/JalviewApp.java @@ -1,12 +1,24 @@ package jalview.api; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.NewickFile; +import jalview.javascript.JSFunctionExec; +import jalview.javascript.MouseOverStructureListener; +import jalview.structure.SelectionSource; +import jalview.structure.VamsasSource; +import java.applet.AppletContext; import java.io.IOException; import java.net.URL; +import java.util.Hashtable; +import java.util.Vector; + +import netscape.javascript.JSObject; public interface JalviewApp { @@ -40,4 +52,31 @@ public interface JalviewApp public void loadTree(NewickFile fin, String treeFile) throws IOException; + public Vector getJsExecQueue(JSFunctionExec jsFunctionExec); + + public AppletContext getAppletContext(); + + public boolean isJsfallbackEnabled(); + + public JSObject getJSObject(); + + public StructureSelectionManagerProvider getStructureSelectionManagerProvider(); + + public void updateColoursFromMouseOver(Object source, + MouseOverStructureListener mouseOverStructureListener); + + public Object[] getSelectionForListener(SequenceGroup seqsel, ColumnSelection colsel, + HiddenColumns hidden, SelectionSource source, Object alignFrame); + + public String arrayToSeparatorList(String[] array); + + public Hashtable getJSHashes(); + + Hashtable> getJSMessages(); + + public Object getFrameForSource(VamsasSource source); + + public jalview.renderer.seqfeatures.FeatureRenderer getNewFeatureRenderer( + AlignViewportI vp); + } diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 2cf33ac..adfb8ca 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -25,6 +25,7 @@ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.TreeBuilder; import jalview.analysis.scoremodels.PIDModel; import jalview.analysis.scoremodels.ScoreModels; +import jalview.api.AlignFrameI; import jalview.api.AlignViewControllerGuiI; import jalview.api.AlignViewControllerI; import jalview.api.AlignViewportI; @@ -118,7 +119,8 @@ import java.util.Vector; import org.jmol.viewer.Viewer; -public class AlignFrame extends EmbmenuFrame implements ActionListener, +public class AlignFrame extends EmbmenuFrame implements AlignFrameI, + ActionListener, ItemListener, KeyListener, AlignViewControllerGuiI { public AlignViewControllerI avc; diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index ac6fcd6..84fec45 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -20,14 +20,20 @@ */ package jalview.bin; +import jalview.api.AlignFrameI; import jalview.api.AlignViewportI; import jalview.api.JalviewApp; +import jalview.api.StructureSelectionManagerProvider; import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.ext.so.SequenceOntology; import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; +import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.gui.Preferences; import jalview.gui.PromptUserConfig; @@ -44,13 +50,19 @@ import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; import jalview.io.NewickFile; import jalview.io.gff.SequenceOntologyFactory; +import jalview.javascript.JSFunctionExec; import jalview.javascript.JalviewLiteJsApi; +import jalview.javascript.MouseOverStructureListener; +import jalview.renderer.seqfeatures.FeatureRenderer; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; +import jalview.structure.SelectionSource; +import jalview.structure.VamsasSource; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.jws2.Jws2Discoverer; +import java.applet.AppletContext; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -68,6 +80,7 @@ import java.security.PermissionCollection; import java.security.Permissions; import java.security.Policy; import java.util.HashMap; +import java.util.Hashtable; import java.util.Map; import java.util.Vector; import java.util.logging.ConsoleHandler; @@ -79,6 +92,7 @@ import javax.swing.UIManager; import groovy.lang.Binding; import groovy.util.GroovyScriptEngine; +import netscape.javascript.JSObject; /** * Main class for Jalview Application
@@ -128,6 +142,10 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi public String appletResourcePath; + private JalviewAppLoader appLoader; + + protected JSFunctionExec jsFunctionExec; + public static AlignFrame getCurrentAlignFrame() { return getInstance().currentAlignFrame; @@ -1226,6 +1244,12 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi */ public void quit() { + if (jsFunctionExec != null) + { + jsFunctionExec.tidyUp(); + jsFunctionExec = null; + } + if (desktop != null) { desktop.quit(); @@ -1266,6 +1290,10 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi private boolean alignPDBStructures; // From JalviewLite; not implemented + private Hashtable> jsmessages; + + private Hashtable jshashes; + @Override public String getParameter(String name) { @@ -1377,9 +1405,112 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi "Jalview applet interface newFeatureSettings not implemented"); } + private Vector jsExecQueue; + + @Override + public Vector getJsExecQueue(JSFunctionExec exec) + { + jsFunctionExec = exec; + return (jsExecQueue == null ? (jsExecQueue = new Vector<>()) + : jsExecQueue); + } + + @Override + public AppletContext getAppletContext() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isJsfallbackEnabled() + { + // TODO Auto-generated method stub + return false; + } + + @Override + public JSObject getJSObject() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public StructureSelectionManagerProvider getStructureSelectionManagerProvider() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void updateColoursFromMouseOver(Object source, + MouseOverStructureListener mouseOverStructureListener) + { + // TODO Auto-generated method stub + + } + + @Override + public Object[] getSelectionForListener(SequenceGroup seqsel, + ColumnSelection colsel, HiddenColumns hidden, + SelectionSource source, Object alignFrame) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public String arrayToSeparatorList(String[] array) + { + return appLoader.arrayToSeparatorList(array); + } + + @Override + public Hashtable getJSHashes() + { + return (jshashes == null + ? (jshashes = new Hashtable<>()) + : jshashes); + } + + @Override + public Hashtable> getJSMessages() + { + return (jsmessages == null + ? (jsmessages = new Hashtable<>()) + : jsmessages); + } + + @Override + public Object getFrameForSource(VamsasSource source) + { + if (source != null) + { + AlignFrame af; + if (source instanceof jalview.gui.AlignViewport + && source == (af = getCurrentAlignFrame()).getViewport()) + { + // should be valid if it just generated an event! + return af; + } + // TODO: ensure that if '_af' is specified along with a handler + // function, then only events from that alignFrame are sent to that + // function + } + return null; + } + + @Override + public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp) + { + return new jalview.gui.FeatureRenderer((AlignmentPanel) vp); + } + }; - new JalviewAppLoader(true).load(app); + appLoader = new JalviewAppLoader(true); + appLoader.load(app); } @Override @@ -1397,14 +1528,14 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String getSelectedSequencesFrom(jalview.appletgui.AlignFrame alf) + public String getSelectedSequencesFrom(AlignFrameI alf) { // TODO Auto-generated method stub return null; } @Override - public String getSelectedSequencesFrom(jalview.appletgui.AlignFrame alf, + public String getSelectedSequencesFrom(AlignFrameI alf, String sep) { // TODO Auto-generated method stub @@ -1420,7 +1551,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void highlightIn(jalview.appletgui.AlignFrame alf, + public void highlightIn(AlignFrameI alf, String sequenceId, String position, String alignedPosition) { // TODO Auto-generated method stub @@ -1442,7 +1573,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void selectIn(jalview.appletgui.AlignFrame alf, String sequenceIds, + public void selectIn(AlignFrameI alf, String sequenceIds, String columns) { // TODO Auto-generated method stub @@ -1450,7 +1581,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void selectIn(jalview.appletgui.AlignFrame alf, String sequenceIds, + public void selectIn(AlignFrameI alf, String sequenceIds, String columns, String sep) { // TODO Auto-generated method stub @@ -1467,7 +1598,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi @Override public String getSelectedSequencesAsAlignmentFrom( - jalview.appletgui.AlignFrame alf, String format, String suffix) + AlignFrameI alf, String format, String suffix) { // TODO Auto-generated method stub return null; @@ -1481,14 +1612,14 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String getAlignmentOrderFrom(jalview.appletgui.AlignFrame alf) + public String getAlignmentOrderFrom(AlignFrameI alf) { // TODO Auto-generated method stub return null; } @Override - public String getAlignmentOrderFrom(jalview.appletgui.AlignFrame alf, + public String getAlignmentOrderFrom(AlignFrameI alf, String sep) { // TODO Auto-generated method stub @@ -1510,7 +1641,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String orderAlignmentBy(jalview.appletgui.AlignFrame alf, + public String orderAlignmentBy(AlignFrameI alf, String order, String undoName, String sep) { // TODO Auto-generated method stub @@ -1525,7 +1656,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String getAlignmentFrom(jalview.appletgui.AlignFrame alf, + public String getAlignmentFrom(AlignFrameI alf, String format) { // TODO Auto-generated method stub @@ -1540,7 +1671,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String getAlignmentFrom(jalview.appletgui.AlignFrame alf, + public String getAlignmentFrom(AlignFrameI alf, String format, String suffix) { // TODO Auto-generated method stub @@ -1555,7 +1686,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void loadAnnotationFrom(jalview.appletgui.AlignFrame alf, + public void loadAnnotationFrom(AlignFrameI alf, String annotation) { // TODO Auto-generated method stub @@ -1570,7 +1701,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public boolean loadFeaturesFrom(jalview.appletgui.AlignFrame alf, + public boolean loadFeaturesFrom(AlignFrameI alf, String features, boolean autoenabledisplay) { // TODO Auto-generated method stub @@ -1585,7 +1716,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String getFeaturesFrom(jalview.appletgui.AlignFrame alf, + public String getFeaturesFrom(AlignFrameI alf, String format) { // TODO Auto-generated method stub @@ -1600,44 +1731,42 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String getAnnotationFrom(jalview.appletgui.AlignFrame alf) + public String getAnnotationFrom(AlignFrameI alf) { // TODO Auto-generated method stub return null; } @Override - public jalview.appletgui.AlignFrame newView() + public AlignFrameI newView() { // TODO Auto-generated method stub return null; } @Override - public jalview.appletgui.AlignFrame newView(String name) + public AlignFrameI newView(String name) { // TODO Auto-generated method stub return null; } @Override - public jalview.appletgui.AlignFrame newViewFrom( - jalview.appletgui.AlignFrame alf) + public AlignFrameI newViewFrom(AlignFrameI alf) { // TODO Auto-generated method stub return null; } @Override - public jalview.appletgui.AlignFrame newViewFrom( - jalview.appletgui.AlignFrame alf, String name) + public AlignFrameI newViewFrom(AlignFrameI alf, String name) { // TODO Auto-generated method stub return null; } @Override - public jalview.appletgui.AlignFrame loadAlignment(String text, + public AlignFrameI loadAlignment(String text, String title) { // TODO Auto-generated method stub @@ -1652,7 +1781,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void setMouseoverListener(jalview.appletgui.AlignFrame af, + public void setMouseoverListener(AlignFrameI af, String listener) { // TODO Auto-generated method stub @@ -1667,7 +1796,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void setSelectionListener(jalview.appletgui.AlignFrame af, + public void setSelectionListener(AlignFrameI af, String listener) { // TODO Auto-generated method stub @@ -1682,7 +1811,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void removeJavascriptListener(jalview.appletgui.AlignFrame af, + public void removeJavascriptListener(AlignFrameI af, String listener) { // TODO Auto-generated method stub @@ -1698,7 +1827,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public boolean addPdbFile(jalview.appletgui.AlignFrame alFrame, + public boolean addPdbFile(AlignFrameI alFrame, String sequenceId, String pdbEntryString, String pdbFile) { // TODO Auto-generated method stub @@ -1706,7 +1835,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void scrollViewToIn(jalview.appletgui.AlignFrame alf, + public void scrollViewToIn(AlignFrameI alf, String topRow, String leftHandColumn) { // TODO Auto-generated method stub @@ -1714,7 +1843,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void scrollViewToRowIn(jalview.appletgui.AlignFrame alf, + public void scrollViewToRowIn(AlignFrameI alf, String topRow) { // TODO Auto-generated method stub @@ -1722,7 +1851,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void scrollViewToColumnIn(jalview.appletgui.AlignFrame alf, + public void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn) { // TODO Auto-generated method stub @@ -1737,7 +1866,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String getFeatureGroupsOn(jalview.appletgui.AlignFrame alf) + public String getFeatureGroupsOn(AlignFrameI alf) { // TODO Auto-generated method stub return null; @@ -1751,7 +1880,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public String getFeatureGroupsOfStateOn(jalview.appletgui.AlignFrame alf, + public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible) { // TODO Auto-generated method stub @@ -1759,7 +1888,7 @@ public class Jalview implements ApplicationSingletonI, JalviewLiteJsApi } @Override - public void setFeatureGroupStateOn(jalview.appletgui.AlignFrame alf, + public void setFeatureGroupStateOn(AlignFrameI alf, String groups, boolean state) { // TODO Auto-generated method stub diff --git a/src/jalview/bin/JalviewAppLoader.java b/src/jalview/bin/JalviewAppLoader.java index 2b6503a..8029aea 100644 --- a/src/jalview/bin/JalviewAppLoader.java +++ b/src/jalview/bin/JalviewAppLoader.java @@ -254,8 +254,7 @@ public class JalviewAppLoader try { ret[0] = param; - DataSourceType protocol = resolveFileProtocol(app, - ret); + DataSourceType protocol = resolveFileProtocol(app, ret); JPredFile predictions = new JPredFile(ret[0], protocol); JnetAnnotationMaker.add_annotation(predictions, app.getViewport().getAlignment(), 0, false); @@ -285,8 +284,7 @@ public class JalviewAppLoader if (param != null) { ret[0] = param; - DataSourceType protocol = resolveFileProtocol(app, - ret); + DataSourceType protocol = resolveFileProtocol(app, ret); param = ret[0]; if (new AnnotationFile().annotateAlignmentView(app.getViewport(), param, protocol)) @@ -324,8 +322,8 @@ public class JalviewAppLoader String param = app.getParameter("hidefeaturegroups"); if (param != null) { - app.setFeatureGroupState( - separatorListToArray(param, separator), false); + app.setFeatureGroupState(separatorListToArray(param, separator), + false); // app.setFeatureGroupStateOn(newAlignFrame, param, false); } // show specific groups @@ -341,8 +339,7 @@ public class JalviewAppLoader if (param != null) { ret[0] = param; - DataSourceType protocol = resolveFileProtocol(app, - ret); + DataSourceType protocol = resolveFileProtocol(app, ret); result = app.parseFeaturesFile(ret[0], protocol); } @@ -391,6 +388,7 @@ public class JalviewAppLoader } String[] ret = new String[1]; + /** * Load a tree for the alignment if specified by parameter. Returns true if a * tree was loaded, else false. @@ -429,7 +427,8 @@ public class JalviewAppLoader { if (debug) { - System.out.println("Tree parameter did not resolve to a valid tree."); + System.out.println( + "Tree parameter did not resolve to a valid tree."); } } } catch (Exception ex) @@ -463,7 +462,7 @@ public class JalviewAppLoader codebase.length() - localfile.length()) + targetPath; return resolvedPath; } - + /* * get URL path and strip off any trailing file e.g. * www.jalview.org/examples/index.html#applets?a=b is trimmed to @@ -476,7 +475,7 @@ public class JalviewAppLoader { directoryPath = directoryPath.substring(0, lastSeparator + 1); } - + if (targetPath.startsWith("/")) { /* @@ -569,7 +568,7 @@ public class JalviewAppLoader retPath[0] = path.substring(5); return DataSourceType.PASTE; } - + /* * is it a URL? */ @@ -577,13 +576,12 @@ public class JalviewAppLoader { return DataSourceType.URL; } - + /* * try relative to document root */ URL documentBase = app.getDocumentBase(); - String withDocBase = resolveUrlForLocalOrAbsolute(path, - documentBase); + String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase); if (HttpUtils.isValidUrl(withDocBase)) { // if (debug) @@ -594,13 +592,12 @@ public class JalviewAppLoader retPath[0] = withDocBase; return DataSourceType.URL; } - + /* * try relative to codebase (if different to document base) */ URL codeBase = app.getCodeBase(); - String withCodeBase = resolveUrlForLocalOrAbsolute(path, - codeBase); + String withCodeBase = resolveUrlForLocalOrAbsolute(path, codeBase); if (!withCodeBase.equals(withDocBase) && HttpUtils.isValidUrl(withCodeBase)) { @@ -671,7 +668,8 @@ public class JalviewAppLoader * @param jalviewApp * @return */ - public String getPastedSequence(JalviewApp jalviewApp) { + public String getPastedSequence(JalviewApp jalviewApp) + { StringBuffer data = new StringBuffer("PASTE"); int i = 1; String file = null; @@ -686,4 +684,50 @@ public class JalviewAppLoader } return file; } -} + + /** + * concatenate the list with separator + * + * @param list + * @param separator + * @return concatenated string + */ + public static String arrayToSeparatorList(String[] list, String separator) + { + // TODO use StringUtils version + StringBuffer v = new StringBuffer(); + if (list != null && list.length > 0) + { + for (int i = 0, iSize = list.length; i < iSize; i++) + { + if (list[i] != null) + { + if (i > 0) + { + v.append(separator); + } + v.append(list[i]); + } + } + // if (debug) + // { + // System.err + // .println("Returning '" + separator + "' separated List:\n"); + // System.err.println(v); + // } + return v.toString(); + } + // if (debug) + // { + // System.err.println( + // "Returning empty '" + separator + "' separated List\n"); + // } + return "" + separator; + } + + public String arrayToSeparatorList(String[] array) + { + return arrayToSeparatorList(array, separator); + } + +} \ No newline at end of file diff --git a/src/jalview/bin/JalviewLite.java b/src/jalview/bin/JalviewLite.java index aec0a5e..1dd7b25 100644 --- a/src/jalview/bin/JalviewLite.java +++ b/src/jalview/bin/JalviewLite.java @@ -21,6 +21,7 @@ package jalview.bin; import jalview.analysis.AlignmentUtils; +import jalview.api.AlignFrameI; import jalview.api.AlignViewportI; import jalview.api.JalviewApp; import jalview.api.StructureSelectionManagerProvider; @@ -33,6 +34,7 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -48,10 +50,14 @@ import jalview.javascript.JSFunctionExec; import jalview.javascript.JalviewLiteJsApi; import jalview.javascript.JsCallBack; import jalview.javascript.MouseOverStructureListener; +import jalview.renderer.seqfeatures.FeatureRenderer; import jalview.structure.SelectionListener; +import jalview.structure.SelectionSource; import jalview.structure.StructureSelectionManager; +import jalview.structure.VamsasSource; import jalview.util.ColorUtils; import jalview.util.MessageManager; +import jalview.viewmodel.AlignmentViewport; import java.applet.Applet; import java.awt.Button; @@ -81,6 +87,7 @@ import netscape.javascript.JSObject; * @author $author$ * @version $Revision: 1.92 $ */ +@SuppressWarnings("serial") public class JalviewLite extends Applet implements StructureSelectionManagerProvider, JalviewLiteJsApi, JalviewApp @@ -99,6 +106,12 @@ public class JalviewLite extends Applet return StructureSelectionManager.getStructureSelectionManager(this); } + @Override + public StructureSelectionManagerProvider getStructureSelectionManagerProvider() + { + return this; + } + // ///////////////////////////////////////// // The following public methods may be called // externally, eg via javascript in HTML page @@ -132,7 +145,7 @@ public class JalviewLite extends Applet * .AlignFrame) */ @Override - public String getSelectedSequencesFrom(AlignFrame alf) + public String getSelectedSequencesFrom(AlignFrameI alf) { return getSelectedSequencesFrom(alf, separator); // ""+0x00AC); } @@ -145,17 +158,18 @@ public class JalviewLite extends Applet * .AlignFrame, java.lang.String) */ @Override - public String getSelectedSequencesFrom(AlignFrame alf, String sep) + public String getSelectedSequencesFrom(AlignFrameI alf, String sep) { StringBuffer result = new StringBuffer(""); if (sep == null || sep.length() == 0) { sep = separator; // "+0x00AC; } - if (alf.viewport.getSelectionGroup() != null) + if (((AlignFrame) alf).viewport.getSelectionGroup() != null) { - SequenceI[] seqs = alf.viewport.getSelectionGroup() - .getSequencesInOrder(alf.viewport.getAlignment()); + SequenceI[] seqs = ((AlignFrame) alf).viewport.getSelectionGroup() + .getSequencesInOrder( + ((AlignFrame) alf).viewport.getAlignment()); for (int i = 0; i < seqs.length; i++) { @@ -188,12 +202,12 @@ public class JalviewLite extends Applet * java.lang.String, java.lang.String, java.lang.String) */ @Override - public void highlightIn(final AlignFrame alf, final String sequenceId, + public void highlightIn(final AlignFrameI alf, final String sequenceId, final String position, final String alignedPosition) { // TODO: could try to highlight in all alignments if alf==null jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher( - alf.viewport.getAlignment().getSequencesArray()); + ((AlignFrame) alf).viewport.getAlignment().getSequencesArray()); final SequenceI sq = matcher.findIdMatch(sequenceId); if (sq != null) { @@ -268,7 +282,7 @@ public class JalviewLite extends Applet * java.lang.String, java.lang.String) */ @Override - public void selectIn(AlignFrame alf, String sequenceIds, String columns) + public void selectIn(AlignFrameI alf, String sequenceIds, String columns) { selectIn(alf, sequenceIds, columns, separator); } @@ -280,7 +294,7 @@ public class JalviewLite extends Applet * java.lang.String, java.lang.String, java.lang.String) */ @Override - public void selectIn(final AlignFrame alf, String sequenceIds, + public void selectIn(final AlignFrameI alf, String sequenceIds, String columns, String sep) { if (sep == null || sep.length() == 0) @@ -300,9 +314,9 @@ public class JalviewLite extends Applet String[] cols = JalviewAppLoader.separatorListToArray(columns, sep); final SequenceGroup sel = new SequenceGroup(); final ColumnSelection csel = new ColumnSelection(); - AlignmentI al = alf.viewport.getAlignment(); + AlignmentI al = ((AlignFrame) alf).viewport.getAlignment(); jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher( - alf.viewport.getAlignment().getSequencesArray()); + ((AlignFrame) alf).viewport.getAlignment().getSequencesArray()); int start = 0, end = al.getWidth(), alw = al.getWidth(); boolean seqsfound = true; if (ids != null && ids.length > 0) @@ -486,8 +500,8 @@ public class JalviewLite extends Applet @Override public void run() { - alf.select(sel, csel, - alf.getAlignViewport().getAlignment().getHiddenColumns()); + ((AlignFrame) alf).select(sel, csel, ((AlignFrame) alf) + .getAlignViewport().getAlignment().getHiddenColumns()); } }); } @@ -516,20 +530,21 @@ public class JalviewLite extends Applet * .appletgui.AlignFrame, java.lang.String, java.lang.String) */ @Override - public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf, + public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf, String format, String suffix) { try { FileFormatI theFormat = FileFormats.getInstance().forName(format); boolean seqlimits = suffix.equalsIgnoreCase(TRUE); - if (alf.viewport.getSelectionGroup() != null) + if (((AlignFrame) alf).viewport.getSelectionGroup() != null) { // JBPNote: getSelectionAsNewSequence behaviour has changed - this // method now returns a full copy of sequence data // TODO consider using getSequenceSelection instead here String reply = new AppletFormatAdapter().formatSequences(theFormat, - new Alignment(alf.viewport.getSelectionAsNewSequence()), + new Alignment(((AlignFrame) alf).viewport + .getSelectionAsNewSequence()), seqlimits); return reply; } @@ -561,7 +576,7 @@ public class JalviewLite extends Applet * ) */ @Override - public String getAlignmentOrderFrom(AlignFrame alf) + public String getAlignmentOrderFrom(AlignFrameI alf) { return getAlignmentOrderFrom(alf, separator); } @@ -574,9 +589,10 @@ public class JalviewLite extends Applet * , java.lang.String) */ @Override - public String getAlignmentOrderFrom(AlignFrame alf, String sep) + public String getAlignmentOrderFrom(AlignFrameI alf, String sep) { - AlignmentI alorder = alf.getAlignViewport().getAlignment(); + AlignmentI alorder = ((AlignFrame) alf).getAlignViewport() + .getAlignment(); String[] order = new String[alorder.getHeight()]; for (int i = 0; i < order.length; i++) { @@ -617,7 +633,7 @@ public class JalviewLite extends Applet * java.lang.String, java.lang.String, java.lang.String) */ @Override - public String orderAlignmentBy(AlignFrame alf, String order, + public String orderAlignmentBy(AlignFrameI alf, String order, String undoName, String sep) { String[] ids = JalviewAppLoader.separatorListToArray(order, sep); @@ -625,7 +641,8 @@ public class JalviewLite extends Applet if (ids != null && ids.length > 0) { jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher( - alf.viewport.getAlignment().getSequencesArray()); + ((AlignFrame) alf).viewport.getAlignment() + .getSequencesArray()); int s = 0; sqs = new SequenceI[ids.length]; for (int i = 0; i < ids.length; i++) @@ -665,7 +682,7 @@ public class JalviewLite extends Applet final String _undoName = undoName; // TODO: deal with synchronization here: cannot raise any events until after // this has returned. - return alf.sortBy(aorder, _undoName) ? TRUE : ""; + return ((AlignFrame) alf).sortBy(aorder, _undoName) ? TRUE : ""; } /* @@ -687,7 +704,7 @@ public class JalviewLite extends Applet * java.lang.String) */ @Override - public String getAlignmentFrom(AlignFrame alf, String format) + public String getAlignmentFrom(AlignFrameI alf, String format) { return getAlignmentFrom(alf, format, TRUE); } @@ -712,7 +729,7 @@ public class JalviewLite extends Applet * java.lang.String, java.lang.String) */ @Override - public String getAlignmentFrom(AlignFrame alf, String format, + public String getAlignmentFrom(AlignFrameI alf, String format, String suffix) { try @@ -721,7 +738,7 @@ public class JalviewLite extends Applet FileFormatI theFormat = FileFormats.getInstance().forName(format); String reply = new AppletFormatAdapter().formatSequences(theFormat, - alf.viewport.getAlignment(), seqlimits); + ((AlignFrame) alf).viewport.getAlignment(), seqlimits); return reply; } catch (IllegalArgumentException ex) { @@ -750,17 +767,19 @@ public class JalviewLite extends Applet * , java.lang.String) */ @Override - public void loadAnnotationFrom(AlignFrame alf, String annotation) + public void loadAnnotationFrom(AlignFrameI alf, String annotation) { - if (new AnnotationFile().annotateAlignmentView(alf.getAlignViewport(), + if (new AnnotationFile().annotateAlignmentView( + ((AlignFrame) alf).getAlignViewport(), annotation, DataSourceType.PASTE)) { - alf.alignPanel.fontChanged(); - alf.alignPanel.setScrollValues(0, 0); + ((AlignFrame) alf).alignPanel.fontChanged(); + ((AlignFrame) alf).alignPanel.setScrollValues(0, 0); } else { - alf.parseFeaturesFile(annotation, DataSourceType.PASTE); + ((AlignFrame) alf).parseFeaturesFile(annotation, + DataSourceType.PASTE); } } @@ -783,10 +802,11 @@ public class JalviewLite extends Applet * , java.lang.String) */ @Override - public boolean loadFeaturesFrom(AlignFrame alf, String features, + public boolean loadFeaturesFrom(AlignFrameI alf, String features, boolean autoenabledisplay) { - return alf.parseFeaturesFile(features, DataSourceType.PASTE, + return ((AlignFrame) alf).parseFeaturesFile(features, + DataSourceType.PASTE, autoenabledisplay); } @@ -809,9 +829,9 @@ public class JalviewLite extends Applet * java.lang.String) */ @Override - public String getFeaturesFrom(AlignFrame alf, String format) + public String getFeaturesFrom(AlignFrameI alf, String format) { - return alf.outputFeatures(false, format); + return ((AlignFrame) alf).outputFeatures(false, format); } /* @@ -833,9 +853,9 @@ public class JalviewLite extends Applet * ) */ @Override - public String getAnnotationFrom(AlignFrame alf) + public String getAnnotationFrom(AlignFrameI alf) { - return alf.outputAnnotations(false); + return ((AlignFrame) alf).outputAnnotations(false); } /* @@ -866,9 +886,9 @@ public class JalviewLite extends Applet * @see jalview.bin.JalviewLiteJsApi#newViewFrom(jalview.appletgui.AlignFrame) */ @Override - public AlignFrame newViewFrom(AlignFrame alf) + public AlignFrame newViewFrom(AlignFrameI alf) { - return alf.newView(null); + return ((AlignFrame) alf).newView(null); } /* @@ -878,9 +898,9 @@ public class JalviewLite extends Applet * java.lang.String) */ @Override - public AlignFrame newViewFrom(AlignFrame alf, String name) + public AlignFrame newViewFrom(AlignFrameI alf, String name) { - return alf.newView(name); + return ((AlignFrame) alf).newView(name); } /* @@ -932,7 +952,7 @@ public class JalviewLite extends Applet * , java.lang.String) */ @Override - public void setMouseoverListener(AlignFrame af, String listener) + public void setMouseoverListener(AlignFrameI af, String listener) { if (listener != null) { @@ -945,7 +965,7 @@ public class JalviewLite extends Applet } } jalview.javascript.MouseOverListener mol = new jalview.javascript.MouseOverListener( - this, af, listener); + this, (AlignFrame) af, listener, debug); javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager(this) .addStructureViewerListener(mol); @@ -954,7 +974,8 @@ public class JalviewLite extends Applet System.err.println("Added a mouseover listener for " + ((af == null) ? "All frames" : "Just views for " - + af.getAlignViewport().getSequenceSetId())); + + ((AlignFrame) af).getAlignViewport() + .getSequenceSetId())); System.err.println("There are now " + javascriptListeners.size() + " listeners in total."); } @@ -979,7 +1000,7 @@ public class JalviewLite extends Applet * , java.lang.String) */ @Override - public void setSelectionListener(AlignFrame af, String listener) + public void setSelectionListener(AlignFrameI af, String listener) { if (listener != null) { @@ -992,7 +1013,7 @@ public class JalviewLite extends Applet } } jalview.javascript.JsSelectionSender mol = new jalview.javascript.JsSelectionSender( - this, af, listener); + this, (AlignFrame) af, listener, debug); javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager(this) .addSelectionListener(mol); @@ -1001,7 +1022,8 @@ public class JalviewLite extends Applet System.err.println("Added a selection listener for " + ((af == null) ? "All frames" : "Just views for " - + af.getAlignViewport().getSequenceSetId())); + + ((AlignFrame) af).getAlignViewport() + .getSequenceSetId())); System.err.println("There are now " + javascriptListeners.size() + " listeners in total."); } @@ -1032,7 +1054,7 @@ public class JalviewLite extends Applet } } MouseOverStructureListener mol = new MouseOverStructureListener(this, - listener, separatorListToArray(modelSet)); + listener, separatorListToArray(modelSet), debug); javascriptListeners.addElement(mol); StructureSelectionManager.getStructureSelectionManager(this) .addStructureViewerListener(mol); @@ -1053,7 +1075,7 @@ public class JalviewLite extends Applet * .AlignFrame, java.lang.String) */ @Override - public void removeJavascriptListener(AlignFrame af, String listener) + public void removeJavascriptListener(AlignFrameI af, String listener) { if (listener != null) { @@ -1148,11 +1170,10 @@ public class JalviewLite extends Applet } if (jsFunctionExec != null) { - jsFunctionExec.stopQueue(); - jsFunctionExec.jvlite = null; + jsFunctionExec.tidyUp(); + jsFunctionExec = null; } initialAlignFrame = null; - jsFunctionExec = null; javascriptListeners = null; StructureSelectionManager.release(this); } @@ -1204,7 +1225,7 @@ public class JalviewLite extends Applet * java.lang.String, java.lang.String) */ @Override - public void scrollViewToIn(final AlignFrame alf, final String topRow, + public void scrollViewToIn(final AlignFrameI alf, final String topRow, final String leftHandColumn) { java.awt.EventQueue.invokeLater(new Runnable() @@ -1214,7 +1235,7 @@ public class JalviewLite extends Applet { try { - alf.scrollTo(new Integer(topRow).intValue(), + ((AlignFrame) alf).scrollTo(new Integer(topRow).intValue(), new Integer(leftHandColumn).intValue()); } catch (Exception ex) @@ -1236,7 +1257,7 @@ public class JalviewLite extends Applet * .AlignFrame, java.lang.String) */ @Override - public void scrollViewToRowIn(final AlignFrame alf, final String topRow) + public void scrollViewToRowIn(final AlignFrameI alf, final String topRow) { java.awt.EventQueue.invokeLater(new Runnable() @@ -1246,7 +1267,7 @@ public class JalviewLite extends Applet { try { - alf.scrollToRow(new Integer(topRow).intValue()); + ((AlignFrame) alf).scrollToRow(new Integer(topRow).intValue()); } catch (Exception ex) { @@ -1267,7 +1288,7 @@ public class JalviewLite extends Applet * .AlignFrame, java.lang.String) */ @Override - public void scrollViewToColumnIn(final AlignFrame alf, + public void scrollViewToColumnIn(final AlignFrameI alf, final String leftHandColumn) { java.awt.EventQueue.invokeLater(new Runnable() @@ -1278,7 +1299,8 @@ public class JalviewLite extends Applet { try { - alf.scrollToColumn(new Integer(leftHandColumn).intValue()); + ((AlignFrame) alf) + .scrollToColumn(new Integer(leftHandColumn).intValue()); } catch (Exception ex) { @@ -1324,9 +1346,9 @@ public class JalviewLite extends Applet boolean embedded = false; - private boolean checkForJmol = true; + boolean checkForJmol = true; - private boolean checkedForJmol = false; // ensure we don't check for jmol + boolean checkedForJmol = false; // ensure we don't check for jmol // every time the app is re-inited @@ -1615,7 +1637,7 @@ public class JalviewLite extends Applet try { // do onInit with the JS executor thread - new JSFunctionExec(this).executeJavascriptFunction(true, + new JSFunctionExec(this, debug).executeJavascriptFunction(true, initjscallback, null, "Calling oninit callback '" + initjscallback + "'."); } catch (Exception e) @@ -2047,7 +2069,7 @@ public class JalviewLite extends Applet /** * set to enable the URL based javascript execution mechanism */ - public boolean jsfallbackEnabled = false; + private boolean jsfallbackEnabled = false; /** * parse the string into a list @@ -2066,49 +2088,10 @@ public class JalviewLite extends Applet * @param list * @return concatenated string */ + @Override public String arrayToSeparatorList(String[] list) { - return arrayToSeparatorList(list, separator); - } - - /** - * concatenate the list with separator - * - * @param list - * @param separator - * @return concatenated string - */ - public static String arrayToSeparatorList(String[] list, String separator) - { - // TODO use StringUtils version - StringBuffer v = new StringBuffer(); - if (list != null && list.length > 0) - { - for (int i = 0, iSize = list.length; i < iSize; i++) - { - if (list[i] != null) - { - if (i > 0) - { - v.append(separator); - } - v.append(list[i]); - } - } - if (debug) - { - System.err - .println("Returning '" + separator + "' separated List:\n"); - System.err.println(v); - } - return v.toString(); - } - if (debug) - { - System.err.println( - "Returning empty '" + separator + "' separated List\n"); - } - return "" + separator; + return JalviewAppLoader.arrayToSeparatorList(list, separator); } /* @@ -2132,9 +2115,10 @@ public class JalviewLite extends Applet * ) */ @Override - public String getFeatureGroupsOn(AlignFrame alf) + public String getFeatureGroupsOn(AlignFrameI alf) { - String lst = arrayToSeparatorList(alf.getFeatureGroups()); + String lst = arrayToSeparatorList( + ((AlignFrame) alf).getFeatureGroups()); return lst; } @@ -2158,9 +2142,10 @@ public class JalviewLite extends Applet * .AlignFrame, boolean) */ @Override - public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible) + public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible) { - return arrayToSeparatorList(alf.getFeatureGroupsOfState(visible)); + return arrayToSeparatorList( + ((AlignFrame) alf).getFeatureGroupsOfState(visible)); } /* @@ -2170,7 +2155,7 @@ public class JalviewLite extends Applet * AlignFrame, java.lang.String, boolean) */ @Override - public void setFeatureGroupStateOn(final AlignFrame alf, + public void setFeatureGroupStateOn(final AlignFrameI alf, final String groups, boolean state) { final boolean st = state;// !(state==null || state.equals("") || @@ -2180,7 +2165,8 @@ public class JalviewLite extends Applet @Override public void run() { - alf.setFeatureGroupState(separatorListToArray(groups), st); + ((AlignFrame) alf) + .setFeatureGroupState(separatorListToArray(groups), st); } }); } @@ -2260,10 +2246,11 @@ public class JalviewLite extends Applet * java.lang.String, java.lang.String, java.lang.String) */ @Override - public boolean addPdbFile(AlignFrame alFrame, String sequenceId, + public boolean addPdbFile(AlignFrameI alFrame, String sequenceId, String pdbEntryString, String pdbFile) { - return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile); + return ((AlignFrame) alFrame).addPdbFile(sequenceId, pdbEntryString, + pdbFile); } @Override @@ -2283,86 +2270,36 @@ public class JalviewLite extends Applet // callInitCallback(); } - private Hashtable jshashes = new Hashtable<>(); + private Hashtable jshashes = new Hashtable<>(); private Hashtable> jsmessages = new Hashtable<>(); - public void setJsMessageSet(String messageclass, String viewId, - String[] colcommands) - { - Hashtable msgset = jsmessages.get(messageclass); - if (msgset == null) - { - msgset = new Hashtable<>(); - jsmessages.put(messageclass, msgset); - } - msgset.put(viewId, colcommands); - long[] l = new long[colcommands.length]; - for (int i = 0; i < colcommands.length; i++) - { - l[i] = colcommands[i].hashCode(); - } - jshashes.put(messageclass + "|" + viewId, l); - } - /* - * (non-Javadoc) - * - * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String, - * java.lang.String) - */ @Override - public String getJsMessage(String messageclass, String viewId) + public Hashtable getJSHashes() { - Hashtable msgset = jsmessages.get(messageclass); - if (msgset != null) - { - String[] msgs = msgset.get(viewId); - if (msgs != null) - { - for (int i = 0; i < msgs.length; i++) - { - if (msgs[i] != null) - { - String m = msgs[i]; - msgs[i] = null; - return m; - } - } - } - } - return ""; + return jshashes; } - public boolean isJsMessageSetChanged(String string, String string2, - String[] colcommands) + @Override + public Hashtable> getJSMessages() { - long[] l = jshashes.get(string + "|" + string2); - if (l == null && colcommands != null) - { - return true; - } - for (int i = 0; i < colcommands.length; i++) - { - if (l[i] != colcommands[i].hashCode()) - { - return true; - } - } - return false; + return jsmessages; } - private Vector jsExecQueue = new Vector(); + private Vector jsExecQueue = new Vector<>(); - public Vector getJsExecQueue() + @Override + public Vector getJsExecQueue(JSFunctionExec exec) { + jsFunctionExec = exec; return jsExecQueue; } - public void setExecutor(JSFunctionExec jsFunctionExec2) - { - jsFunctionExec = jsFunctionExec2; - } + // public void setExecutor(JSFunctionExec jsFunctionExec2) + // { + // jsFunctionExec = jsFunctionExec2; + // } /** * return the given colour value parameter or the given default if parameter @@ -2507,6 +2444,118 @@ public class JalviewLite extends Applet loaderFrame.loadTree(tree, treeFile); } + @Override + public boolean isJsfallbackEnabled() + { + return jsfallbackEnabled; + } + + @Override + public JSObject getJSObject() + { + return JSObject.getWindow(this); + } + + @Override + public void updateColoursFromMouseOver(Object source, + MouseOverStructureListener listener) + { + } + + @Override + public Object[] getSelectionForListener(SequenceGroup seqsel, ColumnSelection colsel, + HiddenColumns hidden, SelectionSource source, Object alignFrame) + { + // System.err.println("Testing selection event relay to + // jsfunction:"+_listener); + String setid = ""; + AlignFrame src = (AlignFrame) alignFrame; + if (source != null) + { + if (source instanceof jalview.appletgui.AlignViewport + && ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame.viewport == source) + { + // should be valid if it just generated an event! + src = ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame; + + } + } + String[] seqs = new String[] {}; + String[] cols = new String[] {}; + int strt = 0, end = (src == null) ? -1 + : src.alignPanel.av.getAlignment().getWidth(); + if (seqsel != null && seqsel.getSize() > 0) + { + seqs = new String[seqsel.getSize()]; + for (int i = 0; i < seqs.length; i++) + { + seqs[i] = seqsel.getSequenceAt(i).getName(); + } + if (strt < seqsel.getStartRes()) + { + strt = seqsel.getStartRes(); + } + if (end == -1 || end > seqsel.getEndRes()) + { + end = seqsel.getEndRes(); + } + } + if (colsel != null && !colsel.isEmpty()) + { + if (end == -1) + { + end = colsel.getMax() + 1; + } + cols = new String[colsel.getSelected().size()]; + for (int i = 0; i < cols.length; i++) + { + cols[i] = "" + (1 + colsel.getSelected().get(i).intValue()); + } + } + else + { + if (seqsel != null && seqsel.getSize() > 0) + { + // send a valid range, otherwise we send the empty selection + cols = new String[2]; + cols[0] = "" + (1 + strt) + "-" + (1 + end); + } + } + return new Object[] + { src, setid, arrayToSeparatorList(seqs), arrayToSeparatorList(cols) }; + } + + @Override + public String getJsMessage(String messageclass, String viewId) + { + return JSFunctionExec.getJsMessage(messageclass, viewId, this); + } + + @Override + public Object getFrameForSource(VamsasSource source) + { + if (source != null) + { + if (source instanceof jalview.appletgui.AlignViewport + && ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame.viewport == source) + { + // should be valid if it just generated an event! + return ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame; + + } + // TODO: ensure that if '_af' is specified along with a handler + // function, then only events from that alignFrame are sent to that + // function + } + return null; + } + + @Override + public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp) + { + return new jalview.appletgui.FeatureRenderer((AlignmentViewport) vp); + } + /** * bind structures in a viewer to any matching sequences in an alignFrame (use * sequenceIds to limit scope of search to specific sequences) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b56f269..0067a6b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -28,6 +28,7 @@ import jalview.analysis.GeneticCodeI; import jalview.analysis.ParseProperties; import jalview.analysis.SequenceIdMatcher; import jalview.api.AlignExportSettingsI; +import jalview.api.AlignFrameI; import jalview.api.AlignViewControllerGuiI; import jalview.api.AlignViewControllerI; import jalview.api.AlignViewportI; @@ -162,7 +163,8 @@ import ext.vamsas.ServiceHandle; * @version $Revision$ */ @SuppressWarnings("serial") -public class AlignFrame extends GAlignFrame implements DropTargetListener, +public class AlignFrame extends GAlignFrame + implements AlignFrameI, DropTargetListener, IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener { diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 0040dd7..f828034 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.analysis.AnnotationSorter; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; +import jalview.api.SequenceRenderer; import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; @@ -1722,4 +1723,10 @@ public class AlignmentPanel extends GAlignmentPanel implements return calculationDialog; } + @Override + public SequenceRenderer getSequenceRenderer() + { + return seqPanel.seqCanvas.getSequenceRenderer(); + } + } diff --git a/src/jalview/javascript/JSFunctionExec.java b/src/jalview/javascript/JSFunctionExec.java index 29f3fa9..ad7a379 100644 --- a/src/jalview/javascript/JSFunctionExec.java +++ b/src/jalview/javascript/JSFunctionExec.java @@ -20,26 +20,28 @@ */ package jalview.javascript; -import jalview.bin.JalviewLite; +import jalview.api.JalviewApp; import java.net.URL; +import java.util.Hashtable; import java.util.Vector; import netscape.javascript.JSObject; public class JSFunctionExec implements Runnable { - public JalviewLite jvlite; + public JalviewApp jvlite; - public JSFunctionExec(JalviewLite applet) + protected boolean debug; + + public JSFunctionExec(JalviewApp applet, boolean debug) { jvlite = applet; - - jsExecQueue = jvlite.getJsExecQueue(); - jvlite.setExecutor(this); + this.debug = debug; + jsExecQueue = jvlite.getJsExecQueue(this); } - private Vector jsExecQueue; + private Vector jsExecQueue; private Thread executor = null; @@ -47,7 +49,7 @@ public class JSFunctionExec implements Runnable { if (jsExecQueue != null) { - Vector q = null; + Vector q = null; synchronized (jsExecQueue) { q = jsExecQueue; @@ -55,9 +57,9 @@ public class JSFunctionExec implements Runnable } if (q != null) { - for (JSFunctionExec jx : q) + for (Runnable jx : q) { - jx.jvlite = null; + ((JSFunctionExec) jx).jvlite = null; } q.removeAllElements(); @@ -78,7 +80,7 @@ public class JSFunctionExec implements Runnable { if (jsExecQueue.size() > 0) { - Runnable r = (Runnable) jsExecQueue.elementAt(0); + Runnable r = jsExecQueue.elementAt(0); jsExecQueue.removeElementAt(0); try { @@ -162,14 +164,14 @@ public class JSFunctionExec implements Runnable JSObject scriptObject = null; try { - scriptObject = JSObject.getWindow(jvlite); + scriptObject = jvlite.getJSObject(); } catch (Exception ex) { } ; if (scriptObject != null) { - if (jvlite.debug && dbgMsg != null) + if (debug && dbgMsg != null) { System.err.println(dbgMsg); } @@ -180,15 +182,15 @@ public class JSFunctionExec implements Runnable // squash any malformedURLExceptions thrown by windows/safari if (!(jex instanceof java.net.MalformedURLException)) { - if (jvlite.debug) + if (debug) { System.err.println(jex); } if (jex instanceof netscape.javascript.JSException - && jvlite.jsfallbackEnabled) + && jvlite.isJsfallbackEnabled()) { jsex[0] = jex; - if (jvlite.debug) + if (debug) { System.err.println("Falling back to javascript: url call"); } @@ -211,7 +213,7 @@ public class JSFunctionExec implements Runnable sb.append("\""); } sb.append(")"); - if (jvlite.debug) + if (debug) { System.err.println(sb.toString()); } @@ -248,7 +250,7 @@ public class JSFunctionExec implements Runnable { if (executor == null) { - executor = new Thread(new JSFunctionExec(jvlite)); + executor = new Thread(new JSFunctionExec(jvlite, debug)); executor.start(); } synchronized (jsExecQueue) @@ -268,4 +270,80 @@ public class JSFunctionExec implements Runnable } } + public static void setJsMessageSet(String messageclass, String viewId, + String[] colcommands, JalviewApp app) + { + Hashtable> jsmessages = app + .getJSMessages(); + Hashtable jshashes = app.getJSHashes(); + + Hashtable msgset = jsmessages.get(messageclass); + if (msgset == null) + { + msgset = new Hashtable<>(); + jsmessages.put(messageclass, msgset); + } + msgset.put(viewId, colcommands); + int[] l = new int[colcommands.length]; + for (int i = 0; i < colcommands.length; i++) + { + l[i] = colcommands[i].hashCode(); + } + jshashes.put(messageclass + "|" + viewId, l); + } + + /* + * (non-Javadoc) + * + * @see jalview.bin.JalviewLiteJsApi#getJsMessage(java.lang.String, + * java.lang.String) + */ + public static String getJsMessage(String messageclass, String viewId, + JalviewApp app) + { + Hashtable msgset = app.getJSMessages() + .get(messageclass); + if (msgset != null) + { + String[] msgs = msgset.get(viewId); + if (msgs != null) + { + for (int i = 0; i < msgs.length; i++) + { + if (msgs[i] != null) + { + String m = msgs[i]; + msgs[i] = null; + return m; + } + } + } + } + return ""; + } + + public static boolean isJsMessageSetChanged(String string, String string2, + String[] colcommands, JalviewApp app) + { + int[] l = app.getJSHashes().get(string + "|" + string2); + if (l == null && colcommands != null) + { + return true; + } + for (int i = 0; i < colcommands.length; i++) + { + if (l[i] != colcommands[i].hashCode()) + { + return true; + } + } + return false; + } + + public void tidyUp() + { + stopQueue(); + jvlite = null; + } + } diff --git a/src/jalview/javascript/JalviewLiteJsApi.java b/src/jalview/javascript/JalviewLiteJsApi.java index b5811aa..6cb8e07 100644 --- a/src/jalview/javascript/JalviewLiteJsApi.java +++ b/src/jalview/javascript/JalviewLiteJsApi.java @@ -20,13 +20,13 @@ */ package jalview.javascript; -import jalview.appletgui.AlignFrame; +import jalview.api.AlignFrameI; /** * The following public methods may be called * externally, eg via javascript in an HTML page. * - *
TODO: introduce abstract interface for jalview.appletgui.AlignFrame
+ *
TODO: introduce abstract interface for jalview.appletgui.AlignFrameI
* * Most function arguments are strings, which contain serialised versions of lists. * Lists of things are separated by a separator character - either the default or a user supplied one. @@ -56,12 +56,12 @@ public interface JalviewLiteJsApi /** * @param alf - * alignframe containing selection + * AlignFrameI containing selection * @return String list of selected sequence IDs, each terminated by current * default separator sequence * */ - public abstract String getSelectedSequencesFrom(AlignFrame alf); + public abstract String getSelectedSequencesFrom(AlignFrameI alf); /** * get list of selected sequence IDs separated by given separator @@ -73,7 +73,7 @@ public interface JalviewLiteJsApi * @return String list of selected sequence IDs, each terminated by the given * separator */ - public abstract String getSelectedSequencesFrom(AlignFrame alf, + public abstract String getSelectedSequencesFrom(AlignFrameI alf, String sep); /** @@ -99,7 +99,7 @@ public interface JalviewLiteJsApi * false, blank or something else - indicate if position is an * alignment column or unaligned sequence position */ - public abstract void highlightIn(AlignFrame alf, String sequenceId, + public abstract void highlightIn(AlignFrameI alf, String sequenceId, String position, String alignedPosition); /** @@ -133,7 +133,7 @@ public interface JalviewLiteJsApi * @param sep * separator between toselect fields */ - public abstract void selectIn(AlignFrame alf, String sequenceIds, + public abstract void selectIn(AlignFrameI alf, String sequenceIds, String columns); /** @@ -145,11 +145,11 @@ public interface JalviewLiteJsApi * @param sep * separator between toselect fields */ - public abstract void selectIn(AlignFrame alf, String sequenceIds, + public abstract void selectIn(AlignFrameI alf, String sequenceIds, String columns, String sep); /** - * get sequences selected in current alignFrame and return their alignment in + * get sequences selected in current AlignFrameI and return their alignment in * format 'format' either with or without suffix * * @param alf @@ -177,7 +177,8 @@ public interface JalviewLiteJsApi * @return selected sequences as flat file or empty string if there was no * current selection */ - public abstract String getSelectedSequencesAsAlignmentFrom(AlignFrame alf, + public abstract String getSelectedSequencesAsAlignmentFrom( + AlignFrameI alf, String format, String suffix); /** @@ -195,7 +196,7 @@ public interface JalviewLiteJsApi * @param alf * @return */ - public abstract String getAlignmentOrderFrom(AlignFrame alf); + public abstract String getAlignmentOrderFrom(AlignFrameI alf); /** * get a sep separated list of sequence IDs reflecting the order of the @@ -206,7 +207,7 @@ public interface JalviewLiteJsApi * - separator to use * @return */ - public abstract String getAlignmentOrderFrom(AlignFrame alf, String sep); + public abstract String getAlignmentOrderFrom(AlignFrameI alf, String sep); /** * re-order the current alignment using the given list of sequence IDs @@ -247,7 +248,7 @@ public interface JalviewLiteJsApi * @return 'true' if alignment was actually reordered. empty string if * alignment did not contain sequences. */ - public abstract String orderAlignmentBy(AlignFrame alf, String order, + public abstract String orderAlignmentBy(AlignFrameI alf, String order, String undoName, String sep); /** @@ -266,7 +267,7 @@ public interface JalviewLiteJsApi * @param format * @return */ - public abstract String getAlignmentFrom(AlignFrame alf, String format); + public abstract String getAlignmentFrom(AlignFrameI alf, String format); /** * get alignment as format with jalview start-end sequence suffix appended @@ -286,7 +287,7 @@ public interface JalviewLiteJsApi * @param suffix * @return */ - public abstract String getAlignmentFrom(AlignFrame alf, String format, + public abstract String getAlignmentFrom(AlignFrameI alf, String format, String suffix); /** @@ -302,12 +303,12 @@ public interface JalviewLiteJsApi * @param alf * @param annotation */ - public abstract void loadAnnotationFrom(AlignFrame alf, + public abstract void loadAnnotationFrom(AlignFrameI alf, String annotation); /** * parse the given string as a jalview feature or GFF annotation file and - * optionally enable feature display on the current alignFrame + * optionally enable feature display on the current AlignFrameI * * @param features * - gff or features file @@ -320,7 +321,7 @@ public interface JalviewLiteJsApi /** * parse the given string as a jalview feature or GFF annotation file and - * optionally enable feature display on the given alignFrame. + * optionally enable feature display on the given AlignFrameI. * * @param alf * @param features @@ -330,7 +331,7 @@ public interface JalviewLiteJsApi * be parsed from the string. * @return true if data parsed as features */ - public abstract boolean loadFeaturesFrom(AlignFrame alf, String features, + public abstract boolean loadFeaturesFrom(AlignFrameI alf, String features, boolean autoenabledisplay); /** @@ -348,7 +349,7 @@ public interface JalviewLiteJsApi * @param format * @return */ - public abstract String getFeaturesFrom(AlignFrame alf, String format); + public abstract String getFeaturesFrom(AlignFrameI alf, String format); /** * get current alignment's annotation as an annotation file @@ -363,30 +364,30 @@ public interface JalviewLiteJsApi * @param alf * @return */ - public abstract String getAnnotationFrom(AlignFrame alf); + public abstract String getAnnotationFrom(AlignFrameI alf); /** - * create a new view and return the alignFrame instance + * create a new view and return the AlignFrameI instance * * @return */ - public abstract AlignFrame newView(); + public abstract AlignFrameI newView(); /** - * create a new view named name and return the alignFrame instance + * create a new view named name and return the AlignFrameI instance * * @param name * @return */ - public abstract AlignFrame newView(String name); + public abstract AlignFrameI newView(String name); /** - * create a new view on alf and return the alignFrame instance + * create a new view on alf and return the AlignFrameI instance * * @param alf * @return */ - public abstract AlignFrame newViewFrom(AlignFrame alf); + public abstract AlignFrameI newViewFrom(AlignFrameI alf); /** * create a new view named name on alf @@ -395,7 +396,7 @@ public interface JalviewLiteJsApi * @param name * @return */ - public abstract AlignFrame newViewFrom(AlignFrame alf, String name); + public abstract AlignFrameI newViewFrom(AlignFrameI alf, String name); /** * @@ -405,15 +406,15 @@ public interface JalviewLiteJsApi * window title * @return null or new alignment frame */ - public abstract AlignFrame loadAlignment(String text, String title); + public abstract AlignFrameI loadAlignment(String text, String title); /** * register a javascript function to handle any alignment mouseover events * * @param listener * name of javascript function (called with arguments - * [jalview.appletgui.AlignFrame,String(sequence id),String(column in - * alignment), String(position in sequence)] + * [jalview.appletgui.AlignFrameI,String(sequence id),String(column + * in alignment), String(position in sequence)] */ public abstract void setMouseoverListener(String listener); @@ -421,12 +422,13 @@ public interface JalviewLiteJsApi * register a javascript function to handle mouseover events * * @param af - * (null or specific alignframe for which events are to be listened + * (null or specific AlignFrameI for which events are to be listened * for) * @param listener * name of javascript function */ - public abstract void setMouseoverListener(AlignFrame af, String listener); + public abstract void setMouseoverListener(AlignFrameI af, + String listener); /** * register a javascript function to handle any alignment selection events. @@ -435,14 +437,15 @@ public interface JalviewLiteJsApi * * @param listener * name of javascript function (called with arguments - * [jalview.appletgui.AlignFrame, String(sequence set id), + * [jalview.appletgui.AlignFrameI, String(sequence set id), * String(separator separated list of sequences which were selected), * String(separator separated list of column ranges (i.e. single * number or hyphenated range) that were selected)] */ public abstract void setSelectionListener(String listener); - public abstract void setSelectionListener(AlignFrame af, String listener); + public abstract void setSelectionListener(AlignFrameI af, + String listener); /** * register a javascript function to handle events normally routed to a Jmol @@ -462,14 +465,14 @@ public interface JalviewLiteJsApi /** * remove any callback using the given listener function and associated with - * the given alignFrame (or null for all callbacks) + * the given AlignFrameI (or null for all callbacks) * * @param af * (may be null) * @param listener * (may be null) */ - public abstract void removeJavascriptListener(AlignFrame af, + public abstract void removeJavascriptListener(AlignFrameI af, String listener); /** @@ -484,10 +487,10 @@ public interface JalviewLiteJsApi String pdbfile); /** - * bind a pdb file to a sequence in the given alignFrame. + * bind a pdb file to a sequence in the given AlignFrameI. * * @param alFrame - * - null or specific alignFrame. This specifies the dataset that + * - null or specific AlignFrameI. This specifies the dataset that * will be searched for a seuqence called sequenceId * @param sequenceId * - sequenceId within the dataset. @@ -499,7 +502,7 @@ public interface JalviewLiteJsApi * structure for indicating when PDB parsing or sequenceId location * fails. */ - public abstract boolean addPdbFile(AlignFrame alFrame, String sequenceId, + public abstract boolean addPdbFile(AlignFrameI alFrame, String sequenceId, String pdbEntryString, String pdbFile); /** @@ -510,7 +513,7 @@ public interface JalviewLiteJsApi * @param topRow * @param leftHandColumn */ - public abstract void scrollViewToIn(AlignFrame alf, String topRow, + public abstract void scrollViewToIn(AlignFrameI alf, String topRow, String leftHandColumn); /** @@ -519,7 +522,7 @@ public interface JalviewLiteJsApi * @param alf * @param topRow */ - public abstract void scrollViewToRowIn(AlignFrame alf, String topRow); + public abstract void scrollViewToRowIn(AlignFrameI alf, String topRow); /** * adjust horizontal scroll to make the given column the left one in the given @@ -528,28 +531,28 @@ public interface JalviewLiteJsApi * @param alf * @param leftHandColumn */ - public abstract void scrollViewToColumnIn(AlignFrame alf, + public abstract void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn); /** * * @return - * @see jalview.appletgui.AlignFrame#getFeatureGroups() + * @see jalview.appletgui.AlignFrameI#getFeatureGroups() */ public abstract String getFeatureGroups(); /** * @param alf - * alignframe to get feature groups on + * AlignFrameI to get feature groups on * @return - * @see jalview.appletgui.AlignFrame#getFeatureGroups() + * @see jalview.appletgui.AlignFrameI#getFeatureGroups() */ - public abstract String getFeatureGroupsOn(AlignFrame alf); + public abstract String getFeatureGroupsOn(AlignFrameI alf); /** * @param visible * @return - * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean) + * @see jalview.appletgui.AlignFrameI#getFeatureGroupsOfState(boolean) */ public abstract String getFeatureGroupsOfState(boolean visible); @@ -558,9 +561,9 @@ public interface JalviewLiteJsApi * align frame to get groups of state visible * @param visible * @return - * @see jalview.appletgui.AlignFrame#getFeatureGroupsOfState(boolean) + * @see jalview.appletgui.AlignFrameI#getFeatureGroupsOfState(boolean) */ - public abstract String getFeatureGroupsOfStateOn(AlignFrame alf, + public abstract String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible); /** @@ -568,10 +571,11 @@ public interface JalviewLiteJsApi * tab separated list of group names * @param state * true or false - * @see jalview.appletgui.AlignFrame#setFeatureGroupState(java.lang.String[], + * @see jalview.appletgui.AlignFrameI#setFeatureGroupState(java.lang.String[], * boolean) */ - public abstract void setFeatureGroupStateOn(AlignFrame alf, String groups, + public abstract void setFeatureGroupStateOn(AlignFrameI alf, + String groups, boolean state); public abstract void setFeatureGroupState(String groups, boolean state); diff --git a/src/jalview/javascript/JsSelectionSender.java b/src/jalview/javascript/JsSelectionSender.java index c2a963e..56efe70 100644 --- a/src/jalview/javascript/JsSelectionSender.java +++ b/src/jalview/javascript/JsSelectionSender.java @@ -20,8 +20,8 @@ */ package jalview.javascript; +import jalview.api.JalviewApp; import jalview.appletgui.AlignFrame; -import jalview.bin.JalviewLite; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceGroup; @@ -35,10 +35,10 @@ public class JsSelectionSender extends JSFunctionExec String _listener; - public JsSelectionSender(JalviewLite jvlite, AlignFrame af, - String listener) + public JsSelectionSender(JalviewApp jvlite, AlignFrame af, + String listener, boolean debug) { - super(jvlite); + super(jvlite, debug); _af = af; _listener = listener; } @@ -47,70 +47,13 @@ public class JsSelectionSender extends JSFunctionExec public void selection(SequenceGroup seqsel, ColumnSelection colsel, HiddenColumns hidden, SelectionSource source) { - // System.err.println("Testing selection event relay to - // jsfunction:"+_listener); + Object[] info = jvlite.getSelectionForListener(seqsel, colsel, hidden, source, _af); try { - String setid = ""; - AlignFrame src = _af; - if (source != null) - { - if (source instanceof jalview.appletgui.AlignViewport - && ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame.viewport == source) - { - // should be valid if it just generated an event! - src = ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame; - } - } - String[] seqs = new String[] {}; - String[] cols = new String[] {}; - int strt = 0, end = (src == null) ? -1 - : src.alignPanel.av.getAlignment().getWidth(); - if (seqsel != null && seqsel.getSize() > 0) - { - seqs = new String[seqsel.getSize()]; - for (int i = 0; i < seqs.length; i++) - { - seqs[i] = seqsel.getSequenceAt(i).getName(); - } - if (strt < seqsel.getStartRes()) - { - strt = seqsel.getStartRes(); - } - if (end == -1 || end > seqsel.getEndRes()) - { - end = seqsel.getEndRes(); - } - } - if (colsel != null && !colsel.isEmpty()) - { - if (end == -1) - { - end = colsel.getMax() + 1; - } - cols = new String[colsel.getSelected().size()]; - for (int i = 0; i < cols.length; i++) - { - cols[i] = "" + (1 + colsel.getSelected().get(i).intValue()); - } - } - else - { - if (seqsel != null && seqsel.getSize() > 0) - { - // send a valid range, otherwise we send the empty selection - cols = new String[2]; - cols[0] = "" + (1 + strt) + "-" + (1 + end); - } - ; - - } System.err.println("Relaying selection to jsfunction:" + _listener); - executeJavascriptFunction(_listener, - new Object[] - { src, setid, jvlite.arrayToSeparatorList(seqs), - jvlite.arrayToSeparatorList(cols) }); + executeJavascriptFunction(_listener, info); + } catch (Exception ex) { System.err.println( @@ -125,6 +68,7 @@ public class JsSelectionSender extends JSFunctionExec } } + } @Override diff --git a/src/jalview/javascript/MouseOverListener.java b/src/jalview/javascript/MouseOverListener.java index 6a4d0f8..7c74965 100644 --- a/src/jalview/javascript/MouseOverListener.java +++ b/src/jalview/javascript/MouseOverListener.java @@ -20,8 +20,8 @@ */ package jalview.javascript; +import jalview.api.JalviewApp; import jalview.appletgui.AlignFrame; -import jalview.bin.JalviewLite; import jalview.datamodel.SequenceI; import jalview.structure.VamsasListener; import jalview.structure.VamsasSource; @@ -48,25 +48,12 @@ public class MouseOverListener extends JSFunctionExec // + seq + " at " + index); last = seq; i = index; - AlignFrame src = null; + Object alignFrame = jvlite.getFrameForSource(source); try { - if (source != null) - { - if (source instanceof jalview.appletgui.AlignViewport - && ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame.viewport == source) - { - // should be valid if it just generated an event! - src = ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame; - - } - // TODO: ensure that if '_af' is specified along with a handler - // function, then only events from that alignFrame are sent to that - // function - } executeJavascriptFunction(_listener, new Object[] - { src, seq.getDisplayId(false), "" + (1 + i), + { alignFrame, seq.getDisplayId(false), "" + (1 + i), "" + seq.findPosition(i) }); } catch (Exception ex) { @@ -84,10 +71,10 @@ public class MouseOverListener extends JSFunctionExec } } - public MouseOverListener(JalviewLite applet, AlignFrame af, - String listener) + public MouseOverListener(JalviewApp applet, AlignFrame af, + String listener, boolean debug) { - super(applet); + super(applet, debug); _af = af; _listener = listener; } diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java index 6071933..28e2ced 100644 --- a/src/jalview/javascript/MouseOverStructureListener.java +++ b/src/jalview/javascript/MouseOverStructureListener.java @@ -20,11 +20,11 @@ */ package jalview.javascript; +import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; -import jalview.api.FeatureRenderer; +import jalview.api.JalviewApp; import jalview.api.SequenceRenderer; import jalview.appletgui.AlignFrame; -import jalview.bin.JalviewLite; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JmolCommands; import jalview.structure.AtomSpec; @@ -76,12 +76,12 @@ public class MouseOverStructureListener extends JSFunctionExec String _listenerfn; - String[] modelSet; + public String[] modelSet; - public MouseOverStructureListener(JalviewLite jalviewLite, - String listener, String[] modelList) + public MouseOverStructureListener(JalviewApp app, String listener, + String[] modelList, boolean debug) { - super(jalviewLite); + super(app, debug); _listenerfn = listener; modelSet = modelList; if (modelSet != null) @@ -165,21 +165,22 @@ public class MouseOverStructureListener extends JSFunctionExec } @Override - public synchronized void updateColours(Object srce) + public synchronized void updateColours(Object source) { - final Object source = srce; StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(jvlite); + .getStructureSelectionManager( + jvlite.getStructureSelectionManagerProvider()); - if (JalviewLite.debug) + if (debug) { System.err.println( this.getClass().getName() + " modelSet[0]: " + modelSet[0]); ssm.reportMapping(); } - if (source instanceof jalview.api.AlignmentViewPanel) + if (source instanceof AlignmentViewPanel) { + AlignmentViewPanel panel = (AlignmentViewPanel) source; SequenceI[][] sequence = new SequenceI[modelSet.length][]; for (int m = 0; m < modelSet.length; m++) { @@ -203,25 +204,20 @@ public class MouseOverStructureListener extends JSFunctionExec // } } - SequenceRenderer sr = ((jalview.appletgui.AlignmentPanel) source) - .getSequenceRenderer(); - FeatureRenderer fr = ((jalview.appletgui.AlignmentPanel) source).av - .isShowSequenceFeatures() - ? new jalview.appletgui.FeatureRenderer( - ((jalview.appletgui.AlignmentPanel) source).av) - : null; + SequenceRenderer sr = panel.getSequenceRenderer(); + AlignViewportI vp = panel.getAlignViewport(); + jalview.renderer.seqfeatures.FeatureRenderer fr = vp + .isShowSequenceFeatures() ? jvlite.getNewFeatureRenderer(vp) + : null; if (fr != null) { - ((jalview.appletgui.FeatureRenderer) fr).transferSettings( - ((jalview.appletgui.AlignmentPanel) source) - .getFeatureRenderer()); + fr.transferSettings(panel.getFeatureRenderer()); } - ; // Form a colour command from the given alignment panel for each distinct // structure - ArrayList ccomands = new ArrayList(); - ArrayList pdbfn = new ArrayList(); + ArrayList ccomands = new ArrayList<>(); + ArrayList pdbfn = new ArrayList<>(); StructureMappingcommandSet[] colcommands = JmolCommands .getColourBySequenceCommand(ssm, modelSet, sequence, sr, (AlignmentViewPanel) source); @@ -237,7 +233,6 @@ public class MouseOverStructureListener extends JSFunctionExec pdbfn.add(ccset.mapping); } - String mclass, mhandle; String ccomandset[] = new String[sz]; sz = 0; for (String[] ccset : ccomands) @@ -245,28 +240,16 @@ public class MouseOverStructureListener extends JSFunctionExec System.arraycopy(ccset, 0, ccomandset, sz, ccset.length); sz += ccset.length; } - if (jvlite.isJsMessageSetChanged(mclass = "colourstruct", - mhandle = ((jalview.appletgui.AlignmentPanel) source).av - .getViewId(), - ccomandset)) + String mclass = "colourstruct"; + String mhandle = vp.getViewId(); + if (isJsMessageSetChanged(mclass, mhandle, ccomandset, jvlite)) { - jvlite.setJsMessageSet(mclass, mhandle, ccomandset); + setJsMessageSet(mclass, mhandle, ccomandset, jvlite); // and notify javascript handler - String st[] = new String[] { "colourstruct", - "" + ((jalview.appletgui.AlignmentPanel) source).av.getViewId(), + String st[] = new String[] { mclass, mhandle, "" + ccomandset.length, jvlite.arrayToSeparatorList( pdbfn.toArray(new String[pdbfn.size()])) }; - try - { - executeJavascriptFunction(true, _listenerfn, st); - } catch (Exception ex) - { - System.err.println("Couldn't execute callback with " + _listenerfn - + " using args { " + st[0] + ", " + st[1] + ", " + st[2] - + "," + st[3] + "}"); // + ","+st[4]+"\n"); - ex.printStackTrace(); - - } + executeJavascriptFunction(true, st); } /* * new Thread(new Runnable() { public void run() { // and send to @@ -283,6 +266,7 @@ public class MouseOverStructureListener extends JSFunctionExec */ } + jvlite.updateColoursFromMouseOver(source, this); } @Override @@ -312,4 +296,19 @@ public class MouseOverStructureListener extends JSFunctionExec return true; } + public void executeJavascriptFunction(boolean b, String[] st) + { + try + { + executeJavascriptFunction(true, _listenerfn, st); + } catch (Exception ex) + { + System.err.println("Couldn't execute callback with " + _listenerfn + + " using args { " + st[0] + ", " + st[1] + ", " + st[2] + "," + + st[3] + "}"); // + ","+st[4]+"\n"); + ex.printStackTrace(); + + } + } + }