01: /**
02: *
03: */package test.check;
04:
05: import java.awt.*;
06:
07: import javax.swing.JPanel;
08:
09: import org.jvnet.lafwidget.layout.TransitionLayout;
10: import org.jvnet.substance.SubstanceLookAndFeel;
11: import org.jvnet.substance.utils.SubstanceCoreUtilities;
12:
13: final class CheckeredPanel extends ScrollablePanel {
14: @Override
15: protected void paintComponent(Graphics g) {
16: Graphics2D graphics = (Graphics2D) g.create();
17: graphics.setComposite(TransitionLayout.getAlphaComposite(this ));
18:
19: int w = this .getWidth();
20: int h = this .getHeight();
21:
22: int cols = 1 + w / 10;
23: int rows = 1 + h / 10;
24: if (SubstanceCoreUtilities.isThemeDark(SubstanceLookAndFeel
25: .getTheme()))
26: graphics.setColor(Color.black);
27: else
28: graphics.setColor(Color.white);
29: graphics.fillRect(0, 0, w, h);
30: for (int i = 0; i < cols; i++) {
31: for (int j = 0; j < rows; j++) {
32: if (((i + j) % 2) == 0) {
33: float val = (i + j) / 100.f;
34: val -= Math.floor(val);
35: boolean isDark = SubstanceCoreUtilities
36: .isThemeDark(SubstanceLookAndFeel
37: .getTheme());
38: float brightness = isDark ? 0.1f : 0.9f;
39: float saturation = 0.2f;
40: graphics.setColor(new Color(Color.HSBtoRGB(val,
41: saturation, brightness)));
42: graphics.fillRect(i * 10, j * 10, 10, 10);
43: }
44: }
45: }
46:
47: graphics.setColor(Color.gray);
48: graphics.setFont(new Font("Arial", Font.PLAIN, 11));
49: rows = 1 + h / 25;
50: for (int i = 0; i < rows; i++) {
51: for (int j = 0; j < w / 25; j++) {
52: graphics.drawString("" + (i + j), j * 25, 25 * i);
53: }
54: }
55: graphics.dispose();
56: }
57:
58: @Override
59: public Dimension getPreferredSize() {
60: return new Dimension(1200, 800);
61: }
62: }
|