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.Graphics;
8 import java.awt.Component;
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 LeftPageBookBorder extends AbstractBorder {
38
39 private BufferedImage topImg;
40 private BufferedImage bottomImg;
41 private BufferedImage rightImg;
42 private BufferedImage topRightImg;
43 private BufferedImage bottomRightImg;
44
45
46
47
48
49 public LeftPageBookBorder() {
50 bottomImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/bottom.jpg");
51 topImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/top.jpg");
52 rightImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/leftpage-east.jpg");
53 topRightImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/leftpage-northeast.jpg");
54 bottomRightImg = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/leftpage-southeast.jpg");
55 }
56
57
58
59
60
61
62
63
64
65
66 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
67 int imgWidth = topImg.getWidth();
68 int imgHeight;
69
70 imgHeight = rightImg.getHeight();
71 imgWidth = rightImg.getWidth();
72 for (int i = y; i < y + height; i += imgHeight) {
73 g.drawImage(rightImg, x + width - imgWidth, i, null);
74 }
75
76
77 for (int i = 0; i < width; i += imgWidth) {
78 g.drawImage(topImg, i, 0, null);
79 }
80
81 imgHeight = bottomImg.getHeight();
82 imgWidth = bottomImg.getWidth();
83 for (int i = 0; i < width; i += imgWidth) {
84 g.drawImage(bottomImg, i, height - imgHeight, null);
85 }
86
87
88 imgWidth = topRightImg.getWidth();
89 g.drawImage(topRightImg, x + width - imgWidth, 0, null);
90
91
92 imgHeight = bottomRightImg.getHeight();
93 imgWidth = bottomRightImg.getWidth();
94 g.drawImage(bottomRightImg, x + width - imgWidth, height - imgHeight, null);
95
96 }
97
98
99
100
101
102
103 public Insets getBorderInsets(Component c) {
104 return new Insets(topImg.getHeight(), rightImg.getWidth(), bottomImg.getHeight(), rightImg.getWidth());
105 }
106
107
108
109
110
111 public boolean isBorderOpaque() {
112 return false;
113 }
114
115 }