com.miginfocom.calendar.grid
Class GridRow

java.lang.Object
  extended by com.miginfocom.calendar.grid.GridRow
All Implemented Interfaces:
TimeSpan, Filter, PropertyProvider, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Comparable, java.util.EventListener

public class GridRow
extends java.lang.Object
implements TimeSpan, Filter, PropertyProvider, java.beans.PropertyChangeListener

A row (which can also be a column) in a grid.

It is called gridRow but can also be a gridColumn. I.e. horizontal or vertical.

Since this row/col can contain other rows call getGridRows() to obtain the real rows. If there are none this will be returned as only elements on the array, otherwise it will be left out.

See Also:
Serialized Form

Field Summary
static PropertyKey FOLDED
          Property key for whether the row is folded or not.
static PropertyKey NAME
          Property key for name of the row.
 
Constructor Summary
GridRow(GridRow parentRow)
          Constructor.
GridRow(GridRow parent, Filter filter)
          Constructor.
GridRow(ImmutableDateRange dateRange)
          Constructor if this is a root grid row.
GridRow(ImmutableDateRange dateRange, Filter filter)
          Constructor if this is a root grid row.
 
Method Summary
 boolean accept(java.lang.Object activity)
          Returns what the filter returns or true if no filter.
 void addPropertyListener(java.beans.PropertyChangeListener l)
          Transfer to addPropertyListener(java.beans.PropertyChangeListener, boolean) with false for as>WeakRef.
 void addPropertyListener(java.beans.PropertyChangeListener l, boolean asWeakRef)
          Add a listener that listens for any changes in the properties for this row.
 int compareTo(java.lang.Object o)
           
 boolean contains(int p)
          Returns if pos is within start and end.
 boolean containsProperty(PropertyKey property)
          Return if the provider contains the property.
 int estimateExternalRow(int p)
          Returns if p is before, within or after this row.
protected  void firePropertyChangeEvent(java.lang.String propName, java.lang.Object oldValue, java.lang.Object newValue)
          Notifies listeners of property changes, but only if there actually was a change.
 java.awt.Paint getBackground()
          Returns the background or null if no GridLineRepetition was sent in the construcotr.
 ImmutableDateRange getDateRange()
          Will return the actual date range stored.
 MutableDateRange getDateRangeClone()
          Returns the date range that the object spans as a clone which is safe to change without chaning the original time span.
 DateRangeI getDateRangeForReading()
          Returns the date range that the object spans.
 int getEnd()
          The end position, or rather just after it.
 Filter getFilter()
          Returns the filter.
 GridLineProvider getGridLineProvider()
          Returns the privoder for the grid lines.
 GridLine[] getGridLines()
          Return the contained grid lines for the sub rows.
 int getGridRowCount()
          Returns the number of sub grid rows.
 GridRow[] getGridRows()
          Return the contained sub rows.
 GridRow[] getGridRowsDeep()
          Returns a deep list of all grid rows and/or grid lines, NOT including this.
 int getIndexOfGridRow(GridRow row)
          Return the index of a child grid row or -1 if row is not a child.
 int getLevel()
          Returns how many levels above this one that exists.
 AtRefNumber getMaximumSize()
          Returns the maximum size for this row or null if not set.
 int getMiddleHi()
          Get middle position rounded upwards if "half".
 int getMiddleLo()
          Get middle position rounded downwards if "half".
 AtRefNumber getMinimumSize()
          Returns the minimum size for this row or null if not set.
 java.lang.String getName()
          Returns the name of the contained filter.
 GridRow getParent()
          Returns the parent row or null if no parent.
 int getPosition(float perc)
          Returns a position perc percent into the row
 AtRefNumber getPreferredSize()
          Returns the preferred size for this row or null if not set.
 java.lang.Object getProperty(PropertyKey property)
          Returns the property for a name.
 int getSize()
          Returns the size of the row.
 AtRefNumber[] getSizes()
          Returns a new array with the values for [min/preferred/max] sizes for this row.
 int getStart()
          Returns the start position of the row.
 MutableDateRange getWritableDateRange()
          Returns the contained date range for editing.
 boolean isFolded()
          Returns if this row is folded.
 boolean isFoldedAbove()
          Returns if any of this row's parents, is folded.
 boolean isFoldedUpwards()
          Returns if this row, or any of this row's parents, is folded.
 boolean isIgnorePropertyEvents()
          Returns if events are currently ignored.
 boolean isLeaf()
          Returns if this row has no sub rows.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Redispatch event to registered listeners without changing source
 java.lang.Object removeProperty(PropertyKey property)
          Removes the property.
 void removePropertyListener(java.beans.PropertyChangeListener l)
          Removes the listener, if it is in the list.
 void setBackground(java.awt.Paint background)
          Sets the background or null if no GridLineRepetition was sent in the construcotr.
 void setDateRange(ImmutableDateRange dateRange)
           
 void setFilter(Filter filter)
          Sets the filter.
 void setFolded(boolean visible)
          Sets if this row should be visible.
 void setGridRows(GridRow[] subRows, GridLineProvider glProvider)
          Sets the sub rows or null for no sub rows.
 boolean setIgnorePropertyEvents(boolean b)
          Sets if events should be ignored, and thus not fired.
 void setMaximumSize(AtRefNumber s)
          Sets the maximum size for this row or null.
 void setMinimumSize(AtRefNumber s)
          Sets the minimum size for this row or null.
 void setPreferredSize(AtRefNumber s)
          Sets the preferred size for this row or null.
 java.lang.Object setProperty(PropertyKey property, java.lang.Object newValue)
          Sets a property for the grid row and if the property changes, fires a property change event.
 void setSize(int size)
          Sets the size of the row.
 void setSizes(AtRefNumber[] newSizes)
          Sets min/preferred/max sizes for this row.
 void setStart(int pos)
          Sets the start position of the row.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FOLDED

