~ubuntu-branches/ubuntu/trusty/libswingx-java/trusty

« back to all changes in this revision

Viewing changes to swingx-core/src/main/java/org/jdesktop/swingx/plaf/synth/SynthBorder.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-06 00:28:45 UTC
  • mfrom: (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110306002845-escned3cbqp5qx0t
Tags: 1:1.6.2-1
* New upstream release.
* Switch to maven as build system:
  - d/control: drop ant, add maven-debian-helper
  - d/rules: use maven.mk
* d/patches/pom.diff: drop, uneeded since upstream fixed its dependencies.
* d/watch: update to use java.net directly.
* d/rules: force debian version for JARs (Closes: #603495).
* d/copyright: Update to lastest DEP-5 r166.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id$
 
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.plaf.synth;
 
23
 
 
24
/*
 
25
 * @(#)SynthBorder.java 1.15 06/11/30
 
26
 *
 
27
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 
28
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 
29
 */
 
30
 
 
31
import java.awt.Component;
 
32
import java.awt.Graphics;
 
33
import java.awt.Insets;
 
34
 
 
35
import javax.swing.JComponent;
 
36
import javax.swing.border.AbstractBorder;
 
37
import javax.swing.plaf.UIResource;
 
38
import javax.swing.plaf.synth.SynthContext;
 
39
import javax.swing.plaf.synth.SynthStyle;
 
40
 
 
41
/**
 
42
 * SynthBorder is a border that delegates to a Painter. The Insets
 
43
 * are determined at construction time.<p>
 
44
 * 
 
45
 * Copied from core
 
46
 *
 
47
 * @version 1.15, 11/30/06
 
48
 * @author Scott Violet
 
49
 */
 
50
class SynthBorder extends AbstractBorder implements UIResource {
 
51
    private SynthUI ui;
 
52
    private Insets insets;
 
53
 
 
54
    SynthBorder(SynthUI ui, Insets insets) {
 
55
        this.ui = ui;
 
56
        this.insets = insets;
 
57
    }
 
58
 
 
59
    SynthBorder(SynthUI ui) {
 
60
        this(ui, null);
 
61
    }
 
62
 
 
63
    @Override
 
64
    public void paintBorder(Component c, Graphics g, int x, int y,
 
65
                            int width, int height) {
 
66
        JComponent jc = (JComponent)c;
 
67
        SynthContext context = ui.getContext(jc);
 
68
        SynthStyle style = context.getStyle();
 
69
        if (style == null) {
 
70
            assert false: "SynthBorder is being used outside after the UI " +
 
71
                          "has been uninstalled";
 
72
            return;
 
73
        }
 
74
        ui.paintBorder(context, g, x, y, width, height);
 
75
    }
 
76
 
 
77
    /**
 
78
     * This default implementation returns a new <code>Insets</code>
 
79
     * instance where the <code>top</code>, <code>left</code>,
 
80
     * <code>bottom</code>, and 
 
81
     * <code>right</code> fields are set to <code>0</code>.
 
82
     * @param c the component for which this border insets value applies
 
83
     * @return the new <code>Insets</code> object initialized to 0
 
84
     */
 
85
    @Override
 
86
    public Insets getBorderInsets(Component c) { 
 
87
        return getBorderInsets(c, null);
 
88
    }
 
89
 
 
90
    /** 
 
91
     * Reinitializes the insets parameter with this Border's current Insets. 
 
92
     * @param c the component for which this border insets value applies
 
93
     * @param insets the object to be reinitialized
 
94
     * @return the <code>insets</code> object
 
95
     */
 
96
    @Override
 
97
    public Insets getBorderInsets(Component c, Insets insets) {
 
98
        if (this.insets != null) {
 
99
            if (insets == null) {
 
100
                insets = new Insets(this.insets.top, this.insets.left,
 
101
                                  this.insets.bottom, this.insets.right);
 
102
            }
 
103
            else {
 
104
                insets.top    = this.insets.top;
 
105
                insets.bottom = this.insets.bottom;
 
106
                insets.left   = this.insets.left;
 
107
                insets.right  = this.insets.right;
 
108
            }
 
109
        }
 
110
        else if (insets == null) {
 
111
            insets = new Insets(0, 0, 0, 0);
 
112
        }
 
113
        else {
 
114
            insets.top = insets.bottom = insets.left = insets.right = 0;
 
115
        }
 
116
        return insets;
 
117
    }
 
118
 
 
119
    /**
 
120
     * This default implementation returns false.
 
121
     * @return false
 
122
     */
 
123
    @Override
 
124
    public boolean isBorderOpaque() {
 
125
        return false;
 
126
    }
 
127
 
 
128
}