<commit_before>package de.enflexit.common.swing;

import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import de.enflexit.common.Language;


/**
 * The Class ProgressMonitor can be used in order to display the progress of 
 * a time consuming process as for example a download or other.
 * 
 * @author <NAME> - DAWIS - ICB - University of Duisburg - Essen
 */
public class ProgressMonitor implements ActionListener {

	private JDesktopPane parentDesktopPane;
	
	private String windowTitle = "Progress Monitor";
	private String headerText = "Progress";
	private String progressText = "Download";
	
	private ImageIcon iconImage;
	private String lookAndFeelClassName;
	
	private Window owner;
	private Container progressMonitorContainer;

	private JPanel jContentPane;
	private JLabel jLabelHeader;
	private JPanel jPanelDummy;
	
	private JLabel jLabelProgress;
	private JProgressBar jProgressBarDownload;
	private JButton jButtonCancel;

	private boolean isSetModal;
	private boolean allow2Cancel = true;
	private boolean canceled = false;
	
	
	/**
	 * Instantiates a new progress monitor. In case that no parent desktop pane is specified, the
	 * class will use a JDialog to display the progress. Otherwise a JInternalFrame will be used. 
	 *
	 * @param windowTitle the window title - may be <code>null</code>
	 * @param headerText the header text - may be <code>null</code>
	 * @param progressText the progress text - may be <code>null</code>
	 * @param iconImage the icon image - may be <code>null</code>
	 * @param parentDesktopPane the parent desktop pane - may be <code>null</code>
	 * @param lookAndFeelClassName the look and feel class reference - may be <code>null</code>
	 */
	public ProgressMonitor(String windowTitle, String headerText, String progressText, ImageIcon iconImage, JDesktopPane parentDesktopPane, String lookAndFeelClassName) {
		if (windowTitle!=null)  this.windowTitle = windowTitle;
		if (headerText!=null)   this.headerText = headerText;
		if (progressText!=null) this.progressText = progressText;
		this.lookAndFeelClassName = lookAndFeelClassName;
		this.iconImage = iconImage;
	}

	/**
	 * Allows to set the owner frame of JDialog, if used.
	 * @param ownerFrame the new owner
	 */
	public void setOwner(Frame ownerFrame) {
		this.owner = ownerFrame;
	}
	/**
	 * Allows to set the owner frame of JDialog, if used.
	 * @param ownerDialog the new owner
	 */
	public void setOwner(Dialog ownerDialog) {
		this.owner = ownerDialog;
	}
	/**
	 * Allows to set the owner window .
	 * @param owner the new owner
	 */
	public void setOwner(Window owner) {
		this.owner = owner;
	}
	
	/**
	 * Sets the progress monitor modal (or not) if possible (applies 
	 * if a dialog is used as container for the progress monitor). 
	 * Default is <code>false</code>.
	 * @param isSetModal the new modal
	 */
	public void setModal(boolean isSetModal) {
		this.isSetModal = isSetModal;
	}
	/**
	 * Checks if the progress monitor should be set modal.
	 * @return true, if is sets the modal
	 */
	public boolean isSetModal() {
		return isSetModal;
	}
	