public static final PropertyKey FOLDED
Property key for whether the row is folded or not. Not set means not folded (sub rows visible).


NAME

public static final PropertyKey NAME
Property key for name of the row.

Constructor Detail

GridRow

public GridRow(ImmutableDateRange dateRange)
Constructor if this is a root grid row.

Parameters:
dateRange - The dates/times that this row should span. Not null.

GridRow

public GridRow(ImmutableDateRange dateRange,
               Filter filter)
Constructor if this is a root grid row.

Parameters:
dateRange - The dates/times that this row should span. Not null.
filter - The filter used to filter ActivityViews.

GridRow

public GridRow(GridRow parentRow)
Constructor.

Parameters:
parentRow - The parent row. Not null.

GridRow

public GridRow(GridRow parent,
               Filter filter)
Constructor.

Parameters:
parent - The parent row. Not null.
filter - The filter used to filter ActivityViews.
Method Detail

getParent

public GridRow getParent()
Returns the parent row or null if no parent.

Returns:
The parent row or null if no parent.

getMinimumSize

public AtRefNumber getMinimumSize()
Returns the minimum size for this row or null if not set. Will NOT check with the dub rows.

Returns:
The minimum size for this row or null if not set.

setMinimumSize

public void setMinimumSize(AtRefNumber s)
Sets the minimum size for this row or null. Will NOT check with the dub rows.

Parameters:
s - The minimum size for this row or null.

getPreferredSize

public AtRefNumber getPreferredSize()
Returns the preferred size for this row or null if not set. Will NOT check with the dub rows.

Returns:
The preferred size for this row or null if not set.

setPreferredSize

public void setPreferredSize(AtRefNumber s)
Sets the preferred size for this row or null.

Parameters:
s - The preferred size for this row or null.

getMaximumSize

public AtRefNumber getMaximumSize()
Returns the maximum size for this row or null if not set.

Returns:
The maximum size for this row or null if not set.

setMaximumSize

public void setMaximumSize(AtRefNumber s)
Sets the maximum size for this row or null.

Parameters:
s - The maximum size for this row or null.

getSizes

public AtRefNumber[] getSizes()
Returns a new array with the values for [min/preferred/max] sizes for this row. This is an optimization for the Distributor.

