|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| package org.ericmignot.modeler.util.graphic; |
|
20 |
| |
|
21 |
| import java.awt.Color; |
|
22 |
| import java.awt.Dimension; |
|
23 |
| import java.awt.Graphics; |
|
24 |
| import java.awt.Graphics2D; |
|
25 |
| import java.awt.RenderingHints; |
|
26 |
| |
|
27 |
| import javax.swing.JPanel; |
|
28 |
| |
|
29 |
| public class FixedSquaredSizePanel extends JPanel |
|
30 |
| { |
|
31 |
| protected int fixedSize; |
|
32 |
| protected Color fillColor; |
|
33 |
| protected Color drawColor; |
|
34 |
| |
|
35 |
0
| public FixedSquaredSizePanel(Color fillColor, Color drawColor, int size)
|
|
36 |
| { |
|
37 |
0
| this.fillColor = fillColor;
|
|
38 |
0
| this.drawColor = drawColor;
|
|
39 |
0
| this.fixedSize = size;
|
|
40 |
| } |
|
41 |
| |
|
42 |
0
| public Color getBackground()
|
|
43 |
| { |
|
44 |
0
| return this.fillColor;
|
|
45 |
| } |
|
46 |
| |
|
47 |
0
| public Color getForeground()
|
|
48 |
| { |
|
49 |
0
| return this.drawColor;
|
|
50 |
| } |
|
51 |
| |
|
52 |
0
| public Dimension getPreferredSize()
|
|
53 |
| { |
|
54 |
0
| return new Dimension(fixedSize, fixedSize);
|
|
55 |
| } |
|
56 |
| |
|
57 |
0
| public void paintComponent(Graphics g)
|
|
58 |
| { |
|
59 |
0
| int width = this.getSize().width;
|
|
60 |
0
| int x = (width - this.fixedSize ) / 2;
|
|
61 |
0
| int height = this.getSize().height;
|
|
62 |
0
| int y = (height - this.fixedSize) / 2;
|
|
63 |
| |
|
64 |
0
| Color oldColor = g.getColor();
|
|
65 |
| |
|
66 |
0
| Graphics2D g2d = (Graphics2D) g;
|
|
67 |
0
| g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
68 |
| |
|
69 |
0
| g.setColor(this.getBackground());
|
|
70 |
0
| g.fillRect(x, y, this.fixedSize-1, this.fixedSize-1);
|
|
71 |
0
| g.setColor(this.getForeground());
|
|
72 |
0
| g.drawRect(x, y, this.fixedSize-1, this.fixedSize-1);
|
|
73 |
| |
|
74 |
0
| g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
|
|
75 |
0
| g.setColor(oldColor);
|
|
76 |
| |
|
77 |
| |
|
78 |
| } |
|
79 |
| |
|
80 |
| } |