-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockBox.java
More file actions
1599 lines (1312 loc) · 63.4 KB
/
LockBox.java
File metadata and controls
1599 lines (1312 loc) · 63.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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
import java.util.prefs.Preferences;
public class LockBox extends JFrame {
private static final String APP_TITLE = "LockBox Password Manager";
private static final String APP_AUTHOR = "Made by lytexdev (Immanuel Mruk)";
private static final String FILE_EXTENSION = "lbx";
// Lila/Pink Theme mit Dark Mode
private static final Color PRIMARY_COLOR = new Color(186, 104, 200); // Lila
private static final Color ACCENT_COLOR = new Color(233, 30, 99); // Pink
private static final Color BACKGROUND_COLOR = new Color(33, 33, 33); // Dunkelgrau
private static final Color CARD_COLOR = new Color(66, 66, 66); // Mittleres Grau
private static final Color TEXT_COLOR = new Color(255, 255, 255); // Weiß
private static final Color TEXT_SECONDARY_COLOR = new Color(180, 180, 180); // Hellgrau
private static final Font TITLE_FONT = new Font("Segoe UI", Font.BOLD, 24);
private static final Font HEADING_FONT = new Font("Segoe UI", Font.BOLD, 18);
private static final Font NORMAL_FONT = new Font("Segoe UI", Font.PLAIN, 14);
private static final Font SMALL_FONT = new Font("Segoe UI", Font.PLAIN, 12);
private PasswordManager manager;
private JPanel mainPanel;
private JPanel welcomePanel;
private JPanel contentPanel;
private JPasswordField masterPasswordField;
private DefaultListModel<Account> accountListModel;
private JList<Account> accountList;
private JScrollPane accountScrollPane;
private JLabel statusLabel;
private JTextField websiteField;
private JTextField usernameField;
private JPasswordField passwordField;
private JButton generateButton;
private JSpinner lengthSpinner;
private JCheckBox showPasswordCheckBox;
private String currentFileName = null;
private Preferences prefs;
private JTextField searchField;
private JPanel detailsPanel;
private JLabel lockIcon;
private Timer autoLockTimer;
private int autoLockMinutes = 5;
public LockBox() {
setTitle(APP_TITLE);
setSize(1000, 700);
setMinimumSize(new Dimension(800, 600));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Load application preferences
prefs = Preferences.userNodeForPackage(LockBox.class);
// Set application icon
setIconImage(createLockIcon(32).getImage());
// Apply modern look and feel
applyDarkTheme();
// Initialize auto-lock timer first
initAutoLockTimer();
// Initialize components
initializeComponents();
// Show the welcome panel first
showWelcomePanel();
setVisible(true);
}
private void initAutoLockTimer() {
autoLockTimer = new Timer(autoLockMinutes * 60 * 1000, e -> {
if (manager != null) {
logout();
JOptionPane.showMessageDialog(this,
"LockBox has been automatically locked due to inactivity.",
"Auto-Lock", JOptionPane.INFORMATION_MESSAGE);
}
});
autoLockTimer.setRepeats(false);
}
private void resetAutoLockTimer() {
if (autoLockTimer.isRunning()) {
autoLockTimer.restart();
} else {
autoLockTimer.start();
}
}
private void applyDarkTheme() {
try {
// Set system look and feel as base
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// Customize UI colors for dark theme
UIManager.put("Panel.background", BACKGROUND_COLOR);
UIManager.put("TextField.background", CARD_COLOR);
UIManager.put("TextField.foreground", TEXT_COLOR);
UIManager.put("TextField.caretForeground", PRIMARY_COLOR);
UIManager.put("PasswordField.background", CARD_COLOR);
UIManager.put("PasswordField.foreground", TEXT_COLOR);
UIManager.put("Button.background", PRIMARY_COLOR);
UIManager.put("Button.foreground", TEXT_COLOR);
UIManager.put("Label.foreground", TEXT_COLOR);
UIManager.put("CheckBox.foreground", TEXT_COLOR);
UIManager.put("List.background", CARD_COLOR);
UIManager.put("List.foreground", TEXT_COLOR);
UIManager.put("List.selectionBackground", ACCENT_COLOR);
UIManager.put("List.selectionForeground", TEXT_COLOR);
UIManager.put("ScrollPane.background", BACKGROUND_COLOR);
UIManager.put("Menu.foreground", TEXT_COLOR);
UIManager.put("Menu.background", BACKGROUND_COLOR);
UIManager.put("MenuBar.background", CARD_COLOR);
UIManager.put("MenuItem.foreground", TEXT_COLOR);
UIManager.put("MenuItem.background", CARD_COLOR);
UIManager.put("OptionPane.background", BACKGROUND_COLOR);
UIManager.put("OptionPane.messageForeground", TEXT_COLOR);
UIManager.put("TabbedPane.background", BACKGROUND_COLOR);
UIManager.put("ComboBox.background", CARD_COLOR);
UIManager.put("ComboBox.foreground", TEXT_COLOR);
UIManager.put("Spinner.background", CARD_COLOR);
UIManager.put("Spinner.foreground", TEXT_COLOR);
UIManager.put("ToolBar.background", CARD_COLOR);
// Update all components
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initializeComponents() {
// Main panel with card layout to switch between welcome and content
mainPanel = new JPanel(new CardLayout());
mainPanel.setBackground(BACKGROUND_COLOR);
setContentPane(mainPanel);
// Create welcome panel
createWelcomePanel();
// Create content panel
createContentPanel();
// Add panels to main panel
mainPanel.add(welcomePanel, "welcome");
mainPanel.add(contentPanel, "content");
// Create menu bar
createMenuBar();
}
private void createMenuBar() {
JMenuBar menuBar = new JMenuBar();
menuBar.setBackground(CARD_COLOR);
// File menu
JMenu fileMenu = new JMenu("File");
fileMenu.setFont(NORMAL_FONT);
fileMenu.setForeground(TEXT_COLOR);
JMenuItem newItem = new JMenuItem("New Database");
newItem.setFont(NORMAL_FONT);
newItem.setBackground(CARD_COLOR);
newItem.setForeground(TEXT_COLOR);
newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK));
newItem.addActionListener(e -> createNewDatabase());
JMenuItem openItem = new JMenuItem("Open Database");
openItem.setFont(NORMAL_FONT);
openItem.setBackground(CARD_COLOR);
openItem.setForeground(TEXT_COLOR);
openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK));
openItem.addActionListener(e -> openExistingDatabase());
JMenuItem saveItem = new JMenuItem("Save");
saveItem.setFont(NORMAL_FONT);
saveItem.setBackground(CARD_COLOR);
saveItem.setForeground(TEXT_COLOR);
saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
saveItem.addActionListener(e -> saveDatabase());
JMenuItem saveAsItem = new JMenuItem("Save As...");
saveAsItem.setFont(NORMAL_FONT);
saveAsItem.setBackground(CARD_COLOR);
saveAsItem.setForeground(TEXT_COLOR);
saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
saveAsItem.addActionListener(e -> saveDatabaseAs());
JMenuItem lockItem = new JMenuItem("Lock Database");
lockItem.setFont(NORMAL_FONT);
lockItem.setBackground(CARD_COLOR);
lockItem.setForeground(TEXT_COLOR);
lockItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_DOWN_MASK));
lockItem.addActionListener(e -> logout());
JMenuItem exitItem = new JMenuItem("Exit");
exitItem.setFont(NORMAL_FONT);
exitItem.setBackground(CARD_COLOR);
exitItem.setForeground(TEXT_COLOR);
exitItem.addActionListener(e -> exitApplication());
fileMenu.add(newItem);
fileMenu.add(openItem);
fileMenu.addSeparator();
fileMenu.add(saveItem);
fileMenu.add(saveAsItem);
fileMenu.addSeparator();
fileMenu.add(lockItem);
fileMenu.addSeparator();
fileMenu.add(exitItem);
// Edit menu
JMenu editMenu = new JMenu("Edit");
editMenu.setFont(NORMAL_FONT);
editMenu.setForeground(TEXT_COLOR);
JMenuItem addAccountItem = new JMenuItem("Add New Entry");
addAccountItem.setFont(NORMAL_FONT);
addAccountItem.setBackground(CARD_COLOR);
addAccountItem.setForeground(TEXT_COLOR);
addAccountItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK));
addAccountItem.addActionListener(e -> addAccount());
JMenuItem deleteAccountItem = new JMenuItem("Delete Entry");
deleteAccountItem.setFont(NORMAL_FONT);
deleteAccountItem.setBackground(CARD_COLOR);
deleteAccountItem.setForeground(TEXT_COLOR);
deleteAccountItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK));
deleteAccountItem.addActionListener(e -> deleteAccount());
JMenuItem copyUsernameItem = new JMenuItem("Copy Username");
copyUsernameItem.setFont(NORMAL_FONT);
copyUsernameItem.setBackground(CARD_COLOR);
copyUsernameItem.setForeground(TEXT_COLOR);
copyUsernameItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK));
copyUsernameItem.addActionListener(e -> copyUsername());
JMenuItem copyPasswordItem = new JMenuItem("Copy Password");
copyPasswordItem.setFont(NORMAL_FONT);
copyPasswordItem.setBackground(CARD_COLOR);
copyPasswordItem.setForeground(TEXT_COLOR);
copyPasswordItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK));
copyPasswordItem.addActionListener(e -> copyPassword());
JMenuItem generatePasswordItem = new JMenuItem("Generate Password");
generatePasswordItem.setFont(NORMAL_FONT);
generatePasswordItem.setBackground(CARD_COLOR);
generatePasswordItem.setForeground(TEXT_COLOR);
generatePasswordItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK));
generatePasswordItem.addActionListener(e -> generatePassword());
editMenu.add(addAccountItem);
editMenu.add(deleteAccountItem);
editMenu.addSeparator();
editMenu.add(copyUsernameItem);
editMenu.add(copyPasswordItem);
editMenu.add(generatePasswordItem);
// Tools menu
JMenu toolsMenu = new JMenu("Tools");
toolsMenu.setFont(NORMAL_FONT);
toolsMenu.setForeground(TEXT_COLOR);
JMenuItem changePasswordItem = new JMenuItem("Change Master Password");
changePasswordItem.setFont(NORMAL_FONT);
changePasswordItem.setBackground(CARD_COLOR);
changePasswordItem.setForeground(TEXT_COLOR);
changePasswordItem.addActionListener(e -> changeMasterPassword());
JMenuItem settingsItem = new JMenuItem("Settings");
settingsItem.setFont(NORMAL_FONT);
settingsItem.setBackground(CARD_COLOR);
settingsItem.setForeground(TEXT_COLOR);
settingsItem.addActionListener(e -> showSettings());
toolsMenu.add(changePasswordItem);
toolsMenu.add(settingsItem);
// Help menu
JMenu helpMenu = new JMenu("Help");
helpMenu.setFont(NORMAL_FONT);
helpMenu.setForeground(TEXT_COLOR);
JMenuItem aboutItem = new JMenuItem("About LockBox");
aboutItem.setFont(NORMAL_FONT);
aboutItem.setBackground(CARD_COLOR);
aboutItem.setForeground(TEXT_COLOR);
aboutItem.addActionListener(e -> showAbout());
helpMenu.add(aboutItem);
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(toolsMenu);
menuBar.add(helpMenu);
// Add author credit on the right
JMenu authorMenu = new JMenu(APP_AUTHOR);
authorMenu.setFont(SMALL_FONT);
authorMenu.setForeground(TEXT_SECONDARY_COLOR);
authorMenu.setEnabled(false);
menuBar.add(Box.createHorizontalGlue());
menuBar.add(authorMenu);
setJMenuBar(menuBar);
}
private void createWelcomePanel() {
welcomePanel = new JPanel();
welcomePanel.setLayout(new BorderLayout());
welcomePanel.setBackground(BACKGROUND_COLOR);
// Create a panel for the content with some padding
JPanel innerPanel = new JPanel();
innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS));
innerPanel.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
innerPanel.setBackground(BACKGROUND_COLOR);
// Logo and title
JPanel logoPanel = new JPanel();
logoPanel.setLayout(new BoxLayout(logoPanel, BoxLayout.Y_AXIS));
logoPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
logoPanel.setBackground(BACKGROUND_COLOR);
JLabel logoLabel = new JLabel(createLockIcon(96));
logoLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
JLabel titleLabel = new JLabel("LockBox");
titleLabel.setFont(new Font("Segoe UI", Font.BOLD, 36));
titleLabel.setForeground(PRIMARY_COLOR);
titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
JLabel subtitleLabel = new JLabel("Secure Password Manager");
subtitleLabel.setFont(new Font("Segoe UI", Font.PLAIN, 18));
subtitleLabel.setForeground(TEXT_COLOR);
subtitleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
JLabel authorLabel = new JLabel(APP_AUTHOR);
authorLabel.setFont(new Font("Segoe UI", Font.ITALIC, 14));
authorLabel.setForeground(TEXT_SECONDARY_COLOR);
authorLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
logoPanel.add(logoLabel);
logoPanel.add(Box.createVerticalStrut(20));
logoPanel.add(titleLabel);
logoPanel.add(Box.createVerticalStrut(10));
logoPanel.add(subtitleLabel);
logoPanel.add(Box.createVerticalStrut(10));
logoPanel.add(authorLabel);
// Recent files panel
JPanel recentPanel = new JPanel();
recentPanel.setLayout(new BoxLayout(recentPanel, BoxLayout.Y_AXIS));
recentPanel.setBackground(BACKGROUND_COLOR);
recentPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
recentPanel.setBorder(BorderFactory.createEmptyBorder(40, 0, 20, 0));
JLabel recentLabel = new JLabel("Recent Databases");
recentLabel.setFont(HEADING_FONT);
recentLabel.setForeground(TEXT_COLOR);
recentLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
recentPanel.add(recentLabel);
recentPanel.add(Box.createVerticalStrut(10));
// Fix for recent files
File appDir = new File(System.getProperty("user.home"), ".lockbox");
if (!appDir.exists()) {
appDir.mkdirs();
}
// Create a dummy file in the .lockbox directory
File dummyFile = new File(appDir, "recent.lbx");
if (!dummyFile.exists()) {
try {
dummyFile.createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
}
// Load and display recent files
String[] recentFiles = getRecentFiles();
// Force add the dummy file to recent files if none exist
if (recentFiles.length == 0) {
addRecentFile(dummyFile.getAbsolutePath());
recentFiles = getRecentFiles();
}
if (recentFiles.length > 0) {
for (String file : recentFiles) {
if (file != null && !file.isEmpty()) {
File f = new File(file);
if (f.exists()) {
JPanel filePanel = createRecentFilePanel(file);
recentPanel.add(filePanel);
recentPanel.add(Box.createVerticalStrut(8));
}
}
}
}
if (recentPanel.getComponentCount() <= 2) { // Only label and strut
JLabel noRecentLabel = new JLabel("No recent databases");
noRecentLabel.setFont(NORMAL_FONT);
noRecentLabel.setForeground(TEXT_SECONDARY_COLOR);
noRecentLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
recentPanel.add(noRecentLabel);
}
// Actions panel
JPanel actionsPanel = new JPanel();
actionsPanel.setLayout(new BoxLayout(actionsPanel, BoxLayout.Y_AXIS));
actionsPanel.setBackground(BACKGROUND_COLOR);
actionsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
actionsPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0));
JLabel actionsLabel = new JLabel("Get Started");
actionsLabel.setFont(HEADING_FONT);
actionsLabel.setForeground(TEXT_COLOR);
actionsLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, 20, 0));
buttonsPanel.setBackground(BACKGROUND_COLOR);
buttonsPanel.setMaximumSize(new Dimension(400, 50));
buttonsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
JButton createButton = createStyledButton("Create New Database", ACCENT_COLOR);
createButton.setFont(NORMAL_FONT);
createButton.addActionListener(e -> createNewDatabase());
JButton openButton = createStyledButton("Open Existing Database", PRIMARY_COLOR);
openButton.setFont(NORMAL_FONT);
openButton.addActionListener(e -> openExistingDatabase());
buttonsPanel.add(createButton);
buttonsPanel.add(openButton);
actionsPanel.add(actionsLabel);
actionsPanel.add(Box.createVerticalStrut(10));
actionsPanel.add(buttonsPanel);
// Add all panels to the inner panel
innerPanel.add(logoPanel);
innerPanel.add(Box.createVerticalStrut(40));
innerPanel.add(recentPanel);
innerPanel.add(Box.createVerticalStrut(20));
innerPanel.add(actionsPanel);
// Wrap inner panel in a scroll pane
JScrollPane scrollPane = new JScrollPane(innerPanel);
scrollPane.setBorder(null);
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
scrollPane.setBackground(BACKGROUND_COLOR);
welcomePanel.add(scrollPane, BorderLayout.CENTER);
}
private JPanel createRecentFilePanel(String filePath) {
JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(CARD_COLOR);
panel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(80, 80, 80), 1),
BorderFactory.createEmptyBorder(10, 15, 10, 15)));
panel.setMaximumSize(new Dimension(2000, 60));
File file = new File(filePath);
JLabel fileLabel = new JLabel(file.getName());
fileLabel.setFont(NORMAL_FONT);
fileLabel.setForeground(TEXT_COLOR);
JLabel pathLabel = new JLabel(file.getParent());
pathLabel.setFont(SMALL_FONT);
pathLabel.setForeground(TEXT_SECONDARY_COLOR);
JPanel textPanel = new JPanel(new GridLayout(2, 1));
textPanel.setBackground(CARD_COLOR);
textPanel.add(fileLabel);
textPanel.add(pathLabel);
JButton openButton = new JButton("Open");
openButton.setFont(SMALL_FONT);
openButton.setForeground(TEXT_COLOR);
openButton.setBackground(PRIMARY_COLOR);
openButton.setBorder(BorderFactory.createLineBorder(PRIMARY_COLOR));
openButton.setFocusPainted(false);
openButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
openButton.addActionListener(e -> openDatabase(filePath));
panel.add(textPanel, BorderLayout.CENTER);
panel.add(openButton, BorderLayout.EAST);
// Make panel clickable
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
openDatabase(filePath);
}
@Override
public void mouseEntered(MouseEvent e) {
panel.setBackground(new Color(80, 80, 80));
textPanel.setBackground(new Color(80, 80, 80));
panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
@Override
public void mouseExited(MouseEvent e) {
panel.setBackground(CARD_COLOR);
textPanel.setBackground(CARD_COLOR);
panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
});
return panel;
}
private JButton createStyledButton(String text, Color color) {
JButton button = new JButton(text);
button.setBackground(color);
button.setForeground(TEXT_COLOR);
button.setFocusPainted(false);
button.setBorderPainted(false);
button.setFont(NORMAL_FONT);
button.setCursor(new Cursor(Cursor.HAND_CURSOR));
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
button.setBackground(darken(color, 0.1f));
}
@Override
public void mouseExited(MouseEvent e) {
button.setBackground(color);
}
});
return button;
}
private Color darken(Color color, float fraction) {
int red = Math.max(0, Math.round(color.getRed() * (1 - fraction)));
int green = Math.max(0, Math.round(color.getGreen() * (1 - fraction)));
int blue = Math.max(0, Math.round(color.getBlue() * (1 - fraction)));
return new Color(red, green, blue);
}
private void createContentPanel() {
contentPanel = new JPanel(new BorderLayout(0, 0));
contentPanel.setBackground(BACKGROUND_COLOR);
// Create toolbar
JToolBar toolBar = new JToolBar();
toolBar.setFloatable(false);
toolBar.setBackground(CARD_COLOR);
toolBar.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
JButton newButton = createToolbarButton("New", "add");
newButton.addActionListener(e -> addAccount());
JButton saveButton = createToolbarButton("Save", "save");
saveButton.addActionListener(e -> saveDatabase());
JButton deleteButton = createToolbarButton("Delete", "delete");
deleteButton.addActionListener(e -> deleteAccount());
JButton copyUsernameButton = createToolbarButton("Username", "user");
copyUsernameButton.addActionListener(e -> copyUsername());
JButton copyPasswordButton = createToolbarButton("Password", "key");
copyPasswordButton.addActionListener(e -> copyPassword());
JButton lockButton = createToolbarButton("Lock", "lock");
lockButton.addActionListener(e -> logout());
// Search field
searchField = new JTextField(15);
searchField.setFont(NORMAL_FONT);
searchField.setBackground(BACKGROUND_COLOR);
searchField.setForeground(TEXT_COLOR);
searchField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(80, 80, 80)),
BorderFactory.createEmptyBorder(5, 10, 5, 10)));
searchField.putClientProperty("JTextField.placeholderText", "Search entries...");
searchField.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
filterAccounts();
}
});
toolBar.add(newButton);
toolBar.add(saveButton);
toolBar.add(deleteButton);
toolBar.addSeparator(new Dimension(20, 20));
toolBar.add(copyUsernameButton);
toolBar.add(copyPasswordButton);
toolBar.add(Box.createHorizontalGlue());
toolBar.add(searchField);
toolBar.addSeparator(new Dimension(20, 20));
toolBar.add(lockButton);
contentPanel.add(toolBar, BorderLayout.NORTH);
// Split pane for list and details
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setBorder(null);
splitPane.setDividerSize(5);
splitPane.setDividerLocation(300);
splitPane.setContinuousLayout(true);
splitPane.setBackground(BACKGROUND_COLOR);
// Account list panel
JPanel leftPanel = new JPanel(new BorderLayout());
leftPanel.setBackground(BACKGROUND_COLOR);
leftPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 5));
accountListModel = new DefaultListModel<>();
accountList = new JList<>(accountListModel);
accountList.setFont(NORMAL_FONT);
accountList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
accountList.setCellRenderer(new AccountListCellRenderer());
accountList.setBackground(CARD_COLOR);
accountList.setForeground(TEXT_COLOR);
accountList.addListSelectionListener(e -> {
if (!e.getValueIsAdjusting()) {
displaySelectedAccount();
resetAutoLockTimer();
}
});
accountScrollPane = new JScrollPane(accountList);
accountScrollPane.setBorder(BorderFactory.createLineBorder(new Color(80, 80, 80)));
accountScrollPane.setBackground(CARD_COLOR);
leftPanel.add(accountScrollPane, BorderLayout.CENTER);
// Details panel
detailsPanel = new JPanel();
detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.Y_AXIS));
detailsPanel.setBackground(BACKGROUND_COLOR);
detailsPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 10));
// Empty state for details panel
createEmptyDetailsState();
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(detailsPanel);
contentPanel.add(splitPane, BorderLayout.CENTER);
// Status bar
JPanel statusPanel = new JPanel(new BorderLayout());
statusPanel.setBackground(CARD_COLOR);
statusPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
statusLabel = new JLabel("Ready");
statusLabel.setFont(SMALL_FONT);
statusLabel.setForeground(TEXT_COLOR);
JLabel authorLabel = new JLabel(APP_AUTHOR);
authorLabel.setFont(SMALL_FONT);
authorLabel.setForeground(TEXT_SECONDARY_COLOR);
authorLabel.setHorizontalAlignment(SwingConstants.CENTER);
lockIcon = new JLabel(createLockIcon(16));
statusPanel.add(statusLabel, BorderLayout.WEST);
statusPanel.add(authorLabel, BorderLayout.CENTER);
statusPanel.add(lockIcon, BorderLayout.EAST);
contentPanel.add(statusPanel, BorderLayout.SOUTH);
}
private void createEmptyDetailsState() {
detailsPanel.removeAll();
JPanel emptyPanel = new JPanel(new GridBagLayout());
emptyPanel.setBackground(BACKGROUND_COLOR);
JLabel emptyLabel = new JLabel("Select an entry or create a new one");
emptyLabel.setFont(NORMAL_FONT);
emptyLabel.setForeground(TEXT_SECONDARY_COLOR);
JButton addNewButton = createStyledButton("Add New Entry", PRIMARY_COLOR);
addNewButton.addActionListener(e -> addAccount());
addNewButton.setMaximumSize(new Dimension(150, 40));
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
centerPanel.setBackground(BACKGROUND_COLOR);
centerPanel.add(emptyLabel);
centerPanel.add(Box.createVerticalStrut(20));
centerPanel.add(addNewButton);
centerPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
// Make all components centered horizontally
emptyLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
addNewButton.setAlignmentX(Component.CENTER_ALIGNMENT);
emptyPanel.add(centerPanel);
detailsPanel.add(emptyPanel);
detailsPanel.revalidate();
detailsPanel.repaint();
}
private void createAccountDetailsPanel() {
detailsPanel.removeAll();
// Form panel with better spacing
JPanel formPanel = new JPanel();
formPanel.setLayout(new BoxLayout(formPanel, BoxLayout.Y_AXIS));
formPanel.setBackground(BACKGROUND_COLOR);
formPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
// Title
JLabel titleLabel = new JLabel("Account Details");
titleLabel.setFont(HEADING_FONT);
titleLabel.setForeground(TEXT_COLOR);
titleLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
formPanel.add(titleLabel);
formPanel.add(Box.createVerticalStrut(20));
// Website field
JLabel websiteLabel = new JLabel("Website / Service");
websiteLabel.setFont(NORMAL_FONT);
websiteLabel.setForeground(TEXT_COLOR);
websiteLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
formPanel.add(websiteLabel);
formPanel.add(Box.createVerticalStrut(5));
websiteField = new JTextField();
websiteField.setFont(NORMAL_FONT);
websiteField.setBackground(CARD_COLOR);
websiteField.setForeground(TEXT_COLOR);
websiteField.setCaretColor(ACCENT_COLOR);
websiteField.setMaximumSize(new Dimension(2000, 35));
websiteField.setAlignmentX(Component.LEFT_ALIGNMENT);
formPanel.add(websiteField);
formPanel.add(Box.createVerticalStrut(15));
// Username field
JLabel usernameLabel = new JLabel("Username / Email");
usernameLabel.setFont(NORMAL_FONT);
usernameLabel.setForeground(TEXT_COLOR);
usernameLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
formPanel.add(usernameLabel);
formPanel.add(Box.createVerticalStrut(5));
usernameField = new JTextField();
usernameField.setFont(NORMAL_FONT);
usernameField.setBackground(CARD_COLOR);
usernameField.setForeground(TEXT_COLOR);
usernameField.setCaretColor(ACCENT_COLOR);
usernameField.setMaximumSize(new Dimension(2000, 35));
usernameField.setAlignmentX(Component.LEFT_ALIGNMENT);
formPanel.add(usernameField);
formPanel.add(Box.createVerticalStrut(15));
// Password field with controls
JLabel passwordLabel = new JLabel("Password");
passwordLabel.setFont(NORMAL_FONT);
passwordLabel.setForeground(TEXT_COLOR);
passwordLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
formPanel.add(passwordLabel);
formPanel.add(Box.createVerticalStrut(5));
JPanel passwordPanel = new JPanel();
passwordPanel.setLayout(new BoxLayout(passwordPanel, BoxLayout.X_AXIS));
passwordPanel.setBackground(BACKGROUND_COLOR);
passwordPanel.setMaximumSize(new Dimension(2000, 35));
passwordPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
passwordField = new JPasswordField();
passwordField.setFont(NORMAL_FONT);
passwordField.setBackground(CARD_COLOR);
passwordField.setForeground(TEXT_COLOR);
passwordField.setCaretColor(ACCENT_COLOR);
showPasswordCheckBox = new JCheckBox("Show");
showPasswordCheckBox.setFont(SMALL_FONT);
showPasswordCheckBox.setBackground(BACKGROUND_COLOR);
showPasswordCheckBox.setForeground(TEXT_COLOR);
showPasswordCheckBox.addActionListener(e -> togglePasswordVisibility());
passwordPanel.add(passwordField);
passwordPanel.add(Box.createHorizontalStrut(10));
passwordPanel.add(showPasswordCheckBox);
formPanel.add(passwordPanel);
formPanel.add(Box.createVerticalStrut(15));
// Password generation
JPanel generatePanel = new JPanel();
generatePanel.setLayout(new BoxLayout(generatePanel, BoxLayout.X_AXIS));
generatePanel.setBackground(BACKGROUND_COLOR);
generatePanel.setMaximumSize(new Dimension(2000, 35));
generatePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
generateButton = new JButton("Generate Password");
generateButton.setFont(SMALL_FONT);
generateButton.setBackground(ACCENT_COLOR);
generateButton.setForeground(TEXT_COLOR);
generateButton.addActionListener(e -> generatePassword());
JLabel lengthLabel = new JLabel("Length:");
lengthLabel.setFont(SMALL_FONT);
lengthLabel.setForeground(TEXT_COLOR);
SpinnerNumberModel spinnerModel = new SpinnerNumberModel(16, 8, 64, 1);
lengthSpinner = new JSpinner(spinnerModel);
lengthSpinner.setMaximumSize(new Dimension(60, 30));
lengthSpinner.setBackground(CARD_COLOR);
lengthSpinner.setForeground(TEXT_COLOR);
generatePanel.add(generateButton);
generatePanel.add(Box.createHorizontalStrut(10));
generatePanel.add(lengthLabel);
generatePanel.add(Box.createHorizontalStrut(5));
generatePanel.add(lengthSpinner);
generatePanel.add(Box.createHorizontalGlue());
formPanel.add(generatePanel);
formPanel.add(Box.createVerticalStrut(30));
// Buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
buttonPanel.setBackground(BACKGROUND_COLOR);
buttonPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
JButton saveButton = createStyledButton("Save", PRIMARY_COLOR);
saveButton.addActionListener(e -> updateAccount());
buttonPanel.add(saveButton);
buttonPanel.add(Box.createHorizontalGlue());
formPanel.add(buttonPanel);
// Add form panel to a scroll pane
JScrollPane scrollPane = new JScrollPane(formPanel);
scrollPane.setBorder(null);
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
scrollPane.setBackground(BACKGROUND_COLOR);
detailsPanel.add(scrollPane);
detailsPanel.revalidate();
detailsPanel.repaint();
}
private JButton createToolbarButton(String text, String iconName) {
JButton button = new JButton(text);
button.setForeground(TEXT_COLOR);
button.setBackground(PRIMARY_COLOR);
button.setBorderPainted(false);
button.setFocusPainted(false);
button.setFont(SMALL_FONT);
button.setCursor(new Cursor(Cursor.HAND_CURSOR));
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
button.setBackground(ACCENT_COLOR);
}
@Override
public void mouseExited(MouseEvent e) {
button.setBackground(PRIMARY_COLOR);
}
});
return button;
}
private ImageIcon createLockIcon(int size) {
// Upgraded lock icon with lila/pink colors
BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
// Enable anti-aliasing
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Draw lock body with gradient
GradientPaint gradient = new GradientPaint(
size/4, size/3, PRIMARY_COLOR,
size*3/4, size*5/6, ACCENT_COLOR);
g2d.setPaint(gradient);
g2d.fillRoundRect(size/4, size/3, size/2, size/2, size/8, size/8);
// Draw lock shackle
g2d.setStroke(new BasicStroke(size/8, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2d.setColor(ACCENT_COLOR);
g2d.drawArc(size/4, size/8, size/2, size/3, 0, 180);
g2d.dispose();
return new ImageIcon(image);
}
private void showWelcomePanel() {
CardLayout cl = (CardLayout) mainPanel.getLayout();
cl.show(mainPanel, "welcome");
// Stop auto-lock timer if it's running
if (autoLockTimer != null && autoLockTimer.isRunning()) {
autoLockTimer.stop();
}
}
private void showContentPanel() {
CardLayout cl = (CardLayout) mainPanel.getLayout();
cl.show(mainPanel, "content");
refreshAccountList();
resetAutoLockTimer();
}
private void createNewDatabase() {
// If already logged in, ask to save current database
if (manager != null) {
int result = JOptionPane.showConfirmDialog(this,
"Do you want to save the current database before creating a new one?",
"Save Current Database", JOptionPane.YES_NO_CANCEL_OPTION);
if (result == JOptionPane.CANCEL_OPTION) {
return;
} else if (result == JOptionPane.YES_OPTION) {
saveDatabase();
}
}
// Create file chooser for new database
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Create New Database");
fileChooser.setFileFilter(new FileNameExtensionFilter("LockBox Database (*." + FILE_EXTENSION + ")", FILE_EXTENSION));
if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
String filePath = selectedFile.getAbsolutePath();
// Add extension if not present
if (!filePath.toLowerCase().endsWith("." + FILE_EXTENSION)) {
filePath += "." + FILE_EXTENSION;
}
// Ask for master password
JPasswordField masterPassField = new JPasswordField(20);
JPasswordField confirmPassField = new JPasswordField(20);
JPanel panel = new JPanel(new GridLayout(0, 1));
panel.setBackground(BACKGROUND_COLOR);
JLabel titleLabel = new JLabel("Create a strong master password:");
titleLabel.setForeground(TEXT_COLOR);
panel.add(titleLabel);
panel.add(masterPassField);
JLabel confirmLabel = new JLabel("Confirm password:");
confirmLabel.setForeground(TEXT_COLOR);
panel.add(confirmLabel);
panel.add(confirmPassField);
// Update the UI components to match theme
UIManager.put("OptionPane.background", BACKGROUND_COLOR);
UIManager.put("Panel.background", BACKGROUND_COLOR);
UIManager.put("OptionPane.messageForeground", TEXT_COLOR);
int result = JOptionPane.showConfirmDialog(this, panel,
"New Database - Set Master Password", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
String masterPassword = new String(masterPassField.getPassword());
String confirmPassword = new String(confirmPassField.getPassword());
if (masterPassword.isEmpty()) {
JOptionPane.showMessageDialog(this,
"Password cannot be empty.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
if (!masterPassword.equals(confirmPassword)) {
JOptionPane.showMessageDialog(this,
"Passwords do not match.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {