Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.at_automation.corporateidentity.groupedcomponents;
- import javafx.application.Platform;
- import javafx.embed.swing.JFXPanel;
- import javafx.scene.Scene;
- import javafx.scene.web.WebEngine;
- import javafx.scene.web.WebView;
- import nl.at_automation.corporateidentity.LicenseManager;
- /**
- * <h1>AtWebBrowser</h1> This component includes a web browser
- *
- * @author Derek Meuwissen
- */
- public class AtWebBrowser extends AtBasicPanel {
- protected String url = "http://at-automation.nl";
- private String html = "";
- private Boolean useHtml = false;
- protected WebView webView;
- protected WebEngine engine;
- protected JFXPanel jfxPanel;
- public AtWebBrowser() {
- super();
- jfxPanel = new JFXPanel();
- Platform.setImplicitExit(false);
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- createJFXContent();
- }
- });
- }
- protected void createJFXContent() {
- webView = new WebView();
- engine = webView.getEngine();
- Scene scene = new Scene(webView);
- jfxPanel.setScene(scene);
- load();
- }
- @Override
- protected void addComponents() {
- add(jfxPanel);
- }
- @Override
- public void rerender() {
- super.rerender();
- jfxPanel.setSize(getSize());
- jfxPanel.setLocation(0, 0);
- }
- protected void load() {
- if (this.useHtml) {
- loadHtml();
- } else {
- loadUrl();
- }
- }
- private void loadUrl() {
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- if(!LicenseManager.getInstance().isLicenseExpired())
- {
- engine.load(url);
- }
- else
- {
- engine.load("https://at-automation.nl");
- }
- }
- });
- }
- private void loadHtml() {
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- if(!LicenseManager.getInstance().isLicenseExpired())
- {
- engine.loadContent(html);
- }
- else
- {
- engine.loadContent("<html>trial expired!</html>");
- }
- }
- });
- }
- public void reload()
- {
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- engine.reload();
- }
- });
- }
- public String getUrl() {
- return this.url;
- }
- public void setUrl(String url) {
- this.url = url.trim();
- if (!this.url.matches("^\\w+://.*")) {
- this.url = "http://" + this.url;
- }
- load();
- }
- public String getHtml() {
- return this.html;
- }
- public void setHtml(String html) {
- this.html = html;
- load();
- }
- public Boolean isUseHtml() {
- return this.useHtml;
- }
- public void setUseHtml(Boolean useHtml) {
- this.useHtml = useHtml;
- load();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment