<commit_before>/*
 * Copyright (c) 1998-2014 by <NAME>. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public License,
 * version 2.0. If a copy of the MPL was not distributed with this file, You
 * can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as defined
 * by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs.widgets.search;

import com.trollworks.toolkit.annotation.Localize;
import com.trollworks.toolkit.ui.UIUtilities;
import com.trollworks.toolkit.ui.layout.FlexRow;
import com.trollworks.toolkit.utility.Localization;
import com.trollworks.toolkit.utility.text.Numbers;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Collections;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

/** A standard search control. */
public class Search extends JPanel implements DocumentListener, KeyListener, FocusListener {
	@Localize("The number of matches found")
	private static String	MSG_HIT_TOOLTIP;
	@Localize("Enter text here and press RETURN to select all matching items")
	private static String	MSG_SEARCH_FIELD_TOOLTIP;
	private SearchTarget	mTarget;
	private JLabel			mHits;
	private JTextField		mFilterField;
	private SearchDropDown	mFloater;
	private String			mFilter;

	static {
		Localization.initialize();
	}

	/**
	 * Creates the search panel.
	 *
	 * @param target The search target.
	 */
	public Search(SearchTarget target) {
		mTarget = target;

		mFilterField = new JTextField(20);
		mFilterField.getDocument().addDocumentListener(this);
		mFilterField.addKeyListener(this);
		mFilterField.addFocusListener(this);
		mFilterField.setToolTipText(MSG_SEARCH_FIELD_TOOLTIP);
		mFilterField.putClientProperty("JTextField.variant", "search"); //$NON-NLS-1$ //$NON-NLS-2$
		add(mFilterField);

		mHits = new JLabel();
		mHits.setToolTipText(MSG_HIT_TOOLTIP);
		adjustHits();<commit_msg>Better sizing.<commit_after>/*
 * Copyright (c) 1998-2014 by <NAME>. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public License,
 * version 2.0. If a copy of the MPL was not distributed with this file, You
 * can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as defined
 * by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs.widgets.search;

import com.trollworks.toolkit.annotation.Localize;
import com.trollworks.toolkit.ui.UIUtilities;
import com.trollworks.toolkit.ui.layout.FlexRow;
import com.trollworks.toolkit.utility.Localization;
import com.trollworks.toolkit.utility.text.Numbers;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Collections;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

/** A standard search control. */
public class Search extends JPanel implements DocumentListener, KeyListener, FocusListener {
	@Localize("The number of matches found")
	private static String	MSG_HIT_TOOLTIP;
	@Localize("Enter text here and press RETURN to select all matching items")
	private static String	MSG_SEARCH_FIELD_TOOLTIP;
	private SearchTarget	mTarget;
	private JLabel			mHits;
	private JTextField		mFilterField;
	private SearchDropDown	mFloater;
	private String			mFilter;

	static {
		Localization.initialize();
	}

	/**
	 * Creates the search panel.
	 *
	 * @param target The search target.
	 */
	public Search(SearchTarget target) {
		mTarget = target;

		mFilterField = new JTextField(10);
		mFilterField.getDocument().addDocumentListener(this);
		mFilterField.addKeyListener(this);
		mFilterField.addFocusListener(this);
		mFilterField.setToolTipText(MSG_SEARCH_FIELD_TOOLTIP);
		// This client property is specific to Mac OS X
		mFilterField.putClientProperty("JTextField.variant", "search"); //$NON-NLS-1$ //$NON-NLS-2$
		mFilterField.setMinimumSize(new Dimension(60, mFilterField.getPreferredSize().height));
		add(mFilterField);

		mHits = new JLabel();
		mHits.setToolTipText(MSG_HIT_TOOLTIP);
		adjustHits();
{'fraction_non_alphanumeric': 0.10071488645920942, 'fraction_numerical': 0.00798990748528175, 'mean_word_length': 5.013906447534766, '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': '2552903', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1490, 'n_words': 390}