pl.netanel.swt.matrix
Class Axis<N extends java.lang.Number>

java.lang.Object
  extended by pl.netanel.swt.matrix.Axis<N>
Type Parameters:
N - specifies the indexing class for the receiver

public class Axis<N extends java.lang.Number>
extends java.lang.Object

Axis represents a horizontal or vertical axis of a matrix. It is divided into sections.

Events:
Selection, DefaultSelection

See Also:
Section

Constructor Summary
Axis()
          Constructs axis indexed by Integer class with two sections.
Axis(java.lang.Class<N> numberClass, int sectionCount, int headerIndex, int bodyIndex)
          Constructs axis indexed by the specified Number subclass containing the specified number of sections.
 
Method Summary
 int compare(AxisItem<N> item1, AxisItem<N> item2)
          Compares positions of items on this axis and returns value greater then 0 if item1 is behind item2, value lower then zero if item1 is before item2 and 0 if items are the same.
 int compare(Section<N> section1, Section<N> section2)
          Compares positions of sections on this axis and returns value greater then 0 if section1 is behind section2, value lower then zero if section1 is before section2 and 0 if sections are the same.
 int computeSize(Section<N> section, N index)
          Computes the optimal cell width that fits its content.
 pl.netanel.swt.matrix.NumberSetCore<N> createNumberSet()
          Deprecated. 
 int getAutoScrollOffset()
          Returns the offset from the edge of scrolling area within which dragging causes the content to scroll automatically and extend the dragged distance.
 Section<N> getBody()
          Returns the body section, which is by default a second section of the axis.
 int[] getCellBound(AxisItem<N> item)
          Returns the cell bound of the specified item in the viewport or null if the position is outside of the viewport scope.
 int getContentWidth()
          Returns the content bound including all the visible cells and lines.
 AxisItem<N> getFocusItem()
          Returns the focus item.
 int getFrozenHead()
          Returns the amount of items frozen at the beginning this axis.
 int getFrozenTail()
          Returns the amount of items frozen at the end this axis.
 Section<N> getHeader()
          Returns the header section, which is by default the first section of the axis.
 AxisItem<N> getItemByViewportDistance(int distance)
          Returns the item visible at the specified distance from the beginning of viewport area or null if the distance is outside of the viewport bounds.
 AxisItem<N> getItemByViewportOffset(AxisItem<N> item, int offset)
          Returns a visible item that is away from the given item by the number of items specified by the offset argument or null if such an item is outside of the viewport bounds or does not exist.
 AxisItem<N> getItemByViewportPosition(int position)
          Returns the item visible at the specified position in the viewport or null if the position is outside of the viewport bounds.
 int[] getLineBound(AxisItem<N> item)
          Returns the line bound of the specified item in the viewport or null if the position is outside of the viewport scope.
 int getMinimalCellWidth()
          Returns the minimal cell width to be achieved by a user driven cell resizing.
 AxisItem<N> getMouseItem()
          Returns the last item the mouse was over.
 int getResizeOffset()
          Returns the offset from the dividing line within which dragging changes the width of the axis item.
 AxisItem<N> getScrollItem()
           
 N getScrollPosition()
           
 Section<N> getSection(int sectionIndex)
          Returns the section at the specified position in this axis.
 int getSectionCount()
          Returns the number of sections in the receiver.
 int getViewportItemCount()
          Returns number of items visible in the viewport.
 int getViewportPosition(AxisItem<N> item)
          Returns the position of the given item in the sequence of items visible in the viewport or -1 if the viewport does not display the item.
 int indexOf(Section<N> section)
          Returns index of the given section in the list of this axis sections or -1 if the section does not belong to this axis.
 boolean isFocusItemEnabled()
          Returns true if the focus item navigation is enabled in the receiver.
 boolean isItemInViewport(Section<N> section, N index)
          Returns true if the given item is visible in the viewport, or false otherwise.
 void pack()
          Sets the optimal size of cells for all items in all sections.
 void scrollTo(AxisItem<N> item)
          Scrolls the axis to the position where the given item is the first visible one in the unfrozen area.
 void scrollTo(N index)
          Scrolls the unfrozen area of the axis to the given index in the sequence of visible axis items.
 void setAutoScrollOffset(int offset)
          Sets the offset from the edge of scrolling area within which dragging causes the content to scroll automatically and extend the dragged distance.
 void setFocusItem(AxisItem<N> item)
          Sets the focus marker to the given item.
 void setFocusItem(Section<N> section, N index)
          Sets the focus marker to the given item.
 void setFocusItemEnabled(boolean state)
          Enables current item navigation in the receiver if the argument is true, and disables it otherwise.
 void setFrozenHead(int amount)
          Freezes the specified amount of items at the beginning this axis.
 void setFrozenTail(int amount)
          Freezes the specified amount of last items at the end of this axis.
 void setMinimalCellWidth(int width)
          Sets the minimal cell width to be achieved by a user driven cell resizing.
 void setResizeOffset(int offset)
          Sets the offset from the dividing line within which dragging changes the axis item width.
 void showItem(AxisItem<N> item)
          Scrolls to the given making it visible in the viewport.
 void showItem(Section<N> section, N index)
          Scrolls to the given making it visible in the viewport.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Axis

