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