<commit_before>package edu.kit.iks.CryptographicsLib;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.Timer;

/**
 * View of the information page
 * 
 * @author <NAME>
 */
public class InformationView extends JPanel implements MouseListener {
	
	/**
	 * Possible scroll directions.
	 */
	private enum ScrollDirection {
	    NONE, UP, DOWN 
	};
	
	/**
	 * The delay between scroll events when a scroll button is pressed.
	 */
	private static final int scrollDelay = 50; 
	
	/**
	 * Serial Version UID
	 */
	private static final long serialVersionUID = -8593552609491347799L;

	/**
	 * QR code for further information
	 */
	private Image qrCode;
	
	/**
	 * The HTML used to display the additional information in a web view.
	 */
	private String html;
	
	/**
	 * The content of the QR code.
	 */
	private String qrCodeContent;
	
	/**
	 * The QR code view.
	 */
	private ImageView qrCodeView;
	
	/**
	 * Displays the contents of the QR code. 
	 */
	private JLabel qrCodeLabel;
	
	/**
	 * The scrollable container of the web view.
	 */
	private JScrollPane webViewContainer;
	
	/**
	 * The web view.
	 */
	private JEditorPane webView;
	
	/**
	 * Scrolls the web view up.
	 */
	private JButton scrollUpButton;
	
	/**
	 * Scrolls the web view down.
	 */
	private JButton scrollDownButton;
	
	/**
	 * The current scroll direction.
	 */
	private ScrollDirection scrollDirection = ScrollDirection.NONE;
	
	/**
	 * This timer is used to periodically scroll up or down depending on the
	 * current value of scroll direction. This is used when pressing the up or
	 * down button.
	 */
	private Timer scrollTimer;
	
	/**
	 * Constructor initializing a new instance of {InformationView}
	 * with given {HTML} and {qrCode}
	 * 
	 * @param html The HTML used to display the additional informations
	 * @param qrCode QR code for further information
	 * @param url The content of the QR code
	 */
	public InformationView(String html, Image qrCode, String qrCodeContent) {
		this.qrCode = qrCode;
		this.html = html;
		this.qrCodeContent = qrCodeContent;
		
		// Initialize view.
		this.setLayout(new BorderLayout());
		this.loadWebViewComponents();
		this.loadScrollButtons();
		this.loadQRCodeViewComponents();
		this.validate();
	}
	
	/**
	 * Loads the web view and related components.
	 */
	private void loadWebViewComponents() {
		JPanel layoutContainer = new JPanel(new BorderLayout());
		
		this.loadWebView();
        layoutContainer.add(this.webViewContainer, BorderLayout.CENTER);
        
        this.loadScrollButtons();
        JPanel buttonLayoutContainer = new JPanel(new BorderLayout());
        buttonLayoutContainer.add(this.scrollUpButton, BorderLayout.NORTH);
        buttonLayoutContainer.add(this.scrollDownButton, BorderLayout.SOUTH);
        layoutContainer.add(buttonLayoutContainer, BorderLayout.EAST);
        
        // Valdiate and add.
        layoutContainer.validate();
        this.add(layoutContainer, BorderLayout.CENTER);
    }
	
	private void loadWebView() {
		// Editor pane used as a web view.
		this.webView = new JEditorPane();
		this.webView.setEditable(false);
		this.webView.setContentType("text/html");
		try {
			this.webView.setText(this.getHtml());
		} catch(Exception e) {
			Logger.e(e);
		}
		this.webView.setCaretPosition(0); // scrolls to the top
		
		// Scroll pane that contains the editor pane.
		this.webViewContainer = new JScrollPane(this.webView);
		this.webViewContainer.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		this.webViewContainer.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
		this.webViewContainer.validate();
	}
	
	/**
	 * Loads the scroll up and scroll down buttons for scrolling the web view.
	 * This is necessary because the scroll bar is very clumsy to control on
	 * a touch screen device.
	 */
	private void loadScrollButtons() {
		// Scroll up button.
		this.scrollUpButton = new JButton("Up");
		this.scrollUpButton.setName("up");
		this.scrollUpButton.addMouseListener(this);
		
		// Scroll down button.
		this.scrollDownButton = new JButton("Down");
		this.scrollDownButton.setName("down");
		this.scrollDownButton.addMouseListener(this);
	}
	
