001 /* 002 * $Id: StringValue.java 3297 2009-03-11 13:45:10Z kleopatra $ 003 * 004 * Copyright 2006 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 */ 021 package org.jdesktop.swingx.renderer; 022 023 import java.io.Serializable; 024 025 026 /** 027 * A simple converter to return a String representation of an object. 028 * 029 * This class is intended to be the "small coin" to configure/format textual 030 * cell content of concrete subclasses of <code>ComponentProvider</code>. 031 * <p> 032 * 033 * F.i. to show a Contributor cell object as "Busywoman, Herta" implement a 034 * custom StringValue and use it in a text rendering provider. 035 * 036 * <pre><code> 037 * StringValue stringValue = new StringValue() { 038 * 039 * public String getString(Object value) { 040 * if (!(value instanceof Contributor)) 041 * return TO_STRING.getString(value); 042 * Contributor contributor = (Contributor) value; 043 * return contributor.lastName + ", " + contributor.firstName; 044 * } 045 * 046 * }; 047 * 048 * ComponentProvider provider = new LabelProvider(stringValue); 049 * table.setDefaultRenderer(Contributor.class, 050 * new DefaultTableRenderer(provider)); 051 * </code></pre> 052 * 053 * <p> 054 * 055 * PENDING: use a full-fledged Format instead? 056 * Would impose a higher burden onto implementors but could be re-used in 057 * editors. 058 * 059 * @author Jeanette Winzenburg 060 * 061 * @see ComponentProvider 062 * @see LabelProvider 063 * @see DefaultTableRenderer 064 * @see DefaultListRenderer 065 * @see DefaultTreeRenderer 066 */ 067 public interface StringValue extends Serializable { 068 069 /** 070 * Returns a string representation of the given value. <p> 071 * 072 * PENDING JW: forgot - why not null return guaranteed? 073 * 074 * @param value the object to present as a string 075 * @return a string representation of the given value, 076 * guaranteed to be not null 077 */ 078 String getString(Object value); 079 }