1 package org.wcb.gui.component.border;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import org.wcb.gui.util.UIHelper;
29
30 import java.awt.BasicStroke;
31 import java.awt.Color;
32 import java.awt.Component;
33 import java.awt.GradientPaint;
34 import java.awt.Graphics;
35 import java.awt.Graphics2D;
36 import java.awt.Insets;
37 import java.awt.Paint;
38 import java.awt.RenderingHints;
39 import java.awt.Shape;
40 import java.awt.Stroke;
41 import java.awt.geom.Arc2D;
42 import java.awt.geom.Line2D;
43 import java.awt.image.BufferedImage;
44
45 import javax.swing.border.Border;
46
47
48 public class SearchFieldBorder implements Border {
49 private static final Color BOTTOM_LINE_COLOR = new Color(216, 216, 216);
50 private static final Color TOP_LINE_1_COLOR = new Color(119, 119, 119);
51 private static final Color TOP_LINE_2_COLOR = new Color(199, 199, 199);
52 private static final Color TOP_LINE_3_COLOR = new Color(241, 241, 241);
53
54 private BufferedImage lens;
55
56
57
58
59 public SearchFieldBorder() {
60 lens = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/lens.png");
61 }
62
63 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
64 int x1 = x + 8;
65 int y1 = y + height - 1;
66 int x2 = x1 + width - 14 - 8;
67 int y2 = y1;
68
69 Graphics2D g2 = (Graphics2D) g;
70 g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
71 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
72 g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
73
74 g2.drawImage(lens, null, 5, 5);
75
76 Shape s;
77
78 g.setColor(TOP_LINE_1_COLOR);
79 s = new Line2D.Double(x1, y, x2 + 1, y);
80 g2.draw(s);
81
82 Stroke oldStroke = g2.getStroke();
83 g2.setStroke(new BasicStroke(2));
84
85 g2.setColor(BOTTOM_LINE_COLOR);
86 s = new Line2D.Double(x1 - 2, y2, x2 + 4, y2);
87 g2.draw(s);
88
89 Paint oldPaint = g2.getPaint();
90 Paint p = new GradientPaint(0, 0, TOP_LINE_1_COLOR, 0, height - 6, BOTTOM_LINE_COLOR);
91 g2.setPaint(p);
92
93
94 if (!System.getProperty("os.name").startsWith("Mac OS")) {
95 s = new Arc2D.Double(0, 0, height - 2, height, 90, 180, Arc2D.OPEN);
96 g2.draw(s);
97 }
98
99 p = new GradientPaint(width - height - 2, 0, TOP_LINE_1_COLOR, width - 2, height - 6, BOTTOM_LINE_COLOR);
100 g2.setPaint(p);
101
102 s = new Arc2D.Double(width - height - 2, 0, height, height, 270, 180, Arc2D.OPEN);
103 g2.draw(s);
104
105 g2.setPaint(oldPaint);
106 g2.setStroke(oldStroke);
107
108 g.setColor(TOP_LINE_2_COLOR);
109 s = new Line2D.Double(x1 - 1, y + 1, x2 + 2, y + 1);
110 g2.draw(s);
111
112 g.setColor(TOP_LINE_3_COLOR);
113 s = new Line2D.Double(x1 - 2, y + 2, x2 + 4, y + 2);
114 g2.draw(s);
115
116 }
117
118 public Insets getBorderInsets(Component c) {
119 return new Insets(3, 24, 2, 14);
120 }
121
122 public boolean isBorderOpaque() {
123 return false;
124 }
125 }