All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.wizard.dcca.client.view.DecoderIconCellRenderer Maven / Gradle / Ivy

There is a newer version: 2.0.29
Show newest version
package org.bidib.wizard.dcca.client.view;

import java.awt.Component;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

import org.bidib.jbidibc.messages.DccAInfoShortGui;
import org.bidib.wizard.common.utils.ImageUtils;

public class DecoderIconCellRenderer extends DefaultTableCellRenderer {

    private static final long serialVersionUID = 1L;

    private static final Integer FALLBACK_ICON_INDEX_STEAMLOCO = 0;

    private static final Integer FALLBACK_ICON_INDEX_DIESELLOCO = 1;

    private static final Integer FALLBACK_ICON_INDEX_ELECTRICLOCO = 2;

    private static final Integer FALLBACK_ICON_INDEX_DIESELTRAINSET = 3;

    private static final Integer FALLBACK_ICON_INDEX_ELECTRICTRAINSET = 4;

    private static final Integer FALLBACK_ICON_INDEX_CONTROLCAR = 5;

    private static final Integer FALLBACK_ICON_INDEX_PASSENGERCAR = 6;

    private static final Integer FALLBACK_ICON_INDEX_LOCODECODER = 7;

    private static final Integer FALLBACK_ICON_INDEX_FUNCTIONDECODER = 8;

    private static final Integer FALLBACK_ICON_INDEX_ACCESSORYDECODER = 9;

    private static final Integer FALLBACK_ICON_INDEX_SIGNALDECODER = 10;

    private static final Integer FALLBACK_ICON_INDEX_TURNTABLEDECODER = 11;

    private static final Integer FALLBACK_ICON_INDEX_LIGHTS = 12;

    private static final Integer FALLBACK_ICON_INDEX_CAR = 13;

    private static final Integer FALLBACK_ICON_INDEX_TRUCK_BUS = 14;

    private static final Integer FALLBACK_ICON_INDEX_OTHER = 15;

    Map fallbackIcons;

    public DecoderIconCellRenderer() {

        fallbackIcons = new LinkedHashMap<>();
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_STEAMLOCO,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/steam-loco-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_DIESELLOCO,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/diesel-loco-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_ELECTRICLOCO, ImageUtils
                .createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/electric-loco-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_DIESELTRAINSET,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_ELECTRICTRAINSET,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_CONTROLCAR,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_PASSENGERCAR,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_LOCODECODER,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_FUNCTIONDECODER,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_ACCESSORYDECODER,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_SIGNALDECODER,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_TURNTABLEDECODER,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_LIGHTS,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_CAR,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/car-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_TRUCK_BUS,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/bus-32x32.png", 16, 16));
        fallbackIcons
            .put(FALLBACK_ICON_INDEX_OTHER,
                ImageUtils.createImageIcon(DecoderIconCellRenderer.class, "/icons/dcca/trainset-32x32.png", 16, 16));

        setHorizontalAlignment(SwingConstants.CENTER);
    }

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

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

        if (value instanceof DccAInfoShortGui) {
            DccAInfoShortGui shortGui = (DccAInfoShortGui) value;
            long lookupImageIndex = shortGui.getLookupImageIndex();
            if (lookupImageIndex > 0) {
                // TODO prepare the lookup image index
                setIcon(null);
                setToolTipText(null);
            }
            else {
                int fallbackIndex = shortGui.getFallbackIconIndex();

                Icon icon = fallbackIcons.get(fallbackIndex);
                setIcon(icon);
            }
            // setToolTipText(fallbackIndex.toString());
        }
        else {
            setIcon(null);
            setToolTipText(null);
        }

        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy