<commit_before>/* *****************************************************************************
 * Copyright (c) 2011, 2020 JCrypTool Team and Contributors All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 * ***************************************************************************
 */
package org.jcryptool.analysis.vigenere.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;
import org.jcryptool.analysis.vigenere.exceptions.IllegalInputException;
import org.jcryptool.analysis.vigenere.exceptions.NoContentException;
import org.jcryptool.analysis.vigenere.interfaces.DataProvider;
import org.jcryptool.core.logging.utils.LogUtil;
import org.jcryptool.core.util.colors.ColorService;
import org.jcryptool.core.util.fonts.FontService;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class FrequencyGui extends Content {
	// graphical elements.
	private Composite cselection;
	private Composite cgraph;
	private Composite cphrase;
	private Label lpreview;

	private Label lsone;
	private Label lstwo;
	private Label lsthree;

	private Text thelp;
	private Text tsample;

	private Button bshift;
	private Button bdecrypt;
	private Button boptions;
	private Button bnext;
	private Button bback;

	// container for frequency graph.
	private FrequencyContainer container;

	// chiffre text and length of pass phrase
	final private String chiffre;
	final private String edtitle;
	private int plength;
	private Label llength;
	private Composite mainComposite;
	private Label labelSeparator;
	private Composite buttonComposite;

	/**
	 * Constructor for the Frquency GUI.
	 * 
	 * @param parent
	 *            The parent composite in which the control should be displayed.
	 *            Parent composite must use GridLayout.
	 * @param chiffre
	 * @param passlength
	 * @param title
	 *            The title of the used Editor.
	 */
	public FrequencyGui(ContentDelegator parent, final String chiffre, final int passlength, final String title) {
		super(parent, SWT.NONE);
		this.chiffre = chiffre;
		this.edtitle = title;
		this.plength = passlength;
		initGUI();
	}

	/**
	 * Initializes the GUI.
	 */
	private void initGUI() {
		try {
			FontData coudat = new FontData(VigenereBreakerGui.COURIER, 10, SWT.NORMAL);
			Font coufont = new Font(getDisplay(), coudat);

			this.setLayout(new GridLayout());
			this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

			cselection = new Composite(this, SWT.NONE);
			cselection.setLayout(new GridLayout(3, false));
			cselection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

			lsone = new Label(cselection, SWT.BORDER | SWT.CENTER);
			lsone.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
			lsone.setText(Messages.VigenereGlobal_navi_friedman);
			lsone.setFont(FontService.getLargeFont());
			lsone.setForeground(ColorService.GRAY);

			lstwo = new Label(cselection, SWT.BORDER | SWT.CENTER);
			lstwo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
			lstwo.setText(Messages.VigenereGlobal_navi_frequency);
			lstwo.setFont(FontService.getLargeFont());

			lsthree = new Label(cselection, SWT.BORDER | SWT.CENTER);
			lsthree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
			lsthree.setText(Messages.VigenereGlobal_navi_decryption);
			lsthree.setFont(FontService.getLargeFont());
			lsthree.setForeground(ColorService.GRAY);

			mainComposite = new Composite(this, SWT.NONE);
			mainComposite.setLayout(new GridLayout(2, true));
			mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

			lpreview = new Label(mainComposite, SWT.NONE);
			lpreview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
			lpreview.setText(Messages.FrequencyGui_label_preview1 + " " + edtitle);

			tsample = new Text(mainComposite, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
			GridData gd_tsample = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
			gd_tsample.widthHint = 600;
			gd_tsample.heightHint = 150;
			tsample.setLayoutData(gd_tsample);
			tsample.setFont(coufont);
			tsample.setEditable(false);

			cgraph = new Composite(mainComposite, SWT.NONE);
			cgraph.setLayout(new GridLayout());
			GridData gd_cgraph = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
			gd_cgraph.minimumHeight = 250;
			cgraph.setLayoutData(gd_cgraph);

			thelp = new Text(mainComposite, SWT.MULTI | SWT.WRAP);
			thelp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 2));
			thelp.setText(String.format(Messages.FrequencyGui_text_help, plength) + Messages.FrequencyGui_0);
			thelp.setFont(FontService.getSmallFont());
			thelp.setEditable(false);

			llength = new Label(mainComposite, SWT.NONE);
			llength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
			llength.setText(Messages.FrequencyGui_label_length + " " + String.valueOf(plength));
			
			cphrase = new Composite(mainComposite, SWT.NONE);
			cphrase.setLayout(new RowLayout());
			cphrase.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

			// Seperator
			labelSeparator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);<commit_msg>Fixes a problem that the graphs width increases after resizing the window.<commit_after>/* *****************************************************************************
 * Copyright (c) 2011, 2020 JCrypTool Team and Contributors All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 * ***************************************************************************
 */
package org.jcryptool.analysis.vigenere.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;
import org.jcryptool.analysis.vigenere.exceptions.IllegalInputException;
import org.jcryptool.analysis.vigenere.exceptions.NoContentException;
import org.jcryptool.analysis.vigenere.interfaces.DataProvider;
import org.jcryptool.core.logging.utils.LogUtil;
import org.jcryptool.core.util.colors.ColorService;
import org.jcryptool.core.util.fonts.FontService;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class FrequencyGui extends Content {
	// graphical elements.
	private Composite cselection;
	private Composite cgraph;
	private Composite cphrase;
	private Label lpreview;

	private Label lsone;
	private Label lstwo;
	private Label lsthree;

	private Text thelp;
	private Text tsample;

	private Button bshift;
	private Button bdecrypt;
	private Button boptions;
	private Button bnext;
	private Button bback;

	// container for frequency graph.
	private FrequencyContainer container;

	// chiffre text and length of pass phrase
	final private String chiffre;
	final private String edtitle;
	private int plength;
	private Label llength;
	private Composite mainComposite;
	private Label labelSeparator;
	private Composite buttonComposite;

	/**
	 * Constructor for the Frquency GUI.
	 * 
	 * @param parent
	 *            The parent composite in which the control should be displayed.
	 *            Parent composite must use GridLayout.
	 * @param chiffre
	 * @param passlength
	 * @param title
	 *            The title of the used Editor.
	 */
	public FrequencyGui(ContentDelegator parent, final String chiffre, final int passlength, final String title) {
		super(parent, SWT.NONE);
		this.chiffre = chiffre;
		this.edtitle = title;
		this.plength = passlength;
		initGUI();
	}

	/**
	 * Initializes the GUI.
	 */
	private void initGUI() {
		try {
			FontData coudat = new FontData(VigenereBreakerGui.COURIER, 10, SWT.NORMAL);
			Font coufont = new Font(getDisplay(), coudat);

			this.setLayout(new GridLayout());
			this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

			cselection = new Composite(this, SWT.NONE);
			cselection.setLayout(new GridLayout(3, false));
			cselection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

			lsone = new Label(cselection, SWT.BORDER | SWT.CENTER);
			lsone.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
			lsone.setText(Messages.VigenereGlobal_navi_friedman);
			lsone.setFont(FontService.getLargeFont());
			lsone.setForeground(ColorService.GRAY);

			lstwo = new Label(cselection, SWT.BORDER | SWT.CENTER);
			lstwo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
			lstwo.setText(Messages.VigenereGlobal_navi_frequency);
			lstwo.setFont(FontService.getLargeFont());

			lsthree = new Label(cselection, SWT.BORDER | SWT.CENTER);
			lsthree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
			lsthree.setText(Messages.VigenereGlobal_navi_decryption);
			lsthree.setFont(FontService.getLargeFont());
			lsthree.setForeground(ColorService.GRAY);

			mainComposite = new Composite(this, SWT.NONE);
			mainComposite.setLayout(new GridLayout(2, true));
			mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

			lpreview = new Label(mainComposite, SWT.NONE);
			lpreview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
			lpreview.setText(Messages.FrequencyGui_label_preview1 + " " + edtitle);

			tsample = new Text(mainComposite, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
			GridData gd_tsample = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
			gd_tsample.widthHint = 600;
			gd_tsample.heightHint = 150;
			tsample.setLayoutData(gd_tsample);
			tsample.setFont(coufont);
			tsample.setEditable(false);

			cgraph = new Composite(mainComposite, SWT.NONE);
			cgraph.setLayout(new GridLayout());
			GridData gd_cgraph = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
			gd_cgraph.widthHint = 600;
			gd_cgraph.minimumHeight = 250;
			cgraph.setLayoutData(gd_cgraph);

			thelp = new Text(mainComposite, SWT.MULTI | SWT.WRAP);
			thelp.setText(String.format(Messages.FrequencyGui_text_help, plength) + Messages.FrequencyGui_0);
			thelp.setFont(FontService.getSmallFont());
			thelp.setEditable(false);
			GridData gd_thelp = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 2);
			gd_thelp.widthHint = 300;
			thelp.setLayoutData(gd_thelp);

			llength = new Label(mainComposite, SWT.NONE);
			llength.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
			llength.setText(Messages.FrequencyGui_label_length + " " + String.valueOf(plength));
			
			cphrase = new Composite(mainComposite, SWT.NONE);
			cphrase.setLayout(new RowLayout());
			cphrase.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

			// Seperator
			labelSeparator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
{'fraction_non_alphanumeric': 0.1241666013020629, 'fraction_numerical': 0.005961251862891207, 'mean_word_length': 4.753610108303249, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '1468598', 'n_tokens_mistral': 4549, 'n_tokens_neox': 4106, 'n_words': 1001}