danger.ui
Class View

java.lang.Object
  |
  +--danger.app.Listener
        |
        +--danger.ui.View
Direct Known Subclasses:
ClockView, Container, FolderView, Geometry, ImageView, LogView, MonthView, PendingStatusView

public class View
extends Listener

Some call it a Widget, Gadget, or Component. Here at Danger the basic building block of the UI toolkit is the View. Views describe a rectangular surface upon which drawing may occur with the use of a Pen. The upper left and lower right corners of a View are defined by parent-relative coordinates.


Field Summary
protected  int mOriginX
           
protected  int mOriginY
           
protected  Style mStyle
           
static int STATE_CAN_FOCUS
           
static int STATE_DEBUG_BOUNDS
           
static int STATE_ENABLED
           
static int STATE_FOCUSED
           
static int STATE_TRANSPARENT
           
static int STATE_VISIBLE
           
 
Constructor Summary
View()
          Create a new View with initial position of 0,0 and no width and no height.
View(int left, int top, int right, int bottom)
          Create a new View, initially not attached to any parent, with the specified bounds
View(Rect bounds)
          Create a new View, initially not attached to any parent, with bounds specified by the provided Rect
 
Method Summary
 void addChild(View child)
          Add a View as a child to this View.
 boolean childIsOnScreen(View child)
           
 void clear(Pen pen)
           
 Style copyStyle()
           
 void disable()
           
 void enable()
           
 boolean eventKeyDown(char c, Event event)
           
 boolean eventKeyHeld(char c, Event event)
           
 boolean eventKeyRepeat(char c, Event event)
           
 boolean eventKeyUp(char c, Event event)
           
 boolean eventPeriodicPulse(int timestamp)
           
 boolean eventShortcut(char inKey)
           
 boolean eventWidgetDown(int widget, Event event)
           
 boolean eventWidgetHeld(int widget, Event event)
           
 boolean eventWidgetUp(int widget, Event event)
           
 boolean getAcceptFocus()
           
 int getBackgroundColor()
           
 int getBottom()
           
 View getBottomChild()
          Find the child view that has the lowest bottom bound
 Rect getBounds()
          Gets the size of this View as a rectangle located at (0, 0)
 Rect getBounds(Rect r)
          Gets the size of this View as a rectangle located at (0, 0)
 View getFirstChild()
          Get the first child of this View.
 View getFocusedChild()
           
 Rect getFrame()
          Gets the position and size of this View in terms of its parent's coordinate space
 Rect getFrame(Rect r)
          Gets the position and size of this View in terms of its parent's coordinate space
 int getHeight()
           
 Rect getInterestingRect()
           
 Rect getInterestingRect(Rect outRect)
           
 View getLastChild()
          Get the last child of this View.
 int getLeft()
          Get the x-position of this View relative to its parent's coordinate system
 Point getOrigin()
           
 Point getOrigin(Point outPoint)
           
 int getOriginX()
           
 int getOriginY()
           
 View getParent()
           
 int getRight()
           
 View getSibling()
          Get the next View in the list of Views belonging to this View's parent.
 Style getStyle()
           
 int getStyleColor(int attribute)
           
 Font getStyleFont(int attribute)
           
 int getTop()
          Get the y-position of this View relative to its parent's coordinate system
 int getWidth()
           
 Window getWindow()
           
 Rect globalToLocal(Rect inRect)
           
 void hide()
           
 void invalidate()
          Cause this View to be repainted at the earliest opportunity, provided it is VISIBLE and not entirely obscured.
 void invalidate(int left, int top, int right, int bottom)
           
 void invalidate(Rect r)
           
 boolean isEnabled()
           
 boolean isFocusable()
           
 boolean isFocused()
           
 boolean isOnScreen()
           
 boolean isTransparent()
           
 boolean isVisible()
          Returns the VISIBLE state of this View.
 boolean keepRectInView(View inChangingView, Rect inImportantRect)
           
 Point localToGlobal(Point inPoint)
           
 Rect localToGlobal(Rect inRect)
           
 Rect localToWindow(Rect inRect)
           
 void loseFocus()
           
 void moveBy(int h, int v)
           
 void offsetOrigin(int inDeltaY)
           
 void offsetOrigin(int inDeltaX, int inDeltaY)
           
 void onAddedToParent()
           
 void onDecoded()
           
protected  void onPeriodicPulse()
           
 void onRemovedFromParent()
           
protected  void onStyleChanged(int attribute)
           
protected  void onWindowPaint()
           
 void paint(Pen pen)
          Draw the contents of this View.
protected  boolean receiveEventInternal(Event event)
          Internal entry point for event processing.
 void reflowChildren(View inBaseChild, int inAmount)
           
 void removeChild(View child)
          Removes a child View from this View.
 void resetOrigin()
           
 void sendEventToWindow(Event event)
           
 void setAcceptFocus(boolean acceptFocus)
           
 void setBackgroundColor(int inColor)
           
 void setBottom(int inBottom)
           
 void setDebugBounds(boolean debugBounds)
           
 void setEnabled(boolean enabled)
           
 void setFrame(Rect frame)
           
 void setHeight(int inHeight)
           
 void setKeyedValue(int key, int value)
           
 void setLeft(int inLeft)
           
 void setOrigin(int inY)
           
 void setOrigin(int x, int y)
           
 void setPosition(int x, int y)
          Moves this View to a new position specified in its parent's coordinate system
 void setRight(int inRight)
           
 void setSize(int width, int height)
           
 void setStyle(Style style)
           
 void setStyleColor(int attribute, int color)
           
 void setStyleFont(int attribute, Font font)
           
 void setStyleFrameColor(int color)
           
 void setTop(int inTop)
           
 void setTransparent(boolean transparent)
           
 void setVisible(boolean visible)
           
 void setWidth(int inWidth)
           
 void setWindow(Window inWindow)
           
protected  boolean shouldDropEvent(Event event)
           
 void show()
           
 boolean styleIsDefault()
           
 void takeFocus(boolean inFromAbove)
           
 boolean willFocusWithin(Rect r)
           
 Rect windowToLocal(Rect inRect)
           
 
Methods inherited from class danger.app.Listener
cancelEvents, receiveEvent, sendEvent, sendEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mOriginX

protected int mOriginX

mOriginY

protected int mOriginY

mStyle

protected Style mStyle

STATE_VISIBLE

public static final int STATE_VISIBLE

STATE_FOCUSED

public static final int STATE_FOCUSED

STATE_ENABLED

public static final int STATE_ENABLED

STATE_CAN_FOCUS

public static final int STATE_CAN_FOCUS

STATE_TRANSPARENT

public static final int STATE_TRANSPARENT

STATE_DEBUG_BOUNDS

public static final int STATE_DEBUG_BOUNDS
Constructor Detail

View

public View()
Create a new View with initial position of 0,0 and no width and no height.

View

public View(Rect bounds)
Create a new View, initially not attached to any parent, with bounds specified by the provided Rect

View

public View(int left,
            int top,
            int right,
            int bottom)
Create a new View, initially not attached to any parent, with the specified bounds
Method Detail

onDecoded

public void onDecoded()

setKeyedValue

public void setKeyedValue(int key,
                          int value)

getInterestingRect

public Rect getInterestingRect()

getInterestingRect

public Rect getInterestingRect(Rect outRect)

getParent

public final View getParent()

getSibling

public final View getSibling()
Get the next View in the list of Views belonging to this View's parent. If this is the last or only View, null will be returned. The order of children will be dependant on the Container object in question.

getFirstChild

public View getFirstChild()
Get the first child of this View. If the View is not a Container a UIException will be thrown. If it is a Container but has no children, null will be returned.

getLastChild

public View getLastChild()
Get the last child of this View. If the View is not a Container a UIException will be thrown. If it is a Container but has no children, null will be returned.

getBottomChild

public View getBottomChild()
Find the child view that has the lowest bottom bound

addChild

public void addChild(View child)
Add a View as a child to this View. A UIException will be thrown if the proposed parent is not a container or if the proposed child is attached to some other View already

removeChild

public void removeChild(View child)
Removes a child View from this View. A UIException will be thrown if this View is not a container or does not contain the specified child

reflowChildren

public void reflowChildren(View inBaseChild,
                           int inAmount)

childIsOnScreen

public boolean childIsOnScreen(View child)

isOnScreen

public boolean isOnScreen()

getFrame

public final Rect getFrame(Rect r)
Gets the position and size of this View in terms of its parent's coordinate space

getFrame

public final Rect getFrame()
Gets the position and size of this View in terms of its parent's coordinate space

getBounds

public final Rect getBounds(Rect r)
Gets the size of this View as a rectangle located at (0, 0)

getBounds

public final Rect getBounds()
Gets the size of this View as a rectangle located at (0, 0)

getWidth

public final int getWidth()

getHeight

public final int getHeight()

getLeft

public final int getLeft()
Get the x-position of this View relative to its parent's coordinate system

getRight

public final int getRight()

getTop

public final int getTop()
Get the y-position of this View relative to its parent's coordinate system

getBottom

public final int getBottom()

setPosition

public void setPosition(int x,
                        int y)
Moves this View to a new position specified in its parent's coordinate system

setSize

public void setSize(int width,
                    int height)

setFrame

public void setFrame(Rect frame)

setWidth

public void setWidth(int inWidth)

setHeight

public void setHeight(int inHeight)

localToGlobal

public Point localToGlobal(Point inPoint)

localToGlobal

public Rect localToGlobal(Rect inRect)

globalToLocal

public Rect globalToLocal(Rect inRect)

localToWindow

public Rect localToWindow(Rect inRect)

windowToLocal

public Rect windowToLocal(Rect inRect)

paint

public void paint(Pen pen)
Draw the contents of this View. This method is called by the graphics system when the View needs to be repainted. A Pen will be provided which is appropriately clipped and translated for drawing on this View.

clear

public void clear(Pen pen)

invalidate

public void invalidate()
Cause this View to be repainted at the earliest opportunity, provided it is VISIBLE and not entirely obscured.

invalidate

public void invalidate(int left,
                       int top,
                       int right,
                       int bottom)

invalidate

public void invalidate(Rect r)

isVisible

public boolean isVisible()
Returns the VISIBLE state of this View. Views which are not visible cannot draw themselves. Newly created Views are not VISIBLE by default.

show

public void show()

hide

public void hide()

setVisible

public final void setVisible(boolean visible)

isEnabled

public boolean isEnabled()

enable

public void enable()

disable

public void disable()

setEnabled

public final void setEnabled(boolean enabled)

getFocusedChild

public View getFocusedChild()

isFocused

public boolean isFocused()

takeFocus

public void takeFocus(boolean inFromAbove)

loseFocus

public void loseFocus()

setTransparent

public void setTransparent(boolean transparent)

isTransparent

public boolean isTransparent()

setAcceptFocus

public void setAcceptFocus(boolean acceptFocus)

getAcceptFocus

public boolean getAcceptFocus()

isFocusable

public boolean isFocusable()

setBackgroundColor

public void setBackgroundColor(int inColor)

getBackgroundColor

public int getBackgroundColor()

setDebugBounds

public void setDebugBounds(boolean debugBounds)

onAddedToParent

public void onAddedToParent()

onRemovedFromParent

public void onRemovedFromParent()

onWindowPaint

protected void onWindowPaint()

onPeriodicPulse

protected void onPeriodicPulse()

shouldDropEvent

protected boolean shouldDropEvent(Event event)

receiveEventInternal

protected final boolean receiveEventInternal(Event event)
Description copied from class: Listener
Internal entry point for event processing. Default behaviour is to do nothing and return false. receiveEventInternal() is called before ReceiveEvent() by the dispatcher. If receiveEventInternal() consumes the event, it is dispatched and done with. Otherwise, ReceiveEvent() gets a crack at it. This dispatch order allows listeners to handle essential events without the danger of them being trampled in the ReceiveEvent() of subclasses. In order to accomplish this, you need to declare your receiveEventInternal() implementation as final.
Overrides:
receiveEventInternal in class Listener
Following copied from class: danger.app.Listener
Parameters:
e - An Event containing the event to be sent.

eventKeyDown

public boolean eventKeyDown(char c,
                            Event event)

eventKeyRepeat

public boolean eventKeyRepeat(char c,
                              Event event)

eventKeyUp

public boolean eventKeyUp(char c,
                          Event event)

eventKeyHeld

public boolean eventKeyHeld(char c,
                            Event event)

eventWidgetUp

public boolean eventWidgetUp(int widget,
                             Event event)

eventWidgetDown

public boolean eventWidgetDown(int widget,
                               Event event)

eventWidgetHeld

public boolean eventWidgetHeld(int widget,
                               Event event)

eventShortcut

public boolean eventShortcut(char inKey)

eventPeriodicPulse

public boolean eventPeriodicPulse(int timestamp)

sendEventToWindow

public final void sendEventToWindow(Event event)

moveBy

public void moveBy(int h,
                   int v)

setTop

public void setTop(int inTop)

setBottom

public void setBottom(int inBottom)

setLeft

public void setLeft(int inLeft)

setRight

public void setRight(int inRight)

setOrigin

public void setOrigin(int x,
                      int y)

setOrigin

public void setOrigin(int inY)

resetOrigin

public void resetOrigin()

getOrigin

public final Point getOrigin()

getOrigin

public final Point getOrigin(Point outPoint)

getOriginX

public final int getOriginX()

getOriginY

public final int getOriginY()

offsetOrigin

public void offsetOrigin(int inDeltaX,
                         int inDeltaY)

offsetOrigin

public void offsetOrigin(int inDeltaY)

getWindow

public Window getWindow()

setWindow

public void setWindow(Window inWindow)

willFocusWithin

public boolean willFocusWithin(Rect r)

keepRectInView

public boolean keepRectInView(View inChangingView,
                              Rect inImportantRect)

getStyle

public Style getStyle()

setStyle

public void setStyle(Style style)

copyStyle

public Style copyStyle()

styleIsDefault

public boolean styleIsDefault()

setStyleColor

public void setStyleColor(int attribute,
                          int color)

setStyleFont

public void setStyleFont(int attribute,
                         Font font)

getStyleColor

public int getStyleColor(int attribute)

getStyleFont

public Font getStyleFont(int attribute)

setStyleFrameColor

public void setStyleFrameColor(int color)

onStyleChanged

protected void onStyleChanged(int attribute)


Danger Confidential. Copyright © 2000-2003, Danger Inc.