~ubuntu-branches/ubuntu/natty/libswingx-java/natty

« back to all changes in this revision

Viewing changes to src/java/org/jdesktop/swingx/decorator/FontHighlighter.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2010-07-26 12:11:27 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100726121127-k0d3b21nhja0dn93
Tags: 1:1.6.1-1
* New upstream release.
* Switch to 3.0 (quilt) format.
* Bump Standards-Version to 3.9.1: no changes needed.
* Drop Depends on JRE: not requested anymore by new Java Policy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: FontHighlighter.java 1164 2009-11-03 04:22:00Z kschaefe $
 
3
 *
 
4
 * Copyright 2009 Sun Microsystems, Inc., 4150 Network Circle,
 
5
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2.1 of the License, or (at your option) any later version.
 
11
 * 
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 *
 
21
 */
 
22
package org.jdesktop.swingx.decorator;
 
23
 
 
24
import java.awt.Component;
 
25
import java.awt.Font;
 
26
 
 
27
import org.jdesktop.swingx.decorator.AbstractHighlighter;
 
28
import org.jdesktop.swingx.decorator.ComponentAdapter;
 
29
import org.jdesktop.swingx.decorator.HighlightPredicate;
 
30
 
 
31
/**
 
32
 * A Highlighter which sets the Font of the component.<p>
 
33
 * 
 
34
 * @author Karl George Schaefer
 
35
 *
 
36
 */
 
37
public class FontHighlighter extends AbstractHighlighter {
 
38
    private Font font;
 
39
    
 
40
    /**
 
41
     * Instantiates a FontHighlighter with null Font. The Highlighter is 
 
42
     * applied always.
 
43
     */
 
44
    public FontHighlighter() {
 
45
        this((HighlightPredicate) null);
 
46
    }
 
47
    
 
48
    /**
 
49
     * Instantiates a FontHighlighter with the given Font. The Highlighter is 
 
50
     * applied always.
 
51
     * 
 
52
     * @param font the Font to apply
 
53
     */
 
54
    public FontHighlighter(Font font) {
 
55
        this(null, font);
 
56
    }
 
57
    
 
58
    /**
 
59
     * Instantiates a FontHighlighter with the given HighlightPredicate and null Font.
 
60
     * 
 
61
     * @param predicate the HighlightPredicate to use, may be null to default to ALWAYS.
 
62
     */
 
63
    public FontHighlighter(HighlightPredicate predicate) {
 
64
        this(predicate, null);
 
65
    }
 
66
    
 
67
    /**
 
68
     * Instantiates a FontHighlighter with the given Font and HighlightPredicate.
 
69
     * 
 
70
     * @param predicate the HighlightPredicate to use, may be null to default to ALWAYS.
 
71
     * @param font the Font to apply, may be null
 
72
     */
 
73
    public FontHighlighter(HighlightPredicate predicate, Font font) {
 
74
        super(predicate);
 
75
        this.font = font;
 
76
    }
 
77
 
 
78
    /**
 
79
     * Returns the Font used for decoration.
 
80
     * 
 
81
     * @return the Font used for decoration
 
82
     * 
 
83
     * @see #setFont(Font)
 
84
     */
 
85
    public Font getFont() {
 
86
        return font;
 
87
    }
 
88
    
 
89
    /**
 
90
     * Sets the Font used for decoration. May be null to not decorate.
 
91
     * 
 
92
     * @param font the Font used for decoration, may be null to not decorate.
 
93
     * 
 
94
     * @see #getFont()
 
95
     */
 
96
    public void setFont(Font font) {
 
97
        if (areEqual(font, getFont())) return;
 
98
        this.font = font;
 
99
        fireStateChanged();
 
100
    }
 
101
 
 
102
    /**
 
103
     * {@inheritDoc}<p>
 
104
     * 
 
105
     * Implemented to return false if the font property is null.
 
106
     */
 
107
    @Override
 
108
    protected boolean canHighlight(Component component, ComponentAdapter adapter) {
 
109
        return font != null;
 
110
    }
 
111
    
 
112
    /**
 
113
     * {@inheritDoc}<p>
 
114
     * 
 
115
     * Implemented to set the component's Font.
 
116
     */
 
117
    @Override
 
118
    protected Component doHighlight(Component component, ComponentAdapter adapter) {
 
119
        component.setFont(font);
 
120
        return component;
 
121
    }
 
122
}