de.enough.polish.ui.containerviews
Class FishEyeContainerView

java.lang.Object
  extended by de.enough.polish.ui.ItemView
      extended by de.enough.polish.ui.ContainerView
          extended by de.enough.polish.ui.containerviews.FishEyeContainerView
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CarouselContainerView

public class FishEyeContainerView
extends ContainerView

Arranges the items in a single row and scales items down.

Activate this view by specifying view-type: fisheye in the ChoiceGroup's, Container's or List's style.

Further attributes are:

Example:

 .myList {
                view-type: fisheye;
                fisheyeview-remove-text: true;
                fisheyeview-scale-start: 70%;
                fisheyeview-scale-end: 40%;
                fisheyeview-alpha-start: 200;
                fisheyeview-alpha-end: 100;
      background-color: green;
      padding: 5;
 }
 

Copyright Enough Software 2007 - 2010

 history
        June 21, 2007 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
protected  int[] currentTranslucencies
           
protected  int endTranslucency
           
protected  Background focusedBackground
           
protected  Border focusedBorder
           
protected  int focusedDirection
           
protected  StringItem focusedLabel
           
protected  Style focusedStyle
           
protected  int focusedWidth
           
protected  boolean includeAllItems
           
protected  boolean isRemoveText
           
protected  boolean isShowTextInTitle
           
protected  String[] labels
           
protected  int maxItemHeight
           
protected  int maxVisibleItems
           
protected  int[][] originalRgbData
           
protected  int[] originalRgbDataWidths
           
protected  int referenceFocusedIndex
           
protected  int[] referenceXCenterPositions
           
protected  int[] referenceYCenterPositions
           
protected  int scaleFactor
           
protected  int scaleFactorEnd
           
protected  int[][] shownRgbData
           
protected  int[] shownRgbDataHeights
           
protected  int[] shownRgbDataWidths
           
protected  int startTranslucency
           
protected  int[] targetTranslucencies
           
protected  int[] targetXCenterPositions
           
protected  int[] targetYCenterPositions
           
 
Fields inherited from class de.enough.polish.ui.ContainerView
allowCycling, allowsAutoTraversal, allowsDirectSelectionByPointerEvent, appearanceMode, columnsSetting, columnsWidths, EQUAL_WIDTH_COLUMNS, focusedIndex, focusedItem, focusFirstElement, isAlignHeights, isExpandItems, isHorizontal, isPointerPressedHandled, isSequentialTraversal, isVertical, leftXOffset, NO_COLUMNS, NORMAL_WIDTH_COLUMNS, numberOfColumns, numberOfRows, parentContainer, restartAnimation, rightXOffset, rowsHeights, scrollContinuous, STATIC_WIDTH_COLUMNS, targetXOffset, topYOffset, xOffset, yOffset
 
Fields inherited from class de.enough.polish.ui.ItemView
availableHeight, availableWidth, contentHeight, contentWidth, isFocused, isLayoutCenter, isLayoutRight, layout, paddingHorizontal, paddingVertical, parentItem
 
Constructor Summary
FishEyeContainerView()
          Creates a new fish eye view
 
Method Summary
 void animate(long currentTime, ClippingRegion repaintRegion)
          Animates this item.
protected  int calculateCurrent(int current, int target)
          Used within the animate() method to move a position or alpha value towards a target position/alpha.
protected  void defocus(Style originalStyle)
          Notifies this view that the parent container is not focused anymore.
 void focus(Style focusstyle, int direction)
          Sets the focus to this container view.
 Style focusItem(int focIndex, Item item, int direction, Style focStyle)
          Focuses the given item and retrieves the previous style of that item.
protected static int getDistance(int i, int focused, int length)
          Retrieves the distance between the given index and the focused element witin the list.
protected  int getScaleFactor(int distance, int length)
          Obtains the scaling factor for the given distance from the center item.
 boolean handlePointerDragged(int x, int y)
          Handles the event when a pointer has been dragged to the specified position.
 boolean handlePointerPressed(int x, int y)
          Handles pointer pressed events.
 boolean handlePointerTouchDown(int x, int y)
          Handles a touch down/press event.
