01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Alexander T. Simbirtsev
19: * @version $Revision$
20: */package javax.swing.border;
21:
22: import java.awt.Component;
23: import java.awt.Graphics;
24: import java.awt.Insets;
25:
26: import org.apache.harmony.x.swing.Utilities;
27:
28: public class CompoundBorder extends AbstractBorder {
29:
30: protected Border outsideBorder;
31: protected Border insideBorder;
32:
33: public CompoundBorder() {
34: }
35:
36: public CompoundBorder(final Border outside, final Border inside) {
37: insideBorder = inside;
38: outsideBorder = outside;
39: }
40:
41: public Insets getBorderInsets(final Component component,
42: final Insets insets) {
43: insets.top = 0;
44: insets.left = 0;
45: insets.right = 0;
46: insets.bottom = 0;
47:
48: if (insideBorder != null) {
49: Utilities.addInsets(insets, insideBorder
50: .getBorderInsets(component));
51: }
52: if (outsideBorder != null) {
53: Utilities.addInsets(insets, outsideBorder
54: .getBorderInsets(component));
55: }
56:
57: return insets;
58: }
59:
60: public Insets getBorderInsets(final Component component) {
61: return getBorderInsets(component, new Insets(0, 0, 0, 0));
62: }
63:
64: public void paintBorder(final Component c, final Graphics g,
65: final int x, final int y, final int width, final int height) {
66: if (outsideBorder != null) {
67: outsideBorder.paintBorder(c, g, x, y, width, height);
68: if (insideBorder != null) {
69: Insets offset = outsideBorder.getBorderInsets(c);
70: insideBorder.paintBorder(c, g, x + offset.left, y
71: + offset.top, width - offset.left
72: - offset.right, height - offset.top
73: - offset.bottom);
74: }
75: } else if (insideBorder != null) {
76: insideBorder.paintBorder(c, g, x, y, width, height);
77: }
78: }
79:
80: public Border getOutsideBorder() {
81: return outsideBorder;
82: }
83:
84: public Border getInsideBorder() {
85: return insideBorder;
86: }
87:
88: public boolean isBorderOpaque() {
89: return (insideBorder == null || insideBorder.isBorderOpaque())
90: && (outsideBorder == null || outsideBorder
91: .isBorderOpaque());
92: }
93:
94: }
|