<commit_before>//
// $Id: RuntimeAdjust.java,v 1.9 2003/03/11 23:08:56 ray Exp $

package com.samskivert.util;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import java.io.File;

import java.util.Iterator;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import com.samskivert.Log;
import com.samskivert.swing.CollapsiblePanel;
import com.samskivert.swing.GroupLayout;
import com.samskivert.swing.MultiLineLabel;
import com.samskivert.swing.ScrollablePanel;
import com.samskivert.swing.VGroupLayout;

/**
 * Provides a service where named variables can be registered as
 * adjustable by the developer at runtime. Generally a special key is
 * configured (via {@link DebugChords}) to pop up the adjustable variables
 * interface which can then be used to toggle booleans, change integer
 * values and generally adjust debugging and tuning parameters. This is
 * not meant to be an interface for end-user configurable parameters, but
 * to allow the developer to tweak runtime parameters more easily.
 *
 * <p> Adjustments are bound to a {@link Config} property which can be
 * changed through the config interface or through the bound runtime
 * adjust.
 *
 * <p> <em>Note:</em> adjusts are meant to be arranged in a two level
 * hierarchy. An adjust's name, therefore, should be of the form:
 * <code>library.package.adjustment</code>. The <code>package</code>
 * component can consist of multiple words joined with a period, but the
 * <code>library</code> will always be the first word before the first
 * period and the <code>adjustment</code> always the last word after the
 * final period. This is mainly only important for organizing the runtime
 * adjustment editing interface.
 */
public class RuntimeAdjust
{
    /**
     * Creates a Swing user interface that can be used to adjust all
     * registered runtime adjustments.
     */
    public static JComponent createAdjustEditor ()
    {
        VGroupLayout layout = new VGroupLayout(
            VGroupLayout.NONE, VGroupLayout.STRETCH,
            3, VGroupLayout.TOP);
        layout.setOffAxisJustification(VGroupLayout.LEFT);

        JTabbedPane editor = new JTabbedPane();
        Font font = editor.getFont();
        Font smaller = font.deriveFont(font.getSize()-1f);

        String library = null;
        ScrollablePanel lpanel = null;
        String pkgname = null;
        CollapsiblePanel pkgpanel = null;

        int acount = _adjusts.size();
        for (int ii = 0; ii < acount; ii++) {
            Adjust adjust = (Adjust)_adjusts.get(ii);

            // create a new library label if necessary
            if (!adjust.getLibrary().equals(library)) {
                library = adjust.getLibrary();
                pkgname = null;
                lpanel = new ScrollablePanel(layout);
                lpanel.setTracksViewportWidth(true);
                lpanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
                editor.addTab(library, lpanel);
            }

            // create a new package panel if necessary
            if (!adjust.getPackage().equals(pkgname)) {
                pkgname = adjust.getPackage();
                pkgpanel = new CollapsiblePanel();
                JCheckBox pkgcheck = new JCheckBox(pkgname);
                pkgcheck.setSelected(true);
                pkgpanel.setTrigger(pkgcheck, null, null);
                pkgpanel.setTriggerContainer(pkgcheck);
                pkgpanel.getContent().setLayout(layout);
                pkgpanel.setCollapsed(false);
                lpanel.add(pkgpanel);
            }

            // add an entry for this adjustment
            pkgpanel.getContent().add(new JSeparator());
            JPanel aeditor = adjust.getEditor();
            aeditor.setFont(smaller);
            pkgpanel.getContent().add(aeditor);
        }

        return editor;
    }

