X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fjavascript%2FMouseOverStructureListener.java;h=7f34a08591af803ecb94bc9abb89f50a0a8bd914;hb=00eeb650b3a72206b1531f9eea145ea2ce24a1fc;hp=88fba0284f1ecfd91c8d575bd27f80ad7c41142c;hpb=6f2610ec4d7a79dde17f9b3d02225c62aa52cfd8;p=jalview.git diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java index 88fba02..7f34a08 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; @@ -96,15 +94,16 @@ public class MouseOverStructureListener extends JSFunctionExec implements } /** - * Returns the first of file, file prefixed by document base, file prefixed by - * codebase which can be resolved to a valid URL. If none can, returns the - * input parameter value. + * 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. * * @param file */ public String resolveModelFile(String file) { - if (isValidUrl(file)) + // TODO reuse JalviewLite.LoadingThread.addProtocol instead + if (HttpUtils.isValidUrl(file)) { return file; } @@ -112,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; } @@ -126,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() { @@ -244,11 +206,11 @@ public class MouseOverStructureListener extends JSFunctionExec implements SequenceRenderer sr = ((jalview.appletgui.AlignmentPanel) source) .getSequenceRenderer(); FeatureRenderer fr = ((jalview.appletgui.AlignmentPanel) source).av - .isShowSequenceFeatures() ? new jalview.appletgui.FeatureRenderer( + .isShowSequenceFeatures() ? new jalview.appletgui.FeatureRendererAndEditor( ((jalview.appletgui.AlignmentPanel) source).av) : null; if (fr != null) { - ((jalview.appletgui.FeatureRenderer) fr) + ((jalview.appletgui.FeatureRendererAndEditor) fr) .transferSettings(((jalview.appletgui.AlignmentPanel) source) .getFeatureRenderer()); }