protected  void initContent(Item parentContainerItem, int firstLineWidth, int availWidth, int availHeight)
          Initializes this container view.
protected  void initItemArrangement(int lineWidth, int availHeight, Item[] myItems, int length, int maxWidth, int maxHeight)
          Arranges the items in this view.
protected  boolean isValid(Item parent, Style style)
          Implementation that are valid only for specific item classes can override this method so that they cannot be accidently attached to unsupported classes.
 boolean isVerticalLayout()
          Checks if this ContainerView arranges its child items vertically.
protected  void paintContent(Container container, Item[] myItems, int x, int y, int leftBorder, int rightBorder, int clipX, int clipY, int clipWidth, int clipHeight, Graphics g)
          Paints the content of this container view.
protected  void paintItem(Item item, int index, int x, int y, int leftBorder, int rightBorder, int clipX, int clipY, int clipWidth, int clipHeight, Graphics g)
          Paints this item at the specified position.
 void releaseResources()
          Releases all resources that are not required to keep the state of this view.
protected  void setStyle(Style style)
          Sets the style for this view.
 
Methods inherited from class de.enough.polish.ui.ContainerView
addFullRepaintRegion, destroy, focusItem, focusItem, getAppearanceMode, getChildAt, getChildHeight, getChildWidth, getContentHeight, getContentWidth, getItemRelativeY, getNextFocusableItem, getNextItem, getParentRelativeY, getScreen, getScrollTargetXOffset, getScrollXOffset, handleKeyPressed, handlePointerDragged, handlePointerReleased, handlePointerTouchUp, initMargin, initPadding, isInBottomRow, isLayoutExpand, isVirtualContainer, paintContent, scroll, setAppearanceMode, setScrollXOffset, setScrollXOffset, shiftFocus, shiftFocus, shiftFocus, showNotify, startScroll
 
Methods inherited from class de.enough.polish.ui.ItemView
addItemBackground, addItemBackgroundBorder, addItemBorder, adjustToContentArea, animate, handleKeyReleased, hideNotify, init, initContentByParent, notifyItemPressedEnd, notifyItemPressedEnd, notifyItemPressedStart, notifyItemPressedStart, onScreenSizeChanged, paintBackground, paintBorder, paintContentByParent, removeItemBackground, removeItemBorder, removeParentBackground, removeParentBorder, removeViewFromParent, requestInit, setContentHeight, setContentWidth, setStyle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

targetXCenterPositions

protected int[] targetXCenterPositions

referenceXCenterPositions

protected int[] referenceXCenterPositions

targetYCenterPositions

protected int[] targetYCenterPositions

referenceYCenterPositions

protected int[] referenceYCenterPositions

isRemoveText

protected boolean isRemoveText

includeAllItems

protected boolean includeAllItems

labels

protected String[] labels

focusedLabel

protected transient StringItem focusedLabel

originalRgbData

protected transient int[][] originalRgbData

originalRgbDataWidths

protected int[] originalRgbDataWidths

shownRgbData

protected transient int[][] shownRgbData

shownRgbDataWidths

protected int[] shownRgbDataWidths

shownRgbDataHeights

protected int[] shownRgbDataHeights

scaleFactor

protected int scaleFactor

scaleFactorEnd

protected int scaleFactorEnd

startTranslucency

protected int startTranslucency

endTranslucency

protected int endTranslucency

targetTranslucencies

protected int[] targetTranslucencies

currentTranslucencies

protected int[] currentTranslucencies

referenceFocusedIndex

protected int referenceFocusedIndex

focusedBackground

protected transient Background focusedBackground

focusedBorder

protected Border focusedBorder

focusedStyle

protected Style focusedStyle

focusedDirection

protected int focusedDirection

focusedWidth

protected int focusedWidth

maxItemHeight

protected int maxItemHeight

isShowTextInTitle

protected boolean isShowTextInTitle

maxVisibleItems

protected int maxVisibleItems
Constructor Detail

FishEyeContainerView

public FishEyeContainerView()
Creates a new fish eye view

Method Detail

animate

public void animate(long currentTime,
                    ClippingRegion repaintRegion)
