3a0a70c2a328f4b40c858b1ba1a3a46c8faee9aa
[fedora-idea.git] / platform / util / src / com / intellij / ui / SideBorder.java
blob3a0a70c2a328f4b40c858b1ba1a3a46c8faee9aa
1 /*
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;
22 import java.awt.*;
24 public class SideBorder extends LineBorder {
25 public static final int LEFT = 0x01;
26 public static final int TOP = 0x02;
27 public static final int RIGHT = 0x04;
28 public static final int BOTTOM = 0x08;
29 public static final int ALL = LEFT | TOP | RIGHT | BOTTOM;
30 private final int mySideMask;
32 public SideBorder(Color color, int mask) {
33 super(color, 1);
34 mySideMask = mask;
37 public Insets getBorderInsets(Component component) {
38 return new Insets(
39 (mySideMask & TOP) != 0 ? getThickness() : 0,
40 (mySideMask & LEFT) != 0 ? getThickness() : 0,
41 (mySideMask & BOTTOM) != 0 ? getThickness() : 0,
42 (mySideMask & RIGHT) != 0 ? getThickness() : 0
46 public Insets getBorderInsets(Component component, Insets insets) {
47 insets.top = (mySideMask & TOP) != 0 ? getThickness() : 0;
48 insets.left = (mySideMask & LEFT) != 0 ? getThickness() : 0;
49 insets.bottom = (mySideMask & BOTTOM) != 0 ? getThickness() : 0;
50 insets.right = (mySideMask & RIGHT) != 0 ? getThickness() : 0;
51 return insets;
54 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
55 Color oldColor = g.getColor();
56 int i;
58 g.setColor(getLineColor());
59 for(i = 0; i < getThickness(); i++){
60 if ((mySideMask & LEFT) != 0){
61 UIUtil.drawLine(g, x + i, y + i, x + i, height - i - i - 1);
63 if ((mySideMask & TOP) != 0){
64 UIUtil.drawLine(g, x + i, y + i, width - i - i - 1, y + i);
66 if ((mySideMask & RIGHT) != 0){
67 UIUtil.drawLine(g, width - i - i - 1, y + i, width - i - i - 1, height - i - i - 1);
69 if ((mySideMask & BOTTOM) != 0){
70 UIUtil.drawLine(g, x + i, height - i - i - 1, width - i - i - 1, height - i - i - 1);
73 g.setColor(oldColor);
76 public void setLineColor(Color color) {
77 lineColor = color;