Skip to content

Commit

Permalink
Fixes code checkstyle violations
Browse files Browse the repository at this point in the history
  • Loading branch information
edimoral committed Mar 4, 2024
1 parent 9c557a2 commit 16dbcf8
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 103 deletions.
12 changes: 6 additions & 6 deletions src/main/java/jpass/ui/EntryDetailsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import jpass.util.DateUtils;
import jpass.xml.bind.Entry;

import static jpass.ui.JPassFrame.localizedMessages;
import static jpass.ui.JPassFrame.getLocalizedMessages;
import static jpass.util.Constants.VIEW_WINDOW_CREATED;
import static jpass.util.Constants.VIEW_WINDOW_MODIFIED;
import static jpass.util.Constants.VIEW_WINDOW_TITLE;
Expand All @@ -61,11 +61,11 @@ public class EntryDetailsTable extends JTable {
= DateUtils.createFormatter(Configuration.getInstance().get("date.format", "yyyy-MM-dd"));

private enum DetailType {
TITLE(localizedMessages.getString(VIEW_WINDOW_TITLE), Entry::getTitle),
URL(localizedMessages.getString(VIEW_WINDOW_URL), Entry::getUrl),
USER(localizedMessages.getString(VIEW_WINDOW_USER), Entry::getUser),
MODIFIED(localizedMessages.getString(VIEW_WINDOW_MODIFIED), entry -> DateUtils.formatIsoDateTime(entry.getLastModification(), FORMATTER)),
CREATED(localizedMessages.getString(VIEW_WINDOW_CREATED), entry -> DateUtils.formatIsoDateTime(entry.getCreationDate(), FORMATTER));
TITLE(getLocalizedMessages().getString(VIEW_WINDOW_TITLE), Entry::getTitle),
URL(getLocalizedMessages().getString(VIEW_WINDOW_URL), Entry::getUrl),
USER(getLocalizedMessages().getString(VIEW_WINDOW_USER), Entry::getUser),
MODIFIED(getLocalizedMessages().getString(VIEW_WINDOW_MODIFIED), entry -> DateUtils.formatIsoDateTime(entry.getLastModification(), FORMATTER)),
CREATED(getLocalizedMessages().getString(VIEW_WINDOW_CREATED), entry -> DateUtils.formatIsoDateTime(entry.getCreationDate(), FORMATTER));

private final String description;
private final Function<Entry, String> valueMapper;
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/jpass/ui/EntryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import jpass.util.StringUtils;
import jpass.xml.bind.Entry;

import static jpass.ui.JPassFrame.localizedMessages;
import static jpass.ui.JPassFrame.getLocalizedMessages;
import static jpass.ui.helper.EntryHelper.copyEntryField;
import static jpass.util.Constants.BUTTON_MESSAGE_CANCEL;
import static jpass.util.Constants.BUTTON_MESSAGE_OK;
Expand Down Expand Up @@ -129,15 +129,15 @@ public EntryDialog(JPassFrame parent, String title, Entry entry, boolean newEntr
this.originalEcho = this.passwordField.getEchoChar();
this.repeatField = TextComponentFactory.newPasswordField(true);

this.showButton = new JToggleButton(localizedMessages.getString(ENTRY_DIALOG_SHOW_ENTRY), MessageDialog.getIcon("show"));
this.showButton = new JToggleButton(getLocalizedMessages().getString(ENTRY_DIALOG_SHOW_ENTRY), MessageDialog.getIcon("show"));
this.showButton.setActionCommand("show_button");
this.showButton.setMnemonic(KeyEvent.VK_S);
this.showButton.addActionListener(this);
this.generateButton = new JButton(localizedMessages.getString(ENTRY_DIALOG_GENERATE_ENTRY), MessageDialog.getIcon("generate"));
this.generateButton = new JButton(getLocalizedMessages().getString(ENTRY_DIALOG_GENERATE_ENTRY), MessageDialog.getIcon("generate"));
this.generateButton.setActionCommand("generate_button");
this.generateButton.setMnemonic(KeyEvent.VK_G);
this.generateButton.addActionListener(this);
this.copyButton = new JButton(localizedMessages.getString(ENTRY_DIALOG_COPY_ENTRY), MessageDialog.getIcon("keyring"));
this.copyButton = new JButton(getLocalizedMessages().getString(ENTRY_DIALOG_COPY_ENTRY), MessageDialog.getIcon("keyring"));
this.copyButton.setActionCommand("copy_button");
this.copyButton.setMnemonic(KeyEvent.VK_P);
this.copyButton.addActionListener(this);
Expand All @@ -152,15 +152,15 @@ public EntryDialog(JPassFrame parent, String title, Entry entry, boolean newEntr
5, 0); // xPad, yPad

this.fieldPanel = new JPanel(new SpringLayout());
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_TITLE))));
this.fieldPanel.add(new JLabel(String.format("%s:", getLocalizedMessages().getString(VIEW_WINDOW_TITLE))));
this.fieldPanel.add(this.titleField);
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_URL))));
this.fieldPanel.add(new JLabel(String.format("%s:", getLocalizedMessages().getString(VIEW_WINDOW_URL))));
this.fieldPanel.add(this.urlField);
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_USER_NAME))));
this.fieldPanel.add(new JLabel(String.format("%s:", getLocalizedMessages().getString(VIEW_WINDOW_USER_NAME))));
this.fieldPanel.add(this.userField);
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_PASSWORD))));
this.fieldPanel.add(new JLabel(String.format("%s:", getLocalizedMessages().getString(VIEW_WINDOW_PASSWORD))));
this.fieldPanel.add(this.passwordField);
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_REPEAT))));
this.fieldPanel.add(new JLabel(String.format("%s:", getLocalizedMessages().getString(VIEW_WINDOW_REPEAT))));
this.fieldPanel.add(this.repeatField);
this.fieldPanel.add(new JLabel(""));
this.fieldPanel.add(this.passwordButtonPanel);
Expand All @@ -176,15 +176,15 @@ public EntryDialog(JPassFrame parent, String title, Entry entry, boolean newEntr

this.notesPanel = new JPanel(new BorderLayout(5, 5));
this.notesPanel.setBorder(new EmptyBorder(0, 5, 0, 5));
this.notesPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_NOTES))), BorderLayout.NORTH);
this.notesPanel.add(new JLabel(String.format("%s:", getLocalizedMessages().getString(VIEW_WINDOW_NOTES))), BorderLayout.NORTH);
this.notesPanel.add(new JScrollPane(this.notesField), BorderLayout.CENTER);