Description copied from class: ItemView
Animates this item. Subclasses can override this method to create animations. The default implementation animates the background and the item view if present.

Overrides:
animate in class ContainerView
Parameters:
currentTime - the current time in milliseconds
repaintRegion - the repaint area that needs to be updated when this item is animated
See Also:
Item.getAbsoluteX(), Item.getAbsoluteY()

getDistance

protected static int getDistance(int i,
                                 int focused,
                                 int length)
Retrieves the distance between the given index and the focused element witin the list.

Parameters:
i - the index
focused - the index of the focused element
length - the length of the list
Returns:
the distance between the index and the focused lement

calculateCurrent

protected int calculateCurrent(int current,
                               int target)
Used within the animate() method to move a position or alpha value towards a target position/alpha.

Parameters:
current - the current value
target - the target value
Returns:
the current value closer to the target

isValid

protected boolean isValid(Item parent,
                          Style style)
Description copied from class: ItemView
Implementation that are valid only for specific item classes can override this method so that they cannot be accidently attached to unsupported classes. This allows casting without checking the parent item with instanceof in each method, for example. The default implementation just returns true for any case.

Overrides:
isValid in class ContainerView
Parameters:
parent - the parent item
style - the style
Returns:
true when the view can be used for the parent item.

initContent

protected void initContent(Item parentContainerItem,
                           int firstLineWidth,
                           int availWidth,
                           int availHeight)
Description copied from class: ContainerView
Initializes this container view. The implementation needs to calculate and set the contentWidth and contentHeight fields. The style of the focused item has already been set. When the contentWidth will be larger than the specified availWidth, the container view allows to scroll horizontally automatically using pointer events.

Overrides:
initContent in class ContainerView
Parameters:
parentContainerItem - the Container which uses this view, use parent.getItems() for retrieving all items.
firstLineWidth - the maximum width of the first line
availWidth - the maximum width of any following lines
availHeight - the maximum height of the view
See Also:
ItemView.contentWidth, ItemView.contentHeight

initItemArrangement

protected void initItemArrangement(int lineWidth,
                                   int availHeight,
                                   Item[] myItems,
                                   int length,
                                   int maxWidth,
                                   int maxHeight)
Arranges the items in this view.

Parameters:
lineWidth - the available line width
availHeight - the available height in pixels
myItems - all items
length - the number of items
maxWidth - the maximum width of one item
maxHeight - the maximum height of one item

getScaleFactor

protected int getScaleFactor(int distance,
                             int length)
Obtains the scaling factor for the given distance from the center item.

Parameters:
distance - the distance to the central/focused item - an item next to the focused item has the distance 0.
length - the number of items of the parent container
Returns:
the scaling factor in percent - 100 means there is nothing to scale.

defocus

protected void defocus(Style originalStyle)
Description copied from class: ItemView
Notifies this view that the parent container is not focused anymore. Please call super.defocus() when overriding this method. The default implementation calls setStyle( originalStyle ) and sets the field "isFocused" to false.

Overrides:
defocus in class ItemView
Parameters:
originalStyle - the previous used style, may be null.

focus

public void focus(Style focusstyle,
                  int direction)
Description copied from class: ItemView
Sets the focus to this container view. The default implementation sets the style and the field "isFocused" to true.

Overrides:
focus in class ItemView
Parameters:
focusstyle - the appropriate style.
direction - the direction from the which the focus is gained, either Canvas.UP, Canvas.DOWN, Canvas.LEFT, Canvas.RIGHT or 0. When 0 is given, the direction is unknown.1

focusItem

public Style focusItem(int focIndex,
                       Item item,
                       int direction,
                       Style focStyle)
Description copied from class: ContainerView
Focuses the given item and retrieves the previous style of that item. The default implementation sets the focusedIndex and focusedItem fields and returns the result of item.focus( focusStyle, direction ). This is a method that is usually called from within the parent Container (in contrast to the other focusItem() methods which forward the call to the parentContainer).

Overrides:
focusItem in class ContainerView
Parameters:
focIndex - the index of the item
item - the item which should be focused
direction - the direction, either Canvas.DOWN, Canvas.RIGHT, Canvas.UP, Canvas.LEFT or 0.
focStyle - the new style for the focused item
Returns:
the previous style of the focussed item