Returns:
The live array. Should not be changed since it can be referenced by others. It can even be a static array.
See Also:
(Can be used as index for the elements, (Can be used as index for the elements, (Can be used as index for the elements

setSizes

public void setSizes(AtRefNumber[] newSizes)
Sets min/preferred/max sizes for this row.

Parameters:
newSizes - The sizes to set. The array will be clones, as opposed to getSizes(). Not null and must be of length 3.
See Also:
(Can be used as index for the elements, (Can be used as index for the elements, (Can be used as index for the elements

isFoldedUpwards

public boolean isFoldedUpwards()
Returns if this row, or any of this row's parents, is folded. Convenience mthod for getting property FOLDED.

Returns:
If this row, or any of this row's parents, is folded.

isFoldedAbove

public boolean isFoldedAbove()
Returns if any of this row's parents, is folded. Convenience method for getting property FOLDED.

Returns:
If any of this row's parents, is folded.

isFolded

public boolean isFolded()
Returns if this row is folded. Convenience mthod for getting property FOLDED.

Returns:
If this row is folded.

setFolded

public void setFolded(boolean visible)
Sets if this row should be visible. Convenience mthod for setting property FOLDED.

Parameters:
visible - If this row should be visible.

getLevel

public int getLevel()
Returns how many levels above this one that exists. If this row has no parent it is at level zero. If this row has one parent and that parent has no parent 1 is returned and so on.

Returns:
How many levels above this one that exists.

getBackground

public java.awt.Paint getBackground()
Returns the background or null if no GridLineRepetition was sent in the construcotr.

Returns:
The background

setBackground

public void setBackground(java.awt.Paint background)
Sets the background or null if no GridLineRepetition was sent in the construcotr.

Parameters:
background - The suggested background

getDateRange

public ImmutableDateRange getDateRange()
Will return the actual date range stored. Ok since it is immutable.

Returns:
The actual date range stored.

setDateRange

public void setDateRange(ImmutableDateRange dateRange)

getFilter

public Filter getFilter()
Returns the filter.

Returns:
The filter. Might be null.

setFilter

public void setFilter(Filter filter)
Sets the filter. If null the filter will always breturn true (no filtering).

Parameters:
filter - The filter. Might be null.

getStart

public int getStart()
Returns the start position of the row. For laying (horizontal) rows it would be the upper edge of the line.

Returns:
The start position of the row

setStart

public void setStart(int pos)
Sets the start position of the row. For laying (horizontal) rows it would be the upper edge of the line.

Parameters:
pos - The start position of the row

getSize

public int getSize()
Returns the size of the row. For laying (horizontal) rows it would be the height of the row.

Returns:
The size of the row.

setSize

public void setSize(int size)
Sets the size of the row. For laying (horizontal) rows it would be the height of the row.

Parameters:
size - The size of the row.

getEnd

public int getEnd()
The end position, or rather just after it. Actually returns pos + size.

Returns:
The end position, or rather just after it. Actually returns pos + size.

getMiddleLo

public int getMiddleLo()
Get middle position rounded downwards if "half". (x.5)

Returns:
Middle position rounded downwards if "half". (x.5)

getMiddleHi

public int getMiddleHi()
Get middle position rounded upwards if "half". (x.5)

Returns:
Middle position rounded upwards if "half". (x.5)

getPosition

public int getPosition(float perc)
Returns a position perc percent into the row

Parameters:
perc - (normally 0.0 - 1.0) The percentage into the grid. Can be < 0.0 or > 1.0, the row will extrapolate the absolute position is those cases.
Returns:
a position perc percent into the row.

contains

public boolean contains(int p)
Returns if pos is within start and end.

Parameters:
p - The position to check.
Returns:
If pos is within start and end.

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

estimateExternalRow

public int estimateExternalRow(int p)
Returns if p is before, within or after this row.

Parameters:
p - The pos to compare.
Returns:
Negative for before, 0 for within and positive for before. If != 0 the value is as many rows away pos would be if every row was os same size as this.

isLeaf

public boolean isLeaf()
Returns if this row has no sub rows.

Returns:
true if no sub rows.

getGridLineProvider

public GridLineProvider getGridLineProvider()
Returns the privoder for the grid lines. May be null.

Returns:
The privoder for the grid lines. May be null.

getGridLines

public GridLine[] getGridLines()
Return the contained grid lines for the sub rows. Only stored in the row, not used here.

Returns:
The contained grid lines for the sub rows. May be null.

getGridRows

public GridRow[] getGridRows()
Return the contained sub rows.

Returns:
The contained sub rows. May be null.

setGridRows

public void setGridRows(GridRow[] subRows,
                        GridLineProvider glProvider)
Sets the sub rows or null for no sub rows.

The layouter of the rows will decide the sizes for the rows, though normally they would be set to fit the main row's bounds. NOrmally the grid lines will have to be recreated as well.

Parameters:
subRows - The sub rows. null removes the rows and makes this row the only one.
glProvider - The object to ask for grid lines. Will be done in this method. If null no grid lines will be created.

getGridRowCount

public int getGridRowCount()
Returns the number of sub grid rows.

Returns:
The number of sub grid rows.

getIndexOfGridRow

public int getIndexOfGridRow(GridRow row)
Return the index of a child grid row or -1 if row is not a child.

Parameters:
row - The row to search for.
Returns:
The index or -1 if not found.

getGridRowsDeep

public GridRow[] getGridRowsDeep()
Returns a deep list of all grid rows and/or grid lines, NOT including this.

Returns:
A deep list of all grid rows and/or grid lines, NOT including this. Can be null.

getProperty

public java.lang.Object getProperty(PropertyKey property)
Description copied from interface: PropertyProvider
Returns the property for a name.

Specified by:
getProperty in interface PropertyProvider
Parameters:
property - The property key for the property to return. Not null.
Returns:
The value, may be null.

containsProperty

public boolean containsProperty(PropertyKey property)
Description copied from interface: PropertyProvider
Return if the provider contains the property.

Specified by:
containsProperty in interface PropertyProvider
Parameters:
property - The property key. Not null.
Returns:
If the provider contains the property.

setProperty

public java.lang.Object setProperty(PropertyKey property,
                                    java.lang.Object newValue)
Sets a property for the grid row and if the property changes, fires a property change event.

Parameters:
property - The key to store the key under.
newValue - The property to store.
Returns:
The old property for key.

removeProperty

public java.lang.Object removeProperty(PropertyKey property)
Removes the property. Fires same property as if the property was set to null.

Parameters:
property - The key to remove the property for.
Returns:
The old value of the property.

addPropertyListener

public void addPropertyListener(java.beans.PropertyChangeListener l)
Transfer to addPropertyListener(java.beans.PropertyChangeListener, boolean) with false for as>WeakRef.

Parameters:
l - The listener.

addPropertyListener

public void addPropertyListener(java.beans.PropertyChangeListener l,
                                boolean asWeakRef)
Add a listener that listens for any changes in the properties for this row.

Parameters:
l - The listener.
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removePropertyListener

public void removePropertyListener(java.beans.PropertyChangeListener l)
Removes the listener, if it is in the list.

Parameters:
l - The listener to remove, not null.

isIgnorePropertyEvents

public boolean isIgnorePropertyEvents()
Returns if events are currently ignored.

Returns:
If events are currently ignored.
See Also:
setIgnorePropertyEvents(boolean)

setIgnorePropertyEvents

public boolean setIgnorePropertyEvents(boolean b)
Sets if events should be ignored, and thus not fired.

Parameters:
b - true turns off events
Returns:
The old state of this flag.

firePropertyChangeEvent

protected void firePropertyChangeEvent(java.lang.String propName,
                                       java.lang.Object oldValue,
                                       java.lang.Object newValue)
Notifies listeners of property changes, but only if there actually was a change. If old and new equals nothing will be fired.

Parameters:
propName - The property that has been changed
oldValue - The old value if that is known. May be null.
newValue - The new value if known. May be null.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Redispatch event to registered listeners without changing source

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
e - The event to redispatch.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getDateRangeClone

public MutableDateRange getDateRangeClone()
Description copied from interface: TimeSpan
Returns the date range that the object spans as a clone which is safe to change without chaning the original time span. If the range is only to be read from use TimeSpan.getDateRangeForReading() instead to avoid unnecessary object cloning.

Specified by:
getDateRangeClone in interface TimeSpan
Returns:
Returns the date range that the object spans.

getDateRangeForReading

public DateRangeI getDateRangeForReading()
Description copied from interface: TimeSpan
Returns the date range that the object spans. If the object contains an immutable date range or a range that must not be changed that is returned here. In order to get a truly immutable date range that will not change call DateRangeI.getImmutable() on the returned range. The contract is to not change the returned date range.

Specified by:
getDateRangeForReading in interface TimeSpan
Returns:
Returns the date range that the object spans.

getWritableDateRange

public MutableDateRange getWritableDateRange()
Description copied from interface: TimeSpan
Returns the contained date range for editing. If the local date range isn't allowed to be edited an UnsupportedOperationException should be thrown.

Specified by:
getWritableDateRange in interface TimeSpan
Returns:
The contained date range for editing.

getName

public java.lang.String getName()
Returns the name of the contained filter. If filter is null property with key NAME is returned.

Specified by:
getName in interface Filter
Returns:
The name of the row as per Filter implementation.

accept

public boolean accept(java.lang.Object activity)
Returns what the filter returns or true if no filter.

Specified by:
accept in interface Filter
Parameters:
activity - An Activity.
Returns:
What the filter returns or true if no filter.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.