com.miginfocom.calendar.activity
Class DefaultActivity

java.lang.Object
  extended by com.miginfocom.calendar.activity.AbstractActivity
      extended by com.miginfocom.calendar.activity.DefaultActivity
All Implemented Interfaces:
Activity, Categorizable, AdjustingPropertyConsumer, TimeSpan, PropertyConsumer, PropertyObservable, PropertyProvider, StateObservable, StatesI, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Comparable, java.util.EventListener

public class DefaultActivity
extends AbstractActivity
implements StatesI

Default implementation of an activity

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.miginfocom.calendar.activity.AbstractActivity
BASE_DATE_RANGE, PROP_AFFECTED_DATE_RANGE, PROP_CALENDAR_ID, PROP_CATEGORY_IDS, PROP_CLIENT_CREATED_MILLIS, PROP_DESCRIPTION, PROP_ENABLED, PROP_ID_OBJECT, PROP_LAST_MODIFIED_MILLIS, PROP_LAYER_INDEX, PROP_LAYOUT_CONTEXT, PROP_LOCATION, PROP_PAINT_CONTEXT, PROP_RECURRENCE, PROP_STORAGE_CREATED_MILLIS, PROP_SUMMARY
 
Fields inherited from interface com.miginfocom.util.states.StateObservable
GROUP_TOGGLE, SPRING, TOGGLE
 
Constructor Summary
DefaultActivity(ImmutableDateRange dateRange, java.lang.Object id)
          Constructs an activity that has the same start and end date.
DefaultActivity(java.util.Map props)
          Constructor that will take the PropertyKey->Value map and set it.
 
Method Summary
 boolean areStatesSet(int states, boolean allStatesSet)
          Returns the status of a state (or states).
 void clearCachedViews(javax.swing.JComponent container)
          Clears any views that are acached.
 ActivityView createView(javax.swing.JComponent parent, InteractionListener iListener, ImmutableDateRange viewRange)
          Creates an activity view.
protected  ActivityView[] createViewList(javax.swing.JComponent parent, InteractionListener iListener, DateRangeI withinRange)
           
 ActivityView getBaseView(javax.swing.JComponent parent, InteractionListener iListener)
          Should NOT be called from client code!
 java.lang.Object getGroupToggleContext(int state)
          Return a context that is used to define a StateObservable.GROUP_TOGGLE pool.
 int getHandledStates()
          Returns the states that are legal for this object.
 int getSettableStates(int states)
          Returns which of the suggested states is actually settable.
 int[] getStateArray()
          Takes the state integer and split them up with a call to States.splitStates(int)
 StatesI getStates()
          Returns the current States object.
 int getStatesSet()
          Returns the states packed in an int
 int getStateType(int state)
          What type of state that state is.
 ActivityView[] getViews(javax.swing.JComponent parent, InteractionListener iListener, DateRangeI withinRange)
          Should NOT be called from client code!
 void invalidateViews()
          Removes all cached paint optimizations for this activity's views so that they will be recreated next paint run.
 boolean isAnyStateSet()
          Returns true if any state is set.
 boolean isHandlingStates(int states)
          Return if all the states is handled.
 boolean isMultiState(int state)
          Returns if more than one object in the same toggle group context can have this state.
 boolean isStateSet(int s)
          Returns the status of a state.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Overridden to repaint all views for every change event.
 void repaintViews()
           
 void setGroupToggleContext(int state, java.lang.Object context)
          Sets the context for the icon to toggle within.
 boolean setStates(int states, boolean b)
          Sets the status of a state (or states).
 
Methods inherited from class com.miginfocom.calendar.activity.AbstractActivity
addCategoryID, addProperties, addPropertiesSilent, addPropertyListener, addPropertyListener, addStaticPropertyChangeListener, clearLayoutNeededFlag, compareTo, containsProperty, endAdjusting, equalProperties, equals, firePropertyChangeEvent, fireStaticPropertyChangeEvent, getBaseDateRange, getCategoryIDs, getCreatedByStorageDate, getCreatedDateByClientDate, getDateRangeClone, getDateRangeForReading, getDescription, getID, getLastModified, getLayerIndex, getLayoutContext, getLocation, getPaintContext, getProperties, getProperty, getPropertyValidator, getRecurrence, getSummary, getWritableDateRange, hashCode, isAdjusting, isCategory, isEnabled, isIgnorePropertyEvents, isLayoutNeeded, isRecurrent, removeCategoryID, removeProperty, removeProperty, removePropertyListener, removePropertySilent, removeStaticPropertyChangeListener, rollbackAdjusting, setBaseDateRange, setCategoryIDs, setCreatedByStorageDate, setCreatedDateByClientDate, setDescription, setEnabled, setID, setIgnorePropertyEvents, setLastModified, setLastUpdateMillis, setLayerIndex, setLayoutContext, setLocation, setPaintContext, setProperties, setProperties, setPropertiesSilent, setProperty, setPropertySilent, setPropertyValidator, setRecurrence, setSummary, startAdjusting, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultActivity

