package edu.kit.iks.CryptographicsLib;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.text.html.HTMLEditorKit;

/**
 * View of the information page
 * 
 * @author Christian Dreher
 */
public class InformationView extends JPanel {
	
	/**
	 * Serial Version UID
	 */
	private static final long serialVersionUID = -8593552609491347799L;

	/**
	 * QR code for further information
	 */
	private Image qrCode;
	
	/**
	 * File path to the local HTML file with further information
	 */
	private String url;
	
	/**
	 * Constructor initializing a new instance of {InformationView}
	 * with given {path} and {qrCode}
	 * 
	 * @param path File path to the local HTML file with further information
	 * @param qrCode QR code for further information
	 */
	public InformationView(String url, Image qrCode) {
		this.qrCode = qrCode;
		this.url = url;
		
		this.setLayout(new GridBagLayout());
		
		// Load the web view.
		this.loadWebView();
		
		// Load the image view.
		GridBagConstraints imageConstraints = new GridBagConstraints();
		imageConstraints.gridx = 0;
		imageConstraints.gridy = 1;
		imageConstraints.weightx = 1.0;
		imageConstraints.weighty = 0.1;
		ImageView view = new ImageView(qrCode);
		this.add(view, imageConstraints);
		
		this.validate();
	}
	
	private void loadWebView() {
	    final JEditorPane editorPane = new JEditorPane();
	    editorPane.setEditable(false);

	    // Use HTML.
	    editorPane.setEditorKitForContentType("text/html", new HTMLEditorKit());
	    try {
	    	editorPane.setPage(this.url);
	    } catch(Exception e) {
	    	Logger.e(e);
	    }
	    JScrollPane scrollPane = new JScrollPane(editorPane); 

	    // Add the scroll pane.
	    GridBagConstraints scrollConstraints = new GridBagConstraints();
	    scrollConstraints.gridx = 0;
	    scrollConstraints.gridy = 0;
	    scrollConstraints.weighty = 0.9;
	    scrollConstraints.weightx = 1.0;
	    scrollConstraints.fill = GridBagConstraints.BOTH;
	    this.add(scrollPane, scrollConstraints);
	}
	
	/**
	 * Gets the file path to the local HTML file with further information
	 * 
	 * @return File path to the local HTML file with further information
	 */
	public String getUrl() {
		return this.url;
	}
	
	/**
	 * Gets the QR code for further information
	 * 
	 * @return QR code for further information
	 */
	public Image getQrCode() {
		return this.qrCode;
	}
}

@@ -139,27 +139,31 @@
 java
+f
 x.
-swing.JEditorPane
+application.Platform
 ;%0Aim
@@ -171,25 +171,34 @@
 ort java
+f
 x.
+embed.
 swing.J
+FX
 Panel;%0Ai
@@ -211,25 +211,47 @@
 java
+f
 x.s
-wing.JScrollPa
+cene.Group;%0Aimport javafx.scene.Sce
 ne;%0A
@@ -265,39 +265,91 @@
 java
+f
 x.s
-wing.text.html.HTMLEditorKit
+cene.web.WebEngine;%0Aimport javafx.scene.web.WebView;%0A%0Aimport javax.swing.JPanel
 ;%0A%0A/
@@ -1523,48 +1523,39 @@
  %7B%0A%09
-    
+%09
 final J
-EditorPane editor
+FXPanel fx
 Pane
+l
  = new J
 Edit
@@ -1554,662 +1554,1093 @@
 ew J
-Editor
+FX
 Pane
+l
 ();%0A%09
-    editorPane.setEditable(false);%0A%0A%09    // Use HTML.%0A%09    editorPane.setEditorKitForContentType(%22text/html%22, new HTMLEditorKit());%0A%09
+%09GridBagConstraints fxConstraints = new GridBagConstraints();%0A        fxConstraints.gridx = 0;%0A        fxConstraints.gridy = 0;%0A        fxConstraints.weightx = 1.0;%0A        fxConstraints.weighty = 0.9;%0A        fxConstraints.fill = GridBagConstraints.BOTH;%0A        this.add(fxPanel, fxConstraints);%0A  
     
-try %7B%0A%09    %09editorPane.setPage(this.url);%0A%09    %7D catch(Exception e
+  %0A        Platform.runLater(new Runnable() %7B // this will run initFX as JavaFX-Thread%0A            @Override%0A            public void run(
 ) %7B%0A
-%09
+  
     
-%09Logger.e(e);%0A%09
+          initFX(fxPanel);%0A        
     %7D%0A
-%09
     
-JScrollPane scrollPane = new JScrollPane(editorPane); %0A%0A%09
+    %7D);%0A    %7D%0A%0A    /* Creates a WebView and fires up google.com */%0A    private void initFX(final JFXPanel fxPanel) %7B%0A
     
+%09
 // 
-Add the scroll pane.%0A%09    GridBagConstraints scrollConstraints = new GridBagConstraints();%0A%09
+TODO properly size and configure%0A        Group group = new Group();%0A        Scene scene = new Scene(group);%0A        fxPanel.setScene(scene);%0A%0A
     
-scrollConstraints.gridx = 0
+    WebView webView = new WebView()
 ;%0A
-%09
     
-scrollConstraints.gridy = 0
+    group.getChildren().add(webView);%0A        webView.setMinSize(800, 600)
 ;%0A
-%09
     
-scrollConstraints.weighty = 0.9;%0A%09    scrollConstraints.weightx = 1.0;%0A%09    scrollConstraints.fill = GridBagConstraints.BOTH
+    webView.setMaxSize(800, 600);%0A%0A        // Obtain the webEngine to navigate.%0A        WebEngine webEngine = webView.getEngine()
 ;%0A
-%09
     
-this.add(scrollPane, scrollConstraints);%0A%09
+    webEngine.load(%22http://www.google.com/%22);%0A    
 %7D%0A%09%0A

Use JavaFX web view.