nice dotted border
[fedora-idea.git] / platform / util / src / com / intellij / ui / PopupBorder.java
blob1eff0a8775229f732fa7b6d5961f0fc87fb3f8a0
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.
16 package com.intellij.ui;
18 import com.intellij.openapi.util.SystemInfo;
20 import javax.swing.border.Border;
21 import java.awt.*;
23 public interface PopupBorder extends Border {
25 void setActive(boolean active);
27 class Factory {
29 private Factory() {
32 public static PopupBorder create(boolean active) {
33 final BaseBorder border =
34 SystemInfo.isMac ? new BaseBorder() : new BaseBorder(true, CaptionPanel.getBorderColor(true), CaptionPanel.getBorderColor(false));
35 border.setActive(active);
36 return border;
40 class BaseBorder implements PopupBorder {
42 private boolean myVisible;
43 private Color myActiveColor;
44 private Color myPassiveColor;
46 private boolean myActive;
48 protected BaseBorder() {
49 this(false, null, null);
52 protected BaseBorder(final boolean visible, final Color activeColor, final Color passiveColor) {
53 myVisible = visible;
54 myActiveColor = activeColor;
55 myPassiveColor = passiveColor;
58 public void setActive(final boolean active) {
59 myActive = active;
62 public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) {
63 if (!myVisible) return;
65 Color color = myActive ? myActiveColor : myPassiveColor;
66 g.setColor(color);
67 g.drawRect(x, y, width - 1, height - 1);
70 public Insets getBorderInsets(final Component c) {
71 return myVisible ? new Insets(1, 1, 1, 1) : new Insets(0, 0, 0, 0);
74 public boolean isBorderOpaque() {
75 return true;