-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUITheme.java
More file actions
174 lines (159 loc) · 7.12 KB
/
Copy pathUITheme.java
File metadata and controls
174 lines (159 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
public final class UITheme {
public static final Color PURPLE = new Color(116, 91, 255);
public static final Color PURPLE_DARK = new Color(83, 62, 190);
public static final Color BLUE = new Color(74, 144, 226);
public static final Color PINK = new Color(245, 126, 182);
public static final Color MINT = new Color(93, 202, 169);
public static final Color YELLOW = new Color(247, 190, 82);
public static final Color RED = new Color(235, 91, 91);
public static final Color BG = new Color(247, 245, 252);
public static final Color TEXT = new Color(43, 43, 62);
public static final Color MUTED = new Color(112, 111, 130);
public static final Color WHITE = Color.WHITE;
private UITheme() {}
public static JLabel title(String text, int size) {
JLabel label = new JLabel(text);
label.setFont(new Font("SansSerif", Font.BOLD, size));
label.setForeground(TEXT);
return label;
}
public static JLabel subtitle(String text) {
JLabel label = new JLabel(text);
label.setFont(new Font("SansSerif", Font.PLAIN, 14));
label.setForeground(MUTED);
return label;
}
public static RoundedButton button(String text, Color color) {
return new RoundedButton(text, color);
}
public static RoundedTextField textField(String placeholder) {
return new RoundedTextField(placeholder);
}
public static RoundedPasswordField passwordField(String placeholder) {
return new RoundedPasswordField(placeholder);
}
public static RoundedPanel card() {
RoundedPanel panel = new RoundedPanel(24, new Color(255, 255, 255, 235));
panel.setBorder(new EmptyBorder(22, 24, 22, 24));
return panel;
}
public static class RoundedButton extends JButton {
private final Color baseColor;
private boolean hover;
public RoundedButton(String text, Color color) {
super(text);
this.baseColor = color;
setFont(new Font("SansSerif", Font.BOLD, 14));
setForeground(Color.WHITE);
setFocusPainted(false);
setBorderPainted(false);
setContentAreaFilled(false);
setOpaque(false);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
setBorder(new EmptyBorder(13, 22, 13, 22));
addMouseListener(new java.awt.event.MouseAdapter() {
@Override public void mouseEntered(java.awt.event.MouseEvent e) { hover = true; repaint(); }
@Override public void mouseExited(java.awt.event.MouseEvent e) { hover = false; repaint(); }
});
}
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color c = hover ? baseColor.brighter() : baseColor;
g2.setColor(new Color(0, 0, 0, 22));
g2.fillRoundRect(1, 4, getWidth() - 2, getHeight() - 3, getHeight(), getHeight());
g2.setColor(c);
g2.fillRoundRect(0, 0, getWidth(), getHeight() - 4, getHeight(), getHeight());
g2.dispose();
super.paintComponent(g);
}
}
public static class RoundedPanel extends JPanel {
private final int radius;
private final Color fill;
public RoundedPanel(int radius, Color fill) {
this.radius = radius;
this.fill = fill;
setOpaque(false);
}
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(0, 0, 0, 18));
g2.fillRoundRect(2, 4, getWidth() - 4, getHeight() - 5, radius, radius);
g2.setColor(fill);
g2.fillRoundRect(0, 0, getWidth() - 2, getHeight() - 4, radius, radius);
g2.dispose();
super.paintComponent(g);
}
}
public static class RoundedTextField extends JTextField {
private final String placeholder;
public RoundedTextField(String placeholder) {
this.placeholder = placeholder;
setFont(new Font("SansSerif", Font.PLAIN, 14));
setForeground(TEXT);
setBorder(new EmptyBorder(12, 16, 12, 16));
setOpaque(false);
}
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(247, 247, 252));
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 18, 18);
g2.setColor(new Color(220, 219, 232));
g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 18, 18);
g2.dispose();
super.paintComponent(g);
if (getText().isEmpty() && !hasFocus()) {
Graphics2D p = (Graphics2D) g.create();
p.setColor(new Color(155, 154, 172));
p.setFont(getFont());
p.drawString(placeholder, 16, getHeight()/2 + 5);
p.dispose();
}
}
}
public static class RoundedPasswordField extends JPasswordField {
private final String placeholder;
public RoundedPasswordField(String placeholder) {
this.placeholder = placeholder;
setFont(new Font("SansSerif", Font.PLAIN, 14));
setForeground(TEXT);
setBorder(new EmptyBorder(12, 16, 12, 16));
setOpaque(false);
}
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(new Color(247, 247, 252));
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 18, 18);
g2.setColor(new Color(220, 219, 232));
g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 18, 18);
g2.dispose();
super.paintComponent(g);
if (getPassword().length == 0 && !hasFocus()) {
Graphics2D p = (Graphics2D) g.create();
p.setColor(new Color(155, 154, 172));
p.setFont(getFont());
p.drawString(placeholder, 16, getHeight()/2 + 5);
p.dispose();
}
}
}
public static class GradientPanel extends JPanel {
private final Color c1, c2;
public GradientPanel(Color c1, Color c2) { this.c1 = c1; this.c2 = c2; setOpaque(false); }
@Override protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setPaint(new GradientPaint(0, 0, c1, getWidth(), getHeight(), c2));
g2.fillRect(0, 0, getWidth(), getHeight());
g2.dispose();
super.paintComponent(g);
}
}
}