this.okButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_OK), MessageDialog.getIcon("accept"));
this.okButton = new JButton(getLocalizedMessages().getString(BUTTON_MESSAGE_OK), MessageDialog.getIcon("accept"));
this.okButton.setActionCommand("ok_button");
this.okButton.setMnemonic(KeyEvent.VK_O);
this.okButton.addActionListener(this);

this.cancelButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_CANCEL), MessageDialog.getIcon("cancel"));
this.cancelButton = new JButton(getLocalizedMessages().getString(BUTTON_MESSAGE_CANCEL), MessageDialog.getIcon("cancel"));
this.cancelButton.setActionCommand("cancel_button");
this.cancelButton.setMnemonic(KeyEvent.VK_C);
this.cancelButton.addActionListener(this);
Expand Down Expand Up @@ -212,13 +212,13 @@ public void actionPerformed(ActionEvent e) {
this.repeatField.setEchoChar(this.showButton.isSelected() ? NULL_ECHO : this.originalEcho);
} else if ("ok_button".equals(command)) {
if (this.titleField.getText().trim().isEmpty()) {
MessageDialog.showWarningMessage(this, localizedMessages.getString(ENTRY_DIALOG_FILL_TITLE_FIELD));
MessageDialog.showWarningMessage(this, getLocalizedMessages().getString(ENTRY_DIALOG_FILL_TITLE_FIELD));
return;
} else if (!checkEntryTitle()) {
MessageDialog.showWarningMessage(this, localizedMessages.getString(ENTRY_DIALOG_TITLE_ALREADY_EXISTS));
MessageDialog.showWarningMessage(this, getLocalizedMessages().getString(ENTRY_DIALOG_TITLE_ALREADY_EXISTS));
return;
} else if (!Arrays.equals(this.passwordField.getPassword(), this.repeatField.getPassword())) {
MessageDialog.showWarningMessage(this, localizedMessages.getString(PASSWORD_PASSWORDS_NOT_IDENTICAL));
MessageDialog.showWarningMessage(this, getLocalizedMessages().getString(PASSWORD_PASSWORDS_NOT_IDENTICAL));
return;
}
this.modifiedEntry = getEntryFromDialog();
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/jpass/ui/GeneratePasswordDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import jpass.util.CryptUtils;
import jpass.util.SpringUtilities;

import static jpass.ui.JPassFrame.localizedMessages;
import static jpass.ui.JPassFrame.getLocalizedMessages;
import static jpass.util.Constants.BUTTON_MESSAGE_ACCEPT;
import static jpass.util.Constants.BUTTON_MESSAGE_CANCEL;
import static jpass.util.Constants.BUTTON_MESSAGE_CLOSE;
Expand Down Expand Up @@ -87,9 +87,9 @@ public final class GeneratePasswordDialog extends JDialog implements ActionListe
* Options for password generation.
*/
private static final String[][] PASSWORD_OPTIONS = {
{localizedMessages.getString(VIEW_WINDOW_UPPER_CASE_LETTERS), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
{localizedMessages.getString(VIEW_WINDOW_LOWER_CASE_LETTERS), "abcdefghijklmnopqrstuvwxyz"},
{localizedMessages.getString(VIEW_WINDOW_NUMBERS), "0123456789"}
{getLocalizedMessages().getString(VIEW_WINDOW_UPPER_CASE_LETTERS), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
{getLocalizedMessages().getString(VIEW_WINDOW_LOWER_CASE_LETTERS), "abcdefghijklmnopqrstuvwxyz"},
{getLocalizedMessages().getString(VIEW_WINDOW_NUMBERS), "0123456789"}
};

private JCheckBox[] checkBoxes;
Expand Down Expand Up @@ -144,12 +144,12 @@ public GeneratePasswordDialog(JDialog parent) {
*/
private void initDialog(final Component parent, final boolean showAcceptButton) {
setModal(true);
setTitle(localizedMessages.getString(PASSWORD_GENERATE_PASSWORD));
setTitle(getLocalizedMessages().getString(PASSWORD_GENERATE_PASSWORD));
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.generatedPassword = null;

this.lengthPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
this.lengthLabel = new JLabel(String.format("%s:", localizedMessages.getString(PASSWORD_PASSWORD_LENGTH)));
this.lengthLabel = new JLabel(String.format("%s:", getLocalizedMessages().getString(PASSWORD_PASSWORD_LENGTH)));
this.lengthPanel.add(this.lengthLabel);

int passwordGenerationLength = Configuration.getInstance().getInteger("default.password.generation.length", 14);
Expand All @@ -164,14 +164,14 @@ private void initDialog(final Component parent, final boolean showAcceptButton)
this.lengthPanel.add(this.lengthSpinner);

this.charactersPanel = new JPanel();
this.charactersPanel.setBorder(new TitledBorder(localizedMessages.getString(VIEW_WINDOW_SETTINGS)));
this.charactersPanel.setBorder(new TitledBorder(getLocalizedMessages().getString(VIEW_WINDOW_SETTINGS)));
this.charactersPanel.add(this.lengthPanel);
this.checkBoxes = new JCheckBox[PASSWORD_OPTIONS.length];
for (int i = 0; i < PASSWORD_OPTIONS.length; i++) {
this.checkBoxes[i] = new JCheckBox(PASSWORD_OPTIONS[i][0], true);
this.charactersPanel.add(this.checkBoxes[i]);
}
this.customSymbolsCheck = new JCheckBox(localizedMessages.getString(VIEW_WINDOW_CUSTOM_SYMBOLS));
this.customSymbolsCheck = new JCheckBox(getLocalizedMessages().getString(VIEW_WINDOW_CUSTOM_SYMBOLS));
this.customSymbolsCheck.setActionCommand("custom_symbols_check");
this.customSymbolsCheck.addActionListener(this);
this.charactersPanel.add(this.customSymbolsCheck);
Expand All @@ -183,11 +183,11 @@ private void initDialog(final Component parent, final boolean showAcceptButton)
SpringUtilities.makeCompactGrid(this.charactersPanel, 6, 1, 5, 5, 5, 5);

this.passwordPanel = new JPanel(new BorderLayout());
this.passwordPanel.setBorder(new TitledBorder(localizedMessages.getString(PASSWORD_GENERATED_PASSWORD)));
this.passwordPanel.setBorder(new TitledBorder(getLocalizedMessages().getString(PASSWORD_GENERATED_PASSWORD)));

this.passwordField = TextComponentFactory.newTextField();
this.passwordPanel.add(this.passwordField, BorderLayout.NORTH);
this.generateButton = new JButton(localizedMessages.getString(ENTRY_DIALOG_GENERATE_ENTRY), MessageDialog.getIcon("generate"));
this.generateButton = new JButton(getLocalizedMessages().getString(ENTRY_DIALOG_GENERATE_ENTRY), MessageDialog.getIcon("generate"));
this.generateButton.setActionCommand("generate_button");
this.generateButton.addActionListener(this);
this.generateButton.setMnemonic(KeyEvent.VK_G);
Expand All @@ -198,15 +198,15 @@ private void initDialog(final Component parent, final boolean showAcceptButton)
this.buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

if (showAcceptButton) {
this.acceptButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_ACCEPT), MessageDialog.getIcon("accept"));
this.acceptButton = new JButton(getLocalizedMessages().getString(BUTTON_MESSAGE_ACCEPT), MessageDialog.getIcon("accept"));
this.acceptButton.setActionCommand("accept_button");
this.acceptButton.setMnemonic(KeyEvent.VK_A);
this.acceptButton.addActionListener(this);
this.buttonPanel.add(this.acceptButton);

this.cancelButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_CANCEL), MessageDialog.getIcon("cancel"));
this.cancelButton = new JButton(getLocalizedMessages().getString(BUTTON_MESSAGE_CANCEL), MessageDialog.getIcon("cancel"));
} else {
this.cancelButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_CLOSE), MessageDialog.getIcon("close"));
this.cancelButton = new JButton(getLocalizedMessages().getString(BUTTON_MESSAGE_CLOSE), MessageDialog.getIcon("close"));
}