public DefaultActivity(java.util.Map props)
Constructor that will take the PropertyKey->Value map and set it. It must at least contain an ImmutableDateRange for the BASE_DATE_RANGE key.

Parameters:
props - The properties. Not null. Must specify the base date range and ID. Will be copied and not stored locally.

DefaultActivity

public DefaultActivity(ImmutableDateRange dateRange,
                       java.lang.Object id)
Constructs an activity that has the same start and end date. Makes a defensive copy of the sent in date range.

Parameters:
dateRange - The date range. Object is overtaken and not cloned. Not null
id - The id that makes this activity unique.
Method Detail

getStates

public StatesI getStates()
Description copied from interface: StateObservable
Returns the current States object. State changes should be made though this object, or preferrably though the StateHander class, which also manages state interactions between StateObservable objects and state change notification coalescing.

Specified by:
getStates in interface StateObservable
Returns:
The current state object

getViews

public ActivityView[] getViews(javax.swing.JComponent parent,
                               InteractionListener iListener,
                               DateRangeI withinRange)
Description copied from interface: Activity
Should NOT be called from client code!

Returns all views for this Activity for parent. If the Activity is recurrent, there normally are multiple views (one for every recurrent event). If no recurrence is defined, the length of the returned array is always 0 or 1 depending on wheter the base date range touches (overlaps) withinRange or not.

If both parent and withinRange are equal in subsequent calls, the view list are cached and returned immediately.

Specified by:
getViews in interface Activity
Parameters:
parent - An object to identify in which context the views are to be returned for. Since an Activity can reside in many views (same Activity painted in more than one JComponent) this object is used to tell them apart. The DateArea that paints the Activity is normally used as the view context.

null can be used and if so will anways return new views, not cached.

iListener - The listener to InteractionEvents. Can be null.
NOTE! This iListener will be set on the views.
withinRange - All returned ActivityViews must thouch (overlap in some way) withinRange. Must not be null since it whould return an infinite number of view for a recurring event that has no distinct end.
Returns:
All views for this Activity, filtered by parent and withinRange-. Never null and no null elements.

getBaseView

public ActivityView getBaseView(javax.swing.JComponent parent,
                                InteractionListener iListener)
Description copied from interface: Activity
Should NOT be called from client code!

Returns the view for the base date range. This method does not take recurrence into account at all.

Specified by:
getBaseView in interface Activity
Parameters:
parent - An object to identify in which context the views are to be returned for. Since an Activity can reside in many views (same Activity painted in more than one JComponent) this object is used to tell them apart. The DateArea that paints the Activity is normally used as the view context.

null can be used and if so will anways return new views, not cached.

iListener - The listener to InteractionEvents. Can be null.
NOTE! This iListener will be set on the views.
Returns:
Returns the view for the base date range. Never null.

clearCachedViews

public void clearCachedViews(javax.swing.JComponent container)
Clears any views that are acached.

Parameters:
container - Optional container. If != null the views for that container only needs to be cleared.
Since:
5.5.16

createViewList

protected ActivityView[] createViewList(javax.swing.JComponent parent,
                                        InteractionListener iListener,
                                        DateRangeI withinRange)

createView

public ActivityView createView(javax.swing.JComponent parent,
                               InteractionListener iListener,
                               ImmutableDateRange viewRange)
Creates an activity view. Override to create different views.

Parameters:
parent - An object to identify in which context the views are to be returned for. Since an Activity can reside in many views (same Activity painted in more than one JComponent) this object is used to tell them apart. The DateArea that paints the Activity is normally used as the view context. null can be used. Not null.
iListener - The listener to InteractionEvents. Can be null.
viewRange - The date range that the view is to have if different from the model. null if same as model. Noramlly only diffrent if the view should represent a recurrency instance.
Returns:
A newly created activity view.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Overridden to repaint all views for every change event.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Overrides:
propertyChange in class AbstractActivity

invalidateViews

public void invalidateViews()
Description copied from interface: Activity
Removes all cached paint optimizations for this activity's views so that they will be recreated next paint run.

Specified by:
invalidateViews in interface Activity
See Also:
ActivityView.invalidate()

repaintViews

public void repaintViews()

getGroupToggleContext

public java.lang.Object getGroupToggleContext(int state)
Description copied from interface: StateObservable
Return a context that is used to define a StateObservable.GROUP_TOGGLE pool. For instance the mouse over state is globally exclusive, only one "object" kan normally have the state GenericStates.MOUSE_OVER_BIT. Therefore all objects implementing this interface normally should return the same (or rather an object that .equals() OR ==) context for all concrete implementations of this interface (null normally) for the GenericStates.MOUSE_OVER_BIT state.
The returned context is normally interpreted by a StateHandler that may, or may not care about it.
Note! This method is only used for states that has the type StateObservable.GROUP_TOGGLE.

