<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.Color;

import javax.swing.JComponent;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import org.jdesktop.swingx.RolloverRenderer;

/**
 * Encapsulates configuration of renderering components.
 * <p>
 * 
 * 
 * It's parameterized for both renderee (C) and rendering component(T).<p>
 * 
 * 
 * @author <NAME>
 * 
 * 
 */
public class RendererController<T extends JComponent, C extends JComponent> 
   implements RolloverRenderer {

    protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);

    private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1,
            1);

    private Color unselectedForeground;

    private Color unselectedBackground;


    private RenderingComponentController<T> componentContext;
    
    private static Border getNoFocusBorder() {
        if (System.getSecurityManager() != null) {
            return SAFE_NO_FOCUS_BORDER;
        } else {
            return noFocusBorder;
        }
    }

    /**
     * Instantiates the renderer component to the type specified
     * by the subclass.
     * 
     * @see #createRendererComponent()
     */
    public RendererController(RenderingComponentController<T> componentContext) {
        setComponentContext(componentContext);
    }

    /**
     * Configures the renderering component's content from the
     * given cell context.
     * 
     * @param context the cell context to configure from
     * 
     */
    protected void configureContent(CellContext<C> context) {
        getComponentContext().configureContent(context);
    }

    /**
     * @param componentContext the componentContext to set
     */
    protected void setComponentContext(RenderingComponentController<T> componentContext) {
        if (componentContext == null) {
            componentContext = createDefaultComponentContext();
        }
        this.componentContext = componentContext;
    }

    /**
     * @return
     */
    protected RenderingComponentController<T> createDefaultComponentContext() {
        return (RenderingComponentController<T>) new RenderingLabelController();
    }

    /**
     * @return the componentContext
     */
    protected RenderingComponentController<T> getComponentContext() {
        return componentContext;
    }
    

    /**
     * @return the rendererComponent
     */
    protected T getRendererComponent() {
        return getComponentContext().rendererComponent;
    }


    //------------------ public configuration

    /**
     * Overrides <code>JComponent.setForeground</code> to assign
     * the unselected-foreground color to the specified color.
     * 
     * @param c set the foreground color to this value
     */
    public void setForeground(Color c) {
        unselectedForeground = c;<commit_msg>hot-fix for build-failure: let default renderingController be null now it compiles, but the tests in renderer package fail (they rely on the default != null)<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.Color;

import javax.swing.JComponent;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import org.jdesktop.swingx.RolloverRenderer;

/**
 * Encapsulates configuration of renderering components.
 * <p>
 * 
 * 
 * It's parameterized for both renderee (C) and rendering component(T).<p>
 * 
 * NOTE: there's a generics problem in createDefaultRenderingController. Eclipse is
 * happy but the standard compiler barks. So it returns null for now!
 * 
 * @author <NAME>
 * 
 * 
 */
public class RendererController<T extends JComponent, C extends JComponent> 
   implements RolloverRenderer {

    protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);

    private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1,
            1);

    private Color unselectedForeground;

    private Color unselectedBackground;


    private RenderingComponentController<T> componentContext;
    
    private static Border getNoFocusBorder() {
        if (System.getSecurityManager() != null) {
            return SAFE_NO_FOCUS_BORDER;
        } else {
            return noFocusBorder;
        }
    }

    /**
     * Instantiates the renderer component to the type specified
     * by the subclass.
     * 
     * @see #createRendererComponent()
     */
    public RendererController(RenderingComponentController<T> componentContext) {
        setComponentContext(componentContext);
    }

    /**
     * Configures the renderering component's content from the
     * given cell context.
     * 
     * @param context the cell context to configure from
     * 
     */
    protected void configureContent(CellContext<C> context) {
        getComponentContext().configureContent(context);
    }

    /**
     * @param componentContext the componentContext to set
     */
    protected void setComponentContext(RenderingComponentController<T> componentContext) {
//        if (componentContext == null) {
//            componentContext = new RenderingLabelController();//createDefaultComponentContext();
//        }
        this.componentContext = componentContext;
    }

    /**
     * @return
     */
    protected RenderingComponentController<T> createDefaultComponentContext() {
        // quickfix for build failure - 
        // generics problem? Eclipse swallows the typecase but not ant nor CC 
        // this will lead to NPE in the test
        return null; //(RenderingComponentController<T>) new RenderingLabelController();
    }

    /**
     * @return the componentContext
     */
    protected RenderingComponentController<T> getComponentContext() {
        return componentContext;
    }
    

    /**
     * @return the rendererComponent
     */
    protected T getRendererComponent() {
        return getComponentContext().rendererComponent;
    }


    //------------------ public configuration

    /**
     * Overrides <code>JComponent.setForeground</code> to assign
     * the unselected-foreground color to the specified color.
     * 
     * @param c set the foreground color to this value
     */
    public void setForeground(Color c) {
        unselectedForeground = c;
{'fraction_non_alphanumeric': 0.08375062593890836, 'fraction_numerical': 0.008512769153730596, 'mean_word_length': 2.954950495049505, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '3870755', 'n_tokens_mistral': 2158, 'n_tokens_neox': 2025, 'n_words': 712}