<commit_before>/*
 * $Id$
 *
 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 *
 * This library 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 library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jdesktop.swingx.renderer;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import javax.swing.JCheckBox;
import javax.swing.UIManager;

import org.jdesktop.swingx.painter.Painter;

/**
 * A <code>JCheckBox</code> optimized for usage in renderers and
 * with a minimal background painter support. <p>
 * 
 * <b>Note</b>: As of revision #4223, there's a complete overhaul (aka: changed the tricksery) to 
 * fix Issue swingx-1513 (allow client code to set renderer transparent) while keeping
 * fix Issue swingx-897 (striping/background lost when painter installed)
 * 
 * @author <NAME>
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class JRendererCheckBox extends JCheckBox implements PainterAware {
    protected Painter painter;
    private boolean fakeTransparency;

    
    public JRendererCheckBox() {
        super();
        // fix # 1546-swingx: striping lost in synth-based lafs
        // forcing opaque to enable painting the background
        setOpaque(true);
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public Painter getPainter() {
        return painter;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setPainter(Painter painter) {
        Painter old = getPainter();
        this.painter = painter;
        firePropertyChange("painter", old, getPainter());
    }

    /**
     * {@inheritDoc} <p>
     * 
     * Overridden to return false if painting flag is true.<p>
     * 
     */
    @Override
    public boolean isOpaque() {
        if (fakeTransparency) {
            return false;
        }
        return super.isOpaque();
    }
    
    /**
     * {@inheritDoc} <p>
     * 
     * Overridden to return false if painting flag is true.<p>
     * 
     */
     @Override
    public boolean isContentAreaFilled() {
        if (fakeTransparency) {
            return false;
        }
        return super.isContentAreaFilled();
    }

    /**
     * {@inheritDoc} <p>
     * 
     * Overridden to not automatically de/register itself from/to the ToolTipManager.
     * As rendering component it is not considered to be active in any way, so the
     * manager must not listen. 
     */
    @Override
    public void setToolTipText(String text) {
        putClientProperty(TOOL_TIP_TEXT_KEY, text);
    }

    /**
     * Overridden to snatch painting from super if a painter installed or Nimbus 
     * detected.
     */
    @Override
    protected void paintComponent(Graphics g) {
        // JW: hack around for #1178-swingx (core issue) 
        // grab painting if Nimbus detected
        if ((painter != null) || isNimbus()) {
            // we have a custom (background) painter<commit_msg>updated java doc<commit_after>/*
 * $Id$
 *
 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 *
 * This library 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 library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jdesktop.swingx.renderer;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

import javax.swing.JCheckBox;
import javax.swing.UIManager;

import org.jdesktop.swingx.painter.Painter;

/**
 * A <code>JCheckBox</code> optimized for usage in renderers and
 * with a minimal background painter support. <p>
 * 
 * <b>Note</b>: As of revision #4223, there's a complete overhaul (aka: changed the tricksery) to 
 * fix Issue swingx-1513 (allow client code to set renderer transparent) while keeping
 * fix Issue swingx-897 (striping/background lost when painter installed)
 * <p>
 * 
 * <b>Note</b>: The change of logic _did_ introduce a regression (swingx-1546) 
 * which was fixed by forcing the box's  opacity to true (for regression release
 * 1.6.5-1). Further improvements (like f.i. the option to delegate to the ui's 
 * update - to allow LAF installed painters - instead of paint) are deferred
 * to a later normal release, more discussions needed.  
 * <p>
 * 
 * @author <NAME>
 * 
 * @see #paintComponent(Graphics)
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class JRendererCheckBox extends JCheckBox implements PainterAware {
    /** the swingx painter */
    protected Painter painter;
    /** a flag to prevent ui painting from filling the background. */
    private boolean fakeTransparency;

    /**
     * Instantiates a JRendererCheckBox with opacity true.
     */
    public JRendererCheckBox() {
        super();
        // fix # 1546-swingx: striping lost in synth-based lafs
        // forcing opaque to enable painting the background
        setOpaque(true);
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public Painter getPainter() {
        return painter;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setPainter(Painter painter) {
        Painter old = getPainter();
        this.painter = painter;
        firePropertyChange("painter", old, getPainter());
    }

    /**
     * {@inheritDoc} <p>
     * 
     * Overridden to return false if painting flag is true.<p>
     * 
     */
    @Override
    public boolean isOpaque() {
        if (fakeTransparency) {
            return false;
        }
        return super.isOpaque();
    }
    
    /**
     * {@inheritDoc} <p>
     * 
     * Overridden to return false if painting flag is true.<p>
     * 
     */
     @Override
    public boolean isContentAreaFilled() {
        if (fakeTransparency) {
            return false;
        }
        return super.isContentAreaFilled();
    }

    /**
     * {@inheritDoc} <p>
     * 
     * Overridden to not automatically de/register itself from/to the ToolTipManager.
     * As rendering component it is not considered to be active in any way, so the
     * manager must not listen. 
     */
    @Override
    public void setToolTipText(String text) {
        putClientProperty(TOOL_TIP_TEXT_KEY, text);
    }

    /**
     * Overridden to snatch painting from super if a painter installed or Nimbus 
     * detected.<p>
     * 
     * The overall logic currently (since 1.6.5) is to simply call super without SwingX
     * painter. Otherwise, that is with SwingX painter:
     * <ol>
     * <li> if opaque  
     * <ol>
     * <li> set a flag which fakes transparency, that is both
     *      <code>contentAreaFilled</code> and 
     *      <code>opaque</code> return false 
     * <li> fill background with the component's background color
     * <li> apply swingx painter
     * <li> hook into <code>ui.paint(...)</code> 
     * <li> reset the flag
     * </ol>
     * <li> else
     * <ol> apply swingx painter
     * <ol> call super
     * <li> 
     * <ol> 
     * </ol>
     * 
     * Note that Nimbus is special cased (mainly due to its bug of 
     * even row striping instead of odd)
     * and handled as if a SwingX painter were set.
     * 
     */
    @Override
    protected void paintComponent(Graphics g) {
        // JW: hack around for #1178-swingx (core issue) 
        // grab painting if Nimbus detected
        if ((painter != null) || isNimbus()) {
            // we have a custom (background) painter
{'fraction_non_alphanumeric': 0.09320276497695852, 'fraction_numerical': 0.011866359447004609, 'mean_word_length': 2.5607054963084495, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, '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': '5566150', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2439, 'n_words': 924}