2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.ui
;
19 import com
.intellij
.util
.ui
.UIUtil
;
21 import javax
.swing
.border
.LineBorder
;
24 public class SideBorder
extends LineBorder
{
26 public static final int LEFT
= 0x01;
27 public static final int TOP
= 0x02;
28 public static final int RIGHT
= 0x04;
29 public static final int BOTTOM
= 0x08;
30 public static final int ALL
= LEFT
| TOP
| RIGHT
| BOTTOM
;
32 private final int mySideMask
;
33 private final boolean myDotted
;
35 public SideBorder(Color color
, int mask
) {
36 this(color
, mask
, false);
39 public SideBorder(Color color
, int mask
, boolean dotted
) {
45 public Insets
getBorderInsets(Component component
) {
47 (mySideMask
& TOP
) != 0 ?
getThickness() : 0,
48 (mySideMask
& LEFT
) != 0 ?
getThickness() : 0,
49 (mySideMask
& BOTTOM
) != 0 ?
getThickness() : 0,
50 (mySideMask
& RIGHT
) != 0 ?
getThickness() : 0
54 public Insets
getBorderInsets(Component component
, Insets insets
) {
55 insets
.top
= (mySideMask
& TOP
) != 0 ?
getThickness() : 0;
56 insets
.left
= (mySideMask
& LEFT
) != 0 ?
getThickness() : 0;
57 insets
.bottom
= (mySideMask
& BOTTOM
) != 0 ?
getThickness() : 0;
58 insets
.right
= (mySideMask
& RIGHT
) != 0 ?
getThickness() : 0;
62 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int width
, int height
) {
63 Color oldColor
= g
.getColor();
66 g
.setColor(getLineColor());
67 for(i
= 0; i
< getThickness(); i
++){
68 if ((mySideMask
& LEFT
) != 0){
69 drawLine(g
, x
+ i
, y
+ i
, x
+ i
, height
- i
- i
- 1);
71 if ((mySideMask
& TOP
) != 0){
72 drawLine(g
, x
+ i
, y
+ i
, width
- i
- i
- 1, y
+ i
);
74 if ((mySideMask
& RIGHT
) != 0){
75 drawLine(g
, width
- i
- i
- 1, y
+ i
, width
- i
- i
- 1, height
- i
- i
- 1);
77 if ((mySideMask
& BOTTOM
) != 0){
78 drawLine(g
, x
+ i
, height
- i
- i
- 1, width
- i
- i
- 1, height
- i
- i
- 1);
84 private void drawLine(Graphics g
, int x1
, int y1
, int x2
, int y2
) {
86 UIUtil
.drawDottedLine((Graphics2D
)g
, x1
, y1
, x2
, y2
, ((Graphics2D
)g
).getBackground(), getLineColor());
89 UIUtil
.drawLine(g
, x1
, y1
, x2
, y2
);
93 public void setLineColor(Color color
) {