diff options
Diffstat (limited to 'src/cppcheckplus/text/MyTextArea.java')
-rw-r--r-- | src/cppcheckplus/text/MyTextArea.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/cppcheckplus/text/MyTextArea.java b/src/cppcheckplus/text/MyTextArea.java new file mode 100644 index 0000000..9860093 --- /dev/null +++ b/src/cppcheckplus/text/MyTextArea.java | |||
@@ -0,0 +1,60 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.Dimension; | ||
4 | import java.awt.Graphics; | ||
5 | import java.awt.Graphics2D; | ||
6 | import java.awt.Image; | ||
7 | import java.awt.TexturePaint; | ||
8 | |||
9 | import javax.swing.BorderFactory; | ||
10 | import javax.swing.ImageIcon; | ||
11 | import javax.swing.JTextArea; | ||
12 | import javax.swing.border.Border; | ||
13 | import javax.swing.plaf.metal.MetalTextFieldUI; | ||
14 | |||
15 | import cppcheckplus.control.MyContorlUtil; | ||
16 | |||
17 | public class MyTextArea extends JTextArea{ | ||
18 | private Image backgroundLeftImage; | ||
19 | private Image backgroundRightImage; | ||
20 | private ImageIcon backgroundImageIcon; | ||
21 | private TexturePaint paint; | ||
22 | private Border border; | ||
23 | |||
24 | public MyTextArea () | ||
25 | { | ||
26 | backgroundLeftImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_left.png"); | ||
27 | backgroundRightImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_right.png"); | ||
28 | backgroundImageIcon = MyContorlUtil.getImageIcon("xujun/control/images/textfield_background.png"); | ||
29 | paint = MyContorlUtil.createTexturePaint("xujun/control/images/textfield_background.png"); | ||
30 | border = BorderFactory.createEmptyBorder(1, 3, 1, 3); | ||
31 | init(); | ||
32 | } | ||
33 | public MyTextArea (String text) | ||
34 | { | ||
35 | this(); | ||
36 | setText(text); | ||
37 | } | ||
38 | |||
39 | private void init() | ||
40 | { | ||
41 | setBorder(border); | ||
42 | setUI(new MetalTextFieldUI() { | ||
43 | |||
44 | protected void paintBackground(Graphics g) | ||
45 | { | ||
46 | Graphics2D g2d = (Graphics2D)g; | ||
47 | g2d.setPaint(paint); | ||
48 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
49 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | ||
50 | g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); | ||
51 | } | ||
52 | |||
53 | }); | ||
54 | } | ||
55 | |||
56 | public Dimension getPreferredSize() | ||
57 | { | ||
58 | return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); | ||
59 | } | ||
60 | } | ||