-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryUI.java
More file actions
316 lines (285 loc) · 11.4 KB
/
Copy pathLibraryUI.java
File metadata and controls
316 lines (285 loc) · 11.4 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class LibraryUI {
public static final Color BACKGROUND = new Color(244, 247, 251);
public static final Color CARD = Color.WHITE;
public static final Color PRIMARY = new Color(33, 99, 235);
public static final Color PRIMARY_DARK = new Color(24, 74, 178);
public static final Color ACCENT = new Color(18, 183, 106);
public static final Color TEXT = new Color(28, 32, 39);
public static final Color MUTED = new Color(99, 110, 125);
public static final Color BORDER = new Color(218, 225, 234);
public static final Color PANEL_TINT = new Color(248, 250, 253);
public static final Font TITLE_FONT = new Font("Segoe UI", Font.BOLD, 24);
public static final Font HERO_FONT = new Font("Segoe UI", Font.BOLD, 32);
public static final Font LABEL_FONT = new Font("Segoe UI", Font.PLAIN, 14);
public static final Font FIELD_FONT = new Font("Segoe UI", Font.PLAIN, 14);
private LibraryUI() {
}
public static JPanel createContentPanel() {
JPanel panel = new JPanel();
panel.setBackground(BACKGROUND);
panel.setBorder(new EmptyBorder(18, 18, 18, 18));
return panel;
}
public static JPanel createGradientPanel() {
return new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
GradientPaint gradient = new GradientPaint(
0, 0, new Color(13, 71, 161),
getWidth(), getHeight(), new Color(39, 110, 241)
);
g2.setPaint(gradient);
g2.fillRoundRect(0, 0, getWidth(), getHeight(), 28, 28);
g2.setColor(new Color(255, 255, 255, 26));
g2.fillOval(getWidth() - 150, -30, 170, 170);
g2.fillOval(getWidth() - 240, 60, 120, 120);
g2.dispose();
}
};
}
public static JPanel createCardPanel() {
JPanel panel = new JPanel();
panel.setBackground(CARD);
panel.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(BORDER, 1, true),
new EmptyBorder(18, 18, 18, 18)
));
return panel;
}
public static JLabel createTitle(String text) {
JLabel label = new JLabel(text);
label.setFont(TITLE_FONT);
label.setForeground(TEXT);
return label;
}
public static JLabel createHeroTitle(String text) {
JLabel label = new JLabel(text);
label.setFont(HERO_FONT);
label.setForeground(Color.WHITE);
return label;
}
public static JLabel createSubtitle(String text) {
JLabel label = new JLabel(text);
label.setFont(LABEL_FONT);
label.setForeground(MUTED);
return label;
}
public static JLabel createHeroSubtitle(String text) {
JLabel label = new JLabel(text);
label.setFont(new Font("Segoe UI", Font.PLAIN, 15));
label.setForeground(new Color(232, 239, 255));
return label;
}
public static JLabel createIconBadge(String iconKey) {
JLabel label = new JLabel(resolveIcon(iconKey));
label.setOpaque(true);
label.setBackground(new Color(255, 255, 255, 34));
label.setBorder(new EmptyBorder(10, 10, 10, 10));
return label;
}
public static JTextField createTextField(int columns) {
JTextField field = new JTextField(columns);
field.setFont(FIELD_FONT);
field.setBackground(Color.WHITE);
field.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(BORDER, 1, true),
new EmptyBorder(8, 10, 8, 10)
));
return field;
}
public static JPasswordField createPasswordField(int columns) {
JPasswordField field = new JPasswordField(columns);
field.setFont(FIELD_FONT);
field.setBackground(Color.WHITE);
field.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(BORDER, 1, true),
new EmptyBorder(8, 10, 8, 10)
));
return field;
}
public static JComboBox<BookItem> createBookDropdown() {
JComboBox<BookItem> comboBox = new JComboBox<>();
comboBox.setFont(FIELD_FONT);
comboBox.setBackground(Color.WHITE);
comboBox.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(BORDER, 1, true),
new EmptyBorder(6, 8, 6, 8)
));
return comboBox;
}
public static JButton createPrimaryButton(String text) {
JButton button = new JButton(text);
button.setFont(new Font("Segoe UI", Font.BOLD, 14));
button.setBackground(PRIMARY);
button.setForeground(Color.WHITE);
button.setFocusPainted(false);
button.setBorder(new EmptyBorder(10, 18, 10, 18));
installButtonHover(button, PRIMARY, PRIMARY_DARK);
return button;
}
public static JButton createPrimaryButton(String text, String iconKey) {
JButton button = createPrimaryButton(text);
button.setIcon(resolveIcon(iconKey));
button.setIconTextGap(10);
return button;
}
public static JButton createSecondaryButton(String text) {
JButton button = new JButton(text);
button.setFont(new Font("Segoe UI", Font.BOLD, 14));
button.setBackground(new Color(233, 240, 255));
button.setForeground(PRIMARY_DARK);
button.setFocusPainted(false);
button.setBorder(new EmptyBorder(10, 18, 10, 18));
installButtonHover(button, new Color(233, 240, 255), new Color(215, 228, 255));
return button;
}
public static JTextArea createInfoArea(int rows, int cols) {
JTextArea area = new JTextArea(rows, cols);
area.setFont(FIELD_FONT);
area.setEditable(false);
area.setLineWrap(true);
area.setWrapStyleWord(true);
area.setBackground(PANEL_TINT);
area.setForeground(TEXT);
area.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(BORDER, 1, true),
new EmptyBorder(12, 12, 12, 12)
));
return area;
}
public static JScrollPane wrap(JComponent component) {
JScrollPane scrollPane = new JScrollPane(component);
scrollPane.setBorder(new LineBorder(BORDER, 1, true));
return scrollPane;
}
public static void styleTable(JTable table) {
table.setFont(FIELD_FONT);
table.setRowHeight(30);
table.setShowGrid(false);
table.setIntercellSpacing(new Dimension(0, 0));
table.getTableHeader().setFont(new Font("Segoe UI", Font.BOLD, 13));
table.getTableHeader().setBackground(new Color(238, 243, 252));
table.getTableHeader().setForeground(TEXT);
table.setSelectionBackground(new Color(219, 232, 255));
table.setSelectionForeground(TEXT);
}
public static JButton createActionCard(String title, String subtitle, String iconKey) {
JButton button = new JButton();
button.setLayout(new BorderLayout(0, 12));
button.setBackground(Color.WHITE);
button.setFocusPainted(false);
button.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(BORDER, 1, true),
new EmptyBorder(16, 16, 16, 16)
));
JLabel icon = new JLabel(resolveIcon(iconKey));
JPanel iconWrap = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
iconWrap.setOpaque(false);
iconWrap.add(icon);
button.add(iconWrap, BorderLayout.NORTH);
JPanel textPanel = new JPanel();
textPanel.setOpaque(false);
textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
JLabel titleLabel = new JLabel(title);
titleLabel.setFont(new Font("Segoe UI", Font.BOLD, 16));
titleLabel.setForeground(TEXT);
JLabel subtitleLabel = new JLabel("<html><body style='width:150px'>" + subtitle + "</body></html>");
subtitleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 12));
subtitleLabel.setForeground(MUTED);
textPanel.add(titleLabel);
textPanel.add(Box.createVerticalStrut(4));
textPanel.add(subtitleLabel);
button.add(textPanel, BorderLayout.CENTER);
installCardHover(button);
return button;
}
public static void revealComponents(Component... components) {
for (Component component : components) {
component.setVisible(false);
}
Timer timer = new Timer(90, null);
timer.addActionListener(e -> {
for (Component component : components) {
if (!component.isVisible()) {
component.setVisible(true);
component.revalidate();
component.repaint();
return;
}
}
timer.stop();
});
timer.setInitialDelay(120);
timer.start();
}
private static void installButtonHover(AbstractButton button, Color base, Color hover) {
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
button.setBackground(hover);
}
@Override
public void mouseExited(MouseEvent e) {
button.setBackground(base);
}
});
}
private static void installCardHover(JButton button) {
Color base = Color.WHITE;
Color hover = new Color(244, 248, 255);
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
button.setBackground(hover);
button.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(PRIMARY, 1, true),
new EmptyBorder(16, 16, 16, 16)
));
}
@Override
public void mouseExited(MouseEvent e) {
button.setBackground(base);
button.setBorder(BorderFactory.createCompoundBorder(
new LineBorder(BORDER, 1, true),
new EmptyBorder(16, 16, 16, 16)
));
}
});
}
private static Icon resolveIcon(String iconKey) {
if ("login".equals(iconKey)) {
return UIManager.getIcon("FileView.computerIcon");
}
if ("add".equals(iconKey)) {
return UIManager.getIcon("FileChooser.newFolderIcon");
}
if ("delete".equals(iconKey)) {
return UIManager.getIcon("OptionPane.errorIcon");
}
if ("search".equals(iconKey)) {
return UIManager.getIcon("FileView.directoryIcon");
}
if ("issue".equals(iconKey)) {
return UIManager.getIcon("OptionPane.informationIcon");
}
if ("return".equals(iconKey)) {
return UIManager.getIcon("OptionPane.questionIcon");
}
if ("view".equals(iconKey)) {
return UIManager.getIcon("FileView.fileIcon");
}
if ("logout".equals(iconKey)) {
return UIManager.getIcon("InternalFrame.closeIcon");
}
return UIManager.getIcon("OptionPane.informationIcon");
}
}