/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package us.guihouse.projector.projection;

import java.awt.Dimension;
import java.awt.Graphics2D;
import javafx.embed.swing.JFXPanel;
import javafx.embed.swing.SwingNode;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.web.WebView;

/**
 *
 * @author guilherme
 */
public class ProjectionWebView implements Projectable {

    private final CanvasDelegate delegate;

    private SwingNode node;
    private Pane container;
    private WebView webView;
    private JFXPanel panel;
    private Dimension maxSize;

    public ProjectionWebView(CanvasDelegate delegate) {
        this.delegate = delegate;
    }

    @Override
    public void paintComponent(Graphics2D g) {
        panel.paint(g);
    }

    @Override
    public CanvasDelegate getCanvasDelegate() {
        return delegate;
    }

    @Override
    public void rebuildLayout() {
        int width = delegate.getWidth();
        int height = delegate.getHeight();

        panel.setBounds(0, 0, width, height);
        panel.setPreferredSize(new Dimension(width, height));
    }

    @Override
    public void init() {
        if (webView == null) {
            this.webView = new WebView();
            this.panel = new JFXPanel();
            panel.setScene(new Scene(webView));
            this.node = new SwingNode();
            node.setContent(panel);
            this.container = new Pane();
            container.getChildren().add(node);
        }

        rebuildLayout();
    }

    @Override
    public void finish() {

    }

    public Dimension getMaxSize() {
        return maxSize;
    }

    public void setMaxSize(Dimension maxSize) {
        this.maxSize = maxSize;
    }

    public WebView getWebView() {
        return webView;
    }

    public void setWebView(WebView webView) {
        this.webView = webView;
    }

    public Node getNode() {
        return container;
    }
}

@@ -241,45 +241,62 @@
 awt.
-Dimension;%0Aimport java.awt.Graphics2D
+*;%0A%0Aimport com.sun.javafx.embed.EmbeddedSceneInterface
 ;%0Aim
@@ -486,16 +486,39 @@
 bView;%0A%0A
+import javax.swing.*;%0A%0A
 /**%0A *%0A 
@@ -785,16 +785,41 @@
 maxSize;
+%0A    private Scene scene;
 %0A%0A    pu
@@ -1240,30 +1240,293 @@
     
-panel.setBounds(0, 0, 
+webView.setPrefWidth(width);%0A        webView.setPrefHeight(height);%0A        webView.setMinWidth(width);%0A        webView.setMinHeight(height);%0A%0A        node.minWidth(width);%0A        node.minHeight(height);%0A        node.resize(width, height);%0A%0A        panel.setMinimumSize(new Dimension(
 widt
@@ -1531,24 +1531,25 @@
 dth, height)
+)
 ;%0A        pa
@@ -1595,24 +1595,327 @@
 h, height));
+%0A%0A        SwingUtilities.invokeLater(() -%3E %7B%0A            Component root = panel;%0A%0A            while (root != null) %7B%0A                root.setMinimumSize(new Dimension(width, height));%0A                root.setBounds(0, 0, width, height);%0A                root = root.getParent();%0A            %7D%0A        %7D);
 %0A    %7D%0A%0A    
@@ -1984,37 +1984,32 @@
 ) %7B%0A            
-this.
 webView = new We
@@ -2013,24 +2013,25 @@
  WebView();%0A
+%0A
             
@@ -2034,85 +2034,609 @@
     
-this.panel = new JFXPanel();%0A            panel.setScene(new Scene(webView)
+int width = delegate.getWidth();%0A            int height = delegate.getHeight();%0A%0A            scene = new Scene(webView, width, height);%0A%0A            panel = new JFXPanel() %7B%0A                @Override%0A                public void setBounds(int x, int y, int width, int height) %7B%0A                    if (width %3E= delegate.getWidth() %7C%7C height %3E= delegate.getHeight()) %7B%0A                        super.setBounds(x, y, width, height);%0A                    %7D else %7B%0A                        System.out.println(%22bug%22);%0A                    %7D%0A                %7D%0A            %7D;%0A%0A            panel.setScene(scene
 );%0A
+%0A
     
@@ -2670,17 +2670,159 @@
 ngNode()
-;
+ %7B%0A                @Override%0A                public boolean isResizable() %7B%0A                    return false;%0A                %7D%0A            %7D;%0A
 %0A       
@@ -2850,16 +2850,17 @@
 panel);%0A
+%0A
         
@@ -2888,24 +2888,112 @@
 new Pane();%0A
+%0A            container.setMinWidth(width);%0A            container.setMinHeight(height);%0A%0A
             

Fix webview