changedUpdate exception
[fedora-idea.git] / platform / platform-impl / src / com / intellij / ui / SeparatorComponent.java
blobae20a803a5327a41720ad52e7e800cc51ce8eaf7
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 javax.swing.*;
19 import java.awt.*;
21 public class SeparatorComponent extends JComponent {
22 private int myVGap = 3;
23 private Color myColor = Color.lightGray;
24 private Color myShadow = new Color(240, 240, 240);
25 private int myHGap = 1;
26 private SeparatorOrientation myOrientation = SeparatorOrientation.HORIZONTAL;
28 public SeparatorComponent() {
32 public SeparatorComponent(int aVerticalGap) {
33 myVGap = aVerticalGap;
34 setBorder(BorderFactory.createEmptyBorder(myVGap, 0, myVGap, 0));
37 public SeparatorComponent(int aVerticalGap, Color aColor, Color aShadowColor) {
38 this(aVerticalGap, 1, aColor, aShadowColor);
41 public SeparatorComponent(int aVerticalGap, int horizontalGap, Color aColor, Color aShadowColor) {
42 myVGap = aVerticalGap;
43 myHGap = horizontalGap;
44 myColor = aColor;
45 myShadow = aShadowColor;
46 setBorder(BorderFactory.createEmptyBorder(myVGap, 0, myVGap, 0));
49 public SeparatorComponent(Color color, SeparatorOrientation orientation) {
50 myColor = color;
51 myOrientation = orientation;
52 myShadow = null;
53 myHGap = 0;
54 myVGap = 0;
57 protected void paintComponent(Graphics g) {
58 if (!isVisible()) return;
60 if (myColor == null) return;
62 g.setColor(myColor);
63 if (myOrientation != SeparatorOrientation.VERTICAL) {
64 g.drawLine(myHGap, myVGap, getWidth() - myHGap - 1, myVGap);
65 if (myShadow != null) {
66 g.setColor(myShadow);
67 g.drawLine(myHGap + 1, myVGap + 1, getWidth() - myHGap, myVGap + 1);
69 } else {
70 g.drawLine(myHGap, myVGap, myHGap, getHeight() - myVGap - 1);
71 if (myShadow != null) {
72 g.setColor(myShadow);
73 g.drawLine(myHGap + 1, myVGap + 1, myHGap + 1, getHeight() - myVGap);
79 public Dimension getPreferredSize() {
80 if (myOrientation != SeparatorOrientation.VERTICAL)
81 return new Dimension(0, myVGap * 2 + 1);
82 else
83 return new Dimension(myHGap * 2 + 1, 1 + ((myShadow != null) ? 1 : 0));
86 public Dimension getMinimumSize() {
87 return getPreferredSize();
90 /**
91 * Create control what consist of label with <strong>title</strong> text in the left side and single line at all rest space.
92 * @param titleText text for a label.
93 * @param containerBackgroungColor background color of container in that control will be putted on.
95 public static JComponent createLabbeledLineSeparator(final String titleText, final Color containerBackgroungColor) {
96 JLabel titleLabel = new JLabel(titleText);
97 titleLabel.setFont(UIManager.getFont("Label.font"));
98 titleLabel.setForeground(Colors.DARK_BLUE);
100 SeparatorComponent separatorComponent = new SeparatorComponent(5, containerBackgroungColor.darker(), containerBackgroungColor.brighter());
102 int hgap = titleText.length() > 0 ? 5 : 0;
103 JPanel result = new JPanel(new BorderLayout(hgap, 10));
104 result.add(titleLabel, BorderLayout.WEST);
105 result.add(separatorComponent, BorderLayout.CENTER);
107 return result;