Skip to content

Commit a9500ba

Browse files
committed
Refine welcome message for clarity and update note formatting
1 parent 308b851 commit a9500ba

4 files changed

Lines changed: 148 additions & 29 deletions

File tree

src/main/java/org/pwss/controller/LoginController.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.pwss.view.screen.LoginScreen;
1717
import org.slf4j.LoggerFactory;
1818

19-
2019
import static org.pwss.app_settings.AppConfig.LICENSE_KEY;
2120

2221
/**
@@ -151,12 +150,12 @@ private void proceedAndValidate() {
151150
int choice = screen.showOptionDialog(JOptionPane.INFORMATION_MESSAGE,
152151
"""
153152
Welcome to Integrity Hash!
154-
155-
You are about to create a user for this application.
156-
Please make sure to remember your credentials as they will be required for future logins.
157-
158-
Do you want to proceed?""",
159-
new String[]{StringConstants.GENERIC_YES, StringConstants.GENERIC_NO},
153+
154+
You are about to set up access to this application. Please make sure to remember your credentials as they will be required for future logins.
155+
156+
Do you want to proceed?
157+
""",
158+
new String[] { StringConstants.GENERIC_YES, StringConstants.GENERIC_NO },
160159
StringConstants.GENERIC_YES);
161160

162161
if (choice == 0) {
@@ -181,7 +180,8 @@ private boolean validateInput() {
181180
String confirmPassword = screen.getConfirmPassword();
182181
String licenseKey = licenseKeySet ? LICENSE_KEY : screen.getLicenseKey();
183182

184-
LoginUtils.LoginValidationResult result = LoginUtils.validateInput(username, password, confirmPassword, licenseKey, createUserMode);
183+
LoginUtils.LoginValidationResult result = LoginUtils.validateInput(username, password, confirmPassword,
184+
licenseKey, createUserMode);
185185
if (!result.isValid()) {
186186
screen.showError(LoginUtils.formatErrors(result.errors()));
187187
}
@@ -253,7 +253,7 @@ private void performLogin() {
253253
if (createUserMode) {
254254
screen.showInfo("User created and logged in successfully!");
255255
} else {
256-
log.info("Logged in successfully!");
256+
log.info("Logged in successfully!");
257257
}
258258
AppConfig.setLicenseKey(licenseKey);
259259
NavigationEvents.navigateTo(Screen.HOME);

src/main/java/org/pwss/utils/StringConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public final class StringConstants {
6363

6464
// Update note related strings
6565
public static final String MON_DIR_POPUP_UPDATE_NOTE = "Update note";
66-
public static final String MON_DIR_POPUP_UPDATE_NOTE_POPUP_PREFIX = "Update note for: ";
66+
public static final String MON_DIR_POPUP_UPDATE_NOTE_POPUP_PREFIX = "Update Note -";
6767
public static final String MON_DIR_POPUP_UPDATE_NOTE_SUCCESS = "Note updated successfully.";
6868
public static final String MON_DIR_POPUP_UPDATE_NOTE_ERROR = "Failed to update note.";
6969

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package org.pwss.utils;
2+
3+
/**
4+
* A utility class for string manipulation operations.
5+
* This class contains static methods to perform various string manipulations.
6+
*/
7+
public final class StringUtils {
8+
9+
/**
10+
*
11+
* Private constructor to prevent instantiation
12+
**/
13+
private StringUtils() {
14+
}
15+
16+
/**
17+
* Adds a space character at the end of the given string.
18+
*
19+
* @param str The input string. If it is null, null is returned.
20+
* @return A new string with a space appended to the end of the input string,
21+
* or null if the input was null.
22+
*/
23+
public static String addSpace(String str) {
24+
if (str == null)
25+
return null;
26+
return str + " ";
27+
}
28+
29+
/**
30+
* Adds a space character at the beginning of the given string.
31+
*
32+
* @param str The input string. If it is null, null is returned.
33+
* @return A new string with a space prepended to the beginning of the input
34+
* string,
35+
* or null if the input was null.
36+
*/
37+
public static String prependSpace(String str) {
38+
if (str == null)
39+
return null;
40+
return " " + str;
41+
}
42+
43+
/**
44+
* Pads the given string on the right with spaces until it reaches the specified
45+
* length.
46+
*
47+
* @param str The input string. If it is null, null is returned.
48+
* @param length The desired length of the resulting string. If the input
49+
* string's
50+
* length is already greater than or equal to this value, the
51+
* original
52+
* string will be returned unchanged.
53+
* @return A new string with spaces appended on the right until it reaches the
54+
* specified
55+
* length, or null if the input was null.
56+
*/
57+
public static String padRight(String str, int length) {
58+
if (str == null)
59+
return null;
60+
if (str.length() >= length)
61+
return str;
62+
StringBuilder sb = new StringBuilder(str);
63+
while (sb.length() < length) {
64+
sb.append(' ');
65+
}
66+
return sb.toString();
67+
}
68+
69+
/**
70+
* Pads the given string on the left with spaces until it reaches the specified
71+
* length.
72+
*
73+
* @param str The input string. If it is null, null is returned.
74+
* @param length The desired length of the resulting string. If the input
75+
* string's
76+
* length is already greater than or equal to this value, the
77+
* original
78+
* string will be returned unchanged.
79+
* @return A new string with spaces prepended on the left until it reaches the
80+
* specified
81+
* length, or null if the input was null.
82+
*/
83+
public static String padLeft(String str, int length) {
84+
if (str == null)
85+
return null;
86+
if (str.length() >= length)
87+
return str;
88+
StringBuilder sb = new StringBuilder();
89+
while (sb.length() < length - str.length()) {
90+
sb.append(' ');
91+
}
92+
sb.append(str);
93+
return sb.toString();
94+
}
95+
96+
/**
97+
* Capitalizes the first letter of the given string.
98+
*
99+
* @param str The input string. If it is null or empty, the original string will
100+
* be returned.
101+
* @return A new string with the first letter capitalized, or the original
102+
* string if
103+
* it was null or empty.
104+
*/
105+
public static String capitalizeFirstLetter(String str) {
106+
if (isEmpty(str))
107+
return str;
108+
return str.substring(0, 1).toUpperCase() + str.substring(1);
109+
}
110+
111+
// Assuming isEmpty method exists as referred in the code
112+
private static boolean isEmpty(String str) {
113+
return str == null || str.isEmpty();
114+
}
115+
}

