1 package org.wcb.gui.component.border;
2
3 import org.wcb.gui.util.UIHelper;
4
5 import javax.swing.border.AbstractBorder;
6 import java.awt.image.BufferedImage;
7 import java.awt.Component;
8 import java.awt.Graphics;
9 import java.awt.Insets;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class BookBorder extends AbstractBorder {
38
39 private BufferedImage topImg;
40 private BufferedImage bottomImg;
41 private BufferedImage rightImg;
42 private BufferedImage topRightImg;
43 private BufferedImage bottomRightImg;
44 private BufferedImage leftSideImg;
45 private BufferedImage topLeftImg;
46 private BufferedImage bottomLeftImg;
47
48
49
50
51 public BookBorder() {
52 bottomImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/bottom.jpg");
53 topImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/top.jpg");
54 rightImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/rightside.jpg");
55 topRightImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/top-right-corner.jpg");
56 bottomRightImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/bottom-right-corner.jpg");
57 leftSideImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/rightpage-west.jpg");
58 bottomLeftImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/rightpage-southwest.jpg");
59 topLeftImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/rightpage-northwest.jpg");
60 }
61
62
63
64
65
66
67
68
69
70
71 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
72 int imgWidth;
73 int imgHeight;
74
75 imgHeight = rightImg.getHeight();
76 imgWidth = rightImg.getWidth();
77 for (int i = y; i < y + height; i += imgHeight) {
78 g.drawImage(rightImg, x + width - imgWidth, i, null);
79 g.drawImage(leftSideImg, 0, i, null);
80 }
81
82
83 for (int i = 0; i < width; i += imgWidth) {
84 g.drawImage(topImg, i, 0, null);
85 }
86
87 imgHeight = bottomImg.getHeight();
88 imgWidth = bottomImg.getWidth();
89 for (int i = 0; i < width; i += imgWidth) {
90 g.drawImage(bottomImg, i, height - imgHeight, null);
91 }
92
93
94
95 imgWidth = topRightImg.getWidth();
96 g.drawImage(topRightImg, x + width - imgWidth, 0, null);
97
98
99 imgHeight = bottomRightImg.getHeight();
100 imgWidth = bottomRightImg.getWidth();
101 g.drawImage(bottomRightImg, x + width - imgWidth, height - imgHeight, null);
102
103
104 g.drawImage(topLeftImg, 0, 0, null);
105
106
107 imgHeight = bottomLeftImg.getHeight();
108 g.drawImage(bottomLeftImg, 0, height - imgHeight, null);
109
110
111
112
113 }
114
115
116
117
118
119
120 public Insets getBorderInsets(Component c) {
121 return new Insets(topImg.getHeight(), rightImg.getWidth(), bottomImg.getHeight(), rightImg.getWidth());
122 }
123
124
125
126
127
128 public boolean isBorderOpaque() {
129 return false;
130 }
131
132 }