ingo@1115: /* ingo@1115: * Copyright (c) 2010 by Intevation GmbH ingo@1115: * ingo@1115: * This program is free software under the LGPL (>=v2.1) ingo@1115: * Read the file LGPL.txt coming with the software for details ingo@1115: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1115: */ ingo@1115: sascha@484: package de.intevation.gnv.raster; sascha@484: sascha@484: import org.apache.log4j.Logger; sascha@484: sascha@484: /** sascha@802: * Converts the interal color index of a polygon to the external index sascha@802: * defined by the corresponding palette entry. sascha@803: * sascha@780: * @author Sascha L. Teichmann sascha@484: */ sascha@484: public class ExternalIndexConverter sascha@484: implements JTSMultiPolygonProducer.ValueConverter sascha@484: { sascha@484: private static Logger log = Logger.getLogger( sascha@484: ExternalIndexConverter.class); sascha@484: sascha@802: /** sascha@802: * The palette where to find the color indices. sascha@802: */ sascha@484: protected Palette palette; sascha@484: sascha@802: /** sascha@802: * Default constructor. sascha@802: */ sascha@484: public ExternalIndexConverter() { sascha@484: } sascha@484: sascha@802: /** sascha@802: * Constrcutor to create an ExternalIndexConverter with sascha@802: * a given palette. sascha@802: * @param palette The palette where to find the color indices. sascha@802: */ sascha@484: public ExternalIndexConverter(Palette palette) { sascha@484: this.palette = palette; sascha@484: } sascha@484: sascha@802: /** sascha@802: * Maps the color index of a polygon to the external index sascha@802: * defined by the corresponing palette entry. sascha@802: * @param value The value to convert sascha@802: * @return The mapped value or the original value if sascha@802: * no corresponing palette entry was found. sascha@802: */ sascha@484: public Integer convert(Integer value) { sascha@484: if (value == null) { sascha@484: return value; sascha@484: } sascha@484: sascha@484: int v = value.intValue(); sascha@484: sascha@484: if (v == -1) { sascha@484: return value; sascha@484: } sascha@484: sascha@484: Palette.Entry entry = palette.getEntryByIndex(v); sascha@484: sascha@484: if (entry == null) { sascha@484: log.warn("cannot find palette entry for index: " + v); sascha@484: return value; sascha@484: } sascha@484: sascha@484: return Integer.valueOf(entry.getExternalIndex()); sascha@484: } sascha@484: } sascha@484: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :