001 /* 002 * $Id: AbstractRenderer.java 3166 2009-01-02 13:27:18Z rah003 $ 003 * 004 * Copyright 2007 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.awt.Color; 024 import java.io.Serializable; 025 026 import org.jdesktop.swingx.rollover.RolloverRenderer; 027 028 /** 029 * Convience common ancestor for SwingX renderers. 030 * 031 * @author Jeanette Winzenburg 032 */ 033 public abstract class AbstractRenderer 034 implements RolloverRenderer, StringValue, Serializable { 035 036 protected ComponentProvider componentController; 037 038 public AbstractRenderer(ComponentProvider provider) { 039 if (provider == null) { 040 provider = createDefaultComponentProvider(); 041 } 042 this.componentController = provider; 043 } 044 045 /** 046 * Returns the ComponentProvider used by this renderer. 047 * 048 * @return the ComponentProvider used by this renderer 049 */ 050 public ComponentProvider getComponentProvider() { 051 return componentController; 052 } 053 054 /** 055 * The default ComponentProvider to use if no special. 056 * 057 * @return the default <code>ComponentProvider</code> 058 */ 059 protected abstract ComponentProvider createDefaultComponentProvider(); 060 061 // --------------- implement StringValue 062 063 /** 064 * {@inheritDoc} 065 */ 066 public String getString(Object value) { 067 return componentController.getString(value); 068 } 069 070 // ------------ implement RolloverRenderer 071 072 /** 073 * {@inheritDoc} 074 */ 075 public void doClick() { 076 if (isEnabled()) { 077 ((RolloverRenderer) componentController).doClick(); 078 } 079 } 080 081 /** 082 * {@inheritDoc} 083 */ 084 public boolean isEnabled() { 085 return (componentController instanceof RolloverRenderer) 086 && ((RolloverRenderer) componentController).isEnabled(); 087 } 088 089 090 //-------------------- legacy: configure arbitrary visuals 091 /** 092 * @param background 093 */ 094 public void setBackground(Color background) { 095 componentController.getDefaultVisuals().setBackground(background); 096 097 } 098 099 /** 100 * @param foreground 101 */ 102 public void setForeground(Color foreground) { 103 componentController.getDefaultVisuals().setForeground(foreground); 104 } 105 106 107 }