Package adams.gui.core
Class BaseSizeSequence
- java.lang.Object
-
- javax.swing.SizeSequence
-
- adams.gui.core.BaseSizeSequence
-
- All Implemented Interfaces:
Serializable
public class BaseSizeSequence extends SizeSequence implements Serializable
Specialized size sequence that can handle mixed row sizes.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BaseSizeSequence()
Creates a newBaseSizeSequence
object that contains no entries.BaseSizeSequence(int numEntries)
Creates a newBaseSizeSequence
object that contains the specified number of entries, all initialized to have size 0.BaseSizeSequence(int[] sizes)
Creates a newBaseSizeSequence
object that contains the specified sizes.BaseSizeSequence(int numEntries, int value)
Creates a newBaseSizeSequence
object that contains the specified number of entries, all initialized to have sizevalue
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getIndex(int position)
Returns the index of the entry that corresponds to the specified position.int
getPosition(int index)
Returns the start position for the specified entry.int
getSize(int index)
Returns the size of the specified entry.int[]
getSizes()
Returns the size of all entries.void
insertEntries(int start, int length, int value)
Adds a contiguous group of entries to thisBaseSizeSequence
.void
removeEntries(int start, int length)
Removes a contiguous group of entries from thisBaseSizeSequence
.void
setSize(int index, int size)
Sets the size of the specified entry.void
setSizes(int[] sizes)
Resets thisBaseSizeSequence
object, using the data in thesizes
argument.protected void
updatePositions(int start)
Updates the positions based on the current sizes.
-
-
-
Constructor Detail
-
BaseSizeSequence
public BaseSizeSequence()
Creates a newBaseSizeSequence
object that contains no entries. To add entries, you can useinsertEntries
orsetSizes
.
-
BaseSizeSequence
public BaseSizeSequence(int numEntries)
Creates a newBaseSizeSequence
object that contains the specified number of entries, all initialized to have size 0.- Parameters:
numEntries
- the number of sizes to track- Throws:
NegativeArraySizeException
- ifnumEntries < 0
-
BaseSizeSequence
public BaseSizeSequence(int numEntries, int value)
Creates a newBaseSizeSequence
object that contains the specified number of entries, all initialized to have sizevalue
.- Parameters:
numEntries
- the number of sizes to trackvalue
- the initial value of each size
-
BaseSizeSequence
public BaseSizeSequence(int[] sizes)
Creates a newBaseSizeSequence
object that contains the specified sizes.- Parameters:
sizes
- the array of sizes to be contained in theBaseSizeSequence
-
-
Method Detail
-
setSizes
public void setSizes(int[] sizes)
Resets thisBaseSizeSequence
object, using the data in thesizes
argument. This method reinitializes this object so that it contains as many entries as thesizes
array. Each entry's size is initialized to the value of the corresponding item insizes
.- Overrides:
setSizes
in classSizeSequence
- Parameters:
sizes
- the array of sizes to be contained in thisBaseSizeSequence
-
getSizes
public int[] getSizes()
Returns the size of all entries.- Overrides:
getSizes
in classSizeSequence
- Returns:
- a new array containing the sizes in this object
-
getPosition
public int getPosition(int index)
Returns the start position for the specified entry. For example,getPosition(0)
returns 0,getPosition(1)
is equal togetSize(0)
,getPosition(2)
is equal togetSize(0)
+getSize(1)
, and so on.Note that if
index
is greater thanlength
the value returned may be meaningless.- Overrides:
getPosition
in classSizeSequence
- Parameters:
index
- the index of the entry whose position is desired- Returns:
- the starting position of the specified entry
-
getIndex
public int getIndex(int position)
Returns the index of the entry that corresponds to the specified position. For example,getIndex(0)
is 0, since the first entry always starts at position 0.- Overrides:
getIndex
in classSizeSequence
- Parameters:
position
- the position of the entry- Returns:
- the index of the entry that occupies the specified position
-
getSize
public int getSize(int index)
Returns the size of the specified entry. Ifindex
is out of the range(0 <= index < getSizes().length)
the behavior is unspecified.- Overrides:
getSize
in classSizeSequence
- Parameters:
index
- the index corresponding to the entry- Returns:
- the size of the entry, -1 if outside boundaries
-
setSize
public void setSize(int index, int size)
Sets the size of the specified entry. Note that if the value ofindex
does not fall in the range:(0 <= index < getSizes().length)
the behavior is unspecified.- Overrides:
setSize
in classSizeSequence
- Parameters:
index
- the index corresponding to the entrysize
- the size of the entry
-
insertEntries
public void insertEntries(int start, int length, int value)
Adds a contiguous group of entries to thisBaseSizeSequence
. Note that the values ofstart
andlength
must satisfy the following conditions:(0 <= start < getSizes().length) AND (length >= 0)
. If these conditions are not met, the behavior is unspecified and an exception may be thrown.- Overrides:
insertEntries
in classSizeSequence
- Parameters:
start
- the index to be assigned to the first entry in the grouplength
- the number of entries in the groupvalue
- the size to be assigned to each new entry- Throws:
ArrayIndexOutOfBoundsException
- if the parameters are outside of the range: (0 <= start < (getSizes().length)) AND (length >= 0)
-
removeEntries
public void removeEntries(int start, int length)
Removes a contiguous group of entries from thisBaseSizeSequence
. Note that the values ofstart
andlength
must satisfy the following conditions:(0 <= start < getSizes().length) AND (length >= 0)
. If these conditions are not met, the behavior is unspecified and an exception may be thrown.- Overrides:
removeEntries
in classSizeSequence
- Parameters:
start
- the index of the first entry to be removedlength
- the number of entries to be removed
-
updatePositions
protected void updatePositions(int start)
Updates the positions based on the current sizes.- Parameters:
start
- the starting index
-
-