view gnv-artifacts/src/main/java/de/intevation/gnv/raster/ExternalIndexConverter.java @ 1115:f953c9a559d8

Added license file and license headers. gnv-artifacts/trunk@1260 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:46:55 +0000
parents feae2f9d6c6f
children
line wrap: on
line source
/*
 * Copyright (c) 2010 by Intevation GmbH
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LGPL.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 */

package de.intevation.gnv.raster;

import org.apache.log4j.Logger;

/**
 * Converts the interal color index of a polygon to the external index
 * defined by the corresponding palette entry.
 *
 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
 */
public class ExternalIndexConverter
implements   JTSMultiPolygonProducer.ValueConverter
{
    private static Logger log = Logger.getLogger(
        ExternalIndexConverter.class);

    /**
     * The palette where to find the color indices.
     */
    protected Palette palette;

    /**
     * Default constructor.
     */
    public ExternalIndexConverter() {
    }

    /**
     * Constrcutor to create an ExternalIndexConverter with
     * a given palette.
     * @param palette The palette where to find the color indices.
     */
    public ExternalIndexConverter(Palette palette) {
        this.palette = palette;
    }

    /**
     * Maps the color index of a polygon to the external index
     * defined by the corresponing palette entry.
     * @param value The value to convert
     * @return The mapped value or the original value if
     * no corresponing palette entry was found.
     */
    public Integer convert(Integer value) {
        if (value == null) {
            return value;
        }

        int v = value.intValue();

        if (v == -1) {
            return value;
        }

        Palette.Entry entry = palette.getEntryByIndex(v);

        if (entry == null) {
            log.warn("cannot find palette entry for index: " + v);
            return value;
        }

        return Integer.valueOf(entry.getExternalIndex());
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org