-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyPass.java
More file actions
1805 lines (1505 loc) · 82.3 KB
/
Copy pathMyPass.java
File metadata and controls
1805 lines (1505 loc) · 82.3 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
package org.virus.mypass;
/*
*
* MyPass (v4.3.1) - By SecVirus (c) 4Ever
*
*
* This file contains the main class.
*
* > ICONS
* -> https://jiconfont.github.io/fontawesome
* > Graphics icons
* -> https://graphics.keenthemes.com/
* > UI
* -> https://mvnrepository.com/artifact/com.formdev/flatlaf
*
* BackGround(hex=46494b, r=70,g=73,b=75)
*
*/
import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
import com.formdev.flatlaf.extras.components.FlatButton;
import com.formdev.flatlaf.icons.FlatSearchWithHistoryIcon;
import com.formdev.flatlaf.ui.FlatTableUI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.FlavorEvent;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.EventObject;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.concurrent.Callable;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.RowFilter;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import jiconfont.IconCode;
import jiconfont.icons.font_awesome.FontAwesome;
import jiconfont.swing.IconFontSwing;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.virus.mypass.ui.Manager;
import org.virus.mypass.ui.Theme;
import org.virus.mypass.history.history_vars;
import org.virus.mypass.util.Converter.Converter;
import org.virus.mypass.ui.Entity;
import org.virus.mypass.ui.KeyBoard;
import org.virus.mypass.ui.License;
import org.virus.mypass.ui.MGenerator;
import org.virus.mypass.ui.Passwords;
import org.virus.mypass.ui.ui_vars;
import static org.virus.mypass.ui.ui_vars.category_column_index;
import static org.virus.mypass.ui.ui_vars.entity_column_index;
import org.virus.mypass.util.AES.Decryption;
import org.virus.mypass.util.AES.Encryption;
import org.virus.mypass.util.ClipBoard.Clear;
import org.virus.mypass.util.ClipBoard.Copy;
import org.virus.mypass.util.ClipBoard.Get;
import org.virus.mypass.ui.Accent;
import org.virus.mypass.ui.HexViewer;
import org.virus.mypass.ui.categories;
import org.virus.mypass.util.Timer.Timer;
public class MyPass {
static JFrame window;
static JMenuBar menubar; // LEAF
static JMenu file_menu,
edit_menu,
edit_copy_entity_menu,
appearance_menu,
appearance_theme_menu,
language_menu,
tools_menu,
security_menu,
window_menu,
help_menu,
about_menu,
direction_window_menu; // This one is for Manager Table.
static JMenuItem NewFile_menu, OpenFile_menu, SaveFile_menu,
NewEntity_menu, EditEntity_menu, DeleteEntity_menu,
edit_copy_entity_entity_menu, edit_copy_entity_username_menu, edit_copy_entity_url_menu, edit_copy_entity_password_menu, edit_copy_entity_note_menu,
edit_change_session_name_menu, security_change_password_menu,
generator_tool_menu, PasswordStrengthMeter_menu, PasswordStrengthReport_menu, HexViewer_menu, converter_tool_menu, clear_clipboard_tool_menu,
help_about_software, help_about_license, help_report_bug, $3_2_0_converter, $4_2_0_converter, $4_3_1_converter;
static JRadioButtonMenuItem menu_light_theme, menu_dark_theme, direction_rtl, direction_ltr, autoStartStopTimer_onFocus, menu_english_language;
static JCheckBoxMenuItem menu_manager_dragable, appearance_animate, topmost_window_menu, resizeable_window_menu, timerAutoStart_security_menu, AutoSaveOnTimeout_security_menu, auto_clear_clipboard_tool_menu, window_toolbar_dragable_menu;
static JPanel panel, manager_frame;
static JToolBar toolbar, subToolbar, SessionTimerToolBar;
static JTextField search_field;
static JButton searchHistory_btn,
NewFile, OpenFile, SaveFile,
NewEntity, EditEntity, DeleteEntity,
GeneratePassword, PasswordStrengthMeter, StrengthReporter, HexViewerButton,
CopyEntity, CopyUsername, CopyUrl, CopyPassword, CopyNote, ClearClipboard,
LogToolbarButton,
ExitToolbarButton,
StartSessionTimer;
static JLabel SessionTimer;
static FlatButton EntityCounter, tutorial, visit_github;
static JTable table;
static JScrollPane table_scrollpane;
static DefaultTableModel table_model;
static DefaultTableCellRenderer table_row_center;
static ButtonGroup themes_group, manager_direction_group, languages_menu_group;
static TableRowSorter<TableModel> manager_sorter;
static JSONObject json_data = new JSONObject();
static String session_filename, session_filepath, current_title, encryption_key, window_theme;
static boolean saved_changes, isNew;
static JSONObject log_history = new JSONObject();
static org.virus.mypass.util.Log.Logger logger = new org.virus.mypass.util.Log.Logger(log_history);
static Timer timer;
public static void main(String[] args) {
logger.add_log(logger.PROGRESS, "Starting MyPass..");
json_data.put("entities", new JSONObject());
json_data.put("settings", new JSONObject());
saved_changes = true;
window_theme = ui_vars.default_theme;
IconFontSwing.register(FontAwesome.getIconFont());
window = new JFrame(ui_vars.tool_title.toString());
window.getRootPane().putClientProperty("JRootPane.titleBarBackground", Accent.AlphaSetGet(25));
Theme.apply_configurations();
Theme.toggle_theme(window, window_theme);
Icon app_icon = IconFontSwing.buildIcon(FontAwesome.MAXCDN, 75, Accent.AlphaSetGet(255));
window.setIconImage(((ImageIcon) app_icon).getImage());
toolbar = new JToolBar();
toolbar.setFloatable(false);
panel = new JPanel(new BorderLayout());
manager_frame = new JPanel(new BorderLayout());
menubar = new JMenuBar();
// =====================================================================
file_menu = new JMenu("File");
NewFile_menu = new JMenuItem("New");
NewFile_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.PLUS_SQUARE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
NewFile_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
NewFile_menu.addActionListener(e -> {
Data.new_file();
});
NewFile_menu.setToolTipText("New Session");
OpenFile_menu = new JMenuItem("Open");
OpenFile_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.FOLDER_OPEN, ui_vars.icons_size, Accent.AlphaSetGet(255)));
OpenFile_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
OpenFile_menu.addActionListener(e -> {
Data.open_file();
});
OpenFile_menu.setToolTipText("Open Existing Session");
SaveFile_menu = new JMenuItem("Save");
SaveFile_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.FLOPPY_O, ui_vars.icons_size, Accent.AlphaSetGet(255)));
SaveFile_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
SaveFile_menu.setEnabled(false);
SaveFile_menu.addActionListener(e -> {
Data.save_file();
});
SaveFile_menu.setToolTipText("Save Current Session");
edit_menu = new JMenu("Edit");
NewEntity_menu = new JMenuItem("New");
NewEntity_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.USER_PLUS, ui_vars.icons_size, Accent.AlphaSetGet(255)));
NewEntity_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK));
NewEntity_menu.setEnabled(false);
NewEntity_menu.addActionListener(e -> {
Data.new_entity();
});
NewEntity_menu.setToolTipText("New Entity");
EditEntity_menu = new JMenuItem("Edit");
EditEntity_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.PENCIL, ui_vars.icons_size, Accent.AlphaSetGet(255)));
EditEntity_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK));
EditEntity_menu.setEnabled(false);
EditEntity_menu.addActionListener(e -> {
Data.edit_entity();
});
EditEntity_menu.setToolTipText("Edit Entity");
DeleteEntity_menu = new JMenuItem("Delete");
DeleteEntity_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.TRASH, ui_vars.icons_size, Accent.AlphaSetGet(255)));
DeleteEntity_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK));
DeleteEntity_menu.setEnabled(false);
DeleteEntity_menu.addActionListener(e -> {
Data.delete_entity();
});
DeleteEntity_menu.setToolTipText("Delete Entity");
// --------------
edit_copy_entity_menu = new JMenu("Copy");
edit_copy_entity_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.CLIPBOARD, ui_vars.icons_size, Accent.AlphaSetGet(255)));
edit_copy_entity_entity_menu = new JMenuItem("Entity");
edit_copy_entity_entity_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.CUBE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
edit_copy_entity_entity_menu.addActionListener(e -> {
Table.content.entity();
});
edit_copy_entity_entity_menu.setToolTipText("Copy Entity name for selected entity");
edit_copy_entity_entity_menu.setEnabled(false);
edit_copy_entity_username_menu = new JMenuItem("Username");
edit_copy_entity_username_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.USER, ui_vars.icons_size, Accent.AlphaSetGet(255)));
edit_copy_entity_username_menu.addActionListener(e -> {
Table.content.copy("username");
});
edit_copy_entity_username_menu.setToolTipText("Copy Username for selected entity");
edit_copy_entity_username_menu.setEnabled(false);
edit_copy_entity_url_menu = new JMenuItem("Url");
edit_copy_entity_url_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.LINK, ui_vars.icons_size, Accent.AlphaSetGet(255)));
edit_copy_entity_url_menu.addActionListener(e -> {
Table.content.copy("url");
});
edit_copy_entity_url_menu.setToolTipText("Copy Url for selected entity");
edit_copy_entity_url_menu.setEnabled(false);
edit_copy_entity_password_menu = new JMenuItem("Password");
edit_copy_entity_password_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.KEY, ui_vars.icons_size, Accent.AlphaSetGet(255)));
edit_copy_entity_password_menu.addActionListener(e -> {
Table.content.copy("password");
});
edit_copy_entity_password_menu.setToolTipText("Copy Password for selected entity");
edit_copy_entity_password_menu.setEnabled(false);
edit_copy_entity_note_menu = new JMenuItem("Note");
edit_copy_entity_note_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.STICKY_NOTE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
edit_copy_entity_note_menu.addActionListener(e -> {
Table.content.copy("note");
});
edit_copy_entity_note_menu.setToolTipText("Copy Note for selected entity");
edit_copy_entity_note_menu.setEnabled(false);
edit_change_session_name_menu = new JMenuItem("Change Session Name");
edit_change_session_name_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.I_CURSOR, ui_vars.icons_size, Accent.AlphaSetGet(255)));
edit_change_session_name_menu.addActionListener(l -> {
String new_name = JOptionPane.showInputDialog(window, "Session name:");
if (new_name != null) {
int answer = JOptionPane.showConfirmDialog(window, "Are you sure?", "Changing session name..", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (answer == 0) {
Ui.put_session_filename(new File(new_name));
unsaved();
}
}
});
edit_change_session_name_menu.setToolTipText("Change running session name");
edit_change_session_name_menu.setEnabled(false);
security_menu = new JMenu("Security");
security_change_password_menu = new JMenuItem("Change Password");
security_change_password_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.MAGIC, ui_vars.icons_size, Accent.AlphaSetGet(255)));
security_change_password_menu.addActionListener(e -> {
String verify_password = Passwords.ask(window, "Password verfiction");
if (verify_password != null) {
if (verify_password.length() > 0) {
if (verify_password.equals(encryption_key)) {
String new_password = Passwords.ask(window, "New password");
if (new_password != null) { // if pressed submit/ok/done in the password dialog
if (new_password.length() > 0) {
int answer = JOptionPane.showOptionDialog(window, "The session '" + session_filename + "' password will be changed.\n\nAre you sure?", "Change password?!", JOptionPane.PLAIN_MESSAGE, JOptionPane.WARNING_MESSAGE, null, new String[]{"Yes", "No"}, "No");
if (answer == 0) {
encryption_key = new_password;
unsaved();
JOptionPane.showMessageDialog(window, "Password changed successfully!", "Password Changed!", JOptionPane.INFORMATION_MESSAGE);
}
}
}
} else {
JOptionPane.showMessageDialog(window, "Couldn't verify password to change it.", "Incorrect Password!", JOptionPane.ERROR_MESSAGE);
}
}
}
});
security_change_password_menu.setToolTipText("Change Session password");
security_change_password_menu.setEnabled(false);
// Seperator ------------
menu_manager_dragable = new JCheckBoxMenuItem("Dragable");
menu_manager_dragable.setToolTipText("Enable/Disable abillity to drag text from manager table");
menu_manager_dragable.setIcon(IconFontSwing.buildIcon(FontAwesome.ARROWS, ui_vars.icons_size, Accent.AlphaSetGet(255)));
appearance_menu = new JMenu("Appearance");
appearance_theme_menu = new JMenu("Theme");
appearance_theme_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.PAINT_BRUSH, ui_vars.icons_size, Accent.AlphaSetGet(255)));
themes_group = new ButtonGroup();
menu_light_theme = new JRadioButtonMenuItem("Light Theme");
// menu_light_theme.setMnemonic(KeyEvent.VK_L);
menu_light_theme.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.ALT_MASK + ActionEvent.CTRL_MASK));
menu_light_theme.setToolTipText("Toggle light theme");
menu_dark_theme = new JRadioButtonMenuItem("Dark Theme", true);
menu_dark_theme.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.ALT_MASK + ActionEvent.CTRL_MASK));
menu_dark_theme.setToolTipText("Toggle dark theme");
appearance_animate = new JCheckBoxMenuItem("Animate", true);
appearance_animate.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK + ActionEvent.CTRL_MASK));
appearance_animate.setToolTipText("Animate theme changes");
appearance_animate.addActionListener(l -> {
unsaved();
});
language_menu = new JMenu("Language");
languages_menu_group = new ButtonGroup();
menu_english_language = new JRadioButtonMenuItem("English", true);
menu_english_language.addActionListener(l -> {
// Locale.setDefault(new Locale("en", "US"));
// SwingUtilities.updateComponentTreeUI(window);
});
tools_menu = new JMenu("Tools");
generator_tool_menu = new JMenuItem("Generator", IconFontSwing.buildIcon(FontAwesome.RANDOM, ui_vars.icons_size, Accent.AlphaSetGet(255)));
generator_tool_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK));
generator_tool_menu.setToolTipText("Password Generator");
generator_tool_menu.addActionListener(e -> {
MGenerator.run(window, null);
});
PasswordStrengthMeter_menu = new JMenuItem("Strength Meter", IconFontSwing.buildIcon(FontAwesome.TACHOMETER, ui_vars.icons_size, Accent.AlphaSetGet(255)));
PasswordStrengthMeter_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK));
PasswordStrengthMeter_menu.setToolTipText("Password Strength Meter");
PasswordStrengthMeter_menu.addActionListener(e -> {
new Passwords.PasswordStrengthIndicator((JFrame) window).setVisible(true);
});
PasswordStrengthReport_menu = new JMenuItem("Strength Report", IconFontSwing.buildIcon(FontAwesome.NEWSPAPER_O, ui_vars.icons_size, Accent.AlphaSetGet(255)));
PasswordStrengthReport_menu.setEnabled(false);
PasswordStrengthReport_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK));
PasswordStrengthReport_menu.setToolTipText("Password Strength Report");
PasswordStrengthReport_menu.addActionListener(e -> {
Passwords.Reporter(window, json_data.getJSONObject("entities"));
});
HexViewer_menu = new JMenuItem("Hex Viewer", IconFontSwing.buildIcon(FontAwesome.TH, ui_vars.icons_size, Accent.AlphaSetGet(255)));
HexViewer_menu.setEnabled(false);
HexViewer_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.SHIFT_MASK + ActionEvent.CTRL_MASK));
HexViewer_menu.setToolTipText("View session's data as hexadecimal");
HexViewer_menu.addActionListener(e -> {
if (!json_data.getJSONObject("entities").isEmpty()) {
HexViewer.hex(window, session_filepath);
}
});
converter_tool_menu = new JMenu("Converter");
converter_tool_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.RECYCLE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
converter_tool_menu.setToolTipText("Convert MyPass password files from version to another");
$3_2_0_converter = new JMenuItem("v3.2.0", IconFontSwing.buildIcon(FontAwesome.RECYCLE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
$3_2_0_converter.setToolTipText("v3.2.0 - v4.2.0");
$3_2_0_converter.addActionListener(e -> {
Converter.$3_2_0(window);
});
$4_2_0_converter = new JMenuItem("v4.2.0", IconFontSwing.buildIcon(FontAwesome.RECYCLE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
$4_2_0_converter.setToolTipText("v4.2.0 - v4.3.1");
$4_2_0_converter.addActionListener(e -> {
Converter.$4_3_1(window);
});
$4_3_1_converter = new JMenuItem("v4.3.1", IconFontSwing.buildIcon(FontAwesome.RECYCLE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
$4_3_1_converter.setToolTipText("v4.3.1 - v?.?.?");
$4_3_1_converter.addActionListener(e -> {
// Converter.$?_?_?(window);
});
$4_3_1_converter.setEnabled(false);
clear_clipboard_tool_menu = new JMenuItem("Clear Clipboard", IconFontSwing.buildIcon(FontAwesome.ERASER, ui_vars.icons_size, Accent.AlphaSetGet(255)));
clear_clipboard_tool_menu.setSelected(false);
clear_clipboard_tool_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK + ActionEvent.CTRL_MASK));
clear_clipboard_tool_menu.setToolTipText("Clear Clipboard (For security)");
clear_clipboard_tool_menu.addActionListener(e -> {
Clear.content();
});
timerAutoStart_security_menu = new JCheckBoxMenuItem("Auto Start Timer");
timerAutoStart_security_menu.setSelected(false);
timerAutoStart_security_menu.setToolTipText("Auto start session timer (For confidentiality)");
timerAutoStart_security_menu.addActionListener(l -> {
unsaved();
});
AutoSaveOnTimeout_security_menu = new JCheckBoxMenuItem("Auto Save On Timeout");
AutoSaveOnTimeout_security_menu.setSelected(true);
AutoSaveOnTimeout_security_menu.setToolTipText("Auto save session data before timeout terminate");
AutoSaveOnTimeout_security_menu.addActionListener(l -> {
unsaved();
});
auto_clear_clipboard_tool_menu = new JCheckBoxMenuItem("Auto Clear Clipboard");
auto_clear_clipboard_tool_menu.setSelected(false);
auto_clear_clipboard_tool_menu.setToolTipText("Auto Clear Clipboard (For security)");
auto_clear_clipboard_tool_menu.addActionListener(l -> {
unsaved();
});
window_menu = new JMenu("Window");
topmost_window_menu = new JCheckBoxMenuItem("Topmost");
topmost_window_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.ALT_MASK + ActionEvent.CTRL_MASK));
topmost_window_menu.setSelected(false);
topmost_window_menu.setToolTipText("On top of all other windows");
topmost_window_menu.addActionListener(l -> {
unsaved();
});
topmost_window_menu.addActionListener(twe -> {
window.setAlwaysOnTop(topmost_window_menu.isSelected());
});
resizeable_window_menu = new JCheckBoxMenuItem("Resizeable");
resizeable_window_menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK + ActionEvent.CTRL_MASK));
resizeable_window_menu.setSelected(true);
resizeable_window_menu.addActionListener(l -> {
unsaved();
});
resizeable_window_menu.addActionListener(twe -> {
if (appearance_animate.isSelected()) {
FlatAnimatedLafChange.showSnapshot();
}
window.setResizable(resizeable_window_menu.isSelected());
if (appearance_animate.isSelected()) {
FlatAnimatedLafChange.hideSnapshotWithAnimation();
}
});
window_toolbar_dragable_menu = new JCheckBoxMenuItem("Toolbar dragable");
window_toolbar_dragable_menu.setSelected(false);
window_toolbar_dragable_menu.addActionListener(e -> {
toolbar.setFloatable(window_toolbar_dragable_menu.isSelected());
unsaved();
});
help_menu = new JMenu("Help");
about_menu = new JMenu("About");
about_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.QUESTION_CIRCLE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
help_about_software = new JMenuItem("Software");
help_about_software.setIcon(IconFontSwing.buildIcon(FontAwesome.DESKTOP, ui_vars.icons_size, Accent.AlphaSetGet(255)));
help_about_license = new JMenuItem("License");
help_about_license.setIcon(IconFontSwing.buildIcon(FontAwesome.STAR, ui_vars.icons_size, Accent.AlphaSetGet(255)));
help_report_bug = new JMenuItem("Report a Bug");
help_report_bug.setIcon(IconFontSwing.buildIcon(FontAwesome.BUG, ui_vars.icons_size, Accent.AlphaSetGet(255)));
help_report_bug.addActionListener(e -> {
visit("https://github.com/isecvirus/MyPass/issues/new");
});
tutorial = new FlatButton();
tutorial.setIcon(IconFontSwing.buildIcon(FontAwesome.BOOK, ui_vars.icons_size, Accent.AlphaSetGet(255)));
// tutorial.setEnabled(false);
tutorial.setToolTipText("Tutorial");
tutorial.setButtonType(FlatButton.ButtonType.toolBarButton);
tutorial.setFocusable(false);
tutorial.addActionListener(e -> {
visit("https://github.com/isecvirus/MyPass/blob/main/README.md#-tutorial");
});
visit_github = new FlatButton();
visit_github.setIcon(IconFontSwing.buildIcon(FontAwesome.GITHUB, ui_vars.icons_size + 2, Accent.AlphaSetGet(255)));
visit_github.setToolTipText("iSecVirus@github");
visit_github.setButtonType(FlatButton.ButtonType.toolBarButton);
visit_github.setFocusable(false);
visit_github.addActionListener(a -> {
visit("https://www.github.com/isecvirus");
});
search_field = new JTextField();
search_field.setLayout(new BorderLayout());
KeyBoard.give(window, search_field);
// search_manager.setMargin(new Insets(5, 5, 5, 5));
// search_manager.setBorder(new EmptyBorder(10, 10, 10, 10));
search_field.setToolTipText("Search.. (RegEx supported)");
JToolBar PrefixSearchToolbar = new JToolBar();
PrefixSearchToolbar.addSeparator();
JToolBar SufixSearchToolbar = new JToolBar();
FlatButton results_count_label = new FlatButton();
results_count_label.setVisible(false);
searchHistory_btn = new JButton((Icon) new FlatSearchWithHistoryIcon(true));
searchHistory_btn.addActionListener(e -> {
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem clear_history = new JMenuItem("Clear History", IconFontSwing.buildIcon(FontAwesome.ERASER, ui_vars.icons_size, Accent.AlphaSetGet(255)));
clear_history.setToolTipText("Clear Search History");
clear_history.addActionListener(ev -> {
history_vars.SearchHistory.clear();
});
clear_history.setEnabled((!history_vars.SearchHistory.isEmpty()));
popupMenu.add(clear_history);
if (!history_vars.SearchHistory.isEmpty()) {
popupMenu.addSeparator();
}
for (int sr = 0; sr < history_vars.SearchHistory.size(); sr++) { // sr=search result
String query = history_vars.SearchHistory.get(sr);
JMenuItem this_item = new JMenuItem(query);
this_item.addActionListener(item_al -> {
search_field.setText(query);
});
popupMenu.add(this_item);
}
popupMenu.show(searchHistory_btn, 0, searchHistory_btn.getHeight());
});
// PrefixSearchToolbar.add(SearchQuery);
SufixSearchToolbar.addSeparator();
SufixSearchToolbar.add(results_count_label);
SufixSearchToolbar.add(searchHistory_btn);
// search_field.putClientProperty("JTextField.leadingIcon", IconFontSwing.buildIcon(FontAwesome.SEARCH, ui_vars.icons_size, ui_vars.icons_color));
// search_field.putClientProperty("JTextField.leadingComponent", PrefixSearchToolbar);
search_field.putClientProperty("JTextField.trailingComponent", SufixSearchToolbar);
search_field.putClientProperty("JTextField.placeholderText", "Search..");
search_field.putClientProperty("JTextField.showClearButton", true);
// search_field.putClientProperty("JComponent.roundRect", Boolean.valueOf(true));
table_model = new DefaultTableModel(0, ui_vars.manager_columns.length);
table_model.setColumnIdentifiers(ui_vars.manager_columns);
table_row_center = new DefaultTableCellRenderer();
table = new JTable(table_model) {
@Override
public boolean editCellAt(int row, int column, EventObject e) {
return false;
}
;
};
table.setSelectionBackground(Accent.AlphaSetGet(65));
table.setOpaque(false);
((DefaultTableCellRenderer) table.getDefaultRenderer(Object.class)).setOpaque(false);
table.getTableHeader().setOpaque(false);
// DefaultTableModel mtm = (DefaultTableModel) table.getModel(); // manager table model
table.getTableHeader().setReorderingAllowed(false);
Manager.CenterTableRows(table, table_row_center, ui_vars.manager_columns);
// table.setDefaultEditor(Object.class, null);
table.setSelectionMode(0); // 0=single selection
// table.setAutoCreateRowSorter(true);
manager_sorter = new TableRowSorter<>(table_model);
table.setRowSorter(manager_sorter);
Font currentFont = table.getFont(); // Get the current font of the table
Font newFont = currentFont.deriveFont(currentFont.getSize() + 1.5f).deriveFont(Font.BOLD); // Create a new font object with increased size and bold style
table.setFont(newFont); // Set the table font to the new font
table.setRowHeight(50);
table.getColumnModel().getColumn(category_column_index).setCellRenderer(new TableCategoryRenderer());
table.getColumnModel().getColumn(category_column_index).setMaxWidth(50);
table.getColumnModel().getColumn(category_column_index).setResizable(false);
// make columns unsortable in the passwords ..
// .. manager table (avoiding passwords arrangment problems).
for (int i = 0; i < ui_vars.manager_columns.length; i++) {
manager_sorter.setSortable(i, false);
}
// manager_sorter.setSortsOnUpdates(true);
search_field.getDocument().addDocumentListener(new DocumentListener() {
public void search(String query) {
if (query.length() > 0) {
try {
manager_sorter.setRowFilter(RowFilter.regexFilter(query));
search_field.setForeground(Color.decode(ui_vars.valid_search_color));
} catch (Exception error) { // PatternSyntaxException, NumberFormatException
search_field.setForeground(Color.decode(ui_vars.invalid_search_color));
}
if (!history_vars.SearchHistory.contains(query)) {
history_vars.SearchHistory.add(query);
}
} else {
manager_sorter.setRowFilter(null);
search_field.setForeground(Color.decode(ui_vars.valid_search_color));
}
int results_count = table.getRowCount();
if (search_field.getText().length() > 0) {
results_count_label.setVisible(true);
results_count_label.setText(String.valueOf(results_count));
} else {
results_count_label.setText("");
results_count_label.setVisible(false);
}
}
@Override
public void changedUpdate(DocumentEvent e) {
search(search_field.getText());
}
@Override
public void removeUpdate(DocumentEvent e) {
search(search_field.getText());
}
@Override
public void insertUpdate(DocumentEvent e) {
search(search_field.getText());
}
});
direction_window_menu = new JMenu("Direction");
direction_window_menu.setIcon(IconFontSwing.buildIcon(FontAwesome.ALIGN_CENTER, ui_vars.icons_size, Accent.AlphaSetGet(255)));
manager_direction_group = new ButtonGroup();
direction_rtl = new JRadioButtonMenuItem("RTL");
direction_rtl.setIcon(IconFontSwing.buildIcon(FontAwesome.ALIGN_RIGHT, ui_vars.icons_size, Accent.AlphaSetGet(255)));
direction_ltr = new JRadioButtonMenuItem("LTR", true);
direction_ltr.setIcon(IconFontSwing.buildIcon(FontAwesome.ALIGN_LEFT, ui_vars.icons_size, Accent.AlphaSetGet(255)));
direction_ltr.addActionListener(l -> {
unsaved();
});
autoStartStopTimer_onFocus = new JRadioButtonMenuItem("Auto Timer", true);
autoStartStopTimer_onFocus.setToolTipText("Auto Start/Stop Timer on Focus/Unfocus window");
autoStartStopTimer_onFocus.setIcon(IconFontSwing.buildIcon(FontAwesome.WINDOW_RESTORE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
autoStartStopTimer_onFocus.setSelected(false);
manager_direction_group.add(direction_rtl);
manager_direction_group.add(direction_ltr);
direction_window_menu.add(direction_rtl);
direction_window_menu.add(direction_ltr);
direction_rtl.addActionListener((ActionEvent e) -> {
Ui.RTL();
});
direction_ltr.addActionListener((ActionEvent e) -> {
Ui.LTR();
});
table.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
table.setFocusable(false);
// table.setColumnSelectionAllowed(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table_scrollpane = new JScrollPane(table);
table_scrollpane.setOpaque(false);
table_scrollpane.getViewport().setOpaque(false);
menu_manager_dragable.addActionListener((ActionEvent e) -> {
Manager.draggable(table);
});
menu_light_theme.addActionListener((ActionEvent e) -> {
if (appearance_animate.isSelected()) {
FlatAnimatedLafChange.showSnapshot();
}
Theme.toggle_theme(window, ui_vars.light_theme);
window_theme = "light";
unsaved();
if (appearance_animate.isSelected()) {
FlatAnimatedLafChange.hideSnapshotWithAnimation();
}
});
menu_dark_theme.addActionListener((ActionEvent e) -> {
if (appearance_animate.isSelected()) {
FlatAnimatedLafChange.showSnapshot();
}
Theme.toggle_theme(window, ui_vars.dark_theme);
window_theme = "dark";
unsaved();
if (appearance_animate.isSelected()) {
FlatAnimatedLafChange.hideSnapshotWithAnimation();
}
});
help_about_software.addActionListener((ActionEvent e) -> {
JOptionPane.showMessageDialog(window, "MyPass is a password manager.\nUse it to secure, store and manage passwords.\n\nJava 18.0.1.1 2022-04-22 (build 18.0.1.1+2-6)", "About MyPass", JOptionPane.INFORMATION_MESSAGE);
});
help_about_license.addActionListener((ActionEvent e) -> {
new License().display(window);
});
// toolbar.add(Box.createHorizontalStrut(5), 0);
NewFile = new JButton(IconFontSwing.buildIcon(FontAwesome.PLUS_SQUARE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
NewFile.setToolTipText("New File");
OpenFile = new JButton(IconFontSwing.buildIcon(FontAwesome.FOLDER_OPEN, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
OpenFile.setToolTipText("Open File");
SaveFile = new JButton(IconFontSwing.buildIcon(FontAwesome.FLOPPY_O, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
SaveFile.setToolTipText("Save File");
SaveFile.setEnabled(false);
// ~~~~~~~~~~~~~~~~~
NewEntity = new JButton(IconFontSwing.buildIcon(FontAwesome.USER_PLUS, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
NewEntity.setToolTipText("New Entity");
NewEntity.setEnabled(false);
EditEntity = new JButton(IconFontSwing.buildIcon(FontAwesome.PENCIL, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
EditEntity.setToolTipText("Edit Entity");
EditEntity.setEnabled(false);
DeleteEntity = new JButton(IconFontSwing.buildIcon(FontAwesome.TRASH, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
DeleteEntity.setToolTipText("Delete Entity");
DeleteEntity.setEnabled(false);
// ~~~~~~~~~~~~~~~~~
CopyEntity = new JButton(IconFontSwing.buildIcon(FontAwesome.CUBE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
CopyEntity.setToolTipText("Copy Entity");
CopyEntity.setEnabled(false);
CopyUsername = new JButton(IconFontSwing.buildIcon(FontAwesome.USER, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
CopyUsername.setToolTipText("Copy Username");
CopyUsername.setEnabled(false);
CopyUrl = new JButton(IconFontSwing.buildIcon(FontAwesome.LINK, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
CopyUrl.setToolTipText("Copy Url");
CopyUrl.setEnabled(false);
CopyPassword = new JButton(IconFontSwing.buildIcon(FontAwesome.KEY, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
CopyPassword.setToolTipText("Copy Password");
CopyPassword.setEnabled(false);
CopyNote = new JButton(IconFontSwing.buildIcon(FontAwesome.STICKY_NOTE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
CopyNote.setToolTipText("Copy Note");
CopyNote.setEnabled(false);
ClearClipboard = new JButton(IconFontSwing.buildIcon(FontAwesome.ERASER, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
ClearClipboard.setToolTipText("Clear Clipboard");
ClearClipboard.setEnabled(false);
check_clipboard_status();
// ~~~~~~~~~~~~~~~~~
GeneratePassword = new JButton(IconFontSwing.buildIcon(FontAwesome.RANDOM, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
GeneratePassword.setToolTipText("Generate Password");
PasswordStrengthMeter = new JButton(IconFontSwing.buildIcon(FontAwesome.TACHOMETER, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
PasswordStrengthMeter.setToolTipText("Password Strength Meter");
StrengthReporter = new JButton(IconFontSwing.buildIcon(FontAwesome.NEWSPAPER_O, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
StrengthReporter.setToolTipText("Password Strength Report");
StrengthReporter.setEnabled(false);
HexViewerButton = new JButton(IconFontSwing.buildIcon(FontAwesome.TH, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
HexViewerButton.setToolTipText("View File Hexadecimal");
HexViewerButton.setEnabled(false);
// ~~~~~~~~~~~~~~~~~
LogToolbarButton = new JButton(IconFontSwing.buildIcon(FontAwesome.FILE_TEXT, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
LogToolbarButton.setToolTipText("Log");
ExitToolbarButton = new JButton(IconFontSwing.buildIcon(FontAwesome.POWER_OFF, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
ExitToolbarButton.setToolTipText("Exit");
timer = new Timer();
StartSessionTimer = new JButton(IconFontSwing.buildIcon(FontAwesome.PLAY_CIRCLE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
SessionTimer = new JLabel(timer.formatTime(timer.getDefaultSessionTime()));
SessionTimer.setToolTipText("Session Ends in");
SessionTimer.setForeground(Color.decode("#222222"));
SessionTimer.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
if (me.getButton() == 3) {
JPopupMenu popup = new JPopupMenu();
JLabel default_label;
JMenuItem update_timer, reset_timer;
JCheckBoxMenuItem start_timer;
default_label = new JLabel(Timer.formatTime(timer.getDefaultSessionTime()));
start_timer = new JCheckBoxMenuItem();
update_timer = new JMenuItem("Update");
reset_timer = new JMenuItem("Reset");
if (timer.isRunning()) {
start_timer.setText("Stop");
start_timer.setIcon(IconFontSwing.buildIcon(FontAwesome.PAUSE_CIRCLE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
} else {
start_timer.setText("Start");
start_timer.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY_CIRCLE, ui_vars.icons_size, Accent.AlphaSetGet(255)));
}
update_timer.setIcon(IconFontSwing.buildIcon(FontAwesome.CLOCK_O, ui_vars.icons_size, Accent.AlphaSetGet(255)));
reset_timer.setIcon(IconFontSwing.buildIcon(FontAwesome.REPEAT, ui_vars.icons_size, Accent.AlphaSetGet(255)));
// default_label.setEnabled(false);
default_label.setFocusable(false);
default_label.setHorizontalAlignment(SwingConstants.CENTER);
default_label.setForeground(Accent.AlphaSetGet(255));
start_timer.addActionListener(e -> {
if (timer.isRunning()) {
SessionTimer.setForeground(Color.decode("#222222"));
timer.stop_timer();
start_timer.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY_CIRCLE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
StartSessionTimer.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY_CIRCLE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
} else {
SessionTimer.setForeground(Accent.AlphaSetGet(255));
timer.start_timer();
start_timer.setIcon(IconFontSwing.buildIcon(FontAwesome.PAUSE_CIRCLE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
StartSessionTimer.setIcon(IconFontSwing.buildIcon(FontAwesome.PAUSE_CIRCLE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
Thread timerThread = new Thread(timer);
timerThread.start();
}
});
update_timer.addActionListener(e -> {
timer.updater(window);
});
reset_timer.addActionListener(e -> {
timer.setCurrentSessionTime(timer.getDefaultSessionTime());
timer.CallBack();
});
popup.add(default_label);
popup.addSeparator();
popup.add(start_timer);
popup.add(update_timer);
popup.add(reset_timer);
popup.show(SessionTimer, 0, SessionTimer.getHeight());
}
}
});
timer.setCallback(new Callable() {
@Override
public Object call() throws Exception {
int current = timer.getCurrentSessionTime();
SessionTimer.setText(Timer.formatTime(current));
if (current == timer.getDefaultSessionTime() / 3) {
new Thread(() -> {
SwingUtilities.invokeLater(() -> {
int answer = JOptionPane.showOptionDialog(window, "Session time about to end, wanna add 1min?", "Session timeout!", JOptionPane.PLAIN_MESSAGE, JOptionPane.QUESTION_MESSAGE, IconFontSwing.buildIcon(FontAwesome.CLOCK_O, ui_vars.icons_size * 3, Accent.AlphaSetGet(255)), new String[]{"yes"}, "yes");
if (answer == 0) {
timer.setCurrentSessionTime(timer.getCurrentSessionTime() + 60);
timer.CallBack();
}
});
}).start();
}
return null;
}
});
timer.setDoneCallback(new Callable() {
@Override
public Object call() throws Exception {
window.dispose();
if (AutoSaveOnTimeout_security_menu.isSelected()) {
Data.save_file();
saved();
}
return null;
}
});
StartSessionTimer.addActionListener(e -> {
if (timer.isRunning()) {
SessionTimer.setForeground(Color.decode("#222222"));
timer.stop_timer();
StartSessionTimer.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY_CIRCLE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
} else {
SessionTimer.setForeground(Accent.AlphaSetGet(255));
timer.start_timer();
StartSessionTimer.setIcon(IconFontSwing.buildIcon(FontAwesome.PAUSE_CIRCLE, ui_vars.icons_size + 5, Accent.AlphaSetGet(255)));
Thread timerThread = new Thread(timer);
timerThread.start();
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mpe) {
Point point = mpe.getPoint();
int row = table.rowAtPoint(point);
Table.selectionChange();
// left mouse button clicked twice
if (mpe.getClickCount() == 2 & mpe.getButton() == 1) {
Data.edit_entity();
}
Table.selectionChange();
}
});
table.getTableHeader().addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
}
});
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
private void handleSelectionEvent(ListSelectionEvent lse) {
if (lse.getValueIsAdjusting()) {
return;
}
Table.selectionChange();
}
public void valueChanged(ListSelectionEvent lse) {
handleSelectionEvent(lse);
}
});
NewFile.addActionListener(e -> {
if (!saved_changes) {
// yes=0
// no=1
// cancel=2
// closed=-1
int answer = JOptionPane.showConfirmDialog(window, "Unsaved changes will be lost.\nDo you want to save?", "Warning!", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (answer == 0) {
Data.save_file();
} else if (answer == 1) {
Data.new_file();
}