1 /*
2 * Copyright (c) 2007 Creative Sphere Limited.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *
10 * Creative Sphere - initial API and implementation
11 *
12 */
13 package org.abstracthorizon.aequo.gui;
14
15 import java.awt.Color;
16 import java.awt.Component;
17 import java.awt.Graphics;
18
19 import javax.swing.border.EmptyBorder;
20
21 /**
22 * Border used for focus that can be easily manipulated.
23 *
24 * @author Daniel Sendula
25 */
26 public class LineBorder extends EmptyBorder {
27
28 /** Line colour */
29 protected Color color = Color.BLACK;
30
31 /**
32 * Constructor
33 * @param top top line thickness
34 * @param left left line thickness
35 * @param bottom bottom line thickness
36 * @param right right line thickness
37 */
38 public LineBorder(int top, int left, int bottom, int right) {
39 super(top, left, bottom, right);
40 }
41
42 /**
43 * Constructor
44 * @param color colour
45 * @param top top line thickness
46 * @param left left line thickness
47 * @param bottom bottom line thickness
48 * @param right right line thickness
49 */
50 public LineBorder(Color color, int top, int left, int bottom, int right) {
51 super(top, left, bottom, right);
52 }
53
54 /**
55 * Returns false
56 * @return false
57 */
58 public boolean isBorderOpaque() { return false; }
59
60 /**
61 * Paints border
62 * @param c component
63 * @param g graphics
64 * @param x x
65 * @param y y
66 * @param width width
67 * @param height height
68 */
69 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
70 int w = width - 1;
71 int h = height - 1;
72
73 Color oldColor = g.getColor();
74 g.setColor(color);
75
76 g.translate(x, y);
77
78 if (top == 1) {
79 g.drawLine(0, 0, w, 0);
80 } else if (top > 1) {
81 g.fillRect(0, 0, w, top);
82 }
83 if (left == 1) {
84 g.drawLine(0, 0, 0, h);
85 } else if (left > 1) {
86 g.fillRect(0, 0, left, h);
87 }
88
89 if (right == 1) {
90 g.drawLine(w, 0, w, h);
91 } else if (right > 1) {
92 g.fillRect(w - right, 0, w, h);
93 }
94
95 if (bottom == 1) {
96 g.drawLine(0, h, w, h);
97 } else if (bottom > 1) {
98 g.fillRect(0, h - bottom, w, h);
99 }
100 g.translate(-x, -y);
101 g.setColor(oldColor);
102 }
103
104 }