Coverage Report - org.dishevelled.identify.IdRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
IdRenderer
100%
6/6
100%
2/2
1.5
 
 1  
 /*
 2  
 
 3  
     dsh-identify  Lightweight components for identifiable beans.
 4  
     Copyright (c) 2003-2019 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.identify;
 25  
 
 26  
 import java.awt.Component;
 27  
 
 28  
 import javax.swing.Renderer;
 29  
 
 30  
 import org.dishevelled.iconbundle.IconState;
 31  
 
 32  
 /**
 33  
  * Renderer that displays the name property value
 34  
  * and appropriate icon from an icon bundle for a given bean.
 35  
  * <p>
 36  
  * The AWT component returned by the <code>getComponent</code>
 37  
  * method is an instance of IdLabel, so the following cast is safe:
 38  
  * <pre>
 39  
  * IdRenderer renderer = new IdRenderer();
 40  
  * IdLabel rendererComponent = (IdLabel) renderer.getComponent();
 41  
  * // set properties on the IdLabel, e.g.
 42  
  * rendererComponent.setIconSize(IconSize.DEFAULT_16X16);
 43  
  * </pre>
 44  
  * <p>
 45  
  *
 46  
  * @author  Michael Heuer
 47  
  */
 48  2
 public final class IdRenderer
 49  
     implements Renderer
 50  
 {
 51  
     /** IdLabel. */
 52  2
     private final IdLabel delegate = new IdLabel();
 53  
 
 54  
 
 55  
     @Override
 56  
     public Component getComponent()
 57  
     {
 58  2
         return delegate;
 59  
     }
 60  
 
 61  
     @Override
 62  
     public void setValue(final Object value, final boolean selected)
 63  
     {
 64  16
         delegate.setValue(value);
 65  16
         delegate.setIconState(selected ? IconState.SELECTED : IconState.NORMAL);
 66  16
     }
 67  
 }