	/**
	 * Loads the QR code view and related components.
	 */
	private void loadQRCodeViewComponents() {<commit_msg>Use UTF-8 characters.<commit_after>package edu.kit.iks.CryptographicsLib;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.Timer;

/**
 * View of the information page
 * 
 * @author <NAME>
 */
public class InformationView extends JPanel implements MouseListener {
	
	/**
	 * Possible scroll directions.
	 */
	private enum ScrollDirection {
	    NONE, UP, DOWN 
	};
	
	/**
	 * The delay between scroll events when a scroll button is pressed.
	 */
	private static final int scrollDelay = 50; 
	
	/**
	 * Serial Version UID
	 */
	private static final long serialVersionUID = -8593552609491347799L;

	/**
	 * QR code for further information
	 */
	private Image qrCode;
	
	/**
	 * The HTML used to display the additional information in a web view.
	 */
	private String html;
	
	/**
	 * The content of the QR code.
	 */
	private String qrCodeContent;
	
	/**
	 * The QR code view.
	 */
	private ImageView qrCodeView;
	
	/**
	 * Displays the contents of the QR code. 
	 */
	private JLabel qrCodeLabel;
	
	/**
	 * The scrollable container of the web view.
	 */
	private JScrollPane webViewContainer;
	
	/**
	 * The web view.
	 */
	private JEditorPane webView;
	
	/**
	 * Scrolls the web view up.
	 */
	private JButton scrollUpButton;
	
	/**
	 * Scrolls the web view down.
	 */
	private JButton scrollDownButton;
	
	/**
	 * The current scroll direction.
	 */
	private ScrollDirection scrollDirection = ScrollDirection.NONE;
	
	/**
	 * This timer is used to periodically scroll up or down depending on the
	 * current value of scroll direction. This is used when pressing the up or
	 * down button.
	 */
	private Timer scrollTimer;
	
	/**
	 * Constructor initializing a new instance of {InformationView}
	 * with given {HTML} and {qrCode}
	 * 
	 * @param html The HTML used to display the additional informations
	 * @param qrCode QR code for further information
	 * @param url The content of the QR code
	 */
	public InformationView(String html, Image qrCode, String qrCodeContent) {
		this.qrCode = qrCode;
		this.html = html;
		this.qrCodeContent = qrCodeContent;
		
		// Initialize view.
		this.setLayout(new BorderLayout());
		this.loadWebViewComponents();
		this.loadScrollButtons();
		this.loadQRCodeViewComponents();
		this.validate();
	}
	
	/**
	 * Loads the web view and related components.
	 */
	private void loadWebViewComponents() {
		JPanel layoutContainer = new JPanel(new BorderLayout());
		
		this.loadWebView();
        layoutContainer.add(this.webViewContainer, BorderLayout.CENTER);
        
        this.loadScrollButtons();
        JPanel buttonLayoutContainer = new JPanel(new BorderLayout());
        buttonLayoutContainer.add(this.scrollUpButton, BorderLayout.NORTH);
        buttonLayoutContainer.add(this.scrollDownButton, BorderLayout.SOUTH);
        layoutContainer.add(buttonLayoutContainer, BorderLayout.EAST);
        
        // Valdiate and add.
        layoutContainer.validate();
        this.add(layoutContainer, BorderLayout.CENTER);
    }
	
	private void loadWebView() {
		// Editor pane used as a web view.
		this.webView = new JEditorPane();
		this.webView.setEditable(false);
		this.webView.setContentType("text/html");
		try {
			this.webView.setText(this.getHtml());
		} catch(Exception e) {
			Logger.e(e);
		}
		this.webView.setCaretPosition(0); // scrolls to the top
		
		// Scroll pane that contains the editor pane.
		this.webViewContainer = new JScrollPane(this.webView);
		this.webViewContainer.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		this.webViewContainer.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
		this.webViewContainer.validate();
	}
	
	/**
	 * Loads the scroll up and scroll down buttons for scrolling the web view.
	 * This is necessary because the scroll bar is very clumsy to control on
	 * a touch screen device.
	 */
	private void loadScrollButtons() {
		// Scroll up button.
		this.scrollUpButton = new JButton(" ↑ ");
		this.scrollUpButton.setName("up");
		this.scrollUpButton.addMouseListener(this);
		
		// Scroll down button.
		this.scrollDownButton = new JButton(" ↓ ");
		this.scrollDownButton.setName("down");
		this.scrollDownButton.addMouseListener(this);
	}
	
	/**
	 * Loads the QR code view and related components.
	 */
	private void loadQRCodeViewComponents() {
{'fraction_non_alphanumeric': 0.0996607294317218, 'fraction_numerical': 0.004770992366412214, 'mean_word_length': 3.559207346544224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '984107', 'n_tokens_mistral': 3090, 'n_tokens_neox': 2709, 'n_words': 794}