001/* 002 * $Id: MappedValues.java 3882 2010-11-05 09:24:37Z kleopatra $ 003 * 004 * Copyright 2009 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021package org.jdesktop.swingx.renderer; 022 023import javax.swing.Icon; 024import javax.swing.plaf.UIResource; 025 026/** 027 * A collection of common {@code MappedValue} implementations. 028 * 029 * @author kschaefer 030 */ 031public final class MappedValues { 032 /** 033 * A {@code MappedValue} that returns either a {@code String} or {@code Icon}, but not both. 034 */ 035 @SuppressWarnings("serial") 036 public static final MappedValue STRING_OR_ICON_ONLY = new MappedValue(new StringValue() { 037 @Override 038 public String getString(Object value) { 039 if (value instanceof Icon) { 040 return StringValues.EMPTY.getString(value); 041 } 042 043 return StringValues.TO_STRING.getString(value); 044 } 045 }, IconValues.ICON); 046 047 /** 048 * MappedValue wrapper of type UIResource to tag LAF installed converters. 049 * 050 * @author (Jeanette Winzenburg, Berlin 051 */ 052 public static class MappedValueUIResource extends MappedValue implements UIResource { 053 054 public MappedValueUIResource(MappedValue delegate) { 055 this(delegate, delegate, delegate); 056 } 057 058 /** 059 * @param stringDelegate 060 * @param iconDelegate 061 * @param booleanDelegate 062 */ 063 public MappedValueUIResource(StringValue stringDelegate, 064 IconValue iconDelegate, BooleanValue booleanDelegate) { 065 super(stringDelegate, iconDelegate, booleanDelegate); 066 } 067 068 /** 069 * @param stringDelegate 070 * @param iconDelegate 071 */ 072 public MappedValueUIResource(StringValue stringDelegate, 073 IconValue iconDelegate) { 074 super(stringDelegate, iconDelegate); 075 } 076 077 } 078 079 private MappedValues() { 080 //prevent instantiation 081 } 082}