paintContent

protected void paintContent(Container container,
                            Item[] myItems,
                            int x,
                            int y,
                            int leftBorder,
                            int rightBorder,
                            int clipX,
                            int clipY,
                            int clipWidth,
                            int clipHeight,
                            Graphics g)
Description copied from class: ContainerView
Paints the content of this container view. This method calls

Overrides:
paintContent in class ContainerView
Parameters:
container - the parent container
myItems - the items that should be painted
x - the left start position
y - the upper start position
leftBorder - the left border, nothing must be painted left of this position
rightBorder - the right border, nothing must be painted right of this position
clipX - absolute horizontal clipping start
clipY - absolute verical clipping start
clipWidth - clipping width
clipHeight - clipping height
g - the Graphics on which this item should be painted.

paintItem

protected void paintItem(Item item,
                         int index,
                         int x,
                         int y,
                         int leftBorder,
                         int rightBorder,
                         int clipX,
                         int clipY,
                         int clipWidth,
                         int clipHeight,
                         Graphics g)
Description copied from class: ContainerView
Paints this item at the specified position. Subclasses can override this method for taking advantage of the table support of the basic ContainerView class. When the item is outside of the given clipping area, it will not be painted.

Overrides:
paintItem in class ContainerView
Parameters:
item - the item that needs to be painted
index - the index of the item
x - the horizontal position of the item
y - the vertical position of the item
leftBorder - the left border
rightBorder - the right border
clipX - absolute horizontal clipping start
clipY - absolute verical clipping start
clipWidth - clipping width
clipHeight - clipping height
g - the graphics context

setStyle

protected void setStyle(Style style)
Description copied from class: ContainerView
Sets the style for this view. The style can include additional parameters for the view. Subclasses should call super.setStyle(style) first.

Overrides:
setStyle in class ContainerView
Parameters:
style - the style

releaseResources

public void releaseResources()
Description copied from class: ItemView
Releases all resources that are not required to keep the state of this view. The default implementation does free nothing and only sets the "isInitialized" flag if the parent item.

Overrides:
releaseResources in class ContainerView

handlePointerDragged

public boolean handlePointerDragged(int x,
                                    int y)
Description copied from class: ItemView
Handles the event when a pointer has been dragged to the specified position. The default implementation just returns false. You only need to implement this method when there are pointer events:
 //#if polish.hasPointerEvents
 

Overrides:
handlePointerDragged in class ItemView
Parameters:
x - the x position of the event relative to the item's horizontal left edge
y - the y position of the event relative to the item's vertical top edge
Returns:
true when the pressing of the pointer was actually handled by this item.

handlePointerPressed

public boolean handlePointerPressed(int x,
                                    int y)
Description copied from class: ItemView
Handles pointer pressed events. This is an optional feature that doesn't need to be implemented by subclasses, since the parent container already forwards the event to the appropriate item (when this method returns false). The default implementation just returns false. You only need to implement this method when there are pointer events:
 //#if polish.hasPointerEvents
 

Overrides:
handlePointerPressed in class ContainerView
Parameters:
x - the x position of the event relative to the item's horizontal left edge
y - the y position of the event relative to the item's vertical top edge
Returns:
true when the event has been handled. When false is returned the parent container will forward the event to the affected item.

handlePointerTouchDown

public boolean handlePointerTouchDown(int x,
                                      int y)
Description copied from class: ItemView
Handles a touch down/press event. This is similar to a pointerPressed event, however it is only available on devices with screens that differentiate between press and touch events (read: BlackBerry Storm).

Overrides:
handlePointerTouchDown in class ContainerView
Parameters:
x - the horizontal pixel position of the touch event relative to the parent item's left position
y - the vertical pixel position of the touch event relative to the parent item's top position
Returns:
true when the event was handled

isVerticalLayout

public boolean isVerticalLayout()
Description copied from class: ContainerView
Checks if this ContainerView arranges its child items vertically.

Overrides:
isVerticalLayout in class ContainerView
Returns:
true when the layout is vertical, false when it is horizontal or complex