public Axis()
Constructs axis indexed by Integer class with two sections.


Axis

public Axis(java.lang.Class<N> numberClass,
            int sectionCount,
            int headerIndex,
            int bodyIndex)
Constructs axis indexed by the specified Number subclass containing the specified number of sections. The header section count is set to one, its visibility to false and focus item enabled to false.

Parameters:
numberClass - sub-type of Number class to index the sections
sectionCount - number of sections to create
Throws:
java.lang.IllegalArgumentException - if numberClass is other then int.class, Integer.class, long.class, Long.class, BigInteger.class
java.lang.IllegalArgumentException - if the sectionCount is lower then 2
java.lang.IndexOutOfBoundsException - if the headerIndex or bodyIndex is out of range ( index < 0 || index >= sectionCount)
java.lang.IllegalArgumentException - if the headerIndex equals bodyIndex
Method Detail

toString

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

getBody

public Section<N> getBody()
Returns the body section, which is by default a second section of the axis. Another section can be set as body by specifying bodyIndex argument in the Axis constructor.

Returns:
the body section
See Also:
getHeader()

getHeader

public Section<N> getHeader()
Returns the header section, which is by default the first section of the axis. Another section can be set as header by specifying headerIndex argument in the Axis constructor.

Returns:
the header section.
See Also:
getBody()

getSection

public Section<N> getSection(int sectionIndex)
Returns the section at the specified position in this axis.

Parameters:
sectionIndex - index of the section to return
Returns:
the section at the specified position in this axis
Throws:
java.lang.IndexOutOfBoundsException - if sectionIndex is out of 0 ... getSectionCount()-1 bounds

indexOf

public int indexOf(Section<N> section)
Returns index of the given section in the list of this axis sections or -1 if the section does not belong to this axis.

Parameters:
section - section to find the index of
Returns:

getSectionCount

public int getSectionCount()
Returns the number of sections in the receiver.

Returns:
the number of sections in the receiver.

getViewportItemCount

public int getViewportItemCount()
Returns number of items visible in the viewport. Including partially visible items.

Returns:
number of items visible in the viewport

getViewportPosition

public int getViewportPosition(AxisItem<N> item)
Returns the position of the given item in the sequence of items visible in the viewport or -1 if the viewport does not display the item.

Parameters:
item - the item to get position for
Returns:
the position of the given item in the viewport
Throws:
java.lang.IllegalArgumentException - if item is null or item's section does not belong to this axis.
java.lang.IndexOutOfBoundsException - if item's index is out of 0 ... SectionCore.getCount()-1 bounds

getItemByViewportPosition

public AxisItem<N> getItemByViewportPosition(int position)
Returns the item visible at the specified position in the viewport or null if the position is outside of the viewport bounds.

Parameters:
position - the position the get the item for
Returns:
the item visible at the specified position in the viewport

getItemByViewportDistance

public AxisItem<N> getItemByViewportDistance(int distance)
Returns the item visible at the specified distance from the beginning of viewport area or null if the distance is outside of the viewport bounds.

Parameters:
distance - the position the get the item for
Returns:
the item visible at the specified distance

getItemByViewportOffset

public AxisItem<N> getItemByViewportOffset(AxisItem<N> item,
                                           int offset)
Returns a visible item that is away from the given item by the number of items specified by the offset argument or null if such an item is outside of the viewport bounds or does not exist.

If the offset is positive the item to returned will be computed in the forward direction. Otherwise item in the backward direction will be returned.

Parameters:
item - the item to set the focus for
offset - number of items to move away from the referenced item
Throws:
java.lang.IllegalArgumentException - if item is null or item's section does not belong to this axis.
java.lang.IndexOutOfBoundsException - if item's index is out of 0 ... SectionCore.getCount()-1 bounds

