Class PeerComponent

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.PeerComponent
All Implemented Interfaces:
Animation, Editable, StyleListener

public class PeerComponent extends Component
A peer component is essentially a "dummy" Codename One component used to calculate the position of the actual native platform specific component. The behavior of a peer component is very platform specific, it is meant for platforms where a native component can be integrated with a Codename One component. Codename One features such as glass pane, z-ordering, dialogs & menus might not work as expected in all situations where peer components are involved. E.g. a peer component might hide itself when a menu/dialog is shown and recreate itself when it is hidden/disposed.
  • Constructor Details

    • PeerComponent

      protected PeerComponent(Object nativePeer)

      This constructor is used by the platform implementation to create instances of this class use the static create method.

      Parameters
      • nativePeer: the native platform specific peer component.
  • Method Details

    • create

      public static PeerComponent create(Object nativePeer)

      Use this method to encapsulate a native UI object

      Parameters
      • nativePeer: the native platform specific peer component.
    • getPeerImage

      protected Image getPeerImage()

      The peer image is drawn when the component doesn't exist or during transition a placeholder image can be placed in the beginning to show something while the peer is being created asynchronously. This image might be replaced by an internal image representing the actual content of the peer

      Returns

      an image

    • setPeerImage

      protected void setPeerImage(Image i)

      The peer image is drawn when the component doesn't exist or during transition a placeholder image can be placed in the beginning to show something while the peer is being created asynchronously. This image might be replaced by an internal image representing the actual content of the peer

      Parameters
      • i: the peer image
    • generatePeerImage

      protected Image generatePeerImage()

      The native implementation should implement this method to generate a native peer image representing the component

      Returns

      a screenshot of the component

    • shouldRenderPeerImage

      protected boolean shouldRenderPeerImage()

      Subclasses should return true here if the peer image should be rendered instead of the actual peer

      Returns

      true to render the peer image

    • getNativePeer

      public Object getNativePeer()

      Returns the native peer instance

      Returns

      the native peer

    • animate

      public boolean animate()

      Allows the animation to reduce "repaint" calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

      Returns

      true if a repaint is desired or false if no repaint is necessary

      Specified by:
      animate in interface Animation
      Overrides:
      animate in class Component
    • deinitialize

      protected void deinitialize()
      Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.
      Overrides:
      deinitialize in class Component
    • fireClicked

      protected void fireClicked()
      When working in 3 softbutton mode "fire" key (center softbutton) is sent to this method in order to allow 3 button devices to work properly. When overriding this method you should also override isSelectableInteraction to indicate that a command is placed appropriately on top of the fire key for 3 soft button phones.
      Overrides:
      fireClicked in class Component
    • initComponent

      protected void initComponent()
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • keyPressed

      public void keyPressed(int keyCode)

      If this Component is focused, the key pressed event will call this method

      Parameters
      • keyCode: the key code value to indicate a physical key.
      Overrides:
      keyPressed in class Component
    • keyReleased

      public void keyReleased(int keyCode)

      If this Component is focused, the key released event will call this method

      Parameters
      • keyCode: the key code value to indicate a physical key.
      Overrides:
      keyReleased in class Component
    • keyRepeated

      public void keyRepeated(int keyCode)

      If this Component is focused, the key repeat event will call this method.

      Parameters
      • keyCode: the key code value to indicate a physical key.
      Overrides:
      keyRepeated in class Component
    • paint

      public void paint(Graphics g)

      This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

      Parameters
      • g: the component graphics
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component
    • paintBackground

      protected void paintBackground(Graphics g)

      This method paints the Component background, it should be overriden by subclasses to perform custom background drawing.

      Parameters
      • g: the component graphics
      Overrides:
      paintBackground in class Component
    • paintBackgrounds

      public void paintBackgrounds(Graphics g)

      This method paints all the parents Components Background.

      Parameters
      • g: the graphics object
      Overrides:
      paintBackgrounds in class Component
    • paintBorder

      protected void paintBorder(Graphics g)

      Draws the component border if such a border exists. The border unlike the content of the component will not be affected by scrolling for a scrollable component.

      Parameters
      • g: graphics context on which the border is painted
      Overrides:
      paintBorder in class Component
    • paintScrollbarX

      protected void paintScrollbarX(Graphics g)

      Paints the UI for the scrollbar on the X axis, this method allows component subclasses to customize the look of a scrollbar

      Parameters
      • g: the component graphics
      Overrides:
      paintScrollbarX in class Component
    • paintScrollbarY

      protected void paintScrollbarY(Graphics g)

      Paints the UI for the scrollbar on the Y axis, this method allows component subclasses to customize the look of a scrollbar

      Parameters
      • g: the component graphics
      Overrides:
      paintScrollbarY in class Component
    • paintScrollbars

      protected void paintScrollbars(Graphics g)

      Paints the UI for the scrollbars on the component, this will be invoked only for scrollable components. This method invokes the appropriate X/Y versions to do all the work.

      Parameters
      • g: the component graphics
      Overrides:
      paintScrollbars in class Component
    • pointerDragged

      public void pointerDragged(int[] x, int[] y)

      If this Component is focused, the pointer dragged event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerDragged in class Component
    • pointerDragged

      public void pointerDragged(int x, int y)

      If this Component is focused, the pointer dragged event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerDragged in class Component
    • pointerHover

      public void pointerHover(int[] x, int[] y)

      Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerHover in class Component
    • pointerHoverReleased

      public void pointerHoverReleased(int[] x, int[] y)

      Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerHoverReleased in class Component
    • pointerPressed

      public void pointerPressed(int[] x, int[] y)

      If this Component is focused, the pointer pressed event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerPressed in class Component
    • pointerPressed

      public void pointerPressed(int x, int y)

      If this Component is focused, the pointer pressed event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerPressed in class Component
    • pointerReleased

      public void pointerReleased(int[] x, int[] y)

      If this Component is focused, the pointer released event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerReleased in class Component
    • pointerReleased

      public void pointerReleased(int x, int y)

      If this Component is focused, the pointer released event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerReleased in class Component
    • invalidate

      public void invalidate()
      Updates the size of the component from the native widget
    • onPositionSizeChange

      protected void onPositionSizeChange()
      Callback useful for sublclasses that need to track the change in size/position of the component (notice that this might be invoked too many times for a single change)!
    • setLightweightMode

      protected void setLightweightMode(boolean l)

      An optional callback for peers indicating that the peer is now rendered as part of a transition or some other state and is thus not truly visible. In this case the peer should either make itself invisible or render itself as an image instead of natively

      Parameters
      • l: true to enable lightweight mode, false to disable it