    /** Provides runtime adjustable boolean variables. */
    public static class BooleanAdjust extends Adjust
        implements ActionListener
    {
        public BooleanAdjust (String descrip, String name,
                              Config config, boolean defval)
        {
            super(descrip, name, config);<commit_msg>Make the adjustment editor scroll sanely.<commit_after>//
// $Id: RuntimeAdjust.java,v 1.10 2003/04/26 17:59:17 mdb Exp $

package com.samskivert.util;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import java.io.File;

import java.util.Iterator;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.Scrollable;

import com.samskivert.Log;
import com.samskivert.swing.CollapsiblePanel;
import com.samskivert.swing.GroupLayout;
import com.samskivert.swing.MultiLineLabel;
import com.samskivert.swing.VGroupLayout;

/**
 * Provides a service where named variables can be registered as
 * adjustable by the developer at runtime. Generally a special key is
 * configured (via {@link DebugChords}) to pop up the adjustable variables
 * interface which can then be used to toggle booleans, change integer
 * values and generally adjust debugging and tuning parameters. This is
 * not meant to be an interface for end-user configurable parameters, but
 * to allow the developer to tweak runtime parameters more easily.
 *
 * <p> Adjustments are bound to a {@link Config} property which can be
 * changed through the config interface or through the bound runtime
 * adjust.
 *
 * <p> <em>Note:</em> adjusts are meant to be arranged in a two level
 * hierarchy. An adjust's name, therefore, should be of the form:
 * <code>library.package.adjustment</code>. The <code>package</code>
 * component can consist of multiple words joined with a period, but the
 * <code>library</code> will always be the first word before the first
 * period and the <code>adjustment</code> always the last word after the
 * final period. This is mainly only important for organizing the runtime
 * adjustment editing interface.
 */
public class RuntimeAdjust
{
    /**
     * Creates a Swing user interface that can be used to adjust all
     * registered runtime adjustments.
     */
    public static JComponent createAdjustEditor ()
    {
        VGroupLayout layout = new VGroupLayout(
            VGroupLayout.NONE, VGroupLayout.STRETCH,
            3, VGroupLayout.TOP);
        layout.setOffAxisJustification(VGroupLayout.LEFT);

        JTabbedPane editor = new EditorPane();
        Font font = editor.getFont();
        Font smaller = font.deriveFont(font.getSize()-1f);

        String library = null;
        JPanel lpanel = null;
        String pkgname = null;
        CollapsiblePanel pkgpanel = null;

        int acount = _adjusts.size();
        for (int ii = 0; ii < acount; ii++) {
            Adjust adjust = (Adjust)_adjusts.get(ii);

            // create a new library label if necessary
            if (!adjust.getLibrary().equals(library)) {
                library = adjust.getLibrary();
                pkgname = null;
                lpanel = new JPanel(layout);
                lpanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
                editor.addTab(library, lpanel);
            }

            // create a new package panel if necessary
            if (!adjust.getPackage().equals(pkgname)) {
                pkgname = adjust.getPackage();
                pkgpanel = new CollapsiblePanel();
                JCheckBox pkgcheck = new JCheckBox(pkgname);
                pkgcheck.setSelected(true);
                pkgpanel.setTrigger(pkgcheck, null, null);
                pkgpanel.setTriggerContainer(pkgcheck);
                pkgpanel.getContent().setLayout(layout);
                pkgpanel.setCollapsed(false);
                lpanel.add(pkgpanel);
            }

            // add an entry for this adjustment
            pkgpanel.getContent().add(new JSeparator());
            JPanel aeditor = adjust.getEditor();
            aeditor.setFont(smaller);
            pkgpanel.getContent().add(aeditor);
        }

        return editor;
    }

    /** Used to make our editor scroll sanely. */
    protected static class EditorPane extends JTabbedPane
        implements Scrollable
    {
        public Dimension getPreferredScrollableViewportSize () {
            return getPreferredSize();
        }

        public int getScrollableUnitIncrement (
            Rectangle visibleRect, int orientation, int direction) {
            return 50;
        }

        public int getScrollableBlockIncrement (
            Rectangle visibleRect, int orientation, int direction) {
            return 200;
        }  

        public boolean getScrollableTracksViewportWidth () {
            return true;
        }

        public boolean getScrollableTracksViewportHeight () {
            return false;
        }
    }

    /** Provides runtime adjustable boolean variables. */
    public static class BooleanAdjust extends Adjust
        implements ActionListener
    {
        public BooleanAdjust (String descrip, String name,
                              Config config, boolean defval)
        {
            super(descrip, name, config);
{'fraction_non_alphanumeric': 0.08510427010923535, 'fraction_numerical': 0.005163853028798411, 'mean_word_length': 2.6661812886785583, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, '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': '6079180', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2616, 'n_words': 829}