isItemInViewport

public boolean isItemInViewport(Section<N> section,
                                N index)
Returns true if the given item is visible in the viewport, or false otherwise.

Parameters:
section - of the item to check
index - of the item to check
Returns:
true if the given item is visible in the viewport
Throws:
java.lang.IllegalArgumentException - if item is null or item's section does not belong to this axis.
java.lang.IndexOutOfBoundsException - if item's index is out of 0 ... SectionCore.getCount()-1 bounds

getCellBound

public int[] getCellBound(AxisItem<N> item)
Returns the cell bound of the specified item in the viewport or null if the position is outside of the viewport scope. Cell bound is an array of integers, where the first one is the distance from the beginning of viewport and the second one is the cell width.

Parameters:
item - the item to get the cell bound for
Returns:
the cell bound at the specified position in the viewport

getLineBound

public int[] getLineBound(AxisItem<N> item)
Returns the line bound of the specified item in the viewport or null if the position is outside of the viewport scope. Line bound is an array of integers, where the first one is the distance from the beginning of viewport and the second one is the line width.

Parameters:
item - the line to get the line bound for
Returns:
the line bound at the specified position in the viewport

getContentWidth

public int getContentWidth()
Returns the content bound including all the visible cells and lines.

If the content is larger then viewport then the viewport size is returned.

Returns:
the content bound including all the visible cells and lines

compare

public int compare(Section<N> section1,
                   Section<N> section2)
Compares positions of sections on this axis and returns value greater then 0 if section1 is behind section2, value lower then zero if section1 is before section2 and 0 if sections are the same.

Parameters:
section1 - a section to compare
section2 - another section to compare
Returns:
comparison result
Throws:
java.lang.IllegalArgumentException - if section1 or section2 is null or does not belong to this axis.

compare

public int compare(AxisItem<N> item1,
                   AxisItem<N> item2)
Compares positions of items on this axis and returns value greater then 0 if item1 is behind item2, value lower then zero if item1 is before item2 and 0 if items are the same.

Parameters:
item1 - one of the items to compare
item2 - another item to compare
Returns:
comparison result
Throws:
java.lang.IllegalArgumentException - if item1 or item2 is null or item's section does not belong to this axis.
java.lang.IndexOutOfBoundsException - if index of item1 or item2 is out of 0 ... SectionCore.getCount()-1 bounds

isFocusItemEnabled

public boolean isFocusItemEnabled()
Returns true if the focus item navigation is enabled in the receiver. Otherwise false is returned.

Returns:
the receiver's focus item enablement state

setFocusItemEnabled

public void setFocusItemEnabled(boolean state)
Enables current item navigation in the receiver if the argument is true, and disables it otherwise.

If the focus cell is disabled the navigation events are ignored and the Painter.NAME_FOCUS_CELL painter of the matrix is disabled.

Parameters:
state - the new focus item enablement state

getFocusItem

public AxisItem<N> getFocusItem()
Returns the focus item. Or null if no item has focus.

Returns:
the focus item

getMouseItem

public AxisItem<N> getMouseItem()
Returns the last item the mouse was over. Or null if there is no such item.

Returns:
the last item the mouse was over

setFocusItem

public void setFocusItem(AxisItem<N> item)
Sets the focus marker to the given item.

If section has the focus item disabled (see SectionCore.setFocusItemEnabled(boolean)) then this method does nothing.

deprecated Use setFocusItem(Section, Number) instead

Parameters:
item - the item to set the focus for
Throws:
java.lang.IllegalArgumentException - if item is null or item's section does not belong to this axis.
java.lang.IndexOutOfBoundsException - if item's index is out of 0 ... SectionCore.getCount()-1 bounds

setFocusItem

public void setFocusItem(Section<N> section,
                         N index)
Sets the focus marker to the given item.

If section has the focus item disabled (see SectionCore.setFocusItemEnabled(boolean)) then this method does nothing.

Parameters:
section - of the item to set the focus for
index - of the item to set the focus for
Throws:
java.lang.IllegalArgumentException - if item is null or item's section does not belong to this axis.
java.lang.IndexOutOfBoundsException - if item's index is out of 0 ... SectionCore.getCount()-1 bounds

showItem

public void showItem(AxisItem<N> item)
Scrolls to the given making it visible in the viewport.

It works only when the matrix size has been set, which usually happens when the shell to which the matrix belongs gets open.

