11
11
import java .awt .SystemColor ;
12
12
import java .awt .event .ActionEvent ;
13
13
import java .awt .event .ActionListener ;
14
+ import java .awt .event .ItemEvent ;
15
+ import java .awt .event .ItemListener ;
14
16
import java .awt .event .KeyAdapter ;
15
17
import java .awt .event .KeyEvent ;
16
18
import java .io .File ;
17
19
import java .io .FileInputStream ;
20
+ import java .io .FileNotFoundException ;
18
21
import java .io .FileOutputStream ;
19
22
import java .io .IOException ;
20
23
import java .io .InputStream ;
25
28
import java .nio .file .NoSuchFileException ;
26
29
import java .nio .file .Path ;
27
30
import java .nio .file .Paths ;
31
+ import java .text .SimpleDateFormat ;
28
32
import java .util .ArrayList ;
33
+ import java .util .Calendar ;
29
34
import java .util .HashMap ;
30
35
import java .util .List ;
31
36
import java .util .Map ;
37
+ import java .util .zip .ZipEntry ;
38
+ import java .util .zip .ZipOutputStream ;
32
39
33
40
import javax .imageio .ImageIO ;
34
41
import javax .swing .BorderFactory ;
89
96
import java .awt .Component ;
90
97
import javax .swing .Box ;
91
98
import javax .swing .ButtonGroup ;
99
+ import java .awt .Rectangle ;
100
+ import java .awt .Point ;
92
101
93
102
public class MainFrame extends JFrame {
94
103
private Logger logger ;
@@ -347,6 +356,13 @@ public class MainFrame extends JFrame {
347
356
private JButton btnDigitalSignatureVerify ;
348
357
private boolean shouldSignWithoutPairing = false ;
349
358
private String signingCIEPAN = "" ;
359
+ private JPanel configPreferencesPanel ;
360
+ private JLabel lblConfigPreferencesTitle ;
361
+ private JLabel lblConfigPreferencesCaption ;
362
+ private JLabel lblConfigPreferencesCaption_1 ;
363
+ private JCheckBox cboxShowTutorial ;
364
+ private JButton btnDeleteLogs ;
365
+ private JButton btnCollectLogs ;
350
366
351
367
private enum SignOp {
352
368
OP_NONE ,
@@ -620,6 +636,9 @@ public void actionPerformed(ActionEvent arg0) {
620
636
rdbtnLoggingLibInfo .setSelected (logConfig .lib .equals (LogLevel .INFO ));
621
637
rdbtnLoggingLibError .setSelected (logConfig .lib .equals (LogLevel .ERROR ));
622
638
selectButton (btnSettings );
639
+ boolean showTutorial = ("false" .equals (Utils .getProperty ("nomore" , "false" ))) ?
640
+ true : false ;
641
+ cboxShowTutorial .setSelected (showTutorial );
623
642
tabbedPane .setSelectedIndex (17 );
624
643
}
625
644
});
@@ -940,7 +959,7 @@ public void actionPerformed(ActionEvent e) {
940
959
if (selectedCIE .getCard ().getIsCustomSign ()) {
941
960
logger .Debug ("Firma personalizzata presente" );
942
961
lblCustomize .setText ("Aggiorna" );
943
- lblHint .setText ("Un tua firma personalizzata è già stata caricata. Vuoi aggiornarla?" );
962
+ lblHint .setText ("La tua firma personalizzata è già stata caricata. Vuoi aggiornarla?" );
944
963
lblFPOK .setVisible (true );
945
964
lblSFP .setVisible (false );
946
965
} else {
@@ -2673,6 +2692,56 @@ public void actionPerformed(ActionEvent e) {
2673
2692
panelConfigLoggingLib .add (rdbtnLoggingLibError );
2674
2693
verticalGlue_4 = Box .createVerticalGlue ();
2675
2694
panelConfigLoggingLib .add (verticalGlue_4 );
2695
+
2696
+ btnDeleteLogs = new JButton ("Elimina cache dei log" );
2697
+ btnDeleteLogs .setForeground (Color .WHITE );
2698
+ btnDeleteLogs .setBackground (new Color (30 , 144 , 255 ));
2699
+ btnDeleteLogs .setBounds (292 , 436 , 236 , 25 );
2700
+ btnDeleteLogs .addActionListener (new ActionListener () {
2701
+ public void actionPerformed (ActionEvent e ) {
2702
+ logger .Info ("Inizia 'deleteLogs'" );
2703
+ deleteLogs ();
2704
+ }
2705
+ });
2706
+ configLoggingPanel .add (btnDeleteLogs );
2707
+
2708
+ btnCollectLogs = new JButton ("Raccogli log per diagnostica" );
2709
+ btnCollectLogs .setForeground (Color .WHITE );
2710
+ btnCollectLogs .setBackground (new Color (30 , 144 , 255 ));
2711
+ btnCollectLogs .setBounds (47 , 436 , 236 , 25 );
2712
+ btnCollectLogs .addActionListener (new ActionListener () {
2713
+ public void actionPerformed (ActionEvent e ) {
2714
+ logger .Info ("Inizia 'CollectLogs'" );
2715
+ collectLogs ();
2716
+ }
2717
+ });
2718
+ configLoggingPanel .add (btnCollectLogs );
2719
+
2720
+ configPreferencesPanel = new JPanel ();
2721
+ configTabbedPane .addTab ("Preferenze" , null , configPreferencesPanel , null );
2722
+ configPreferencesPanel .setLayout (null );
2723
+
2724
+ lblConfigPreferencesTitle = new JLabel ("Configurazione preferenze" );
2725
+ lblConfigPreferencesTitle .setBounds (72 , 5 , 421 , 33 );
2726
+ lblConfigPreferencesTitle .setHorizontalAlignment (SwingConstants .CENTER );
2727
+ lblConfigPreferencesTitle .setFont (new Font ("Dialog" , Font .BOLD , 28 ));
2728
+ configPreferencesPanel .add (lblConfigPreferencesTitle );
2729
+
2730
+ lblConfigPreferencesCaption = new JLabel ("Le opzioni di seguito riportate consentono di personalizzare" );
2731
+ lblConfigPreferencesCaption .setBounds (40 , 43 , 486 , 18 );
2732
+ lblConfigPreferencesCaption .setFont (new Font ("Dialog" , Font .BOLD , 15 ));
2733
+ configPreferencesPanel .add (lblConfigPreferencesCaption );
2734
+
2735
+ lblConfigPreferencesCaption_1 = new JLabel ("il comportamento di CIE ID secondo le proprie preferenze" );
2736
+ lblConfigPreferencesCaption_1 .setBounds (45 , 66 , 475 , 18 );
2737
+ lblConfigPreferencesCaption_1 .setFont (new Font ("Dialog" , Font .BOLD , 15 ));
2738
+ configPreferencesPanel .add (lblConfigPreferencesCaption_1 );
2739
+
2740
+ cboxShowTutorial = new JCheckBox ("Mostra schermate introduttive all'avvio di CIE ID" );
2741
+ cboxShowTutorial .setSize (363 , 23 );
2742
+ cboxShowTutorial .setLocation (new Point (94 , 148 ));
2743
+ configPreferencesPanel .add (cboxShowTutorial );
2744
+ cboxShowTutorial .setActionCommand ("" );
2676
2745
configButtonsPanel = new JPanel ();
2677
2746
configButtonsPanel .setBackground (Color .WHITE );
2678
2747
configButtonsPanel .setBounds (0 , 524 , 595 , 47 );
@@ -2735,7 +2804,8 @@ public void actionPerformed(ActionEvent arg0) {
2735
2804
} else {
2736
2805
Utils .setProperty ("proxyPort" , txtPort .getText ());
2737
2806
}
2738
-
2807
+
2808
+ Utils .setProperty ("nomore" , cboxShowTutorial .isSelected () ? "false" : "true" );
2739
2809
disableConfigurationPaneControls ();
2740
2810
}
2741
2811
});
@@ -2761,6 +2831,88 @@ public void actionPerformed(ActionEvent arg0) {
2761
2831
2762
2832
System .out .println ("tabbedPanel: " + tabbedPane );
2763
2833
}
2834
+
2835
+ private void collectLogs () {
2836
+ boolean logFound = false ;
2837
+ JFileChooser fileChooser = new JFileChooser ();
2838
+
2839
+ fileChooser .setDialogType (JFileChooser .SAVE_DIALOG );
2840
+ fileChooser .setDialogTitle ("Seleziona il percorso in cui salvare l'archivio dei log" );
2841
+ FileNameExtensionFilter filter ;
2842
+ filter = new FileNameExtensionFilter ("Archivio zip" , ".zip" );
2843
+ fileChooser .setFileFilter (filter );
2844
+ fileChooser .setSelectedFile (new File (System .getProperty ("user.home" ) + "/CIEIDLog_" +
2845
+ new SimpleDateFormat ("dd_MM_yyyy_HH_mm_ss" ).format (Calendar .getInstance ().getTime ()) + ".zip" ));
2846
+
2847
+ if (fileChooser .showSaveDialog (null ) == JFileChooser .APPROVE_OPTION ) {
2848
+ File zipFile = fileChooser .getSelectedFile ();
2849
+ ZipOutputStream logZipOutputStream ;
2850
+ try {
2851
+ logZipOutputStream = new ZipOutputStream (new FileOutputStream (zipFile ));
2852
+ File folder = new File (System .getProperty ("user.home" ), ".CIEPKI" );
2853
+ for (final File fileEntry : folder .listFiles ()) {
2854
+ if (fileEntry .getName ().endsWith (".log" )) {
2855
+ logFound = true ;
2856
+ ZipEntry entry = new ZipEntry (fileEntry .getName ());
2857
+ logZipOutputStream .putNextEntry (entry );
2858
+
2859
+ byte [] data = Files .readAllBytes (fileEntry .toPath ());
2860
+ logZipOutputStream .write (data , 0 , data .length );
2861
+ logZipOutputStream .closeEntry ();
2862
+ }
2863
+ }
2864
+
2865
+ logZipOutputStream .close ();
2866
+
2867
+ if (logFound ) {
2868
+ logger .Info ("[INFO] collectLogs() - Archivio dei log creato con successo al path: " + zipFile .getAbsolutePath ());
2869
+ JOptionPane .showMessageDialog (this .getContentPane (), "La raccolta dei log di diagnostica è avvenuta con successo.\n " +
2870
+ "Puoi adesso condividere con gli sviluppatori l'archivio\n generato per un'analisi della problematica riscontrata." ,
2871
+ "Raccolta completata" , JOptionPane .INFORMATION_MESSAGE );
2872
+ }
2873
+
2874
+ else {
2875
+ JOptionPane .showMessageDialog (this .getContentPane (), "Non sono presenti log. Effettua prima delle operazioni con l'applicativo, " +
2876
+ "quindi ripeti l'operazione di raccolta dei log." , "Raccolta log" , JOptionPane .INFORMATION_MESSAGE );
2877
+
2878
+ Files .deleteIfExists (zipFile .toPath ());
2879
+ }
2880
+ } catch (IOException ex ) {
2881
+ logger .Error ("[ERROR] collectLogs() - Si è verificato un errore durante l'operazione:\n \n " + ex .getLocalizedMessage ());
2882
+ JOptionPane .showMessageDialog (this .getContentPane (), "Si è verificato un errore durante l'operazione:\n \n " + ex .getLocalizedMessage (),
2883
+ "Attenzione" , JOptionPane .ERROR_MESSAGE );
2884
+ }
2885
+ }
2886
+ }
2887
+
2888
+ private void deleteLogs () {
2889
+ if (JOptionPane .showConfirmDialog (this .getContentPane (), "Avanzando con l'operazione, verranno eliminati tutti i file di log\n " +
2890
+ "generati dal software CIE ID. Confermi di voler procedere?" , "Eliminazione log" , JOptionPane .YES_NO_OPTION ) != JOptionPane .YES_OPTION ) {
2891
+ return ;
2892
+ }
2893
+
2894
+ try {
2895
+ File folder = new File (System .getProperty ("user.home" ), ".CIEPKI" );
2896
+ for (final File fileEntry : folder .listFiles ()) {
2897
+ if (fileEntry .getName ().endsWith (".log" )) {
2898
+ Files .deleteIfExists (fileEntry .toPath ());
2899
+ }
2900
+ }
2901
+
2902
+ logger .Info ("[INFO] deleteLogs() - Log eliminati con successo." );
2903
+ JOptionPane .showMessageDialog (this .getContentPane (), "L'eliminazione dei log è avvenuta con successo. Se hai riscontrato un'anomalia nel software\n " +
2904
+ "che intendi segnalare, puoi impostare il livello di logging su 'Debug', replicare l'operazione,\n " +
2905
+ "raccogliere i log con l'apposito pulsante e condividerli con lo sviluppatore." ,
2906
+ "Eliminazione completata" , JOptionPane .ERROR_MESSAGE );
2907
+
2908
+ } catch (Exception ex ) {
2909
+ logger .Error ("[ERROR] deleteLogs() - Si è verificato un errore durante l'operazione:" + ex .getLocalizedMessage ());
2910
+ JOptionPane .showMessageDialog (this .getContentPane (), "Si è verificato un errore durante la cancellazione dei log.\n " +
2911
+ "È possibile che alcuni file siano aperti ed in uso da terze parti, per cui non\n " +
2912
+ " è stato possibile procedere con l'eliminazione. Motivazione:\n \n " + ex .getLocalizedMessage (),
2913
+ "Attenzione" , JOptionPane .ERROR_MESSAGE );
2914
+ }
2915
+ }
2764
2916
2765
2917
private void chooseSignOrVerifyFileOperation (String filePath ) {
2766
2918
logger .Info ("Inizia 'filesDropped'" );
@@ -2807,6 +2959,7 @@ private void setConfigurationPaneControlsState(boolean value) {
2807
2959
rdbtnLoggingLibDebug .setEnabled (value );
2808
2960
rdbtnLoggingLibInfo .setEnabled (value );
2809
2961
rdbtnLoggingLibError .setEnabled (value );
2962
+ cboxShowTutorial .setEnabled (value );
2810
2963
}
2811
2964
2812
2965
private void selectButton (JButton button ) {
@@ -3959,5 +4112,4 @@ private void saveLogConfigToFile() {
3959
4112
System .out .println (exception );
3960
4113
}
3961
4114
}
3962
-
3963
4115
}
0 commit comments