Java 类org.w3c.dom.html.HTMLAnchorElement 实例源码

项目:aem-ide-tooling-4-intellij    文件:HyperlinkRedirectListener.java   
@Override
public void handleEvent(Event event) {
    HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget();
    String href = anchorElement.getHref();

    boolean done = false;
    try {
        if(Desktop.isDesktopSupported()) {
            openLinkInSystemBrowser(href);
            done = true;
        } else {
            LOGGER.warn("OS does not support desktop operations like browsing. Cannot open link '{}'.", href);
        }
    } catch(URISyntaxException | IOException e) {
        LOGGER.warn("OS does not support desktop operations like browsing. Failed open link '{}'.", href, e);
    }
    if(done) {
        event.preventDefault();
    }
}
项目:marathonv5    文件:HyperlinkRedirectListener.java   
@Override public void handleEvent(Event event) {
    HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget();
    String href = anchorElement.getHref();

    if (Desktop.isDesktopSupported()) {
        openLinkInSystemBrowser(href);
    } else {
        LOGGER.warning("OS does not support desktop operations like browsing. Cannot open link '{" + href + "}'.");
    }

    event.preventDefault();
}
项目:waterrower-workout    文件:HyperlinkRedirectListener.java   
@Override
public void handleEvent(Event event) {
    HTMLAnchorElement anchorElement = (HTMLAnchorElement)event.getCurrentTarget();
    String href = anchorElement.getHref();

    if (isDesktopSupported()) {
        openLinkInSystemBrowser(href);
    } else {
        Log.warn(APPLICATION, "OS does not support desktop operations like browsing. Cannot open link '"+href+"'!");
    }

    event.preventDefault();
}
项目:opencards    文件:MdSlideManager.java   
private static void redirectLinksToBrowser(WebEngine webEngine) {
    webEngine.getLoadWorker().stateProperty().addListener(
            (ov, oldState, newState) -> {
                // adjust link handling
                if (webEngine.getDocument() == null)
                    return;

                NodeList nodeList = webEngine.getDocument().getElementsByTagName("a");
                for (int i = 0; i < nodeList.getLength(); i++) {
                    Node node = nodeList.item(i);
                    EventTarget eventTarget = (EventTarget) node;

                    eventTarget.addEventListener("click", evt -> {
                        EventTarget target = evt.getCurrentTarget();
                        HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
                        String href = anchorElement.getHref();

                        //handle opening URL outside JavaFX WebView
                        try {
                            Desktop.getDesktop().browse(new URI(href));
                        } catch (IOException | URISyntaxException e) {
                            e.printStackTrace();
                        }
                        evt.preventDefault();
                    }, false);
                }
            });
}
项目:JobHunter    文件:WebViewOnClickListener.java   
@Override
public void handleEvent(Event evt) {
    final EventTarget target = evt.getCurrentTarget();
    final HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
    final String href = anchorElement.getHref();
    evt.preventDefault();
    JavaFXUtils.openWebpage(href);
}
项目:fxnav-interceptor    文件:AnchorClickEventListener.java   
@Override
public void handleEvent(Event evt) {
    EventTarget target = evt.getCurrentTarget();
    HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
    String url = anchorElement.getHref();

    // If the clicked link is downloadable
    // then we prevent the browser to follow the link
    // and instead we perform the download ourselves
    if (downloader.isDownloadable(url)) {
        downloader.download(url);
        evt.preventDefault();
    }
}
项目:ScriptBox    文件:NavigationController.java   
/**
 * Tests if is passed Element an element which may be followed.
 * 
 * @param element Element to be tested.
 * @return True, if we can follow passed element.
 */
private static boolean isLinkableElement(Element element) {
        if (element instanceof HTMLAnchorElement) {
            return true;
        } else if (element instanceof HTMLAreaElement) {
            return true;
        }

        return false;
}
项目:ScriptBox    文件:NavigationController.java   
/**
 * Returns target attribute from the linkable element.
 * 
 * @param element Linkable element.
 * @return Target attribute.
 */
private static String getTargetFromElement(Element element) {
        String targetAttr = null;
        if (element instanceof HTMLAnchorElement) {
            targetAttr = ((HTMLAnchorElement)element).getTarget();
        } else if (element instanceof HTMLAreaElement) {
            targetAttr = ((HTMLAreaElement)element).getTarget();
        }

        return targetAttr;
}
项目:ScriptBox    文件:NavigationController.java   
/**
 * Returns href attribute from the linkable element.
 * 
 * @param element Linkable element.
 * @return Href attribute.
 */
private static String getHrefFromElement(Element element) {
        String targetAttr = null;
        if (element instanceof HTMLAnchorElement) {
            targetAttr = ((HTMLAnchorElement)element).getHref();
        } else if (element instanceof HTMLAreaElement) {
            targetAttr = ((HTMLAreaElement)element).getHref();
        }

        return targetAttr;
}
项目:jabref    文件:OpenHyperlinksInExternalBrowser.java   
@Override
public void handleEvent(Event event) {
    HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget();
    String href = anchorElement.getHref();

    try {
        JabRefDesktop.openBrowser(href);
    } catch (IOException e) {
        LOGGER.error("Problem opening browser", e);
    }
    event.preventDefault();
}
项目:EscapistsEditor    文件:MapRendererComponent.java   
private static void initFX(final JFXPanel fxPanel) {
    final WebView webView = new WebView();
    fxPanel.setScene(new Scene(webView));

    // Obtain the webEngine to navigate
    final WebEngine webEngine = webView.getEngine();
    webEngine.loadContent("Escapists Map Editor\n" +
            "Written by jselby\nhttp://redd.it/2wacp2\n\n" +
            "You don't have a map loaded currently - \nGo to File in the top left, and press a button there!\n" +
            "Loading...");
    webEngine.load("http://escapists.jselby.net/welcome/");

    webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
        @Override
        public void changed(ObservableValue<? extends Worker.State> observable,
                            Worker.State oldValue, Worker.State newValue) {
            if (newValue == Worker.State.SUCCEEDED) {
                final Document document = webEngine.getDocument();
                NodeList nodeList = document.getElementsByTagName("a");
                for (int i = 0; i < nodeList.getLength(); i++) {
                    Node node = nodeList.item(i);
                    EventTarget eventTarget = (EventTarget) node;
                    eventTarget.addEventListener("click", new org.w3c.dom.events.EventListener() {
                        @Override
                        public void handleEvent(Event evt) {
                            EventTarget target = evt.getCurrentTarget();
                            HTMLAnchorElement anchorElement = (HTMLAnchorElement) target;
                            String href = anchorElement.getHref();
                            Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
                            if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
                                try {
                                    desktop.browse(new URL(href).toURI());
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            evt.preventDefault();
                        }
                    }, false);
                }
            }
        }
    });
}