X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fjavascript%2FMouseOverStructureListener.java;h=6d366d067d319d931abfdff979911806d9931f0f;hb=799c26111d6936a2e70cb5f1fd7d7312311e6db9;hp=7f833e7fa4e0887b6350d952ad990c6c92c72ac2;hpb=088cd0cc2ea8c0ca326da400c2290d0fa759cdbb;p=jalview.git diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java index 7f833e7..6d366d0 100644 --- a/src/jalview/javascript/MouseOverStructureListener.java +++ b/src/jalview/javascript/MouseOverStructureListener.java @@ -32,10 +32,8 @@ import jalview.structure.StructureListener; import jalview.structure.StructureMapping; import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; +import jalview.util.HttpUtils; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -90,14 +88,13 @@ public class MouseOverStructureListener extends JSFunctionExec implements { for (int i = 0; i < modelSet.length; i++) { - // ? leave file names 'as is' to match StructureMapping.pdbfile - // modelSet[i] = resolveModelFile(modelSet[i]); + modelSet[i] = resolveModelFile(modelSet[i]); } } } /** - * Returns the first out of file, file prefixed by document base, or file + * Returns the first out of: file, file prefixed by document base, or file * prefixed by codebase which can be resolved to a valid URL. If none can, * returns the input parameter value. * @@ -105,7 +102,8 @@ public class MouseOverStructureListener extends JSFunctionExec implements */ public String resolveModelFile(String file) { - if (isValidUrl(file)) + // TODO reuse JalviewLite.LoadingThread.addProtocol instead + if (HttpUtils.isValidUrl(file)) { return file; } @@ -113,13 +111,13 @@ public class MouseOverStructureListener extends JSFunctionExec implements String db = jvlite.getDocumentBase().toString(); db = db.substring(0, db.lastIndexOf("/")); String docBaseFile = db + "/" + file; - if (isValidUrl(docBaseFile)) + if (HttpUtils.isValidUrl(docBaseFile)) { return docBaseFile; } String cb = jvlite.getCodeBase() + file; - if (isValidUrl(cb)) + if (HttpUtils.isValidUrl(cb)) { return cb; } @@ -127,43 +125,6 @@ public class MouseOverStructureListener extends JSFunctionExec implements return file; } - /** - * Returns true if it is possible to open an input stream at the given URL, - * else false. The input stream is closed. - * - * @param file - * @return - */ - private boolean isValidUrl(String file) - { - InputStream is = null; - try - { - is = new URL(file).openStream(); - if (is != null) - { - return true; - } - } catch (IOException x) - { - // MalformedURLException, FileNotFoundException - return false; - } finally - { - if (is != null) - { - try - { - is.close(); - } catch (IOException e) - { - // ignore - } - } - } - return false; - } - @Override public String[] getPdbFile() { @@ -261,7 +222,7 @@ public class MouseOverStructureListener extends JSFunctionExec implements ArrayList pdbfn = new ArrayList(); StructureMappingcommandSet[] colcommands = JmolCommands .getColourBySequenceCommand(ssm, modelSet, sequence, sr, fr, - ((AlignmentViewPanel) source).getAlignment()); + ((AlignmentViewPanel) source).getAlignViewport()); if (colcommands == null) { return; @@ -337,7 +298,8 @@ public class MouseOverStructureListener extends JSFunctionExec implements return _listenerfn; } - public void finalise() + @Override + public void finalize() throws Throwable { jvlite = null; super.finalize();