Parameters:
item - the item to show
Throws:
java.lang.IllegalArgumentException - if item is null or item's section does not belong to this axis.
java.lang.IndexOutOfBoundsException - if item's index is out of 0 ... SectionCore.getCount()-1 bounds

scrollTo

public void scrollTo(AxisItem<N> item)
Scrolls the axis to the position where the given item is the first visible one in the unfrozen area.

Parameters:
item - item to scroll to

scrollTo

public void scrollTo(N index)
Scrolls the unfrozen area of the axis to the given index in the sequence of visible axis items.

Parameters:
index - index in the sequence of visible axis items

showItem

public void showItem(Section<N> section,
                     N index)
Scrolls to the given making it visible in the viewport.

It works only when the matrix size has been set, which usually happens when the shell to which the matrix belongs gets open.

Parameters:
section - section of the item to show
index - index of the item to show
Throws:
java.lang.IllegalArgumentException - if item is null or item's section does not belong to this axis.
java.lang.IndexOutOfBoundsException - if item's index is out of 0 ... SectionCore.getCount()-1 bounds

setFrozenHead

public void setFrozenHead(int amount)
Freezes the specified amount of items at the beginning this axis.

Parameters:
amount - of items to freeze
Throws:
java.lang.IllegalArgumentException - if the argument is lower then zero

getFrozenHead

public int getFrozenHead()
Returns the amount of items frozen at the beginning this axis.

Returns:
the amount of items frozen at the beginning this axis

setFrozenTail

public void setFrozenTail(int amount)
Freezes the specified amount of last items at the end of this axis.

Parameters:
amount - of items to freeze
Throws:
java.lang.IllegalArgumentException - if the argument is lower then zero

getFrozenTail

public int getFrozenTail()
Returns the amount of items frozen at the end this axis.

Returns:
the amount of items frozen at the end this axis

getAutoScrollOffset

public int getAutoScrollOffset()
Returns the offset from the edge of scrolling area within which dragging causes the content to scroll automatically and extend the dragged distance. The default value is 8 for horizontal and 6 for vertical axis.


setAutoScrollOffset

public void setAutoScrollOffset(int offset)
Sets the offset from the edge of scrolling area within which dragging causes the content to scroll automatically and extend the dragged distance.

Parameters:
offset - maximum distance from the edge of the scrolling area in which dragging will cause the content to scroll automatically
Throws:
java.lang.IllegalArgumentException - if the argument is lower then zero

getResizeOffset

public int getResizeOffset()
Returns the offset from the dividing line within which dragging changes the width of the axis item. The default value is 3 for horizontal and 2 for vertical axis.


setResizeOffset

public void setResizeOffset(int offset)
Sets the offset from the dividing line within which dragging changes the axis item width.

Parameters:
offset - maximum distance from the edge of the line in which dragging will cause cell width change
Throws:
java.lang.IllegalArgumentException - if the argument is lower then zero

getMinimalCellWidth

public int getMinimalCellWidth()
Returns the minimal cell width to be achieved by a user driven cell resizing.

Returns:
the minimal cell width to be achieved by a user driven cell resizing

setMinimalCellWidth

public void setMinimalCellWidth(int width)
Sets the minimal cell width to be achieved by a user driven cell resizing.

The default cell size of any section in this axis lower then minimal cell width is increased to then minimal cell width.

Parameters:
width - new minimal width to set

pack

public void pack()
Sets the optimal size of cells for all items in all sections.


computeSize

public int computeSize(Section<N> section,
                       N index)
Computes the optimal cell width that fits its content.
Warning: for a large number of items it may take a long time to compute, because of the necessity to iterate over all items.

index is the item index in the model, not the visual position of the item on the screen which can be altered by move and hide operations.

The width is calculated by Painter.computeSize(Number, Number, int, int) of the zones to which the section belongs.

Parameters:
index - index of the item to set the cell width for
Returns:
the optimal width
Throws:
java.lang.IllegalArgumentException - if index is null
java.lang.IndexOutOfBoundsException - if index is out of 0 ... Section.getCount()-1 bounds

createNumberSet

@Deprecated
public pl.netanel.swt.matrix.NumberSetCore<N> createNumberSet()
Deprecated. 

Creates a number set.

Returns:
newly created number set

getScrollItem

public AxisItem<N> getScrollItem()

getScrollPosition

public N getScrollPosition()


Copyright © 2011 netanel.pl. All Rights Reserved.