Guest User

Untitled

a guest
May 2nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. package nl.at_automation.corporateidentity.groupedcomponents;
  2.  
  3. import javafx.application.Platform;
  4. import javafx.embed.swing.JFXPanel;
  5. import javafx.scene.Scene;
  6. import javafx.scene.web.WebEngine;
  7. import javafx.scene.web.WebView;
  8. import nl.at_automation.corporateidentity.LicenseManager;
  9.  
  10. /**
  11. * <h1>AtWebBrowser</h1> This component includes a web browser
  12. *
  13. * @author Derek Meuwissen
  14. */
  15. public class AtWebBrowser extends AtBasicPanel {
  16.  
  17. protected String url = "http://at-automation.nl";
  18. private String html = "";
  19.  
  20. private Boolean useHtml = false;
  21.  
  22. protected WebView webView;
  23. protected WebEngine engine;
  24.  
  25. protected JFXPanel jfxPanel;
  26.  
  27. public AtWebBrowser() {
  28.  
  29. super();
  30. jfxPanel = new JFXPanel();
  31. Platform.setImplicitExit(false);
  32. Platform.runLater(new Runnable() {
  33.  
  34. @Override
  35. public void run() {
  36. createJFXContent();
  37. }
  38. });
  39.  
  40. }
  41.  
  42. protected void createJFXContent() {
  43.  
  44. webView = new WebView();
  45.  
  46. engine = webView.getEngine();
  47.  
  48. Scene scene = new Scene(webView);
  49. jfxPanel.setScene(scene);
  50.  
  51. load();
  52.  
  53. }
  54.  
  55. @Override
  56. protected void addComponents() {
  57. add(jfxPanel);
  58. }
  59.  
  60. @Override
  61. public void rerender() {
  62. super.rerender();
  63.  
  64. jfxPanel.setSize(getSize());
  65. jfxPanel.setLocation(0, 0);
  66.  
  67. }
  68.  
  69. protected void load() {
  70. if (this.useHtml) {
  71. loadHtml();
  72. } else {
  73. loadUrl();
  74. }
  75. }
  76.  
  77. private void loadUrl() {
  78. Platform.runLater(new Runnable() {
  79. @Override
  80. public void run() {
  81. if(!LicenseManager.getInstance().isLicenseExpired())
  82. {
  83. engine.load(url);
  84. }
  85. else
  86. {
  87. engine.load("https://at-automation.nl");
  88. }
  89.  
  90. }
  91. });
  92.  
  93. }
  94.  
  95. private void loadHtml() {
  96. Platform.runLater(new Runnable() {
  97. @Override
  98. public void run() {
  99. if(!LicenseManager.getInstance().isLicenseExpired())
  100. {
  101. engine.loadContent(html);
  102. }
  103. else
  104. {
  105. engine.loadContent("<html>trial expired!</html>");
  106. }
  107.  
  108. }
  109. });
  110.  
  111. }
  112.  
  113. public void reload()
  114. {
  115. Platform.runLater(new Runnable() {
  116. @Override
  117. public void run() {
  118. engine.reload();
  119. }
  120. });
  121. }
  122.  
  123. public String getUrl() {
  124. return this.url;
  125. }
  126.  
  127. public void setUrl(String url) {
  128.  
  129. this.url = url.trim();
  130. if (!this.url.matches("^\\w+://.*")) {
  131. this.url = "http://" + this.url;
  132. }
  133. load();
  134. }
  135.  
  136. public String getHtml() {
  137. return this.html;
  138. }
  139.  
  140. public void setHtml(String html) {
  141. this.html = html;
  142. load();
  143. }
  144.  
  145. public Boolean isUseHtml() {
  146. return this.useHtml;
  147. }
  148.  
  149. public void setUseHtml(Boolean useHtml) {
  150. this.useHtml = useHtml;
  151.  
  152. load();
  153. }
  154.  
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment