001/* 002 * $Id$ 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 * 021 */ 022package org.jdesktop.swingx.decorator; 023 024import java.awt.Component; 025 026/** 027 * A Highlighter which sets the enabled property.<p> 028 * 029 * Note: the enabled is a mutable property of this Highlighter which defaults to false 030 * because we assume that's the most common use case to make a rendering component 031 * look disabled when the parent is enabled. It's mutable for symmetry reasons, though 032 * the other way round - enabled looking rendering component on a disabled parent - 033 * most probably will confuse users. 034 * 035 * @author Jeanette Winzenburg (slight cleanup) 036 * @author original contributed by swingx member martinm1000 037 */ 038public class EnabledHighlighter extends AbstractHighlighter { 039 040 private boolean enabled; 041 042 /** 043 * Instantiates a EnabledHighlighter with default enabled property (== false). 044 * The Highlighter is applied always. 045 */ 046 public EnabledHighlighter() { 047 this(null); 048 } 049 050 /** 051 * Instantiates a EnabledHighlighter with the specified enabled property. 052 * The Highlighter is applied always. 053 * 054 * @param enabled the enabled property 055 */ 056 public EnabledHighlighter(boolean enabled) { 057 this(null, enabled); 058 } 059 060 /** 061 * Instantiates a EnabledHighlighter with the specified HighlightPredicate and 062 * default enabled property (== false). 063 * @param predicate the HighlightPredicate to use, may be null to default to ALWAYS. 064 */ 065 public EnabledHighlighter(HighlightPredicate predicate) { 066 this(predicate, false); 067 } 068 069 /** 070 * Instantiates a EnabledHighlighter with the specified HighlightPredicate and 071 * default enabled property. 072 * @param predicate the HighlightPredicate to use, may be null to default to ALWAYS. 073 * @param enabled the enabled property 074 */ 075 public EnabledHighlighter(HighlightPredicate predicate, boolean enabled) { 076 super(predicate); 077 this.enabled = enabled; 078 } 079 080 081 /** 082 * Returns the enabled property. 083 * @return the enabled 084 */ 085 public boolean isEnabled() { 086 return enabled; 087 } 088 089 /** 090 * Sets the enabled property. The default value is false. 091 * 092 * @param enabled the enabled to set 093 */ 094 public void setEnabled(boolean enabled) { 095 if (isEnabled() == enabled) return; 096 this.enabled = enabled; 097 fireStateChanged(); 098 } 099 100 /** 101 * {@inheritDoc} <p> 102 * 103 * Implemented to set the rendering component's enabled property. 104 */ 105 @Override 106 protected Component doHighlight(Component renderer, ComponentAdapter adapter) { 107 renderer.setEnabled(enabled); 108 return renderer; 109 } 110 111 112}