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
.plaf
.beg
;
18 import com
.intellij
.util
.ui
.UIUtil
;
21 import javax
.swing
.border
.AbstractBorder
;
22 import javax
.swing
.border
.Border
;
23 import javax
.swing
.border
.LineBorder
;
24 import javax
.swing
.plaf
.BorderUIResource
;
25 import javax
.swing
.plaf
.UIResource
;
26 import javax
.swing
.plaf
.basic
.BasicBorders
;
27 import javax
.swing
.plaf
.metal
.MetalLookAndFeel
;
28 import javax
.swing
.text
.JTextComponent
;
32 * @author Eugene Belyaev
34 public class BegBorders
{
35 private static Border ourButtonBorder
;
36 private static Border ourTextFieldBorder
;
37 private static Border ourScrollPaneBorder
;
39 public static Border
getButtonBorder() {
40 if (ourButtonBorder
== null) {
41 ourButtonBorder
= new BorderUIResource
.CompoundBorderUIResource(
43 new BasicBorders
.MarginBorder());
45 return ourButtonBorder
;
48 public static Border
getTextFieldBorder() {
49 if (ourTextFieldBorder
== null) {
50 ourTextFieldBorder
= new BorderUIResource
.CompoundBorderUIResource(
51 new TextFieldBorder(),
52 //new FlatLineBorder(),
53 BorderFactory
.createEmptyBorder(2, 2, 2, 2));
55 return ourTextFieldBorder
;
58 public static Border
getScrollPaneBorder() {
59 if (ourScrollPaneBorder
== null) {
60 ourScrollPaneBorder
= new BorderUIResource
.LineBorderUIResource(MetalLookAndFeel
.getControlDarkShadow());
61 //ourScrollPaneBorder = new FlatLineBorder();
63 return ourScrollPaneBorder
;
67 public static class FlatLineBorder
extends LineBorder
implements UIResource
{
68 public FlatLineBorder() {
69 super(new Color(127, 157, 185), 1, true);
73 public static class ButtonBorder
extends AbstractBorder
implements UIResource
{
74 protected static Insets borderInsets
= new Insets(3, 3, 3, 3);
76 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
, int h
) {
77 AbstractButton button
= (AbstractButton
) c
;
78 ButtonModel model
= button
.getModel();
80 if (model
.isEnabled()) {
81 boolean isPressed
= model
.isPressed() && model
.isArmed();
82 boolean isDefault
= (button
instanceof JButton
&& ((JButton
) button
).isDefaultButton());
84 if (isPressed
&& isDefault
) {
85 drawDefaultButtonPressedBorder(g
, x
, y
, w
, h
);
86 } else if (isPressed
) {
87 drawPressed3DBorder(g
, x
, y
, w
, h
);
88 } else if (isDefault
) {
89 drawDefaultButtonBorder(g
, x
, y
, w
, h
, false);
91 drawButtonBorder(g
, x
, y
, w
, h
, false);
93 } else { // disabled state
94 drawDisabledBorder(g
, x
, y
, w
- 1, h
- 1);
98 public Insets
getBorderInsets(Component c
) {
102 public Insets
getBorderInsets(Component c
, Insets newInsets
) {
103 newInsets
.top
= borderInsets
.top
;
104 newInsets
.left
= borderInsets
.left
;
105 newInsets
.bottom
= borderInsets
.bottom
;
106 newInsets
.right
= borderInsets
.right
;
111 public static class ScrollPaneBorder
extends AbstractBorder
implements UIResource
{
112 private static final Insets insets
= new Insets(1, 1, 2, 2);
114 public void paintBorder(Component c
, Graphics g
, int x
, int y
,
116 JScrollPane scroll
= (JScrollPane
) c
;
117 JComponent colHeader
= scroll
.getColumnHeader();
118 int colHeaderHeight
= 0;
119 if (colHeader
!= null)
120 colHeaderHeight
= colHeader
.getHeight();
122 JComponent rowHeader
= scroll
.getRowHeader();
123 int rowHeaderWidth
= 0;
124 if (rowHeader
!= null)
125 rowHeaderWidth
= rowHeader
.getWidth();
130 g.setColor(MetalLookAndFeel.getControlDarkShadow());
131 g.drawRect(0, 0, w - 2, h - 2);
132 g.setColor(MetalLookAndFeel.getControlHighlight());
134 g.drawLine(w - 1, 1, w - 1, h - 1);
135 g.drawLine(1, h - 1, w - 1, h - 1);
137 g.setColor(MetalLookAndFeel.getControl());
138 if (colHeaderHeight > 0) {
139 g.drawLine(w - 2, 2 + colHeaderHeight, w - 2, 2 + colHeaderHeight);
141 if (rowHeaderWidth > 0) {
142 g.drawLine(1 + rowHeaderWidth, h - 2, 1 + rowHeaderWidth, h - 2);
148 drawLineBorder(g
, x
, y
, w
, h
);
151 public Insets
getBorderInsets(Component c
) {
156 public static class TextFieldBorder
/*extends MetalBorders.Flush3DBorder*/ extends LineBorder
implements UIResource
{
157 public TextFieldBorder() {
161 public boolean isBorderOpaque() {
165 public void paintBorder(Component c
, Graphics g
, int x
, int y
,
167 if (!(c
instanceof JTextComponent
)) {
168 // special case for non-text components (bug ID 4144840)
170 drawFlush3DBorder(g
, x
, y
, w
, h
);
172 drawDisabledBorder(g
, x
, y
, w
, h
);
177 if (c
.isEnabled() && ((JTextComponent
) c
).isEditable()) {
178 drawLineBorder(g
, x
, y
, w
, h
);
181 g.setColor(MetalLookAndFeel.getControlDarkShadow());
182 g.drawLine(1, 0, w - 2, 0);
183 g.drawLine(0, 1, 0, h - 2);
184 g.drawLine(w - 1, 1, w - 1, h - 2);
185 g.drawLine(1, h - 1, w - 2, h - 1);
190 drawDisabledBorder(g
, x
, y
, w
, h
);
195 static void drawLineBorder(Graphics g
, int x
, int y
, int w
, int h
) {
197 g
.setColor(MetalLookAndFeel
.getControlDarkShadow());
198 g
.drawRect(0, 0, w
- 1, h
- 1);
202 static void drawFlush3DBorder(Graphics g
, int x
, int y
, int w
, int h
) {
204 g
.setColor(MetalLookAndFeel
.getControlHighlight());
205 g
.drawRect(1, 1, w
- 2, h
- 2);
206 g
.setColor(MetalLookAndFeel
.getControlDarkShadow());
207 g
.drawRect(0, 0, w
- 2, h
- 2);
211 static void drawDisabledBorder(Graphics g
, int x
, int y
, int w
, int h
) {
213 g
.setColor(MetalLookAndFeel
.getControlShadow());
214 g
.drawRect(0, 0, w
- 1, h
- 1);
218 static void drawDefaultButtonPressedBorder(Graphics g
, int x
, int y
, int w
, int h
) {
219 drawPressed3DBorder(g
, x
+ 1, y
+ 1, w
- 1, h
- 1);
221 g
.setColor(MetalLookAndFeel
.getControlDarkShadow());
222 g
.drawRect(0, 0, w
- 3, h
- 3);
223 UIUtil
.drawLine(g
, w
- 2, 0, w
- 2, 0);
224 UIUtil
.drawLine(g
, 0, h
- 2, 0, h
- 2);
228 static void drawPressed3DBorder(Graphics g
, int x
, int y
, int w
, int h
) {
231 drawFlush3DBorder(g
, 0, 0, w
, h
);
233 g
.setColor(MetalLookAndFeel
.getControlShadow());
234 UIUtil
.drawLine(g
, 1, 1, 1, h
- 1);
235 UIUtil
.drawLine(g
, 1, 1, w
- 1, 1);
239 static void drawDefaultButtonBorder(Graphics g
, int x
, int y
, int w
, int h
, boolean active
) {
240 drawButtonBorder(g
, x
+ 1, y
+ 1, w
- 1, h
- 1, active
);
242 g
.setColor(MetalLookAndFeel
.getControlDarkShadow());
243 g
.drawRect(0, 0, w
- 3, h
- 3);
244 UIUtil
.drawLine(g
, w
- 2, 0, w
- 2, 0);
245 UIUtil
.drawLine(g
, 0, h
- 2, 0, h
- 2);
249 static void drawButtonBorder(Graphics g
, int x
, int y
, int w
, int h
, boolean active
) {
251 drawActiveButtonBorder(g
, x
, y
, w
, h
);
253 drawFlush3DBorder(g
, x
, y
, w
, h
);
255 drawLineBorder(g, x, y, w - 1, h - 1);
256 g.setColor(MetalLookAndFeel.getControlHighlight());
257 g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
258 g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
263 static void drawActiveButtonBorder(Graphics g
, int x
, int y
, int w
, int h
) {
264 drawFlush3DBorder(g
, x
, y
, w
, h
);
265 g
.setColor(MetalLookAndFeel
.getPrimaryControl());
266 UIUtil
.drawLine(g
, x
+ 1, y
+ 1, x
+ 1, h
- 3);
267 UIUtil
.drawLine(g
, x
+ 1, y
+ 1, w
- 3, x
+ 1);
268 g
.setColor(MetalLookAndFeel
.getPrimaryControlDarkShadow());
269 UIUtil
.drawLine(g
, x
+ 2, h
- 2, w
- 2, h
- 2);
270 UIUtil
.drawLine(g
, w
- 2, y
+ 2, w
- 2, h
- 2);