001/* 002 * Created on 31.03.2011 003 * 004 */ 005package org.jdesktop.swingx.decorator; 006 007import java.awt.Component; 008import java.awt.ComponentOrientation; 009 010/** 011 * A Highlighter which applies the ComponentOrientation to the component. 012 * 013 * @author Jeanette Winzenburg, Berlin 014 */ 015public class ComponentOrientationHighlighter extends AbstractHighlighter { 016 017 private ComponentOrientation co; 018 019 /** 020 * Instantiates a ComponentOrientationHighlighter with <code>ComponentOrientation.LEFT_TO_RIGHT</code>. 021 * The Highlighter is applied always. 022 */ 023 public ComponentOrientationHighlighter() { 024 this((HighlightPredicate) null); 025 } 026 027 /** 028 * Instantiates a ComponentOrientationHighlighter with the given HighlightPredicate 029 * and <code>ComponentOrientation.LEFT_TO_RIGHT</code>. 030 * 031 * @param predicate the HighlightPredicate to use, may be null to default to ALWAYS. 032 */ 033 public ComponentOrientationHighlighter(HighlightPredicate predicate) { 034 this(predicate, null); 035 } 036 037 /** 038 * Instantiates a ComponentOrientationHighlighter with the given ComponentOrientation. 039 * The Highlighter is applied always. 040 * 041 * @param co the ComponentOrientation to apply 042 */ 043 public ComponentOrientationHighlighter(ComponentOrientation co) { 044 this(null, co); 045 } 046 047 /** 048 * Instantiates a ComponentOrientationHighlighter with the given ComponentOrientation and HighlightPredicate. 049 * 050 * @param predicate the HighlightPredicate to use, may be null to default to ALWAYS. 051 * @param co the ComponentOrientation to apply, may be null 052 */ 053 public ComponentOrientationHighlighter(HighlightPredicate predicate, 054 ComponentOrientation co) { 055 super(predicate); 056 setComponentOrientation(co); 057 } 058 059 /** 060 * Returns the ComponentOrientation to apply. 061 * 062 * @return the ComponentOrientation to apply, guaranteed to be not null. 063 */ 064 public ComponentOrientation getComponentOrientation() { 065 return co; 066 } 067 068 /** 069 * Sets the ComponentOrientation to apply. 070 * 071 * @param co the co to set, may be null to denote fallback to LEFT_TO_RIGHT 072 */ 073 public void setComponentOrientation(ComponentOrientation co) { 074 if (co == null) { 075 co = ComponentOrientation.LEFT_TO_RIGHT; 076 } 077 if (areEqual(this.co, co)) return; 078 this.co = co; 079 fireStateChanged(); 080 } 081 082 /** 083 * @inherited <p> 084 * Implementated to decorate the given component with the ComponentOrientation. 085 */ 086 @Override 087 protected Component doHighlight(Component component, 088 ComponentAdapter adapter) { 089 component.applyComponentOrientation(getComponentOrientation()); 090 return component; 091 } 092 093 094}