javauis/lcdui_qt/src/com/nokia/mj/impl/nokialcdui/LCDUIInvoker.java
branchRCL_3
changeset 65 ae942d28ec0e
equal deleted inserted replaced
60:6c158198356e 65:ae942d28ec0e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 package com.nokia.mj.impl.nokialcdui;
       
    18 
       
    19 import javax.microedition.lcdui.*;
       
    20 
       
    21 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
       
    22 
       
    23 import com.nokia.mid.ui.DirectGraphics;
       
    24 
       
    25 /**
       
    26  * Abstract class providing the interface to internal LCDUI resources.
       
    27  */
       
    28 public abstract class LCDUIInvoker
       
    29 {
       
    30 
       
    31     /**
       
    32      * Invoker instance.
       
    33      */
       
    34     private static com.nokia.mj.impl.nokialcdui.LCDUIInvoker invokerInstance;
       
    35 
       
    36     /**
       
    37      * Method called at LCDUI initialization and setting the invoker.
       
    38      *
       
    39      * @param invoker In
       
    40      */
       
    41     public static void setInvoker(LCDUIInvoker invoker)
       
    42     {
       
    43         invokerInstance = invoker;
       
    44     }
       
    45 
       
    46     /**
       
    47      * Synchronized execution of runnable with eSWT thread.
       
    48      *
       
    49      * @param runnable a runnable
       
    50      */
       
    51     public static void eSWTUIThreadRunnerSyncExec(Runnable runnable)
       
    52     {
       
    53         invokerInstance.doESWTUIThreadRunnerSyncExec(runnable);
       
    54     }
       
    55 
       
    56     /**
       
    57      * Returns main eSWT Control that is used by LCDUI Displayable or Item.
       
    58      *
       
    59      * @param lcduiObject - LCDUI Displayable or Item.
       
    60      * @return eSWT Control that is used by Displayable/Item or null if no
       
    61      *         Control is available.
       
    62      */
       
    63     public static org.eclipse.swt.widgets.Control getEswtControl(Object lcduiObject)
       
    64     {
       
    65         return invokerInstance.doGetEswtControl(lcduiObject);
       
    66     }
       
    67 
       
    68     public static void setItemControlStateChangeListener(ItemControlStateChangeListener listener,Item item)
       
    69     {
       
    70         invokerInstance.doSetItemControlStateChangeListener(listener,item);
       
    71     }
       
    72 
       
    73     /**
       
    74      * Returns eSWT Display that is used by LCDUI.
       
    75      *
       
    76      * @return eSWT Display that is used by LCDUI.
       
    77      */
       
    78     public static org.eclipse.swt.widgets.Display getEswtDisplay()
       
    79     {
       
    80         return invokerInstance.doGetEswtDisplay();
       
    81     }
       
    82 
       
    83     /**
       
    84      * Returns eSWT Image from an LCDUI Image. The returned object is an already
       
    85      * existing eSWT Image object contained within the LCDUI Image, so calling
       
    86      * this function is efficient.
       
    87      *
       
    88      * @param img - LCDUI Image object.
       
    89      * @return eSWT Image.
       
    90      */
       
    91     public static org.eclipse.swt.graphics.Image getEswtImage(Image img)
       
    92     {
       
    93         return invokerInstance.doGetEswtImage(img);
       
    94     }
       
    95 
       
    96     /**
       
    97      * Returns the WindowSurface where g will be drawing.
       
    98      * @param g The graphics object
       
    99      * @return WindowSurface where g will be drawing.
       
   100      */
       
   101     public static org.eclipse.swt.internal.qt.graphics.WindowSurface getWindowSurface(Graphics g)
       
   102     {
       
   103         return invokerInstance.doGetWindowSurface(g);
       
   104     }
       
   105     
       
   106     /**
       
   107      * Creates LCDUI Image from an eSWT Image. The returned object is a new
       
   108      * LCDUI Image object created from the eSWT Image, so this method is not
       
   109      * as efficient as getEswtImage.
       
   110      *
       
   111      * @param img - eSWT Image object.
       
   112      * @return LCDUI Image.
       
   113      */
       
   114     public static Image createLcduiImage(org.eclipse.swt.graphics.Image img)
       
   115     {
       
   116         return invokerInstance.doGetLcduiImage(img);
       
   117     }
       
   118 
       
   119 
       
   120     /**
       
   121      * Get the DirectGraphics object associated with this Graphics object.
       
   122      *
       
   123      * @param g Graphics object
       
   124      * @return DirectGraphics object
       
   125      */
       
   126     public static DirectGraphics getDirectGraphics(Graphics g)
       
   127     {
       
   128         return invokerInstance.doGetDirectGraphics(g);
       
   129     }
       
   130 
       
   131     public static GraphicsContext getGc(Graphics g)
       
   132     {
       
   133         return invokerInstance.doGetGc(g);
       
   134     }
       
   135 
       
   136     /**
       
   137      * Get a freely sized Font with the given parameters.
       
   138      *
       
   139      * @param face font face
       
   140      * @param style font style
       
   141      * @param height font height
       
   142      * @return the requested Font
       
   143      */
       
   144     public static Font getFreeSizedFont(int face, int style, int height)
       
   145     {
       
   146         return invokerInstance.doGetFreeSizedFont(face, style, height);
       
   147     }
       
   148 
       
   149     /**
       
   150      * Init GameCanvas.
       
   151      *
       
   152      * @param canvas GameCanvas object
       
   153      * @param suppressKeys suppress game keys
       
   154      * @return framebuffer image
       
   155      */
       
   156     public static void initGameCanvas(Object canvas, boolean suppressKeys)
       
   157     {
       
   158         invokerInstance.doInitGameCanvas(canvas, suppressKeys);
       
   159     }
       
   160 
       
   161     /**
       
   162      * Get the frameBuffer's Graphics object.
       
   163      *
       
   164      * @param canvas GameCanvas object
       
   165      * @return Graphics object
       
   166      */
       
   167     public static Object getGraphics(Object canvas)
       
   168     {
       
   169         return invokerInstance.doGetGraphics(canvas);
       
   170     }
       
   171 
       
   172     public static Object getFlushLock(Object graphics)
       
   173     {
       
   174         return invokerInstance.doGetFlushLock(graphics);
       
   175     }
       
   176 
       
   177     /**
       
   178      * Get game key states.
       
   179      *
       
   180      * @param canvas GameCanvas object
       
   181      * @return key states
       
   182      */
       
   183     public static int getKeyStates(Object canvas)
       
   184     {
       
   185         return invokerInstance.doGetKeyStates(canvas);
       
   186     }
       
   187 
       
   188     /**
       
   189      * Renders the GameCanvas's frameBuffer to the Graphics object at (0,0).
       
   190      *
       
   191      * @param canvas GameCanvas object
       
   192      * @param graphics Graphics object
       
   193      */
       
   194     public static void renderGraphics(Object canvas, Object graphics)
       
   195     {
       
   196         invokerInstance.doRenderGraphics(canvas, graphics);
       
   197     }
       
   198 
       
   199     /**
       
   200      * Flushes the GameCanvas's frameBuffer to the display.
       
   201      *
       
   202      * @param canvas GameCanvas object
       
   203      * @param x clip X
       
   204      * @param y clip Y
       
   205      * @param width clip width
       
   206      * @param height clip height
       
   207      */
       
   208     public static void flushGraphics(Object canvas,
       
   209                                      int x, int y, int width, int height)
       
   210     {
       
   211         invokerInstance.doFlushGraphics(canvas, x, y, width, height);
       
   212     }
       
   213 
       
   214     /**
       
   215      * Synchronizes any pending buffered draw commands to the target of the 
       
   216      * graphics object.
       
   217      *
       
   218      * Must be called from UI-thread.
       
   219      *
       
   220      * @param graphics The object to synchronize
       
   221      */
       
   222     public static void sync(Object graphics)
       
   223     {
       
   224     	invokerInstance.doSync(graphics);
       
   225     }
       
   226     
       
   227     /**
       
   228      * Begins an external renderer session to given Graphics. An external renderer
       
   229      * could be, for example,  M3G renderer. The opened rendering session must be
       
   230      * ended by calling the endExternalRendering().
       
   231      *
       
   232      * This function must be called from UI-thread only.
       
   233      *
       
   234      * @param g Graphics where the rendering session starts.
       
   235      */
       
   236     public static void startExternalRendering(Graphics g)
       
   237     {
       
   238         invokerInstance.doStartExternalRendering(g);
       
   239     }
       
   240     
       
   241     /**
       
   242      * Ends the external rendering session on given Graphics that was started
       
   243      * by calling startExternalRendering().
       
   244      *
       
   245      * This function must be called from UI-thread only.
       
   246      *
       
   247      * @param g The Graphics instance.
       
   248      */
       
   249     public static void endExternalRendering(Graphics g)
       
   250     {
       
   251         invokerInstance.doEndExternalRendering(g);
       
   252     }
       
   253      
       
   254     
       
   255     /**
       
   256      * Returns the dynamic property value.
       
   257      *
       
   258      * @param key property key
       
   259      * @return property value
       
   260      */
       
   261     public static String getDynamicProperty(String key)
       
   262     {
       
   263         return invokerInstance.doGetDynamicProperty(key);
       
   264     }
       
   265 
       
   266     /**
       
   267      * Detect pixel level collision.
       
   268      */
       
   269     public static boolean detectCollision(Image image1, int transform1, int p1x, int p1y,
       
   270                                           int r1x1, int r1y1, int r1x2, int r1y2,
       
   271                                           Image image2, int transform2, int p2x, int p2y,
       
   272                                           int r2x1, int r2y1, int r2x2, int r2y2)
       
   273     {
       
   274         return invokerInstance.doDetectCollision(image1, transform1, p1x, p1y,
       
   275                 r1x1, r1y1, r1x2, r1y2,
       
   276                 image2, transform2, p2x, p2y,
       
   277                 r2x1, r2y1, r2x2, r2y2);
       
   278     }
       
   279 
       
   280 
       
   281     // MMAPI support
       
   282 
       
   283     protected abstract org.eclipse.swt.widgets.Control doGetEswtControl(
       
   284         Object lcduiObj);
       
   285 
       
   286     protected abstract org.eclipse.swt.widgets.Display doGetEswtDisplay();
       
   287 
       
   288     protected abstract org.eclipse.swt.graphics.Image doGetEswtImage(Image img);
       
   289 
       
   290     protected abstract Image doGetLcduiImage(org.eclipse.swt.graphics.Image img);
       
   291 
       
   292     protected abstract void doSetItemControlStateChangeListener(ItemControlStateChangeListener listener,Item item);
       
   293 
       
   294     protected abstract org.eclipse.swt.internal.qt.graphics.WindowSurface doGetWindowSurface( Graphics g );
       
   295     
       
   296     // DirectGraphics support
       
   297 
       
   298     protected abstract DirectGraphics doGetDirectGraphics(Graphics g);
       
   299 
       
   300     protected abstract GraphicsContext doGetGc(Graphics g);
       
   301 
       
   302     protected abstract Font doGetFreeSizedFont(int face, int style, int height);
       
   303 
       
   304     // GameCanvas support
       
   305 
       
   306     protected abstract void doInitGameCanvas(Object canvas,
       
   307             boolean suppressKeys);
       
   308 
       
   309     protected abstract Object doGetGraphics(Object canvas);
       
   310 
       
   311     protected abstract Object doGetFlushLock(Object graphics);
       
   312 
       
   313     protected abstract int doGetKeyStates(Object canvas);
       
   314 
       
   315     protected abstract void doRenderGraphics(Object canvas, Object graphics);
       
   316 
       
   317     protected abstract void doFlushGraphics(Object canvas,
       
   318                                             int x, int y, int width, int height);
       
   319 
       
   320     protected abstract void doSync(Object graphics);
       
   321     
       
   322     protected abstract void doStartExternalRendering(Graphics g);
       
   323     
       
   324     protected abstract void doEndExternalRendering(Graphics g);
       
   325     
       
   326     protected abstract String doGetDynamicProperty(String key);
       
   327 
       
   328     protected abstract boolean doDetectCollision(Image image1, int transform1, int p1x, int p1y,
       
   329             int r1x1, int r1y1, int r1x2, int r1y2,
       
   330             Image image2, int transform2, int p2x, int p2y,
       
   331             int r2x1, int r2y1, int r2x2, int r2y2);
       
   332 
       
   333     // TactileFeedback support
       
   334     protected abstract void doESWTUIThreadRunnerSyncExec(Runnable runnable);
       
   335 
       
   336 
       
   337 }