/** * Returns <CODE>null</CODE> if the specified string is empty or * <CODE>null</CODE>. Otherwise the string itself is returned. * * @param s String to check * @return Returns null string if string is empty, otherwise string itself. */ public static String nullifyIfEmpty(String s) { return ModelUtil.hasLength(s) ? s : null; }
/** * Validate the given text - to pass it must contain letters, digits, '@', '-', '_', '.', ',' * or a space character. * * @param text the text to check * @return true if the given text is valid, false otherwise. */ public boolean validateChars(String text) { if (!ModelUtil.hasLength(text)) { return false; } for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); if (!Character.isLetterOrDigit(ch) && ch != '@' && ch != '-' && ch != '_' && ch != '.' && ch != ',' && ch != ' ') { return false; } } return true; }
/** * Sets the reason the user was disconnected from the server. * * @param reason the reason the user was disconnected from the server. */ public void setDisconnectReason(String reason) { if (!ModelUtil.hasLength(reason)) { reason = Res.getString("message.generic.reconnect.message"); } String builder = "<html><body><table height=100% width=100%><tr><td align=center>" + "<b><u>" + reason + "</u></b>" + "</td></tr></table></body></html>"; pane.setText( builder ); }
public boolean isMessageIntercepted(TranscriptWindow window, String userid, Message message) { String body = message.getBody(); if (ModelUtil.hasLength(body) && body.startsWith("/me ")) { body = body.replaceFirst("/me", userid); window.insertNotificationMessage(body, Color.MAGENTA); return true; } return false; }
/** * Checks the users input and enables/disables the login button depending on state. */ private void validateDialog() { loginButton.setEnabled(loginAnonymouslyBox.isSelected() || ModelUtil.hasLength(getUsername()) && ( ModelUtil.hasLength(getPassword()) || localPref.isSSOEnabled() ) && ModelUtil.hasLength(getServerName()) ); }
public boolean validate_settings() { boolean valid = true; UIManager.put( "OptionPane.okButtonText", Res.getString( "ok" ) ); if ( usePKIBox.isSelected() ) { if ( !ModelUtil.hasLength( fileField.getText() ) ) { JOptionPane.showMessageDialog( optionsDialog, "You must specify a file location", Res.getString( "title.error" ), JOptionPane.ERROR_MESSAGE ); fileField.requestFocus(); valid = false; } } return valid; }
private void handlePopup(MouseEvent e) { popup = new JPopupMenu(); popup.add(cutMenu); popup.add(copyMenu); popup.add(pasteMenu); fireContextMenuListeners(); popup.addSeparator(); popup.add(selectAll); // Handle enable boolean textSelected = ModelUtil.hasLength(getSelectedText()); String clipboard = SparkManager.getClipboard(); cutMenu.setEnabled(textSelected && isEditable()); copyMenu.setEnabled(textSelected); pasteMenu.setEnabled(ModelUtil.hasLength(clipboard) && isEditable()); popup.show(this, e.getX(), e.getY()); }
/** * Loads the language set by the user. If no language is set, then the default implementation will be used. */ private void loadLanguage() { final LocalPreferences preferences = SettingsManager.getLocalPreferences(); final String setLanguage = preferences.getLanguage(); if (ModelUtil.hasLength(setLanguage)) { Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { if (locale.toString().equals(setLanguage)) { Locale.setDefault(locale); break; } } } } public void copyEmoticonFiles(String workdir) {
/** * Returns the url of the avatar belonging to this contact. * * @return the url of the avatar. * @throws MalformedURLException thrown if the address is invalid. */ public URL getAvatarURL() throws MalformedURLException { contactsDir.mkdirs(); if (ModelUtil.hasLength(hash)) { final File imageFile = new File(contactsDir, hash); if (imageFile.exists()) { return imageFile.toURI().toURL(); } } return SparkManager.getVCardManager().getAvatarURLIfAvailable(getJid()); }
public String getNickname(BareJid jid) { String vcardNickname = null; VCard vCard = SparkManager.getVCardManager().getVCard(jid); if (vCard != null && vCard.getError() == null) { String firstName = vCard.getFirstName(); String lastName = vCard.getLastName(); String nickname = vCard.getNickName(); if (ModelUtil.hasLength(nickname)) { vcardNickname = nickname; } else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) { vcardNickname = firstName + " " + lastName; } else if (ModelUtil.hasLength(firstName)) { vcardNickname = firstName; } } return vcardNickname; }
public boolean isDataValid() { boolean dataIsValid = true; if (ModelUtil.hasLength(panel.getPassword()) && ModelUtil.hasLength(panel.getConfirmationPassword())) { if (!panel.getPassword().equals(panel.getConfirmationPassword())) { errorMessage = Res.getString("message.passwords.no.match"); dataIsValid = false; } } return dataIsValid; }
/** * Sets the status label text based on the users status. * * @param status the users status. */ public void setStatusText(String status) { setStatus(status); if (ModelUtil.hasLength(status)) { getDescriptionLabel().setText(" - " + status); } else { getDescriptionLabel().setText(""); } }
public URL getAvatarURL(BareJid jid) { VCard vcard = getVCard(jid); if (vcard != null) { String hash = vcard.getAvatarHash(); if (!ModelUtil.hasLength(hash)) { return null; } final File avatarFile = new File(contactsDir, hash); try { return avatarFile.toURI().toURL(); } catch (MalformedURLException e) { Log.error(e); } } return null; }
@Override public void sendMessage( String text ) { // IF there is no body, just return and do nothing if ( !ModelUtil.hasLength( text ) ) { return; } // Set the body of the message using typedMessage and remove control characters final Message message = new Message(); message.setBody( text.replaceAll( "[\\u0001-\\u0008\\u000B-\\u001F]", "" ) ); sendMessage( message ); }
/** * Enables/Disables the editable components in the login screen. * * @param editable true to enable components, otherwise false to disable. */ private void enableComponents(boolean editable) { // Need to set both editable and enabled for best behavior. usernameField.setEditable(editable); usernameField.setEnabled(editable && !loginAnonymouslyBox.isSelected()); passwordField.setEditable(editable); passwordField.setEnabled(editable && !loginAnonymouslyBox.isSelected()); final String lockedDownURL = Default.getString(Default.HOST_NAME); if (!ModelUtil.hasLength(lockedDownURL)) { serverField.setEditable(editable); serverField.setEnabled(editable); } if (editable) { // Reapply focus to username field passwordField.requestFocus(); } }
@Override public void actionPerformed( ActionEvent e ) { final String newSubject = JOptionPane.showInputDialog( getChatRoom(), Res.getString( "message.enter.new.subject" ) + ":", Res.getString( "title.change.subject" ), JOptionPane.QUESTION_MESSAGE ); if ( ModelUtil.hasLength( newSubject ) ) { try { chat.changeSubject( newSubject ); } catch ( XMPPException | SmackException | InterruptedException xmpee ) { getTranscriptWindow().insertNotificationMessage( xmpee.getMessage(), ChatManager.ERROR_COLOR ); scrollToBottom(); } } } } );
@Override public void kicked( Jid s, String reason ) { if ( ModelUtil.hasLength( reason ) ) { insertText( reason ); } else { insertText( Res.getString( "message.your.kicked", s ) ); } getChatInputEditor().setEnabled( false ); getSplitPane().setRightComponent( null ); leaveChatRoom(); }
public void keyReleased(KeyEvent keyEvent) { if (keyEvent.getKeyChar() == KeyEvent.VK_ENTER) { if (ModelUtil.hasLength(contactField.getText())) { ContactItem item = contactMap.get(contactField.getText()); if (item == null) { item = contactField.getSelectedContactItem(); } if (item != null) { parent.setGlassPane(glassPane); parent.getGlassPane().setVisible(false); contactField.dispose(); SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName()); } } } else if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) { parent.setGlassPane(glassPane); parent.getGlassPane().setVisible(false); contactField.dispose(); } } });
public String getNickname() { final VCardManager vCardManager = SparkManager.getVCardManager(); VCard vcard = vCardManager.getVCard(); if (vcard == null) { return SparkManager.getSessionManager().getUsername(); } else { String nickname = vcard.getNickName(); if (ModelUtil.hasLength(nickname)) { return nickname; } else { String firstName = vcard.getFirstName(); if (ModelUtil.hasLength(firstName)) { return firstName; } } } // Default to node if nothing. String username = SparkManager.getSessionManager().getUsername(); username = XmppStringUtils.unescapeLocalpart(username); return username; }
private void openChatRoom(int row) { String jidString = (String)resultsTable.getValueAt(row, 0); EntityBareJid jid = JidCreate.entityBareFromOrThrowUnchecked(jidString); Localpart nickname = jid.getLocalpart(); TableColumn column; try { column = resultsTable.getColumn("nick"); int col = column.getModelIndex(); String nicknameString = (String)resultsTable.getValueAt(row, col); if (!ModelUtil.hasLength(nicknameString)) { nickname = JidCreate.from(nicknameString).getLocalpartOrThrow(); } } catch (Exception e1) { // Ignore e1 } ChatManager chatManager = SparkManager.getChatManager(); ChatRoom chatRoom = chatManager.createChatRoom(jid, nickname, nickname); ChatContainer chatRooms = chatManager.getChatContainer(); chatRooms.activateChatRoom(chatRoom); }