14
14
import org .slf4j .LoggerFactory ;
15
15
16
16
import javax .swing .*;
17
- import java .awt .event .MouseAdapter ;
18
- import java .awt .event .MouseEvent ;
19
17
import java .io .File ;
20
18
import java .util .ArrayList ;
21
19
import java .util .List ;
@@ -39,24 +37,24 @@ private SettingsDialog(DeviceScreen deviceScreen) {
39
37
}
40
38
41
39
private void initalizeUi () {
42
- addButton ( "Manage Columns" , "EDIT" , () -> showManageDeviceColumnsDialog (deviceScreen ));
43
- addButton ( "Custom Apps" , "EDIT" , this ::showAppsSettings );
44
- addButton ( "Customize Toolbar" , "EDIT" , () -> showManageToolbar (deviceScreen ));
45
- addButton ( "Download Location" , "EDIT" , this ::showDownloadLocation );
46
-
47
- addCheckbox ( "Minimize to System Tray" , PreferenceUtils .PrefBoolean .PREF_EXIT_TO_TRAY , false , null );
48
- addCheckbox ( "Check for updates" , PreferenceUtils .PrefBoolean .PREF_CHECK_UPDATES , true , isChecked -> deviceScreen .scheduleUpdateChecks ());
49
- addCheckbox ( "Show background image" , PreferenceUtils .PrefBoolean .PREF_SHOW_BACKGROUND , true , isChecked -> {
40
+ UiUtils . addSettingButton ( this , "Manage Columns" , "EDIT" , () -> showManageDeviceColumnsDialog (deviceScreen ));
41
+ UiUtils . addSettingButton ( this , "Custom Apps" , "EDIT" , this ::showAppsSettings );
42
+ UiUtils . addSettingButton ( this , "Customize Toolbar" , "EDIT" , () -> showManageToolbar (deviceScreen ));
43
+ UiUtils . addSettingButton ( this , "Download Location" , "EDIT" , this ::showDownloadLocation );
44
+
45
+ UiUtils . addSettingCheckbox ( this , "Minimize to System Tray" , PreferenceUtils .PrefBoolean .PREF_EXIT_TO_TRAY , false , null );
46
+ UiUtils . addSettingCheckbox ( this , "Check for updates" , PreferenceUtils .PrefBoolean .PREF_CHECK_UPDATES , true , isChecked -> deviceScreen .scheduleUpdateChecks ());
47
+ UiUtils . addSettingCheckbox ( this , "Show background image" , PreferenceUtils .PrefBoolean .PREF_SHOW_BACKGROUND , true , isChecked -> {
50
48
// force table background to be repainted
51
49
deviceScreen .model .fireTableDataChanged ();
52
50
});
53
51
54
- JButton logButton = addButton ( "Log Level" , "EDIT" , null );
52
+ JButton logButton = UiUtils . addSettingButton ( this , "Log Level" , "EDIT" , null );
55
53
UiUtils .addClickListener (logButton , e -> toggleLogLevels (logButton ));
56
54
updateLogLevel (logButton );
57
55
58
- addButton ( "View Logs" , "VIEW" , this ::viewLogs );
59
- addButton ( "Reset Preferences" , "RESET" , this ::resetPreferences );
56
+ UiUtils . addSettingButton ( this , "View Logs" , "VIEW" , this ::viewLogs );
57
+ UiUtils . addSettingButton ( this , "Reset Preferences" , "RESET" , this ::resetPreferences );
60
58
61
59
doLayout ();
62
60
invalidate ();
@@ -102,55 +100,6 @@ private void toggleLogLevels(JButton logButton) {
102
100
updateLogLevel (logButton );
103
101
}
104
102
105
- public interface ButtonListener {
106
- void onClicked ();
107
- }
108
-
109
- private JButton addButton (String label , String action , ButtonListener listener ) {
110
- add (new JLabel (label ));
111
- JButton button = new JButton (action );
112
- if (listener != null ) {
113
- UiUtils .addClickListener (button , e -> {
114
- listener .onClicked ();
115
- });
116
- }
117
- add (button , "wrap" );
118
- return button ;
119
- }
120
-
121
- public interface CheckBoxListener {
122
- void onChecked (boolean isChecked );
123
- }
124
-
125
- private void addCheckbox (String label , PreferenceUtils .PrefBoolean pref , boolean defaultValue , CheckBoxListener listener ) {
126
- JLabel textLabel = new JLabel (label );
127
- add (textLabel );
128
-
129
- JCheckBox checkbox = new JCheckBox ();
130
- boolean currentChecked = PreferenceUtils .getPreference (pref , defaultValue );
131
- checkbox .setSelected (currentChecked );
132
- checkbox .setHorizontalTextPosition (SwingConstants .LEFT );
133
- add (checkbox , "align center, wrap" );
134
-
135
- checkbox .addActionListener (actionEvent -> {
136
- boolean selected = checkbox .isSelected ();
137
- PreferenceUtils .setPreference (pref , selected );
138
- if (listener != null ) listener .onChecked (selected );
139
- });
140
-
141
- textLabel .addMouseListener (new MouseAdapter () {
142
- @ Override
143
- public void mouseClicked (MouseEvent mouseEvent ) {
144
- // TODO: fire checkbox action listener directly
145
- boolean selected = !checkbox .isSelected ();
146
- checkbox .setSelected (selected );
147
- PreferenceUtils .setPreference (pref , selected );
148
- if (listener != null ) listener .onChecked (selected );
149
- }
150
- });
151
-
152
- }
153
-
154
103
private void resetPreferences () {
155
104
if (!DialogHelper .showConfirmDialog (deviceScreen , "Reset Preferences" , "Reset All Preferences?" )) return ;
156
105
0 commit comments