|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.miginfocom.calendar.grid.AbstractGrid
public abstract class AbstractGrid
Implements most of the basic geometry work for a Grid. It doesn't have any rows or gridlines created, that
will be done by calling createGridLinesAndCellRows() the first time setSize(java.awt.Dimension) is called
sice the rows/cells can't be created without the bounds set.
This grid only supports one level of sub-grid lines. This means that every row in the secondary dimension can consist of a
number of sub rows. Those however can not (even though the GridRow API can support an arbitrary depth) contain sub
grid rows. Also, currently all rows have to have an equal amount of grid rows.
This class is immutable once created and should be recreated if data on which it is build changes.
Note! Subclasses should call createGridLinesAndCellRows() at the end of the constructor to create the grid rows/lines or at
least create them in some other way. Use setCellRows(int, GridRow[]) and setGridLines(int, GridLine[]) to set the rows.
Listeners will be attached to them and removed if new rows are installed.
| Field Summary |
|---|
| Fields inherited from interface com.miginfocom.calendar.grid.Grid |
|---|
OUTLINE_SHAPE_MODE_EXACT, OUTLINE_SHAPE_MODE_EXACT_CLIPPED, OUTLINE_SHAPE_MODE_POLYGON, OUTLINE_SHAPE_MODE_RECTANGLE, PRIMARY_DIMENSION, SECONDARY_DIMENSION, SIZE_MODE_INSIDE, SIZE_MODE_MIDDLE, SIZE_MODE_OUTSIDE, SIZE_MODE_UPPER_LEFT |
| Constructor Summary | |
|---|---|
protected |
AbstractGrid(int primDim,
int primDimCellCount,
int secDimCellCount,
GridLineSpecification gridLineSpec)
Constructor. |
| Method Summary | |
|---|---|
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 grid, as well as the GridRows it contains. |
protected void |
assertSize(int row,
int col)
Throws a IndexOutOfBoundsException if cell doesn't exist |
protected abstract void |
createGridLinesAndCellRows()
Implement this to create the cell rows and grid lines. |
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.lang.Integer |
getAbsolutePreferredHeight()
Returns the preferred height if it can be specified. |
java.lang.Integer |
getAbsolutePreferredWidth()
Returns the preferred width if it can be specified. |
java.awt.Rectangle |
getBoundingBox(int startRow,
int startCol,
int endRow,
int endCol,
int cellSizeMode,
boolean forDraw)
Returns the bounds that contains all cells between the two cells (inclusive). |
java.awt.Rectangle |
getBoundsOfCell(int r,
int c,
int cellSizeMode,
boolean forDraw)
Returns a rectangle of the bounds of a cell, or hole, in the grid. |
java.awt.Point |
getCell(int number)
Return the cell for a cell number. |
int |
getCellCount(int dim)
Returns the number of cells in the specified dimension |
int |
getCellNumber(java.awt.Point cell)
Returns the cell number for a cell. |
java.awt.Polygon |
getCellsOutline(int startRow,
int startCol,
int endRow,
int endCol,
int cellSizeMode,
boolean forDraw)
Traces the outline from the start cell to the end cell so that all cells between the start and end cell is inside the polygon, and no other cells. |
int |
getColumnCount()
Returns the number of columns (holes) in the grid. |
int |
getColumnDimIx()
Returns the column dimension index. |
java.lang.Integer |
getColumnForX(int x,
boolean lenient)
Returns the column that the x-value is over. |
GridLine[] |
getColumnGridLines()
Returns the column grid lines. |
GridRow[] |
getColumns()
Returns the grid-rows for the cell columns |
GridLine[] |
getGridLines(int dimIx)
Returns the live grid lines for one dimension. |
GridLineSpecification |
getGridLineSpecification()
Returns the grid line specification for this grid. |
GridRow[] |
getGridRows(int dimIx)
Returns the live rows for the cells for one dimension. |
int |
getHeight()
Returns the height |
int |
getMaximumHeight()
Returns the maximum height that this grid can have. |
int |
getMaximumWidth()
Returns the maximum width that this grid can have. |
int |
getMinimumHeight()
Returns the minimum height that this grid can have. |
int |
getMinimumWidth()
Returns the minimum width that this grid can have. |
protected int |
getOrientationForDimIx(int dimIx)
Returns the dimension for dimIx. |
java.lang.Float |
getPercentInsideColumn(int x,
boolean lenient)
Returns how far into the column that the x-value is over, in percent (0..1) |
java.lang.Float |
getPercentInsideRow(int y,
boolean lenient)
Returns how far into the row that the y-value is over, in percent (0..1) |
int |
getPrimaryDimension()
Returns the primary dimension. |
GridDimensionLayout |
getPrimaryDimensionLayout()
|
protected int |
getRelPos(int dimIx,
float perc)
Returns an absolute pixel position perc percent into the grid's cells. |
GridRow |
getRowAt(int dimIx,
java.awt.Point p,
int maxDepth)
Recursively call getRowIndexForPos(int, int, boolean) to get the deepest grid row that pos hits. |
GridRow |
getRowAt(int dimIx,
java.awt.Point p,
int maxDepth,
boolean lenientBounds)
Deprecated. Since rows may not be layed out neck-to-neck from v5.5 the lenient argument can not be used. Use getRowAt(int, java.awt.Point, int) instead. |
int |
getRowCount()
Returns the number of rows (holes) in the grid. |
int |
getRowDimIx()
Returns the row dimension index. |
java.lang.Integer |
getRowForY(int y,
boolean lenient)
Returns the row that the y-value is over. |
GridLine[] |
getRowGridLines()
Returns the row grid lines. |
protected java.lang.Integer |
getRowIndexForPos(int dimIx,
int pos,
boolean lenientBounds)
Returns the cell for a position |
GridRow[] |
getRows()
Returns the grid-rows for the cell rows |
GridDimensionLayout |
getSecondaryDimensionLayout()
|
java.awt.Dimension |
getSize()
Returns the size of the grid |
int |
getSize(int dimIx)
Returns either bounds.width or bounds.height depending on which dimension is the primary |
int |
getWidth()
Returns the width |
int |
getX(float perc)
Returns the x-position that is percentage percentange into the grid. |
int |
getY(float perc)
Returns the y-position that is percentage percentange into the grid. |
boolean |
isIgnorePropertyEvents()
Returns if events are currently ignored. |
void |
layout()
Calculates all positions for all rows. |
void |
propertyChange(java.beans.PropertyChangeEvent e)
Just dispatch it to the listeners for this class. |
void |
removePropertyListener(java.beans.PropertyChangeListener l)
Removes the listener, if it is in the list. |
protected void |
setCellRows(int dimIx,
GridRow[] newCellRows)
Sets the cell rows. |
void |
setGridLines(int dimIx,
GridLine[] newGridLines)
Sets the grid lines. |
boolean |
setIgnorePropertyEvents(boolean b)
Sets if events should be ignored, and thus not fired. |
void |
setPrimaryDimensionLayout(GridDimensionLayout layout)
|
void |
setSecondaryDimensionLayout(GridDimensionLayout layout)
|
void |
setSize(java.awt.Dimension size)
Sets the size and set the layout to dirty, but doen't lay it out. |
int |
toPos(int dimIx,
java.awt.Point p)
Return either p.x or p.y depending in the indicated dimension. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected AbstractGrid(int primDim,
int primDimCellCount,
int secDimCellCount,
GridLineSpecification gridLineSpec)
bounds
after creation. This constructor creates a grid which contains all possible dates/times within dateRange.
primDim - The dimensions the cells should be laid out if they where sequental. e.g.
code>SwingConstants.HORIZONTAL means that the "next" cell if normally to the right, if not
reached the last column, where it wraps to next row.primDimCellCount - The number of cells in the primary dimension. & gt 0.secDimCellCount - The number of cells in the secondary dimension. & gt 0.gridLineSpec - The specification for the grid lines in the primary, secondary and for all sub dimensins. Not null.setSize(java.awt.Dimension)| Method Detail |
|---|
public GridDimensionLayout getSecondaryDimensionLayout()
public void setSecondaryDimensionLayout(GridDimensionLayout layout)
public GridDimensionLayout getPrimaryDimensionLayout()
public void setPrimaryDimensionLayout(GridDimensionLayout layout)
public int getColumnCount()
Grid
getColumnCount in interface GridGrid.getCellCount(int)public int getRowCount()
Grid
getRowCount in interface GridGrid.getCellCount(int)public int getCellCount(int dim)
Grid
getCellCount in interface Griddim - Grid.PRIMARY_DIMENSION or Grid.SECONDARY_DIMENSION
Grid.getColumnCount(),
Grid.getRowCount()public java.awt.Dimension getSize()
Grid
getSize in interface Gridpublic int getSize(int dimIx)
Gridbounds.width or bounds.height depending on which dimension is the primary
getSize in interface GriddimIx - Either Grid.PRIMARY_DIMENSION or Grid.SECONDARY_DIMENSION
public int getHeight()
Grid
getHeight in interface Gridpublic int getWidth()
Grid
getWidth in interface Gridpublic void setSize(java.awt.Dimension size)
Grid
setSize in interface Gridsize - The new size. Not null.Grid.layout()public int getMinimumWidth()
Grid0 if not explicitly set.
getMinimumWidth in interface Grid0 if not explicitly set.public int getMaximumWidth()
GridMigUtil.BIG_INT if not explicitly set.
getMaximumWidth in interface GridMigUtil.BIG_INT if not explicitly set.public int getMinimumHeight()
Grid0 if not explicitly set.
getMinimumHeight in interface Grid0 if not explicitly set.public int getMaximumHeight()
GridMigUtil.BIG_INT if not explicitly set.
getMaximumHeight in interface GridMigUtil.BIG_INT if not explicitly set.public java.lang.Integer getAbsolutePreferredWidth()
GridGridSegmentSpec if it has a preferred width and
if so, returns it. If the GridSegmentSpec has a relative preferred width (Float), it is
considered dynamic and null is returned.minimumWidth == maximumWidth == preferredWidth.
getAbsolutePreferredWidth in interface Gridnull if dynamic, i.e. unspecified.public java.lang.Integer getAbsolutePreferredHeight()
GridGridSegmentSpec if it has a preferred height and
if so, returns it. If the GridSegmentSpec has a relative preferred height (Float), it is
considered dynamic and null is returned.minimumWidth == maximumWidth == preferredWidth.
getAbsolutePreferredHeight in interface Gridnull if dynamic, i.e. unspecified.public int getX(float perc)
Gridpercentage percentange into the grid. For a normal grid the is a simple operation (linear),
but for a segmented grid with segments of different scales this could non-trivial to calculate.
getX in interface Gridperc - (normally 0.0 - 1.0) The percentage into the grid. Can be < 0.0 or > 1.0, the grid should extrapolate the absolute position
is those cases.
percentage percentange into the grid.public int getY(float perc)
Gridpercentage percentange into the grid.
getY in interface Gridperc - (normally 0.0 - 1.0) The percentage into the grid. Can be < 0.0 or > 1.0, the grid should extrapolate the absolute position
is those cases.
percentage percentange into the grid.
protected int getRelPos(int dimIx,
float perc)
perc percent into the grid's cells.
dimIx - The dimension. E.g. Grid.PRIMARY_DIMENSION or Grid.SECONDARY_DIMENSIONperc - (normally 0.0 - 1.0) The percentage into the grid. Can be < 0.0 or > 1.0, the grid will extrapolate the absolute position
is those cases.
perc percent into the grid's cells.
public int toPos(int dimIx,
java.awt.Point p)
p.x or p.y depending in the indicated dimension. Just a convenience method for
getOrientationForDimIx(dimIx) == VER ? p.y : p.x;.
dimIx - The dimension. E.g. Grid.PRIMARY_DIMENSIONp - The point
p.x or p.y depending in the indicated dimension.
public java.lang.Integer getColumnForX(int x,
boolean lenient)
Grid
getColumnForX in interface Gridx - The x-valuelenient - If true this method never returns null, it returns first or last column of outside grid
depending on whether the point is before or after the nearest col
public java.lang.Integer getRowForY(int y,
boolean lenient)
Grid
getRowForY in interface Gridy - The y-value in the coordinate system that grid's bounds is in.lenient - If true this method never returns null, it returns first or last row of outside grid
depending on whether the point is before or after the nearest col
public GridRow[] getColumns()
Grid
getColumns in interface GridnullGridRowpublic GridRow[] getRows()
Grid
getRows in interface GridnullGridRowpublic GridRow[] getGridRows(int dimIx)
Grid
getGridRows in interface GriddimIx - The dimension. E.g. Grid.PRIMARY_DIMENSION.
public GridLine[] getColumnGridLines()
Grid
getColumnGridLines in interface Gridnull.public GridLine[] getRowGridLines()
Grid
getRowGridLines in interface Gridnull.
protected void setCellRows(int dimIx,
GridRow[] newCellRows)
newCellRows.
dimIx - The dimension. E.g. PRIMARY_DIMENSIONnewCellRows - The new cell rows to setpublic GridLine[] getGridLines(int dimIx)
Grid
getGridLines in interface GriddimIx - The dimension. E.g. Grid.PRIMARY_DIMENSION.
public void setGridLines(int dimIx,
GridLine[] newGridLines)
GridnewGridLines.
setGridLines in interface GriddimIx - The dimension. E.g. PRIMARY_DIMENSIONnewGridLines - The new grid lines to setpublic GridLineSpecification getGridLineSpecification()
Grid
getGridLineSpecification in interface Gridnull.public final int getColumnDimIx()
Grid
getColumnDimIx in interface GridGrid.SECONDARY_DIMENSION,
Grid.PRIMARY_DIMENSIONpublic final int getRowDimIx()
Grid
getRowDimIx in interface GridGrid.SECONDARY_DIMENSION,
Grid.PRIMARY_DIMENSIONprotected final int getOrientationForDimIx(int dimIx)
dimIx.
dimIx - the dimension index. E.g. PRIMARY_DIMENSION.
dimIx. E.g. SwingUtilities.VERTICALGrid.SECONDARY_DIMENSION,
Grid.PRIMARY_DIMENSION
protected java.lang.Integer getRowIndexForPos(int dimIx,
int pos,
boolean lenientBounds)
dimIx - The dimension. E.g. Grid.SECONDARY_DIMENSIONpos - The pixel position.lenientBounds - If true this method never returns null, it returns first or last cell of outside grid
depending on whether the point is before or after the nearest cell.
null.
public GridRow getRowAt(int dimIx,
java.awt.Point p,
int maxDepth)
getRowIndexForPos(int, int, boolean) to get the deepest grid row that pos hits.
Follows the same rules but for a hitted row that row's potential sub rows are then asked.
dimIx - The dimension. E.g. Grid.SECONDARY_DIMENSIONp - The pixel position. Only x OR y will be interesting (depending on dimIx).maxDepth - The maximum depth to recursively check for sub rows. If 0 then one if rows will be returned.
null if none.
public GridRow getRowAt(int dimIx,
java.awt.Point p,
int maxDepth,
boolean lenientBounds)
getRowAt(int, java.awt.Point, int) instead.
getRowIndexForPos(int, int, boolean) to get the grid row that pos hits.
Follows the same rules but for a hitted row that row's potential sub rows are then asked.
dimIx - The dimension. E.g. Grid.SECONDARY_DIMENSIONp - The pixel position. Only x OR y will be interesting (depending on dimIx).maxDepth - The maximum depth to recursively check for sub rows. If 0 then one if rows will be returned.lenientBounds - NOT USED
null if none.
public java.lang.Float getPercentInsideColumn(int x,
boolean lenient)
Grid
getPercentInsideColumn in interface Gridx - The x-value in the coordinate system that grid's bounds is in.lenient - If true this method never returns null, it returns 0 or 1 depending on whether the point is
before or after the nearest col
public java.lang.Float getPercentInsideRow(int y,
boolean lenient)
Grid
getPercentInsideRow in interface Gridy - The y-value in the coordinate system that grid's bounds is in.lenient - If true this method never returns null, it returns 0 or 1 depending on whether the point is
before or after the nearest col
public int getPrimaryDimension()
Grid
getPrimaryDimension in interface Grid
public java.awt.Rectangle getBoundsOfCell(int r,
int c,
int cellSizeMode,
boolean forDraw)
Grid
getBoundsOfCell in interface Gridr - The row, zero basedc - The column, zero basedcellSizeMode - The size and placement of the returned rectangle. Eg. Grid.SIZE_MODE_INSIDEforDraw - If true the returned size is for draw-commands. If false it's sized for fill-commands
(one pixel bigger) see class doc for more info.
public java.awt.Rectangle getBoundingBox(int startRow,
int startCol,
int endRow,
int endCol,
int cellSizeMode,
boolean forDraw)
Grid
getBoundingBox in interface GridstartRow - The start row. Must exist in the gridstartCol - The start column. Must exist in the gridendRow - The end row. Must exist in the gridendCol - The end column. Must exist in the gridcellSizeMode - The size and placement of the returned outline. Eg. SIZE_MODE_INSIDEforDraw - If true the returned size is for draw-commands. If false it's sized for fill-commands
(one pixel bigger normally) see class doc for more info.
public java.awt.Polygon getCellsOutline(int startRow,
int startCol,
int endRow,
int endCol,
int cellSizeMode,
boolean forDraw)
Grid
getCellsOutline in interface GridstartRow - The start row. Must exist in the gridstartCol - The start column. Must exist in the gridendRow - The end row. Must exist in the gridendCol - The end column. Must exist in the gridcellSizeMode - The size and placement of the returned outline. Eg. SIZE_MODE_INSIDEforDraw - If true the returned size is for draw-commands. If false it's sized for fill-commands
(one pixel bigger normally) see class doc for more info.
public int getCellNumber(java.awt.Point cell)
Grid
getCellNumber in interface Gridcell - The cell. Row, column.
public java.awt.Point getCell(int number)
Grid
getCell in interface Gridnumber - The cell number (as in if they was laied out in one line and not wrapped).
null. New object free to use.Grid.getCellNumber(java.awt.Point)public void layout()
GridOnly does the actual layout if the layout is dirty.
layout in interface Grid
protected final void assertSize(int row,
int col)
public void propertyChange(java.beans.PropertyChangeEvent e)
propertyChange in interface java.beans.PropertyChangeListenere - The event, originating from a GridRow.protected abstract void createGridLinesAndCellRows()
setBounds is
called and MUST initialize cells and gridRows to the correct sizes.
Set cellRows and gridLines with setCellRows(int, GridRow[]) and setGridLines(int, GridLine[]).
public void addPropertyListener(java.beans.PropertyChangeListener l)
addPropertyListener(java.beans.PropertyChangeListener, boolean) with false for
as>WeakRef.
l - The listener.
public void addPropertyListener(java.beans.PropertyChangeListener l,
boolean asWeakRef)
GridRows it contains. The source
can be checked to see if the property is from the grid or from a grid row.
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.public void removePropertyListener(java.beans.PropertyChangeListener l)
l - The listener to remove, not null.public boolean isIgnorePropertyEvents()
setIgnorePropertyEvents(boolean)public boolean setIgnorePropertyEvents(boolean b)
b - true turns off events
protected void firePropertyChangeEvent(java.lang.String propName,
java.lang.Object oldValue,
java.lang.Object newValue)
propName - The property that has been changedoldValue - The old value if that is known. May be null.newValue - The new value if known. May be null.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||