<commit_before>package org.cytoscape.work.internal.tunables.utils;

import static javax.swing.GroupLayout.DEFAULT_SIZE;
import static javax.swing.GroupLayout.PREFERRED_SIZE;

import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ToolTipManager;

import org.cytoscape.work.swing.AbstractGUITunableHandler.TunableFieldPanel;

/*
 * #%L
 * Cytoscape Work Swing Impl (work-swing-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2006 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */


/**
 * This class is for setting an initial default size for the tunable text boxes.
 * @author rozagh
 */
public final class GUIDefaults {

	public static final int TEXT_BOX_WIDTH = 150;
	
	public static void updateFieldPanel(final JPanel p, final Component c, final boolean horizontalForm) {
		updateFieldPanel(p, new JLabel(" "), c, horizontalForm);
	}
	
	public static void updateFieldPanel(final JPanel p, JLabel label, final Component control,
			final boolean horizontalForm) {
		if (label == null)
			label = new JLabel(" ");
		
		if (horizontalForm)
			label.setHorizontalAlignment(JLabel.LEFT);
		else
			label.setHorizontalAlignment(JLabel.RIGHT);
		
		updateFieldPanel(p, (Component)label, control, horizontalForm);
	}
	
	public static void updateFieldPanel(final JPanel p, final JTextArea textArea, final Component control,
			final boolean horizontalForm) {
		if (textArea != null) {
			textArea.setLineWrap(true);
			textArea.setWrapStyleWord(true);
			textArea.setOpaque(false);
			textArea.setBorder(null);
			textArea.setEditable(false);
			
			updateFieldPanel(p, (Component)textArea, control, horizontalForm);
		} else {
			updateFieldPanel(p, new JLabel(" "), control, horizontalForm);
		}
	}
	
	public static void setTooltip(String text, JComponent... components) {
		if (text == null)
			return;
		
		text = text.trim();
		
		if (text.isEmpty())
			return;
		
		final ToolTipManager tipManager = ToolTipManager.sharedInstance();
		tipManager.setInitialDelay(1);
		tipManager.setDismissDelay(7500);
		
		for (final JComponent c : components) {
			if (c != null)
				c.setToolTipText(text);
		}
	}
	
	private static void updateFieldPanel(final JPanel p, final Component label, final Component control,
			final boolean horizontalForm) {
		if (p instanceof TunableFieldPanel) {
			((TunableFieldPanel)p).setControl(control);
			
			if (label instanceof JLabel)
				((TunableFieldPanel)p).setLabel((JLabel)label);
			else if (label instanceof JTextArea)
				((TunableFieldPanel)p).setMultiLineLabel((JTextArea)label);
			
			return;
		}
		
		p.removeAll();
		
		final GroupLayout layout = new GroupLayout(p);
		p.setLayout(layout);
		layout.setAutoCreateContainerGaps(false);
		layout.setAutoCreateGaps(true);
		
		if (horizontalForm) {
			p.setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 1));
			
			layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING, true)
					.addComponent(label, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)
					.addComponent(control, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)
			);
			layout.setVerticalGroup(layout.createSequentialGroup()
					.addComponent(label, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)
					.addComponent(control, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)
			);
		} else {
			p.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
			<commit_msg>Refs #3094: Adds another pixel to the gap between Tunables fields.<commit_after>package org.cytoscape.work.internal.tunables.utils;

import static javax.swing.GroupLayout.DEFAULT_SIZE;
import static javax.swing.GroupLayout.PREFERRED_SIZE;

import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ToolTipManager;

import org.cytoscape.work.swing.AbstractGUITunableHandler.TunableFieldPanel;

/*
 * #%L
 * Cytoscape Work Swing Impl (work-swing-impl)
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2006 - 2013 The Cytoscape Consortium
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 2.1 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */


/**
 * This class is for setting an initial default size for the tunable text boxes.
 * @author rozagh
 */
public final class GUIDefaults {

	public static final int TEXT_BOX_WIDTH = 150;
	
	public static void updateFieldPanel(final JPanel p, final Component c, final boolean horizontalForm) {
		updateFieldPanel(p, new JLabel(" "), c, horizontalForm);
	}
	
	public static void updateFieldPanel(final JPanel p, JLabel label, final Component control,
			final boolean horizontalForm) {
		if (label == null)
			label = new JLabel(" ");
		
		if (horizontalForm)
			label.setHorizontalAlignment(JLabel.LEFT);
		else
			label.setHorizontalAlignment(JLabel.RIGHT);
		
		updateFieldPanel(p, (Component)label, control, horizontalForm);
	}
	
	public static void updateFieldPanel(final JPanel p, final JTextArea textArea, final Component control,
			final boolean horizontalForm) {
		if (textArea != null) {
			textArea.setLineWrap(true);
			textArea.setWrapStyleWord(true);
			textArea.setOpaque(false);
			textArea.setBorder(null);
			textArea.setEditable(false);
			
			updateFieldPanel(p, (Component)textArea, control, horizontalForm);
		} else {
			updateFieldPanel(p, new JLabel(" "), control, horizontalForm);
		}
	}
	
	public static void setTooltip(String text, JComponent... components) {
		if (text == null)
			return;
		
		text = text.trim();
		
		if (text.isEmpty())
			return;
		
		final ToolTipManager tipManager = ToolTipManager.sharedInstance();
		tipManager.setInitialDelay(1);
		tipManager.setDismissDelay(7500);
		
		for (final JComponent c : components) {
			if (c != null)
				c.setToolTipText(text);
		}
	}
	
	private static void updateFieldPanel(final JPanel p, final Component label, final Component control,
			final boolean horizontalForm) {
		if (p instanceof TunableFieldPanel) {
			((TunableFieldPanel)p).setControl(control);
			
			if (label instanceof JLabel)
				((TunableFieldPanel)p).setLabel((JLabel)label);
			else if (label instanceof JTextArea)
				((TunableFieldPanel)p).setMultiLineLabel((JTextArea)label);
			
			return;
		}
		
		p.removeAll();
		
		final GroupLayout layout = new GroupLayout(p);
		p.setLayout(layout);
		layout.setAutoCreateContainerGaps(false);
		layout.setAutoCreateGaps(true);
		
		if (horizontalForm) {
			p.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
			
			layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING, true)
					.addComponent(label, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)
					.addComponent(control, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)
			);
			layout.setVerticalGroup(layout.createSequentialGroup()
					.addComponent(label, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)
					.addComponent(control, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)
			);
		} else {
			p.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
			
{'fraction_non_alphanumeric': 0.09901105293775452, 'fraction_numerical': 0.006980802792321117, 'mean_word_length': 4.4199243379571245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '264486', 'n_tokens_mistral': 2929, 'n_tokens_neox': 2559, 'n_words': 720}