this.cancelButton.setActionCommand("cancel_button");
Expand Down Expand Up @@ -247,7 +247,7 @@ public void actionPerformed(ActionEvent e) {
}

if (characterSet.isEmpty()) {
MessageDialog.showWarningMessage(this, localizedMessages.getString(PASSWORD_CAN_NOT_GENERATE_PASSWORD));
MessageDialog.showWarningMessage(this, getLocalizedMessages().getString(PASSWORD_CAN_NOT_GENERATE_PASSWORD));
return;
}

Expand All @@ -260,7 +260,7 @@ public void actionPerformed(ActionEvent e) {
} else if ("accept_button".equals(command)) {
this.generatedPassword = this.passwordField.getText();
if (this.generatedPassword.isEmpty()) {
MessageDialog.showWarningMessage(this, localizedMessages.getString(PASSWORD_GENERATE_PASSWORD_REQUEST));
MessageDialog.showWarningMessage(this, getLocalizedMessages().getString(PASSWORD_GENERATE_PASSWORD_REQUEST));
return;
}
dispose();
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/jpass/ui/JPassFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
*/
public final class JPassFrame extends JFrame {

public static ResourceBundle localizedMessages = null;
private static ResourceBundle localizedMessages = null;
private static final Logger LOG = Logger.getLogger(JPassFrame.class.getName());

private static JPassFrame instance;
Expand Down Expand Up @@ -371,4 +371,12 @@ public boolean isProcessing() {
public SearchPanel getSearchPanel() {
return searchPanel;
}

/**
* Gets the resource bundle for localization
* @return resource bundle
*/
public static ResourceBundle getLocalizedMessages() {
return localizedMessages;
}
}
Loading

0 comments on commit 16dbcf8

Please sign in to comment.