View Javadoc
1   package com.jsql.view.swing.panel.preferences;
2   
3   import com.jsql.view.swing.panel.PanelPreferences;
4   import com.jsql.view.swing.util.MediatorHelper;
5   
6   import javax.swing.*;
7   import javax.swing.border.Border;
8   import java.util.stream.Stream;
9   
10  public class PanelGeneral extends JPanel {
11  
12      public static final Border MARGIN = BorderFactory.createEmptyBorder(0,0,2,0);
13  
14      private final JCheckBox checkboxIsCheckingUpdate = new JCheckBox("Check update at startup", MediatorHelper.model().getMediatorUtils().getPreferencesUtil().isCheckingUpdate());
15      private final JCheckBox checkboxIsReportingBugs = new JCheckBox("Report unhandled exceptions", MediatorHelper.model().getMediatorUtils().getPreferencesUtil().isReportingBugs());
16      private final JCheckBox checkboxIs4K = new JCheckBox("Enable high-definition mode for 4K screens (need a restart)", MediatorHelper.model().getMediatorUtils().getPreferencesUtil().is4K());
17      
18      public PanelGeneral(PanelPreferences panelPreferences) {
19          this.checkboxIsReportingBugs.setToolTipText("Send unhandled exception to developer in order to fix issues.");
20          this.checkboxIs4K.setToolTipText("Upscale GUI by factor 2.5 for compatibility with high-definition screens");
21  
22          Stream.of(
23              this.checkboxIsCheckingUpdate,
24              this.checkboxIsReportingBugs,
25              this.checkboxIs4K
26          )
27          .forEach(button -> button.addActionListener(panelPreferences.getActionListenerSave()));
28  
29          var labelOrigin = new JLabel("<html><b>Settings and behaviors</b></html>");
30          labelOrigin.setBorder(PanelGeneral.MARGIN);
31  
32          var groupLayout = new GroupLayout(this);
33          this.setLayout(groupLayout);
34  
35          groupLayout.setHorizontalGroup(
36              groupLayout
37              .createSequentialGroup()
38              .addGroup(
39                  groupLayout
40                  .createParallelGroup(GroupLayout.Alignment.LEADING, false)
41                  .addComponent(labelOrigin)
42                  .addComponent(this.checkboxIsCheckingUpdate)
43                  .addComponent(this.checkboxIsReportingBugs)
44                  .addComponent(this.checkboxIs4K)
45              )
46          );
47  
48          groupLayout.setVerticalGroup(
49              groupLayout
50              .createSequentialGroup()
51              .addGroup(
52                  groupLayout
53                  .createParallelGroup(GroupLayout.Alignment.BASELINE)
54                  .addComponent(labelOrigin)
55              )
56              .addGroup(
57                  groupLayout
58                  .createParallelGroup(GroupLayout.Alignment.BASELINE)
59                  .addComponent(this.checkboxIsCheckingUpdate)
60              )
61              .addGroup(
62                  groupLayout
63                  .createParallelGroup(GroupLayout.Alignment.BASELINE)
64                  .addComponent(this.checkboxIsReportingBugs)
65              )
66              .addGroup(
67                  groupLayout
68                  .createParallelGroup(GroupLayout.Alignment.BASELINE)
69                  .addComponent(this.checkboxIs4K)
70              )
71          );
72      }
73  
74      
75      // Getter and setter
76      
77      public JCheckBox getCheckboxIsCheckingUpdate() {
78          return this.checkboxIsCheckingUpdate;
79      }
80  
81      public JCheckBox getCheckboxIsReportingBugs() {
82          return this.checkboxIsReportingBugs;
83      }
84  
85      public JCheckBox getCheckboxIs4K() {
86          return this.checkboxIs4K;
87      }
88  }