<commit_before>package org.u_compare.gui;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URL;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import org.u_compare.gui.control.ComponentController;
import org.u_compare.gui.control.ParameterController;
import org.u_compare.gui.control.ParameterControllerFactory;
import org.u_compare.gui.control.DropTargetController;
import org.u_compare.gui.debugging.GUITestingHarness;
import org.u_compare.gui.model.DescriptionChangeListener;
import org.u_compare.gui.model.LockedStatusChangeListener;
import org.u_compare.gui.model.MinimizedStatusChangeListener;
import org.u_compare.gui.model.SubComponentsChangedListener;
import org.u_compare.gui.model.AggregateComponent;
import org.u_compare.gui.model.Component;
import org.u_compare.gui.model.Workflow;
import org.u_compare.gui.model.WorkflowStatusListener;
import org.u_compare.gui.model.Workflow.WorkflowStatus;
import org.u_compare.gui.model.parameters.Parameter;

/**
 * TODO: We do need to separate this monster into multiple classes.
 * 
 * @author pontus
 * @author olaf
 * @author luke
 * @version 2009-08-26
 */
@SuppressWarnings("serial")
public class ComponentPanel extends DraggableJPanel implements
		SubComponentsChangedListener, LockedStatusChangeListener,
		MinimizedStatusChangeListener, DescriptionChangeListener {

	private final static String ICON_CLOSE_PATH = "gfx/icon_close1.png";
	private final static String ICON_CLOSE_PATH_HIGHLIGHT =
		"gfx/icon_close1highlight.png";
	private final static String ICON_MAX_PATH = "gfx/icon_maximize1.png";
	private final static String ICON_MIN_PATH = "gfx/icon_minimize1.png";
	private final static String ICON_LOCKED_PATH = "gfx/icon_locked.png";
	private final static String ICON_UNLOCKED_PATH = "gfx/icon_unlocked.png";

	private final static int PREFERRED_WIDTH = 300;

	private static final int AGGREGATE_PADDING = 2;
	private static final int DESCRIPTION_PANEL_PADDING = 5;

	private static final int BORDER_ROUNDING = 5;
	private static final int BORDER_WIDTH = 2;
	private static final Color BORDER_COLOR = Color.DARK_GRAY;
	private static Color HEADER_COLOR = Color.WHITE;
	private static Color BODY_COLOR;

	private static final int BUTTON_DECREMENT = 0;

	private static final boolean MINIMIZE_SUBCOMPONENTS = true;
	
	private static boolean iconsLoaded = false;
	private static ImageIcon minIcon;
	private static ImageIcon maxIcon;
	private static ImageIcon lockedIcon;
	private static ImageIcon unlockedIcon;
	private static ImageIcon closeIcon;

	private JPanel innerPanel;
	private JPanel topPanel;
	private JPanel aggregatePanel;
	private JButton minButton; // = new
								// BasicArrowButton(BasicArrowButton.SOUTH);
	private JButton lockButton;
	protected String title;
	private JPanel buttonPanel;
	private JButton closeButton;

	private ActionListener closeListener;
	private ActionListener minListener;
	private ActionListener lockListener;
	private ActionListener titleListener;
	private ActionListener descriptionListener;
	
	private FocusListener titleFocusListener;
	private FocusListener descriptionFocusListener;

	private Component component;

	private ComponentController controller;
	private JPanel titlePanel;
	private JLabel titleLabel;
	private JTextField titleTextField;
	private ActionListener closeHighlight;
	private ActionListener closeUnhighlight;
	private BevelBorder highlighted;
	private Border empty;
	private JPanel descriptionPanel;
	private JTextArea description;
	private JTextArea editableDescription;
	private String descriptionText;
	private java.awt.Component textField;
	
	private WorkflowControlPanel workflowControlPanel;
	
	protected ComponentPanel(ComponentController controller){
		super(controller);
	}
	
	public ComponentPanel(Component component,
			ComponentController controller) {
		
		super(controller);
		initialConfiguration(component, controller);
		
		if (component.isAggregate()) {
			((AggregateComponent) component)
					.registerSubComponentsChangedListener(this);
		}
		
		
		if (!component.isWorkflow()) {
			this.setBorder(new RoundedBorder(null, BORDER_COLOR, BODY_COLOR,
					BORDER_ROUNDING, BORDER_WIDTH, false));
		}
		
		//LUKES: WorkflowPanel up to here


		// set up a top panel (inside the inner panel) and layout
		topPanel = new JPanel();
		BorderLayout topLayout = new BorderLayout();
		topPanel.setLayout(topLayout);
		topPanel.setOpaque(false);
		
		if (!component.isWorkflow()) {
			topPanel.setBorder(new RoundedBorder(null, BORDER_COLOR,
					HEADER_COLOR, BORDER_ROUNDING, BORDER_WIDTH, true));

			setupTitlePanel();
			setupButtonPanel();
			this.add(topPanel, BorderLayout.NORTH);

		} else {
			setupTitlePanel();
			this.add(topPanel, BorderLayout.NORTH);
		}

		setupInnerPanel();
		setupDescriptionPanel();
		if(component.isWorkflow()){
			setupWorkflowControlPanel();
		}
		if(!component.isWorkflow()){
			setupInputOutputPanel();
		}
		setupParameterPanel();
		setupMinimizedStatus();
		setupSubComponents();		
	}
	
	protected void initialConfiguration(Component component,
			ComponentController controller){
		
		this.controller = controller;
		this.component = component;
		
		//Register Listeners
		component.registerLockedStatusChangeListener(this);
		component.registerMinimizedStatusChangeListener(this);
		component.registerComponentDescriptionChangeListener(this);
		
		//Set display properties
		BODY_COLOR = defaultColor;
		this.setOpaque(false);
		
		BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
		this.setLayout(layout);
		
	}
	
	protected void setupTitlePanel(){
		
		titleListener = new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setTitle(titleTextField.getText());
				titleTextField.setVisible(false);
				titleLabel.setVisible(true);
			}
		};
		
		titleFocusListener = new FocusListener() {
			
			public void focusGained(FocusEvent e) {
			}

			public void focusLost(FocusEvent e) {
				setTitle(titleTextField.getText());
				titleTextField.setVisible(false);
				titleLabel.setVisible(true);
			}
		};
		
		// add a title panel
		titlePanel = new JPanel(new CardLayout());

		title = component.getName();
		titleLabel = new JLabel(title);
										
		titleTextField = new JTextField(title);
		titleLabel.setFont(new Font("sansserif", Font.BOLD, 12));
		titleTextField.setFont(new Font("sansserif", Font.BOLD, 12));
		titleTextField.setVisible(false);

		titlePanel.add(titleLabel, BorderLayout.LINE_START);
		titlePanel.add(titleTextField, BorderLayout.LINE_START);
		titlePanel.setBackground(Color.WHITE);
		topPanel.add(titlePanel, BorderLayout.LINE_START);

		titlePanel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {<commit_msg>limited size for component title<commit_after>package org.u_compare.gui;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URL;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.text.AbstractDocument.Content;

import org.u_compare.gui.control.ComponentController;
import org.u_compare.gui.control.ParameterController;
import org.u_compare.gui.control.ParameterControllerFactory;
import org.u_compare.gui.control.DropTargetController;
import org.u_compare.gui.debugging.GUITestingHarness;
import org.u_compare.gui.model.DescriptionChangeListener;
import org.u_compare.gui.model.LockedStatusChangeListener;
import org.u_compare.gui.model.MinimizedStatusChangeListener;
import org.u_compare.gui.model.SubComponentsChangedListener;
import org.u_compare.gui.model.AggregateComponent;
import org.u_compare.gui.model.Component;
import org.u_compare.gui.model.Workflow;
import org.u_compare.gui.model.WorkflowStatusListener;
import org.u_compare.gui.model.Workflow.WorkflowStatus;
import org.u_compare.gui.model.parameters.Parameter;

/**
 * TODO: We do need to separate this monster into multiple classes.
 * 
 * @author pontus
 * @author olaf
 * @author luke
 * @version 2009-08-26
 */
@SuppressWarnings("serial")
public class ComponentPanel extends DraggableJPanel implements
		SubComponentsChangedListener, LockedStatusChangeListener,
		MinimizedStatusChangeListener, DescriptionChangeListener {

	private final static String ICON_CLOSE_PATH = "gfx/icon_close1.png";
	private final static String ICON_CLOSE_PATH_HIGHLIGHT =
		"gfx/icon_close1highlight.png";
	private final static String ICON_MAX_PATH = "gfx/icon_maximize1.png";
	private final static String ICON_MIN_PATH = "gfx/icon_minimize1.png";
	private final static String ICON_LOCKED_PATH = "gfx/icon_locked.png";
	private final static String ICON_UNLOCKED_PATH = "gfx/icon_unlocked.png";

	private final static int PREFERRED_WIDTH = 300;

	private static final int AGGREGATE_PADDING = 2;
	private static final int DESCRIPTION_PANEL_PADDING = 5;

	private static final int BORDER_ROUNDING = 5;
	private static final int BORDER_WIDTH = 2;
	private static final Color BORDER_COLOR = Color.DARK_GRAY;
	private static Color HEADER_COLOR = Color.WHITE;
	private static Color BODY_COLOR;

	private static final int BUTTON_DECREMENT = 0;

	private static final boolean MINIMIZE_SUBCOMPONENTS = true;
	private static int TITLE_SIZE_LIMIT = 50;
	
	private static boolean iconsLoaded = false;
	private static ImageIcon minIcon;
	private static ImageIcon maxIcon;
	private static ImageIcon lockedIcon;
	private static ImageIcon unlockedIcon;
	private static ImageIcon closeIcon;

	private JPanel innerPanel;
	private JPanel topPanel;
	private JPanel aggregatePanel;
	private JButton minButton; // = new
								// BasicArrowButton(BasicArrowButton.SOUTH);
	private JButton lockButton;
	protected String title;
	private JPanel buttonPanel;
	private JButton closeButton;

	private ActionListener closeListener;
	private ActionListener minListener;
	private ActionListener lockListener;
	private ActionListener titleListener;
	private ActionListener descriptionListener;
	
	private FocusListener titleFocusListener;
	private FocusListener descriptionFocusListener;

	private Component component;

	private ComponentController controller;
	private JPanel titlePanel;
	private JLabel titleLabel;
	private JTextField titleTextField;
	private ActionListener closeHighlight;
	private ActionListener closeUnhighlight;
	private BevelBorder highlighted;
	private Border empty;
	private JPanel descriptionPanel;
	private JTextArea description;
	private JTextArea editableDescription;
	private String descriptionText;
	private java.awt.Component textField;
	
	private WorkflowControlPanel workflowControlPanel;
	
	protected ComponentPanel(ComponentController controller){
		super(controller);
	}
	
	public ComponentPanel(Component component,
			ComponentController controller) {
		
		super(controller);
		initialConfiguration(component, controller);
		
		if (component.isAggregate()) {
			((AggregateComponent) component)
					.registerSubComponentsChangedListener(this);
		}
		
		
		if (!component.isWorkflow()) {
			this.setBorder(new RoundedBorder(null, BORDER_COLOR, BODY_COLOR,
					BORDER_ROUNDING, BORDER_WIDTH, false));
		}
		
		//LUKES: WorkflowPanel up to here


		// set up a top panel (inside the inner panel) and layout
		topPanel = new JPanel();
		BorderLayout topLayout = new BorderLayout();
		topPanel.setLayout(topLayout);
		topPanel.setOpaque(false);
		
		if (!component.isWorkflow()) {
			topPanel.setBorder(new RoundedBorder(null, BORDER_COLOR,
					HEADER_COLOR, BORDER_ROUNDING, BORDER_WIDTH, true));

			setupTitlePanel();
			setupButtonPanel();
			this.add(topPanel, BorderLayout.NORTH);

		} else {
			setupTitlePanel();
			this.add(topPanel, BorderLayout.NORTH);
		}

		setupInnerPanel();
		setupDescriptionPanel();
		if(component.isWorkflow()){
			setupWorkflowControlPanel();
		}
		if(!component.isWorkflow()){
			setupInputOutputPanel();
		}
		setupParameterPanel();
		setupMinimizedStatus();
		setupSubComponents();		
	}
	
	protected void initialConfiguration(Component component,
			ComponentController controller){
		
		this.controller = controller;
		this.component = component;
		
		//Register Listeners
		component.registerLockedStatusChangeListener(this);
		component.registerMinimizedStatusChangeListener(this);
		component.registerComponentDescriptionChangeListener(this);
		
		//Set display properties
		BODY_COLOR = defaultColor;
		this.setOpaque(false);
		
		BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
		this.setLayout(layout);
		
	}
	
	protected void setupTitlePanel(){
		
		titleListener = new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setTitle(titleTextField.getText());
				titleTextField.setVisible(false);
				titleLabel.setVisible(true);
			}
		};
		
		titleFocusListener = new FocusListener() {
			
			public void focusGained(FocusEvent e) {
			}

			public void focusLost(FocusEvent e) {
				setTitle(titleTextField.getText());
				titleTextField.setVisible(false);
				titleLabel.setVisible(true);
			}
		};
		
		// add a title panel
		titlePanel = new JPanel(new CardLayout());

		title = component.getName();
		titleLabel = new JLabel(title);
										
		titleTextField = new JTextField(15);
		titleTextField.setText(title);
		titleTextField.setDocument
        	(new JTextFieldLimit(TITLE_SIZE_LIMIT));
		titleLabel.setFont(new Font("sansserif", Font.BOLD, 12));
		titleTextField.setFont(new Font("sansserif", Font.BOLD, 12));
		titleTextField.setVisible(false);

		titlePanel.add(titleLabel, BorderLayout.LINE_START);
		titlePanel.add(titleTextField, BorderLayout.LINE_START);
		titlePanel.setBackground(Color.WHITE);
		topPanel.add(titlePanel, BorderLayout.LINE_START);

		titlePanel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
{'fraction_non_alphanumeric': 0.08650177608209446, 'fraction_numerical': 0.00355216418892251, 'mean_word_length': 5.441949152542373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7647680', 'n_tokens_mistral': 4894, 'n_tokens_neox': 4388, 'n_words': 1015}