Specified by:
getGroupToggleContext in interface StateObservable
Parameters:
state - The state. Should not be more than one (not or:ed)
Returns:
The context. May be null.
See Also:
StateObservable.getStateType(int), StateObservable.isMultiState(int)

setGroupToggleContext

public void setGroupToggleContext(int state,
                                  java.lang.Object context)
Description copied from interface: StateObservable
Sets the context for the icon to toggle within. Approximately same as a button group for JRadioButtons. Normally this value is returned by StateObservable.getGroupToggleContext(int), but that depends on the concrete implementation that may, for instance, want to enforce a certain behaviour.

Specified by:
setGroupToggleContext in interface StateObservable
Parameters:
state - The state to set the context for. Should only be one state, not or:ed.
context - The context to set. Can be any object, including null, but should have a correct implementation of .equals() if non-null.
See Also:
States.getStateArray(), StateObservable.getGroupToggleContext(int)

getHandledStates

public int getHandledStates()
Description copied from interface: StateObservable
Returns the states that are legal for this object. Or:ed together.

Specified by:
getHandledStates in interface StateObservable
Returns:
The states that are legal for this object. Or:ed together.
See Also:
StateObservable.isHandlingStates(int)

getStateType

public int getStateType(int state)
Description copied from interface: StateObservable
What type of state that state is. I.e. how the state is set and unset.

Specified by:
getStateType in interface StateObservable
Parameters:
state - The state. Should not be more than one (not or:ed)
Returns:
What type state is. E.g. StateObservable.SPRING

isMultiState

public boolean isMultiState(int state)
Description copied from interface: StateObservable
Returns if more than one object in the same toggle group context can have this state. Multiple states are normally set with a modifier. E.g. select many activities with shift held down.

Specified by:
isMultiState in interface StateObservable
Parameters:
state - The state. Should not be more than one (not or:ed)
Returns:
If more than one object in the same toggle group context can have this state
See Also:
StateObservable.getGroupToggleContext(int)

isHandlingStates

public boolean isHandlingStates(int states)
Description copied from interface: StateObservable
Return if all the states is handled.

Specified by:
isHandlingStates in interface StateObservable
Parameters:
states - The state(s) to check
Returns:
true is it is handled
See Also:
StateObservable.getHandledStates()

getSettableStates

public int getSettableStates(int states)
Description copied from interface: StateObservable
Returns which of the suggested states is actually settable. Note that a state may be supported but not currently possible to set, for instance if the object is disabled it can't be selected.

Specified by:
getSettableStates in interface StateObservable
Parameters:
states - The states or:ed together
Returns:
The states allowed to set

areStatesSet

public boolean areStatesSet(int states,
                            boolean allStatesSet)
Description copied from interface: StatesI
Returns the status of a state (or states).

Specified by:
areStatesSet in interface StatesI
Parameters:
states - The state or states to be tested if they are all/some on. eg. GenericStates.MOUSE_OVER_BIT or (GenericStates.SELECTED_BIT | GenericStates.DRAGGING_BIT)
allStatesSet - If true all (and) of states must be set for true to be returned. If false only one of the (or) must be set for true to be returned.
Returns:
true if all (or some, depending on allStatesSet) states in state was on (set to true)

getStateArray

public int[] getStateArray()
Description copied from interface: StatesI
Takes the state integer and split them up with a call to States.splitStates(int)

Specified by:
getStateArray in interface StatesI
Returns:
The states splitted into an array

isAnyStateSet

public boolean isAnyStateSet()
Description copied from interface: StatesI
Returns true if any state is set.

Specified by:
isAnyStateSet in interface StatesI
Returns:
true if any state is set.

isStateSet

public boolean isStateSet(int s)
Description copied from interface: StatesI
Returns the status of a state. This is a short for StatesI.areStatesSet(int, boolean) but only handles ONE state so and or or doesn't matter.

Specified by:
isStateSet in interface StatesI
Parameters:
s - The state to be tested if it is on. eg. GenericStates.MOUSE_OVER_BIT
Returns:
true if the state was set (on), false otherwise.

getStatesSet

public int getStatesSet()
Description copied from interface: StatesI
Returns the states packed in an int

Specified by:
getStatesSet in interface StatesI
Returns:
The states packed in an int

setStates

public boolean setStates(int states,
                         boolean b)
Description copied from interface: StatesI
Sets the status of a state (or states).

Specified by:
setStates in interface StatesI
Parameters:
states - The state or states to be set to on (set to true). eg. GenericStates.MOUSE_OVER_BIT or (GenericStates.SELECTED_BIT | GenericStates.DRAGGING_BIT)
b - true means on
Returns:
If the state/states for the activity actually changed


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.