mirror of https://github.com/sipwise/jitsi.git
parent
2fb1f2db0c
commit
ab366d7717
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.contactlist.contactsource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.contactlist.*;
|
||||
|
||||
/**
|
||||
* The <tt>MetaContactQuery</tt> corresponds to a particular query made through
|
||||
* the <tt>MetaContactListSource</tt>. Each query once started could be
|
||||
* canceled. One could also register a listener in order to be notified for
|
||||
* changes in query status and query contact results.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class MetaContactQuery
|
||||
{
|
||||
private boolean isCanceled = false;
|
||||
|
||||
private int resultCount = 0;
|
||||
|
||||
/**
|
||||
* A list of all registered query listeners.
|
||||
*/
|
||||
private final List<MetaContactQueryListener> queryListeners
|
||||
= new LinkedList<MetaContactQueryListener>();
|
||||
|
||||
/**
|
||||
* Cancels this query.
|
||||
*/
|
||||
public void cancel()
|
||||
{
|
||||
isCanceled = true;
|
||||
queryListeners.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <tt>true</tt> if this query has been canceled, otherwise returns
|
||||
* <tt>false</tt>.
|
||||
* @return <tt>true</tt> if this query has been canceled, otherwise returns
|
||||
* <tt>false</tt>.
|
||||
*/
|
||||
public boolean isCanceled()
|
||||
{
|
||||
return isCanceled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current number of results received for this query.
|
||||
* @return the current number of results received for this query
|
||||
*/
|
||||
public int getResultCount()
|
||||
{
|
||||
return resultCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the result count of this query. This method is meant to be used to
|
||||
* set the initial result count which is before firing any events. The
|
||||
* result count would be then augmented each time the fireQueryEvent is
|
||||
* called.
|
||||
* @param resultCount the initial result count to set
|
||||
*/
|
||||
public void setInitialResultCount(int resultCount)
|
||||
{
|
||||
this.resultCount = resultCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given <tt>MetaContactQueryListener</tt> to the list of
|
||||
* registered listeners. The <tt>MetaContactQueryListener</tt> would be
|
||||
* notified each time a new <tt>MetaContactQuery</tt> result has been
|
||||
* received or if the query has been completed or has been canceled by user
|
||||
* or for any other reason.
|
||||
* @param l the <tt>MetaContactQueryListener</tt> to add
|
||||
*/
|
||||
public void addContactQueryListener(MetaContactQueryListener l)
|
||||
{
|
||||
synchronized (queryListeners)
|
||||
{
|
||||
queryListeners.add(l);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given <tt>MetaContactQueryListener</tt> to the list of
|
||||
* registered listeners. The <tt>MetaContactQueryListener</tt> would be
|
||||
* notified each time a new <tt>MetaContactQuery</tt> result has been
|
||||
* received or if the query has been completed or has been canceled by user
|
||||
* or for any other reason.
|
||||
* @param l the <tt>MetaContactQueryListener</tt> to remove
|
||||
*/
|
||||
public void removeContactQueryListener(MetaContactQueryListener l)
|
||||
{
|
||||
synchronized (queryListeners)
|
||||
{
|
||||
queryListeners.remove(l);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the <tt>MetaContactQueryListener</tt> that a new
|
||||
* <tt>MetaContact</tt> has been received as a result of a search.
|
||||
* @param metaContact the received <tt>MetaContact</tt>
|
||||
*/
|
||||
public void fireQueryEvent(MetaContact metaContact)
|
||||
{
|
||||
resultCount++;
|
||||
|
||||
MetaContactQueryEvent event
|
||||
= new MetaContactQueryEvent(this, metaContact);
|
||||
|
||||
List<MetaContactQueryListener> listeners;
|
||||
synchronized (queryListeners)
|
||||
{
|
||||
listeners = new LinkedList<MetaContactQueryListener>(queryListeners);
|
||||
}
|
||||
|
||||
Iterator<MetaContactQueryListener> listenersIter = listeners.iterator();
|
||||
while (listenersIter.hasNext())
|
||||
{
|
||||
MetaContactQueryListener listener = listenersIter.next();
|
||||
|
||||
listener.metaContactReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the <tt>MetaContactQueryListener</tt> that a new
|
||||
* <tt>MetaGroup</tt> has been received as a result of a search.
|
||||
* @param metaGroup the received <tt>MetaGroup</tt>
|
||||
*/
|
||||
public void fireQueryEvent(MetaContactGroup metaGroup)
|
||||
{
|
||||
MetaGroupQueryEvent event
|
||||
= new MetaGroupQueryEvent(this, metaGroup);
|
||||
|
||||
List<MetaContactQueryListener> listeners;
|
||||
synchronized (queryListeners)
|
||||
{
|
||||
listeners = new LinkedList<MetaContactQueryListener>(queryListeners);
|
||||
}
|
||||
|
||||
Iterator<MetaContactQueryListener> listenersIter = listeners.iterator();
|
||||
while (listenersIter.hasNext())
|
||||
{
|
||||
listenersIter.next().metaGroupReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the <tt>MetaContactQueryListener</tt> that this query has
|
||||
* changed its status.
|
||||
* @param queryStatus the new query status
|
||||
*/
|
||||
public void fireQueryEvent(int queryStatus)
|
||||
{
|
||||
MetaContactQueryStatusEvent event
|
||||
= new MetaContactQueryStatusEvent(this, queryStatus);
|
||||
|
||||
List<MetaContactQueryListener> listeners;
|
||||
synchronized (queryListeners)
|
||||
{
|
||||
listeners = new LinkedList<MetaContactQueryListener>(queryListeners);
|
||||
}
|
||||
|
||||
Iterator<MetaContactQueryListener> listenersIter = listeners.iterator();
|
||||
while (listenersIter.hasNext())
|
||||
{
|
||||
listenersIter.next().metaContactQueryStatusChanged(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.contactlist.contactsource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.contactlist.*;
|
||||
|
||||
/**
|
||||
* The <tt>MetaContactQueryEvent</tt> is triggered each time a
|
||||
* <tt>MetaContact</tt> is received as a result of a <tt>MetaContactQuery</tt>.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class MetaContactQueryEvent
|
||||
extends EventObject
|
||||
{
|
||||
/**
|
||||
* The <tt>MetaContact</tt> this event is about.
|
||||
*/
|
||||
private final MetaContact metaContact;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>MetaGroupQueryEvent</tt> by specifying the
|
||||
* <tt>source</tt> query this event comes from and the <tt>metaContact</tt>
|
||||
* this event is about.
|
||||
*
|
||||
* @param source the <tt>MetaContactQuery</tt> that triggered this event
|
||||
* @param metaContact the <tt>MetaContact</tt> this event is about
|
||||
*/
|
||||
public MetaContactQueryEvent( MetaContactQuery source,
|
||||
MetaContact metaContact)
|
||||
{
|
||||
super(source);
|
||||
this.metaContact = metaContact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>MetaContactQuery</tt> that triggered this event.
|
||||
* @return the <tt>MetaContactQuery</tt> that triggered this event
|
||||
*/
|
||||
public MetaContactQuery getQuerySource()
|
||||
{
|
||||
return (MetaContactQuery) source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>MetaContact</tt> this event is about.
|
||||
* @return the <tt>MetaContact</tt> this event is about
|
||||
*/
|
||||
public MetaContact getMetaContact()
|
||||
{
|
||||
return metaContact;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.contactlist.contactsource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The <tt>MetaContactQueryStatusEvent</tt> is triggered each time a
|
||||
* <tt>MetaContactQuery</tt> changes its status. Possible statuses are:
|
||||
* QUERY_COMPLETED, QUERY_CANCELED and QUERY_ERROR.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class MetaContactQueryStatusEvent
|
||||
extends EventObject
|
||||
{
|
||||
/**
|
||||
* Indicates that a query has been completed.
|
||||
*/
|
||||
public static final int QUERY_COMPLETED = 0;
|
||||
|
||||
/**
|
||||
* Indicates that a query has been canceled.
|
||||
*/
|
||||
public static final int QUERY_CANCELED = 1;
|
||||
|
||||
/**
|
||||
* Indicates that a query has been stopped because of an error.
|
||||
*/
|
||||
public static final int QUERY_ERROR = 2;
|
||||
|
||||
/**
|
||||
* Indicates the type of this event.
|
||||
*/
|
||||
private final int eventType;
|
||||
|
||||
/**
|
||||
* Creates a <tt>MetaContactQueryStatusEvent</tt> by specifying the source
|
||||
* <tt>MetaContactQuery</tt> and the <tt>eventType</tt> indicating why
|
||||
* initially this event occurred.
|
||||
* @param source the initiator of the event
|
||||
* @param eventType the type of the event. One of the QUERY_XXX constants
|
||||
* defined in this class
|
||||
*/
|
||||
public MetaContactQueryStatusEvent( MetaContactQuery source,
|
||||
int eventType)
|
||||
{
|
||||
super(source);
|
||||
|
||||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>ContactQuery</tt> that triggered this event.
|
||||
* @return the <tt>ContactQuery</tt> that triggered this event
|
||||
*/
|
||||
public MetaContactQuery getQuerySource()
|
||||
{
|
||||
return (MetaContactQuery) source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of this event.
|
||||
* @return the type of this event
|
||||
*/
|
||||
public int getEventType()
|
||||
{
|
||||
return eventType;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.contactlist.contactsource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.contactlist.*;
|
||||
|
||||
/**
|
||||
* The <tt>MetaGroupQueryEvent</tt> is triggered each time a
|
||||
* <tt>MetaContactGroup</tt> is received as a result of a
|
||||
* <tt>MetaContactQuery</tt>.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class MetaGroupQueryEvent
|
||||
extends EventObject
|
||||
{
|
||||
/**
|
||||
* The <tt>MetaContactGroup</tt> this event is about.
|
||||
*/
|
||||
private final MetaContactGroup metaGroup;
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>MetaGroupQueryEvent</tt> by specifying the
|
||||
* <tt>source</tt> query this event comes from and the <tt>metaGroup</tt>
|
||||
* this event is about.
|
||||
*
|
||||
* @param source the <tt>MetaContactQuery</tt> that triggered this event
|
||||
* @param metaGroup the <tt>MetaContactGroup</tt> this event is about
|
||||
*/
|
||||
public MetaGroupQueryEvent( MetaContactQuery source,
|
||||
MetaContactGroup metaGroup)
|
||||
{
|
||||
super(source);
|
||||
this.metaGroup = metaGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>MetaContactQuery</tt> that triggered this event.
|
||||
* @return the <tt>MetaContactQuery</tt> that triggered this event
|
||||
*/
|
||||
public MetaContactQuery getQuerySource()
|
||||
{
|
||||
return (MetaContactQuery) source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>MetaContactGroup</tt> this event is about.
|
||||
* @return the <tt>MetaContactGroup</tt> this event is about
|
||||
*/
|
||||
public MetaContactGroup getMetaGroup()
|
||||
{
|
||||
return metaGroup;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.util.swing;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* The <tt>LowPriorityEventQueue</tt> schedules low priority events to be
|
||||
* dispatched through the system event queue.
|
||||
*
|
||||
* @author Yana Stamcheva
|
||||
*/
|
||||
public class LowPriorityEventQueue
|
||||
{
|
||||
/**
|
||||
* Causes <code>runnable</code> to have its <code>run</code>
|
||||
* method called in the event dispatch thread with low priority.
|
||||
*
|
||||
* @param runnable the <code>Runnable</code> whose <code>run</code>
|
||||
* method should be executed synchronously on the <code>EventQueue</code>
|
||||
*/
|
||||
public static void invokeLater(Runnable runnable)
|
||||
{
|
||||
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
|
||||
new LowPriorityInvocationEvent(
|
||||
Toolkit.getDefaultToolkit(), runnable));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <tt>LowPriorityInvocationEvent</tt> is an <tt>InvocationEvent</tt>
|
||||
* that replaces the default event id with the <tt>PaintEvent.UPDATE</tt>
|
||||
* in order to indicate that this event should be dispatched with the same
|
||||
* priority as an update paint event, which is normally with lower priority
|
||||
* than other events.
|
||||
*/
|
||||
private static class LowPriorityInvocationEvent extends InvocationEvent
|
||||
{
|
||||
public LowPriorityInvocationEvent(Object source, Runnable runnable)
|
||||
{
|
||||
super(source, PaintEvent.UPDATE, runnable, null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue