<commit_before>/*
 * Copyright (c) 2009 <NAME> and <NAME>.
 *
 * This file is part of the SeaGlass Pluggable Look and Feel.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * $Id$
 */
package com.seaglass.painter;

import java.awt.Graphics2D;

import javax.swing.ImageIcon;
import javax.swing.JComponent;

/**
 * An abstraction of an image painter, using AbstractRegionPainter and an image
 * resource.
 * 
 * @author <NAME>
 */
public abstract class AbstractImagePainter<E> extends AbstractRegionPainter {

    private static final String IMAGE_DIR = "/com/seaglass/resources/images";

    private PaintContext        ctx;

    protected ImageIcon         image;

    public AbstractImagePainter(E state) {
        super();
        this.ctx = null;
        String imageName = getImageName(state);
        if (imageName == null) {
            throw new RuntimeException("No file was found for the state " + state);
        }

        image = getImage(imageName);
    }

    protected ImageIcon getImage(String imageName) {
        StringBuilder imagePath = new StringBuilder(IMAGE_DIR);
        imagePath.append('/');
        imagePath.append(imageName);
        imagePath.append(".png");

        return new ImageIcon(AbstractImagePainter.class.getResource(imagePath.toString()));
    }

    protected abstract String getImageName(E state);

    @Override
    protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
        image.paintIcon(c, g, 0, 0);
    }

    protected Object[] getExtendedCacheKeys(JComponent c) {
        Object[] extendedCacheKeys = new Object[] {};
        return extendedCacheKeys;
    }

    @Override
    protected final PaintContext getPaintContext() {
        return ctx;
    }
    
    protected final void setPaintContext(PaintContext ctx) {
        this.ctx = ctx;
    }
}<commit_msg>Added some comments.<commit_after>/*
 * Copyright (c) 2009 <NAME> and <NAME>.
 *
 * This file is part of the SeaGlass Pluggable Look and Feel.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * $Id$
 */
package com.seaglass.painter;

import java.awt.Graphics2D;

import javax.swing.ImageIcon;
import javax.swing.JComponent;

/**
 * An abstraction of an image painter, using AbstractRegionPainter and an image
 * resource.
 * 
 * @author <NAME>
 */
public abstract class AbstractImagePainter<E> extends AbstractRegionPainter {

    private static final String IMAGE_DIR = "/com/seaglass/resources/images";

    private PaintContext        ctx;

    protected ImageIcon         image;

    /**
     * Create a new AbstractImagePainter for the specified state.
     * 
     * @param state
     *            the state to paint.
     */
    public AbstractImagePainter(E state) {
        super();
        this.ctx = null;
        String imageName = getImageName(state);
        if (imageName == null) {
            throw new RuntimeException("No file was found for the state " + state);
        }

        image = getImage(imageName);
    }

    /**
     * Load the image based on the simple name.
     * 
     * @param imageName
     *            the simple image name.
     * @return an ImageIcon to draw.
     */
    protected ImageIcon getImage(String imageName) {
        StringBuilder imagePath = new StringBuilder(IMAGE_DIR);
        imagePath.append('/');
        imagePath.append(imageName);
        imagePath.append(".png");

        return new ImageIcon(AbstractImagePainter.class.getResource(imagePath.toString()));
    }

    /**
     * Override this to provide the image file name for a given state.
     * 
     * @param state
     *            the state to draw
     * @return the simple image name.
     */
    protected abstract String getImageName(E state);

    protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
        image.paintIcon(c, g, 0, 0);
    }

    protected Object[] getExtendedCacheKeys(JComponent c) {
        Object[] extendedCacheKeys = new Object[] {};
        return extendedCacheKeys;
    }

    protected final PaintContext getPaintContext() {
        return ctx;
    }

    protected final void setPaintContext(PaintContext ctx) {
        this.ctx = ctx;
    }
}
{'fraction_non_alphanumeric': 0.08882958444529165, 'fraction_numerical': 0.004574914220358368, 'mean_word_length': 2.7802593659942363, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4228526', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1380, 'n_words': 498}