	/**
	 * Returns the progress monitor container that is either a JDialog or a JInternFrame.
	 * @return the progress monitor container
	 */
	private Container getProgressMonitorContainer() {
		if (progressMonitorContainer==null) {
			
			Dimension defaultSize = new Dimension(570, 188);
			if (this.parentDesktopPane==null) {
				JDialog jDialog = new JDialog(this.owner);	
				jDialog.setSize(defaultSize);
				jDialog.setModal(this.isSetModal);
				jDialog.setResizable(false);
				jDialog.setTitle(this.windowTitle);
				if (this.owner==null) {
					jDialog.setAlwaysOnTop(true);
				}
				if (this.iconImage!=null) {
					jDialog.setIconImage(this.iconImage.getImage());	
				}
				jDialog.setContentPane(this.getJContentPane());
				jDialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
				
				this.progressMonitorContainer = jDialog; 
				this.setLookAndFeel();	
					
			} else {
				JInternalFrame jInternalFrame = new JInternalFrame();<commit_msg>Size adjustment in 'common' ProgressMonitor<commit_after>package de.enflexit.common.swing;

import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import de.enflexit.common.Language;


/**
 * The Class ProgressMonitor can be used in order to display the progress of 
 * a time consuming process as for example a download or other.
 * 
 * @author <NAME> - DAWIS - ICB - University of Duisburg - Essen
 */
public class ProgressMonitor implements ActionListener {

	private JDesktopPane parentDesktopPane;
	
	private String windowTitle = "Progress Monitor";
	private String headerText = "Progress";
	private String progressText = "Download";
	
	private ImageIcon iconImage;
	private String lookAndFeelClassName;
	
	private Window owner;
	private Container progressMonitorContainer;

	private JPanel jContentPane;
	private JLabel jLabelHeader;
	private JPanel jPanelDummy;
	
	private JLabel jLabelProgress;
	private JProgressBar jProgressBarDownload;
	private JButton jButtonCancel;

	private boolean isSetModal;
	private boolean allow2Cancel = true;
	private boolean canceled = false;
	
	
	/**
	 * Instantiates a new progress monitor. In case that no parent desktop pane is specified, the
	 * class will use a JDialog to display the progress. Otherwise a JInternalFrame will be used. 
	 *
	 * @param windowTitle the window title - may be <code>null</code>
	 * @param headerText the header text - may be <code>null</code>
	 * @param progressText the progress text - may be <code>null</code>
	 * @param iconImage the icon image - may be <code>null</code>
	 * @param parentDesktopPane the parent desktop pane - may be <code>null</code>
	 * @param lookAndFeelClassName the look and feel class reference - may be <code>null</code>
	 */
	public ProgressMonitor(String windowTitle, String headerText, String progressText, ImageIcon iconImage, JDesktopPane parentDesktopPane, String lookAndFeelClassName) {
		if (windowTitle!=null)  this.windowTitle = windowTitle;
		if (headerText!=null)   this.headerText = headerText;
		if (progressText!=null) this.progressText = progressText;
		this.lookAndFeelClassName = lookAndFeelClassName;
		this.iconImage = iconImage;
	}

	/**
	 * Allows to set the owner frame of JDialog, if used.
	 * @param ownerFrame the new owner
	 */
	public void setOwner(Frame ownerFrame) {
		this.owner = ownerFrame;
	}
	/**
	 * Allows to set the owner frame of JDialog, if used.
	 * @param ownerDialog the new owner
	 */
	public void setOwner(Dialog ownerDialog) {
		this.owner = ownerDialog;
	}
	/**
	 * Allows to set the owner window .
	 * @param owner the new owner
	 */
	public void setOwner(Window owner) {
		this.owner = owner;
	}
	
	/**
	 * Sets the progress monitor modal (or not) if possible (applies 
	 * if a dialog is used as container for the progress monitor). 
	 * Default is <code>false</code>.
	 * @param isSetModal the new modal
	 */
	public void setModal(boolean isSetModal) {
		this.isSetModal = isSetModal;
	}
	/**
	 * Checks if the progress monitor should be set modal.
	 * @return true, if is sets the modal
	 */
	public boolean isSetModal() {
		return isSetModal;
	}
	
	/**
	 * Returns the progress monitor container that is either a JDialog or a JInternFrame.
	 * @return the progress monitor container
	 */
	private Container getProgressMonitorContainer() {
		if (progressMonitorContainer==null) {
			
			Dimension defaultSize = new Dimension(570, 200);
			if (this.parentDesktopPane==null) {
				JDialog jDialog = new JDialog(this.owner);	
				jDialog.setSize(defaultSize);
				jDialog.setModal(this.isSetModal);
				jDialog.setResizable(false);
				jDialog.setTitle(this.windowTitle);
				if (this.owner==null) {
					jDialog.setAlwaysOnTop(true);
				}
				if (this.iconImage!=null) {
					jDialog.setIconImage(this.iconImage.getImage());	
				}
				jDialog.setContentPane(this.getJContentPane());
				jDialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
				
				this.progressMonitorContainer = jDialog; 
				this.setLookAndFeel();	
					
			} else {
				JInternalFrame jInternalFrame = new JInternalFrame();
{'fraction_non_alphanumeric': 0.090019153011279, 'fraction_numerical': 0.0014896786550329857, 'mean_word_length': 4.212978369384359, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4745931', 'n_tokens_mistral': 3007, 'n_tokens_neox': 2711, 'n_words': 855}