src/main/java/org/pwss/view/popup_menu/MonitoredDirectoryPopupFactory.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
import org.pwss.model.request.notes.RestoreNoteType;
2020
import org.pwss.model.table.MonitoredDirectoryTableModel;
2121
import org.pwss.utils.StringConstants;
22+
import org.pwss.utils.StringUtils;
2223
import org.pwss.view.popup_menu.listener.MonitoredDirectoryPopupListener;
2324

2425
/**
25-
* Factory class to create a context menu (popup menu) for monitored directories in a JTable.
26-
* The menu provides options to scan the directory, reset its baseline, and edit its details.
26+
* Factory class to create a context menu (popup menu) for monitored directories
27+
* in a JTable.
28+
* The menu provides options to scan the directory, reset its baseline, and edit
29+
* its details.
2730
*/
2831
public class MonitoredDirectoryPopupFactory {
2932
private final MonitoredDirectoryPopupListener listener;
@@ -39,11 +42,13 @@ public JPopupMenu create(JTable table, int viewRow) {
3942
MonitoredDirectoryTableModel model = (MonitoredDirectoryTableModel) table.getModel();
4043
Optional<MonitoredDirectory> dirOpt = model.getDirectoryAt(modelRow);
4144

42-
if (dirOpt.isEmpty()) return menu;
45+
if (dirOpt.isEmpty())
46+
return menu;
4347
MonitoredDirectory dir = dirOpt.get();
4448

4549
// Scan this directory
46-
JMenuItem scanItem = new JMenuItem(dir.baselineEstablished() ? StringConstants.MON_DIR_POPUP_START_SCAN : StringConstants.MON_DIR_POPUP_ESTABLISH_BASELINE);
50+
JMenuItem scanItem = new JMenuItem(dir.baselineEstablished() ? StringConstants.MON_DIR_POPUP_START_SCAN
51+
: StringConstants.MON_DIR_POPUP_ESTABLISH_BASELINE);
4752
scanItem.addActionListener(e -> listener.onStartScan());
4853

4954
// Reset baseline
@@ -87,19 +92,23 @@ public JPopupMenu create(JTable table, int viewRow) {
8792
* @return the JMenuItem for toggling the active status
8893
*/
8994
private JMenuItem getToggleActiveMenuItem(MonitoredDirectory dir) {
90-
JMenuItem editItem = new JMenuItem(dir.isActive() ? StringConstants.MON_DIR_TOGGLE_ACTIVE_DISABLE : StringConstants.MON_DIR_TOGGLE_ACTIVE_ENABLE);
95+
JMenuItem editItem = new JMenuItem(dir.isActive() ? StringConstants.MON_DIR_TOGGLE_ACTIVE_DISABLE
96+
: StringConstants.MON_DIR_TOGGLE_ACTIVE_ENABLE);
9197
editItem.addActionListener(e -> listener.onToggleActiveStatus(dir));
9298
return editItem;
9399
}
94100

95101
/**
96-
* Creates a menu item for toggling the inclusion of subdirectories in a monitored directory.
102+
* Creates a menu item for toggling the inclusion of subdirectories in a
103+
* monitored directory.
97104
*
98105
* @param dir the monitored directory for which to create the menu item
99106
* @return the JMenuItem for toggling the inclusion of subdirectories
100107
*/
101108
private JMenuItem getToggleIncludeSubDirsItem(MonitoredDirectory dir) {
102-
JMenuItem editItem = new JMenuItem(dir.includeSubdirectories() ? StringConstants.MON_DIR_TOGGLE_INCLUDE_SUBDIR_DISABLE : StringConstants.MON_DIR_TOGGLE_INCLUDE_SUBDIR_ENABLE);
109+
JMenuItem editItem = new JMenuItem(
110+
dir.includeSubdirectories() ? StringConstants.MON_DIR_TOGGLE_INCLUDE_SUBDIR_DISABLE
111+
: StringConstants.MON_DIR_TOGGLE_INCLUDE_SUBDIR_ENABLE);
103112
editItem.addActionListener(e -> listener.onToggleIncludeSubdirectories(dir));
104113
return editItem;
105114
}
@@ -121,8 +130,7 @@ private JMenuItem getShowNoteItem(MonitoredDirectory dir) {
121130
listener.getParentComponent(),
122131
note,
123132
StringConstants.MON_DIR_POPUP_SHOW_NOTE,
124-
JOptionPane.INFORMATION_MESSAGE
125-
);
133+
JOptionPane.INFORMATION_MESSAGE);
126134
});
127135
return showNoteItem;
128136
}
@@ -137,7 +145,8 @@ private JMenuItem getUpdateNoteItem(MonitoredDirectory dir) {
137145
JMenuItem updateNoteItem = new JMenuItem(StringConstants.MON_DIR_POPUP_UPDATE_NOTE);
138146
updateNoteItem.addActionListener(e -> {
139147
// Label for directory path
140-
JLabel label = new JLabel(StringConstants.MON_DIR_POPUP_UPDATE_NOTE_POPUP_PREFIX + dir.path());
148+
JLabel label = new JLabel(
149+
StringConstants.MON_DIR_POPUP_UPDATE_NOTE_POPUP_PREFIX + StringUtils.prependSpace(dir.path()));
141150
label.setAlignmentX(Component.LEFT_ALIGNMENT);
142151

143152
// Text area for note input
@@ -164,8 +173,7 @@ private JMenuItem getUpdateNoteItem(MonitoredDirectory dir) {
164173
panel,
165174
StringConstants.MON_DIR_POPUP_UPDATE_NOTE,
166175
JOptionPane.OK_CANCEL_OPTION,
167-
JOptionPane.PLAIN_MESSAGE
168-
);
176+
JOptionPane.PLAIN_MESSAGE);
169177

170178
// User cancelled
171179
if (result != JOptionPane.OK_OPTION)
@@ -200,8 +208,7 @@ private JMenuItem getRestoreNoteItem(MonitoredDirectory dir) {
200208
listener.getParentComponent(),
201209
StringConstants.MON_DIR_POPUP_RESTORE_NO_NOTE_FALLBACK + dir.path(),
202210
StringConstants.MON_DIR_POPUP_RESTORE_NOTE,
203-
JOptionPane.INFORMATION_MESSAGE
204-
);
211+
JOptionPane.INFORMATION_MESSAGE);
205212
return;
206213
}
207214

@@ -241,8 +248,7 @@ private JMenuItem getRestoreNoteItem(MonitoredDirectory dir) {
241248
JOptionPane.PLAIN_MESSAGE,
242249
null,
243250
options.toArray(),
244-
options.get(0)
245-
);
251+
options.get(0));
246252

247253
// Handle result
248254
if (choice == JOptionPane.CLOSED_OPTION || choice == options.size() - 1) {
@@ -273,8 +279,7 @@ private JMenuItem getResetBaselineItem(MonitoredDirectory dir) {
273279
listener.getParentComponent(),
274280
StringConstants.MON_DIR_POPUP_RESET_BASELINE_POPUP_MESSAGE + dir.path(),
275281
StringConstants.MON_DIR_POPUP_RESET_BASELINE_POPUP_TITLE,
276-
JOptionPane.WARNING_MESSAGE
277-
);
282+
JOptionPane.WARNING_MESSAGE);
278283

279284
try {
280285
// User cancelled
@@ -290,4 +295,3 @@ private JMenuItem getResetBaselineItem(MonitoredDirectory dir) {
290295
return resetBaselineItem;
291296
}
292297
}
293-

0 commit comments

Comments
 (0)