Skip to content

Commit

Permalink
Merge pull request #876 from stokito/empty_string
Browse files Browse the repository at this point in the history
SPARK-2337 Refacroring, cleanup and reformat
  • Loading branch information
Plyha authored Aug 24, 2024
2 parents f44c3bd + b4a355f commit 9609360
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 81 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jivesoftware/LoginDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void windowClosing(WindowEvent e) {
quitLogin();
}
});
if (loginPanel.getUsername().trim().length() > 0) {
if (ModelUtil.hasLength(loginPanel.getUsername())) {
loginPanel.getPasswordField().requestFocus();
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jivesoftware/gui/LoginUIPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public void windowClosing(WindowEvent e) {
quitLogin();
}
});
if (getUsernameField().getText().trim().length() > 0) {
if (ModelUtil.hasLength(getUsernameField().getText())) {
getPasswordField().requestFocus();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,11 @@ public void propertyChange(PropertyChangeEvent e) {
dialog.setVisible(false);
}
else if (Res.getString("ok").equals(value)) {
stringValue = textArea.getText();
if (stringValue.trim().length() == 0) {
stringValue = textArea.getText().trim();
if (stringValue.isEmpty()) {
stringValue = null;
}
else {
stringValue = stringValue.trim();
}
dialog.setVisible(false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,10 @@ public void propertyChange(PropertyChangeEvent e) {
dialog.setVisible(false);
}
else if (Res.getString("ok").equals(value)) {
stringValue = String.valueOf(passwordField.getPassword());
if (stringValue.trim().length() == 0) {
stringValue = String.valueOf(passwordField.getPassword()).trim();
if (stringValue.isEmpty()) {
stringValue = null;
}
else {
stringValue = stringValue.trim();
}
dialog.setVisible(false);
}
}
Expand Down
51 changes: 22 additions & 29 deletions core/src/main/java/org/jivesoftware/spark/ui/RosterDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,10 @@ public void mouseEntered(MouseEvent e) {

groupBox.setEditable(true);

if (groupModel.size() == 0) {
if (groupModel.isEmpty()) {
groupBox.addItem("Friends");
}

if (groupModel.size() > 0) {
groupBox.setSelectedIndex(0);
}
groupBox.setSelectedIndex(0);

jidField.addFocusListener(new FocusListener() {
@Override
Expand All @@ -235,7 +232,7 @@ public void focusLost(FocusEvent e) {
fullJID = fullJID + "@" + SparkManager.getConnection().getXMPPServiceDomain();
}

if ( !fullJID.isEmpty() && !fullJID.startsWith( "@" ))
if (!fullJID.startsWith( "@" ))
{
BareJid bareJid = JidCreate.bareFromOrThrowUnchecked(fullJID);
vcardNickname = SparkManager.getUserManager().getNickname( bareJid );
Expand All @@ -259,7 +256,7 @@ public void focusLost(FocusEvent e) {
accounts.addItem(item);
}

if (accountCol.size() > 0) {
if (!accountCol.isEmpty()) {
accountsLabel.setVisible(true);
accounts.setVisible(true);
publicBox.setVisible(true);
Expand All @@ -281,7 +278,7 @@ public void setDefaultGroup(ContactGroup contactGroup) {
if (groupModel.contains(groupName)) {
groupBox.setSelectedItem(groupName);
}
else if (groupModel.size() > 0) {
else {
groupBox.addItem(groupName);
groupBox.setSelectedItem(groupName);
}
Expand Down Expand Up @@ -309,7 +306,7 @@ public void setDefaultNickname(String nickname) {
@Override
public void actionPerformed(ActionEvent e) {
String group = JOptionPane.showInputDialog(dialog, Res.getString("label.enter.group.name") + ":", Res.getString("title.new.roster.group"), JOptionPane.QUESTION_MESSAGE);
if (group != null && group.length() > 0 && !groupModel.contains(group)) {
if (group != null && !group.isEmpty() && !groupModel.contains(group)) {
Roster.getInstanceFor( SparkManager.getConnection() ).createGroup(group);
groupModel.add(group);
int size = groupModel.size();
Expand Down Expand Up @@ -341,18 +338,18 @@ public Dimension getPreferredSize() {
mainPanel.add(titlePanel, BorderLayout.NORTH);
mainPanel.add(panel, BorderLayout.CENTER);

JButton addbutton = new JButton(Res.getString("add"));
JButton buttonAdd = new JButton(Res.getString("add"));

addbutton.addActionListener( e -> addContactButton() );
buttonAdd.addActionListener( e -> addContactButton() );

JButton cancelbutton = new JButton(Res.getString("cancel"));
cancelbutton.addActionListener( e -> dialog.dispose() );
JButton buttonCancel = new JButton(Res.getString("cancel"));
buttonCancel.addActionListener( e -> dialog.dispose() );


JPanel buttonpanel = new JPanel(new FlowLayout());
buttonpanel.add(addbutton);
buttonpanel.add(cancelbutton);
mainPanel.add(buttonpanel, BorderLayout.SOUTH);
JPanel panelButtons = new JPanel(new FlowLayout());
panelButtons.add(buttonAdd);
panelButtons.add(buttonCancel);
mainPanel.add(panelButtons, BorderLayout.SOUTH);

dialog = new JDialog(parent, Res.getString("title.add.contact"), false);
dialog.setContentPane(mainPanel);
Expand Down Expand Up @@ -450,17 +447,14 @@ public void finished() {

rosterEntryThread.start();
}

/**
* Creates a Popupdialog above the Search Button displaying matching
* Contacts
*
* @param byname
* , the Searchname, atleast 5 Chars long
* @param event
* , the MouseEvent which triggered it
* Creates a PopupDialog above the Search Button displaying matching Contacts
*
* @param byname the Search name, at least 5 chars long
* @param event the MouseEvent which triggered it
* @throws XMPPException
* @throws InterruptedException
* @throws InterruptedException
*/
public void searchForContact(String byname, MouseEvent event)
throws XMPPException, SmackException.NotConnectedException, SmackException.NoResponseException, InterruptedException
Expand Down Expand Up @@ -558,7 +552,7 @@ public RosterEntry addEntry(BareJid jid, String nickname, String group) {

boolean isSubscribed = true;
if (userEntry != null) {
isSubscribed = userEntry.getGroups().size() == 0;
isSubscribed = userEntry.getGroups().isEmpty();
}

if (isSubscribed) {
Expand Down Expand Up @@ -617,8 +611,7 @@ private void addContactButton() {

UIManager.put("OptionPane.okButtonText", Res.getString("ok"));

if(jid.length()==0)
{
if (jid.isEmpty()) {
JOptionPane.showMessageDialog(dialog, Res.getString("message.invalid.jid.error"),
Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,11 @@ public void propertyChange(PropertyChangeEvent e) {
dialog.setVisible(false);
}
else if (Res.getString("ok").equals(value)) {
stringValue = textArea.getText();
if (stringValue.trim().length() == 0) {
stringValue = textArea.getText().trim();
if (stringValue.isEmpty()) {
stringValue = "";
}
else {
stringValue = stringValue.trim();
}
dialog.setVisible(false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ public void actionPerformed(ActionEvent e) {
}
};
String label = locale.getDisplayLanguage(locale);
if (locale.getDisplayCountry(locale) != null &&
locale.getDisplayCountry(locale).trim().length() > 0) {
label = label + "-" + locale.getDisplayCountry(locale).trim();
if (!locale.getDisplayCountry(locale).isEmpty()) {
label = label + "-" + locale.getDisplayCountry(locale);
}
action.putValue(Action.NAME, label);
languageMenu.add(action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class SpellcheckChatRoomDecorator implements ActionListener,
private JTextComponentSpellChecker _sc;
private RolloverButton _spellingButton;
private ChatRoom _room;
private JComboBox _languageSelection = new JComboBox();
private JComboBox<String> _languageSelection = new JComboBox<>();
private Map<String, String> _languages;

public SpellcheckChatRoomDecorator(ChatRoom room) {
Expand Down Expand Up @@ -141,26 +141,22 @@ public void closing() {
private void languagestoLocales()
{
String spellLanguage = SpellcheckManager.getInstance().getSpellcheckerPreference().getPreferences().getSpellLanguage();
_languages = new HashMap<String, String>();
_languages = new HashMap<>();
Locale[] locales = Locale.getAvailableLocales();
ArrayList<String> languages = SpellcheckManager.getInstance().getSupportedLanguages();
for (int i = 0; i < languages.size(); i++) {
for (String language : languages) {
for (final Locale locale : locales) {
if (locale.toString().equals(languages.get(i))) {
String label = locale.getDisplayLanguage(Locale
.getDefault());
if (locale.getDisplayCountry(locale) != null
&& locale.getDisplayCountry(locale).trim().length() > 0) {
label = label + "-"
+ locale.getDisplayCountry(locale).trim();
if (locale.toString().equals(language)) {
String label = locale.getDisplayLanguage(Locale.getDefault());
if (!locale.getDisplayCountry(locale).isEmpty()) {
label = label + "-" + locale.getDisplayCountry(locale);
}
_languages.put(label, languages.get(i));
_languages.put(label, language);
_languageSelection.addItem(label);
if (languages.get(i).equals(spellLanguage))
{
if (language.equals(spellLanguage)) {
_languageSelection.setSelectedItem(label);
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class SpellcheckerPreferenceDialog extends JPanel implements

private JCheckBox spellcheckingEnabled;
private JCheckBox autospellcheckingEnabled;
private JComboBox spellLanguages;
private JComboBox<String> spellLanguages;
private JCheckBox ignoreCase;
private JCheckBox showLanguages;
private JPanel spellPanel;
Expand All @@ -52,7 +52,7 @@ public SpellcheckerPreferenceDialog(ArrayList<String> languages) {
spellPanel = new JPanel();
spellcheckingEnabled = new JCheckBox();
autospellcheckingEnabled = new JCheckBox();
spellLanguages = new JComboBox();
spellLanguages = new JComboBox<>();
showLanguages = new JCheckBox();
spellPanel.setLayout(new GridBagLayout());

Expand All @@ -72,20 +72,17 @@ public void actionPerformed(ActionEvent e) {

// autospellcheckingEnabled.setText(SpellcheckerResource.getString("preference.autoSpellcheckingEnabled"));

for (int i = 0; i < languages.size(); i++) {
for (final Locale locale : locales) {
if (locale.toString().equals(languages.get(i))) {
String label = locale.getDisplayLanguage(Locale
.getDefault());
if (locale.getDisplayCountry(locale) != null
&& locale.getDisplayCountry(locale).trim().length() > 0) {
label = label + "-"
+ locale.getDisplayCountry(locale).trim();
}
spellLanguages.addItem(label);
}
}
}
for (String language : languages) {
for (final Locale locale : locales) {
if (locale.toString().equals(language)) {
String label = locale.getDisplayLanguage(Locale.getDefault());
if (!locale.getDisplayCountry(locale).isEmpty()) {
label = label + "-" + locale.getDisplayCountry(locale);
}
spellLanguages.addItem(label);
}
}
}

spellPanel.add(spellcheckingEnabled, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
spellPanel.add(autospellcheckingEnabled, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
Expand Down

0 comments on commit 9609360

Please sign in to comment.