import java.awt.BorderLayout;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import javafx.embed.swing.SwingFXUtils;
import javafx.embed.swing.SwingNode;
import javafx.fxml.FXML;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;

public class TabController {

    @FXML
    private TabPane tabPane;

    @FXML
    private Tab visibleTab, invisibleTab;

    @FXML
    private SwingNode visibleNode, invisibleNode;

    @FXML
    private Button export;

    @FXML
    private BorderPane invisibleBP, visibleBP;

    private JPanel visiblePanel, invisiblePanel;

    public void initialize()
    {
        this.visiblePanel = new JPanel(new BorderLayout());
        this.invisiblePanel = new JPanel(new BorderLayout());       

        URL url = null;
        Image image = null;
        try{
            url = new URL("http://devstickers.com/assets/img/pro/d1i3.png");
            image = ImageIO.read(url);
        } catch (IOException e){ e.printStackTrace(); }

        ImageIcon img1 = new ImageIcon(image);
        this.visiblePanel.add(new JLabel(img1), BorderLayout.CENTER);       
        this.visibleNode.setContent(this.visiblePanel); 

        ImageIcon img2 = new ImageIcon(image);
        this.invisiblePanel.add(new JLabel(img2), BorderLayout.CENTER);         
        this.invisibleNode.setContent(this.invisiblePanel);

    }

    @FXML
    private void handleExport()
    {
        File visibleFile = new File("visible_file.png");
        File invisibleFile = new File("invisible_file.png");
        System.out.println("Export these pictures");
        try {
            ImageIO.write(SwingFXUtils.fromFXImage(this.invisibleBP.snapshot(new SnapshotParameters(), null), null), "png", invisibleFile);
            ImageIO.write(SwingFXUtils.fromFXImage(this.visibleBP.snapshot(new SnapshotParameters(), null), null), "png", visibleFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}