diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-06-30 08:29:32 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2011-06-30 08:29:32 +0000 |
commit | e314c85e748c3633c9f620fc3552fe64bbd59259 (patch) | |
tree | 2d9c8c83d298ddf66de716a6e9c4d8fecd9ba63f /src/net/java/sip | |
parent | ee06f7d446b82fa55c61f0efc6934edc962d191e (diff) | |
download | jitsi-e314c85e748c3633c9f620fc3552fe64bbd59259.zip jitsi-e314c85e748c3633c9f620fc3552fe64bbd59259.tar.gz jitsi-e314c85e748c3633c9f620fc3552fe64bbd59259.tar.bz2 |
Adds a missing return and removes a few instance fields in the contact list UI, spares a few allocations in the history.
Diffstat (limited to 'src/net/java/sip')
16 files changed, 190 insertions, 212 deletions
diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryContactSource.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryContactSource.java index 0ce7349..032b31d 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryContactSource.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryContactSource.java @@ -18,7 +18,8 @@ import net.java.sip.communicator.service.contactsource.*; * * @author Yana Stamcheva */ -public class CallHistoryContactSource implements ContactSourceService +public class CallHistoryContactSource + implements ContactSourceService { /** * The display name of this contact source. @@ -252,10 +253,10 @@ public class CallHistoryContactSource implements ContactSourceService */ private void fireQueryStatusEvent(int newStatus) { + Collection<ContactQueryListener> listeners; ContactQueryStatusEvent event = new ContactQueryStatusEvent(this, newStatus); - Collection<ContactQueryListener> listeners; synchronized (queryListeners) { listeners diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryQueryImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryQueryImpl.java index b2b0ceb..9bd3574 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryQueryImpl.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryQueryImpl.java @@ -131,9 +131,7 @@ public class CallHistoryQueryImpl synchronized (queryListeners) { for (CallHistoryQueryListener l : queryListeners) - { l.callRecordReceived(event); - } } } @@ -150,9 +148,7 @@ public class CallHistoryQueryImpl synchronized (queryListeners) { for (CallHistoryQueryListener l : queryListeners) - { l.queryStatusChanged(event); - } } } diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java index d4da33a..6002c6d 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java @@ -303,7 +303,6 @@ public class CallHistoryServiceImpl History history = this.getHistory(null, null); InteractiveHistoryReader historyReader = history.getInteractiveReader(); - HistoryQuery historyQuery = historyReader.findByKeyword( address, "callParticipantIDs", recordCount); diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/CallHistoryFilter.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/CallHistoryFilter.java index 8689910..c71229c 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/CallHistoryFilter.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/CallHistoryFilter.java @@ -80,14 +80,12 @@ public class CallHistoryFilter { SourceContact sourceContact = (SourceContact) descriptor; - if ((sourceContact.getContactSource().getIdentifier() - .equals(ContactSourceService.CALL_HISTORY))) + if (sourceContact.getContactSource().getIdentifier() + .equals(ContactSourceService.CALL_HISTORY)) return true; } else if (uiContact instanceof NotificationContact) - { return true; - } return false; } @@ -100,12 +98,7 @@ public class CallHistoryFilter */ public boolean isMatching(UIGroup uiGroup) { - if (uiGroup instanceof NotificationGroup) - { - return true; - } - - return false; + return (uiGroup instanceof NotificationGroup); } /** @@ -122,11 +115,11 @@ public class CallHistoryFilter while (contactsIter.hasNext()) { - GuiActivator.getContactList() - .addContact(uiSource.createUIContact(contactsIter.next()), - uiSource.getUIGroup(), - false, - true); + GuiActivator.getContactList().addContact( + uiSource.createUIContact(contactsIter.next()), + uiSource.getUIGroup(), + false, + true); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeModel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeModel.java index a67385a..eb367d5 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeModel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeModel.java @@ -72,6 +72,7 @@ public class ContactListTreeModel public void clear() { if (!SwingUtilities.isEventDispatchThread()) + { try { SwingUtilities.invokeAndWait(new Runnable() @@ -90,6 +91,8 @@ public class ContactListTreeModel { e.printStackTrace(); } + return; + } // The following code is always invoked in the swing thread. int childCount = rootGroupNode.getChildCount(); @@ -153,7 +156,7 @@ public class ContactListTreeModel /** * The <tt>RootUIGroup</tt> is the root group in this contact list model. */ - private class RootUIGroup + private static class RootUIGroup implements UIGroup { /** diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactNode.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactNode.java index 2ddffb0..1c93e41 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactNode.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactNode.java @@ -21,7 +21,7 @@ public class ContactNode /** * The <tt>UIContact</tt> corresponding to this contact node. */ - private UIContact contact; + private final UIContact contact; /** * Indicates if this node is currently active. Has unread messages waiting. diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/FilterQuery.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/FilterQuery.java index 6f255a8..8da7afa 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/FilterQuery.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/FilterQuery.java @@ -53,9 +53,9 @@ public class FilterQuery /** * The list of filter queries. */ - private Map<Object, List<SourceContact>> filterQueries - = Collections.synchronizedMap(new Hashtable<Object, - List<SourceContact>>()); + private final Map<Object, List<SourceContact>> filterQueries + = Collections.synchronizedMap( + new Hashtable<Object, List<SourceContact>>()); /** * Indicates the number of running queries. @@ -94,9 +94,7 @@ public class FilterQuery externalQuery.addContactQueryListener(this); } else if (contactQuery instanceof MetaContactQuery) - { ((MetaContactQuery) contactQuery).addContactQueryListener(this); - } filterQueries.put(contactQuery, queryResults); runningQueries++; @@ -139,16 +137,14 @@ public class FilterQuery */ public void cancel() { - Iterator<Object> queriesIter; synchronized(filterQueries) { isCanceled = true; - queriesIter = filterQueries.keySet().iterator(); + Iterator<Object> queriesIter = filterQueries.keySet().iterator(); + while (queriesIter.hasNext()) - { cancelQuery(queriesIter.next()); - } } } @@ -198,7 +194,7 @@ public class FilterQuery // Check if this query is in our filter queries list. if (!filterQueries.containsKey(query) - || event.getEventType() == ContactQuery.QUERY_IN_PROGRESS) + || event.getEventType() == ContactQuery.QUERY_IN_PROGRESS) return; removeQuery(query); @@ -263,7 +259,7 @@ public class FilterQuery { if (query instanceof ContactQuery) { - ContactQuery contactQuery = ((ContactQuery) query); + ContactQuery contactQuery = (ContactQuery) query; contactQuery.cancel(); contactQuery.removeContactQueryListener( GuiActivator.getContactList()); @@ -272,7 +268,7 @@ public class FilterQuery } else if (query instanceof MetaContactQuery) { - MetaContactQuery metaContactQuery = ((MetaContactQuery) query); + MetaContactQuery metaContactQuery = (MetaContactQuery) query; metaContactQuery.cancel(); metaContactQuery.removeContactQueryListener( GuiActivator.getContactList()); diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/GroupNode.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/GroupNode.java index 2f31201..f34c83f 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/GroupNode.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/GroupNode.java @@ -9,6 +9,7 @@ package net.java.sip.communicator.impl.gui.main.contactlist; import java.util.*; import javax.swing.*; +import javax.swing.plaf.*; import javax.swing.tree.*; import net.java.sip.communicator.impl.gui.lookandfeel.*; @@ -25,9 +26,10 @@ public class GroupNode implements ContactListNode { /** - * The Group node logger. + * The <tt>Logger</tt> used by the <tt>GroupNode</tt> class and its + * instances for logging output. */ - private final Logger logger = Logger.getLogger(GroupNode.class); + private static final Logger logger = Logger.getLogger(GroupNode.class); /** * The parent contact list model. @@ -40,9 +42,15 @@ public class GroupNode private final UIGroup group; /** - * A node comparator used to sort the list of children. + * The <tt>ContactListNode</tt> <tt>Comparator</tt> used to sort the list of + * children. + * <p> + * Since the <tt>NodeComparator</tt> class is static, it makes sense to not + * have it instantiated per <tt>GroupNode</tt> instance but rather share one + * and the same between all of them. + * </p> */ - private final NodeComparator nodeComparator = new NodeComparator(); + private static final NodeComparator nodeComparator = new NodeComparator(); /** * Indicates if this group node is collapsed or expanded. @@ -296,7 +304,9 @@ public class GroupNode */ public void clear() { - for (int i = 0; i < getChildCount(); i ++) + int childCount = getChildCount(); + + for (int i = 0; i < childCount; i ++) { TreeNode treeNode = getChildAt(i); @@ -324,9 +334,7 @@ public class GroupNode */ private void fireNodeInserted(int index) { - int[] newIndexs = new int[1]; - newIndexs[0] = index; - treeModel.nodesWereInserted(this, newIndexs); + treeModel.nodesWereInserted(this, new int[]{index}); } /** @@ -337,29 +345,29 @@ public class GroupNode */ private void fireNodeRemoved(ContactListNode node, int index) { - int[] removedIndexs = new int[1]; - removedIndexs[0] = index; - treeModel.nodesWereRemoved(this, removedIndexs, new Object[]{node}); + treeModel.nodesWereRemoved(this, new int[]{index}, new Object[]{node}); } /** - * Notifies all interested listeners that all nodes has changed. + * Notifies all interested listeners that all nodes have changed. */ private void fireNodesChanged() { int childCount = getChildCount(); - int[] changedIndexs = new int[childCount]; + int[] changedIndexes = new int[childCount]; + for (int i = 0; i < childCount; i++) - changedIndexs[i] = i; + changedIndexes[i] = i; - treeModel.nodesChanged(this, changedIndexs); + treeModel.nodesChanged(this, changedIndexes); } /** * Note: this comparator imposes orderings that are inconsistent with * equals. */ - private class NodeComparator implements Comparator<ContactListNode> + private static class NodeComparator + implements Comparator<ContactListNode> { /** * Compares its two arguments for order. Returns a negative integer, @@ -373,21 +381,25 @@ public class GroupNode */ public int compare(ContactListNode node1, ContactListNode node2) { - int index1 = node1.getSourceIndex(); - int index2 = node2.getSourceIndex(); - // Child groups are shown after child contacts. - if (node1 instanceof GroupNode && node2 instanceof ContactNode) - return 1; + if (node1 instanceof GroupNode) + { + if (node2 instanceof ContactNode) + return 1; + } + else if (node1 instanceof ContactNode) + { + if (node2 instanceof GroupNode) + return -1; + } - if (node1 instanceof ContactNode && node2 instanceof GroupNode) - return -1; + int index1 = node1.getSourceIndex(); + int index2 = node2.getSourceIndex(); - // If the first index is unknown then we position it to the end. + // If the first index is unknown then we position it at the end. if (index1 < 0) return 1; - - // If the second index is unknown then we position it to the end. + // If the second index is unknown then we position it at the end. if (index2 < 0) return -1; @@ -405,14 +417,11 @@ public class GroupNode private int getLeadSelectionRow() { JTree tree = treeModel.getParentTree(); - int[] rows = tree.getSelectionRows(); - int selectedRow = -1; - if (rows != null && rows.length > 0) - { + + if ((rows != null) && (rows.length != 0)) selectedRow = rows[0]; - } return selectedRow; } @@ -436,15 +445,15 @@ public class GroupNode private void refreshSelection(int lastSelectedIndex, int newSelectedIndex) { JTree tree = treeModel.getParentTree(); + TreeUI treeUI = tree.getUI(); - TreePath oldSelectionPath = tree.getPathForRow(lastSelectedIndex); - TreePath newSelectionPath = tree.getPathForRow(newSelectedIndex); - - if (tree.getUI() instanceof SIPCommTreeUI) + if (treeUI instanceof SIPCommTreeUI) { - SIPCommTreeUI treeUI = (SIPCommTreeUI) tree.getUI(); + SIPCommTreeUI sipCommTreeUI = (SIPCommTreeUI) treeUI; + TreePath oldSelectionPath = tree.getPathForRow(lastSelectedIndex); + TreePath newSelectionPath = tree.getPathForRow(newSelectedIndex); - treeUI.selectionChanged(oldSelectionPath, newSelectionPath); + sipCommTreeUI.selectionChanged(oldSelectionPath, newSelectionPath); } } }
\ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFilter.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFilter.java index a4fbcda..2391dd7 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFilter.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFilter.java @@ -146,10 +146,13 @@ public class SearchFilter { Iterator<String> searchStrings = uiContact.getSearchStrings(); - while (searchStrings != null && searchStrings.hasNext()) + if (searchStrings != null) { - if (isMatching(searchStrings.next())) - return true; + while (searchStrings.hasNext()) + { + if (isMatching(searchStrings.next())) + return true; + } } return false; } @@ -210,36 +213,29 @@ public class SearchFilter */ private boolean isMatching(String text) { - Matcher matcher = filterPattern.matcher(text); - - if(matcher.find()) - return true; - - return false; + return filterPattern.matcher(text).find(); } /** * Adds the list of <tt>sourceContacts</tt> to the contact list. * @param sourceContacts the list of <tt>SourceContact</tt>s to add */ - private void addMatching( List<SourceContact> sourceContacts) + private void addMatching(List<SourceContact> sourceContacts) { Iterator<SourceContact> contactsIter = sourceContacts.iterator(); + while (contactsIter.hasNext()) - { addSourceContact(contactsIter.next()); - } } /** * Adds the given <tt>sourceContact</tt> to the contact list. * @param sourceContact the <tt>SourceContact</tt> to add */ - private void addSourceContact( SourceContact sourceContact) + private void addSourceContact(SourceContact sourceContact) { ContactSourceService contactSource = sourceContact.getContactSource(); - ExternalContactSource sourceUI = TreeContactList.getContactSource(contactSource); @@ -272,13 +268,12 @@ public class SearchFilter break; case HISTORY_SOURCE: { + Collection<ExternalContactSource> historySources + = new LinkedList<ExternalContactSource>(); ExternalContactSource historySource = TreeContactList.getContactSource( ContactSourceService.CALL_HISTORY); - Collection<ExternalContactSource> historySources - = new LinkedList<ExternalContactSource>(); - historySources.add(historySource); contactSources = historySources; break; @@ -296,7 +291,6 @@ public class SearchFilter { if (contactSources == null) contactSources = TreeContactList.getContactSources(); - return contactSources; } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java index 978cf4d..cabaa19 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java @@ -73,13 +73,13 @@ public class TreeContactList * these contacts with a special icon. */ private final java.util.List<ContactNode> activeContacts - = new Vector<ContactNode>(); + = new ArrayList<ContactNode>(); /** * A list of all registered <tt>ContactListListener</tt>-s. */ private final java.util.List<ContactListListener> contactListListeners - = new Vector<ContactListListener>(); + = new ArrayList<ContactListListener>(); /** * The presence filter. @@ -171,16 +171,12 @@ public class TreeContactList public void childContactsReordered(MetaContactGroupEvent evt) { MetaContactGroup metaGroup = evt.getSourceMetaContactGroup(); + UIGroup uiGroup; - UIGroup uiGroup = null; - if (!MetaContactListSource.isRootGroup(metaGroup)) - { - uiGroup = MetaContactListSource.getUIGroup(metaGroup); - } - else - { + if (MetaContactListSource.isRootGroup(metaGroup)) uiGroup = treeModel.getRoot().getGroupDescriptor(); - } + else + uiGroup = MetaContactListSource.getUIGroup(metaGroup); if (uiGroup != null) { @@ -328,15 +324,12 @@ public class TreeContactList if (uiContact == null) return; - UIGroup oldUIGroup = null; - if (!MetaContactListSource.isRootGroup(oldParent)) - { - oldUIGroup = MetaContactListSource.getUIGroup(oldParent); - } - else - { + UIGroup oldUIGroup; + + if (MetaContactListSource.isRootGroup(oldParent)) oldUIGroup = treeModel.getRoot().getGroupDescriptor(); - } + else + oldUIGroup = MetaContactListSource.getUIGroup(oldParent); if (oldUIGroup != null) removeContact(uiContact); @@ -729,9 +722,7 @@ public class TreeContactList { ContactNode contactNode = contact.getContactNode(); - if (contactNode != null) - return contactNode.isActive(); - return false; + return (contactNode == null) ? false : contactNode.isActive(); } /** @@ -775,9 +766,7 @@ public class TreeContactList if (isGroupSorted) groupNode = parentNode.sortedAddContactGroup(group); else - { groupNode = parentNode.addContactGroup(group); - } } } @@ -789,7 +778,7 @@ public class TreeContactList groupNode.addContact(contact); if ((!currentFilter.equals(presenceFilter) - || !groupNode.isCollapsed())) + || !groupNode.isCollapsed())) this.expandGroup(groupNode); else this.expandGroup(treeModel.getRoot()); @@ -854,7 +843,7 @@ public class TreeContactList // If in the meantime the filter has changed we don't // add the contact. if (query != null - && currentFilterQuery.containsQuery(query)) + && currentFilterQuery.containsQuery(query)) { addContact(contact, group, isSorted, true); } @@ -1243,7 +1232,6 @@ public class TreeContactList fireContactListEvent( new Vector<ContactListListener>(contactListListeners), evt); - return; } } } @@ -1478,9 +1466,7 @@ public class TreeContactList SwingUtilities.convertPointToScreen(contactListPoint, this); rightButtonMenu.setInvoker(this); - rightButtonMenu.setLocation(contactListPoint.x, contactListPoint.y); - rightButtonMenu.setVisible(true); } @@ -1500,7 +1486,7 @@ public class TreeContactList // For now we only save the group state only if we're in presence // filter mode. if (collapsedNode instanceof GroupNode - && currentFilter.equals(presenceFilter)) + && currentFilter.equals(presenceFilter)) { GroupNode groupNode = (GroupNode) collapsedNode; String id = groupNode.getGroupDescriptor().getId(); @@ -1522,7 +1508,7 @@ public class TreeContactList // For now we only save the group state only if we're in presence // filter mode. if (collapsedNode instanceof GroupNode - && currentFilter.equals(presenceFilter)) + && currentFilter.equals(presenceFilter)) { GroupNode groupNode = (GroupNode) collapsedNode; String id = groupNode.getGroupDescriptor().getId(); @@ -1794,7 +1780,6 @@ public class TreeContactList { if (notificationSource == null) notificationSource = new NotificationContactSource(); - return notificationSource; } @@ -1954,7 +1939,7 @@ public class TreeContactList // If we find that the contact is actually a number, we get rid of the // @ if it exists. if (atIndex >= 0 - && StringUtils.isNumber(contactString.substring(0, atIndex))) + && StringUtils.isNumber(contactString.substring(0, atIndex))) { setSourceContactImage( contactString.substring(0, atIndex), label, imgWidth, imgHeight); @@ -1972,9 +1957,7 @@ public class TreeContactList Iterator<ContactQuery> queriesIter = loadedQueries.iterator(); while (queriesIter.hasNext()) - { queriesIter.next().cancel(); - } } /** @@ -2071,8 +2054,8 @@ public class TreeContactList ProtocolProviderService preferredProvider = null; List<Class<? extends OperationSet>> opSetClasses = contactDetail.getSupportedOperationSets(); - if (opSetClasses != null - && opSetClasses.size() > 0) + + if (opSetClasses != null && opSetClasses.size() > 0) { preferredProvider = contactDetail.getPreferredProtocolProvider( @@ -2089,7 +2072,7 @@ public class TreeContactList * Listens for adding and removing of <tt>ContactSourceService</tt> * implementations. */ - private class ContactSourceServiceListener + private static class ContactSourceServiceListener implements ServiceListener { public void serviceChanged(ServiceEvent event) @@ -2134,13 +2117,15 @@ public class TreeContactList public void contactPresenceStatusChanged( final ContactPresenceStatusChangeEvent evt) { - final Contact sourceContact = evt.getSourceContact(); + if (evt.getOldStatus() == evt.getNewStatus()) + return; - final MetaContact metaContact = GuiActivator.getContactListService() - .findMetaContactByContact(sourceContact); + final Contact sourceContact = evt.getSourceContact(); + final MetaContact metaContact + = GuiActivator.getContactListService().findMetaContactByContact( + sourceContact); - if (metaContact == null - || (evt.getOldStatus() == evt.getNewStatus())) + if (metaContact == null) return; UIContact uiContact @@ -2148,8 +2133,7 @@ public class TreeContactList if (uiContact == null) { - uiContact = MetaContactListSource - .createUIContact(metaContact); + uiContact = MetaContactListSource.createUIContact(metaContact); if (currentFilter != null && currentFilter.isMatching(uiContact)) { @@ -2159,12 +2143,11 @@ public class TreeContactList UIGroup uiGroup = null; if (!MetaContactListSource.isRootGroup(parentGroup)) { - uiGroup = MetaContactListSource - .getUIGroup(parentGroup); + uiGroup = MetaContactListSource.getUIGroup(parentGroup); if (uiGroup == null) - uiGroup = MetaContactListSource - .createUIGroup(parentGroup); + uiGroup + = MetaContactListSource.createUIGroup(parentGroup); } if (logger.isDebugEnabled()) @@ -2173,8 +2156,7 @@ public class TreeContactList addContact(uiContact, uiGroup, true, true); } else - MetaContactListSource - .removeUIContact(metaContact); + MetaContactListSource.removeUIContact(metaContact); } else { @@ -2195,7 +2177,8 @@ public class TreeContactList * <tt>RenameAction</tt> is invoked when user presses the F2 key. Depending * on the selection opens the appropriate form for renaming. */ - private class RenameAction extends AbstractAction + private class RenameAction + extends AbstractAction { private static final long serialVersionUID = 0L; @@ -2216,13 +2199,12 @@ public class TreeContactList RenameContactDialog dialog = new RenameContactDialog( GuiActivator.getUIService().getMainFrame(), (MetaContact) metaUIContact.getDescriptor()); + Dimension screenSize + = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setLocation( - Toolkit.getDefaultToolkit().getScreenSize().width/2 - - 200, - Toolkit.getDefaultToolkit().getScreenSize().height/2 - - 50 - ); + screenSize.width/2 - 200, + screenSize.height/2 - 50); dialog.setVisible(true); diff --git a/src/net/java/sip/communicator/impl/history/HistoryImpl.java b/src/net/java/sip/communicator/impl/history/HistoryImpl.java index 8c7685e..594d93f 100644 --- a/src/net/java/sip/communicator/impl/history/HistoryImpl.java +++ b/src/net/java/sip/communicator/impl/history/HistoryImpl.java @@ -142,22 +142,16 @@ public class HistoryImpl */ public InteractiveHistoryReader getInteractiveReader() { - if (this.interactiveReader == null) - { - this.interactiveReader = new InteractiveHistoryReaderImpl(this); - } - - return this.interactiveReader; + if (interactiveReader == null) + interactiveReader = new InteractiveHistoryReaderImpl(this); + return interactiveReader; } public HistoryWriter getWriter() { - if (this.writer == null) - { - this.writer = new HistoryWriterImpl(this); - } - - return this.writer; + if (writer == null) + writer = new HistoryWriterImpl(this); + return writer; } protected HistoryServiceImpl getHistoryServiceImpl() diff --git a/src/net/java/sip/communicator/impl/history/HistoryReaderImpl.java b/src/net/java/sip/communicator/impl/history/HistoryReaderImpl.java index afc76c9..27bdcc1 100644 --- a/src/net/java/sip/communicator/impl/history/HistoryReaderImpl.java +++ b/src/net/java/sip/communicator/impl/history/HistoryReaderImpl.java @@ -204,7 +204,7 @@ public class HistoryReaderImpl String ts = node.getAttributes().getNamedItem("timestamp") .getNodeValue(); - Date timestamp = new Date(Long.parseLong(ts)); + long timestamp = Long.parseLong(ts); ArrayList<String> nameVals = new ArrayList<String>(); @@ -352,7 +352,7 @@ public class HistoryReaderImpl String ts = node.getAttributes().getNamedItem("timestamp") .getNodeValue(); - Date timestamp = new Date(Long.parseLong(ts)); + long timestamp = Long.parseLong(ts); if(!isInPeriod(timestamp, date, null)) continue; @@ -446,7 +446,7 @@ public class HistoryReaderImpl String ts = node.getAttributes().getNamedItem("timestamp") .getNodeValue(); - Date timestamp = new Date(Long.parseLong(ts)); + long timestamp = Long.parseLong(ts); if(!isInPeriod(timestamp, null, date)) continue; @@ -547,8 +547,7 @@ public class HistoryReaderImpl String ts = node.getAttributes().getNamedItem("timestamp") .getNodeValue(); - - Date timestamp = new Date(Long.parseLong(ts)); + long timestamp = Long.parseLong(ts); if(isInPeriod(timestamp, startDate, endDate)) { @@ -590,21 +589,23 @@ public class HistoryReaderImpl * @param endDate Date the end of the period * @return boolean */ - static boolean isInPeriod(Date timestamp, Date startDate, Date endDate) + static boolean isInPeriod(long timestamp, Date startDate, Date endDate) { if(startDate == null) { if(endDate == null) return true; else - return timestamp.before(endDate); + return timestamp < endDate.getTime(); } else { if(endDate == null) - return timestamp.after(startDate); + return timestamp > startDate.getTime(); else - return timestamp.after(startDate) && timestamp.before(endDate); + return + timestamp > startDate.getTime() + && timestamp < endDate.getTime(); } } @@ -621,7 +622,7 @@ public class HistoryReaderImpl * @return HistoryRecord */ static HistoryRecord filterByKeyword( NodeList propertyNodes, - Date timestamp, + long timestamp, String[] keywords, String field, boolean caseSensitive) @@ -951,8 +952,14 @@ public class HistoryReaderImpl { public int compare(HistoryRecord h1, HistoryRecord h2) { - return h1.getTimestamp(). - compareTo(h2.getTimestamp()); + long d = (h2.getTimestamp() - h1.getTimestamp()); + + if (d == 0) + return 0; + else if (d < 0) + return -1; + else + return 1; } } } diff --git a/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java b/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java index fb8d124..1d466fc 100644 --- a/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java +++ b/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java @@ -58,12 +58,15 @@ public class HistoryWriterImpl public void addRecord(String[] propertyValues) throws IOException { - this.addRecord(structPropertyNames, propertyValues, new Date()); + addRecord( + structPropertyNames, + propertyValues, + System.currentTimeMillis()); } public void addRecord(String[] propertyValues, Date timestamp) throws IOException { - this.addRecord(structPropertyNames, propertyValues, timestamp); + this.addRecord(structPropertyNames, propertyValues, timestamp.getTime()); } /** @@ -79,10 +82,10 @@ public class HistoryWriterImpl */ private void addRecord(String[] propertyNames, String[] propertyValues, - Date date) + long date) throws InvalidParameterException, IOException { - // Synchronized to assure that two concurent threads can insert records + // Synchronized to assure that two concurrent threads can insert records // safely. synchronized (this.docCreateLock) { @@ -99,7 +102,7 @@ public class HistoryWriterImpl synchronized (root) { Element elem = this.currentDoc.createElement("record"); - elem.setAttribute("timestamp", Long.toString(date.getTime())); + elem.setAttribute("timestamp", Long.toString(date)); for (int i = 0; i < propertyNames.length; i++) { @@ -159,7 +162,7 @@ public class HistoryWriterImpl * @param date Date * @param loadLastFile boolean */ - private void createNewDoc(Date date, boolean loadLastFile) + private void createNewDoc(long date, boolean loadLastFile) { boolean loaded = false; @@ -180,7 +183,7 @@ public class HistoryWriterImpl loaded = true; } - // if something happend and file was not loaded + // if something happened and file was not loaded // then we must create new one if(this.currentDoc == null) { @@ -190,7 +193,7 @@ public class HistoryWriterImpl if (!loaded) { - this.currentFile = Long.toString(date.getTime()); + this.currentFile = Long.toString(date); // while (this.currentFile.length() < 8) // { // this.currentFile = "0" + this.currentFile; diff --git a/src/net/java/sip/communicator/impl/history/InteractiveHistoryReaderImpl.java b/src/net/java/sip/communicator/impl/history/InteractiveHistoryReaderImpl.java index be4c6cb..84a3b4b 100644 --- a/src/net/java/sip/communicator/impl/history/InteractiveHistoryReaderImpl.java +++ b/src/net/java/sip/communicator/impl/history/InteractiveHistoryReaderImpl.java @@ -94,14 +94,19 @@ public class InteractiveHistoryReaderImpl final boolean caseSensitive, final int resultCount) { - String queryString = ""; + StringBuilder queryString = new StringBuilder(); for (String s : keywords) - queryString += " " + s; + { + queryString.append(' '); + queryString.append(s); + } - final HistoryQueryImpl query = new HistoryQueryImpl(queryString); + final HistoryQueryImpl query + = new HistoryQueryImpl(queryString.toString()); new Thread() { + @Override public void run() { find(startDate, endDate, keywords, field, caseSensitive, @@ -133,12 +138,11 @@ public class InteractiveHistoryReaderImpl Vector<String> filelist = HistoryReaderImpl.filterFilesByDate( history.getFileList(), startDate, endDate, true); - Iterator<String> fileIterator = filelist.iterator(); + while (fileIterator.hasNext() && resultCount > 0 && !query.isCanceled()) { String filename = fileIterator.next(); - Document doc = history.getDocumentForFile(filename); if(doc == null) @@ -146,17 +150,14 @@ public class InteractiveHistoryReaderImpl NodeList nodes = doc.getElementsByTagName("record"); - Node node; for ( int i = nodes.getLength() - 1; i >= 0 && !query.isCanceled(); i--) { - node = nodes.item(i); - + Node node = nodes.item(i); String ts = node.getAttributes().getNamedItem("timestamp") .getNodeValue(); - - Date timestamp = new Date(Long.parseLong(ts)); + long timestamp = Long.parseLong(ts); if(HistoryReaderImpl.isInPeriod(timestamp, startDate, endDate)) { diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java index 9514f71..2382e02 100644 --- a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java @@ -638,7 +638,7 @@ public class MessageHistoryServiceImpl // the HistoryRecord timestamp is the timestamp when the record // was written long messageReceivedDate = msg.getMessageReceivedDate(); - long hrTimestamp = hr.getTimeInMillis(); + long hrTimestamp = hr.getTimestamp(); if (messageReceivedDate != 0) { if(messageReceivedDate - hrTimestamp > 86400000) // 24*60*60*1000 @@ -684,7 +684,7 @@ public class MessageHistoryServiceImpl // the HistoryRecord timestamp is the timestamp when the record // was written long messageReceivedDate = msg.getMessageReceivedDate(); - long hrTimestamp = hr.getTimeInMillis(); + long hrTimestamp = hr.getTimestamp(); if(messageReceivedDate != 0) { if(messageReceivedDate - hrTimestamp > 86400000) // 24*60*60*1000 diff --git a/src/net/java/sip/communicator/service/history/records/HistoryRecord.java b/src/net/java/sip/communicator/service/history/records/HistoryRecord.java index c645fcf..8036cdd 100644 --- a/src/net/java/sip/communicator/service/history/records/HistoryRecord.java +++ b/src/net/java/sip/communicator/service/history/records/HistoryRecord.java @@ -6,17 +6,14 @@ */ package net.java.sip.communicator.service.history.records; -import java.util.*; - /** * @author Alexander Pelov */ public class HistoryRecord { - - private Date timestamp; - private String[] propertyNames; - private String[] propertyValues; + private final long timestamp; + private final String[] propertyNames; + private final String[] propertyValues; /** * Constructs an entry containing multiple name-value pairs, where the names @@ -29,7 +26,10 @@ public class HistoryRecord public HistoryRecord(HistoryRecordStructure entryStructure, String[] propertyValues) { - this(entryStructure.getPropertyNames(), propertyValues, new Date()); + this( + entryStructure.getPropertyNames(), + propertyValues, + System.currentTimeMillis()); } /** @@ -41,7 +41,7 @@ public class HistoryRecord */ public HistoryRecord(String[] propertyNames, String[] propertyValues) { - this(propertyNames, propertyValues, new Date()); + this(propertyNames, propertyValues, System.currentTimeMillis()); } /** @@ -53,7 +53,8 @@ public class HistoryRecord * @param timestamp */ public HistoryRecord(HistoryRecordStructure entryStructure, - String[] propertyValues, Date timestamp) + String[] propertyValues, + long timestamp) { this(entryStructure.getPropertyNames(), propertyValues, timestamp); } @@ -66,8 +67,9 @@ public class HistoryRecord * @param propertyValues * @param timestamp */ - public HistoryRecord(String[] propertyNames, String[] propertyValues, - Date timestamp) + public HistoryRecord(String[] propertyNames, + String[] propertyValues, + long timestamp) { // TODO: Validate: Assert.assertNonNull(propertyNames, "The property names should be non-null."); // TODO: Validate: Assert.assertNonNull(propertyValues, "The property values should be non-null."); @@ -91,16 +93,11 @@ public class HistoryRecord return this.propertyValues; } - public Date getTimestamp() + public long getTimestamp() { return this.timestamp; } - public long getTimeInMillis() - { - return (timestamp == null) ? 0 : timestamp.getTime(); - } - /** * Returns the String representation of this HistoryRecord. * @@ -108,12 +105,15 @@ public class HistoryRecord */ public String toString() { - String s = "History Record: "; + StringBuilder s = new StringBuilder("History Record: "); + for (int i = 0; i < propertyNames.length; i++) { - s += propertyNames[i] + "=" + propertyValues[i] + "\n"; + s.append(propertyNames[i]); + s.append('='); + s.append(propertyValues[i]); + s.append('\n'); } - - return s; + return s.toString(); } } |