<commit_before>/*
 * $Id$
 *
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 */

package org.jdesktop.swingx;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.MetalLookAndFeel;
import org.jdesktop.swingx.plaf.TitledPanelUI;
import org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI;

/**
 * A special type of Panel that has a Title section and a
 * Content section.<br>
 * The following 3 properties can be set with the UIManager to
 * change the look and feel of the JXTitledPanel:
 * <ul>
 * 	<li>JXTitledPanel.title.foreground</li>
 * 	<li>JXTitledPanel.title.background</li>
 * 	<li>JXTitledPanel.title.font</li>
 * </ul>
 * @author <NAME>
 * @author <NAME>
 */
public class JXTitledPanel extends JXPanel {
    /**
     * @see #getUIClassID
     * @see #readObject
     */
    private static final String uiClassID = "TitledPanelUI";
    private static final PropertyChangeListener LAF_LISTENER;
    
    /**
     * Initialization that would ideally be moved into various look and feel
     * classes.
     */
    static {
        loadDefaults();
        LAF_LISTENER = new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("lookAndFeel")) {
                    loadDefaults();
                }
            }
        };
        UIManager.addPropertyChangeListener(LAF_LISTENER);
    }
    
    private static void loadDefaults() {
        LookAndFeel laf = UIManager.getLookAndFeel();
        if (laf.getID().equals("GTK")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", UIManager.getColor("light"));
            defaults.put("JXTitledPanel.title.darkBackground", UIManager.getColor("dark"));
            defaults.put("JXTitledPanel.title.lightBackground", UIManager.getColor("mid"));
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Motif")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", UIManager.getColor("activeCaptionText"));
            defaults.put("JXTitledPanel.title.lightBackground", UIManager.getColor("inactiveCaption"));
            defaults.put("JXTitledPanel.title.darkBackground", UIManager.getColor("activeCaption"));
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Mac")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", new ColorUIResource(0, 0, 0));
            defaults.put("JXTitledPanel.title.darkBackground", new ColorUIResource(140, 140, 140));
            defaults.put("JXTitledPanel.title.lightBackground", new ColorUIResource(240, 240, 240));
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Windows")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", new ColorUIResource(33, 93, 198));
            defaults.put("JXTitledPanel.title.darkBackground", new ColorUIResource(198, 211, 247));
            defaults.put("JXTitledPanel.title.lightBackground", new ColorUIResource(255, 255, 255));
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Plastic")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", Color.WHITE);
            defaults.put("JXTitledPanel.title.darkBackground", Color.GRAY);
            defaults.put("JXTitledPanel.title.lightBackground", Color.LIGHT_GRAY);
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Metal")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            MetalLookAndFeel mlaf = (MetalLookAndFeel)laf;
            defaults.put("JXTitledPanel.title.foreground", new ColorUIResource(255, 255, 255));
            defaults.put("JXTitledPanel.title.darkBackground", mlaf.getCurrentTheme().getPrimaryControlDarkShadow());
            defaults.put("JXTitledPanel.title.lightBackground", mlaf.getCurrentTheme().getPrimaryControl());
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", Color.WHITE);
            defaults.put("JXTitledPanel.title.darkBackground", Color.GRAY);
            defaults.put("JXTitledPanel.title.lightBackground", Color.LIGHT_GRAY);
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        }
    }
    
	/**
	 * The text to use for the title
	 */
	private String title = "";
    /**
     * The Font to use for the Title
     */
    private Font titleFont;
    /**
     * For the gradient, this is the background color to use for the
     * dark part of the gradient
     */
    private Color titleDarkBackground;
    /**
     * For the gradient, this is the light color to use for the light part
     * of the gradient
     */
    private Color titleLightBackground;
    /**
     * The forground color to use for the Title (particularly for the text)
     */
    private Color titleForeground;
	/**
	 * The ContentPanel.  Whatever this container is will be displayed in the
	 * Content section
	 */
	private Container contentPanel;

	/**
	 * Create a new JTitledPanel with an empty string for the title.
	 */
	public JXTitledPanel() {
		this("");
	}

	/**
	 * Create a new JTitledPanel with the given title as the title for the panel.
	 * @param title
	 */
	public JXTitledPanel(String title) {
		this.title = (title == null ? "" : title);
        setContentContainer(new JXPanel());
	}

	/**
	 * Create a new JTitledPanel with the given String as the title, and the
	 * given Container as the content panel.
	 * @param title
	 * @param content
	 */
	public JXTitledPanel(String title, Container content) {
		this(title);<commit_msg>fixed constructor that takes a title, the UI delegates weren't getting this change via the property change listeners<commit_after>/*
 * $Id$
 *
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 */

package org.jdesktop.swingx;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.MetalLookAndFeel;
import org.jdesktop.swingx.plaf.TitledPanelUI;
import org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI;

/**
 * A special type of Panel that has a Title section and a
 * Content section.<br>
 * The following 3 properties can be set with the UIManager to
 * change the look and feel of the JXTitledPanel:
 * <ul>
 * 	<li>JXTitledPanel.title.foreground</li>
 * 	<li>JXTitledPanel.title.background</li>
 * 	<li>JXTitledPanel.title.font</li>
 * </ul>
 * @author <NAME>
 * @author <NAME>
 */
public class JXTitledPanel extends JXPanel {
    /**
     * @see #getUIClassID
     * @see #readObject
     */
    private static final String uiClassID = "TitledPanelUI";
    private static final PropertyChangeListener LAF_LISTENER;
    
    /**
     * Initialization that would ideally be moved into various look and feel
     * classes.
     */
    static {
        loadDefaults();
        LAF_LISTENER = new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("lookAndFeel")) {
                    loadDefaults();
                }
            }
        };
        UIManager.addPropertyChangeListener(LAF_LISTENER);
    }
    
    private static void loadDefaults() {
        LookAndFeel laf = UIManager.getLookAndFeel();
        if (laf.getID().equals("GTK")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", UIManager.getColor("light"));
            defaults.put("JXTitledPanel.title.darkBackground", UIManager.getColor("dark"));
            defaults.put("JXTitledPanel.title.lightBackground", UIManager.getColor("mid"));
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Motif")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", UIManager.getColor("activeCaptionText"));
            defaults.put("JXTitledPanel.title.lightBackground", UIManager.getColor("inactiveCaption"));
            defaults.put("JXTitledPanel.title.darkBackground", UIManager.getColor("activeCaption"));
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Mac")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", new ColorUIResource(0, 0, 0));
            defaults.put("JXTitledPanel.title.darkBackground", new ColorUIResource(140, 140, 140));
            defaults.put("JXTitledPanel.title.lightBackground", new ColorUIResource(240, 240, 240));
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Windows")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", new ColorUIResource(33, 93, 198));
            defaults.put("JXTitledPanel.title.darkBackground", new ColorUIResource(255, 255, 255));
            defaults.put("JXTitledPanel.title.lightBackground", new ColorUIResource(198, 211, 247));
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Plastic")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", Color.WHITE);
            defaults.put("JXTitledPanel.title.darkBackground", Color.GRAY);
            defaults.put("JXTitledPanel.title.lightBackground", Color.LIGHT_GRAY);
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else if (laf.getID().equals("Metal")) {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            MetalLookAndFeel mlaf = (MetalLookAndFeel)laf;
            defaults.put("JXTitledPanel.title.foreground", new ColorUIResource(255, 255, 255));
            defaults.put("JXTitledPanel.title.darkBackground", mlaf.getCurrentTheme().getPrimaryControlDarkShadow());
            defaults.put("JXTitledPanel.title.lightBackground", mlaf.getCurrentTheme().getPrimaryControl());
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        } else {
            UIDefaults defaults = UIManager.getDefaults();
            defaults.put(uiClassID, "org.jdesktop.swingx.plaf.metal.MetalTitledPanelUI");
            //adds some keys to the UIDefaults for the JXTitledPanel component
            defaults.put("JXTitledPanel.title.foreground", Color.WHITE);
            defaults.put("JXTitledPanel.title.darkBackground", Color.GRAY);
            defaults.put("JXTitledPanel.title.lightBackground", Color.LIGHT_GRAY);
            defaults.put("JXTitledPanel.title.font", UIManager.getFont("Button.font"));
        }
    }
    
	/**
	 * The text to use for the title
	 */
	private String title = "";
    /**
     * The Font to use for the Title
     */
    private Font titleFont;
    /**
     * For the gradient, this is the background color to use for the
     * dark part of the gradient
     */
    private Color titleDarkBackground;
    /**
     * For the gradient, this is the light color to use for the light part
     * of the gradient
     */
    private Color titleLightBackground;
    /**
     * The forground color to use for the Title (particularly for the text)
     */
    private Color titleForeground;
	/**
	 * The ContentPanel.  Whatever this container is will be displayed in the
	 * Content section
	 */
	private Container contentPanel;

	/**
	 * Create a new JTitledPanel with an empty string for the title.
	 */
	public JXTitledPanel() {
		this("");
	}

	/**
	 * Create a new JTitledPanel with the given title as the title for the panel.
	 * @param title
	 */
	public JXTitledPanel(String title) {
		setTitle(title);
        setContentContainer(new JXPanel());
	}

	/**
	 * Create a new JTitledPanel with the given String as the title, and the
	 * given Container as the content panel.
	 * @param title
	 * @param content
	 */
	public JXTitledPanel(String title, Container content) {
		this(title);
{'fraction_non_alphanumeric': 0.11406359523354362, 'fraction_numerical': 0.0087937296883961, 'mean_word_length': 3.083788706739526, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '3947073', 'n_tokens_mistral': 4736, 'n_tokens_neox': 4599, 'n_words': 1025}