/** * This is a utility method that compares two Booleans when one or * both of the objects might be <CODE>null</CODE> The result of * this method is determined as follows: * <OL> * <LI>If <CODE>b1</CODE> and <CODE>b2</CODE> are both TRUE or * neither <CODE>b1</CODE> nor <CODE>b2</CODE> is TRUE, * return <CODE>false</CODE>. * <LI>Otherwise, return <CODE>true</CODE>. * </OL> * <p/> * This method produces the exact logically inverted result as the * {@link #areBooleansEqual(Boolean, Boolean)} method.<P> * * @param b1 First boolean to compare * @param b2 Second boolean to compare * @return True if booleans are different */ public static boolean areBooleansDifferent(Boolean b1, Boolean b2) { return !areBooleansEqual(b1, b2); }
private boolean validatePanel() { String roomName = nameField.getText(); String password = new String(passwordField.getPassword()); String confirmPassword = new String(confirmPasswordField.getPassword()); boolean isPrivate = privateCheckbox.isSelected(); // Check for valid information if (!ModelUtil.hasLength(roomName)) { showError(Res.getString("message.specify.name.error")); nameField.requestFocus(); return false; } if (isPrivate) { if (!ModelUtil.hasLength(password)) { showError(Res.getString("message.password.private.room.error")); passwordField.requestFocus(); return false; } if (!ModelUtil.hasLength(confirmPassword)) { showError(Res.getString("message.confirmation.password.error")); confirmPasswordField.requestFocus(); return false; } if (!ModelUtil.areEqual(password, confirmPassword)) { showError(Res.getString("message.passwords.no.match")); passwordField.requestFocus(); return false; } } return true; }
/** * Returns a single string that is the concatenation of all the * strings in the specified string array. A single space is * put between each string array element. Null array elements * are skipped. If the array itself is null, the empty string * is returned. This method is guaranteed to return a non-null * value, if no expections are thrown. * * @param strs Array of strings to concatenate. * @return Concatenated string. */ public static String concat(String[] strs) { return concat(strs, " "); //NOTRANS }
/** * 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; }
protected void allTabsClosed() { final Iterator<SparkTabbedPaneListener> list = ModelUtil.reverseListIterator(listeners .listIterator()); while (list.hasNext()) { list.next().allTabsRemoved(); } }
if (!ModelUtil.hasLength(status)) { if (contactItem.getPresence() == null || contactItem.getPresence().getType() == Presence.Type.unavailable) { status = Res.getString("offline"); } else if (contactItem.getPresence().isAway()) { status += "\n"; String time = ModelUtil.getTimeFromLong(idleTime); status += Res.getString("message.idle.for", time); title = vcard.getField("TITLE"); phone = vcard.getPhoneWork("VOICE"); if (!ModelUtil.hasLength(title)) { title = ""; if (!ModelUtil.hasLength(phone)) { phone = "";
/** * Returns <CODE>null</CODE> if the specified object is null * or if its <CODE>toString()</CODE> representation is empty. * Otherwise, the <CODE>toString()</CODE> representation of the * object itself is returned. * * @param o Object to check * @return Returns null string if string(object) is empty, otherwise string itself. */ public static String nullifyingToString(Object o) { return o != null ? nullifyIfEmpty(o.toString()) : null; }
/** * This is a utility method that compares two objects when one or * both of the objects might be <CODE>null</CODE>. The result * returned by this method is determined as follows: * <OL> * <LI>If <CODE>o1</CODE> and <CODE>o2</CODE> are the same object * according to the <CODE>==</CODE> operator, return * <CODE>false</CODE>. * <LI>Otherwise, if either <CODE>o1</CODE> or <CODE>o2</CODE> is * <CODE>null</CODE>, return <CODE>true</CODE>. * <LI>Otherwise, return <CODE>!o1.equals(o2)</CODE>. * </OL> * <p/> * This method produces the exact logically inverted result as the * {@link #areEqual(Object, Object)} method.<P> * <p/> * For array types, one of the <CODE>equals</CODE> methods in * {@link java.util.Arrays} should be used instead of this method. * Note that arrays with more than one dimension will require some * custom code in order to implement <CODE>equals</CODE> properly. * * @param o1 First object to compare * @param o2 Second object to compare * @return True if objects are different */ public static boolean areDifferent(Object o1, Object o2) { return !areEqual(o1, o2); }
public void actionPerformed(ActionEvent actionEvent) { try { String client = ""; if (item.getPresence().getType() != Presence.Type.unavailable) { client = item.getPresence().getFrom().toString(); if ((client != null) && (client.lastIndexOf("/") != -1)) { client = client.substring(client.lastIndexOf("/")); } else client = "/"; } Jid jid = JidCreate.from(item.getJid().toString() + client); LastActivity activity = LastActivityManager.getInstanceFor( SparkManager.getConnection() ).getLastActivity(jid); long idleTime = (activity.getIdleTime() * 1000); String time = ModelUtil.getTimeFromLong(idleTime); UIManager.put("OptionPane.okButtonText", Res.getString("ok")); JOptionPane.showMessageDialog(getGUI(), Res.getString("message.idle.for", time), Res.getString("title.last.activity"), JOptionPane.INFORMATION_MESSAGE); } catch (Exception e1) { UIManager.put("OptionPane.okButtonText", Res.getString("ok")); JOptionPane.showMessageDialog(getGUI(), Res.getString("message.unable.to.retrieve.last.activity", item.getJID()), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); } } };
/** * 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; }
/** * Flash the given window, but stop flashing when the window takes focus. * * @param window the window to start flashing. */ public void flashWindowStopOnFocus(Window window) { final Iterator<NativeHandler> alertNotifiers = ModelUtil.reverseListIterator(nativeHandlers.listIterator()); while (alertNotifiers.hasNext()) { final NativeHandler alert = alertNotifiers.next(); boolean handle = alert.handleNotification(); if (handle) { alert.flashWindowStopWhenFocused(window); } } }
public String getEmptyPropertyIfNull(String name) { return ModelUtil.nullifyIfEmpty(getSettings().get(name)); }
/** * 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 ); }
/** * Stop the flashing of the window. * * @param window the window to stop flashing. */ public void stopFlashing(Window window) { final Iterator<NativeHandler> alertNotifiers = ModelUtil.reverseListIterator(nativeHandlers.listIterator()); while (alertNotifiers.hasNext()) { final NativeHandler alert = alertNotifiers.next(); boolean handle = alert.handleNotification(); if (handle) { alert.stopFlashing(window); } } }
/** * 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()) ); }
/** * Flash the given window. * * @param window the window to flash. */ public void flashWindow(Window window) { final Iterator<NativeHandler> alertNotifier = ModelUtil.reverseListIterator(nativeHandlers.listIterator()); while (alertNotifier.hasNext()) { final NativeHandler alert = alertNotifier.next(); boolean handle = alert.handleNotification(); if (handle) { alert.flashWindow(window); } } }
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; }
protected void fireTabAdded( SparkTab tab, Component component, int index ) { final Iterator<SparkTabbedPaneListener> list = ModelUtil.reverseListIterator( listeners.listIterator() ); while ( list.hasNext() ) { final SparkTabbedPaneListener listener = list.next(); try { listener.tabAdded( tab, component, index ); } catch ( Exception e ) { Log.error( "A SparkTabbedPaneListener (" + listener + ") threw an exception while processing a 'tabAdded' event (tab: '" + tab + "', component: '" + component + "', index: '" + index + "').", e ); } } }
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; }
protected void fireTabRemoved( SparkTab tab, Component component, int index ) { final Iterator<SparkTabbedPaneListener> list = ModelUtil.reverseListIterator( listeners.listIterator() ); while ( list.hasNext() ) { final SparkTabbedPaneListener listener = list.next(); try { listener.tabRemoved( tab, component, index ); } catch ( Exception e ) { Log.error( "A SparkTabbedPaneListener (" + listener + ") threw an exception while processing a 'tabRemoved' event (tab: '" + tab + "', component: '" + component + "', index: '" + index + "').", e ); } } }