edu.rice.cs.drjava.ui.avail
Class GUIAvailabilityNotifier

java.lang.Object
  extended by edu.rice.cs.drjava.model.EventNotifier<GUIAvailabilityListener>
      extended by edu.rice.cs.drjava.ui.avail.GUIAvailabilityNotifier
All Implemented Interfaces:
GUIAvailabilityListener
Direct Known Subclasses:
DefaultGUIAvailabilityNotifier

public class GUIAvailabilityNotifier
extends EventNotifier<GUIAvailabilityListener>
implements GUIAvailabilityListener

Keeps track of all listeners to GUI availability.

All methods in this class must use the synchronization methods provided by ReaderWriterLock. This ensures that multiple notifications (reads) can occur simultaneously, but only one thread can be adding or removing listeners (writing) at a time, and no reads can occur during a write.

No methods on this class should be synchronized using traditional Java synchronization!

Version:
$Id: GUIAvailabilityNotifier.java 5355 2010-08-11 21:20:32Z mgricken $

Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.rice.cs.drjava.ui.avail.GUIAvailabilityListener
GUIAvailabilityListener.ComponentType
 
Field Summary
protected  HashMap<GUIAvailabilityListener.ComponentType,Integer> _values
          The current availabilities of the individual components.
 
Fields inherited from class edu.rice.cs.drjava.model.EventNotifier
_listeners, _lock
 
Constructor Summary
GUIAvailabilityNotifier()
          Create a new notifier with all components available.
 
Method Summary
 void availabilityChanged(GUIAvailabilityListener.ComponentType component, boolean available)
          Called to change a components availability.
 void available(GUIAvailabilityListener.ComponentType component)
          Make a component (more) available.
 void ensureAvailabilityIs(GUIAvailabilityListener.ComponentType component, boolean available)
          Make sure the availability of the component is as specified.
 void ensureAvailable(GUIAvailabilityListener.ComponentType component)
          Make sure a component is available, i.e.
 void ensureUnavailable(GUIAvailabilityListener.ComponentType component)
          Make sure a component is unavailable, i.e.
 int getCount(GUIAvailabilityListener.ComponentType component)
          Returns the count for the specified component, where 0 means available, and 1 or greater means unavailable (perhaps nested).
 boolean isAvailable(GUIAvailabilityListener.ComponentType component)
          Return true if the component is available.
protected  void notifyListeners(GUIAvailabilityListener.ComponentType component)
          Notify the listeners for the specified component.
 void unavailable(GUIAvailabilityListener.ComponentType component)
          Make a component (more) unavailable.
 
Methods inherited from class edu.rice.cs.drjava.model.EventNotifier
addListener, removeAllListeners, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_values

protected final HashMap<GUIAvailabilityListener.ComponentType,Integer> _values
The current availabilities of the individual components.

Constructor Detail

GUIAvailabilityNotifier

public GUIAvailabilityNotifier()
Create a new notifier with all components available.

Method Detail

isAvailable

public boolean isAvailable(GUIAvailabilityListener.ComponentType component)
Return true if the component is available.

Parameters:
component - the component to query
Returns:
true if available

getCount

public int getCount(GUIAvailabilityListener.ComponentType component)
Returns the count for the specified component, where 0 means available, and 1 or greater means unavailable (perhaps nested).

Parameters:
component - the component to query
Returns:
count

ensureUnavailable

public void ensureUnavailable(GUIAvailabilityListener.ComponentType component)
Make sure a component is unavailable, i.e. the count is at least 1. If the count is 0, increase it to 1. If the count is already 1 or greater, than don't do anything.

Parameters:
component - the component that needs to be unavailable

unavailable

public void unavailable(GUIAvailabilityListener.ComponentType component)
Make a component (more) unavailable. This may be nested.

Parameters:
component - the component that is unavailable

ensureAvailable

public void ensureAvailable(GUIAvailabilityListener.ComponentType component)
Make sure a component is available, i.e. the count is 0. If the count is greater than 0, change it to 0. If the count is already 0, than don't do anything.

Parameters:
component - the component that needs to be available

available

public void available(GUIAvailabilityListener.ComponentType component)
Make a component (more) available. This may be nested. If the count of the component is still larger than 0 after this call, the component will remain unavailable.

Parameters:
component - the component that is available

ensureAvailabilityIs

public void ensureAvailabilityIs(GUIAvailabilityListener.ComponentType component,
                                 boolean available)
Make sure the availability of the component is as specified. If available is true, this calls ensureAvailable; if available is false, it calls ensureUnavailable.

Parameters:
component - the component that needs to be available
available - true to make the component available, false otherwise

availabilityChanged

public void availabilityChanged(GUIAvailabilityListener.ComponentType component,
                                boolean available)
Called to change a components availability. Nested (non-)availability is supported: calling this method with available=false twice will require two calls with available=true to make the component available again.

Specified by:
availabilityChanged in interface GUIAvailabilityListener
Parameters:
component - the component whose availability changed
available - true if component is available

notifyListeners

protected void notifyListeners(GUIAvailabilityListener.ComponentType component)
Notify the listeners for the specified component.

Parameters:
component - the component whose listeners should be notified