Package com.explodingpixels.macwidgets

Source Code of com.explodingpixels.macwidgets.ITunesRatingTableCellRenderer

package com.explodingpixels.macwidgets;

import com.explodingpixels.data.Rating;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Component;
import java.util.HashMap;
import java.util.Map;

public class ITunesRatingTableCellRenderer extends DefaultTableCellRenderer {

    private Map<Rating, RatingComponent> fRatingsToRatingComponents =
            new HashMap<Rating, RatingComponent>();

    public ITunesRatingTableCellRenderer() {
        // iterate over each value in the rating enumeration and add a
        // corresponding rating component.
        for (Rating rating : Rating.values()) {
            fRatingsToRatingComponents.put(rating, new RatingComponent(rating));
        }

    }

    @Override
    public Component getTableCellRendererComponent(
            JTable table, Object value, boolean isSelected, boolean hasFocus,
            int row, int column) {

        super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
                row, column);

        Rating rating = (Rating) value;

        // grab the cached rating component for the corresponding rating.
        RatingComponent renderer = fRatingsToRatingComponents.get(rating);
        renderer.setFocused(table.hasFocus());
        renderer.setSelected(table.isRowSelected(row));

        renderer.getComponent().setBackground(getBackground());

        return renderer.getComponent();
    }

}
TOP

Related Classes of com.explodingpixels.macwidgets.ITunesRatingTableCellRenderer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.