001    /*
002     * $Id: MappedValue.java 3100 2008-10-14 22:33:10Z rah003 $
003     *
004     * Copyright 2008 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 javax.swing.Icon;
024    
025    /**
026     * Compound implementation of XXValue. Currently, XX stands for String, 
027     * Icon, Boolean. <p>
028     * 
029     * Quick hack around #590-swingx: LabelProvider should respect StringValue
030     * when formatting (instead of going clever with icons).
031     * 
032     * Note: this will change!
033     * 
034     * @see CheckBoxProvider
035     */
036    public class MappedValue implements StringValue, IconValue, BooleanValue {
037    
038        private StringValue stringDelegate;
039        private IconValue iconDelegate;
040        private BooleanValue booleanDelegate;
041    
042        public MappedValue(StringValue stringDelegate, IconValue iconDelegate) {
043            this(stringDelegate, iconDelegate, null);
044        }
045        
046        public MappedValue(StringValue stringDelegate, IconValue iconDelegate, 
047                BooleanValue booleanDelegate) {
048            this.stringDelegate = stringDelegate;
049            this.iconDelegate = iconDelegate;
050            this.booleanDelegate = booleanDelegate;
051        }
052        
053        /**
054         * {@inheritDoc}<p>
055         * 
056         * This implementation delegates to the contained StringValue if available or
057         * returns an empty String, if not.
058         *  
059         */
060        public String getString(Object value) {
061            if (stringDelegate != null) {
062                return stringDelegate.getString(value);
063            }
064            return "";
065        }
066    
067        /**
068         * {@inheritDoc}<p>
069         * 
070         * This implementation delegates to the contained IconValue if available or
071         * returns null, if not.
072         *  
073         */
074        public Icon getIcon(Object value) {
075            if (iconDelegate != null) {
076                return iconDelegate.getIcon(value);
077            }
078            return null;
079        }
080        
081        /**
082         * {@inheritDoc}<p>
083         * 
084         * This implementation delegates to the contained BooleanValue if available or
085         * returns false, if not.
086         *  
087         */
088        public boolean getBoolean(Object value) {
089            if (booleanDelegate != null) {
090                return booleanDelegate.getBoolean(value);
091            }
092            return false;
093        }
094        
095    }