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.
16 package com
.intellij
.ui
;
18 import com
.intellij
.util
.ui
.UIUtil
;
20 import javax
.swing
.border
.LineBorder
;
24 * @author Eugene Zhuravlev
26 public class OneSideRoundedLineBorder
extends LineBorder
{
27 private final int myArcSize
;
28 private final int myRadius
;
29 private boolean myIsTopRounded
;
30 private boolean myIsBottomRounded
;
31 private boolean myDrawDottedAngledSide
;
32 private static final float[] DASH
= new float[]{0, 2, 0, 2};
35 public OneSideRoundedLineBorder(Color color
, int arcSize
) {
36 this(color
, arcSize
, 1, true, false, false);
39 public OneSideRoundedLineBorder(Color color
, int arcSize
, int thickness
, boolean isTopRounded
, boolean isBottomRounded
, boolean drawDottedAngledSide
) {
40 super(color
, thickness
);
42 myIsTopRounded
= isTopRounded
;
43 myIsBottomRounded
= isBottomRounded
;
44 myRadius
= myArcSize
/ 2;
45 myDrawDottedAngledSide
= drawDottedAngledSide
;
49 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int width
, int height
) {
50 final Graphics2D g2
= (Graphics2D
) g
;
52 final Object oldAntialiasing
= g2
.getRenderingHint(RenderingHints
.KEY_ANTIALIASING
);
53 g2
.setRenderingHint(RenderingHints
.KEY_ANTIALIASING
, RenderingHints
.VALUE_ANTIALIAS_ON
);
54 final Color oldColor
= g2
.getColor();
55 g2
.setColor(lineColor
);
57 for (int idx
= 0; idx
< thickness
; idx
++) {
58 final int correctedHeight
= height
- idx
- idx
- 1;
59 final int correctedWidth
= width
- idx
- idx
- 1;
60 final int startX
= x
+ idx
;
61 final int startY
= y
+ idx
;
63 if (myIsTopRounded
&& myIsBottomRounded
) {
64 g2
.drawRoundRect(startX
, startY
, correctedWidth
, correctedHeight
, myArcSize
, myArcSize
);
66 else if (myIsTopRounded
){
67 UIUtil
.drawLine(g2
, startX
+ myRadius
, startY
, startX
+ correctedWidth
- myRadius
, startY
); // top
68 if (myDrawDottedAngledSide
) {
69 drawDottedLine(g2
, startX
, startY
+ correctedHeight
, startX
+ correctedWidth
, startY
+ correctedHeight
); // bottom
72 UIUtil
.drawLine(g2
, startX
, startY
+ correctedHeight
, startX
+ correctedWidth
, startY
+ correctedHeight
); // bottom
74 g2
.drawArc(startX
, startY
, myArcSize
, myArcSize
, 90, 90);
75 g2
.drawArc(startX
+ correctedWidth
- myArcSize
, startY
, myArcSize
, myArcSize
, 0, 90);
76 UIUtil
.drawLine(g2
, startX
, startY
+ myRadius
+ 1, startX
, startY
+ correctedHeight
); // left
77 UIUtil
.drawLine(g2
, startX
+ correctedWidth
, startY
+ myRadius
+ 1, startX
+ correctedWidth
, startY
+ correctedHeight
); // right
79 else if (myIsBottomRounded
) {
83 g2
.drawRect(startX
, startY
, correctedWidth
, correctedHeight
);
87 g2
.setColor(oldColor
);
88 g2
.setRenderingHint(RenderingHints
.KEY_ANTIALIASING
, oldAntialiasing
);
91 private void drawDottedLine(Graphics2D g
, int x1
, int y1
, int x2
, int y2
) {
92 final Stroke saved
= g
.getStroke();
93 g
.setStroke(new BasicStroke(1, BasicStroke
.CAP_ROUND
, BasicStroke
.JOIN_ROUND
, 0, DASH
, y1
% 2));
95 UIUtil
.drawLine(g
, x1
, y1
, x2
, y2
);